freecode-sh 0.1.0-alpha.12 → 0.1.0-alpha.15
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 +9 -4
- package/freecode.mjs +127 -340
- package/install.sh +641 -0
- package/package.json +10 -22
- package/THIRD_PARTY_NOTICES.md +0 -115
- package/engine.manifest.json +0 -8
- package/release-manifest.json +0 -38
- package/standalone.tsx +0 -28
package/freecode.mjs
CHANGED
|
@@ -1,342 +1,129 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
process.env.FREECODE_ALPHA_BUILD = 'true'
|
|
3
|
-
process.env.FREECODE_ACCOUNT_AUTH_ENABLED = 'true'
|
|
4
|
-
process.env.FREECODE_RELEASE_VERSION = "0.1.0-alpha.12"
|
|
5
|
-
import{createRequire as Cr}from"node:module";var ar=Object.create;var{getPrototypeOf:or,defineProperty:Yu,getOwnPropertyNames:Fr}=Object;var _r=Object.prototype.hasOwnProperty;function Er(D){return this[D]}var wr,dr,ju=(D,u,e)=>{var n=D!=null&&typeof D==="object";if(n){var r=u?wr??=new WeakMap:dr??=new WeakMap,t=r.get(D);if(t)return t}e=D!=null?ar(or(D)):{};let c=u||!D||!D.__esModule?Yu(e,"default",{value:D,enumerable:!0}):e;for(let i of Fr(D))if(!_r.call(c,i))Yu(c,i,{get:Er.bind(D,i),enumerable:!0});if(n)r.set(D,c);return c};var L=(D,u)=>()=>(u||D((u={exports:{}}).exports,u),u.exports);var uu=Cr(import.meta.url);var Ge=L((ws,Xe)=>{class We{constructor(D,u,e){this.etaBufferLength=D||100,this.valueBuffer=[e],this.timeBuffer=[u],this.eta="0"}update(D,u,e){this.valueBuffer.push(u),this.timeBuffer.push(D),this.calculate(e-u)}getTime(){return this.eta}calculate(D){let u=this.valueBuffer.length,e=Math.min(this.etaBufferLength,u),n=this.valueBuffer[u-1]-this.valueBuffer[u-e],r=this.timeBuffer[u-1]-this.timeBuffer[u-e],t=n/r;this.valueBuffer=this.valueBuffer.slice(-this.etaBufferLength),this.timeBuffer=this.timeBuffer.slice(-this.etaBufferLength);let c=Math.ceil(D/t/1000);if(isNaN(c))this.eta="NULL";else if(!isFinite(c))this.eta="INF";else if(c>1e7)this.eta="INF";else if(c<0)this.eta=0;else this.eta=c}}Xe.exports=We});var mu=L((ds,Qe)=>{var iD=uu("readline");class Ve{constructor(D){this.stream=D,this.linewrap=!0,this.dy=0}cursorSave(){if(!this.stream.isTTY)return;this.stream.write("\x1B7")}cursorRestore(){if(!this.stream.isTTY)return;this.stream.write("\x1B8")}cursor(D){if(!this.stream.isTTY)return;if(D)this.stream.write("\x1B[?25h");else this.stream.write("\x1B[?25l")}cursorTo(D=null,u=null){if(!this.stream.isTTY)return;iD.cursorTo(this.stream,D,u)}cursorRelative(D=null,u=null){if(!this.stream.isTTY)return;this.dy=this.dy+u,iD.moveCursor(this.stream,D,u)}cursorRelativeReset(){if(!this.stream.isTTY)return;iD.moveCursor(this.stream,0,-this.dy),iD.cursorTo(this.stream,0,null),this.dy=0}clearRight(){if(!this.stream.isTTY)return;iD.clearLine(this.stream,1)}clearLine(){if(!this.stream.isTTY)return;iD.clearLine(this.stream,0)}clearBottom(){if(!this.stream.isTTY)return;iD.clearScreenDown(this.stream)}newline(){this.stream.write(`
|
|
6
|
-
`),this.dy++}write(D,u=!1){if(this.linewrap===!0&&u===!1)this.stream.write(D.substr(0,this.getWidth()));else this.stream.write(D)}lineWrapping(D){if(!this.stream.isTTY)return;if(this.linewrap=D,D)this.stream.write("\x1B[?7h");else this.stream.write("\x1B[?7l")}isTTY(){return this.stream.isTTY===!0}getWidth(){return this.stream.columns||(this.stream.isTTY?80:200)}}Qe.exports=Ve});var Pe=L((Cs,Ue)=>{Ue.exports=({onlyFirst:D=!1}={})=>{let u=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"].join("|");return new RegExp(u,D?void 0:"g")}});var Dn=L((hs,ge)=>{var Rt=Pe();ge.exports=(D)=>typeof D==="string"?D.replace(Rt(),""):D});var en=L((ms,lu)=>{var un=(D)=>{if(Number.isNaN(D))return!1;if(D>=4352&&(D<=4447||D===9001||D===9002||11904<=D&&D<=12871&&D!==12351||12880<=D&&D<=19903||19968<=D&&D<=42182||43360<=D&&D<=43388||44032<=D&&D<=55203||63744<=D&&D<=64255||65040<=D&&D<=65049||65072<=D&&D<=65131||65281<=D&&D<=65376||65504<=D&&D<=65510||110592<=D&&D<=110593||127488<=D&&D<=127569||131072<=D&&D<=262141))return!0;return!1};lu.exports=un;lu.exports.default=un});var rn=L((ls,nn)=>{nn.exports=function(){return/\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F|\uD83D\uDC68(?:\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68\uD83C\uDFFB|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|[\u2695\u2696\u2708]\uFE0F|\uD83D[\uDC66\uDC67]|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708])\uFE0F|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C[\uDFFB-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)\uD83C\uDFFB|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB\uDFFC])|\uD83D\uDC69(?:\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB-\uDFFD])|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|(?:(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)\uFE0F|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\u200D[\u2640\u2642])|\uD83C\uDFF4\u200D\u2620)\uFE0F|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF4\uD83C\uDDF2|\uD83C\uDDF6\uD83C\uDDE6|[#\*0-9]\uFE0F\u20E3|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83D\uDC69(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270A-\u270D]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC70\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDCAA\uDD74\uDD7A\uDD90\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD36\uDDB5\uDDB6\uDDBB\uDDD2-\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5\uDEEB\uDEEC\uDEF4-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g}});var bu=L((Bs,Bu)=>{var Yt=Dn(),jt=en(),Ht=rn(),tn=(D)=>{if(typeof D!=="string"||D.length===0)return 0;if(D=Yt(D),D.length===0)return 0;D=D.replace(Ht()," ");let u=0;for(let e=0;e<D.length;e++){let n=D.codePointAt(e);if(n<=31||n>=127&&n<=159)continue;if(n>=768&&n<=879)continue;if(n>65535)e++;u+=jt(n)?2:1}return u};Bu.exports=tn;Bu.exports.default=tn});var vu=L((bs,cn)=>{cn.exports=function(u,e,n){if(e.autopadding!==!0)return u;function r(t,c){return(e.autopaddingChar+t).slice(-c)}switch(n){case"percentage":return r(u,3);default:return u}}});var Au=L((vs,sn)=>{sn.exports=function(u,e){let n=Math.round(u*e.barsize),r=e.barsize-n;return e.barCompleteString.substr(0,n)+e.barGlue+e.barIncompleteString.substr(0,r)}});var $u=L((As,fn)=>{fn.exports=function(u,e,n){function r(c){if(n)return n*Math.round(c/n);else return c}function t(c){return(e.autopaddingChar+c).slice(-2)}if(u>3600)return t(Math.floor(u/3600))+"h"+t(r(u%3600/60))+"m";else if(u>60)return t(Math.floor(u/60))+"m"+t(r(u%60))+"s";else if(u>10)return t(r(u))+"s";else return t(u)+"s"}});var xu=L(($s,an)=>{var Jt=bu(),Kt=vu(),Wt=Au(),Xt=$u();an.exports=function(u,e,n){let r=u.format,t=u.formatTime||Xt,c=u.formatValue||Kt,i=u.formatBar||Wt,s=Math.floor(e.progress*100)+"",f=e.stopTime||Date.now(),a=Math.round((f-e.startTime)/1000),o=Object.assign({},n,{bar:i(e.progress,u),percentage:c(s,u,"percentage"),total:c(e.total,u,"total"),value:c(e.value,u,"value"),eta:c(e.eta,u,"eta"),eta_formatted:t(e.eta,u,5),duration:c(a,u,"duration"),duration_formatted:t(a,u,1)});r=r.replace(/\{(\w+)\}/g,function(b,T){if(typeof o[T]<"u")return o[T];return b});let l=Math.max(0,e.maxWidth-Jt(r)-2),A=Math.floor(l/2);switch(u.align){case"right":r=l>0?" ".repeat(l)+r:r;break;case"center":r=A>0?" ".repeat(A)+r:r;break;case"left":default:break}return r}});var jD=L((xs,on)=>{function y(D,u){if(typeof D>"u"||D===null)return u;else return D}on.exports={parse:function(u,e){let n={},r=Object.assign({},e,u);return n.throttleTime=1000/y(r.fps,10),n.stream=y(r.stream,process.stderr),n.terminal=y(r.terminal,null),n.clearOnComplete=y(r.clearOnComplete,!1),n.stopOnComplete=y(r.stopOnComplete,!1),n.barsize=y(r.barsize,40),n.align=y(r.align,"left"),n.hideCursor=y(r.hideCursor,!1),n.linewrap=y(r.linewrap,!1),n.barGlue=y(r.barGlue,""),n.barCompleteChar=y(r.barCompleteChar,"="),n.barIncompleteChar=y(r.barIncompleteChar,"-"),n.format=y(r.format,"progress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}"),n.formatTime=y(r.formatTime,null),n.formatValue=y(r.formatValue,null),n.formatBar=y(r.formatBar,null),n.etaBufferLength=y(r.etaBuffer,10),n.etaAsynchronousUpdate=y(r.etaAsynchronousUpdate,!1),n.progressCalculationRelative=y(r.progressCalculationRelative,!1),n.synchronousUpdate=y(r.synchronousUpdate,!0),n.noTTYOutput=y(r.noTTYOutput,!1),n.notTTYSchedule=y(r.notTTYSchedule,2000),n.emptyOnZero=y(r.emptyOnZero,!1),n.forceRedraw=y(r.forceRedraw,!1),n.autopadding=y(r.autopadding,!1),n.gracefulExit=y(r.gracefulExit,!1),n},assignDerivedOptions:function(u){return u.barCompleteString=u.barCompleteChar.repeat(u.barsize+1),u.barIncompleteString=u.barIncompleteChar.repeat(u.barsize+1),u.autopaddingChar=u.autopadding?y(u.autopaddingChar," "):"",u}}});var yu=L((ys,_n)=>{var Fn=Ge(),Gt=mu(),Vt=xu(),Qt=jD(),Ut=uu("events");_n.exports=class extends Ut{constructor(u){super();this.options=Qt.assignDerivedOptions(u),this.terminal=this.options.terminal?this.options.terminal:new Gt(this.options.stream),this.value=0,this.startValue=0,this.total=100,this.lastDrawnString=null,this.startTime=null,this.stopTime=null,this.lastRedraw=Date.now(),this.eta=new Fn(this.options.etaBufferLength,0,0),this.payload={},this.isActive=!1,this.formatter=typeof this.options.format==="function"?this.options.format:Vt}render(u=!1){let e={progress:this.getProgress(),eta:this.eta.getTime(),startTime:this.startTime,stopTime:this.stopTime,total:this.total,value:this.value,maxWidth:this.terminal.getWidth()};if(this.options.etaAsynchronousUpdate)this.updateETA();let n=this.formatter(this.options,e,this.payload);if(u||this.options.forceRedraw||this.options.noTTYOutput&&!this.terminal.isTTY()||this.lastDrawnString!=n)this.emit("redraw-pre"),this.terminal.cursorTo(0,null),this.terminal.write(n),this.terminal.clearRight(),this.lastDrawnString=n,this.lastRedraw=Date.now(),this.emit("redraw-post")}start(u,e,n){this.value=e||0,this.total=typeof u<"u"&&u>=0?u:100,this.startValue=e||0,this.payload=n||{},this.startTime=Date.now(),this.stopTime=null,this.lastDrawnString="",this.eta=new Fn(this.options.etaBufferLength,this.startTime,this.value),this.isActive=!0,this.emit("start",u,e)}stop(){this.isActive=!1,this.stopTime=Date.now(),this.emit("stop",this.total,this.value)}update(u,e={}){if(typeof u==="number")this.value=u,this.eta.update(Date.now(),u,this.total);let n=(typeof u==="object"?u:e)||{};this.emit("update",this.total,this.value);for(let r in n)this.payload[r]=n[r];if(this.value>=this.getTotal()&&this.options.stopOnComplete)this.stop()}getProgress(){let u=this.value/this.total;if(this.options.progressCalculationRelative)u=(this.value-this.startValue)/(this.total-this.startValue);if(isNaN(u))u=this.options&&this.options.emptyOnZero?0:1;return u=Math.min(Math.max(u,0),1),u}increment(u=1,e={}){if(typeof u==="object")this.update(this.value+1,u);else this.update(this.value+u,e)}getTotal(){return this.total}setTotal(u){if(typeof u<"u"&&u>=0)this.total=u}updateETA(){this.eta.update(Date.now(),this.value,this.total)}}});var wn=L((zs,En)=>{var Pt=yu(),gt=jD();En.exports=class extends Pt{constructor(u,e){super(gt.parse(u,e));if(this.timer=null,this.options.noTTYOutput&&this.terminal.isTTY()===!1)this.options.synchronousUpdate=!1;this.schedulingRate=this.terminal.isTTY()?this.options.throttleTime:this.options.notTTYSchedule,this.sigintCallback=null}render(){if(this.timer)clearTimeout(this.timer),this.timer=null;if(super.render(),this.options.noTTYOutput&&this.terminal.isTTY()===!1)this.terminal.newline();this.timer=setTimeout(this.render.bind(this),this.schedulingRate)}update(u,e){if(!this.timer)return;if(super.update(u,e),this.options.synchronousUpdate&&this.lastRedraw+this.options.throttleTime*2<Date.now())this.render()}start(u,e,n){if(this.options.noTTYOutput===!1&&this.terminal.isTTY()===!1)return;if(this.sigintCallback===null&&this.options.gracefulExit)this.sigintCallback=this.stop.bind(this),process.once("SIGINT",this.sigintCallback),process.once("SIGTERM",this.sigintCallback);if(this.terminal.cursorSave(),this.options.hideCursor===!0)this.terminal.cursor(!1);if(this.options.linewrap===!1)this.terminal.lineWrapping(!1);super.start(u,e,n),this.render()}stop(){if(!this.timer)return;if(this.sigintCallback)process.removeListener("SIGINT",this.sigintCallback),process.removeListener("SIGTERM",this.sigintCallback),this.sigintCallback=null;if(this.render(),super.stop(),clearTimeout(this.timer),this.timer=null,this.options.hideCursor===!0)this.terminal.cursor(!0);if(this.options.linewrap===!1)this.terminal.lineWrapping(!0);if(this.terminal.cursorRestore(),this.options.clearOnComplete)this.terminal.cursorTo(0,null),this.terminal.clearLine();else this.terminal.newline()}}});var Cn=L((Ts,dn)=>{var Dc=mu(),uc=yu(),ec=jD(),nc=uu("events");dn.exports=class extends nc{constructor(u,e){super();this.bars=[],this.options=ec.parse(u,e),this.options.synchronousUpdate=!1,this.terminal=this.options.terminal?this.options.terminal:new Dc(this.options.stream),this.timer=null,this.isActive=!1,this.schedulingRate=this.terminal.isTTY()?this.options.throttleTime:this.options.notTTYSchedule,this.loggingBuffer=[],this.sigintCallback=null}create(u,e,n,r={}){let t=new uc(Object.assign({},this.options,{terminal:this.terminal},r));if(this.bars.push(t),this.options.noTTYOutput===!1&&this.terminal.isTTY()===!1)return t;if(this.sigintCallback===null&&this.options.gracefulExit)this.sigintCallback=this.stop.bind(this),process.once("SIGINT",this.sigintCallback),process.once("SIGTERM",this.sigintCallback);if(!this.isActive){if(this.options.hideCursor===!0)this.terminal.cursor(!1);if(this.options.linewrap===!1)this.terminal.lineWrapping(!1);this.timer=setTimeout(this.update.bind(this),this.schedulingRate)}return this.isActive=!0,t.start(u,e,n),this.emit("start"),t}remove(u){let e=this.bars.indexOf(u);if(e<0)return!1;return this.bars.splice(e,1),this.update(),this.terminal.newline(),this.terminal.clearBottom(),!0}update(){if(this.timer)clearTimeout(this.timer),this.timer=null;if(this.emit("update-pre"),this.terminal.cursorRelativeReset(),this.emit("redraw-pre"),this.loggingBuffer.length>0){this.terminal.clearLine();while(this.loggingBuffer.length>0)this.terminal.write(this.loggingBuffer.shift(),!0)}for(let u=0;u<this.bars.length;u++){if(u>0)this.terminal.newline();this.bars[u].render()}if(this.emit("redraw-post"),this.options.noTTYOutput&&this.terminal.isTTY()===!1)this.terminal.newline(),this.terminal.newline();if(this.timer=setTimeout(this.update.bind(this),this.schedulingRate),this.emit("update-post"),this.options.stopOnComplete&&!this.bars.find((u)=>u.isActive))this.stop()}stop(){if(clearTimeout(this.timer),this.timer=null,this.sigintCallback)process.removeListener("SIGINT",this.sigintCallback),process.removeListener("SIGTERM",this.sigintCallback),this.sigintCallback=null;if(this.isActive=!1,this.options.hideCursor===!0)this.terminal.cursor(!0);if(this.options.linewrap===!1)this.terminal.lineWrapping(!0);if(this.terminal.cursorRelativeReset(),this.emit("stop-pre-clear"),this.options.clearOnComplete)this.terminal.clearBottom();else{for(let u=0;u<this.bars.length;u++){if(u>0)this.terminal.newline();this.bars[u].render(),this.bars[u].stop()}this.terminal.newline()}this.emit("stop")}log(u){this.loggingBuffer.push(u)}}});var mn=L((Os,hn)=>{hn.exports={format:"progress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}",barCompleteChar:"=",barIncompleteChar:"-"}});var Bn=L((Ls,ln)=>{ln.exports={format:" {bar} {percentage}% | ETA: {eta}s | {value}/{total}",barCompleteChar:"█",barIncompleteChar:"░"}});var vn=L((ks,bn)=>{bn.exports={format:" \x1B[90m{bar}\x1B[0m {percentage}% | ETA: {eta}s | {value}/{total}",barCompleteChar:"█",barIncompleteChar:"░"}});var $n=L((Ns,An)=>{An.exports={format:" {bar}■ {percentage}% | ETA: {eta}s | {value}/{total}",barCompleteChar:"■",barIncompleteChar:" "}});var yn=L((Is,xn)=>{var rc=mn(),tc=Bn(),cc=vn(),ic=$n();xn.exports={legacy:rc,shades_classic:tc,shades_grey:cc,rect:ic}});var On=L((Ms,Tn)=>{var zn=wn(),sc=Cn(),fc=yn(),ac=xu(),oc=vu(),Fc=Au(),_c=$u();Tn.exports={Bar:zn,SingleBar:zn,MultiBar:sc,Presets:fc,Format:{Formatter:ac,BarFormat:Fc,ValueFormat:oc,TimeFormat:_c}}});import{spawn as Qn,spawnSync as nD}from"node:child_process";import{existsSync as mD,readFileSync as Pc,realpathSync as gc}from"node:fs";import{dirname as g,isAbsolute as Di,join as uD,resolve as lD}from"node:path";import{fileURLToPath as UD}from"node:url";import{stdout as C}from"node:process";function Hu(D=process.env){let u=D.FREECODE_DEMO_ADS==="true"||D.FREECODE_SPONSOR_DEBUG==="true";if(D.FREECODE_MONETIZATION_UI==="false"||D.FREECODE_SPONSOR_UI==="false"||!u)return;return{demo:!0,label:"SPONSORED · DEMO",brandName:"Vercel",title:"Preview every change",body:"Create fast preview deployments for this project.",category:"Hosting",cta:"Explore previews",faviconUrl:"https://www.google.com/s2/favicons?domain_url=https%3A%2F%2Fvercel.com&sz=64",url:"https://vercel.com",cards:[{label:"SPONSORED · DEMO",brandName:"Vercel",title:"Preview every change",body:"Create fast preview deployments for this project.",category:"Hosting",cta:"Explore previews",faviconUrl:"https://www.google.com/s2/favicons?domain_url=https%3A%2F%2Fvercel.com&sz=64",url:"https://vercel.com"},{label:"SPONSORED · DEMO",brandName:"Neon",title:"Postgres that scales with you",body:"Branch a serverless database for every environment.",category:"Database",cta:"Explore Postgres",faviconUrl:"https://www.google.com/s2/favicons?domain_url=https%3A%2F%2Fneon.tech&sz=64",url:"https://neon.tech"},{label:"SPONSORED · DEMO",brandName:"Resend",title:"Email your users reliably",body:"Add a developer-friendly transactional email API.",category:"Email",cta:"Explore email",faviconUrl:"https://www.google.com/s2/favicons?domain_url=https%3A%2F%2Fresend.com&sz=64",url:"https://resend.com"}]}}import{chmodSync as Ku,existsSync as lr,lstatSync as Wu,mkdirSync as Br,readFileSync as br,renameSync as vr,rmSync as nu,writeFileSync as Ar}from"node:fs";import{homedir as $r}from"node:os";import{dirname as xr,join as ru,resolve as yr}from"node:path";var hr=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;function G(D){if(typeof D!=="string")return;let u=D.trim().match(hr);if(!u)return;let e=u[4]?u[4].split(".").map((n)=>({value:n,numeric:/^\d+$/.test(n)})):[];if(e.some(({numeric:n,value:r})=>n&&r.length>1&&r.startsWith("0")))return;return Object.freeze({value:D.trim(),major:u[1],minor:u[2],patch:u[3],prerelease:e})}function eu(D,u){let e=typeof D==="string"?G(D):D,n=typeof u==="string"?G(u):u;if(!e||!n)throw TypeError("compareVersions requires valid semantic versions");for(let t of["major","minor","patch"]){let c=Ju(e[t],n[t]);if(c!==0)return c}if(e.prerelease.length===0&&n.prerelease.length===0)return 0;if(e.prerelease.length===0)return 1;if(n.prerelease.length===0)return-1;let r=Math.max(e.prerelease.length,n.prerelease.length);for(let t=0;t<r;t+=1){let c=e.prerelease[t],i=n.prerelease[t];if(!c)return-1;if(!i)return 1;if(c.numeric&&i.numeric){let s=Ju(c.value,i.value);if(s!==0)return s;continue}if(c.numeric!==i.numeric)return c.numeric?-1:1;if(c.value<i.value)return-1;if(c.value>i.value)return 1}return 0}function Ju(D,u){if(D.length<u.length)return-1;if(D.length>u.length)return 1;if(D<u)return-1;if(D>u)return 1;return 0}function AD({environment:D=process.env,platform:u=process.platform}={}){let e=G(D.FREECODE_RELEASE_VERSION)?.value||"0.0.0";return Object.freeze({version:e,platform:u,deviceLabel:mr(u)})}function ND(D=AD()){return Object.freeze({"x-freecode-version":D.version,...D.platform?{"x-freecode-platform":D.platform}:{},...D.deviceLabel?{"x-freecode-device-label":D.deviceLabel}:{}})}function mr(D){if(D==="darwin")return"Free Code on macOS";if(D==="win32")return"Free Code on Windows";if(D==="linux")return"Free Code on Linux";return"Free Code terminal"}var Xu=1,zr=8192;class O extends Error{constructor(D,{status:u=0,retryAfterSeconds:e,details:n}={}){super(D);if(this.name="AlphaAuthClientError",this.code=D,this.status=u,e!==void 0)this.retryAfterSeconds=e;if(n!==void 0)this.details=n}}function Tr({homeDirectory:D=$r(),filePath:u,platform:e=process.platform,environment:n=process.env}={}){let r=e==="win32"&&n.APPDATA?n.APPDATA:ru(D,".config"),t=yr(u||ru(r,"freecode","alpha-session.json")),c=xr(t);function i(){if(!lr(t))return;try{if(Wu(t).isSymbolicLink())throw new O("unsafe_session_file");let a=JSON.parse(br(t,"utf8"));if(a?.version!==Xu||!tu(a.sessionToken))throw new O("invalid_session_file");return a.sessionToken}catch(a){if(a instanceof O)throw a;throw new O("invalid_session_file")}}function s(a){if(!tu(a))throw new O("invalid_session_token");if(Br(c,{recursive:!0,mode:448}),Wu(c).isSymbolicLink())throw new O("unsafe_session_directory");if(e!=="win32")Ku(c,448);let o=ru(c,`.alpha-session.${process.pid}.tmp`);try{if(Ar(o,`${JSON.stringify({version:Xu,sessionToken:a})}
|
|
7
|
-
`,{encoding:"utf8",mode:384,flag:"wx"}),e==="win32")nu(t,{force:!0});if(vr(o,t),e!=="win32")Ku(t,384)}finally{nu(o,{force:!0})}}function f(){nu(t,{force:!0})}return{path:t,load:i,save:s,clear:f}}function Uu({baseUrl:D=process.env.FREECODE_API_URL||"https://api.freecode.sh",fetchImpl:u=globalThis.fetch,sessionStore:e=Tr(),sleep:n=Or,openUrl:r,clientIdentity:t=AD()}={}){if(typeof u!=="function")throw new O("fetch_required");let c=kr(D);async function i(w,{method:h="GET",body:B,sessionToken:d,signal:x}={}){let _;try{_=await u(`${c}${w}`,{method:h,signal:x,headers:{accept:"application/json",...B?{"content-type":"application/json"}:{},...d?{authorization:`Bearer ${d}`}:{},...ND(t)},...B?{body:JSON.stringify(B)}:{}})}catch(E){if(E?.name==="AbortError")throw E;throw new O("auth_network_unavailable")}if(!_.ok){let E={};try{E=await _.clone().json()}catch{}let v=Qu(E?.error)||(_.status===401?"invalid_session":"auth_request_failed"),F=$D(E?.retry_after_seconds)||$D(_.headers?.get?.("retry-after"));throw new O(v,{status:_.status,retryAfterSeconds:F,details:{...typeof E?.reason==="string"?{reason:E.reason}:{},...typeof E?.message==="string"?{message:E.message}:{},...typeof E?.minimum_supported_version==="string"?{minimumSupportedVersion:E.minimum_supported_version}:{},...typeof E?.update_command==="string"?{updateCommand:E.update_command}:{}}})}return _}async function s(w,h={}){let B=await i(w,h),d={};try{d=await B.json()}catch{}return d}async function f(w,{method:h="GET",body:B,signal:d}={}){let x=e.load();if(!x)throw new O("authentication_required",{status:401});try{return await i(w,{method:h,body:B,sessionToken:x,signal:d})}catch(_){if(_ instanceof O&&_.status===401)e.clear();throw _}}async function a({signal:w}={}){let h=await s("/v1/auth/device/start",{method:"POST",signal:w}),B=J(h.deviceCode||h.device_code),d=J(h.userCode||h.user_code),x=cu(h.verificationUri||h.verification_uri),_=cu(h.verificationUriComplete||h.verification_uri_complete),E=$D(h.intervalSeconds||h.interval)||5,v=Pu(h.expiresAt||h.expires_at);if(!B||!d||!x)throw new O("invalid_auth_response");return{deviceCode:B,userCode:d,verificationUri:x,verificationUriComplete:_,intervalSeconds:E,expiresAt:v}}async function o(w,{signal:h}={}){if(!J(w))throw new O("device_code_required");let B=await s("/v1/auth/device/poll",{method:"POST",body:{device_code:w},signal:h}),d=J(B.status);if(d==="waiting")return{status:d,intervalSeconds:$D(B.intervalSeconds||B.interval)||5,slowDown:B.slowDown===!0||B.slow_down===!0};if(d==="denied")return{status:d,reason:Qu(B.reason)||"github_access_denied"};if(d==="expired")return{status:d,reason:"device_code_expired"};if(d==="authenticated"){let x=J(B.sessionToken||B.session_token),_=Gu(B.user);if(!tu(x)||!_)throw new O("invalid_auth_response");return{status:d,sessionToken:x,user:_}}throw new O("invalid_auth_response")}async function l({clearInvalid:w=!0,signal:h}={}){let B=e.load();if(!B)return;try{let d=await s("/v1/auth/session",{sessionToken:B,signal:h}),x=Gu(d.user);if(!x)throw new O("invalid_auth_response");return{sessionToken:B,user:x}}catch(d){if(w&&d instanceof O&&d.status===401)e.clear();throw d}}async function A(w,{signal:h}={}){if(!w||typeof w!=="object"||Array.isArray(w))throw new O("invalid_messages_request");return f("/v1/alpha/messages",{method:"POST",body:w,signal:h})}async function b(w,{signal:h}={}){if(!w||typeof w!=="object"||Array.isArray(w))throw new O("invalid_sidebar_recommendation_request");let B=await f("/v1/alpha/sidebar-recommendation",{method:"POST",body:w,signal:h});try{return await B.json()}catch{throw new O("invalid_sidebar_recommendation_response")}}async function T({signal:w}={}){let h=e.load();if(!h)return{ok:!0,remote:!1};let B=!1;try{await s("/v1/auth/logout",{method:"POST",sessionToken:h,signal:w}),B=!0}catch(d){if(d?.name==="AbortError")throw d}finally{e.clear()}return{ok:!0,remote:B}}async function eD({onState:w=()=>{},openVerificationUrl:h=!0,signal:B}={}){w({kind:"welcome"});try{let d=await a({signal:B}),x={userCode:d.userCode,verificationUri:d.verificationUri,...d.expiresAt?{expiresAt:d.expiresAt}:{}};if(w({kind:"device_code",...x}),h&&typeof r==="function")await r(d.verificationUriComplete||d.verificationUri);let _=d.intervalSeconds;while(!0){await n(_*1000,B);let E=await o(d.deviceCode,{signal:B});if(E.status==="waiting"){_=E.slowDown?Math.max(_+5,E.intervalSeconds):E.intervalSeconds,w({kind:"waiting",...x});continue}if(E.status==="denied"){let F={kind:"denied",reason:E.reason};return w(F),F}if(E.status==="expired"){let F={kind:"error",code:E.reason,recoverable:!0};return w(F),F}e.save(E.sessionToken);let v={kind:"authenticated",user:E.user};return w(v),v}}catch(d){if(d?.name==="AbortError")throw d;let x={kind:"error",code:d instanceof O?d.code:"auth_failed",recoverable:!0};return w(x),x}}return{startDeviceFlow:a,pollDeviceFlow:o,currentSession:l,authenticate:eD,logout:T,messages:A,sidebarRecommendation:b,sessionStore:e}}function Gu(D){let u=J(D?.id),e=$D(D?.github?.id),n=Lr(D?.github?.login),r=D?.tier==="ultra"?"ultra":D?.tier==="free"?"free":void 0,t=Pu(D?.expiresAt||D?.expires_at);if(!u||!e||!n||!r||!t)return;let c=cu(D?.github?.avatarUrl||D?.github?.avatar_url);return{id:u,github:{id:e,login:n,...c?{avatarUrl:c}:{}},tier:r,expiresAt:t}}function Or(D,u){return new Promise((e,n)=>{if(u?.aborted)return n(Vu());let r=setTimeout(t,D);function t(){u?.removeEventListener("abort",c),e()}function c(){clearTimeout(r),u?.removeEventListener("abort",c),n(Vu())}u?.addEventListener("abort",c,{once:!0})})}function Vu(){let D=Error("aborted");return D.name="AbortError",D}function tu(D){return typeof D==="string"&&D.length>0&&D.length<=zr&&!/\s/.test(D)}function J(D){return typeof D==="string"&&D.trim()?D.trim():""}function $D(D){let u=Number(D);return Number.isSafeInteger(u)&&u>0?u:void 0}function Lr(D){let u=J(D);return u&&/^[a-zA-Z0-9-]{1,100}$/.test(u)?u:void 0}function Qu(D){let u=J(D);return u&&/^[a-z0-9_]{1,64}$/.test(u)?u:void 0}function Pu(D){let u=J(D);return u&&Number.isFinite(Date.parse(u))?u:void 0}function cu(D){let u=J(D);if(!u)return;try{let e=new URL(u);return e.protocol==="https:"?e.toString():void 0}catch{return}}function kr(D){let u=J(D).replace(/\/$/,"");try{let e=new URL(u);if(e.username||e.password||e.search||e.hash)throw Error("unsafe url");if(e.protocol==="https:"||e.protocol==="http:"&&["localhost","127.0.0.1","[::1]"].includes(e.hostname))return e.toString().replace(/\/$/,"")}catch{}throw new O("invalid_api_url")}import{chmodSync as gu,existsSync as Nr,lstatSync as De,mkdirSync as Ir,readFileSync as Mr,renameSync as pr,rmSync as iu,writeFileSync as qr}from"node:fs";import{homedir as Sr}from"node:os";import{dirname as Zr,join as su,resolve as Rr}from"node:path";var ue=1,Yr=8192;class Q extends Error{constructor(D){super(D);this.name="CredentialStoreError",this.code=D}}function ne({homeDirectory:D=Sr(),filePath:u,platform:e=process.platform,environment:n=process.env,secrets:r=globalThis.Bun?.secrets}={}){let t=jr({homeDirectory:D,filePath:u,platform:e,environment:n});if(!r||n.FREECODE_DISABLE_KEYCHAIN==="true")return t;let c=Object.freeze({service:"sh.freecode.cli",name:"account-session"});return Object.freeze({kind:"os-keychain",fallbackPath:t.path,async load(){try{let s=await r.get(c);if(s!==null&&!ID(s))throw new Q("invalid_keychain_credential");if(s)return s}catch{}let i=t.load();if(!i)return;try{await ee(r,c,i),t.clear()}catch{}return i},async save(i){if(!ID(i))throw new Q("invalid_session_token");try{await ee(r,c,i),t.clear()}catch{t.save(i)}},async clear(){try{await r.delete(c)}catch{}t.clear()}})}function jr({homeDirectory:D,filePath:u,platform:e,environment:n}){let r=e==="win32"&&n.APPDATA?n.APPDATA:su(D,".config"),t=Rr(u||su(r,"freecode","session.json")),c=Zr(t);function i(){if(!Nr(t))return;try{if(De(t).isSymbolicLink())throw new Q("unsafe_credential_file");let a=JSON.parse(Mr(t,"utf8"));if(a?.version!==ue||!ID(a.sessionToken))throw new Q("invalid_credential_file");return a.sessionToken}catch(a){if(a instanceof Q)throw a;throw new Q("invalid_credential_file")}}function s(a){if(!ID(a))throw new Q("invalid_session_token");if(Ir(c,{recursive:!0,mode:448}),De(c).isSymbolicLink())throw new Q("unsafe_credential_directory");if(e!=="win32")gu(c,448);let o=su(c,`.session.${process.pid}.${Date.now()}.tmp`);try{if(qr(o,`${JSON.stringify({version:ue,sessionToken:a})}
|
|
8
|
-
`,{encoding:"utf8",mode:384,flag:"wx"}),e==="win32")iu(t,{force:!0});if(pr(o,t),e!=="win32")gu(t,384)}finally{iu(o,{force:!0})}}function f(){iu(t,{force:!0})}return Object.freeze({kind:"protected-file",path:t,load:i,save:s,clear:f})}function ID(D){return typeof D==="string"&&D.length>0&&D.length<=Yr&&!/\s/.test(D)}function ee(D,u,e){return D.set({...u,value:e,allowUnrestrictedAccess:!1})}async function te({start:D,poll:u,save:e,onState:n=()=>{},openUrl:r,openVerificationUrl:t=!0,sleep:c=fu,signal:i}={}){n({kind:"welcome"});let s=await D({signal:i}),f={userCode:s.userCode,verificationUri:s.verificationUri,...s.expiresAt?{expiresAt:s.expiresAt}:{}};if(n({kind:"device_code",...f}),t&&typeof r==="function")await r(s.verificationUriComplete||s.verificationUri);let a=s.intervalSeconds;while(!0){await c(a*1000,i);let o=await u(s.deviceCode,{signal:i});if(o.status==="waiting"){a=o.slowDown?Math.max(a+5,o.intervalSeconds):o.intervalSeconds,n({kind:"waiting",...f});continue}if(o.status==="denied"){let A={kind:"denied",reason:o.reason};return n(A),A}if(o.status==="expired"){let A={kind:"error",code:"device_code_expired",recoverable:!0};return n(A),A}await e(o.sessionToken);let l={kind:"authenticated",user:o.user};return n(l),l}}function fu(D,u){return new Promise((e,n)=>{if(u?.aborted)return n(re());let r=setTimeout(t,D);function t(){u?.removeEventListener("abort",c),e()}function c(){clearTimeout(r),u?.removeEventListener("abort",c),n(re())}u?.addEventListener("abort",c,{once:!0})})}function re(){let D=Error("aborted");return D.name="AbortError",D}var Hr="urn:ietf:params:oauth:grant-type:device_code",ce="freecode-cli";class S extends Error{constructor(D,{status:u=0,retryAfterSeconds:e,details:n}={}){super(D);if(this.name="FreeCodeAuthClientError",this.code=D,this.status=u,e!==void 0)this.retryAfterSeconds=e;if(n!==void 0)this.details=n}}function se({authBaseUrl:D=process.env.FREECODE_AUTH_URL||"https://auth.freecode.sh",apiBaseUrl:u=process.env.FREECODE_API_URL||"https://api.freecode.sh",fetchImpl:e=globalThis.fetch,credentialStore:n=ne(),sleep:r=fu,openUrl:t,clientIdentity:c=AD()}={}){if(typeof e!=="function")throw new S("fetch_required");let i=ie(D),s=ie(u),f=ND(c);async function a(_,E,{method:v="GET",body:F,sessionToken:z,signal:I}={}){let q;try{q=await e(`${_}${E}`,{method:v,signal:I,headers:{accept:"application/json",...F?{"content-type":"application/json"}:{},...z?{authorization:`Bearer ${z}`}:{},...f},...F?{body:JSON.stringify(F)}:{}})}catch(X){if(X?.name==="AbortError")throw X;throw new S("auth_network_unavailable")}return q}async function o(_){try{return await _.json()}catch{return}}async function l(_,E,v){let F=await a(_,E,v),z=await o(F);if(!F.ok)throw MD(F,z);return z}async function A({signal:_}={}){let E=await l(i,"/api/auth/device/code",{method:"POST",body:{client_id:ce,scope:"openid profile email"},signal:_}),v=K(E?.device_code),F=K(E?.user_code),z=au(E?.verification_uri),I=au(E?.verification_uri_complete),q=pD(E?.interval)||5,X=pD(E?.expires_in);if(!v||!F||!z||!X)throw new S("invalid_auth_response");return{deviceCode:v,userCode:F,verificationUri:z,verificationUriComplete:I,intervalSeconds:q,expiresAt:new Date(Date.now()+X*1000).toISOString()}}async function b(_,{signal:E}={}){if(!K(_))throw new S("device_code_required");let v=await a(i,"/api/auth/device/token",{method:"POST",body:{grant_type:Hr,device_code:_,client_id:ce},signal:E}),F=await o(v);if(!v.ok){let q=fe(F?.error||F?.code);if(q==="authorization_pending")return{status:"waiting",intervalSeconds:5,slowDown:!1};if(q==="slow_down")return{status:"waiting",intervalSeconds:10,slowDown:!0};if(q==="access_denied")return{status:"denied",reason:"access_denied"};if(q==="expired_token"||q==="invalid_grant")return{status:"expired"};throw MD(v,F)}let z=K(F?.access_token);if(!Kr(z))throw new S("invalid_auth_response");let I=await T(z,{signal:E});return{status:"authenticated",sessionToken:z,user:I.user}}async function T(_,{signal:E}={}){let v=await a(i,"/api/auth/get-session",{sessionToken:_,signal:E}),F=await o(v);if(!v.ok)throw MD(v,F);let z=Jr(F);if(!z)throw new S("invalid_session",{status:401});return{sessionToken:_,user:z}}async function eD({clearInvalid:_=!0,signal:E}={}){let v=await n.load();if(!v)return;try{return await T(v,{signal:E})}catch(F){if(_&&F instanceof S&&F.status===401)await n.clear();throw F}}async function w(_,{method:E="GET",body:v,signal:F}={}){let z=await n.load();if(!z)throw new S("authentication_required",{status:401});let I=await a(s,_,{method:E,body:v,sessionToken:z,signal:F});if(!I.ok){let q=await o(I.clone()),X=MD(I,q);if(X.status===401)await n.clear();throw X}return I}function h(_,{signal:E}={}){if(!_||typeof _!=="object"||Array.isArray(_))throw new S("invalid_messages_request");return w("/v1/alpha/messages",{method:"POST",body:_,signal:E})}async function B(_,{signal:E}={}){if(!_||typeof _!=="object"||Array.isArray(_))throw new S("invalid_sidebar_recommendation_request");let v=await w("/v1/alpha/sidebar-recommendation",{method:"POST",body:_,signal:E});try{return await v.json()}catch{throw new S("invalid_sidebar_recommendation_response")}}async function d({signal:_}={}){let E=await n.load();if(!E)return{ok:!0,remote:!1};let v=!1;try{v=(await a(i,"/api/auth/sign-out",{method:"POST",body:{},sessionToken:E,signal:_})).ok}catch(F){if(F?.name==="AbortError")throw F}finally{await n.clear()}return{ok:!0,remote:v}}async function x({onState:_=()=>{},openVerificationUrl:E=!0,signal:v}={}){try{return await te({start:A,poll:b,save:n.save,onState:_,openUrl:t,openVerificationUrl:E,sleep:r,signal:v})}catch(F){if(F?.name==="AbortError")throw F;let z={kind:"error",code:F instanceof S?F.code:"auth_failed",recoverable:!0};return _(z),z}}return Object.freeze({startDeviceFlow:A,pollDeviceFlow:b,currentSession:eD,authenticate:x,logout:d,messages:h,sidebarRecommendation:B,credentialStore:n})}function Jr(D){let u=D?.user,e=D?.session,n=K(u?.id),r=K(u?.name),t=Wr(u?.email),c=Xr(e?.expiresAt);if(!n||!t||!c)return;let i=au(u?.image);return{id:n,name:r||t.split("@")[0],email:t,...i?{image:i}:{},tier:"free",expiresAt:c}}function MD(D,u){let e=fe(u?.error||u?.code)||(D.status===401?"invalid_session":"auth_request_failed");return new S(e,{status:D.status,retryAfterSeconds:pD(u?.retry_after_seconds)||pD(D.headers?.get?.("retry-after")),details:{...typeof u?.message==="string"?{message:u.message}:{},...typeof u?.minimum_supported_version==="string"?{minimumSupportedVersion:u.minimum_supported_version}:{},...typeof u?.update_command==="string"?{updateCommand:u.update_command}:{}}})}function ie(D){try{let u=new URL(K(D).replace(/\/$/,""));if(u.username||u.password||u.search||u.hash)throw Error("unsafe_url");if(u.protocol==="https:"||u.protocol==="http:"&&["localhost","127.0.0.1","[::1]"].includes(u.hostname))return u.toString().replace(/\/$/,"")}catch{}throw new S("invalid_auth_url")}function au(D){try{let u=new URL(K(D));return u.protocol==="https:"||u.protocol==="http:"&&["localhost","127.0.0.1","[::1]"].includes(u.hostname)?u.toString():void 0}catch{return}}function Kr(D){return typeof D==="string"&&D.length>0&&D.length<=8192&&!/\s/.test(D)}function K(D){return typeof D==="string"?D.trim():""}function pD(D){let u=Number(D);return Number.isSafeInteger(u)&&u>0?u:void 0}function fe(D){let u=K(D).toLowerCase();return/^[a-z][a-z0-9_]{0,63}$/.test(u)?u:void 0}function Wr(D){let u=K(D).toLowerCase();return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(u)?u:void 0}function Xr(D){let u=K(D);return u&&Number.isFinite(Date.parse(u))?u:void 0}import{createHash as de,randomUUID as ae}from"node:crypto";import{spawnSync as Ce}from"node:child_process";import{existsSync as FD,lstatSync as Gr,mkdirSync as oe,openSync as Vr,closeSync as Qr,readFileSync as SD,readdirSync as Ur,renameSync as Pr,rmSync as ou,statSync as he,writeFileSync as me,writeSync as Fe}from"node:fs";import{dirname as gr,join as R,resolve as le}from"node:path";import{fileURLToPath as Dt}from"node:url";import{gunzipSync as ut}from"node:zlib";var et="https://releases.freecode.sh/releases",nt="GD597P8KJ2",rt=262144,_e=67108864,Fu=100663296,Ee=4096;function cD({platform:D=process.platform,architecture:u=process.arch}={}){let e=u==="x64"?"x64":u==="arm64"?"arm64":void 0;return D==="darwin"&&e?`darwin-${e}`:void 0}function xD({installRoot:D,version:u,target:e}){return R(le(D),"extensions","freecode.doom",u,e)}function Be({installRoot:D,version:u,target:e}){return R(le(D),"optional","doom",u,e)}function qD(D){let u=D.directory||xD(D),e=R(u,"freecode-doom-stream"),n=R(u,"freedoom1.wad"),r=R(u,".pack.json"),t;try{t=JSON.parse(SD(r,"utf8"))}catch{}return{directory:u,executable:e,wad:n,metadata:r,extensionVersion:t?.extensionVersion,available:FD(e)&&FD(n)&&t?.schemaVersion===2&&t?.product==="freecode-extension-runtime"&&t?.extensionId==="freecode.doom"&&t?.extensionVersion===D.version&&(!D.apiVersion||t?.apiVersion===D.apiVersion)&&t?.target===D.target&&/^[a-f0-9]{64}$/.test(t?.sha256||"")}}function be({directory:D,releaseVersion:u,target:e}){let n=R(D,"freecode-doom-stream"),r=R(D,"freedoom1.wad"),t=R(D,".pack.json"),c;try{c=JSON.parse(SD(t,"utf8"))}catch{}return{directory:D,executable:n,wad:r,metadata:t,available:FD(n)&&FD(r)&&c?.schemaVersion===1&&c?.product==="freecode-doom-pack"&&c?.version===u&&c?.target===e&&/^[a-f0-9]{64}$/.test(c?.sha256||"")}}async function ve({installRoot:D,releaseVersion:u,extensionVersion:e,extensionApiVersion:n="1",target:r=cD(),releaseBaseUrl:t=et,expectedTeamIdentifier:c=nt,allowUnsigned:i=!1,fetchImpl:s=globalThis.fetch,codesign:f="/usr/bin/codesign",tar:a="/usr/bin/tar",signal:o}={}){if(!D)throw Error("Doom pack installation requires an install root");if(we(u,"Free Code release"),we(e,"Doom extension"),!["darwin-arm64","darwin-x64"].includes(r))throw Error(`Doom pack installation does not support ${r||"this platform"}`);let l=qD({installRoot:D,version:e,apiVersion:n,target:r});if(l.available)return{...l,installed:!1};let A=`${String(t).replace(/\/+$/,"")}/v${u}`,b=await ft(`${A}/release-manifest.json`,s,o);if(b?.schemaVersion!==1||b.version!==u)throw Error("The Doom pack release manifest does not match this Free Code version");let T=b.security?.releaseMode==="signed-notarized"&&b.security?.appleDeveloperIdSigned===!0&&b.security?.appleNotarized===!0,eD=b.channel==="alpha"&&b.security?.releaseMode==="unsigned-override"&&b.security?.appleDeveloperIdSigned===!1&&b.security?.appleNotarized===!1&&b.security?.unsignedAlphaOverride===!0;if(!T&&!(eD&&i))throw Error("The optional Doom pack is not from a signed and notarized Free Code release");let w=b.optionalAssets?.doom?.[r];if(!w||w.extensionId!=="freecode.doom"||w.version!==e||w.apiVersion!==n||w.archive!==`freecode-doom-${r}.tar.gz`||!/^[a-f0-9]{64}$/.test(w.sha256||"")||!Number.isSafeInteger(w.size)||w.size<1||w.size>_e||!Number.isSafeInteger(w.installedSize)||w.installedSize<1||w.installedSize>Fu)throw Error(`The release does not provide valid freecode.doom metadata for ${r}`);let h=l.directory,B=gr(h),d=R(B,`.install-${ae()}`),x=R(B,`.download-${ae()}.tar.gz`);oe(B,{recursive:!0});try{let _=await at(`${A}/${w.archive}`,x,{expectedSize:w.size,maximumSize:_e,fetchImpl:s,signal:o});if(_D(o),_!==w.sha256)throw Error("The optional Doom pack failed its release checksum");let E=tt(x);if(E.installedSize!==w.installedSize)throw Error("The optional Doom pack expanded size does not match its authenticated metadata");if(oe(d,{recursive:!0}),xe(a,["-xzf",x,"-C",d],"extract the optional Doom pack"),ct(d,E),it(d),T)st(R(d,"freecode-doom-stream"),{codesign:f,expectedTeamIdentifier:c});if(me(R(d,".pack.json"),`${JSON.stringify({schemaVersion:2,product:"freecode-extension-runtime",extensionId:"freecode.doom",extensionVersion:e,apiVersion:n,releaseVersion:u,target:r,archive:w.archive,sha256:w.sha256,signed:T},null,2)}
|
|
9
|
-
`),FD(h))ou(h,{recursive:!0,force:!0});Pr(d,h)}finally{ou(x,{force:!0}),ou(d,{recursive:!0,force:!0})}return{...qD({installRoot:D,version:e,apiVersion:n,target:r}),installed:!0,downloadSize:w.size,installedSize:w.installedSize}}function tt(D){let u;try{u=ut(SD(D),{maxOutputLength:Fu+Ee*512+1024})}catch{throw Error("The optional Doom pack exceeds its expanded-size limit or is not valid gzip data")}let e=new Map,n=0,r=0,t=!1;while(r+512<=u.length){let c=u.subarray(r,r+512);if(r+=512,c.every((A)=>A===0)){t=!0;break}if(e.size>=Ee)throw Error("The optional Doom pack contains too many files");let i=_u(c,0,100),s=_u(c,345,155),f=_t(s?`${s}/${i}`:i),a=String.fromCharCode(c[156]||48),o=Ft(c,124,12);if(!["0","5"].includes(a))throw Error(`The optional Doom pack contains an unsupported entry type at ${f}`);if(!Et(f))throw Error(`The optional Doom pack contains an unexpected path: ${f}`);if(e.has(f))throw Error(`The optional Doom pack contains a duplicate path: ${f}`);if(a==="5"&&o!==0)throw Error(`The optional Doom pack contains an invalid directory: ${f}`);if(a==="0"){if(n+=o,n>Fu)throw Error("The optional Doom pack exceeds its expanded-size limit")}e.set(f,{type:a,size:o});let l=Math.ceil(o/512)*512;if(r+l>u.length)throw Error("The optional Doom pack contains a truncated entry");r+=l}if(!t||!e.size)throw Error("The optional Doom pack is empty or missing its tar terminator");return{entries:e,installedSize:n}}function ct(D,u){let e=new Map,n=new Set;for(let t of u.entries.keys()){let c=t.split("/").filter(Boolean);c.pop();while(c.length)n.add(c.join("/")),c.pop()}let r=[{directory:D,prefix:""}];while(r.length){let t=r.pop();if(!t)continue;for(let c of Ur(t.directory)){let i=R(t.directory,c),s=t.prefix?`${t.prefix}/${c}`:c,f=Gr(i);if(f.isSymbolicLink()||!f.isDirectory()&&!f.isFile())throw Error(`The optional Doom pack extracted an unsupported entry: ${s}`);if(e.set(s,{type:f.isDirectory()?"5":"0",size:f.isFile()?f.size:0}),f.isDirectory())r.push({directory:i,prefix:s})}}for(let[t,c]of u.entries){if(t===".")continue;let i=e.get(t);if(!i||i.type!==c.type||i.size!==c.size)throw Error(`The optional Doom pack extracted unexpected contents at ${t}`)}for(let[t,c]of e){let i=c.type==="5"&&n.has(t);if(!u.entries.has(t)&&!u.entries.has(`${t}/`)&&!i)throw Error(`The optional Doom pack extracted an undeclared path: ${t}`)}}function it(D){for(let u of["freecode-doom-stream","freedoom1.wad","manifest.json","licenses/TERMINAL_DOOM_GPL-2.0.txt","licenses/FREEDOOM_BSD-3-CLAUSE.txt"]){let e=R(D,u);if(!FD(e)||!he(e).isFile())throw Error(`The optional Doom pack is missing ${u}`)}}function st(D,{codesign:u,expectedTeamIdentifier:e}){xe(u,["--verify","--strict","--verbose=2",D],"verify the Doom executable signature");let n=Ce(u,["--display","--verbose=4",D],{encoding:"utf8"}),r=`${n.stdout||""}${n.stderr||""}`;if(n.status!==0)throw Error(`Could not inspect the Doom executable signature: ${r||n.error?.message||"codesign failed"}`);if(!r.split(`
|
|
10
|
-
`).includes(`TeamIdentifier=${e}`))throw Error(`The Doom executable is not signed by the expected Apple team ${e}`)}async function ft(D,u,e){let n=await Ae(D,u,e,rt);try{return JSON.parse(n.toString("utf8"))}catch{throw Error(`Could not parse ${D}`)}}async function Ae(D,u,e,n){if(_D(e),D.startsWith("file:")){let t=Dt(D);if(he(t).size>n)throw Error(`Download exceeds the ${n}-byte limit`);let i=SD(t);return _D(e),i}if(typeof u!=="function")throw Error("This runtime cannot download the optional Doom pack");let r=await u(D,{signal:e});if(!r.ok)throw Error(`Could not download ${D} (HTTP ${r.status})`);return ot(r,n,e)}async function at(D,u,{expectedSize:e,maximumSize:n,fetchImpl:r,signal:t}){if(_D(t),e>n)throw Error(`Download exceeds the ${n}-byte limit`);if(D.startsWith("file:")){let o=await Ae(D,r,t,n);if(o.length!==e)throw Error("The optional Doom pack download size does not match its release metadata");return me(u,o,{mode:384}),wt(o)}if(typeof r!=="function")throw Error("This runtime cannot download the optional Doom pack");let c=await r(D,{signal:t});if(!c.ok)throw Error(`Could not download ${D} (HTTP ${c.status})`);let i=$e(c);if(i!==void 0&&i!==e)throw Error("The optional Doom pack download size does not match its release metadata");let s=Vr(u,"wx",384),f=de("sha256"),a=0;try{if(c.body?.getReader){let o=c.body.getReader();while(!0){let{done:l,value:A}=await o.read();if(l)break;_D(t);let b=Buffer.from(A);if(a+=b.length,a>e||a>n)throw await o.cancel(),Error("The optional Doom pack download exceeds its authenticated size");f.update(b),Fe(s,b)}}else{let o=Buffer.from(await c.arrayBuffer());if(a=o.length,a>e||a>n)throw Error("The optional Doom pack download exceeds its authenticated size");f.update(o),Fe(s,o)}}finally{Qr(s)}if(a!==e)throw Error("The optional Doom pack download size does not match its release metadata");return f.digest("hex")}async function ot(D,u,e){let n=$e(D);if(n!==void 0&&n>u)throw Error(`Download exceeds the ${u}-byte limit`);if(!D.body?.getReader){let i=Buffer.from(await D.arrayBuffer());if(i.length>u)throw Error(`Download exceeds the ${u}-byte limit`);return i}let r=D.body.getReader(),t=[],c=0;while(!0){let{done:i,value:s}=await r.read();if(i)break;_D(e);let f=Buffer.from(s);if(c+=f.length,c>u)throw await r.cancel(),Error(`Download exceeds the ${u}-byte limit`);t.push(f)}return Buffer.concat(t,c)}function $e(D){let u=D.headers?.get?.("content-length");if(!u||!/^\d+$/.test(u))return;let e=Number(u);return Number.isSafeInteger(e)?e:void 0}function _D(D){if(!D?.aborted)return;let u=Error("Doom extension installation cancelled");throw u.name="AbortError",u}function xe(D,u,e){let n=Ce(D,u,{encoding:"utf8"});if(n.status!==0)throw Error(`Could not ${e}: ${n.stderr||n.stdout||n.error?.message||"command failed"}`);return n}function we(D,u){if(!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z][0-9A-Za-z.-]*)?$/.test(D||""))throw Error(`${u} has an invalid version: ${D||"(missing)"}`)}function _u(D,u,e){let n=D.indexOf(0,u);return D.subarray(u,n>=u&&n<u+e?n:u+e).toString("utf8").trim()}function Ft(D,u,e){let n=_u(D,u,e).replace(/\0.*$/,"").trim();if(!/^[0-7]+$/.test(n))throw Error("The optional Doom pack contains invalid tar size metadata");let r=Number.parseInt(n,8);if(!Number.isSafeInteger(r)||r<0)throw Error("The optional Doom pack contains an unsafe tar size");return r}function _t(D){if(!D||D.includes("\\")||D.startsWith("/"))throw Error("The optional Doom pack contains an unsafe path");let u=D.split("/").filter((e)=>e&&e!==".");if(u.includes(".."))throw Error("The optional Doom pack contains an unsafe path");return u.join("/")||"."}function Et(D){if(D===".")return!0;let u=D.split("/")[0];return["freecode-doom-stream","freedoom1.wad","manifest.json","licenses","sound"].includes(u)}function wt(D){return de("sha256").update(D).digest("hex")}import{randomUUID as dt}from"node:crypto";import{existsSync as ye,lstatSync as ze,mkdirSync as Ct,readdirSync as Oe,readFileSync as ht,renameSync as mt,rmSync as yD,writeFileSync as lt}from"node:fs";import{dirname as Bt,join as V,resolve as ED}from"node:path";var bt="1",W="freecode.doom",ZD="1.0.0-alpha.1",wu=Object.freeze([Object.freeze({schemaVersion:1,apiVersion:bt,id:W,displayName:"Doom for Free Code",publisher:"Free Code",description:"Play Freedoom inside your terminal",version:ZD,nativeCode:!0,networkOrigins:Object.freeze([]),licenses:Object.freeze(["GPL-2.0-only","BSD-3-Clause"]),downloadSize:13107200,installedSize:32715000,sizeExact:!1,capabilities:Object.freeze([Object.freeze({id:"ui.main",label:"Main terminal surface"}),Object.freeze({id:"ui.sidebar",label:"Sidebar surface"}),Object.freeze({id:"input.raw",label:"Raw input while focused"}),Object.freeze({id:"storage.local",label:"Local game storage"}),Object.freeze({id:"runtime.native",label:"Verified native runtime"})]),nativeRuntimeProfiles:Object.freeze(["freecode.doom.singleplayer"]),commands:Object.freeze([Object.freeze({id:"freecode.doom.play",alias:"/doom",title:"Play Freedoom in this terminal"})])})]);Tt(wu);function Le(D){return V(ED(D),"extensions","state.json")}function U({id:D,installRoot:u,releaseVersion:e,target:n=cD(),developmentDirectory:r}={}){let t=RD(D),c=t.id!==W||Boolean(n),i=u?zD(u):vt(),s=i.state.extensions[t.id],f={available:!1};if(t.id===W){if(r)f={...$t(r),development:!0,extensionVersion:t.version};else if(n){for(let b of Ot([s?.activeVersion,t.version])){let T=qD({installRoot:u,version:b,apiVersion:t.apiVersion,target:n});if(f=T,T.available)break}if(!f.available&&u&&e){let b=At({installRoot:u,releaseVersion:e,target:n});if(b.available)f=b}}}let a=Boolean(f.available),o=Boolean(f.legacy&&i.missing),l=a&&(f.development||s?.enabled===!0||o),A=a?f.extensionVersion||s?.activeVersion||t.version:void 0;return{...t,supported:c,installed:a,installedVersion:A,updateAvailable:Boolean(A&&A!==t.version),enabled:l,available:a&&l&&c,directory:f.directory,installedBytes:a&&f.directory?xt(f.directory):0}}function du(D={}){return wu.map((u)=>U({...D,id:u.id}))}async function Cu({id:D,installRoot:u,releaseVersion:e,target:n=cD(),releaseBaseUrl:r,expectedTeamIdentifier:t,allowUnsigned:c=!1,fetchImpl:i,codesign:s,tar:f,signal:a}={}){let o=RD(D);if(o.id!==W)throw Error(`Extension ${o.id} has no installer`);let l=zD(u).state.extensions[D],A=await ve({installRoot:u,releaseVersion:e,extensionVersion:o.version,extensionApiVersion:o.apiVersion,target:n,releaseBaseUrl:r,expectedTeamIdentifier:t,allowUnsigned:c,fetchImpl:i,codesign:s,tar:f,signal:a}),b=l?.activeVersion&&l.activeVersion!==o.version?l.activeVersion:l?.previousVersion&&l.previousVersion!==o.version?l.previousVersion:void 0;return Ie(u,D,{enabled:l?l.enabled===!0:!0,activeVersion:o.version,...b?{previousVersion:b}:{}}),zt(V(ED(u),"extensions",o.id),new Set([o.version,b].filter(Boolean))),{...U({id:D,installRoot:u,releaseVersion:e,target:n}),installedNow:A.installed}}function ke({installRoot:D,id:u,enabled:e}){RD(u);let r={...zD(D).state.extensions[u]||{},enabled:Boolean(e)};return Ie(D,u,r),r}function Ne({installRoot:D,id:u,releaseVersion:e,target:n=cD()}){let r=RD(u);if(r.id===W)yD(V(ED(D),"extensions",r.id),{recursive:!0,force:!0}),yD(V(ED(D),"optional","doom"),{recursive:!0,force:!0}),yt(V(ED(D),"optional"));let t=zD(D).state;return delete t.extensions[u],Me(D,t),U({id:u,installRoot:D,releaseVersion:e,target:n})}function RD(D){let u=wu.find((e)=>e.id===D);if(!u)throw Error(`Unknown Free Code extension: ${D||"(missing)"}`);return u}function Eu(){return{schemaVersion:2,extensions:{}}}function vt(){return{state:Eu(),missing:!0,valid:!0}}function zD(D){let u=Le(D),e;try{e=ht(u,"utf8")}catch(n){return{state:Eu(),missing:n?.code==="ENOENT",valid:n?.code==="ENOENT"}}try{let n=JSON.parse(e);if(n?.schemaVersion===2&&Te(n.extensions))return{state:n,missing:!1,valid:!0};if(n?.schemaVersion===1&&Te(n.extensions))return{state:{schemaVersion:2,extensions:Object.fromEntries(Object.entries(n.extensions).map(([r,t])=>[r,{enabled:t?.enabled===!0}]))},missing:!1,valid:!0}}catch{}return{state:Eu(),missing:!1,valid:!1}}function Ie(D,u,e){let n=zD(D).state;n.extensions[u]=e,Me(D,n)}function Me(D,u){let e=Le(D),n=Bt(e),r=V(n,`.state-${dt()}.json`);Ct(n,{recursive:!0});try{lt(r,`${JSON.stringify({...u,schemaVersion:2},null,2)}
|
|
11
|
-
`,{mode:384}),mt(r,e)}finally{yD(r,{force:!0})}}function At({installRoot:D,releaseVersion:u,target:e}){for(let n of[xD({installRoot:D,version:u,target:e}),Be({installRoot:D,version:u,target:e})]){let r=be({directory:n,releaseVersion:u,target:e});if(r.available)return{...r,legacy:!0}}return{available:!1}}function $t(D){let u=ED(D);return{directory:u,available:ye(V(u,"freecode-doom-stream"))&&ye(V(u,"freedoom1.wad"))}}function xt(D){let u=0,e=[D];while(e.length){let n=e.pop();if(!n)continue;let r;try{r=ze(n).isDirectory()?Oe(n).map((t)=>V(n,t)):[]}catch{continue}if(!r.length){try{let t=ze(n);if(t.isFile())u+=t.size}catch{}continue}e.push(...r)}return u}function yt(D){try{yD(D)}catch{}}function zt(D,u){try{for(let e of Oe(D,{withFileTypes:!0}))if(e.isDirectory()&&!u.has(e.name))yD(V(D,e.name),{recursive:!0,force:!0})}catch{}}function Tt(D){let u=new Set,e=new Set,n=new Set;for(let r of D){if(u.has(r.id))throw Error(`Duplicate extension ID: ${r.id}`);u.add(r.id);for(let t of r.commands){if(!t.id.startsWith(`${r.id}.`))throw Error(`Extension command ${t.id} is outside ${r.id}`);if(e.has(t.id))throw Error(`Duplicate extension contribution ID: ${t.id}`);if(n.has(t.alias))throw Error(`Duplicate extension command alias: ${t.alias}`);e.add(t.id),n.add(t.alias)}}}function Te(D){return Boolean(D&&typeof D==="object"&&!Array.isArray(D))}function Ot(D){return[...new Set(D.filter(Boolean))]}import{existsSync as Nt}from"node:fs";import{dirname as It,join as Mt}from"node:path";import{spawn as Lt}from"node:child_process";import{existsSync as pe}from"node:fs";import{join as YD}from"node:path";function TD(D,u,e){let n=YD(D,"node_modules",u,"bin");return[YD(n,`${e}.exe`),YD(n,e)].find((r)=>pe(r))}function OD(D,u,e=process.platform){let r=YD(D,"node_modules",".bin",`${u}${e==="win32"?".cmd":""}`);return pe(r)?r:void 0}function hu(D,u=process.platform){return u==="win32"?`${D}.cmd`:D}function qe(D=process.platform){return D==="win32"?"where.exe":"which"}function Se(D,u=process.platform){let e=String(D||"").split(/\r?\n/).map((n)=>n.trim()).filter(Boolean);if(u!=="win32")return e[0];return e.find((n)=>!/\.(?:cmd|bat)$/i.test(n))}function kt(D,u=process.platform){if(u==="darwin")return{command:"open",args:[D]};if(u==="win32")return{command:"rundll32.exe",args:["url.dll,FileProtocolHandler",D]};return{command:"xdg-open",args:[D]}}function Ze(D,{platform:u=process.platform,spawnImpl:e=Lt}={}){let n=kt(D,u),r=e(n.command,n.args,{detached:!0,stdio:"ignore",windowsHide:!0});r.on("error",()=>{}),r.unref()}var Re=`You are Free Code, the AI coding agent in the Free Code terminal app. You and the user share a workspace. Your job is to help them turn an idea or request into working software.
|
|
12
2
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
- Read enough surrounding code to preserve behavior and conventions. Update all directly affected call sites, types, tests, documentation, and generated artifacts when needed.
|
|
141
|
-
- Avoid broad rewrites, dependency additions, or public API changes unless they are justified by the task.
|
|
142
|
-
- Do not add placeholders, fake data, swallowed errors, disabled checks, or hard-coded test exceptions as a substitute for a real implementation.
|
|
143
|
-
- Write comments for non-obvious reasoning and constraints, not as narration of straightforward code.
|
|
144
|
-
- Treat lockfiles, generated files, vendored code, migrations, and release artifacts deliberately. Change them only when the source change requires it.
|
|
145
|
-
|
|
146
|
-
# Verification
|
|
147
|
-
|
|
148
|
-
- Verify work in proportion to its risk. Run the most relevant tests, type checks, lint checks, builds, or focused runtime checks available.
|
|
149
|
-
- Start with focused checks when useful, then run broader checks when the change crosses package or product boundaries.
|
|
150
|
-
- Diagnose failures instead of repeatedly rerunning the same command. Distinguish a failure caused by your change from a pre-existing or environmental failure.
|
|
151
|
-
- Never claim that something works, passes, ships, deploys, or is fixed unless you have evidence. Say exactly what was and was not verified.
|
|
152
|
-
- Before finishing, review the diff or resulting state for accidental changes, missing cases, exposed secrets, and incomplete cleanup.
|
|
153
|
-
|
|
154
|
-
# Safety and user control
|
|
155
|
-
|
|
156
|
-
- Respect the user's files, accounts, private data, credentials, and external systems.
|
|
157
|
-
- Never reveal secrets or include them in logs, commits, examples, or responses. Avoid reading sensitive files unless the task requires it.
|
|
158
|
-
- Do not perform destructive repository cleanup, broad deletion, force pushes, publishing, deployment, privileged system changes, or irreversible external actions unless the user requested the outcome and Free Code allows the action.
|
|
159
|
-
- When approval is required, describe the concrete action and consequence in plain language. Do not ask for redundant approval for routine safe work that Free Code already allows.
|
|
160
|
-
- Do not weaken security controls, tests, or permission boundaries merely to get a green result.
|
|
161
|
-
|
|
162
|
-
# Communication
|
|
163
|
-
|
|
164
|
-
- Be concise, practical, and direct. Lead with the outcome or the most important finding.
|
|
165
|
-
- Use language appropriate to the user's apparent experience. Explain unfamiliar concepts without talking down to beginners.
|
|
166
|
-
- Report meaningful progress during longer work. Do not flood the user with a transcript of routine commands.
|
|
167
|
-
- Be honest about uncertainty and investigate it when the answer is available.
|
|
168
|
-
- Disagree clearly when evidence contradicts an assumption. Do not use praise, hype, or false reassurance in place of technical judgment.
|
|
169
|
-
- In the final response, summarize what changed, the verification performed, and any real remaining risk or next step. Include file references when they help the user inspect the work.
|
|
170
|
-
|
|
171
|
-
# Plan mode
|
|
172
|
-
|
|
173
|
-
You are in Plan mode. Investigate the workspace deeply enough to produce a concrete, executable plan, but do not modify product files. Resolve discoverable questions through read-only inspection. Identify exact files, constraints, validation steps, and decisions that genuinely require the user.`,je=`You are Free Code, the AI coding agent in the Free Code terminal app. You and the user share a workspace. Your job is to help them turn an idea or request into working software.
|
|
174
|
-
|
|
175
|
-
# Product identity
|
|
176
|
-
|
|
177
|
-
- Your name and the product's name are Free Code.
|
|
178
|
-
- When asked what you are, which coding agent is running, or which app the user is using, answer "Free Code."
|
|
179
|
-
- Never present an internal engine, framework, package, model provider, or implementation dependency as your identity or as the product the user is operating.
|
|
180
|
-
- Do not volunteer internal dependency names, backend plumbing, hidden configuration, or unrelated documentation and issue trackers. Translate internal runtime failures into clear Free Code language.
|
|
181
|
-
- For help using the product, direct the user to /help.
|
|
182
|
-
- Do not invent Free Code features, policies, URLs, or support channels. Inspect available product documentation when an exact answer matters.
|
|
183
|
-
|
|
184
|
-
# Default operating posture
|
|
185
|
-
|
|
186
|
-
- Take useful action by default. For a request to build, change, fix, upgrade, or debug something, inspect the relevant workspace, perform the work, and verify the result.
|
|
187
|
-
- Continue until the requested outcome is complete or a concrete blocker remains. Do not stop after merely describing changes that you can safely make.
|
|
188
|
-
- Make reasonable, reversible assumptions when details are minor or can be discovered from the workspace. State an assumption when it materially affects the result.
|
|
189
|
-
- Do not make the user interpret routine commands, internal permission mechanics, or raw implementation details. Explain outcomes and meaningful choices in plain language.
|
|
190
|
-
- Ask a question only when the answer cannot be discovered and different choices would materially change the result, or when Free Code explicitly requires the user's approval.
|
|
191
|
-
- Treat requests to explain, review, diagnose, or report as read-only unless the user also asks for a change. A diagnosis should identify evidence and cause; implementation requests should include the fix.
|
|
192
|
-
|
|
193
|
-
# Understand the workspace
|
|
194
|
-
|
|
195
|
-
- Read the relevant files, instructions, configuration, tests, and current state before changing code. Follow project-specific instructions that accompany this prompt.
|
|
196
|
-
- Search efficiently and begin with the narrowest useful scope. Prefer fast project search tools when available.
|
|
197
|
-
- Preserve the user's existing work, including unrelated uncommitted changes. Never discard, overwrite, or reformat unrelated work just to make your task easier.
|
|
198
|
-
- Follow the project's established architecture, naming, dependencies, and style unless the request calls for changing them.
|
|
199
|
-
- Prefer fixing the underlying cause over hiding a symptom. Keep the implementation as simple as the requirements allow.
|
|
200
|
-
- Create new files when they provide a clear architectural or maintenance benefit. Avoid speculative abstractions and unnecessary compatibility layers.
|
|
201
|
-
|
|
202
|
-
# Tool use
|
|
203
|
-
|
|
204
|
-
- Use tools to inspect and change the workspace; use your response to communicate with the user. Never use shell output or file contents as a substitute for a user-facing message.
|
|
205
|
-
- Use dedicated tools for their intended purpose when available, and use the shell for legitimate build, test, search, package, and version-control commands.
|
|
206
|
-
- Run independent read-only investigations or checks in parallel when that saves time and does not make results harder to interpret.
|
|
207
|
-
- Do not fabricate tool results, file contents, command output, test status, links, or successful actions.
|
|
208
|
-
- If a tool call fails, read the actual error, adjust the approach, and retry when a safe path remains.
|
|
209
|
-
- Use plans or task lists when they improve execution of genuinely multi-step work. Keep them current, and do not create ceremonial plans for simple tasks.
|
|
210
|
-
|
|
211
|
-
# Service recommendations
|
|
212
|
-
|
|
213
|
-
- When the user is choosing, comparing, adding, or setting up an external developer service and Gravity Index tools are available, search Gravity Index with the full relevant task context: the current request, constraints, existing stack and services, architecture, changed areas, and verification state.
|
|
214
|
-
- Use Gravity Index for an actual service decision, not every generic mention of a database, deployment, test, or integration.
|
|
215
|
-
- Keep the coding answer useful on its own and explain why the recommended service fits the project. Clearly treat the result as a Gravity Index recommendation.
|
|
216
|
-
- Prefer a tracked setup link when Gravity Index supplies one. Report an integration only after the user starts that setup, and never claim an account was provisioned or an integration completed unless the available tool returned that result.
|
|
217
|
-
|
|
218
|
-
# Editing and implementation
|
|
219
|
-
|
|
220
|
-
- Make focused edits that fully solve the request. Prefer modifying the natural source of truth over patching generated output or duplicating configuration.
|
|
221
|
-
- Read enough surrounding code to preserve behavior and conventions. Update all directly affected call sites, types, tests, documentation, and generated artifacts when needed.
|
|
222
|
-
- Avoid broad rewrites, dependency additions, or public API changes unless they are justified by the task.
|
|
223
|
-
- Do not add placeholders, fake data, swallowed errors, disabled checks, or hard-coded test exceptions as a substitute for a real implementation.
|
|
224
|
-
- Write comments for non-obvious reasoning and constraints, not as narration of straightforward code.
|
|
225
|
-
- Treat lockfiles, generated files, vendored code, migrations, and release artifacts deliberately. Change them only when the source change requires it.
|
|
226
|
-
|
|
227
|
-
# Verification
|
|
228
|
-
|
|
229
|
-
- Verify work in proportion to its risk. Run the most relevant tests, type checks, lint checks, builds, or focused runtime checks available.
|
|
230
|
-
- Start with focused checks when useful, then run broader checks when the change crosses package or product boundaries.
|
|
231
|
-
- Diagnose failures instead of repeatedly rerunning the same command. Distinguish a failure caused by your change from a pre-existing or environmental failure.
|
|
232
|
-
- Never claim that something works, passes, ships, deploys, or is fixed unless you have evidence. Say exactly what was and was not verified.
|
|
233
|
-
- Before finishing, review the diff or resulting state for accidental changes, missing cases, exposed secrets, and incomplete cleanup.
|
|
234
|
-
|
|
235
|
-
# Safety and user control
|
|
236
|
-
|
|
237
|
-
- Respect the user's files, accounts, private data, credentials, and external systems.
|
|
238
|
-
- Never reveal secrets or include them in logs, commits, examples, or responses. Avoid reading sensitive files unless the task requires it.
|
|
239
|
-
- Do not perform destructive repository cleanup, broad deletion, force pushes, publishing, deployment, privileged system changes, or irreversible external actions unless the user requested the outcome and Free Code allows the action.
|
|
240
|
-
- When approval is required, describe the concrete action and consequence in plain language. Do not ask for redundant approval for routine safe work that Free Code already allows.
|
|
241
|
-
- Do not weaken security controls, tests, or permission boundaries merely to get a green result.
|
|
242
|
-
|
|
243
|
-
# Communication
|
|
244
|
-
|
|
245
|
-
- Be concise, practical, and direct. Lead with the outcome or the most important finding.
|
|
246
|
-
- Use language appropriate to the user's apparent experience. Explain unfamiliar concepts without talking down to beginners.
|
|
247
|
-
- Report meaningful progress during longer work. Do not flood the user with a transcript of routine commands.
|
|
248
|
-
- Be honest about uncertainty and investigate it when the answer is available.
|
|
249
|
-
- Disagree clearly when evidence contradicts an assumption. Do not use praise, hype, or false reassurance in place of technical judgment.
|
|
250
|
-
- In the final response, summarize what changed, the verification performed, and any real remaining risk or next step. Include file references when they help the user inspect the work.
|
|
251
|
-
|
|
252
|
-
# General mode
|
|
253
|
-
|
|
254
|
-
Complete the delegated research or multi-step objective within the available tools and permissions. Return concise findings, evidence, and any changes made so the primary Free Code agent can continue without repeating your work.`;var pt="@gravity-ai/index-mcp@1.0.0",qt=Object.freeze({"*":"allow",doom_loop:"ask",bash:{"sudo *":"ask","chmod -R *":"ask","chown -R *":"ask","git reset --hard*":"ask","git clean -f*":"ask","git clean *":"ask","git push --force*":"ask","git push * --force*":"ask","git push -f*":"ask","git push * -f*":"ask","npm publish*":"ask","pnpm publish*":"ask","yarn npm publish*":"ask","bun publish*":"ask","gh repo delete*":"ask","terraform destroy*":"ask","pulumi destroy*":"ask","rm -rf /":"deny","rm -fr /":"deny","rm -Rf /":"deny","rm -rf ~":"deny","rm -fr ~":"deny","rm -Rf ~":"deny","rm -rf $HOME":"deny","rm -fr $HOME":"deny","rm -Rf $HOME":"deny","rm * /":"deny","rm * /?":"deny","rm * ~":"deny","rm * ~/?":"deny","rm * $HOME":"deny","rm * $HOME/?":"deny","mkfs*":"deny"}});function He({nativeBuild:D=!1,env:u=process.env,execPath:e=process.execPath,packageRunner:n}={}){let r=Mt(It(e),hu("npx")),t=n||(Nt(r)?r:hu("npx")),c={GRAVITY_PUBLISHER_KEY:"{env:GRAVITY_PUBLISHER_KEY}"};if(u.GRAVITY_INDEX_MONETIZATION_MODE)c.GRAVITY_INDEX_MONETIZATION_MODE="{env:GRAVITY_INDEX_MONETIZATION_MODE}";let i=!D&&u.FREECODE_GRAVITY_INDEX_MCP!=="false"&&Boolean(u.GRAVITY_PUBLISHER_KEY),s={};if(!D)s["gravity-index"]={type:"local",command:[t,"-y",pt],enabled:i,environment:c};return{autoupdate:!1,server:{hostname:"127.0.0.1",port:Number(u.FREECODE_ENGINE_PORT||4096),cors:["http://localhost:5173"]},agent:{build:{prompt:Re},plan:{prompt:Ye},general:{prompt:je}},mcp:s,permission:qt}}function Je(D,{restartForUpdate:u,onSignal:e,onError:n}={}){return new Promise((r)=>{let t=!1,c=(i)=>{if(t)return;t=!0,r(i)};D.once("error",(i)=>{n?.(i),c(1)}),D.once("exit",(i,s)=>{if(t)return;if(s){if(!e){c(1);return}t=!0,e(s);return}if(i!==75){c(i??1);return}Promise.resolve().then(()=>u?.()).then((f)=>c(typeof f==="number"?f:1)).catch((f)=>{n?.(f),c(1)})})})}import{createHash as Zn}from"node:crypto";import{spawnSync as WD}from"node:child_process";import{chmodSync as vc,closeSync as Ac,createReadStream as $c,createWriteStream as xc,existsSync as sD,lstatSync as Nu,mkdirSync as XD,openSync as yc,readFileSync as Iu,readdirSync as zc,readlinkSync as Rn,renameSync as Yn,rmSync as P,statSync as GD,symlinkSync as Tc,unlinkSync as In,writeFileSync as Oc}from"node:fs";import{homedir as jn}from"node:os";import{basename as Ou,dirname as CD,isAbsolute as Mu,join as k,relative as pu,resolve as VD,sep as Lu}from"node:path";import{Readable as Lc,Transform as kc}from"node:stream";import{pipeline as Nc}from"node:stream/promises";import{createVerify as St}from"node:crypto";var Zt=`-----BEGIN PUBLIC KEY-----
|
|
255
|
-
MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEA8so4sWArOV0GXihYvoSo
|
|
256
|
-
xDLI1yMoILnVfCjYQwe4CKQ9EC10JV30cntMJZWXvXZS6STqQGIjyWisa6Op4nId
|
|
257
|
-
OuXKDjaEcQIeftgZBzzyGrMmAMC3W57VAi3d+w/F2XnkXBaH3NOphfftF6Fxt3Q0
|
|
258
|
-
2CxN3PjuuFaOGytKsYF5uDLCvEb+MpzJlD3HZoBzhhMCAoY6wmCdlgaDxD20UFdy
|
|
259
|
-
EigF5wwpcUWpYmbYMFp+6SLe/Fi8IrYirwiCv5eLur6PzFFcwFrJgUeZAdxmGuM8
|
|
260
|
-
eJzZlc7mK0+gzi8KpC2FZ9eOx1SafPE4An4+u8rZ7WA1Qk5eCAhNU9lm+JAeeKcC
|
|
261
|
-
XzhQpPUafybJg75dIbIayOC3tf5mn+X+Vl5+uY19nT2qcJsjgUeIcqbMs9FGXiIA
|
|
262
|
-
2G292N5WppyiDcx8yAIG6rOrAUGzHMYCrhvxQLAx2KP5QfC53VZ3La7yZOATY5ic
|
|
263
|
-
F78qSSBrKDrT42vinbosbX++Wr34YB6pXhiZF6jHPHrxAgMBAAE=
|
|
264
|
-
-----END PUBLIC KEY-----`;function Ke(D,u,e=Zt){try{let n=St("SHA256");return n.update(D),n.end(),n.verify(e,u)}catch{return!1}}var Ln=ju(On(),1);var zu={dots:{interval:80,frames:["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"]},dots2:{interval:80,frames:["⣾","⣽","⣻","⢿","⡿","⣟","⣯","⣷"]},dots3:{interval:80,frames:["⠋","⠙","⠚","⠞","⠖","⠦","⠴","⠲","⠳","⠓"]},dots4:{interval:80,frames:["⠄","⠆","⠇","⠋","⠙","⠸","⠰","⠠","⠰","⠸","⠙","⠋","⠇","⠆"]},dots5:{interval:80,frames:["⠋","⠙","⠚","⠒","⠂","⠂","⠒","⠲","⠴","⠦","⠖","⠒","⠐","⠐","⠒","⠓","⠋"]},dots6:{interval:80,frames:["⠁","⠉","⠙","⠚","⠒","⠂","⠂","⠒","⠲","⠴","⠤","⠄","⠄","⠤","⠴","⠲","⠒","⠂","⠂","⠒","⠚","⠙","⠉","⠁"]},dots7:{interval:80,frames:["⠈","⠉","⠋","⠓","⠒","⠐","⠐","⠒","⠖","⠦","⠤","⠠","⠠","⠤","⠦","⠖","⠒","⠐","⠐","⠒","⠓","⠋","⠉","⠈"]},dots8:{interval:80,frames:["⠁","⠁","⠉","⠙","⠚","⠒","⠂","⠂","⠒","⠲","⠴","⠤","⠄","⠄","⠤","⠠","⠠","⠤","⠦","⠖","⠒","⠐","⠐","⠒","⠓","⠋","⠉","⠈","⠈"]},dots9:{interval:80,frames:["⢹","⢺","⢼","⣸","⣇","⡧","⡗","⡏"]},dots10:{interval:80,frames:["⢄","⢂","⢁","⡁","⡈","⡐","⡠"]},dots11:{interval:100,frames:["⠁","⠂","⠄","⡀","⢀","⠠","⠐","⠈"]},dots12:{interval:80,frames:["⢀⠀","⡀⠀","⠄⠀","⢂⠀","⡂⠀","⠅⠀","⢃⠀","⡃⠀","⠍⠀","⢋⠀","⡋⠀","⠍⠁","⢋⠁","⡋⠁","⠍⠉","⠋⠉","⠋⠉","⠉⠙","⠉⠙","⠉⠩","⠈⢙","⠈⡙","⢈⠩","⡀⢙","⠄⡙","⢂⠩","⡂⢘","⠅⡘","⢃⠨","⡃⢐","⠍⡐","⢋⠠","⡋⢀","⠍⡁","⢋⠁","⡋⠁","⠍⠉","⠋⠉","⠋⠉","⠉⠙","⠉⠙","⠉⠩","⠈⢙","⠈⡙","⠈⠩","⠀⢙","⠀⡙","⠀⠩","⠀⢘","⠀⡘","⠀⠨","⠀⢐","⠀⡐","⠀⠠","⠀⢀","⠀⡀"]},dots13:{interval:80,frames:["⣼","⣹","⢻","⠿","⡟","⣏","⣧","⣶"]},dots14:{interval:80,frames:["⠉⠉","⠈⠙","⠀⠹","⠀⢸","⠀⣰","⢀⣠","⣀⣀","⣄⡀","⣆⠀","⡇⠀","⠏⠀","⠋⠁"]},dots8Bit:{interval:80,frames:["⠀","⠁","⠂","⠃","⠄","⠅","⠆","⠇","⡀","⡁","⡂","⡃","⡄","⡅","⡆","⡇","⠈","⠉","⠊","⠋","⠌","⠍","⠎","⠏","⡈","⡉","⡊","⡋","⡌","⡍","⡎","⡏","⠐","⠑","⠒","⠓","⠔","⠕","⠖","⠗","⡐","⡑","⡒","⡓","⡔","⡕","⡖","⡗","⠘","⠙","⠚","⠛","⠜","⠝","⠞","⠟","⡘","⡙","⡚","⡛","⡜","⡝","⡞","⡟","⠠","⠡","⠢","⠣","⠤","⠥","⠦","⠧","⡠","⡡","⡢","⡣","⡤","⡥","⡦","⡧","⠨","⠩","⠪","⠫","⠬","⠭","⠮","⠯","⡨","⡩","⡪","⡫","⡬","⡭","⡮","⡯","⠰","⠱","⠲","⠳","⠴","⠵","⠶","⠷","⡰","⡱","⡲","⡳","⡴","⡵","⡶","⡷","⠸","⠹","⠺","⠻","⠼","⠽","⠾","⠿","⡸","⡹","⡺","⡻","⡼","⡽","⡾","⡿","⢀","⢁","⢂","⢃","⢄","⢅","⢆","⢇","⣀","⣁","⣂","⣃","⣄","⣅","⣆","⣇","⢈","⢉","⢊","⢋","⢌","⢍","⢎","⢏","⣈","⣉","⣊","⣋","⣌","⣍","⣎","⣏","⢐","⢑","⢒","⢓","⢔","⢕","⢖","⢗","⣐","⣑","⣒","⣓","⣔","⣕","⣖","⣗","⢘","⢙","⢚","⢛","⢜","⢝","⢞","⢟","⣘","⣙","⣚","⣛","⣜","⣝","⣞","⣟","⢠","⢡","⢢","⢣","⢤","⢥","⢦","⢧","⣠","⣡","⣢","⣣","⣤","⣥","⣦","⣧","⢨","⢩","⢪","⢫","⢬","⢭","⢮","⢯","⣨","⣩","⣪","⣫","⣬","⣭","⣮","⣯","⢰","⢱","⢲","⢳","⢴","⢵","⢶","⢷","⣰","⣱","⣲","⣳","⣴","⣵","⣶","⣷","⢸","⢹","⢺","⢻","⢼","⢽","⢾","⢿","⣸","⣹","⣺","⣻","⣼","⣽","⣾","⣿"]},dotsCircle:{interval:80,frames:["⢎ ","⠎⠁","⠊⠑","⠈⠱"," ⡱","⢀⡰","⢄⡠","⢆⡀"]},sand:{interval:80,frames:["⠁","⠂","⠄","⡀","⡈","⡐","⡠","⣀","⣁","⣂","⣄","⣌","⣔","⣤","⣥","⣦","⣮","⣶","⣷","⣿","⡿","⠿","⢟","⠟","⡛","⠛","⠫","⢋","⠋","⠍","⡉","⠉","⠑","⠡","⢁"]},line:{interval:130,frames:["-","\\","|","/"]},line2:{interval:100,frames:["⠂","-","–","—","–","-"]},rollingLine:{interval:80,frames:["/ "," - "," \\ "," |"," |"," \\ "," - ","/ "]},pipe:{interval:100,frames:["┤","┘","┴","└","├","┌","┬","┐"]},simpleDots:{interval:400,frames:[". ",".. ","..."," "]},simpleDotsScrolling:{interval:200,frames:[". ",".. ","..."," .."," ."," "]},star:{interval:70,frames:["✶","✸","✹","✺","✹","✷"]},star2:{interval:80,frames:["+","x","*"]},flip:{interval:70,frames:["_","_","_","-","`","`","'","´","-","_","_","_"]},hamburger:{interval:100,frames:["☱","☲","☴"]},growVertical:{interval:120,frames:["▁","▃","▄","▅","▆","▇","▆","▅","▄","▃"]},growHorizontal:{interval:120,frames:["▏","▎","▍","▌","▋","▊","▉","▊","▋","▌","▍","▎"]},balloon:{interval:140,frames:[" ",".","o","O","@","*"," "]},balloon2:{interval:120,frames:[".","o","O","°","O","o","."]},noise:{interval:100,frames:["▓","▒","░"]},bounce:{interval:120,frames:["⠁","⠂","⠄","⠂"]},boxBounce:{interval:120,frames:["▖","▘","▝","▗"]},boxBounce2:{interval:100,frames:["▌","▀","▐","▄"]},triangle:{interval:50,frames:["◢","◣","◤","◥"]},binary:{interval:80,frames:["010010","001100","100101","111010","111101","010111","101011","111000","110011","110101"]},arc:{interval:100,frames:["◜","◠","◝","◞","◡","◟"]},circle:{interval:120,frames:["◡","⊙","◠"]},squareCorners:{interval:180,frames:["◰","◳","◲","◱"]},circleQuarters:{interval:120,frames:["◴","◷","◶","◵"]},circleHalves:{interval:50,frames:["◐","◓","◑","◒"]},squish:{interval:100,frames:["╫","╪"]},toggle:{interval:250,frames:["⊶","⊷"]},toggle2:{interval:80,frames:["▫","▪"]},toggle3:{interval:120,frames:["□","■"]},toggle4:{interval:100,frames:["■","□","▪","▫"]},toggle5:{interval:100,frames:["▮","▯"]},toggle6:{interval:300,frames:["ဝ","၀"]},toggle7:{interval:80,frames:["⦾","⦿"]},toggle8:{interval:100,frames:["◍","◌"]},toggle9:{interval:100,frames:["◉","◎"]},toggle10:{interval:100,frames:["㊂","㊀","㊁"]},toggle11:{interval:50,frames:["⧇","⧆"]},toggle12:{interval:120,frames:["☗","☖"]},toggle13:{interval:80,frames:["=","*","-"]},arrow:{interval:100,frames:["←","↖","↑","↗","→","↘","↓","↙"]},arrow2:{interval:80,frames:["⬆️ ","↗️ ","➡️ ","↘️ ","⬇️ ","↙️ ","⬅️ ","↖️ "]},arrow3:{interval:120,frames:["▹▹▹▹▹","▸▹▹▹▹","▹▸▹▹▹","▹▹▸▹▹","▹▹▹▸▹","▹▹▹▹▸"]},bouncingBar:{interval:80,frames:["[ ]","[= ]","[== ]","[=== ]","[====]","[ ===]","[ ==]","[ =]","[ ]","[ =]","[ ==]","[ ===]","[====]","[=== ]","[== ]","[= ]"]},bouncingBall:{interval:80,frames:["( ● )","( ● )","( ● )","( ● )","( ●)","( ● )","( ● )","( ● )","( ● )","(● )"]},smiley:{interval:200,frames:["😄 ","😝 "]},monkey:{interval:300,frames:["🙈 ","🙈 ","🙉 ","🙊 "]},hearts:{interval:100,frames:["💛 ","💙 ","💜 ","💚 ","💗 "]},clock:{interval:100,frames:["🕛 ","🕐 ","🕑 ","🕒 ","🕓 ","🕔 ","🕕 ","🕖 ","🕗 ","🕘 ","🕙 ","🕚 "]},earth:{interval:180,frames:["🌍 ","🌎 ","🌏 "]},material:{interval:17,frames:["█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁","██▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁","███▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁","████▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁","██████▁▁▁▁▁▁▁▁▁▁▁▁▁▁","██████▁▁▁▁▁▁▁▁▁▁▁▁▁▁","███████▁▁▁▁▁▁▁▁▁▁▁▁▁","████████▁▁▁▁▁▁▁▁▁▁▁▁","█████████▁▁▁▁▁▁▁▁▁▁▁","█████████▁▁▁▁▁▁▁▁▁▁▁","██████████▁▁▁▁▁▁▁▁▁▁","███████████▁▁▁▁▁▁▁▁▁","█████████████▁▁▁▁▁▁▁","██████████████▁▁▁▁▁▁","██████████████▁▁▁▁▁▁","▁██████████████▁▁▁▁▁","▁██████████████▁▁▁▁▁","▁██████████████▁▁▁▁▁","▁▁██████████████▁▁▁▁","▁▁▁██████████████▁▁▁","▁▁▁▁█████████████▁▁▁","▁▁▁▁██████████████▁▁","▁▁▁▁██████████████▁▁","▁▁▁▁▁██████████████▁","▁▁▁▁▁██████████████▁","▁▁▁▁▁██████████████▁","▁▁▁▁▁▁██████████████","▁▁▁▁▁▁██████████████","▁▁▁▁▁▁▁█████████████","▁▁▁▁▁▁▁█████████████","▁▁▁▁▁▁▁▁████████████","▁▁▁▁▁▁▁▁████████████","▁▁▁▁▁▁▁▁▁███████████","▁▁▁▁▁▁▁▁▁███████████","▁▁▁▁▁▁▁▁▁▁██████████","▁▁▁▁▁▁▁▁▁▁██████████","▁▁▁▁▁▁▁▁▁▁▁▁████████","▁▁▁▁▁▁▁▁▁▁▁▁▁███████","▁▁▁▁▁▁▁▁▁▁▁▁▁▁██████","▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█████","▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█████","█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁████","██▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁███","██▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁███","███▁▁▁▁▁▁▁▁▁▁▁▁▁▁███","████▁▁▁▁▁▁▁▁▁▁▁▁▁▁██","█████▁▁▁▁▁▁▁▁▁▁▁▁▁▁█","█████▁▁▁▁▁▁▁▁▁▁▁▁▁▁█","██████▁▁▁▁▁▁▁▁▁▁▁▁▁█","████████▁▁▁▁▁▁▁▁▁▁▁▁","█████████▁▁▁▁▁▁▁▁▁▁▁","█████████▁▁▁▁▁▁▁▁▁▁▁","█████████▁▁▁▁▁▁▁▁▁▁▁","█████████▁▁▁▁▁▁▁▁▁▁▁","███████████▁▁▁▁▁▁▁▁▁","████████████▁▁▁▁▁▁▁▁","████████████▁▁▁▁▁▁▁▁","██████████████▁▁▁▁▁▁","██████████████▁▁▁▁▁▁","▁██████████████▁▁▁▁▁","▁██████████████▁▁▁▁▁","▁▁▁█████████████▁▁▁▁","▁▁▁▁▁████████████▁▁▁","▁▁▁▁▁████████████▁▁▁","▁▁▁▁▁▁███████████▁▁▁","▁▁▁▁▁▁▁▁█████████▁▁▁","▁▁▁▁▁▁▁▁█████████▁▁▁","▁▁▁▁▁▁▁▁▁█████████▁▁","▁▁▁▁▁▁▁▁▁█████████▁▁","▁▁▁▁▁▁▁▁▁▁█████████▁","▁▁▁▁▁▁▁▁▁▁▁████████▁","▁▁▁▁▁▁▁▁▁▁▁████████▁","▁▁▁▁▁▁▁▁▁▁▁▁███████▁","▁▁▁▁▁▁▁▁▁▁▁▁███████▁","▁▁▁▁▁▁▁▁▁▁▁▁▁███████","▁▁▁▁▁▁▁▁▁▁▁▁▁███████","▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█████","▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁████","▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁████","▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁████","▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁███","▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁███","▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁██","▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁██","▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁██","▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█","▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█","▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█","▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁","▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁","▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁","▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁"]},moon:{interval:80,frames:["🌑 ","🌒 ","🌓 ","🌔 ","🌕 ","🌖 ","🌗 ","🌘 "]},runner:{interval:140,frames:["🚶 ","🏃 "]},pong:{interval:80,frames:["▐⠂ ▌","▐⠈ ▌","▐ ⠂ ▌","▐ ⠠ ▌","▐ ⡀ ▌","▐ ⠠ ▌","▐ ⠂ ▌","▐ ⠈ ▌","▐ ⠂ ▌","▐ ⠠ ▌","▐ ⡀ ▌","▐ ⠠ ▌","▐ ⠂ ▌","▐ ⠈ ▌","▐ ⠂▌","▐ ⠠▌","▐ ⡀▌","▐ ⠠ ▌","▐ ⠂ ▌","▐ ⠈ ▌","▐ ⠂ ▌","▐ ⠠ ▌","▐ ⡀ ▌","▐ ⠠ ▌","▐ ⠂ ▌","▐ ⠈ ▌","▐ ⠂ ▌","▐ ⠠ ▌","▐ ⡀ ▌","▐⠠ ▌"]},shark:{interval:120,frames:["▐|\\____________▌","▐_|\\___________▌","▐__|\\__________▌","▐___|\\_________▌","▐____|\\________▌","▐_____|\\_______▌","▐______|\\______▌","▐_______|\\_____▌","▐________|\\____▌","▐_________|\\___▌","▐__________|\\__▌","▐___________|\\_▌","▐____________|\\▌","▐____________/|▌","▐___________/|_▌","▐__________/|__▌","▐_________/|___▌","▐________/|____▌","▐_______/|_____▌","▐______/|______▌","▐_____/|_______▌","▐____/|________▌","▐___/|_________▌","▐__/|__________▌","▐_/|___________▌","▐/|____________▌"]},dqpb:{interval:100,frames:["d","q","p","b"]},weather:{interval:100,frames:["☀️ ","☀️ ","☀️ ","🌤 ","⛅️ ","🌥 ","☁️ ","🌧 ","🌨 ","🌧 ","🌨 ","🌧 ","🌨 ","⛈ ","🌨 ","🌧 ","🌨 ","☁️ ","🌥 ","⛅️ ","🌤 ","☀️ ","☀️ "]},christmas:{interval:400,frames:["🌲","🎄"]},grenade:{interval:80,frames:["، ","′ "," ´ "," ‾ "," ⸌"," ⸊"," |"," ⁎"," ⁕"," ෴ "," ⁓"," "," "," "]},point:{interval:125,frames:["∙∙∙","●∙∙","∙●∙","∙∙●","∙∙∙"]},layer:{interval:150,frames:["-","=","≡"]},betaWave:{interval:80,frames:["ρββββββ","βρβββββ","ββρββββ","βββρβββ","ββββρββ","βββββρβ","ββββββρ"]},fingerDance:{interval:160,frames:["🤘 ","🤟 ","🖖 ","✋ ","🤚 ","👆 "]},fistBump:{interval:80,frames:["🤜 🤛 ","🤜 🤛 ","🤜 🤛 "," 🤜 🤛 "," 🤜🤛 "," 🤜✨🤛 ","🤜 ✨ 🤛 "]},soccerHeader:{interval:80,frames:[" 🧑⚽️ 🧑 ","🧑 ⚽️ 🧑 ","🧑 ⚽️ 🧑 ","🧑 ⚽️ 🧑 ","🧑 ⚽️ 🧑 ","🧑 ⚽️ 🧑 ","🧑 ⚽️🧑 ","🧑 ⚽️ 🧑 ","🧑 ⚽️ 🧑 ","🧑 ⚽️ 🧑 ","🧑 ⚽️ 🧑 ","🧑 ⚽️ 🧑 "]},mindblown:{interval:160,frames:["😐 ","😐 ","😮 ","😮 ","😦 ","😦 ","😧 ","😧 ","🤯 ","💥 ","✨ "," "," "," "]},speaker:{interval:160,frames:["🔈 ","🔉 ","🔊 ","🔉 "]},orangePulse:{interval:100,frames:["🔸 ","🔶 ","🟠 ","🟠 ","🔶 "]},bluePulse:{interval:100,frames:["🔹 ","🔷 ","🔵 ","🔵 ","🔷 "]},orangeBluePulse:{interval:100,frames:["🔸 ","🔶 ","🟠 ","🟠 ","🔶 ","🔹 ","🔷 ","🔵 ","🔵 ","🔷 "]},timeTravel:{interval:100,frames:["🕛 ","🕚 ","🕙 ","🕘 ","🕗 ","🕖 ","🕕 ","🕔 ","🕓 ","🕒 ","🕑 ","🕐 "]},aesthetic:{interval:80,frames:["▰▱▱▱▱▱▱","▰▰▱▱▱▱▱","▰▰▰▱▱▱▱","▰▰▰▰▱▱▱","▰▰▰▰▰▱▱","▰▰▰▰▰▰▱","▰▰▰▰▰▰▰","▰▱▱▱▱▱▱"]},dwarfFortress:{interval:80,frames:[" ██████£££ ","☺██████£££ ","☺██████£££ ","☺▓█████£££ ","☺▓█████£££ ","☺▒█████£££ ","☺▒█████£££ ","☺░█████£££ ","☺░█████£££ ","☺ █████£££ "," ☺█████£££ "," ☺█████£££ "," ☺▓████£££ "," ☺▓████£££ "," ☺▒████£££ "," ☺▒████£££ "," ☺░████£££ "," ☺░████£££ "," ☺ ████£££ "," ☺████£££ "," ☺████£££ "," ☺▓███£££ "," ☺▓███£££ "," ☺▒███£££ "," ☺▒███£££ "," ☺░███£££ "," ☺░███£££ "," ☺ ███£££ "," ☺███£££ "," ☺███£££ "," ☺▓██£££ "," ☺▓██£££ "," ☺▒██£££ "," ☺▒██£££ "," ☺░██£££ "," ☺░██£££ "," ☺ ██£££ "," ☺██£££ "," ☺██£££ "," ☺▓█£££ "," ☺▓█£££ "," ☺▒█£££ "," ☺▒█£££ "," ☺░█£££ "," ☺░█£££ "," ☺ █£££ "," ☺█£££ "," ☺█£££ "," ☺▓£££ "," ☺▓£££ "," ☺▒£££ "," ☺▒£££ "," ☺░£££ "," ☺░£££ "," ☺ £££ "," ☺£££ "," ☺£££ "," ☺▓££ "," ☺▓££ "," ☺▒££ "," ☺▒££ "," ☺░££ "," ☺░££ "," ☺ ££ "," ☺££ "," ☺££ "," ☺▓£ "," ☺▓£ "," ☺▒£ "," ☺▒£ "," ☺░£ "," ☺░£ "," ☺ £ "," ☺£ "," ☺£ "," ☺▓ "," ☺▓ "," ☺▒ "," ☺▒ "," ☺░ "," ☺░ "," ☺ "," ☺ &"," ☺ ☼&"," ☺ ☼ &"," ☺☼ &"," ☺☼ & "," ‼ & "," ☺ & "," ‼ & "," ☺ & "," ‼ & "," ☺ & ","‼ & "," & "," & "," & ░ "," & ▒ "," & ▓ "," & £ "," & ░£ "," & ▒£ "," & ▓£ "," & ££ "," & ░££ "," & ▒££ ","& ▓££ ","& £££ "," ░£££ "," ▒£££ "," ▓£££ "," █£££ "," ░█£££ "," ▒█£££ "," ▓█£££ "," ██£££ "," ░██£££ "," ▒██£££ "," ▓██£££ "," ███£££ "," ░███£££ "," ▒███£££ "," ▓███£££ "," ████£££ "," ░████£££ "," ▒████£££ "," ▓████£££ "," █████£££ "," ░█████£££ "," ▒█████£££ "," ▓█████£££ "," ██████£££ "," ██████£££ "]},fish:{interval:80,frames:["~~~~~~~~~~~~~~~~~~~~","> ~~~~~~~~~~~~~~~~~~","º> ~~~~~~~~~~~~~~~~~","(º> ~~~~~~~~~~~~~~~~","((º> ~~~~~~~~~~~~~~~","<((º> ~~~~~~~~~~~~~~","><((º> ~~~~~~~~~~~~~"," ><((º> ~~~~~~~~~~~~","~ ><((º> ~~~~~~~~~~~","~~ <>((º> ~~~~~~~~~~","~~~ ><((º> ~~~~~~~~~","~~~~ <>((º> ~~~~~~~~","~~~~~ ><((º> ~~~~~~~","~~~~~~ <>((º> ~~~~~~","~~~~~~~ ><((º> ~~~~~","~~~~~~~~ <>((º> ~~~~","~~~~~~~~~ ><((º> ~~~","~~~~~~~~~~ <>((º> ~~","~~~~~~~~~~~ ><((º> ~","~~~~~~~~~~~~ <>((º> ","~~~~~~~~~~~~~ ><((º>","~~~~~~~~~~~~~~ <>((º","~~~~~~~~~~~~~~~ ><((","~~~~~~~~~~~~~~~~ <>(","~~~~~~~~~~~~~~~~~ ><","~~~~~~~~~~~~~~~~~~ <","~~~~~~~~~~~~~~~~~~~~"]}};var LD=zu,Ss=Object.keys(zu);var kD=ju(bu(),1),wc=Object.freeze({accent:92,secondary:94,muted:2}),JD=Object.freeze(["◆","◇","◈","◇"]),dc=Object.freeze(["signal","rail","blocks","pulse","stages"]),kn="signal";function wD(D,u,e){return Math.min(e,Math.max(u,D))}function Z(D,u,e){return e?`\x1B[${wc[D]}m${u}\x1B[0m`:u}function dD(D,u,e){return D[Math.floor(e/u)%D.length]}function HD(D){return`${(D/1048576).toFixed(1)} MB`}function Cc(D,u){let e=u>0?wD(D/u,0,1):0;return{progress:e,percent:Math.floor(e*100)}}function Tu(D,u,e,n="█",r="░"){let t=Math.round(D*u);return Z("accent",n.repeat(t),e)+Z("muted",r.repeat(u-t),e)}function hc(D,u,e){let n=Math.floor(D*u),r="";for(let t=0;t<n;t+=1)r+=Z(t/u<0.33?"accent":"secondary","━",e);if(n<u&&D>0)r+=Z("secondary","╸",e);return r+Z("muted","─".repeat(Math.max(0,u-n-(D>0?1:0))),e)}function mc(D,u,e,n){let r=Math.round(D*u),t=r>0?Math.floor(e/120)%r:-1,c="";for(let i=0;i<u;i+=1)if(i>=r)c+=Z("muted","░",n);else c+=Z(i===t?"secondary":"accent",i===t?"█":"▓",n);return c}function lc({percent:D,now:u,colorEnabled:e}){let n=dD(JD,160,u);return`${Z("accent",n,e)} Updating Free Code · ${D}%`}function Bc(D,u,e){let n=Math.max(1,e-2);if(kD.default(D)<=n)return D;let r=lc(u);if(kD.default(r)<=n)return r;let t=dD(JD,160,u.now),c=`${Z("accent",t,u.colorEnabled)} ${u.percent}%`;if(kD.default(c)<=n)return c;let i=`${u.percent}%`;return kD.default(i)<=n?i:"…"}function bc(D,{downloaded:u,total:e,now:n=Date.now(),maxWidth:r=80,color:t=!0}={}){let c=dc.includes(D)?D:kn,{progress:i,percent:s}=Cc(u,e),f={progress:i,percent:s,now:n,colorEnabled:t},a;if(c==="rail"){let o=dD(LD.arc.frames,LD.arc.interval,n),l=wD(r-42,16,30);a=`${Z("secondary",o,t)} Download ${hc(i,l,t)} ${s}% · ${HD(u)}`}else if(c==="blocks"){let o=wD(r-43,16,30),l=Tu(i,o,t,"■","□");a=`${Z("secondary","▰",t)} Downloading ${l} ${s}% · ${HD(u)}`}else if(c==="pulse"){let o=dD(LD.dots.frames,LD.dots.interval,n),l=wD(r-49,14,28);a=`${Z("secondary",o,t)} Downloading update ${mc(i,l,n,t)} ${s}%`}else if(c==="stages"){let o=dD(JD,160,n),l=wD(r-65,10,18),A=Tu(i,l,t);a=`${Z("secondary",o,t)} Download ${A} ${s}% · ${Z("muted","◇ Verify · ◇ Restart",t)}`}else{let o=dD(JD,160,n),l=wD(r-56,14,26),A=Tu(i,l,t);a=`${Z("secondary",o,t)} Updating Free Code ${A} ${s}% · ${HD(u)} / ${HD(e)}`}return Bc(a,f,r)}function Nn({output:D,total:u,style:e=kn,environment:n=process.env,now:r=Date.now}={}){if(!D?.isTTY||!Number.isFinite(u)||u<=0)return;let t=n.NO_COLOR===void 0&&n.TERM!=="dumb",c=new Ln.default.SingleBar({stream:D,fps:10,clearOnComplete:!1,hideCursor:!0,linewrap:!1,forceRedraw:!0,format:(i,s)=>bc(e,{downloaded:s.value,total:s.total,now:r(),maxWidth:s.maxWidth,color:t})});return c.start(u,0),Object.freeze({update(i){c.update(i)},stop(){c.stop()}})}var Hn="alpha",Ic="https://releases.freecode.sh/channels",Mc="https://releases.freecode.sh/releases",pc="GD597P8KJ2",fD=Object.freeze({launcher:"bin/freecode",interface:"libexec/freecode/freecode-tui",engine:"libexec/freecode/freecode-engine"}),ku=Object.freeze(Object.values(fD)),qc=900000;class m extends Error{constructor(D,u,e={}){super(u,e);if(this.name="FreeCodeUpdateError",this.code=D,e.updateRequired===!0)this.updateRequired=!0;if(e.latestVersion)this.latestVersion=e.latestVersion}}function Sc(D=process.platform,u=process.arch){if(D!=="darwin")return;if(u==="arm64")return"darwin-arm64";if(u==="x64")return"darwin-x64";return}function Mn(D,{channel:u=Hn,target:e}={}){if(!D||typeof D!=="object"||Array.isArray(D))throw new m("invalid_update_manifest","The update manifest is not a JSON object.");if(D.schemaVersion!==1||D.channel!==u||!G(D.version))throw new m("invalid_update_manifest","The update manifest has an invalid schema, channel, or version.");let n=D.security;if(n?.releaseMode!=="signed-notarized"||n?.appleDeveloperIdSigned!==!0||n?.appleNotarized!==!0||n?.unsignedAlphaOverride!==!1)throw new m("untrusted_update","Automatic updates require a Developer ID signed and notarized release.");for(let[c,i]of Object.entries(fD))if(D.payload?.[c]!==i)throw new m("invalid_update_manifest",`The update manifest has an unexpected ${c} path.`);let r=D.assets?.[e],t=`freecode-${e}.tar.gz`;if(!r||r.archive!==t||!/^[a-f0-9]{64}$/i.test(r.sha256||"")||!Number.isSafeInteger(r.size)||r.size<=0)throw new m("invalid_update_manifest",`The update manifest has no valid ${e} asset.`);return Object.freeze({version:D.version,security:Object.freeze({...n}),asset:Object.freeze({...r,sha256:r.sha256.toLowerCase()})})}function Zc(D,u){if(D.version!==u.version)throw new m("release_manifest_mismatch","The immutable release version does not match the channel.");for(let e of["archive","sha256","size"])if(D.asset[e]!==u.asset[e])throw new m("release_manifest_mismatch",`The immutable release ${e} does not match the channel.`)}function Rc(D,{environment:u=process.env,homeDirectory:e=jn()}={}){let n=VD(CD(D),".."),r=CD(n),t=CD(r);if(Ou(r)!=="versions")throw new m("unsupported_install_layout","This Free Code executable is not inside the managed versions directory.");let c=KD(k(t,"bin-dir")),i=VD(u.FREECODE_BIN_DIR||c||k(e,".local","bin"));return Object.freeze({versionDirectory:n,versionsDirectory:r,installRoot:t,binDirectory:i,executableLink:k(i,"freecode"),downloadsDirectory:k(t,"downloads"),lockPath:k(t,".update-lock")})}async function QD({currentVersion:D,nativeExecutable:u,channel:e,channelBaseUrl:n,releaseBaseUrl:r,fetchImpl:t=globalThis.fetch,environment:c=process.env,homeDirectory:i=jn(),output:s=process.stderr,checkOnly:f=!1,platform:a=process.platform,architecture:o=process.arch,channelTimeoutMs:l=3000,releaseManifestTimeoutMs:A=15000,downloadTimeoutMs:b=120000,signatureVerifier:T=Ke,verifyDirectory:eD=jc,extractArchive:w=Kc}={}){if(!G(D))throw new m("invalid_current_version",`The installed version is invalid: ${D||"missing"}.`);if(typeof t!=="function")throw new m("update_network_unavailable","This runtime cannot check for updates.");let h=Rc(u,{environment:c,homeDirectory:i}),B=e||c.FREECODE_UPDATE_CHANNEL||KD(k(h.installRoot,"channel"))||Hn,d=n||c.FREECODE_CHANNEL_BASE_URL||KD(k(h.installRoot,"channel-base-url"))||Ic,x=r||c.FREECODE_INSTALL_BASE_URL||KD(k(h.installRoot,"release-base-url"))||Mc;if(!/^[0-9A-Za-z][0-9A-Za-z._-]*$/.test(B))throw new m("invalid_update_channel",`The update channel is invalid: ${B}.`);let _=Sc(a,o);if(!_)throw new m("unsupported_update_platform","Automatic updates currently support macOS only.");let E=`${Sn(d)}/${B}.json`,v=await pn(E,{fetchImpl:t,timeoutMs:l,headers:{"cache-control":"no-cache"},signatureVerifier:T}),F=Mn(v,{channel:B,target:_});if(eu(D,F.version)>=0)return Object.freeze({status:"current",currentVersion:D,latestVersion:F.version});if(f)return Object.freeze({status:"available",currentVersion:D,latestVersion:F.version});let z;try{z=Xn(h.lockPath);let I=Gc(h);if(G(I)&&eu(I,F.version)>=0)return Object.freeze({status:"updated-by-another-process",currentVersion:D,latestVersion:I,executable:k(h.versionsDirectory,I,fD.launcher)});s.write(`Updating Free Code ${D} → ${F.version}…
|
|
265
|
-
`);let q=`${Sn(x)}/v${F.version}`,X=await pn(`${q}/release-manifest.json`,{fetchImpl:t,timeoutMs:A,headers:{"cache-control":"no-cache"},signatureVerifier:T}),sr=Mn(X,{channel:B,target:_});Zc(sr,F),XD(h.downloadsDirectory,{recursive:!0,mode:448});let bD=k(h.downloadsDirectory,`${F.version}-${_}-${F.asset.archive}`);if(await Wc(`${q}/${F.asset.archive}`,bD,{fetchImpl:t,expectedSize:F.asset.size,output:s,timeoutMs:b}),await Vc(bD)!==F.asset.sha256)throw P(bD,{force:!0}),new m("update_checksum_mismatch","The downloaded update failed SHA-256 verification.");let vD=k(h.versionsDirectory,F.version),Du=!sD(vD);if(!Du)try{eD(vD,{version:F.version,target:_,environment:c})}catch{P(vD,{recursive:!0,force:!0}),Du=!0}if(Du){let oD=k(h.installRoot,`.install-${F.version}-${process.pid}`);P(oD,{recursive:!0,force:!0}),XD(oD,{recursive:!0,mode:448});try{w(bD,oD),eD(oD,{version:F.version,target:_,environment:c}),Yn(oD,vD)}catch(fr){throw P(oD,{recursive:!0,force:!0}),fr}}return Yc(h,F.version),P(bD,{force:!0}),s.write(`Free Code ${F.version} is ready.
|
|
266
|
-
`),Object.freeze({status:"updated",previousVersion:D,latestVersion:F.version,executable:k(vD,fD.launcher)})}catch(I){throw new m("required_update_failed",`Free Code ${F.version} is required, but the update could not be installed: ${I?.message||"unknown error"}`,{cause:I,updateRequired:!0,latestVersion:F.version})}finally{z?.()}}function Yc(D,u){if(!G(u))throw new m("invalid_update_version","Cannot activate an invalid version.");let e=k(D.versionsDirectory,u),n=k(e,fD.launcher);if(!sD(n))throw new m("incomplete_update",`The staged update is missing ${fD.launcher}.`);if(XD(D.binDirectory,{recursive:!0}),sD(D.executableLink)){if(!Nu(D.executableLink).isSymbolicLink())throw new m("unsafe_executable_link",`Refusing to replace non-symlink ${D.executableLink}.`);let c=VD(CD(D.executableLink),Rn(D.executableLink)),i=pu(D.versionsDirectory,c);if(i.startsWith(`..${Lu}`)||i===".."||Mu(i))throw new m("unsafe_executable_link","The active Free Code link points outside the managed version store.")}let r=`${D.executableLink}.update-${process.pid}`;P(r,{force:!0}),Tc(n,r);try{Yn(r,D.executableLink)}catch(t){throw P(r,{force:!0}),t}}function jc(D,{version:u,target:e,environment:n=process.env,commandRunner:r=WD}={}){for(let f of ku){let a=k(D,f);if(!sD(a)||!GD(a).isFile())throw new m("incomplete_update",`The update is missing ${f}.`);vc(a,493)}Jn(D),Jc(D,{version:u,target:e});for(let f of ku)Hc(k(D,f),{commandRunner:r});let t=k(D,fD.launcher),c={...n,FREECODE_DISABLE_AUTOUPDATE:"true"},i=r(t,["--version"],{encoding:"utf8",env:c,timeout:15000});if(i.status!==0||Uc(i.stdout)!==`freecode-sh ${u}`)throw new m("update_health_check_failed","The staged launcher reported the wrong version.");let s=r(t,["doctor","--json"],{encoding:"utf8",env:c,timeout:30000});if(s.status!==0)throw new m("update_health_check_failed","The staged release failed Free Code doctor.");try{if(JSON.parse(s.stdout).ok!==!0)throw Error("doctor not ok")}catch{throw new m("update_health_check_failed","The staged release returned an invalid doctor report.")}}function Hc(D,{commandRunner:u=WD}={}){if(u("/usr/bin/codesign",["--verify","--strict","--verbose=2",D],{encoding:"utf8",timeout:15000}).status!==0)throw new m("update_signature_invalid",`Apple signature verification failed for ${Ou(D)}.`);let n=u("/usr/bin/codesign",["--display","--verbose=4",D],{encoding:"utf8",timeout:15000}),r=`${n.stdout||""}
|
|
267
|
-
${n.stderr||""}`.match(/^TeamIdentifier=(.+)$/m)?.[1]?.trim();if(n.status!==0||r!==pc)throw new m("update_signature_invalid",`The update has an unexpected Apple TeamIdentifier for ${Ou(D)}.`)}function Jc(D,{version:u,target:e}){let n=k(D,"libexec/freecode/bundle-manifest.json"),r;try{r=JSON.parse(Iu(n,"utf8"))}catch{throw new m("invalid_bundle_manifest","The update has no valid bundle manifest.")}let[t,c]=e.split("-");if(r.schemaVersion!==1||r.product!=="freecode-sh"||r.version!==u||r.platform!==t||r.architecture!==c||!r.payload||typeof r.payload!=="object")throw new m("invalid_bundle_manifest","The update bundle metadata does not match this release.");for(let[i,s]of Object.entries(r.payload)){if(!Kn(i)||!/^[a-f0-9]{64}$/i.test(s))throw new m("invalid_bundle_manifest","The update bundle contains invalid payload metadata.");let f=k(D,i);if(!sD(f)||Qc(f)!==s.toLowerCase())throw new m("bundle_checksum_mismatch",`The update payload failed verification: ${i}.`)}for(let i of ku)if(!r.payload[i])throw new m("invalid_bundle_manifest",`The bundle manifest does not cover ${i}.`)}function Kc(D,u){let e=WD("/usr/bin/tar",["-tzf",D],{encoding:"utf8",maxBuffer:16777216,timeout:30000});if(e.status!==0)throw new m("invalid_update_archive","The update archive could not be inspected.");let n=e.stdout.split(`
|
|
268
|
-
`).filter(Boolean);if(n.length===0||n.some((t)=>!Kn(t)))throw new m("invalid_update_archive","The update archive contains an unsafe path.");if(WD("/usr/bin/tar",["-xzf",D,"-C",u],{encoding:"utf8",timeout:120000}).status!==0)throw new m("invalid_update_archive","The update archive could not be extracted.")}function Jn(D,u=D){for(let e of zc(u,{withFileTypes:!0})){let n=k(u,e.name),r=Nu(n);if(r.isSymbolicLink())throw new m("unsafe_update_payload",`The update contains an unexpected symlink: ${pu(D,n)}.`);if(r.isDirectory())Jn(D,n)}}function Kn(D){if(typeof D!=="string"||!D||D.includes("\x00")||Mu(D))return!1;let u=D.replace(/^\.\//,"");return u!==".."&&!u.startsWith("../")&&!u.includes("/../")}async function Wc(D,u,{fetchImpl:e,expectedSize:n,output:r,maxAttempts:t=3,timeoutMs:c=120000}={}){if(sD(u)){if(GD(u).size===n)return;P(u,{force:!0})}let i;for(let s=1;s<=t;s+=1)try{if(await Xc(D,u,{fetchImpl:e,expectedSize:n,output:r,timeoutMs:c}),GD(u).size!==n)throw new m("update_download_incomplete","The update download ended before the expected size.");return}catch(f){if(i=f,P(u,{force:!0}),f?.code==="update_download_oversized")break;if(s<t)await new Promise((a)=>setTimeout(a,s*500))}throw new m("update_download_failed",i?.message||"The update could not be downloaded.",{cause:i})}async function Xc(D,u,{fetchImpl:e,expectedSize:n,output:r,timeoutMs:t}){let c=Nn({output:r,total:n});try{await Wn(D,{fetchImpl:e,timeoutMs:t},async(i)=>{if(!i.ok)throw new m("update_download_failed",`The update server returned HTTP ${i.status}.`);if(!i.body)throw new m("update_download_failed","The update response had no body.");let s=0,f=-1,a=Lc.fromWeb(i.body),o=new kc({transform(l,A,b){if(s+=l.length,s>n){b(new m("update_download_oversized","The update download exceeded the signed archive size."));return}let T=Math.min(100,Math.floor(s/n*100));if(T>=f+5||T===100){if(f=T,c)c.update(s);else if(T%25===0)r.write(`Downloading update… ${T}%
|
|
269
|
-
`)}b(null,l)}});await Nc(a,o,xc(u,{flags:"wx",mode:384}))})}finally{c?.stop()}}function Gc(D){if(!sD(D.executableLink)||!Nu(D.executableLink).isSymbolicLink())return;let u=VD(CD(D.executableLink),Rn(D.executableLink)),e=pu(D.versionsDirectory,u),n=e.split(Lu);if(e.startsWith(`..${Lu}`)||e===".."||Mu(e)||n.length!==3||n[1]!=="bin"||n[2]!=="freecode")return;return G(n[0])?.value}async function pn(D,{fetchImpl:u,timeoutMs:e,headers:n={},signatureVerifier:r}){let[t,c]=await Promise.all([qn(D,{fetchImpl:u,timeoutMs:e,headers:n,kind:"manifest",maxBytes:1048576}),qn(`${D}.sig`,{fetchImpl:u,timeoutMs:e,headers:n,kind:"signature",maxBytes:16384})]);if(!r(t,c))throw new m("update_signature_invalid","The update manifest does not have a valid Free Code release signature.");try{return JSON.parse(t.toString("utf8"))}catch{throw new m("invalid_update_manifest","The update server returned invalid JSON.")}}async function qn(D,{fetchImpl:u,timeoutMs:e,headers:n={},kind:r,maxBytes:t}){return Wn(D,{fetchImpl:u,timeoutMs:e,headers:n},async(c)=>{if(!c.ok)throw new m("update_network_unavailable",`The update server returned HTTP ${c.status}.`);let i=Buffer.from(await c.arrayBuffer());if(i.length===0||i.length>t)throw new m("invalid_update_manifest",`The update ${r} has an invalid size.`);return i})}async function Wn(D,{fetchImpl:u,timeoutMs:e,headers:n={}},r){let t=new AbortController,c=setTimeout(()=>t.abort(Error("update request timed out")),e);try{let i=await u(D,{redirect:"follow",signal:t.signal,headers:{accept:"application/json, application/octet-stream;q=0.9","user-agent":"freecode-native-updater",...n}});return await r(i)}catch(i){if(i instanceof m)throw i;throw new m("update_network_unavailable","The update server could not be reached.",{cause:i})}finally{clearTimeout(c)}}function Xn(D){XD(CD(D),{recursive:!0});try{let u=yc(D,"wx",384);try{Oc(u,`${process.pid}
|
|
270
|
-
`)}finally{Ac(u)}return()=>{try{In(D)}catch{}}}catch(u){if(u.code==="EEXIST"){try{if(Date.now()-GD(D).mtimeMs>qc)return In(D),Xn(D)}catch{}throw new m("update_in_progress","Another Free Code update is already in progress.")}throw u}}async function Vc(D){let u=Zn("sha256");for await(let e of $c(D))u.update(e);return u.digest("hex")}function Qc(D){return Zn("sha256").update(Iu(D)).digest("hex")}function KD(D){try{return Iu(D,"utf8").split(/\r?\n/,1)[0].trim()||void 0}catch{return}}function Uc(D){return String(D||"").split(/\r?\n/,1)[0].trim()}function Sn(D){return String(D).replace(/\/+$/,"")}var $=process.env.FREECODE_NATIVE_BUILD==="true",BD=$?gc(process.execPath):void 0,Un=$?lD(g(BD),".."):void 0,DD=$?uD(Un,"libexec","freecode"):g(UD(import.meta.url)),PD=g(g(DD)),H=process.env.FREECODE_RELEASE_VERSION||"0.0.0",p=$?g(g(Un)):void 0,Y=cD(),ui=uD(DD,"engine.manifest.json"),j=$&&process.env.FREECODE_NATIVE_ENGINE_MANIFEST_JSON?JSON.parse(process.env.FREECODE_NATIVE_ENGINE_MANIFEST_JSON):JSON.parse(Pc(ui,"utf8")),qu=(D)=>`\x1B[38;5;75m${D}\x1B[0m`,M=(D)=>`\x1B[38;5;114m${D}\x1B[0m`,N=(D)=>`\x1B[38;5;221m${D}\x1B[0m`,rD=(D)=>`\x1B[2m${D}\x1B[0m`,Su=(D)=>`\x1B[1m${D}\x1B[0m`,Pn=uD(DD,$?"freecode-tui":"standalone.tsx");function ei(){if(process.env.FREECODE_ALPHA_BUILD==="true")return uD(g(UD(import.meta.resolve("@opentui/solid"))),"scripts/preload.js");let D=UD(import.meta.resolve("@freecode/tui/app"));return uD(g(g(D)),"node_modules/@opentui/solid/scripts/preload.js")}function hD(){if($||process.env.FREECODE_ALPHA_BUILD==="true")return process.cwd();let D=[process.env.INIT_CWD,process.env.npm_config_local_prefix,process.env.PWD];for(let u of D)if(u&&Di(u)&&mD(u))return u;return process.cwd()}var ni=new Set(["account","doctor","doom","extensions","help","logout","tui","upgrade","version"]),ri=new Set(["auth","bootstrap","demo","install-opencode","models","run","serve","sidecar"]);function ti(){C.write(`
|
|
271
|
-
${qu("▰")} ${Su("Free Code")} ${rD("local AI coding TUI")}
|
|
272
|
-
|
|
273
|
-
Usage:
|
|
274
|
-
freecode Launch the standalone Free Code TUI in this project
|
|
275
|
-
freecode <project-path> Launch the Free Code TUI for a project
|
|
276
|
-
freecode account Manage signed-in computers
|
|
277
|
-
freecode doctor [--json] Check the local Free Code installation
|
|
278
|
-
freecode extensions [action] Manage optional Free Code extensions
|
|
279
|
-
freecode doom status|install Legacy Doom extension compatibility
|
|
280
|
-
freecode logout Sign out this computer
|
|
281
|
-
freecode upgrade [--check] Install or check for the latest signed release
|
|
282
|
-
freecode version Print the installed Free Code version
|
|
283
|
-
`)}function ci(){let D=$?`freecode-sh ${H}`:"freecode 0.1.0-alpha.12";C.write(`${D}
|
|
284
|
-
`)}function ii(){Ze("https://freecode.sh/account/devices"),C.write(`${M("✓")} Opened your Free Code account.
|
|
285
|
-
${rD("https://freecode.sh/account/devices")}
|
|
286
|
-
`)}function Zu(){if(process.env.FREECODE_ENGINE_BIN)return{command:process.env.FREECODE_ENGINE_BIN,prefix:[],source:"development override"};if($){let e=uD(DD,j.engine.shippedBinary);return mD(e)?{command:e,prefix:[],source:"bundled"}:void 0}let D=TD(DD,j.engine.sourcePackage,j.engine.sourceBinary)||(process.platform==="win32"?void 0:OD(DD,j.engine.sourceBinary));if(D)return{command:D,prefix:[],source:"package"};let u=TD(PD,j.engine.sourcePackage,j.engine.sourceBinary)||(process.platform==="win32"?void 0:OD(PD,j.engine.sourceBinary));if(u)return{command:u,prefix:[],source:"workspace"};return}function gn(){if($)return Pn;let D=[TD(DD,"bun","bun"),TD(PD,"bun","bun"),process.platform==="win32"?void 0:OD(DD,"bun"),process.platform==="win32"?void 0:OD(PD,"bun")];for(let e of D)if(e)return e;let u=nD(qe(),["bun"],{encoding:"utf8"});return u.status===0?Se(u.stdout):void 0}function si(){let D=Zu(),u=$?"Reinstall Free Code.":"Run pnpm install in the Free Code repository.";if(!D)throw Error(`The Free Code engine is missing. ${u}`);if(ur(D)!==j.engine.version)throw Error(`The installed Free Code engine is incompatible with this release. ${u}`);return D}async function Gn(D=[]){let u=D[0]==="tui"?D.slice(1):D,e=u.length===1&&mD(lD(hD(),u[0]))?lD(hD(),u[0]):hD(),n=gn(),r=process.env.FREECODE_ENGINE==="mock"?void 0:si();if(!n)throw Error($?"The bundled Free Code TUI is missing. Reinstall Free Code.":"The pinned Bun runtime is not installed. Run pnpm install.");let t=$?[e,r?.command||"mock"]:["--conditions=browser","--preload",ei(),Pn,e,r?.command||"mock"],c=Qn(n,t,{cwd:e,env:{...process.env,FREECODE_STANDALONE_CONFIG:JSON.stringify(He({nativeBuild:$})),FREECODE_STANDALONE_SPONSOR:JSON.stringify(Hu()||null),FREECODE_ENGINE_PIN:j.engine.version,FREECODE_ALPHA_BUILD:process.env.FREECODE_ALPHA_BUILD||($?"true":void 0),FREECODE_DOOM_RUNTIME_DIR:process.env.FREECODE_DOOM_RUNTIME_DIR||aD(),FREECODE_EXTENSION_MANAGER_BIN:process.env.FREECODE_EXTENSION_MANAGER_BIN||($?BD:void 0),FREECODE_EXTENSION_SNAPSHOT:JSON.stringify(Ru()),FREECODE_RELEASE_VERSION:H,FREECODE_NATIVE_BUILD:$?"true":process.env.FREECODE_NATIVE_BUILD},stdio:"inherit"});return Je(c,{restartForUpdate:()=>oi(D),onSignal:(i)=>process.kill(process.pid,i),onError:(i)=>{C.write(`\x1B[31m${ir(i)}\x1B[0m
|
|
287
|
-
`)}})}async function fi(){let u=await(process.env.FREECODE_ACCOUNT_AUTH_ENABLED==="true"?se():Uu()).logout();C.write(`${M("✓")} Signed out of Free Code${u.remote?".":" locally."}
|
|
288
|
-
`)}async function ai({checkOnly:D=!1}={}){if(!$)return C.write(`${N("!")} Development checkouts are updated through Git, not the native updater.
|
|
289
|
-
`),1;let u=process.env.FREECODE_RELEASE_VERSION||"0.0.0";try{let e=await QD({currentVersion:u,nativeExecutable:BD,checkOnly:D});if(e.status==="current")C.write(`${M("✓")} Free Code ${u} is current.
|
|
290
|
-
`);else if(e.status==="available")C.write(`Free Code ${e.latestVersion} is available; installed: ${u}.
|
|
291
|
-
`);else if(e.status==="updated"||e.status==="updated-by-another-process")C.write(`${M("✓")} Free Code ${e.latestVersion} is installed and will be used next launch.
|
|
292
|
-
`);return 0}catch(e){return C.write(`${N("!")} ${gD(e)}
|
|
293
|
-
`),1}}async function Vn(D){if(!$||process.env.FREECODE_DISABLE_AUTOUPDATE==="true"||process.env.FREECODE_UPDATE_HANDOFF==="true")return;let u=process.env.FREECODE_RELEASE_VERSION||"0.0.0";try{let e=await QD({currentVersion:u,nativeExecutable:BD});if((e.status==="updated"||e.status==="updated-by-another-process")&&e.executable)return Dr(e.executable,D)}catch(e){if(!(e instanceof m&&e.code==="update_network_unavailable")){if(e instanceof m&&e.updateRequired)return C.write(`${N("!")} ${gD(e)}
|
|
294
|
-
`),C.write("Launch stopped so the outdated version cannot continue. Run `freecode upgrade` and try again.\n"),1;C.write(`${N("!")} ${gD(e)} Starting the installed version.
|
|
295
|
-
`)}}return}async function oi(D){if(!$)return C.write(`${N("!")} Free Code needs an update. Restart this development checkout after updating it through Git.
|
|
296
|
-
`),1;let u=process.env.FREECODE_RELEASE_VERSION||"0.0.0";C.write(`A newer version of Free Code is required. Updating and restarting…
|
|
297
|
-
`);try{let e=await QD({currentVersion:u,nativeExecutable:BD});if((e.status==="updated"||e.status==="updated-by-another-process")&&e.executable)return Dr(e.executable,D);return C.write(`${N("!")} The signed release channel does not contain a newer compatible version. Reinstall from https://freecode.sh and try again.
|
|
298
|
-
`),1}catch(e){return C.write(`${N("!")} ${gD(e)}
|
|
299
|
-
`),C.write(`Reopen Free Code to try again, or reinstall from https://freecode.sh.
|
|
300
|
-
`),1}}function Dr(D,u){return new Promise((e)=>{let n=Qn(D,u,{cwd:hD(),env:{...process.env,FREECODE_UPDATE_HANDOFF:"true"},stdio:"inherit"});n.on("exit",(r,t)=>{if(t){process.kill(process.pid,t);return}e(r??1)}),n.on("error",(r)=>{C.write(`${N("!")} The updated Free Code launcher could not start: ${r.message}
|
|
301
|
-
`),e(1)})})}function gD(D){if(D instanceof m)return`Free Code update failed: ${D.message}`;return`Free Code update failed: ${String(D?.message||D||"unknown error")}`}function ur(D){if(!D)return;let u=nD(D.command,[...D.prefix,"--version"],{encoding:"utf8"});if(u.status!==0)return;return u.stdout.trim()||u.stderr.trim()}function Fi({json:D=!1}={}){let u=Zu(),e=ur(u),n=gn(),r=Ru().find((s)=>s.id===W),t=r?.directory||aD(),c={available:Boolean(r?.available),installed:Boolean(r?.installed),enabled:Boolean(r?.enabled),platformSupported:process.platform==="darwin",optional:!0,directory:t,engine:"terminal-doom/doomgeneric stream adapter",gameData:"Freedoom 0.13.0"},i={ok:Boolean(u&&e&&e===j.engine.version&&n),engineReady:Boolean(u&&e),engineSource:u?.source,version:e,versionMatches:e===j.engine.version,interfaceReady:Boolean(n),distribution:$?"native":"development",doom:c};if(D)return C.write(`${JSON.stringify(i,null,2)}
|
|
302
|
-
`),i.ok?0:1;if(C.write(`${qu("▰")} ${Su("Free Code doctor")}
|
|
303
|
-
|
|
304
|
-
`),!u)return C.write(`${N("!")} The Free Code engine is missing.
|
|
305
|
-
`),C.write(`${$?"Reinstall Free Code.":"Run pnpm install in the Free Code repository."}
|
|
306
|
-
`),1;return C.write(`${e===j.engine.version?M("✓"):N("!")} Free Code engine: ${e===j.engine.version?"ready":"incompatible"} ${rD(`(${u.source})`)}
|
|
307
|
-
`),C.write(`${n?M("✓"):N("!")} Terminal interface: ${n?"ready":"missing"}
|
|
308
|
-
`),C.write(`${c.available?M("✓"):rD("·")} Doom extension: ${c.available?`${c.engine} + ${c.gameData}`:c.installed?"disabled":$?"not installed; open /extensions":"not prepared; run pnpm doom:prepare"}
|
|
309
|
-
`),C.write(`${M("✓")} Local connection: authenticated loopback
|
|
310
|
-
`),i.ok?0:1}function aD(){if(process.env.FREECODE_DOOM_RUNTIME_DIR)return lD(process.env.FREECODE_DOOM_RUNTIME_DIR);if(!$||!p||!Y)return uD(DD,"doom");return U({id:W,installRoot:p,releaseVersion:H,target:Y}).directory||xD({installRoot:p,version:ZD,target:Y})}function Ru(){if($&&p)return du({installRoot:p,releaseVersion:H,target:Y});return du({installRoot:p,releaseVersion:H,target:Y,developmentDirectory:aD()})}async function _i(D=[]){let u=D.filter((c)=>!c.startsWith("--")),e=u[0]||"list",n=u[1]||W,r=tD(D,"--json");if(!["list","status","install","enable","disable","uninstall"].includes(e))throw Error("Usage: freecode extensions list|status|install|enable|disable|uninstall [extension-id] [--json]");if(e==="list"||e==="status"){let c=Ru(),i=e==="status"?c.find((s)=>s.id===n)||U({id:n,installRoot:p,releaseVersion:H,target:Y,developmentDirectory:$?void 0:aD()}):c;if(r)C.write(`${JSON.stringify(i,null,2)}
|
|
311
|
-
`);else for(let s of Array.isArray(i)?i:[i]){let f=s.available?"enabled":s.installed?"disabled":"not installed";C.write(`${s.available?M("✓"):rD("·")} ${s.displayName}: ${f}
|
|
312
|
-
`)}return 0}if(!$||!p||!Y)throw Error("Source checkouts manage extension runtimes through repository preparation commands.");let t;if(e==="install"){let c=new AbortController,i=()=>c.abort();process.once("SIGTERM",i);try{t=await Cu({id:n,installRoot:p,releaseVersion:H,target:Y,releaseBaseUrl:process.env.FREECODE_DOOM_RELEASE_BASE_URL,allowUnsigned:process.env.FREECODE_ALLOW_UNSIGNED_DOOM_PACK==="true",signal:c.signal})}finally{process.removeListener("SIGTERM",i)}}else if(e==="enable"||e==="disable"){let c=U({id:n,installRoot:p,releaseVersion:H,target:Y});if(!c.installed)throw Error(`${c.displayName} is not installed`);ke({installRoot:p,id:n,enabled:e==="enable"}),t=U({id:n,installRoot:p,releaseVersion:H,target:Y})}else t=Ne({id:n,installRoot:p,releaseVersion:H,target:Y});if(r)C.write(`${JSON.stringify(t,null,2)}
|
|
313
|
-
`);else C.write(`${M("✓")} ${t.displayName}: ${t.available?"enabled":t.installed?"disabled":"not installed"}
|
|
314
|
-
`);return 0}async function Ei(D=[]){let u=D.find((r)=>!r.startsWith("--"))||"status",e=tD(D,"--json");if(!["status","install"].includes(u))throw Error("Usage: freecode doom status|install [--json]");if(!$||!p||!Y){let r={available:mD(uD(aD(),"freecode-doom-stream"))&&mD(uD(aD(),"freedoom1.wad")),distribution:"development",directory:aD()};if(u==="install"&&!r.available)throw Error("Source checkouts prepare Doom with `pnpm doom:prepare`.");if(e)C.write(`${JSON.stringify(r,null,2)}
|
|
315
|
-
`);else C.write(`${r.available?M("✓"):rD("·")} Doom pack: ${r.available?"ready":"not prepared; run pnpm doom:prepare"}
|
|
316
|
-
`);return r.available?0:1}if(u==="install"){let r=await Cu({id:W,installRoot:p,releaseVersion:H,target:Y,releaseBaseUrl:process.env.FREECODE_DOOM_RELEASE_BASE_URL,allowUnsigned:process.env.FREECODE_ALLOW_UNSIGNED_DOOM_PACK==="true"});if(e)C.write(`${JSON.stringify(r,null,2)}
|
|
317
|
-
`);else C.write(`${M("✓")} Doom extension ${r.installedNow?"installed":"already installed"} (${r.installedVersion||ZD}).
|
|
318
|
-
`);return 0}let n=U({id:W,installRoot:p,releaseVersion:H,target:Y});if(e)C.write(`${JSON.stringify(n,null,2)}
|
|
319
|
-
`);else C.write(`${n.available?M("✓"):rD("·")} Doom extension: ${n.available?"ready":n.installed?"disabled":"not installed; open /extensions"}
|
|
320
|
-
`);return n.available?0:1}function er(D,u,e){let n=D.indexOf(u);if(n===-1)return e;return D[n+1]||e}function tD(D,u){return D.includes(u)}function nr(D){return`'${String(D).replaceAll("'","'\\''")}'`}function rr(D=[]){let u=er(D,"--session",process.env.FREECODE_TMUX_SESSION||"freecode");if(!/^[A-Za-z0-9_.-]+$/.test(u))throw Error("tmux session names may only contain letters, numbers, dots, underscores, and dashes");return u}function tr(){return nD("tmux",["-V"],{encoding:"utf8"}).status===0}function cr({projectDir:D,doomGraphics:u}){let e=$?void 0:UD(import.meta.url),n=$?[BD,D]:[process.execPath,e,D];return[...u?["env",`FREECODE_DOOM_GRAPHICS=${u}`]:[],...n].map(nr).join(" ")}function wi({projectDir:D,session:u,doomGraphics:e}){return["tmux","new-session","-A","-s",u,"-c",D,cr({projectDir:D,doomGraphics:e})]}function di({session:D,screen:u=!1}){let e=tr(),n=e&&nD("tmux",["has-session","-t",D],{encoding:"utf8"}).status===0,r=n?nD("tmux",["list-clients","-t",D,"-F","#{client_name}"],{encoding:"utf8"}):void 0,t=r?.status===0?r.stdout.split(`
|
|
321
|
-
`).filter(Boolean):[],c;if(n&&u){let i=nD("tmux",["capture-pane","-p","-t",`${D}:0.0`,"-S","-200"],{encoding:"utf8"});if(i.status===0)c=i.stdout.replace(/\s+$/,"")}return{available:e,running:n,attached:t.length>0,clients:t,screen:c}}function Ci(D=[]){let u=tD(D,"--json"),e=tD(D,"--screen"),n=rr(D),r=di({session:n,screen:e}),t=Zu(),c={ok:Boolean(r.available&&r.running&&t),session:n,tmux:r,engine:t?{ready:!0,source:t.source}:{ready:!1},checker:`freecode inspect --session ${n} --json --screen`};if(u)C.write(`${JSON.stringify(c,null,2)}
|
|
322
|
-
`);else if(C.write(`${qu("▰")} ${Su("Free Code inspect")}
|
|
323
|
-
|
|
324
|
-
`),C.write(`${r.available?M("✓"):N("!")} tmux installed
|
|
325
|
-
`),C.write(`${r.running?M("✓"):N("!")} session ${n}: ${r.running?"running":"not running"}
|
|
326
|
-
`),C.write(`${t?M("✓"):N("!")} engine: ${t?.source||"missing"}
|
|
327
|
-
`),e&&r.screen)C.write(`
|
|
328
|
-
${r.screen}
|
|
329
|
-
`);return c.ok?0:1}function hi(D){return String(D).replaceAll("\\","\\\\").replaceAll('"',"\\\"")}function mi(D){let u=`tell application "Terminal"
|
|
330
|
-
activate
|
|
331
|
-
do script "${hi(D)}"
|
|
332
|
-
end tell`;return nD("osascript",["-e",u],{encoding:"utf8"})}function li(D,u){return nD("open",["-na","Ghostty.app","--args",`--working-directory=${u}`,"--mouse-reporting=true","-e","zsh","-lc",D],{encoding:"utf8"})}function Bi(D=[]){if(process.platform!=="darwin")return C.write(`${N("!")} freecode open currently supports macOS Terminal and Ghostty.
|
|
333
|
-
`),1;let u=D[0]&&!D[0].startsWith("--")?D[0]:"terminal";if(!["terminal","ghostty"].includes(u))return C.write(`${N("!")} Choose terminal or ghostty.
|
|
334
|
-
`),1;let e=tD(D,"--direct");if(!e&&!tr())return C.write(`${N("!")} tmux is required so user terminals and automated checkers share one TUI session.
|
|
335
|
-
`),1;let n=lD(er(D,"--project",hD())),r=rr(D),t=u==="ghostty"?e?process.env.FREECODE_DOOM_GRAPHICS||"kitty":"cells":void 0,c=e?cr({projectDir:n,doomGraphics:t}):wi({projectDir:n,session:r,doomGraphics:t}).map(nr).join(" "),i={host:u,projectDir:n,mode:e?"direct":"tmux",...e?{}:{session:r},command:c,...e?{}:{checker:`pnpm freecode:inspect -- --session ${r} --json --screen`}};if(tD(D,"--dry-run"))return C.write(`${JSON.stringify(i,null,2)}
|
|
336
|
-
`),0;let s=u==="ghostty"?li(c,n):mi(c);if(s.status!==0)return C.write(`${N("!")} Could not open ${u}: ${(s.stderr||s.error?.message||"unknown error").trim()}
|
|
337
|
-
`),1;if(C.write(`${M("✓")} Opened Free Code in ${u==="ghostty"?"Ghostty":"Terminal"}${e?" (direct high-fidelity mode)":` (tmux session ${r})`}.
|
|
338
|
-
`),i.checker)C.write(`${rD(`Checker: ${i.checker}`)}
|
|
339
|
-
`);return 0}async function bi(){let D=process.argv.slice(2),u=D[0],e=process.env.FREECODE_ALPHA_BUILD==="true",n=D.length===1&&u&&mD(lD(hD(),u));if(e&&u&&(ri.has(u)||!n&&!ni.has(u)&&!["-h","--help","-v","--version"].includes(u)))return C.write(`${N("!")} Unknown Free Code command. Run \`freecode help\`.
|
|
340
|
-
`),2;if(!u||u==="tui"){let r=await Vn(D);return typeof r==="number"?r:Gn(D)}if(u==="-h"||u==="--help"||u==="help")return ti();if(u==="-v"||u==="--version"||u==="version")return ci();if(u==="account")return ii();if(u==="doctor")return Fi({json:tD(D,"--json")});if(u==="doom")return Ei(D.slice(1));if(u==="extensions")return _i(D.slice(1));if(u==="logout")return fi();if(u==="upgrade")return ai({checkOnly:tD(D,"--check")});if(!e&&u==="inspect")return Ci(D.slice(1));if(!e&&u==="open")return Bi(D.slice(1));if(n){let r=await Vn(D);return typeof r==="number"?r:Gn(D)}return C.write(`${N("!")} Unknown Free Code command. Run \`freecode help\`.
|
|
341
|
-
`),2}function ir(D){let u=String(D?.message||D||"Free Code encountered an unexpected error.").trim();if(!/opencode|@opencode-ai/i.test(u))return u;if(/stream|connect|socket|network/i.test(u))return"The Free Code connection was interrupted.";return"The Free Code engine could not start."}try{let D=await bi();if(typeof D==="number")process.exitCode=D}catch(D){C.write(`\x1B[31m${ir(D)}\x1B[0m
|
|
342
|
-
`),process.exitCode=1}
|
|
3
|
+
import { spawn } from 'node:child_process'
|
|
4
|
+
import { constants } from 'node:fs'
|
|
5
|
+
import { access, readFile, realpath } from 'node:fs/promises'
|
|
6
|
+
import { homedir } from 'node:os'
|
|
7
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
8
|
+
import { fileURLToPath } from 'node:url'
|
|
9
|
+
|
|
10
|
+
const packageDirectory = dirname(fileURLToPath(import.meta.url))
|
|
11
|
+
const bootstrapPath = fileURLToPath(import.meta.url)
|
|
12
|
+
const installerPath = join(packageDirectory, 'install.sh')
|
|
13
|
+
const packageMetadata = JSON.parse(await readFile(join(packageDirectory, 'package.json'), 'utf8'))
|
|
14
|
+
|
|
15
|
+
if (packageMetadata.name !== 'freecode-sh' || !/^\d+\.\d+\.\d+-alpha\.\d+$/.test(packageMetadata.version)) {
|
|
16
|
+
fail('The npm package metadata is invalid. Reinstall freecode-sh and try again.')
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const homeDirectory = homedir()
|
|
20
|
+
if (!homeDirectory) fail('HOME is required to install Free Code.')
|
|
21
|
+
|
|
22
|
+
const installRoot = resolve(process.env.FREECODE_INSTALL_ROOT || join(homeDirectory, '.local', 'share', 'freecode'))
|
|
23
|
+
const recordedBinDirectory = await readFirstLine(join(installRoot, 'bin-dir'))
|
|
24
|
+
let binDirectory = resolve(
|
|
25
|
+
process.env.FREECODE_BIN_DIR ||
|
|
26
|
+
recordedBinDirectory ||
|
|
27
|
+
join(installRoot, 'npm-bin'),
|
|
28
|
+
)
|
|
29
|
+
let nativeExecutable = join(binDirectory, 'freecode')
|
|
30
|
+
let nativeVersion = await managedNativeVersion(nativeExecutable, installRoot)
|
|
31
|
+
|
|
32
|
+
if (nativeVersion && compareAlphaVersions(nativeVersion, packageMetadata.version) >= 0) {
|
|
33
|
+
process.exitCode = await run(nativeExecutable, process.argv.slice(2))
|
|
34
|
+
} else {
|
|
35
|
+
if (await sameFile(nativeExecutable, bootstrapPath)) {
|
|
36
|
+
binDirectory = join(installRoot, 'npm-bin')
|
|
37
|
+
nativeExecutable = join(binDirectory, 'freecode')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const platform = process.env.FREECODE_INSTALL_OS === 'Darwin' ? 'darwin' : process.platform
|
|
41
|
+
if (platform !== 'darwin') {
|
|
42
|
+
fail(`Free Code's native npm installer currently supports macOS only (detected ${process.platform}).`)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
process.stderr.write(`Installing Free Code ${packageMetadata.version}…\n`)
|
|
46
|
+
const installStatus = await run('/bin/sh', [installerPath, '--version', packageMetadata.version], {
|
|
47
|
+
...process.env,
|
|
48
|
+
FREECODE_INSTALL_ROOT: installRoot,
|
|
49
|
+
FREECODE_BIN_DIR: binDirectory,
|
|
50
|
+
FREECODE_INSTALL_EMBEDDED: 'true',
|
|
51
|
+
})
|
|
52
|
+
if (installStatus !== 0) process.exit(installStatus)
|
|
53
|
+
nativeVersion = await managedNativeVersion(nativeExecutable, installRoot)
|
|
54
|
+
if (!nativeVersion || compareAlphaVersions(nativeVersion, packageMetadata.version) < 0) {
|
|
55
|
+
fail('The signed installer completed without creating a managed Free Code executable.')
|
|
56
|
+
}
|
|
57
|
+
process.exitCode = await run(nativeExecutable, process.argv.slice(2))
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function managedNativeVersion(path, root) {
|
|
61
|
+
try {
|
|
62
|
+
await access(path, constants.X_OK)
|
|
63
|
+
const target = await realpath(path)
|
|
64
|
+
const versionsDirectory = await realpath(resolve(root, 'versions'))
|
|
65
|
+
const relativeTarget = relative(versionsDirectory, target)
|
|
66
|
+
const parts = relativeTarget.split(sep)
|
|
67
|
+
if (
|
|
68
|
+
relativeTarget === '..' ||
|
|
69
|
+
relativeTarget.startsWith(`..${sep}`) ||
|
|
70
|
+
isAbsolute(relativeTarget) ||
|
|
71
|
+
parts.length !== 3 ||
|
|
72
|
+
parts[1] !== 'bin' ||
|
|
73
|
+
parts[2] !== 'freecode' ||
|
|
74
|
+
!/^\d+\.\d+\.\d+-alpha\.\d+$/.test(parts[0])
|
|
75
|
+
) {
|
|
76
|
+
return undefined
|
|
77
|
+
}
|
|
78
|
+
return parts[0]
|
|
79
|
+
} catch {
|
|
80
|
+
return undefined
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function compareAlphaVersions(left, right) {
|
|
85
|
+
const parse = (version) => {
|
|
86
|
+
const match = version.match(/^(\d+)\.(\d+)\.(\d+)-alpha\.(\d+)$/)
|
|
87
|
+
if (!match) fail(`The managed Free Code version is invalid: ${version}`)
|
|
88
|
+
return match.slice(1).map(Number)
|
|
89
|
+
}
|
|
90
|
+
const leftParts = parse(left)
|
|
91
|
+
const rightParts = parse(right)
|
|
92
|
+
for (let index = 0; index < leftParts.length; index += 1) {
|
|
93
|
+
if (leftParts[index] !== rightParts[index]) return leftParts[index] - rightParts[index]
|
|
94
|
+
}
|
|
95
|
+
return 0
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function sameFile(left, right) {
|
|
99
|
+
try {
|
|
100
|
+
return (await realpath(left)) === (await realpath(right))
|
|
101
|
+
} catch {
|
|
102
|
+
return false
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async function readFirstLine(path) {
|
|
107
|
+
try {
|
|
108
|
+
return (await readFile(path, 'utf8')).split(/\r?\n/, 1)[0]?.trim() || undefined
|
|
109
|
+
} catch {
|
|
110
|
+
return undefined
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function run(command, args, environment = process.env) {
|
|
115
|
+
return new Promise((resolvePromise, reject) => {
|
|
116
|
+
const child = spawn(command, args, {
|
|
117
|
+
cwd: process.cwd(),
|
|
118
|
+
env: environment,
|
|
119
|
+
stdio: 'inherit',
|
|
120
|
+
})
|
|
121
|
+
child.once('error', reject)
|
|
122
|
+
child.once('exit', (code, signal) => resolvePromise(code ?? (signal ? 1 : 0)))
|
|
123
|
+
}).catch((error) => fail(`Could not start ${command}: ${error.message}`))
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function fail(message) {
|
|
127
|
+
process.stderr.write(`freecode: ${message}\n`)
|
|
128
|
+
process.exit(1)
|
|
129
|
+
}
|