@brianlovin/hn-cli 0.4.17 → 0.4.18

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.
Files changed (2) hide show
  1. package/dist/cli.js +2 -2
  2. package/package.json +6 -6
package/dist/cli.js CHANGED
@@ -89,7 +89,7 @@ ${A}</tr>
89
89
  `}strong({tokens:A}){return`<strong>${this.parser.parseInline(A)}</strong>`}em({tokens:A}){return`<em>${this.parser.parseInline(A)}</em>`}codespan({text:A}){return`<code>${qg(A,!0)}</code>`}br(A){return"<br>"}del({tokens:A}){return`<del>${this.parser.parseInline(A)}</del>`}link({href:A,title:q,tokens:g}){let E=this.parser.parseInline(g),F=nJ(A);if(F===null)return E;A=F;let K='<a href="'+A+'"';return q&&(K+=' title="'+qg(q)+'"'),K+=">"+E+"</a>",K}image({href:A,title:q,text:g,tokens:E}){E&&(g=this.parser.parseInline(E,this.parser.textRenderer));let F=nJ(A);if(F===null)return qg(g);A=F;let K=`<img src="${A}" alt="${g}"`;return q&&(K+=` title="${qg(q)}"`),K+=">",K}text(A){return"tokens"in A&&A.tokens?this.parser.parseInline(A.tokens):("escaped"in A)&&A.escaped?A.text:qg(A.text)}},QG=class{strong({text:A}){return A}em({text:A}){return A}codespan({text:A}){return A}del({text:A}){return A}html({text:A}){return A}text({text:A}){return A}link({text:A}){return""+A}image({text:A}){return""+A}br(){return""}checkbox({raw:A}){return A}},Iq=class A{options;renderer;textRenderer;constructor(q){this.options=q||Z6,this.options.renderer=this.options.renderer||new kZ,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new QG}static parse(q,g){return new A(g).parse(q)}static parseInline(q,g){return new A(g).parseInline(q)}parse(q){let g="";for(let E=0;E<q.length;E++){let F=q[E];if(this.options.extensions?.renderers?.[F.type]){let Z=F,j=this.options.extensions.renderers[Z.type].call({parser:this},Z);if(j!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(Z.type)){g+=j||"";continue}}let K=F;switch(K.type){case"space":{g+=this.renderer.space(K);break}case"hr":{g+=this.renderer.hr(K);break}case"heading":{g+=this.renderer.heading(K);break}case"code":{g+=this.renderer.code(K);break}case"table":{g+=this.renderer.table(K);break}case"blockquote":{g+=this.renderer.blockquote(K);break}case"list":{g+=this.renderer.list(K);break}case"checkbox":{g+=this.renderer.checkbox(K);break}case"html":{g+=this.renderer.html(K);break}case"def":{g+=this.renderer.def(K);break}case"paragraph":{g+=this.renderer.paragraph(K);break}case"text":{g+=this.renderer.text(K);break}default:{let Z='Token with "'+K.type+'" type was not found.';if(this.options.silent)return console.error(Z),"";throw Error(Z)}}}return g}parseInline(q,g=this.renderer){let E="";for(let F=0;F<q.length;F++){let K=q[F];if(this.options.extensions?.renderers?.[K.type]){let j=this.options.extensions.renderers[K.type].call({parser:this},K);if(j!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(K.type)){E+=j||"";continue}}let Z=K;switch(Z.type){case"escape":{E+=g.text(Z);break}case"html":{E+=g.html(Z);break}case"link":{E+=g.link(Z);break}case"image":{E+=g.image(Z);break}case"checkbox":{E+=g.checkbox(Z);break}case"strong":{E+=g.strong(Z);break}case"em":{E+=g.em(Z);break}case"codespan":{E+=g.codespan(Z);break}case"br":{E+=g.br(Z);break}case"del":{E+=g.del(Z);break}case"text":{E+=g.text(Z);break}default:{let j='Token with "'+Z.type+'" type was not found.';if(this.options.silent)return console.error(j),"";throw Error(j)}}}return E}},qF=class{options;block;constructor(A){this.options=A||Z6}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(A){return A}postprocess(A){return A}processAllTokens(A){return A}emStrongMask(A){return A}provideLexer(){return this.block?Tq.lex:Tq.lexInline}provideParser(){return this.block?Iq.parse:Iq.parseInline}},FH=class{defaults=EG();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=Iq;Renderer=kZ;TextRenderer=QG;Lexer=Tq;Tokenizer=wZ;Hooks=qF;constructor(...A){this.use(...A)}walkTokens(A,q){let g=[];for(let E of A)switch(g=g.concat(q.call(this,E)),E.type){case"table":{let F=E;for(let K of F.header)g=g.concat(this.walkTokens(K.tokens,q));for(let K of F.rows)for(let Z of K)g=g.concat(this.walkTokens(Z.tokens,q));break}case"list":{let F=E;g=g.concat(this.walkTokens(F.items,q));break}default:{let F=E;this.defaults.extensions?.childTokens?.[F.type]?this.defaults.extensions.childTokens[F.type].forEach((K)=>{let Z=F[K].flat(1/0);g=g.concat(this.walkTokens(Z,q))}):F.tokens&&(g=g.concat(this.walkTokens(F.tokens,q)))}}return g}use(...A){let q=this.defaults.extensions||{renderers:{},childTokens:{}};return A.forEach((g)=>{let E={...g};if(E.async=this.defaults.async||E.async||!1,g.extensions&&(g.extensions.forEach((F)=>{if(!F.name)throw Error("extension name required");if("renderer"in F){let K=q.renderers[F.name];K?q.renderers[F.name]=function(...Z){let j=F.renderer.apply(this,Z);return j===!1&&(j=K.apply(this,Z)),j}:q.renderers[F.name]=F.renderer}if("tokenizer"in F){if(!F.level||F.level!=="block"&&F.level!=="inline")throw Error("extension level must be 'block' or 'inline'");let K=q[F.level];K?K.unshift(F.tokenizer):q[F.level]=[F.tokenizer],F.start&&(F.level==="block"?q.startBlock?q.startBlock.push(F.start):q.startBlock=[F.start]:F.level==="inline"&&(q.startInline?q.startInline.push(F.start):q.startInline=[F.start]))}"childTokens"in F&&F.childTokens&&(q.childTokens[F.name]=F.childTokens)}),E.extensions=q),g.renderer){let F=this.defaults.renderer||new kZ(this.defaults);for(let K in g.renderer){if(!(K in F))throw Error(`renderer '${K}' does not exist`);if(["options","parser"].includes(K))continue;let Z=K,j=g.renderer[Z],U=F[Z];F[Z]=(...G)=>{let Y=j.apply(F,G);return Y===!1&&(Y=U.apply(F,G)),Y||""}}E.renderer=F}if(g.tokenizer){let F=this.defaults.tokenizer||new wZ(this.defaults);for(let K in g.tokenizer){if(!(K in F))throw Error(`tokenizer '${K}' does not exist`);if(["options","rules","lexer"].includes(K))continue;let Z=K,j=g.tokenizer[Z],U=F[Z];F[Z]=(...G)=>{let Y=j.apply(F,G);return Y===!1&&(Y=U.apply(F,G)),Y}}E.tokenizer=F}if(g.hooks){let F=this.defaults.hooks||new qF;for(let K in g.hooks){if(!(K in F))throw Error(`hook '${K}' does not exist`);if(["options","block"].includes(K))continue;let Z=K,j=g.hooks[Z],U=F[Z];qF.passThroughHooks.has(K)?F[Z]=(G)=>{if(this.defaults.async&&qF.passThroughHooksRespectAsync.has(K))return(async()=>{let M=await j.call(F,G);return U.call(F,M)})();let Y=j.call(F,G);return U.call(F,Y)}:F[Z]=(...G)=>{if(this.defaults.async)return(async()=>{let M=await j.apply(F,G);return M===!1&&(M=await U.apply(F,G)),M})();let Y=j.apply(F,G);return Y===!1&&(Y=U.apply(F,G)),Y}}E.hooks=F}if(g.walkTokens){let F=this.defaults.walkTokens,K=g.walkTokens;E.walkTokens=function(Z){let j=[];return j.push(K.call(this,Z)),F&&(j=j.concat(F.call(this,Z))),j}}this.defaults={...this.defaults,...E}}),this}setOptions(A){return this.defaults={...this.defaults,...A},this}lexer(A,q){return Tq.lex(A,q??this.defaults)}parser(A,q){return Iq.parse(A,q??this.defaults)}parseMarkdown(A){return(q,g)=>{let E={...g},F={...this.defaults,...E},K=this.onError(!!F.silent,!!F.async);if(this.defaults.async===!0&&E.async===!1)return K(Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof q>"u"||q===null)return K(Error("marked(): input parameter is undefined or null"));if(typeof q!="string")return K(Error("marked(): input parameter is of type "+Object.prototype.toString.call(q)+", string expected"));if(F.hooks&&(F.hooks.options=F,F.hooks.block=A),F.async)return(async()=>{let Z=F.hooks?await F.hooks.preprocess(q):q,j=await(F.hooks?await F.hooks.provideLexer():A?Tq.lex:Tq.lexInline)(Z,F),U=F.hooks?await F.hooks.processAllTokens(j):j;F.walkTokens&&await Promise.all(this.walkTokens(U,F.walkTokens));let G=await(F.hooks?await F.hooks.provideParser():A?Iq.parse:Iq.parseInline)(U,F);return F.hooks?await F.hooks.postprocess(G):G})().catch(K);try{F.hooks&&(q=F.hooks.preprocess(q));let Z=(F.hooks?F.hooks.provideLexer():A?Tq.lex:Tq.lexInline)(q,F);F.hooks&&(Z=F.hooks.processAllTokens(Z)),F.walkTokens&&this.walkTokens(Z,F.walkTokens);let j=(F.hooks?F.hooks.provideParser():A?Iq.parse:Iq.parseInline)(Z,F);return F.hooks&&(j=F.hooks.postprocess(j)),j}catch(Z){return K(Z)}}}onError(A,q){return(g)=>{if(g.message+=`
