@andrueandersoncs/lint-anything 0.7.0 → 0.9.0

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.
@@ -0,0 +1,351 @@
1
+ #!/usr/bin/env bun
2
+ // @bun
3
+ var me=(e,t)=>{switch(t.length){case 0:return e;case 1:return t[0](e);case 2:return t[1](t[0](e));case 3:return t[2](t[1](t[0](e)));case 4:return t[3](t[2](t[1](t[0](e))));case 5:return t[4](t[3](t[2](t[1](t[0](e)))));case 6:return t[5](t[4](t[3](t[2](t[1](t[0](e))))));case 7:return t[6](t[5](t[4](t[3](t[2](t[1](t[0](e)))))));case 8:return t[7](t[6](t[5](t[4](t[3](t[2](t[1](t[0](e))))))));case 9:return t[8](t[7](t[6](t[5](t[4](t[3](t[2](t[1](t[0](e)))))))));default:{let n=e;for(let r=0,o=t.length;r<o;r++)n=t[r](n);return n}}};var H=function(e,t){if(typeof e==="function")return function(){return e(arguments)?t.apply(this,arguments):(n)=>t(n,...arguments)};switch(e){case 0:case 1:throw RangeError(`Invalid arity ${e}`);case 2:return function(n,r){if(arguments.length>=2)return t(n,r);return function(o){return t(o,n)}};case 3:return function(n,r,o){if(arguments.length>=3)return t(n,r,o);return function(s){return t(s,n,r)}};default:return function(){if(arguments.length>=e)return t.apply(this,arguments);let n=arguments;return function(r){return t(r,...n)}}}};var he=(e)=>e;var jt=(e)=>()=>e,Dt=jt(!0);var xt=jt(void 0),Vn=xt;var Ve=(e)=>{let t=new Set(Reflect.ownKeys(e));if(e.constructor===Object)return t;if(e instanceof Error)t.delete("stack");let n=Object.getPrototypeOf(e),r=n;while(r!==null&&r!==Object.prototype){let o=Reflect.ownKeys(r);for(let s=0;s<o.length;s++)t.add(o[s]);r=Object.getPrototypeOf(r)}if(t.has("constructor")&&typeof e.constructor==="function"&&n===e.constructor.prototype)t.delete("constructor");return t},Ke=new WeakSet,Ze=(e)=>new Uint8Array(e.buffer,e.byteOffset,e.byteLength),Ge=(e)=>e instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&e instanceof SharedArrayBuffer,Ye=(e)=>{try{return new Uint8Array(e)}catch{return}};var gt=0,Kn=()=>{gt++};function Ut(e){return typeof e==="function"}function Is(e){return typeof e==="object"&&e!==null||Ut(e)}var U=H(2,(e,t)=>Is(e)&&(t in e));var V="~effect/Hash",N=(e)=>{switch(typeof e){case"number":return Jt(e);case"bigint":return Z(e.toString(10));case"string":return Z(e);case"function":case"object":if(e===null)break;else if(e instanceof Date){if(Number.isNaN(e.getTime()))return Z("Invalid Date");return Z(e.toISOString())}else if(e instanceof RegExp)return Z(e.toString());else{if(Ke.has(e))return Bt(e);let t=Gn.get(e);if(t!==void 0)return t;if(Ht.has(e))return Kn(),Z("[Circular]");Ht.add(e);let n=gt,r;try{if(Fs(e))r=e[V]();else if(typeof e==="function")r=Bt(e);else if(Ge(e)){let o=Ye(e);r=o===void 0?Bt(e):Xe(o)}else if(e instanceof DataView)r=Xe(Ze(e));else if(Array.isArray(e)||ArrayBuffer.isView(e))r=Xe(e);else if(e instanceof Map)r=Ls(e);else if(e instanceof Set)r=Ns(e);else r=Ms(e)}finally{Ht.delete(e)}if(n===gt)Gn.set(e,r);return r}}return be(Yn(Z(String(e))))},Bt=(e)=>{if(!qt.has(e))qt.set(e,be(Math.random()*4294967296|0));return qt.get(e)},Yn=(e)=>(e^=e>>>16,e=Math.imul(e,2246822507),e^=e>>>13,e=Math.imul(e,3266489909),e^e>>>16),X=H(2,(e,t)=>Yn(Math.imul(e,2654435761)+Math.imul(t,2246822507))),be=(e)=>e&3221225471|e>>>1&1073741824,Fs=(e)=>U(e,V)&&typeof e[V]==="function",zt=new DataView(new ArrayBuffer(8)),Jt=(e)=>{let t=e|0;if(t===e)return be(t);return zt.setFloat64(0,e!==e?NaN:e),be(X(zt.getInt32(0),zt.getInt32(4)))},Z=(e)=>{let t=5381,n=e.length;while(n)t=t*33^e.charCodeAt(--n);return be(t)},Vt=(e,t)=>{let n=12289;for(let r of t)n^=X(N(r),N(e[r]));return be(n)},Ms=(e)=>Vt(e,Ve(e)),Xn=(e,t)=>(n)=>{let r=e;for(let o of n)r^=t(o);return be(r)},Xe=(e)=>{let t=6151;for(let n of e)t=X(t,N(n));return be(t)},Ls=Xn(Z("Map"),([e,t])=>X(N(e),N(t))),Zn=Z("Set"),Ns=Xn(Zn,(e)=>X(Zn,N(e))),qt=new WeakMap,Gn=new WeakMap,Ht=new WeakSet;var K="~effect/Equal";function G(){if(arguments.length===1)return(e)=>$e(e,arguments[0]);return $e(arguments[0],arguments[1])}function $e(e,t){if(e===t)return!0;if(e==null||t==null)return!1;let n=typeof e;if(n!==typeof t)return!1;if(n==="number"&&e!==e&&t!==t)return!0;if(n!=="object"&&n!=="function")return!1;if(Ke.has(e)||Ke.has(t))return!1;return Ps(e,t)}function Ps(e,t){let n=yt.length;for(let s=n;s-- >0;)if(yt[s]===e&&Zt[s]===t)return!0;if(n)return Qn(e,t);let r=er.get(e);if(!r)er.set(e,r=new WeakMap);let o=r.get(t);if(o===void 0)r.set(t,o=Qn(e,t));return o}function Qn(e,t){yt.push(e),Zt.push(t);try{return js(e,t)}finally{yt.pop(),Zt.pop()}}var yt=[],Zt=[],er=new WeakMap;function js(e,t){if(N(e)!==N(t))return!1;else if(e instanceof Date){if(!(t instanceof Date))return!1;let r=e.getTime(),o=t.getTime();return r===o||Number.isNaN(r)&&Number.isNaN(o)}else if(e instanceof RegExp)return t instanceof RegExp&&e.toString()===t.toString();let n=nr(e);if(n!==nr(t)||typeof e==="function"&&!n)return!1;else if(n)return e[K](t);else if(Array.isArray(e)){if(!Array.isArray(t)||e.length!==t.length)return!1;return Ds(e,t)}else if(Ge(e)){if(!Ge(t)||e instanceof ArrayBuffer!==t instanceof ArrayBuffer)return!1;let r=Ye(e),o=Ye(t);return r!==void 0&&o!==void 0&&Kt(r,o)}else if(ArrayBuffer.isView(e)){let r=e instanceof DataView;if(!ArrayBuffer.isView(t)||e.byteLength!==t.byteLength||r!==t instanceof DataView)return!1;if(r)return Kt(Ze(e),Ze(t));return Kt(e,t)}else if(e instanceof Map){if(!(t instanceof Map)||e.size!==t.size)return!1;return tr(e,t,Ws,Bs)}else if(e instanceof Set){if(!(t instanceof Set)||e.size!==t.size)return!1;return tr(e,t,N,$e)}return Us(e,t)}function Ds(e,t){for(let n=0;n<e.length;n++)if(!$e(e[n],t[n]))return!1;return!0}function Kt(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function Us(e,t){let n=Ve(e),r=Ve(t);if(n.size!==r.size)return!1;for(let o of n)if(!r.has(o)||!$e(e[o],t[o]))return!1;return!0}function tr(e,t,n,r){let o=new Map,s=0;for(let i of t){let c=n(i),l=o.get(c);if(l)l.push(i);else o.set(c,[i]);s++}e:for(let i of e){let c=o.get(n(i));if(c){for(let l=0;l<c.length;l++)if(r(i,c[l])){c[l]=c[c.length-1],c.pop(),s--;continue e}}return!1}return s===0}var Ws=(e)=>N(e[0]),Bs=(e,t)=>$e(e[0],t[0])&&$e(e[1],t[1]);var nr=(e)=>U(e,K)&&typeof e[K]==="function";var bt=Symbol.for("~effect/Redactable"),zs=(e)=>U(e,bt);function wt(e){if(zs(e))return Gt(e);return e}function Gt(e){return e[bt](globalThis[Ce]?.context??qs)}var Ce="~effect/Fiber/currentFiber",rr=new Map,qs={"~effect/Context":{},base:rr,depth:0,mapUnsafe:rr,pipe(){return me(this,arguments)}};function ne(e,t){let n=t?.space??0,r=new WeakSet,o=!n?"":typeof n==="number"?" ".repeat(n):n,s=(a)=>o.repeat(a),i=(a,f)=>{let d=a?.constructor;return d&&d!==Object.prototype.constructor&&d.name?`${d.name}(${f})`:f},c=(a)=>{try{return Reflect.ownKeys(a)}catch{return["[ownKeys threw]"]}};function l(a,f=0){try{return p(a,f)}catch{if(typeof a==="object"&&a!==null||typeof a==="function")r.delete(a);return"[inspection threw]"}}function p(a,f=0){if(typeof a==="string")return JSON.stringify(a);if(typeof a==="number"||a==null||typeof a==="boolean"||typeof a==="symbol")return String(a);if(typeof a==="bigint")return String(a)+"n";if(typeof a==="object"||typeof a==="function"){if(r.has(a))return Js;r.add(a);let d;if(bt in a)d=l(Gt(a),f);else if(Array.isArray(a))d=!o||a.length<=1?`[${a.map((h)=>l(h,f)).join(",")}]`:`[
4
+ ${s(f+1)}${a.map((h)=>l(h,f+1)).join(`,
5
+ `+s(f+1))}
6
+ ${s(f)}]`;else if(a instanceof Date)d=Vs(a);else if(!t?.ignoreToString&&U(a,"toString")&&typeof a.toString==="function"&&a.toString!==Object.prototype.toString&&a.toString!==Array.prototype.toString){let h=Ks(a);d=a instanceof Error&&a.cause!==void 0?`${h} (cause: ${l(a.cause,f)})`:h}else if(Symbol.iterator in a)d=`${a.constructor.name}(${l(Array.from(a),f)})`;else{let h=c(a);if(!o||h.length<=1){let u=`{${h.map((S)=>`${or(S)}:${l(sr(a,S),f)}`).join(",")}}`;d=i(a,u)}else{let u=`{
7
+ ${h.map((S)=>`${s(f+1)}${or(S)}: ${l(sr(a,S),f+1)}`).join(`,
8
+ `)}
9
+ ${s(f)}}`;d=i(a,u)}}return r.delete(a),d}return String(a)}return l(e,0)}var Js="[Circular]";function or(e){return typeof e==="string"?JSON.stringify(e):String(e)}function Vs(e){try{return e.toISOString()}catch{return"Invalid Date"}}function Ks(e){try{let t=e.toString();return typeof t==="string"?t:String(t)}catch{return"[toString threw]"}}function sr(e,t){try{return e[t]}catch{return"[property access threw]"}}var et=Symbol.for("nodejs.util.inspect.custom"),tt=(e)=>{try{if(e=wt(e),U(e,"toJSON")&&Ut(e.toJSON)&&e.toJSON.length===0)return e.toJSON();else if(Array.isArray(e))return e.map(tt);return e}catch{return"[toJSON threw]"}};var ol={toJSON(){return tt(this)},[et](){return this.toJSON()},toString(){return ne(this.toJSON())}};var Ys=()=>{let e=Object.getOwnPropertyDescriptor(Error,"stackTraceLimit");if(e===void 0)return Object.isExtensible(Error);return Object.hasOwn(e,"writable")?e.writable===!0:e.set!==void 0},Xs=Ys(),$t=()=>Error.stackTraceLimit,Te=(e)=>{if(Xs)Error.stackTraceLimit=e};class nt{constructor(e){this.value=e,this.done=!1}next(e){if(this.done)return this.value=e,this;return this.done=!0,{value:this.value,done:!1}}}var Qs=()=>{let t={["~effect/Utils/internal"]:(s)=>s()},n={["~effect/Utils/internal"]:(s)=>{try{return s()}finally{}}},r=$t();if(r===0)return n["~effect/Utils/internal"];Te(2);let o=t["~effect/Utils/internal"](()=>Error());return Te(r),o.stack?.includes("~effect/Utils/internal")===!0?t["~effect/Utils/internal"]:n["~effect/Utils/internal"]},rt=Qs();function ti(e,t,n){if(t==="__proto__")Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0});else e[t]=n}function ir(e,t){if(!Object.hasOwn(t,"__proto__")){Object.assign(e,t);return}for(let n of Reflect.ownKeys(t))if(Object.prototype.propertyIsEnumerable.call(t,n))ti(e,n,t[n])}var ke="~effect/Effect",Ie="~effect/Exit",ri={_A:he,_E:he,_R:he},en=`${ke}/identifier`,C=`${ke}/args`,P=`${ke}/evaluate`,B=`${ke}/successCont`,re=`${ke}/failureCont`,Fe=`${ke}/ensureCont`,Se=Symbol.for("effect/Effect/Yield"),st={pipe(){return me(this,arguments)},toJSON(){return{...this}},toString(){return ne(this.toJSON(),{ignoreToString:!0,space:2})},[et](){return this.toJSON()}},dl={[V](){return Vt(this,Object.keys(this))},[K](e){let t=Object.keys(this),n=Object.keys(e);if(t.length!==n.length)return!1;for(let r=0;r<t.length;r++)if(t[r]!==n[r]||!G(this[t[r]],e[t[r]]))return!1;return!0}},oi={[ke]:ri,...st,[Symbol.iterator](){return new nt(this)},toJSON(){return{_id:"Effect",op:this[en],...C in this?{args:this[C]}:void 0}}};var si=(e)=>U(e,Ie),Xt="~effect/Cause",Yt="~effect/Cause/Reason",tn=(e)=>U(e,Xt);class xe{constructor(e){this[Xt]=Xt,this.reasons=e}pipe(){return me(this,arguments)}toJSON(){return{_id:"Cause",reasons:this.reasons.map((e)=>e.toJSON())}}toString(){return`Cause(${ne(this.reasons)})`}[et](){return this.toJSON()}[K](e){return tn(e)&&this.reasons.length===e.reasons.length&&this.reasons.every((t,n)=>G(t,e.reasons[n]))}[V](){return Xe(this.reasons)}}var ar=new WeakMap;class it{[Yt];annotations;_tag;constructor(e,t,n){if(this[Yt]=Yt,this._tag=e,t!==at&&typeof n==="object"&&n!==null&&t.size>0){let r=ar.get(n);if(r)t=new Map([...r,...t]);ar.set(n,t)}this.annotations=t}annotate(e,t){if(e.mapUnsafe.size===0)return this;let n=new Map(this.annotations);if(e.mapUnsafe.forEach((o,s)=>{if(t?.overwrite!==!0&&n.has(s))return;n.set(s,o)}),t?.overwrite!==!0&&n.size===this.annotations.size)return this;let r=Object.assign(Object.create(Object.getPrototypeOf(this)),this);return r.annotations=n,r}pipe(){return me(this,arguments)}toString(){return ne(this)}[et](){return this.toString()}}var at=new Map;class nn extends it{constructor(e,t=at){super("Fail",t,e);this.error=e}toString(){return`Fail(${ne(this.error)})`}toJSON(){return{_tag:"Fail",error:this.error}}[K](e){return sn(e)&&G(this.error,e.error)&&G(this.annotations,e.annotations)}[V](){return X(Z(this._tag))(X(N(this.error))(N(this.annotations)))}}var kt=(e)=>new xe(e),ii=(e,t)=>{let n=new Map,r=[];for(let o of e.concat(t)){let s=N(o),i=n.get(s);if(i===void 0)n.set(s,[o]);else if(i.some((c)=>G(c,o)))continue;else i.push(o);r.push(o)}return r},rn=H(2,(e,t)=>{if(e.reasons.length===0)return t;else if(t.reasons.length===0)return e;let n=new xe(ii(e.reasons,t.reasons));return G(e,n)?e:n}),on=(e,t)=>{let n=e.reasons.slice();for(let r of t.reasons)if(ot(r)&&!n.some((o)=>ot(o)&&o.fiberId===r.fiberId&&o.annotations===r.annotations))n.push(r);return n.length===e.reasons.length?e:new xe(n)};var ai=(e)=>new xe([new nn(e)]);class St extends it{constructor(e,t=at){super("Die",t,e);this.defect=e}toString(){return`Die(${ne(this.defect)})`}toJSON(){return{_tag:"Die",defect:this.defect}}[K](e){return an(e)&&G(this.defect,e.defect)&&G(this.annotations,e.annotations)}[V](){return X(Z(this._tag))(X(N(this.defect))(N(this.annotations)))}}var ci=(e)=>new xe([new St(e)]),_t=H((e)=>tn(e[0]),(e,t,n)=>{if(t.mapUnsafe.size===0)return e;return new xe(e.reasons.map((r)=>r.annotate(t,n)))}),sn=(e)=>e._tag==="Fail",an=(e)=>e._tag==="Die",ot=(e)=>e._tag==="Interrupt";function li(e){return Me("Effect.evaluate: Not implemented")}var oe=(e)=>({...oi,[en]:e.op,[P]:e[P]??li,[B]:e[B],[re]:e[re],[Fe]:e[Fe]}),ae=(e)=>{let t=oe(e),n=function(r){this[C]=r};return n.prototype=t,function(r){return new n(r)}},cr=(e)=>{let t={[Ie]:Ie,_tag:e.op,get[e.prop](){return this[C]},...oe(e),toString(){return`${e.op}(${ne(this[C])})`},toJSON(){return{_id:"Exit",_tag:e.op,[e.prop]:this[C]}},[K](r){return si(r)&&r._tag===this._tag&&G(this[C],r[C])},[V](){return X(Z(e.op),N(this[C]))}},n=function(r){this[C]=r};return n.prototype=t,function(r){return new n(r)}},te=cr({op:"Success",prop:"value",[P](e){let t=e.getCont(B);return t?t[B](this[C],e,this):e.yieldWith(this)}}),cn={key:"effect/Cause/StackTrace"},lr={key:"effect/Cause/InterruptorStackTrace"},ge=cr({op:"Failure",prop:"cause",[P](e){let t=this[C],n=!1;if(e.cache.stackFrame)t=_t(t,{mapUnsafe:new Map([[cn.key,e.cache.stackFrame]])}),n=!0;let r=e.getCont(re),o=e._interruptedCause;if(o&&e.interruptible){let s=!1;while(r&&e.interruptible)s||=en in r,r=e.getCont(re);if(s)t=kt(t.reasons.filter((i)=>i._tag!=="Fail"));t=on(t,o),n=!0}return r?r[re](t,e,n?void 0:this):e.yieldWith(n?ge(t):this)}}),ln=(e)=>ge(ai(e)),Me=(e)=>ge(ci(e)),Le=ae({op:"WithFiber",[P](e){return this[C](e)}}),ml=ae({op:"WithFiberSucceed",[P](e){let t=this[C](e),n=e.getCont(B);return n?n[B](t,e):e.yieldWith(te(t))}}),ui=function(){class e extends globalThis.Error{}let t=oe({op:"YieldableError",[P](){return ln(this)}});return delete t.toString,Object.assign(e.prototype,t),e}(),pi=function(){let e=Symbol.for("effect/Data/Error/plainArgs");return class extends ui{constructor(n){super(n?.message,n?.cause?{cause:n.cause}:void 0);if(n)ir(this,n),Object.defineProperty(this,e,{value:n,enumerable:!1})}toJSON(){return{...this[e],...this}}}}(),ur=(e)=>{class t extends pi{_tag=e}return t.prototype.name=e,t};var Qt="~effect/Cause/Done",pr=(e)=>U(e,Qt),hl={[Qt]:Qt,_tag:"Done",value:void 0};var fr=(e)=>oe({op:e.label,[P]:e.evaluate});var mr="~effect/Result",hr={[mr]:{_A:(e)=>e,_E:(e)=>e},...st,[Symbol.iterator](){return new nt(this)}},fi=Object.assign(Object.create(hr),{_tag:"Success",_op:"Success",[K](e){return un(e)&&xr(e)&&G(this.success,e.success)},[V](){return X(N(this._tag))(N(this.success))},toString(){return`success(${ne(this.success)})`},toJSON(){return{_id:"Result",_tag:this._tag,value:tt(this.success)}}}),di=Object.assign(Object.create(hr),{_tag:"Failure",_op:"Failure",[K](e){return un(e)&&pn(e)&&G(this.failure,e.failure)},[V](){return X(N(this._tag))(N(this.failure))},toString(){return`failure(${ne(this.failure)})`},toJSON(){return{_id:"Result",_tag:this._tag,failure:tt(this.failure)}}}),un=(e)=>U(e,mr),pn=(e)=>e._tag==="Failure",xr=(e)=>e._tag==="Success",gr=function(e){this.failure=e};gr.prototype=di;var yr=(e)=>new gr(e),br=function(e){this.success=e};br.prototype=fi;var wr=(e)=>new br(e);var $r="~effect/Context/Service",kr=function(){function e(){}let t=e;Object.setPrototypeOf(t,hi);let n=(r,o)=>{if(t.key=r,o?.defaultValue)t[dn]=dn,t.defaultValue=o.defaultValue;if(o?.make)t.make=o.make;if(o?.fiberCached)Sr.add(r);return t};return arguments.length>0?n(arguments[0],arguments[1]):n},hi={[$r]:$r,...fr({label:"Service",evaluate(e){return te(se(e.context,this))}}),toJSON(){return{_id:"Service",key:this.key}},of(e){return e},context(e){return yn(this,e)},use(e){return Le((t)=>e(se(t.context,this)))},useSync(e){return Le((t)=>te(e(se(t.context,this))))}},Sr=new Set,dn="~effect/Context/Reference",_r="~effect/Context",xi=8,mn=(e,t,n,r,o)=>{let s=Object.create(gi);return s.cacheRoot=e??s,s.base=t,s.overlay=n,s.depth=r,s._flat=void 0,s.baseHits=0,s.maxDepth=o,s},hn=(e,t)=>{if(!t)return;hn(e,t.parent),e.set(t.key,t.value)},Er=(e)=>{if(e._flat)return e._flat;if(!e.overlay)return e._flat=e.base;let t=new Map(e.base);return hn(t,e.overlay),e._flat=t};var xn=Symbol(),vr=(e,t)=>{let n=e;for(let o=n.overlay;o;o=o.parent)if(o.key===t)return o.value;let r=n.base.get(t);if(r===void 0&&!n.base.has(t))return xn;if(n.overlay&&++n.baseHits>=n.base.size&&n.baseHits>=xi)n.base=Er(n),n.overlay=void 0,n.depth=0;return r},Et=(e,t)=>{let n=t?.maxDepth;return mn(void 0,e,void 0,0,Number.isInteger(n)&&n>=0?n:8)},gi={get mapUnsafe(){return Er(this)},...st,[_r]:{_Services:(e)=>e},toJSON(){return{_id:"Context",services:Array.from(this.mapUnsafe).map(([e,t])=>({key:e,value:t}))}},[K](e){if(!yi(e))return!1;let t=this.mapUnsafe,n=e.mapUnsafe;if(t.size!==n.size)return!1;for(let[r,o]of t)if(!n.has(r)||!G(o,n.get(r)))return!1;return!0},[V](){return Jt(this.mapUnsafe.size)}},Ar=(e,t)=>e.cacheRoot===t.cacheRoot,yi=(e)=>U(e,_r);var bi=(e)=>!!e[dn],gn=()=>wi,wi=Et(new Map),yn=(e,t)=>Et(new Map([[e.key,t]])),Or=H(3,(e,t,n)=>$i(e,t.key,n)),$i=(e,t,n)=>{let r=e,o=Sr.has(t)?void 0:r.cacheRoot;if(r.depth>=r.maxDepth){let s=new Map(r._flat??r.base);if(!r._flat)hn(s,r.overlay);return s.set(t,n),mn(o,s,void 0,0,r.maxDepth)}return mn(o,r.base,{key:t,value:n,parent:r.overlay},r.depth+1,r.maxDepth)};var vt=(e,t)=>{let n=vr(e,t);return n===xn?void 0:n},Rr=H(2,(e,t)=>{let n=vr(e,t.key);if(n===xn){if(bi(t))return ki(t);throw Si(t)}return n}),se=Rr,fn="~effect/Context/defaultValue",ki=(e)=>{if(fn in e)return e[fn];return e[fn]=e.defaultValue()},Si=(e)=>{let t=Error(`Service not found${e.key?`: ${String(e.key)}`:""}`);if(t.stack){let n=t.stack.split(`
10
+ `);n.splice(1,3),t.stack=n.join(`
11
+ `)}return t};var ce=kr;var bn=wr,Ot=yr;var wn=pn;var $n=globalThis.Array;var Tr=(e)=>$n.isArray(e)?e:$n.from(e);var Rl=$n.isArray;var Ir=()=>[];var kn=ce("effect/Scheduler",{fiberCached:!0,defaultValue:()=>new Sn}),Mr=(e)=>{let t=!1;return Promise.resolve().then(()=>{if(!t)e()}),()=>{t=!0}},_i="setImmediate"in globalThis?(e)=>{let t=globalThis.setImmediate(e);return()=>globalThis.clearImmediate(t)}:(e)=>{let t=setTimeout(e,0);return()=>clearTimeout(t)},Lr=(e)=>{try{return _i(e)}catch{return Mr(e)}};class Nr{buckets=[];scheduleTask(e,t){let n=this.buckets,r=n.length,o,s=0;for(;s<r;s++){if(n[s][0]>t)break;o=n[s]}if(o&&o[0]===t)o[1].push(e);else if(s===r)n.push([t,[e]]);else n.splice(s,0,[t,[e]])}drain(){let e=this.buckets;return this.buckets=[],e}}class Sn{executionMode;setImmediate;constructor(e="async",t){this.executionMode=e,this.setImmediate=t??(e==="sync"?Mr:Lr)}shouldYield(e){return e.currentOpCount>=e.cache.maxOpsBeforeYield}makeDispatcher(){return new Pr(this.setImmediate)}}class Pr{tasks=new Nr;running=void 0;setImmediate;constructor(e=Lr){this.setImmediate=e}scheduleTask(e,t){if(this.tasks.scheduleTask(e,t),this.running===void 0)this.running=this.setImmediate(this.afterScheduled)}afterScheduled=()=>{this.running=void 0,this.runTasks()};runTasks(){let e=this.tasks.drain();for(let t=0;t<e.length;t++){let n=e[t][1];for(let r=0;r<n.length;r++)n[r]()}}flush(){while(this.tasks.buckets.length>0){if(this.running!==void 0)this.running(),this.running=void 0;this.runTasks()}}}var jr=ce("effect/Scheduler/MaxOpsBeforeYield",{fiberCached:!0,defaultValue:()=>2048}),Dr=ce("effect/Scheduler/PreventSchedulerYield",{fiberCached:!0,defaultValue:()=>!1});var Wr="effect/Tracer/ParentSpan";var Br="effect/Tracer";var qr="effect/Metric/FiberRuntimeMetrics";var Hr=ce("effect/References/CurrentStackFrame",{fiberCached:!0,defaultValue:xt}),Jr=ce("effect/References/TracerEnabled",{fiberCached:!0,defaultValue:Dt});var Vr=ce("effect/References/CurrentLogLevel",{fiberCached:!0,defaultValue:()=>"Info"}),Kr=ce("effect/References/MinimumLogLevel",{fiberCached:!0,defaultValue:()=>"Info"});class eo extends it{constructor(e,t=at){super("Interrupt",t,"Interrupted");this.fiberId=e}toString(){return`Interrupt(${this.fiberId})`}toJSON(){return{_tag:"Interrupt",fiberId:this.fiberId}}[K](e){return ot(e)&&this.fiberId===e.fiberId&&this.annotations===e.annotations}[V](){return Z(`${this._tag}:${this.fiberId}`)}}var vi=(e)=>new xe([new eo(e)]),Ai=(e)=>e.reasons.some(sn);var Oi=(e)=>{for(let t=0;t<e.reasons.length;t++){let n=e.reasons[t];if(n._tag==="Fail")return bn(n.error)}return Ot(e)};var to=(e)=>e.reasons.some(an),_n=(e)=>to(e)&&Ai(e)?kt(e.reasons.map((t)=>t._tag==="Fail"&&!pr(t.error)?new St(t.error,t.annotations):t)):e,no=(e)=>to(e)?Ot(_n(e)):Oi(e);var Ri=(e)=>e.reasons.some(ot);var Ci=(e)=>{let t;for(let n of e.reasons){if(n._tag==="Fail")return n.error;if(n._tag==="Die")t??=n}if(t!==void 0)return t.defect;if(e.reasons.length>0)return new globalThis.Error("All fibers interrupted without error");return new globalThis.Error("Empty cause")};var Ti="~effect/Fiber",Ii={_A:he,_E:he},Fi={id:0},Zr=(()=>{try{return globalThis.process?.getBuiltinModule?.("node:async_hooks")?.AsyncResource}catch{return}})(),ro=()=>Zr===void 0?void 0:new Zr("effect/Fiber"),Mi=()=>globalThis[Ce];class En{constructor(e,t=!0){this.setContext(e),this.id=++Fi.id,this.currentOpCount=0,this.interruptible=t,this._stack=[],this._observers=void 0,this._exit=void 0,this._children=void 0,this._interruptedCause=void 0,this._yielded=void 0,this._running=!1,this._deferredInterrupt=!1,this._parent=void 0,this._asyncContext=void 0,this.cache.runtimeMetrics?.recordFiberStart(this.context)}get[Ti](){return Ii}get currentDispatcher(){return this._dispatcher??=this.cache.scheduler.makeDispatcher()}getRef(e){return se(this.context,e)}addObserver(e){if(this._exit)return e(this._exit),Vn;if(this._observers===void 0)this._observers=[e];else this._observers.push(e);return()=>this.removeObserver(e)}removeObserver(e){if(this._exit||this._observers===void 0)return;let t=this._observers.indexOf(e);if(t>=0)this._observers.splice(t,1)}interruptUnsafe(e,t){if(this._exit)return;let n=vi(e);if(this.cache.stackFrame)n=_t(n,yn(cn,this.cache.stackFrame));if(t)n=_t(n,t);if(this._interruptedCause=this._interruptedCause?on(this._interruptedCause,n):n,this.interruptible)if(this._running)this._deferredInterrupt=!0;else this.evaluate(ue(this._interruptedCause))}pollUnsafe(){return this._exit}evaluate(e){if(this._exit)return;else if(this._asyncContext!==void 0){let o=this._asyncContext;this._asyncContext=void 0;try{return o.runInAsyncScope(this.evaluate,this,e)}finally{o.emitDestroy()}}else if(this._yielded!==void 0){let o=this._yielded;this._yielded=void 0,o()}let t=this.runLoop(e);if(t===Se){this._asyncContext=ro();return}let n=Gr.interruptChildren&&Gr.interruptChildren(this);if(n!==void 0)return this.evaluate(Pe(n,()=>t));if(this._exit=t,this.cache.runtimeMetrics?.recordFiberEnd(this.context,this._exit),this._parent)this._parent._children?.delete(this),this._parent=void 0;if(this._observers!==void 0){let o=this._observers;this._observers=void 0;for(let s=0;s<o.length;s++)o[s](t)}this._stack.length=0,this._children=void 0,this.context=gn();let r=this.cache;if(r.span!==void 0||r.stackFrame!==void 0)this.cache={...r,span:void 0,stackFrame:void 0}}runLoop(e){let t=globalThis[Ce];globalThis[Ce]=this;let n=this._running;this._running=!0;let r=!1,o=e;this.currentOpCount=0;try{while(!0)try{if(this._deferredInterrupt)this._deferredInterrupt=!1,o=ue(this._interruptedCause);this.currentOpCount++;let s=this.cache;if(!r&&!s.preventYield&&s.scheduler.shouldYield(this)){r=!0;let i=o;o=Pe(co,()=>i)}if(o=s.tracerContext?s.tracerContext(o,this):o[P](this),o===Se){let i=this._yielded;if(Ie in i)return this._deferredInterrupt=!1,this._yielded=void 0,i;else if(this._deferredInterrupt){this._yielded=void 0,i();continue}return Se}}catch(s){if(!U(o,P))return Me(`Fiber.runLoop: Not a valid effect: ${String(o)}`);o=Me(s)}}finally{this._running=n,globalThis[Ce]=t}}getCont(e){if(this._deferredInterrupt)return this._deferredInterrupt=!1,Ni;while(!0){let t=this._stack.pop();if(!t)return;let n=t[Fe];if(n!==void 0){let r=n.call(t,this);if(r)return r[e]=r,r}if(t[e])return t}}succeedWith(e){if((++this.currentOpCount&Pi-1)===0)return te(e);let t=this.getCont(B);return t?t[B](e,this):this.yieldWith(te(e))}yieldWith(e){return this._yielded=e,Se}children(){return this._children??=new Set}pipe(){return me(this,arguments)}setContext(e){let t=this.context;if(this.context=e,t!==void 0&&Ar(t,e))return;let n=e.cacheRoot,r=n._fiberCache??=Li(e);if(this.cache?.scheduler!==r.scheduler)this._dispatcher=void 0;this.cache=r}get currentSpanLocal(){let e=this.cache.span;return e?._tag==="Span"?e:void 0}}var Li=(e)=>{let t=vt(e,Br);return{scheduler:se(e,kn),tracer:t,tracerContext:t?t.context:void 0,tracerEnabled:se(e,Jr),span:vt(e,Wr),logLevel:se(e,Vr),minimumLogLevel:se(e,Kr),stackFrame:se(e,Hr),runtimeMetrics:vt(e,qr),maxOpsBeforeYield:se(e,jr),preventYield:se(e,Dr)}},Ni={[B](e,t){return ue(t._interruptedCause)},[re](e,t){return ue(t._interruptedCause)}},Pi=32,Gr={interruptChildren:void 0},oo=(e)=>{if(!e.cache.stackFrame)return;let t=new Map;return t.set(lr.key,e.cache.stackFrame),Et(t)};var ji=(e)=>On((t)=>{let n=e[Symbol.iterator](),r=[],o=void 0;function s(){let i=n.next();while(!i.done){if(i.value._exit){r.push(i.value._exit),i=n.next();continue}o=i.value.addObserver((c)=>{r.push(c),s()});return}t(le(r))}return s(),io(()=>o?.())});var Yr=(e)=>Le((t)=>{let n=oo(t),r=Ir();for(let o of e)o.interruptUnsafe(t.id,n),r.push(o);return mo(ji(r))});var le=te,ue=ge,so=ln,io=ae({op:"Sync",[P](e){let t=this[C],n=t(),r=e.getCont(B);return r?r[B](n,e):e.yieldWith(te(n))}}),Ee=ae({op:"Suspend",[P](e){let t=this[C];return t()}});var ao=ae({op:"Yield",[P](e){let t=!1;return e.currentDispatcher.scheduleTask(()=>{if(t)return;e.evaluate(ve)},this[C]??0),e.yieldWith(()=>{t=!0})}}),co=ao(0);var vn=(e)=>Me(e);var Ne=le(void 0);var lo=(e)=>An(function(t,n){e(n).then((r)=>t(le(r)),(r)=>t(vn(r)))},e.length!==0),uo=(e)=>{let t=typeof e==="function"?e:e.try,n=typeof e==="function"?(r)=>new Ro(r,"An error occurred in Effect.tryPromise"):e.catch;return An(function(r,o){let s=(i)=>Ee(()=>{try{return so(rt(()=>n(i)))}catch(c){return vn(c)}});try{t(o).then((i)=>r(le(i)),(i)=>r(s(i)))}catch(i){r(s(i))}},t.length!==0)};var An=function(){let e=oe({op:"Async",[P](n){let r=!1,o=!1,s=this.withSignal?new AbortController:void 0,i=this.register.call(n.cache.scheduler,(c)=>{if(r)return;if(r=!0,o)n.evaluate(c);else o=c},s?.signal);if(o!==!1)return o;if(o=!0,n.yieldWith(()=>{r=!0}),s===void 0&&i===void 0)return Se;return n._stack.push(Di(()=>(r=!0,s?.abort(),i??ve))),Se}}),t=function(n,r){this.register=n,this.withSignal=r};return t.prototype=e,function(n,r){return new t(n,r)}}(),Di=ae({op:"AsyncFinalizer",[Fe](e){if(e.interruptible)e.interruptible=!1,e._stack.push(ko)},[re](e,t){return Ri(e)?Pe(Gi(ge(e),this[C]()),()=>ue(e)):ue(e)}}),On=(e)=>An(e,e.length>=2);var po=(...e)=>{if(e.length===1){let r=e[0];return Ee(()=>Xr(r()))}let[t,n]=e;return Ee(()=>Xr(n.call(t.self)))};var Xr=function(){let e=oe({op:"Iterator",[B](n,r){let o=this.iterator;while(!0){let s=o.next(n);if(s.done)return le(s.value);if(!Tn(s.value))return r._stack.push(this),s.value;else if(s.value._tag==="Failure")return s.value;n=s.value.value}},[P](n){return this[B](this.initial,n)}}),t=function(n,r){this.iterator=n,this.initial=r};return t.prototype=e,function(n,r){return new t(n,r)}}(),Rn=H(2,(e,t)=>new ct(e,fo,le(t))),Rt=function(e){return e._stack.push(this),this[C]},Ui=oe({op:"OnSuccess",[P]:Rt}),ct=function(e,t,n){this[C]=e,this[B]=t,this.payload=n};ct.prototype=Ui;var fo=function(){return this.payload};var Cn=(()=>{let e=$t();if(e===0)return!1;let t="~effect/Effect/stackProbe",n={[t]:function(){return Error()}};Te(1);let r=n[t]();return Te(e),r.stack?.includes("[as "+t+"]")===!0})(),Wi=function(e,t){let n=this.payload;return t.succeedWith(Cn?n(e):rt(()=>n(e)))},Bi=function(e){let t=this.payload;return t(e)};var mo=(e)=>new ct(e,fo,ve);var Pe=H(2,(e,t)=>new ct(e,Bi,t));var Tn=(e)=>e[Ie]!==void 0;var ho=H(2,(e,t)=>new ct(e,Wi,t));var zi=(e)=>e._tag==="Success";var ve=te(void 0);var xo=H(2,(e,t)=>new go(e,t.length!==1?(n)=>t(n):t)),qi=oe({op:"OnFailure",[P]:Rt}),go=function(e,t){this[C]=e,this[re]=t};go.prototype=qi;var yo=(e)=>wo(e,{onFailure:Ot,onSuccess:bn});var Hi=oe({op:"OnSuccessAndFailure",[P]:Rt}),Ji=function(e,t,n){this[C]=e,this[B]=t,this[re]=n};Ji.prototype=Hi;var Vi=function(e,t){let n=this.payload;return t.succeedWith(Cn?n.onSuccess(e):rt(()=>n.onSuccess(e)))},Ki=(e,t)=>{let n=oe({op:e,[P]:Rt,[B]:Vi,[re]:t}),r=function(o,s){this[C]=o,this.payload=s};return r.prototype=n,r},Zi=Ki("Match",function(e,t){let n=no(e);if(wn(n))return ue(n.failure);let r=this.payload;return t.succeedWith(Cn?r.onFailure(n.success):rt(()=>r.onFailure(n.success)))});var bo=H(2,(e,t)=>new Zi(e,t)),wo=H(2,(e,t)=>{if(Tn(e)){if(e._tag==="Success")return te(t.onSuccess(e.value));let n=no(e.cause);if(wn(n))return ge(n.failure);return te(t.onFailure(n.success))}return bo(e,t)});var mu=ae({op:"Exit",[P](e){return e._stack.push(this),this[C]},[B](e,t,n){return t.succeedWith(n??te(e))},[re](e,t,n){return t.succeedWith(n??ge(e))}});var Gi=(e,t)=>zi(e)?t:xo(t,(n)=>ue(_n(rn(e.cause,n))));var $o=(e)=>Le((t)=>{if(!t.interruptible)return e;return t.interruptible=!1,t._stack.push(ko),e}),Yi=ae({op:"SetInterruptible",[Fe](e){if(e.interruptible=this[C],e._interruptedCause&&e.interruptible)return()=>ue(e._interruptedCause)}}),ko=Yi(!0);var So=ae({op:"While",[B](e,t){if(this[C].step(e),this[C].while())return t._stack.push(this),this[C].body();return ve},[P](e){if(this[C].while())return e._stack.push(this),this[C].body();return ve}}),_o=H((e)=>typeof e[1]==="function",(e,t,n)=>Ee(()=>{let r=Qi(n?.concurrency);if(r===1)return Xi(e,t,n);let o=Tr(e),s=o.length;if(s===0)return n?.discard?Ne:le([]);let i=n?.discard?void 0:Array(s),c=ta({f:t,out:i},o,{concurrency:r});return c?Rn(c,i):le(i)}));var Xi=(e,t,n)=>Ee(()=>{let r=n?.discard?void 0:[],o=e[Symbol.iterator](),s=o.next(),i=0;return Rn(So({while:()=>!s.done,body:()=>t(s.value,i++),step:(c)=>{if(r)r.push(c);s=o.next()}}),r)}),Qi=(e)=>e==="unbounded"?Number.POSITIVE_INFINITY:Math.max(1,e??1);var ea=(e)=>{let{onItem:t,step:n}=e;return(r,o,s)=>{let i=0,c=s.end??o.length,l=s.concurrency,p=!1,a,f,d,h,u,S=(m)=>{let w=Me(m);return h=w,p=!0,f&&f.size>0?Pe($o(Yr(Array.from(f))),()=>h??w):w},x=()=>{let m=!1;for(;!h&&i<c;i++){let w=o[i],y=u??t(r,w,i);if(Tn(y)){if(h=n(r,w,y,i),h)break}else if(!a)return On((g)=>{a=Mi(),f=new Set,u=y,d=g;let _;try{_=x()}catch(E){return g(S(E))}if(_)return g(_);return Ee(()=>(h??=ve,Pe(f?Yr(f):Ne,()=>h?._tag==="Failure"?h:Ne)))});else{u=void 0;let g=na(a,y,!0,!0,"inherit");if(g._exit){if(h=n(r,w,g._exit,i),h)break;continue}f.add(g);let _=i;if(g.addObserver((E)=>{f.delete(g);try{if(h){if(E._tag==="Failure"){let b=E.cause.reasons.filter((v)=>v._tag!=="Interrupt");if(b.length>0){let v=kt(b);h=ge(h._tag==="Failure"?_n(rn(h.cause,v)):v)}}}else{let b=n(r,w,E,_);if(b)h=b,x()}if(m){let b=x();if(b)d(b)}else if(p&&f.size===0)d(h??Ne)}catch(b){d(S(b))}}),f.size<l)continue;m=!0,i++;return}}if(p=!0,h){if(f&&f.size>0){let w=oo(a);f.forEach((y)=>y.interruptUnsafe(a.id,w));return}if(d||h._tag==="Failure")return h}else if(d){if(!f)return ve;else if(f.size===0)d(Ne)}};return x()}};var ta=ea({onItem(e,t,n){return e.f(t,n)},step(e,t,n,r){if(n._tag==="Failure")return n;else if(e.out)e.out[r]=n.value}});var na=(e,t,n=!1,r=!1,o=!1)=>{let s=e,i=o==="inherit"?s.interruptible:!o,c=new En(s.context,i);if(!r)s.children().add(c),c._parent=s;if(n)c.evaluate(t);else c._asyncContext=ro(),s.currentDispatcher.scheduleTask(()=>c.evaluate(t),0);return c};var Eo=(e)=>(t,n)=>{let r=new En(n?.scheduler?Or(e,kn,n.scheduler):e,n?.uninterruptible!==!0);if(r.evaluate(t),r._exit)return r;if(n?.signal)if(n.signal.aborted)r.interruptUnsafe();else{let o=()=>r.interruptUnsafe();n.signal.addEventListener("abort",o,{once:!0}),r.addObserver(()=>n.signal.removeEventListener("abort",o))}if(n?.onFiberStart)n.onFiberStart(r);return r};var vo=(e)=>{let t=Eo(e);return(n,r)=>{let o=t(n,r);return new Promise((s)=>{o.addObserver((i)=>s(i))})}};var Ao=(e)=>{let t=vo(e);return(n,r)=>t(n,r).then((o)=>{if(o._tag==="Failure")throw Ci(o.cause);return o.value})},Oo=Ao(gn());var Qr="~effect/Cause/UnknownError";class Ro extends ur("UnknownError"){[Qr]=Qr;constructor(e,t){super({message:t,cause:e})}}var ra="~effect/Logger",hu={[ra]:{_Message:he,_Output:he},pipe(){return me(this,arguments)}};var _e={bold:"1",red:"31",green:"32",yellow:"33",blue:"34",cyan:"36",white:"37",gray:"90",black:"30",bgBrightRed:"101"},xu={None:[],All:[],Trace:[_e.gray],Debug:[_e.blue],Info:[_e.green],Warn:[_e.yellow],Error:[_e.red],Fatal:[_e.bgBrightRed,_e.black]};var Co=_o;var To=lo,sa=uo,Io=le;var ia=po;var aa=yo;var Fo=ho;var ca=Oo;import{existsSync as Mo}from"fs";import{join as Lo}from"path";var la=()=>{let e=Bun.which("ast-grep");if(e!==null)return e;let t=Lo(process.cwd(),"node_modules",".bin","ast-grep");if(Mo(t))return t;let n=Lo(import.meta.dir,"..","..","node_modules",".bin","ast-grep");if(Mo(n))return n;return},pe=(e,t,n)=>{if(n.length===0)return"";let r=la();if(r===void 0)console.error(`${e}: ast-grep not found on PATH or in ./node_modules/.bin (install with: bun add -d @ast-grep/cli)`),process.exit(2);let o=Bun.spawnSync([r,"scan","--inline-rules",t,"--json=stream",...n],{stdout:"pipe",stderr:"pipe"});if(o.exitCode!==0)console.error(`${e}: ast-grep failed: ${o.stderr.toString()}`),process.exit(2);return o.stdout.toString()},ua=new Set(["id","text","path","lines"]),pa=(e)=>{let t;try{t=JSON.parse(e)}catch{return"not valid JSON"}if(typeof t!=="object"||t===null||Array.isArray(t))return"not an object";let n=t;if(typeof n.id!=="string"||n.id==="")return"id must be a non-empty string";if(typeof n.text!=="string"||n.text==="")return"text must be a non-empty string";if(n.path!==void 0&&typeof n.path!=="string")return"path must be a string";let r=n.lines;if(r!==void 0&&!(Array.isArray(r)&&r.length===2&&r.every(Number.isInteger)))return"lines must be [start, end]";let o=[];for(let[s,i]of Object.entries(n)){if(ua.has(s))continue;if(typeof i!=="string")return`context field ${s} must be a string`;o.push([s,i])}return{id:n.id,text:n.text,...typeof n.path==="string"?{path:n.path}:{},...r===void 0?{}:{lines:r},evidence:o}},fa=({evidence:e,...t})=>JSON.stringify({...t,...Object.fromEntries(e)}),W=async(e,t)=>{if(t.length>0)console.error(`${e}: unexpected arguments ${t.join(" ")}; pass file paths on stdin, one per line`),process.exit(2);return(await Bun.stdin.text()).split(`
12
+ `).filter((n)=>n!=="")},we=async(e,t)=>{let n=[];for(let[s,i]of(await Bun.stdin.text()).split(`
13
+ `).entries()){if(i.trim()==="")continue;let c=pa(i);if(typeof c==="string")console.error(`${e}: input line ${s+1} is not a valid item: ${c}`),process.exit(2);n.push(c)}let r=await ca(aa(t(n)));if(r._tag==="Failure")console.error(`${e}: ${r.failure.message}`),process.exit(2);if(r.success.length===0)return;let o=`${r.success.map(fa).join(`
14
+ `)}
15
+ `;await new Promise((s)=>process.stdout.write(o,()=>s()))};var da=86400000,No=(e)=>new Date(e).toISOString().slice(0,10),ma=(e,[t,n],r)=>To(()=>Bun.$`git blame --porcelain -L ${t},${n} -- ${e}`.quiet().nothrow()).pipe(Fo((o)=>{let s=o.stdout.toString();if(o.exitCode!==0||/^0{40} /m.test(s))return;let i=[...s.matchAll(/^committer-time (\d+)$/gm)].map((l)=>Number(l[1])*1000);if(i.length===0)return;let c=No(Math.max(...i));return`${c}, ${Math.round((Date.parse(r)-Date.parse(c))/da)} days before ${r}`})),Po=async(e)=>{if(e.length>1)console.error(`blame: unexpected arguments ${e.slice(1).join(" ")}`),process.exit(2);let t=e[0]??No(Date.now());if(Number.isNaN(Date.parse(t)))console.error(`blame: pass the date ages are counted to, YYYY-MM-DD (got ${JSON.stringify(t)})`),process.exit(2);await we("blame",(n)=>Co(n,(r)=>r.path===void 0||r.lines===void 0?Io(r):ma(r.path,r.lines,t).pipe(Fo((o)=>o===void 0?r:{...r,evidence:[...r.evidence,["changed",o]]})),{concurrency:8}))};var jo=/^\s*(?:\/\/|#|\/\*|\*)/,ha=8,Do=async(e)=>{let t=await W("comments",e),n=[];for(let r of t){let s=(await Bun.file(r).text()).split(`
16
+ `),i=0;while(i<s.length){if(!jo.test(s[i])){i++;continue}let c=i;while(i<s.length&&jo.test(s[i]))i++;let l=i-1,p=[],a=0;for(let S=i;S<s.length&&p.length<ha;S++){let x=s[S];if(x.trim()===""&&a>=3)break;if(p.push(x),x.trim()!=="")a++}let f=i<s.length?i:l,d=s.slice(c,l+1).join(`
17
+ `),h=i<s.length?s[i]:"",u=h===""?d:`${d}
18
+ ${h}`;n.push(JSON.stringify({id:`${r}:${c+1}`,path:r,lines:[c+1,f+1],...p.length>1?{"following code":p.join(`
19
+ `)}:{},text:u}))}}if(n.length>0)await new Promise((r)=>process.stdout.write(`${n.join(`
20
+ `)}
21
+ `,()=>r()))};var Mn=(e)=>e.endsWith(".go")?"go":e.endsWith(".py")?"py":/\.[cm]?[jt]sx?$/.test(e)?"ts":void 0,Ue=(e,t)=>{let n=e.split(`
22
+ `),r=[],o=[],s=[{kind:"code",braces:0}],i=0,c=!1,l,p="";for(let a of n){o.push(i);let f="",d=0,h=()=>s[s.length-1];while(d<a.length){let u=a[d],S=a.slice(d,d+2);if(c){if(S==="*/")c=!1,f+=" ",d+=2;else f+=" ",d++;continue}if(l!==void 0||h().kind==="template"){let m=l??"`";if(u==="\\"&&t!=="go"){f+=" ",d+=2;continue}if(m==="`"&&l===void 0&&S==="${"){s.push({kind:"code",braces:0}),f+="${",d+=2;continue}if(a.startsWith(m,d)){if(l!==void 0)l=void 0;else s.pop();f+=m,d+=m.length,p="a";continue}f+=" ",d++;continue}if(S==="//"&&t!=="py"){f+=" ".repeat(a.length-d);break}if(u==="#"&&t==="py"){f+=" ".repeat(a.length-d);break}if(S==="/*"&&t!=="py"){c=!0,f+=" ",d+=2;continue}if(t==="py"&&(a.startsWith('"""',d)||a.startsWith("'''",d))){l=a.slice(d,d+3),f+=l,d+=3;continue}if(u==='"'||u==="'"||u==="`"&&t==="go"){let m=d+1;while(m<a.length&&a[m]!==u)m+=u!=="`"&&a[m]==="\\"?2:1;if(m>=a.length&&u==="`"){l="`",f+="`"+" ".repeat(a.length-d-1);break}f+=u+" ".repeat(Math.max(0,Math.min(m,a.length)-d-1))+(m<a.length?u:""),d=m+1,p="a";continue}if(u==="`"){s.push({kind:"template"}),f+="`",d++;continue}if(u==="/"&&t==="ts"&&/^$|[(,=:[!&|?{};]$/.test(p)&&a[d+1]!=="/"){let m=d+1,w=!1;while(m<a.length&&(w||a[m]!=="/")){if(a[m]==="\\")m++;else if(a[m]==="[")w=!0;else if(a[m]==="]")w=!1;m++}if(m<a.length){f+="/"+" ".repeat(m-d-1)+"/",d=m+1,p="a";continue}}let x=h();if(u==="{"&&x.kind==="code")x.braces++;if(u==="}"&&x.kind==="code"){if(x.braces===0&&s.length>1){s.pop(),f+="}",d++;continue}x.braces--}if("([{".includes(u))i++;if(")]}".includes(u))i=Math.max(0,i-1);if(u.trim()!=="")p=/[\w$]/.test(u)?p===""||/[\w$]/.test(p)?p+u:u:u;if(/^(return|typeof|case|in|of)$/.test(p))p="(";f+=u,d++}if(l!==void 0&&l.length===1&&l!=="`")l=void 0;r.push(f)}return{lines:n,code:r,depth:o}},Fn=(e)=>e.length-e.trimStart().length,Ct=(e)=>e.trim()==="",xa=/(?:[=+\-*/%,.?:&|^<>!(\[{]|=>)\s*$/,ga=/^\s*(?:[.?:+\-*/%&|^,)\]}>]|=>|&&|\|\||as\b|in\b|instanceof\b|extends\b|implements\b)/,De=(e,t,n,r,o)=>{let{code:s,depth:i}=e,c=[],l=-1;for(let p=t;p<=n;p++){if(Ct(s[p]))continue;if(o==="py"){if(i[p]!==0||Fn(s[p])!==r){l=p;continue}if(l>=0&&s[l].trimEnd().endsWith("\\")){l=p;continue}}else{if(i[p]!==r){l=p;continue}if(/^\s*[)\]}]/.test(s[p])||ga.test(s[p])){l=p;continue}if(l>=0&&i[l]===r&&xa.test(s[l])&&!/^\s*@/.test(s[l])){l=p;continue}}if(l>=0&&c.length>0&&c[c.length-1]===l&&/^\s*@/.test(s[l])&&i[l]===i[p]){l=p;continue}c.push(p),l=p}return c.map((p,a)=>{let f=a+1<c.length?c[a+1]-1:n;while(f>p&&Ct(s[f]))f--;return{start:p,end:f}})},In=(e,t,n)=>{for(let r=t;r<=n;r++)if(!Ct(e.code[r])&&!/^\s*@/.test(e.code[r]))return r;return t},Uo=(e,t,n)=>{let r=e.depth[t];for(let o=t;o<=n;o++)if(e.code[o].includes("{")&&(e.depth[o+1]??0)>r)return{from:o+1,to:n,level:r+1};return},ya=/^(export\s+)?(?:default\s+)?(?:declare\s+)?(?:abstract\s+)?(?:async\s+)?(function\*?|class|interface|type|enum|const|let|var|namespace)\s+([A-Za-z_$][\w$]*)/,ba=/^\s*((?:(?:public|private|protected|static|readonly|abstract|override|async|declare|accessor)\s+)*)(?:(get|set)\s+)?(\*?\s*#?[A-Za-z_$][\w$]*)\s*[?!]?\s*([(<:=;]|$)/,We=(e,t)=>{let{code:n,lines:r}=e,o=[],s=r.length-1,i=(c)=>r[c].trim().slice(0,160);if(t==="ts"){let c=new Set;for(let l of n){for(let f of l.matchAll(/\bexport\s*(?:type\s*)?\{([^}]*)\}/g))for(let d of f[1].split(","))c.add(d.trim().split(/\s+/)[0]);let p=/^\s*export\s+default\s+([A-Za-z_$][\w$]*)\s*;?\s*$/.exec(l)??/^\s*module\.exports\s*=\s*([A-Za-z_$][\w$]*)/.exec(l);if(p!==null)c.add(p[1]);let a=/^\s*module\.exports\s*=\s*\{([^}]*)\}/.exec(l);if(a!==null)for(let f of a[1].split(","))c.add(f.trim().split(/[\s:]/)[0])}for(let{start:l,end:p}of De(e,0,s,0,t)){let a=In(e,l,p),f=ya.exec(n[a].trim()),d=/^\s*(?:module\.)?exports\.([A-Za-z_$][\w$]*)\s*=/.exec(n[a]);if(d!==null){o.push({kind:"const",name:d[1],start:l,end:p,exported:!0,signature:i(a)});continue}if(f===null)continue;let[,h,u,S]=f;if(o.push({kind:u,name:S,start:l,end:p,exported:h!==void 0||c.has(S),signature:i(a)}),u!=="class")continue;let x=Uo(e,a,p);if(x===void 0)continue;for(let m of De(e,x.from,p,x.level,t)){let w=In(e,m.start,m.end),y=ba.exec(n[w]);if(y===null)continue;let g=y[1],_=y[3].replace(/^\*\s*/,"");if(_==="constructor"){o.push({kind:"constructor",name:_,start:m.start,end:m.end,exported:!0,owner:S,signature:i(w)});continue}let E=y[4]==="("||y[4]==="<"||y[2]!==void 0;o.push({kind:y[2]!==void 0?`${y[2]}ter`:E?"method":"property",name:_,start:m.start,end:m.end,exported:!/\b(private|protected)\b/.test(g)&&!_.startsWith("#"),owner:S,signature:i(w)})}}}else if(t==="go"){let c=(l)=>/^[A-Z]/.test(l);for(let{start:l,end:p}of De(e,0,s,0,t)){let a=n[l],f=/^func\s*\(\s*(?:\w+\s+)?\*?\s*(\w+)(?:\[[^\]]*\])?\s*\)\s*(\w+)/.exec(a);if(f!==null){o.push({kind:"method",name:f[2],start:l,end:p,exported:c(f[2]),owner:f[1],signature:i(l)});continue}if(f=/^func\s+(\w+)/.exec(a),f!==null){o.push({kind:"function",name:f[1],start:l,end:p,exported:c(f[1]),signature:i(l)});continue}let d=/^(type|var|const)\s*\(/.exec(a),h=d!==null?De(e,l+1,p,1,t).map((u)=>({...u,kind:d[1],text:n[u.start].trim()})):/^(type|var|const)\s+/.test(a)?[{start:l,end:p,kind:/^(\w+)/.exec(a)[1],text:a.replace(/^(type|var|const)\s+/,"")}]:[];for(let u of h){let S=/^(\w+(?:\s*,\s*\w+)*)/.exec(u.text);if(S===null)continue;let x=u.kind==="type"&&/^\w+(?:\[[^\]]*\])?\s+struct\s*\{/.test(u.text);for(let y of S[1].split(/\s*,\s*/))o.push({kind:x?"struct":u.kind==="type"&&/^\w+\s+interface\b/.test(u.text)?"interface":u.kind,name:y,start:u.start,end:u.end,exported:c(y),signature:i(u.start)});if(!x)continue;let m=Uo(e,u.start,u.end);if(m===void 0)continue;let w=S[1];for(let y of De(e,m.from,u.end,m.level,t)){let g=n[y.start].trim();if(g.startsWith("}"))continue;let _=/^(\w+(?:\s*,\s*\w+)*)\s+\S/.exec(g),E=/^\*?(?:\w+\.)?(\w+)\s*$/.exec(g);for(let b of _!==null?_[1].split(/\s*,\s*/):E!==null?[E[1]]:[])o.push({kind:"field",name:b,start:y.start,end:y.end,exported:c(b),owner:w,signature:i(y.start)})}}}}else{let c,l=/^__all__\s*(?::[^=]*)?=\s*[[(]([\s\S]*?)[\])]/m.exec(r.join(`
23
+ `));if(l!==null)c=new Set([...l[1].matchAll(/["'](\w+)["']/g)].map((d)=>d[1]));let p=(d)=>!d.startsWith("_")&&(c===void 0||c.has(d)),a=(d,h)=>{let u=d+1;while(u<=h&&(Ct(n[u])||e.depth[u]>0))u++;return u},f=(d,h,u,S,x)=>{for(let{start:m,end:w}of De(e,d,h,u,t)){let y=In(e,m,w),g=n[y].trim(),_=r.slice(m,y).map((b)=>b.trim()).join(" "),E=/^(?:async\s+)?def\s+(\w+)/.exec(g);if(E!==null){let b=E[1],v=S===void 0?"function":/@(\w+\.)?(property|cached_property)\b/.test(_)?"property":"method";if(!x)o.push({kind:v,name:b,start:m,end:w,exported:S===void 0?p(b):!b.startsWith("_"),owner:S,signature:i(y)});let O=a(y,w);if(O<=w)f(O,w,Fn(n[O]),void 0,!0);continue}if(E=/^class\s+(\w+)/.exec(g),E!==null){let b=E[1],v=!x&&(S===void 0?p(b):!b.startsWith("_"));o.push({kind:"class",name:b,start:m,end:w,exported:v,owner:x?void 0:S,signature:i(y)});let O=a(y,w);if(O<=w)f(O,w,Fn(n[O]),b,!1);continue}if(x)continue;if(E=/^(\w+)\s*(?::[^=]+)?=(?!=)/.exec(g)??/^(\w+)\s*:\s*\S[^=]*$/.exec(g),E!==null){let b=E[1];o.push({kind:S===void 0?"variable":"attribute",name:b,start:m,end:w,exported:S===void 0?p(b):!b.startsWith("_"),owner:S,signature:i(y)})}}};f(0,s,0,void 0,!1)}return o},Ln=(e)=>new RegExp(`(?<![\\w$])${e.replace(/[$]/g,"\\$")}(?![\\w$])`,"g"),Wo=(e,t,n,r,o)=>{let s=o?new RegExp(`\\.${t.replace(/[$]/g,"\\$")}(?![\\w$])`):new RegExp(Ln(t).source),i=[];for(let c=0;c<e.code.length;c++){if(c>=n&&c<=r)continue;if(s.test(e.code[c]))i.push(c)}return i},Bo=(e,t)=>{let n;for(let r of e)if(r.start<=t&&t<=r.end&&(n===void 0||r.end-r.start<n.end-n.start))n=r;return n},fe=(e,t,n,r=Number.POSITIVE_INFINITY)=>{let o=e.slice(t,Math.min(n,t+r-1)+1).map((s,i)=>`${t+i+1}: ${s}`);if(n-t+1>r)o.push(`\u2026 (${n-t+1-r} more lines)`);return o.join(`
24
+ `)},Be=async(e,t=Bun.argv.slice(2))=>{let n=[];for(let r of await W("module",t)){let o=Mn(r);if(o===void 0)continue;let s=await Bun.file(r).text();if(s.trim()==="")continue;for(let i of e(r,s,o))n.push(JSON.stringify(i))}if(n.length>0)await new Promise((r)=>process.stdout.write(`${n.join(`
25
+ `)}
26
+ `,()=>r()))};var wa=1000,lt=4,$a=6,ka=30,Sa=(e)=>{let t=(o)=>o>0&&e[o-1].trim()===""&&e[o].trim()!=="",n=(o)=>t(o)&&!/^[\s})\]]/.test(e[o]),r=[];for(let o=0;o<e.length;){let s=o,i=0;while(s<e.length&&i+Buffer.byteLength(e[s])+1<=wa)i+=Buffer.byteLength(e[s])+1,s++;if(s<e.length){let c=(p)=>{for(let a=s;a>o;a--)if(p(a))return a;return-1};s=[c(n),c(t)].find((p)=>p>o)??Math.max(s,o+1)}r.push([o,s-1]),o=s}return r.filter(([o,s])=>e.slice(o,s+1).some((i)=>i.trim()!==""))},_a=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`[^`]*`|[A-Za-z_$][\w$]*|\d[\w.]*|[^\s\w]/g,Ea=/^(?:["'`].{0,4}["'`]|\d|10|100|0x0|0\.\d)$/,zo=(e)=>e.trim().replace(/\s+/g," "),va=(e)=>e.length<24||/^(?:import\b|from\s+\S+\s+import\b|if err != nil\b|return (?:nil, )?err\b|\} else \{$|[})\]]+[;,]?$)/.test(e),qo=async(e)=>{let t=[];for(let n of await W("duplicates",e)){let r=Mn(n),o=await Bun.file(n).text();if(o.trim()==="")continue;let s=o.replace(/\n$/,"").split(`
27
+ `),i=r==="py"?/^\s*#/:/^\s*(?:\/\/|\/\*|\*)/,c=[];for(let[d,h]of s.entries()){if(i.test(h))continue;for(let u of h.matchAll(_a))c.push({text:u[0],line:d})}let l=new Map;for(let d=0;d+lt<=c.length;d++){let h=c.slice(d,d+lt).map((S)=>S.text).join("\x00"),u=l.get(h);if(u===void 0)l.set(h,u=[]);u.push(d)}let p=new Map;for(let{text:d,line:h}of c){if(!/^["'`\d]/.test(d)||Ea.test(d))continue;let u=p.get(d)??[];if(u[u.length-1]!==h)u.push(h);p.set(d,u)}let a=new Map;for(let[d,h]of s.entries()){let u=zo(h);if(va(u)||i.test(h))continue;a.set(u,[...a.get(u)??[],d])}for(let[d,h]of a)if(h.length<2)a.delete(d);let f=0;for(let[d,h]of Sa(s)){while(f<c.length&&c[f].line<d)f++;let u=new Map,S=0;for(let g=f;g+lt<=c.length&&c[g].line<=h;g++){if(c[g+lt-1].line>h)break;S++;let _=c.slice(g,g+lt).map((b)=>b.text).join("\x00"),E=l.get(_);if(E.length>$a)continue;for(let b of E){let v=c[b].line;if(v>=d&&v<=h)continue;let O=u.get(v);if(O===void 0)u.set(v,O=new Set);O.add(g)}}let x=[];for(let g of[...u.keys()].sort((_,E)=>_-E)){let _=x[x.length-1];if(_!==void 0&&g-_.to<=4){_.to=g;for(let E of u.get(g))_.shared.add(E)}else x.push({from:g,to:g,shared:new Set(u.get(g))})}let m=x.map((g)=>({...g,share:S===0?0:g.shared.size/S})).filter((g)=>g.shared.size>=6&&g.share>=0.1).sort((g,_)=>_.shared.size-g.shared.size).slice(0,2),w=m.length===0?"No code outside this excerpt shares more than a few token sequences with it.":m.map((g)=>`Lines ${g.from+1}-${g.to+1} share ${Math.round(g.share*100)}% of this excerpt's 4-token sequences:
28
+ ${fe(s,g.from,g.to,ka)}`).join(`
29
+
30
+ `),y=[];for(let g=d;g<=h;g++){let _=a.get(zo(s[g]));if(_===void 0)continue;let E=_.filter((b)=>b<d||b>h);if(E.length===0||_.find((b)=>b>=d&&b<=h)!==g)continue;y.push(`line ${g+1} \`${s[g].trim().slice(0,100)}\` also on line ${E.slice(0,5).map((b)=>b+1).join(", ")}${E.length>5?", \u2026":""}`)}for(let[g,_]of p){let E=_.filter((v)=>v>=d&&v<=h),b=_.filter((v)=>v<d||v>h);if(E.length===0||b.length===0)continue;y.push(`literal ${g.slice(0,80)} (line ${E.map((v)=>v+1).join(", ")}) also on line ${b.slice(0,5).map((v)=>v+1).join(", ")}${b.length>5?", \u2026":""}`)}t.push(JSON.stringify({id:`${n}:${d+1}-${h+1}`,path:n,lines:[d+1,h+1],similar:w,"repeated elsewhere":y.slice(0,10).join(`
31
+ `),text:fe(s,d,h)}))}}if(t.length>0)await new Promise((n)=>process.stdout.write(`${t.join(`
32
+ `)}
33
+ `,()=>n()))};var Tt=(e)=>e.length-e.trimStart().length,Ho=(e,t,n)=>e.slice(t-1,n).map((r,o)=>`${t+o}: ${r}`).join(`
34
+ `),Aa=/\b(function|def|func|class)\b|=>\s*\{?\s*$|\)\s*(:\s*[^=]+)?\{\s*$|:\s*$/,Jo=80,Oa=(e,[t,n])=>{let r=Tt(e[t-1]??"");for(let s=t-1;s>=1;s--){let i=e[s-1];if(i.trim()===""||Tt(i)>=r||!Aa.test(i))continue;let c=n;for(let a=n+1;a<=e.length;a++){let f=e[a-1];if(f.trim()==="")continue;if(Tt(f)<=Tt(i)){c=/^\s*[}\])]/.test(f)?a:a-1;break}c=a}let l=Math.max(s,Math.min(t-30,c-Jo+1)),p=Math.min(c,l+Jo-1);return`lines ${l}-${p}:
35
+ ${Ho(e,l,p)}`}let o=Math.min(e.length,n+15);return`no enclosing block; lines ${n+1}-${o} follow:
36
+ ${Ho(e,n+1,o)}`},Vo=async(e)=>{if(e.length>0)console.error(`enclosing: unexpected arguments ${e.join(" ")}`),process.exit(2);let t=new Map;await we("enclosing",(n)=>Co(n,(r)=>ia(function*(){if(r.path===void 0||r.lines===void 0)return r;let o=r.path;if(!t.has(o)){let s=yield*sa({try:()=>Bun.file(o).text(),catch:()=>Error(`cannot read ${o}`)});t.set(o,s.split(`
37
+ `))}return{...r,evidence:[...r.evidence,["enclosing",Oa(t.get(o),r.lines)]]}})))};var Ra=`
38
+ id: dropped
39
+ language: go
40
+ rule:
41
+ any:
42
+ - kind: expression_statement
43
+ has: { kind: call_expression, stopBy: neighbor }
44
+ - kind: defer_statement
45
+ - kind: go_statement
46
+ - any: [ { kind: assignment_statement }, { kind: short_var_declaration }, { kind: var_spec } ]
47
+ all:
48
+ - has: { has: { kind: identifier, regex: "^_$" }, stopBy: neighbor }
49
+ - has: { kind: expression_list, stopBy: neighbor, has: { kind: call_expression, stopBy: neighbor } }
50
+ `,Ca=[/^fmt\.(Print|Printf|Println|Fprint|Fprintf|Fprintln)\(/,/^(panic|close|delete|print|println|clear|copy|recover)\(/,/^(t|b|tb|f)\.(Helper|Parallel|Fatal|Fatalf|Error|Errorf|Log|Logf|Skip|Skipf|SkipNow|Fail|FailNow|Cleanup|Setenv|Chdir|Run)\(/,/^[\w.]+\.(Lock|Unlock|RLock|RUnlock|Done)\(\)$/,/^(cancel|wg\.Add)\b/,/^(assert|require)\.\w+\(/],Ta=4,Nn=new Map,Ia=async(e)=>{if(!Nn.has(e))Nn.set(e,(await Bun.file(e).text()).split(`
51
+ `));return Nn.get(e)},Fa=(e)=>/^(?:defer|go) (.*)$/.exec(e)?.[1]??/^(?:var )?[^=(]*?:?= (.*)$/.exec(e)?.[1]??e,Ma=(e,t)=>{let n=0;for(let r=t;r<e.length;r++){if(e[r]==="(")n++;if(e[r]===")"&&--n===0)return e.slice(r+1).replace(/\{\s*$/,"").trim()}return},La=(e,t,n)=>{let r=new RegExp(n?`^func \\([^)]*\\) ${t}(?:\\[[^\\]]*\\])?\\(`:`^func ${t}(?:\\[[^\\]]*\\])?\\(|^\\s*${t}\\s*:?=\\s*func\\s*\\(`),o=e.flatMap((f,d)=>r.test(f)?[d]:[]);if(o.length!==1)return"";let s=o[0],i=[];for(let f=s;f<e.length&&i.length<8;f++)if(i.push(e[f].trim()),/\{\s*$/.test(e[f]))break;let c=i.join(" "),l=r.exec(c),p=l===null?void 0:Ma(c,l.index+l[0].length-1);if(p===void 0)return"";let a=/\berror\b/.test(p)?"its results include an error":"it returns no error";return`line ${s+1}: \`${c.replace(/\s*\{\s*$/,"")}\` (${a})`},Na=(e)=>{let t=/^(?:var )?(.*?)\s*:?=\s/.exec(e)?.[1];if(t===void 0||!/^[\w.,\s[\]*]+$/.test(t)||/^(defer|go)\b/.test(e))return"";let n=t.split(",").map((i)=>i.trim()),r=n.flatMap((i,c)=>i==="_"?[c+1]:[]);if(r.length===0)return"";let o=n[n.length-1];if(/^[A-Za-z]*[Ee]rr\w*$/.test(o))return;let s=`\`_\` takes result ${r.join(" and ")} of ${n.length}`;return o==="_"?`${s}, including the last (where a Go function returns its error, if it has one)`:`${s}; the last result goes to \`${o}\``},Pa=(e)=>{if(/\bos\.Open\(/.test(e))return" (os.Open opens a file only for reading)";if(/\bos\.Create\(/.test(e))return" (os.Create opens a file for writing)";if(/\bos\.OpenFile\(/.test(e)){if(/O_(WRONLY|RDWR|APPEND|CREATE|TRUNC)/.test(e))return" (os.OpenFile with write flags opens a file for writing)";return/O_RDONLY/.test(e)?" (os.OpenFile with O_RDONLY opens a file only for reading)":""}return""},ja=(e,t,n)=>{let r=new RegExp(`(?:^|[\\s,(])${n}(?:\\s*,\\s*[\\w.]+)*\\s*:?=[^=]|\\bvar ${n}\\b`);for(let o=t-1;o>=1;o--){let s=e[o-1];if(r.test(s))return`\`${n}\` set at line ${o}: ${s.trim()}${Pa(s)}`;if(/^func /.test(s))break}return""},Ko=async(e)=>{let t=await W("errors-go",e),n=[];if(t.length>0){let r=pe("errors-go",Ra,t),o=new Set;for(let s of r.split(`
52
+ `)){if(s.trim()==="")continue;let i=JSON.parse(s),c=i.text.replace(/\s+/g," ").trim(),l=Fa(c);if(/^func\s*\(/.test(l))continue;if(Ca.some((m)=>m.test(l)))continue;let p=Na(c);if(p===void 0)continue;let a=await Ia(i.file),f=i.range.start.line+1,d=Math.min(i.range.end.line+1,f+Ta-1),h=`${i.file}:${f}`;if(o.has(h))continue;o.add(h);let u=a.slice(f-1,d).join(`
53
+ `)+(d<i.range.end.line+1?`
54
+ \u2026`:""),S=/^([\w.]*?)(\w+)\s*(?:\[[^\]]*\])?\(/.exec(l.replace(/\([^()]*\)\./g,".")),x=S?.[1]?.split(".")[0]??"";n.push(JSON.stringify({id:h,path:i.file,lines:[f,d],text:u,declared:S?La(a,S[2],S[1]!==""):"",blank:p,receiver:x===""?"":ja(a,f,x)}))}}if(n.length>0)await new Promise((r)=>process.stdout.write(`${n.join(`
55
+ `)}
56
+ `,()=>r()))};var Xo="^(catch|catchAll|catchTag|catchTags|catchAllCause|catchError|mapError|orElse|tapError)$",Pn=(e)=>`
57
+ id: handler
58
+ language: ${e}
59
+ rule:
60
+ any:
61
+ - kind: catch_clause
62
+ - kind: call_expression
63
+ has: { field: function, kind: member_expression, has: { field: property, regex: "${Xo}" } }
64
+ ---
65
+ id: try
66
+ language: ${e}
67
+ rule: { kind: try_statement }
68
+ `,Da=[Pn("typescript"),Pn("tsx"),Pn("javascript"),`
69
+ id: handler
70
+ language: python
71
+ rule:
72
+ any:
73
+ - kind: except_clause
74
+ - kind: with_statement
75
+ has: { kind: with_clause, regex: "\\\\bsuppress\\\\(" }
76
+ ---
77
+ id: try
78
+ language: python
79
+ rule: { kind: try_statement }
80
+ `,`
81
+ id: handler
82
+ language: go
83
+ rule:
84
+ any:
85
+ - kind: if_statement
86
+ any:
87
+ - has: { field: condition, regex: "(?i)err" }
88
+ - has: { field: initializer, regex: "(?i)err|recover\\\\(\\\\)" }
89
+ - kind: expression_case
90
+ has: { field: value, regex: "(?i)err" }
91
+ - kind: return_statement
92
+ regex: "(?i)err\\\\w*\\\\s*[!=]=\\\\s*nil"
93
+ ---
94
+ id: construct
95
+ language: go
96
+ rule:
97
+ kind: call_expression
98
+ has: { field: function, regex: "^(fmt\\\\.Errorf|errors\\\\.(New|Wrap|Wrapf)|log\\\\.(Fatal|Fatalf|Fatalln|Panic|Panicf))$" }
99
+ `].join(`
100
+ ---
101
+ `),jn=25,It=12,Ua=/\b(function|def|func)\b|=>\s*\{?\s*$|^\s*(async\s+)?(static\s+)?(public\s+|private\s+|protected\s+)?\*?\w+\s*\([^)]*\)\s*(:\s*[^={]+)?\{\s*$/,ze=(e)=>e.length-e.trimStart().length,Wa=/^\s*if [^{]*\{\s*\n\s*return\s+(?:(?:nil|""|0|false|\w+\{\}|\w+),\s*)*err\s*\n\s*\}\s*$/,Un=(e,t,n)=>e.slice(t-1,n).map((r,o)=>`${t+o}: ${r}`).join(`
102
+ `),Zo=(e,t,n,r)=>n-t+1>r?`${Un(e,t,t+r-1)}
103
+ \u2026`:Un(e,t,n),Ba=(e,t)=>{let n=ze(e[t-1]??"");for(let r=t-1;r>=1;r--){let o=e[r-1];if(o.trim()!==""&&ze(o)<n&&Ua.test(o))return`${r}: ${o.trim()}`}return""},za=(e,t)=>{let n=t-1;while(n>1&&t-n<It){let r=e[n-2];if(r.trim()===""||/[{}]\s*$/.test(r)||ze(r)<ze(e[t-1]))break;n--}return n>=1&&n<t&&e[n-1].trim()!==""?Un(e,n,t-1):""},ut=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`[^`]*`/g,Go=(e,t)=>new RegExp(`(?<![\\w.])${t}\\b`).test(e.replace(ut,"")),qa=/\b(console|log|logger|logging|klog|slog|zap|zerolog|print)\w*\s*[.(]|\.(Error|Errorf|Warn|Warnf|Warning|Info|Infof|Debug|Debugf|Msg|Msgf|Print|Printf|Println|error|warn|warning|info|debug|exception|critical)\(/,Yo=(e,t,n)=>{let r="",o=0;for(let s=t;s<=Math.min(n,t+4);s++){let i=e[s-1].replace(ut,'""');if(r+=`${e[s-1].trim()} `,o+=(i.match(/\(/g)??[]).length-(i.match(/\)/g)??[]).length,o<=0)break}return r},Ha=(e,t)=>{if(t==="py")return/\bexcept\b.*\bas\s+(\w+)/.exec(e)?.[1];if(t==="js")return/\bcatch\s*\(\s*(\w+)/.exec(e)?.[1]??/\.\w+\(\s*(?:async\s+)?\(?\s*(\w+)\s*(?:[:,)]|=>)/.exec(e)?.[1];return/(?<![\w.])([A-Za-z]*[Ee]rr\w*)\b/.exec(e.replace(ut,"").replace(/\berrors\./g,""))?.[1]},Ja=(e,t,n,r)=>{let o=r==="go"?e[t-1]:Yo(e,t,n),s=Ha(o,r),i=[];if(s===void 0){if(r!=="go"&&!/\braise\s*$/m.test(e.slice(t-1,n).join(`
104
+ `)))i.push(r==="py"?"The clause binds no name for the exception.":"The handler binds no name for the error.")}else{let l=e.slice(t,n).join(`
105
+ `);if(!Go(l,s))i.push(`\`${s}\` is not used in the handler's body.`)}let c=s===void 0?"the error":`\`${s}\``;for(let l=t;l<=n;l++){let p=e[l-1],a=p.replace(ut,'""');if(/^\s*(\/\/|#)/.test(p))continue;let f=Yo(e,l,n),d=s!==void 0&&Go(f,s);if(r==="go"&&/\bfmt\.Errorf\(/.test(a)){let h=/fmt\.Errorf\(\s*("(?:[^"\\]|\\.)*"|`[^`]*`)/.exec(f)?.[1]??"";if(/%w/.test(h))i.push(`Line ${l}: fmt.Errorf wraps an error with %w.`);else if(d&&/\.Error\(\)/.test(f))i.push(`Line ${l}: fmt.Errorf turns ${c} into a string with .Error() and has no %w, so the new error does not wrap it.`);else if(d)i.push(`Line ${l}: fmt.Errorf formats ${c} without %w, so the new error does not wrap it.`);else i.push(`Line ${l}: fmt.Errorf builds a new error without ${c}.`)}else if(r==="go"&&/\berrors\.New\(/.test(a))i.push(`Line ${l}: errors.New builds a new error${d?` from ${c}'s text, which does not wrap it`:` without ${c}`}.`);else if(r==="js"&&/\bthrow\b/.test(a))if(s!==void 0&&new RegExp(`\\bthrow\\s+${s}\\b`).test(a))i.push(`Line ${l}: rethrows ${c}.`);else if(/\bcause\b/.test(f))i.push(`Line ${l}: throws a new error with a \`cause\`.`);else i.push(`Line ${l}: throws a new error ${d?`built from ${c} but without \`cause\``:`without ${c}`}.`);else if(r==="py"&&/^\s*raise\b/.test(a))if(/^\s*raise\s*$/.test(a))i.push(`Line ${l}: re-raises the original exception.`);else if(/\bfrom\s+None\b/.test(a))i.push(`Line ${l}: raises a new exception \`from None\`, suppressing the original.`);else if(/\bfrom\s+\w+/.test(f))i.push(`Line ${l}: raises a new exception chained with \`from\`.`);else if(s!==void 0&&new RegExp(`^\\s*raise\\s+${s}\\s*$`).test(a))i.push(`Line ${l}: re-raises ${c}.`);else i.push(`Line ${l}: raises a new exception without \`from\`; Python keeps the original as its implicit context (\`__context__\`).`);else if(qa.test(a)){if(!d&&!/\.exception\(|exc_info|\.Err\(/.test(f))i.push(`Line ${l}: logs without ${c}.`)}else if(/^\s*return\b/.test(a)&&!d&&l>t)i.push(`Line ${l}: returns without ${c}.`);else if(/^\s*pass\s*$/.test(a))i.push(`Line ${l}: \`pass\` discards ${c}.`)}return i.join(`
106
+ `)},Dn=new Map,Va=async(e)=>{if(!Dn.has(e))Dn.set(e,(await Bun.file(e).text()).split(`
107
+ `));return Dn.get(e)},Qo=async(e)=>{let t=await W("errors",e),n=[];if(t.length>0){let o=pe("errors",Da,t).split(`
108
+ `).filter((a)=>a.trim()!=="").map((a)=>JSON.parse(a)).sort((a,f)=>a.file.localeCompare(f.file)||a.range.byteOffset.start-f.range.byteOffset.start||a.range.byteOffset.end-f.range.byteOffset.end||a.ruleId.localeCompare(f.ruleId)),s=(a)=>[a.range.start.line+1,a.range.end.line+1],i=o.filter((a)=>a.ruleId==="try"),c=o.filter((a)=>a.ruleId==="handler"),l=(a,f)=>a.file===f.file&&s(f)[0]<=s(a)[0]&&s(a)[1]<=s(f)[1],p=new Set;for(let a of o){if(a.ruleId==="try")continue;if(a.ruleId==="construct"&&c.some((w)=>w!==a&&l(a,w)))continue;if(a.ruleId==="construct"&&!/\b[Ee]rr\w*|\w*Err\b/.test(a.text.replace(/^[\w.]+\(/,"").replace(ut,"")))continue;if(a.file.endsWith(".go")&&a.ruleId==="handler"&&Wa.test(a.text))continue;if(/^if [^{]*\b\w*[Ee]rr\w*\s*==\s*nil\s*\{/.test(a.text)&&!/!=/.test(a.text.split("{")[0])&&!/\}\s*else\b/.test(a.text))continue;let f=await Va(a.file),[d,h]=s(a),u="";if(/^(catch|except)\b/.test(a.text)){let w=i.filter((y)=>l(a,y)).sort((y,g)=>s(g)[0]-s(y)[0])[0];if(w!==void 0){let y=Math.min(...c.filter((g)=>l(g,w)&&/^(catch|except)\b/.test(g.text)&&ze(f[s(g)[0]-1])<=ze(f[s(a)[0]-1])).map((g)=>s(g)[0]));u=Zo(f,s(w)[0],y-1,It)}}else if(a.file.endsWith(".go")){if(a.ruleId==="handler"&&!/^if [^{]*;/.test(a.text))u=za(f,d)}else if(!a.text.startsWith("with")){let w=f.findIndex((y,g)=>g+1>=d&&g+1<=h&&new RegExp(`\\.(${Xo.slice(2,-2)})\\b`).test(y));if(w!==-1&&w+1>d)u=Zo(f,Math.max(d,w+1-It),w,It),d=w+1}let S=`${a.file}:${d}`;if(p.has(S))continue;p.add(S);let x=h-d+1>jn?`${f.slice(d-1,d-1+jn).join(`
109
+ `)}
110
+ \u2026`:f.slice(d-1,h).join(`
111
+ `);h=Math.min(h,d+jn-1);let m=a.file.endsWith(".go")?"go":a.file.endsWith(".py")?"py":"js";n.push(JSON.stringify({id:S,path:a.file,lines:[d,h],text:x,handles:u,function:Ba(f,d),facts:Ja(f,d,h,m)}))}}if(n.length>0)await new Promise((r)=>process.stdout.write(`${n.join(`
112
+ `)}
113
+ `,()=>r()))};var Ka=(e,t)=>{let n=e.split(`
114
+ `);if(Buffer.byteLength(e)<=t)return[{start:1,end:n.length,text:e}];let r=(i)=>i>0&&n[i-1].trim()===""&&n[i].trim()!=="",o=(i)=>r(i)&&!/^[\s})\]]/.test(n[i]),s=[];for(let i=0;i<n.length;){let c=i,l=0;while(c<n.length&&l+Buffer.byteLength(n[c])+1<=t)l+=Buffer.byteLength(n[c])+1,c++;if(c<n.length){let p=(f)=>{for(let d=c;d>i;d--)if(f(d))return d;return-1};c=[p(o),p(r)].find((f)=>f>i)??Math.max(c,i+1)}s.push({start:i+1,end:c,text:n.slice(i,c).join(`
115
+ `)}),i=c}return s},es=async(e)=>{let[t,...n]=e,r=Number(t??"1000");if(!Number.isInteger(r)||r<1)console.error("excerpts: first argument must be the excerpt size in bytes (default: 1000)"),process.exit(2);let o=await W("excerpts",n),s=[];for(let i of o){let c=await Bun.file(i).text(),l=c.split(`
116
+ `).length;for(let{start:p,end:a,text:f}of Ka(c,r)){if(f==="")continue;let d=p===1&&a===l?i:`${i} (lines ${p}-${a} of ${l})`;s.push(JSON.stringify({id:`${i}:${p}`,path:i,lines:[p,a],text:`path: ${d}
117
+
118
+ file:
119
+ ${f}`}))}}if(s.length>0)await new Promise((i)=>process.stdout.write(`${s.join(`
120
+ `)}
121
+ `,()=>i()))};var ts=new Map,Za=async(e)=>{let t=await Bun.file(e).text().catch(()=>"");if(t==="")return"";let n=e.toLowerCase(),r=t.split(`
122
+ `),o=[];if(/(?:^|\/)(?:tests?|__tests__|spec)\/|(?:\.|_)(?:test|spec)\.[a-z]+$|^test_/.test(n))o.push("test file");if(/(?:^|\/)(?:cmd|cli|bin|main|app|server|setup|bootstrap|wiring|di|container|factory|provider|client)(?:[_./-]|$)/.test(n))o.push("entry/wiring/factory path");if(/(?:^|\/)(?:utils?|helpers?|common|shared|lib|tools|misc)(?:[_./-]|$)/.test(n))o.push("utility/toolbox path");if(/(?:^|\/)(?:types?|models?|schemas?|dto|config|options?|constants?|errors?)(?:[_./-]|$)/.test(n))o.push("types/DTO/config path");let s=r.filter((l)=>/^(?:export\s+(?:default\s+)?(?:async\s+)?(?:function|class|const|let|type|interface|enum)\b|func\s+(?:\([^)]+\)\s+)?[A-Z]|type\s+[A-Z]|var\s+[A-Z]|const\s+[A-Z]|def\s+[a-zA-Z]|class\s+[a-zA-Z])/.test(l)).length,i=r.length;return[`${e} (${i} lines, ~${s} top-level decls)`,...o.length>0?[`role hints: ${o.join(", ")}`]:[]].join("; ")},Ga=(e)=>{let t=ts.get(e);if(t===void 0)t=Za(e),ts.set(e,t);return t},ns=async(e)=>{if(e.length>0)console.error(`file-role: unexpected arguments ${e.join(" ")}`),process.exit(2);await we("file-role",(t)=>To(async()=>Promise.all(t.map(async(n)=>{if(n.path===void 0)return n;let r=await Ga(n.path);if(r==="")return n;return{...n,evidence:[["file role",r],...n.evidence]}}))))};var rs=(e)=>/\.(ts|tsx|js|jsx|mjs|cjs)$/.test(e)?"ts":e.endsWith(".py")?"py":e.endsWith(".go")?"go":void 0,pt=(e,t,n)=>`id: ${e}
123
+ language: ${t}
124
+ rule:
125
+ any: [${n.map((r)=>`{kind: ${r}}`).join(", ")}]`,Ya=["function_declaration","generator_function_declaration","method_definition","arrow_function","function_expression"],os=["class_declaration","class"],Xa=[...["typescript","tsx","javascript"].flatMap((e)=>[pt("function",e,Ya),pt("class",e,e==="javascript"?os:[...os,"abstract_class_declaration"])]),pt("function","python",["function_definition"]),pt("class","python",["class_definition"]),pt("function","go",["function_declaration","method_declaration","func_literal"])].join(`
126
+ ---
127
+ `),Qa=/^\s*(?:describe|suite|context|test\.describe|describe\.\w+)\s*\(/,ec=/^func\s*(?:\([^)]*\)\s*)?(\w+)\s*[([]/,ps=/^func\s*\([^)]*\)\s*\w+\s*[([]/,tc=(e,t,n)=>{if(e==="py")return/def\s+(\w+)/.exec(t)?.[1];if(e==="go")return ec.exec(t)?.[1]??/(\w+)\s*:?=\s*$/.exec(n.trimEnd())?.[1];let r=/^(?:export\s+)?(?:default\s+)?(?:async\s+)?function\s*\*?\s*([\w$]+)/.exec(t)?.[1];if(r!==void 0)return r;if(!/^(?:async\s*)?(?:function\b|\(|[\w$]+\s*=>|<)/.test(t))return/^(?:(?:public|private|protected|static|async|readonly|override|abstract|get|set|declare)\s+|\*\s*)*([\w$#]+|\[[^\]]*\])/.exec(t)?.[1];let o=/(?:(?:const|let|var)\s+([\w$]+)\s*(?::[^=]*)?=|([\w$#]+)\s*[:=]|([\w$]+)\s*\??:\s*[^=]*=)\s*(?:async\s*)?$/.exec(n.trimEnd());return o?.[1]??o?.[2]??o?.[3]},ss=(e,t)=>{let n=0;for(let r=t;r<e.length;r++){let o=e[r];if(o==="("||o==="["||o==="{")n++;if(o===")"||o==="]"||o==="}"){if(n--,n===0)return{inner:e.slice(t+1,r),close:r}}}return{inner:e.slice(t+1),close:e.length}},qe=(e)=>{let t=[],n=0,r=0;for(let o=0;o<e.length;o++){let s=e[o];if("([{<".includes(s))n++;if(")]}>".includes(s)&&e[o-1]!=="=")n--;if(s===","&&n===0)t.push(e.slice(r,o)),r=o+1}return t.push(e.slice(r)),t.map((o)=>o.trim()).filter((o)=>o!=="")},is=(e,t)=>{let n=t.indexOf("(");if(n===-1)return[];if(e==="go"&&ps.test(t))n=t.indexOf("(",ss(t,n).close);if(n===-1)return[];let r=qe(ss(t,n).inner),o=[];if(e==="go"){let i=[];for(let c of r){let[l,...p]=c.split(/\s+/);if(p.length===0){i.push(l);continue}if(p.join(" ")==="bool")o.push(...[...i,l].map((a)=>`${a} (positional)`));i=[]}return o}let s=!1;for(let i of r){if(e==="py"&&/^\*\w*$/.test(i))s=!0;if(e==="py"&&/^\*\*/.test(i))continue;let c=e==="py"?/^(\w+)\s*:\s*(?:bool|Optional\[bool\]|bool\s*\|\s*None)\s*(?:=|$)/:/^([\w$]+)\??\s*:\s*boolean\b(?:\s*\|\s*(?:undefined|null))?\s*(?:=|$)/,l=e==="py"?/^(\w+)\s*(?::[^=]*)?=\s*(?:True|False)$/:/^([\w$]+)\??\s*(?::[^=]*)?=\s*(?:true|false)$/,p=c.exec(i)?.[1]??l.exec(i)?.[1];if(p!==void 0)o.push(`${p} (${s?"keyword-only":"positional"})`)}return o},Wn=(e,t)=>{let n=t.trim();if(n===""||/^[)\]};,]+;?$/.test(n))return!0;if(/^(\/\/|\/\*|\*|#)/.test(n))return!0;if(e==="ts")return/^(import\b|export\s+(\*|\{[^}]*\})\s+from\b|["']use (strict|client|server)["'])/.test(n);if(e==="py")return/^(import\s|from\s+\S+\s+import\b|"""|''')/.test(n);return/^(package\s|import\s|"[^"]*"$|\w+\s+"[^"]*"$)/.test(n)},nc=(e,t,n)=>{let r=new Map,o=!1;for(let[s,i]of t.entries()){if(n[s])continue;let c=[];if(e==="ts"){let l=/^(?:export\s+)?(?:declare\s+)?(?:let|var|const)\s+([\w$]+)/.exec(i);if(l!==null)c=[l[1]]}else if(e==="py"){let l=/^([A-Za-z_]\w*)\s*(?::[^=]+)?=(?!=)/.exec(i);if(l!==null)c=[l[1]]}else if(/^var\s*\($/.test(i))o=!0;else if(o&&/^\)/.test(i))o=!1;else if(o)c=/^\t(\w+(?:\s*,\s*\w+)*)\b/.exec(i)?.[1]?.split(/\s*,\s*/)??[];else c=/^var\s+(\w+(?:\s*,\s*\w+)*)/.exec(i)?.[1]?.split(/\s*,\s*/)??[];for(let l of c)if(l!=="_"&&!r.has(l))r.set(l,s+1)}return r},rc=[["clock",/\b(?:time\.(?:Now|Since|Until|time|monotonic)\(|Date\.now\(|new Date\(\s*\)|datetime\.(?:now|utcnow|today)\(|date\.today\(|performance\.now\()/],["random",/\b(?:Math\.random\(|crypto\.(?:randomUUID|getRandomValues|randomBytes)\(|rand\.[A-Z]\w*\(|random\.\w+\(|uuid\.(?:uuid4|New|NewString|v4)\(|uuidv4\(|secrets\.\w+\()/],["environment",/(?:process\.env\b|\bos\.(?:Getenv|LookupEnv|environ|getenv)\b|\benvknob\.\w+|import\.meta\.env\b|\bBun\.env\b|\bDeno\.env\b)/],["filesystem",/\b(?:fs\.\w+|readFileSync|writeFileSync|os\.(?:ReadFile|WriteFile|Open|OpenFile|Create|Remove|RemoveAll|Rename|MkdirAll|Stat|ReadDir)\(|ioutil\.\w+\(|Path\([^)]*\)\.(?:read|write)_\w+\()|(?<![\w.])open\(/],["constructs a collaborator",/(?:\bnew\s+[A-Z]\w*(?:Client|Store|Service|Session|Repository|Repo|Connection|Pool|Logger|Dialer|Transport|Server|Database|Cache|Queue|Producer|Consumer|Agent)\b|\bboto3\.(?:client|resource|Session)\(|\b(?:requests|httpx)\.(?:get|post|put|patch|delete|request|Session|Client|AsyncClient)\(|\bhttp\.(?:DefaultClient|Get|Post|Head)\b|&?\b\w+\.(?:Client|Dialer|Transport|Server)\{|\bsql\.Open\(|\b(?:redis|kafka|grpc)\.(?:NewClient|Dial|NewReader|NewWriter)\w*\()/]],as=(e,t,n)=>{let r=[];for(let o=t;o<=n;o++){let s=e[o-1];if(/^\s*(\/\/|#|\*)/.test(s))continue;let i=rc.filter(([,c])=>c.test(s)).map(([c])=>c);if(i.length>0)r.push(`line ${o} (${i.join(", ")}): ${Ae(s.trim(),140)}`)}return r.length<=15?r.join(`
128
+ `):`${r.slice(0,15).join(`
129
+ `)}
130
+ (${r.length-15} more)`},cs=new Set(["data","info","obj","object","item","tmp","temp","res","resp","result","ret","rv","val","value","thing","stuff","handle","process","manager","helper","util","out","param","foo","bar","misc","aux","dummy"]),oc=new Set(["i","j","k","n","e","t","ok","id","db","tx","w","r","wg","mu","fn","cb","ex","ip","os","io","fs","_"]),fs=(e)=>e.replace(/^[_$#]+|[_$]+$/g,"").replace(/([a-z0-9])([A-Z])/g,"$1_$2").toLowerCase().split(/_+/).filter((t)=>t!==""),sc=(e,t)=>{let n=t.replace(/^[_$#]+/,"");if(n===""||oc.has(n))return!1;if(n.length<=2)return e!=="go";let r=fs(t);return r.length<=2&&r.some((o)=>cs.has(o)||cs.has(o.replace(/s$/,"")))},ds=(e,t,n,r)=>{let o=new Map,s=(i,c)=>{for(let l of c){let p=l.trim().replace(/^(?:\.\.\.|\*+|readonly\s+|public\s+|private\s+|protected\s+)/,"").split(/[\s:=?,]/)[0].replace(/[()[\]{}]/g,"");if(!/^[A-Za-z_$#][\w$]*$/.test(p)||["self","cls","this","const","let","var"].includes(p))continue;let a=o.get(p)??[];if(!a.includes(i))a.push(i);o.set(p,a)}};for(let i=n;i<=r;i++){let c=t[i-1];if(/^\s*(\/\/|#|\*)/.test(c))continue;if(e==="ts"){for(let p of c.matchAll(/\b(?:const|let|var)\s+([\w$]+)/g))s(i,[p[1]]);for(let p of c.matchAll(/\b(?:const|let|var)\s+[{[]([^}\]]*)[}\]]/g))s(i,p[1].split(",").map((a)=>a.split(":").pop()));for(let p of c.matchAll(/\bcatch\s*\(\s*([\w$]+)/g))s(i,[p[1]]);for(let p of c.matchAll(/\bfunction\s*\*?\s*([\w$]*)\s*(?:<[^>]*>)?\s*\(([^()]*)\)/g))s(i,[p[1],...qe(p[2])]);for(let p of c.matchAll(/(?:^|[^\w$.])\(([^()]*)\)\s*(?::\s*[^=;{]+)?=>/g))s(i,qe(p[1]));for(let p of c.matchAll(/(?:^|[^\w$.])([\w$]+)\s*=>/g))s(i,[p[1]]);let l=/^\s*(?:(?:public|private|protected|static|async|readonly|override|get|set)\s+)*([\w$#]+)\s*(?:<[^>]*>)?\s*\(([^()]*)\)\s*(?::[^{]*)?\{\s*$/.exec(c);if(l!==null&&!["if","for","while","switch","catch","return"].includes(l[1]))s(i,[l[1],...qe(l[2])])}else if(e==="py"){let l=/^\s*([A-Za-z_][\w\s,]*?)\s*(?::[^=]*)?=(?!=)/.exec(c);if(l!==null)s(i,l[1].split(","));for(let p of c.matchAll(/\bfor\s+([\w\s,()]+?)\s+in\b/g))s(i,p[1].split(","));for(let p of c.matchAll(/\bas\s+(\w+)/g))s(i,[p[1]]);for(let p of c.matchAll(/\bdef\s+(\w+)\s*\(([^)]*)\)?/g))s(i,[p[1],...qe(p[2])]);for(let p of c.matchAll(/\blambda\s+([\w\s,*=]+):/g))s(i,p[1].split(","));if(/^\s+[\w*]+\s*(?::[^=,]*)?(?:=[^,]*)?,?\s*$/.test(c)&&/\bdef\b[^:]*$/.test(t.slice(Math.max(n-1,i-6),i-1).join(" ")))s(i,[c])}else{for(let l of c.matchAll(/(?:^|[\s(;])((?:\w+\s*,\s*)*\w+)\s*:=/g))s(i,l[1].split(","));for(let l of c.matchAll(/\bvar\s+(\w+)/g))s(i,[l[1]]);for(let l of c.matchAll(/\bfunc\s*(?:\([^)]*\)\s*)?(\w*)\s*\(([^)]*)\)/g))s(i,[l[1],...qe(l[2])])}}return o},ls=(e,t,n,r)=>[...ds(e,t,n,r)].filter(([o])=>sc(e,o)).slice(0,15).map(([o,s])=>`${o} (line${s.length>1?"s":""} ${s.slice(0,5).join(", ")}${s.length>5?", \u2026":""})`).join(", "),ic=/\.(?:delete|pop|push|shift|unshift|splice|set|setdefault|add|clear|remove|append|extend|insert|update|put|write|save|send|emit|dispatch|publish|enqueue|close|reset|stop|start|kill|exec|execute|commit|rollback|flush|create|destroy|drop|rename|unlink|mkdir|post|patch|upload|store|persist|record|register|unregister|subscribe|notify|invalidate|evict|Set|Add|Delete|Remove|Put|Write|Store|Send|Close|Reset|Exec|Update|Create|Inc|Observe)(?:[A-Z_]\w*)?\(/g,ac=/(?:\bos\.(?:WriteFile|Remove|RemoveAll|Rename|Exit|Setenv|MkdirAll|Create)\(|\bfetch\(|\bexec\.Command\(|\bsubprocess\.|\bdel\s|(?<![\w.])delete\(|\bsetattr\(|\bglobal\s|\bnonlocal\s|[\w\])]\s*<-\s*[^\s-])/,cc=new Set(["get","is","has","find","compute","calc","calculate","validate","check","lookup","count","list","can","should"]),us=(e,t,n,r,o)=>{let s=e==="go"?ps.test(t)?/^func\s*\(\s*(\w+)/.exec(t)?.[1]:void 0:e==="py"?"self|cls":"this",i=s===void 0?void 0:new RegExp(`(?<![\\w.])(?:${s})(?:\\.[\\w$#]+|\\[[^\\]]+\\])+\\s*(?:[-+*/|&]?=(?!=)|\\+\\+|--)`),c=new Set(ds(e,n,r+1,o).keys()),l=(a)=>[...a.matchAll(ic)].some((f)=>{let d=/([\w$]+)[\w$.?[\]'"]*$/.exec(a.slice(0,f.index))?.[1];return d===void 0||!c.has(d)}),p=[];for(let a=r;a<=o;a++){let f=n[a-1];if(/^\s*(\/\/|#|\*)/.test(f))continue;let d=[...i?.test(f)?["changes state"]:[],...l(f)?["mutating or I/O call"]:[],...ac.test(f)?["I/O"]:[]];if(d.length>0)p.push(`line ${a} (${d.join(", ")}): ${Ae(f.trim(),120)}`)}return p.length<=20?p.join(`
131
+ `):`${p.slice(0,20).join(`
132
+ `)}
133
+ (${p.length-20} more)`},Bn=(e)=>e.replace(/[$]/g,"\\$"),Ae=(e,t)=>e.length>t?`${e.slice(0,t)}\u2026`:e,ms=async(e)=>{let t=[...e],n=(E)=>{let b=t.indexOf(E);if(b===-1)return;return t.splice(b,1),!0},r=(E)=>{let b=t.indexOf(E);if(b===-1)return;let v=t[b+1];return t.splice(b,2),v},o=Number(r("--min-lines")??"1"),s=Number(r("--chunk")??"Infinity"),i=n("--outer")??!1,c=n("--named")??!1,l=n("--module")??!1,p=n("--flags")??!1,a=n("--no-call-items")??!1,f=n("--globals")??!1,d=n("--context")??!1,h=n("--docs")??!1,u=n("--hidden")??!1,S=n("--names")??!1,x=n("--effects")??!1,m=Number(r("--classes")??"Infinity"),y=(await W("functions",t)).filter((E)=>rs(E)!==void 0),g=new Map;if(y.length>0){let E=pe("functions",Xa,y);for(let b of E.split(`
134
+ `)){if(b.trim()==="")continue;let v=JSON.parse(b);g.set(v.file,[...g.get(v.file)??[],v])}}let _=[];for(let E of y){let b=rs(E),O=(await Bun.file(E).text()).split(`
135
+ `),mt=g.get(E)??[],I=mt.filter((k)=>k.ruleId==="class").map((k)=>({start:k.range.start.line+1,end:k.range.end.line+1,name:/class\s+([\w$]+)/.exec(k.text)?.[1]??"(anonymous class)"})),Q=mt.filter((k)=>k.ruleId==="function").map((k)=>{let A=k.range.start.line+1,F=A;while(F>1&&/^\s*@/.test(O[F-2]))F--;if(h)while(F>1&&/^\s*(\/\/|\/\*|\*|#)/.test(O[F-2]))F--;let M=k.text.slice(0,600),z=O[A-1].slice(0,k.range.start.column),R=tc(b,M,z);return{start:F,end:k.range.end.line+1,nodeLine:A,nodeColumn:k.range.start.column,header:M,name:R}}),Je=(k)=>k.name===void 0&&Qa.test(O[k.nodeLine-1]),ye=(k,A)=>k!==A&&k.start<=A.start&&A.end<=k.end&&(k.start<A.start||k.end>A.end||k.nodeColumn<A.nodeColumn),Y=Q.filter((k)=>!Je(k)),J=O.map((k,A)=>Y.some((F)=>F.start<=A+1&&A+1<=F.end)),ee=f?nc(b,O,J):new Map,ie=(k)=>is(b,k.header).some((A)=>A.endsWith("(positional)")),ht=p?Y.filter(ie):[],Oe=new Map;if(x)for(let k of Y){if(k.name===void 0)continue;let A=us(b,k.header,O,k.nodeLine,k.end).split(`
136
+ `).filter((F)=>F.startsWith("line ")).length;Oe.set(k.name,Math.max(Oe.get(k.name)??0,A))}for(let k of Y){if(i&&Y.some((R)=>ye(R,k)))continue;if(c&&k.name===void 0)continue;if(k.end-k.nodeLine+1<o)continue;let A=[];if(d){let R=Y.filter((T)=>ye(T,k)).sort((T,q)=>q.start-T.start)[0],L=I.filter((T)=>T.start<=k.start&&k.end<=T.end).sort((T,q)=>q.start-T.start)[0];if(R!==void 0&&(L===void 0||L.start<R.start))A.push(["defined in",`function ${R.name??"(anonymous)"} (line ${R.nodeLine})`]);else if(L!==void 0)A.push(["defined in",`class ${L.name} (line ${L.start})`])}if(p){if(!ht.includes(k))continue;let R=is(b,k.header);if(A.push(["boolean parameters",R.join(", ")]),k.name!==void 0){let L=new RegExp(`(?<![\\w$])${Bn(k.name)}\\s*(?:<[^>()]*>)?\\(`),T=(D)=>L.test(D)&&!/^\s*(def|func|function)\b/.test(D),q=O.flatMap((D,de)=>(de+1<k.start||de+1>k.nodeLine)&&T(D)?[`line ${de+1}: ${Ae(D.trim(),160)}`]:[]);if(A.push(["call sites",q.length===0?"none in this file":q.slice(0,8).join(`
137
+ `)+(q.length>8?`
138
+ (${q.length-8} more)`:"")]),!a)for(let[D,de]of O.entries()){if(ht.some((Jn)=>Jn.start<=D+1&&D+1<=Jn.end))continue;if(!T(de)||!/(?<![\w$.])(?:true|false|True|False)(?![\w$])/.test(de))continue;_.push(JSON.stringify({id:`${E}:${D+1} call of ${k.name}`,path:E,lines:[D+1,D+1],"called function":`${Ae(O[k.nodeLine-1].trim(),200)} (line ${k.nodeLine})`,"boolean parameters":R.join(", "),text:de.trim()}))}}}if(f){let R=O.slice(k.start-1,k.end).join(`
139
+ `),L=[...ee].filter(([T])=>new RegExp(`(?<![\\w$.])${Bn(T)}(?![\\w$])`).test(R));A.push(["module-level variables used",L.length===0?"none":L.map(([T,q])=>`${T} (line ${q}: ${Ae(O[q-1].trim(),140)})`).join(`
140
+ `)])}if(u)A.push(["hidden dependencies",as(O,k.nodeLine,k.end)]);if(S)A.push(["generic or short names declared",ls(b,O,k.nodeLine,k.end)]);if(x){let R=fs(k.name??"")[0];if(R!==void 0&&cc.has(R))A.push(["name reads as",`a query (${R}\u2026)`]);A.push(["side effects",us(b,k.header,O,k.nodeLine,k.end)]);let L=O.slice(k.nodeLine,k.end).join(`
141
+ `),T=[...Oe].filter(([q])=>q!==k.name&&new RegExp(`(?<![\\w$])${Bn(q)}\\s*\\(`).test(L));A.push(["calls in this file",T.slice(0,10).map(([q,D])=>`${q} (${D===0?"no side effects found":`${D} side-effect line${D===1?"":"s"}`})`).join(", ")])}let F=k.end-k.start+1;if(F<=s){_.push(JSON.stringify({id:`${E}:${k.nodeLine} ${k.name??"(anonymous)"}`,path:E,lines:[k.start,k.end],text:O.slice(k.start-1,k.end).join(`
142
+ `),...Object.fromEntries(A)}));continue}let M=Math.ceil(F/s),z=Math.ceil(F/M);for(let R=0;R<M;R++){let L=k.start+R*z,T=Math.min(k.end,L+z-1),q=A.map(([D,de])=>D==="generic or short names declared"?[D,ls(b,O,L,T)]:D==="hidden dependencies"?[D,as(O,L,T)]:[D,de]);_.push(JSON.stringify({id:`${E}:${L} ${k.name??"(anonymous)"} (part ${R+1} of ${M})`,path:E,lines:[L,T],function:`${Ae(O[k.nodeLine-1].trim(),160)} (lines ${k.start}-${k.end}; this item is lines ${L}-${T} of it)`,...Object.fromEntries(q),text:O.slice(L-1,T).join(`
143
+ `)}))}}for(let k of I){let A=Y.filter((M)=>k.start<M.start&&M.end<=k.end&&!Y.some((z)=>z!==M&&k.start<z.start&&ye(z,M))&&!I.some((z)=>z!==k&&k.start<z.start&&z.start<=M.start&&M.end<=z.end));if(A.length<m)continue;let F=O.flatMap((M,z)=>{let R=z+1;if(R<k.start||R>k.end||Wn(b,M))return[];let L=A.find((T)=>T.start<=R&&R<=T.end);if(L!==void 0&&R!==L.nodeLine)return[];if(L===void 0&&Y.some((T)=>T.start<=R&&R<=T.end))return[];return[`${R}: ${Ae(M,160)}`]});_.push(JSON.stringify({id:`${E}:${k.start} class ${k.name}`,path:E,lines:[k.start,k.end],text:F.length<=120?F.join(`
144
+ `):`${F.slice(0,120).join(`
145
+ `)}
146
+ (${F.length-120} more lines)`}))}if(l){let A=[],F=()=>{while(A.length>0&&Wn(b,O[A[A.length-1]-1]))A.pop();while(A.length>0&&Wn(b,O[A[0]-1]))A.shift();if(A.length>0){let[M,z]=[A[0],A[A.length-1]];_.push(JSON.stringify({id:`${E}:${M} (module code)`,path:E,lines:[M,z],text:O.slice(M-1,z).join(`
147
+ `)}))}A=[]};for(let M=1;M<=O.length;M++)if(J[M-1])F();else if(A.push(M),A.length>=60)F();F()}}if(_.length>0)await new Promise((E)=>process.stdout.write(`${_.join(`
148
+ `)}
149
+ `,()=>E()))};var ft="(?i)(^|\\\\.)(log\\\\w*|logger|print\\\\w*|printf|sprintf|errorf|fatal\\\\w*|panic\\\\w*|warn\\\\w*|info\\\\w*|debug\\\\w*|trace|error|exception|assert\\\\w*|t\\\\.run|describe|it|test|skip|gettext|_)$",hs=["literal_type","type_annotation","enum_body","property_signature"],zn=(e,t)=>`
150
+ id: literal
151
+ language: ${e}
152
+ rule:
153
+ any:
154
+ - kind: number
155
+ - kind: string
156
+ - kind: template_string
157
+ not: { has: { kind: template_substitution } }
158
+ not:
159
+ any:
160
+ - inside: { kind: import_statement, stopBy: end }
161
+ - inside: { kind: export_statement, has: { field: source, kind: string } }
162
+ ${t.map((n)=>` - inside: { kind: ${n}, stopBy: end }`).join(`
163
+ `)}
164
+ - inside: { kind: pair, field: key }
165
+ - inside:
166
+ kind: arguments
167
+ inside:
168
+ any:
169
+ - { kind: call_expression, has: { field: function, regex: "${ft}" } }
170
+ - { kind: new_expression, has: { field: constructor, regex: "${ft}" } }
171
+ - inside:
172
+ kind: call_expression
173
+ has: { field: function, regex: "^(require|import)$" }
174
+ stopBy: end
175
+ - inside:
176
+ kind: lexical_declaration
177
+ regex: "^const"
178
+ inside: { any: [ { kind: program }, { kind: export_statement } ] }
179
+ stopBy: { any: [ { kind: arrow_function }, { kind: function_expression }, { kind: function_declaration }, { kind: method_definition }, { kind: class_body } ] }
180
+ - inside:
181
+ kind: variable_declarator
182
+ has: { field: name, regex: "^[A-Z][A-Z0-9_]+$" }
183
+ stopBy: { any: [ { kind: arrow_function }, { kind: function_expression } ] }
184
+ `,lc=[zn("typescript",hs),zn("tsx",[...hs,"jsx_attribute"]),zn("javascript",["jsx_attribute"]),`
185
+ id: literal
186
+ language: python
187
+ rule:
188
+ any:
189
+ - kind: integer
190
+ - kind: float
191
+ - kind: string
192
+ not: { has: { kind: interpolation } }
193
+ not:
194
+ any:
195
+ - inside: { kind: expression_statement }
196
+ - inside: { kind: import_from_statement, stopBy: end }
197
+ - inside: { kind: type, stopBy: end }
198
+ - inside: { kind: pair, field: key }
199
+ - inside:
200
+ kind: argument_list
201
+ inside: { kind: call, has: { field: function, regex: "${ft}" } }
202
+ - inside:
203
+ kind: keyword_argument
204
+ inside: { kind: argument_list, inside: { kind: call, has: { field: function, regex: "${ft}" } } }
205
+ - inside: { kind: assert_statement, stopBy: end }
206
+ - inside:
207
+ kind: assignment
208
+ has: { field: left, regex: "^_*[A-Z][A-Z0-9_]*$" }
209
+ stopBy: { any: [ { kind: lambda }, { kind: function_definition } ] }
210
+ `,`
211
+ id: literal
212
+ language: go
213
+ rule:
214
+ any:
215
+ - kind: int_literal
216
+ - kind: float_literal
217
+ - kind: interpreted_string_literal
218
+ - kind: raw_string_literal
219
+ not:
220
+ any:
221
+ - inside: { kind: import_declaration, stopBy: end }
222
+ - inside: { kind: const_declaration, stopBy: end }
223
+ - inside:
224
+ kind: var_declaration
225
+ inside: { kind: source_file }
226
+ stopBy: { kind: func_literal }
227
+ - inside: { kind: field_declaration, field: tag }
228
+ - inside: { kind: literal_element, inside: { kind: keyed_element, field: key } }
229
+ - inside:
230
+ kind: argument_list
231
+ inside: { kind: call_expression, has: { field: function, regex: "${ft}|^fmt\\\\." } }
232
+ `].join(`
233
+ ---
234
+ `),uc=(e)=>e.replace(/^[rbuf]*("""|'''|["'`])/i,"").replace(/("""|'''|["'`])$/,""),pc=(e,t)=>{if(/^[\d._]/.test(e)){if(!/^(0|1)(\.0*)?$/.test(e.replace(/_/g,"")))return!1;return!(e==="1"&&/\b1\s*(\*\s*time\.|<<)|time\.\w+\s*\*\s*1\b/.test(t))}let n=uc(e);if(n.trim().length<=1)return!0;if(n.trim().split(/\s+/).length>=3||/[.!?:]\s*$/.test(n)&&/\s/.test(n))return!0;return/%[-+# 0-9.]*[sdvfqwxXtTeEgGcbopU]|\{\d*\}|\{\w+\}/.test(n)},Ft=new Map,fc=async(e)=>{if(!Ft.has(e))Ft.set(e,(await Bun.file(e).text()).split(`
235
+ `));return Ft.get(e)},xs=(e)=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),dc=(e)=>{let t=`\\s*(?::[^=]+)?=\\s*${xs(e)}\\s*[;,]?\\s*(?:(?://|#).*)?$`;return new RegExp(`^\\s*(?:export\\s+)?(?:const|final|static|readonly)\\s+(?:\\w+\\s+)*?\\w+${t}|^\\s*[A-Z_][A-Z0-9_]*${t}|^\\s+[A-Z]\\w*(?:\\s+\\w+)?${t}`)},mc=(e,t,n)=>n.flatMap((r)=>{if(/^\d$/.test(r))return[];let o=new RegExp(`(?<![\\w.])${xs(r)}(?![\\w.])`),s=e.flatMap((a,f)=>f+1!==t&&o.test(a)?[f+1]:[]);if(s.length===0)return[];let i=dc(r),c=s.filter((a)=>i.test(e[a-1])),l=s.slice(0,8).join(", ")+(s.length>8?", \u2026":""),p=c.slice(0,3).map((a)=>`line ${a}: ${e[a-1].trim()}`).join("; ");return[`${r} also on line${s.length>1?"s":""} ${l}${p===""?"":`; named at ${p}`}`]}).join(`
236
+ `),gs=async(e)=>{let t=await W("literals",e),n=[];if(t.length>0){let r=pe("literals",lc,t),o=new Map;for(let s of r.split(`
237
+ `)){if(s.trim()==="")continue;let i=JSON.parse(s),c=i.range.start.line+1,l=await fc(i.file);if(i.text.includes(`
238
+ `)||pc(i.text,l[c-1]))continue;let p=`${i.file}:${c}`,a=o.get(p)??{file:i.file,line:c,literals:[]};if(!a.literals.includes(i.text))a.literals.push(i.text);o.set(p,a)}for(let[s,{file:i,line:c,literals:l}]of o){let p=Ft.get(i);n.push(JSON.stringify({id:s,path:i,lines:[c,c],text:p[c-1],literals:l.join(", "),elsewhere:mc(p,c,l)}))}}if(n.length>0)await new Promise((r)=>process.stdout.write(`${n.join(`
239
+ `)}
240
+ `,()=>r()))};var hc=25,qn=40,xc=new Set(["function","class","interface","type","enum","const","let","var","variable","namespace","struct","method","property","getter","setter"]),Lt=(e)=>`${e.owner===void 0?"":`${e.owner}.`}${e.name}`,Mt=(e)=>e.length===0?"none":`${e.slice(0,qn).map(Lt).join(", ")}${e.length>qn?`, \u2026 (${e.length-qn} more)`:""}`,ys=(e)=>Be((t,n,r)=>{let o=Ue(n,r),s=We(o,r),i=new Map(s.filter((a)=>a.owner===void 0).map((a)=>[a.name,a.exported])),c=s.filter((a)=>a.owner===void 0),l=[];if(r==="go"&&/(^|\/)internal\//.test(t))l.push("The file is in an `internal/` package.");if(r==="py"&&t.split("/").some((a)=>a.startsWith("_")&&!a.startsWith("__")))l.push("The file is in a private (underscore-named) module.");if(r==="py"&&/^__all__\s*(?::[^=]*)?=/m.test(n))l.push("The file declares `__all__`.");let p=[...l,`Public top-level names: ${Mt(c.filter((a)=>a.exported))}.`,`Non-public top-level names: ${Mt(c.filter((a)=>!a.exported))}.`].join(`
241
+ `);return s.filter((a)=>a.exported&&xc.has(a.kind)&&!a.name.startsWith("__")).filter((a)=>a.owner===void 0||i.get(a.owner)!==!1).map((a)=>{let f=a.owner!==void 0,d=Wo(o,a.name,a.start,a.end,f).filter((y)=>!s.some((g)=>g.start===y&&g.kind==="method"&&g.owner===a.name&&r==="go")),h=d.map((y)=>{let g=Bo(s,y),_=g===void 0?"at top level":`in ${Lt(g)} (${g.kind}, ${g.exported?"public":"not public"})`;return`line ${y+1} ${_}: ${o.lines[y].trim().slice(0,100)}`}),u=h.slice(0,6);if(h.length>u.length)u.push(`\u2026 (${h.length-u.length} more lines)`);let S=f?`${a.kind} of ${a.owner}`:a.kind,x=a.kind==="class"?s.filter((y)=>y.owner===a.name&&y.start>a.start&&y.end<=a.end):[],m=x.length>0?Math.max(a.start,x[0].start-1):a.end,w=x.length===0?"":`
242
+ (members: public ${Mt(x.filter((y)=>y.exported))}; non-public ${Mt(x.filter((y)=>!y.exported))})`;return{id:`${t}:${a.start+1}:${Lt(a)}`,path:t,lines:[a.start+1,m+1],references:`Public ${S} \`${Lt(a)}\`. ${d.length===0?"Not referenced anywhere else in this file.":`Referenced on ${d.length} other line(s) of this file:
243
+ ${u.join(`
244
+ `)}`}`,module:p,text:fe(o.lines,a.start,m,hc)+w}})},e);var Hn=25,bs=(e)=>Be((t,n,r)=>{let o=Ue(n,r),{lines:s,code:i}=o,c=We(o,r),l=(u)=>{if(r==="py"){for(let m=u+1;m<Math.min(s.length,u+6);m++){let w=/^\s*[rbuf]?("""|''')\s*(.*?)\s*(?:\1)?\s*$/.exec(s[m]);if(w!==null)return w[2]||(s[m+1]??"").trim();if(i[m].trim().endsWith(":"))continue;if(i[m].trim()!==""&&o.depth[m]===0)break}return""}let S=u-1;while(S>=0&&i[S].trim()===""&&s[S].trim()!=="")S--;return s.slice(S+1,u).map((m)=>m.trim().replace(/^(?:\/\/+|\/\*+|\*+\/?|#)\s*/,"")).filter((m)=>m!==""&&!m.startsWith("@"))[0]??""},p=new Set,a=r==="go"?/^\s*(?:import\s+)?(?:\w+\s+)?"([^"]+)"\s*$/:r==="py"?/^\s*(?:from\s+(\S+)\s+import|import\s+([\w.]+))/:/^\s*(?:import\b.*?from\s+|import\s+|(?:const|let|var)\s+.*?=\s*require\()\s*["'`]([^"'`]+)["'`]/,f=c[0]?.start??s.length;for(let u=0;u<s.length;u++){if(r==="go"&&u>=f)break;let S=a.exec(s[u]);if(S!==null)p.add(S[1]??S[2])}let d=[`${t} (${s.length} lines)`];if(p.size>0)d.push(`imports: ${[...p].join(", ")}`);d.push("");let h=new Set(c.filter((u)=>u.owner===void 0).map((u)=>u.name));for(let u of c){if(u.owner!==void 0&&!(r==="go"&&!h.has(u.owner)))continue;let S=l(u.start);d.push(`${u.start+1}-${u.end+1}: ${u.signature.replace(/\s*\{\s*$/,"")}${S===""?"":` \u2014 ${S.slice(0,120)}`}`);let x=c.filter((g)=>g.owner===u.name&&g.kind!=="constructor"&&g.start>=u.start&&(r==="go"||g.end<=u.end));if(x.length===0)continue;let m=x.filter((g)=>["field","property","attribute"].includes(g.kind)&&!(r==="py"&&g.kind==="property")),w=x.filter((g)=>!m.includes(g)),y=(g)=>`${g.slice(0,Hn).map((_)=>_.name).join(", ")}${g.length>Hn?`, \u2026 (${g.length-Hn} more)`:""}`;if(m.length>0)d.push(` fields: ${y(m)}`);if(w.length>0)d.push(` methods: ${y(w)}`)}return[{id:t,path:t,lines:[1,s.length],text:d.join(`
245
+ `)}]},e);var ws=30,Nt=25,gc=/^(?:u?int\d*|string|bool|float\d+|complex\d+|byte|rune|error|uintptr|time\.(?:Duration|Time)|atomic\.\w+|sync\.\w+)$/,yc=/:\s*(?:number|string|boolean|bigint|int|str|bool|float)\s*(?:[;=]|$)|=\s*(?:-?\d[\d_.]*|["'`][^"'`]*["'`]|true|false|True|False)\s*;?\s*$/,bc=(e)=>{let t=0;for(let n=e.length-1;n>=0;n--){let r=e[n];if(r===")"||r==="]"||r==="}")t++;else if(r==="("||r==="["||r==="{")if(t>0)t--;else return r==="("&&/[\w$]\s*$/.test(e.slice(0,n))&&!/\breturn\s*$/.test(e.slice(0,n))}return!1},wc={go:/^(?:\[\]|map\[|&|\w+(?:\.\w+)?\{|make\()/,ts:/^(?:\[|\{|new\s+(?:Map|Set|Array|WeakMap)\b)/,py:/^(?:\[|\{|(?:dict|list|set|defaultdict|OrderedDict|deque)\()/},$c=(e,t)=>{let n=e.indexOf("(");if(n<0)return new Set;let r=e.slice(n+1),o=new Set;if(t==="go"){for(let s of r.matchAll(/(?:^|[(,])\s*(\w+)(?=\s*(?:,|\s+[\w*[\].{}]))/g))o.add(s[1]);for(let s of r.matchAll(/(\w+)\s+(?:u?int\d*|string|bool|float\d+|byte|rune|time\.Duration)\b/g))o.delete(s[1])}else{for(let s of r.matchAll(/(?:^|[(,])\s*(?:(?:public|private|protected|readonly|override)\s+)*\*{0,2}(\w+)\s*[?:=,)]/g))o.add(s[1]);for(let s of r.matchAll(/(\w+)\s*\??:\s*(?:number|string|boolean|bigint|int|str|bool|float|bytes)\b(?!\s*\[)/g))o.delete(s[1])}return o.delete("self"),o.delete("this"),o},kc=(e,t)=>{let n=[];for(let r=t.start;r<=t.end&&r<t.start+15;r++)if(n.push(e.code[r]),/[{:]\s*$/.test(e.code[r])&&e.depth[r+1]!==void 0&&n.join("").split("(").length===n.join("").split(")").length)break;return n.join(" ")},$s=(e)=>Be((t,n,r)=>{let o=Ue(n,r),{lines:s,code:i}=o,c=We(o,r),l=[],p=(x,m,w,y,g,_)=>l.push({id:`${t}:${m+1}:${x}`,path:t,lines:[m+1,w+1],state:g,finding:_,text:y}),a=new Map,f=(x)=>{let m=a.get(x);if(m===void 0)a.set(x,m={decl:c.find((w)=>w.owner===void 0&&w.name===x&&(w.kind==="class"||w.kind==="struct")),fields:[],methods:[]});return m};for(let x of c){if(x.owner===void 0)continue;let m=f(x.owner);if(x.kind==="field"||x.kind==="property"&&r!=="py"||x.kind==="attribute")m.fields.push({name:x.name.replace(/^#/,""),line:x.start,exported:x.exported,detail:s[x.start].trim().slice(0,140)});else if(["method","constructor","getter","setter","property"].includes(x.kind))m.methods.push(x)}for(let x of a.values())for(let m of x.methods){if(r==="ts"&&m.kind==="constructor")for(let w=m.start;w<=Math.min(m.end,m.start+15);w++){for(let y of i[w].matchAll(/\b(public|private|protected|readonly)\s+(?:readonly\s+)?(\w+)\s*[?:]/g))x.fields.push({name:y[2],line:w,exported:y[1]==="public"||y[1]==="readonly",detail:`constructor parameter property: ${y[0]}`});if(/\{\s*$/.test(i[w]))break}if(r==="py")for(let w=m.start;w<=m.end;w++){let y=/^\s*self\.(\w+)\s*(?::[^=]+)?=(?!=)\s*(.*)$/.exec(i[w]);if(y===null||x.fields.some((g)=>g.name===y[1]&&g.detail.startsWith("self.")))continue;x.fields.push({name:y[1],line:w,exported:!y[1].startsWith("_"),detail:s[w].trim().slice(0,140)})}}let d=(x)=>{let m=a.get(x),w=m.decl?.kind??"type",y=[...m.fields].sort((b,v)=>b.line-v.line),g=y.slice(0,Nt).map((b)=>`${b.line+1}: ${b.detail}`);if(y.length>Nt)g.push(`\u2026 (${y.length-Nt} more fields)`);let _=y.some((b)=>/\b(?:Mutex|RWMutex|Lock|RLock)\b|threading\.|asyncio\.Lock/.test(b.detail)),E=m.methods.filter((b)=>b.exported&&b.kind!=="constructor").length;return[`${w} ${x}${m.decl===void 0?"":` (${m.decl.exported?"public":"not public"}, line ${m.decl.start+1})`}: ${m.methods.length} methods in this file (${E} public)${_?", guarded by a lock":""}.`,y.length===0?"No fields found.":`Fields:
246
+ ${g.join(`
247
+ `)}`].join(`
248
+ `)},h=new Map;for(let x of c){if(x.owner!==void 0||!["var","let","const","variable"].includes(x.kind))continue;if(r==="go"&&x.kind==="const")continue;let m=/=\s*(.*)$/.exec(i[x.start])?.[1]?.trim()??(r==="go"?i[x.start].trim().replace(/^var\s+/,"").replace(/^\w+\s+/,""):"");if(!wc[r].test(m)&&!(r==="go"&&/^(?:\[\]|map\[)/.test(m)))continue;h.set(x.name,x)}let u=new Set,S=(x)=>`Module-level ${x.kind} \`${x.name}\` (${x.exported?"public":"not public"}), line ${x.start+1}:
249
+ ${fe(s,x.start,x.end,8)}`;for(let x of c){if(!["method","getter","setter","constructor","function","property"].includes(x.kind))continue;if(x.kind==="property"&&r==="ts")continue;let m=x.owner===void 0?void 0:a.get(x.owner),w=r==="go"?/^func\s*\(\s*(\w+)/.exec(i[x.start])?.[1]:r==="py"?"self":"this",y=[];if(m!==void 0&&w!==void 0){let _=new Map(m.fields.map((I)=>[I.name,I])),E=$c(kc(o,x),r),b=new Map,v=`${w}\\.#?\\w+(?:\\s*\\[|\\.(?:get|Get|Load)\\(|\\s*;?\\s*$)|${w}\\.(?:get|load|lookup|find|fetch)\\w*\\(`,O=r==="go"?new RegExp(`^\\s*(\\w+)(?:\\s*,\\s*\\w+)*\\s*:?=\\s*(?:${v})`,"i"):r==="ts"?new RegExp(`^\\s*(?:const|let|var)\\s+(\\w+)\\b[^=]*=\\s*(?:${v})`,"i"):new RegExp(`^\\s*(\\w+)\\s*(?::[^=]+)?=(?!=)\\s*(?:${v})`,"i");for(let I=x.start;I<=x.end;I++){let Q=O.exec(i[I]);if(Q!==null&&Q[1]!==w&&Q[1]!=="_")b.set(Q[1],I)}E.delete(w);let mt=new RegExp(`(&?)\\b${w}\\.#?(\\w+)(?![\\w$(.\\[])`,"g");for(let I=x.start;I<=x.end;I++){let Q=i[I],Je=/\breturn\b/.test(Q),ye=new Set;for(let J of Q.matchAll(mt)){let ee=J[2];if(ye.has(ee)||!Je&&J[1]===""||bc(Q.slice(0,J.index)))continue;if(new RegExp(`\\b${w}\\.#?${ee}\\s*(?::[^=]+)?=(?!=)`).test(Q)&&!Je)continue;let ie=_.get(ee),ht=ie===void 0?"":ie.detail.replace(new RegExp(`^${ie.name}\\s+`),"");if(J[1]===""&&ie!==void 0&&(r==="go"?gc.test(ht.split(/\s/)[0]??""):yc.test(ie.detail)))continue;ye.add(ee);let Oe=ie===void 0?"":` (declared at line ${ie.line+1}: ${ie.detail})`;y.push(J[1]==="&"?`Line ${I+1} takes the address of the field \`${ee}\`${Oe}.`:`Line ${I+1} returns the field \`${ee}\`${Oe}.`)}if(Je){for(let[J,ee]of b)if(new RegExp(`\\breturn\\b.*\\b${J}\\b(?![\\w$(])`).test(Q)&&!ye.has(J))ye.add(J),y.push(`Line ${I+1} returns \`${J}\` (or part of it), taken from the receiver's state at line ${ee+1}: ${s[ee].trim().slice(0,120)}`)}let Y=new RegExp(`\\b${w}\\.#?(\\w+)\\s*(?::[^=]+)?=(?!=)\\s*(.+?)\\s*;?\\s*$`).exec(Q);if(Y!==null){let J=[...E].find((ee)=>new RegExp(`(?<![\\w$.])${ee}(?![\\w$])`).test(Y[2]));if(J!==void 0)y.push(`Line ${I+1} stores \`${Y[2].slice(0,80)}\` (from the parameter \`${J}\`) in the field \`${Y[1]}\`.`)}}for(let I of m.fields)if(x.kind==="constructor"&&I.detail.startsWith("constructor parameter property")&&I.line>=x.start&&I.line<=x.end)y.push(`Line ${I.line+1} makes the parameter \`${I.name}\` a field (${I.exported?"publicly readable":"not public"}), stored as given.`)}for(let[_,E]of h)for(let b=x.start;b<=x.end;b++){let v=i[b];if(!Ln(_).test(v))continue;if(new RegExp(`\\breturn\\s+${_.replace(/[$]/g,"\\$")}\\s*(?:[,;)]|$)`).test(v)||new RegExp(`(?:\\.\\.\\.|\\*\\*)${_}\\b`).test(v))y.push(`Line ${b+1} returns or spreads the module-level mutable \`${_}\` (line ${E.start+1}).`),u.add(_)}if(y.length===0)continue;let g=x.owner!==void 0?d(x.owner):[...u].filter((_)=>y.some((E)=>E.includes(`\`${_}\``))).map((_)=>S(h.get(_))).join(`
250
+
251
+ `);p(`${x.owner===void 0?"":`${x.owner}.`}${x.name}`,x.start,x.end,fe(s,x.start,x.end,ws),g,y.join(`
252
+ `))}for(let[x,m]of a){let w=m.fields.filter((v)=>v.exported);if(w.length===0||m.decl!==void 0&&!m.decl.exported&&r==="go")continue;let y=[...new Set(w.map((v)=>v.line))].sort((v,O)=>v-O),g=y[0],_=y[y.length-1],E=r==="go"&&m.decl!==void 0?fe(s,m.decl.start,m.decl.end,40):y.slice(0,Nt).map((v)=>`${v+1}: ${s[v].trim()}`).join(`
253
+ `),b=r==="go"&&m.decl!==void 0?[m.decl.start,m.decl.end]:[g,_];p(`${x} fields`,b[0],b[1],E,d(x),`Public fields of ${x}: ${w.map((v)=>v.name).join(", ")}.`)}for(let[x,m]of h){if(!m.exported&&!u.has(x))continue;p(x,m.start,m.end,fe(s,m.start,m.end,ws),"",`Module-level mutable ${m.kind} \`${x}\`, ${m.exported?"public":"not public"}${u.has(x)?", returned or spread by a function":""}.`)}return l.sort((x,m)=>x.lines[0]-m.lines[0])},e);var ks=async(e)=>{let t=e.includes("--no-lines"),n=e.filter((r)=>r!=="--no-lines");if(n.length>0)console.error(`present: unexpected arguments ${n.join(" ")} (supported: --no-lines)`),process.exit(2);await we("present",(r)=>Io(r.map((o)=>({id:o.id,...o.path===void 0?{}:{path:o.path},...o.lines===void 0?{}:{lines:o.lines},text:[`location: ${o.path??o.id}${t||o.lines===void 0?"":` (lines ${o.lines[0]}-${o.lines[1]})`}`,...o.evidence.flatMap(([s,i])=>i===""?[]:[`${s}:
254
+ ${i}`]),`item:
255
+ ${o.text}`].join(`
256
+
257
+ `),evidence:[]}))))};import{resolve as Ss}from"path";var Sc="it|test|describe|context|suite|specify|beforeEach|afterEach|beforeAll|afterAll|before|after",_c=(e)=>`
258
+ id: call/${e}
259
+ language: ${e}
260
+ rule:
261
+ kind: call_expression
262
+ all:
263
+ - has: {field: function, regex: '^(${Sc})(\\.\\w+)*(\\(|$)'}
264
+ - has: {field: arguments, has: {any: [{kind: arrow_function}, {kind: function_expression}]}}
265
+ ---
266
+ id: helper/${e}
267
+ language: ${e}
268
+ rule:
269
+ any:
270
+ - kind: function_declaration
271
+ - kind: class_declaration
272
+ - kind: lexical_declaration
273
+ has: {kind: variable_declarator, has: {field: value, any: [{kind: arrow_function}, {kind: function_expression}]}}
274
+ inside: {any: [{kind: program}, {kind: export_statement}]}
275
+ `,Ec=[...["TypeScript","Tsx","JavaScript"].map(_c),`
276
+ id: def
277
+ language: Python
278
+ rule: {kind: function_definition}
279
+ ---
280
+ id: decorated
281
+ language: Python
282
+ rule: {kind: decorated_definition}
283
+ ---
284
+ id: class
285
+ language: Python
286
+ rule: {kind: class_definition}
287
+ ---
288
+ id: func
289
+ language: Go
290
+ rule: {any: [{kind: function_declaration}, {kind: method_declaration}]}
291
+ ---
292
+ id: run
293
+ language: Go
294
+ rule:
295
+ kind: call_expression
296
+ all:
297
+ - has: {field: function, regex: '\\.Run$'}
298
+ - has: {field: arguments, has: {kind: func_literal}}
299
+ `].join(`
300
+ ---
301
+ `),vc=(e)=>{if(e.length===0)return[];return pe("tests",Ec,e).split(`
302
+ `).filter((n)=>n.trim()!=="").map((n)=>JSON.parse(n)).map((n)=>({...n,ruleId:n.ruleId.split("/")[0]})).sort((n,r)=>n.file.localeCompare(r.file)||n.range.byteOffset.start-r.range.byteOffset.start||n.range.byteOffset.end-r.range.byteOffset.end||n.ruleId.localeCompare(r.ruleId))},Ac=/^\s*(?:"((?:[^"\\]|\\.)*)"|'((?:[^'\\]|\\.)*)'|`([^`]*)`)/,_s=(e)=>{let t=Ac.exec(e);return t===null?void 0:t[1]??t[2]??t[3]},Oc=(e)=>{let t=[],n=e.filter((c)=>c.ruleId==="decorated").map((c)=>c.range),r=(c)=>n.filter((l)=>l.byteOffset.end===c.byteOffset.end&&l.byteOffset.start<c.byteOffset.start).sort((l,p)=>p.byteOffset.start-l.byteOffset.start)[0];for(let c of e){let l=(c.ruleId==="def"||c.ruleId==="class"?r(c.range):void 0)??c.range,p=(f,d,h=!0)=>t.push({kind:f,name:d,literal:h,start:l.start.line+1,end:l.end.line+1,bytes:[l.byteOffset.start,l.byteOffset.end]}),a=c.text.split(`
303
+ `)[0];if(c.ruleId==="call"){let f=/^[\w.]+/.exec(c.text)[0],d=f.split(".")[0],h=/^[\w.]+\([\s\S]*?\)\s*\(/.exec(c.text),u=f.endsWith(".each")&&h!==null?c.text.slice(h[0].length):c.text.slice(f.length+1),S=_s(u);if(/^(before|after)/.test(d))p("helper",f);else if(S!==void 0)p(/^(describe|context|suite)$/.test(d)?"suite":"test",S)}else if(c.ruleId==="helper")p("helper",/(?:function\*?|class|const|let|var)\s+([\w$]+)/.exec(a)?.[1]??a.trim());else if(c.ruleId==="def"){let f=/def\s+(\w+)/.exec(a)[1];p(/^test/.test(f)?"test":"helper",f)}else if(c.ruleId==="class")p("suite",/class\s+(\w+)/.exec(a)[1]);else if(c.ruleId==="func"){let f=/func\s+(?:\([^)]*\)\s*)?(\w+)/.exec(a)[1];p(/^(Test|Fuzz)/.test(f)?"test":"helper",f)}else if(c.ruleId==="run"){let f=c.text.slice(c.text.indexOf("(")+1),d=_s(f);p("subtest",d??f.split(",")[0].trim(),d!==void 0)}}t.sort((c,l)=>c.bytes[0]-l.bytes[0]||l.bytes[1]-c.bytes[1]);let o=(c)=>{let l=[];for(let p of c){while(l.length>0&&l.at(-1).bytes[1]<p.bytes[1])l.pop();p.parent=l.at(-1),l.push(p)}return c};o(t);let s=(c)=>t.some((l)=>l.kind!=="helper"&&Pt(l).includes(c)),i=t.map((c)=>c.kind==="helper"&&s(c)?{...c,kind:"wrapper"}:{...c});return o(o(i).flatMap((c)=>{if(Pt(c).every((l)=>l.kind==="suite"||l.kind==="wrapper"))return[c];return c.kind==="test"||c.kind==="subtest"?[{...c,kind:"subtest"}]:[]}))},Pt=(e)=>{let t=[];for(let n=e.parent;n!==void 0;n=n.parent)t.push(n);return t};var dt=(e,t)=>e.length<=t?e.join(`
304
+ `):[...e.slice(0,t),`\u2026 and ${e.length-t} more`].join(`
305
+ `),Rc=(e,t)=>{let n=t.filter((o)=>o!==e&&Pt(o).includes(e)&&o.kind==="subtest"&&o.literal),r=[];for(let o=e.start;o<=e.end;o++)if(!n.some((s)=>s.start<=o&&o<=s.end))r.push(o);return r},Es=(e)=>/\.[cm]?[jt]sx?$/.test(e)?"js":e.endsWith(".py")?"py":e.endsWith(".go")?"go":void 0,Cc={js:/\b(expect|assert)\b|\bt\.(is|not|deepEqual|notDeepEqual|true|false|truthy|falsy|throws|throwsAsync|notThrows|regex|like|snapshot|pass|fail)\b|\.should\b/,py:/^\s*assert\b|\bself\.(assert|fail)\w*\(|\bpytest\.(raises|warns|fail)\b|\.assert_\w+\(|\bassert_\w+\(/,go:/\b(assert|require)\.\w+\(|\bt\.(Error|Errorf|Fatal|Fatalf|Fail|FailNow)\(|\bcmp\.Diff\(|\bt\.Log/},Tc=(e,t,n)=>{let r=new Set;for(let o of n){if(!Cc[e].test(t[o-1]))continue;if(e==="go"&&/^\s*t\.(Error|Fatal|Fail)/.test(t[o-1])&&/^\s*(if|}\s*else)\b/.test(t[o-2]??""))r.add(o-1);r.add(o)}return[...r].sort((o,s)=>o-s)},Ic=(e,t)=>{let n=t.split(`
306
+ `),r=new Set,o=new Set,s=new Set,i=new Set,c=new Set,l=new Set;if(e==="py"){for(let a of t.matchAll(/^\s*from\s+[\w.]+\s+import\s+\(?([^)\n]*(?:\n[^)\n]*)*?)\)?\s*$/gm))for(let f of a[1].split(/[,\s]+/))if(/^_[a-zA-Z]/.test(f))r.add(f);for(let a of t.matchAll(/^\s*class\s+(\w+)/gm))o.add(a[1])}if(e==="go"){let a=/^import\s*\(([\s\S]*?)^\)/m.exec(t)?.[1]??"",f=[...t.matchAll(/^import\s+(\w+\s+)?"[^"]+"/gm)].map((h)=>h[0]);for(let h of[...a.split(`
307
+ `),...f]){let u=/(?:^|\s)(\w+)?\s*"([^"]+)"/.exec(h);if(u===null)continue;s.add(u[1]??u[2].split("/").at(-1).replace(/^go-/,"").replace(/\.v\d+$/,"").replace(/-/g,"_"))}let d=(h)=>h.split(/\s*,\s*/).filter((u)=>u!=="_");for(let h of t.matchAll(/\b(\w+(?:\s*,\s*\w+)*)\s*:=/g))for(let u of d(h[1]))i.add(u);for(let h of t.matchAll(/\b(?:var|const)\s+(\w+(?:\s*,\s*\w+)*)/g))for(let u of d(h[1]))i.add(u);for(let h of t.matchAll(/\bfunc\s+(?:\([^)]*\)\s*)?(\w+)/g))i.add(h[1]);for(let h of t.matchAll(/^(?:var|const)\s*\(([\s\S]*?)^\)/gm))for(let u of h[1].matchAll(/^\s*(\w+)/gm))i.add(u[1]);for(let h of t.matchAll(/\bfor\s+(\w+(?:\s*,\s*\w+)?)\s*:=\s*range\b/g))for(let u of d(h[1]))c.add(u);for(let h of t.matchAll(/func\s*(?:\([^)]*\)\s*)?\w*\s*\(([^)]*)\)/g))for(let u of h[1].split(",")){let S=/^\s*(\w+)/.exec(u)?.[1];if(S)i.add(S)}for(let h of t.matchAll(/^type\s+\w+\s+struct\s*\{([\s\S]*?)^\}/gm))for(let u of h[1].matchAll(/^\s*(\w+)/gm))l.add(u[1]);for(let h of t.matchAll(/^func\s*\([^)]*\)\s*(\w+)/gm))l.add(h[1])}let p=/^package\s+(\w+)/m.exec(t)?.[1]??"";return{language:e,lines:n,privateImports:r,pyClasses:o,goImports:s,goVariables:i,goTableVariables:c,goMembers:l,goSamePackage:!p.endsWith("_test")}},Fc=(e)=>e.replace(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`[^`]*`/g,'""'),Mc=(e,t)=>{let n=t.replace(e.language==="py"?/#.*$/:/\/\/.*$/,""),r=Fc(n),o=[];if(e.language==="py"){for(let s of r.matchAll(/\b([A-Za-z_][\w.]*?)\.(_[A-Za-z]\w*)\b/g)){if(/^(self|cls)$/.test(s[1])||e.pyClasses.has(s[1].split(".")[0]))continue;o.push(`${s[1]}.${s[2]}`)}for(let s of n.matchAll(/\b(?:getattr|setattr|hasattr)\(\s*([\w.]+)\s*,\s*["'](_[A-Za-z]\w*)["']/g))o.push(`${s[1]}.${s[2]}`);for(let s of r.matchAll(/(?<![\w.])(_[A-Za-z]\w*)\b/g))if(e.privateImports.has(s[1]))o.push(`${s[1]} (imported private name)`)}if(e.language==="js"){for(let s of r.matchAll(/\bas\s+(?:unknown\s+as\s+|any\b)[^)]*\)\s*\??\.\s*([\w$#]+)/g))o.push(`${s[1]} (read through a cast)`);for(let s of r.matchAll(/\bas\s+unknown\s+as\s+\{\s*([\w$]+)\s*[:(?]/g))o.push(`${s[1]} (typed through a cast to reach it)`);for(let s of n.matchAll(/\b([\w$]+)\[\s*["'`]([\w$]+)["'`]\s*\]/g))if(!/^(process|env|headers|window|globalThis)$/.test(s[1]))o.push(`${s[1]}["${s[2]}"] (bracket access)`);for(let s of r.matchAll(/\b([\w$]+)\.(_[\w$]+|#[\w$]+)\b/g))o.push(`${s[1]}.${s[2]}`);if(/@ts-(ignore|expect-error)/.test(t))o.push("type check suppressed")}if(e.language==="go"&&e.goSamePackage){for(let i of r.matchAll(/(?<![\w.])([A-Za-z_]\w*)((?:\.[A-Za-z_]\w*)+)/g)){if(e.goImports.has(i[1])||e.goTableVariables.has(i[1])||/^(t|b|f|tb)$/.test(i[1]))continue;for(let c of i[2].slice(1).split("."))if(/^[a-z_]/.test(c)&&!e.goMembers.has(c))o.push(`${i[1]}${i[2]} (unexported ${c})`)}let s=/^\s*([a-z_]\w*)\s*=[^=]/.exec(r)?.[1];if(s!==void 0&&s!=="_"&&!e.goVariables.has(s))o.push(`${s} (package variable set by the test)`)}return[...new Set(o)]},j="[\"'`]",Lc={py:[[new RegExp(`\\bpatch\\(\\s*(?:target\\s*=\\s*)?${j}([\\w.]+)${j}`,"g"),(e)=>`${e[1]} patched`],[new RegExp(`\\bpatch\\.object\\(\\s*([\\w.]+)\\s*,\\s*${j}(\\w+)${j}`,"g"),(e)=>`${e[1]}.${e[2]} patched`],[/\bpatch\.dict\(\s*([\w.]+|["'][\w.]+["'])/g,(e)=>`dict ${e[1]} patched`],[new RegExp(`\\bmonkeypatch\\.setattr\\(\\s*([\\w.]+)\\s*,\\s*${j}(\\w+)${j}`,"g"),(e)=>`${e[1]}.${e[2]} replaced`],[new RegExp(`\\bmonkeypatch\\.setattr\\(\\s*${j}([\\w.]+)${j}`,"g"),(e)=>`${e[1]} replaced`],[new RegExp(`\\bmonkeypatch\\.(?:setenv|delenv)\\(\\s*${j}(\\w+)${j}`,"g"),(e)=>`environment variable ${e[1]} set`],[new RegExp(`\\bmocker\\.spy\\(\\s*([\\w.]+)\\s*,\\s*${j}(\\w+)${j}`,"g"),(e)=>`${e[1]}.${e[2]} spied on`],[/(?:^|[^\w.])(\w+)\s*=\s*(?:\w+\.)*(Magic|Async|NonCallable)?Mock\(\s*(?:spec(?:_set)?\s*=\s*([\w.]+))?/g,(e)=>`${e[1]} is a ${e[2]??""}Mock${e[3]===void 0?"":` of ${e[3]}`}`],[/\bcreate_autospec\(\s*([\w.]+)/g,(e)=>`autospec mock of ${e[1]}`],[/\b(respx|responses\.add|httpx_mock|requests_mock|aioresponses)\b/g,()=>"HTTP requests faked"],[/\b(freeze_time|freezegun|time_machine)\b/g,()=>"clock frozen"]],js:[[new RegExp(`\\b(?:vi|jest)\\.(?:mock|doMock)\\(\\s*${j}([^"'\`]+)${j}`,"g"),(e)=>`module "${e[1]}" mocked`],[new RegExp(`\\b(?:vi|jest)\\.spyOn\\(\\s*([\\w$.]+)\\s*,\\s*${j}([\\w$]+)${j}`,"g"),(e)=>`${e[1]}.${e[2]} spied on`],[/([\w$.]+)\s*[:=]\s*(?:vi|jest)\.fn\(/g,(e)=>`${e[1]} is a mock function`],[/\b(?:vi|jest|sinon)\.useFakeTimers\(/g,()=>"clock faked"],[new RegExp(`\\b(?:vi|jest)\\.stubGlobal\\(\\s*${j}([\\w$]+)${j}`,"g"),(e)=>`global ${e[1]} stubbed`],[new RegExp(`\\b(?:vi|jest)\\.stubEnv\\(\\s*${j}([\\w$]+)${j}`,"g"),(e)=>`environment variable ${e[1]} stubbed`],[new RegExp(`\\bsinon\\.(stub|spy|mock|replace)\\(\\s*([\\w$.]+)(?:\\s*,\\s*${j}([\\w$]+)${j})?`,"g"),(e)=>`${e[2]}${e[3]===void 0?"":`.${e[3]}`} ${e[1]==="spy"?"spied on":`${e[1]}bed`}`.replace("replacebed","replaced")],[/(?:vi\.mocked\(\s*([\w$.]+)\s*\)|([\w$.]+))\.mock(?:Implementation|ReturnValue|ResolvedValue|RejectedValue)\w*\(/g,(e)=>`${e[1]??e[2]} given canned behavior`],[/\b(?:globalThis|global|window)\.fetch\s*=[^=]/g,()=>"global fetch replaced"],[/\b(nock|msw|setupServer|fetchMock)\b/g,()=>"HTTP requests faked"]],go:[[/\.EXPECT\(\)\.(\w+)\(/g,(e)=>`mock expects a call to ${e[1]}`],[/\b(\w+)\.On\(\s*"(\w+)"/g,(e)=>`mock ${e[1]} expects a call to ${e[2]}`],[/\bhttptest\.New(?:TLS)?Server\b/g,()=>"fake HTTP server"],[/\bhttptest\.NewRecorder\b/g,()=>"HTTP response recorder"],[/\bNewMock(\w+)\(/g,(e)=>`generated mock of ${e[1]}`]]},Nc={not_called:"asserted not called",called_once_with:"asserted called once with specific arguments",called_once:"asserted called exactly once",called_with:"asserted called with specific arguments",called:"asserted called",any_call:"asserted called with specific arguments at some point",has_calls:"asserted to receive a specific sequence of calls",awaited:"asserted awaited",awaited_once:"asserted awaited exactly once",awaited_with:"asserted awaited with specific arguments",awaited_once_with:"asserted awaited once with specific arguments",not_awaited:"asserted not awaited"},Pc={py:[[/([\w.]+)\.assert_((?:not_)?(?:called|awaited)\w*|any_call|has_calls)\(/g,(e)=>`${e[1]} ${Nc[e[2]]??`checked with assert_${e[2]}`}`],[/([\w.]+)\.(?:call_count|await_count)\b/g,(e)=>`number of calls to ${e[1]} checked`],[/([\w.]+)\.(?:call_args(?:_list)?|mock_calls|await_args(?:_list)?|method_calls)\b/g,(e)=>`arguments of calls to ${e[1]} checked`],[/\bassert\s+(not\s+)?([\w.]+)\.called\b/g,(e)=>`${e[2]} asserted ${e[1]===void 0?"":"not "}called`]],js:[[/expect\(\s*([^()]+?(?:\([^()]*\))?)\s*\)\s*(\.not)?\s*\.(?:toHaveBeenCalledTimes|toBeCalledTimes)\(\s*([^)]*)\)/g,(e)=>`${e[1]} asserted ${e[2]===void 0?"":"not "}called ${e[3]} times`],[/expect\(\s*([^()]+?(?:\([^()]*\))?)\s*\)\s*(\.not)?\s*\.(?:toHaveBeenCalledWith|toBeCalledWith|toHaveBeenLastCalledWith|lastCalledWith)\(/g,(e)=>`${e[1]} asserted ${e[2]===void 0?"":"not "}called with specific arguments`],[/expect\(\s*([^()]+?(?:\([^()]*\))?)\s*\)\s*\.(?:toHaveBeenNthCalledWith|nthCalledWith)\(\s*(\w+)/g,(e)=>`arguments of call ${e[2]} to ${e[1]} asserted`],[/expect\(\s*([^()]+?(?:\([^()]*\))?)\s*\)\s*(\.not)?\s*\.(?:toHaveBeenCalled|toBeCalled)\(\s*\)/g,(e)=>`${e[1]} asserted ${e[2]===void 0?"":"not "}called`],[/([\w$.]+)\.mock\.(?:calls|results|lastCall)\b/g,(e)=>`calls to ${e[1]} inspected`],[/([\w$.]+)\.(calledOnce|calledTwice|calledThrice|calledWith\w*|callCount|notCalled|callOrder)\b/g,(e)=>`${e[1]}.${e[2]} checked`]],go:[[/\.AssertCalled\(\s*\w+\s*,\s*"(\w+)"/g,(e)=>`${e[1]} asserted called`],[/\.AssertNotCalled\(\s*\w+\s*,\s*"(\w+)"/g,(e)=>`${e[1]} asserted not called`],[/\.AssertNumberOfCalls\(\s*\w+\s*,\s*"(\w+)"\s*,\s*(\w+)/g,(e)=>`${e[1]} asserted called ${e[2]} times`],[/\.AssertExpectations\(/g,()=>"all expected mock calls asserted"],[/\.EXPECT\(\)\.(\w+)\([^\n]*?\.(Times|MinTimes|MaxTimes)\((\w+)\)/g,(e)=>`${e[1]} expected ${e[2]==="Times"?"":`${e[2]} `}${e[3]} times`]]},jc=[[/\b(requests|httpx|urllib\d?|urlopen|socket|aiohttp|fetch|axios|grpc|smtplib|boto3|botocore|websockets?|https?|HTTP)\b/i,"network"],[/\b(time|datetime|sleep|monotonic|now|utcnow|Date|setTimeout|setInterval|clock|timers?)\b/,"clock"],[/\b(open|os\.path|pathlib|Path|shutil|fs|tempfile|readFile\w*|writeFile\w*|glob)\b/,"filesystem"],[/\b(db|database|session|cursor|sql\w*|redis|mongo\w*|sqlite3|psycopg2?)\b/i,"database"],[/\b(subprocess|environ|env|environment|child_process|exec|spawn)\b/,"process or environment"],[/\b(random|uuid\d?|secrets|randomUUID)\b/,"randomness"]],Dc=(e)=>jc.find(([t])=>t.test(e))?.[1],vs=(e,t)=>{let n={touched:new Map,mocked:new Map,calls:new Map},r=(i,c,l)=>{let p=i.get(c)??[];if(!p.includes(l))i.set(c,[...p,l])};for(let i of t){let c=e.lines[i-1];for(let p of Mc(e,c))r(n.touched,p,i);let l=[c,...e.lines.slice(i,i+2)].join(`
308
+ `);for(let[p,a]of[[Lc,n.mocked],[Pc,n.calls]])for(let[f,d]of p[e.language])for(let h of l.matchAll(f))if(h.index<c.length)r(a,d(h),i)}let o=(i)=>`line${i.length>1?"s":""} ${i.join(", ")}`,s=(i,c=!1)=>dt([...i].map(([l,p])=>{let a=c?Dc(l):void 0;return`${l}${a===void 0?"":` [${a}: an external boundary]`} (${o(p)})`}),20)||"none found";return{private_members_touched:s(n.touched),mocks_and_patches:s(n.mocked,!0),assertions_on_calls:s(n.calls)}},As=async(e)=>{let[t,...n]=e;if(t!=="names"&&t!=="behavior")console.error(`tests: first argument must be names or behavior (got ${JSON.stringify(t)})`),process.exit(2);let r=await W("tests",n),o=[],s=new Map;for(let i of vc(r.filter((c)=>Es(c)!==void 0))){let c=Ss(i.file);s.set(c,[...s.get(c)??[],i])}for(let i of r){let c=Es(i);if(c===void 0)continue;let l=await Bun.file(i).text(),p=l.split(`
309
+ `),a=Oc(s.get(Ss(i))??[]),f=t==="behavior"?Ic(c,l):void 0,d=(u)=>a.filter((S)=>S.parent===u),h=(u)=>`${u.kind} ${JSON.stringify(u.name)}`;for(let u of a){let S=Pt(u).reverse().map((y)=>y.name).join(" > "),m=a.some((y)=>y!==u&&y.start===u.start&&y.bytes[0]<u.bytes[0])?`${i}:${u.start}+${u.bytes[0]}`:`${i}:${u.start}`,w=u.kind==="suite"&&c==="js";if(t==="names"){if(w)o.push(JSON.stringify({id:m,path:i,lines:[u.start,u.end],kind:"describe block: names a group of tests",suite:S,tests:dt(d(u).filter((b)=>b.kind!=="helper").map(h),30),text:u.name}));if(u.kind!=="test"&&u.kind!=="subtest")continue;let y=Rc(u,a),g=d(u).filter((b)=>b.kind==="subtest"),_=u.literal?u:u.parent??u,E=c==="go"&&(!u.literal||g.some((b)=>!b.literal))?[...p.slice(_.start-1,_.end).join(`
310
+ `).matchAll(/\b(?:name|desc|description|title|scenario)\s*:\s*("(?:[^"\\]|\\.)*"|`[^`]*`)/gi)].map((b)=>b[1]):[];o.push(JSON.stringify({id:m,path:i,lines:[u.start,u.end],kind:u.literal?u.kind:`subtest named per table row by \`${u.name}\` (the rows' names are in table_case_names)`,suite:S,subtests:dt(g.filter((b)=>b.literal).map((b)=>JSON.stringify(b.name)),30),table_case_names:dt(E,30),checks:dt(Tc(c,p,y).map((b)=>`${b}: ${p[b-1].trim()}`),25)||"no assertions found",text:u.name}))}else if(w||u.kind==="wrapper"){let y=d(u),g=[];for(let _=u.start+1;_<u.end;_++)if(p[_-1].trim()!==""&&!y.some((E)=>E.start<=_&&_<=E.end))g.push(_);if(u.kind==="wrapper"&&g.length===0)continue;o.push(JSON.stringify({id:m,path:i,lines:[u.start,u.end],role:`${w?"describe block":"function that declares tests"}; the evidence covers its own code, outside the tests, hooks, and helpers in it`,suite:S,...vs(f,g),text:p.slice(u.start-1,u.end).join(`
311
+ `)}))}else if(u.kind!=="suite"){let y=[];for(let g=u.start;g<=u.end;g++)y.push(g);o.push(JSON.stringify({id:m,path:i,lines:[u.start,u.end],role:u.kind==="test"?"test":u.kind==="subtest"?"subtest":"helper, fixture, or hook shared by tests",suite:S,...vs(f,y),text:p.slice(u.start-1,u.end).join(`
312
+ `)}))}}}if(o.length>0)await new Promise((i)=>process.stdout.write(`${o.join(`
313
+ `)}
314
+ `,()=>i()))};var Os=async(e)=>{let t=[];for(let n of await W("whole-file",e)){let r=await Bun.file(n).text();if(r.trim()==="")continue;let o=r.endsWith(`
315
+ `)?r.split(`
316
+ `).length-1:r.split(`
317
+ `).length;t.push(JSON.stringify({id:n,path:n,lines:[1,Math.max(1,o)],text:r}))}if(t.length>0)await new Promise((n)=>process.stdout.write(`${t.join(`
318
+ `)}
319
+ `,()=>n()))};var Uc={functions:ms,comments:Do,errors:Qo,"errors-go":Ko,literals:gs,"module-exports":ys,"module-state":$s,"module-outline":bs,tests:As,duplicates:qo,excerpts:es,"whole-file":Os,"file-role":ns,enclosing:Vo,blame:Po,present:ks},Wc=`usage: bun select.js <step> [options]
320
+
321
+ File cutters (read file paths on stdin, one per line; emit JSONL items):
322
+ functions [flags] TS/JS/Py/Go functions & methods (requires ast-grep)
323
+ flags: --min-lines N --chunk N --outer --named --module
324
+ --flags --no-call-items --classes N --globals
325
+ --context --docs --hidden --names --effects
326
+ comments contiguous comment blocks with up to 8 lines of following code
327
+ errors TS/JS/Py/Go error handlers + handled code + facts (ast-grep)
328
+ errors-go Go statements that may drop an error (ast-grep)
329
+ literals un-named magic numbers/strings + elsewhere uses (ast-grep)
330
+ module-exports public declarations + in-file references + module summary
331
+ module-state classes/structs with mutable fields & exposure facts
332
+ module-outline file outline: imports, top-level declarations, members
333
+ tests <names|behavior>
334
+ test units for naming or behavior-vs-implementation rules (ast-grep)
335
+ duplicates candidate pairs of similar/repeated blocks in a file
336
+ excerpts [bytes] consecutive excerpts of at most bytes (default: 1000)
337
+ whole-file one item per non-empty file
338
+
339
+ Pipe steps (read JSONL items on stdin; emit JSONL items):
340
+ file-role attach compact \`file role\` hints (test, wiring, utility, DTO)
341
+ enclosing attach \`enclosing\` block around each item's lines
342
+ blame [YYYY-MM-DD] attach \`changed\` git-blame date and age in days (default: today)
343
+ present [--no-lines]
344
+ render location & context fields into \`text\` (final step);
345
+ pass --no-lines to omit line numbers from \`text\` for cache hits
346
+
347
+ Example:
348
+ rg --files -g '*.{ts,tsx,js,py,go}' |
349
+ bun select.js functions --flags --no-call-items |
350
+ bun select.js file-role |
351
+ bun select.js present --no-lines`,[He,...Bc]=Bun.argv.slice(2);if(He===void 0||He==="--help"||He==="-h"||He==="help")console.log(Wc),process.exit(0);var Rs=Uc[He];if(Rs===void 0)console.error(`select.js: unknown step ${JSON.stringify(He)} (run with --help to list steps)`),process.exit(2);await Rs(Bc);