howtocode 0.7.68 → 0.7.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -1
- package/dist/{chunk-NPD6557W.js → chunk-336TZTEK.js} +1 -1
- package/dist/{chunk-7LAMZWB5.js → chunk-4SK7TRJW.js} +1 -1
- package/dist/chunk-5FIFNXLT.js +10 -0
- package/dist/{chunk-EPNFKO5O.js → chunk-63TDK73J.js} +1 -1
- package/dist/{chunk-LUBZSBUH.js → chunk-CJLCMZKZ.js} +1 -1
- package/dist/{chunk-L4XKIPIG.js → chunk-E2UZLMQH.js} +1 -1
- package/dist/{chunk-XVHYS2UZ.js → chunk-EOZHQRU2.js} +1 -1
- package/dist/chunk-FABEBOGV.js +2 -0
- package/dist/{chunk-KS6FRAVP.js → chunk-GM6T357A.js} +1 -1
- package/dist/chunk-GNV6G3JW.js +201 -0
- package/dist/{chunk-YX2QDCVK.js → chunk-GQYIIDKK.js} +1 -1
- package/dist/{chunk-4KNWFMK6.js → chunk-HGINAX3Z.js} +1 -1
- package/dist/{chunk-O3XEEDMR.js → chunk-I555QJLZ.js} +1 -1
- package/dist/{chunk-6PZTZT6T.js → chunk-LAPEUVNT.js} +1 -1
- package/dist/{chunk-HKABQFBG.js → chunk-MXO4OS67.js} +1 -1
- package/dist/{chunk-W2U7D5UF.js → chunk-RJYOUCLJ.js} +1 -1
- package/dist/chunk-RKIOE6G6.js +141 -0
- package/dist/{chunk-YFJKKWIX.js → chunk-SDU65XW4.js} +1 -1
- package/dist/{chunk-NIDL55H4.js → chunk-SOWZZCT4.js} +1 -1
- package/dist/{chunk-AVNJV7SN.js → chunk-T3KNQOMX.js} +1 -1
- package/dist/{chunk-3H2ECHBB.js → chunk-ULXYWUXZ.js} +1 -1
- package/dist/{chunk-SVONBXW3.js → chunk-ZJL4OEXX.js} +3 -3
- package/dist/{chunk-2GVIOMRN.js → cli-auth.js} +1 -1
- package/dist/main-app.js +7 -7
- package/dist/main.js +10 -0
- package/package.json +2 -2
- package/dist/chunk-465RG5I6.js +0 -10
- package/dist/chunk-HDH5ER4H.js +0 -141
- package/dist/chunk-U3GZBLTM.js +0 -2
- package/dist/chunk-VDUY46W2.js +0 -198
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ the whole setup:
|
|
|
37
37
|
**1. Create the account** — open <https://howtofix.id> and sign up. Sign in with
|
|
38
38
|
Google works (a `@gmail.com` address).
|
|
39
39
|
|
|
40
|
-
**2. Create a token** — open <https://howtofix.id/
|
|
40
|
+
**2. Create a token** — open <https://howtofix.id/keys> and make one. It
|
|
41
41
|
starts with `sk-`. Treat it like a password: it is the credential this CLI uses,
|
|
42
42
|
and it is the only thing you have to copy.
|
|
43
43
|
|
|
@@ -179,6 +179,7 @@ Everything lives in `~/.howtocode/agent`:
|
|
|
179
179
|
|
|
180
180
|
- `models.json` — providers and model catalog
|
|
181
181
|
- `auth.json` — stored credentials
|
|
182
|
+
- `vault.json` — encrypted secret store (`/vault init`, then `/vault unlock`)
|
|
182
183
|
- `settings.json` — defaults
|
|
183
184
|
- `sessions/` — transcripts
|
|
184
185
|
- `agents/` — parked background agent runs (`*.json`) and your subagent definitions (`*.md`)
|
|
@@ -188,6 +189,11 @@ Set `HOWTOCODE_CODING_AGENT_DIR` to use a different root. The underlying SDK is
|
|
|
188
189
|
|
|
189
190
|
If no key is stored, the CLI says so and tells you to run `/connect`.
|
|
190
191
|
|
|
192
|
+
If you use `/connect <email>:<password>` instead of pasting a token, the account
|
|
193
|
+
credential goes into the vault when one is unlocked; unlocking an existing vault
|
|
194
|
+
also moves any older plaintext `account-credential.json` into it. Without a
|
|
195
|
+
vault the fallback file is mode `0600`.
|
|
196
|
+
|
|
191
197
|
## Flags
|
|
192
198
|
|
|
193
199
|
```
|
|
@@ -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-
|
|
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-5FIFNXLT.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 +1 @@
|
|
|
1
|
-
import{b as a,c as b,d as c,e as d,f as e,g as f,h as g,i as h,j as i,k as j,l as k,m as l,n as m,o as n,p as o,q as p,r as q,s as r,t as s}from"./chunk-
|
|
1
|
+
import{b as a,c as b,d as c,e as d,f as e,g as f,h as g,i as h,j as i,k as j,l as k,m as l,n as m,o as n,p as o,q as p,r as q,s as r,t as s}from"./chunk-ZJL4OEXX.js";import"./chunk-UTYFLLSM.js";import"./chunk-WOT6VMZA.js";export{c as APPROVAL_LABELS,b as APPROVAL_MODES,f as MODE_MAX_TIER,e as TIER_RANK,s as createPermissionExtension,h as criticalCommand,p as decideToolCall,q as describeToolCall,r as formatApprovalPrompt,l as getApprovalMode,d as isApprovalMode,n as isDangerousBypass,a as isReadOnlyCommand,j as loadApprovalMode,g as resolveTier,k as saveApprovalMode,i as setApprovalMode,o as setApprovalPrompt,m as setDangerousBypass};
|
|
@@ -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 s=e.subarray(t,t+r),i=s.indexOf(0);return s.subarray(0,i===-1?s.length:i).toString("utf8").trim()}function W(e,t,r){let s=O(e,t,r);if(!s)return 0;let i=Number.parseInt(s,8);return Number.isFinite(i)?i:0}function ye(e){let t={},r=0;for(;r<e.length;){let s=e.indexOf(32,r);if(s===-1)break;let i=Number.parseInt(e.toString("utf8",r,s),10);if(!Number.isFinite(i)||i<=0)break;let n=e.toString("utf8",s+1,r+i-1),o=n.indexOf("=");o>0&&(t[n.slice(0,o)]=n.slice(o+1)),r+=i}return t}function K(e){let t=me(e),r=[],s=0,i,n={};for(;s+k<=t.length;){let o=t.subarray(s,s+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(s+k,s+k+l):Buffer.alloc(0);if(s+=k+Math.ceil(l/k)*k,m==="x"||m==="g"){n=ye(v);continue}if(m==="L"){i=v.toString("utf8").replace(/\0.*$/s,"").trim();continue}let y=n.path??i??(c?`${c}/${a}`:a);i=void 0,n={};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(s=>s!==""&&s!=="."&&s!==".."):!1}function X(e,t){let r=`${t.replace(/\/+$/,"")}/`,s=[];for(let i of e){if(!i.path.startsWith(r))continue;let n=i.path.slice(r.length);n&&s.push({...i,path:n})}return s}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 s=l=>{let f=t[l];return typeof f!="string"||f.trim()===""?(r.push(`${l} must be a non-empty string`),""):f.trim()},i=s("name");s("title"),s("description"),s("category");let n=s("version");i&&!re.test(i)&&r.push(`name "${i}" must be lowercase letters, digits and dashes`),n&&!$e.test(n)&&r.push(`version "${n}" 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 s=ne(e,r);if(s.length>0)return{problems:s};let i=r,n=Array.isArray(i.tags)?i.tags.filter(o=>typeof o=="string"):[];return{problems:[],manifest:{name:String(i.name),title:String(i.title),description:String(i.description),category:String(i.category),tags:n,version:String(i.version),skills:i.skills.map(o=>String(o)),prompt:typeof i.prompt=="string"?i.prompt:void 0,mcp:i.mcp&&typeof i.mcp=="object"&&!Array.isArray(i.mcp)?i.mcp:void 0,integrates:typeof i.integrates=="string"&&i.integrates.trim()!==""?i.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=[],s=[],i=(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}):s.push(`${a}: ${l.join("; ")}`)},n;try{n=R(e).sort()}catch{return{entries:r,problems:s}}for(let o of n){if(o.startsWith("."))continue;let a=u(e,o);try{if(!x(a).isDirectory())continue}catch{continue}if(S(u(a,"preset.json"))){i(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}i(f,u(o,l))}}return{entries:r,problems:s}}function Ye(e){let t=I(te(),"bundled"),r=[...t.entries],s=[...t.problems],i=new Map(r.map(n=>[n.manifest.name,n]));for(let n of F(H(e))){let o=I(n,"installed");s.push(...o.problems);for(let a of o.entries){let c=i.get(a.manifest.name);if(c){let l=r.indexOf(c);l>=0&&(r[l]=a),i.set(a.manifest.name,a)}else r.push(a),i.set(a.manifest.name,a)}}return{entries:r,problems:s}}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,s)=>r.manifest.title.localeCompare(s.manifest.title))}function ie(e){let t=[];for(let r of F(H(e))){let{entries:s}=I(r,"installed");for(let i of s)ee(i.dir)||t.push(u(i.dir,"skills"))}return t}function rt(e){let t=[];for(let r of F(H(e))){let{entries:s}=I(r,"installed");for(let i of s){if(ee(i.dir))continue;let n=i.manifest.prompt;if(!n)continue;let o=u(i.dir,n);if($(i.dir,o))try{let a=j(o,"utf8").trim();a&&t.push({name:i.manifest.name,title:i.manifest.title,text:a})}catch{}}}return t}function nt(e,t){let r=0;for(let s of t.skills)try{r+=x(u(e,"skills",s,"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),s=Date.now()+6e4;for(;;)try{M(r,`${process.pid}
|
|
2
|
+
`,{flag:"wx"});break}catch(i){if(i.code!=="EEXIST")throw i;let n=!1;try{n=Date.now()-x(r).mtimeMs>12e4}catch{continue}if(n){b(r,{force:!0});continue}if(Date.now()>s)throw new Error(`another install is holding ${r}; remove it if no install is running`);Ee(100)}try{for(let i of R(e))i.startsWith(".staging-")&&b(u(e,i),{recursive:!0,force:!0});return t()}finally{b(r,{force:!0})}}function oe(e,t,r){let s=u(t,r.name);return Oe(t,()=>{P(t,{recursive:!0});let i=L(u(t,".staging-"));try{he(e,i,{recursive:!0}),b(s,{recursive:!0,force:!0}),be(i,s)}catch(n){throw b(i,{recursive:!0,force:!0}),n}return s})}function ae(e,t){if(!S(e))return{ok:!1,problems:[`no such directory: ${e}`]};let{manifest:r,problems:s}=se(e);if(!r)return{ok:!1,problems:s};let i=oe(e,t,r);return{ok:!0,name:r.name,target:i,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(s){return{ok:!1,problems:[`git clone failed: ${(s instanceof Error?s.message:String(s)).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=[],s=[];if(!re.test(e))return{removed:r,problems:[`"${e}" is not a preset name`]};for(let i of H(t)){let n=u(i,e);if(S(n)){if(!$(i,n)){s.push(`refusing to remove ${n}: outside ${i}`);continue}b(n,{recursive:!0,force:!0}),r.push(n)}}return r.length===0&&s.push(`"${e}" is not installed`),{removed:r,problems:s}}function ot(e){return Y(e)}function Re(e){let t=[],r=(n,o)=>{for(let a of R(n,{withFileTypes:!0}).sort((c,l)=>c.name.localeCompare(l.name))){let c=u(n,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 s=0;for(let[n]of t)s+=x(u(e,n)).size;let i=t.map(([n,o])=>`${o} ${n}`).join(`
|
|
4
|
+
`);return{digest:Z("sha256").update(i).digest("hex").slice(0,16),fileCount:t.length,bytes:s}}function at(){let e=u(te(),"hub.json");try{let t=j(e,"utf8"),r=JSON.parse(t),s=_(r)&&Array.isArray(r.entries)?r.entries:[],i=[];for(let n of s)_(n)&&(typeof n.name!="string"||typeof n.repo!="string"||typeof n.sha!="string"||typeof n.path!="string"||typeof n.category!="string"||i.push({name:n.name,title:typeof n.title=="string"?n.title:n.name,description:typeof n.description=="string"?n.description:"",category:n.category,skill:typeof n.skill=="string"?n.skill:n.name,path:n.path,repo:n.repo,sha:n.sha,license:typeof n.license=="string"?n.license:"unknown",stars:typeof n.stars=="number"?n.stars:0,sizeKb:typeof n.sizeKb=="number"?n.sizeKb:0,...typeof n.digest=="string"?{digest:n.digest}:{},...typeof n.fileCount=="number"?{fileCount:n.fileCount}:{},...typeof n.modelInvocable=="boolean"?{modelInvocable:n.modelInvocable}:{}}));return{entries:i,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,s)=>s.stars-r.stars||r.name.localeCompare(s.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 s=L(u(V(),"howtocode-hub-"));try{let i=await fetch(Ie(e),{signal:AbortSignal.timeout(r),redirect:"follow"});if(!i.ok)return{ok:!1,problems:[`${e.repo}: HTTP ${i.status} from codeload`]};let n=Buffer.from(await i.arrayBuffer()),o=K(n),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(s,"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(i){return{ok:!1,problems:[`download failed: ${(i instanceof Error?i.message:String(i)).split(`
|
|
6
|
+
`)[0]}`]}}finally{b(s,{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 s=p(e,r),i=p(t,r);if(!T(i)){try{J(s,i,{recursive:!0,force:!1})}catch{}continue}let n=!1;try{n=N(s).isDirectory()}catch{continue}if(n&&N(i).isDirectory()){fe(s,i);continue}try{let o=N(i).size,a=N(s).size;!n&&o<=2&&a>o&&J(s,i,{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 s=t?r[t]:r;if(!s||typeof s!="object")return;let i=!1;for(let[n,o]of Object.entries(s)){let a=o,c=typeof a?.baseUrl=="string"?a.baseUrl:"";c&&!/^https?:\/\/(api\.)?howtofix\.id(?:\/|$)/i.test(c)&&(delete s[n],i=!0)}if(t===void 0){let n;try{let o=JSON.parse(ce(p(Te(e),"models.json"),"utf8"));o.providers&&typeof o.providers=="object"&&(n=new Set(Object.keys(o.providers)))}catch{}if(n&&n.size>0)for(let o of Object.keys(s))n.has(o)||n.has(o.replace(/^howtofix/,"howtocode"))||(delete s[o],i=!0)}for(let[n,o]of Object.entries(s)){let a=n==="howtofix"?"howtocode":n==="howtofix-free"?"howtocode-free":n;a===n||s[a]!==void 0||(s[a]=o,delete s[n],i=!0)}if(i)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,s]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 s!="object"||s===null||Array.isArray(s)){t.push(`mcp server "${r}" must be an object`);continue}let i=s,n=typeof i.command=="string"&&i.command.trim()!=="",o=typeof i.url=="string"&&i.url.trim()!=="";!n&&!o&&t.push(`mcp server "${r}" needs either a command or a url`),i.args!==void 0&&!Array.isArray(i.args)&&t.push(`mcp server "${r}": args must be an array`);for(let a of["env","headers"]){let c=i[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 s=B(t),i=[];if(E(s))try{JSON.parse(D(s,"utf8"))}catch{return{added:[],skipped:[],problems:[`${s} is not valid JSON; leaving it alone`]}}let n=G(s),o=[],a=[];for(let c of r){if(n.mcpServers[c]!==void 0){a.push(c);continue}n.mcpServers[c]=e[c],o.push(c)}if(o.length>0)try{A(s,`${JSON.stringify(n,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:i}}function Ht(e,t=new Set,r=g){let s=B(r),i=[];if(e.length===0||!E(s))return{removed:[],kept:[],problems:i};let n=G(s),o=[],a=[];for(let c of e)if(n.mcpServers[c]!==void 0){if(t.has(c)){a.push(c);continue}delete n.mcpServers[c],o.push(c)}if(o.length>0)try{A(s,`${JSON.stringify(n,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:i}}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),s=Object.keys(r.mcpServers).filter(i=>{let n=r.mcpServers[i];return[n.command,...Array.isArray(n.args)?n.args:[]].map(a=>String(a??"")).some(a=>a===pe||a.startsWith(`${pe}@`))});if(s.length===0)return[];for(let i of s)delete r.mcpServers[i];try{A(t,`${JSON.stringify(r,null,2)}
|
|
10
|
+
`)}catch{return[]}return s}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(s=>typeof s=="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(n){return{entries:[],problems:[`${e} is not valid JSON: ${n instanceof Error?n.message:String(n)}`]}}let s=r?.entries;if(!Array.isArray(s))return{entries:[],problems:[`${e} has no entries array`]};let i=[];for(let n of s){if(typeof n!="object"||n===null||Array.isArray(n))continue;let o=n,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}i.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:i,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,s)=>r.title.localeCompare(s.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 +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-
|
|
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-MXO4OS67.js";import"./chunk-7LA2AMZB.js";import"./chunk-SOWZZCT4.js";import"./chunk-I555QJLZ.js";import"./chunk-UTYFLLSM.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,2 +1,2 @@
|
|
|
1
|
-
import{a as T}from"./chunk-UTYFLLSM.js";import{g as R,j as P}from"./chunk-NIDL55H4.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{g as T,j as R}from"./chunk-SOWZZCT4.js";import{a as P}from"./chunk-UTYFLLSM.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??T(),o=R(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 P(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-
|
|
1
|
+
import{a,b,c}from"./chunk-SDU65XW4.js";import"./chunk-5FIFNXLT.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 c,d as l}from"./chunk-27TRKD65.js";import{
|
|
1
|
+
import{b as c,d as l}from"./chunk-27TRKD65.js";import{a as i,b as r}from"./chunk-I555QJLZ.js";import{H as s}from"./chunk-5FIFNXLT.js";import"./chunk-UTYFLLSM.js";import"./chunk-WOT6VMZA.js";var d=[["/connect","sign in to howtofix.id: approve it in your browser"],["/model","choose which model answers"],["/help","list every command"],["/quit","leave"]],u=[" \u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557"," \u2588\u2588\u2551 \u2588\u2588\u2551\u255A\u2588\u2588\u2557\u2588\u2588\u2554\u255D\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D"," \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2588\u2588\u2588\u2557 "," \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551 \u2588\u2588\u2554\u2588\u2588\u2557 \u2588\u2588\u2554\u2550\u2550\u255D "," \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u255D \u2588\u2588\u2557\u2588\u2588\u2551 "," \u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D "],g=[" _ _ _____ ","| | | | __ __ | ___|","| |_| | \\ \\/ / | |_ ","| _ | > < | _| ","|_| |_| /_/\\_\\ |_| "];function m(){if(process.platform==="win32")return!1;let e=(process.env.LC_ALL||process.env.LC_CTYPE||process.env.LANG||"").toLowerCase();return e===""||e==="c"||e==="posix"||!e.includes("utf-8")&&!e.includes("utf8")?!1:!/ja|ko|zh|_kr|_jp|_cn|_tw|_hk/.test(e)}function h(){return m()?u:g}var _="https://howtofix.id/cli";function p(e){let n=process.env.HOME??"",t=n!==""&&e.startsWith(n)?`~${e.slice(n.length)}`:e,o=t.split("/").filter(Boolean);return o.length>3?`\u2026/${o.slice(-2).join("/")}`:t}function f(e){let n=e.signedIn?d.filter(([t])=>t!=="/connect"):d;return[...h(),"",`${i} ${r} \u2014 a terminal coding agent. Describe the change you want and it reads, edits and runs the code in front of you.`,"",` working in ${p(e.cwd)}`,...e.note?[` session ${e.note}`]:[],"",...e.signedIn?[" already signed in to howtofix.id",""]:[],...n.map(([t,o])=>` ${t.padEnd(11)}${o}`),"",' Or just start typing. Every message goes to the model; anything beginning with "/" stays local.'].join(`
|
|
2
2
|
`)}function v(){return[{value:"connect",label:"Sign in to howtofix.id",description:"approve the sign-in in your browser"},{value:"ready",label:"I have a key \u2014 just give me the prompt",description:"drops you at the prompt; run /connect whenever you like"},{value:"release",label:"What's in this release",description:`opens the ${r} notes in your browser`}]}async function E(e,n,t){c(s).welcomeSeen||(l(s),t(`welcome to ${i}`,f(e)),!e.signedIn&&await new Promise(o=>{n("First run \u2014 how do you want to begin?",v(),a=>{a==="connect"&&e.runSlash("/connect"),a==="release"&&e.openExternal(_),o()},()=>o())}))}export{E as maybeShowWelcome};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{spawnSync as d}from"node:child_process";import{accessSync as b,constants as l}from"node:fs";import{join as c}from"node:path";function u(e){try{return b(e,l.X_OK),!0}catch{return!1}}function x(e=process.platform,r=process.env.PATH??""){let n=r.split(":").filter(Boolean),o=t=>n.map(i=>c(i,t)).find(u);if(e==="linux"){let t=o("bwrap");return t&&d(t,["--ro-bind","/","/","--","true"],{stdio:"ignore",timeout:3e3}).status===0?"bubblewrap":void 0}if(e==="darwin")return o("sandbox-exec")?"seatbelt":void 0}function a(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function s(e,r){return e==="bubblewrap"?["bwrap","--die-with-parent","--new-session","--ro-bind","/","/","--dev","/dev","--proc","/proc","--tmpfs","/tmp","--bind",r.cwd,r.cwd,"--bind",r.agentDir,r.agentDir,"--chdir",r.cwd,"--",...r.argv]:["sandbox-exec","-p",["(version 1)","(deny default)","(allow process*)","(allow signal)","(allow sysctl-read)","(allow mach-lookup)","(allow network*)","(allow file-read*)",`(allow file-write* (subpath "${a(r.cwd)}") (subpath "${a(r.agentDir)}") (subpath "/tmp") (subpath "/private/tmp") (subpath "/private/var/folders"))`,""].join(`
|
|
2
|
+
`),...r.argv]}function g(e){return e==="bubblewrap"?"sandbox: bubblewrap \u2014 project writable, rest of the filesystem read-only":"sandbox: seatbelt \u2014 project writable, rest of the filesystem read-only"}function m(e,r){let n=d(s(e,r)[0],s(e,r).slice(1),{stdio:"inherit",env:{...process.env,HOWTOCODE_SANDBOXED:"1"}});return n.error?(console.error(`sandbox: could not start ${e}: ${n.error.message}`),1):n.status??1}export{x as a,s as b,g as c,m as d};
|
|
@@ -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-
|
|
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-GNV6G3JW.js";import{b as xe}from"./chunk-27TRKD65.js";import{c as ue}from"./chunk-MXO4OS67.js";import{h as pe,l as fe}from"./chunk-CJLCMZKZ.js";import{t as me}from"./chunk-ZJL4OEXX.js";import"./chunk-7LA2AMZB.js";import"./chunk-SOWZZCT4.js";import{b as G,c as ie,d as ae}from"./chunk-I555QJLZ.js";import{H as S,K as de,v as ce,w as le}from"./chunk-5FIFNXLT.js";import"./chunk-UTYFLLSM.js";import"./chunk-MVVEYKN6.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}
|