90
90
  Please report this to https://github.com/markedjs/marked.`,A){let E="<p>An error occurred:</p><pre>"+qg(g.message+"",!0)+"</pre>";return q?Promise.resolve(E):E}if(q)return Promise.reject(g);throw g}}},K6=new FH;function OA(A,q){return K6.parse(A,q)}OA.options=OA.setOptions=function(A){return K6.setOptions(A),OA.defaults=K6.defaults,JO(OA.defaults),OA};OA.getDefaults=EG;OA.defaults=Z6;OA.use=function(...A){return K6.use(...A),OA.defaults=K6.defaults,JO(OA.defaults),OA};OA.walkTokens=function(A,q){return K6.walkTokens(A,q)};OA.parseInline=K6.parseInline;OA.Parser=Iq;OA.parser=Iq.parse;OA.Renderer=kZ;OA.TextRenderer=QG;OA.Lexer=Tq;OA.lexer=Tq.lex;OA.Tokenizer=wZ;OA.Hooks=qF;OA.parse=OA;var{options:xN,setOptions:RN,use:hN,walkTokens:SN,parseInline:zN}=OA,aN=Iq.parse,BN=Tq.lex;var KH=JA.fromHex("#9a9ea3"),ZH=JA.fromHex("#252527");class TO extends DA{orientation;_value;_min;_max;_viewPortSize;_backgroundColor;_foregroundColor;_onChange;constructor(A,q){super(A,{flexShrink:0,...q});this.orientation=q.orientation,this._min=q.min??0,this._max=q.max??100,this._value=q.value??this._min,this._viewPortSize=q.viewPortSize??Math.max(1,(this._max-this._min)*0.1),this._onChange=q.onChange,this._backgroundColor=q.backgroundColor?u(q.backgroundColor):ZH,this._foregroundColor=q.foregroundColor?u(q.foregroundColor):KH,this.setupMouseHandling()}get value(){return this._value}set value(A){let q=Math.max(this._min,Math.min(this._max,A));if(q!==this._value)this._value=q,this._onChange?.(q),this.emit("change",{value:q}),this.requestRender()}get min(){return this._min}set min(A){if(A!==this._min){if(this._min=A,this._value<A)this.value=A;this.requestRender()}}get max(){return this._max}set max(A){if(A!==this._max){if(this._max=A,this._value>A)this.value=A;this.requestRender()}}set viewPortSize(A){let q=Math.max(0.01,Math.min(A,this._max-this._min));if(q!==this._viewPortSize)this._viewPortSize=q,this.requestRender()}get viewPortSize(){return this._viewPortSize}get backgroundColor(){return this._backgroundColor}set backgroundColor(A){this._backgroundColor=u(A),this.requestRender()}get foregroundColor(){return this._foregroundColor}set foregroundColor(A){this._foregroundColor=u(A),this.requestRender()}calculateDragOffsetVirtual(A){let q=this.orientation==="vertical"?this.y:this.x,g=(this.orientation==="vertical"?A.y:A.x)-q,E=Math.max(0,Math.min((this.orientation==="vertical"?this.height:this.width)*2,g*2)),F=this.getVirtualThumbStart(),K=this.getVirtualThumbSize();return Math.max(0,Math.min(K,E-F))}setupMouseHandling(){let A=!1,q=0;this.onMouseDown=(g)=>{g.stopPropagation(),g.preventDefault();let E=this.getThumbRect();if(g.x>=E.x&&g.x<E.x+E.width&&g.y>=E.y&&g.y<E.y+E.height)A=!0,q=this.calculateDragOffsetVirtual(g);else this.updateValueFromMouseDirect(g),A=!0,q=this.calculateDragOffsetVirtual(g)},this.onMouseDrag=(g)=>{if(!A)return;g.stopPropagation(),this.updateValueFromMouseWithOffset(g,q)},this.onMouseUp=(g)=>{if(A)this.updateValueFromMouseWithOffset(g,q);A=!1}}updateValueFromMouseDirect(A){let q=this.orientation==="vertical"?this.y:this.x,g=this.orientation==="vertical"?this.height:this.width,F=(this.orientation==="vertical"?A.y:A.x)-q,K=Math.max(0,Math.min(g,F)),Z=g===0?0:K/g,j=this._max-this._min,U=this._min+Z*j;this.value=U}updateValueFromMouseWithOffset(A,q){let g=this.orientation==="vertical"?this.y:this.x,E=this.orientation==="vertical"?this.height:this.width,F=this.orientation==="vertical"?A.y:A.x,K=E*2,Z=F-g,U=Math.max(0,Math.min(E,Z))*2,G=this.getVirtualThumbSize(),Y=Math.max(0,K-G),M=U-q;M=Math.max(0,Math.min(Y,M));let Q=Y===0?0:M/Y,$=this._max-this._min,_=this._min+Q*$;this.value=_}getThumbRect(){let A=this.getVirtualThumbSize(),q=this.getVirtualThumbStart(),g=Math.floor(q/2),E=Math.ceil((q+A)/2)-g;if(this.orientation==="vertical")return{x:this.x,y:this.y+g,width:this.width,height:Math.max(1,E)};else return{x:this.x+g,y:this.y,width:Math.max(1,E),height:this.height}}renderSelf(A){if(this.orientation==="horizontal")this.renderHorizontal(A);else this.renderVertical(A)}renderHorizontal(A){let q=this.getVirtualThumbSize(),g=this.getVirtualThumbStart(),E=g+q;A.fillRect(this.x,this.y,this.width,this.height,this._backgroundColor);let F=Math.floor(g/2),K=Math.ceil(E/2)-1,Z=Math.max(0,F),j=Math.min(this.width-1,K);for(let U=Z;U<=j;U++){let G=U*2,Y=G+2,M=Math.max(g,G),$=Math.min(E,Y)-M,_=" ";if($>=2)_="\u2588";else if(M===G)_="\u258C";else _="\u2590";for(let P=0;P<this.height;P++)A.setCellWithAlphaBlending(this.x+U,this.y+P,_,this._foregroundColor,this._backgroundColor)}}renderVertical(A){let q=this.getVirtualThumbSize(),g=this.getVirtualThumbStart(),E=g+q;A.fillRect(this.x,this.y,this.width,this.height,this._backgroundColor);let F=Math.floor(g/2),K=Math.ceil(E/2)-1,Z=Math.max(0,F),j=Math.min(this.height-1,K);for(let U=Z;U<=j;U++){let G=U*2,Y=G+2,M=Math.max(g,G),$=Math.min(E,Y)-M,_=" ";if($>=2)_="\u2588";else if($>0)if(M-G===0)_="\u2580";else _="\u2584";for(let P=0;P<this.width;P++)A.setCellWithAlphaBlending(this.x+P,this.y+U,_,this._foregroundColor,this._backgroundColor)}}getVirtualThumbSize(){let A=this.orientation==="vertical"?this.height*2:this.width*2,q=this._max-this._min;if(q===0)return A;let g=Math.max(1,this._viewPortSize),E=q+g;if(E<=g)return A;let F=g/E,K=Math.floor(A*F);return Math.max(1,Math.min(K,A))}getVirtualThumbStart(){let A=this.orientation==="vertical"?this.height*2:this.width*2,q=this._max-this._min;if(q===0)return 0;let g=(this._value-this._min)/q,E=this.getVirtualThumbSize();return Math.round(g*(A-E))}}class eU extends DA{slider;startArrow;endArrow;orientation;_focusable=!0;_scrollSize=0;_scrollPosition=0;_viewportSize=0;_showArrows=!1;_manualVisibility=!1;_onChange;scrollStep=null;get visible(){return super.visible}set visible(A){this._manualVisibility=!0,super.visible=A}resetVisibilityControl(){this._manualVisibility=!1,this.recalculateVisibility()}get scrollSize(){return this._scrollSize}get scrollPosition(){return this._scrollPosition}get viewportSize(){return this._viewportSize}set scrollSize(A){if(A===this.scrollSize)return;this._scrollSize=A,this.recalculateVisibility(),this.updateSliderFromScrollState(),this.scrollPosition=this.scrollPosition}set scrollPosition(A){let q=Math.round(Math.min(Math.max(0,A),this.scrollSize-this.viewportSize));if(q!==this._scrollPosition)this._scrollPosition=q,this.updateSliderFromScrollState()}set viewportSize(A){if(A===this.viewportSize)return;this._viewportSize=A,this.slider.viewPortSize=Math.max(1,this._viewportSize),this.recalculateVisibility(),this.updateSliderFromScrollState(),this.scrollPosition=this.scrollPosition}get showArrows(){return this._showArrows}set showArrows(A){if(A===this._showArrows)return;this._showArrows=A,this.startArrow.visible=A,this.endArrow.visible=A}constructor(A,{trackOptions:q,arrowOptions:g,orientation:E,showArrows:F=!1,...K}){super(A,{flexDirection:E==="vertical"?"column":"row",alignSelf:"stretch",alignItems:"stretch",...K});this._onChange=K.onChange,this.orientation=E,this._showArrows=F;let Z=Math.max(0,this._scrollSize-this._viewportSize),j=Math.max(1,this._viewportSize),U=q?.viewPortSize??j;this.slider=new TO(A,{orientation:E,min:0,max:Z,value:this._scrollPosition,viewPortSize:U,onChange:(Q)=>{this._scrollPosition=Math.round(Q),this._onChange?.(this._scrollPosition),this.emit("change",{position:this._scrollPosition})},...E==="vertical"?{width:Math.max(1,Math.min(2,this.width)),height:"100%",marginLeft:"auto"}:{width:"100%",height:1,marginTop:"auto"},flexGrow:1,flexShrink:1,...q}),this.updateSliderFromScrollState();let G=g?{foregroundColor:g.backgroundColor,backgroundColor:g.backgroundColor,attributes:g.attributes,...g}:{};this.startArrow=new AG(A,{alignSelf:"center",visible:this.showArrows,direction:this.orientation==="vertical"?"up":"left",height:this.orientation==="vertical"?1:1,...G}),this.endArrow=new AG(A,{alignSelf:"center",visible:this.showArrows,direction:this.orientation==="vertical"?"down":"right",height:this.orientation==="vertical"?1:1,...G}),this.add(this.startArrow),this.add(this.slider),this.add(this.endArrow);let Y=void 0,M=void 0;this.startArrow.onMouseDown=(Q)=>{Q.stopPropagation(),Q.preventDefault(),this.scrollBy(-0.5,"viewport"),Y=setTimeout(()=>{this.scrollBy(-0.5,"viewport"),Y=setInterval(()=>{this.scrollBy(-0.2,"viewport")},200)},500)},this.startArrow.onMouseUp=(Q)=>{Q.stopPropagation(),clearInterval(Y)},this.endArrow.onMouseDown=(Q)=>{Q.stopPropagation(),Q.preventDefault(),this.scrollBy(0.5,"viewport"),M=setTimeout(()=>{this.scrollBy(0.5,"viewport"),M=setInterval(()=>{this.scrollBy(0.2,"viewport")},200)},500)},this.endArrow.onMouseUp=(Q)=>{Q.stopPropagation(),clearInterval(M)}}set arrowOptions(A){Object.assign(this.startArrow,A),Object.assign(this.endArrow,A),this.requestRender()}set trackOptions(A){Object.assign(this.slider,A),this.requestRender()}updateSliderFromScrollState(){let A=Math.max(0,this._scrollSize-this._viewportSize);this.slider.min=0,this.slider.max=A,this.slider.value=Math.min(this._scrollPosition,A)}scrollBy(A,q="absolute"){let E=(q==="viewport"?this.viewportSize:q==="content"?this.scrollSize:q==="step"?this.scrollStep??1:1)*A;this.scrollPosition+=E}recalculateVisibility(){if(!this._manualVisibility){let A=this.scrollSize<=this.viewportSize?1:this.viewportSize/this.scrollSize;super.visible=A<1}}handleKeyPress(A){switch(A.name){case"left":case"h":if(this.orientation!=="horizontal")return!1;return this.scrollBy(-0.2,"viewport"),!0;case"right":case"l":if(this.orientation!=="horizontal")return!1;return this.scrollBy(0.2,"viewport"),!0;case"up":case"k":if(this.orientation!=="vertical")return!1;return this.scrollBy(-0.2,"viewport"),!0;case"down":case"j":if(this.orientation!=="vertical")return!1;return this.scrollBy(0.2,"viewport"),!0;case"pageup":return this.scrollBy(-0.5,"viewport"),!0;case"pagedown":return this.scrollBy(0.5,"viewport"),!0;case"home":return this.scrollBy(-1,"content"),!0;case"end":return this.scrollBy(1,"content"),!0}return!1}}class AG extends DA{_direction;_foregroundColor;_backgroundColor;_attributes;_arrowChars;constructor(A,q){super(A,q);if(this._direction=q.direction,this._foregroundColor=q.foregroundColor?u(q.foregroundColor):JA.fromValues(1,1,1,1),this._backgroundColor=q.backgroundColor?u(q.backgroundColor):JA.fromValues(0,0,0,0),this._attributes=q.attributes??0,this._arrowChars={up:"\u25B2",down:"\u25BC",left:"\u25C0",right:"\u25B6",...q.arrowChars},!q.width)this.width=Bun.stringWidth(this.getArrowChar())}get direction(){return this._direction}set direction(A){if(this._direction!==A)this._direction=A,this.requestRender()}get foregroundColor(){return this._foregroundColor}set foregroundColor(A){if(this._foregroundColor!==A)this._foregroundColor=u(A),this.requestRender()}get backgroundColor(){return this._backgroundColor}set backgroundColor(A){if(this._backgroundColor!==A)this._backgroundColor=u(A),this.requestRender()}get attributes(){return this._attributes}set attributes(A){if(this._attributes!==A)this._attributes=A,this.requestRender()}set arrowChars(A){this._arrowChars={...this._arrowChars,...A},this.requestRender()}renderSelf(A){let q=this.getArrowChar();A.drawText(q,this.x,this.y,this._foregroundColor,this._backgroundColor,this._attributes)}getArrowChar(){switch(this._direction){case"up":return this._arrowChars.up;case"down":return this._arrowChars.down;case"left":return this._arrowChars.left;case"right":return this._arrowChars.right;default:return"?"}}}class IO extends y{viewport;_viewportCulling;constructor(A,q,g,E){super(A,E);this.viewport=q,this._viewportCulling=g}get viewportCulling(){return this._viewportCulling}set viewportCulling(A){this._viewportCulling=A}_getVisibleChildren(){if(this._viewportCulling)return lU(this.viewport,this.getChildrenSortedByPrimaryAxis(),this.primaryAxis,0).map((A)=>A.num);return this.getChildrenSortedByPrimaryAxis().map((A)=>A.num)}}class kq extends y{static idCounter=0;internalId=0;wrapper;viewport;content;horizontalScrollBar;verticalScrollBar;_focusable=!0;selectionListener;autoScrollMouseX=0;autoScrollMouseY=0;autoScrollThresholdVertical=3;autoScrollThresholdHorizontal=3;autoScrollSpeedSlow=6;autoScrollSpeedMedium=36;autoScrollSpeedFast=72;isAutoScrolling=!1;cachedAutoScrollSpeed=3;autoScrollAccumulatorX=0;autoScrollAccumulatorY=0;scrollAccumulatorX=0;scrollAccumulatorY=0;_stickyScroll;_stickyScrollTop=!1;_stickyScrollBottom=!1;_stickyScrollLeft=!1;_stickyScrollRight=!1;_stickyStart;_hasManualScroll=!1;_isApplyingStickyScroll=!1;scrollAccel;get stickyScroll(){return this._stickyScroll}set stickyScroll(A){this._stickyScroll=A,this.updateStickyState()}get stickyStart(){return this._stickyStart}set stickyStart(A){this._stickyStart=A,this.updateStickyState()}get scrollTop(){return this.verticalScrollBar.scrollPosition}set scrollTop(A){if(this.verticalScrollBar.scrollPosition=A,!this._isApplyingStickyScroll){let q=Math.max(0,this.scrollHeight-this.viewport.height);if(!this.isAtStickyPosition()&&q>1)this._hasManualScroll=!0}this.updateStickyState()}get scrollLeft(){return this.horizontalScrollBar.scrollPosition}set scrollLeft(A){if(this.horizontalScrollBar.scrollPosition=A,!this._isApplyingStickyScroll){let q=Math.max(0,this.scrollWidth-this.viewport.width);if(!this.isAtStickyPosition()&&q>1)this._hasManualScroll=!0}this.updateStickyState()}get scrollWidth(){return this.horizontalScrollBar.scrollSize}get scrollHeight(){return this.verticalScrollBar.scrollSize}updateStickyState(){if(!this._stickyScroll)return;let A=Math.max(0,this.scrollHeight-this.viewport.height),q=Math.max(0,this.scrollWidth-this.viewport.width);if(this.scrollTop<=0){if(this._stickyScrollTop=!0,this._stickyScrollBottom=!1,this._stickyStart==="top"||this._stickyStart==="bottom"&&A===0)this._hasManualScroll=!1}else if(this.scrollTop>=A){if(this._stickyScrollTop=!1,this._stickyScrollBottom=!0,this._stickyStart==="bottom")this._hasManualScroll=!1}else this._stickyScrollTop=!1,this._stickyScrollBottom=!1;if(this.scrollLeft<=0){if(this._stickyScrollLeft=!0,this._stickyScrollRight=!1,this._stickyStart==="left"||this._stickyStart==="right"&&q===0)this._hasManualScroll=!1}else if(this.scrollLeft>=q){if(this._stickyScrollLeft=!1,this._stickyScrollRight=!0,this._stickyStart==="right")this._hasManualScroll=!1}else this._stickyScrollLeft=!1,this._stickyScrollRight=!1}applyStickyStart(A){switch(this._isApplyingStickyScroll=!0,A){case"top":this._stickyScrollTop=!0,this._stickyScrollBottom=!1,this.verticalScrollBar.scrollPosition=0;break;case"bottom":this._stickyScrollTop=!1,this._stickyScrollBottom=!0,this.verticalScrollBar.scrollPosition=Math.max(0,this.scrollHeight-this.viewport.height);break;case"left":this._stickyScrollLeft=!0,this._stickyScrollRight=!1,this.horizontalScrollBar.scrollPosition=0;break;case"right":this._stickyScrollLeft=!1,this._stickyScrollRight=!0,this.horizontalScrollBar.scrollPosition=Math.max(0,this.scrollWidth-this.viewport.width);break}this._isApplyingStickyScroll=!1}constructor(A,{wrapperOptions:q,viewportOptions:g,contentOptions:E,rootOptions:F,scrollbarOptions:K,verticalScrollbarOptions:Z,horizontalScrollbarOptions:j,stickyScroll:U=!1,stickyStart:G,scrollX:Y=!1,scrollY:M=!0,scrollAcceleration:Q,viewportCulling:$=!0,..._}){super(A,{flexDirection:"row",alignItems:"stretch",..._,...F});if(this.internalId=kq.idCounter++,this._stickyScroll=U,this._stickyStart=G,this.scrollAccel=Q??new kU,this.wrapper=new y(A,{flexDirection:"column",flexGrow:1,...q,id:`scroll-box-wrapper-${this.internalId}`}),super.add(this.wrapper),this.viewport=new y(A,{flexDirection:"column",flexGrow:1,overflow:"hidden",onSizeChange:()=>{this.recalculateBarProps()},...g,id:`scroll-box-viewport-${this.internalId}`}),this.wrapper.add(this.viewport),this.content=new IO(A,this.viewport,$,{alignSelf:"flex-start",flexShrink:0,...Y?{minWidth:"100%"}:{minWidth:"100%",maxWidth:"100%"},...M?{minHeight:"100%"}:{minHeight:"100%",maxHeight:"100%"},onSizeChange:()=>{this.recalculateBarProps()},...E,id:`scroll-box-content-${this.internalId}`}),this.viewport.add(this.content),this.verticalScrollBar=new eU(A,{...K,...Z,arrowOptions:{...K?.arrowOptions,...Z?.arrowOptions},id:`scroll-box-vertical-scrollbar-${this.internalId}`,orientation:"vertical",onChange:(P)=>{if(this.content.translateY=-P,!this._isApplyingStickyScroll){let N=Math.max(0,this.scrollHeight-this.viewport.height);if(!this.isAtStickyPosition()&&N>1)this._hasManualScroll=!0}this.updateStickyState()}}),super.add(this.verticalScrollBar),this.horizontalScrollBar=new eU(A,{...K,...j,arrowOptions:{...K?.arrowOptions,...j?.arrowOptions},id:`scroll-box-horizontal-scrollbar-${this.internalId}`,orientation:"horizontal",onChange:(P)=>{if(this.content.translateX=-P,!this._isApplyingStickyScroll){let N=Math.max(0,this.scrollWidth-this.viewport.width);if(!this.isAtStickyPosition()&&N>1)this._hasManualScroll=!0}this.updateStickyState()}}),this.wrapper.add(this.horizontalScrollBar),this.recalculateBarProps(),G&&U)this.applyStickyStart(G);this.selectionListener=()=>{let P=this._ctx.getSelection();if(!P||!P.isSelecting)this.stopAutoScroll()},this._ctx.on("selection",this.selectionListener)}onUpdate(A){this.handleAutoScroll(A)}scrollBy(A,q="absolute"){if(typeof A==="number")this.verticalScrollBar.scrollBy(A,q);else this.verticalScrollBar.scrollBy(A.y,q),this.horizontalScrollBar.scrollBy(A.x,q)}scrollTo(A){if(typeof A==="number")this.scrollTop=A;else this.scrollTop=A.y,this.scrollLeft=A.x}isAtStickyPosition(){if(!this._stickyScroll||!this._stickyStart)return!1;let A=Math.max(0,this.scrollHeight-this.viewport.height),q=Math.max(0,this.scrollWidth-this.viewport.width);switch(this._stickyStart){case"top":return this.scrollTop===0;case"bottom":return this.scrollTop>=A;case"left":return this.scrollLeft===0;case"right":return this.scrollLeft>=q;default:return!1}}add(A,q){return this.content.add(A,q)}insertBefore(A,q){return this.content.insertBefore(A,q)}remove(A){this.content.remove(A)}getChildren(){return this.content.getChildren()}onMouseEvent(A){if(A.type==="scroll"){let q=A.scroll?.direction;if(A.modifiers.shift)q=q==="up"?"left":q==="down"?"right":q==="right"?"down":"up";let g=A.scroll?.delta??0,E=Date.now(),F=this.scrollAccel.tick(E),K=g*F;if(q==="up"){this.scrollAccumulatorY-=K;let U=Math.trunc(this.scrollAccumulatorY);if(U!==0)this.scrollTop+=U,this.scrollAccumulatorY-=U}else if(q==="down"){this.scrollAccumulatorY+=K;let U=Math.trunc(this.scrollAccumulatorY);if(U!==0)this.scrollTop+=U,this.scrollAccumulatorY-=U}else if(q==="left"){this.scrollAccumulatorX-=K;let U=Math.trunc(this.scrollAccumulatorX);if(U!==0)this.scrollLeft+=U,this.scrollAccumulatorX-=U}else if(q==="right"){this.scrollAccumulatorX+=K;let U=Math.trunc(this.scrollAccumulatorX);if(U!==0)this.scrollLeft+=U,this.scrollAccumulatorX-=U}let Z=Math.max(0,this.scrollHeight-this.viewport.height),j=Math.max(0,this.scrollWidth-this.viewport.width);if(Z>1||j>1)this._hasManualScroll=!0}if(A.type==="drag"&&A.isSelecting)this.updateAutoScroll(A.x,A.y);else if(A.type==="up")this.stopAutoScroll()}handleKeyPress(A){if(this.verticalScrollBar.handleKeyPress(A))return this._hasManualScroll=!0,this.scrollAccel.reset(),this.resetScrollAccumulators(),!0;if(this.horizontalScrollBar.handleKeyPress(A))return this._hasManualScroll=!0,this.scrollAccel.reset(),this.resetScrollAccumulators(),!0;return!1}resetScrollAccumulators(){this.scrollAccumulatorX=0,this.scrollAccumulatorY=0}startAutoScroll(A,q){if(this.stopAutoScroll(),this.autoScrollMouseX=A,this.autoScrollMouseY=q,this.cachedAutoScrollSpeed=this.getAutoScrollSpeed(A,q),this.isAutoScrolling=!0,!this.live)this.live=!0}updateAutoScroll(A,q){this.autoScrollMouseX=A,this.autoScrollMouseY=q,this.cachedAutoScrollSpeed=this.getAutoScrollSpeed(A,q);let g=this.getAutoScrollDirectionX(A),E=this.getAutoScrollDirectionY(q);if(g===0&&E===0)this.stopAutoScroll();else if(!this.isAutoScrolling)this.startAutoScroll(A,q)}stopAutoScroll(){let A=this.isAutoScrolling;if(this.isAutoScrolling=!1,this.autoScrollAccumulatorX=0,this.autoScrollAccumulatorY=0,A&&!this.hasOtherLiveReasons())this.live=!1}hasOtherLiveReasons(){return!1}handleAutoScroll(A){if(!this.isAutoScrolling)return;let q=this.getAutoScrollDirectionX(this.autoScrollMouseX),g=this.getAutoScrollDirectionY(this.autoScrollMouseY),E=this.cachedAutoScrollSpeed*(A/1000),F=!1;if(q!==0){this.autoScrollAccumulatorX+=q*E;let K=Math.trunc(this.autoScrollAccumulatorX);if(K!==0)this.scrollLeft+=K,this.autoScrollAccumulatorX-=K,F=!0}if(g!==0){this.autoScrollAccumulatorY+=g*E;let K=Math.trunc(this.autoScrollAccumulatorY);if(K!==0)this.scrollTop+=K,this.autoScrollAccumulatorY-=K,F=!0}if(F)this._ctx.requestSelectionUpdate();if(q===0&&g===0)this.stopAutoScroll()}getAutoScrollDirectionX(A){let q=A-this.x,g=q,E=this.width-q;if(g<=this.autoScrollThresholdHorizontal)return this.scrollLeft>0?-1:0;else if(E<=this.autoScrollThresholdHorizontal){let F=this.scrollWidth-this.viewport.width;return this.scrollLeft<F?1:0}return 0}getAutoScrollDirectionY(A){let q=A-this.y,g=q,E=this.height-q;if(g<=this.autoScrollThresholdVertical)return this.scrollTop>0?-1:0;else if(E<=this.autoScrollThresholdVertical){let F=this.scrollHeight-this.viewport.height;return this.scrollTop<F?1:0}return 0}getAutoScrollSpeed(A,q){let g=A-this.x,E=q-this.y,F=g,K=this.width-g,Z=E,j=this.height-E,U=Math.min(F,K,Z,j);if(U<=1)return this.autoScrollSpeedFast;else if(U<=2)return this.autoScrollSpeedMedium;else return this.autoScrollSpeedSlow}recalculateBarProps(){let A=this._isApplyingStickyScroll;if(this._isApplyingStickyScroll=!0,this.verticalScrollBar.scrollSize=this.content.height,this.verticalScrollBar.viewportSize=this.viewport.height,this.horizontalScrollBar.scrollSize=this.content.width,this.horizontalScrollBar.viewportSize=this.viewport.width,this._stickyScroll){let q=Math.max(0,this.scrollHeight-this.viewport.height),g=Math.max(0,this.scrollWidth-this.viewport.width);if(this._stickyStart&&!this._hasManualScroll)this.applyStickyStart(this._stickyStart);else{if(this._stickyScrollTop)this.scrollTop=0;else if(this._stickyScrollBottom&&q>0)this.scrollTop=q;if(this._stickyScrollLeft)this.scrollLeft=0;else if(this._stickyScrollRight&&g>0)this.scrollLeft=g}}this._isApplyingStickyScroll=A,process.nextTick(()=>{this.requestRender()})}set rootOptions(A){Object.assign(this,A),this.requestRender()}set wrapperOptions(A){Object.assign(this.wrapper,A),this.requestRender()}set viewportOptions(A){Object.assign(this.viewport,A),this.requestRender()}set contentOptions(A){Object.assign(this.content,A),this.requestRender()}set scrollbarOptions(A){Object.assign(this.verticalScrollBar,A),Object.assign(this.horizontalScrollBar,A),this.requestRender()}set verticalScrollbarOptions(A){Object.assign(this.verticalScrollBar,A),this.requestRender()}set horizontalScrollbarOptions(A){Object.assign(this.horizontalScrollBar,A),this.requestRender()}get scrollAcceleration(){return this.scrollAccel}set scrollAcceleration(A){this.scrollAccel=A}get viewportCulling(){return this.content.viewportCulling}set viewportCulling(A){this.content.viewportCulling=A,this.requestRender()}destroySelf(){if(this.selectionListener)this._ctx.off("selection",this.selectionListener),this.selectionListener=void 0;super.destroySelf()}}var jH;((A)=>{A.SELECTION_CHANGED="selectionChanged",A.ITEM_SELECTED="itemSelected"})(jH||={});var UH;((A)=>{A.SELECTION_CHANGED="selectionChanged",A.ITEM_SELECTED="itemSelected"})(UH||={});import{exec as AW}from"child_process";import{spawn as oV}from"child_process";import{appendFileSync as GH,writeFileSync as YH}from"fs";import{join as QH}from"path";import{homedir as JH}from"os";var xO=QH(JH(),".config","hn-cli","debug.log"),PO=!1;function OH(){if(!PO)try{YH(xO,`--- HN CLI Debug Log Started: ${new Date().toISOString()} ---
91
91
  `),PO=!0}catch{}}function EA(...A){OH();let q=new Date().toISOString(),g=A.map((E)=>{if(typeof E==="object")try{return JSON.stringify(E,null,2)}catch{return String(E)}return String(E)}).join(" ");try{GH(xO,`[${q}] ${g}
