howtocode 0.7.66 → 0.7.68

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,10 +0,0 @@
1
- import{a as A}from"./chunk-UTYFLLSM.js";import{existsSync as E,readFileSync as D}from"node:fs";import{dirname as _e,join as fe}from"node:path";import{fileURLToPath as Le}from"node:url";import{cpSync as z,existsSync as T,readdirSync as Ie,readFileSync as Re,renameSync as He,statSync as N,writeFileSync as je}from"node:fs";import{homedir as ce}from"node:os";import{join as g,resolve as Ne}from"node:path";import{cpSync as me,existsSync as S,mkdirSync as O,mkdtempSync as L,readdirSync as I,readFileSync as H,renameSync as ye,rmSync as b,statSync as x,writeFileSync as M}from"node:fs";import{tmpdir as q}from"node:os";import{dirname as V,isAbsolute as he,join as u,relative as be,resolve as C}from"node:path";import{fileURLToPath as Se}from"node:url";import{execFileSync as ke}from"node:child_process";import{createHash as X}from"node:crypto";import{gunzipSync as de}from"node:zlib";var k=512;function P(e,r,t){let s=e.subarray(r,r+t),n=s.indexOf(0);return s.subarray(0,n===-1?s.length:n).toString("utf8").trim()}function G(e,r,t){let s=P(e,r,t);if(!s)return 0;let n=Number.parseInt(s,8);return Number.isFinite(n)?n:0}function ge(e){let r={},t=0;for(;t<e.length;){let s=e.indexOf(32,t);if(s===-1)break;let n=Number.parseInt(e.toString("utf8",t,s),10);if(!Number.isFinite(n)||n<=0)break;let i=e.toString("utf8",s+1,t+n-1),o=i.indexOf("=");o>0&&(r[i.slice(0,o)]=i.slice(o+1)),t+=n}return r}function W(e){let r=de(e),t=[],s=0,n,i={};for(;s+k<=r.length;){let o=r.subarray(s,s+k);if(o.every(pe=>pe===0))break;let a=P(o,0,100),c=P(o,345,155),l=G(o,124,12),f=G(o,100,8),m=String.fromCharCode(o[156]??48),w=P(o,157,100),v=l>0?r.subarray(s+k,s+k+l):Buffer.alloc(0);if(s+=k+Math.ceil(l/k)*k,m==="x"||m==="g"){i=ge(v);continue}if(m==="L"){n=v.toString("utf8").replace(/\0.*$/s,"").trim();continue}let y=i.path??n??(c?`${c}/${a}`:a);n=void 0,i={};let p=y.indexOf("/");if(p===-1||(y=y.slice(p+1),y=y.replace(/\/+$/,""),!y))continue;let h=m==="5"?"directory":m==="2"?"symlink":m==="0"||m==="\0"||m===""?"file":"other";t.push({path:y,kind:h,size:l,mode:f&511,...h==="file"?{data:Buffer.from(v)}:{},...h==="symlink"?{link:w}:{}})}return t}function K(e){if(!e||e.startsWith("/")||e.startsWith("\\")||/^[a-zA-Z]:/.test(e))return!1;let r=e.replace(/\/+$/,"");return r?r.split("/").every(s=>s!==""&&s!=="."&&s!==".."):!1}function U(e,r){let t=`${r.replace(/\/+$/,"")}/`,s=[];for(let n of e){if(!n.path.startsWith(t))continue;let i=n.path.slice(t.length);i&&s.push({...n,path:i})}return s}function ve(){return u(d,"presets")}function Q(e){return u(e,".howtocode","presets")}function Y(e){return S(u(e,".disabled"))}function ee(){return u(V(Se(import.meta.url)),"presets")}function j(e){return[Q(e),ve()]}var re=/^[a-z0-9][a-z0-9-]*$/,xe=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;function _(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function $(e,r){let t=be(C(e),C(r));return t!==""&&!t.startsWith("..")&&!he(t)}function te(e,r){let t=[];if(!_(r))return["preset.json must be a JSON object"];let s=l=>{let f=r[l];return typeof f!="string"||f.trim()===""?(t.push(`${l} must be a non-empty string`),""):f.trim()},n=s("name");s("title"),s("description"),s("category");let i=s("version");n&&!re.test(n)&&t.push(`name "${n}" must be lowercase letters, digits and dashes`),i&&!xe.test(i)&&t.push(`version "${i}" is not a version like 1.0.0`);let o=r.skills;if(!Array.isArray(o)||o.length===0)t.push("skills must be a non-empty array of directory names");else for(let l of o){if(typeof l!="string"||l.trim()===""){t.push("every skills entry must be a non-empty string");continue}let f=u(e,"skills",l.trim());if(!$(u(e,"skills"),f)){t.push(`skill "${l}" escapes the preset directory`);continue}S(u(f,"SKILL.md"))||t.push(`skill "${l}" has no SKILL.md at ${u("skills",l)}`)}let a=r.prompt;if(a!==void 0)if(typeof a!="string"||a.trim()==="")t.push("prompt must be a non-empty string when present");else{let l=u(e,a.trim());$(e,l)?S(l)||t.push(`prompt file "${a}" does not exist`):t.push(`prompt "${a}" escapes the preset directory`)}let c=r.tags;return c!==void 0&&!Array.isArray(c)&&t.push("tags must be an array when present"),t.push(...Z(r.mcp)),t}function ne(e){let r=u(e,"preset.json");if(!S(r))return{problems:[`no preset.json in ${e}`]};let t;try{t=JSON.parse(H(r,"utf8"))}catch(o){return{problems:[`preset.json is not valid JSON: ${o instanceof Error?o.message:String(o)}`]}}let s=te(e,t);if(s.length>0)return{problems:s};let n=t,i=Array.isArray(n.tags)?n.tags.filter(o=>typeof o=="string"):[];return{problems:[],manifest:{name:String(n.name),title:String(n.title),description:String(n.description),category:String(n.category),tags:i,version:String(n.version),skills:n.skills.map(o=>String(o)),prompt:typeof n.prompt=="string"?n.prompt:void 0,mcp:n.mcp&&typeof n.mcp=="object"&&!Array.isArray(n.mcp)?n.mcp:void 0,integrates:typeof n.integrates=="string"&&n.integrates.trim()!==""?n.integrates.trim():void 0}}}function F(e){return e.filter(r=>{try{return x(r).isDirectory()}catch{return!1}})}function R(e,r){let t=[],s=[],n=(o,a)=>{if(!S(u(o,"preset.json")))return;let{manifest:c,problems:l}=ne(o);c?t.push({manifest:c,dir:o,source:r}):s.push(`${a}: ${l.join("; ")}`)},i;try{i=I(e).sort()}catch{return{entries:t,problems:s}}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"))){n(a,o);continue}let c;try{c=I(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}n(f,u(o,l))}}return{entries:t,problems:s}}function Qe(e){let r=R(ee(),"bundled"),t=[...r.entries],s=[...r.problems],n=new Map(t.map(i=>[i.manifest.name,i]));for(let i of F(j(e))){let o=R(i,"installed");s.push(...o.problems);for(let a of o.entries){let c=n.get(a.manifest.name);if(c){let l=t.indexOf(c);l>=0&&(t[l]=a),n.set(a.manifest.name,a)}else t.push(a),n.set(a.manifest.name,a)}}return{entries:t,problems:s}}function Ye(e){return[...new Set(e.map(r=>r.manifest.category))].sort()}function er(e,r){return e.filter(t=>t.manifest.category===r).sort((t,s)=>t.manifest.title.localeCompare(s.manifest.title))}function se(e){let r=[];for(let t of F(j(e))){let{entries:s}=R(t,"installed");for(let n of s)Y(n.dir)||r.push(u(n.dir,"skills"))}return r}function rr(e){let r=[];for(let t of F(j(e))){let{entries:s}=R(t,"installed");for(let n of s){if(Y(n.dir))continue;let i=n.manifest.prompt;if(!i)continue;let o=u(n.dir,i);if($(n.dir,o))try{let a=H(o,"utf8").trim();a&&r.push({name:n.manifest.name,title:n.manifest.title,text:a})}catch{}}}return r}function tr(e,r){let t=0;for(let s of r.skills)try{t+=x(u(e,"skills",s,"SKILL.md")).size}catch{}return t}function we(e){Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,e)}var $e=".install.lock";function Ee(e,r){O(e,{recursive:!0});let t=u(e,$e),s=Date.now()+6e4;for(;;)try{M(t,`${process.pid}
2
- `,{flag:"wx"});break}catch(n){if(n.code!=="EEXIST")throw n;let i=!1;try{i=Date.now()-x(t).mtimeMs>12e4}catch{continue}if(i){b(t,{force:!0});continue}if(Date.now()>s)throw new Error(`another install is holding ${t}; remove it if no install is running`);we(100)}try{for(let n of I(e))n.startsWith(".staging-")&&b(u(e,n),{recursive:!0,force:!0});return r()}finally{b(t,{force:!0})}}function ie(e,r,t){let s=u(r,t.name);return Ee(r,()=>{O(r,{recursive:!0});let n=L(u(r,".staging-"));try{me(e,n,{recursive:!0}),b(s,{recursive:!0,force:!0}),ye(n,s)}catch(i){throw b(n,{recursive:!0,force:!0}),i}return s})}function oe(e,r){if(!S(e))return{ok:!1,problems:[`no such directory: ${e}`]};let{manifest:t,problems:s}=ne(e);if(!t)return{ok:!1,problems:s};let n=ie(e,r,t);return{ok:!0,name:t.name,target:n,problems:[]}}function Ae(e,r){let t=L(u(q(),"howtocode-preset-"));try{return ke("git",["clone","--depth","1","--quiet",e,t],{stdio:"pipe"}),oe(t,r)}catch(s){return{ok:!1,problems:[`git clone failed: ${(s instanceof Error?s.message:String(s)).split(`
3
- `)[0]}`]}}finally{b(t,{recursive:!0,force:!0})}}function nr(e,r){return/^(https?:\/\/|git@|git:\/\/)/.test(e)?Ae(e,r):oe(C(e),r)}function sr(e,r){let t=[],s=[];if(!re.test(e))return{removed:t,problems:[`"${e}" is not a preset name`]};for(let n of j(r)){let i=u(n,e);if(S(i)){if(!$(n,i)){s.push(`refusing to remove ${i}: outside ${n}`);continue}b(i,{recursive:!0,force:!0}),t.push(i)}}return t.length===0&&s.push(`"${e}" is not installed`),{removed:t,problems:s}}function ir(e){return Q(e)}function Pe(e){let r=[],t=(i,o)=>{for(let a of I(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()?t(c,l):a.isFile()&&r.push([l,X("sha256").update(H(c)).digest("hex")]))}};t(e,"");let s=0;for(let[i]of r)s+=x(u(e,i)).size;let n=r.map(([i,o])=>`${o} ${i}`).join(`
4
- `);return{digest:X("sha256").update(n).digest("hex").slice(0,16),fileCount:r.length,bytes:s}}function or(){let e=u(ee(),"hub.json");try{let r=H(e,"utf8"),t=JSON.parse(r),s=_(t)&&Array.isArray(t.entries)?t.entries:[],n=[];for(let i of s)_(i)&&(typeof i.name!="string"||typeof i.repo!="string"||typeof i.sha!="string"||typeof i.path!="string"||typeof i.category!="string"||n.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:n,problems:[]}}catch(r){return r?.code==="ENOENT"?{entries:[],problems:[]}:{entries:[],problems:[`registry unreadable: ${r instanceof Error?r.message:String(r)}`]}}}function ar(e){return[...new Set(e.map(r=>r.category))].sort()}function cr(e,r){return e.filter(t=>t.category===r).sort((t,s)=>s.stars-t.stars||t.name.localeCompare(s.name))}function lr(e,r){return e.find(t=>t.name===r)}function Oe(e){return`https://codeload.github.com/${e.repo}/tar.gz/${e.sha}`}async function ur(e,r,t=12e4){let s=L(u(q(),"howtocode-hub-"));try{let n=await fetch(Oe(e),{signal:AbortSignal.timeout(t),redirect:"follow"});if(!n.ok)return{ok:!1,problems:[`${e.repo}: HTTP ${n.status} from codeload`]};let i=Buffer.from(await n.arrayBuffer()),o=W(i),a=U(o,e.path).filter(p=>p.kind==="file"||p.kind==="directory");if(!a.some(p=>p.path==="SKILL.md"))return{ok:!1,problems:[`${e.repo}@${e.sha.slice(0,7)} has no ${e.path}/SKILL.md`]};let c=u(s,"preset",e.name),l=u(c,"skills",e.skill),f=0;for(let p of a){if(!K(p.path))return{ok:!1,problems:[`refusing unsafe path in archive: ${p.path}`]};let h=u(l,p.path);if(!$(l,h))return{ok:!1,problems:[`refusing path outside the skill: ${p.path}`]};if(p.kind==="directory"){O(h,{recursive:!0});continue}O(V(h),{recursive:!0}),M(h,p.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=Pe(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=te(c,m);if(v.length>0)return{ok:!1,problems:v};let y=ie(c,r,m);return{ok:!0,name:e.name,target:y,problems:[],skill:e.skill,modelInvocable:e.modelInvocable}}catch(n){return{ok:!1,problems:[`download failed: ${(n instanceof Error?n.message:String(n)).split(`
6
- `)[0]}`]}}finally{b(s,{recursive:!0,force:!0})}}function Te(){let e=(process.env.HOWTOCODE_HOME??process.env.HOWTOFIX_HOME??process.env.HOME??"").trim();return Ne(e||ce())}function le(e,r){for(let t of Ie(e)){let s=g(e,t),n=g(r,t);if(!T(n)){try{z(s,n,{recursive:!0,force:!1})}catch{}continue}let i=!1;try{i=N(s).isDirectory()}catch{continue}if(i&&N(n).isDirectory()){le(s,n);continue}try{let o=N(n).size,a=N(s).size;!i&&o<=2&&a>o&&z(s,n,{force:!0})}catch{}}}function De(e){let r=g(ce(),".howtofix");if(T(r)){if(!T(e))try{He(r,e);return}catch{try{z(r,e,{recursive:!0});return}catch{return}}le(r,e),Me(e)}}function Me(e){ae(g(e,"agent","models.json"),"providers"),ae(g(e,"agent","auth.json"),void 0)}function ae(e,r){if(!T(e))return;let t;try{t=JSON.parse(Re(e,"utf8"))}catch{return}let s=r?t[r]:t;if(!s||typeof s!="object")return;let n=!1;for(let[i,o]of Object.entries(s)){let a=i==="howtofix"?"howtocode":i==="howtofix-free"?"howtocode-free":i;a===i||s[a]!==void 0||(s[a]=o,delete s[i],n=!0)}if(n)try{je(e,`${JSON.stringify(t,null,2)}
7
- `)}catch{}}var d=process.env.HOWTOCODE_CODING_AGENT_DIR?.trim()||process.env.HOWTOFIX_CODING_AGENT_DIR?.trim()||(()=>{let e=g(Te(),".howtocode");return De(e),g(e,"agent")})(),yr=g(d,"skills");function Ce(e){return g(e,".howtocode","skills")}function hr(e){let r=[Ce(e)];return r.push(...se(e)),r}var br=g(d,"agents"),Sr=g(d,"usage-cache.json"),kr=g(d,"reachable-models.json"),vr=g(d,"workflows");function xr(){process.env.HXF_CODING_AGENT_DIR=d}var wr=g(d,"images");function J(e=d){return fe(e,"mcp.json")}function Z(e){let r=[];if(e===void 0)return r;if(typeof e!="object"||e===null||Array.isArray(e))return["mcp must be an object of server names"];for(let[t,s]of Object.entries(e)){if(!/^[A-Za-z0-9_-]+$/.test(t)){r.push(`mcp server "${t}" must use only letters, digits, _ and -`);continue}if(typeof s!="object"||s===null||Array.isArray(s)){r.push(`mcp server "${t}" must be an object`);continue}let n=s,i=typeof n.command=="string"&&n.command.trim()!=="",o=typeof n.url=="string"&&n.url.trim()!=="";!i&&!o&&r.push(`mcp server "${t}" needs either a command or a url`),n.args!==void 0&&!Array.isArray(n.args)&&r.push(`mcp server "${t}": args must be an array`);for(let a of["env","headers"]){let c=n[a];if(c!==void 0){if(typeof c!="object"||c===null||Array.isArray(c)){r.push(`mcp server "${t}": ${a} must be an object of strings`);continue}for(let[l,f]of Object.entries(c))typeof f!="string"&&r.push(`mcp server "${t}": ${a}.${l} must be a string`)}}}return r}function B(e){if(!E(e))return{mcpServers:{}};try{let r=JSON.parse(D(e,"utf8"));if(!r||typeof r!="object"||Array.isArray(r))return{mcpServers:{}};let t=r.mcpServers;return!t||typeof t!="object"||Array.isArray(t)?{mcpServers:{}}:{mcpServers:t}}catch{return{mcpServers:{}}}}function Rr(e,r=d){let t=Object.keys(e);if(t.length===0)return{added:[],skipped:[],problems:[]};let s=J(r),n=[];if(E(s))try{JSON.parse(D(s,"utf8"))}catch{return{added:[],skipped:[],problems:[`${s} is not valid JSON; leaving it alone`]}}let i=B(s),o=[],a=[];for(let c of t){if(i.mcpServers[c]!==void 0){a.push(c);continue}i.mcpServers[c]=e[c],o.push(c)}if(o.length>0)try{A(s,`${JSON.stringify(i,null,2)}
8
- `)}catch(c){return{added:[],skipped:a,problems:[`could not write ${s}: ${c instanceof Error?c.message:String(c)}`]}}return{added:o,skipped:a,problems:n}}function Hr(e,r=new Set,t=d){let s=J(t),n=[];if(e.length===0||!E(s))return{removed:[],kept:[],problems:n};let i=B(s),o=[],a=[];for(let c of e)if(i.mcpServers[c]!==void 0){if(r.has(c)){a.push(c);continue}delete i.mcpServers[c],o.push(c)}if(o.length>0)try{A(s,`${JSON.stringify(i,null,2)}
9
- `)}catch(c){return{removed:[],kept:a,problems:[`could not write ${s}: ${c instanceof Error?c.message:String(c)}`]}}return{removed:o,kept:a,problems:n}}var ue="@netrodev/howtocode-roblox-bridge";function jr(e=d){let r=J(e);if(!E(r))return[];try{JSON.parse(D(r,"utf8"))}catch{return[]}let t=B(r),s=Object.keys(t.mcpServers).filter(n=>{let i=t.mcpServers[n];return[i.command,...Array.isArray(i.args)?i.args:[]].map(a=>String(a??"")).some(a=>a===ue||a.startsWith(`${ue}@`))});if(s.length===0)return[];for(let n of s)delete t.mcpServers[n];try{A(r,`${JSON.stringify(t,null,2)}
10
- `)}catch{return[]}return s}function Nr(e){if(typeof e.url=="string"&&e.url)return`http: ${e.url}`;let r=typeof e.command=="string"?e.command:"",t=Array.isArray(e.args)?e.args.filter(s=>typeof s=="string"):[];return`stdio: ${[r,...t].join(" ")}`.trim()}function Fe(){return fe(_e(Le(import.meta.url)),"presets","mcp-hub.json")}function Tr(e=Fe()){let r=[];if(!E(e))return{entries:[],problems:[`no MCP catalogue at ${e}`]};let t;try{t=JSON.parse(D(e,"utf8"))}catch(i){return{entries:[],problems:[`${e} is not valid JSON: ${i instanceof Error?i.message:String(i)}`]}}let s=t?.entries;if(!Array.isArray(s))return{entries:[],problems:[`${e} has no entries array`]};let n=[];for(let i of s){if(typeof i!="object"||i===null||Array.isArray(i))continue;let o=i,a=typeof o.name=="string"?o.name.trim():"";if(!a){r.push("an entry has no name");continue}if(!/^[A-Za-z0-9_-]+$/.test(a)){r.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){r.push(`"${a}" has neither a command nor a url`);continue}n.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:n,problems:r}}function Dr(e){return[...new Set(e.map(r=>r.category))].sort()}function Mr(e,r){return e.filter(t=>t.category===r).sort((t,s)=>t.title.localeCompare(s.title))}function Cr(e,r){return e.find(t=>t.name===r)}function _r(e){let r={};return e.command&&(r.command=e.command),e.url&&(r.url=e.url),e.args&&e.args.length>0&&(r.args=[...e.args]),e.env&&Object.keys(e.env).length>0&&(r.env={...e.env}),e.description&&(r.description=e.description),r}function Lr(e,r=process.env){return(e.needs??[]).filter(t=>!r[t])}export{J as a,Z as b,Rr as c,Hr as d,ue as e,jr as f,Nr as g,Fe as h,Tr as i,Dr as j,Mr as k,Cr as l,_r as m,Lr as n,Y as o,ee as p,te as q,ne as r,Qe as s,Ye as t,er as u,se as v,rr as w,tr as x,oe as y,nr as z,sr as A,ir as B,or as C,ar as D,cr as E,lr as F,ur as G,d as H,yr as I,Ce as J,hr as K,br as L,Sr as M,kr as N,vr as O,xr as P,wr as Q};