howtocode 0.7.65 → 0.7.67

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.
@@ -1 +1 @@
1
- import{a,b,c,d,e,f,g,h,i,j,k,l,m,n}from"./chunk-ABDZXFNM.js";import"./chunk-UTYFLLSM.js";import"./chunk-WOT6VMZA.js";export{e as RETIRED_ROBLOX_BRIDGE,c as addMcpServers,g as describeMcpServer,a as mcpConfigPath,j as mcpHubCategories,l as mcpHubFind,k as mcpHubIn,h as mcpHubPath,n as missingEnvFor,i as readMcpHub,d as removeMcpServers,f as retireRobloxBridge,m as serverSpecFromEntry,b as validateMcpBlock};
1
+ import{a,b,c,d,e,f,g,h,i,j,k,l,m,n}from"./chunk-465RG5I6.js";import"./chunk-UTYFLLSM.js";import"./chunk-WOT6VMZA.js";export{e as RETIRED_ROBLOX_BRIDGE,c as addMcpServers,g as describeMcpServer,a as mcpConfigPath,j as mcpHubCategories,l as mcpHubFind,k as mcpHubIn,h as mcpHubPath,n as missingEnvFor,i as readMcpHub,d as removeMcpServers,f as retireRobloxBridge,m as serverSpecFromEntry,b as validateMcpBlock};
@@ -0,0 +1,10 @@
1
+ import{a as A}from"./chunk-UTYFLLSM.js";import{existsSync as E,readFileSync as D}from"node:fs";import{dirname as Le,join as de}from"node:path";import{fileURLToPath as Fe}from"node:url";import{cpSync as J,existsSync as T,readdirSync as je,readFileSync as ce,renameSync as He,statSync as N,writeFileSync as Ne}from"node:fs";import{homedir as ue}from"node:os";import{dirname as Te,join as p,resolve as De}from"node:path";import{cpSync as he,existsSync as S,mkdirSync as P,mkdtempSync as L,readdirSync as R,readFileSync as j,renameSync as be,rmSync as b,statSync as x,writeFileSync as M}from"node:fs";import{tmpdir as V}from"node:os";import{dirname as Q,isAbsolute as Se,join as u,relative as ke,resolve as C}from"node:path";import{fileURLToPath as ve}from"node:url";import{execFileSync as xe}from"node:child_process";import{createHash as Z}from"node:crypto";import{gunzipSync as me}from"node:zlib";var k=512;function O(e,t,r){let n=e.subarray(t,t+r),s=n.indexOf(0);return n.subarray(0,s===-1?n.length:s).toString("utf8").trim()}function W(e,t,r){let n=O(e,t,r);if(!n)return 0;let s=Number.parseInt(n,8);return Number.isFinite(s)?s:0}function ye(e){let t={},r=0;for(;r<e.length;){let n=e.indexOf(32,r);if(n===-1)break;let s=Number.parseInt(e.toString("utf8",r,n),10);if(!Number.isFinite(s)||s<=0)break;let i=e.toString("utf8",n+1,r+s-1),o=i.indexOf("=");o>0&&(t[i.slice(0,o)]=i.slice(o+1)),r+=s}return t}function K(e){let t=me(e),r=[],n=0,s,i={};for(;n+k<=t.length;){let o=t.subarray(n,n+k);if(o.every(ge=>ge===0))break;let a=O(o,0,100),c=O(o,345,155),l=W(o,124,12),f=W(o,100,8),m=String.fromCharCode(o[156]??48),w=O(o,157,100),v=l>0?t.subarray(n+k,n+k+l):Buffer.alloc(0);if(n+=k+Math.ceil(l/k)*k,m==="x"||m==="g"){i=ye(v);continue}if(m==="L"){s=v.toString("utf8").replace(/\0.*$/s,"").trim();continue}let y=i.path??s??(c?`${c}/${a}`:a);s=void 0,i={};let d=y.indexOf("/");if(d===-1||(y=y.slice(d+1),y=y.replace(/\/+$/,""),!y))continue;let h=m==="5"?"directory":m==="2"?"symlink":m==="0"||m==="\0"||m===""?"file":"other";r.push({path:y,kind:h,size:l,mode:f&511,...h==="file"?{data:Buffer.from(v)}:{},...h==="symlink"?{link:w}:{}})}return r}function U(e){if(!e||e.startsWith("/")||e.startsWith("\\")||/^[a-zA-Z]:/.test(e))return!1;let t=e.replace(/\/+$/,"");return t?t.split("/").every(n=>n!==""&&n!=="."&&n!==".."):!1}function X(e,t){let r=`${t.replace(/\/+$/,"")}/`,n=[];for(let s of e){if(!s.path.startsWith(r))continue;let i=s.path.slice(r.length);i&&n.push({...s,path:i})}return n}function we(){return u(g,"presets")}function Y(e){return u(e,".howtocode","presets")}function ee(e){return S(u(e,".disabled"))}function te(){return u(Q(ve(import.meta.url)),"presets")}function H(e){return[Y(e),we()]}var re=/^[a-z0-9][a-z0-9-]*$/,$e=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;function _(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function $(e,t){let r=ke(C(e),C(t));return r!==""&&!r.startsWith("..")&&!Se(r)}function ne(e,t){let r=[];if(!_(t))return["preset.json must be a JSON object"];let n=l=>{let f=t[l];return typeof f!="string"||f.trim()===""?(r.push(`${l} must be a non-empty string`),""):f.trim()},s=n("name");n("title"),n("description"),n("category");let i=n("version");s&&!re.test(s)&&r.push(`name "${s}" must be lowercase letters, digits and dashes`),i&&!$e.test(i)&&r.push(`version "${i}" is not a version like 1.0.0`);let o=t.skills;if(!Array.isArray(o)||o.length===0)r.push("skills must be a non-empty array of directory names");else for(let l of o){if(typeof l!="string"||l.trim()===""){r.push("every skills entry must be a non-empty string");continue}let f=u(e,"skills",l.trim());if(!$(u(e,"skills"),f)){r.push(`skill "${l}" escapes the preset directory`);continue}S(u(f,"SKILL.md"))||r.push(`skill "${l}" has no SKILL.md at ${u("skills",l)}`)}let a=t.prompt;if(a!==void 0)if(typeof a!="string"||a.trim()==="")r.push("prompt must be a non-empty string when present");else{let l=u(e,a.trim());$(e,l)?S(l)||r.push(`prompt file "${a}" does not exist`):r.push(`prompt "${a}" escapes the preset directory`)}let c=t.tags;return c!==void 0&&!Array.isArray(c)&&r.push("tags must be an array when present"),r.push(...q(t.mcp)),r}function se(e){let t=u(e,"preset.json");if(!S(t))return{problems:[`no preset.json in ${e}`]};let r;try{r=JSON.parse(j(t,"utf8"))}catch(o){return{problems:[`preset.json is not valid JSON: ${o instanceof Error?o.message:String(o)}`]}}let n=ne(e,r);if(n.length>0)return{problems:n};let s=r,i=Array.isArray(s.tags)?s.tags.filter(o=>typeof o=="string"):[];return{problems:[],manifest:{name:String(s.name),title:String(s.title),description:String(s.description),category:String(s.category),tags:i,version:String(s.version),skills:s.skills.map(o=>String(o)),prompt:typeof s.prompt=="string"?s.prompt:void 0,mcp:s.mcp&&typeof s.mcp=="object"&&!Array.isArray(s.mcp)?s.mcp:void 0,integrates:typeof s.integrates=="string"&&s.integrates.trim()!==""?s.integrates.trim():void 0}}}function F(e){return e.filter(t=>{try{return x(t).isDirectory()}catch{return!1}})}function I(e,t){let r=[],n=[],s=(o,a)=>{if(!S(u(o,"preset.json")))return;let{manifest:c,problems:l}=se(o);c?r.push({manifest:c,dir:o,source:t}):n.push(`${a}: ${l.join("; ")}`)},i;try{i=R(e).sort()}catch{return{entries:r,problems:n}}for(let o of i){if(o.startsWith("."))continue;let a=u(e,o);try{if(!x(a).isDirectory())continue}catch{continue}if(S(u(a,"preset.json"))){s(a,o);continue}let c;try{c=R(a).sort()}catch{continue}for(let l of c){if(l.startsWith("."))continue;let f=u(a,l);try{if(!x(f).isDirectory())continue}catch{continue}s(f,u(o,l))}}return{entries:r,problems:n}}function Ye(e){let t=I(te(),"bundled"),r=[...t.entries],n=[...t.problems],s=new Map(r.map(i=>[i.manifest.name,i]));for(let i of F(H(e))){let o=I(i,"installed");n.push(...o.problems);for(let a of o.entries){let c=s.get(a.manifest.name);if(c){let l=r.indexOf(c);l>=0&&(r[l]=a),s.set(a.manifest.name,a)}else r.push(a),s.set(a.manifest.name,a)}}return{entries:r,problems:n}}function et(e){return[...new Set(e.map(t=>t.manifest.category))].sort()}function tt(e,t){return e.filter(r=>r.manifest.category===t).sort((r,n)=>r.manifest.title.localeCompare(n.manifest.title))}function ie(e){let t=[];for(let r of F(H(e))){let{entries:n}=I(r,"installed");for(let s of n)ee(s.dir)||t.push(u(s.dir,"skills"))}return t}function rt(e){let t=[];for(let r of F(H(e))){let{entries:n}=I(r,"installed");for(let s of n){if(ee(s.dir))continue;let i=s.manifest.prompt;if(!i)continue;let o=u(s.dir,i);if($(s.dir,o))try{let a=j(o,"utf8").trim();a&&t.push({name:s.manifest.name,title:s.manifest.title,text:a})}catch{}}}return t}function nt(e,t){let r=0;for(let n of t.skills)try{r+=x(u(e,"skills",n,"SKILL.md")).size}catch{}return r}function Ee(e){Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,e)}var Ae=".install.lock";function Oe(e,t){P(e,{recursive:!0});let r=u(e,Ae),n=Date.now()+6e4;for(;;)try{M(r,`${process.pid}
2
+ `,{flag:"wx"});break}catch(s){if(s.code!=="EEXIST")throw s;let i=!1;try{i=Date.now()-x(r).mtimeMs>12e4}catch{continue}if(i){b(r,{force:!0});continue}if(Date.now()>n)throw new Error(`another install is holding ${r}; remove it if no install is running`);Ee(100)}try{for(let s of R(e))s.startsWith(".staging-")&&b(u(e,s),{recursive:!0,force:!0});return t()}finally{b(r,{force:!0})}}function oe(e,t,r){let n=u(t,r.name);return Oe(t,()=>{P(t,{recursive:!0});let s=L(u(t,".staging-"));try{he(e,s,{recursive:!0}),b(n,{recursive:!0,force:!0}),be(s,n)}catch(i){throw b(s,{recursive:!0,force:!0}),i}return n})}function ae(e,t){if(!S(e))return{ok:!1,problems:[`no such directory: ${e}`]};let{manifest:r,problems:n}=se(e);if(!r)return{ok:!1,problems:n};let s=oe(e,t,r);return{ok:!0,name:r.name,target:s,problems:[]}}function Pe(e,t){let r=L(u(V(),"howtocode-preset-"));try{return xe("git",["clone","--depth","1","--quiet",e,r],{stdio:"pipe"}),ae(r,t)}catch(n){return{ok:!1,problems:[`git clone failed: ${(n instanceof Error?n.message:String(n)).split(`
3
+ `)[0]}`]}}finally{b(r,{recursive:!0,force:!0})}}function st(e,t){return/^(https?:\/\/|git@|git:\/\/)/.test(e)?Pe(e,t):ae(C(e),t)}function it(e,t){let r=[],n=[];if(!re.test(e))return{removed:r,problems:[`"${e}" is not a preset name`]};for(let s of H(t)){let i=u(s,e);if(S(i)){if(!$(s,i)){n.push(`refusing to remove ${i}: outside ${s}`);continue}b(i,{recursive:!0,force:!0}),r.push(i)}}return r.length===0&&n.push(`"${e}" is not installed`),{removed:r,problems:n}}function ot(e){return Y(e)}function Re(e){let t=[],r=(i,o)=>{for(let a of R(i,{withFileTypes:!0}).sort((c,l)=>c.name.localeCompare(l.name))){let c=u(i,a.name),l=o?`${o}/${a.name}`:a.name;a.isSymbolicLink()||(a.isDirectory()?r(c,l):a.isFile()&&t.push([l,Z("sha256").update(j(c)).digest("hex")]))}};r(e,"");let n=0;for(let[i]of t)n+=x(u(e,i)).size;let s=t.map(([i,o])=>`${o} ${i}`).join(`
4
+ `);return{digest:Z("sha256").update(s).digest("hex").slice(0,16),fileCount:t.length,bytes:n}}function at(){let e=u(te(),"hub.json");try{let t=j(e,"utf8"),r=JSON.parse(t),n=_(r)&&Array.isArray(r.entries)?r.entries:[],s=[];for(let i of n)_(i)&&(typeof i.name!="string"||typeof i.repo!="string"||typeof i.sha!="string"||typeof i.path!="string"||typeof i.category!="string"||s.push({name:i.name,title:typeof i.title=="string"?i.title:i.name,description:typeof i.description=="string"?i.description:"",category:i.category,skill:typeof i.skill=="string"?i.skill:i.name,path:i.path,repo:i.repo,sha:i.sha,license:typeof i.license=="string"?i.license:"unknown",stars:typeof i.stars=="number"?i.stars:0,sizeKb:typeof i.sizeKb=="number"?i.sizeKb:0,...typeof i.digest=="string"?{digest:i.digest}:{},...typeof i.fileCount=="number"?{fileCount:i.fileCount}:{},...typeof i.modelInvocable=="boolean"?{modelInvocable:i.modelInvocable}:{}}));return{entries:s,problems:[]}}catch(t){return t?.code==="ENOENT"?{entries:[],problems:[]}:{entries:[],problems:[`registry unreadable: ${t instanceof Error?t.message:String(t)}`]}}}function ct(e){return[...new Set(e.map(t=>t.category))].sort()}function lt(e,t){return e.filter(r=>r.category===t).sort((r,n)=>n.stars-r.stars||r.name.localeCompare(n.name))}function ut(e,t){return e.find(r=>r.name===t)}function Ie(e){return`https://codeload.github.com/${e.repo}/tar.gz/${e.sha}`}async function ft(e,t,r=12e4){let n=L(u(V(),"howtocode-hub-"));try{let s=await fetch(Ie(e),{signal:AbortSignal.timeout(r),redirect:"follow"});if(!s.ok)return{ok:!1,problems:[`${e.repo}: HTTP ${s.status} from codeload`]};let i=Buffer.from(await s.arrayBuffer()),o=K(i),a=X(o,e.path).filter(d=>d.kind==="file"||d.kind==="directory");if(!a.some(d=>d.path==="SKILL.md"))return{ok:!1,problems:[`${e.repo}@${e.sha.slice(0,7)} has no ${e.path}/SKILL.md`]};let c=u(n,"preset",e.name),l=u(c,"skills",e.skill),f=0;for(let d of a){if(!U(d.path))return{ok:!1,problems:[`refusing unsafe path in archive: ${d.path}`]};let h=u(l,d.path);if(!$(l,h))return{ok:!1,problems:[`refusing path outside the skill: ${d.path}`]};if(d.kind==="directory"){P(h,{recursive:!0});continue}P(Q(h),{recursive:!0}),M(h,d.data??Buffer.alloc(0)),f+=1}let m={name:e.name,title:e.title,description:e.description,category:e.category,version:"1.0.0",skills:[e.skill],source:`${e.repo}@${e.sha}`,license:e.license};if(M(u(c,"preset.json"),`${JSON.stringify(m,null,2)}
5
+ `),!e.digest)return{ok:!1,problems:[`${e.repo}@${e.sha.slice(0,7)}: registry entry has no digest`,"refusing to install; content cannot be verified against what was reviewed"]};let w=Re(l);if(w.digest!==e.digest)return{ok:!1,problems:[`${e.repo}@${e.sha.slice(0,7)}: content changed under a pinned commit`,`expected ${e.digest} (${e.fileCount??"?"} files), got ${w.digest} (${w.fileCount} files)`,"refusing to install; the registry needs regenerating"]};let v=ne(c,m);if(v.length>0)return{ok:!1,problems:v};let y=oe(c,t,m);return{ok:!0,name:e.name,target:y,problems:[],skill:e.skill,modelInvocable:e.modelInvocable}}catch(s){return{ok:!1,problems:[`download failed: ${(s instanceof Error?s.message:String(s)).split(`
6
+ `)[0]}`]}}finally{b(n,{recursive:!0,force:!0})}}function Me(){let e=(process.env.HOWTOCODE_HOME??process.env.HOWTOFIX_HOME??process.env.HOME??"").trim();return De(e||ue())}function fe(e,t){for(let r of je(e)){let n=p(e,r),s=p(t,r);if(!T(s)){try{J(n,s,{recursive:!0,force:!1})}catch{}continue}let i=!1;try{i=N(n).isDirectory()}catch{continue}if(i&&N(s).isDirectory()){fe(n,s);continue}try{let o=N(s).size,a=N(n).size;!i&&o<=2&&a>o&&J(n,s,{force:!0})}catch{}}}function Ce(e){let t=p(ue(),".howtofix");if(T(t)){if(!T(e))try{He(t,e),z(e);return}catch{try{J(t,e,{recursive:!0}),z(e);return}catch{return}}fe(t,e),z(e)}}function z(e){le(p(e,"agent","models.json"),"providers"),le(p(e,"agent","auth.json"),void 0)}function le(e,t){if(!T(e))return;let r;try{r=JSON.parse(ce(e,"utf8"))}catch{return}let n=t?r[t]:r;if(!n||typeof n!="object")return;let s=!1;for(let[i,o]of Object.entries(n)){let a=o,c=typeof a?.baseUrl=="string"?a.baseUrl:"";c&&!/^https?:\/\/(api\.)?howtofix\.id(?:\/|$)/i.test(c)&&(delete n[i],s=!0)}if(t===void 0){let i=new Set(Object.keys(JSON.parse(ce(p(Te(e),"models.json"),"utf8")).providers??{}));for(let o of Object.keys(n))i.has(o)||i.has(o.replace(/^howtofix/,"howtocode"))||(delete n[o],s=!0)}for(let[i,o]of Object.entries(n)){let a=i==="howtofix"?"howtocode":i==="howtofix-free"?"howtocode-free":i;a===i||n[a]!==void 0||(n[a]=o,delete n[i],s=!0)}if(s)try{Ne(e,`${JSON.stringify(r,null,2)}
7
+ `)}catch{}}var g=process.env.HOWTOCODE_CODING_AGENT_DIR?.trim()||process.env.HOWTOFIX_CODING_AGENT_DIR?.trim()||(()=>{let e=p(Me(),".howtocode");return Ce(e),p(e,"agent")})(),ht=p(g,"skills");function _e(e){return p(e,".howtocode","skills")}function bt(e){let t=[_e(e)];return t.push(...ie(e)),t}var St=p(g,"agents"),kt=p(g,"usage-cache.json"),vt=p(g,"reachable-models.json"),xt=p(g,"workflows");function wt(){process.env.HXF_CODING_AGENT_DIR=g}var $t=p(g,"images");function B(e=g){return de(e,"mcp.json")}function q(e){let t=[];if(e===void 0)return t;if(typeof e!="object"||e===null||Array.isArray(e))return["mcp must be an object of server names"];for(let[r,n]of Object.entries(e)){if(!/^[A-Za-z0-9_-]+$/.test(r)){t.push(`mcp server "${r}" must use only letters, digits, _ and -`);continue}if(typeof n!="object"||n===null||Array.isArray(n)){t.push(`mcp server "${r}" must be an object`);continue}let s=n,i=typeof s.command=="string"&&s.command.trim()!=="",o=typeof s.url=="string"&&s.url.trim()!=="";!i&&!o&&t.push(`mcp server "${r}" needs either a command or a url`),s.args!==void 0&&!Array.isArray(s.args)&&t.push(`mcp server "${r}": args must be an array`);for(let a of["env","headers"]){let c=s[a];if(c!==void 0){if(typeof c!="object"||c===null||Array.isArray(c)){t.push(`mcp server "${r}": ${a} must be an object of strings`);continue}for(let[l,f]of Object.entries(c))typeof f!="string"&&t.push(`mcp server "${r}": ${a}.${l} must be a string`)}}}return t}function G(e){if(!E(e))return{mcpServers:{}};try{let t=JSON.parse(D(e,"utf8"));if(!t||typeof t!="object"||Array.isArray(t))return{mcpServers:{}};let r=t.mcpServers;return!r||typeof r!="object"||Array.isArray(r)?{mcpServers:{}}:{mcpServers:r}}catch{return{mcpServers:{}}}}function jt(e,t=g){let r=Object.keys(e);if(r.length===0)return{added:[],skipped:[],problems:[]};let n=B(t),s=[];if(E(n))try{JSON.parse(D(n,"utf8"))}catch{return{added:[],skipped:[],problems:[`${n} is not valid JSON; leaving it alone`]}}let i=G(n),o=[],a=[];for(let c of r){if(i.mcpServers[c]!==void 0){a.push(c);continue}i.mcpServers[c]=e[c],o.push(c)}if(o.length>0)try{A(n,`${JSON.stringify(i,null,2)}
8
+ `)}catch(c){return{added:[],skipped:a,problems:[`could not write ${n}: ${c instanceof Error?c.message:String(c)}`]}}return{added:o,skipped:a,problems:s}}function Ht(e,t=new Set,r=g){let n=B(r),s=[];if(e.length===0||!E(n))return{removed:[],kept:[],problems:s};let i=G(n),o=[],a=[];for(let c of e)if(i.mcpServers[c]!==void 0){if(t.has(c)){a.push(c);continue}delete i.mcpServers[c],o.push(c)}if(o.length>0)try{A(n,`${JSON.stringify(i,null,2)}
9
+ `)}catch(c){return{removed:[],kept:a,problems:[`could not write ${n}: ${c instanceof Error?c.message:String(c)}`]}}return{removed:o,kept:a,problems:s}}var pe="@netrodev/howtocode-roblox-bridge";function Nt(e=g){let t=B(e);if(!E(t))return[];try{JSON.parse(D(t,"utf8"))}catch{return[]}let r=G(t),n=Object.keys(r.mcpServers).filter(s=>{let i=r.mcpServers[s];return[i.command,...Array.isArray(i.args)?i.args:[]].map(a=>String(a??"")).some(a=>a===pe||a.startsWith(`${pe}@`))});if(n.length===0)return[];for(let s of n)delete r.mcpServers[s];try{A(t,`${JSON.stringify(r,null,2)}
10
+ `)}catch{return[]}return n}function Tt(e){if(typeof e.url=="string"&&e.url)return`http: ${e.url}`;let t=typeof e.command=="string"?e.command:"",r=Array.isArray(e.args)?e.args.filter(n=>typeof n=="string"):[];return`stdio: ${[t,...r].join(" ")}`.trim()}function ze(){return de(Le(Fe(import.meta.url)),"presets","mcp-hub.json")}function Dt(e=ze()){let t=[];if(!E(e))return{entries:[],problems:[`no MCP catalogue at ${e}`]};let r;try{r=JSON.parse(D(e,"utf8"))}catch(i){return{entries:[],problems:[`${e} is not valid JSON: ${i instanceof Error?i.message:String(i)}`]}}let n=r?.entries;if(!Array.isArray(n))return{entries:[],problems:[`${e} has no entries array`]};let s=[];for(let i of n){if(typeof i!="object"||i===null||Array.isArray(i))continue;let o=i,a=typeof o.name=="string"?o.name.trim():"";if(!a){t.push("an entry has no name");continue}if(!/^[A-Za-z0-9_-]+$/.test(a)){t.push(`"${a}" is not a usable server name`);continue}let c=typeof o.command=="string"&&o.command.trim()!=="",l=typeof o.url=="string"&&o.url.trim()!=="";if(!c&&!l){t.push(`"${a}" has neither a command nor a url`);continue}s.push({name:a,title:typeof o.title=="string"?o.title:a,description:typeof o.description=="string"?o.description:"",category:typeof o.category=="string"?o.category:"other",preset:typeof o.preset=="string"?o.preset:void 0,command:typeof o.command=="string"?o.command:void 0,url:typeof o.url=="string"?o.url:void 0,args:Array.isArray(o.args)?o.args.filter(f=>typeof f=="string"):void 0,env:o.env&&typeof o.env=="object"&&!Array.isArray(o.env)?o.env:void 0,needs:Array.isArray(o.needs)?o.needs.filter(f=>typeof f=="string"):void 0,docs:typeof o.docs=="string"?o.docs:void 0})}return{entries:s,problems:t}}function Mt(e){return[...new Set(e.map(t=>t.category))].sort()}function Ct(e,t){return e.filter(r=>r.category===t).sort((r,n)=>r.title.localeCompare(n.title))}function _t(e,t){return e.find(r=>r.name===t)}function Lt(e){let t={};return e.command&&(t.command=e.command),e.url&&(t.url=e.url),e.args&&e.args.length>0&&(t.args=[...e.args]),e.env&&Object.keys(e.env).length>0&&(t.env={...e.env}),e.description&&(t.description=e.description),t}function Ft(e,t=process.env){return(e.needs??[]).filter(r=>!t[r])}export{B as a,q as b,jt as c,Ht as d,pe as e,Nt as f,Tt as g,ze as h,Dt as i,Mt as j,Ct as k,_t as l,Lt as m,Ft as n,ee as o,te as p,ne as q,se as r,Ye as s,et as t,tt as u,ie as v,rt as w,nt as x,ae as y,st as z,it as A,ot as B,at as C,ct as D,lt as E,ut as F,ft as G,g as H,ht as I,_e as J,bt as K,St as L,kt as M,vt as N,xt as O,wt as P,$t as Q};
@@ -1,4 +1,4 @@
1
- import{$ as We,B as De,C as Ce,E as R,F as H,Fa as ot,H as B,I as Pe,Q as je,R as Ne,Ra as st,S as Me,T as Fe,U as Le,Ua as Q,V as Be,W as Ue,Wa as rt,Y as Ge,_ as Y,a as N,b as M,ba as He,c as ge,ca as qe,d as he,da as ze,e as we,ea as V,f as be,fa as Ze,g as A,ga as Ke,i as ye,j as ke,ja as Xe,k as Se,l as _e,la as Ye,m as X,ma as q,na as Ve,o as Te,oa as Je,p as Ee,q as $e,qa as J,r as ve,s as Ae,t as x,u as Re,ua as Qe,va as et,w as Oe,x as W,xa as tt,y as Ie,ya as nt}from"./chunk-RU6VPYMJ.js";import{b as xe}from"./chunk-27TRKD65.js";import{c as ue}from"./chunk-JC3DY2HZ.js";import{h as pe,l as fe}from"./chunk-NQNMEZEO.js";import{t as me}from"./chunk-SVONBXW3.js";import"./chunk-7LA2AMZB.js";import{H as S,K as de,v as ce,w as le}from"./chunk-ABDZXFNM.js";import"./chunk-UTYFLLSM.js";import"./chunk-MVVEYKN6.js";import"./chunk-CYOHDIPQ.js";import{b as G,c as ie,d as ae}from"./chunk-4AQGNUVQ.js";import"./chunk-WOT6VMZA.js";import{join as Nt}from"node:path";import{hostname as io}from"node:os";import{createAgentSession as ao,createCodemodeExtension as co,createMcpExtension as lo,createToolSearchExtension as uo,DefaultResourceLoader as po,ProjectTrustStore as fo,SessionManager as Z,SettingsManager as mo}from"@netrodev/hxf-coding-agent";import{existsSync as Ft,readFileSync as Lt}from"node:fs";import{join as Bt}from"node:path";var it=Bt(S,"APPEND_SYSTEM.md"),Ut=["<non-interactive>","This run has no user attached: it was started with --print, and there is nobody to answer a question. Anything that stops and waits for a reply \u2014 `ask`, a confirmation, a skill that resolves a mode by asking which mode to use \u2014 will simply end the run with the task unfinished.","So do not ask. Where an instruction tells you to ask the user and wait, take the default it describes and continue, and say which default you took and why in your final answer. The user reads that answer; they cannot answer mid-run.","Where a skill offers a choice of modes, prefer the one that applies the rules while you work over the one that audits afterwards: this is the mode for building something now, and the audit mode can still be run later by the same person who reads your answer.","</non-interactive>"].join(`
1
+ import{$ as We,B as De,C as Ce,E as R,F as H,Fa as ot,H as B,I as Pe,Q as je,R as Ne,Ra as st,S as Me,T as Fe,U as Le,Ua as Q,V as Be,W as Ue,Wa as rt,Y as Ge,_ as Y,a as N,b as M,ba as He,c as ge,ca as qe,d as he,da as ze,e as we,ea as V,f as be,fa as Ze,g as A,ga as Ke,i as ye,j as ke,ja as Xe,k as Se,l as _e,la as Ye,m as X,ma as q,na as Ve,o as Te,oa as Je,p as Ee,q as $e,qa as J,r as ve,s as Ae,t as x,u as Re,ua as Qe,va as et,w as Oe,x as W,xa as tt,y as Ie,ya as nt}from"./chunk-VDUY46W2.js";import{b as xe}from"./chunk-27TRKD65.js";import{c as ue}from"./chunk-GEAWXEQG.js";import{h as pe,l as fe}from"./chunk-K4ONXZQE.js";import{t as me}from"./chunk-SVONBXW3.js";import"./chunk-7LA2AMZB.js";import{H as S,K as de,v as ce,w as le}from"./chunk-465RG5I6.js";import"./chunk-UTYFLLSM.js";import"./chunk-MVVEYKN6.js";import"./chunk-NFVGCV56.js";import{b as G,c as ie,d as ae}from"./chunk-XSUEEWKS.js";import"./chunk-WOT6VMZA.js";import{join as Nt}from"node:path";import{hostname as io}from"node:os";import{createAgentSession as ao,createCodemodeExtension as co,createMcpExtension as lo,createToolSearchExtension as uo,DefaultResourceLoader as po,ProjectTrustStore as fo,SessionManager as Z,SettingsManager as mo}from"@netrodev/hxf-coding-agent";import{existsSync as Ft,readFileSync as Lt}from"node:fs";import{join as Bt}from"node:path";var it=Bt(S,"APPEND_SYSTEM.md"),Ut=["<non-interactive>","This run has no user attached: it was started with --print, and there is nobody to answer a question. Anything that stops and waits for a reply \u2014 `ask`, a confirmation, a skill that resolves a mode by asking which mode to use \u2014 will simply end the run with the task unfinished.","So do not ask. Where an instruction tells you to ask the user and wait, take the default it describes and continue, and say which default you took and why in your final answer. The user reads that answer; they cannot answer mid-run.","Where a skill offers a choice of modes, prefer the one that applies the rules while you work over the one that audits afterwards: this is the mode for building something now, and the audit mode can still be run later by the same person who reads your answer.","</non-interactive>"].join(`
2
2
  `),Gt=16*1024;function Wt(e){try{if(!Ft(e))return;let t=Lt(e,"utf8").trim();return!t||Buffer.byteLength(t,"utf8")>Gt?void 0:t}catch{return}}function at(e,t){let s=[t?e:`${e}
3
3
 
4
4
  ${Ut}`],n=Wt(it);return n&&s.push(`# Standing instructions from ${it}
@@ -1 +1 @@
1
- import{d as a,e as b,f as c,g as d,h as e,i as f,j as g,k as h,l as i}from"./chunk-NQNMEZEO.js";import"./chunk-UTYFLLSM.js";import"./chunk-CYOHDIPQ.js";import"./chunk-4AQGNUVQ.js";import"./chunk-WOT6VMZA.js";export{b as CLI_REFRESH_SKEW_MS,c as accessTokenIsFresh,g as clearCliCredential,a as cliCredentialsPath,e as readCliCredential,h as refreshCliCredential,d as refreshTokenIsUsable,i as renewCliCredentialIfNeeded,f as writeCliCredential};
1
+ import{d as a,e as b,f as c,g as d,h as e,i as f,j as g,k as h,l as i}from"./chunk-K4ONXZQE.js";import"./chunk-UTYFLLSM.js";import"./chunk-NFVGCV56.js";import"./chunk-XSUEEWKS.js";import"./chunk-WOT6VMZA.js";export{b as CLI_REFRESH_SKEW_MS,c as accessTokenIsFresh,g as clearCliCredential,a as cliCredentialsPath,e as readCliCredential,h as refreshCliCredential,d as refreshTokenIsUsable,i as renewCliCredentialIfNeeded,f as writeCliCredential};
@@ -1,4 +1,4 @@
1
- import{b as j}from"./chunk-MCAAX33K.js";import{H as m,N as A}from"./chunk-ABDZXFNM.js";import"./chunk-UTYFLLSM.js";import{j as R}from"./chunk-MVVEYKN6.js";import{b as M,d as T,f as D}from"./chunk-TUXY64DT.js";import{a as I}from"./chunk-U3GZBLTM.js";import{a as b}from"./chunk-4AQGNUVQ.js";import"./chunk-WOT6VMZA.js";import{spawnSync as J}from"node:child_process";import{existsSync as S,readdirSync as E,readFileSync as x,realpathSync as B,statSync as C,writeFileSync as F,unlinkSync as z}from"node:fs";import{dirname as N,join as p}from"node:path";var k=[22,19];async function W(t="https://api.howtofix.id/api/status"){let n=[],[s,e]=process.versions.node.split(".").map(Number),r=s>k[0]||s===k[0]&&e>=k[1];n.push({name:"node",ok:r,detail:`${process.versions.node} (needs >= ${k[0]}.${k[1]})`});let i=J("git",["--version"],{encoding:"utf8"});n.push({name:"git",ok:i.status===0,detail:i.status===0?i.stdout.trim():"not found on PATH"});let o=I();n.push({name:"sandbox",ok:!!o,detail:o??"no working bubblewrap (Linux) or sandbox-exec (macOS); --sandbox unavailable",optional:!0});let l=!1,c=m;try{let d=p(m,`.doctor-${process.pid}`);F(d,"ok"),z(d),l=!0}catch(d){c=`${m} is not writable: ${d instanceof Error?d.message:String(d)}`}n.push({name:"state dir",ok:l,detail:c});let a=p(m,"auth.json"),u="no auth.json \u2014 run `howtocode` and sign in",h=!1;try{let d=JSON.parse(x(a,"utf8")),f=Object.keys(d).length;h=f>0,u=h?`${f} provider credential${f===1?"":"s"}`:u}catch{}n.push({name:"auth",ok:h,detail:u,optional:!0});try{let d=Date.now(),f=await fetch(t,{signal:AbortSignal.timeout(5e3)});n.push({name:"gateway",ok:f.ok,detail:`${t} \u2192 ${f.status} in ${Date.now()-d}ms`,optional:!0})}catch(d){n.push({name:"gateway",ok:!1,detail:`${t} unreachable: ${d instanceof Error?d.message:String(d)}`,optional:!0})}return n.push(G()),n}function G(t=q()){if(t===void 0)return{name:"install",ok:!0,detail:"not an npm install; skipped",optional:!0};if(!S(t))return{name:"install",ok:!0,detail:"no bundled dependencies to check",optional:!0};let n=[],s=0;for(let e of["@netrodev"]){let r=p(t,e);if(S(r))for(let i of E(r)){let o=p(r,i,"dist");if(S(o))for(let l of _(o)){s+=1;let c=x(l,"utf8");for(let a of c.matchAll(/import\("(\.[^"]+)"\)/g)){let u=p(N(l),a[1]);S(u)||n.push(`${e}/${i}: ${u.slice(o.length+1)}`)}}}}return n.length>0?{name:"install",ok:!1,detail:`${n.length} module${n.length===1?"":"s"} missing (${n[0]}); reinstall with \`npm install -g howtocode@latest\``}:{name:"install",ok:!0,detail:`${s} lazy module${s===1?"":"s"} present`}}function q(){try{return p(N(N(B(process.argv[1]??""))),"node_modules")}catch{return}}function _(t,n=[]){let s;try{s=E(t)}catch{return n}for(let e of s){let r=p(t,e);if(e.endsWith(".lazy.js"))n.push(r);else if(!e.includes("."))try{C(r).isDirectory()&&_(r,n)}catch{}}return n}async function ie(){let t=await W(),n=Math.max(...t.map(e=>e.name.length));for(let e of t){let r=e.ok?"ok ":e.optional?"warn":"FAIL";console.log(` ${r} ${e.name.padEnd(n)} ${e.detail}`)}let s=t.filter(e=>!e.ok&&!e.optional);return s.length>0?(console.log(`
1
+ import{b as j}from"./chunk-MCAAX33K.js";import{H as m,N as A}from"./chunk-465RG5I6.js";import"./chunk-UTYFLLSM.js";import{j as R}from"./chunk-MVVEYKN6.js";import{b as M,d as T,f as D}from"./chunk-TUXY64DT.js";import{a as I}from"./chunk-U3GZBLTM.js";import{a as b}from"./chunk-XSUEEWKS.js";import"./chunk-WOT6VMZA.js";import{spawnSync as J}from"node:child_process";import{existsSync as S,readdirSync as E,readFileSync as x,realpathSync as B,statSync as C,writeFileSync as F,unlinkSync as z}from"node:fs";import{dirname as N,join as p}from"node:path";var k=[22,19];async function W(t="https://api.howtofix.id/api/status"){let n=[],[s,e]=process.versions.node.split(".").map(Number),r=s>k[0]||s===k[0]&&e>=k[1];n.push({name:"node",ok:r,detail:`${process.versions.node} (needs >= ${k[0]}.${k[1]})`});let i=J("git",["--version"],{encoding:"utf8"});n.push({name:"git",ok:i.status===0,detail:i.status===0?i.stdout.trim():"not found on PATH"});let o=I();n.push({name:"sandbox",ok:!!o,detail:o??"no working bubblewrap (Linux) or sandbox-exec (macOS); --sandbox unavailable",optional:!0});let l=!1,c=m;try{let d=p(m,`.doctor-${process.pid}`);F(d,"ok"),z(d),l=!0}catch(d){c=`${m} is not writable: ${d instanceof Error?d.message:String(d)}`}n.push({name:"state dir",ok:l,detail:c});let a=p(m,"auth.json"),u="no auth.json \u2014 run `howtocode` and sign in",h=!1;try{let d=JSON.parse(x(a,"utf8")),f=Object.keys(d).length;h=f>0,u=h?`${f} provider credential${f===1?"":"s"}`:u}catch{}n.push({name:"auth",ok:h,detail:u,optional:!0});try{let d=Date.now(),f=await fetch(t,{signal:AbortSignal.timeout(5e3)});n.push({name:"gateway",ok:f.ok,detail:`${t} \u2192 ${f.status} in ${Date.now()-d}ms`,optional:!0})}catch(d){n.push({name:"gateway",ok:!1,detail:`${t} unreachable: ${d instanceof Error?d.message:String(d)}`,optional:!0})}return n.push(G()),n}function G(t=q()){if(t===void 0)return{name:"install",ok:!0,detail:"not an npm install; skipped",optional:!0};if(!S(t))return{name:"install",ok:!0,detail:"no bundled dependencies to check",optional:!0};let n=[],s=0;for(let e of["@netrodev"]){let r=p(t,e);if(S(r))for(let i of E(r)){let o=p(r,i,"dist");if(S(o))for(let l of _(o)){s+=1;let c=x(l,"utf8");for(let a of c.matchAll(/import\("(\.[^"]+)"\)/g)){let u=p(N(l),a[1]);S(u)||n.push(`${e}/${i}: ${u.slice(o.length+1)}`)}}}}return n.length>0?{name:"install",ok:!1,detail:`${n.length} module${n.length===1?"":"s"} missing (${n[0]}); reinstall with \`npm install -g howtocode@latest\``}:{name:"install",ok:!0,detail:`${s} lazy module${s===1?"":"s"} present`}}function q(){try{return p(N(N(B(process.argv[1]??""))),"node_modules")}catch{return}}function _(t,n=[]){let s;try{s=E(t)}catch{return n}for(let e of s){let r=p(t,e);if(e.endsWith(".lazy.js"))n.push(r);else if(!e.includes("."))try{C(r).isDirectory()&&_(r,n)}catch{}}return n}async function ie(){let t=await W(),n=Math.max(...t.map(e=>e.name.length));for(let e of t){let r=e.ok?"ok ":e.optional?"warn":"FAIL";console.log(` ${r} ${e.name.padEnd(n)} ${e.detail}`)}let s=t.filter(e=>!e.ok&&!e.optional);return s.length>0?(console.log(`
2
2
  ${s.length} problem${s.length===1?"":"s"} must be fixed before a session will work.`),1):0}function ce(t=m){let n=p(t,"models.json"),s;try{s=x(n,"utf8")}catch(a){return a.code==="ENOENT"?console.log(` no models.json at ${n} \u2014 run \`howtocode /connect\` to pull the catalogue`):j(b,"models",a),1}let e;try{e=JSON.parse(s)}catch(a){return console.error(`${b}: models: ${n} is not valid JSON (${a instanceof Error?a.message:String(a)})`),console.error(" fix the file, or delete it and run `howtocode /connect` to write a new one"),1}let r=e.providers??{},i=D(A),o=i?new Set(i.ids):void 0,l=new Set,c=0;for(let[a,u]of Object.entries(r)){let h=u.models??[],d=h.map(f=>f.id).filter(Boolean);for(let f of d)l.add(f);c+=d.length,console.log(` ${a} (${d.length})`);for(let f of h){if(!f.id)continue;let O=T(m).get(f.id),$=M(O??[]),g=$?` ${$}`:"",w=o&&!o.has(f.id)?" \u2014 not on this account":"";console.log(` ${f.id}${g}${w}`)}}if(o){let a=[...l].filter(u=>!o.has(u)).length;console.log(`
3
3
  ${[...o].filter(u=>l.has(u)).length} of ${c} listed model(s) this account can call${a>0?`; ${a} cannot (kept for other plans)`:""}`)}else console.log("\n which of these this account can call is unknown: run `howtocode` once to record it");return c===0?(console.log(" no models configured"),1):0}function v(t=15,n=m){let s=p(n,"sessions"),e;try{e=E(s)}catch{return[]}let r=[];for(let i of e){let o=p(s,i),l;try{l=E(o)}catch{continue}for(let c of l){if(!c.endsWith(".jsonl"))continue;let a=p(o,c);try{let u=C(a);r.push({file:a,project:i,modified:u.mtimeMs,bytes:u.size})}catch{}}}return r.sort((i,o)=>o.modified-i.modified).slice(0,t)}function le(t){let n=t.indexOf("--search");if(n>=0){let o=t[n+1]?.trim();if(!o)return console.error(`${b}: sessions: --search needs a word or phrase`),2;let l=K(o);if(l.length===0)return console.log(` no session mentions "${o}"`),0;for(let c of l){let a=new Date(c.row.modified).toISOString().replace("T"," ").slice(0,16),u=`${c.matches} hit${c.matches===1?"":"s"}`;console.log(` ${a} ${c.row.project} (${u})`),console.log(` ${c.row.file}`),console.log(` ${c.snippet}`)}return 0}let s=t.indexOf("--limit"),e=s>=0&&Number(t[s+1])||15,r=v(e);if(r.length===0)return console.log(` no saved sessions under ${p(m,"sessions")}`),t.includes("--export")?1:0;let i=t.indexOf("--export");if(i>=0){let o=Number(t[i+1]);if(!Number.isInteger(o)||o<1||o>r.length)return console.error(`${b}: sessions: --export needs a number from the list (1-${r.length})`),2;let l=r[o-1];try{console.log(Q(l.file))}catch(c){return j(b,"sessions",c),1}return 0}return r.forEach((o,l)=>{let c=new Date(o.modified).toISOString().replace("T"," ").slice(0,16),a=Math.round(o.bytes/1024);console.log(` ${String(l+1).padStart(2)} ${c} ${String(a).padStart(6)}k ${o.project}`),console.log(` ${o.file}`)}),0}function H(t){let n=t;try{let s=JSON.parse(t),e=s.message?.content??s.content;if(typeof e=="string"&&e.trim())n=e;else if(Array.isArray(e)){let r=e.map(i=>i&&typeof i=="object"&&"text"in i?String(i.text):"").join(" ");r.trim()&&(n=r)}}catch{}return R(X(n).replace(/\s+/g," ").trim())}function X(t){return t.replace(/\u001b\[[0-9;?]*[ -/]*[@-~]|\u001b\][^\u0007]*\u0007|\u001b[@-Z\\-_]/g,"")}function Z(t,n,s=80){let e=t.toLowerCase().indexOf(n);if(e<0)return t.slice(0,s*2).trim();let r=Math.max(0,e-s),i=Math.min(t.length,e+n.length+s);return`${r>0?"\u2026":""}${t.slice(r,i).trim()}${i<t.length?"\u2026":""}`}function K(t,n=10,s=m){let e=t.toLowerCase(),r=new RegExp(`\\b${e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\b`,"i"),i=[];for(let o of v(Number.MAX_SAFE_INTEGER,s)){let l;try{l=x(o.file,"utf8")}catch{continue}let c=0,a=0,u=0,h=0,d=!1,f="";for(let $ of l.split(`
4
4
  `)){let g=$.toLowerCase(),w=g.indexOf(e);if(w<0)continue;let y=0;for(;w>=0;)y++,w=g.indexOf(e,w+e.length);c+=y;let L=g.includes('"role":"user"'),P=g.includes('"role":"toolresult"')||g.includes('"role":"tool"');L?a+=y:P?h+=y:u+=y,r.test($)&&(d=!0),f||(f=Z(H($),e))}if(c===0)continue;let O=(a>0?100:0)+(u>0?10:0)+Math.min(h,5)+(d?5:0)+Math.min(c,10)/100;i.push({row:o,matches:c,score:O,snippet:f})}return i.sort((o,l)=>l.score-o.score||l.row.modified-o.row.modified).slice(0,n)}function Q(t){let n=[`# Session ${t.split(/[\\/]/).pop()??t}`,""];for(let s of x(t,"utf8").split(`
@@ -1 +1 @@
1
- import{A,B,C,D,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"./chunk-JC3DY2HZ.js";import"./chunk-7LA2AMZB.js";import"./chunk-UTYFLLSM.js";import"./chunk-CYOHDIPQ.js";import"./chunk-4AQGNUVQ.js";import"./chunk-WOT6VMZA.js";export{g as CATALOG_CACHE_TTL_MS,m as DEFAULT_CONTEXT_WINDOW,a as HOWTOCODE_BASE_URL,b as HOWTOCODE_CONSOLE_URL,l as HOWTOCODE_MODEL_COMPAT,c as HOWTOCODE_PROVIDERS,j as HTTP_IDLE_TIMEOUT_MS,r as UNLIMITED_SENTINEL,w as applyCatalog,x as applyCompat,B as checkAccount,s as checkCreditPools,t as checkUsage,d as configuredProviderIds,y as countNewModels,k as ensureGatewaySettings,C as fetchGatewayPrices,A as findLiveModels,q as isHowtoCodeProvider,h as loadCatalog,o as looksLikeToken,n as maskToken,v as mergeModels,e as newProviderEntry,p as parseModelIds,z as probeModel,D as readProviderKey,f as repairGatewayModels,i as repairModelFacts,u as syncGatewayModelsOnStart};
1
+ import{A,B,C,D,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"./chunk-GEAWXEQG.js";import"./chunk-7LA2AMZB.js";import"./chunk-UTYFLLSM.js";import"./chunk-NFVGCV56.js";import"./chunk-XSUEEWKS.js";import"./chunk-WOT6VMZA.js";export{g as CATALOG_CACHE_TTL_MS,m as DEFAULT_CONTEXT_WINDOW,a as HOWTOCODE_BASE_URL,b as HOWTOCODE_CONSOLE_URL,l as HOWTOCODE_MODEL_COMPAT,c as HOWTOCODE_PROVIDERS,j as HTTP_IDLE_TIMEOUT_MS,r as UNLIMITED_SENTINEL,w as applyCatalog,x as applyCompat,B as checkAccount,s as checkCreditPools,t as checkUsage,d as configuredProviderIds,y as countNewModels,k as ensureGatewaySettings,C as fetchGatewayPrices,A as findLiveModels,q as isHowtoCodeProvider,h as loadCatalog,o as looksLikeToken,n as maskToken,v as mergeModels,e as newProviderEntry,p as parseModelIds,z as probeModel,D as readProviderKey,f as repairGatewayModels,i as repairModelFacts,u as syncGatewayModelsOnStart};
@@ -1,4 +1,4 @@
1
- import{a as v}from"./chunk-7LA2AMZB.js";import{a as w}from"./chunk-UTYFLLSM.js";import{h as M,i as T}from"./chunk-CYOHDIPQ.js";import{existsSync as H,mkdirSync as I,readFileSync as b}from"node:fs";import{join as k}from"node:path";var J="https://models.dev/api.json";var N=["anthropic","openai","google","deepseek","zai","xai","moonshotai","minimax","alibaba","xiaomi","meta","tencent","nvidia","venice","openrouter"];function _(n){return n.toLowerCase().replace(/[^a-z0-9]+/g,"")}function S(n){let e=n.split("/");return _(e[e.length-1]??n)}function q(n){let e=new Map,s=new Map;if(!n||typeof n!="object")return e;let t=n,r=c=>{let o=N.indexOf(c);return o===-1?N.length:o};for(let c of Object.keys(t).sort()){let o=t[c]?.models;if(!(!o||typeof o!="object"))for(let a of Object.keys(o)){let i=o[a],u=Number(i?.limit?.context);if(!Number.isFinite(u)||u<=0)continue;let l=_(a),f=r(c),d=s.get(l);if(d!==void 0&&d<=f)continue;let m=Number(i?.limit?.output);e.set(l,{contextWindow:Math.floor(u),maxTokens:Number.isFinite(m)&&m>0?Math.floor(m):void 0,reasoning:i?.reasoning===!0,vision:Array.isArray(i?.modalities?.input)&&i.modalities.input.includes("image")}),s.set(l,f)}}return e}function A(n,e){let s=_(e);if(!s)return;let t=n.get(s);if(t)return t;let r=S(e);for(let[c,o]of n)if(S(c)===r)return o;for(let[c,o]of n)if(c.endsWith(s)||s.endsWith(c))return o}function R(n){return`${n}/models-dev-cache.json`}function $(n){let e={};for(let[s,t]of n)e[s]=[t.contextWindow,t.maxTokens??0,t.reasoning?1:0,t.vision?1:0];return JSON.stringify(e)}function P(n){let e=new Map,s;try{s=JSON.parse(n)}catch{return e}if(!s||typeof s!="object")return e;for(let[t,r]of Object.entries(s)){if(!Array.isArray(r)||r.length<3)continue;let c=Number(r[0]),o=Number(r[1]);!Number.isFinite(c)||c<=0||e.set(t,{contextWindow:Math.floor(c),maxTokens:Number.isFinite(o)&&o>0?Math.floor(o):void 0,reasoning:r[2]===1||r[2]===!0,vision:r[3]===1||r[3]===!0})}return e}async function U(n){let e=n?.url??J,s=n?.fetchImpl??fetch,t=n?.timeoutMs??2e4,r=new AbortController,c=setTimeout(()=>r.abort(),t);try{let o=await s(e,{signal:r.signal,headers:{Accept:"application/json"}});if(!o.ok)return{ok:!1,message:`the model catalogue answered ${o.status}`};let a=q(await o.json());return a.size===0?{ok:!1,message:"the model catalogue was empty or in an unexpected shape"}:{ok:!0,index:a}}catch(o){return{ok:!1,message:o instanceof Error&&o.name==="AbortError"?`the model catalogue did not answer within ${Math.round(t/1e3)}s`:"could not reach the model catalogue"}}finally{clearTimeout(c)}}var x="https://api.howtofix.id/v1",ce=v,C=["howtocode","howtocode-free"];function ue(n){try{let s=JSON.parse(b(k(n,"models.json"),"utf8")).providers;return!s||typeof s!="object"?new Set:new Set(Object.keys(s))}catch{return new Set}}function le(){return{baseUrl:x,api:"openai-completions",headers:{[M]:T()}}}function de(n){let e=k(n,"models.json"),s;try{s=JSON.parse(b(e,"utf8"))}catch{return 0}let t=s.providers;if(!t||typeof t!="object")return 0;let r=0;for(let c of C){let o=t[c];if(!o||!Array.isArray(o.models))continue;let a=Y(o.models),i={...o.headers??{},[M]:T()},u=o.headers?.[M]!==i[M];a.changed===0&&!u||(o.models=a.models,o.headers=i,r+=a.changed===0?1:a.changed)}if(r===0)return 0;try{w(e,`${JSON.stringify(s,null,2)}
1
+ import{a as v}from"./chunk-7LA2AMZB.js";import{a as w}from"./chunk-UTYFLLSM.js";import{h as M,i as T}from"./chunk-NFVGCV56.js";import{existsSync as H,mkdirSync as I,readFileSync as b}from"node:fs";import{join as k}from"node:path";var J="https://models.dev/api.json";var N=["anthropic","openai","google","deepseek","zai","xai","moonshotai","minimax","alibaba","xiaomi","meta","tencent","nvidia","venice","openrouter"];function _(n){return n.toLowerCase().replace(/[^a-z0-9]+/g,"")}function S(n){let e=n.split("/");return _(e[e.length-1]??n)}function q(n){let e=new Map,s=new Map;if(!n||typeof n!="object")return e;let t=n,r=c=>{let o=N.indexOf(c);return o===-1?N.length:o};for(let c of Object.keys(t).sort()){let o=t[c]?.models;if(!(!o||typeof o!="object"))for(let a of Object.keys(o)){let i=o[a],u=Number(i?.limit?.context);if(!Number.isFinite(u)||u<=0)continue;let l=_(a),f=r(c),d=s.get(l);if(d!==void 0&&d<=f)continue;let m=Number(i?.limit?.output);e.set(l,{contextWindow:Math.floor(u),maxTokens:Number.isFinite(m)&&m>0?Math.floor(m):void 0,reasoning:i?.reasoning===!0,vision:Array.isArray(i?.modalities?.input)&&i.modalities.input.includes("image")}),s.set(l,f)}}return e}function A(n,e){let s=_(e);if(!s)return;let t=n.get(s);if(t)return t;let r=S(e);for(let[c,o]of n)if(S(c)===r)return o;for(let[c,o]of n)if(c.endsWith(s)||s.endsWith(c))return o}function R(n){return`${n}/models-dev-cache.json`}function $(n){let e={};for(let[s,t]of n)e[s]=[t.contextWindow,t.maxTokens??0,t.reasoning?1:0,t.vision?1:0];return JSON.stringify(e)}function P(n){let e=new Map,s;try{s=JSON.parse(n)}catch{return e}if(!s||typeof s!="object")return e;for(let[t,r]of Object.entries(s)){if(!Array.isArray(r)||r.length<3)continue;let c=Number(r[0]),o=Number(r[1]);!Number.isFinite(c)||c<=0||e.set(t,{contextWindow:Math.floor(c),maxTokens:Number.isFinite(o)&&o>0?Math.floor(o):void 0,reasoning:r[2]===1||r[2]===!0,vision:r[3]===1||r[3]===!0})}return e}async function U(n){let e=n?.url??J,s=n?.fetchImpl??fetch,t=n?.timeoutMs??2e4,r=new AbortController,c=setTimeout(()=>r.abort(),t);try{let o=await s(e,{signal:r.signal,headers:{Accept:"application/json"}});if(!o.ok)return{ok:!1,message:`the model catalogue answered ${o.status}`};let a=q(await o.json());return a.size===0?{ok:!1,message:"the model catalogue was empty or in an unexpected shape"}:{ok:!0,index:a}}catch(o){return{ok:!1,message:o instanceof Error&&o.name==="AbortError"?`the model catalogue did not answer within ${Math.round(t/1e3)}s`:"could not reach the model catalogue"}}finally{clearTimeout(c)}}var x="https://api.howtofix.id/v1",ce=v,C=["howtocode","howtocode-free"];function ue(n){try{let s=JSON.parse(b(k(n,"models.json"),"utf8")).providers;return!s||typeof s!="object"?new Set:new Set(Object.keys(s))}catch{return new Set}}function le(){return{baseUrl:x,api:"openai-completions",headers:{[M]:T()}}}function de(n){let e=k(n,"models.json"),s;try{s=JSON.parse(b(e,"utf8"))}catch{return 0}let t=s.providers;if(!t||typeof t!="object")return 0;let r=0;for(let c of C){let o=t[c];if(!o||!Array.isArray(o.models))continue;let a=Y(o.models),i={...o.headers??{},[M]:T()},u=o.headers?.[M]!==i[M];a.changed===0&&!u||(o.models=a.models,o.headers=i,r+=a.changed===0?1:a.changed)}if(r===0)return 0;try{w(e,`${JSON.stringify(s,null,2)}
2
2
  `)}catch{return 0}return r}var G=10080*60*1e3;async function F(n,e){let s=R(n),t=e?.now??Date.now(),r,c=0;try{let i=JSON.parse(b(s,"utf8"));typeof i?.entries=="string"&&(r=P(i.entries),c=Number(i.at)||0)}catch{r=void 0}if(r&&r.size>0&&t-c<G&&!e?.force)return{index:r};let a=await U({fetchImpl:e?.fetchImpl});if(!a.ok)return r&&r.size>0?{index:r,message:a.message}:{index:new Map,message:a.message};try{I(n,{recursive:!0}),w(s,`${JSON.stringify({at:t,entries:$(a.index)})}
3
3
  `)}catch{}return{index:a.index}}async function fe(n,e){let s=k(n,"models.json"),t;try{t=JSON.parse(b(s,"utf8"))}catch{return{changed:0}}let r=t.providers;if(!r||typeof r!="object")return{changed:0};let{index:c,message:o}=await F(n,e);if(c.size===0&&!e?.prices&&!e?.tiers)return{changed:0,message:o};let a=0;for(let i of C){let u=r[i];if(!u||!Array.isArray(u.models))continue;let l=Z(u.models,c,e?.prices,e?.tiers);l.changed!==0&&(u.models=l.models,a+=l.changed)}if(a>0)try{w(s,`${JSON.stringify(t,null,2)}
4
4
  `)}catch{return{changed:0,message:"the models file could not be written"}}return{changed:a,message:o}}var B=3e5;function me(n){let e=k(n,"settings.json"),s={};try{let t=b(e,"utf8"),r=JSON.parse(t);r&&typeof r=="object"&&!Array.isArray(r)&&(s=r)}catch{if(H(e))return!1}if("httpIdleTimeoutMs"in s)return!1;s.httpIdleTimeoutMs=B;try{I(n,{recursive:!0}),w(e,`${JSON.stringify(s,null,2)}
@@ -1 +1 @@
1
- import{a,b,c,d,e,f,g,h,i,j}from"./chunk-CYOHDIPQ.js";import"./chunk-4AQGNUVQ.js";import"./chunk-WOT6VMZA.js";export{h as CLI_CLIENT_HEADER,a as CLI_SIGNING_KEY_ID,i as cliClientHeader,c as cliSignaturePayload,f as cliSigningKeyFingerprint,e as cliSigningKeyMatchesPanel,b as cliSigningPublicKey,d as createNonce,g as describeClient,j as signLoginRequest};
1
+ import{a,b,c,d,e,f,g,h,i,j}from"./chunk-NFVGCV56.js";import"./chunk-XSUEEWKS.js";import"./chunk-WOT6VMZA.js";export{h as CLI_CLIENT_HEADER,a as CLI_SIGNING_KEY_ID,i as cliClientHeader,c as cliSignaturePayload,f as cliSigningKeyFingerprint,e as cliSigningKeyMatchesPanel,b as cliSigningPublicKey,d as createNonce,g as describeClient,j as signLoginRequest};
@@ -1,2 +1,2 @@
1
- import{a as T}from"./chunk-UTYFLLSM.js";import{g as R,j as P}from"./chunk-CYOHDIPQ.js";import{existsSync as z,readFileSync as ye,rmSync as xe}from"node:fs";import{join as ve}from"node:path";import{createHash as q,randomBytes as J}from"node:crypto";import{createServer as ne}from"node:http";import{execFileSync as X}from"node:child_process";import{createHmac as Q}from"node:crypto";import{readFileSync as ee}from"node:fs";import{arch as F,cpus as M,hostname as N,platform as v,userInfo as O}from"node:os";var te="howtocode-cli-hwid-v1";function x(e){try{let t=ee(e,"utf8").trim();return t.length>0?t:void 0}catch{return}}function $(e,t){try{let r=X(e,t,{encoding:"utf8",timeout:3e3,stdio:["ignore","pipe","ignore"]});return r.trim().length>0?r.trim():void 0}catch{return}}function re(){let e=v();if(e==="linux"){let t=x("/etc/machine-id");if(t)return{value:t,source:"machine-id",strong:!0};let r=x("/var/lib/dbus/machine-id");if(r)return{value:r,source:"dbus-machine-id",strong:!0};let o=x("/sys/class/dmi/id/product_uuid");return o?{value:o,source:"dmi-product-uuid",strong:!0}:void 0}if(e==="win32"){let r=$("reg",["query","HKLM\\SOFTWARE\\Microsoft\\Cryptography","/v","MachineGuid"])?.match(/MachineGuid\s+REG_SZ\s+(\S+)/i);return r?.[1]?{value:r[1],source:"windows-machine-guid",strong:!0}:void 0}if(e==="darwin"){let r=$("ioreg",["-rd1","-c","IOPlatformExpertDevice"])?.match(/"IOPlatformUUID"\s*=\s*"([^"]+)"/);return r?.[1]?{value:r[1],source:"platform-uuid",strong:!0}:void 0}}function H(){let e=re(),t=e?.value??[N(),v(),F(),O().username].join("\0"),r=e?.source??"hostname";return{id:Q("sha256",te).update(t).digest("hex").slice(0,32),source:r,strong:e?.strong??!1}}function U(e){return[e.id,e.source,N(),v(),F(),O().username,String(M().length),M()[0]?.model??""]}var _="https://howtofix.id",se=300*1e3,G=3e3,K="/callback";function I(e){return e.toString("base64").replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function oe(){return I(J(32))}function ie(e){return I(q("sha256").update(e).digest())}function ae(){return I(J(16))}var ce="howtocode-cli-",ue="x-howtocode-client",le="cli";function L(e){let t=e??U(H());return ce+q("sha256").update(t.join("\0")).digest("hex").slice(0,32)}function de(){return{"content-type":"application/json",[ue]:le}}var fe=()=>new Promise((e,t)=>{let r=ne();r.once("error",t),r.listen(0,"127.0.0.1",()=>{let{port:o}=r.address();e({port:o,close:()=>r.close(),waitForCode:(n,s)=>new Promise((i,a)=>{let c=(l,f)=>{let h=new URL(l.url??"/","http://127.0.0.1");if(h.pathname!==K){f.writeHead(404).end("not found");return}let y=(V,Z)=>f.writeHead(200,{"content-type":"text/html; charset=utf-8"}).end(`<!doctype html><meta charset="utf-8"><h2>${V}</h2><p>${Z}</p>`),S=h.searchParams.get("error")??"",E=h.searchParams.get("code")??"",Y=h.searchParams.get("state")??"";if(S){y("Sign-in was refused","You can close this tab."),u(new Error(`the browser reported: ${S}`));return}if(!E||Y!==n){y("This callback did not belong to the login","You can close this tab."),u(new Error("the callback carried the wrong state"));return}y("Signed in","You can close this tab and go back to HowToCode."),u(void 0,E)},u=(l,f)=>{r.off("request",c),s?.removeEventListener("abort",g),l?a(l):i(f)},g=()=>u(new Error("cancelled"));s?.addEventListener("abort",g,{once:!0}),r.on("request",c)})})})});function k(e,t){e.onProgress?.(t)}async function p(e,t,r,o){let n=await e(t,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(r),signal:o}),s={};try{s=await n.json()}catch{}let i=Number(n.headers?.get?.("retry-after"));return{status:n.status,body:s,retryAfterSeconds:Number.isFinite(i)&&i>0?i:void 0}}function d(...e){for(let t of e)if(typeof t=="string"&&t.trim()!=="")return t.trim()}function j(...e){for(let t of e)if(typeof t=="number"&&Number.isFinite(t))return t;return 0}function me(e){try{let t=new URL(e).searchParams.get("code");return t&&t.trim()!==""?t.trim():void 0}catch{return}}async function ge(e,t,r){let o=await e(t,{headers:de(),signal:r}),n={};try{n=await o.json()}catch{}let s=Number(o.headers?.get?.("retry-after"));return{status:o.status,body:n,retryAfterSeconds:Number.isFinite(s)&&s>0?s:void 0}}function A(e){let t=e.data,r=[e.token,e.api_key,e.apiKey,e.key,t?.token,t?.api_key,t?.apiKey,t?.key];for(let o of r)if(typeof o=="string"&&o.trim().startsWith("sk-"))return o.trim()}function pe(e){let t=e.data,r=d(e.token,t?.token),o=d(e.refresh_token,t?.refresh_token),n=d(e.device_id,t?.device_id);if(!r||!o||!n)return;let s=j(e.access_expires_at,t?.access_expires_at),i=j(e.refresh_expires_at,t?.refresh_expires_at);return{accessToken:r,accessExpiresAt:s,refreshToken:o,deviceId:n,refreshExpiresAt:i}}function m(e,t){let r=e.message??e.error;return typeof r=="string"&&r.trim()?r.trim():t}async function He(e){let t=e.fetchImpl??fetch,r=(e.panelUrl??_).replace(/\/+$/,""),o=e.timeoutMs??se,n={...e,panel:r,fetchImpl:t,timeoutMs:o},s=await ke(n);if(s.ok||s.terminal)return s.result;let i=await he(n);if(i.ok||i.terminal)return i.result;let a=await we(n);return a.ok?a:{ok:!1,message:`${s.result.ok?"":s.result.message}; ${i.result.ok?"":i.result.message}; ${a.message}. howtofix.id does not offer a browser login a local client can complete yet \u2014 run /connect and paste a token from ${r}/keys instead.`}}async function he(e){let t=oe(),r=ae(),o;try{o=await(e.loopback??fe)();let n=`http://127.0.0.1:${o.port}${K}`,s=await p(e.fetchImpl,`${e.panel}/api/oauth/device/start`,{redirect_uri:n,code_challenge:ie(t),code_challenge_method:"S256",state:r},e.signal);if(s.status===404)return{ok:!1,terminal:!1,result:{ok:!1,message:"the panel has no loopback login endpoint"}};if(s.status>=400)return{ok:!1,terminal:!1,result:{ok:!1,message:m(s.body,`the panel refused the login (${s.status})`)}};let i=typeof s.body.authorize_url=="string"?s.body.authorize_url:"";if(!i)return{ok:!1,terminal:!1,result:{ok:!1,message:"the panel did not say where to send the browser"}};k(e,{kind:"browser",url:i});let a=await be(o.waitForCode(r,e.signal),e.timeoutMs),c=await p(e.fetchImpl,`${e.panel}/api/oauth/device/token`,{flow_token:s.body.flow_token,code:a,code_verifier:t},e.signal);if(c.status>=400)return{ok:!1,terminal:!0,result:{ok:!1,message:m(c.body,`the panel refused the exchange (${c.status})`)}};let u=A(c.body);return u?{ok:!0,result:{ok:!0,token:u}}:{ok:!1,terminal:!0,result:{ok:!1,message:"the panel did not return an API key"}}}catch(n){let s=n instanceof Error?n.message:String(n);return{ok:!1,terminal:s==="cancelled",result:{ok:!1,message:s}}}finally{o?.close()}}async function ke(e){let t=e.fingerprintId??L(),r=e.clientInfo??R(),o=P(t,r);try{let n=await p(e.fetchImpl,`${e.panel}/api/auth/cli/code`,{fingerprintId:t,clientInfo:r,...o},e.signal);if(n.status===404)return{ok:!1,terminal:!1,result:{ok:!1,message:"the panel has no CLI login endpoint"}};if(n.status===401)return{ok:!1,terminal:!1,result:{ok:!1,message:"the panel did not recognise this build as the HowToCode CLI \u2014 update it with `npm install -g howtocode@latest`"}};if(n.status===429)return{ok:!1,terminal:!0,result:{ok:!1,message:`too many sign-in attempts from this machine right now.${n.retryAfterSeconds?` Try again in ${Math.ceil(n.retryAfterSeconds/60)} minute(s).`:""}`}};if(n.status>=400)return{ok:!1,terminal:!1,result:{ok:!1,message:m(n.body,`the panel refused the login (${n.status})`)}};let s=n.body.data??{},i=d(n.body.login_url,s.login_url),a=d(n.body.code,s.code)??(i?me(i):void 0),c=d(n.body.secret,s.secret);return!i||!a?{ok:!1,terminal:!1,result:{ok:!1,message:"the panel did not return a login URL"}}:c?(k(e,{kind:"browser",url:i}),await D(e,a,c)):(k(e,{kind:"browser",url:i}),await D(e,a,void 0))}catch(n){let s=n instanceof Error?n.message:String(n);return{ok:!1,terminal:s==="cancelled",result:{ok:!1,message:s}}}}async function D(e,t,r){let o=e.pollIntervalMs??G,n=Date.now()+e.timeoutMs;for(;Date.now()<n;){await w(o,e.signal);let s=new URLSearchParams(r?{code:t,secret:r}:{code:t});s.set("capability","device-refresh");let i=await ge(e.fetchImpl,`${e.panel}/api/auth/cli/status?${s}`,e.signal);if(i.status===404)return{ok:!1,terminal:!1,result:{ok:!1,message:"the panel has no CLI login status endpoint"}};if(i.status===403)return{ok:!1,terminal:!0,result:{ok:!1,message:"the panel rejected this poll \u2014 run /connect again"}};if(i.status===429){let u=Math.min(Math.max(i.retryAfterSeconds??5,1)*1e3,3e4);await w(u,e.signal);continue}let a=A(i.body);if(a)return{ok:!0,result:{ok:!0,token:a,credential:pe(i.body)}};if(d(i.body.data?.status,i.body.status)==="expired")return{ok:!1,terminal:!0,result:{ok:!1,message:"the sign-in link expired before it was approved"}};if(i.status>=400)return{ok:!1,terminal:!0,result:{ok:!1,message:m(i.body,`the panel refused the poll (${i.status})`)}}}return{ok:!1,terminal:!0,result:{ok:!1,message:"the sign-in was not approved in time"}}}async function we(e){let t=e.pollIntervalMs??G;try{let r=await p(e.fetchImpl,`${e.panel}/api/oauth/device`,{},e.signal);if(r.status===404)return{ok:!1,message:"the panel has no device-code endpoint"};if(r.status>=400)return{ok:!1,message:m(r.body,`the panel refused the request (${r.status})`)};let o=typeof r.body.device_code=="string"?r.body.device_code:"",n=typeof r.body.user_code=="string"?r.body.user_code:"",s=typeof r.body.verification_uri=="string"?r.body.verification_uri:`${e.panel}/oauth/device`;if(!o||!n)return{ok:!1,message:"the panel did not return a code to show"};k(e,{kind:"code",code:n,url:s});let i=Date.now()+e.timeoutMs;for(;Date.now()<i;){await w(t,e.signal);let a=await p(e.fetchImpl,`${e.panel}/api/oauth/device/poll`,{device_code:o},e.signal);if(a.status===404)return{ok:!1,message:"the panel has no device-code poll endpoint"};let c=typeof a.body.status=="string"?a.body.status:"";if(c==="pending")continue;if(c==="slow_down"){await w(t,e.signal);continue}if(c==="denied")return{ok:!1,message:"the sign-in was refused in the browser"};if(c==="expired")return{ok:!1,message:"the code expired; run /connect again"};let u=A(a.body);if(u)return{ok:!0,token:u};if(a.status>=400)return{ok:!1,message:m(a.body,`the panel refused the poll (${a.status})`)}}return{ok:!1,message:"the code was not approved in time"}}catch(r){return{ok:!1,message:r instanceof Error?r.message:String(r)}}}function be(e,t){return new Promise((r,o)=>{let n=setTimeout(()=>o(new Error("the sign-in was not finished in time")),t);e.then(s=>{clearTimeout(n),r(s)},s=>{clearTimeout(n),o(s)})})}function w(e,t){return new Promise((r,o)=>{let n=setTimeout(r,e);t?.addEventListener("abort",()=>{clearTimeout(n),o(new Error("cancelled"))},{once:!0})})}function b(e){return ve(e,"cli-credentials.json")}var _e=300*1e3;function Ie(e,t=Date.now()){return e.accessToken?!Number.isFinite(e.accessExpiresAt)||e.accessExpiresAt<=0?!0:e.accessExpiresAt*1e3-_e>t:!1}function Le(e,t=Date.now()){return!e.refreshToken||!e.deviceId?!1:!Number.isFinite(e.refreshExpiresAt)||e.refreshExpiresAt<=0?!0:e.refreshExpiresAt*1e3>t}function Ge(e){let t=b(e);if(!z(t))return;let r;try{r=JSON.parse(ye(t,"utf8"))}catch{return}if(!r||typeof r!="object"||Array.isArray(r))return;let o=r,n=typeof o.accessToken=="string"?o.accessToken.trim():"",s=typeof o.refreshToken=="string"?o.refreshToken.trim():"",i=typeof o.deviceId=="string"?o.deviceId.trim():"";if(!(!n||!s||!i))return{accessToken:n,accessExpiresAt:W(o.accessExpiresAt),refreshToken:s,deviceId:i,refreshExpiresAt:W(o.refreshExpiresAt)}}function Ae(e,t){try{return T(b(e),`${JSON.stringify(t,null,2)}
1
+ import{a as T}from"./chunk-UTYFLLSM.js";import{g as R,j as P}from"./chunk-NFVGCV56.js";import{existsSync as z,readFileSync as ye,rmSync as xe}from"node:fs";import{join as ve}from"node:path";import{createHash as q,randomBytes as J}from"node:crypto";import{createServer as ne}from"node:http";import{execFileSync as X}from"node:child_process";import{createHmac as Q}from"node:crypto";import{readFileSync as ee}from"node:fs";import{arch as F,cpus as M,hostname as N,platform as v,userInfo as O}from"node:os";var te="howtocode-cli-hwid-v1";function x(e){try{let t=ee(e,"utf8").trim();return t.length>0?t:void 0}catch{return}}function $(e,t){try{let r=X(e,t,{encoding:"utf8",timeout:3e3,stdio:["ignore","pipe","ignore"]});return r.trim().length>0?r.trim():void 0}catch{return}}function re(){let e=v();if(e==="linux"){let t=x("/etc/machine-id");if(t)return{value:t,source:"machine-id",strong:!0};let r=x("/var/lib/dbus/machine-id");if(r)return{value:r,source:"dbus-machine-id",strong:!0};let o=x("/sys/class/dmi/id/product_uuid");return o?{value:o,source:"dmi-product-uuid",strong:!0}:void 0}if(e==="win32"){let r=$("reg",["query","HKLM\\SOFTWARE\\Microsoft\\Cryptography","/v","MachineGuid"])?.match(/MachineGuid\s+REG_SZ\s+(\S+)/i);return r?.[1]?{value:r[1],source:"windows-machine-guid",strong:!0}:void 0}if(e==="darwin"){let r=$("ioreg",["-rd1","-c","IOPlatformExpertDevice"])?.match(/"IOPlatformUUID"\s*=\s*"([^"]+)"/);return r?.[1]?{value:r[1],source:"platform-uuid",strong:!0}:void 0}}function H(){let e=re(),t=e?.value??[N(),v(),F(),O().username].join("\0"),r=e?.source??"hostname";return{id:Q("sha256",te).update(t).digest("hex").slice(0,32),source:r,strong:e?.strong??!1}}function U(e){return[e.id,e.source,N(),v(),F(),O().username,String(M().length),M()[0]?.model??""]}var _="https://howtofix.id",se=300*1e3,G=3e3,K="/callback";function I(e){return e.toString("base64").replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function oe(){return I(J(32))}function ie(e){return I(q("sha256").update(e).digest())}function ae(){return I(J(16))}var ce="howtocode-cli-",ue="x-howtocode-client",le="cli";function L(e){let t=e??U(H());return ce+q("sha256").update(t.join("\0")).digest("hex").slice(0,32)}function de(){return{"content-type":"application/json",[ue]:le}}var fe=()=>new Promise((e,t)=>{let r=ne();r.once("error",t),r.listen(0,"127.0.0.1",()=>{let{port:o}=r.address();e({port:o,close:()=>r.close(),waitForCode:(n,s)=>new Promise((i,a)=>{let c=(l,f)=>{let h=new URL(l.url??"/","http://127.0.0.1");if(h.pathname!==K){f.writeHead(404).end("not found");return}let y=(V,Z)=>f.writeHead(200,{"content-type":"text/html; charset=utf-8"}).end(`<!doctype html><meta charset="utf-8"><h2>${V}</h2><p>${Z}</p>`),S=h.searchParams.get("error")??"",E=h.searchParams.get("code")??"",Y=h.searchParams.get("state")??"";if(S){y("Sign-in was refused","You can close this tab."),u(new Error(`the browser reported: ${S}`));return}if(!E||Y!==n){y("This callback did not belong to the login","You can close this tab."),u(new Error("the callback carried the wrong state"));return}y("Signed in","You can close this tab and go back to HowToCode."),u(void 0,E)},u=(l,f)=>{r.off("request",c),s?.removeEventListener("abort",g),l?a(l):i(f)},g=()=>u(new Error("cancelled"));s?.addEventListener("abort",g,{once:!0}),r.on("request",c)})})})});function k(e,t){e.onProgress?.(t)}async function p(e,t,r,o){let n=await e(t,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(r),signal:o}),s={};try{s=await n.json()}catch{}let i=Number(n.headers?.get?.("retry-after"));return{status:n.status,body:s,retryAfterSeconds:Number.isFinite(i)&&i>0?i:void 0}}function d(...e){for(let t of e)if(typeof t=="string"&&t.trim()!=="")return t.trim()}function j(...e){for(let t of e)if(typeof t=="number"&&Number.isFinite(t))return t;return 0}function me(e){try{let t=new URL(e).searchParams.get("code");return t&&t.trim()!==""?t.trim():void 0}catch{return}}async function ge(e,t,r){let o=await e(t,{headers:de(),signal:r}),n={};try{n=await o.json()}catch{}let s=Number(o.headers?.get?.("retry-after"));return{status:o.status,body:n,retryAfterSeconds:Number.isFinite(s)&&s>0?s:void 0}}function A(e){let t=e.data,r=[e.token,e.api_key,e.apiKey,e.key,t?.token,t?.api_key,t?.apiKey,t?.key];for(let o of r)if(typeof o=="string"&&o.trim().startsWith("sk-"))return o.trim()}function pe(e){let t=e.data,r=d(e.token,t?.token),o=d(e.refresh_token,t?.refresh_token),n=d(e.device_id,t?.device_id);if(!r||!o||!n)return;let s=j(e.access_expires_at,t?.access_expires_at),i=j(e.refresh_expires_at,t?.refresh_expires_at);return{accessToken:r,accessExpiresAt:s,refreshToken:o,deviceId:n,refreshExpiresAt:i}}function m(e,t){let r=e.message??e.error;return typeof r=="string"&&r.trim()?r.trim():t}async function He(e){let t=e.fetchImpl??fetch,r=(e.panelUrl??_).replace(/\/+$/,""),o=e.timeoutMs??se,n={...e,panel:r,fetchImpl:t,timeoutMs:o},s=await ke(n);if(s.ok||s.terminal)return s.result;let i=await he(n);if(i.ok||i.terminal)return i.result;let a=await we(n);return a.ok?a:{ok:!1,message:`${s.result.ok?"":s.result.message}; ${i.result.ok?"":i.result.message}; ${a.message}. howtofix.id does not offer a browser login a local client can complete yet \u2014 run /connect and paste a token from ${r}/keys instead.`}}async function he(e){let t=oe(),r=ae(),o;try{o=await(e.loopback??fe)();let n=`http://127.0.0.1:${o.port}${K}`,s=await p(e.fetchImpl,`${e.panel}/api/oauth/device/start`,{redirect_uri:n,code_challenge:ie(t),code_challenge_method:"S256",state:r},e.signal);if(s.status===404)return{ok:!1,terminal:!1,result:{ok:!1,message:"the panel has no loopback login endpoint"}};if(s.status>=400)return{ok:!1,terminal:!1,result:{ok:!1,message:m(s.body,`the panel refused the login (${s.status})`)}};let i=typeof s.body.authorize_url=="string"?s.body.authorize_url:"";if(!i)return{ok:!1,terminal:!1,result:{ok:!1,message:"the panel did not say where to send the browser"}};k(e,{kind:"browser",url:i});let a=await be(o.waitForCode(r,e.signal),e.timeoutMs),c=await p(e.fetchImpl,`${e.panel}/api/oauth/device/token`,{flow_token:s.body.flow_token,code:a,code_verifier:t},e.signal);if(c.status>=400)return{ok:!1,terminal:!0,result:{ok:!1,message:m(c.body,`the panel refused the exchange (${c.status})`)}};let u=A(c.body);return u?{ok:!0,result:{ok:!0,token:u}}:{ok:!1,terminal:!0,result:{ok:!1,message:"the panel did not return an API key"}}}catch(n){let s=n instanceof Error?n.message:String(n);return{ok:!1,terminal:s==="cancelled",result:{ok:!1,message:s}}}finally{o?.close()}}async function ke(e){let t=e.fingerprintId??L(),r=e.clientInfo??R(),o=P(t,r);try{let n=await p(e.fetchImpl,`${e.panel}/api/auth/cli/code`,{fingerprintId:t,clientInfo:r,...o},e.signal);if(n.status===404)return{ok:!1,terminal:!1,result:{ok:!1,message:"the panel has no CLI login endpoint"}};if(n.status===401)return{ok:!1,terminal:!1,result:{ok:!1,message:"the panel did not recognise this build as the HowToCode CLI \u2014 update it with `npm install -g howtocode@latest`"}};if(n.status===429)return{ok:!1,terminal:!0,result:{ok:!1,message:`too many sign-in attempts from this machine right now.${n.retryAfterSeconds?` Try again in ${Math.ceil(n.retryAfterSeconds/60)} minute(s).`:""}`}};if(n.status>=400)return{ok:!1,terminal:!1,result:{ok:!1,message:m(n.body,`the panel refused the login (${n.status})`)}};let s=n.body.data??{},i=d(n.body.login_url,s.login_url),a=d(n.body.code,s.code)??(i?me(i):void 0),c=d(n.body.secret,s.secret);return!i||!a?{ok:!1,terminal:!1,result:{ok:!1,message:"the panel did not return a login URL"}}:c?(k(e,{kind:"browser",url:i}),await D(e,a,c)):(k(e,{kind:"browser",url:i}),await D(e,a,void 0))}catch(n){let s=n instanceof Error?n.message:String(n);return{ok:!1,terminal:s==="cancelled",result:{ok:!1,message:s}}}}async function D(e,t,r){let o=e.pollIntervalMs??G,n=Date.now()+e.timeoutMs;for(;Date.now()<n;){await w(o,e.signal);let s=new URLSearchParams(r?{code:t,secret:r}:{code:t});s.set("capability","device-refresh");let i=await ge(e.fetchImpl,`${e.panel}/api/auth/cli/status?${s}`,e.signal);if(i.status===404)return{ok:!1,terminal:!1,result:{ok:!1,message:"the panel has no CLI login status endpoint"}};if(i.status===403)return{ok:!1,terminal:!0,result:{ok:!1,message:"the panel rejected this poll \u2014 run /connect again"}};if(i.status===429){let u=Math.min(Math.max(i.retryAfterSeconds??5,1)*1e3,3e4);await w(u,e.signal);continue}let a=A(i.body);if(a)return{ok:!0,result:{ok:!0,token:a,credential:pe(i.body)}};if(d(i.body.data?.status,i.body.status)==="expired")return{ok:!1,terminal:!0,result:{ok:!1,message:"the sign-in link expired before it was approved"}};if(i.status>=400)return{ok:!1,terminal:!0,result:{ok:!1,message:m(i.body,`the panel refused the poll (${i.status})`)}}}return{ok:!1,terminal:!0,result:{ok:!1,message:"the sign-in was not approved in time"}}}async function we(e){let t=e.pollIntervalMs??G;try{let r=await p(e.fetchImpl,`${e.panel}/api/oauth/device`,{},e.signal);if(r.status===404)return{ok:!1,message:"the panel has no device-code endpoint"};if(r.status>=400)return{ok:!1,message:m(r.body,`the panel refused the request (${r.status})`)};let o=typeof r.body.device_code=="string"?r.body.device_code:"",n=typeof r.body.user_code=="string"?r.body.user_code:"",s=typeof r.body.verification_uri=="string"?r.body.verification_uri:`${e.panel}/oauth/device`;if(!o||!n)return{ok:!1,message:"the panel did not return a code to show"};k(e,{kind:"code",code:n,url:s});let i=Date.now()+e.timeoutMs;for(;Date.now()<i;){await w(t,e.signal);let a=await p(e.fetchImpl,`${e.panel}/api/oauth/device/poll`,{device_code:o},e.signal);if(a.status===404)return{ok:!1,message:"the panel has no device-code poll endpoint"};let c=typeof a.body.status=="string"?a.body.status:"";if(c==="pending")continue;if(c==="slow_down"){await w(t,e.signal);continue}if(c==="denied")return{ok:!1,message:"the sign-in was refused in the browser"};if(c==="expired")return{ok:!1,message:"the code expired; run /connect again"};let u=A(a.body);if(u)return{ok:!0,token:u};if(a.status>=400)return{ok:!1,message:m(a.body,`the panel refused the poll (${a.status})`)}}return{ok:!1,message:"the code was not approved in time"}}catch(r){return{ok:!1,message:r instanceof Error?r.message:String(r)}}}function be(e,t){return new Promise((r,o)=>{let n=setTimeout(()=>o(new Error("the sign-in was not finished in time")),t);e.then(s=>{clearTimeout(n),r(s)},s=>{clearTimeout(n),o(s)})})}function w(e,t){return new Promise((r,o)=>{let n=setTimeout(r,e);t?.addEventListener("abort",()=>{clearTimeout(n),o(new Error("cancelled"))},{once:!0})})}function b(e){return ve(e,"cli-credentials.json")}var _e=300*1e3;function Ie(e,t=Date.now()){return e.accessToken?!Number.isFinite(e.accessExpiresAt)||e.accessExpiresAt<=0?!0:e.accessExpiresAt*1e3-_e>t:!1}function Le(e,t=Date.now()){return!e.refreshToken||!e.deviceId?!1:!Number.isFinite(e.refreshExpiresAt)||e.refreshExpiresAt<=0?!0:e.refreshExpiresAt*1e3>t}function Ge(e){let t=b(e);if(!z(t))return;let r;try{r=JSON.parse(ye(t,"utf8"))}catch{return}if(!r||typeof r!="object"||Array.isArray(r))return;let o=r,n=typeof o.accessToken=="string"?o.accessToken.trim():"",s=typeof o.refreshToken=="string"?o.refreshToken.trim():"",i=typeof o.deviceId=="string"?o.deviceId.trim():"";if(!(!n||!s||!i))return{accessToken:n,accessExpiresAt:W(o.accessExpiresAt),refreshToken:s,deviceId:i,refreshExpiresAt:W(o.refreshExpiresAt)}}function Ae(e,t){try{return T(b(e),`${JSON.stringify(t,null,2)}
2
2
  `,{mode:384}),!0}catch{return!1}}function Ce(e){try{let t=b(e);z(t)&&xe(t,{force:!0})}catch{}}function W(e){return typeof e=="number"&&Number.isFinite(e)?e:0}async function Se(e,t){let r=(t?.panelUrl??_).replace(/\/+$/,""),o=t?.fetchImpl??fetch,n=t?.timeoutMs??15e3,s=new AbortController,i=setTimeout(()=>s.abort(),n);try{let a=await o(`${r}/api/auth/cli/refresh`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({device_id:e.deviceId,refresh_token:e.refreshToken,fingerprint_id:L()}),signal:s.signal}),c=await a.json().catch(()=>({}));if(a.status===401||a.status===403)return{ok:!1,terminal:!0,message:"this sign-in is no longer valid; run /connect to sign in again"};if(!a.ok)return{ok:!1,terminal:!1,message:`the panel refused the renewal (${a.status})`};let u=c.data??{},g=C(c.token,u.token),l=C(c.refresh_token,u.refresh_token),f=C(c.device_id,u.device_id)??e.deviceId;return!g||!l?{ok:!1,terminal:!1,message:"the panel did not return a renewed credential"}:{ok:!0,terminal:!1,credential:{accessToken:g,accessExpiresAt:B(c.access_expires_at,u.access_expires_at),refreshToken:l,deviceId:f,refreshExpiresAt:B(c.refresh_expires_at,u.refresh_expires_at)}}}catch(a){return{ok:!1,terminal:!1,message:a instanceof Error&&a.name==="AbortError"?`the panel did not answer within ${Math.round(n/1e3)}s`:"could not reach the panel"}}finally{clearTimeout(i)}}function C(...e){for(let t of e)if(typeof t=="string"&&t.trim())return t.trim()}function B(...e){for(let t of e)if(typeof t=="number"&&Number.isFinite(t))return t;return 0}async function Ke(e,t,r){let o=r?.now??Date.now();if(Ie(t,o)||!Le(t,o))return{credential:t,renewed:!1,terminal:!1};let n=await Se(t,r);if(!n.ok||!n.credential)return n.terminal&&Ce(e),{credential:t,renewed:!1,terminal:n.terminal,message:n.message};let s=Ae(e,n.credential);return{credential:n.credential,renewed:!0,terminal:!1,message:s?void 0:`the renewed sign-in could not be saved to ${b(e)}`}}export{H as a,_ as b,He as c,b as d,_e as e,Ie as f,Le as g,Ge as h,Ae as i,Ce as j,Se as k,Ke as l};
@@ -1 +1 @@
1
- import{a,b,c}from"./chunk-3YSNDQVR.js";import"./chunk-ABDZXFNM.js";import"./chunk-UTYFLLSM.js";import"./chunk-WOT6VMZA.js";export{c as formatSkillList,b as skillInvocation,a as skillSearchPaths};
1
+ import{a,b,c}from"./chunk-YFJKKWIX.js";import"./chunk-465RG5I6.js";import"./chunk-UTYFLLSM.js";import"./chunk-WOT6VMZA.js";export{c as formatSkillList,b as skillInvocation,a as skillSearchPaths};
@@ -1,2 +1,2 @@
1
- import{b as o}from"./chunk-4AQGNUVQ.js";import{createPrivateKey as p,createPublicKey as f,createHash as l,randomBytes as d,sign as y}from"node:crypto";import{arch as c,cpus as m,hostname as I,platform as s}from"node:os";var a="hf-cli-1",C="MC4CAQAwBQYDK2VwBCIEIDmKoNgInS7oDpncee1d1+Mnci1R/q4aE5xxHeCKq4Dc",x="howtocode-cli-auth-v1",i;function u(){return i||(i=p({key:Buffer.from(C,"base64"),format:"der",type:"pkcs8"})),i}function g(){return f(u())}function K(t,e,n,r){return Buffer.from([x,t,e,n,r].join(`
1
+ import{b as o}from"./chunk-XSUEEWKS.js";import{createPrivateKey as p,createPublicKey as f,createHash as l,randomBytes as d,sign as y}from"node:crypto";import{arch as c,cpus as m,hostname as I,platform as s}from"node:os";var a="hf-cli-1",C="MC4CAQAwBQYDK2VwBCIEIDmKoNgInS7oDpncee1d1+Mnci1R/q4aE5xxHeCKq4Dc",x="howtocode-cli-auth-v1",i;function u(){return i||(i=p({key:Buffer.from(C,"base64"),format:"der",type:"pkcs8"})),i}function g(){return f(u())}function K(t,e,n,r){return Buffer.from([x,t,e,n,r].join(`
2
2
  `),"utf8")}function h(){return d(16).toString("hex")}var E="tQ91uspGl0sw5Y8x+soLYnFNX6a9vEzSzCuuvalzdKk=";function P(){let t=g().export({format:"der",type:"spki"});return t.subarray(t.length-32).toString("base64")===E}function N(){let t=g().export({format:"der",type:"spki"});return l("sha256").update(t).digest("hex").slice(0,16)}function $(){let e=(m()[0]?.model??"").replace(/\s+/g," ").trim(),n=I(),r=e?`${n} (${s()}/${c()}, ${e})`:`${n} (${s()}/${c()})`;return`CLI (${o}, ${r})`}var k="X-HowToCode-Client";function A(){return`CLI (${o})`}function B(t,e){let n=h(),r=y(null,K(a,t,e,n),u());return{keyId:a,nonce:n,signature:r.toString("base64")}}export{a,g as b,K as c,h as d,P as e,N as f,$ as g,k as h,A as i,B as j};
@@ -1 +1 @@
1
- import{H as a,I as b,J as c,K as d,L as e,M as f,N as g,O as h,P as i,Q as j}from"./chunk-ABDZXFNM.js";import"./chunk-UTYFLLSM.js";import"./chunk-WOT6VMZA.js";export{e as AGENTS_STORE_DIR,a as AGENT_DIR,j as IMAGES_DIR,g as REACHABLE_CACHE_PATH,f as USAGE_CACHE_PATH,b as USER_SKILLS_DIR,h as WORKFLOWS_DIR,d as additionalSkillPaths,i as pinAgentDir,c as projectSkillsDir};
1
+ import{H as a,I as b,J as c,K as d,L as e,M as f,N as g,O as h,P as i,Q as j}from"./chunk-465RG5I6.js";import"./chunk-UTYFLLSM.js";import"./chunk-WOT6VMZA.js";export{e as AGENTS_STORE_DIR,a as AGENT_DIR,j as IMAGES_DIR,g as REACHABLE_CACHE_PATH,f as USAGE_CACHE_PATH,b as USER_SKILLS_DIR,h as WORKFLOWS_DIR,d as additionalSkillPaths,i as pinAgentDir,c as projectSkillsDir};
@@ -1,4 +1,4 @@
1
- import{$a as us,A as _o,Aa as zo,Ba as Yo,Ca as Jo,D as Mt,Da as Xo,E as Lo,Ea as Zo,G as Oo,Ga as de,Ha as E,Ia as J,J as No,Ja as A,K as Fo,Ka as Qo,L as Rt,La as es,M as jo,Ma as ts,N as Do,Na as ns,O as Wo,Oa as Kn,P as Dn,Pa as rs,Qa as is,Sa as Gn,Ta as os,Va as ss,X as Wn,Xa as as,Ya as ls,Z as Un,Za as cs,_a as ds,aa as Qe,ab as fs,bb as ms,c as So,e as Co,g as Ao,h as To,ha as Uo,ia as et,ka as It,n as Mo,oa as Bo,pa as Ko,ra as Go,sa as Ho,ta as Vo,v as Ro,wa as qo,x as Io,z as jn,za as Bn}from"./chunk-RU6VPYMJ.js";import{b as ps,c as gs}from"./chunk-3YSNDQVR.js";import{b as Ee,c as Ze,e as Eo,f as Et,g as Po,h as Pt}from"./chunk-27TRKD65.js";import{A as io,B as St,C as oo,b as Rn,c as ye,d as zi,e as Yi,h as Ji,n as In,o as Xi,q as oe,s as Zi,t as Ie,v as Qi,w as eo,x as to,y as no,z as ro}from"./chunk-JC3DY2HZ.js";import{a as so,b as ao,c as lo,d as co,f as uo,g as fo,h as mo,i as po,l as go}from"./chunk-NQNMEZEO.js";import{a as Ct,b as _n,c as Ln,d as ho,e as At}from"./chunk-3FYCFLNK.js";import{u as bo}from"./chunk-SDO33XPR.js";import{a as wo}from"./chunk-ORJ2QZBG.js";import{a as yo,c as Tt,d as On,j as ko,k as $o,l as vo,n as Nn,o as Fn,p as xo}from"./chunk-SVONBXW3.js";import{a as Pn,b as Mn,c as Di,d as Wi}from"./chunk-EZNNALD3.js";import{b as xt}from"./chunk-7LA2AMZB.js";import{A as Li,B as $t,C as vt,D as Oi,E as Sn,F as Cn,G as Ni,H as R,M as Xe,N as An,O as Fi,Q as ji,c as vn,d as wt,g as yt,i as xi,j as Si,k as Ci,l as Ai,m as kt,n as Ti,o as xn,p as Ei,s as se,t as Pi,u as Mi,x as Ri,y as Ii,z as _i}from"./chunk-ABDZXFNM.js";import{a as ie}from"./chunk-UTYFLLSM.js";import{j as Tn,k as En}from"./chunk-MVVEYKN6.js";import{b as Ui,c as Bi,d as Ki,e as Gi,f as Hi}from"./chunk-TUXY64DT.js";import{h as Vi,i as qi}from"./chunk-CYOHDIPQ.js";import{a as $n,b as bt,e as vi}from"./chunk-4AQGNUVQ.js";import"./chunk-WOT6VMZA.js";import{execFile as ud}from"node:child_process";import{promisify as fd}from"node:util";import{appendFileSync as md,existsSync as Vt,mkdirSync as yr,readFileSync as qt,rmSync as pd,statSync as za,writeFileSync as kr}from"node:fs";import{basename as gd,dirname as hd,join as me,resolve as bd}from"node:path";function hs(e){if(e==="")return!0;let t=/^\x1b\[(\d+);(\d+)u$/.exec(e);if(t&&Number(t[1])===99&&(Number(t[2])&5)!==0)return!0;let n=/^\x1b\[27;(\d+);(\d+)~$/.exec(e);return!!(n&&Number(n[2])===99&&(Number(n[1])&5)!==0)}function bs(e){let t=!1;process.on("SIGINT",()=>{t||(t=!0,e())})}function Cl(e){if(!e||typeof e!="object")return;let t=e;if(!(typeof t.input!="number"&&typeof t.cacheRead!="number"&&typeof t.cacheWrite!="number"))return t}function Al(e){let t=e?.input??0,n=e?.cacheRead??0,i=e?.cacheWrite??0;return{input:t,cacheRead:n,cacheWrite:i,prompt:t+n+i}}function Tl(e){if(typeof e!="string")return null;let t=Date.parse(e);return Number.isNaN(t)?null:t}function El(e){if(!e||typeof e!="object")return;let t=e,i=(t.message&&typeof t.message=="object"?t.message:void 0)??t,o=Cl(i.usage);if(!o)return;let u=typeof i.provider=="string"?i.provider:"",a=typeof i.model=="string"?i.model:"";return{usage:o,model:[u,a].filter(Boolean).join("/")}}function ws(e){let t=0,n=0,i=[],o=0,u=null;for(let g of e){let b=El(g);if(!b)continue;let{input:k,cacheRead:C,cacheWrite:_,prompt:O}=Al(b.usage);if(O===0)continue;t+=C,n+=k+_;let F=Tl(g.timestamp),W=u,G=W?W.at:null;if(W!==null&&C===0&&k>=1e3){let Q=F!==null&&G!==null?Math.max(0,F-G):0;i.push({missedTokens:k,idleMs:Q,modelChanged:b.model!==""&&W.model!==""&&b.model!==W.model}),o+=k}u={prompt:O,at:F??G??null,model:b.model}}let a=t+n;return{cachedTokens:t,billedTokens:n,hitRate:a>0?t/a*100:null,misses:i,missedTokens:o}}function ys(e){return e.modelChanged?"model changed, so its cache had to be built":e.idleMs>=3e5?`cache expired after ${Math.round(e.idleMs/1e3)}s idle`:e.idleMs>0?"prompt changed too early in the prefix to hit":"reason not recorded"}import{copyToClipboard as wd,ProjectTrustStore as yd,SessionManager as kd}from"@netrodev/hxf-coding-agent";import{CombinedAutocompleteProvider as Ya,Container as $d,Editor as vd,matchesKey as q,ProcessTerminal as xd,ScrollView as Sd,KeybindingsManager as Qa,setKeybindings as el,isKeyRelease as Cd,parseColor as Yt,TUI_KEYBINDINGS as tl,SelectList as Ad,TuiAltScreen as Td,truncateToWidth as We,VStack as Ed,visibleWidth as Sr,wrapTextWithAnsi as nl}from"@netrodev/hxf-tui";import{spawn as Pl}from"node:child_process";function Ml(e,t,n=2e3){return new Promise(i=>{let o=!1,u,a=k=>{o||(o=!0,u!==void 0&&clearTimeout(u),i(k))},g;try{g=Pl(e,[...t],{stdio:["ignore","pipe","ignore"]})}catch{a({ok:!1,stdout:""});return}u=setTimeout(()=>{g.kill("SIGKILL"),a({ok:!1,stdout:""})},n);let b=[];g.stdout?.on("data",k=>b.push(k)),g.on("error",()=>a({ok:!1,stdout:""})),g.on("close",k=>{a({ok:k===0,stdout:Buffer.concat(b).toString("utf8")})})})}function Hn(){return process.env.XDG_SESSION_TYPE==="wayland"||(process.env.WAYLAND_DISPLAY?.length??0)>0}async function Rl(){let e=[];process.platform==="darwin"?e.push({command:"pbpaste",args:[]}):process.platform==="win32"?e.push({command:"powershell.exe",args:["-NoProfile","-Command","Get-Clipboard -Raw"]}):(Hn()&&(e.push({command:"wl-paste",args:["--no-newline","--type","text/plain;charset=utf-8"]}),e.push({command:"wl-paste",args:["--no-newline","--type","text/plain"]}),e.push({command:"wl-paste",args:["--no-newline"]})),((process.env.DISPLAY?.length??0)>0||!Hn())&&(e.push({command:"xclip",args:["-selection","clipboard","-o"]}),e.push({command:"xsel",args:["--clipboard","--output"]})),e.push({command:"termux-clipboard-get",args:[]}));for(let t of e){let n=await Ml(t.command,t.args);if(n.ok&&n.stdout.length>0)return n.stdout}}async function ks(){let e;try{let{getNativeClipboard:i}=await import("@netrodev/hxf-tui");e=i()}catch{e=void 0}if(e)try{let i=await e.getText();if(typeof i=="string"&&i.length>0)return{ok:!0,text:i}}catch{}let t=await Rl();return t!==void 0?{ok:!0,text:t}:{ok:!1,reason:`no clipboard tool could read it \u2014 ${Hn()?"install wl-clipboard (wl-paste)":process.platform==="darwin"?"pbpaste should be present on macOS":process.platform==="win32"?"Get-Clipboard should be present on Windows":"install xclip or xsel, or run under a display"}`}}import{spawn as Il}from"node:child_process";import{mkdirSync as _l,writeFileSync as Ll}from"node:fs";import{join as Ol}from"node:path";import{getNativeClipboard as Nl}from"@netrodev/hxf-tui";async function _e(e,t,n=4e3){let{promise:i,resolve:o}=Promise.withResolvers(),u=!1,a,g=C=>{u||(u=!0,clearTimeout(a),o(C))},b;try{b=Il(e,[...t],{stdio:["ignore","pipe","ignore"]})}catch{return g(void 0),i}a=setTimeout(()=>{b.kill("SIGKILL"),g(void 0)},n);let k=[];return b.stdout?.on("data",C=>k.push(C)),b.on("error",()=>g(void 0)),b.on("close",C=>{let _=Buffer.concat(k);g(C===0&&_.length>0?_:void 0)}),i}function $s(){return process.env.XDG_SESSION_TYPE==="wayland"||(process.env.WAYLAND_DISPLAY?.length??0)>0}function Fl(e){return e.length>8&&e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71}function jl(e){return e.length>3&&e[0]===255&&e[1]===216&&e[2]===255}async function Dl(){try{let e=await Nl()?.getImage();if(e&&e.length>0)return Buffer.from(e)}catch{}if(process.platform==="darwin"){let e=await _e("pngpaste",["-"]);return e||await _e("osascript",["-e",`set d to the clipboard as \xABclass PNGf\xBB
1
+ import{$a as us,A as _o,Aa as zo,Ba as Yo,Ca as Jo,D as Mt,Da as Xo,E as Lo,Ea as Zo,G as Oo,Ga as de,Ha as E,Ia as J,J as No,Ja as A,K as Fo,Ka as Qo,L as Rt,La as es,M as jo,Ma as ts,N as Do,Na as ns,O as Wo,Oa as Kn,P as Dn,Pa as rs,Qa as is,Sa as Gn,Ta as os,Va as ss,X as Wn,Xa as as,Ya as ls,Z as Un,Za as cs,_a as ds,aa as Qe,ab as fs,bb as ms,c as So,e as Co,g as Ao,h as To,ha as Uo,ia as et,ka as It,n as Mo,oa as Bo,pa as Ko,ra as Go,sa as Ho,ta as Vo,v as Ro,wa as qo,x as Io,z as jn,za as Bn}from"./chunk-VDUY46W2.js";import{b as ps,c as gs}from"./chunk-YFJKKWIX.js";import{b as Ee,c as Ze,e as Eo,f as Et,g as Po,h as Pt}from"./chunk-27TRKD65.js";import{A as io,B as St,C as oo,b as Rn,c as ye,d as zi,e as Yi,h as Ji,n as In,o as Xi,q as oe,s as Zi,t as Ie,v as Qi,w as eo,x as to,y as no,z as ro}from"./chunk-GEAWXEQG.js";import{a as so,b as ao,c as lo,d as co,f as uo,g as fo,h as mo,i as po,l as go}from"./chunk-K4ONXZQE.js";import{a as Ct,b as _n,c as Ln,d as ho,e as At}from"./chunk-3FYCFLNK.js";import{u as bo}from"./chunk-SDO33XPR.js";import{a as wo}from"./chunk-ORJ2QZBG.js";import{a as yo,c as Tt,d as On,j as ko,k as $o,l as vo,n as Nn,o as Fn,p as xo}from"./chunk-SVONBXW3.js";import{a as Pn,b as Mn,c as Di,d as Wi}from"./chunk-EZNNALD3.js";import{b as xt}from"./chunk-7LA2AMZB.js";import{A as Li,B as $t,C as vt,D as Oi,E as Sn,F as Cn,G as Ni,H as R,M as Xe,N as An,O as Fi,Q as ji,c as vn,d as wt,g as yt,i as xi,j as Si,k as Ci,l as Ai,m as kt,n as Ti,o as xn,p as Ei,s as se,t as Pi,u as Mi,x as Ri,y as Ii,z as _i}from"./chunk-465RG5I6.js";import{a as ie}from"./chunk-UTYFLLSM.js";import{j as Tn,k as En}from"./chunk-MVVEYKN6.js";import{b as Ui,c as Bi,d as Ki,e as Gi,f as Hi}from"./chunk-TUXY64DT.js";import{h as Vi,i as qi}from"./chunk-NFVGCV56.js";import{a as $n,b as bt,e as vi}from"./chunk-XSUEEWKS.js";import"./chunk-WOT6VMZA.js";import{execFile as ud}from"node:child_process";import{promisify as fd}from"node:util";import{appendFileSync as md,existsSync as Vt,mkdirSync as yr,readFileSync as qt,rmSync as pd,statSync as za,writeFileSync as kr}from"node:fs";import{basename as gd,dirname as hd,join as me,resolve as bd}from"node:path";function hs(e){if(e==="")return!0;let t=/^\x1b\[(\d+);(\d+)u$/.exec(e);if(t&&Number(t[1])===99&&(Number(t[2])&5)!==0)return!0;let n=/^\x1b\[27;(\d+);(\d+)~$/.exec(e);return!!(n&&Number(n[2])===99&&(Number(n[1])&5)!==0)}function bs(e){let t=!1;process.on("SIGINT",()=>{t||(t=!0,e())})}function Cl(e){if(!e||typeof e!="object")return;let t=e;if(!(typeof t.input!="number"&&typeof t.cacheRead!="number"&&typeof t.cacheWrite!="number"))return t}function Al(e){let t=e?.input??0,n=e?.cacheRead??0,i=e?.cacheWrite??0;return{input:t,cacheRead:n,cacheWrite:i,prompt:t+n+i}}function Tl(e){if(typeof e!="string")return null;let t=Date.parse(e);return Number.isNaN(t)?null:t}function El(e){if(!e||typeof e!="object")return;let t=e,i=(t.message&&typeof t.message=="object"?t.message:void 0)??t,o=Cl(i.usage);if(!o)return;let u=typeof i.provider=="string"?i.provider:"",a=typeof i.model=="string"?i.model:"";return{usage:o,model:[u,a].filter(Boolean).join("/")}}function ws(e){let t=0,n=0,i=[],o=0,u=null;for(let g of e){let b=El(g);if(!b)continue;let{input:k,cacheRead:C,cacheWrite:_,prompt:O}=Al(b.usage);if(O===0)continue;t+=C,n+=k+_;let F=Tl(g.timestamp),W=u,G=W?W.at:null;if(W!==null&&C===0&&k>=1e3){let Q=F!==null&&G!==null?Math.max(0,F-G):0;i.push({missedTokens:k,idleMs:Q,modelChanged:b.model!==""&&W.model!==""&&b.model!==W.model}),o+=k}u={prompt:O,at:F??G??null,model:b.model}}let a=t+n;return{cachedTokens:t,billedTokens:n,hitRate:a>0?t/a*100:null,misses:i,missedTokens:o}}function ys(e){return e.modelChanged?"model changed, so its cache had to be built":e.idleMs>=3e5?`cache expired after ${Math.round(e.idleMs/1e3)}s idle`:e.idleMs>0?"prompt changed too early in the prefix to hit":"reason not recorded"}import{copyToClipboard as wd,ProjectTrustStore as yd,SessionManager as kd}from"@netrodev/hxf-coding-agent";import{CombinedAutocompleteProvider as Ya,Container as $d,Editor as vd,matchesKey as q,ProcessTerminal as xd,ScrollView as Sd,KeybindingsManager as Qa,setKeybindings as el,isKeyRelease as Cd,parseColor as Yt,TUI_KEYBINDINGS as tl,SelectList as Ad,TuiAltScreen as Td,truncateToWidth as We,VStack as Ed,visibleWidth as Sr,wrapTextWithAnsi as nl}from"@netrodev/hxf-tui";import{spawn as Pl}from"node:child_process";function Ml(e,t,n=2e3){return new Promise(i=>{let o=!1,u,a=k=>{o||(o=!0,u!==void 0&&clearTimeout(u),i(k))},g;try{g=Pl(e,[...t],{stdio:["ignore","pipe","ignore"]})}catch{a({ok:!1,stdout:""});return}u=setTimeout(()=>{g.kill("SIGKILL"),a({ok:!1,stdout:""})},n);let b=[];g.stdout?.on("data",k=>b.push(k)),g.on("error",()=>a({ok:!1,stdout:""})),g.on("close",k=>{a({ok:k===0,stdout:Buffer.concat(b).toString("utf8")})})})}function Hn(){return process.env.XDG_SESSION_TYPE==="wayland"||(process.env.WAYLAND_DISPLAY?.length??0)>0}async function Rl(){let e=[];process.platform==="darwin"?e.push({command:"pbpaste",args:[]}):process.platform==="win32"?e.push({command:"powershell.exe",args:["-NoProfile","-Command","Get-Clipboard -Raw"]}):(Hn()&&(e.push({command:"wl-paste",args:["--no-newline","--type","text/plain;charset=utf-8"]}),e.push({command:"wl-paste",args:["--no-newline","--type","text/plain"]}),e.push({command:"wl-paste",args:["--no-newline"]})),((process.env.DISPLAY?.length??0)>0||!Hn())&&(e.push({command:"xclip",args:["-selection","clipboard","-o"]}),e.push({command:"xsel",args:["--clipboard","--output"]})),e.push({command:"termux-clipboard-get",args:[]}));for(let t of e){let n=await Ml(t.command,t.args);if(n.ok&&n.stdout.length>0)return n.stdout}}async function ks(){let e;try{let{getNativeClipboard:i}=await import("@netrodev/hxf-tui");e=i()}catch{e=void 0}if(e)try{let i=await e.getText();if(typeof i=="string"&&i.length>0)return{ok:!0,text:i}}catch{}let t=await Rl();return t!==void 0?{ok:!0,text:t}:{ok:!1,reason:`no clipboard tool could read it \u2014 ${Hn()?"install wl-clipboard (wl-paste)":process.platform==="darwin"?"pbpaste should be present on macOS":process.platform==="win32"?"Get-Clipboard should be present on Windows":"install xclip or xsel, or run under a display"}`}}import{spawn as Il}from"node:child_process";import{mkdirSync as _l,writeFileSync as Ll}from"node:fs";import{join as Ol}from"node:path";import{getNativeClipboard as Nl}from"@netrodev/hxf-tui";async function _e(e,t,n=4e3){let{promise:i,resolve:o}=Promise.withResolvers(),u=!1,a,g=C=>{u||(u=!0,clearTimeout(a),o(C))},b;try{b=Il(e,[...t],{stdio:["ignore","pipe","ignore"]})}catch{return g(void 0),i}a=setTimeout(()=>{b.kill("SIGKILL"),g(void 0)},n);let k=[];return b.stdout?.on("data",C=>k.push(C)),b.on("error",()=>g(void 0)),b.on("close",C=>{let _=Buffer.concat(k);g(C===0&&_.length>0?_:void 0)}),i}function $s(){return process.env.XDG_SESSION_TYPE==="wayland"||(process.env.WAYLAND_DISPLAY?.length??0)>0}function Fl(e){return e.length>8&&e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71}function jl(e){return e.length>3&&e[0]===255&&e[1]===216&&e[2]===255}async function Dl(){try{let e=await Nl()?.getImage();if(e&&e.length>0)return Buffer.from(e)}catch{}if(process.platform==="darwin"){let e=await _e("pngpaste",["-"]);return e||await _e("osascript",["-e",`set d to the clipboard as \xABclass PNGf\xBB
2
2
  return d`])}if(process.platform==="win32"){let e=["Add-Type -AssemblyName System.Windows.Forms","$img = [System.Windows.Forms.Clipboard]::GetImage()","if ($img -ne $null) {"," $ms = New-Object System.IO.MemoryStream"," $img.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png)"," [Console]::OpenStandardOutput().Write($ms.ToArray(), 0, $ms.Length)","}"].join("; ");return _e("powershell.exe",["-NoProfile","-Command",e])}if($s()){let e=await _e("wl-paste",["--type","image/png"]);if(e)return e}if((process.env.DISPLAY?.length??0)>0||!$s()){let e=await _e("xclip",["-selection","clipboard","-t","image/png","-o"]);if(e)return e;let t=await _e("xclip",["-selection","clipboard","-t","image/jpeg","-o"]);if(t)return t}}function Wl(e,t){let n=t==="image/jpeg"?"jpg":"png";return`pasted-${new Date(e).toISOString().replace(/[:.]/g,"-")}.${n}`}async function Vn(e=ji,t=Date.now()){let n=await Dl();if(!n)return{ok:!1,reason:"the clipboard holds no image"};let i=Fl(n)?"image/png":jl(n)?"image/jpeg":void 0;if(!i)return{ok:!1,reason:"the clipboard image is not PNG or JPEG"};try{_l(e,{recursive:!0});let o=Ol(e,Wl(t,i));return Ll(o,n,{mode:384}),{ok:!0,image:{path:o,data:n.toString("base64"),mimeType:i}}}catch(o){return{ok:!1,reason:`could not store the image: ${o instanceof Error?o.message:String(o)}`}}}import{TreeSelectorComponent as Pd,initTheme as Md}from"@netrodev/hxf-coding-agent";import{getKeybindings as Ja}from"@netrodev/hxf-tui";import{mixColors as Ul,parseColor as Bl,styleText as he}from"@netrodev/hxf-tui";var ue=process.env.HOWTOCODE_NO_MOTION!=="1",Kl=45,vs=5,xs=8,qn=1e4,Ss=6e4,Cs=3,As=4,zn=e=>e<0?0:e>1?1:e;function ke(e,t,n){let i=zn(n);return i>=1?t:i<=0?e:Ul(e,t,i)}var _t=class{value;velocity=0;last=Date.now();target;constructor(t,n=t){this.value=t,this.target=n}set(t){this.target=t}get moving(){return Math.abs(this.target-this.value)>.15}snap(t){this.value=t,this.target=t,this.velocity=0,this.last=Date.now()}step(t=Date.now()){let n=Math.max(0,t-this.last),i=Math.min(250,n)/1e3;if(this.last=t,!ue)return this.value=this.target,this.velocity=0,this.value;n>250&&(this.velocity=0);let o=150,u=2*Math.sqrt(o),a=Math.max(1,Math.ceil(i/.008)),g=i/a;for(let b=0;b<a;b+=1)this.velocity+=(this.target-this.value)*o*g-this.velocity*u*g,this.value+=this.velocity*g;return this.moving||(this.value=this.target,this.velocity=0),this.value}};function Yn(e,t,n,i){return!ue||e<=qn?t:e>=Ss?i:ke(n,i,(e-qn)/(Ss-qn))}function Ts(e,t){return!ue||t<=0||e<0?1:1-(1-zn(e/t))**3}var Es=260,Gl=45;function Ps(e,t,n=Gl,i=400){return!ue||n<=0||e<0||e>=i?t:Math.min(t,Math.floor(e/n)+1)}function Ms(e,t,n=Date.now(),i=1400){if(!ue||i<=0)return e;let o=n%i/i;return ke(e,t,o<.5?o*2:(1-o)*2)}function Lt(e,t,n){let i=he(e,{fg:t.rest},de);if(!ue||e.length===0)return i;let o=zn(n);if(o>=1)return i;let u=t.band??1,a=e.length+As*2,b=Math.min(a-1,Math.floor(o*a))-As,k=G=>{let Q=Math.abs(G-b);return Q>u?0:1-Q/(u+1)},C="",_=0,O=null,F=0,W=0;for(let G of e){let Q=k(W);O===null?O=Q:Q!==O&&(C+=he(e.slice(_,F),{fg:ke(t.rest,t.lit,O)},de),_=F,O=Q),F+=G.length,W+=1}return C+he(e.slice(_),{fg:ke(t.rest,t.lit,O??0)},de)}function Jn(e,t,n=Date.now(),i=90){let o=t[0]??Bl("#e6e6e6");if(t.length===0||e.length===0)return he(e,{fg:o},de);if(!ue||i<=0)return he(e,{fg:t[t.length-1]??o},de);let u=t.length*i,a=(n%u+u)%u,g="",b=0,k=null,C=0,_=0,O=F=>{let W=(a+F*i)/u%1*t.length,G=Math.floor(W)%t.length,Q=(G+1)%t.length;return ke(t[G]??o,t[Q]??o,W-Math.floor(W))};for(let F of e){let W=O(_);k===null?k=W:W!==k&&(g+=he(e.slice(b,C),{fg:k},de),b=C,k=W),C+=F.length,_+=1}return g+he(e.slice(b),{fg:k??o},de)}function Hl(e,t){let n=Math.abs(e-t);return n>=vs?0:Math.ceil((1-n/vs)*Cs)/Cs}function Rs(e,t,n=Date.now()){let i=t.charMs??Kl;if(!ue||e.length===0||i<=0)return he(e,{fg:t.base},de);let o=e.length+xs*2,u=n/i%o-xs,a=(O,F)=>he(O,{fg:ke(t.base,t.bright,F)},de),g="",b=0,k=null,C=0,_=0;for(let O of e){let F=Hl(_,u);k===null?k=F:F!==k&&(g+=a(e.slice(b,C),k),b=C,k=F),C+=O.length,_+=1}return g+a(e.slice(b),k??0)}import{readFileSync as Vl,statSync as ql}from"node:fs";import{homedir as zl}from"node:os";import{extname as Yl}from"node:path";var Xn="\x1B[200~",Zn="\x1B[201~",Jl={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp"},Is=10*1024*1024,Xl=256*1024,Zl=20;function _s(e){if(!e.startsWith(Xn)||!e.endsWith(Zn))return;let t=e.slice(Xn.length,e.length-Zn.length);if(!(t.includes(Xn)||t.includes(Zn)))return t}function Ls(e){return e.trim()===""}function Ql(e){return/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\")||e.startsWith("/")||e==="~"||e.startsWith("~/")}function ec(e,t=zl()){let n=e.trim();return n.startsWith("file://")&&(n=decodeURIComponent(n.slice(7)),/^\/[a-zA-Z]:\//.test(n)&&(n=n.slice(1))),!/^[a-zA-Z]:[\\/]/.test(n)&&!n.startsWith("\\\\")&&(n=n.replace(/\\([ ()'&])/g,"$1")),n==="~"?t:n.startsWith("~/")?t+n.slice(1):n}function Os(e,t){let n=e.trim();if(!n||n.length>8192)return;let i,o=[...n.matchAll(/"([^"]+)"|'([^']+)'/g)].map(a=>a[1]??a[2]??"");if(o.length>0&&n.replace(/"[^"]+"|'[^']+'/g,"").trim()===""?i=o:i=n.split(/\r?\n/).map(a=>a.trim()).filter(a=>a.length>0),i.length===0||i.length>Zl||!i.every(a=>Ql(a)||a.startsWith("file://")))return;let u=i.map(a=>ec(a));return u.every(t)?u:void 0}function Ns(e){return Jl[Yl(e).toLowerCase()]}function Fs(e){return`[file ${e}]`}function Qn(e){return`[image ${e}]`}function js(e,t){return e.replace(/\[file ([^\]\n]+)\]/g,(n,i)=>{let o=t(i);return o===void 0?n:`<file name="${i}">
3
3
  ${o.trimEnd()}
4
4
  </file>`})}function Ds(e){try{let t=ql(e);if(!t.isFile()||t.size===0||t.size>Xl)return;let n=Vl(e);return n.includes(0)?void 0:n.toString("utf8")}catch{return}}import{Markdown as kc,wrapTextWithAnsi as $c}from"@netrodev/hxf-tui";import{homedir as tc}from"node:os";import{isAbsolute as nc,relative as rc,resolve as ic,sep as Ws}from"node:path";import{getImageDimensions as oc,imageFallback as Us,renderImage as sc}from"@netrodev/hxf-tui";var ac="\u25CF",nr="\u2514",Nt="\u22EF",er=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function rt(e=1e3/30){let t=Math.floor(Date.now()/e)%er.length;return er[t]??er[0]}var lc="\u25B2";var cc="\u25CB",dc=["create_object","set_properties","delete_object","clone_instance","reparent_instance","set_script_source","edit_script_lines","insert_script_lines","execute_luau","generate_mesh","generate_material","generate_procedural_model"];function rr(e){return e.includes("__")?e.slice(e.lastIndexOf("__")+2):e}function Hs(e){return dc.includes(rr(e))}function tt(e,t=process.cwd()){if(!e||!nc(e))return e;let n=ic(e),i=rc(t,n);if(i==="")return".";if(i&&!i.startsWith(`..${Ws}`)&&i!=="..")return i;let o=tc();return o&&(n===o||n.startsWith(o+Ws))?`~${n.slice(o.length)}`:n}function ae(e,t){let n=e.replace(/\s+/g," ").trim();return n.length>t?`${n.slice(0,Math.max(1,t-1))}\u2026`:n}function U(e,t){if(e&&typeof e=="object"){let n=e[t];if(typeof n=="string"&&n.length>0)return n;if(typeof n=="number")return String(n)}}function uc(e,t=160){if(!e||typeof e!="object")return"";try{let n=JSON.stringify(e);return n&&n!=="{}"?ae(n,t):""}catch{return""}}function fc(e,t){switch(e){case"read":{let n=tt(U(t,"path")??""),i=[U(t,"offset"),U(t,"limit")].filter(Boolean);return i.length>0?`${n} ${i.length===1?`offset=${i[0]}`:`offset=${i[0]}, limit=${i[1]}`}`:n}case"edit":case"write":return tt(U(t,"path")??"");case"bash":case"powershell":{let n=U(t,"command")??"";return t?.run_in_background===!0?`${n} [background]`:n}case"bash_output":{let n=U(t,"task_id"),i=U(t,"filter");return n?i?`${n} filter=${i}`:n:"all tasks"}case"kill_shell":return U(t,"task_id")??"";case"compress":{let n=U(t,"topic")??"",i=Array.isArray(t.content)?t.content.length:0;return i>1?`${n} (${i} ranges)`:n}case"grep":{let n=U(t,"pattern")??"",i=U(t,"path");return i?`${n} in ${tt(i)}`:n}case"find":case"glob":{let n=U(t,"pattern")??U(t,"glob")??"",i=U(t,"path");return i?`${n} in ${tt(i)}`:n}case"ls":return tt(U(t,"path")??".");case"task":return U(t,"agent")??"task";case"ask":return U(t,"question")??"";case"web_search":return U(t,"query")??"";case"web_fetch":return U(t,"url")??"";case"lsp":{let n=U(t,"action")??"lsp",i=U(t,"file")??"",o=U(t,"line");return o?`${n} ${i}:${o}`:`${n} ${i}`}case"quality":return U(t,"path")??"changed files";case"think":return"private";case"todo":{let n=U(t,"op")??"view",i=U(t,"task"),o=t?.items;return n==="init"&&Array.isArray(o)?`init ${o.length} task${o.length===1?"":"s"}`:i?`${n} ${i}`:n}case"context":{let n=U(t,"op")??"list",i=U(t,"key");return i?`${n} ${i}`:n}case"workflow":{let n=U(t,"path");if(n)return n;let i=U(t,"code")??"",o=/export\s+const\s+meta\s*=\s*\{[\s\S]*?name\s*:\s*["'`]([^"'`]+)/.exec(i)?.[1];if(o)return o;let u=i.trim().split(`
@@ -137,4 +137,4 @@ plan file: ${jo()??"(unknown)"}`);return}if(s==="goal"){let d=l.trim();if(!d){m(
137
137
  ${jn(p)}`);return}if(s==="session"){let d=$.model;m("session",d?`${d.provider}/${d.id}`:"no model");return}if(s==="skills"){m("skills",gs($.resourceLoader.getSkills().skills));return}if(s==="preset"){$i(l);return}if(s==="roblox"){let d=se(e.cwd).entries.find(x=>x.manifest.name==="rotoolbox");if(!d||d.source!=="installed"){m("roblox","RoToolbox is not installed. Run /preset and install RoToolbox first.");return}let p=xn(d.dir),w=$.getActiveToolNames().filter(x=>/roblox[-_]studio/i.test(x)),h=w.length>0;m("roblox",p?`RoToolbox: disabled
138
138
  Enable with /preset enable rotoolbox
139
139
  The MCP server and manager stay stopped while disabled.`:["RoToolbox: active",`MCP server: ${h?`connected \u2014 ${w.length} tool${w.length===1?"":"s"} registered`:"not connected yet"}`,"Open Roblox Studio with a place, then use a prompt to inspect it.","Disable with /preset disable rotoolbox"].join(`
140
- `));return}let f=ps(r,$.resourceLoader.getSkills().skills.map(d=>d.name));if(f){oi(f);return}let y=$.extensionRunner.getCommand(s??"");if(y){try{await y.handler(l,$.extensionRunner.createCommandContext())}catch(d){H(d instanceof Error?d.message:String(d))}return}m("command",`/${s??""} is not available in this screen yet`)};Mo((r,s)=>{let{promise:c,resolve:l}=Promise.withResolvers();return j(r,s.map(f=>({value:f,label:f})),l,()=>l("cancelled")),c}),process.on("SIGTERM",He),bs(()=>{He()}),t.setTitle(`${$n} ${bt}`),Ud(),i.start(),i.requestRender(!0),pn(!0);{let{maybeShowWelcome:r}=await import("./chunk-SBVQNV6A.js");await r({cwd:e.cwd,note:e.note,signedIn:be!==void 0,runSlash:s=>{Je(s)},openExternal:s=>{Fe(s)}},j,m)}e.initialPrompt&&gn(e.initialPrompt),await new Promise(()=>{})}var X,Bd=1e3/30,Kd=45e3;export{Er as Dock,Ar as Hud,Tr as PinnedBlock,jd as approvalDetail,Fd as infoPanel,It as orderModelsForDefault,Nd as pickerPanel,Sm as runWorkbench,xr as slashCommands,Dd as workflowPanel,zt as workflowPanelFromRun,Pr as workflowRunOf};
140
+ `));return}let f=ps(r,$.resourceLoader.getSkills().skills.map(d=>d.name));if(f){oi(f);return}let y=$.extensionRunner.getCommand(s??"");if(y){try{await y.handler(l,$.extensionRunner.createCommandContext())}catch(d){H(d instanceof Error?d.message:String(d))}return}m("command",`/${s??""} is not available in this screen yet`)};Mo((r,s)=>{let{promise:c,resolve:l}=Promise.withResolvers();return j(r,s.map(f=>({value:f,label:f})),l,()=>l("cancelled")),c}),process.on("SIGTERM",He),bs(()=>{He()}),t.setTitle(`${$n} ${bt}`),Ud(),i.start(),i.requestRender(!0),pn(!0);{let{maybeShowWelcome:r}=await import("./chunk-XAIUZHIW.js");await r({cwd:e.cwd,note:e.note,signedIn:be!==void 0,runSlash:s=>{Je(s)},openExternal:s=>{Fe(s)}},j,m)}e.initialPrompt&&gn(e.initialPrompt),await new Promise(()=>{})}var X,Bd=1e3/30,Kd=45e3;export{Er as Dock,Ar as Hud,Tr as PinnedBlock,jd as approvalDetail,Fd as infoPanel,It as orderModelsForDefault,Nd as pickerPanel,Sm as runWorkbench,xr as slashCommands,Dd as workflowPanel,zt as workflowPanelFromRun,Pr as workflowRunOf};
@@ -1 +1 @@
1
- import{j as a}from"./chunk-MVVEYKN6.js";import{b as r}from"./chunk-4AQGNUVQ.js";import"./chunk-WOT6VMZA.js";function c(e){return{prompt:s=>e.session.prompt(s),abort:()=>e.session.abort(),subscribe:s=>e.session.subscribe(n=>s(n)),getLastAssistantText:()=>a(e.session.getLastAssistantText()??""),lastStopReason:()=>{let s=e.session.state.messages.at(-1);return s?.role==="assistant"?s.stopReason:void 0},dispose:()=>e.dispose()}}async function g(e,s){let{openSession:n}=await import("./chunk-DL7CRCHC.js"),i=t=>n({cwd:t,model:s.model,thinking:s.thinking,continueSession:!1,noSession:!1,sessionPath:void 0,interactive:!1});if(e==="acp"){let{runAcp:t}=await import("./chunk-TOV557ET.js");await t({input:process.stdin,output:process.stdout,version:r,createAgent:async u=>c(await i(u))});return}let{runRpc:p}=await import("./chunk-QOYTPACU.js"),{createJsonEventEncoder:d}=await import("./chunk-MCDEIIEN.js"),o=await i(s.cwd),m=d();await p({input:process.stdin,output:process.stdout,agent:c(o),encodeEvent:t=>m.line(t),state:()=>({sessionId:o.session.sessionId,model:o.modelLabel,cwd:s.cwd})})}export{c as agentFromSession,g as serveProtocol};
1
+ import{j as a}from"./chunk-MVVEYKN6.js";import{b as r}from"./chunk-XSUEEWKS.js";import"./chunk-WOT6VMZA.js";function c(e){return{prompt:s=>e.session.prompt(s),abort:()=>e.session.abort(),subscribe:s=>e.session.subscribe(n=>s(n)),getLastAssistantText:()=>a(e.session.getLastAssistantText()??""),lastStopReason:()=>{let s=e.session.state.messages.at(-1);return s?.role==="assistant"?s.stopReason:void 0},dispose:()=>e.dispose()}}async function g(e,s){let{openSession:n}=await import("./chunk-7NGP36QA.js"),i=t=>n({cwd:t,model:s.model,thinking:s.thinking,continueSession:!1,noSession:!1,sessionPath:void 0,interactive:!1});if(e==="acp"){let{runAcp:t}=await import("./chunk-TOV557ET.js");await t({input:process.stdin,output:process.stdout,version:r,createAgent:async u=>c(await i(u))});return}let{runRpc:p}=await import("./chunk-QOYTPACU.js"),{createJsonEventEncoder:d}=await import("./chunk-MCDEIIEN.js"),o=await i(s.cwd),m=d();await p({input:process.stdin,output:process.stdout,agent:c(o),encodeEvent:t=>m.line(t),state:()=>({sessionId:o.session.sessionId,model:o.modelLabel,cwd:s.cwd})})}export{c as agentFromSession,g as serveProtocol};