92
- `)}catch{}}import{homedir as MH}from"os";import{join as RO}from"path";import{existsSync as hO,mkdirSync as $H,readFileSync as _H,writeFileSync as XH}from"fs";var SO=[{id:"claude-haiku-4-5-20251001",name:"Claude Haiku 4.5"},{id:"claude-sonnet-4-5-20250929",name:"Claude Sonnet 4.5"},{id:"claude-opus-4-5-20251101",name:"Claude Opus 4.5"}],zO=[{id:"gpt-5-nano-2025-08-07",name:"GPT-5 Nano"},{id:"gpt-5-mini-2025-08-07",name:"GPT-5 Mini"},{id:"gpt-5.2-2025-12-11",name:"GPT-5.2"}],HH="claude-haiku-4-5-20251001",VH="gpt-5-nano-2025-08-07",j6="claude-haiku-4-5-20251001",xg="gpt-5-nano-2025-08-07",JG=RO(MH(),".config","hn-cli"),OG=RO(JG,"config.json");function aO(A){if(!A.anthropicApiKey)delete A.anthropicModel;if(!A.openaiApiKey)delete A.openaiModel;if(A.provider){if(!(A.provider==="anthropic"?!!A.anthropicApiKey:!!A.openaiApiKey))delete A.provider}return A}function tA(){try{if(hO(OG)){let A=_H(OG,"utf-8"),q=JSON.parse(A);return aO(q)}}catch{}return{}}function Fg(A){if(!hO(JG))$H(JG,{recursive:!0});let q=aO(A);XH(OG,JSON.stringify(q,null,2))}function nA(A){if(A==="anthropic"){if(process.env.ANTHROPIC_API_KEY)return process.env.ANTHROPIC_API_KEY}else if(A==="openai"){if(process.env.OPENAI_API_KEY)return process.env.OPENAI_API_KEY}let q=tA();if(A==="anthropic")return q.anthropicApiKey;else return q.openaiApiKey}function U6(){if(process.env.ANTHROPIC_API_KEY)return"anthropic";if(process.env.OPENAI_API_KEY)return"openai";let A=tA();if(A.provider&&nA(A.provider))return A.provider;if(A.anthropicApiKey)return"anthropic";if(A.openaiApiKey)return"openai";return}function BO(){return U6()!==void 0}function ZF(A){let q=tA();if(A==="anthropic")return q.anthropicModel||HH;else return q.openaiModel||VH}function wO(A,q){let g=tA();if(A==="anthropic")g.anthropicModel=q;else g.openaiModel=q;Fg(g)}function kO(){let A=tA();Fg({telemetryEnabled:A.telemetryEnabled,userId:A.userId,filterSettings:A.filterSettings})}function G6(){return tA().telemetryEnabled!==!1}function bZ(A){let q=tA();q.telemetryEnabled=A,Fg(q)}function CO(){let A=tA();if(A.userId)return A.userId;let q=crypto.randomUUID();return A.userId=q,Fg(A),q}var yO="0.4.17";var bO={name:"@brianlovin/hn-cli",version:yO,description:"Interactive terminal UI for browsing Hacker News",module:"src/index.ts",type:"module",bin:{hn:"./bin/hn"},files:["dist","bin"],scripts:{start:"bun run src/index.ts",dev:"bun run --watch src/index.ts","dev:update":"HN_SIMULATE_VERSION=0.1.0 HN_SIMULATE_LATEST=0.3.0 bun run --watch src/index.ts",build:"bun build src/index.ts --outdir dist --target bun --minify --entry-naming cli.js","build:binaries":"bun run script/build-binaries.ts","build:binaries:single":"bun run script/build-binaries.ts --single",prepublishOnly:"bun run build && bun run typecheck",test:"bun test",typecheck:"bun tsc --noEmit",debug:"bun run src/debug.ts"},repository:{type:"git",url:"git+https://github.com/brianlovin/hn-cli.git"},homepage:"https://github.com/brianlovin/hn-cli",bugs:"https://github.com/brianlovin/hn-cli/issues",author:"Brian Lovin",license:"MIT",keywords:["hacker-news","cli","terminal","tui","hn"],engines:{bun:">=1.0.0"},publishConfig:{access:"public",provenance:!0},devDependencies:{"@types/bun":"latest"},peerDependencies:{typescript:"^5"},dependencies:{"@anthropic-ai/sdk":"^0.71.2","@opentui/core":"^0.1.75",openai:"^6.16.0"},optionalDependencies:{"@brianlovin/hn-cli-darwin-arm64":"0.4.17","@brianlovin/hn-cli-darwin-x64":"0.4.17","@brianlovin/hn-cli-linux-arm64":"0.4.17","@brianlovin/hn-cli-linux-x64":"0.4.17","@brianlovin/hn-cli-windows-x64":"0.4.17"}};var WH=bO.version;function vO(){if(IH)return!1;if(process.argv.includes("--telemetry-test"))return!1;if(process.argv.includes("--watch"))return!0;let A=process.argv[1]||"";if(A.includes("/src/")||A.endsWith("/src/index.ts"))return!0;return!1}var LH="https://brianlovin.com/api/hn-cli/telemetry",_G=10,NH=5000,TH=1500,MG=3,Pq=[],XG=!1,IH=!1,$G=!1,e6=0;function mO(){XG=!0}function dA(A,q){if(!XG||!G6()||vO())return;if(Pq.push({event:A,timestamp:Date.now(),properties:q}),Pq.length>=_G)PH().catch(()=>{})}async function PH(){await cO(NH)}async function fO(){await cO(TH)}async function cO(A){if(!XG||!G6()||vO()||Pq.length===0)return;if($G)return;if(e6>=MG)return;$G=!0;let q=[...Pq];Pq=[];try{let g=CO(),E=new AbortController,F=setTimeout(()=>E.abort(),A),K=await fetch(LH,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({userId:g,version:WH,events:q}),signal:E.signal});if(clearTimeout(F),!K.ok){if(e6++,Pq.length<_G*2&&e6<MG)Pq=[...q,...Pq]}else e6=0}catch{if(e6++,Pq.length<_G*2&&e6<MG)Pq=[...q,...Pq]}finally{$G=!1}}var Y6={maxPosts:24,fetchLimit:200,hoursWindow:24,minPoints:50,minComments:20,commentWeight:0.75,recencyBonusMax:100,maxRootComments:12,maxChildComments:8,maxCommentLevel:3,storiesTtlMinutes:5},AE={maxPosts:{min:1,max:50,step:1,label:"Max Stories",description:"Maximum number of stories to display"},fetchLimit:{min:50,max:500,step:50,label:"Fetch Limit",description:"Number of posts to fetch from HN API"},hoursWindow:{min:1,max:168,step:1,label:"Time Window (hours)",description:"Only show stories that are trending in this window"},minPoints:{min:0,max:500,step:10,label:"Min Points",description:"The minimum number of votes required"},minComments:{min:0,max:100,step:5,label:"Min Comments",description:"The minimum number of comments required"},commentWeight:{min:0,max:2,step:0.25,label:"Comment Weight",description:"Weight of comments in ranking (0-2)"},recencyBonusMax:{min:0,max:200,step:10,label:"Recency Bonus",description:"Maximum bonus points for new posts"},maxRootComments:{min:1,max:50,step:1,label:"Root Comments",description:"How many root comments to display per story"},maxChildComments:{min:1,max:20,step:1,label:"Child Comments",description:"The maximum number of child comments to display per root comment"},maxCommentLevel:{min:1,max:10,step:1,label:"Nesting Depth",description:"The maximum depth of nested replies to display"},storiesTtlMinutes:{min:1,max:60,step:1,label:"Cache TTL (min)",description:"How long to cache stories before refresh"}},pO=[{key:"filtering",label:"Story Filtering",settings:["maxPosts","hoursWindow","minPoints","minComments"]},{key:"comments",label:"Comments",settings:["maxRootComments","maxChildComments","maxCommentLevel"]}];function dO(A,q){let g=AE[A],E=Math.max(g.min,Math.min(g.max,q)),F=Math.round((E-g.min)/g.step);return g.min+F*g.step}function uO(A){let q={...Y6};for(let g of Object.keys(Y6))if(A[g]!==void 0)q[g]=dO(g,A[g]);return q}function Gq(){let A=tA();if(!A.filterSettings)return{...Y6};return uO(A.filterSettings)}function lO(A){let q=tA();q.filterSettings=uO(A),Fg(q)}function iO(A,q){let g=Gq();return g[A]=dO(A,q),lO(g),g}function tO(){return lO(Y6),{...Y6}}function nO(A,q){if(A==="commentWeight")return q.toFixed(2);return String(q)}var xH="https://hacker-news.firebaseio.com/v0",sO="https://api.hnpwa.com/v0";async function RH(){let A=await fetch(`${xH}/topstories.json`);if(!A.ok)throw Error("Failed to fetch top stories");return A.json()}function rO(A,q){if(!A)return null;if(A.level>q.maxCommentLevel)return null;return{...A,comments:A.comments.slice(0,q.maxChildComments).map((g)=>rO(g,q)).filter(Boolean)}}function oO(A,q,g){let E=A.comments.slice(0,g.maxRootComments).map((F)=>rO(F,g)).filter(Boolean);return{...A,comments:q?E:[]}}async function VG(A,q){let g=q??Gq();try{let E=await fetch(`${sO}/item/${A}.json`);if(!E.ok)return null;let F=await E.json();return oO(F,!0,g)}catch{return null}}async function eO(A){let q=A??Gq(),E=(await RH()).sort((Q,$)=>$-Q).slice(0,q.fetchLimit),F=await Promise.all(E.map(async(Q)=>{try{let $=await fetch(`${sO}/item/${Q}.json`);if(!$.ok)return null;let _=await $.json();return oO(_,!1,q)}catch{return null}})),K=Date.now()/1000,Z=K-3600*q.hoursWindow;return F.filter((Q)=>Q!==null).filter((Q)=>Q.type==="link").filter((Q)=>Q.time>Z).filter((Q)=>(Q.points||0)>=q.minPoints||Q.comments_count>=q.minComments).sort((Q,$)=>{let _=(K-Q.time)/3600,P=(K-$.time)/3600,N=Math.max(0,q.recencyBonusMax*(1-_/q.hoursWindow)),W=Math.max(0,q.recencyBonusMax*(1-P/q.hoursWindow)),x=(Q.points||0)+Q.comments_count*q.commentWeight+N;return($.points||0)+$.comments_count*q.commentWeight+W-x}).slice(0,q.maxPosts)}var hH={bg:void 0,bgSelected:"#2a2a2a",border:"#3a3a3a",textPrimary:"#e0e0e0",textSecondary:"#888888",textTertiary:"#666666",accent:"#ff6600",link:"#6699ff",success:"#4ade80",error:"#ef4444",hint:"#a855f7",commentL1:"#555555",commentL2:"#444444",commentL3:"#333333"},SH={bg:void 0,bgSelected:"#e8e8e8",border:"#cccccc",textPrimary:"#1a1a1a",textSecondary:"#666666",textTertiary:"#888888",accent:"#ff6600",link:"#0066cc",success:"#22c55e",error:"#dc2626",hint:"#9333ea",commentL1:"#cccccc",commentL2:"#dddddd",commentL3:"#eeeeee"},V={...hH};function zH(A){if(!A)return!1;let q=A.replace("#",""),g=parseInt(q.substr(0,2),16),E=parseInt(q.substr(2,2),16),F=parseInt(q.substr(4,2),16);return(0.299*g+0.587*E+0.114*F)/255>0.5}async function AM(A){try{let q=await A.getPalette({timeout:100});if(q.defaultBackground&&zH(q.defaultBackground))Object.assign(V,SH)}catch{}}function qM(A){return{0:V.accent,1:V.commentL1,2:V.commentL2,3:V.commentL3}[A]??V.commentL3}var yA=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function Rg(A){return A.replace(/<\/p>\s*<p>/g,`
92
+ `)}catch{}}import{homedir as MH}from"os";import{join as RO}from"path";import{existsSync as hO,mkdirSync as $H,readFileSync as _H,writeFileSync as XH}from"fs";var SO=[{id:"claude-haiku-4-5-20251001",name:"Claude Haiku 4.5"},{id:"claude-sonnet-4-5-20250929",name:"Claude Sonnet 4.5"},{id:"claude-opus-4-5-20251101",name:"Claude Opus 4.5"}],zO=[{id:"gpt-5-nano-2025-08-07",name:"GPT-5 Nano"},{id:"gpt-5-mini-2025-08-07",name:"GPT-5 Mini"},{id:"gpt-5.2-2025-12-11",name:"GPT-5.2"}],HH="claude-haiku-4-5-20251001",VH="gpt-5-nano-2025-08-07",j6="claude-haiku-4-5-20251001",xg="gpt-5-nano-2025-08-07",JG=RO(MH(),".config","hn-cli"),OG=RO(JG,"config.json");function aO(A){if(!A.anthropicApiKey)delete A.anthropicModel;if(!A.openaiApiKey)delete A.openaiModel;if(A.provider){if(!(A.provider==="anthropic"?!!A.anthropicApiKey:!!A.openaiApiKey))delete A.provider}return A}function tA(){try{if(hO(OG)){let A=_H(OG,"utf-8"),q=JSON.parse(A);return aO(q)}}catch{}return{}}function Fg(A){if(!hO(JG))$H(JG,{recursive:!0});let q=aO(A);XH(OG,JSON.stringify(q,null,2))}function nA(A){if(A==="anthropic"){if(process.env.ANTHROPIC_API_KEY)return process.env.ANTHROPIC_API_KEY}else if(A==="openai"){if(process.env.OPENAI_API_KEY)return process.env.OPENAI_API_KEY}let q=tA();if(A==="anthropic")return q.anthropicApiKey;else return q.openaiApiKey}function U6(){if(process.env.ANTHROPIC_API_KEY)return"anthropic";if(process.env.OPENAI_API_KEY)return"openai";let A=tA();if(A.provider&&nA(A.provider))return A.provider;if(A.anthropicApiKey)return"anthropic";if(A.openaiApiKey)return"openai";return}function BO(){return U6()!==void 0}function ZF(A){let q=tA();if(A==="anthropic")return q.anthropicModel||HH;else return q.openaiModel||VH}function wO(A,q){let g=tA();if(A==="anthropic")g.anthropicModel=q;else g.openaiModel=q;Fg(g)}function kO(){let A=tA();Fg({telemetryEnabled:A.telemetryEnabled,userId:A.userId,filterSettings:A.filterSettings})}function G6(){return tA().telemetryEnabled!==!1}function bZ(A){let q=tA();q.telemetryEnabled=A,Fg(q)}function CO(){let A=tA();if(A.userId)return A.userId;let q=crypto.randomUUID();return A.userId=q,Fg(A),q}var yO="0.4.18";var bO={name:"@brianlovin/hn-cli",version:yO,description:"Interactive terminal UI for browsing Hacker News",module:"src/index.ts",type:"module",bin:{hn:"./bin/hn"},files:["dist","bin"],scripts:{start:"bun run src/index.ts",dev:"bun run --watch src/index.ts","dev:update":"HN_SIMULATE_VERSION=0.1.0 HN_SIMULATE_LATEST=0.3.0 bun run --watch src/index.ts",build:"bun build src/index.ts --outdir dist --target bun --minify --entry-naming cli.js","build:binaries":"bun run script/build-binaries.ts","build:binaries:single":"bun run script/build-binaries.ts --single",prepublishOnly:"bun run build && bun run typecheck",test:"bun test",typecheck:"bun tsc --noEmit",debug:"bun run src/debug.ts"},repository:{type:"git",url:"git+https://github.com/brianlovin/hn-cli.git"},homepage:"https://github.com/brianlovin/hn-cli",bugs:"https://github.com/brianlovin/hn-cli/issues",author:"Brian Lovin",license:"MIT",keywords:["hacker-news","cli","terminal","tui","hn"],engines:{bun:">=1.0.0"},publishConfig:{access:"public",provenance:!0},devDependencies:{"@types/bun":"latest"},peerDependencies:{typescript:"^5"},dependencies:{"@anthropic-ai/sdk":"^0.71.2","@opentui/core":"^0.1.75",openai:"^6.16.0"},optionalDependencies:{"@brianlovin/hn-cli-darwin-arm64":"0.4.18","@brianlovin/hn-cli-darwin-x64":"0.4.18","@brianlovin/hn-cli-linux-arm64":"0.4.18","@brianlovin/hn-cli-linux-x64":"0.4.18","@brianlovin/hn-cli-windows-x64":"0.4.18"}};var WH=bO.version;function vO(){if(IH)return!1;if(process.argv.includes("--telemetry-test"))return!1;if(process.argv.includes("--watch"))return!0;let A=process.argv[1]||"";if(A.includes("/src/")||A.endsWith("/src/index.ts"))return!0;return!1}var LH="https://brianlovin.com/api/hn-cli/telemetry",_G=10,NH=5000,TH=1500,MG=3,Pq=[],XG=!1,IH=!1,$G=!1,e6=0;function mO(){XG=!0}function dA(A,q){if(!XG||!G6()||vO())return;if(Pq.push({event:A,timestamp:Date.now(),properties:q}),Pq.length>=_G)PH().catch(()=>{})}async function PH(){await cO(NH)}async function fO(){await cO(TH)}async function cO(A){if(!XG||!G6()||vO()||Pq.length===0)return;if($G)return;if(e6>=MG)return;$G=!0;let q=[...Pq];Pq=[];try{let g=CO(),E=new AbortController,F=setTimeout(()=>E.abort(),A),K=await fetch(LH,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({userId:g,version:WH,events:q}),signal:E.signal});if(clearTimeout(F),!K.ok){if(e6++,Pq.length<_G*2&&e6<MG)Pq=[...q,...Pq]}else e6=0}catch{if(e6++,Pq.length<_G*2&&e6<MG)Pq=[...q,...Pq]}finally{$G=!1}}var Y6={maxPosts:24,fetchLimit:200,hoursWindow:24,minPoints:50,minComments:20,commentWeight:0.75,recencyBonusMax:100,maxRootComments:12,maxChildComments:8,maxCommentLevel:3,storiesTtlMinutes:5},AE={maxPosts:{min:1,max:50,step:1,label:"Max Stories",description:"Maximum number of stories to display"},fetchLimit:{min:50,max:500,step:50,label:"Fetch Limit",description:"Number of posts to fetch from HN API"},hoursWindow:{min:1,max:168,step:1,label:"Time Window (hours)",description:"Only show stories that are trending in this window"},minPoints:{min:0,max:500,step:10,label:"Min Points",description:"The minimum number of votes required"},minComments:{min:0,max:100,step:5,label:"Min Comments",description:"The minimum number of comments required"},commentWeight:{min:0,max:2,step:0.25,label:"Comment Weight",description:"Weight of comments in ranking (0-2)"},recencyBonusMax:{min:0,max:200,step:10,label:"Recency Bonus",description:"Maximum bonus points for new posts"},maxRootComments:{min:1,max:50,step:1,label:"Root Comments",description:"How many root comments to display per story"},maxChildComments:{min:1,max:20,step:1,label:"Child Comments",description:"The maximum number of child comments to display per root comment"},maxCommentLevel:{min:1,max:10,step:1,label:"Nesting Depth",description:"The maximum depth of nested replies to display"},storiesTtlMinutes:{min:1,max:60,step:1,label:"Cache TTL (min)",description:"How long to cache stories before refresh"}},pO=[{key:"filtering",label:"Story Filtering",settings:["maxPosts","hoursWindow","minPoints","minComments"]},{key:"comments",label:"Comments",settings:["maxRootComments","maxChildComments","maxCommentLevel"]}];function dO(A,q){let g=AE[A],E=Math.max(g.min,Math.min(g.max,q)),F=Math.round((E-g.min)/g.step);return g.min+F*g.step}function uO(A){let q={...Y6};for(let g of Object.keys(Y6))if(A[g]!==void 0)q[g]=dO(g,A[g]);return q}function Gq(){let A=tA();if(!A.filterSettings)return{...Y6};return uO(A.filterSettings)}function lO(A){let q=tA();q.filterSettings=uO(A),Fg(q)}function iO(A,q){let g=Gq();return g[A]=dO(A,q),lO(g),g}function tO(){return lO(Y6),{...Y6}}function nO(A,q){if(A==="commentWeight")return q.toFixed(2);return String(q)}var xH="https://hacker-news.firebaseio.com/v0",sO="https://api.hnpwa.com/v0";async function RH(){let A=await fetch(`${xH}/topstories.json`);if(!A.ok)throw Error("Failed to fetch top stories");return A.json()}function rO(A,q){if(!A)return null;if(A.level>q.maxCommentLevel)return null;return{...A,comments:A.comments.slice(0,q.maxChildComments).map((g)=>rO(g,q)).filter(Boolean)}}function oO(A,q,g){let E=A.comments.slice(0,g.maxRootComments).map((F)=>rO(F,g)).filter(Boolean);return{...A,comments:q?E:[]}}async function VG(A,q){let g=q??Gq();try{let E=await fetch(`${sO}/item/${A}.json`);if(!E.ok)return null;let F=await E.json();return oO(F,!0,g)}catch{return null}}async function eO(A){let q=A??Gq(),E=(await RH()).sort((Q,$)=>$-Q).slice(0,q.fetchLimit),F=await Promise.all(E.map(async(Q)=>{try{let $=await fetch(`${sO}/item/${Q}.json`);if(!$.ok)return null;let _=await $.json();return oO(_,!1,q)}catch{return null}})),K=Date.now()/1000,Z=K-3600*q.hoursWindow;return F.filter((Q)=>Q!==null).filter((Q)=>Q.type==="link").filter((Q)=>Q.time>Z).filter((Q)=>(Q.points||0)>=q.minPoints||Q.comments_count>=q.minComments).sort((Q,$)=>{let _=(K-Q.time)/3600,P=(K-$.time)/3600,N=Math.max(0,q.recencyBonusMax*(1-_/q.hoursWindow)),W=Math.max(0,q.recencyBonusMax*(1-P/q.hoursWindow)),x=(Q.points||0)+Q.comments_count*q.commentWeight+N;return($.points||0)+$.comments_count*q.commentWeight+W-x}).slice(0,q.maxPosts)}var hH={bg:void 0,bgSelected:"#2a2a2a",border:"#3a3a3a",textPrimary:"#e0e0e0",textSecondary:"#888888",textTertiary:"#666666",accent:"#ff6600",link:"#6699ff",success:"#4ade80",error:"#ef4444",hint:"#a855f7",commentL1:"#555555",commentL2:"#444444",commentL3:"#333333"},SH={bg:void 0,bgSelected:"#e8e8e8",border:"#cccccc",textPrimary:"#1a1a1a",textSecondary:"#666666",textTertiary:"#888888",accent:"#ff6600",link:"#0066cc",success:"#22c55e",error:"#dc2626",hint:"#9333ea",commentL1:"#cccccc",commentL2:"#dddddd",commentL3:"#eeeeee"},V={...hH};function zH(A){if(!A)return!1;let q=A.replace("#",""),g=parseInt(q.substr(0,2),16),E=parseInt(q.substr(2,2),16),F=parseInt(q.substr(4,2),16);return(0.299*g+0.587*E+0.114*F)/255>0.5}async function AM(A){try{let q=await A.getPalette({timeout:100});if(q.defaultBackground&&zH(q.defaultBackground))Object.assign(V,SH)}catch{}}function qM(A){return{0:V.accent,1:V.commentL1,2:V.commentL2,3:V.commentL3}[A]??V.commentL3}var yA=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function Rg(A){return A.replace(/<\/p>\s*<p>/g,`
93
93
 
94
94
  `).replace(/<p>/g,`
95
95
 
@@ -98,7 +98,7 @@ Please report this to https://github.com/markedjs/marked.`,A){let E="<p>An error
98
98
  `).replace(/<br\s*\/?>/g,`
99
99
  `).replace(/<a[^>]*href="([^"]*)"[^>]*>([^<]*)<\/a>/g,"$2 ($1)").replace(/<code>/g,"`").replace(/<\/code>/g,"`").replace(/<pre>/g,"\n```\n").replace(/<\/pre>/g,"\n```\n").replace(/<[^>]+>/g,"").replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#x27;/g,"'").replace(/&#x2F;/g,"/").replace(/&#39;/g,"'").replace(/&nbsp;/g," ").replace(/\n{3,}/g,`
100
100
 
101
- `).trim()}function WG(A,q){if(A.name==="s"){dA("settings_opened"),q.showSettings();return}if(A.name==="j")q.navigateStory(1);else if(A.name==="k")q.navigateStory(-1);else if(A.name==="down")q.scrollComments(3);else if(A.name==="up")q.scrollComments(-3);else if(A.name==="space"||A.name===" ")dA("comment_nav"),q.navigateToNextComment();else if(A.name==="o")dA("url_opened",{type:"url"}),q.openStoryUrl();else if(A.name==="c")dA("chat_opened"),q.openChat();else if(A.name==="r")dA("refresh"),q.refresh();else if(A.name==="t")dA("tldr_requested"),q.handleTldrRequest()}function gM(A){return new y(A,{id:"suggestions-container",width:"100%",flexDirection:"column",flexShrink:0,paddingLeft:2,paddingRight:2,paddingTop:0,paddingBottom:0,backgroundColor:V.bg,borderStyle:"single",border:[],borderColor:V.border})}function MA(A,q){if(!q.container)return;for(let Z of q.container.getChildren())q.container.remove(Z.id);let g=q.container;if(q.hidden){g.paddingTop=0,g.paddingBottom=0,g.border=[];return}if(q.loading||q.suggestions.length>0)g.paddingTop=0,g.paddingBottom=0,g.border=["top"];else g.paddingTop=0,g.paddingBottom=0,g.border=[];if(q.loading){let Z=new B(A,{id:"suggestions-loading",content:`${yA[q.loadingFrame]??"\u280B"} Generating suggestions...`,fg:V.textSecondary});q.container.add(Z);return}if(q.suggestions.length===0)return;let F=new B(A,{id:"suggestions-header",content:"\u2726 Suggested questions",fg:V.textTertiary});q.container.add(F);let K=new y(A,{id:"suggestions-spacer",height:1});q.container.add(K);for(let Z=0;Z<q.suggestions.length;Z++){let j=q.suggestions[Z];if(!j)continue;let U=Z===q.selectedIndex,G=new y(A,{id:`suggestion-row-${Z}`,width:"100%",flexDirection:"row",backgroundColor:V.bg}),Y=new B(A,{id:`suggestion-indicator-${Z}`,content:U?"\u203A ":"\u2022 ",fg:U?V.accent:V.textSecondary,width:2,flexShrink:0});G.add(Y);let M=new y(A,{id:`suggestion-text-container-${Z}`,flexGrow:1,flexDirection:"row",flexWrap:"wrap"}),Q=new B(A,{id:`suggestion-text-${Z}`,content:j,fg:U?V.accent:V.textSecondary,wrapMode:"word"});if(M.add(Q),U){let $=new B(A,{id:`suggestion-hint-${Z}`,content:" tab to type",fg:V.textTertiary});M.add($)}G.add(M),q.container.add(G)}}function EM(A){return{container:A,suggestions:[],originalSuggestions:[],selectedIndex:-1,loading:!1,loadingFrame:0,hidden:!1}}function FM(A){return new y(A,{id:"slash-commands-container",width:"100%",flexDirection:"column",flexShrink:0,paddingLeft:2,paddingRight:2,paddingTop:0,paddingBottom:0,backgroundColor:V.bg,borderStyle:"single",border:[],borderColor:V.border})}function KM(A,q){return{container:A,commands:q,filteredCommands:[...q],selectedIndex:q.length-1,isVisible:!1,query:""}}function ZM(A,q){A.query=q;let g=q.toLowerCase();if(!g)A.filteredCommands=[...A.commands];else A.filteredCommands=A.commands.filter((E)=>E.name.toLowerCase().includes(g)||E.description.toLowerCase().includes(g));A.selectedIndex=A.filteredCommands.length>0?A.filteredCommands.length-1:-1}function LG(A,q){if(A.filteredCommands.length===0)return;let g=A.selectedIndex+q;A.selectedIndex=Math.max(0,Math.min(A.filteredCommands.length-1,g))}function Q6(A,q){if(!q.container)return;for(let E of q.container.getChildren())q.container.remove(E.id);let g=q.container;if(!q.isVisible||q.filteredCommands.length===0){g.paddingTop=0,g.paddingBottom=0,g.border=[];return}g.paddingTop=0,g.paddingBottom=0,g.border=["top"];for(let E=0;E<q.filteredCommands.length;E++){let F=q.filteredCommands[E];if(!F)continue;let K=E===q.selectedIndex,Z=new y(A,{id:`slash-command-row-${E}`,width:"100%",flexDirection:"row",backgroundColor:V.bg}),j=new B(A,{id:`slash-command-indicator-${E}`,content:K?"\u203A ":" ",fg:K?V.accent:V.textSecondary,width:2,flexShrink:0});Z.add(j);let U=new B(A,{id:`slash-command-name-${E}`,content:`/${F.name}`,fg:K?V.accent:V.textPrimary});Z.add(U);let G=new B(A,{id:`slash-command-desc-${E}`,content:` \u2014 ${F.description}`,fg:V.textSecondary});Z.add(G),q.container.add(Z)}}function jM(A){if(A.selectedIndex<0||A.selectedIndex>=A.filteredCommands.length)return null;return A.filteredCommands[A.selectedIndex]??null}function UM(A){A.isVisible=!0,A.query="",A.filteredCommands=[...A.commands],A.selectedIndex=A.commands.length-1}function vZ(A){A.isVisible=!1,A.query="",A.filteredCommands=[...A.commands],A.selectedIndex=A.commands.length-1}function NG(A,q){let g=q.input?.plainText??"",E=q.slashCommands,F=q.suggestions,K=g.startsWith("/")?g.slice(1):"";if(g.startsWith("/")&&!K.includes(" ")){if(!E.isVisible)UM(E),F.hidden=!0,MA(A,F);return ZM(E,K),Q6(A,E),!0}else{if(E.isVisible)vZ(E),Q6(A,E),F.hidden=!1,MA(A,F);return!1}}function TG(A,q,g,E){if(A.name==="escape"){if(g.slashCommands?.isVisible){vZ(g.slashCommands),Q6(q,g.slashCommands),g.input?.clear(),g.suggestions.hidden=!1,MA(q,g.suggestions);return}E.hideChatView();return}if(A.super&&(A.name==="j"||A.name==="k")){let G=A.name==="j"?1:-1;E.navigateStory(G);return}let{suggestions:F,slashCommands:K}=g,Z=g.input?.plainText??"",j=Z.startsWith("/")?Z.slice(1):"",U=Z.startsWith("/")&&!j.includes(" ");if(U&&K?.isVisible&&K.filteredCommands.length>0){if(A.name==="up"||A.name==="k"){if(K.selectedIndex>0)LG(K,-1),Q6(q,K);return}else if(A.name==="down"||A.name==="j"){if(K.selectedIndex<K.filteredCommands.length-1)LG(K,1),Q6(q,K);return}}if(!U&&F.suggestions.length>0&&g.input&&!g.input.plainText.trim()){if(A.name==="up"||A.name==="k"){if(F.selectedIndex===-1)F.selectedIndex=F.suggestions.length-1;else if(F.selectedIndex>0)F.selectedIndex--;g.input.blur(),MA(q,F);return}else if(A.name==="down"||A.name==="j"){if(F.selectedIndex===F.suggestions.length-1)F.selectedIndex=-1,g.input.focus();else if(F.selectedIndex>=0)F.selectedIndex++,g.input.blur();MA(q,F);return}}if(A.name==="tab"&&F.selectedIndex>=0&&F.suggestions.length>0){let G=F.suggestions[F.selectedIndex];if(G&&g.input){g.input.focus(),g.input.clear(),g.input.insertText(G+" "),F.suggestions=[],F.selectedIndex=-1,MA(q,F);return}}if((A.name==="return"||A.name==="enter")&&!A.shift){if(U&&K?.isVisible){let G=jM(K);if(G){g.input?.clear(),vZ(K),Q6(q,K),g.suggestions.hidden=!1,MA(q,g.suggestions),G.handler();return}return}if(g.input&&g.input.plainText.trim()){E.sendChatMessage();return}if(F.selectedIndex>=0&&F.suggestions.length>0){E.selectSuggestion();return}return}if(A.sequence&&A.sequence.length===1&&!A.ctrl&&!A.meta){let G=A.sequence.charCodeAt(0);if(G>=32&&G<=126){if(g.input&&!g.input.focused)g.input.focus();if(A.sequence==="/"&&!Z){setTimeout(()=>{NG(q,g)},0);return}if(U){setTimeout(()=>{NG(q,g)},0);return}if(F.suggestions.length>0)F.suggestions=[],F.selectedIndex=-1,MA(q,F)}}if(A.name==="backspace"&&g.input)setTimeout(()=>{if(!g?.input||!g?.suggestions)return;let G=g.input.plainText;if(!NG(q,g)&&!G.trim()&&g.suggestions.originalSuggestions.length>0&&g.suggestions.suggestions.length===0)g.suggestions.suggestions=[...g.suggestions.originalSuggestions],g.suggestions.selectedIndex=g.suggestions.suggestions.length-1,MA(q,g.suggestions)},10)}function aH(A,q){return A.length===1&&q.length>0&&q.toLowerCase().startsWith(A.toLowerCase())}function hg(A,q){let g=new y(A,{width:"100%",height:2,flexShrink:0,flexDirection:"row",alignItems:"center",paddingLeft:2,paddingRight:2,backgroundColor:V.bg,borderStyle:"single",border:["top"],borderColor:V.border,gap:2}),E=q.filter((Z)=>!Z.rightAlign),F=q.filter((Z)=>Z.rightAlign),K=(Z)=>{let{key:j,desc:U}=Z;if(aH(j,U)){let G=U[0]??"",Y=new B(A,{content:iA`${nE(s6(V.textPrimary)(G))}${U.slice(1)}`,fg:V.textSecondary});g.add(Y)}else{let G=new y(A,{flexDirection:"row",gap:1}),Y=new B(A,{content:j,fg:V.textPrimary}),M=new B(A,{content:U,fg:V.textSecondary});G.add(Y),G.add(M),g.add(G)}};for(let Z of E)K(Z);if(F.length>0){let Z=new y(A,{flexGrow:1});g.add(Z);for(let j of F)K(j)}return g}var GM=[{key:"\u2423",desc:"next"},{key:"o",desc:"open"},{key:"c",desc:"chat"},{key:"s",desc:"settings",rightAlign:!0}],YM=[{key:"j/k",desc:"navigate"}],QM=[{key:"/",desc:"commands"},{key:"esc",desc:"close",rightAlign:!0}],JM=[{key:"j/k",desc:"navigate"},{key:"\u2190/\u2192",desc:"adjust"},{key:"\u21B5",desc:"select"},{key:"r",desc:"reset"},{key:"esc",desc:"close",rightAlign:!0}];var OM={anthropic:{display:"platform.claude.com",full:"https://platform.claude.com/settings/keys"},openai:{display:"platform.openai.com",full:"https://platform.openai.com/api-keys"}};function MM(A){let q=new y(A,{id:"settings-header",width:"100%",flexDirection:"column",flexShrink:0,paddingLeft:2,paddingRight:2,paddingTop:1,paddingBottom:1,borderStyle:"single",border:["bottom"],borderColor:V.border,backgroundColor:V.bg}),g=new B(A,{content:iA`${Nq("Settings")}`,fg:V.textSecondary});q.add(g);let E=new kq(A,{width:"100%",flexGrow:1,scrollY:!0,backgroundColor:V.bg,contentOptions:{flexDirection:"column",paddingLeft:2,paddingRight:2,paddingTop:1,paddingBottom:1,backgroundColor:V.bg}}),F=new y(A,{width:"100%",flexDirection:"column",backgroundColor:V.bg});E.add(F);let K=hg(A,JM);return{selectedIndex:0,header:q,scroll:E,content:F,shortcutsBar:K}}function jF(A){let q=!!nA("anthropic"),g=!!nA("openai"),E=q||g,F=A==="anthropic"?SO:zO,K=Gq(),Z=[];if(Z.push({item:{type:"provider",provider:"anthropic",hasKey:q},enabled:!0}),Z.push({item:{type:"provider",provider:"openai",hasKey:g},enabled:!0}),E)for(let j of F)Z.push({item:{type:"model",modelId:j.id,modelName:j.name},enabled:!0});for(let j of pO){Z.push({item:{type:"category_header",label:j.label},enabled:!1});for(let U of j.settings){let G=K[U],Y=G!==Y6[U],M=AE[U];Z.push({item:{type:"filter_setting",key:U,value:G,isModified:Y},enabled:!0}),Z.push({item:{type:"setting_subtitle",text:M.description},enabled:!1})}}if(Z.push({item:{type:"telemetry",enabled:G6()},enabled:!0}),E)Z.push({item:{type:"action",action:"clear_keys"},enabled:!0});return Z}function IG(A,q,g){for(let U of q.content.getChildren())q.content.remove(U.id);let E=jF(g),F=ZF(g),K=new B(A,{content:iA`${Nq("AI Features")}`,fg:V.textSecondary});q.content.add(K);for(let U=0;U<E.length;U++){let G=E[U];if(!G||G.item.type!=="provider")continue;let Y=U===q.selectedIndex,M=G.item.provider===g,Q=G.item.hasKey,$=G.item.provider==="anthropic"?"Anthropic":"OpenAI",_=new y(A,{id:`settings-item-${U}`,flexDirection:"row",gap:1}),P=new B(A,{content:Y?"\u203A":" ",fg:V.accent});_.add(P);let N=new B(A,{content:M?"\u25CF":"\u25CB",fg:M?V.accent:V.textSecondary});_.add(N);let W=new B(A,{content:$,fg:Y?V.accent:V.textPrimary});if(_.add(W),!Q){let x=OM[G.item.provider].display,C=new B(A,{content:Y?`${x} (tab)`:x,fg:V.textTertiary});_.add(C)}q.content.add(_)}if(E.some((U)=>U.item.type==="model")){q.content.add(new y(A,{height:1}));let U=new B(A,{content:iA`${Nq("Model")}`,fg:V.textSecondary});q.content.add(U);for(let G=0;G<E.length;G++){let Y=E[G];if(!Y||Y.item.type!=="model")continue;let M=G===q.selectedIndex,Q=Y.item.modelId===F,$=new y(A,{id:`settings-item-${G}`,flexDirection:"row",gap:1}),_=new B(A,{content:M?"\u203A":" ",fg:V.accent});$.add(_);let P=new B(A,{content:Q?"\u25CF":"\u25CB",fg:Q?V.accent:V.textSecondary});$.add(P);let N=new B(A,{content:Y.item.modelName,fg:M?V.accent:V.textPrimary});$.add(N),q.content.add($)}}q.content.add(new y(A,{height:1}));for(let U=0;U<E.length;U++){let G=E[U];if(!G)continue;if(G.item.type==="category_header"){q.content.add(new y(A,{height:1}));let Y=new B(A,{content:iA`${Nq(G.item.label)}`,fg:V.textSecondary});q.content.add(Y);continue}if(G.item.type==="filter_setting"){let Y=U===q.selectedIndex,M=AE[G.item.key],Q=nO(G.item.key,G.item.value),$=new y(A,{id:`settings-item-${U}`,flexDirection:"row",gap:1}),_=new B(A,{content:Y?"\u203A":" ",fg:V.accent});$.add(_);let P=new B(A,{content:M.label,fg:Y?V.accent:V.textPrimary});$.add(P);let N=new B(A,{content:`[${Q}]`,fg:G.item.isModified?V.accent:V.textSecondary});if($.add(N),Y){let W=new B(A,{content:"\u2190 \u2192",fg:V.textTertiary});$.add(W)}q.content.add($)}if(G.item.type==="setting_subtitle"){let Y=new y(A,{flexDirection:"row",marginBottom:1}),M=new B(A,{content:" ",fg:V.textSecondary});Y.add(M);let Q=new B(A,{content:G.item.text,fg:V.textSecondary});Y.add(Q),q.content.add(Y)}}q.content.add(new y(A,{height:1}));let j=new B(A,{content:iA`${Nq("Telemetry")}`,fg:V.textSecondary});q.content.add(j);for(let U=0;U<E.length;U++){let G=E[U];if(!G||G.item.type!=="telemetry")continue;let Y=U===q.selectedIndex,M=G.item.enabled,Q=new y(A,{id:`settings-item-${U}`,flexDirection:"row",gap:1}),$=new B(A,{content:Y?"\u203A":" ",fg:V.accent});Q.add($);let _=new B(A,{content:M?"\u25CF":"\u25CB",fg:M?V.accent:V.textSecondary});Q.add(_);let P=new B(A,{content:M?"Enabled":"Disabled",fg:Y?V.accent:V.textPrimary});Q.add(P);let N=new B(A,{content:"(private and anonymous)",fg:V.textTertiary});Q.add(N),q.content.add(Q)}q.content.add(new y(A,{height:1}));for(let U=0;U<E.length;U++){let G=E[U];if(!G||G.item.type!=="action")continue;let Y=U===q.selectedIndex,M="";switch(G.item.action){case"clear_keys":M="Clear All API Keys";break}let Q=new y(A,{id:`settings-item-${U}`,flexDirection:"row",gap:1}),$=new B(A,{content:Y?"\u203A":" ",fg:V.accent});Q.add($);let _=new B(A,{content:`[${M}]`,fg:Y?V.accent:V.textPrimary});Q.add(_),q.content.add(Q)}}function PG(A,q,g){let E=jF(g),F=E.length-1,K=A.selectedIndex,Z=0,j=E.length;do if(K=Math.max(0,Math.min(F,K+q)),Z++,K===0||K===F||E[K]?.enabled)break;while(Z<j);if(E[K]?.enabled)A.selectedIndex=K,BH(A)}function BH(A){let q=`settings-item-${A.selectedIndex}`,g=A.scroll.getChildren()[0];if(!g)return;let E=(G)=>{for(let Y of G.getChildren()){if(Y.id===q)return Y;if(Y instanceof y){let M=E(Y);if(M)return M}}return null},F=E(g);if(!F)return;let K=F.y-g.y,Z=F.height||1,j=A.scroll.height,U=A.scroll.scrollTop;if(K<U)A.scroll.scrollTop=Math.max(0,K-1);else if(K+Z>U+j)A.scroll.scrollTop=K+Z-j+1}function $M(A,q){let E=jF(q)[A.selectedIndex];if(!E||!E.enabled)return null;switch(E.item.type){case"provider":if(!E.item.hasKey)return E.item.provider==="anthropic"?{type:"add_anthropic"}:{type:"add_openai"};if(E.item.provider!==q)return{type:"switch_provider",provider:E.item.provider};return null;case"model":return{type:"select_model",modelId:E.item.modelId,provider:q};case"telemetry":return{type:"toggle_telemetry"};case"filter_setting":return{type:"adjust_setting",key:E.item.key,delta:AE[E.item.key].step};case"action":switch(E.item.action){case"clear_keys":return{type:"clear_keys"}}}return null}function xG(A,q,g){let F=jF(q)[A.selectedIndex];if(!F||!F.enabled)return null;if(F.item.type==="filter_setting"){let K=AE[F.item.key].step;return{type:"adjust_setting",key:F.item.key,delta:g>0?K:-K}}return null}function _M(A){return!1}function XM(A,q){let E=jF(q)[A.selectedIndex];if(!E)return null;if(E.item.type==="provider"&&!E.item.hasKey)return OM[E.item.provider].full;return null}function RG(A,q,g,E){if(A.name==="escape"){if(!_M(q))E.hideSettings();else E.rerenderSettings();return}if(A.name==="j"||A.name==="down")PG(q,1,g),E.rerenderSettings();else if(A.name==="k"||A.name==="up")PG(q,-1,g),E.rerenderSettings();else if(A.name==="tab"){let F=XM(q,g);if(F)E.openUrl(F)}else if(A.name==="left"||A.name==="h"){let F=xG(q,g,-1);if(F)E.handleSettingsAction(F)}else if(A.name==="right"||A.name==="l"){let F=xG(q,g,1);if(F)E.handleSettingsAction(F)}else if(A.name==="return"||A.name==="enter"){let F=$M(q,g);if(F)E.handleSettingsAction(F)}else if(A.name==="r")tO(),E.rerenderSettings()}function mZ(){return{step:"provider",selectedProvider:"anthropic",keyInput:null}}function HM(A,q,g){let E=new y(A,{width:"100%",height:"100%",flexDirection:"column",paddingLeft:2,paddingRight:2,paddingTop:2,backgroundColor:V.bg}),F=new B(A,{content:"Set up AI Chat",fg:V.accent});if(E.add(F),E.add(new y(A,{height:1})),q.step==="provider")wH(A,E,q);else if(q.step==="key")kH(A,E,q,g);return E}function wH(A,q,g){let E=new B(A,{content:"Choose your AI provider:",fg:V.textPrimary});q.add(E),q.add(new y(A,{height:1}));let F=new y(A,{flexDirection:"row",gap:1}),K=new B(A,{content:g.selectedProvider==="anthropic"?"\u25CF":"\u25CB",fg:g.selectedProvider==="anthropic"?V.accent:V.textSecondary}),Z=new B(A,{content:"Anthropic",fg:g.selectedProvider==="anthropic"?V.accent:V.textPrimary});F.add(K),F.add(Z),q.add(F);let j=new y(A,{flexDirection:"row",gap:1}),U=new B(A,{content:g.selectedProvider==="openai"?"\u25CF":"\u25CB",fg:g.selectedProvider==="openai"?V.accent:V.textSecondary}),G=new B(A,{content:"OpenAI",fg:g.selectedProvider==="openai"?V.accent:V.textPrimary});j.add(U),j.add(G),q.add(j),q.add(new y(A,{height:2}));let Y=new B(A,{content:"\u2191/\u2193 to select, Enter to continue, Esc to cancel",fg:V.textSecondary});q.add(Y)}function kH(A,q,g,E){let F=g.selectedProvider==="anthropic"?"Anthropic":"OpenAI",K=new B(A,{content:`Enter your ${F} API key:`,fg:V.textPrimary});q.add(K),q.add(new y(A,{height:1}));let Z=new y(A,{width:"100%",flexDirection:"row"}),j=new B(A,{content:"\u203A",fg:V.accent});Z.add(j);let U=new y(A,{width:1});Z.add(U),g.keyInput=new CZ(A,{flexGrow:1,placeholder:g.selectedProvider==="anthropic"?"sk-ant-...":"sk-...",backgroundColor:V.bg}),g.keyInput.on("enter",()=>{let M=g.keyInput?.value.trim();if(M)E.onSaveKey(g.selectedProvider,M)}),Z.add(g.keyInput),q.add(Z),q.add(new y(A,{height:2}));let G=new B(A,{content:"Your key is stored locally at ~/.config/hn-cli/config.json",fg:V.textSecondary,wrapMode:"word"});q.add(G),q.add(new y(A,{height:2}));let Y=new B(A,{content:"Enter to save, Esc to cancel",fg:V.textSecondary});q.add(Y),setTimeout(()=>{if(g.keyInput)g.keyInput.focus(),g.keyInput.value=""},50)}function hG(A,q){if(A.step!=="provider")return;A.selectedProvider=q>0?"openai":"anthropic"}function VM(A){if(A.step==="provider")A.step="key"}function SG(A,q,g){if(A.name==="escape"){g.hideAuthSetup();return}if(q.step==="provider"){if(A.name==="j"||A.name==="down")hG(q,1),g.showAuthSetupUI();else if(A.name==="k"||A.name==="up")hG(q,-1),g.showAuthSetupUI();else if(A.name==="return"||A.name==="enter")VM(q),g.showAuthSetupUI()}}import{spawn as DH}from"child_process";var CH="https://registry.npmjs.org/@brianlovin/hn-cli/latest",WM="@brianlovin/hn-cli",Kg=process.env.HN_SIMULATE_VERSION??yO,zG=process.env.HN_SIMULATE_LATEST;function LM(A,q){let g=A.split(".").map(Number),E=q.split(".").map(Number);for(let F=0;F<3;F++){let K=g[F]??0,Z=E[F]??0;if(Z>K)return!0;if(Z<K)return!1}return!1}async function NM(){if(zG)return{hasUpdate:LM(Kg,zG),currentVersion:Kg,latestVersion:zG};try{let A=new AbortController,q=setTimeout(()=>A.abort(),3000),g=await fetch(CH,{signal:A.signal,headers:{Accept:"application/json"}});if(clearTimeout(q),!g.ok)return null;let F=(await g.json()).version;if(!F)return null;return{hasUpdate:LM(Kg,F),currentVersion:Kg,latestVersion:F}}catch{return null}}function fZ(){if(process.versions.bun!==void 0)return`bun install -g ${WM}@latest`;return`npm install -g ${WM}@latest`}async function yH(A){let q=process.platform,g;if(q==="darwin")g=["pbcopy"];else if(q==="linux")g=["xclip","-selection","clipboard"];else if(q==="win32")g=["clip"];else return!1;try{let E=g[0],F=g.slice(1);return new Promise((K)=>{let Z=DH(E,F,{stdio:["pipe","ignore","ignore"]});Z.on("close",()=>K(!0)),Z.on("error",()=>K(!1)),Z.stdin?.write(A),Z.stdin?.end()})}catch{return!1}}function TM(A,q){let g=new y(A,{width:"100%",height:2,flexDirection:"row",alignItems:"center",justifyContent:"space-between",paddingLeft:1,paddingRight:2,backgroundColor:V.bg,borderStyle:"single",border:["bottom"],borderColor:V.border}),E=new y(A,{flexDirection:"row",alignItems:"center"}),F=new B(A,{content:"\u25A0",fg:V.accent,width:2,paddingLeft:1});E.add(F);let K=new B(A,{content:"Hacker News",fg:V.accent});E.add(K),g.add(E);let Z=new y(A,{flexDirection:"row",gap:2,alignItems:"center"}),j=new B(A,{content:"",fg:V.textSecondary});Z.add(j);let U=new B(A,{content:`v${Kg}`,fg:V.textSecondary});Z.add(U);let G=new y(A,{flexDirection:"row",alignItems:"center",gap:1}),Y=new B(A,{content:"",fg:V.textSecondary}),M=new B(A,{content:"->",fg:V.textSecondary}),Q=new B(A,{content:"",fg:V.success}),$=new B(A,{content:"\xB7",fg:V.textSecondary}),_=null,P=new B(A,{content:" ",fg:V.success,width:2}),N=new B(A,{content:"",fg:V.textSecondary,onMouseOver:()=>{N.fg=V.textPrimary},onMouseOut:()=>{N.fg=V.textSecondary},onMouseDown:()=>{let x=fZ();if(yH(x),P.content="\u2713",_)clearTimeout(_);_=setTimeout(()=>{P.content=" ",_=null},3000)}});return G.add(Y),G.add(M),G.add(Q),G.add($),G.add(N),G.add(P),g.add(Z),{header:g,state:{loadingIndicator:j,loadingInterval:null,loadingFrame:0,rightContainer:Z,versionLabel:U,updateContainer:G,currentVersionLabel:Y,updateArrow:M,latestVersionLabel:Q,updateCommand:N,copiedIndicator:P}}}function IM(A,q){if(q?.hasUpdate){if(A.currentVersionLabel.content=`v${q.currentVersion}`,A.latestVersionLabel.content=`v${q.latestVersion}`,A.updateCommand.content=fZ(),A.versionLabel.content="",!A.rightContainer.getChildren().some((F)=>F.id===A.updateContainer.id))A.rightContainer.add(A.updateContainer)}else A.versionLabel.content=`v${Kg}`,A.rightContainer.remove(A.updateContainer.id)}function PM(A,q){if(A.loadingInterval)return;A.loadingFrame=0,A.loadingInterval=setInterval(()=>{if(A.loadingIndicator&&!q()){let g=yA[A.loadingFrame]??"\u280B";A.loadingIndicator.content=g,A.loadingFrame=(A.loadingFrame+1)%yA.length}},80)}function xM(A){if(A.loadingInterval)clearInterval(A.loadingInterval),A.loadingInterval=null;if(A.loadingIndicator)A.loadingIndicator.content=""}function RM(A,q,g,E,F){let K=new y(A,{id:`story-${q.id}`,width:"100%",paddingTop:0,paddingBottom:0,backgroundColor:V.bg,flexDirection:"row",onMouseDown:()=>{F.onSelect(g)}}),Z=new B(A,{id:`chevron-${q.id}`,content:E?"\u203A":"\u2022",fg:E?V.accent:V.textTertiary,width:2,paddingLeft:1});K.add(Z);let j=new y(A,{id:`content-${q.id}`,flexGrow:1,flexDirection:"column",paddingRight:2});K.add(j);let U=new B(A,{id:`title-${q.id}`,content:q.title,fg:E?V.accent:V.textPrimary});if(j.add(U),q.domain){let G=new B(A,{id:`domain-${q.id}`,content:q.domain,fg:V.textSecondary});j.add(G)}return K}function aG(A,q,g){let E=A.getChildren();if(E.length>=2){let F=E[0];if(F&&"content"in F)F.content=g?"\u203A":"\u2022",F.fg=g?V.accent:V.textTertiary;let Z=E[1].getChildren();if(Z.length>0){let j=Z[0];if(j&&"content"in j)j.fg=g?V.accent:V.textPrimary}}}function hM(A,q){let g=A.getChildren();if(g.length>=1){let E=g[0];if(E&&"content"in E)E.content=q}}function SM(A){let q=new y(A,{id:"story-list-panel",width:"35%",maxWidth:60,flexShrink:0,height:"100%",flexDirection:"column",borderStyle:"single",border:["right"],borderColor:V.border,backgroundColor:V.bg,paddingLeft:1}),g=new kq(A,{width:"100%",flexGrow:1,scrollY:!0,backgroundColor:V.bg,contentOptions:{flexDirection:"column",backgroundColor:V.bg,gap:1}}),E=hg(A,YM),F=new y(A,{id:"story-list-notification-box",width:"100%",flexDirection:"row"}),K=new B(A,{id:"story-list-notification-icon",content:"?",fg:V.textTertiary,width:2,paddingLeft:1}),Z=new B(A,{id:"story-list-notification-text",content:"",fg:V.textSecondary});return F.add(K),F.add(Z),q.add(g),q.add(E),{panel:q,scroll:g,shortcutsBar:E,items:new Map,notificationBox:F}}function zM(A,q){let g=A.notificationBox.getChildren()[1];if(g)g.content=q;let E=A.scroll.getChildren();if(!E.some((K)=>K.id===A.notificationBox.id)){let K=E.filter((Z)=>Z.id!==A.notificationBox.id);for(let Z of K)A.scroll.remove(Z.id);A.scroll.add(A.notificationBox);for(let Z of K)A.scroll.add(Z)}}function cZ(A,q,g,E,F){for(let K of q.scroll.getChildren())if(K.id!==q.notificationBox.id)q.scroll.remove(K.id);q.items.clear(),g.forEach((K,Z)=>{let U=RM(A,K,Z,Z===E,F);q.items.set(Z,U),q.scroll.add(U)})}function aM(A,q,g,E){let F=A.items.get(g),K=q[g];if(F&&K)aG(F,K,!1);let Z=A.items.get(E),j=q[E];if(Z&&j)aG(Z,j,!0)}function BM(A,q){let F=q*3,K=F+2,Z=A.scroll.height,j=A.scroll.scrollTop;if(F<j)A.scroll.scrollTop=F;else if(K>j+Z)A.scroll.scrollTop=K-Z}function BG(A,q,g){let E=A.items.get(q);if(E)hM(E,g)}function wG(A,q){let g=q.level===0,E=qM(q.level),F=new y(A,{id:`comment-wrapper-${q.id}`,width:"100%",marginTop:1,flexDirection:"row"});if(q.level>0){let j=new y(A,{width:q.level*2,flexShrink:0});F.add(j)}let K=new y(A,{id:`comment-${q.id}`,flexGrow:1,flexShrink:1,paddingLeft:1,paddingRight:1,borderStyle:"single",border:["left"],borderColor:E,flexDirection:"column"}),Z=new B(A,{content:q.user||"[deleted]",fg:g?V.accent:V.textSecondary});if(K.add(Z),q.content){let j=new B(A,{content:Rg(q.content),fg:V.textPrimary,wrapMode:"word"});K.add(j)}else if(q.deleted){let j=new B(A,{content:"[deleted]",fg:V.textTertiary});K.add(j)}if(F.add(K),q.comments&&q.comments.length>0){let j=new y(A,{width:"100%",flexDirection:"column"});for(let G of q.comments){let Y=wG(A,G);j.add(Y)}let U=new y(A,{width:"100%",flexDirection:"column"});return U.add(F),U.add(j),U}return F}function wM(A,q,g){let E=new y(A,{width:"100%",flexDirection:"column",flexShrink:0,paddingLeft:2,paddingRight:2,paddingTop:1,paddingBottom:1,borderStyle:"single",border:["bottom"],borderColor:V.border,backgroundColor:V.bg}),F=new B(A,{content:q.title,fg:V.textPrimary,wrapMode:"word",flexShrink:0,maxHeight:2,onMouseDown:()=>g.onOpenStoryUrl(),onMouseOver:()=>{F.fg=V.accent},onMouseOut:()=>{F.fg=V.textPrimary}});if(E.add(F),q.domain){let K=new B(A,{content:q.domain,fg:V.textSecondary,flexShrink:0,maxHeight:1,onMouseDown:()=>g.onOpenStoryUrl()});E.add(K)}return{container:E}}function kM(A,q,g,E){for(let K of q.getChildren())q.remove(K.id);let F=new B(A,{content:g.title,fg:V.textPrimary,wrapMode:"word",flexShrink:0,maxHeight:2,onMouseDown:()=>E.onOpenStoryUrl(),onMouseOver:()=>{F.fg=V.accent},onMouseOut:()=>{F.fg=V.textPrimary}});if(q.add(F),g.domain){let K=new B(A,{content:g.domain,fg:V.textSecondary,flexShrink:0,maxHeight:1,onMouseDown:()=>E.onOpenStoryUrl()});q.add(K)}}function CM(A,q){let g=new y(A,{width:0,flexGrow:1,flexShrink:0,height:"100%",flexDirection:"column",backgroundColor:V.bg}),E=new y(A,{id:"detail-header",width:"100%",flexDirection:"column",flexShrink:0,paddingLeft:2,paddingRight:2,paddingTop:1,paddingBottom:1,borderStyle:"single",border:["bottom"],borderColor:V.border,backgroundColor:V.bg}),F=new kq(A,{width:"100%",flexGrow:1,scrollY:!0,backgroundColor:V.bg,contentOptions:{flexDirection:"column",paddingLeft:2,paddingRight:2,paddingTop:1,backgroundColor:V.bg}}),K=new y(A,{width:"100%",flexDirection:"column",backgroundColor:V.bg});F.add(K);let Z=hg(A,GM);return{panel:g,header:E,scroll:F,content:K,shortcutsBar:Z,rootCommentBoxes:[]}}function pZ(A){if(!A.panel.getChildren().some((E)=>E.id===A.header.id))A.panel.add(A.header),A.panel.add(A.scroll),A.panel.add(A.shortcutsBar)}function J6(A,q,g,E,F){for(let G of q.content.getChildren())q.content.remove(G.id);if(q.rootCommentBoxes=[],kM(A,q.header,g,E),g.content){let G=new y(A,{width:"100%",marginBottom:2}),Y=new B(A,{content:Rg(g.content),fg:V.textPrimary,wrapMode:"word"});G.add(Y),q.content.add(G)}if(F?.isLoading){let G=new y(A,{width:"100%",flexDirection:"column",marginBottom:1,paddingBottom:1,borderStyle:"single",border:["bottom"],borderColor:V.border}),Y=F.loadingFrame??0,M=yA[Y%yA.length],Q=new B(A,{content:`${M} Generating TLDR...`,fg:V.textTertiary});G.add(Q),q.content.add(G)}else if(F?.hasError){let G=new y(A,{width:"100%",flexDirection:"column",marginBottom:1,paddingBottom:1,borderStyle:"single",border:["bottom"],borderColor:V.border}),Y=new B(A,{content:"Failed to generate TLDR. Press t to retry.",fg:V.error});G.add(Y),q.content.add(G)}else if(F?.tldr){let G=new y(A,{width:"100%",flexDirection:"column",flexShrink:1,marginBottom:1,paddingBottom:1,borderStyle:"single",border:["bottom"],borderColor:V.border}),Y=new B(A,{content:iA`${Nq("TL;DR")}`,fg:V.accent});G.add(Y);let M=new y(A,{height:1});G.add(M);let Q=new B(A,{content:iA`${Nq("Article summary")}`,fg:V.textSecondary});G.add(Q);let $=new y(A,{flexGrow:1,flexShrink:1}),_=new B(A,{content:F.tldr.articleSummary,fg:V.textPrimary,wrapMode:"word"});$.add(_),G.add($);let P=new y(A,{height:1});G.add(P);let N=new B(A,{content:iA`${Nq("Discussion summary")}`,fg:V.textSecondary});G.add(N);let W=new y(A,{flexGrow:1,flexShrink:1}),x=new B(A,{content:F.tldr.discussionSummary,fg:V.textPrimary,wrapMode:"word"});W.add(x),G.add(W);let C=new y(A,{height:1});G.add(C);let D=new B(A,{content:"c to continue chatting",fg:V.textTertiary});G.add(D),q.content.add(G)}let K=new y(A,{width:"100%",flexDirection:"column"}),Z=new y(A,{width:"100%",flexDirection:"row"}),j=new B(A,{content:`${g.comments_count} comments`,fg:V.textSecondary});Z.add(j);let U=new B(A,{content:iA` \u00B7 ${nE(s6(V.textPrimary)("t"))}ldr`,fg:V.textTertiary});if(Z.add(U),K.add(Z),g.comments&&g.comments.length>0)for(let G=0;G<g.comments.length;G++){let Y=g.comments[G];if(!Y)continue;let M=wG(A,Y);if(K.add(M),Y.level===0)q.rootCommentBoxes.push(M)}else{let G=new B(A,{content:"No comments yet...",fg:V.textSecondary});K.add(G)}q.content.add(K),q.scroll.scrollTop=0}function kG(A,q){if(q<0||q>=A.rootCommentBoxes.length)return;let g=A.rootCommentBoxes[q];if(!g)return;let E=A.scroll.content,F=g.y-E.y;A.scroll.scrollTop=Math.max(0,F-1)}var dZ=30,bH="\u2588",vH="\u2591",DM=6;function yM(A){let q=(dZ-1)*2,g=A%q,E=g<dZ?g:q-g,F=Math.floor(DM/2),K=E-F,Z=E+F+DM%2;K=Math.max(0,K),Z=Math.min(dZ,Z);let j="";for(let U=0;U<dZ;U++)j+=U>=K&&U<Z?bH:vH;return j}function bM(A){let q=new y(A,{width:"100%",height:"100%",flexDirection:"column",alignItems:"center",justifyContent:"center",backgroundColor:V.bg}),g=new B(A,{content:"",fg:V.textSecondary}),E=new B(A,{content:"",fg:V.textSecondary,marginTop:2});return q.add(g),q.add(E),{container:q,progressBar:g,statusText:E,mode:"loading",frame:0,animationInterval:null}}function vM(A,q,g){if(UF(A),A.mode=q,A.frame=0,q==="loading")A.progressBar.content=yM(0),A.statusText.content="",A.animationInterval=setInterval(()=>{if(g()){UF(A);return}A.frame++,A.progressBar.content=yM(A.frame)},40);else A.progressBar.content="",A.statusText.content="Press j/k to browse stories"}function UF(A){if(A.animationInterval)clearInterval(A.animationInterval),A.animationInterval=null}function mM(A,q){let g=new y(A,{width:"100%",flexShrink:0,flexDirection:"row",alignItems:"flex-start",paddingLeft:2,paddingRight:2,backgroundColor:V.bg,borderStyle:"single",border:["top"],borderColor:V.border}),E=new B(A,{content:"\u203A ",fg:V.accent});g.add(E);let F=new wq(A,{width:"100%",flexGrow:1,height:1,maxHeight:5,wrapMode:"word",placeholder:"Ask a question about this story...",backgroundColor:V.bg,keyBindings:[{name:"return",shift:!0,action:"newline"},{name:"return",action:"submit"}]});return F.on("submit",()=>{q.onSubmit()}),g.on("click",()=>{F.focus()}),g.add(F),{container:g,input:F}}function uZ(A,q,g){let E=new kq(A,{width:"100%",flexGrow:1,scrollY:!0,backgroundColor:V.bg,contentOptions:{flexDirection:"column",paddingLeft:2,paddingRight:2,paddingTop:1,backgroundColor:V.bg}}),F=new y(A,{width:"100%",flexDirection:"column",backgroundColor:V.bg});E.add(F);let K=gM(A),Z=EM(K),j=FM(A),G=KM(j,[{name:"clear",description:"Clear chat history",handler:()=>g.onClearChat()}]),Y=mM(A,{onSubmit:g.onSubmit}),M=hg(A,QM),Q=new y(A,{width:"100%",height:"100%",flexDirection:"column",backgroundColor:V.bg}),{container:$}=wM(A,q,{onOpenStoryUrl:g.onOpenStoryUrl});return Q.add($),Q.add(E),Q.add(K),Q.add(j),Q.add(Y.container),Q.add(M),{panel:Q,scroll:E,content:F,input:Y.input,suggestions:Z,slashCommands:G,messages:[],isActive:!0,isTyping:!1,typingFrame:0,typingInterval:null}}function Sg(A,q,g){if(!q.content)return;for(let F of q.content.getChildren())q.content.remove(F.id);let E=-1;for(let F=q.messages.length-1;F>=0;F--)if(q.messages[F]?.role==="user"){E=F;break}for(let F=0;F<q.messages.length;F++){let K=q.messages[F];if(!K)continue;let Z=F>=E&&E!==-1,j=new y(A,{width:"100%",flexDirection:"column",marginBottom:1}),U=new y(A,{flexDirection:"row",gap:1}),G=K.role==="user"?V.accent:V.link,Y=new B(A,{content:"\u2022",fg:G});U.add(Y);let M=g==="anthropic"?"Claude":"GPT",Q=new B(A,{content:K.role==="user"?"You":M,fg:G});U.add(Q),j.add(U);let $=new y(A,{width:"100%",paddingLeft:2}),_=new B(A,{content:K.content,fg:Z?V.textPrimary:V.textSecondary,wrapMode:"word"});$.add(_),j.add($),q.content.add(j)}CG(q)}function CG(A){if(!A.scroll||!A.isActive)return;A.scroll.scrollTop=A.scroll.scrollHeight,setTimeout(()=>{if(A.scroll&&A.isActive)A.scroll.scrollTop=A.scroll.scrollHeight},50),setTimeout(()=>{if(A.scroll&&A.isActive)A.scroll.scrollTop=A.scroll.scrollHeight},150)}function qE(A,q,g,E,F){q.messages.push({role:g,content:E}),Sg(A,q,F)}function fM(A,q,g){if(q.typingInterval)return;q.isTyping=!0,q.typingFrame=0,q.typingInterval=setInterval(()=>{if(!q.isActive||!q.isTyping){O6(q);return}q.typingFrame=(q.typingFrame+1)%yA.length;let E=q.messages[q.messages.length-1];if(E&&E.role==="assistant"&&E.content==="..."){let F=yA[q.typingFrame]??"\u280B";E.content=F,Sg(A,q,g),E.content="..."}},80)}function O6(A){if(A.isTyping=!1,A.typingInterval)clearInterval(A.typingInterval),A.typingInterval=null}function f(A,q,g,E,F){if(E==="m")throw TypeError("Private method is not writable");if(E==="a"&&!F)throw TypeError("Private accessor was defined without a setter");if(typeof q==="function"?A!==q||!F:!q.has(A))throw TypeError("Cannot write private member to an object whose class did not declare it");return E==="a"?F.call(A,g):F?F.value=g:q.set(A,g),g}function I(A,q,g,E){if(g==="a"&&!E)throw TypeError("Private accessor was defined without a getter");if(typeof q==="function"?A!==q||!E:!q.has(A))throw TypeError("Cannot read private member from an object whose class did not declare it");return g==="m"?E:g==="a"?E.call(A):E?E.value:q.get(A)}var DG=function(){let{crypto:A}=globalThis;if(A?.randomUUID)return DG=A.randomUUID.bind(A),A.randomUUID();let q=new Uint8Array(1),g=A?()=>A.getRandomValues(q)[0]:()=>Math.random()*255&255;return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,(E)=>(+E^g()&15>>+E/4).toString(16))};function Zg(A){return typeof A==="object"&&A!==null&&(("name"in A)&&A.name==="AbortError"||("message"in A)&&String(A.message).includes("FetchRequestCanceledException"))}var GF=(A)=>{if(A instanceof Error)return A;if(typeof A==="object"&&A!==null){try{if(Object.prototype.toString.call(A)==="[object Error]"){let q=Error(A.message,A.cause?{cause:A.cause}:{});if(A.stack)q.stack=A.stack;if(A.cause&&!q.cause)q.cause=A.cause;if(A.name)q.name=A.name;return q}}catch{}try{return Error(JSON.stringify(A))}catch{}}return Error(A)};class t extends Error{}class TA extends t{constructor(A,q,g,E){super(`${TA.makeMessage(A,q,g)}`);this.status=A,this.headers=E,this.requestID=E?.get("request-id"),this.error=q}static makeMessage(A,q,g){let E=q?.message?typeof q.message==="string"?q.message:JSON.stringify(q.message):q?JSON.stringify(q):g;if(A&&E)return`${A} ${E}`;if(A)return`${A} status code (no body)`;if(E)return E;return"(no status code or body)"}static generate(A,q,g,E){if(!A||!E)return new M6({message:g,cause:GF(q)});let F=q;if(A===400)return new QF(A,F,g,E);if(A===401)return new JF(A,F,g,E);if(A===403)return new OF(A,F,g,E);if(A===404)return new MF(A,F,g,E);if(A===409)return new $F(A,F,g,E);if(A===422)return new _F(A,F,g,E);if(A===429)return new XF(A,F,g,E);if(A>=500)return new HF(A,F,g,E);return new TA(A,F,g,E)}}class bA extends TA{constructor({message:A}={}){super(void 0,void 0,A||"Request was aborted.",void 0)}}class M6 extends TA{constructor({message:A,cause:q}){super(void 0,void 0,A||"Connection error.",void 0);if(q)this.cause=q}}class YF extends M6{constructor({message:A}={}){super({message:A??"Request timed out."})}}class QF extends TA{}class JF extends TA{}class OF extends TA{}class MF extends TA{}class $F extends TA{}class _F extends TA{}class XF extends TA{}class HF extends TA{}var fH=/^[a-z][a-z0-9+.-]*:/i,cM=(A)=>{return fH.test(A)},yG=(A)=>(yG=Array.isArray,yG(A)),bG=yG;function lZ(A){if(typeof A!=="object")return{};return A??{}}function pM(A){if(!A)return!0;for(let q in A)return!1;return!0}function dM(A,q){return Object.prototype.hasOwnProperty.call(A,q)}var uM=(A,q)=>{if(typeof q!=="number"||!Number.isInteger(q))throw new t(`${A} must be an integer`);if(q<0)throw new t(`${A} must be a positive integer`);return q};var iZ=(A)=>{try{return JSON.parse(A)}catch(q){return}};var lM=(A)=>new Promise((q)=>setTimeout(q,A));var zg="0.71.2";var sM=()=>{return typeof window<"u"&&typeof window.document<"u"&&typeof navigator<"u"};function cH(){if(typeof Deno<"u"&&Deno.build!=null)return"deno";if(typeof EdgeRuntime<"u")return"edge";if(Object.prototype.toString.call(typeof globalThis.process<"u"?globalThis.process:0)==="[object process]")return"node";return"unknown"}var pH=()=>{let A=cH();if(A==="deno")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":zg,"X-Stainless-OS":tM(Deno.build.os),"X-Stainless-Arch":iM(Deno.build.arch),"X-Stainless-Runtime":"deno","X-Stainless-Runtime-Version":typeof Deno.version==="string"?Deno.version:Deno.version?.deno??"unknown"};if(typeof EdgeRuntime<"u")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":zg,"X-Stainless-OS":"Unknown","X-Stainless-Arch":`other:${EdgeRuntime}`,"X-Stainless-Runtime":"edge","X-Stainless-Runtime-Version":globalThis.process.version};if(A==="node")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":zg,"X-Stainless-OS":tM(globalThis.process.platform??"unknown"),"X-Stainless-Arch":iM(globalThis.process.arch??"unknown"),"X-Stainless-Runtime":"node","X-Stainless-Runtime-Version":globalThis.process.version??"unknown"};let q=dH();if(q)return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":zg,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":`browser:${q.browser}`,"X-Stainless-Runtime-Version":q.version};return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":zg,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":"unknown","X-Stainless-Runtime-Version":"unknown"}};function dH(){if(typeof navigator>"u"||!navigator)return null;let A=[{key:"edge",pattern:/Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"ie",pattern:/MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"ie",pattern:/Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"chrome",pattern:/Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"firefox",pattern:/Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"safari",pattern:/(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/}];for(let{key:q,pattern:g}of A){let E=g.exec(navigator.userAgent);if(E){let F=E[1]||0,K=E[2]||0,Z=E[3]||0;return{browser:q,version:`${F}.${K}.${Z}`}}}return null}var iM=(A)=>{if(A==="x32")return"x32";if(A==="x86_64"||A==="x64")return"x64";if(A==="arm")return"arm";if(A==="aarch64"||A==="arm64")return"arm64";if(A)return`other:${A}`;return"unknown"},tM=(A)=>{if(A=A.toLowerCase(),A.includes("ios"))return"iOS";if(A==="android")return"Android";if(A==="darwin")return"MacOS";if(A==="win32")return"Windows";if(A==="freebsd")return"FreeBSD";if(A==="openbsd")return"OpenBSD";if(A==="linux")return"Linux";if(A)return`Other:${A}`;return"Unknown"},nM,rM=()=>{return nM??(nM=pH())};function oM(){if(typeof fetch<"u")return fetch;throw Error("`fetch` is not defined as a global; Either pass `fetch` to the client, `new Anthropic({ fetch })` or polyfill the global, `globalThis.fetch = fetch`")}function vG(...A){let q=globalThis.ReadableStream;if(typeof q>"u")throw Error("`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`");return new q(...A)}function tZ(A){let q=Symbol.asyncIterator in A?A[Symbol.asyncIterator]():A[Symbol.iterator]();return vG({start(){},async pull(g){let{done:E,value:F}=await q.next();if(E)g.close();else g.enqueue(F)},async cancel(){await q.return?.()}})}function VF(A){if(A[Symbol.asyncIterator])return A;let q=A.getReader();return{async next(){try{let g=await q.read();if(g?.done)q.releaseLock();return g}catch(g){throw q.releaseLock(),g}},async return(){let g=q.cancel();return q.releaseLock(),await g,{done:!0,value:void 0}},[Symbol.asyncIterator](){return this}}}async function eM(A){if(A===null||typeof A!=="object")return;if(A[Symbol.asyncIterator]){await A[Symbol.asyncIterator]().return?.();return}let q=A.getReader(),g=q.cancel();q.releaseLock(),await g}var A9=({headers:A,body:q})=>{return{bodyHeaders:{"content-type":"application/json"},body:JSON.stringify(q)}};function E9(A){let q=0;for(let F of A)q+=F.length;let g=new Uint8Array(q),E=0;for(let F of A)g.set(F,E),E+=F.length;return g}var q9;function WF(A){let q;return(q9??(q=new globalThis.TextEncoder,q9=q.encode.bind(q)))(A)}var g9;function mG(A){let q;return(g9??(q=new globalThis.TextDecoder,g9=q.decode.bind(q)))(A)}var rA,oA;class ag{constructor(){rA.set(this,void 0),oA.set(this,void 0),f(this,rA,new Uint8Array,"f"),f(this,oA,null,"f")}decode(A){if(A==null)return[];let q=A instanceof ArrayBuffer?new Uint8Array(A):typeof A==="string"?WF(A):A;f(this,rA,E9([I(this,rA,"f"),q]),"f");let g=[],E;while((E=iH(I(this,rA,"f"),I(this,oA,"f")))!=null){if(E.carriage&&I(this,oA,"f")==null){f(this,oA,E.index,"f");continue}if(I(this,oA,"f")!=null&&(E.index!==I(this,oA,"f")+1||E.carriage)){g.push(mG(I(this,rA,"f").subarray(0,I(this,oA,"f")-1))),f(this,rA,I(this,rA,"f").subarray(I(this,oA,"f")),"f"),f(this,oA,null,"f");continue}let F=I(this,oA,"f")!==null?E.preceding-1:E.preceding,K=mG(I(this,rA,"f").subarray(0,F));g.push(K),f(this,rA,I(this,rA,"f").subarray(E.index),"f"),f(this,oA,null,"f")}return g}flush(){if(!I(this,rA,"f").length)return[];return this.decode(`
101
+ `).trim()}function WG(A,q){if(A.name==="s"){dA("settings_opened"),q.showSettings();return}if(A.name==="j")q.navigateStory(1);else if(A.name==="k")q.navigateStory(-1);else if(A.name==="down")q.scrollComments(3);else if(A.name==="up")q.scrollComments(-3);else if(A.name==="space"||A.name===" ")dA("comment_nav"),q.navigateToNextComment();else if(A.name==="o")dA("url_opened",{type:"url"}),q.openStoryUrl();else if(A.name==="c")dA("chat_opened"),q.openChat();else if(A.name==="r")dA("refresh"),q.refresh();else if(A.name==="t")dA("tldr_requested"),q.handleTldrRequest()}function gM(A){return new y(A,{id:"suggestions-container",width:"100%",flexDirection:"column",flexShrink:0,paddingLeft:2,paddingRight:2,paddingTop:0,paddingBottom:0,backgroundColor:V.bg,borderStyle:"single",border:[],borderColor:V.border})}function MA(A,q){if(!q.container)return;for(let Z of q.container.getChildren())q.container.remove(Z.id);let g=q.container;if(q.hidden){g.paddingTop=0,g.paddingBottom=0,g.border=[];return}if(q.loading||q.suggestions.length>0)g.paddingTop=0,g.paddingBottom=0,g.border=["top"];else g.paddingTop=0,g.paddingBottom=0,g.border=[];if(q.loading){let Z=new B(A,{id:"suggestions-loading",content:`${yA[q.loadingFrame]??"\u280B"} Generating suggestions...`,fg:V.textSecondary});q.container.add(Z);return}if(q.suggestions.length===0)return;let F=new B(A,{id:"suggestions-header",content:"\u2726 Suggested questions",fg:V.textTertiary});q.container.add(F);let K=new y(A,{id:"suggestions-spacer",height:1});q.container.add(K);for(let Z=0;Z<q.suggestions.length;Z++){let j=q.suggestions[Z];if(!j)continue;let U=Z===q.selectedIndex,G=new y(A,{id:`suggestion-row-${Z}`,width:"100%",flexDirection:"row",backgroundColor:V.bg}),Y=new B(A,{id:`suggestion-indicator-${Z}`,content:U?"\u203A ":"\u2022 ",fg:U?V.accent:V.textSecondary,width:2,flexShrink:0});G.add(Y);let M=new y(A,{id:`suggestion-text-container-${Z}`,flexGrow:1,flexDirection:"row",flexWrap:"wrap"}),Q=new B(A,{id:`suggestion-text-${Z}`,content:j,fg:U?V.accent:V.textSecondary,wrapMode:"word"});if(M.add(Q),U){let $=new B(A,{id:`suggestion-hint-${Z}`,content:" tab to type",fg:V.textTertiary});M.add($)}G.add(M),q.container.add(G)}}function EM(A){return{container:A,suggestions:[],originalSuggestions:[],selectedIndex:-1,loading:!1,loadingFrame:0,hidden:!1}}function FM(A){return new y(A,{id:"slash-commands-container",width:"100%",flexDirection:"column",flexShrink:0,paddingLeft:2,paddingRight:2,paddingTop:0,paddingBottom:0,backgroundColor:V.bg,borderStyle:"single",border:[],borderColor:V.border})}function KM(A,q){return{container:A,commands:q,filteredCommands:[...q],selectedIndex:q.length-1,isVisible:!1,query:""}}function ZM(A,q){A.query=q;let g=q.toLowerCase();if(!g)A.filteredCommands=[...A.commands];else A.filteredCommands=A.commands.filter((E)=>E.name.toLowerCase().includes(g)||E.description.toLowerCase().includes(g));A.selectedIndex=A.filteredCommands.length>0?A.filteredCommands.length-1:-1}function LG(A,q){if(A.filteredCommands.length===0)return;let g=A.selectedIndex+q;A.selectedIndex=Math.max(0,Math.min(A.filteredCommands.length-1,g))}function Q6(A,q){if(!q.container)return;for(let E of q.container.getChildren())q.container.remove(E.id);let g=q.container;if(!q.isVisible||q.filteredCommands.length===0){g.paddingTop=0,g.paddingBottom=0,g.border=[];return}g.paddingTop=0,g.paddingBottom=0,g.border=["top"];for(let E=0;E<q.filteredCommands.length;E++){let F=q.filteredCommands[E];if(!F)continue;let K=E===q.selectedIndex,Z=new y(A,{id:`slash-command-row-${E}`,width:"100%",flexDirection:"row",backgroundColor:V.bg}),j=new B(A,{id:`slash-command-indicator-${E}`,content:K?"\u203A ":" ",fg:K?V.accent:V.textSecondary,width:2,flexShrink:0});Z.add(j);let U=new B(A,{id:`slash-command-name-${E}`,content:`/${F.name}`,fg:K?V.accent:V.textPrimary});Z.add(U);let G=new B(A,{id:`slash-command-desc-${E}`,content:` \u2014 ${F.description}`,fg:V.textSecondary});Z.add(G),q.container.add(Z)}}function jM(A){if(A.selectedIndex<0||A.selectedIndex>=A.filteredCommands.length)return null;return A.filteredCommands[A.selectedIndex]??null}function UM(A){A.isVisible=!0,A.query="",A.filteredCommands=[...A.commands],A.selectedIndex=A.commands.length-1}function vZ(A){A.isVisible=!1,A.query="",A.filteredCommands=[...A.commands],A.selectedIndex=A.commands.length-1}function NG(A,q){let g=q.input?.plainText??"",E=q.slashCommands,F=q.suggestions,K=g.startsWith("/")?g.slice(1):"";if(g.startsWith("/")&&!K.includes(" ")){if(!E.isVisible)UM(E),F.hidden=!0,MA(A,F);return ZM(E,K),Q6(A,E),!0}else{if(E.isVisible)vZ(E),Q6(A,E),F.hidden=!1,MA(A,F);return!1}}function TG(A,q,g,E){if(A.name==="escape"){if(g.slashCommands?.isVisible){vZ(g.slashCommands),Q6(q,g.slashCommands),g.input?.clear(),g.suggestions.hidden=!1,MA(q,g.suggestions);return}E.hideChatView();return}if(A.super&&(A.name==="j"||A.name==="k")){let G=A.name==="j"?1:-1;E.navigateStory(G);return}let{suggestions:F,slashCommands:K}=g,Z=g.input?.plainText??"",j=Z.startsWith("/")?Z.slice(1):"",U=Z.startsWith("/")&&!j.includes(" ");if(U&&K?.isVisible&&K.filteredCommands.length>0){if(A.name==="up"||A.name==="k"){if(K.selectedIndex>0)LG(K,-1),Q6(q,K);return}else if(A.name==="down"||A.name==="j"){if(K.selectedIndex<K.filteredCommands.length-1)LG(K,1),Q6(q,K);return}}if(!U&&F.suggestions.length>0&&g.input&&!g.input.plainText.trim()){if(A.name==="up"||A.name==="k"){if(F.selectedIndex===-1)F.selectedIndex=F.suggestions.length-1;else if(F.selectedIndex>0)F.selectedIndex--;g.input.blur(),MA(q,F);return}else if(A.name==="down"||A.name==="j"){if(F.selectedIndex===F.suggestions.length-1)F.selectedIndex=-1,g.input.focus();else if(F.selectedIndex>=0)F.selectedIndex++,g.input.blur();MA(q,F);return}}if(A.name==="tab"&&F.selectedIndex>=0&&F.suggestions.length>0){let G=F.suggestions[F.selectedIndex];if(G&&g.input){g.input.focus(),g.input.clear(),g.input.insertText(G+" "),F.suggestions=[],F.selectedIndex=-1,MA(q,F);return}}if((A.name==="return"||A.name==="enter")&&!A.shift){if(U&&K?.isVisible){let G=jM(K);if(G){g.input?.clear(),vZ(K),Q6(q,K),g.suggestions.hidden=!1,MA(q,g.suggestions),G.handler();return}return}if(g.input&&g.input.plainText.trim()){E.sendChatMessage();return}if(F.selectedIndex>=0&&F.suggestions.length>0){E.selectSuggestion();return}return}if(A.sequence&&A.sequence.length===1&&!A.ctrl&&!A.meta){let G=A.sequence.charCodeAt(0);if(G>=32&&G<=126){if(g.input&&!g.input.focused)g.input.focus();if(A.sequence==="/"&&!Z){setTimeout(()=>{NG(q,g)},0);return}if(U){setTimeout(()=>{NG(q,g)},0);return}if(F.suggestions.length>0)F.suggestions=[],F.selectedIndex=-1,MA(q,F)}}if(A.name==="backspace"&&g.input)setTimeout(()=>{if(!g?.input||!g?.suggestions)return;let G=g.input.plainText;if(!NG(q,g)&&!G.trim()&&g.suggestions.originalSuggestions.length>0&&g.suggestions.suggestions.length===0)g.suggestions.suggestions=[...g.suggestions.originalSuggestions],g.suggestions.selectedIndex=g.suggestions.suggestions.length-1,MA(q,g.suggestions)},10)}function aH(A,q){return A.length===1&&q.length>0&&q.toLowerCase().startsWith(A.toLowerCase())}function hg(A,q){let g=new y(A,{width:"100%",height:2,flexShrink:0,flexDirection:"row",alignItems:"center",paddingLeft:2,paddingRight:2,backgroundColor:V.bg,borderStyle:"single",border:["top"],borderColor:V.border,gap:2}),E=q.filter((Z)=>!Z.rightAlign),F=q.filter((Z)=>Z.rightAlign),K=(Z)=>{let{key:j,desc:U}=Z;if(aH(j,U)){let G=U[0]??"",Y=new B(A,{content:iA`${nE(s6(V.textPrimary)(G))}${U.slice(1)}`,fg:V.textSecondary});g.add(Y)}else{let G=new y(A,{flexDirection:"row",gap:1}),Y=new B(A,{content:j,fg:V.textPrimary}),M=new B(A,{content:U,fg:V.textSecondary});G.add(Y),G.add(M),g.add(G)}};for(let Z of E)K(Z);if(F.length>0){let Z=new y(A,{flexGrow:1});g.add(Z);for(let j of F)K(j)}return g}var GM=[{key:"\u2423",desc:"next"},{key:"o",desc:"open"},{key:"c",desc:"chat"},{key:"s",desc:"settings",rightAlign:!0}],YM=[{key:"j/k",desc:"navigate"}],QM=[{key:"/",desc:"commands"},{key:"esc",desc:"close",rightAlign:!0}],JM=[{key:"j/k",desc:"navigate"},{key:"\u2190/\u2192",desc:"adjust"},{key:"\u21B5",desc:"select"},{key:"r",desc:"reset"},{key:"esc",desc:"close",rightAlign:!0}];var OM={anthropic:{display:"platform.claude.com",full:"https://platform.claude.com/settings/keys"},openai:{display:"platform.openai.com",full:"https://platform.openai.com/api-keys"}};function MM(A){let q=new y(A,{id:"settings-header",width:"100%",flexDirection:"column",flexShrink:0,paddingLeft:2,paddingRight:2,paddingTop:1,paddingBottom:1,borderStyle:"single",border:["bottom"],borderColor:V.border,backgroundColor:V.bg}),g=new B(A,{content:iA`${Nq("Settings")}`,fg:V.textSecondary});q.add(g);let E=new kq(A,{width:"100%",flexGrow:1,scrollY:!0,backgroundColor:V.bg,contentOptions:{flexDirection:"column",paddingLeft:2,paddingRight:2,paddingTop:1,paddingBottom:1,backgroundColor:V.bg}}),F=new y(A,{width:"100%",flexDirection:"column",backgroundColor:V.bg});E.add(F);let K=hg(A,JM);return{selectedIndex:0,header:q,scroll:E,content:F,shortcutsBar:K}}function jF(A){let q=!!nA("anthropic"),g=!!nA("openai"),E=q||g,F=A==="anthropic"?SO:zO,K=Gq(),Z=[];if(Z.push({item:{type:"provider",provider:"anthropic",hasKey:q},enabled:!0}),Z.push({item:{type:"provider",provider:"openai",hasKey:g},enabled:!0}),E)for(let j of F)Z.push({item:{type:"model",modelId:j.id,modelName:j.name},enabled:!0});for(let j of pO){Z.push({item:{type:"category_header",label:j.label},enabled:!1});for(let U of j.settings){let G=K[U],Y=G!==Y6[U],M=AE[U];Z.push({item:{type:"filter_setting",key:U,value:G,isModified:Y},enabled:!0}),Z.push({item:{type:"setting_subtitle",text:M.description},enabled:!1})}}if(Z.push({item:{type:"telemetry",enabled:G6()},enabled:!0}),E)Z.push({item:{type:"action",action:"clear_keys"},enabled:!0});return Z}function IG(A,q,g){for(let U of q.content.getChildren())q.content.remove(U.id);let E=jF(g),F=ZF(g),K=new B(A,{content:iA`${Nq("AI Features")}`,fg:V.textSecondary});q.content.add(K);for(let U=0;U<E.length;U++){let G=E[U];if(!G||G.item.type!=="provider")continue;let Y=U===q.selectedIndex,M=G.item.provider===g,Q=G.item.hasKey,$=G.item.provider==="anthropic"?"Anthropic":"OpenAI",_=new y(A,{id:`settings-item-${U}`,flexDirection:"row",gap:1}),P=new B(A,{content:Y?"\u203A":" ",fg:V.accent});_.add(P);let N=new B(A,{content:M?"\u25CF":"\u25CB",fg:M?V.accent:V.textSecondary});_.add(N);let W=new B(A,{content:$,fg:Y?V.accent:V.textPrimary});if(_.add(W),!Q){let x=OM[G.item.provider].display,C=new B(A,{content:Y?`${x} (tab)`:x,fg:V.textTertiary});_.add(C)}q.content.add(_)}if(E.some((U)=>U.item.type==="model")){q.content.add(new y(A,{height:1}));let U=new B(A,{content:iA`${Nq("Model")}`,fg:V.textSecondary});q.content.add(U);for(let G=0;G<E.length;G++){let Y=E[G];if(!Y||Y.item.type!=="model")continue;let M=G===q.selectedIndex,Q=Y.item.modelId===F,$=new y(A,{id:`settings-item-${G}`,flexDirection:"row",gap:1}),_=new B(A,{content:M?"\u203A":" ",fg:V.accent});$.add(_);let P=new B(A,{content:Q?"\u25CF":"\u25CB",fg:Q?V.accent:V.textSecondary});$.add(P);let N=new B(A,{content:Y.item.modelName,fg:M?V.accent:V.textPrimary});$.add(N),q.content.add($)}}q.content.add(new y(A,{height:1}));for(let U=0;U<E.length;U++){let G=E[U];if(!G)continue;if(G.item.type==="category_header"){q.content.add(new y(A,{height:1}));let Y=new B(A,{content:iA`${Nq(G.item.label)}`,fg:V.textSecondary});q.content.add(Y);continue}if(G.item.type==="filter_setting"){let Y=U===q.selectedIndex,M=AE[G.item.key],Q=nO(G.item.key,G.item.value),$=new y(A,{id:`settings-item-${U}`,flexDirection:"row",gap:1}),_=new B(A,{content:Y?"\u203A":" ",fg:V.accent});$.add(_);let P=new B(A,{content:M.label,fg:Y?V.accent:V.textPrimary});$.add(P);let N=new B(A,{content:`[${Q}]`,fg:G.item.isModified?V.accent:V.textSecondary});if($.add(N),Y){let W=new B(A,{content:"\u2190 \u2192",fg:V.textTertiary});$.add(W)}q.content.add($)}if(G.item.type==="setting_subtitle"){let Y=new y(A,{flexDirection:"row",marginBottom:1}),M=new B(A,{content:" ",fg:V.textSecondary});Y.add(M);let Q=new B(A,{content:G.item.text,fg:V.textSecondary});Y.add(Q),q.content.add(Y)}}q.content.add(new y(A,{height:1}));let j=new B(A,{content:iA`${Nq("Telemetry")}`,fg:V.textSecondary});q.content.add(j);for(let U=0;U<E.length;U++){let G=E[U];if(!G||G.item.type!=="telemetry")continue;let Y=U===q.selectedIndex,M=G.item.enabled,Q=new y(A,{id:`settings-item-${U}`,flexDirection:"row",gap:1}),$=new B(A,{content:Y?"\u203A":" ",fg:V.accent});Q.add($);let _=new B(A,{content:M?"\u25CF":"\u25CB",fg:M?V.accent:V.textSecondary});Q.add(_);let P=new B(A,{content:M?"Enabled":"Disabled",fg:Y?V.accent:V.textPrimary});Q.add(P);let N=new B(A,{content:"(private and anonymous)",fg:V.textTertiary});Q.add(N),q.content.add(Q)}q.content.add(new y(A,{height:1}));for(let U=0;U<E.length;U++){let G=E[U];if(!G||G.item.type!=="action")continue;let Y=U===q.selectedIndex,M="";switch(G.item.action){case"clear_keys":M="Clear All API Keys";break}let Q=new y(A,{id:`settings-item-${U}`,flexDirection:"row",gap:1}),$=new B(A,{content:Y?"\u203A":" ",fg:V.accent});Q.add($);let _=new B(A,{content:`[${M}]`,fg:Y?V.accent:V.textPrimary});Q.add(_),q.content.add(Q)}}function PG(A,q,g){let E=jF(g),F=E.length-1,K=A.selectedIndex,Z=0,j=E.length;do if(K=Math.max(0,Math.min(F,K+q)),Z++,K===0||K===F||E[K]?.enabled)break;while(Z<j);if(E[K]?.enabled)A.selectedIndex=K,BH(A)}function BH(A){let q=`settings-item-${A.selectedIndex}`,g=A.scroll.getChildren()[0];if(!g)return;let E=(G)=>{for(let Y of G.getChildren()){if(Y.id===q)return Y;if(Y instanceof y){let M=E(Y);if(M)return M}}return null},F=E(g);if(!F)return;let K=F.y-g.y,Z=F.height||1,j=A.scroll.height,U=A.scroll.scrollTop;if(K<U)A.scroll.scrollTop=Math.max(0,K-1);else if(K+Z>U+j)A.scroll.scrollTop=K+Z-j+1}function $M(A,q){let E=jF(q)[A.selectedIndex];if(!E||!E.enabled)return null;switch(E.item.type){case"provider":if(!E.item.hasKey)return E.item.provider==="anthropic"?{type:"add_anthropic"}:{type:"add_openai"};if(E.item.provider!==q)return{type:"switch_provider",provider:E.item.provider};return null;case"model":return{type:"select_model",modelId:E.item.modelId,provider:q};case"telemetry":return{type:"toggle_telemetry"};case"filter_setting":return{type:"adjust_setting",key:E.item.key,delta:AE[E.item.key].step};case"action":switch(E.item.action){case"clear_keys":return{type:"clear_keys"}}}return null}function xG(A,q,g){let F=jF(q)[A.selectedIndex];if(!F||!F.enabled)return null;if(F.item.type==="filter_setting"){let K=AE[F.item.key].step;return{type:"adjust_setting",key:F.item.key,delta:g>0?K:-K}}return null}function _M(A){return!1}function XM(A,q){let E=jF(q)[A.selectedIndex];if(!E)return null;if(E.item.type==="provider"&&!E.item.hasKey)return OM[E.item.provider].full;return null}function RG(A,q,g,E){if(A.name==="escape"){if(!_M(q))E.hideSettings();else E.rerenderSettings();return}if(A.name==="j"||A.name==="down")PG(q,1,g),E.rerenderSettings();else if(A.name==="k"||A.name==="up")PG(q,-1,g),E.rerenderSettings();else if(A.name==="tab"){let F=XM(q,g);if(F)E.openUrl(F)}else if(A.name==="left"||A.name==="h"){let F=xG(q,g,-1);if(F)E.handleSettingsAction(F)}else if(A.name==="right"||A.name==="l"){let F=xG(q,g,1);if(F)E.handleSettingsAction(F)}else if(A.name==="return"||A.name==="enter"){let F=$M(q,g);if(F)E.handleSettingsAction(F)}else if(A.name==="r")tO(),E.rerenderSettings()}function mZ(){return{step:"provider",selectedProvider:"anthropic",keyInput:null}}function HM(A,q,g){let E=new y(A,{width:"100%",height:"100%",flexDirection:"column",paddingLeft:2,paddingRight:2,paddingTop:2,backgroundColor:V.bg}),F=new B(A,{content:"Set up AI Chat",fg:V.accent});if(E.add(F),E.add(new y(A,{height:1})),q.step==="provider")wH(A,E,q);else if(q.step==="key")kH(A,E,q,g);return E}function wH(A,q,g){let E=new B(A,{content:"Choose your AI provider:",fg:V.textPrimary});q.add(E),q.add(new y(A,{height:1}));let F=new y(A,{flexDirection:"row",gap:1}),K=new B(A,{content:g.selectedProvider==="anthropic"?"\u25CF":"\u25CB",fg:g.selectedProvider==="anthropic"?V.accent:V.textSecondary}),Z=new B(A,{content:"Anthropic",fg:g.selectedProvider==="anthropic"?V.accent:V.textPrimary});F.add(K),F.add(Z),q.add(F);let j=new y(A,{flexDirection:"row",gap:1}),U=new B(A,{content:g.selectedProvider==="openai"?"\u25CF":"\u25CB",fg:g.selectedProvider==="openai"?V.accent:V.textSecondary}),G=new B(A,{content:"OpenAI",fg:g.selectedProvider==="openai"?V.accent:V.textPrimary});j.add(U),j.add(G),q.add(j),q.add(new y(A,{height:2}));let Y=new B(A,{content:"\u2191/\u2193 to select, Enter to continue, Esc to cancel",fg:V.textSecondary});q.add(Y)}function kH(A,q,g,E){let F=g.selectedProvider==="anthropic"?"Anthropic":"OpenAI",K=new B(A,{content:`Enter your ${F} API key:`,fg:V.textPrimary});q.add(K),q.add(new y(A,{height:1}));let Z=new y(A,{width:"100%",flexDirection:"row"}),j=new B(A,{content:"\u203A",fg:V.accent});Z.add(j);let U=new y(A,{width:1});Z.add(U),g.keyInput=new CZ(A,{flexGrow:1,placeholder:g.selectedProvider==="anthropic"?"sk-ant-...":"sk-...",backgroundColor:V.bg}),g.keyInput.on("enter",()=>{let M=g.keyInput?.value.trim();if(M)E.onSaveKey(g.selectedProvider,M)}),Z.add(g.keyInput),q.add(Z),q.add(new y(A,{height:2}));let G=new B(A,{content:"Your key is stored locally at ~/.config/hn-cli/config.json",fg:V.textSecondary,wrapMode:"word"});q.add(G),q.add(new y(A,{height:2}));let Y=new B(A,{content:"Enter to save, Esc to cancel",fg:V.textSecondary});q.add(Y),setTimeout(()=>{if(g.keyInput)g.keyInput.focus(),g.keyInput.value=""},50)}function hG(A,q){if(A.step!=="provider")return;A.selectedProvider=q>0?"openai":"anthropic"}function VM(A){if(A.step==="provider")A.step="key"}function SG(A,q,g){if(A.name==="escape"){g.hideAuthSetup();return}if(q.step==="provider"){if(A.name==="j"||A.name==="down")hG(q,1),g.showAuthSetupUI();else if(A.name==="k"||A.name==="up")hG(q,-1),g.showAuthSetupUI();else if(A.name==="return"||A.name==="enter")VM(q),g.showAuthSetupUI()}}import{spawn as DH}from"child_process";var CH="https://registry.npmjs.org/@brianlovin/hn-cli/latest",WM="@brianlovin/hn-cli",Kg=process.env.HN_SIMULATE_VERSION??yO,zG=process.env.HN_SIMULATE_LATEST;function LM(A,q){let g=A.split(".").map(Number),E=q.split(".").map(Number);for(let F=0;F<3;F++){let K=g[F]??0,Z=E[F]??0;if(Z>K)return!0;if(Z<K)return!1}return!1}async function NM(){if(zG)return{hasUpdate:LM(Kg,zG),currentVersion:Kg,latestVersion:zG};try{let A=new AbortController,q=setTimeout(()=>A.abort(),3000),g=await fetch(CH,{signal:A.signal,headers:{Accept:"application/json"}});if(clearTimeout(q),!g.ok)return null;let F=(await g.json()).version;if(!F)return null;return{hasUpdate:LM(Kg,F),currentVersion:Kg,latestVersion:F}}catch{return null}}function fZ(){if(process.versions.bun!==void 0)return`bun install -g ${WM}@latest`;return`npm install -g ${WM}@latest`}async function yH(A){let q=process.platform,g;if(q==="darwin")g=["pbcopy"];else if(q==="linux")g=["xclip","-selection","clipboard"];else if(q==="win32")g=["clip"];else return!1;try{let E=g[0],F=g.slice(1);return new Promise((K)=>{let Z=DH(E,F,{stdio:["pipe","ignore","ignore"]});Z.on("close",()=>K(!0)),Z.on("error",()=>K(!1)),Z.stdin?.write(A),Z.stdin?.end()})}catch{return!1}}function TM(A,q){let g=new y(A,{width:"100%",height:2,flexDirection:"row",alignItems:"center",justifyContent:"space-between",paddingLeft:1,paddingRight:2,backgroundColor:V.bg,borderStyle:"single",border:["bottom"],borderColor:V.border}),E=new y(A,{flexDirection:"row",alignItems:"center"}),F=new B(A,{content:"\u25A0",fg:V.accent,width:2,paddingLeft:1});E.add(F);let K=new B(A,{content:"Hacker News",fg:V.accent});E.add(K),g.add(E);let Z=new y(A,{flexDirection:"row",gap:2,alignItems:"center"}),j=new B(A,{content:"",fg:V.textSecondary});Z.add(j);let U=new B(A,{content:`v${Kg}`,fg:V.textSecondary});Z.add(U);let G=new y(A,{flexDirection:"row",alignItems:"center",gap:1}),Y=new B(A,{content:"",fg:V.textSecondary}),M=new B(A,{content:"->",fg:V.textSecondary}),Q=new B(A,{content:"",fg:V.success}),$=new B(A,{content:"\xB7",fg:V.textSecondary}),_=null,P=new B(A,{content:" ",fg:V.success,width:2}),N=new B(A,{content:"",fg:V.textSecondary,onMouseOver:()=>{N.fg=V.textPrimary},onMouseOut:()=>{N.fg=V.textSecondary},onMouseDown:()=>{let x=fZ();if(yH(x),P.content="\u2713",_)clearTimeout(_);_=setTimeout(()=>{P.content=" ",_=null},3000)}});return G.add(Y),G.add(M),G.add(Q),G.add($),G.add(N),G.add(P),g.add(Z),{header:g,state:{loadingIndicator:j,loadingInterval:null,loadingFrame:0,rightContainer:Z,versionLabel:U,updateContainer:G,currentVersionLabel:Y,updateArrow:M,latestVersionLabel:Q,updateCommand:N,copiedIndicator:P}}}function IM(A,q){if(q?.hasUpdate){if(A.currentVersionLabel.content=`v${q.currentVersion}`,A.latestVersionLabel.content=`v${q.latestVersion}`,A.updateCommand.content=fZ(),A.versionLabel.content="",!A.rightContainer.getChildren().some((F)=>F.id===A.updateContainer.id))A.rightContainer.add(A.updateContainer)}else A.versionLabel.content=`v${Kg}`,A.rightContainer.remove(A.updateContainer.id)}function PM(A,q){if(A.loadingInterval)return;A.loadingFrame=0,A.loadingInterval=setInterval(()=>{if(A.loadingIndicator&&!q()){let g=yA[A.loadingFrame]??"\u280B";A.loadingIndicator.content=g,A.loadingFrame=(A.loadingFrame+1)%yA.length}},80)}function xM(A){if(A.loadingInterval)clearInterval(A.loadingInterval),A.loadingInterval=null;if(A.loadingIndicator)A.loadingIndicator.content=""}function RM(A,q,g,E,F){let K=new y(A,{id:`story-${q.id}`,width:"100%",paddingTop:0,paddingBottom:0,backgroundColor:V.bg,flexDirection:"row",onMouseDown:()=>{F.onSelect(g)}}),Z=new B(A,{id:`chevron-${q.id}`,content:E?"\u203A":"\u2022",fg:E?V.accent:V.textTertiary,width:2,paddingLeft:1});K.add(Z);let j=new y(A,{id:`content-${q.id}`,flexGrow:1,flexDirection:"column",paddingRight:2});K.add(j);let U=new B(A,{id:`title-${q.id}`,content:q.title,fg:E?V.accent:V.textPrimary});if(j.add(U),q.domain){let G=new B(A,{id:`domain-${q.id}`,content:q.domain,fg:V.textSecondary});j.add(G)}return K}function aG(A,q,g){let E=A.getChildren();if(E.length>=2){let F=E[0];if(F&&"content"in F)F.content=g?"\u203A":"\u2022",F.fg=g?V.accent:V.textTertiary;let Z=E[1].getChildren();if(Z.length>0){let j=Z[0];if(j&&"content"in j)j.fg=g?V.accent:V.textPrimary}}}function hM(A,q){let g=A.getChildren();if(g.length>=1){let E=g[0];if(E&&"content"in E)E.content=q}}function SM(A){let q=new y(A,{id:"story-list-panel",width:"35%",maxWidth:60,flexShrink:0,height:"100%",flexDirection:"column",borderStyle:"single",border:["right"],borderColor:V.border,backgroundColor:V.bg,paddingLeft:1}),g=new kq(A,{width:"100%",flexGrow:1,scrollY:!0,backgroundColor:V.bg,contentOptions:{flexDirection:"column",backgroundColor:V.bg,gap:1}}),E=hg(A,YM),F=new y(A,{id:"story-list-notification-box",width:"100%",flexDirection:"row"}),K=new B(A,{id:"story-list-notification-icon",content:"?",fg:V.textTertiary,width:2,paddingLeft:1}),Z=new B(A,{id:"story-list-notification-text",content:"",fg:V.textSecondary});return F.add(K),F.add(Z),q.add(g),q.add(E),{panel:q,scroll:g,shortcutsBar:E,items:new Map,notificationBox:F}}function zM(A,q){let g=A.notificationBox.getChildren()[1];if(g)g.content=q;let E=A.scroll.getChildren();if(!E.some((K)=>K.id===A.notificationBox.id)){let K=E.filter((Z)=>Z.id!==A.notificationBox.id);for(let Z of K)A.scroll.remove(Z.id);A.scroll.add(A.notificationBox);for(let Z of K)A.scroll.add(Z)}}function cZ(A,q,g,E,F){for(let K of q.scroll.getChildren())if(K.id!==q.notificationBox.id)q.scroll.remove(K.id);q.items.clear(),g.forEach((K,Z)=>{let U=RM(A,K,Z,Z===E,F);q.items.set(Z,U),q.scroll.add(U)})}function aM(A,q,g,E){let F=A.items.get(g),K=q[g];if(F&&K)aG(F,K,!1);let Z=A.items.get(E),j=q[E];if(Z&&j)aG(Z,j,!0)}function BM(A,q){let g=A.items.get(q);if(!g)return;let E=A.scroll.content.y,F=g.y-E,K=F+g.height,Z=A.scroll.viewport.height,j=A.scroll.scrollTop;if(F<j)A.scroll.scrollTop=F;else if(K>j+Z)A.scroll.scrollTop=K-Z}function BG(A,q,g){let E=A.items.get(q);if(E)hM(E,g)}function wG(A,q){let g=q.level===0,E=qM(q.level),F=new y(A,{id:`comment-wrapper-${q.id}`,width:"100%",marginTop:1,flexDirection:"row"});if(q.level>0){let j=new y(A,{width:q.level*2,flexShrink:0});F.add(j)}let K=new y(A,{id:`comment-${q.id}`,flexGrow:1,flexShrink:1,paddingLeft:1,paddingRight:1,borderStyle:"single",border:["left"],borderColor:E,flexDirection:"column"}),Z=new B(A,{content:q.user||"[deleted]",fg:g?V.accent:V.textSecondary});if(K.add(Z),q.content){let j=new B(A,{content:Rg(q.content),fg:V.textPrimary,wrapMode:"word"});K.add(j)}else if(q.deleted){let j=new B(A,{content:"[deleted]",fg:V.textTertiary});K.add(j)}if(F.add(K),q.comments&&q.comments.length>0){let j=new y(A,{width:"100%",flexDirection:"column"});for(let G of q.comments){let Y=wG(A,G);j.add(Y)}let U=new y(A,{width:"100%",flexDirection:"column"});return U.add(F),U.add(j),U}return F}function wM(A,q,g){let E=new y(A,{width:"100%",flexDirection:"column",flexShrink:0,paddingLeft:2,paddingRight:2,paddingTop:1,paddingBottom:1,borderStyle:"single",border:["bottom"],borderColor:V.border,backgroundColor:V.bg}),F=new B(A,{content:q.title,fg:V.textPrimary,wrapMode:"word",flexShrink:0,maxHeight:2,onMouseDown:()=>g.onOpenStoryUrl(),onMouseOver:()=>{F.fg=V.accent},onMouseOut:()=>{F.fg=V.textPrimary}});if(E.add(F),q.domain){let K=new B(A,{content:q.domain,fg:V.textSecondary,flexShrink:0,maxHeight:1,onMouseDown:()=>g.onOpenStoryUrl()});E.add(K)}return{container:E}}function kM(A,q,g,E){for(let K of q.getChildren())q.remove(K.id);let F=new B(A,{content:g.title,fg:V.textPrimary,wrapMode:"word",flexShrink:0,maxHeight:2,onMouseDown:()=>E.onOpenStoryUrl(),onMouseOver:()=>{F.fg=V.accent},onMouseOut:()=>{F.fg=V.textPrimary}});if(q.add(F),g.domain){let K=new B(A,{content:g.domain,fg:V.textSecondary,flexShrink:0,maxHeight:1,onMouseDown:()=>E.onOpenStoryUrl()});q.add(K)}}function CM(A,q){let g=new y(A,{width:0,flexGrow:1,flexShrink:0,height:"100%",flexDirection:"column",backgroundColor:V.bg}),E=new y(A,{id:"detail-header",width:"100%",flexDirection:"column",flexShrink:0,paddingLeft:2,paddingRight:2,paddingTop:1,paddingBottom:1,borderStyle:"single",border:["bottom"],borderColor:V.border,backgroundColor:V.bg}),F=new kq(A,{width:"100%",flexGrow:1,scrollY:!0,backgroundColor:V.bg,contentOptions:{flexDirection:"column",paddingLeft:2,paddingRight:2,paddingTop:1,backgroundColor:V.bg}}),K=new y(A,{width:"100%",flexDirection:"column",backgroundColor:V.bg});F.add(K);let Z=hg(A,GM);return{panel:g,header:E,scroll:F,content:K,shortcutsBar:Z,rootCommentBoxes:[]}}function pZ(A){if(!A.panel.getChildren().some((E)=>E.id===A.header.id))A.panel.add(A.header),A.panel.add(A.scroll),A.panel.add(A.shortcutsBar)}function J6(A,q,g,E,F){for(let G of q.content.getChildren())q.content.remove(G.id);if(q.rootCommentBoxes=[],kM(A,q.header,g,E),g.content){let G=new y(A,{width:"100%",marginBottom:2}),Y=new B(A,{content:Rg(g.content),fg:V.textPrimary,wrapMode:"word"});G.add(Y),q.content.add(G)}if(F?.isLoading){let G=new y(A,{width:"100%",flexDirection:"column",marginBottom:1,paddingBottom:1,borderStyle:"single",border:["bottom"],borderColor:V.border}),Y=F.loadingFrame??0,M=yA[Y%yA.length],Q=new B(A,{content:`${M} Generating TLDR...`,fg:V.textTertiary});G.add(Q),q.content.add(G)}else if(F?.hasError){let G=new y(A,{width:"100%",flexDirection:"column",marginBottom:1,paddingBottom:1,borderStyle:"single",border:["bottom"],borderColor:V.border}),Y=new B(A,{content:"Failed to generate TLDR. Press t to retry.",fg:V.error});G.add(Y),q.content.add(G)}else if(F?.tldr){let G=new y(A,{width:"100%",flexDirection:"column",flexShrink:1,marginBottom:1,paddingBottom:1,borderStyle:"single",border:["bottom"],borderColor:V.border}),Y=new B(A,{content:iA`${Nq("TL;DR")}`,fg:V.accent});G.add(Y);let M=new y(A,{height:1});G.add(M);let Q=new B(A,{content:iA`${Nq("Article summary")}`,fg:V.textSecondary});G.add(Q);let $=new y(A,{flexGrow:1,flexShrink:1}),_=new B(A,{content:F.tldr.articleSummary,fg:V.textPrimary,wrapMode:"word"});$.add(_),G.add($);let P=new y(A,{height:1});G.add(P);let N=new B(A,{content:iA`${Nq("Discussion summary")}`,fg:V.textSecondary});G.add(N);let W=new y(A,{flexGrow:1,flexShrink:1}),x=new B(A,{content:F.tldr.discussionSummary,fg:V.textPrimary,wrapMode:"word"});W.add(x),G.add(W);let C=new y(A,{height:1});G.add(C);let D=new B(A,{content:"c to continue chatting",fg:V.textTertiary});G.add(D),q.content.add(G)}let K=new y(A,{width:"100%",flexDirection:"column"}),Z=new y(A,{width:"100%",flexDirection:"row"}),j=new B(A,{content:`${g.comments_count} comments`,fg:V.textSecondary});Z.add(j);let U=new B(A,{content:iA` \u00B7 ${nE(s6(V.textPrimary)("t"))}ldr`,fg:V.textTertiary});if(Z.add(U),K.add(Z),g.comments&&g.comments.length>0)for(let G=0;G<g.comments.length;G++){let Y=g.comments[G];if(!Y)continue;let M=wG(A,Y);if(K.add(M),Y.level===0)q.rootCommentBoxes.push(M)}else{let G=new B(A,{content:"No comments yet...",fg:V.textSecondary});K.add(G)}q.content.add(K),q.scroll.scrollTop=0}function kG(A,q){if(q<0||q>=A.rootCommentBoxes.length)return;let g=A.rootCommentBoxes[q];if(!g)return;let E=A.scroll.content,F=g.y-E.y;A.scroll.scrollTop=Math.max(0,F-1)}var dZ=30,bH="\u2588",vH="\u2591",DM=6;function yM(A){let q=(dZ-1)*2,g=A%q,E=g<dZ?g:q-g,F=Math.floor(DM/2),K=E-F,Z=E+F+DM%2;K=Math.max(0,K),Z=Math.min(dZ,Z);let j="";for(let U=0;U<dZ;U++)j+=U>=K&&U<Z?bH:vH;return j}function bM(A){let q=new y(A,{width:"100%",height:"100%",flexDirection:"column",alignItems:"center",justifyContent:"center",backgroundColor:V.bg}),g=new B(A,{content:"",fg:V.textSecondary}),E=new B(A,{content:"",fg:V.textSecondary,marginTop:2});return q.add(g),q.add(E),{container:q,progressBar:g,statusText:E,mode:"loading",frame:0,animationInterval:null}}function vM(A,q,g){if(UF(A),A.mode=q,A.frame=0,q==="loading")A.progressBar.content=yM(0),A.statusText.content="",A.animationInterval=setInterval(()=>{if(g()){UF(A);return}A.frame++,A.progressBar.content=yM(A.frame)},40);else A.progressBar.content="",A.statusText.content="Press j/k to browse stories"}function UF(A){if(A.animationInterval)clearInterval(A.animationInterval),A.animationInterval=null}function mM(A,q){let g=new y(A,{width:"100%",flexShrink:0,flexDirection:"row",alignItems:"flex-start",paddingLeft:2,paddingRight:2,backgroundColor:V.bg,borderStyle:"single",border:["top"],borderColor:V.border}),E=new B(A,{content:"\u203A ",fg:V.accent});g.add(E);let F=new wq(A,{width:"100%",flexGrow:1,height:1,maxHeight:5,wrapMode:"word",placeholder:"Ask a question about this story...",backgroundColor:V.bg,keyBindings:[{name:"return",shift:!0,action:"newline"},{name:"return",action:"submit"}]});return F.on("submit",()=>{q.onSubmit()}),g.on("click",()=>{F.focus()}),g.add(F),{container:g,input:F}}function uZ(A,q,g){let E=new kq(A,{width:"100%",flexGrow:1,scrollY:!0,backgroundColor:V.bg,contentOptions:{flexDirection:"column",paddingLeft:2,paddingRight:2,paddingTop:1,backgroundColor:V.bg}}),F=new y(A,{width:"100%",flexDirection:"column",backgroundColor:V.bg});E.add(F);let K=gM(A),Z=EM(K),j=FM(A),G=KM(j,[{name:"clear",description:"Clear chat history",handler:()=>g.onClearChat()}]),Y=mM(A,{onSubmit:g.onSubmit}),M=hg(A,QM),Q=new y(A,{width:"100%",height:"100%",flexDirection:"column",backgroundColor:V.bg}),{container:$}=wM(A,q,{onOpenStoryUrl:g.onOpenStoryUrl});return Q.add($),Q.add(E),Q.add(K),Q.add(j),Q.add(Y.container),Q.add(M),{panel:Q,scroll:E,content:F,input:Y.input,suggestions:Z,slashCommands:G,messages:[],isActive:!0,isTyping:!1,typingFrame:0,typingInterval:null}}function Sg(A,q,g){if(!q.content)return;for(let F of q.content.getChildren())q.content.remove(F.id);let E=-1;for(let F=q.messages.length-1;F>=0;F--)if(q.messages[F]?.role==="user"){E=F;break}for(let F=0;F<q.messages.length;F++){let K=q.messages[F];if(!K)continue;let Z=F>=E&&E!==-1,j=new y(A,{width:"100%",flexDirection:"column",marginBottom:1}),U=new y(A,{flexDirection:"row",gap:1}),G=K.role==="user"?V.accent:V.link,Y=new B(A,{content:"\u2022",fg:G});U.add(Y);let M=g==="anthropic"?"Claude":"GPT",Q=new B(A,{content:K.role==="user"?"You":M,fg:G});U.add(Q),j.add(U);let $=new y(A,{width:"100%",paddingLeft:2}),_=new B(A,{content:K.content,fg:Z?V.textPrimary:V.textSecondary,wrapMode:"word"});$.add(_),j.add($),q.content.add(j)}CG(q)}function CG(A){if(!A.scroll||!A.isActive)return;A.scroll.scrollTop=A.scroll.scrollHeight,setTimeout(()=>{if(A.scroll&&A.isActive)A.scroll.scrollTop=A.scroll.scrollHeight},50),setTimeout(()=>{if(A.scroll&&A.isActive)A.scroll.scrollTop=A.scroll.scrollHeight},150)}function qE(A,q,g,E,F){q.messages.push({role:g,content:E}),Sg(A,q,F)}function fM(A,q,g){if(q.typingInterval)return;q.isTyping=!0,q.typingFrame=0,q.typingInterval=setInterval(()=>{if(!q.isActive||!q.isTyping){O6(q);return}q.typingFrame=(q.typingFrame+1)%yA.length;let E=q.messages[q.messages.length-1];if(E&&E.role==="assistant"&&E.content==="..."){let F=yA[q.typingFrame]??"\u280B";E.content=F,Sg(A,q,g),E.content="..."}},80)}function O6(A){if(A.isTyping=!1,A.typingInterval)clearInterval(A.typingInterval),A.typingInterval=null}function f(A,q,g,E,F){if(E==="m")throw TypeError("Private method is not writable");if(E==="a"&&!F)throw TypeError("Private accessor was defined without a setter");if(typeof q==="function"?A!==q||!F:!q.has(A))throw TypeError("Cannot write private member to an object whose class did not declare it");return E==="a"?F.call(A,g):F?F.value=g:q.set(A,g),g}function I(A,q,g,E){if(g==="a"&&!E)throw TypeError("Private accessor was defined without a getter");if(typeof q==="function"?A!==q||!E:!q.has(A))throw TypeError("Cannot read private member from an object whose class did not declare it");return g==="m"?E:g==="a"?E.call(A):E?E.value:q.get(A)}var DG=function(){let{crypto:A}=globalThis;if(A?.randomUUID)return DG=A.randomUUID.bind(A),A.randomUUID();let q=new Uint8Array(1),g=A?()=>A.getRandomValues(q)[0]:()=>Math.random()*255&255;return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,(E)=>(+E^g()&15>>+E/4).toString(16))};function Zg(A){return typeof A==="object"&&A!==null&&(("name"in A)&&A.name==="AbortError"||("message"in A)&&String(A.message).includes("FetchRequestCanceledException"))}var GF=(A)=>{if(A instanceof Error)return A;if(typeof A==="object"&&A!==null){try{if(Object.prototype.toString.call(A)==="[object Error]"){let q=Error(A.message,A.cause?{cause:A.cause}:{});if(A.stack)q.stack=A.stack;if(A.cause&&!q.cause)q.cause=A.cause;if(A.name)q.name=A.name;return q}}catch{}try{return Error(JSON.stringify(A))}catch{}}return Error(A)};class t extends Error{}class TA extends t{constructor(A,q,g,E){super(`${TA.makeMessage(A,q,g)}`);this.status=A,this.headers=E,this.requestID=E?.get("request-id"),this.error=q}static makeMessage(A,q,g){let E=q?.message?typeof q.message==="string"?q.message:JSON.stringify(q.message):q?JSON.stringify(q):g;if(A&&E)return`${A} ${E}`;if(A)return`${A} status code (no body)`;if(E)return E;return"(no status code or body)"}static generate(A,q,g,E){if(!A||!E)return new M6({message:g,cause:GF(q)});let F=q;if(A===400)return new QF(A,F,g,E);if(A===401)return new JF(A,F,g,E);if(A===403)return new OF(A,F,g,E);if(A===404)return new MF(A,F,g,E);if(A===409)return new $F(A,F,g,E);if(A===422)return new _F(A,F,g,E);if(A===429)return new XF(A,F,g,E);if(A>=500)return new HF(A,F,g,E);return new TA(A,F,g,E)}}class bA extends TA{constructor({message:A}={}){super(void 0,void 0,A||"Request was aborted.",void 0)}}class M6 extends TA{constructor({message:A,cause:q}){super(void 0,void 0,A||"Connection error.",void 0);if(q)this.cause=q}}class YF extends M6{constructor({message:A}={}){super({message:A??"Request timed out."})}}class QF extends TA{}class JF extends TA{}class OF extends TA{}class MF extends TA{}class $F extends TA{}class _F extends TA{}class XF extends TA{}class HF extends TA{}var fH=/^[a-z][a-z0-9+.-]*:/i,cM=(A)=>{return fH.test(A)},yG=(A)=>(yG=Array.isArray,yG(A)),bG=yG;function lZ(A){if(typeof A!=="object")return{};return A??{}}function pM(A){if(!A)return!0;for(let q in A)return!1;return!0}function dM(A,q){return Object.prototype.hasOwnProperty.call(A,q)}var uM=(A,q)=>{if(typeof q!=="number"||!Number.isInteger(q))throw new t(`${A} must be an integer`);if(q<0)throw new t(`${A} must be a positive integer`);return q};var iZ=(A)=>{try{return JSON.parse(A)}catch(q){return}};var lM=(A)=>new Promise((q)=>setTimeout(q,A));var zg="0.71.2";var sM=()=>{return typeof window<"u"&&typeof window.document<"u"&&typeof navigator<"u"};function cH(){if(typeof Deno<"u"&&Deno.build!=null)return"deno";if(typeof EdgeRuntime<"u")return"edge";if(Object.prototype.toString.call(typeof globalThis.process<"u"?globalThis.process:0)==="[object process]")return"node";return"unknown"}var pH=()=>{let A=cH();if(A==="deno")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":zg,"X-Stainless-OS":tM(Deno.build.os),"X-Stainless-Arch":iM(Deno.build.arch),"X-Stainless-Runtime":"deno","X-Stainless-Runtime-Version":typeof Deno.version==="string"?Deno.version:Deno.version?.deno??"unknown"};if(typeof EdgeRuntime<"u")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":zg,"X-Stainless-OS":"Unknown","X-Stainless-Arch":`other:${EdgeRuntime}`,"X-Stainless-Runtime":"edge","X-Stainless-Runtime-Version":globalThis.process.version};if(A==="node")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":zg,"X-Stainless-OS":tM(globalThis.process.platform??"unknown"),"X-Stainless-Arch":iM(globalThis.process.arch??"unknown"),"X-Stainless-Runtime":"node","X-Stainless-Runtime-Version":globalThis.process.version??"unknown"};let q=dH();if(q)return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":zg,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":`browser:${q.browser}`,"X-Stainless-Runtime-Version":q.version};return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":zg,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":"unknown","X-Stainless-Runtime-Version":"unknown"}};function dH(){if(typeof navigator>"u"||!navigator)return null;let A=[{key:"edge",pattern:/Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"ie",pattern:/MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"ie",pattern:/Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"chrome",pattern:/Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"firefox",pattern:/Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"safari",pattern:/(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/}];for(let{key:q,pattern:g}of A){let E=g.exec(navigator.userAgent);if(E){let F=E[1]||0,K=E[2]||0,Z=E[3]||0;return{browser:q,version:`${F}.${K}.${Z}`}}}return null}var iM=(A)=>{if(A==="x32")return"x32";if(A==="x86_64"||A==="x64")return"x64";if(A==="arm")return"arm";if(A==="aarch64"||A==="arm64")return"arm64";if(A)return`other:${A}`;return"unknown"},tM=(A)=>{if(A=A.toLowerCase(),A.includes("ios"))return"iOS";if(A==="android")return"Android";if(A==="darwin")return"MacOS";if(A==="win32")return"Windows";if(A==="freebsd")return"FreeBSD";if(A==="openbsd")return"OpenBSD";if(A==="linux")return"Linux";if(A)return`Other:${A}`;return"Unknown"},nM,rM=()=>{return nM??(nM=pH())};function oM(){if(typeof fetch<"u")return fetch;throw Error("`fetch` is not defined as a global; Either pass `fetch` to the client, `new Anthropic({ fetch })` or polyfill the global, `globalThis.fetch = fetch`")}function vG(...A){let q=globalThis.ReadableStream;if(typeof q>"u")throw Error("`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`");return new q(...A)}function tZ(A){let q=Symbol.asyncIterator in A?A[Symbol.asyncIterator]():A[Symbol.iterator]();return vG({start(){},async pull(g){let{done:E,value:F}=await q.next();if(E)g.close();else g.enqueue(F)},async cancel(){await q.return?.()}})}function VF(A){if(A[Symbol.asyncIterator])return A;let q=A.getReader();return{async next(){try{let g=await q.read();if(g?.done)q.releaseLock();return g}catch(g){throw q.releaseLock(),g}},async return(){let g=q.cancel();return q.releaseLock(),await g,{done:!0,value:void 0}},[Symbol.asyncIterator](){return this}}}async function eM(A){if(A===null||typeof A!=="object")return;if(A[Symbol.asyncIterator]){await A[Symbol.asyncIterator]().return?.();return}let q=A.getReader(),g=q.cancel();q.releaseLock(),await g}var A9=({headers:A,body:q})=>{return{bodyHeaders:{"content-type":"application/json"},body:JSON.stringify(q)}};function E9(A){let q=0;for(let F of A)q+=F.length;let g=new Uint8Array(q),E=0;for(let F of A)g.set(F,E),E+=F.length;return g}var q9;function WF(A){let q;return(q9??(q=new globalThis.TextEncoder,q9=q.encode.bind(q)))(A)}var g9;function mG(A){let q;return(g9??(q=new globalThis.TextDecoder,g9=q.decode.bind(q)))(A)}var rA,oA;class ag{constructor(){rA.set(this,void 0),oA.set(this,void 0),f(this,rA,new Uint8Array,"f"),f(this,oA,null,"f")}decode(A){if(A==null)return[];let q=A instanceof ArrayBuffer?new Uint8Array(A):typeof A==="string"?WF(A):A;f(this,rA,E9([I(this,rA,"f"),q]),"f");let g=[],E;while((E=iH(I(this,rA,"f"),I(this,oA,"f")))!=null){if(E.carriage&&I(this,oA,"f")==null){f(this,oA,E.index,"f");continue}if(I(this,oA,"f")!=null&&(E.index!==I(this,oA,"f")+1||E.carriage)){g.push(mG(I(this,rA,"f").subarray(0,I(this,oA,"f")-1))),f(this,rA,I(this,rA,"f").subarray(I(this,oA,"f")),"f"),f(this,oA,null,"f");continue}let F=I(this,oA,"f")!==null?E.preceding-1:E.preceding,K=mG(I(this,rA,"f").subarray(0,F));g.push(K),f(this,rA,I(this,rA,"f").subarray(E.index),"f"),f(this,oA,null,"f")}return g}flush(){if(!I(this,rA,"f").length)return[];return this.decode(`
102
102
  `)}}rA=new WeakMap,oA=new WeakMap;ag.NEWLINE_CHARS=new Set([`
103
103
  `,"\r"]);ag.NEWLINE_REGEXP=/\r\n|[\n\r]/g;function iH(A,q){for(let F=q??0;F<A.length;F++){if(A[F]===10)return{preceding:F,index:F+1,carriage:!1};if(A[F]===13)return{preceding:F,index:F+1,carriage:!0}}return null}function F9(A){for(let E=0;E<A.length-1;E++){if(A[E]===10&&A[E+1]===10)return E+2;if(A[E]===13&&A[E+1]===13)return E+2;if(A[E]===13&&A[E+1]===10&&E+3<A.length&&A[E+2]===13&&A[E+3]===10)return E+4}return-1}var sZ={off:0,error:200,warn:300,info:400,debug:500},fG=(A,q,g)=>{if(!A)return;if(dM(sZ,A))return A;zA(g).warn(`${q} was set to ${JSON.stringify(A)}, expected one of ${JSON.stringify(Object.keys(sZ))}`);return};function LF(){}function nZ(A,q,g){if(!q||sZ[A]>sZ[g])return LF;else return q[A].bind(q)}var tH={error:LF,warn:LF,info:LF,debug:LF},K9=new WeakMap;function zA(A){let q=A.logger,g=A.logLevel??"off";if(!q)return tH;let E=K9.get(q);if(E&&E[0]===g)return E[1];let F={error:nZ("error",q,g),warn:nZ("warn",q,g),info:nZ("info",q,g),debug:nZ("debug",q,g)};return K9.set(q,[g,F]),F}var jg=(A)=>{if(A.options)A.options={...A.options},delete A.options.headers;if(A.headers)A.headers=Object.fromEntries((A.headers instanceof Headers?[...A.headers]:Object.entries(A.headers)).map(([q,g])=>[q,q.toLowerCase()==="x-api-key"||q.toLowerCase()==="authorization"||q.toLowerCase()==="cookie"||q.toLowerCase()==="set-cookie"?"***":g]));if("retryOfRequestLogID"in A){if(A.retryOfRequestLogID)A.retryOf=A.retryOfRequestLogID;delete A.retryOfRequestLogID}return A};var NF;class eA{constructor(A,q,g){this.iterator=A,NF.set(this,void 0),this.controller=q,f(this,NF,g,"f")}static fromSSEResponse(A,q,g){let E=!1,F=g?zA(g):console;async function*K(){if(E)throw new t("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");E=!0;let Z=!1;try{for await(let j of nH(A,q)){if(j.event==="completion")try{yield JSON.parse(j.data)}catch(U){throw F.error("Could not parse message into JSON:",j.data),F.error("From chunk:",j.raw),U}if(j.event==="message_start"||j.event==="message_delta"||j.event==="message_stop"||j.event==="content_block_start"||j.event==="content_block_delta"||j.event==="content_block_stop")try{yield JSON.parse(j.data)}catch(U){throw F.error("Could not parse message into JSON:",j.data),F.error("From chunk:",j.raw),U}if(j.event==="ping")continue;if(j.event==="error")throw new TA(void 0,iZ(j.data)??j.data,void 0,A.headers)}Z=!0}catch(j){if(Zg(j))return;throw j}finally{if(!Z)q.abort()}}return new eA(K,q,g)}static fromReadableStream(A,q,g){let E=!1;async function*F(){let Z=new ag,j=VF(A);for await(let U of j)for(let G of Z.decode(U))yield G;for(let U of Z.flush())yield U}async function*K(){if(E)throw new t("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");E=!0;let Z=!1;try{for await(let j of F()){if(Z)continue;if(j)yield JSON.parse(j)}Z=!0}catch(j){if(Zg(j))return;throw j}finally{if(!Z)q.abort()}}return new eA(K,q,g)}[(NF=new WeakMap,Symbol.asyncIterator)](){return this.iterator()}tee(){let A=[],q=[],g=this.iterator(),E=(F)=>{return{next:()=>{if(F.length===0){let K=g.next();A.push(K),q.push(K)}return F.shift()}}};return[new eA(()=>E(A),this.controller,I(this,NF,"f")),new eA(()=>E(q),this.controller,I(this,NF,"f"))]}toReadableStream(){let A=this,q;return vG({async start(){q=A[Symbol.asyncIterator]()},async pull(g){try{let{value:E,done:F}=await q.next();if(F)return g.close();let K=WF(JSON.stringify(E)+`
104
104
  `);g.enqueue(K)}catch(E){g.error(E)}},async cancel(){await q.return?.()}})}}async function*nH(A,q){if(!A.body){if(q.abort(),typeof globalThis.navigator<"u"&&globalThis.navigator.product==="ReactNative")throw new t("The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api");throw new t("Attempted to iterate over a response with no body")}let g=new Z9,E=new ag,F=VF(A.body);for await(let K of sH(F))for(let Z of E.decode(K)){let j=g.decode(Z);if(j)yield j}for(let K of E.flush()){let Z=g.decode(K);if(Z)yield Z}}async function*sH(A){let q=new Uint8Array;for await(let g of A){if(g==null)continue;let E=g instanceof ArrayBuffer?new Uint8Array(g):typeof g==="string"?WF(g):g,F=new Uint8Array(q.length+E.length);F.set(q),F.set(E,q.length),q=F;let K;while((K=F9(q))!==-1)yield q.slice(0,K),q=q.slice(K)}if(q.length>0)yield q}class Z9{constructor(){this.event=null,this.data=[],this.chunks=[]}decode(A){if(A.endsWith("\r"))A=A.substring(0,A.length-1);if(!A){if(!this.event&&!this.data.length)return null;let F={event:this.event,data:this.data.join(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brianlovin/hn-cli",
3
- "version": "0.4.17",
3
+ "version": "0.4.18",
4
4
  "description": "Interactive terminal UI for browsing Hacker News",
5
5
  "module": "src/index.ts",
6
6
  "type": "module",
@@ -57,10 +57,10 @@
57
57
  "openai": "^6.16.0"
58
58
  },
59
59
  "optionalDependencies": {
60
- "@brianlovin/hn-cli-darwin-arm64": "0.4.17",
61
- "@brianlovin/hn-cli-darwin-x64": "0.4.17",
62
- "@brianlovin/hn-cli-linux-arm64": "0.4.17",
63
- "@brianlovin/hn-cli-linux-x64": "0.4.17",
64
- "@brianlovin/hn-cli-windows-x64": "0.4.17"
60
+ "@brianlovin/hn-cli-darwin-arm64": "0.4.18",
61
+ "@brianlovin/hn-cli-darwin-x64": "0.4.18",
62
+ "@brianlovin/hn-cli-linux-arm64": "0.4.18",
63
+ "@brianlovin/hn-cli-linux-x64": "0.4.18",
64
+ "@brianlovin/hn-cli-windows-x64": "0.4.18"
65
65
  }
66
66
  }