@tokmizer/plugin 0.9.51 → 0.9.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,43 +1,50 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire as __tkrCreateRequire } from "node:module"; const require = __tkrCreateRequire(import.meta.url);
3
- var hr=Object.defineProperty;var gr=(t,e)=>{for(var n in e)hr(t,n,{get:e[n],enumerable:!0})};import{readdir as As,readFile as Rs}from"node:fs/promises";import{join as Gt,dirname as Cs}from"node:path";import{fileURLToPath as Is}from"node:url";var m={};gr(m,{BRAND:()=>Zr,DIRTY:()=>ee,EMPTY_PATH:()=>vr,INVALID:()=>v,NEVER:()=>Ts,OK:()=>O,ParseStatus:()=>I,Schema:()=>w,ZodAny:()=>q,ZodArray:()=>W,ZodBigInt:()=>ne,ZodBoolean:()=>re,ZodBranded:()=>De,ZodCatch:()=>me,ZodDate:()=>se,ZodDefault:()=>pe,ZodDiscriminatedUnion:()=>Ke,ZodEffects:()=>L,ZodEnum:()=>de,ZodError:()=>D,ZodFirstPartyTypeKind:()=>x,ZodFunction:()=>Ge,ZodIntersection:()=>ce,ZodIssueCode:()=>p,ZodLazy:()=>le,ZodLiteral:()=>ue,ZodMap:()=>ke,ZodNaN:()=>we,ZodNativeEnum:()=>fe,ZodNever:()=>F,ZodNull:()=>oe,ZodNullable:()=>U,ZodNumber:()=>te,ZodObject:()=>N,ZodOptional:()=>P,ZodParsedType:()=>y,ZodPipeline:()=>Ne,ZodPromise:()=>J,ZodReadonly:()=>he,ZodRecord:()=>We,ZodSchema:()=>w,ZodSet:()=>Ee,ZodString:()=>Y,ZodSymbol:()=>ve,ZodTransformer:()=>L,ZodTuple:()=>Z,ZodType:()=>w,ZodUndefined:()=>ie,ZodUnion:()=>ae,ZodUnknown:()=>K,ZodVoid:()=>xe,addIssueToContext:()=>h,any:()=>Jr,array:()=>ts,bigint:()=>Kr,boolean:()=>Vt,coerce:()=>Ss,custom:()=>Zt,date:()=>Wr,datetimeRegex:()=>Bt,defaultErrorMap:()=>H,discriminatedUnion:()=>is,effect:()=>ys,enum:()=>ms,function:()=>ds,getErrorMap:()=>ye,getParsedType:()=>z,instanceof:()=>Hr,intersection:()=>os,isAborted:()=>He,isAsync:()=>_e,isDirty:()=>Ve,isValid:()=>G,late:()=>Ur,lazy:()=>fs,literal:()=>ps,makeIssue:()=>Oe,map:()=>ls,nan:()=>Vr,nativeEnum:()=>hs,never:()=>Qr,null:()=>qr,nullable:()=>bs,number:()=>Ht,object:()=>ns,objectUtil:()=>rt,oboolean:()=>ws,onumber:()=>Es,optional:()=>_s,ostring:()=>ks,pipeline:()=>xs,preprocess:()=>vs,promise:()=>gs,quotelessJson:()=>yr,record:()=>cs,set:()=>us,setErrorMap:()=>br,strictObject:()=>rs,string:()=>Ut,symbol:()=>Gr,transformer:()=>ys,tuple:()=>as,undefined:()=>Yr,union:()=>ss,unknown:()=>Xr,util:()=>S,void:()=>es});var S;(function(t){t.assertEqual=s=>{};function e(s){}t.assertIs=e;function n(s){throw new Error}t.assertNever=n,t.arrayToEnum=s=>{let i={};for(let o of s)i[o]=o;return i},t.getValidEnumValues=s=>{let i=t.objectKeys(s).filter(a=>typeof s[s[a]]!="number"),o={};for(let a of i)o[a]=s[a];return t.objectValues(o)},t.objectValues=s=>t.objectKeys(s).map(function(i){return s[i]}),t.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{let i=[];for(let o in s)Object.prototype.hasOwnProperty.call(s,o)&&i.push(o);return i},t.find=(s,i)=>{for(let o of s)if(i(o))return o},t.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&Number.isFinite(s)&&Math.floor(s)===s;function r(s,i=" | "){return s.map(o=>typeof o=="string"?`'${o}'`:o).join(i)}t.joinValues=r,t.jsonStringifyReplacer=(s,i)=>typeof i=="bigint"?i.toString():i})(S||(S={}));var rt;(function(t){t.mergeShapes=(e,n)=>({...e,...n})})(rt||(rt={}));var y=S.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),z=t=>{switch(typeof t){case"undefined":return y.undefined;case"string":return y.string;case"number":return Number.isNaN(t)?y.nan:y.number;case"boolean":return y.boolean;case"function":return y.function;case"bigint":return y.bigint;case"symbol":return y.symbol;case"object":return Array.isArray(t)?y.array:t===null?y.null:t.then&&typeof t.then=="function"&&t.catch&&typeof t.catch=="function"?y.promise:typeof Map<"u"&&t instanceof Map?y.map:typeof Set<"u"&&t instanceof Set?y.set:typeof Date<"u"&&t instanceof Date?y.date:y.object;default:return y.unknown}};var p=S.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),yr=t=>JSON.stringify(t,null,2).replace(/"([^"]+)":/g,"$1:"),D=class t extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};let n=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,n):this.__proto__=n,this.name="ZodError",this.issues=e}format(e){let n=e||function(i){return i.message},r={_errors:[]},s=i=>{for(let o of i.issues)if(o.code==="invalid_union")o.unionErrors.map(s);else if(o.code==="invalid_return_type")s(o.returnTypeError);else if(o.code==="invalid_arguments")s(o.argumentsError);else if(o.path.length===0)r._errors.push(n(o));else{let a=r,l=0;for(;l<o.path.length;){let u=o.path[l];l===o.path.length-1?(a[u]=a[u]||{_errors:[]},a[u]._errors.push(n(o))):a[u]=a[u]||{_errors:[]},a=a[u],l++}}};return s(this),r}static assert(e){if(!(e instanceof t))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,S.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=n=>n.message){let n={},r=[];for(let s of this.issues)if(s.path.length>0){let i=s.path[0];n[i]=n[i]||[],n[i].push(e(s))}else r.push(e(s));return{formErrors:r,fieldErrors:n}}get formErrors(){return this.flatten()}};D.create=t=>new D(t);var _r=(t,e)=>{let n;switch(t.code){case p.invalid_type:t.received===y.undefined?n="Required":n=`Expected ${t.expected}, received ${t.received}`;break;case p.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(t.expected,S.jsonStringifyReplacer)}`;break;case p.unrecognized_keys:n=`Unrecognized key(s) in object: ${S.joinValues(t.keys,", ")}`;break;case p.invalid_union:n="Invalid input";break;case p.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${S.joinValues(t.options)}`;break;case p.invalid_enum_value:n=`Invalid enum value. Expected ${S.joinValues(t.options)}, received '${t.received}'`;break;case p.invalid_arguments:n="Invalid function arguments";break;case p.invalid_return_type:n="Invalid function return type";break;case p.invalid_date:n="Invalid date";break;case p.invalid_string:typeof t.validation=="object"?"includes"in t.validation?(n=`Invalid input: must include "${t.validation.includes}"`,typeof t.validation.position=="number"&&(n=`${n} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?n=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?n=`Invalid input: must end with "${t.validation.endsWith}"`:S.assertNever(t.validation):t.validation!=="regex"?n=`Invalid ${t.validation}`:n="Invalid";break;case p.too_small:t.type==="array"?n=`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:t.type==="string"?n=`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:t.type==="number"?n=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="bigint"?n=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="date"?n=`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:n="Invalid input";break;case p.too_big:t.type==="array"?n=`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:t.type==="string"?n=`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:t.type==="number"?n=`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="bigint"?n=`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="date"?n=`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:n="Invalid input";break;case p.custom:n="Invalid input";break;case p.invalid_intersection_types:n="Intersection results could not be merged";break;case p.not_multiple_of:n=`Number must be a multiple of ${t.multipleOf}`;break;case p.not_finite:n="Number must be finite";break;default:n=e.defaultError,S.assertNever(t)}return{message:n}},H=_r;var Pt=H;function br(t){Pt=t}function ye(){return Pt}var Oe=t=>{let{data:e,path:n,errorMaps:r,issueData:s}=t,i=[...n,...s.path||[]],o={...s,path:i};if(s.message!==void 0)return{...s,path:i,message:s.message};let a="",l=r.filter(u=>!!u).slice().reverse();for(let u of l)a=u(o,{data:e,defaultError:a}).message;return{...s,path:i,message:a}},vr=[];function h(t,e){let n=ye(),r=Oe({issueData:e,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,n,n===H?void 0:H].filter(s=>!!s)});t.common.issues.push(r)}var I=class t{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,n){let r=[];for(let s of n){if(s.status==="aborted")return v;s.status==="dirty"&&e.dirty(),r.push(s.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,n){let r=[];for(let s of n){let i=await s.key,o=await s.value;r.push({key:i,value:o})}return t.mergeObjectSync(e,r)}static mergeObjectSync(e,n){let r={};for(let s of n){let{key:i,value:o}=s;if(i.status==="aborted"||o.status==="aborted")return v;i.status==="dirty"&&e.dirty(),o.status==="dirty"&&e.dirty(),i.value!=="__proto__"&&(typeof o.value<"u"||s.alwaysSet)&&(r[i.value]=o.value)}return{status:e.value,value:r}}},v=Object.freeze({status:"aborted"}),ee=t=>({status:"dirty",value:t}),O=t=>({status:"valid",value:t}),He=t=>t.status==="aborted",Ve=t=>t.status==="dirty",G=t=>t.status==="valid",_e=t=>typeof Promise<"u"&&t instanceof Promise;var b;(function(t){t.errToObj=e=>typeof e=="string"?{message:e}:e||{},t.toString=e=>typeof e=="string"?e:e?.message})(b||(b={}));var M=class{constructor(e,n,r,s){this._cachedPath=[],this.parent=e,this.data=n,this._path=r,this._key=s}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}},Mt=(t,e)=>{if(G(e))return{success:!0,data:e.value};if(!t.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;let n=new D(t.common.issues);return this._error=n,this._error}}};function E(t){if(!t)return{};let{errorMap:e,invalid_type_error:n,required_error:r,description:s}=t;if(e&&(n||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:s}:{errorMap:(o,a)=>{let{message:l}=t;return o.code==="invalid_enum_value"?{message:l??a.defaultError}:typeof a.data>"u"?{message:l??r??a.defaultError}:o.code!=="invalid_type"?{message:a.defaultError}:{message:l??n??a.defaultError}},description:s}}var w=class{get description(){return this._def.description}_getType(e){return z(e.data)}_getOrReturnCtx(e,n){return n||{common:e.parent.common,data:e.data,parsedType:z(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new I,ctx:{common:e.parent.common,data:e.data,parsedType:z(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){let n=this._parse(e);if(_e(n))throw new Error("Synchronous parse encountered promise.");return n}_parseAsync(e){let n=this._parse(e);return Promise.resolve(n)}parse(e,n){let r=this.safeParse(e,n);if(r.success)return r.data;throw r.error}safeParse(e,n){let r={common:{issues:[],async:n?.async??!1,contextualErrorMap:n?.errorMap},path:n?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:z(e)},s=this._parseSync({data:e,path:r.path,parent:r});return Mt(r,s)}"~validate"(e){let n={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:z(e)};if(!this["~standard"].async)try{let r=this._parseSync({data:e,path:[],parent:n});return G(r)?{value:r.value}:{issues:n.common.issues}}catch(r){r?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),n.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:n}).then(r=>G(r)?{value:r.value}:{issues:n.common.issues})}async parseAsync(e,n){let r=await this.safeParseAsync(e,n);if(r.success)return r.data;throw r.error}async safeParseAsync(e,n){let r={common:{issues:[],contextualErrorMap:n?.errorMap,async:!0},path:n?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:z(e)},s=this._parse({data:e,path:r.path,parent:r}),i=await(_e(s)?s:Promise.resolve(s));return Mt(r,i)}refine(e,n){let r=s=>typeof n=="string"||typeof n>"u"?{message:n}:typeof n=="function"?n(s):n;return this._refinement((s,i)=>{let o=e(s),a=()=>i.addIssue({code:p.custom,...r(s)});return typeof Promise<"u"&&o instanceof Promise?o.then(l=>l?!0:(a(),!1)):o?!0:(a(),!1)})}refinement(e,n){return this._refinement((r,s)=>e(r)?!0:(s.addIssue(typeof n=="function"?n(r,s):n),!1))}_refinement(e){return new L({schema:this,typeName:x.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:n=>this["~validate"](n)}}optional(){return P.create(this,this._def)}nullable(){return U.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return W.create(this)}promise(){return J.create(this,this._def)}or(e){return ae.create([this,e],this._def)}and(e){return ce.create(this,e,this._def)}transform(e){return new L({...E(this._def),schema:this,typeName:x.ZodEffects,effect:{type:"transform",transform:e}})}default(e){let n=typeof e=="function"?e:()=>e;return new pe({...E(this._def),innerType:this,defaultValue:n,typeName:x.ZodDefault})}brand(){return new De({typeName:x.ZodBranded,type:this,...E(this._def)})}catch(e){let n=typeof e=="function"?e:()=>e;return new me({...E(this._def),innerType:this,catchValue:n,typeName:x.ZodCatch})}describe(e){let n=this.constructor;return new n({...this._def,description:e})}pipe(e){return Ne.create(this,e)}readonly(){return he.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}},xr=/^c[^\s-]{8,}$/i,kr=/^[0-9a-z]+$/,Er=/^[0-9A-HJKMNP-TV-Z]{26}$/i,wr=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,Sr=/^[a-z0-9_-]{21}$/i,Tr=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Ar=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,Rr=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Cr="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",st,Ir=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Or=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,Dr=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,Nr=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,$r=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Pr=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,Ft="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",Mr=new RegExp(`^${Ft}$`);function jt(t){let e="[0-5]\\d";t.precision?e=`${e}\\.\\d{${t.precision}}`:t.precision==null&&(e=`${e}(\\.\\d+)?`);let n=t.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${n}`}function Lr(t){return new RegExp(`^${jt(t)}$`)}function Bt(t){let e=`${Ft}T${jt(t)}`,n=[];return n.push(t.local?"Z?":"Z"),t.offset&&n.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${n.join("|")})`,new RegExp(`^${e}$`)}function Fr(t,e){return!!((e==="v4"||!e)&&Ir.test(t)||(e==="v6"||!e)&&Dr.test(t))}function jr(t,e){if(!Tr.test(t))return!1;try{let[n]=t.split(".");if(!n)return!1;let r=n.replace(/-/g,"+").replace(/_/g,"/").padEnd(n.length+(4-n.length%4)%4,"="),s=JSON.parse(atob(r));return!(typeof s!="object"||s===null||"typ"in s&&s?.typ!=="JWT"||!s.alg||e&&s.alg!==e)}catch{return!1}}function Br(t,e){return!!((e==="v4"||!e)&&Or.test(t)||(e==="v6"||!e)&&Nr.test(t))}var Y=class t extends w{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==y.string){let i=this._getOrReturnCtx(e);return h(i,{code:p.invalid_type,expected:y.string,received:i.parsedType}),v}let r=new I,s;for(let i of this._def.checks)if(i.kind==="min")e.data.length<i.value&&(s=this._getOrReturnCtx(e,s),h(s,{code:p.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),r.dirty());else if(i.kind==="max")e.data.length>i.value&&(s=this._getOrReturnCtx(e,s),h(s,{code:p.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),r.dirty());else if(i.kind==="length"){let o=e.data.length>i.value,a=e.data.length<i.value;(o||a)&&(s=this._getOrReturnCtx(e,s),o?h(s,{code:p.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}):a&&h(s,{code:p.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}),r.dirty())}else if(i.kind==="email")Rr.test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"email",code:p.invalid_string,message:i.message}),r.dirty());else if(i.kind==="emoji")st||(st=new RegExp(Cr,"u")),st.test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"emoji",code:p.invalid_string,message:i.message}),r.dirty());else if(i.kind==="uuid")wr.test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"uuid",code:p.invalid_string,message:i.message}),r.dirty());else if(i.kind==="nanoid")Sr.test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"nanoid",code:p.invalid_string,message:i.message}),r.dirty());else if(i.kind==="cuid")xr.test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"cuid",code:p.invalid_string,message:i.message}),r.dirty());else if(i.kind==="cuid2")kr.test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"cuid2",code:p.invalid_string,message:i.message}),r.dirty());else if(i.kind==="ulid")Er.test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"ulid",code:p.invalid_string,message:i.message}),r.dirty());else if(i.kind==="url")try{new URL(e.data)}catch{s=this._getOrReturnCtx(e,s),h(s,{validation:"url",code:p.invalid_string,message:i.message}),r.dirty()}else i.kind==="regex"?(i.regex.lastIndex=0,i.regex.test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"regex",code:p.invalid_string,message:i.message}),r.dirty())):i.kind==="trim"?e.data=e.data.trim():i.kind==="includes"?e.data.includes(i.value,i.position)||(s=this._getOrReturnCtx(e,s),h(s,{code:p.invalid_string,validation:{includes:i.value,position:i.position},message:i.message}),r.dirty()):i.kind==="toLowerCase"?e.data=e.data.toLowerCase():i.kind==="toUpperCase"?e.data=e.data.toUpperCase():i.kind==="startsWith"?e.data.startsWith(i.value)||(s=this._getOrReturnCtx(e,s),h(s,{code:p.invalid_string,validation:{startsWith:i.value},message:i.message}),r.dirty()):i.kind==="endsWith"?e.data.endsWith(i.value)||(s=this._getOrReturnCtx(e,s),h(s,{code:p.invalid_string,validation:{endsWith:i.value},message:i.message}),r.dirty()):i.kind==="datetime"?Bt(i).test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{code:p.invalid_string,validation:"datetime",message:i.message}),r.dirty()):i.kind==="date"?Mr.test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{code:p.invalid_string,validation:"date",message:i.message}),r.dirty()):i.kind==="time"?Lr(i).test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{code:p.invalid_string,validation:"time",message:i.message}),r.dirty()):i.kind==="duration"?Ar.test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"duration",code:p.invalid_string,message:i.message}),r.dirty()):i.kind==="ip"?Fr(e.data,i.version)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"ip",code:p.invalid_string,message:i.message}),r.dirty()):i.kind==="jwt"?jr(e.data,i.alg)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"jwt",code:p.invalid_string,message:i.message}),r.dirty()):i.kind==="cidr"?Br(e.data,i.version)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"cidr",code:p.invalid_string,message:i.message}),r.dirty()):i.kind==="base64"?$r.test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"base64",code:p.invalid_string,message:i.message}),r.dirty()):i.kind==="base64url"?Pr.test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"base64url",code:p.invalid_string,message:i.message}),r.dirty()):S.assertNever(i);return{status:r.value,value:e.data}}_regex(e,n,r){return this.refinement(s=>e.test(s),{validation:n,code:p.invalid_string,...b.errToObj(r)})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...b.errToObj(e)})}url(e){return this._addCheck({kind:"url",...b.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...b.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...b.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...b.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...b.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...b.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...b.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...b.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...b.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...b.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...b.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...b.errToObj(e)})}datetime(e){return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof e?.precision>"u"?null:e?.precision,offset:e?.offset??!1,local:e?.local??!1,...b.errToObj(e?.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof e?.precision>"u"?null:e?.precision,...b.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...b.errToObj(e)})}regex(e,n){return this._addCheck({kind:"regex",regex:e,...b.errToObj(n)})}includes(e,n){return this._addCheck({kind:"includes",value:e,position:n?.position,...b.errToObj(n?.message)})}startsWith(e,n){return this._addCheck({kind:"startsWith",value:e,...b.errToObj(n)})}endsWith(e,n){return this._addCheck({kind:"endsWith",value:e,...b.errToObj(n)})}min(e,n){return this._addCheck({kind:"min",value:e,...b.errToObj(n)})}max(e,n){return this._addCheck({kind:"max",value:e,...b.errToObj(n)})}length(e,n){return this._addCheck({kind:"length",value:e,...b.errToObj(n)})}nonempty(e){return this.min(1,b.errToObj(e))}trim(){return new t({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new t({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new t({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isCIDR(){return!!this._def.checks.find(e=>e.kind==="cidr")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get isBase64url(){return!!this._def.checks.find(e=>e.kind==="base64url")}get minLength(){let e=null;for(let n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxLength(){let e=null;for(let n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}};Y.create=t=>new Y({checks:[],typeName:x.ZodString,coerce:t?.coerce??!1,...E(t)});function zr(t,e){let n=(t.toString().split(".")[1]||"").length,r=(e.toString().split(".")[1]||"").length,s=n>r?n:r,i=Number.parseInt(t.toFixed(s).replace(".","")),o=Number.parseInt(e.toFixed(s).replace(".",""));return i%o/10**s}var te=class t extends w{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==y.number){let i=this._getOrReturnCtx(e);return h(i,{code:p.invalid_type,expected:y.number,received:i.parsedType}),v}let r,s=new I;for(let i of this._def.checks)i.kind==="int"?S.isInteger(e.data)||(r=this._getOrReturnCtx(e,r),h(r,{code:p.invalid_type,expected:"integer",received:"float",message:i.message}),s.dirty()):i.kind==="min"?(i.inclusive?e.data<i.value:e.data<=i.value)&&(r=this._getOrReturnCtx(e,r),h(r,{code:p.too_small,minimum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),s.dirty()):i.kind==="max"?(i.inclusive?e.data>i.value:e.data>=i.value)&&(r=this._getOrReturnCtx(e,r),h(r,{code:p.too_big,maximum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),s.dirty()):i.kind==="multipleOf"?zr(e.data,i.value)!==0&&(r=this._getOrReturnCtx(e,r),h(r,{code:p.not_multiple_of,multipleOf:i.value,message:i.message}),s.dirty()):i.kind==="finite"?Number.isFinite(e.data)||(r=this._getOrReturnCtx(e,r),h(r,{code:p.not_finite,message:i.message}),s.dirty()):S.assertNever(i);return{status:s.value,value:e.data}}gte(e,n){return this.setLimit("min",e,!0,b.toString(n))}gt(e,n){return this.setLimit("min",e,!1,b.toString(n))}lte(e,n){return this.setLimit("max",e,!0,b.toString(n))}lt(e,n){return this.setLimit("max",e,!1,b.toString(n))}setLimit(e,n,r,s){return new t({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:r,message:b.toString(s)}]})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:b.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:b.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:b.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:b.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:b.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:b.toString(n)})}finite(e){return this._addCheck({kind:"finite",message:b.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:b.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:b.toString(e)})}get minValue(){let e=null;for(let n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxValue(){let e=null;for(let n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&S.isInteger(e.value))}get isFinite(){let e=null,n=null;for(let r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(n===null||r.value>n)&&(n=r.value):r.kind==="max"&&(e===null||r.value<e)&&(e=r.value)}return Number.isFinite(n)&&Number.isFinite(e)}};te.create=t=>new te({checks:[],typeName:x.ZodNumber,coerce:t?.coerce||!1,...E(t)});var ne=class t extends w{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==y.bigint)return this._getInvalidInput(e);let r,s=new I;for(let i of this._def.checks)i.kind==="min"?(i.inclusive?e.data<i.value:e.data<=i.value)&&(r=this._getOrReturnCtx(e,r),h(r,{code:p.too_small,type:"bigint",minimum:i.value,inclusive:i.inclusive,message:i.message}),s.dirty()):i.kind==="max"?(i.inclusive?e.data>i.value:e.data>=i.value)&&(r=this._getOrReturnCtx(e,r),h(r,{code:p.too_big,type:"bigint",maximum:i.value,inclusive:i.inclusive,message:i.message}),s.dirty()):i.kind==="multipleOf"?e.data%i.value!==BigInt(0)&&(r=this._getOrReturnCtx(e,r),h(r,{code:p.not_multiple_of,multipleOf:i.value,message:i.message}),s.dirty()):S.assertNever(i);return{status:s.value,value:e.data}}_getInvalidInput(e){let n=this._getOrReturnCtx(e);return h(n,{code:p.invalid_type,expected:y.bigint,received:n.parsedType}),v}gte(e,n){return this.setLimit("min",e,!0,b.toString(n))}gt(e,n){return this.setLimit("min",e,!1,b.toString(n))}lte(e,n){return this.setLimit("max",e,!0,b.toString(n))}lt(e,n){return this.setLimit("max",e,!1,b.toString(n))}setLimit(e,n,r,s){return new t({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:r,message:b.toString(s)}]})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:b.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:b.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:b.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:b.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:b.toString(n)})}get minValue(){let e=null;for(let n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxValue(){let e=null;for(let n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}};ne.create=t=>new ne({checks:[],typeName:x.ZodBigInt,coerce:t?.coerce??!1,...E(t)});var re=class extends w{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==y.boolean){let r=this._getOrReturnCtx(e);return h(r,{code:p.invalid_type,expected:y.boolean,received:r.parsedType}),v}return O(e.data)}};re.create=t=>new re({typeName:x.ZodBoolean,coerce:t?.coerce||!1,...E(t)});var se=class t extends w{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==y.date){let i=this._getOrReturnCtx(e);return h(i,{code:p.invalid_type,expected:y.date,received:i.parsedType}),v}if(Number.isNaN(e.data.getTime())){let i=this._getOrReturnCtx(e);return h(i,{code:p.invalid_date}),v}let r=new I,s;for(let i of this._def.checks)i.kind==="min"?e.data.getTime()<i.value&&(s=this._getOrReturnCtx(e,s),h(s,{code:p.too_small,message:i.message,inclusive:!0,exact:!1,minimum:i.value,type:"date"}),r.dirty()):i.kind==="max"?e.data.getTime()>i.value&&(s=this._getOrReturnCtx(e,s),h(s,{code:p.too_big,message:i.message,inclusive:!0,exact:!1,maximum:i.value,type:"date"}),r.dirty()):S.assertNever(i);return{status:r.value,value:new Date(e.data.getTime())}}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}min(e,n){return this._addCheck({kind:"min",value:e.getTime(),message:b.toString(n)})}max(e,n){return this._addCheck({kind:"max",value:e.getTime(),message:b.toString(n)})}get minDate(){let e=null;for(let n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(let n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e!=null?new Date(e):null}};se.create=t=>new se({checks:[],coerce:t?.coerce||!1,typeName:x.ZodDate,...E(t)});var ve=class extends w{_parse(e){if(this._getType(e)!==y.symbol){let r=this._getOrReturnCtx(e);return h(r,{code:p.invalid_type,expected:y.symbol,received:r.parsedType}),v}return O(e.data)}};ve.create=t=>new ve({typeName:x.ZodSymbol,...E(t)});var ie=class extends w{_parse(e){if(this._getType(e)!==y.undefined){let r=this._getOrReturnCtx(e);return h(r,{code:p.invalid_type,expected:y.undefined,received:r.parsedType}),v}return O(e.data)}};ie.create=t=>new ie({typeName:x.ZodUndefined,...E(t)});var oe=class extends w{_parse(e){if(this._getType(e)!==y.null){let r=this._getOrReturnCtx(e);return h(r,{code:p.invalid_type,expected:y.null,received:r.parsedType}),v}return O(e.data)}};oe.create=t=>new oe({typeName:x.ZodNull,...E(t)});var q=class extends w{constructor(){super(...arguments),this._any=!0}_parse(e){return O(e.data)}};q.create=t=>new q({typeName:x.ZodAny,...E(t)});var K=class extends w{constructor(){super(...arguments),this._unknown=!0}_parse(e){return O(e.data)}};K.create=t=>new K({typeName:x.ZodUnknown,...E(t)});var F=class extends w{_parse(e){let n=this._getOrReturnCtx(e);return h(n,{code:p.invalid_type,expected:y.never,received:n.parsedType}),v}};F.create=t=>new F({typeName:x.ZodNever,...E(t)});var xe=class extends w{_parse(e){if(this._getType(e)!==y.undefined){let r=this._getOrReturnCtx(e);return h(r,{code:p.invalid_type,expected:y.void,received:r.parsedType}),v}return O(e.data)}};xe.create=t=>new xe({typeName:x.ZodVoid,...E(t)});var W=class t extends w{_parse(e){let{ctx:n,status:r}=this._processInputParams(e),s=this._def;if(n.parsedType!==y.array)return h(n,{code:p.invalid_type,expected:y.array,received:n.parsedType}),v;if(s.exactLength!==null){let o=n.data.length>s.exactLength.value,a=n.data.length<s.exactLength.value;(o||a)&&(h(n,{code:o?p.too_big:p.too_small,minimum:a?s.exactLength.value:void 0,maximum:o?s.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:s.exactLength.message}),r.dirty())}if(s.minLength!==null&&n.data.length<s.minLength.value&&(h(n,{code:p.too_small,minimum:s.minLength.value,type:"array",inclusive:!0,exact:!1,message:s.minLength.message}),r.dirty()),s.maxLength!==null&&n.data.length>s.maxLength.value&&(h(n,{code:p.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),r.dirty()),n.common.async)return Promise.all([...n.data].map((o,a)=>s.type._parseAsync(new M(n,o,n.path,a)))).then(o=>I.mergeArray(r,o));let i=[...n.data].map((o,a)=>s.type._parseSync(new M(n,o,n.path,a)));return I.mergeArray(r,i)}get element(){return this._def.type}min(e,n){return new t({...this._def,minLength:{value:e,message:b.toString(n)}})}max(e,n){return new t({...this._def,maxLength:{value:e,message:b.toString(n)}})}length(e,n){return new t({...this._def,exactLength:{value:e,message:b.toString(n)}})}nonempty(e){return this.min(1,e)}};W.create=(t,e)=>new W({type:t,minLength:null,maxLength:null,exactLength:null,typeName:x.ZodArray,...E(e)});function be(t){if(t instanceof N){let e={};for(let n in t.shape){let r=t.shape[n];e[n]=P.create(be(r))}return new N({...t._def,shape:()=>e})}else return t instanceof W?new W({...t._def,type:be(t.element)}):t instanceof P?P.create(be(t.unwrap())):t instanceof U?U.create(be(t.unwrap())):t instanceof Z?Z.create(t.items.map(e=>be(e))):t}var N=class t extends w{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;let e=this._def.shape(),n=S.objectKeys(e);return this._cached={shape:e,keys:n},this._cached}_parse(e){if(this._getType(e)!==y.object){let u=this._getOrReturnCtx(e);return h(u,{code:p.invalid_type,expected:y.object,received:u.parsedType}),v}let{status:r,ctx:s}=this._processInputParams(e),{shape:i,keys:o}=this._getCached(),a=[];if(!(this._def.catchall instanceof F&&this._def.unknownKeys==="strip"))for(let u in s.data)o.includes(u)||a.push(u);let l=[];for(let u of o){let d=i[u],f=s.data[u];l.push({key:{status:"valid",value:u},value:d._parse(new M(s,f,s.path,u)),alwaysSet:u in s.data})}if(this._def.catchall instanceof F){let u=this._def.unknownKeys;if(u==="passthrough")for(let d of a)l.push({key:{status:"valid",value:d},value:{status:"valid",value:s.data[d]}});else if(u==="strict")a.length>0&&(h(s,{code:p.unrecognized_keys,keys:a}),r.dirty());else if(u!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{let u=this._def.catchall;for(let d of a){let f=s.data[d];l.push({key:{status:"valid",value:d},value:u._parse(new M(s,f,s.path,d)),alwaysSet:d in s.data})}}return s.common.async?Promise.resolve().then(async()=>{let u=[];for(let d of l){let f=await d.key,c=await d.value;u.push({key:f,value:c,alwaysSet:d.alwaysSet})}return u}).then(u=>I.mergeObjectSync(r,u)):I.mergeObjectSync(r,l)}get shape(){return this._def.shape()}strict(e){return b.errToObj,new t({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(n,r)=>{let s=this._def.errorMap?.(n,r).message??r.defaultError;return n.code==="unrecognized_keys"?{message:b.errToObj(e).message??s}:{message:s}}}:{}})}strip(){return new t({...this._def,unknownKeys:"strip"})}passthrough(){return new t({...this._def,unknownKeys:"passthrough"})}extend(e){return new t({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new t({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:x.ZodObject})}setKey(e,n){return this.augment({[e]:n})}catchall(e){return new t({...this._def,catchall:e})}pick(e){let n={};for(let r of S.objectKeys(e))e[r]&&this.shape[r]&&(n[r]=this.shape[r]);return new t({...this._def,shape:()=>n})}omit(e){let n={};for(let r of S.objectKeys(this.shape))e[r]||(n[r]=this.shape[r]);return new t({...this._def,shape:()=>n})}deepPartial(){return be(this)}partial(e){let n={};for(let r of S.objectKeys(this.shape)){let s=this.shape[r];e&&!e[r]?n[r]=s:n[r]=s.optional()}return new t({...this._def,shape:()=>n})}required(e){let n={};for(let r of S.objectKeys(this.shape))if(e&&!e[r])n[r]=this.shape[r];else{let i=this.shape[r];for(;i instanceof P;)i=i._def.innerType;n[r]=i}return new t({...this._def,shape:()=>n})}keyof(){return zt(S.objectKeys(this.shape))}};N.create=(t,e)=>new N({shape:()=>t,unknownKeys:"strip",catchall:F.create(),typeName:x.ZodObject,...E(e)});N.strictCreate=(t,e)=>new N({shape:()=>t,unknownKeys:"strict",catchall:F.create(),typeName:x.ZodObject,...E(e)});N.lazycreate=(t,e)=>new N({shape:t,unknownKeys:"strip",catchall:F.create(),typeName:x.ZodObject,...E(e)});var ae=class extends w{_parse(e){let{ctx:n}=this._processInputParams(e),r=this._def.options;function s(i){for(let a of i)if(a.result.status==="valid")return a.result;for(let a of i)if(a.result.status==="dirty")return n.common.issues.push(...a.ctx.common.issues),a.result;let o=i.map(a=>new D(a.ctx.common.issues));return h(n,{code:p.invalid_union,unionErrors:o}),v}if(n.common.async)return Promise.all(r.map(async i=>{let o={...n,common:{...n.common,issues:[]},parent:null};return{result:await i._parseAsync({data:n.data,path:n.path,parent:o}),ctx:o}})).then(s);{let i,o=[];for(let l of r){let u={...n,common:{...n.common,issues:[]},parent:null},d=l._parseSync({data:n.data,path:n.path,parent:u});if(d.status==="valid")return d;d.status==="dirty"&&!i&&(i={result:d,ctx:u}),u.common.issues.length&&o.push(u.common.issues)}if(i)return n.common.issues.push(...i.ctx.common.issues),i.result;let a=o.map(l=>new D(l));return h(n,{code:p.invalid_union,unionErrors:a}),v}}get options(){return this._def.options}};ae.create=(t,e)=>new ae({options:t,typeName:x.ZodUnion,...E(e)});var V=t=>t instanceof le?V(t.schema):t instanceof L?V(t.innerType()):t instanceof ue?[t.value]:t instanceof de?t.options:t instanceof fe?S.objectValues(t.enum):t instanceof pe?V(t._def.innerType):t instanceof ie?[void 0]:t instanceof oe?[null]:t instanceof P?[void 0,...V(t.unwrap())]:t instanceof U?[null,...V(t.unwrap())]:t instanceof De||t instanceof he?V(t.unwrap()):t instanceof me?V(t._def.innerType):[],Ke=class t extends w{_parse(e){let{ctx:n}=this._processInputParams(e);if(n.parsedType!==y.object)return h(n,{code:p.invalid_type,expected:y.object,received:n.parsedType}),v;let r=this.discriminator,s=n.data[r],i=this.optionsMap.get(s);return i?n.common.async?i._parseAsync({data:n.data,path:n.path,parent:n}):i._parseSync({data:n.data,path:n.path,parent:n}):(h(n,{code:p.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),v)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,n,r){let s=new Map;for(let i of n){let o=V(i.shape[e]);if(!o.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(let a of o){if(s.has(a))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(a)}`);s.set(a,i)}}return new t({typeName:x.ZodDiscriminatedUnion,discriminator:e,options:n,optionsMap:s,...E(r)})}};function it(t,e){let n=z(t),r=z(e);if(t===e)return{valid:!0,data:t};if(n===y.object&&r===y.object){let s=S.objectKeys(e),i=S.objectKeys(t).filter(a=>s.indexOf(a)!==-1),o={...t,...e};for(let a of i){let l=it(t[a],e[a]);if(!l.valid)return{valid:!1};o[a]=l.data}return{valid:!0,data:o}}else if(n===y.array&&r===y.array){if(t.length!==e.length)return{valid:!1};let s=[];for(let i=0;i<t.length;i++){let o=t[i],a=e[i],l=it(o,a);if(!l.valid)return{valid:!1};s.push(l.data)}return{valid:!0,data:s}}else return n===y.date&&r===y.date&&+t==+e?{valid:!0,data:t}:{valid:!1}}var ce=class extends w{_parse(e){let{status:n,ctx:r}=this._processInputParams(e),s=(i,o)=>{if(He(i)||He(o))return v;let a=it(i.value,o.value);return a.valid?((Ve(i)||Ve(o))&&n.dirty(),{status:n.value,value:a.data}):(h(r,{code:p.invalid_intersection_types}),v)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([i,o])=>s(i,o)):s(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}};ce.create=(t,e,n)=>new ce({left:t,right:e,typeName:x.ZodIntersection,...E(n)});var Z=class t extends w{_parse(e){let{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==y.array)return h(r,{code:p.invalid_type,expected:y.array,received:r.parsedType}),v;if(r.data.length<this._def.items.length)return h(r,{code:p.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),v;!this._def.rest&&r.data.length>this._def.items.length&&(h(r,{code:p.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),n.dirty());let i=[...r.data].map((o,a)=>{let l=this._def.items[a]||this._def.rest;return l?l._parse(new M(r,o,r.path,a)):null}).filter(o=>!!o);return r.common.async?Promise.all(i).then(o=>I.mergeArray(n,o)):I.mergeArray(n,i)}get items(){return this._def.items}rest(e){return new t({...this._def,rest:e})}};Z.create=(t,e)=>{if(!Array.isArray(t))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new Z({items:t,typeName:x.ZodTuple,rest:null,...E(e)})};var We=class t extends w{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==y.object)return h(r,{code:p.invalid_type,expected:y.object,received:r.parsedType}),v;let s=[],i=this._def.keyType,o=this._def.valueType;for(let a in r.data)s.push({key:i._parse(new M(r,a,r.path,a)),value:o._parse(new M(r,r.data[a],r.path,a)),alwaysSet:a in r.data});return r.common.async?I.mergeObjectAsync(n,s):I.mergeObjectSync(n,s)}get element(){return this._def.valueType}static create(e,n,r){return n instanceof w?new t({keyType:e,valueType:n,typeName:x.ZodRecord,...E(r)}):new t({keyType:Y.create(),valueType:e,typeName:x.ZodRecord,...E(n)})}},ke=class extends w{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==y.map)return h(r,{code:p.invalid_type,expected:y.map,received:r.parsedType}),v;let s=this._def.keyType,i=this._def.valueType,o=[...r.data.entries()].map(([a,l],u)=>({key:s._parse(new M(r,a,r.path,[u,"key"])),value:i._parse(new M(r,l,r.path,[u,"value"]))}));if(r.common.async){let a=new Map;return Promise.resolve().then(async()=>{for(let l of o){let u=await l.key,d=await l.value;if(u.status==="aborted"||d.status==="aborted")return v;(u.status==="dirty"||d.status==="dirty")&&n.dirty(),a.set(u.value,d.value)}return{status:n.value,value:a}})}else{let a=new Map;for(let l of o){let u=l.key,d=l.value;if(u.status==="aborted"||d.status==="aborted")return v;(u.status==="dirty"||d.status==="dirty")&&n.dirty(),a.set(u.value,d.value)}return{status:n.value,value:a}}}};ke.create=(t,e,n)=>new ke({valueType:e,keyType:t,typeName:x.ZodMap,...E(n)});var Ee=class t extends w{_parse(e){let{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==y.set)return h(r,{code:p.invalid_type,expected:y.set,received:r.parsedType}),v;let s=this._def;s.minSize!==null&&r.data.size<s.minSize.value&&(h(r,{code:p.too_small,minimum:s.minSize.value,type:"set",inclusive:!0,exact:!1,message:s.minSize.message}),n.dirty()),s.maxSize!==null&&r.data.size>s.maxSize.value&&(h(r,{code:p.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),n.dirty());let i=this._def.valueType;function o(l){let u=new Set;for(let d of l){if(d.status==="aborted")return v;d.status==="dirty"&&n.dirty(),u.add(d.value)}return{status:n.value,value:u}}let a=[...r.data.values()].map((l,u)=>i._parse(new M(r,l,r.path,u)));return r.common.async?Promise.all(a).then(l=>o(l)):o(a)}min(e,n){return new t({...this._def,minSize:{value:e,message:b.toString(n)}})}max(e,n){return new t({...this._def,maxSize:{value:e,message:b.toString(n)}})}size(e,n){return this.min(e,n).max(e,n)}nonempty(e){return this.min(1,e)}};Ee.create=(t,e)=>new Ee({valueType:t,minSize:null,maxSize:null,typeName:x.ZodSet,...E(e)});var Ge=class t extends w{constructor(){super(...arguments),this.validate=this.implement}_parse(e){let{ctx:n}=this._processInputParams(e);if(n.parsedType!==y.function)return h(n,{code:p.invalid_type,expected:y.function,received:n.parsedType}),v;function r(a,l){return Oe({data:a,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,ye(),H].filter(u=>!!u),issueData:{code:p.invalid_arguments,argumentsError:l}})}function s(a,l){return Oe({data:a,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,ye(),H].filter(u=>!!u),issueData:{code:p.invalid_return_type,returnTypeError:l}})}let i={errorMap:n.common.contextualErrorMap},o=n.data;if(this._def.returns instanceof J){let a=this;return O(async function(...l){let u=new D([]),d=await a._def.args.parseAsync(l,i).catch(g=>{throw u.addIssue(r(l,g)),u}),f=await Reflect.apply(o,this,d);return await a._def.returns._def.type.parseAsync(f,i).catch(g=>{throw u.addIssue(s(f,g)),u})})}else{let a=this;return O(function(...l){let u=a._def.args.safeParse(l,i);if(!u.success)throw new D([r(l,u.error)]);let d=Reflect.apply(o,this,u.data),f=a._def.returns.safeParse(d,i);if(!f.success)throw new D([s(d,f.error)]);return f.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new t({...this._def,args:Z.create(e).rest(K.create())})}returns(e){return new t({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,n,r){return new t({args:e||Z.create([]).rest(K.create()),returns:n||K.create(),typeName:x.ZodFunction,...E(r)})}},le=class extends w{get schema(){return this._def.getter()}_parse(e){let{ctx:n}=this._processInputParams(e);return this._def.getter()._parse({data:n.data,path:n.path,parent:n})}};le.create=(t,e)=>new le({getter:t,typeName:x.ZodLazy,...E(e)});var ue=class extends w{_parse(e){if(e.data!==this._def.value){let n=this._getOrReturnCtx(e);return h(n,{received:n.data,code:p.invalid_literal,expected:this._def.value}),v}return{status:"valid",value:e.data}}get value(){return this._def.value}};ue.create=(t,e)=>new ue({value:t,typeName:x.ZodLiteral,...E(e)});function zt(t,e){return new de({values:t,typeName:x.ZodEnum,...E(e)})}var de=class t extends w{_parse(e){if(typeof e.data!="string"){let n=this._getOrReturnCtx(e),r=this._def.values;return h(n,{expected:S.joinValues(r),received:n.parsedType,code:p.invalid_type}),v}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){let n=this._getOrReturnCtx(e),r=this._def.values;return h(n,{received:n.data,code:p.invalid_enum_value,options:r}),v}return O(e.data)}get options(){return this._def.values}get enum(){let e={};for(let n of this._def.values)e[n]=n;return e}get Values(){let e={};for(let n of this._def.values)e[n]=n;return e}get Enum(){let e={};for(let n of this._def.values)e[n]=n;return e}extract(e,n=this._def){return t.create(e,{...this._def,...n})}exclude(e,n=this._def){return t.create(this.options.filter(r=>!e.includes(r)),{...this._def,...n})}};de.create=zt;var fe=class extends w{_parse(e){let n=S.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==y.string&&r.parsedType!==y.number){let s=S.objectValues(n);return h(r,{expected:S.joinValues(s),received:r.parsedType,code:p.invalid_type}),v}if(this._cache||(this._cache=new Set(S.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){let s=S.objectValues(n);return h(r,{received:r.data,code:p.invalid_enum_value,options:s}),v}return O(e.data)}get enum(){return this._def.values}};fe.create=(t,e)=>new fe({values:t,typeName:x.ZodNativeEnum,...E(e)});var J=class extends w{unwrap(){return this._def.type}_parse(e){let{ctx:n}=this._processInputParams(e);if(n.parsedType!==y.promise&&n.common.async===!1)return h(n,{code:p.invalid_type,expected:y.promise,received:n.parsedType}),v;let r=n.parsedType===y.promise?n.data:Promise.resolve(n.data);return O(r.then(s=>this._def.type.parseAsync(s,{path:n.path,errorMap:n.common.contextualErrorMap})))}};J.create=(t,e)=>new J({type:t,typeName:x.ZodPromise,...E(e)});var L=class extends w{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===x.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){let{status:n,ctx:r}=this._processInputParams(e),s=this._def.effect||null,i={addIssue:o=>{h(r,o),o.fatal?n.abort():n.dirty()},get path(){return r.path}};if(i.addIssue=i.addIssue.bind(i),s.type==="preprocess"){let o=s.transform(r.data,i);if(r.common.async)return Promise.resolve(o).then(async a=>{if(n.value==="aborted")return v;let l=await this._def.schema._parseAsync({data:a,path:r.path,parent:r});return l.status==="aborted"?v:l.status==="dirty"?ee(l.value):n.value==="dirty"?ee(l.value):l});{if(n.value==="aborted")return v;let a=this._def.schema._parseSync({data:o,path:r.path,parent:r});return a.status==="aborted"?v:a.status==="dirty"?ee(a.value):n.value==="dirty"?ee(a.value):a}}if(s.type==="refinement"){let o=a=>{let l=s.refinement(a,i);if(r.common.async)return Promise.resolve(l);if(l instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return a};if(r.common.async===!1){let a=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return a.status==="aborted"?v:(a.status==="dirty"&&n.dirty(),o(a.value),{status:n.value,value:a.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(a=>a.status==="aborted"?v:(a.status==="dirty"&&n.dirty(),o(a.value).then(()=>({status:n.value,value:a.value}))))}if(s.type==="transform")if(r.common.async===!1){let o=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!G(o))return v;let a=s.transform(o.value,i);if(a instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:n.value,value:a}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(o=>G(o)?Promise.resolve(s.transform(o.value,i)).then(a=>({status:n.value,value:a})):v);S.assertNever(s)}};L.create=(t,e,n)=>new L({schema:t,typeName:x.ZodEffects,effect:e,...E(n)});L.createWithPreprocess=(t,e,n)=>new L({schema:e,effect:{type:"preprocess",transform:t},typeName:x.ZodEffects,...E(n)});var P=class extends w{_parse(e){return this._getType(e)===y.undefined?O(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};P.create=(t,e)=>new P({innerType:t,typeName:x.ZodOptional,...E(e)});var U=class extends w{_parse(e){return this._getType(e)===y.null?O(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};U.create=(t,e)=>new U({innerType:t,typeName:x.ZodNullable,...E(e)});var pe=class extends w{_parse(e){let{ctx:n}=this._processInputParams(e),r=n.data;return n.parsedType===y.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:n.path,parent:n})}removeDefault(){return this._def.innerType}};pe.create=(t,e)=>new pe({innerType:t,typeName:x.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...E(e)});var me=class extends w{_parse(e){let{ctx:n}=this._processInputParams(e),r={...n,common:{...n.common,issues:[]}},s=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return _e(s)?s.then(i=>({status:"valid",value:i.status==="valid"?i.value:this._def.catchValue({get error(){return new D(r.common.issues)},input:r.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new D(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}};me.create=(t,e)=>new me({innerType:t,typeName:x.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...E(e)});var we=class extends w{_parse(e){if(this._getType(e)!==y.nan){let r=this._getOrReturnCtx(e);return h(r,{code:p.invalid_type,expected:y.nan,received:r.parsedType}),v}return{status:"valid",value:e.data}}};we.create=t=>new we({typeName:x.ZodNaN,...E(t)});var Zr=Symbol("zod_brand"),De=class extends w{_parse(e){let{ctx:n}=this._processInputParams(e),r=n.data;return this._def.type._parse({data:r,path:n.path,parent:n})}unwrap(){return this._def.type}},Ne=class t extends w{_parse(e){let{status:n,ctx:r}=this._processInputParams(e);if(r.common.async)return(async()=>{let i=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return i.status==="aborted"?v:i.status==="dirty"?(n.dirty(),ee(i.value)):this._def.out._parseAsync({data:i.value,path:r.path,parent:r})})();{let s=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return s.status==="aborted"?v:s.status==="dirty"?(n.dirty(),{status:"dirty",value:s.value}):this._def.out._parseSync({data:s.value,path:r.path,parent:r})}}static create(e,n){return new t({in:e,out:n,typeName:x.ZodPipeline})}},he=class extends w{_parse(e){let n=this._def.innerType._parse(e),r=s=>(G(s)&&(s.value=Object.freeze(s.value)),s);return _e(n)?n.then(s=>r(s)):r(n)}unwrap(){return this._def.innerType}};he.create=(t,e)=>new he({innerType:t,typeName:x.ZodReadonly,...E(e)});function Lt(t,e){let n=typeof t=="function"?t(e):typeof t=="string"?{message:t}:t;return typeof n=="string"?{message:n}:n}function Zt(t,e={},n){return t?q.create().superRefine((r,s)=>{let i=t(r);if(i instanceof Promise)return i.then(o=>{if(!o){let a=Lt(e,r),l=a.fatal??n??!0;s.addIssue({code:"custom",...a,fatal:l})}});if(!i){let o=Lt(e,r),a=o.fatal??n??!0;s.addIssue({code:"custom",...o,fatal:a})}}):q.create()}var Ur={object:N.lazycreate},x;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline",t.ZodReadonly="ZodReadonly"})(x||(x={}));var Hr=(t,e={message:`Input not instance of ${t.name}`})=>Zt(n=>n instanceof t,e),Ut=Y.create,Ht=te.create,Vr=we.create,Kr=ne.create,Vt=re.create,Wr=se.create,Gr=ve.create,Yr=ie.create,qr=oe.create,Jr=q.create,Xr=K.create,Qr=F.create,es=xe.create,ts=W.create,ns=N.create,rs=N.strictCreate,ss=ae.create,is=Ke.create,os=ce.create,as=Z.create,cs=We.create,ls=ke.create,us=Ee.create,ds=Ge.create,fs=le.create,ps=ue.create,ms=de.create,hs=fe.create,gs=J.create,ys=L.create,_s=P.create,bs=U.create,vs=L.createWithPreprocess,xs=Ne.create,ks=()=>Ut().optional(),Es=()=>Ht().optional(),ws=()=>Vt().optional(),Ss={string:(t=>Y.create({...t,coerce:!0})),number:(t=>te.create({...t,coerce:!0})),boolean:(t=>re.create({...t,coerce:!0})),bigint:(t=>ne.create({...t,coerce:!0})),date:(t=>se.create({...t,coerce:!0}))};var Ts=v;var Se=m.object({slug:m.string().min(1).max(64),description:m.string().max(255).optional(),match_command:m.string().min(1),priority:m.number().int().default(50),strip_ansi:m.boolean().default(!1),strip_lines_matching:m.array(m.string()).default([]),keep_failures:m.boolean().default(!1),fold_passing:m.boolean().default(!1),fold_passing_threshold:m.number().int().positive().max(1e3).optional(),mask_abs_paths:m.boolean().default(!1),preserve_exact:m.boolean().default(!1),truncate_lines_at:m.number().int().positive().max(1e4).optional(),max_lines:m.number().int().positive().max(1e5).optional(),scale_with_level:m.boolean().default(!0),transform:m.string().max(64).optional(),on_empty:m.string().max(255).optional()});var Os=Cs(Is(import.meta.url)),Kt=process.env.TOKMIZER_FILTERS_DIR||Gt(Os,"..","..","filters"),X=null,Wt=!1;function Ds(){return process.env.TOKMIZER_DEV==="1"||process.env.TOKMIZER_DEV==="true"}async function Yt(){if(X)return X;if(!Ds())return!Wt&&process.env.TOKMIZER_DEBUG==="1"&&(process.stderr.write(`tokmizer: disk loader disabled (set TOKMIZER_DEV=1 to re-enable for local dev).
4
- `),Wt=!0),X=new Map,X;let t=new Map,e,n;try{e=(await import("smol-toml")).parse,n=(await As(Kt)).filter(r=>r.endsWith(".toml"))}catch{return X=t,X}for(let r of n){let s=await Rs(Gt(Kt,r),"utf8"),o=e(s).filters;if(o)for(let[a,l]of Object.entries(o)){let u=Se.parse({slug:a,...l});t.set(a,{...u,matchRegex:new RegExp(u.match_command)})}}return X=t,X}import{createHash as Ns}from"node:crypto";var $s=m.enum(["normal","compact","minimal"]),Ps=m.enum(["off","light","balanced","max"]),$e=m.object({enabled:m.boolean().default(!0),telemetryOptIn:m.boolean().default(!0),outputVerbosity:$s.default("compact"),reducer:Ps.default("off"),filters:m.object({enableAll:m.boolean().default(!0),disabled:m.array(m.string().max(64)).max(100).default([])}).default({enableAll:!0,disabled:[]})}),Ms=["git","git-status","git-log","git-diff","grep","find","diff","ls","ls-long","ps","cat","head","tail","df","du","tree","wc","nl","xargs","seq","echo","printf","sleep","shasum","python","node","read-tool","grep-tool","glob-tool","bash-tool","npm","npm-test","docker","kubectl","curl","cargo","go-test","go-build","gh","gh-api","aws","dotnet","prisma","tsc","next","jest","vitest","pytest","pip","rspec"],Ls=/^[0-9a-f]{16}$/,qt=new Map;function j(t){let e=qt.get(t);return e||(e=Ns("sha256").update(`tkr:${t}`).digest("hex").slice(0,16),qt.set(t,e)),e}var Jt=null;function Ye(t,e=!1){return e||!t||t.length===0?(Jt??=new Set(Ms.map(j)),new Set(Jt)):new Set(t.map(n=>Ls.test(n)?n:j(n)))}var Te=new Map,Fs=256,Xt=new WeakMap;function js(t){if(!t)return"*";let e=Xt.get(t);return e===void 0&&(e=[...t].join(","),Xt.set(t,e)),e}function qe(t,e,n){let r=`${t}::${js(n)}`,s=Te.get(r);if(s!==void 0)return s;let i=null;for(let o of e)n&&!n.has(j(o.slug))||o.matchRegex.test(t)&&(!i||o.priority>i.priority)&&(i=o);if(Te.size>=Fs){let o=Te.keys().next().value;o&&Te.delete(o)}return Te.set(r,i),i}function Qt(){Te.clear()}var Bs=/\x1b\[[0-9;?]*[ -/]*[@-~]/g,zs=/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g;function ge(t){return t.replace(Bs,"").replace(zs,"")}function en(t,e){return e.length===0?t:t.filter(n=>!e.some(r=>r.test(n)))}function tn(t,e){return t.map(n=>{if(n.length<=e)return n;let r=n.charCodeAt(e-1),s=n.charCodeAt(e),i=r>=55296&&r<=56319&&s>=56320&&s<=57343?e-1:e;return`${n.slice(0,i)}\u2026`})}function Je(t){return`\u2026 (${t} more lines omitted)`}function nn(t,e){if(t.length<=e)return{kept:t,dropped:[]};let n=Math.ceil(e*.7),r=e-n,s=t.slice(n,t.length-r);return{kept:[...t.slice(0,n),Je(s.length),...t.slice(t.length-r)],dropped:s}}var Zs=/^\s*(?:[✓✔√]|ok )/,Q=/✕|✗|×|\bFAIL\b|\bERROR\b|\bFATAL\b|\bError|\berror|Expected|Received|\bfailed\b|^\s*Tests?:|^\s*Test Suites?:/;function rn(t,e){let n=e>0?e:5,r=[],s=0,i=a=>{s>=n?r.push(`\u2026 ${s} passing checks folded \u2026`):r.push(...a)},o=[];for(let a of t)Zs.test(a)&&!Q.test(a)?(o.push(a),s+=1):(i(o),o=[],s=0,r.push(a));return i(o),r}var Us=/(?:\/[\w.@+-]+){3,}/g;function sn(t){return t.map(e=>e.replace(Us,n=>{let r=n.split("/").filter(Boolean);return r.length<=2?n:`\u2026/${r.slice(-2).join("/")}`}))}var Hs=/^(\s*)(?:export\s+)?(?:async\s+)?(?:function|interface|type|const|let|var|def|fn|impl|trait|struct|enum)\s+[\w$]+/,Vs=/\{\s*$/;var Ks=/^\s*(?:(?:public|private|protected|static|async|get|set|readonly|override)\s+)*([\w$]+)\s*\(([^)]*)\)\s*(?::\s*[^{]+)?\{\s*$/,Ws=new Set(["if","for","while","switch","catch","do","with","return","else","function","await","yield"]);function Gs(t){let e=Ks.exec(t);return!e||Ws.has(e[1])?!1:!/=>|\bfunction\b/.test(e[2])}var Ys=/^\s*(?:if|for|while|switch|try|do)\b[^{}]*\{\s*$/;function qs(t,e,n){let r=e;for(;r<t.length;){if(t[r]==="\\"){r+=2;continue}if(t[r]===n)return!0;r+=1}return!1}function Js(t,e){let n=0,r=null,s=0;for(;s<t.length;){let i=t[s];if(e.inBlockComment){if(i==="*"&&t[s+1]==="/"){e.inBlockComment=!1,s+=2;continue}s+=1;continue}if(e.inTemplate){if(i==="\\"){s+=2;continue}i==="`"&&(e.inTemplate=!1),s+=1;continue}if(r){if(i==="\\"){s+=2;continue}i===r&&(r=null),s+=1;continue}if(i==="/"&&t[s+1]==="/")break;if(i==="/"&&t[s+1]==="*"){e.inBlockComment=!0,s+=2;continue}if(i==="`"){e.inTemplate=!0,s+=1;continue}if(i==="'"||i==='"'){let o=s>0?t[s-1]:"";!(i==="'"&&(o==="<"||o==="&"))&&qs(t,s+1,i)&&(r=i),s+=1;continue}i==="{"||i==="("||i==="["?n+=1:(i==="}"||i===")"||i==="]")&&(n-=1),s+=1}return n}var Xs=/^\s*… (\d+) lines? folded …$/;function ot(t){let e=new Array(t.length).fill(!1);for(let n=0;n<t.length;n+=1){let r=Xs.exec(t[n]);if(!r)continue;let s=Number(r[1])-1,i=n+1;for(;s>0&&i<t.length&&t[i]==="";)e[i]=!0,s-=1,i+=1;n=i-1}return e}function Xe(t){let e=[],n=0;for(;n<t.length;){let r=t[n];if(Hs.test(r)&&Vs.test(r)||Gs(r)||Ys.test(r)){let s={inBlockComment:!1,inTemplate:!1},i=0,o=n,a=!1;for(;o<t.length&&o-n<200;)if(i+=Js(t[o],s),o+=1,i<=0&&!s.inTemplate&&!s.inBlockComment){a=!0;break}let l=o-n;if(a&&l>=3){let u=l-2,d=/^\s*/.exec(t[n+1]??"")?.[0]??" ";e.push(r),e.push(`${d}\u2026 ${u} ${u===1?"line":"lines"} folded \u2026`);for(let f=0;f<u-1;f++)e.push("");e.push(t[o-1]),n=o;continue}}e.push(r),n+=1}return e}var Qs=/\b(?:function|class|interface|import\s+|export\s+|def\s+|fn\s+|impl\s+|package\s+|namespace\s+|using\s+|#include|=>\s*\{|=\s*function)/;function on(t){let e=t.slice(0,4096);return!(!Qs.test(e)||e.split(`
5
- `).length<6)}var ei=/^\s*(?:\d{4}-\d{2}-\d{2}[T\s]\d{2}:\d{2}:\d{2}(?:\.\d+)?Z?|\d{2}:\d{2}:\d{2}(?:\.\d+)?)\s*/,ti=/^\s*(?:\[(?:DEBUG|TRACE|INFO|VERBOSE)\]|(?:DEBUG|TRACE|INFO|VERBOSE)(?!\s*:))(?=\s|:|$)(?!\s*[+\-*\/%&|^?]*=)/,ni=new RegExp(Q.source,"i"),ri=/\bWARN(?:ING)?\b/i;function an(t){let e=[],n=0,r=()=>{n>0&&e.push(`\u2026 ${n} verbose log line${n===1?"":"s"} dropped \u2026`),n=0};for(let s of t){if(ti.test(s.replace(ei,""))&&!ni.test(s)&&!ri.test(s)){n+=1;continue}r(),e.push(s)}return r(),e}function cn(t){if(t.length===0)return t;let e=[],n=1,r=t[0];for(let s=1;s<t.length;s++){if(t[s]===r){n+=1;continue}e.push(n>1?`${r} \xD7${n}`:r),r=t[s],n=1}return e.push(n>1?`${r} \xD7${n}`:r),e}function ln(t){let e=[],n=0;for(let r of t){if(r.trim()===""){n+=1;continue}n>0&&e.push(""),n=0,e.push(r)}return e}var un=new Map;function $(t,e){un.set(t,e)}function dn(t){return un.get(t)}var si=/^[dbclps\-][rwxsStT\-]{9}[@.+]?(?:\s|$)/,ii=/^[./~][^\s]*:$/,at=1e3;function oi(t){if(t<1024)return String(t);let e=["K","M","G","T"],n=t/1024,r=0;for(;n>=1024&&r<e.length-1;)n/=1024,r+=1;return`${n.toFixed(1)}${e[r]}`}function ai(t){if(!si.test(t))return null;let e=t.split(/\s+/);if(e.length<9)return null;let n=Number(e[4]);if(!Number.isFinite(n))return null;let r=e.slice(8).join(" ").trim();if(r===""||r==="."||r==="..")return null;let s=e[0].charCodeAt(0)===100;return{name:r,size:n,isDir:s}}function ci(t){if(t.length<3)return null;let e=new Map;for(let s of t){let i=s.name.lastIndexOf(".");if(i<=0)continue;let o=s.name.slice(i);e.set(o,(e.get(o)??0)+1)}let n=null,r=0;for(let[s,i]of e)i>r&&(r=i,n=s);return n&&r>=Math.ceil(t.length/2)?`${r} ${n}`:null}function li(t){let e=[],n=[],r=!1;for(let c of t){if(/^total\s+\d+/.test(c))continue;if(ii.test(c.trim()))return t;let g=ai(c);g&&(r=!0,(g.isDir?e:n).push(g))}if(!r)return t;let s=(c,g)=>c.name.localeCompare(g.name);e.sort(s),n.sort((c,g)=>g.size-c.size||s(c,g));let i=[...e,...n],o=Math.min(40,Math.max(0,...i.map(c=>c.isDir?c.name.length+1:c.name.length))),a=[];for(let c of i){let g=c.isDir?`${c.name}/`:c.name,_=c.isDir?"":oi(c.size);a.push(_?`${g.padEnd(o)} ${_}`:g)}if(a.length>at){let c=a.length-at;a=[...a.slice(0,at),`\u2026 ${c} more lines omitted`]}let l=n.length===1?"file":"files",u=e.length===1?"dir":"dirs",d=ci(n),f=`${n.length} ${l}, ${e.length} ${u}`+(d?` (${d})`:"");return a.push(f),a}$("smart-ls",li);$("smart-read",t=>Xe(t));var fn=1e3;function ui(t){let e=t.filter(d=>d.trim()!=="");if(e.length===0||e.filter(d=>!/\s/.test(d.trim())).length<e.length*.6)return t;let r=new Map,s=[],i=0;for(let d of e){let f=d.trim();if(f.startsWith("find:")){s.push(f);continue}let c=f.replace(/^\.\//,"").replace(/\/+$/,""),g=c.lastIndexOf("/"),_=g>=0?c.slice(0,g):"",k=g>=0?c.slice(g+1):c;if(!k)continue;let A=r.get(_)??[];A.push(/\s/.test(k)?`"${k}"`:k),r.set(_,A),i+=1}if(i===0)return t;let o=new Set([""]);for(let d of r.keys()){if(d==="")continue;let f=d.split("/");for(let c=1;c<=f.length;c+=1)o.add(f.slice(0,c).join("/"))}let a=[...o].sort(),l=a.filter(d=>d!=="").length,u=[`${i}F ${l}D:`,""];for(let d of a){let f=d===""?0:d.split("/").length,c=d===""?".":d.slice(d.lastIndexOf("/")+1),g=r.get(d)??[],_=g.length?` ${g.join(" ")}`:"";u.push(`${" ".repeat(f)}${c}/${_}`)}if(u.length+s.length>fn){let d=Math.max(0,fn-s.length),f=u.length-d;return[...u.slice(0,d),`\u2026 ${f} more lines omitted`,...s]}return[...u,...s]}$("smart-find",ui);var ct=1e3,pn=200,di=60,fi=190,pi=/^([^\s:]+):(\d+):(.*)$/,mi=/^([^:]+?)-(\d+)-(.*)$/,hi=/^([^\s:]+):(.*)$/,mn=/(?:^|\/)(?:__tests__|tests?|spec|fixtures?|__mocks__|__snapshots__)\/|\.(?:test|spec)\.[^/]+$/i;function hn(t){let e=t.trim();return e.length>pn?`${e.slice(0,pn)}\u2026`:e}function gi(t){let e=[],n="";for(let r of t){let s=n?`${n}, ${r}`:r;s.length>fi&&n?(e.push(`${n},`),n=r):n=s}return n&&e.push(n),e}function yi(t){let e=t.filter(f=>f.trim()!=="");if(e.length===0)return t;let n=new Map,r=new Map,s=null,i=0,o=0;for(let f of e){if(f==="--"){s&&n.get(s).push({separator:!0});continue}if(/^[A-Za-z]:[\\/]/.test(f))return t;let c=pi.exec(f),g=mi.exec(f);if(c&&g)return t;let _=c||g?null:hi.exec(f),k=(c??g??_)?.[1];if(!k)return t;let A=c?{line:c[2],content:c[3],context:!1}:g?{line:g[2],content:g[3],context:!0}:{line:"",content:_[2],context:!1},R=n.get(k)??[];R.push(A),n.set(k,R),A.context||(i+=1,r.set(k,(r.get(k)??0)+1)),o+=1,s=k}if(n.size===o)return t;let a=[...n.keys()].sort((f,c)=>{let g=mn.test(f)?1:0,_=mn.test(c)?1:0;return g-_||(f<c?-1:f>c?1:0)}),l=[];for(let f of a){l.push(`${f} (${r.get(f)??0}):`);for(let c of n.get(f))"separator"in c?l.push(" --"):c.line?l.push(` ${c.line}${c.context?"-":":"} ${hn(c.content)}`):l.push(` ${hn(c.content)}`)}let u=a.length>1&&l.length>di?gi(a.map(f=>`${f} (${r.get(f)??0})`)):[],d=[`${i}m ${a.length}f:`,...u,"",...l];if(d.length>ct){let f=d.length-ct;return[...d.slice(0,ct),`\u2026 ${f} more lines omitted`]}return d}$("smart-grep",yi);var gn=/^(?:([|\\/ ._-]*\*[|\\/* ._-]* ))?commit [0-9a-f]{7,40}\b/,_i=/^[|\\/* ._-]*$/,bi=/^ {4}/,vi=2;function xi(t){if(!t.some(u=>gn.test(u)))return t;let e=[],n=0,r=0,s=0,i="",o=!1,a=!1,l=()=>{r>0&&e.push(`${i} \u2026 ${r} ${r===1?"line":"lines"} folded \u2026`),r=0};for(let u of t){let d=u.slice(0,s),f=_i.test(d),c=f?u.slice(s):u,g=bi.test(c),_=o&&g?null:gn.exec(u);if(_){l(),n=0,s=_[1]?.length??0,o=!0,a=!1,e.push(u);continue}if(/^diff --(?:git|cc|combined) /.test(c)&&(a=!0),g&&!a&&!(s>0&&c.trim().length===0)){n+=1,n<=vi?e.push(u):(r+=1,i=f?d:"");continue}l(),e.push(u)}return l(),e}$("smart-log",xi);var ki=/^[\s=]+$/,Ei=/^\s*=+\s+(.*?)\s+=+\s*$/,wi=512;$("strip-banners",t=>{let e=[];for(let n of t){if(ki.test(n))continue;let r=n.length<=wi?Ei.exec(n):null;e.push(r?r[1]:n)}return e});function Si(t){let e=[],n=0,r=0;for(;r<t.length;){let s=t[r].replace(/\s+$/,"");if(s===""){n+=1,r+=1,n<=1&&e.push("");continue}n=0;let i=1;for(;r+i<t.length&&t[r+i].replace(/\s+$/,"")===s;)i+=1;if(i>=3)e.push(s),e.push(` \u2026 (repeated ${i}x)`);else for(let o=0;o<i;o++)e.push(s);r+=i}for(;e.length>0&&e[e.length-1]==="";)e.pop();return e}$("squeeze-output",Si);function Ti(t){return t==="compact"?.6:t==="minimal"?.3:1}var Ai=20;function Ri(t){let[e,n,r,s]=t.slice(-4);if(!e||!n||!r||!s||!/^\s*Test Files\s+([1-9]\d*) passed \(\1\)$/.test(e)||!/^\s*Tests\s+([1-9]\d*) passed \(\1\)$/.test(n)||!/^\s*Start at\s+\d{2}:\d{2}:\d{2}$/.test(r))return t;let i=/^(\s*Duration\s+\d+(?:\.\d+)?(?:ms|s)) \(transform [^\n]+\)$/.exec(s)?.[1];return i?[...t.slice(0,-4).filter((a,l)=>l>2||!/^ RUN v\d+\.\d+\.\d+(?:[\w.+-]*) .+$/.test(a)),e,n,i]:t}var yn=new WeakMap;function Ci(t){let e=yn.get(t);if(e)return e;let n=t.strip_lines_matching.map(s=>new RegExp(s)),r={def:t,stripRegexes:n};return yn.set(t,r),r}function _n(t,e,n={}){return lt(t,e,n).text}function lt(t,e,n={}){let r=n.verbosity??"normal";if(!e.strip_ansi&&e.strip_lines_matching.length===0&&!e.transform&&!e.mask_abs_paths&&!e.fold_passing&&!e.truncate_lines_at&&!e.max_lines&&!e.on_empty&&!n.smartCode&&r==="normal")return{text:t,droppedTail:null};let s=Ci(e),i=t;e.strip_ansi&&(i=ge(i));let o=i.endsWith(`
6
- `),a=(o?i.slice(0,-1):i).split(`
7
- `);if(s.stripRegexes.length&&(a=e.keep_failures?a.filter(f=>Q.test(f)||!s.stripRegexes.some(c=>c.test(f))):en(a,s.stripRegexes)),r!=="normal"&&!e.preserve_exact&&(a=cn(a),a=ln(a)),r==="minimal"&&!e.preserve_exact&&(a=an(a),(e.slug==="vitest"||e.slug==="npm-test")&&(a=Ri(a))),!e.preserve_exact&&(n.smartCode||n.smartCode===void 0&&r!=="normal"&&on(i))&&(a=Xe(a)),e.transform){let f=dn(e.transform);f&&(a=f(a))}let l=e.slug==="read-tool";if(!l){let f=ot(a);f.some(Boolean)&&(a=a.filter((c,g)=>!f[g]))}e.mask_abs_paths&&(a=sn(a)),e.fold_passing&&(a=rn(a,e.fold_passing_threshold??5)),e.truncate_lines_at&&(a=tn(a,e.truncate_lines_at));let u=null;if(e.max_lines){let f=e.scale_with_level?Ti(n.verbosity):1,c=Math.min(e.max_lines,Math.max(Ai,Math.round(e.max_lines*f))),g=l?ot(a):null,_=g?g.filter(k=>!k).length:a.length;if(_>c){let k=c;if(g){let R=0;for(k=0;k<a.length&&R<c;)g[k]||(R+=1),k+=1}let A=_-c;if(e.keep_failures){let R=a.slice(k),B=R.filter(C=>!Q.test(C)),Re=R.reduce((C,Ce,Ie)=>C+(!Q.test(Ce)&&!g?.[k+Ie]?1:0),0);u=B.length>0?B.join(`
8
- `):null,a=[...a.slice(0,k),...Re>0?[Je(Re)]:[],...R.filter(C=>Q.test(C))]}else if(l)u=a.slice(k).join(`
9
- `),a=[...a.slice(0,k),Je(A)];else{let{kept:R,dropped:B}=nn(a,c);u=B.length>0?B.join(`
10
- `):null,a=R}}}let d=a.join(`
11
- `);return o&&d.length>0&&(d+=`
12
- `),d.trim().length===0&&e.on_empty&&(d=e.on_empty),{text:d,droppedTail:u}}var Ii=[/\bERROR\b/,/\bFAIL\b/,/\bFAILED\b/,/\bFATAL\b/,/^Traceback /m,/^Error: /m,/^\s+at .*\(.*:\d+:\d+\)/m,/panic:/,/SyntaxError:/,/TypeError:/,/ReferenceError:/,/AssertionError:/,/^\s*(?:error|fatal):/i,/thread '.*' panicked/,/\b[1-9]\d* (?:failed|errors?)\b/];function bn(t){if(!t)return!1;for(let e of ge(t).split(`
13
- `))if(!/^\s*[✓✔√]\s/.test(e)&&Ii.some(n=>n.test(e)))return!0;return!1}var Oi=new Set(["sudo","command","time","nice","nohup","env","stdbuf","timeout"]),Di=/^[A-Za-z_][A-Za-z0-9_]*=/,ut=/^([a-z]+)-tool(?::\s|$)/;function Pe(t){let e=t.trim(),n=e.split(/\s+/),r=0;for(;r<n.length;){let a=n[r];if(Di.test(a)){r++;continue}if(Oi.has(a)){for(r++,a==="timeout"&&r<n.length&&/^\d+(?:\.\d+)?[smhd]?$/.test(n[r])&&r++;(a==="stdbuf"||a==="nice")&&r<n.length&&n[r].startsWith("-");)r++;continue}break}if(r>=n.length)return e;let s=n[r],i=s.includes("/")?s.slice(s.lastIndexOf("/")+1):s,o=n.slice(r+1);return o.length?`${i} ${o.join(" ")}`:i}var Ni=new Set(["cd","export","source","set","unset","mkdir","true",":","pushd","popd","alias","ulimit","umask","echo","printf","sleep","touch","rm","cp","mv","chmod","ln"]);function vn(t,e){let n=!1,r=!1,s=0,i=[];for(let o=0;o<t.length;o++){let a=t[o];if(a==="\\"&&!n){o++;continue}a==="'"&&!r?n=!n:a==='"'&&!n?r=!r:!n&&!r&&(a===";"?(i.push(t.slice(s,o)),s=o+1):a==="|"&&t[o+1]==="|"?(i.push(t.slice(s,o)),o++,s=o+1):a==="|"?e||(i.push(t.slice(s,o)),s=o+1):a==="&"&&t[o+1]==="&"&&(i.push(t.slice(s,o)),o++,s=o+1))}return i.push(t.slice(s)),i}function $i(t){let e=vn(t,!1);for(let n=e.length-1;n>=0;n--){let r=e[n].trim();if(r)return r}return t.trim()}function dt(t){let e=vn(t,!0).map(n=>n.trim()).filter(Boolean);if(e.length===0)return null;for(let n of e.slice(0,-1)){let r=Pe(n).split(/\s+/)[0]??"";if(!Ni.has(r))return null}return $i(e[e.length-1])}function xn(t){let e=!1,n=!1,r=0,s=[];for(let i=0;i<t.length;i++){let o=t[i];if(o==="\\"&&!e){i++;continue}o==="'"&&!n?e=!e:o==='"'&&!e?n=!n:!e&&!n&&(o==="|"||o===";"?(s.push(t.slice(r,i)),o==="|"&&t[i+1]==="|"&&i++,r=i+1):o==="&"&&t[i+1]==="&"&&(s.push(t.slice(r,i)),i++,r=i+1))}s.push(t.slice(r));for(let i=s.length-1;i>=0;i--){let o=s[i].trim();if(o)return o}return t.trim()}function kn(t){let e=ut.exec(t),n=t;if(e){if(e[1]!=="bash")return[t];let i=t.indexOf(": ");if(i<0)return[t];n=t.slice(i+2)}let r=dt(n),s=r?Pe(r):null;return s&&s!==t?[s,t]:[t]}var En=`
3
+ var Ir=Object.defineProperty;var $r=(t,e)=>{for(var n in e)Ir(t,n,{get:e[n],enumerable:!0})};import{readdir as Us,readFile as Hs}from"node:fs/promises";import{join as Qt,dirname as Vs}from"node:path";import{fileURLToPath as Ks}from"node:url";var m={};$r(m,{BRAND:()=>ss,DIRTY:()=>se,EMPTY_PATH:()=>Mr,INVALID:()=>v,NEVER:()=>Zs,OK:()=>N,ParseStatus:()=>D,Schema:()=>w,ZodAny:()=>Q,ZodArray:()=>J,ZodBigInt:()=>ie,ZodBoolean:()=>ae,ZodBranded:()=>De,ZodCatch:()=>_e,ZodDate:()=>ce,ZodDefault:()=>ye,ZodDiscriminatedUnion:()=>Ge,ZodEffects:()=>z,ZodEnum:()=>he,ZodError:()=>M,ZodFirstPartyTypeKind:()=>x,ZodFunction:()=>Je,ZodIntersection:()=>fe,ZodIssueCode:()=>p,ZodLazy:()=>pe,ZodLiteral:()=>me,ZodMap:()=>Te,ZodNaN:()=>Re,ZodNativeEnum:()=>ge,ZodNever:()=>Z,ZodNull:()=>ue,ZodNullable:()=>K,ZodNumber:()=>oe,ZodObject:()=>L,ZodOptional:()=>j,ZodParsedType:()=>y,ZodPipeline:()=>Ne,ZodPromise:()=>ee,ZodReadonly:()=>be,ZodRecord:()=>qe,ZodSchema:()=>w,ZodSet:()=>Ae,ZodString:()=>X,ZodSymbol:()=>we,ZodTransformer:()=>z,ZodTuple:()=>V,ZodType:()=>w,ZodUndefined:()=>le,ZodUnion:()=>de,ZodUnknown:()=>q,ZodVoid:()=>Se,addIssueToContext:()=>h,any:()=>ps,array:()=>ys,bigint:()=>cs,boolean:()=>Jt,coerce:()=>zs,custom:()=>Wt,date:()=>ls,datetimeRegex:()=>Vt,defaultErrorMap:()=>W,discriminatedUnion:()=>xs,effect:()=>Ds,enum:()=>Os,function:()=>As,getErrorMap:()=>xe,getParsedType:()=>H,instanceof:()=>is,intersection:()=>ks,isAborted:()=>Ke,isAsync:()=>ke,isDirty:()=>We,isValid:()=>Y,late:()=>os,lazy:()=>Rs,literal:()=>Cs,makeIssue:()=>$e,map:()=>Ss,nan:()=>as,nativeEnum:()=>Is,never:()=>hs,null:()=>fs,nullable:()=>Ps,number:()=>qt,object:()=>_s,objectUtil:()=>it,oboolean:()=>Bs,onumber:()=>js,optional:()=>Ns,ostring:()=>Fs,pipeline:()=>Ls,preprocess:()=>Ms,promise:()=>$s,quotelessJson:()=>Dr,record:()=>ws,set:()=>Ts,setErrorMap:()=>Pr,strictObject:()=>bs,string:()=>Gt,symbol:()=>us,transformer:()=>Ds,tuple:()=>Es,undefined:()=>ds,union:()=>vs,unknown:()=>ms,util:()=>T,void:()=>gs});var T;(function(t){t.assertEqual=s=>{};function e(s){}t.assertIs=e;function n(s){throw new Error}t.assertNever=n,t.arrayToEnum=s=>{let o={};for(let i of s)o[i]=i;return o},t.getValidEnumValues=s=>{let o=t.objectKeys(s).filter(a=>typeof s[s[a]]!="number"),i={};for(let a of o)i[a]=s[a];return t.objectValues(i)},t.objectValues=s=>t.objectKeys(s).map(function(o){return s[o]}),t.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{let o=[];for(let i in s)Object.prototype.hasOwnProperty.call(s,i)&&o.push(i);return o},t.find=(s,o)=>{for(let i of s)if(o(i))return i},t.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&Number.isFinite(s)&&Math.floor(s)===s;function r(s,o=" | "){return s.map(i=>typeof i=="string"?`'${i}'`:i).join(o)}t.joinValues=r,t.jsonStringifyReplacer=(s,o)=>typeof o=="bigint"?o.toString():o})(T||(T={}));var it;(function(t){t.mergeShapes=(e,n)=>({...e,...n})})(it||(it={}));var y=T.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),H=t=>{switch(typeof t){case"undefined":return y.undefined;case"string":return y.string;case"number":return Number.isNaN(t)?y.nan:y.number;case"boolean":return y.boolean;case"function":return y.function;case"bigint":return y.bigint;case"symbol":return y.symbol;case"object":return Array.isArray(t)?y.array:t===null?y.null:t.then&&typeof t.then=="function"&&t.catch&&typeof t.catch=="function"?y.promise:typeof Map<"u"&&t instanceof Map?y.map:typeof Set<"u"&&t instanceof Set?y.set:typeof Date<"u"&&t instanceof Date?y.date:y.object;default:return y.unknown}};var p=T.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),Dr=t=>JSON.stringify(t,null,2).replace(/"([^"]+)":/g,"$1:"),M=class t extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};let n=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,n):this.__proto__=n,this.name="ZodError",this.issues=e}format(e){let n=e||function(o){return o.message},r={_errors:[]},s=o=>{for(let i of o.issues)if(i.code==="invalid_union")i.unionErrors.map(s);else if(i.code==="invalid_return_type")s(i.returnTypeError);else if(i.code==="invalid_arguments")s(i.argumentsError);else if(i.path.length===0)r._errors.push(n(i));else{let a=r,c=0;for(;c<i.path.length;){let u=i.path[c];c===i.path.length-1?(a[u]=a[u]||{_errors:[]},a[u]._errors.push(n(i))):a[u]=a[u]||{_errors:[]},a=a[u],c++}}};return s(this),r}static assert(e){if(!(e instanceof t))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,T.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=n=>n.message){let n={},r=[];for(let s of this.issues)if(s.path.length>0){let o=s.path[0];n[o]=n[o]||[],n[o].push(e(s))}else r.push(e(s));return{formErrors:r,fieldErrors:n}}get formErrors(){return this.flatten()}};M.create=t=>new M(t);var Nr=(t,e)=>{let n;switch(t.code){case p.invalid_type:t.received===y.undefined?n="Required":n=`Expected ${t.expected}, received ${t.received}`;break;case p.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(t.expected,T.jsonStringifyReplacer)}`;break;case p.unrecognized_keys:n=`Unrecognized key(s) in object: ${T.joinValues(t.keys,", ")}`;break;case p.invalid_union:n="Invalid input";break;case p.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${T.joinValues(t.options)}`;break;case p.invalid_enum_value:n=`Invalid enum value. Expected ${T.joinValues(t.options)}, received '${t.received}'`;break;case p.invalid_arguments:n="Invalid function arguments";break;case p.invalid_return_type:n="Invalid function return type";break;case p.invalid_date:n="Invalid date";break;case p.invalid_string:typeof t.validation=="object"?"includes"in t.validation?(n=`Invalid input: must include "${t.validation.includes}"`,typeof t.validation.position=="number"&&(n=`${n} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?n=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?n=`Invalid input: must end with "${t.validation.endsWith}"`:T.assertNever(t.validation):t.validation!=="regex"?n=`Invalid ${t.validation}`:n="Invalid";break;case p.too_small:t.type==="array"?n=`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:t.type==="string"?n=`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:t.type==="number"?n=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="bigint"?n=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="date"?n=`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:n="Invalid input";break;case p.too_big:t.type==="array"?n=`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:t.type==="string"?n=`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:t.type==="number"?n=`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="bigint"?n=`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="date"?n=`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:n="Invalid input";break;case p.custom:n="Invalid input";break;case p.invalid_intersection_types:n="Intersection results could not be merged";break;case p.not_multiple_of:n=`Number must be a multiple of ${t.multipleOf}`;break;case p.not_finite:n="Number must be finite";break;default:n=e.defaultError,T.assertNever(t)}return{message:n}},W=Nr;var Bt=W;function Pr(t){Bt=t}function xe(){return Bt}var $e=t=>{let{data:e,path:n,errorMaps:r,issueData:s}=t,o=[...n,...s.path||[]],i={...s,path:o};if(s.message!==void 0)return{...s,path:o,message:s.message};let a="",c=r.filter(u=>!!u).slice().reverse();for(let u of c)a=u(i,{data:e,defaultError:a}).message;return{...s,path:o,message:a}},Mr=[];function h(t,e){let n=xe(),r=$e({issueData:e,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,n,n===W?void 0:W].filter(s=>!!s)});t.common.issues.push(r)}var D=class t{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,n){let r=[];for(let s of n){if(s.status==="aborted")return v;s.status==="dirty"&&e.dirty(),r.push(s.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,n){let r=[];for(let s of n){let o=await s.key,i=await s.value;r.push({key:o,value:i})}return t.mergeObjectSync(e,r)}static mergeObjectSync(e,n){let r={};for(let s of n){let{key:o,value:i}=s;if(o.status==="aborted"||i.status==="aborted")return v;o.status==="dirty"&&e.dirty(),i.status==="dirty"&&e.dirty(),o.value!=="__proto__"&&(typeof i.value<"u"||s.alwaysSet)&&(r[o.value]=i.value)}return{status:e.value,value:r}}},v=Object.freeze({status:"aborted"}),se=t=>({status:"dirty",value:t}),N=t=>({status:"valid",value:t}),Ke=t=>t.status==="aborted",We=t=>t.status==="dirty",Y=t=>t.status==="valid",ke=t=>typeof Promise<"u"&&t instanceof Promise;var _;(function(t){t.errToObj=e=>typeof e=="string"?{message:e}:e||{},t.toString=e=>typeof e=="string"?e:e?.message})(_||(_={}));var B=class{constructor(e,n,r,s){this._cachedPath=[],this.parent=e,this.data=n,this._path=r,this._key=s}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}},zt=(t,e)=>{if(Y(e))return{success:!0,data:e.value};if(!t.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;let n=new M(t.common.issues);return this._error=n,this._error}}};function E(t){if(!t)return{};let{errorMap:e,invalid_type_error:n,required_error:r,description:s}=t;if(e&&(n||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:s}:{errorMap:(i,a)=>{let{message:c}=t;return i.code==="invalid_enum_value"?{message:c??a.defaultError}:typeof a.data>"u"?{message:c??r??a.defaultError}:i.code!=="invalid_type"?{message:a.defaultError}:{message:c??n??a.defaultError}},description:s}}var w=class{get description(){return this._def.description}_getType(e){return H(e.data)}_getOrReturnCtx(e,n){return n||{common:e.parent.common,data:e.data,parsedType:H(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new D,ctx:{common:e.parent.common,data:e.data,parsedType:H(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){let n=this._parse(e);if(ke(n))throw new Error("Synchronous parse encountered promise.");return n}_parseAsync(e){let n=this._parse(e);return Promise.resolve(n)}parse(e,n){let r=this.safeParse(e,n);if(r.success)return r.data;throw r.error}safeParse(e,n){let r={common:{issues:[],async:n?.async??!1,contextualErrorMap:n?.errorMap},path:n?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:H(e)},s=this._parseSync({data:e,path:r.path,parent:r});return zt(r,s)}"~validate"(e){let n={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:H(e)};if(!this["~standard"].async)try{let r=this._parseSync({data:e,path:[],parent:n});return Y(r)?{value:r.value}:{issues:n.common.issues}}catch(r){r?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),n.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:n}).then(r=>Y(r)?{value:r.value}:{issues:n.common.issues})}async parseAsync(e,n){let r=await this.safeParseAsync(e,n);if(r.success)return r.data;throw r.error}async safeParseAsync(e,n){let r={common:{issues:[],contextualErrorMap:n?.errorMap,async:!0},path:n?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:H(e)},s=this._parse({data:e,path:r.path,parent:r}),o=await(ke(s)?s:Promise.resolve(s));return zt(r,o)}refine(e,n){let r=s=>typeof n=="string"||typeof n>"u"?{message:n}:typeof n=="function"?n(s):n;return this._refinement((s,o)=>{let i=e(s),a=()=>o.addIssue({code:p.custom,...r(s)});return typeof Promise<"u"&&i instanceof Promise?i.then(c=>c?!0:(a(),!1)):i?!0:(a(),!1)})}refinement(e,n){return this._refinement((r,s)=>e(r)?!0:(s.addIssue(typeof n=="function"?n(r,s):n),!1))}_refinement(e){return new z({schema:this,typeName:x.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:n=>this["~validate"](n)}}optional(){return j.create(this,this._def)}nullable(){return K.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return J.create(this)}promise(){return ee.create(this,this._def)}or(e){return de.create([this,e],this._def)}and(e){return fe.create(this,e,this._def)}transform(e){return new z({...E(this._def),schema:this,typeName:x.ZodEffects,effect:{type:"transform",transform:e}})}default(e){let n=typeof e=="function"?e:()=>e;return new ye({...E(this._def),innerType:this,defaultValue:n,typeName:x.ZodDefault})}brand(){return new De({typeName:x.ZodBranded,type:this,...E(this._def)})}catch(e){let n=typeof e=="function"?e:()=>e;return new _e({...E(this._def),innerType:this,catchValue:n,typeName:x.ZodCatch})}describe(e){let n=this.constructor;return new n({...this._def,description:e})}pipe(e){return Ne.create(this,e)}readonly(){return be.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}},Lr=/^c[^\s-]{8,}$/i,Fr=/^[0-9a-z]+$/,jr=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Br=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,zr=/^[a-z0-9_-]{21}$/i,Zr=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Ur=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,Hr=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Vr="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",at,Kr=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Wr=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,Gr=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,qr=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Jr=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Yr=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,Ut="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",Xr=new RegExp(`^${Ut}$`);function Ht(t){let e="[0-5]\\d";t.precision?e=`${e}\\.\\d{${t.precision}}`:t.precision==null&&(e=`${e}(\\.\\d+)?`);let n=t.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${n}`}function Qr(t){return new RegExp(`^${Ht(t)}$`)}function Vt(t){let e=`${Ut}T${Ht(t)}`,n=[];return n.push(t.local?"Z?":"Z"),t.offset&&n.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${n.join("|")})`,new RegExp(`^${e}$`)}function es(t,e){return!!((e==="v4"||!e)&&Kr.test(t)||(e==="v6"||!e)&&Gr.test(t))}function ts(t,e){if(!Zr.test(t))return!1;try{let[n]=t.split(".");if(!n)return!1;let r=n.replace(/-/g,"+").replace(/_/g,"/").padEnd(n.length+(4-n.length%4)%4,"="),s=JSON.parse(atob(r));return!(typeof s!="object"||s===null||"typ"in s&&s?.typ!=="JWT"||!s.alg||e&&s.alg!==e)}catch{return!1}}function ns(t,e){return!!((e==="v4"||!e)&&Wr.test(t)||(e==="v6"||!e)&&qr.test(t))}var X=class t extends w{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==y.string){let o=this._getOrReturnCtx(e);return h(o,{code:p.invalid_type,expected:y.string,received:o.parsedType}),v}let r=new D,s;for(let o of this._def.checks)if(o.kind==="min")e.data.length<o.value&&(s=this._getOrReturnCtx(e,s),h(s,{code:p.too_small,minimum:o.value,type:"string",inclusive:!0,exact:!1,message:o.message}),r.dirty());else if(o.kind==="max")e.data.length>o.value&&(s=this._getOrReturnCtx(e,s),h(s,{code:p.too_big,maximum:o.value,type:"string",inclusive:!0,exact:!1,message:o.message}),r.dirty());else if(o.kind==="length"){let i=e.data.length>o.value,a=e.data.length<o.value;(i||a)&&(s=this._getOrReturnCtx(e,s),i?h(s,{code:p.too_big,maximum:o.value,type:"string",inclusive:!0,exact:!0,message:o.message}):a&&h(s,{code:p.too_small,minimum:o.value,type:"string",inclusive:!0,exact:!0,message:o.message}),r.dirty())}else if(o.kind==="email")Hr.test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"email",code:p.invalid_string,message:o.message}),r.dirty());else if(o.kind==="emoji")at||(at=new RegExp(Vr,"u")),at.test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"emoji",code:p.invalid_string,message:o.message}),r.dirty());else if(o.kind==="uuid")Br.test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"uuid",code:p.invalid_string,message:o.message}),r.dirty());else if(o.kind==="nanoid")zr.test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"nanoid",code:p.invalid_string,message:o.message}),r.dirty());else if(o.kind==="cuid")Lr.test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"cuid",code:p.invalid_string,message:o.message}),r.dirty());else if(o.kind==="cuid2")Fr.test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"cuid2",code:p.invalid_string,message:o.message}),r.dirty());else if(o.kind==="ulid")jr.test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"ulid",code:p.invalid_string,message:o.message}),r.dirty());else if(o.kind==="url")try{new URL(e.data)}catch{s=this._getOrReturnCtx(e,s),h(s,{validation:"url",code:p.invalid_string,message:o.message}),r.dirty()}else o.kind==="regex"?(o.regex.lastIndex=0,o.regex.test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"regex",code:p.invalid_string,message:o.message}),r.dirty())):o.kind==="trim"?e.data=e.data.trim():o.kind==="includes"?e.data.includes(o.value,o.position)||(s=this._getOrReturnCtx(e,s),h(s,{code:p.invalid_string,validation:{includes:o.value,position:o.position},message:o.message}),r.dirty()):o.kind==="toLowerCase"?e.data=e.data.toLowerCase():o.kind==="toUpperCase"?e.data=e.data.toUpperCase():o.kind==="startsWith"?e.data.startsWith(o.value)||(s=this._getOrReturnCtx(e,s),h(s,{code:p.invalid_string,validation:{startsWith:o.value},message:o.message}),r.dirty()):o.kind==="endsWith"?e.data.endsWith(o.value)||(s=this._getOrReturnCtx(e,s),h(s,{code:p.invalid_string,validation:{endsWith:o.value},message:o.message}),r.dirty()):o.kind==="datetime"?Vt(o).test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{code:p.invalid_string,validation:"datetime",message:o.message}),r.dirty()):o.kind==="date"?Xr.test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{code:p.invalid_string,validation:"date",message:o.message}),r.dirty()):o.kind==="time"?Qr(o).test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{code:p.invalid_string,validation:"time",message:o.message}),r.dirty()):o.kind==="duration"?Ur.test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"duration",code:p.invalid_string,message:o.message}),r.dirty()):o.kind==="ip"?es(e.data,o.version)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"ip",code:p.invalid_string,message:o.message}),r.dirty()):o.kind==="jwt"?ts(e.data,o.alg)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"jwt",code:p.invalid_string,message:o.message}),r.dirty()):o.kind==="cidr"?ns(e.data,o.version)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"cidr",code:p.invalid_string,message:o.message}),r.dirty()):o.kind==="base64"?Jr.test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"base64",code:p.invalid_string,message:o.message}),r.dirty()):o.kind==="base64url"?Yr.test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"base64url",code:p.invalid_string,message:o.message}),r.dirty()):T.assertNever(o);return{status:r.value,value:e.data}}_regex(e,n,r){return this.refinement(s=>e.test(s),{validation:n,code:p.invalid_string,..._.errToObj(r)})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",..._.errToObj(e)})}url(e){return this._addCheck({kind:"url",..._.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",..._.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",..._.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",..._.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",..._.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",..._.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",..._.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",..._.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",..._.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",..._.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",..._.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",..._.errToObj(e)})}datetime(e){return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof e?.precision>"u"?null:e?.precision,offset:e?.offset??!1,local:e?.local??!1,..._.errToObj(e?.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof e?.precision>"u"?null:e?.precision,..._.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",..._.errToObj(e)})}regex(e,n){return this._addCheck({kind:"regex",regex:e,..._.errToObj(n)})}includes(e,n){return this._addCheck({kind:"includes",value:e,position:n?.position,..._.errToObj(n?.message)})}startsWith(e,n){return this._addCheck({kind:"startsWith",value:e,..._.errToObj(n)})}endsWith(e,n){return this._addCheck({kind:"endsWith",value:e,..._.errToObj(n)})}min(e,n){return this._addCheck({kind:"min",value:e,..._.errToObj(n)})}max(e,n){return this._addCheck({kind:"max",value:e,..._.errToObj(n)})}length(e,n){return this._addCheck({kind:"length",value:e,..._.errToObj(n)})}nonempty(e){return this.min(1,_.errToObj(e))}trim(){return new t({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new t({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new t({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isCIDR(){return!!this._def.checks.find(e=>e.kind==="cidr")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get isBase64url(){return!!this._def.checks.find(e=>e.kind==="base64url")}get minLength(){let e=null;for(let n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxLength(){let e=null;for(let n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}};X.create=t=>new X({checks:[],typeName:x.ZodString,coerce:t?.coerce??!1,...E(t)});function rs(t,e){let n=(t.toString().split(".")[1]||"").length,r=(e.toString().split(".")[1]||"").length,s=n>r?n:r,o=Number.parseInt(t.toFixed(s).replace(".","")),i=Number.parseInt(e.toFixed(s).replace(".",""));return o%i/10**s}var oe=class t extends w{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==y.number){let o=this._getOrReturnCtx(e);return h(o,{code:p.invalid_type,expected:y.number,received:o.parsedType}),v}let r,s=new D;for(let o of this._def.checks)o.kind==="int"?T.isInteger(e.data)||(r=this._getOrReturnCtx(e,r),h(r,{code:p.invalid_type,expected:"integer",received:"float",message:o.message}),s.dirty()):o.kind==="min"?(o.inclusive?e.data<o.value:e.data<=o.value)&&(r=this._getOrReturnCtx(e,r),h(r,{code:p.too_small,minimum:o.value,type:"number",inclusive:o.inclusive,exact:!1,message:o.message}),s.dirty()):o.kind==="max"?(o.inclusive?e.data>o.value:e.data>=o.value)&&(r=this._getOrReturnCtx(e,r),h(r,{code:p.too_big,maximum:o.value,type:"number",inclusive:o.inclusive,exact:!1,message:o.message}),s.dirty()):o.kind==="multipleOf"?rs(e.data,o.value)!==0&&(r=this._getOrReturnCtx(e,r),h(r,{code:p.not_multiple_of,multipleOf:o.value,message:o.message}),s.dirty()):o.kind==="finite"?Number.isFinite(e.data)||(r=this._getOrReturnCtx(e,r),h(r,{code:p.not_finite,message:o.message}),s.dirty()):T.assertNever(o);return{status:s.value,value:e.data}}gte(e,n){return this.setLimit("min",e,!0,_.toString(n))}gt(e,n){return this.setLimit("min",e,!1,_.toString(n))}lte(e,n){return this.setLimit("max",e,!0,_.toString(n))}lt(e,n){return this.setLimit("max",e,!1,_.toString(n))}setLimit(e,n,r,s){return new t({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:r,message:_.toString(s)}]})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:_.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:_.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:_.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:_.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:_.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:_.toString(n)})}finite(e){return this._addCheck({kind:"finite",message:_.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:_.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:_.toString(e)})}get minValue(){let e=null;for(let n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxValue(){let e=null;for(let n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&T.isInteger(e.value))}get isFinite(){let e=null,n=null;for(let r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(n===null||r.value>n)&&(n=r.value):r.kind==="max"&&(e===null||r.value<e)&&(e=r.value)}return Number.isFinite(n)&&Number.isFinite(e)}};oe.create=t=>new oe({checks:[],typeName:x.ZodNumber,coerce:t?.coerce||!1,...E(t)});var ie=class t extends w{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==y.bigint)return this._getInvalidInput(e);let r,s=new D;for(let o of this._def.checks)o.kind==="min"?(o.inclusive?e.data<o.value:e.data<=o.value)&&(r=this._getOrReturnCtx(e,r),h(r,{code:p.too_small,type:"bigint",minimum:o.value,inclusive:o.inclusive,message:o.message}),s.dirty()):o.kind==="max"?(o.inclusive?e.data>o.value:e.data>=o.value)&&(r=this._getOrReturnCtx(e,r),h(r,{code:p.too_big,type:"bigint",maximum:o.value,inclusive:o.inclusive,message:o.message}),s.dirty()):o.kind==="multipleOf"?e.data%o.value!==BigInt(0)&&(r=this._getOrReturnCtx(e,r),h(r,{code:p.not_multiple_of,multipleOf:o.value,message:o.message}),s.dirty()):T.assertNever(o);return{status:s.value,value:e.data}}_getInvalidInput(e){let n=this._getOrReturnCtx(e);return h(n,{code:p.invalid_type,expected:y.bigint,received:n.parsedType}),v}gte(e,n){return this.setLimit("min",e,!0,_.toString(n))}gt(e,n){return this.setLimit("min",e,!1,_.toString(n))}lte(e,n){return this.setLimit("max",e,!0,_.toString(n))}lt(e,n){return this.setLimit("max",e,!1,_.toString(n))}setLimit(e,n,r,s){return new t({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:r,message:_.toString(s)}]})}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:_.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:_.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:_.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:_.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:_.toString(n)})}get minValue(){let e=null;for(let n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxValue(){let e=null;for(let n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}};ie.create=t=>new ie({checks:[],typeName:x.ZodBigInt,coerce:t?.coerce??!1,...E(t)});var ae=class extends w{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==y.boolean){let r=this._getOrReturnCtx(e);return h(r,{code:p.invalid_type,expected:y.boolean,received:r.parsedType}),v}return N(e.data)}};ae.create=t=>new ae({typeName:x.ZodBoolean,coerce:t?.coerce||!1,...E(t)});var ce=class t extends w{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==y.date){let o=this._getOrReturnCtx(e);return h(o,{code:p.invalid_type,expected:y.date,received:o.parsedType}),v}if(Number.isNaN(e.data.getTime())){let o=this._getOrReturnCtx(e);return h(o,{code:p.invalid_date}),v}let r=new D,s;for(let o of this._def.checks)o.kind==="min"?e.data.getTime()<o.value&&(s=this._getOrReturnCtx(e,s),h(s,{code:p.too_small,message:o.message,inclusive:!0,exact:!1,minimum:o.value,type:"date"}),r.dirty()):o.kind==="max"?e.data.getTime()>o.value&&(s=this._getOrReturnCtx(e,s),h(s,{code:p.too_big,message:o.message,inclusive:!0,exact:!1,maximum:o.value,type:"date"}),r.dirty()):T.assertNever(o);return{status:r.value,value:new Date(e.data.getTime())}}_addCheck(e){return new t({...this._def,checks:[...this._def.checks,e]})}min(e,n){return this._addCheck({kind:"min",value:e.getTime(),message:_.toString(n)})}max(e,n){return this._addCheck({kind:"max",value:e.getTime(),message:_.toString(n)})}get minDate(){let e=null;for(let n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(let n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e!=null?new Date(e):null}};ce.create=t=>new ce({checks:[],coerce:t?.coerce||!1,typeName:x.ZodDate,...E(t)});var we=class extends w{_parse(e){if(this._getType(e)!==y.symbol){let r=this._getOrReturnCtx(e);return h(r,{code:p.invalid_type,expected:y.symbol,received:r.parsedType}),v}return N(e.data)}};we.create=t=>new we({typeName:x.ZodSymbol,...E(t)});var le=class extends w{_parse(e){if(this._getType(e)!==y.undefined){let r=this._getOrReturnCtx(e);return h(r,{code:p.invalid_type,expected:y.undefined,received:r.parsedType}),v}return N(e.data)}};le.create=t=>new le({typeName:x.ZodUndefined,...E(t)});var ue=class extends w{_parse(e){if(this._getType(e)!==y.null){let r=this._getOrReturnCtx(e);return h(r,{code:p.invalid_type,expected:y.null,received:r.parsedType}),v}return N(e.data)}};ue.create=t=>new ue({typeName:x.ZodNull,...E(t)});var Q=class extends w{constructor(){super(...arguments),this._any=!0}_parse(e){return N(e.data)}};Q.create=t=>new Q({typeName:x.ZodAny,...E(t)});var q=class extends w{constructor(){super(...arguments),this._unknown=!0}_parse(e){return N(e.data)}};q.create=t=>new q({typeName:x.ZodUnknown,...E(t)});var Z=class extends w{_parse(e){let n=this._getOrReturnCtx(e);return h(n,{code:p.invalid_type,expected:y.never,received:n.parsedType}),v}};Z.create=t=>new Z({typeName:x.ZodNever,...E(t)});var Se=class extends w{_parse(e){if(this._getType(e)!==y.undefined){let r=this._getOrReturnCtx(e);return h(r,{code:p.invalid_type,expected:y.void,received:r.parsedType}),v}return N(e.data)}};Se.create=t=>new Se({typeName:x.ZodVoid,...E(t)});var J=class t extends w{_parse(e){let{ctx:n,status:r}=this._processInputParams(e),s=this._def;if(n.parsedType!==y.array)return h(n,{code:p.invalid_type,expected:y.array,received:n.parsedType}),v;if(s.exactLength!==null){let i=n.data.length>s.exactLength.value,a=n.data.length<s.exactLength.value;(i||a)&&(h(n,{code:i?p.too_big:p.too_small,minimum:a?s.exactLength.value:void 0,maximum:i?s.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:s.exactLength.message}),r.dirty())}if(s.minLength!==null&&n.data.length<s.minLength.value&&(h(n,{code:p.too_small,minimum:s.minLength.value,type:"array",inclusive:!0,exact:!1,message:s.minLength.message}),r.dirty()),s.maxLength!==null&&n.data.length>s.maxLength.value&&(h(n,{code:p.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),r.dirty()),n.common.async)return Promise.all([...n.data].map((i,a)=>s.type._parseAsync(new B(n,i,n.path,a)))).then(i=>D.mergeArray(r,i));let o=[...n.data].map((i,a)=>s.type._parseSync(new B(n,i,n.path,a)));return D.mergeArray(r,o)}get element(){return this._def.type}min(e,n){return new t({...this._def,minLength:{value:e,message:_.toString(n)}})}max(e,n){return new t({...this._def,maxLength:{value:e,message:_.toString(n)}})}length(e,n){return new t({...this._def,exactLength:{value:e,message:_.toString(n)}})}nonempty(e){return this.min(1,e)}};J.create=(t,e)=>new J({type:t,minLength:null,maxLength:null,exactLength:null,typeName:x.ZodArray,...E(e)});function Ee(t){if(t instanceof L){let e={};for(let n in t.shape){let r=t.shape[n];e[n]=j.create(Ee(r))}return new L({...t._def,shape:()=>e})}else return t instanceof J?new J({...t._def,type:Ee(t.element)}):t instanceof j?j.create(Ee(t.unwrap())):t instanceof K?K.create(Ee(t.unwrap())):t instanceof V?V.create(t.items.map(e=>Ee(e))):t}var L=class t extends w{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;let e=this._def.shape(),n=T.objectKeys(e);return this._cached={shape:e,keys:n},this._cached}_parse(e){if(this._getType(e)!==y.object){let u=this._getOrReturnCtx(e);return h(u,{code:p.invalid_type,expected:y.object,received:u.parsedType}),v}let{status:r,ctx:s}=this._processInputParams(e),{shape:o,keys:i}=this._getCached(),a=[];if(!(this._def.catchall instanceof Z&&this._def.unknownKeys==="strip"))for(let u in s.data)i.includes(u)||a.push(u);let c=[];for(let u of i){let d=o[u],f=s.data[u];c.push({key:{status:"valid",value:u},value:d._parse(new B(s,f,s.path,u)),alwaysSet:u in s.data})}if(this._def.catchall instanceof Z){let u=this._def.unknownKeys;if(u==="passthrough")for(let d of a)c.push({key:{status:"valid",value:d},value:{status:"valid",value:s.data[d]}});else if(u==="strict")a.length>0&&(h(s,{code:p.unrecognized_keys,keys:a}),r.dirty());else if(u!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{let u=this._def.catchall;for(let d of a){let f=s.data[d];c.push({key:{status:"valid",value:d},value:u._parse(new B(s,f,s.path,d)),alwaysSet:d in s.data})}}return s.common.async?Promise.resolve().then(async()=>{let u=[];for(let d of c){let f=await d.key,l=await d.value;u.push({key:f,value:l,alwaysSet:d.alwaysSet})}return u}).then(u=>D.mergeObjectSync(r,u)):D.mergeObjectSync(r,c)}get shape(){return this._def.shape()}strict(e){return _.errToObj,new t({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(n,r)=>{let s=this._def.errorMap?.(n,r).message??r.defaultError;return n.code==="unrecognized_keys"?{message:_.errToObj(e).message??s}:{message:s}}}:{}})}strip(){return new t({...this._def,unknownKeys:"strip"})}passthrough(){return new t({...this._def,unknownKeys:"passthrough"})}extend(e){return new t({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new t({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:x.ZodObject})}setKey(e,n){return this.augment({[e]:n})}catchall(e){return new t({...this._def,catchall:e})}pick(e){let n={};for(let r of T.objectKeys(e))e[r]&&this.shape[r]&&(n[r]=this.shape[r]);return new t({...this._def,shape:()=>n})}omit(e){let n={};for(let r of T.objectKeys(this.shape))e[r]||(n[r]=this.shape[r]);return new t({...this._def,shape:()=>n})}deepPartial(){return Ee(this)}partial(e){let n={};for(let r of T.objectKeys(this.shape)){let s=this.shape[r];e&&!e[r]?n[r]=s:n[r]=s.optional()}return new t({...this._def,shape:()=>n})}required(e){let n={};for(let r of T.objectKeys(this.shape))if(e&&!e[r])n[r]=this.shape[r];else{let o=this.shape[r];for(;o instanceof j;)o=o._def.innerType;n[r]=o}return new t({...this._def,shape:()=>n})}keyof(){return Kt(T.objectKeys(this.shape))}};L.create=(t,e)=>new L({shape:()=>t,unknownKeys:"strip",catchall:Z.create(),typeName:x.ZodObject,...E(e)});L.strictCreate=(t,e)=>new L({shape:()=>t,unknownKeys:"strict",catchall:Z.create(),typeName:x.ZodObject,...E(e)});L.lazycreate=(t,e)=>new L({shape:t,unknownKeys:"strip",catchall:Z.create(),typeName:x.ZodObject,...E(e)});var de=class extends w{_parse(e){let{ctx:n}=this._processInputParams(e),r=this._def.options;function s(o){for(let a of o)if(a.result.status==="valid")return a.result;for(let a of o)if(a.result.status==="dirty")return n.common.issues.push(...a.ctx.common.issues),a.result;let i=o.map(a=>new M(a.ctx.common.issues));return h(n,{code:p.invalid_union,unionErrors:i}),v}if(n.common.async)return Promise.all(r.map(async o=>{let i={...n,common:{...n.common,issues:[]},parent:null};return{result:await o._parseAsync({data:n.data,path:n.path,parent:i}),ctx:i}})).then(s);{let o,i=[];for(let c of r){let u={...n,common:{...n.common,issues:[]},parent:null},d=c._parseSync({data:n.data,path:n.path,parent:u});if(d.status==="valid")return d;d.status==="dirty"&&!o&&(o={result:d,ctx:u}),u.common.issues.length&&i.push(u.common.issues)}if(o)return n.common.issues.push(...o.ctx.common.issues),o.result;let a=i.map(c=>new M(c));return h(n,{code:p.invalid_union,unionErrors:a}),v}}get options(){return this._def.options}};de.create=(t,e)=>new de({options:t,typeName:x.ZodUnion,...E(e)});var G=t=>t instanceof pe?G(t.schema):t instanceof z?G(t.innerType()):t instanceof me?[t.value]:t instanceof he?t.options:t instanceof ge?T.objectValues(t.enum):t instanceof ye?G(t._def.innerType):t instanceof le?[void 0]:t instanceof ue?[null]:t instanceof j?[void 0,...G(t.unwrap())]:t instanceof K?[null,...G(t.unwrap())]:t instanceof De||t instanceof be?G(t.unwrap()):t instanceof _e?G(t._def.innerType):[],Ge=class t extends w{_parse(e){let{ctx:n}=this._processInputParams(e);if(n.parsedType!==y.object)return h(n,{code:p.invalid_type,expected:y.object,received:n.parsedType}),v;let r=this.discriminator,s=n.data[r],o=this.optionsMap.get(s);return o?n.common.async?o._parseAsync({data:n.data,path:n.path,parent:n}):o._parseSync({data:n.data,path:n.path,parent:n}):(h(n,{code:p.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),v)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,n,r){let s=new Map;for(let o of n){let i=G(o.shape[e]);if(!i.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(let a of i){if(s.has(a))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(a)}`);s.set(a,o)}}return new t({typeName:x.ZodDiscriminatedUnion,discriminator:e,options:n,optionsMap:s,...E(r)})}};function ct(t,e){let n=H(t),r=H(e);if(t===e)return{valid:!0,data:t};if(n===y.object&&r===y.object){let s=T.objectKeys(e),o=T.objectKeys(t).filter(a=>s.indexOf(a)!==-1),i={...t,...e};for(let a of o){let c=ct(t[a],e[a]);if(!c.valid)return{valid:!1};i[a]=c.data}return{valid:!0,data:i}}else if(n===y.array&&r===y.array){if(t.length!==e.length)return{valid:!1};let s=[];for(let o=0;o<t.length;o++){let i=t[o],a=e[o],c=ct(i,a);if(!c.valid)return{valid:!1};s.push(c.data)}return{valid:!0,data:s}}else return n===y.date&&r===y.date&&+t==+e?{valid:!0,data:t}:{valid:!1}}var fe=class extends w{_parse(e){let{status:n,ctx:r}=this._processInputParams(e),s=(o,i)=>{if(Ke(o)||Ke(i))return v;let a=ct(o.value,i.value);return a.valid?((We(o)||We(i))&&n.dirty(),{status:n.value,value:a.data}):(h(r,{code:p.invalid_intersection_types}),v)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([o,i])=>s(o,i)):s(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}};fe.create=(t,e,n)=>new fe({left:t,right:e,typeName:x.ZodIntersection,...E(n)});var V=class t extends w{_parse(e){let{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==y.array)return h(r,{code:p.invalid_type,expected:y.array,received:r.parsedType}),v;if(r.data.length<this._def.items.length)return h(r,{code:p.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),v;!this._def.rest&&r.data.length>this._def.items.length&&(h(r,{code:p.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),n.dirty());let o=[...r.data].map((i,a)=>{let c=this._def.items[a]||this._def.rest;return c?c._parse(new B(r,i,r.path,a)):null}).filter(i=>!!i);return r.common.async?Promise.all(o).then(i=>D.mergeArray(n,i)):D.mergeArray(n,o)}get items(){return this._def.items}rest(e){return new t({...this._def,rest:e})}};V.create=(t,e)=>{if(!Array.isArray(t))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new V({items:t,typeName:x.ZodTuple,rest:null,...E(e)})};var qe=class t extends w{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==y.object)return h(r,{code:p.invalid_type,expected:y.object,received:r.parsedType}),v;let s=[],o=this._def.keyType,i=this._def.valueType;for(let a in r.data)s.push({key:o._parse(new B(r,a,r.path,a)),value:i._parse(new B(r,r.data[a],r.path,a)),alwaysSet:a in r.data});return r.common.async?D.mergeObjectAsync(n,s):D.mergeObjectSync(n,s)}get element(){return this._def.valueType}static create(e,n,r){return n instanceof w?new t({keyType:e,valueType:n,typeName:x.ZodRecord,...E(r)}):new t({keyType:X.create(),valueType:e,typeName:x.ZodRecord,...E(n)})}},Te=class extends w{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==y.map)return h(r,{code:p.invalid_type,expected:y.map,received:r.parsedType}),v;let s=this._def.keyType,o=this._def.valueType,i=[...r.data.entries()].map(([a,c],u)=>({key:s._parse(new B(r,a,r.path,[u,"key"])),value:o._parse(new B(r,c,r.path,[u,"value"]))}));if(r.common.async){let a=new Map;return Promise.resolve().then(async()=>{for(let c of i){let u=await c.key,d=await c.value;if(u.status==="aborted"||d.status==="aborted")return v;(u.status==="dirty"||d.status==="dirty")&&n.dirty(),a.set(u.value,d.value)}return{status:n.value,value:a}})}else{let a=new Map;for(let c of i){let u=c.key,d=c.value;if(u.status==="aborted"||d.status==="aborted")return v;(u.status==="dirty"||d.status==="dirty")&&n.dirty(),a.set(u.value,d.value)}return{status:n.value,value:a}}}};Te.create=(t,e,n)=>new Te({valueType:e,keyType:t,typeName:x.ZodMap,...E(n)});var Ae=class t extends w{_parse(e){let{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==y.set)return h(r,{code:p.invalid_type,expected:y.set,received:r.parsedType}),v;let s=this._def;s.minSize!==null&&r.data.size<s.minSize.value&&(h(r,{code:p.too_small,minimum:s.minSize.value,type:"set",inclusive:!0,exact:!1,message:s.minSize.message}),n.dirty()),s.maxSize!==null&&r.data.size>s.maxSize.value&&(h(r,{code:p.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),n.dirty());let o=this._def.valueType;function i(c){let u=new Set;for(let d of c){if(d.status==="aborted")return v;d.status==="dirty"&&n.dirty(),u.add(d.value)}return{status:n.value,value:u}}let a=[...r.data.values()].map((c,u)=>o._parse(new B(r,c,r.path,u)));return r.common.async?Promise.all(a).then(c=>i(c)):i(a)}min(e,n){return new t({...this._def,minSize:{value:e,message:_.toString(n)}})}max(e,n){return new t({...this._def,maxSize:{value:e,message:_.toString(n)}})}size(e,n){return this.min(e,n).max(e,n)}nonempty(e){return this.min(1,e)}};Ae.create=(t,e)=>new Ae({valueType:t,minSize:null,maxSize:null,typeName:x.ZodSet,...E(e)});var Je=class t extends w{constructor(){super(...arguments),this.validate=this.implement}_parse(e){let{ctx:n}=this._processInputParams(e);if(n.parsedType!==y.function)return h(n,{code:p.invalid_type,expected:y.function,received:n.parsedType}),v;function r(a,c){return $e({data:a,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,xe(),W].filter(u=>!!u),issueData:{code:p.invalid_arguments,argumentsError:c}})}function s(a,c){return $e({data:a,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,xe(),W].filter(u=>!!u),issueData:{code:p.invalid_return_type,returnTypeError:c}})}let o={errorMap:n.common.contextualErrorMap},i=n.data;if(this._def.returns instanceof ee){let a=this;return N(async function(...c){let u=new M([]),d=await a._def.args.parseAsync(c,o).catch(g=>{throw u.addIssue(r(c,g)),u}),f=await Reflect.apply(i,this,d);return await a._def.returns._def.type.parseAsync(f,o).catch(g=>{throw u.addIssue(s(f,g)),u})})}else{let a=this;return N(function(...c){let u=a._def.args.safeParse(c,o);if(!u.success)throw new M([r(c,u.error)]);let d=Reflect.apply(i,this,u.data),f=a._def.returns.safeParse(d,o);if(!f.success)throw new M([s(d,f.error)]);return f.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new t({...this._def,args:V.create(e).rest(q.create())})}returns(e){return new t({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,n,r){return new t({args:e||V.create([]).rest(q.create()),returns:n||q.create(),typeName:x.ZodFunction,...E(r)})}},pe=class extends w{get schema(){return this._def.getter()}_parse(e){let{ctx:n}=this._processInputParams(e);return this._def.getter()._parse({data:n.data,path:n.path,parent:n})}};pe.create=(t,e)=>new pe({getter:t,typeName:x.ZodLazy,...E(e)});var me=class extends w{_parse(e){if(e.data!==this._def.value){let n=this._getOrReturnCtx(e);return h(n,{received:n.data,code:p.invalid_literal,expected:this._def.value}),v}return{status:"valid",value:e.data}}get value(){return this._def.value}};me.create=(t,e)=>new me({value:t,typeName:x.ZodLiteral,...E(e)});function Kt(t,e){return new he({values:t,typeName:x.ZodEnum,...E(e)})}var he=class t extends w{_parse(e){if(typeof e.data!="string"){let n=this._getOrReturnCtx(e),r=this._def.values;return h(n,{expected:T.joinValues(r),received:n.parsedType,code:p.invalid_type}),v}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){let n=this._getOrReturnCtx(e),r=this._def.values;return h(n,{received:n.data,code:p.invalid_enum_value,options:r}),v}return N(e.data)}get options(){return this._def.values}get enum(){let e={};for(let n of this._def.values)e[n]=n;return e}get Values(){let e={};for(let n of this._def.values)e[n]=n;return e}get Enum(){let e={};for(let n of this._def.values)e[n]=n;return e}extract(e,n=this._def){return t.create(e,{...this._def,...n})}exclude(e,n=this._def){return t.create(this.options.filter(r=>!e.includes(r)),{...this._def,...n})}};he.create=Kt;var ge=class extends w{_parse(e){let n=T.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==y.string&&r.parsedType!==y.number){let s=T.objectValues(n);return h(r,{expected:T.joinValues(s),received:r.parsedType,code:p.invalid_type}),v}if(this._cache||(this._cache=new Set(T.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){let s=T.objectValues(n);return h(r,{received:r.data,code:p.invalid_enum_value,options:s}),v}return N(e.data)}get enum(){return this._def.values}};ge.create=(t,e)=>new ge({values:t,typeName:x.ZodNativeEnum,...E(e)});var ee=class extends w{unwrap(){return this._def.type}_parse(e){let{ctx:n}=this._processInputParams(e);if(n.parsedType!==y.promise&&n.common.async===!1)return h(n,{code:p.invalid_type,expected:y.promise,received:n.parsedType}),v;let r=n.parsedType===y.promise?n.data:Promise.resolve(n.data);return N(r.then(s=>this._def.type.parseAsync(s,{path:n.path,errorMap:n.common.contextualErrorMap})))}};ee.create=(t,e)=>new ee({type:t,typeName:x.ZodPromise,...E(e)});var z=class extends w{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===x.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){let{status:n,ctx:r}=this._processInputParams(e),s=this._def.effect||null,o={addIssue:i=>{h(r,i),i.fatal?n.abort():n.dirty()},get path(){return r.path}};if(o.addIssue=o.addIssue.bind(o),s.type==="preprocess"){let i=s.transform(r.data,o);if(r.common.async)return Promise.resolve(i).then(async a=>{if(n.value==="aborted")return v;let c=await this._def.schema._parseAsync({data:a,path:r.path,parent:r});return c.status==="aborted"?v:c.status==="dirty"?se(c.value):n.value==="dirty"?se(c.value):c});{if(n.value==="aborted")return v;let a=this._def.schema._parseSync({data:i,path:r.path,parent:r});return a.status==="aborted"?v:a.status==="dirty"?se(a.value):n.value==="dirty"?se(a.value):a}}if(s.type==="refinement"){let i=a=>{let c=s.refinement(a,o);if(r.common.async)return Promise.resolve(c);if(c instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return a};if(r.common.async===!1){let a=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return a.status==="aborted"?v:(a.status==="dirty"&&n.dirty(),i(a.value),{status:n.value,value:a.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(a=>a.status==="aborted"?v:(a.status==="dirty"&&n.dirty(),i(a.value).then(()=>({status:n.value,value:a.value}))))}if(s.type==="transform")if(r.common.async===!1){let i=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!Y(i))return v;let a=s.transform(i.value,o);if(a instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:n.value,value:a}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(i=>Y(i)?Promise.resolve(s.transform(i.value,o)).then(a=>({status:n.value,value:a})):v);T.assertNever(s)}};z.create=(t,e,n)=>new z({schema:t,typeName:x.ZodEffects,effect:e,...E(n)});z.createWithPreprocess=(t,e,n)=>new z({schema:e,effect:{type:"preprocess",transform:t},typeName:x.ZodEffects,...E(n)});var j=class extends w{_parse(e){return this._getType(e)===y.undefined?N(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};j.create=(t,e)=>new j({innerType:t,typeName:x.ZodOptional,...E(e)});var K=class extends w{_parse(e){return this._getType(e)===y.null?N(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};K.create=(t,e)=>new K({innerType:t,typeName:x.ZodNullable,...E(e)});var ye=class extends w{_parse(e){let{ctx:n}=this._processInputParams(e),r=n.data;return n.parsedType===y.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:n.path,parent:n})}removeDefault(){return this._def.innerType}};ye.create=(t,e)=>new ye({innerType:t,typeName:x.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...E(e)});var _e=class extends w{_parse(e){let{ctx:n}=this._processInputParams(e),r={...n,common:{...n.common,issues:[]}},s=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return ke(s)?s.then(o=>({status:"valid",value:o.status==="valid"?o.value:this._def.catchValue({get error(){return new M(r.common.issues)},input:r.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new M(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}};_e.create=(t,e)=>new _e({innerType:t,typeName:x.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...E(e)});var Re=class extends w{_parse(e){if(this._getType(e)!==y.nan){let r=this._getOrReturnCtx(e);return h(r,{code:p.invalid_type,expected:y.nan,received:r.parsedType}),v}return{status:"valid",value:e.data}}};Re.create=t=>new Re({typeName:x.ZodNaN,...E(t)});var ss=Symbol("zod_brand"),De=class extends w{_parse(e){let{ctx:n}=this._processInputParams(e),r=n.data;return this._def.type._parse({data:r,path:n.path,parent:n})}unwrap(){return this._def.type}},Ne=class t extends w{_parse(e){let{status:n,ctx:r}=this._processInputParams(e);if(r.common.async)return(async()=>{let o=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return o.status==="aborted"?v:o.status==="dirty"?(n.dirty(),se(o.value)):this._def.out._parseAsync({data:o.value,path:r.path,parent:r})})();{let s=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return s.status==="aborted"?v:s.status==="dirty"?(n.dirty(),{status:"dirty",value:s.value}):this._def.out._parseSync({data:s.value,path:r.path,parent:r})}}static create(e,n){return new t({in:e,out:n,typeName:x.ZodPipeline})}},be=class extends w{_parse(e){let n=this._def.innerType._parse(e),r=s=>(Y(s)&&(s.value=Object.freeze(s.value)),s);return ke(n)?n.then(s=>r(s)):r(n)}unwrap(){return this._def.innerType}};be.create=(t,e)=>new be({innerType:t,typeName:x.ZodReadonly,...E(e)});function Zt(t,e){let n=typeof t=="function"?t(e):typeof t=="string"?{message:t}:t;return typeof n=="string"?{message:n}:n}function Wt(t,e={},n){return t?Q.create().superRefine((r,s)=>{let o=t(r);if(o instanceof Promise)return o.then(i=>{if(!i){let a=Zt(e,r),c=a.fatal??n??!0;s.addIssue({code:"custom",...a,fatal:c})}});if(!o){let i=Zt(e,r),a=i.fatal??n??!0;s.addIssue({code:"custom",...i,fatal:a})}}):Q.create()}var os={object:L.lazycreate},x;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline",t.ZodReadonly="ZodReadonly"})(x||(x={}));var is=(t,e={message:`Input not instance of ${t.name}`})=>Wt(n=>n instanceof t,e),Gt=X.create,qt=oe.create,as=Re.create,cs=ie.create,Jt=ae.create,ls=ce.create,us=we.create,ds=le.create,fs=ue.create,ps=Q.create,ms=q.create,hs=Z.create,gs=Se.create,ys=J.create,_s=L.create,bs=L.strictCreate,vs=de.create,xs=Ge.create,ks=fe.create,Es=V.create,ws=qe.create,Ss=Te.create,Ts=Ae.create,As=Je.create,Rs=pe.create,Cs=me.create,Os=he.create,Is=ge.create,$s=ee.create,Ds=z.create,Ns=j.create,Ps=K.create,Ms=z.createWithPreprocess,Ls=Ne.create,Fs=()=>Gt().optional(),js=()=>qt().optional(),Bs=()=>Jt().optional(),zs={string:(t=>X.create({...t,coerce:!0})),number:(t=>oe.create({...t,coerce:!0})),boolean:(t=>ae.create({...t,coerce:!0})),bigint:(t=>ie.create({...t,coerce:!0})),date:(t=>ce.create({...t,coerce:!0}))};var Zs=v;var Ce=m.object({slug:m.string().min(1).max(64),description:m.string().max(255).optional(),match_command:m.string().min(1),priority:m.number().int().default(50),strip_ansi:m.boolean().default(!1),strip_lines_matching:m.array(m.string()).default([]),keep_failures:m.boolean().default(!1),fold_passing:m.boolean().default(!1),fold_passing_threshold:m.number().int().positive().max(1e3).optional(),mask_abs_paths:m.boolean().default(!1),preserve_exact:m.boolean().default(!1),truncate_lines_at:m.number().int().positive().max(1e4).optional(),max_lines:m.number().int().positive().max(1e5).optional(),scale_with_level:m.boolean().default(!0),transform:m.string().max(64).optional(),on_empty:m.string().max(255).optional()});var Ws=Vs(Ks(import.meta.url)),Yt=process.env.TOKMIZER_FILTERS_DIR||Qt(Ws,"..","..","filters"),te=null,Xt=!1;function Gs(){return process.env.TOKMIZER_DEV==="1"||process.env.TOKMIZER_DEV==="true"}async function en(){if(te)return te;if(!Gs())return!Xt&&process.env.TOKMIZER_DEBUG==="1"&&(process.stderr.write(`tokmizer: disk loader disabled (set TOKMIZER_DEV=1 to re-enable for local dev).
4
+ `),Xt=!0),te=new Map,te;let t=new Map,e,n;try{e=(await import("smol-toml")).parse,n=(await Us(Yt)).filter(r=>r.endsWith(".toml"))}catch{return te=t,te}for(let r of n){let s=await Hs(Qt(Yt,r),"utf8"),i=e(s).filters;if(i)for(let[a,c]of Object.entries(i)){let u=Ce.parse({slug:a,...c});t.set(a,{...u,matchRegex:new RegExp(u.match_command)})}}return te=t,te}import{createHash as qs}from"node:crypto";var Js=m.enum(["normal","compact","minimal"]),Ys=m.enum(["off","light","balanced","max"]),Pe=m.object({enabled:m.boolean().default(!0),telemetryOptIn:m.boolean().default(!0),outputVerbosity:Js.default("compact"),reducer:Ys.default("off"),filters:m.object({enableAll:m.boolean().default(!0),disabled:m.array(m.string().max(64)).max(100).default([])}).default({enableAll:!0,disabled:[]})}),Xs=["git","git-status","git-log","git-diff","grep","find","diff","ls","ls-long","ps","cat","head","tail","df","du","tree","wc","nl","xargs","seq","echo","printf","sleep","shasum","python","node","read-tool","grep-tool","glob-tool","bash-tool","npm","npm-test","docker","kubectl","curl","cargo","go-test","go-build","gh","gh-api","aws","dotnet","prisma","tsc","next","jest","vitest","pytest","pip","rspec"],Qs=/^[0-9a-f]{16}$/,tn=new Map;function U(t){let e=tn.get(t);return e||(e=qs("sha256").update(`tkr:${t}`).digest("hex").slice(0,16),tn.set(t,e)),e}var nn=null;function Ye(t,e=!1){return e||!t||t.length===0?(nn??=new Set(Xs.map(U)),new Set(nn)):new Set(t.map(n=>Qs.test(n)?n:U(n)))}var rn=new WeakMap,eo=256;function Xe(t,e,n,r=e){let s=rn.get(r);s||(s=new Map,rn.set(r,s));let o=JSON.stringify([t,n?[...n].sort():null]),i=s.get(o);if(i!==void 0)return i;let a=null;for(let c of e)n&&!n.has(U(c.slug))||c.matchRegex.test(t)&&(!a||c.priority>a.priority)&&(a=c);if(s.size>=eo){let c=s.keys().next().value;c&&s.delete(c)}return s.set(o,a),a}var to=/\x1b\[[0-9;?]*[ -/]*[@-~]/g,no=/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g;function ve(t){return t.replace(to,"").replace(no,"")}function sn(t,e){return e.length===0?t:t.filter(n=>!e.some(r=>r.test(n)))}function on(t,e){return t.map(n=>{if(n.length<=e)return n;let r=n.charCodeAt(e-1),s=n.charCodeAt(e),o=r>=55296&&r<=56319&&s>=56320&&s<=57343?e-1:e;return`${n.slice(0,o)}\u2026`})}function Qe(t){return`\u2026 (${t} more lines omitted)`}function an(t,e){if(t.length<=e)return{kept:t,dropped:[]};let n=Math.ceil(e*.7),r=e-n,s=t.slice(n,t.length-r);return{kept:[...t.slice(0,n),Qe(s.length),...t.slice(t.length-r)],dropped:s}}var ro=/^\s*(?:[✓✔√]|ok )/,ne=/✕|✗|×|\bFAIL\b|\bERROR\b|\bFATAL\b|\bError|\berror|Expected|Received|\bfailed\b|^\s*Tests?:|^\s*Test Suites?:/;function cn(t,e){let n=e>0?e:5,r=[],s=0,o=a=>{s>=n?r.push(`\u2026 ${s} passing checks folded \u2026`):r.push(...a)},i=[];for(let a of t)ro.test(a)&&!ne.test(a)?(i.push(a),s+=1):(o(i),i=[],s=0,r.push(a));return o(i),r}var so=/(?:\/[\w.@+-]+){3,}/g;function ln(t){return t.map(e=>e.replace(so,n=>{let r=n.split("/").filter(Boolean);return r.length<=2?n:`\u2026/${r.slice(-2).join("/")}`}))}var oo=/^(\s*)(?:export\s+)?(?:async\s+)?(?:function|interface|type|const|let|var|def|fn|impl|trait|struct|enum)\s+[\w$]+/,io=/\{\s*$/;var ao=/^\s*(?:(?:public|private|protected|static|async|get|set|readonly|override)\s+)*([\w$]+)\s*\(([^)]*)\)\s*(?::\s*[^{]+)?\{\s*$/,co=new Set(["if","for","while","switch","catch","do","with","return","else","function","await","yield"]);function lo(t){let e=ao.exec(t);return!e||co.has(e[1])?!1:!/=>|\bfunction\b/.test(e[2])}var uo=/^\s*(?:if|for|while|switch|try|do)\b[^{}]*\{\s*$/;function fo(t,e,n){let r=e;for(;r<t.length;){if(t[r]==="\\"){r+=2;continue}if(t[r]===n)return!0;r+=1}return!1}function po(t,e){let n=0,r=null,s=0;for(;s<t.length;){let o=t[s];if(e.inBlockComment){if(o==="*"&&t[s+1]==="/"){e.inBlockComment=!1,s+=2;continue}s+=1;continue}if(e.inTemplate){if(o==="\\"){s+=2;continue}o==="`"&&(e.inTemplate=!1),s+=1;continue}if(r){if(o==="\\"){s+=2;continue}o===r&&(r=null),s+=1;continue}if(o==="/"&&t[s+1]==="/")break;if(o==="/"&&t[s+1]==="*"){e.inBlockComment=!0,s+=2;continue}if(o==="`"){e.inTemplate=!0,s+=1;continue}if(o==="'"||o==='"'){let i=s>0?t[s-1]:"";!(o==="'"&&(i==="<"||i==="&"))&&fo(t,s+1,o)&&(r=o),s+=1;continue}o==="{"||o==="("||o==="["?n+=1:(o==="}"||o===")"||o==="]")&&(n-=1),s+=1}return n}var mo=/^\s*… (\d+) lines? folded …$/;function lt(t){let e=new Array(t.length).fill(!1);for(let n=0;n<t.length;n+=1){let r=mo.exec(t[n]);if(!r)continue;let s=Number(r[1])-1,o=n+1;for(;s>0&&o<t.length&&t[o]==="";)e[o]=!0,s-=1,o+=1;n=o-1}return e}function Me(t,e=3){let n=[],r=0;for(;r<t.length;){let s=t[r];if(oo.test(s)&&io.test(s)||lo(s)||uo.test(s)){let o={inBlockComment:!1,inTemplate:!1},i=0,a=r,c=!1;for(;a<t.length&&a-r<200;)if(i+=po(t[a],o),a+=1,i<=0&&!o.inTemplate&&!o.inBlockComment){c=!0;break}let u=a-r;if(c&&u<e){n.push(...t.slice(r,a)),r=a;continue}if(c&&u>=3){let d=u-2,f=/^\s*/.exec(t[r+1]??"")?.[0]??" ";n.push(s),n.push(`${f}\u2026 ${d} ${d===1?"line":"lines"} folded \u2026`);for(let l=0;l<d-1;l++)n.push("");n.push(t[a-1]),r=a;continue}}n.push(s),r+=1}return n}var ho=/\b(?:function|class|interface|import\s+|export\s+|def\s+|fn\s+|impl\s+|package\s+|namespace\s+|using\s+|#include|=>\s*\{|=\s*function)/;function et(t){let e=t.slice(0,4096);return!(!ho.test(e)||e.split(`
5
+ `).length<6)}var go=/^\s*(?:\d{4}-\d{2}-\d{2}[T\s]\d{2}:\d{2}:\d{2}(?:\.\d+)?Z?|\d{2}:\d{2}:\d{2}(?:\.\d+)?)\s*/,yo=/^\s*(?:\[(?:DEBUG|TRACE|INFO|VERBOSE)\]|(?:DEBUG|TRACE|INFO|VERBOSE)(?!\s*:))(?=\s|:|$)(?!\s*[+\-*\/%&|^?]*=)/,_o=new RegExp(ne.source,"i"),bo=/\bWARN(?:ING)?\b/i;function un(t){let e=[],n=0,r=()=>{n>0&&e.push(`\u2026 ${n} verbose log line${n===1?"":"s"} dropped \u2026`),n=0};for(let s of t){if(yo.test(s.replace(go,""))&&!_o.test(s)&&!bo.test(s)){n+=1;continue}r(),e.push(s)}return r(),e}function dn(t){if(t.length===0)return t;let e=[],n=1,r=t[0];for(let s=1;s<t.length;s++){if(t[s]===r){n+=1;continue}e.push(n>1?`${r} \xD7${n}`:r),r=t[s],n=1}return e.push(n>1?`${r} \xD7${n}`:r),e}function fn(t){let e=[],n=0;for(let r of t){if(r.trim()===""){n+=1;continue}n>0&&e.push(""),n=0,e.push(r)}return e}var pn=new Map;function F(t,e){pn.set(t,e)}function mn(t){return pn.get(t)}var vo=/^[dbclps\-][rwxsStT\-]{9}[@.+]?(?:\s|$)/,xo=/^[./~][^\s]*:$/,ut=1e3;function ko(t){if(t<1024)return String(t);let e=["K","M","G","T"],n=t/1024,r=0;for(;n>=1024&&r<e.length-1;)n/=1024,r+=1;return`${n.toFixed(1)}${e[r]}`}function Eo(t){if(!vo.test(t))return null;let e=t.split(/\s+/);if(e.length<9)return null;let n=Number(e[4]);if(!Number.isFinite(n))return null;let r=e.slice(8).join(" ").trim();if(r===""||r==="."||r==="..")return null;let s=e[0].charCodeAt(0)===100;return{name:r,size:n,isDir:s}}function wo(t){if(t.length<3)return null;let e=new Map;for(let s of t){let o=s.name.lastIndexOf(".");if(o<=0)continue;let i=s.name.slice(o);e.set(i,(e.get(i)??0)+1)}let n=null,r=0;for(let[s,o]of e)o>r&&(r=o,n=s);return n&&r>=Math.ceil(t.length/2)?`${r} ${n}`:null}function So(t){let e=[],n=[],r=!1;for(let l of t){if(/^total\s+\d+/.test(l))continue;if(xo.test(l.trim()))return t;let g=Eo(l);g&&(r=!0,(g.isDir?e:n).push(g))}if(!r)return t;let s=(l,g)=>l.name.localeCompare(g.name);e.sort(s),n.sort((l,g)=>g.size-l.size||s(l,g));let o=[...e,...n],i=Math.min(40,Math.max(0,...o.map(l=>l.isDir?l.name.length+1:l.name.length))),a=[];for(let l of o){let g=l.isDir?`${l.name}/`:l.name,k=l.isDir?"":ko(l.size);a.push(k?`${g.padEnd(i)} ${k}`:g)}if(a.length>ut){let l=a.length-ut;a=[...a.slice(0,ut),`\u2026 ${l} more lines omitted`]}let c=n.length===1?"file":"files",u=e.length===1?"dir":"dirs",d=wo(n),f=`${n.length} ${c}, ${e.length} ${u}`+(d?` (${d})`:"");return a.push(f),a}F("smart-ls",So);F("smart-read",t=>Me(t));var hn=1e3;function To(t){let e=t.filter(d=>d.trim()!=="");if(e.length===0||e.filter(d=>!/\s/.test(d.trim())).length<e.length*.6)return t;let r=new Map,s=[],o=0;for(let d of e){let f=d.trim();if(f.startsWith("find:")){s.push(f);continue}let l=f.replace(/^\.\//,"").replace(/\/+$/,""),g=l.lastIndexOf("/"),k=g>=0?l.slice(0,g):"",A=g>=0?l.slice(g+1):l;if(!A)continue;let b=r.get(k)??[];b.push(/\s/.test(A)?`"${A}"`:A),r.set(k,b),o+=1}if(o===0)return t;let i=new Set([""]);for(let d of r.keys()){if(d==="")continue;let f=d.split("/");for(let l=1;l<=f.length;l+=1)i.add(f.slice(0,l).join("/"))}let a=[...i].sort(),c=a.filter(d=>d!=="").length,u=[`${o}F ${c}D:`,""];for(let d of a){let f=d===""?0:d.split("/").length,l=d===""?".":d.slice(d.lastIndexOf("/")+1),g=r.get(d)??[],k=g.length?` ${g.join(" ")}`:"";u.push(`${" ".repeat(f)}${l}/${k}`)}if(u.length+s.length>hn){let d=Math.max(0,hn-s.length),f=u.length-d;return[...u.slice(0,d),`\u2026 ${f} more lines omitted`,...s]}return[...u,...s]}F("smart-find",To);var dt=1e3,gn=200,Ao=60,Ro=190,Co=/^([^\s:]+):(\d+):(.*)$/,Oo=/^([^:]+?)-(\d+)-(.*)$/,Io=/^([^\s:]+):(.*)$/,yn=/(?:^|\/)(?:__tests__|tests?|spec|fixtures?|__mocks__|__snapshots__)\/|\.(?:test|spec)\.[^/]+$/i;function _n(t){let e=t.trim();return e.length>gn?`${e.slice(0,gn)}\u2026`:e}function $o(t){let e=[],n="";for(let r of t){let s=n?`${n}, ${r}`:r;s.length>Ro&&n?(e.push(`${n},`),n=r):n=s}return n&&e.push(n),e}function Do(t){let e=t.filter(f=>f.trim()!=="");if(e.length===0)return t;let n=new Map,r=new Map,s=null,o=0,i=0;for(let f of e){if(f==="--"){s&&n.get(s).push({separator:!0});continue}if(/^[A-Za-z]:[\\/]/.test(f))return t;let l=Co.exec(f),g=Oo.exec(f);if(l&&g)return t;let k=l||g?null:Io.exec(f),A=(l??g??k)?.[1];if(!A)return t;let b=l?{line:l[2],content:l[3],context:!1}:g?{line:g[2],content:g[3],context:!0}:{line:"",content:k[2],context:!1},R=n.get(A)??[];R.push(b),n.set(A,R),b.context||(o+=1,r.set(A,(r.get(A)??0)+1)),i+=1,s=A}if(n.size===i)return t;let a=[...n.keys()].sort((f,l)=>{let g=yn.test(f)?1:0,k=yn.test(l)?1:0;return g-k||(f<l?-1:f>l?1:0)}),c=[];for(let f of a){c.push(`${f} (${r.get(f)??0}):`);for(let l of n.get(f))"separator"in l?c.push(" --"):l.line?c.push(` ${l.line}${l.context?"-":":"} ${_n(l.content)}`):c.push(` ${_n(l.content)}`)}let u=a.length>1&&c.length>Ao?$o(a.map(f=>`${f} (${r.get(f)??0})`)):[],d=[`${o}m ${a.length}f:`,...u,"",...c];if(d.length>dt){let f=d.length-dt;return[...d.slice(0,dt),`\u2026 ${f} more lines omitted`]}return d}F("smart-grep",Do);var bn=/^(?:([|\\/ ._-]*\*[|\\/* ._-]* ))?commit [0-9a-f]{7,40}\b/,No=/^[|\\/* ._-]*$/,Po=/^ {4}/,Mo=2;function Lo(t){if(!t.some(u=>bn.test(u)))return t;let e=[],n=0,r=0,s=0,o="",i=!1,a=!1,c=()=>{r>0&&e.push(`${o} \u2026 ${r} ${r===1?"line":"lines"} folded \u2026`),r=0};for(let u of t){let d=u.slice(0,s),f=No.test(d),l=f?u.slice(s):u,g=Po.test(l),k=i&&g?null:bn.exec(u);if(k){c(),n=0,s=k[1]?.length??0,i=!0,a=!1,e.push(u);continue}if(/^diff --(?:git|cc|combined) /.test(l)&&(a=!0),g&&!a&&!(s>0&&l.trim().length===0)){n+=1,n<=Mo?e.push(u):(r+=1,o=f?d:"");continue}c(),e.push(u)}return c(),e}F("smart-log",Lo);var Fo=/^[\s=]+$/,jo=/^\s*=+\s+(.*?)\s+=+\s*$/,Bo=512;F("strip-banners",t=>{let e=[];for(let n of t){if(Fo.test(n))continue;let r=n.length<=Bo?jo.exec(n):null;e.push(r?r[1]:n)}return e});function zo(t){let e=[],n=0,r=0;for(;r<t.length;){let s=t[r].replace(/\s+$/,"");if(s===""){n+=1,r+=1,n<=1&&e.push("");continue}n=0;let o=1;for(;r+o<t.length&&t[r+o].replace(/\s+$/,"")===s;)o+=1;if(o>=3)e.push(s),e.push(` \u2026 (repeated ${o}x)`);else for(let i=0;i<o;i++)e.push(s);r+=o}for(;e.length>0&&e[e.length-1]==="";)e.pop();return e}F("squeeze-output",zo);function Zo(t){return t==="compact"?.6:t==="minimal"?.3:1}var Uo=20;function Ho(t){let[e,n,r,s]=t.slice(-4);if(!e||!n||!r||!s||!/^\s*Test Files\s+([1-9]\d*) passed \(\1\)$/.test(e)||!/^\s*Tests\s+([1-9]\d*) passed \(\1\)$/.test(n)||!/^\s*Start at\s+\d{2}:\d{2}:\d{2}$/.test(r))return t;let o=/^(\s*Duration\s+\d+(?:\.\d+)?(?:ms|s)) \(transform [^\n]+\)$/.exec(s)?.[1];return o?[...t.slice(0,-4).filter((a,c)=>c>2||!/^ RUN v\d+\.\d+\.\d+(?:[\w.+-]*) .+$/.test(a)),e,n,o]:t}var vn=new WeakMap;function Vo(t){let e=vn.get(t);if(e)return e;let n=t.strip_lines_matching.map(s=>new RegExp(s)),r={def:t,stripRegexes:n};return vn.set(t,r),r}function xn(t,e,n={}){return ft(t,e,n).text}function ft(t,e,n={}){let r=n.verbosity??"normal";if(!e.strip_ansi&&e.strip_lines_matching.length===0&&!e.transform&&!e.mask_abs_paths&&!e.fold_passing&&!e.truncate_lines_at&&!e.max_lines&&!e.on_empty&&!n.smartCode&&r==="normal")return{text:t,droppedTail:null};let s=Vo(e),o=t;e.strip_ansi&&(o=ve(o));let i=o.endsWith(`
6
+ `),a=(i?o.slice(0,-1):o).split(`
7
+ `);s.stripRegexes.length&&(a=e.keep_failures?a.filter(l=>ne.test(l)||!s.stripRegexes.some(g=>g.test(l))):sn(a,s.stripRegexes)),r!=="normal"&&!e.preserve_exact&&(a=dn(a),a=fn(a)),r==="minimal"&&!e.preserve_exact&&(a=un(a),(e.slug==="vitest"||e.slug==="npm-test")&&(a=Ho(a)));let c=e.transform==="smart-read"&&n.smartCode!==!0?r==="compact"?25:r==="minimal"?13:3:3;if(!e.preserve_exact&&(n.smartCode||n.smartCode===void 0&&r!=="normal"&&et(o))&&(a=Me(a,c)),e.transform){let l=mn(e.transform);e.transform==="smart-read"?a=Me(a,c):l&&(a=l(a))}let u=e.slug==="read-tool";if(!u){let l=lt(a);l.some(Boolean)&&(a=a.filter((g,k)=>!l[k]))}e.mask_abs_paths&&(a=ln(a)),e.fold_passing&&(a=cn(a,e.fold_passing_threshold??5)),e.truncate_lines_at&&(a=on(a,e.truncate_lines_at));let d=null;if(e.max_lines){let l=e.scale_with_level?Zo(n.verbosity):1,g=Math.min(e.max_lines,Math.max(Uo,Math.round(e.max_lines*l))),k=u?lt(a):null,A=k?k.filter(b=>!b).length:a.length;if(A>g){let b=g;if(k){let S=0;for(b=0;b<a.length&&S<g;)k[b]||(S+=1),b+=1}let R=A-g;if(e.keep_failures){let S=a.slice(b),O=S.filter(P=>!ne.test(P)),I=S.reduce((P,re,Ve)=>P+(!ne.test(re)&&!k?.[b+Ve]?1:0),0);d=O.length>0?O.join(`
8
+ `):null,a=[...a.slice(0,b),...I>0?[Qe(I)]:[],...S.filter(P=>ne.test(P))]}else if(u)d=a.slice(b).join(`
9
+ `),a=[...a.slice(0,b),Qe(R)];else{let{kept:S,dropped:O}=an(a,g);d=O.length>0?O.join(`
10
+ `):null,a=S}}}let f=a.join(`
11
+ `);return i&&f.length>0&&(f+=`
12
+ `),f.trim().length===0&&e.on_empty&&(f=e.on_empty),{text:f,droppedTail:d}}var Ko=[/\bERROR\b/,/\bFAIL\b/,/\bFAILED\b/,/\bFATAL\b/,/^Traceback /m,/^Error: /m,/^\s+at .*\(.*:\d+:\d+\)/m,/panic:/,/SyntaxError:/,/TypeError:/,/ReferenceError:/,/AssertionError:/,/^\s*(?:error|fatal):/i,/thread '.*' panicked/,/\b[1-9]\d* (?:failed|errors?)\b/];function kn(t){if(!t)return!1;for(let e of ve(t).split(`
13
+ `))if(!/^\s*[✓✔√]\s/.test(e)&&Ko.some(n=>n.test(e)))return!0;return!1}var Wo=new Set(["sudo","command","time","nice","nohup","env","stdbuf","timeout"]),Go=/^[A-Za-z_][A-Za-z0-9_]*=/,pt=/^([a-z]+)-tool(?::\s|$)/;function Oe(t){let e=t.trim(),n=e.split(/\s+/),r=0;for(;r<n.length;){let a=n[r];if(Go.test(a)){r++;continue}if(Wo.has(a)){for(r++,a==="timeout"&&r<n.length&&/^\d+(?:\.\d+)?[smhd]?$/.test(n[r])&&r++;(a==="stdbuf"||a==="nice")&&r<n.length&&n[r].startsWith("-");)r++;continue}break}if(r>=n.length)return e;let s=n[r],o=s.includes("/")?s.slice(s.lastIndexOf("/")+1):s,i=n.slice(r+1);return i.length?`${o} ${i.join(" ")}`:o}var qo=new Set(["cd","export","source","set","unset","mkdir","true",":","pushd","popd","alias","ulimit","umask","echo","printf","sleep","touch","rm","cp","mv","chmod","ln"]);function En(t,e){let n=!1,r=!1,s=0,o=[];for(let i=0;i<t.length;i++){let a=t[i];if(a==="\\"&&!n){i++;continue}a==="'"&&!r?n=!n:a==='"'&&!n?r=!r:!n&&!r&&(a===";"?(o.push(t.slice(s,i)),s=i+1):a==="|"&&t[i+1]==="|"?(o.push(t.slice(s,i)),i++,s=i+1):a==="|"?e||(o.push(t.slice(s,i)),s=i+1):a==="&"&&t[i+1]==="&"&&(o.push(t.slice(s,i)),i++,s=i+1))}return o.push(t.slice(s)),o}function Jo(t){let e=En(t,!1);for(let n=e.length-1;n>=0;n--){let r=e[n].trim();if(r)return r}return t.trim()}function mt(t){let e=En(t,!0).map(n=>n.trim()).filter(Boolean);if(e.length===0)return null;for(let n of e.slice(0,-1)){let r=Oe(n).split(/\s+/)[0]??"";if(!qo.has(r))return null}return Jo(e[e.length-1])}function wn(t){let e=!1,n=!1,r=0,s=[];for(let o=0;o<t.length;o++){let i=t[o];if(i==="\\"&&!e){o++;continue}i==="'"&&!n?e=!e:i==='"'&&!e?n=!n:!e&&!n&&(i==="|"||i===";"?(s.push(t.slice(r,o)),i==="|"&&t[o+1]==="|"&&o++,r=o+1):i==="&"&&t[o+1]==="&"&&(s.push(t.slice(r,o)),o++,r=o+1))}s.push(t.slice(r));for(let o=s.length-1;o>=0;o--){let i=s[o].trim();if(i)return i}return t.trim()}function Sn(t){let e=pt.exec(t),n=t;if(e){if(e[1]!=="bash")return[t];let o=t.indexOf(": ");if(o<0)return[t];n=t.slice(o+2)}let r=mt(n),s=r?Oe(r):null;return s&&s!==t?[s,t]:[t]}var Tn=`
14
14
  [YOLO: omitted]
15
- `;function ft(t){let e=Buffer.from(t,"utf8");if(e.length<=256)return t;let n=256-Buffer.byteLength(En,"utf8"),r=Math.floor(n/2);for(;(e[r]&192)===128;)r-=1;let s=e.length-(n-r);for(;(e[s]&192)===128;)s+=1;return e.subarray(0,r).toString("utf8")+En+e.subarray(s).toString("utf8")}var Pi=/^ID {2,}TITLE {2,}BRANCH {2,}STATE {2,}CREATED *$/,Mi=/^… \([1-9]\d* more lines omitted\)$/,Li=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?Z$/;function Fi(t,e){if(!e)return t.split(`
16
- `).map(i=>i.replace(/^[ \t]+|[ \t]+(?=\r?$)/g,"")).join(`
17
- `);let n="",r=!1,s=!1;for(let i of t)r?(n+=i,s?s=!1:i==="\\"?s=!0:i==='"'&&(r=!1)):i==='"'?(r=!0,n+=i):i!==" "&&i!==" "&&i!=="\r"&&i!==`
18
- `&&(n+=i);return n+(t.endsWith(`
15
+ `;function ht(t){let e=Buffer.from(t,"utf8");if(e.length<=256)return t;let n=256-Buffer.byteLength(Tn,"utf8"),r=Math.floor(n/2);for(;(e[r]&192)===128;)r-=1;let s=e.length-(n-r);for(;(e[s]&192)===128;)s+=1;return e.subarray(0,r).toString("utf8")+Tn+e.subarray(s).toString("utf8")}var Yo=/^ID {2,}TITLE {2,}BRANCH {2,}STATE {2,}CREATED *$/,Xo=/^… \([1-9]\d* more lines omitted\)$/,gt=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?Z$/;function Qo(t,e){if(!e)return t.split(`
16
+ `).map(o=>o.replace(/^[ \t]+|[ \t]+(?=\r?$)/g,"")).join(`
17
+ `);let n="",r=!1,s=!1;for(let o of t)r?(n+=o,s?s=!1:o==="\\"?s=!0:o==='"'&&(r=!1)):o==='"'?(r=!0,n+=o):o!==" "&&o!==" "&&o!=="\r"&&o!==`
18
+ `&&(n+=o);return n+(t.endsWith(`
19
19
  `)?`
20
- `:"")}function ji(t,e){if(/@\d|\r/.test(t))return t;let n=t.endsWith(`
20
+ `:"")}function ei(t,e){if(/@(?:p)?\d|\r/.test(t))return t;let n=t.endsWith(`
21
21
  `)?`
22
22
  `:"",r=(n?t.slice(0,-1):t).split(`
23
- `),s=r.findIndex(c=>Pi.test(c));if(s>=0&&r.slice(0,s).some(c=>c!==""&&!/^Showing \d+ of \d+ (?:open|closed|all) pull requests in \S+$/.test(c)))return t;let i=s>=0?[...r[s].matchAll(/\S+/g)].map(c=>c.index):[],o=[];for(let c=s+1;c<r.length;c+=1){let g=r[c];if(Mi.test(g))continue;if(/…|\.\.\./.test(g))return t;let _;if(s>=0){if(/[^\x20-\x7e]/.test(g))return t;let k=i.map((A,R)=>g.slice(A,i[R+1]));if(k.slice(0,-1).some(A=>A[0]===" "||!A.endsWith(" "))||(_=k.map(A=>A.replace(/ +$/,"")),!/^#\d+$/.test(_[0])||!/^\S+$/.test(_[2])||!/^(OPEN|CLOSED|MERGED|DRAFT)$/.test(_[3])||!/^\d+(?:s|m|h|d|w|mo|y)$/.test(_[4])))return t}else if(_=g.split(" "),_.length!==5||!/^\d+$/.test(_[0])||!_[1]||!_[2]||!/^(OPEN|CLOSED|MERGED|DRAFT)$/.test(_[3])||!Li.test(_[4])||!Number.isFinite(Date.parse(_[4])))return t;if(_.some(k=>/[\u0000-\u001f\u007f]/.test(k)))return t;o.push({index:c,cells:_})}if(o.length===0)return t;s>=0&&(r[s]="ID TITLE BRANCH STATE CREATED");for(let c of o)r[c.index]=c.cells.join(" ");let a=r.join(`
24
- `)+n;if(!e)return a;let l=new Map;for(let{cells:c}of o)l.set(c[1],(l.get(c[1])??0)+1);let u=new Map,d=[];for(let[c,g]of l){if(c.length<40||g<3||c.trim().split(/\s+/).length<8)continue;let _=`@${u.size+1}`,k=JSON.stringify(c).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029"),A=`TITLE ${_} = ${k}`;g*(Buffer.byteLength(c)-Buffer.byteLength(_))<=Buffer.byteLength(A)+1||(u.set(c,_),d.push(A))}if(d.length===0)return a;for(let{index:c,cells:g}of o)r[c]=g.map((_,k)=>k===1?u.get(_)??_:_).join(" ");let f=[...r,"",...d].join(`
25
- `)+n;return Buffer.byteLength(f)<Buffer.byteLength(a)?f:a}function pt(t,e,n){if(e!=="compact"&&e!=="minimal")return t;let r=t;if(/^[ \t\r\n]*[\[{]/.test(t)){try{JSON.parse(t)}catch{return t}r=Fi(t,e==="minimal")}else n==="gh"&&(r=ji(t,e==="minimal"));return Buffer.byteLength(r)<Buffer.byteLength(t)?r:t}var wn=null;function mt(t){wn=t}async function Bi(t,e){let n=await Yt();return qe(t,n.values(),e)}var zi=/^(?:grep|rg|find|eslint|ruff|flake8|mypy|prettier|biome|black|stylelint)(?:\s|$)|^git\s+(?:diff|grep)\b/,Zi=2048;async function ht(t,e,n,r={}){let s=Buffer.byteLength(e,"utf8"),{exitCode:i,yolo:o=!1,...a}=r,l=Pe(xn(t.startsWith("bash-tool: ")?t.slice(11):t)),u=i!=null&&i!==0&&!(i===1&&zi.test(l)),d=wn??Bi,f=null;for(let C of kn(t))if(f=await d(C,n),f)break;!f&&s>=Zi&&!ut.test(t)&&(f=await d(`bash-tool: ${t}`,n));let c=dt(t.startsWith("bash-tool: ")?t.slice(11):t),g=f?.slug==="git-log"&&c!=null&&/^git\s+log(?:\s|$)/.test(Pe(c)),_=i==null&&(g?/^(?:fatal|error):/im.test(ge(e)):bn(e));if(!f||(u||_)&&f.preserve_exact&&!o)return{output:e,filterId:null,rawBytes:s,filteredBytes:s,debugBypass:u||_,...o?{droppedTail:null}:{}};let k=C=>{if(!o)return C;let Ce=C.filteredBytes>s||s>0&&C.output.length===0?e:C.output,Ie=!C.debugBypass&&!f?.preserve_exact?pt(Ce,"minimal",C.filterId??""):Ce,$t=ft(Ie)===Ie?Ie:ft(Ce);return{...C,output:$t,filteredBytes:Buffer.byteLength($t,"utf8"),droppedTail:null}};if(u||_){let C=o?_n(e,{...f,keep_failures:!0,transform:void 0,max_lines:void 0,truncate_lines_at:void 0,on_empty:void 0},{verbosity:"minimal",smartCode:!1}):f.strip_ansi&&!f.preserve_exact?ge(e):e;return k({output:C,filterId:f.slug,rawBytes:s,filteredBytes:Buffer.byteLength(C,"utf8"),debugBypass:!0})}let{text:A,droppedTail:R}=lt(e,f,o?{...a,verbosity:"minimal"}:a),B=!o&&!f.preserve_exact?pt(A,a.verbosity,f.slug):A,Re=Buffer.byteLength(B,"utf8");return e.trim().length>0&&Re>=s?k({output:e,filterId:f.slug,rawBytes:s,filteredBytes:s,debugBypass:!1,droppedTail:null}):k({output:B,filterId:f.slug,rawBytes:s,filteredBytes:Re,debugBypass:!1,droppedTail:R})}async function Sn(){let t=[];for await(let e of process.stdin)t.push(e);return Buffer.concat(t).toString("utf8")}import{existsSync as no}from"node:fs";import{fileURLToPath as ro}from"node:url";import{dirname as so,join as io}from"node:path";import{appendFileSync as Gi,chmodSync as Yi,mkdirSync as qi,existsSync as Ji,readFileSync as ou,rmSync as au}from"node:fs";import{dirname as Xi,join as Qi}from"node:path";import Ui from"node:os";import{join as Tn}from"node:path";function T(){return process.env.TOKMIZER_HOME||Tn(Ui.homedir(),".tokmizer")}function Me(){return Tn(T(),"install-id")}import{readFileSync as Hi,renameSync as Vi,statSync as Ki,writeFileSync as Wi}from"node:fs";function Qe(t,e,n){try{if(Ki(t).size<=e)return;let r=Hi(t,"utf8").split(`
26
- `).filter(a=>a.trim()!==""),s=[],i=0;for(let a=r.length-1;a>=0;a-=1){let l=r[a],u=Buffer.byteLength(l)+1;if(i+u>n)break;s.push(l),i+=u}s.reverse();let o=`${t}.tmp-${process.pid}`;Wi(o,s.length?`${s.join(`
23
+ `),s=r.findIndex(b=>Yo.test(b));if(s>=0&&r.slice(0,s).some(b=>b!==""&&!/^Showing \d+ of \d+ (?:open|closed|all) pull requests in \S+$/.test(b)))return t;let o=s>=0?[...r[s].matchAll(/\S+/g)].map(b=>b.index):[],i=[];for(let b=s+1;b<r.length;b+=1){let R=r[b];if(Xo.test(R))continue;if(/…|\.\.\./.test(R))return t;let S;if(s>=0){if(/[^\x20-\x7e]/.test(R))return t;let O=o.map((I,P)=>R.slice(I,o[P+1]));if(O.slice(0,-1).some(I=>I[0]===" "||!I.endsWith(" "))||(S=O.map(I=>I.replace(/ +$/,"")),!/^#\d+$/.test(S[0])||!/^\S+$/.test(S[2])||!/^(OPEN|CLOSED|MERGED|DRAFT)$/.test(S[3])||!/^\d+(?:s|m|h|d|w|mo|y)$/.test(S[4])))return t}else if(S=R.split(" "),S.length!==5||!/^\d+$/.test(S[0])||!S[1]||!S[2]||!/^(OPEN|CLOSED|MERGED|DRAFT)$/.test(S[3])||!gt.test(S[4])||!Number.isFinite(Date.parse(S[4])))return t;if(S.some(O=>/[\u0000-\u001f\u007f]/.test(O)))return t;i.push({index:b,cells:S})}if(i.length===0)return t;s>=0&&(r[s]="ID TITLE BRANCH STATE CREATED");for(let b of i)r[b.index]=b.cells.join(" ");let a=r.join(`
24
+ `)+n;if(!e)return a;let c=new Map;for(let{cells:b}of i)c.set(b[1],(c.get(b[1])??0)+1);let u=new Map,d=[];for(let[b,R]of c){if(b.length<40||R<3||b.trim().split(/\s+/).length<8)continue;let S=`@${u.size+1}`,O=JSON.stringify(b).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029"),I=`TITLE ${S} = ${O}`;R*(Buffer.byteLength(b)-Buffer.byteLength(S))<=Buffer.byteLength(I)+1||(u.set(b,S),d.push(I))}let f=new Map;for(let{cells:b}of i){if(u.has(b[1]))continue;let R=/^((?:\S+\s+){4})\S/.exec(b[1])?.[1];R&&R.length>=24&&f.set(R,(f.get(R)??0)+1)}let l=new Map;for(let[b,R]of f){if(R<3)continue;let S=`@p${l.size+1}`,O=`TITLE prefix ${S} = ${JSON.stringify(b).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}`;R*(Buffer.byteLength(b)-Buffer.byteLength(S)-1)<=Buffer.byteLength(O)+1||(l.set(b,S),d.push(O))}let g=i[0].cells[4].slice(10),k=i.length>=3&&gt.test(i[0].cells[4])&&i.every(({cells:b})=>gt.test(b[4])&&b[4].slice(10)===g)&&i.length*g.length>`CREATED suffix = ${JSON.stringify(g)}`.length+1;if(k&&d.push(`CREATED suffix = ${JSON.stringify(g)}`),d.length===0)return a;for(let{index:b,cells:R}of i){let S=u.get(R[1]),O=/^((?:\S+\s+){4})\S/.exec(R[1])?.[1],I=O?l.get(O):void 0;r[b]=R.map((P,re)=>re===1?S??(I?`${I}:${P.slice(O.length)}`:P):re===4&&k?P.slice(0,10):P).join(" ")}let A=[...r,"",...d].join(`
25
+ `)+n;return Buffer.byteLength(A)<Buffer.byteLength(a)?A:a}function yt(t,e,n){if(e!=="compact"&&e!=="minimal")return t;let r=t;if(/^[ \t\r\n]*[\[{]/.test(t)){try{JSON.parse(t)}catch{return t}r=Qo(t,e==="minimal")}else n==="gh"&&(r=ei(t,e==="minimal"));return Buffer.byteLength(r)<Buffer.byteLength(t)?r:t}var ti=/^(?:\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d+)?Z?\s+)?(?:\[(?:DEBUG|TRACE|INFO|WARN|WARNING|ERROR|FATAL)\]|DEBUG|TRACE|INFO|WARN|WARNING|ERROR|FATAL)(?::|\s|$)/,ni=/^\[tkr: previous log line repeated \d+ additional times\]$/m;function An(t){if(Buffer.byteLength(t)<2048||et(t)||ni.test(t))return t;let e=t.split(`
26
+ `),n=[];for(let r=0;r<e.length;){let s=e[r],o=r+1;if(ti.test(s))for(;o<e.length&&e[o]===s;)o+=1;let i=o-r,a=`[tkr: previous log line repeated ${i-1} additional times]`;if(i>=3&&Buffer.byteLength(a)+1<(i-1)*(Buffer.byteLength(s)+1))n.push(s,a);else for(let c=r;c<o;c+=1)n.push(s);r=o}return n.join(`
27
+ `)}var Rn=null;function _t(t){Rn=t}async function ri(t,e){let n=await en();return Xe(t,n.values(),e,n)}var si=/^(?:grep|rg|find|eslint|ruff|flake8|mypy|prettier|biome|black|stylelint)(?:\s|$)|^git\s+(?:diff|grep)\b/,oi=2048;async function bt(t,e,n,r={}){let s=Buffer.byteLength(e,"utf8"),{exitCode:o,yolo:i=!1,resolver:a,...c}=r,u=Oe(wn(t.startsWith("bash-tool: ")?t.slice(11):t)),d=o!=null&&o!==0&&!(o===1&&si.test(u)),f=a??Rn??ri,l=null;for(let $ of Sn(t))if(l=await f($,n),l)break;!l&&s>=oi&&!pt.test(t)&&(l=await f(`bash-tool: ${t}`,n));let g=mt(t.startsWith("bash-tool: ")?t.slice(11):t),k=l?.slug==="git-log"&&g!=null&&/^git\s+log(?:\s|$)/.test(Oe(g)),A=o==null&&(k?/^(?:fatal|error):/im.test(ve(e)):kn(e)),b=l?.transform==="smart-read"&&s<=16384&&(e.endsWith(`
28
+ `)?e.slice(0,-1):e).split(`
29
+ `).length<=200,R=s<=16384&&g!=null&&/^(?:head|tail)(?:\s|$)|^sed\s+(?:(?:-[Eru]+|--(?:regexp-extended|unbuffered|sandbox))\s+)*(?:-[Enruse]*n[Enruse]*(?:\s|$)|--(?:quiet|silent)(?:\s|$))/.test(Oe(g)),S=l?.transform==="smart-read"&&(c.verbosity??"normal")==="normal"&&c.smartCode!==!0;if(!i&&(S||R||b&&c.smartCode!==!0))return{output:e,filterId:l?.slug??null,rawBytes:s,filteredBytes:s,debugBypass:d||A,droppedTail:null};if(!l||(d||A)&&l.preserve_exact&&!i)return{output:e,filterId:null,rawBytes:s,filteredBytes:s,debugBypass:d||A,...i?{droppedTail:null}:{}};let O=$=>{if(!i)return $;let st=$.filteredBytes>s||s>0&&$.output.length===0?e:$.output,ot=!$.debugBypass&&!l?.preserve_exact?yt(st,"minimal",$.filterId??""):st,jt=ht(ot)===ot?ot:ht(st);return{...$,output:jt,filteredBytes:Buffer.byteLength(jt,"utf8"),droppedTail:null}};if(d||A){let $=i?xn(e,{...l,keep_failures:!0,transform:void 0,max_lines:void 0,truncate_lines_at:void 0,on_empty:void 0},{verbosity:"minimal",smartCode:!1}):l.strip_ansi&&!l.preserve_exact?ve(e):e;return!i&&c.verbosity==="minimal"&&l.transform!=="smart-read"&&($=An($)),!i&&l.slug==="pytest"&&(c.verbosity==="compact"||c.verbosity==="minimal")&&/^={3,} test session starts ={3,}\r?$/m.test($)&&/^={3,} FAILURES ={3,}\r?$/m.test($)&&($=$.replace(/^([=_])\1{2,} (.+?) \1{3,}(\r?)$/gm,"$2$3")),O({output:$,filterId:l.slug,rawBytes:s,filteredBytes:Buffer.byteLength($,"utf8"),debugBypass:!0})}let{text:I,droppedTail:P}=ft(e,l,i?{...c,verbosity:"minimal",...l.transform==="smart-read"?{smartCode:!0}:{}}:c),re=!i&&!l.preserve_exact?yt(I,c.verbosity,l.slug):I,Ve=Buffer.byteLength(re,"utf8");return e.trim().length>0&&Ve>=s?O({output:e,filterId:l.slug,rawBytes:s,filteredBytes:s,debugBypass:!1,droppedTail:null}):O({output:re,filterId:l.slug,rawBytes:s,filteredBytes:Ve,debugBypass:!1,droppedTail:P})}async function Cn(){let t=[];for await(let e of process.stdin)t.push(e);return Buffer.concat(t).toString("utf8")}import{existsSync as Nn}from"node:fs";import{fileURLToPath as bi}from"node:url";import{dirname as vi,join as Pn}from"node:path";import{appendFileSync as di,chmodSync as fi,mkdirSync as pi,existsSync as mi,readFileSync as $u,rmSync as Du}from"node:fs";import{dirname as hi,join as gi}from"node:path";import ii from"node:os";import{join as On}from"node:path";function C(){return process.env.TOKMIZER_HOME||On(ii.homedir(),".tokmizer")}function Le(){return On(C(),"install-id")}import{readFileSync as ai,renameSync as ci,statSync as li,writeFileSync as ui}from"node:fs";function In(t,e,n){try{if(li(t).size<=e)return;let r=ai(t,"utf8").split(`
30
+ `).filter(a=>a.trim()!==""),s=[],o=0;for(let a=r.length-1;a>=0;a-=1){let c=r[a],u=Buffer.byteLength(c)+1;if(o+u>n)break;s.push(c),o+=u}s.reverse();let i=`${t}.tmp-${process.pid}`;ui(i,s.length?`${s.join(`
27
31
  `)}
28
- `:"",{mode:384}),Vi(o,t)}catch{}}var eo="usage.jsonl";var An=2*1024*1024;function to(){return Qi(T(),eo)}function Rn(t,e,n=to()){try{let r=Xi(n);Ji(r)||qi(r,{recursive:!0,mode:448});let s=t.replace(/[^A-Za-z0-9._-]/g,"").slice(0,64)||"unknown";Gi(n,`{"t":${Math.floor(Date.now()/1e3)},"s":"${s}","o":${e?1:0}}
29
- `,{mode:384}),Yi(n,384),Qe(n,An,An/2)}catch{}}var oo=new Set(["tkr","tkr-exec","token","claude","cd","export","source","echo","mkdir","rm","mv","cp","chmod","ln","true","false",":","test","[","exit","return","nohup","sudo","doas","env"]),ao=new Set(["for","while","until","if","then","else","elif","fi","do","done","case","esac","select","function","time","coproc","in","!","[[","]]","{","}",".","declare","typeset","local","readonly","unset","set","shift","trap","wait","read","eval","exec","break","continue","pushd","popd","dirs","alias","unalias","hash","ulimit","umask","getopts","let","shopt","builtin","command","compgen","complete","disown","suspend","jobs","fg","bg","kill","history","fc","bind","enable","caller","type"]),Cn=new Set(["sh","bash","zsh","dash","ksh","fish","python","python3","python2","node","ruby","perl","php","awk","sed","deno","bun"]),In=/(?:^|\s)(?:--follow|-[0-9a-zA-Z]*f[a-zA-Z]*)(?:\s|=|$)/,co=new Set(["docker","podman","kubectl","nerdctl","docker-compose","stern","flyctl"]);function lo(t,e){let n=gt(e);return n==="tail"||n==="journalctl"?In.test(t):n==="stern"?!0:co.has(n)?/\blogs?\b/.test(t)&&In.test(t):!1}var On=/^[A-Za-z_][A-Za-z0-9_]*\+?=/,uo=/^[A-Za-z_][A-Za-z0-9_-]*\s*\(\s*\)/,fo=/(?:^|[;&|\n({])\s*[A-Za-z_][A-Za-z0-9_-]*\s*\(\s*\)/;function gt(t){let e=t.lastIndexOf("/");return e===-1?t:t.slice(e+1)}function po(t){let e=!1,n=!1,r=!1,s=!1;for(let i=0;i<t.length;i++){let o=t[i];if(s){s=!1;continue}if(o==="\\"&&!e){s=!0;continue}if(!n&&!r&&o==="'"){e=!e;continue}if(!e&&!r&&o==='"'){n=!n;continue}if(!e&&!n&&o==="`"){r=!r;continue}if(!e&&!n&&!r&&o===">")return!0}return!1}function Dn(t){let e=[],n="",r=0,s=!1,i=!1,o=!1,a=!1,l=0,u=0,d=()=>{n.length>0&&(e.push({kind:"cmd",text:n}),n="")},f=c=>{d(),e.push({kind:"sep",text:c})};for(;r<t.length;){let c=t[r];if(a){n+=c,a=!1,r+=1;continue}if(c==="\\"&&!s){n+=c,a=!0,r+=1;continue}if(!i&&!o&&c==="'"){s=!s,n+=c,r+=1;continue}if(!s&&!o&&c==='"'){i=!i,n+=c,r+=1;continue}if(!s&&!i&&c==="`"){o=!o,n+=c,r+=1;continue}if(!(s||i||o)){if(c==="$"&&t[r+1]==="{"){n+="${",u+=1,r+=2;continue}if(u>0){c==="{"?u+=1:c==="}"&&(u-=1),n+=c,r+=1;continue}if(c==="$"&&t[r+1]==="("){n+="$(",l+=1,r+=2;continue}if(c==="("){n+="(",l+=1,r+=1;continue}if(l>0){c==="("?l+=1:c===")"&&(l-=1),n+=c,r+=1;continue}if(c===">"&&t[r+1]==="|"){n+=">|",r+=2;continue}if(c==="&"&&t[r+1]==="&"){f("&&"),r+=2;continue}if(c==="&"&&t[r+1]!==">"){let _=n.replace(/\s+$/,""),k=_[_.length-1];if(k!==">"&&k!=="<"&&k!=="&"){f("&"),r+=1;continue}}if(c==="|"&&t[r+1]==="|"){f("||"),r+=2;continue}if(c==="|"&&t[r+1]==="&"){f("|&"),r+=2;continue}if(c===";"&&t[r+1]===";"){let _=t[r+2]==="&";f(_?";;&":";;"),r+=_?3:2;continue}if(c===";"){f(";"),r+=1;continue}if(c===`
32
+ `:"",{mode:384}),ci(i,t)}catch{}}var yi="usage.jsonl";var $n=2*1024*1024;function _i(){return gi(C(),yi)}function Dn(t,e,n=_i()){try{let r=hi(n);mi(r)||pi(r,{recursive:!0,mode:448});let s=t.replace(/[^A-Za-z0-9._-]/g,"").slice(0,64)||"unknown";di(n,`{"t":${Math.floor(Date.now()/1e3)},"s":"${s}","o":${e?1:0}}
33
+ `,{mode:384}),fi(n,384),In(n,$n,$n/2)}catch{}}var xi=new Set(["tkr","tkr-exec","token","claude","cd","export","source","echo","mkdir","rm","mv","cp","chmod","ln","true","false",":","test","[","exit","return","nohup","sudo","doas","env"]),ki=new Set(["for","while","until","if","then","else","elif","fi","do","done","case","esac","select","function","time","coproc","in","!","[[","]]","{","}",".","declare","typeset","local","readonly","unset","set","shift","trap","wait","read","eval","exec","break","continue","pushd","popd","dirs","alias","unalias","hash","ulimit","umask","getopts","let","shopt","builtin","command","compgen","complete","disown","suspend","jobs","fg","bg","kill","history","fc","bind","enable","caller","type"]),Mn=new Set(["sh","bash","zsh","dash","ksh","fish","python","python3","python2","node","ruby","perl","php","awk","sed","deno","bun"]),Ln=/(?:^|\s)(?:--follow|-[0-9a-zA-Z]*f[a-zA-Z]*)(?:\s|=|$)/,Ei=new Set(["docker","podman","kubectl","nerdctl","docker-compose","stern","flyctl"]);function wi(t,e){let n=vt(e);return n==="tail"||n==="journalctl"?Ln.test(t):n==="stern"?!0:Ei.has(n)?/\blogs?\b/.test(t)&&Ln.test(t):!1}var Fn=/^[A-Za-z_][A-Za-z0-9_]*\+?=/,Si=/^[A-Za-z_][A-Za-z0-9_-]*\s*\(\s*\)/,Ti=/(?:^|[;&|\n({])\s*[A-Za-z_][A-Za-z0-9_-]*\s*\(\s*\)/;function vt(t){let e=t.lastIndexOf("/");return e===-1?t:t.slice(e+1)}function Ai(t){let e=!1,n=!1,r=!1,s=!1;for(let o=0;o<t.length;o++){let i=t[o];if(s){s=!1;continue}if(i==="\\"&&!e){s=!0;continue}if(!n&&!r&&i==="'"){e=!e;continue}if(!e&&!r&&i==='"'){n=!n;continue}if(!e&&!n&&i==="`"){r=!r;continue}if(!e&&!n&&!r&&i===">")return!0}return!1}function jn(t){let e=[],n="",r=0,s=!1,o=!1,i=!1,a=!1,c=0,u=0,d=()=>{n.length>0&&(e.push({kind:"cmd",text:n}),n="")},f=l=>{d(),e.push({kind:"sep",text:l})};for(;r<t.length;){let l=t[r];if(a){n+=l,a=!1,r+=1;continue}if(l==="\\"&&!s){n+=l,a=!0,r+=1;continue}if(!o&&!i&&l==="'"){s=!s,n+=l,r+=1;continue}if(!s&&!i&&l==='"'){o=!o,n+=l,r+=1;continue}if(!s&&!o&&l==="`"){i=!i,n+=l,r+=1;continue}if(!(s||o||i)){if(l==="$"&&t[r+1]==="{"){n+="${",u+=1,r+=2;continue}if(u>0){l==="{"?u+=1:l==="}"&&(u-=1),n+=l,r+=1;continue}if(l==="$"&&t[r+1]==="("){n+="$(",c+=1,r+=2;continue}if(l==="("){n+="(",c+=1,r+=1;continue}if(c>0){l==="("?c+=1:l===")"&&(c-=1),n+=l,r+=1;continue}if(l===">"&&t[r+1]==="|"){n+=">|",r+=2;continue}if(l==="&"&&t[r+1]==="&"){f("&&"),r+=2;continue}if(l==="&"&&t[r+1]!==">"){let k=n.replace(/\s+$/,""),A=k[k.length-1];if(A!==">"&&A!=="<"&&A!=="&"){f("&"),r+=1;continue}}if(l==="|"&&t[r+1]==="|"){f("||"),r+=2;continue}if(l==="|"&&t[r+1]==="&"){f("|&"),r+=2;continue}if(l===";"&&t[r+1]===";"){let k=t[r+2]==="&";f(k?";;&":";;"),r+=k?3:2;continue}if(l===";"){f(";"),r+=1;continue}if(l===`
30
34
  `){f(`
31
- `),r+=1;continue}if(c==="|"){f("|"),r+=1;continue}}n+=c,r+=1}return s||i||o||l!==0||u!==0||a?[{kind:"cmd",text:t,unsafe:!0}]:(d(),e)}function mo(t){return t.trim().split(/\s+/)[0]??""}function ho(){try{let t=so(ro(import.meta.url)),e=io(t,"..","bin","tkr-exec.js");return no(e)?`node '${e.replace(/'/g,"'\\''")}'`:null}catch{return null}}function go(t,e="tkr-exec"){if(t.includes("<<")||fo.test(t))return t;let n=Dn(t),r=[];for(let s=0;s<n.length;s++){let i=n[s];if(i.kind==="sep"||i.unsafe){r.push(i.text);continue}let o=i.text.trim();if(!o){r.push(i.text);continue}let a=mo(o),l=n[s+1],u=l?.kind==="sep"&&(l.text==="|"||l.text==="|&"),d=l?.kind==="sep"&&l.text==="&";if(oo.has(a)||ao.has(a)||Cn.has(a)||Cn.has(gt(a))||On.test(a)||a.startsWith("(")||a.startsWith("#")||a.startsWith("<")||a.startsWith(">")||uo.test(o)||lo(o,a)||a.endsWith(")")||u||d||po(i.text)||i.text.includes("<(")||i.text.includes(">(")||a==="node"&&o.includes("tkr-exec.js")){r.push(i.text);continue}let f=i.text.match(/^\s*/)?.[0]??"",c=i.text.match(/\s*$/)?.[0]??"";r.push(`${f}${e} ${o}${c}`)}return r.join("")}var yo=new Set(["command","workdir","timeout_ms","yield_time_ms","max_output_tokens","shell","login","tty","description"]),_o=new Set(["cd","cat","head","tail","ls","tree","find","grep","rg","wc","nl","sort","cut","diff","stat","file","du","df","ps","jq","yq","pwd","which"]),bo=new Set(["log","diff","show","status","blame","ls-files","rev-parse","describe","shortlog"]),vo={find:/^-(?:delete|exec|execdir|ok|okdir|fprint|fls)/,sort:/^(?:-[^-]*o|--output|--compress-program)/,rg:/^(?:--pre|-[^-]*z|--search-zip)/,yq:/^(?:-[^-]*[is]|--inplace|--split-exp)/,file:/^(?:-C|--compile)/,tree:/^(?:-o|--output|-R$|-H$)/,git:/^(?:--output|--ext-diff|--textconv|-c$|--exec-path|--git-dir|--work-tree)/};function xo(t){if(/\$|`|<\(|>\(|\\\r?\n/.test(t)||/>/.test(t.replace(/2>&1|[12]?>\s*\/dev\/null/g,"")))return!1;for(let e of Dn(t)){if(e.kind==="sep")continue;if(e.unsafe)return!1;let n=e.text.trim().split(/\s+/).filter(Boolean).map(i=>i.replace(/['"\\]/g,""));if(n.length===0)continue;if(n.some(i=>On.test(i)))return!1;let r=gt(n[0]);if(r!==n[0])return!1;let s=vo[r];if(s&&n.slice(1).some(i=>s.test(i)))return!1;if(!(r==="git"?bo.has(n[1]??""):_o.has(r)))return!1}return!0}function Nn(t,e,n=ho()){if(t.tool_name!=="Bash")return null;let r=t.tool_input??{};if(r.run_in_background)return null;let s=r.command;if(typeof s!="string"||!s||e==="codex"&&Object.keys(r).some(o=>!yo.has(o))||e==="codex"&&!xo(s)||!n)return null;let i=go(s,n);return Rn(t.session_id??"unknown",i!==s),i===s?null:JSON.stringify({hookSpecificOutput:e==="codex"?{hookEventName:"PreToolUse",permissionDecision:"allow",updatedInput:{...r,command:i}}:{hookEventName:"PreToolUse",updatedInput:{command:i}}})}import{join as ko}from"node:path";import{mkdir as bu,readFile as Eo,writeFile as vu,unlink as xu,rename as ku}from"node:fs/promises";var wo="state.json";function So(){try{let t=Intl.DateTimeFormat().resolvedOptions().timeZone;return t&&t.length>0?t:"Etc/UTC"}catch{return"Etc/UTC"}}function To(t){return t?.dir??T()}async function Le(t){let e=To(t);try{let n=await Eo(ko(e,wo),"utf8"),r=JSON.parse(n);return{...r,lastSettingsRevision:r.lastSettingsRevision??0,timeZone:r.timeZone??So(),bonusActive:r.bonusActive??!1,...r.bonusResetAt!==void 0?{bonusResetAt:r.bonusResetAt}:{}}}catch{return null}}function Ao(){let t=Number(process.env.TOKMIZER_OFFLINE_GRACE_MS);return Number.isFinite(t)&&t>0?t:6048e5}function $n(t,e=Date.now()){let n=t.lastHeartbeatOkAt;if(typeof n=="number"&&e-n>Ao())return!0;if(t.subEndsAt){let r=Date.parse(t.subEndsAt);if(Number.isFinite(r)&&e>r)return!0}return!1}function Pn(t,e=Date.now()){return t.plan}import{readFile as Ro,writeFile as Au,mkdir as Ru,chmod as Cu,rm as Iu,rename as Ou,readdir as Du}from"node:fs/promises";import{join as Co}from"node:path";var Io="settings-cache.json",Mn=$e.parse({}),Mu=$e.partial().extend({filters:$e.shape.filters.removeDefault().partial().optional()});async function Fe(){try{let t=await Ro(Co(T(),Io),"utf8"),e=JSON.parse(t);return $e.parse({...Mn,...e})}catch{return Mn}}var Oo=[[/(authorization\s*:\s*)([A-Za-z][A-Za-z0-9._-]*)\s+[^\s'"]+/gi,"$1$2 [REDACTED]"],[/(authorization\s*:\s*)[A-Za-z0-9._\-+/=]{8,}/gi,"$1[REDACTED]"],[/(bearer\s+)[A-Za-z0-9._\-+/=]{8,}/gi,"$1[REDACTED]"],[/((?:^|\s)(?:-b|--cookie)[=\s]+['"]?)[^\s'";=]+=[^\s'";]+(?:\s*;\s*[^\s'";=]+=[^\s'";]+)*/gi,"$1[REDACTED]"],[/((?:^|[\s'"])(?:Set-)?Cookie\s*:\s*)[^\s'";=]+=[^\s'";]+(?:\s*;\s*[^\s'";=]+=[^\s'";]+)*/gi,"$1[REDACTED]"],[/(--?(?:password|passwd|passphrase|apipass|pass|pwd|token|api[-_]?key|secret|bearer|cookie|jwt)(?:-[a-z0-9]+)*[=\s]+)\S+/gi,"$1[REDACTED]"],[/((?:^|\s)-b[=\s]?['"]?)[^\s'"=]+=[^\s'"]+/gi,"$1[REDACTED]"],[/((?:^|\s)(?:-u[=\s]?|(?:--user|-a)[=\s])['"]?[^\s:/'"]*:)(\/[^/\s'"][^\s'"]*|[^\s/'"0-9][^\s'"]*|[0-9][^\s'"]*[^\s'"0-9][^\s'"]*)/gi,"$1[REDACTED]"],[/((?:^|\s)(?:-u[=\s]?|(?:--user|-a)[=\s])['"]?[^\s:/'"]*[^\s:/'"0-9][^\s:/'"]*:)(?:\/[^/\s'"]|[^\s/'"])[^\s'"]*/gi,"$1[REDACTED]"],[/((?:^|\s)(?:-u[=\s]?|(?:--user|-a)[=\s])['"]?:)(?:\/[^/\s'"]|[^\s/'"])[^\s'"]*/gi,"$1[REDACTED]"],[/((?:[A-Za-z0-9]+-){0,8}(?:X-Api-Key|Private-Token|[A-Za-z0-9]+-(?:Token|Key|Auth|Secret))\s*:\s*)[^\s'"]+/gi,"$1[REDACTED]"],[/((?:^|[\s'"])(?:Set-)?Cookie\s*:\s*)[^\s'"]+/gi,"$1[REDACTED]"],[/(-i\s+)(\/[^\s]+|~\/[^\s]+|[A-Z]:\\[^\s]+)/g,"$1[REDACTED]"],[/([a-zA-Z][a-zA-Z0-9+.-]{0,31}:\/\/[^:/\s@]*:)[^\s@]+(@[^@/\s]+)/g,"$1[REDACTED]$2"],[/(AWS_(?:ACCESS_KEY_ID|SECRET_ACCESS_KEY|SESSION_TOKEN)\s*=\s*)\S+/g,"$1[REDACTED]"],[/(GOOGLE_APPLICATION_CREDENTIALS\s*=\s*)\S+/g,"$1[REDACTED]"],[/(AZURE_(?:CLIENT_SECRET|TENANT_ID|CLIENT_ID)\s*=\s*)\S+/g,"$1[REDACTED]"],[/(sk-(?:proj-)?[A-Za-z0-9_-]{20,})/g,"sk-[REDACTED]"],[/\b(OPENAI_API_KEY\s*=\s*)\S+/g,"$1[REDACTED]"],[/\b(ANTHROPIC_API_KEY\s*=\s*)\S+/g,"$1[REDACTED]"],[/(sk-ant-[A-Za-z0-9_-]{20,})/g,"sk-ant-[REDACTED]"],[/\b(GH(?:_|ITHUB_)?TOKEN\s*=\s*)\S+/g,"$1[REDACTED]"],[/\b(GITLAB_TOKEN\s*=\s*)\S+/g,"$1[REDACTED]"],[/\b(SLACK_(?:BOT_)?TOKEN\s*=\s*)\S+/g,"$1[REDACTED]"],[/(xox[bpsoa]-[A-Za-z0-9-]{10,})/g,"xox[REDACTED]"],[/(xapp-[A-Za-z0-9-]{10,})/g,"[REDACTED]"],[/(sk_(?:test|live)_[A-Za-z0-9]{16,})/g,"sk_[REDACTED]"],[/(gh[a-z])_[A-Za-z0-9]{20,}/g,"$1_[REDACTED]"],[/(github_pat)_[A-Za-z0-9_]{20,}/g,"$1_[REDACTED]"],[/(gl(?:pat|rt|soat|imt|dt|ft|agent|oas|cbt|ptt))-[A-Za-z0-9_-]{16,}/g,"$1-[REDACTED]"],[/(npm_[A-Za-z0-9_-]{20,})/g,"npm_[REDACTED]"],[/(?:AKIA|ASIA|AGPA|AIDA|AROA|ANPA)[0-9A-Z]{16,}/g,"[REDACTED_AWS_KEY]"],[/AIza[A-Za-z0-9_-]{35}/g,"[REDACTED_GOOGLE_KEY]"],[/hv[sb]\.[A-Za-z0-9_-]{20,}/g,"[REDACTED_VAULT_TOKEN]"],[/dop_v1_[A-Za-z0-9]{40,}/g,"[REDACTED]"],[/dckr_pat_[A-Za-z0-9_-]{20,}/g,"[REDACTED]"],[/pypi-[A-Za-z0-9_-]{16,}/g,"[REDACTED]"],[/rk_(?:live|test)_[A-Za-z0-9]{16,}/g,"[REDACTED]"],[/whsec_[A-Za-z0-9]{16,}/g,"[REDACTED]"],[/SG\.[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}/g,"[REDACTED]"],[/(eyJ[A-Za-z0-9_-]{6,}(?:\.[A-Za-z0-9_-]{4,}){1,2})/g,"[REDACTED_JWT]"],[/-----BEGIN [A-Z ]*PRIVATE KEY-----(?:[\s\S]*?-----END[^\n]*-----|\r?\n[A-Za-z0-9+/=][A-Za-z0-9+/=\r\n]*)?/g,"[REDACTED_PEM]"],[/\b((?:--?)?[A-Za-z0-9_]*(?:TOKEN|SECRET|PASSWORD|PASSWD|PASS|APIKEY|KEY|CRED|CREDS|CREDENTIAL|CREDENTIALS|AUTH|_PWD)[A-Za-z0-9_]*['"]?\s*=\s*)(?:"[^"]*"|'[^']*'|[^"'\s]\S*)/gi,"$1[REDACTED]"],[/\b([A-Za-z0-9_]*(?:TOKEN|SECRET|PASSWORD|PASSWD|PASS|APIKEY|KEY|CRED|CREDS|CREDENTIAL|CREDENTIALS|_PWD)[A-Za-z0-9_]*['"]?\s*:\s*)(?:"[^"]*"|'[^']*'|[^\s'",}]+)/gi,"$1[REDACTED]"],[/((?:^|[\s'"{,])['"]?(?:[A-Za-z0-9_]+_)?auth['"]?\s*:\s*)(?:"[^"]*"|'[^']*'|[^\s'",}]+)/gi,"$1[REDACTED]"],[/(\bpwd\s*[=:]\s*)(?:"[^"]*"|'[^']*'|[^/~\s][^\s;'"]*)/gi,"$1[REDACTED]"],[/([=:]\s*["']?)[A-Za-z0-9_\-+/=]{40,}/g,"$1[REDACTED]"]];function je(t){let e=t;for(let[n,r]of Oo)e=e.replace(n,r);return e}import{join as zn}from"node:path";import{appendFileSync as Fo,chmodSync as jo,existsSync as Bo,mkdirSync as zo,readFileSync as ed,renameSync as td,rmdirSync as nd,statSync as Zo,unlinkSync as rd,utimesSync as sd,writeFileSync as id}from"node:fs";import{createHash as Bu,randomUUID as Do}from"node:crypto";import{readFile as Ln,writeFile as Fn,mkdir as No}from"node:fs/promises";async function yt(){try{let n=(await Ln(Me(),"utf8")).trim();if(/^[0-9a-f-]{36}$/i.test(n))return n}catch{}await No(T(),{recursive:!0});let t=Do();try{return await Fn(Me(),t,{mode:384,flag:"wx"}),t}catch{try{let e=(await Ln(Me(),"utf8")).trim();if(/^[0-9a-f-]{36}$/i.test(e))return e}catch{}return await Fn(Me(),t,{mode:384}),t}}import{createRequire as $o}from"node:module";var Po=$o(import.meta.url);function Mo(){for(let t of["../package.json","../../package.json"])try{let e=Po(t).version;if(typeof e=="string"&&e)return e}catch{}return"0.0.0"}var _t=Mo();var jn=`-----BEGIN PUBLIC KEY-----
35
+ `),r+=1;continue}if(l==="|"){f("|"),r+=1;continue}}n+=l,r+=1}return s||o||i||c!==0||u!==0||a?[{kind:"cmd",text:t,unsafe:!0}]:(d(),e)}function Ri(t){return t.trim().split(/\s+/)[0]??""}function Ci(){try{let t=vi(bi(import.meta.url)),e=Pn(t,"..","bin","tkr-exec");if(process.platform!=="win32"&&Nn(e))return`'${e.replace(/'/g,"'\\''")}'`;let n=Pn(t,"..","bin","tkr-exec.js");return Nn(n)?`node '${n.replace(/'/g,"'\\''")}'`:null}catch{return null}}function Oi(t,e="tkr-exec"){if(t.includes("<<")||Ti.test(t))return t;let n=jn(t),r=[];for(let s=0;s<n.length;s++){let o=n[s];if(o.kind==="sep"||o.unsafe){r.push(o.text);continue}let i=o.text.trim();if(!i){r.push(o.text);continue}let a=Ri(i),c=n[s+1],u=c?.kind==="sep"&&(c.text==="|"||c.text==="|&"),d=c?.kind==="sep"&&c.text==="&";if(i===e||i.startsWith(e)&&/^\s/.test(i.slice(e.length))||xi.has(a)||ki.has(a)||Mn.has(a)||Mn.has(vt(a))||Fn.test(a)||a.startsWith("(")||a.startsWith("#")||a.startsWith("<")||a.startsWith(">")||Si.test(i)||wi(i,a)||a.endsWith(")")||u||d||Ai(o.text)||o.text.includes("<(")||o.text.includes(">(")||a==="node"&&i.includes("tkr-exec.js")){r.push(o.text);continue}let f=o.text.match(/^\s*/)?.[0]??"",l=o.text.match(/\s*$/)?.[0]??"";r.push(`${f}${e} ${i}${l}`)}return r.join("")}var Ii=new Set(["command","workdir","timeout_ms","yield_time_ms","max_output_tokens","shell","login","tty","description"]),$i=new Set(["cd","cat","head","tail","ls","tree","find","grep","rg","wc","nl","sort","cut","diff","stat","file","du","df","ps","jq","yq","pwd","which"]),Di=new Set(["log","diff","show","status","blame","ls-files","rev-parse","describe","shortlog"]),Ni={find:/^-(?:delete|exec|execdir|ok|okdir|fprint|fls)/,sort:/^(?:-[^-]*o|--output|--compress-program)/,rg:/^(?:--pre|-[^-]*z|--search-zip)/,yq:/^(?:-[^-]*[is]|--inplace|--split-exp)/,file:/^(?:-C|--compile)/,tree:/^(?:-o|--output|-R$|-H$)/,git:/^(?:--output|--ext-diff|--textconv|-c$|--exec-path|--git-dir|--work-tree)/};function Pi(t){if(/\$|`|<\(|>\(|\\\r?\n/.test(t)||/>/.test(t.replace(/2>&1|[12]?>\s*\/dev\/null/g,"")))return!1;for(let e of jn(t)){if(e.kind==="sep")continue;if(e.unsafe)return!1;let n=e.text.trim().split(/\s+/).filter(Boolean).map(o=>o.replace(/['"\\]/g,""));if(n.length===0)continue;if(n.some(o=>Fn.test(o)))return!1;let r=vt(n[0]);if(r!==n[0])return!1;let s=Ni[r];if(s&&n.slice(1).some(o=>s.test(o)))return!1;if(!(r==="git"?Di.has(n[1]??""):$i.has(r)))return!1}return!0}function Bn(t,e,n=Ci(),r=Dn){if(t.tool_name!=="Bash")return null;let s=t.tool_input??{};if(s.run_in_background)return null;let o=s.command;if(typeof o!="string"||!o||e==="codex"&&Object.keys(s).some(a=>!Ii.has(a))||e==="codex"&&!Pi(o)||!n)return null;let i=Oi(o,n);return r(t.session_id??"unknown",i!==o),i===o?null:JSON.stringify({hookSpecificOutput:e==="codex"?{hookEventName:"PreToolUse",permissionDecision:"allow",updatedInput:{...s,command:i}}:{hookEventName:"PreToolUse",updatedInput:{command:i}}})}import{join as Mi}from"node:path";import{mkdir as Vu,readFile as Li,writeFile as Ku,unlink as Wu,rename as Gu}from"node:fs/promises";var Fi="state.json";function ji(){try{let t=Intl.DateTimeFormat().resolvedOptions().timeZone;return t&&t.length>0?t:"Etc/UTC"}catch{return"Etc/UTC"}}function Bi(t){return t?.dir??C()}async function Fe(t){let e=Bi(t);try{let n=await Li(Mi(e,Fi),"utf8"),r=JSON.parse(n),s=r.timeZone;return{...r,lastSettingsRevision:r.lastSettingsRevision??0,get timeZone(){return s??=ji()},bonusActive:r.bonusActive??!1,...r.bonusResetAt!==void 0?{bonusResetAt:r.bonusResetAt}:{}}}catch{return null}}function zi(){let t=Number(process.env.TOKMIZER_OFFLINE_GRACE_MS);return Number.isFinite(t)&&t>0?t:6048e5}function zn(t,e=Date.now()){let n=t.lastHeartbeatOkAt;if(typeof n=="number"&&e-n>zi())return!0;if(t.subEndsAt){let r=Date.parse(t.subEndsAt);if(Number.isFinite(r)&&e>r)return!0}return!1}function Zn(t,e=Date.now()){return t.plan}import{readFile as Zi,writeFile as Qu,mkdir as ed,chmod as td,rm as nd,rename as rd,readdir as sd}from"node:fs/promises";import{join as Ui}from"node:path";var Hi="settings-cache.json",Un=Pe.parse({}),cd=Pe.partial().extend({filters:Pe.shape.filters.removeDefault().partial().optional()});async function je(){try{let t=await Zi(Ui(C(),Hi),"utf8"),e=JSON.parse(t);return Pe.parse({...Un,...e})}catch{return Un}}var Vi=[[/(authorization\s*:\s*)([A-Za-z][A-Za-z0-9._-]*)\s+[^\s'"]+/gi,"$1$2 [REDACTED]"],[/(authorization\s*:\s*)[A-Za-z0-9._\-+/=]{8,}/gi,"$1[REDACTED]"],[/(bearer\s+)[A-Za-z0-9._\-+/=]{8,}/gi,"$1[REDACTED]"],[/((?:^|\s)(?:-b|--cookie)[=\s]+['"]?)[^\s'";=]+=[^\s'";]+(?:\s*;\s*[^\s'";=]+=[^\s'";]+)*/gi,"$1[REDACTED]"],[/((?:^|[\s'"])(?:Set-)?Cookie\s*:\s*)[^\s'";=]+=[^\s'";]+(?:\s*;\s*[^\s'";=]+=[^\s'";]+)*/gi,"$1[REDACTED]"],[/(--?(?:password|passwd|passphrase|apipass|pass|pwd|token|api[-_]?key|secret|bearer|cookie|jwt)(?:-[a-z0-9]+)*[=\s]+)\S+/gi,"$1[REDACTED]"],[/((?:^|\s)-b[=\s]?['"]?)[^\s'"=]+=[^\s'"]+/gi,"$1[REDACTED]"],[/((?:^|\s)(?:-u[=\s]?|(?:--user|-a)[=\s])['"]?[^\s:/'"]*:)(\/[^/\s'"][^\s'"]*|[^\s/'"0-9][^\s'"]*|[0-9][^\s'"]*[^\s'"0-9][^\s'"]*)/gi,"$1[REDACTED]"],[/((?:^|\s)(?:-u[=\s]?|(?:--user|-a)[=\s])['"]?[^\s:/'"]*[^\s:/'"0-9][^\s:/'"]*:)(?:\/[^/\s'"]|[^\s/'"])[^\s'"]*/gi,"$1[REDACTED]"],[/((?:^|\s)(?:-u[=\s]?|(?:--user|-a)[=\s])['"]?:)(?:\/[^/\s'"]|[^\s/'"])[^\s'"]*/gi,"$1[REDACTED]"],[/((?:[A-Za-z0-9]+-){0,8}(?:X-Api-Key|Private-Token|[A-Za-z0-9]+-(?:Token|Key|Auth|Secret))\s*:\s*)[^\s'"]+/gi,"$1[REDACTED]"],[/((?:^|[\s'"])(?:Set-)?Cookie\s*:\s*)[^\s'"]+/gi,"$1[REDACTED]"],[/(-i\s+)(\/[^\s]+|~\/[^\s]+|[A-Z]:\\[^\s]+)/g,"$1[REDACTED]"],[/([a-zA-Z][a-zA-Z0-9+.-]{0,31}:\/\/[^:/\s@]*:)[^\s@]+(@[^@/\s]+)/g,"$1[REDACTED]$2"],[/(AWS_(?:ACCESS_KEY_ID|SECRET_ACCESS_KEY|SESSION_TOKEN)\s*=\s*)\S+/g,"$1[REDACTED]"],[/(GOOGLE_APPLICATION_CREDENTIALS\s*=\s*)\S+/g,"$1[REDACTED]"],[/(AZURE_(?:CLIENT_SECRET|TENANT_ID|CLIENT_ID)\s*=\s*)\S+/g,"$1[REDACTED]"],[/(sk-(?:proj-)?[A-Za-z0-9_-]{20,})/g,"sk-[REDACTED]"],[/\b(OPENAI_API_KEY\s*=\s*)\S+/g,"$1[REDACTED]"],[/\b(ANTHROPIC_API_KEY\s*=\s*)\S+/g,"$1[REDACTED]"],[/(sk-ant-[A-Za-z0-9_-]{20,})/g,"sk-ant-[REDACTED]"],[/\b(GH(?:_|ITHUB_)?TOKEN\s*=\s*)\S+/g,"$1[REDACTED]"],[/\b(GITLAB_TOKEN\s*=\s*)\S+/g,"$1[REDACTED]"],[/\b(SLACK_(?:BOT_)?TOKEN\s*=\s*)\S+/g,"$1[REDACTED]"],[/(xox[bpsoa]-[A-Za-z0-9-]{10,})/g,"xox[REDACTED]"],[/(xapp-[A-Za-z0-9-]{10,})/g,"[REDACTED]"],[/(sk_(?:test|live)_[A-Za-z0-9]{16,})/g,"sk_[REDACTED]"],[/(gh[a-z])_[A-Za-z0-9]{20,}/g,"$1_[REDACTED]"],[/(github_pat)_[A-Za-z0-9_]{20,}/g,"$1_[REDACTED]"],[/(gl(?:pat|rt|soat|imt|dt|ft|agent|oas|cbt|ptt))-[A-Za-z0-9_-]{16,}/g,"$1-[REDACTED]"],[/(npm_[A-Za-z0-9_-]{20,})/g,"npm_[REDACTED]"],[/(?:AKIA|ASIA|AGPA|AIDA|AROA|ANPA)[0-9A-Z]{16,}/g,"[REDACTED_AWS_KEY]"],[/AIza[A-Za-z0-9_-]{35}/g,"[REDACTED_GOOGLE_KEY]"],[/hv[sb]\.[A-Za-z0-9_-]{20,}/g,"[REDACTED_VAULT_TOKEN]"],[/dop_v1_[A-Za-z0-9]{40,}/g,"[REDACTED]"],[/dckr_pat_[A-Za-z0-9_-]{20,}/g,"[REDACTED]"],[/pypi-[A-Za-z0-9_-]{16,}/g,"[REDACTED]"],[/rk_(?:live|test)_[A-Za-z0-9]{16,}/g,"[REDACTED]"],[/whsec_[A-Za-z0-9]{16,}/g,"[REDACTED]"],[/SG\.[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}/g,"[REDACTED]"],[/(eyJ[A-Za-z0-9_-]{6,}(?:\.[A-Za-z0-9_-]{4,}){1,2})/g,"[REDACTED_JWT]"],[/-----BEGIN [A-Z ]*PRIVATE KEY-----(?:[\s\S]*?-----END[^\n]*-----|\r?\n[A-Za-z0-9+/=][A-Za-z0-9+/=\r\n]*)?/g,"[REDACTED_PEM]"],[/\b((?:--?)?[A-Za-z0-9_]*(?:TOKEN|SECRET|PASSWORD|PASSWD|PASS|APIKEY|KEY|CRED|CREDS|CREDENTIAL|CREDENTIALS|AUTH|_PWD)[A-Za-z0-9_]*['"]?\s*=\s*)(?:"[^"]*"|'[^']*'|[^"'\s]\S*)/gi,"$1[REDACTED]"],[/\b([A-Za-z0-9_]*(?:TOKEN|SECRET|PASSWORD|PASSWD|PASS|APIKEY|KEY|CRED|CREDS|CREDENTIAL|CREDENTIALS|_PWD)[A-Za-z0-9_]*['"]?\s*:\s*)(?:"[^"]*"|'[^']*'|[^\s'",}]+)/gi,"$1[REDACTED]"],[/((?:^|[\s'"{,])['"]?(?:[A-Za-z0-9_]+_)?auth['"]?\s*:\s*)(?:"[^"]*"|'[^']*'|[^\s'",}]+)/gi,"$1[REDACTED]"],[/(\bpwd\s*[=:]\s*)(?:"[^"]*"|'[^']*'|[^/~\s][^\s;'"]*)/gi,"$1[REDACTED]"],[/([=:]\s*["']?)[A-Za-z0-9_\-+/=]{40,}/g,"$1[REDACTED]"]];function Be(t){let e=t;for(let[n,r]of Vi)e=e.replace(n,r);return e}import{join as Gn}from"node:path";import{appendFileSync as Xi,chmodSync as Qi,existsSync as ea,mkdirSync as ta,readFileSync as Td,renameSync as Ad,rmdirSync as Rd,statSync as na,unlinkSync as Cd,utimesSync as Od,writeFileSync as Id}from"node:fs";import{createHash as fd,randomUUID as Ki}from"node:crypto";import{readFile as Hn,writeFile as Vn,mkdir as Wi}from"node:fs/promises";async function xt(){try{let n=(await Hn(Le(),"utf8")).trim();if(/^[0-9a-f-]{36}$/i.test(n))return n}catch{}await Wi(C(),{recursive:!0});let t=Ki();try{return await Vn(Le(),t,{mode:384,flag:"wx"}),t}catch{try{let e=(await Hn(Le(),"utf8")).trim();if(/^[0-9a-f-]{36}$/i.test(e))return e}catch{}return await Vn(Le(),t,{mode:384}),t}}import{createRequire as Gi}from"node:module";var qi=Gi(import.meta.url);function Ji(){for(let t of["../package.json","../../package.json"])try{let e=qi(t).version;if(typeof e=="string"&&e)return e}catch{}return"0.0.0"}var kt=Ji();var Kn=`-----BEGIN PUBLIC KEY-----
32
36
  MCowBQYDK2VwAyEAj/kMlXlhTIGHRKxOKMuGFa1S1ybxxwgdYcAE0YM9fgU=
33
37
  -----END PUBLIC KEY-----
34
- `;var Yu=300*1e3;function Bn(){return((process.env.TOKMIZER_DEV==="1"?process.env.TOKMIZER_RESP_SIGNING_PUBLIC_KEY_PEM:void 0)??jn).replace(/\\n/g,`
35
- `)}var Uo=512*1024;function Zn(){return zn(T(),"spool")}function Ho(t){return zn(Zn(),`${t}.jsonl`)}function et(t,e){try{zo(Zn(),{recursive:!0,mode:448});let n=Ho(t);if(Bo(n)&&Zo(n).size>=Uo)return;Fo(n,JSON.stringify(e)+`
36
- `,{mode:384}),jo(n,384)}catch{return}}var Ko=/^[a-z0-9][a-z0-9._-]*$/i,Wo=/^[a-z][a-z-]+$/,Go=/^[A-Za-z_][A-Za-z0-9_]*=/,Yo=new Set(["gh","glab","gup","hub","gist"]),qo=/^(gh[a-z]_|github_pat_|gl(?:pat|rt|soat|imt|dt|ft|agent|oas)-|npm_|xox|sk-|sk_|eyj|a(?:kia|sia|gpa|ida|roa|npa)|aiza|hv[sb]\.)/i,Jo=24,Xo=new Set(["docker","podman","npm","pnpm","yarn","npx","bun","deno","cargo","rustup","go","pip","pip3","uv","poetry","brew","apt","apt-get","dnf","yum","pacman","kubectl","helm","terraform","aws","gcloud","az","systemctl","composer","bundle","gem","dotnet","prisma","tkr","rtk","token"]);function Un(t){let e=t.toLowerCase();return e.startsWith("git")||Yo.has(e)}function bt(t){let e=t.trim().split(/\s+/).filter(a=>a.length>0),n=0;for(;n<e.length&&Go.test(e[n]??"");)n+=1;let r=e[n];if(!r||!Ko.test(r)||r.length>Jo||Un(r)||qo.test(r)||je(r)!==r)return"";let s=e[n+1];return s&&Un(s)?"":(s&&Xo.has(r.toLowerCase())&&Wo.test(s)?`${r} ${s}`:r).slice(0,64)}async function Hn(t){if(!t.telemetryOptIn)return;let e=bt(t.cmd),n=e&&je(e)===e?e:"other",r=t.sessionId?t.sessionId.replace(/[^A-Za-z0-9._-]/g,"").slice(0,64):"";et("telemetry",{cmd:n,tokensSaved:Math.max(0,Math.round(t.tokensSaved)),...t.tokensRestored?{tokensRestored:Math.max(0,Math.round(t.tokensRestored))}:{},...t.rawTokens!=null?{rawTokens:Math.max(0,Math.round(t.rawTokens))}:{},optimized:t.optimized,...r?{sessionId:r}:{},...t.host?{host:t.host}:{}})}async function Vn(t){if(t.plan!=="pro"||!(await Fe()).telemetryOptIn)return;let e=bt(t.cmd);!e||je(e)!==e||et("learn",{cmd:e,filterId:t.filterId==null?null:j(t.filterId),rawBytes:t.rawBytes,filteredBytes:t.filteredBytes})}import{appendFileSync as Qo,chmodSync as ea,mkdirSync as ta}from"node:fs";import{join as na}from"node:path";var ra="stats.jsonl";var Kn=2*1024*1024;var sa=new Set(["sudo","command","time","nice","nohup","env","stdbuf","timeout"]),ia=new Set(["-u","-g","-n","-s","-k"]),oa=/^[a-z0-9][a-z0-9._-]*$/i,aa=new Set(["git","npm","pnpm","yarn","npx","docker","kubectl","helm","cargo","go","brew","gh","pip","pip3","apt","apt-get","systemctl","terraform","aws","gcloud","az","bundle","rake","rails","prisma","poetry","uv","gem","composer"]),Gn=/^[A-Za-z_][A-Za-z0-9_]*=/;function Wn(t){return t.length===0||t[0]==="cd"||t.every(e=>Gn.test(e))}function ca(t){let e=[],n="",r=!1,s=null,i=()=>{r&&e.push(n),n="",r=!1};for(let o of t){if(s){o===s?s=null:n+=o;continue}if(o==="'"||o==='"'){s=o,r=!0;continue}if(o===" "||o===" "){i();continue}if(`|;&<>
37
- `.includes(o)){if(i(),Wn(e)){e=[];continue}return e}n+=o,r=!0}return i(),Wn(e)?[]:e}function Yn(t){let e=ca(t).map(a=>a.replace(/^[({]+/,"")).filter(Boolean),n=0;for(;n<e.length;){let a=e[n];if(Gn.test(a)){n+=1;continue}if(sa.has(a)){for(n+=1;n<e.length;){let l=e[n];if(l.startsWith("-")){n+=ia.has(l)?2:1;continue}if(/^\d+(?:\.\d+)?[smhd]?$/.test(l)){n+=1;continue}break}continue}break}if(n>=e.length)return"";let r=e[n],s=r.includes("/")?r.slice(r.lastIndexOf("/")+1):r,i=e[n+1];return(i&&!i.startsWith("-")&&oa.test(i)&&aa.has(s.toLowerCase())?`${s} ${i}`:s).slice(0,24)}function la(){return na(T(),ra)}function qn(t,e,n=la(),r=!1,s,i,o){if(!Number.isSafeInteger(t)||!Number.isSafeInteger(e)||t<0||e<0||t+e===0)return;let a=s?`,"h":${JSON.stringify(s)}`:"",l=i?`,"k":${JSON.stringify(i)}`:"",u=o?`,"c":${JSON.stringify(o.slice(0,24))}`:"",d=`{"t":${Math.floor(Date.now()/1e3)},"r":${t},"f":${e}${r?',"m":1':""}${a}${l}${u}}
38
- `;try{ta(T(),{recursive:!0,mode:448}),Qo(n,d,{mode:384}),ea(n,384),Qe(n,Kn,Kn/2)}catch{return}}function Jn(t,e,n){let r=n!=null?Math.min(t,n):t,s=n!=null?Math.min(e,n):e;return{raw:r,filtered:s}}var ua=[{host:"claude-code",vars:["CLAUDECODE","CLAUDE_CODE_ENTRYPOINT","CLAUDE_CODE","CLAUDE_CODE_VERSION","ANTHROPIC_CLAUDE_CODE"]},{host:"codex",vars:["CODEX_VERSION","CODEX_CLI","OPENAI_CODEX","CODEX_THREAD_ID","CODEX_SESSION_ID"]},{host:"cursor",vars:["CURSOR_VERSION","CURSOR_TRACE_ID"]},{host:"cline",vars:["CLINE_VERSION","CLINE_API_KEY"]},{host:"aider",vars:["AIDER_VERSION","AIDER_MODEL"]},{host:"gemini-cli",vars:["GEMINI_CLI_VERSION","GEMINI_API_KEY"]},{host:"windsurf",vars:["WINDSURF_VERSION","WINDSURF_USER"]},{host:"copilot",vars:["GITHUB_COPILOT_VERSION","COPILOT_INTEGRATION_ID"]}],Cd=[...ua.map(t=>t.host),"shell"];function Xn(t){return null}import{createConnection as wa}from"node:net";import{spawn as Sa}from"node:child_process";import{existsSync as ir,openSync as Et,closeSync as rr,unlinkSync as St,writeFileSync as Tt,mkdirSync as At,readFileSync as Ta,appendFileSync as Aa,rmSync as Ra,statSync as Ca}from"node:fs";import{dirname as Ia,join as Rt}from"node:path";import{fileURLToPath as Oa}from"node:url";var da=m.object({id:m.string().min(1).max(64),op:m.literal("filter"),cmd:m.string().min(1).max(2048),plan:m.enum(["trial","smart","pro"]),allowed:m.array(m.string().min(1).max(64)).max(512).optional(),installId:m.string().min(1).max(64).optional()}),fa=m.object({id:m.string().min(1).max(64),op:m.literal("ping")}),pa=m.object({id:m.string().min(1).max(64),op:m.literal("shutdown"),installId:m.string().min(1).max(64)}),ma=m.object({id:m.string().min(1).max(64),op:m.literal("reload"),installId:m.string().min(1).max(64).optional()}),Nd=m.discriminatedUnion("op",[da,fa,pa,ma]),$d=m.object({id:m.string(),ok:m.literal(!0),data:m.unknown()}),Pd=m.object({id:m.string(),ok:m.literal(!1),err:m.string(),retryAfterMs:m.number().int().nonnegative().optional()}),Qn=m.object({filter:Se.nullable(),cacheHit:m.boolean().optional()}),tt=`
39
- `,Md=64*1024;function vt(t){return JSON.stringify(t)+tt}function*er(t){let e=0;for(;;){let n=t.indexOf(tt,e);if(n<0)return;yield t.slice(e,n),e=n+1}}function Be(){return`${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}import ha from"node:os";import{join as ze}from"node:path";import{existsSync as ga,statSync as ya,lstatSync as tr,unlinkSync as _a,mkdirSync as ba,chmodSync as va}from"node:fs";import{createHash as xa}from"node:crypto";var xt=100;function ka(t){let e=xa("sha256").update(T()).digest("hex").slice(0,8),n=ze(ha.tmpdir(),`tkr-${t}-${e}`),r=ze(n,"d.sock");if(Buffer.byteLength(r)>xt)throw new Error("Temporary directory path is too long for IPC");return nr(n,t),r}function Ea(t,e){try{let n=tr(t);return n.isDirectory()&&n.uid===e&&(n.mode&63)===0}catch{return!1}}function nr(t,e){ba(t,{recursive:!0,mode:448});let n=tr(t);if(!n.isDirectory()||n.uid!==e)throw new Error("Unsafe IPC directory");va(t,448)}function Ze(){if(process.platform==="win32")return{path:`\\\\.\\pipe\\tokmizer-${process.env.USERNAME??"tokmizer"}`,isPipe:!0};let t=typeof process.getuid=="function"?process.getuid():0,e=process.env.XDG_RUNTIME_DIR;if(e&&Ea(e,t)){let s=ze(e,`tokmizer-${t}.sock`);if(Buffer.byteLength(s)<=xt)return{path:s,isPipe:!1}}let n=ze(T(),"run"),r=ze(n,"daemon.sock");return Buffer.byteLength(r)>xt?{path:ka(t),isPipe:!1}:(nr(n,t),{path:r,isPipe:!1})}async function kt(){let{path:t,isPipe:e}=Ze();if(e||!ga(t))return;try{if(!ya(t).isSocket())return}catch{return}let n=await import("node:net");if(!await new Promise(s=>{let i=n.createConnection(t),o=a=>{i.removeAllListeners();try{i.destroy()}catch{}s(a)};i.once("connect",()=>o(!0)),i.once("error",a=>{let l=a.code;o(l!=="ECONNREFUSED"&&l!=="ENOENT")}),setTimeout(()=>o(!0),250)}))try{_a(t)}catch{}}var Ud=5*6e4;var or=500,Da=3e3,sr=1,Na=6e4,$a=256*1024;function Ct(){return Rt(T(),"daemon.spawn.fail")}function It(){return Rt(T(),"daemon.log")}function Pa(){try{let t=Number(Ta(Ct(),"utf8"));return Number.isFinite(t)&&Date.now()-t<Na}catch{return!1}}function Ma(t){try{At(T(),{recursive:!0});let e=It();try{Ca(e).size>$a&&St(e)}catch{}Aa(e,`${new Date().toISOString()} ${t}
40
- `)}catch{}}function La(t){try{At(T(),{recursive:!0}),Tt(Ct(),String(Date.now()))}catch{}Ma(`spawn failed: ${t.message}`)}function Fa(){try{Ra(Ct(),{force:!0})}catch{}}async function nt(t,e){return new Promise((n,r)=>{let s=wa(t),i=a=>{if(s.removeAllListeners("connect"),s.removeAllListeners("error"),clearTimeout(o),a){try{s.destroy()}catch{}r(a)}else n(s)},o=setTimeout(()=>i(new Error("connect timeout")),e);s.once("connect",()=>i(null)),s.once("error",a=>i(a))})}function ja(){return process.env.TOKMIZER_DAEMON_BIN?process.env.TOKMIZER_DAEMON_BIN:Oa(new URL("../bin/tkr-daemon.js",import.meta.url))}async function wt(t,e=3e3){let n=Math.ceil(e/75),r=process.platform==="win32";for(let s=0;s<n;s++){if(r)try{return(await nt(t,75)).destroy(),!0}catch{}else if(ir(t))return!0;await new Promise(i=>setTimeout(i,75))}return!1}async function Ba(t){let e=ja();if(!ir(e))throw new Error(`tkr-daemon binary not found at ${e}`);let{path:n}=Ze(),r=process.platform==="win32"?T():Ia(n);try{At(r,{recursive:!0})}catch{}let s=Rt(r,"daemon.spawn.lock"),i=null;try{i=Et(s,"wx"),Tt(i,String(process.pid))}catch(o){if(o.code==="EEXIST"){if(await wt(n,5e3))return;try{St(s)}catch{}try{i=Et(s,"wx"),Tt(i,String(process.pid))}catch(l){if(l.code==="EEXIST"){await wt(n,5e3);return}throw l}}else throw o}try{let o=null;try{o=Et(It(),"a")}catch{}if(Sa(process.execPath,[e],{detached:!0,stdio:["ignore","ignore",o??"ignore"],env:{...process.env,TOKMIZER_DAEMON_INSTALL_ID:t}}).unref(),o!==null)try{rr(o)}catch{}if(!await wt(n,3e3))throw new Error("tkr-daemon failed to bind socket within 3s")}finally{if(i!==null){try{rr(i)}catch{}try{St(s)}catch{}}}}async function za(t={}){let{path:e}=t.socketPath?{path:t.socketPath}:Ze(),n=await yt();try{let r=await nt(e,or);r.write(vt({id:Be(),op:"shutdown",installId:n})),await new Promise(s=>setTimeout(s,150));try{r.destroy()}catch{}return!0}catch{return!1}}async function Za(t,e){let n=Date.now()+e;for(;Date.now()<n;){try{(await nt(t,250)).destroy()}catch{return!0}await new Promise(r=>setTimeout(r,100))}return!1}async function Ot(t={}){let{path:e}=t.socketPath?{path:t.socketPath}:Ze(),n=await yt(),r=null,s=0,i=!1;for(;s<=sr;)try{r=await nt(e,or),Fa();break}catch{if(s+=1,s>sr)throw new Error(`tkr-daemon unreachable at ${e}`);if(Pa())throw new Error(`tkr-daemon spawn on cooldown (see ${It()})`);await kt();try{await Ba(n),i=!0}catch(d){throw La(d),d}}if(!r)throw new Error("tkr-daemon: socket setup failed");let o=new Map,a="";r.setEncoding("utf8"),r.on("data",d=>{a+=d;let f=-1;for(let g=0;g<a.length;g++)a[g]===tt&&(f=g);if(f<0)return;let c=[];for(let g of er(a.slice(0,f+1)))c.push(g);a=a.slice(f+1);for(let g of c)if(g)try{let _=JSON.parse(g),k=o.get(_.id);if(!k)continue;clearTimeout(k.timer),o.delete(_.id),k.resolve(_)}catch{}}),r.on("close",()=>{for(let d of o.values())clearTimeout(d.timer),d.reject(new Error("daemon socket closed"));o.clear()}),r.on("error",()=>{});function l(d){return new Promise((f,c)=>{let g=setTimeout(()=>{o.delete(d.id),c(new Error(`daemon request timeout (${d.op})`))},Da);o.set(d.id,{resolve:f,reject:c,timer:g}),r.write(vt(d))})}let u={filter:async(d,f,c)=>{let g=await l({id:Be(),op:"filter",cmd:d.slice(0,2048),plan:f,...c&&c.length>0?{allowed:c.slice(0,512)}:{},installId:n});if(!g.ok)return null;let _=Qn.safeParse(g.data);return _.success?_.data.filter:null},ping:async()=>{let d=await l({id:Be(),op:"ping"});if(!d.ok)throw new Error(d.err);return d.data},reload:async()=>{let d=await l({id:Be(),op:"reload",installId:n});if(!d.ok)throw new Error(d.err);return d.data},close:()=>{try{r.end()}catch{}}};if(!t.skipVersionCheck&&!i){let d=!1;try{d=(await u.ping()).version!==_t}catch{}if(d){try{await za(t.socketPath?{socketPath:t.socketPath}:{})}catch{}u.close();let f=await Za(e,2e3);if(await kt(),!f)throw new Error("stale daemon still running after shutdown request");return Ot({...t,skipVersionCheck:!0})}}return u}import{createPublicKey as Xa,verify as Qa}from"node:crypto";import{createCipheriv as sf,createDecipheriv as Ua,hkdfSync as Ha,randomBytes as of}from"node:crypto";var Va=Buffer.from("tokmizer-bundle-enc-v1"),Ka=Buffer.from("rules-bundle");function Wa(t){return Buffer.from(Ha("sha256",Buffer.from(t,"utf8"),Va,Ka,32))}function ar(t,e){let n=Wa(e),r=Buffer.from(t,"base64url"),s=r.subarray(0,12),i=r.subarray(12,28),o=r.subarray(28),a=Ua("aes-256-gcm",n,s);return a.setAuthTag(i),Buffer.concat([a.update(o),a.final()]).toString("utf8")}import{chmodSync as lf,readFileSync as Ga,writeFileSync as uf,mkdirSync as df,renameSync as ff}from"node:fs";import{join as Ya}from"node:path";var qa=m.object({payload:m.string().min(1),signature:m.string().min(1),enc:m.literal("v1"),fetchedAt:m.number().int().nonnegative()});function Ja(){return Ya(T(),"bundle-cache.json")}function cr(){try{let t=Ga(Ja(),"utf8"),e=qa.safeParse(JSON.parse(t));return e.success?e.data:null}catch{return null}}var ec=m.object({bundleVersion:m.number().int().nonnegative(),signedAt:m.number().int(),filters:m.array(Se)}),Tf=m.object({payload:m.string().min(1),signature:m.string().min(1),enc:m.literal("v1")}),tc=10080*60*1e3;function nc(){let t=Number(process.env.TOKMIZER_MAX_BUNDLE_AGE_MS);return Number.isFinite(t)&&t>0?t:tc}function rc(t,e){let n=Bn();if(!n||!n.includes("BEGIN PUBLIC KEY"))throw new Error("tkr-daemon: no valid signing public key configured (set TOKMIZER_RESP_SIGNING_PUBLIC_KEY_PEM at build time).");let r=Xa({key:n,format:"pem"});if(!Qa(null,Buffer.from(t.payload,"utf8"),r,Buffer.from(t.signature,"base64url")))throw new Error("tkr-daemon: rules bundle signature invalid");return JSON.parse(ar(t.payload,e))}function sc(t,e){let n=rc(t,e),r=ec.parse(n);if(Date.now()-r.signedAt>nc())throw new Error("tkr-daemon: rules bundle is stale");let s=new Map;for(let i of r.filters)s.set(i.slug,{...i,matchRegex:new RegExp(i.match_command)});return Qt(),{bundleVersion:r.bundleVersion,signedAt:r.signedAt,ruleCount:s.size,startedAt:Date.now(),fetchedAt:Date.now(),selectFor:(i,o,a)=>qe(i,s.values(),a&&a.length>0?new Set(a):null)}}async function lr(){try{let t=cr();if(!t)return null;let e=await Le();return e?.signingSecret?sc(t,e.signingSecret):null}catch{return null}}var Ae=null,Ue=null;async function ic(){if(Ae)return Ae;if(Ue)return Ue;let t=Ot().then(e=>{if(Ue===t)return Ae=e,e;try{e.close()}catch{}return null}).catch(()=>null);return Ue=t,t}var Dt=null,Nt=!1;async function oc(){return Nt||(Nt=!0,Dt=await lr()),Dt}async function ur(t,e,n){let r=await oc();if(!r)return null;let s=r.selectFor(t,e,[...n]);return!s||!n.has(j(s.slug))?null:s}function ac(t){return t?{...t,matchRegex:new RegExp(t.match_command)}:null}function dr(t){mt(async(e,n)=>{let r=t==="free"?"trial":t,s=n??Ye(void 0),i=await ic();if(!i)return ur(e,r,s);try{let o=await i.filter(e,r,[...s]);return!o||!s.has(j(o.slug))?null:ac(o)}catch{return ur(e,r,s)}})}function fr(){if(mt(null),Ae)try{Ae.close()}catch{}Ae=null,Ue=null,Dt=null,Nt=!1}import{readFileSync as cc}from"node:fs";import{join as lc}from"node:path";function pr(){try{return cc(lc(T(),"yolo-mode"),"utf8")==="on"}catch{return!1}}var uc=new Set(["shell","bash","exec","run_shell_command","execute_shell_command"]);async function dc(t){if(t.event!=="after_tool_call")return{action:"continue"};if(!uc.has(t.tool))return{action:"continue"};let e=t.command??(t.args??[]).join(" ");if(!e)return{action:"continue"};let n=t.stdout??"",r=t.stderr??"",s=pr();if(!n&&(!s||!r))return{action:"continue"};let i=await Fe();if(!i.enabled)return{action:"continue"};let o=await Le();if(!o||!o.token)return{action:"continue"};let a=Pn(o);dr(a);let l=Ye(o.allowedFilters,$n(o)),u=new Set(i.filters.disabled.map(j)),d=u.size>0?new Set([...l].filter(B=>!u.has(B))):l,f,c=null;try{f=await ht(e,n,d,{verbosity:i.outputVerbosity,yolo:s,exitCode:t.exit_code}),s&&r&&(c=await ht(e,r,d,{verbosity:i.outputVerbosity,yolo:s,exitCode:t.exit_code}))}finally{fr()}let g=f.filteredBytes<f.rawBytes||c!=null&&c.filteredBytes<c.rawBytes,_=c?.output??r,k=_?f.output?`${f.output}
41
- ${_}`:_:f.output,A=Buffer.byteLength(n,"utf8")+Buffer.byteLength(r,"utf8"),R=Jn(A,g?Buffer.byteLength(k,"utf8"):A,Xn("codex"));return qn(R.raw,R.filtered,void 0,!1,"codex","sh",Yn(e)),await Vn({cmd:e,filterId:f.filterId,rawBytes:f.rawBytes,filteredBytes:f.filteredBytes,plan:a}),await Hn({cmd:e,tokensSaved:Math.max(0,Math.round((R.raw-R.filtered)/4)),rawTokens:Math.round(R.raw/4),optimized:f.filterId!=null,telemetryOptIn:i.telemetryOptIn,host:"codex"}),g?{action:"replace_output",replacement:k,reason:"tokmizer"}:{action:"continue"}}async function fc(t){let e=JSON.stringify({action:"continue"});if(!t)return e;let n;try{n=JSON.parse(t)}catch{return e}if(n.hook_event_name==="PreToolUse")return Nn(n,"codex")??"";if(n.hook_event_name)return"";try{return JSON.stringify(await dc(n))}catch(r){return process.stderr.write(`tkr-codex: ${r.message}
42
- `),e}}async function mr(){let t=await fc(await Sn());t&&process.stdout.write(t)}mr().catch(t=>{process.stderr.write(`tkr-codex-hook: ${t.message}
38
+ `;var xd=300*1e3;function Wn(){return((process.env.TOKMIZER_DEV==="1"?process.env.TOKMIZER_RESP_SIGNING_PUBLIC_KEY_PEM:void 0)??Kn).replace(/\\n/g,`
39
+ `)}var ra=512*1024;function qn(){return Gn(C(),"spool")}function sa(t){return Gn(qn(),`${t}.jsonl`)}function tt(t,e){try{ta(qn(),{recursive:!0,mode:448});let n=sa(t);if(ea(n)&&na(n).size>=ra)return;Xi(n,JSON.stringify(e)+`
40
+ `,{mode:384}),Qi(n,384)}catch{return}}var ia=/^[a-z0-9][a-z0-9._-]*$/i,aa=/^[a-z][a-z-]+$/,ca=/^[A-Za-z_][A-Za-z0-9_]*=/,la=new Set(["gh","glab","gup","hub","gist"]),ua=/^(gh[a-z]_|github_pat_|gl(?:pat|rt|soat|imt|dt|ft|agent|oas)-|npm_|xox|sk-|sk_|eyj|a(?:kia|sia|gpa|ida|roa|npa)|aiza|hv[sb]\.)/i,da=24,fa=new Set(["docker","podman","npm","pnpm","yarn","npx","bun","deno","cargo","rustup","go","pip","pip3","uv","poetry","brew","apt","apt-get","dnf","yum","pacman","kubectl","helm","terraform","aws","gcloud","az","systemctl","composer","bundle","gem","dotnet","prisma","tkr","rtk","token"]);function Jn(t){let e=t.toLowerCase();return e.startsWith("git")||la.has(e)}function Et(t){let e=t.trim().split(/\s+/).filter(a=>a.length>0),n=0;for(;n<e.length&&ca.test(e[n]??"");)n+=1;let r=e[n];if(!r||!ia.test(r)||r.length>da||Jn(r)||ua.test(r)||Be(r)!==r)return"";let s=e[n+1];return s&&Jn(s)?"":(s&&fa.has(r.toLowerCase())&&aa.test(s)?`${r} ${s}`:r).slice(0,64)}async function Yn(t){if(!t.telemetryOptIn)return;let e=Et(t.cmd),n=e&&Be(e)===e?e:"other",r=t.sessionId?t.sessionId.replace(/[^A-Za-z0-9._-]/g,"").slice(0,64):"";tt("telemetry",{cmd:n,tokensSaved:Math.max(0,Math.round(t.tokensSaved)),...t.tokensRestored?{tokensRestored:Math.max(0,Math.round(t.tokensRestored))}:{},...t.rawTokens!=null?{rawTokens:Math.max(0,Math.round(t.rawTokens))}:{},optimized:t.optimized,...r?{sessionId:r}:{},...t.host?{host:t.host}:{}})}async function Xn(t){if(t.plan!=="pro"||!(await je()).telemetryOptIn)return;let e=Et(t.cmd);!e||Be(e)!==e||tt("learn",{cmd:e,filterId:t.filterId==null?null:U(t.filterId),rawBytes:t.rawBytes,filteredBytes:t.filteredBytes})}import{appendFileSync as ma,chmodSync as ha,mkdirSync as ga,readFileSync as rr,renameSync as sr,rmSync as or,statSync as ir,writeFileSync as wt}from"node:fs";import{dirname as ya,join as ar}from"node:path";var pa={"claude-code":"anthropic",codex:"openai",copilot:"openai","gemini-cli":"google",cursor:"anthropic",windsurf:"anthropic",cline:"anthropic",aider:"anthropic",shell:"anthropic"};function Qn(t){return t?pa[t]??"anthropic":"anthropic"}var _a="stats.jsonl",ba="stats-ledger.json",er=2*1024*1024,va=3e4;function cr(){return{n:0,nc:0,r:0,f:0,or:0,of:0,x:0,sn:0,sr:0,sf:0,mr:0,mf:0,rn:0,rb:0,t0:null,t1:null,cmds:{},prov:{}}}function xa(t){let e=t.trim();if(!e)return null;try{let n=JSON.parse(e);return typeof n.t!="number"||!Number.isFinite(n.t)||n.t<0||n.t>864e10||typeof n.r!="number"||!Number.isSafeInteger(n.r)||n.r<0||typeof n.f!="number"||!Number.isSafeInteger(n.f)||n.f<0||n.r+n.f===0?null:{t:n.t,r:n.r,f:n.f,m:n.m===1,...typeof n.h=="string"?{h:n.h}:{},...typeof n.k=="string"?{k:n.k}:{},...typeof n.c=="string"&&n.c?{c:n.c}:{}}}catch{return null}}function ka(t,e){if(e.m){t.mr+=e.r,t.mf+=e.f;return}if(e.k==="restore"&&(t.rn+=1,t.rb+=e.f),t.n+=1,t.or+=e.r,t.of+=e.f,e.f>e.r&&(t.x+=1),t.t0=t.t0==null?e.t:Math.min(t.t0,e.t),t.t1=t.t1==null?e.t:Math.max(t.t1,e.t),e.c){let n=t.cmds[e.c]??{n:0,nc:0,r:0,f:0,sh:!1};n.n+=1,e.f<e.r&&(n.nc+=1),(e.k==="sh"||e.k==="restore")&&(n.sh=!0),n.r+=e.r,n.f+=e.f,t.cmds[e.c]=n}if(e.f<e.r){t.nc+=1,t.r+=e.r,t.f+=e.f,e.k==="sh"&&(t.sn+=1,t.sr+=e.r,t.sf+=e.f);let n=Qn(e.h),r=t.prov[n]??{r:0,f:0};r.r+=e.r,r.f+=e.f,t.prov[n]=r}}function Ea(t){let e=new Date(t*1e3);return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`}function lr(t){return ar(ya(t),ba)}function wa(t){let e=lr(t),n;try{n=rr(e,"utf8")}catch{return{}}try{let r=JSON.parse(n);if(!r.days||typeof r.days!="object")throw new Error("invalid ledger");let s={};for(let[o,i]of Object.entries(r.days))!/^\d{4}-\d{2}-\d{2}$/.test(o)||!i||typeof i!="object"||(s[o]={...cr(),...i});return s}catch{try{sr(e,`${e}.corrupt-${Date.now()}`)}catch{}return{}}}function tr(t,e){let n=`${t}.tmp-${process.pid}`;wt(n,e,{mode:384}),sr(n,t)}function Sa(t){try{return wt(t,String(process.pid),{flag:"wx",mode:384}),!0}catch{}try{return Date.now()-ir(t).mtimeMs<va?!1:(or(t,{force:!0}),wt(t,String(process.pid),{flag:"wx",mode:384}),!0)}catch{return!1}}function Ta(t,e=er,n=er/2){try{if(ir(t).size<=e)return}catch{return}let r=`${t}.lock`;if(Sa(r))try{let s=rr(t,"utf8").split(`
41
+ `).filter(u=>u.trim()!==""),o=s.length,i=0;for(;o>0;){let u=Buffer.byteLength(s[o-1])+1;if(i+u>n)break;i+=u,o-=1}let a=wa(t);for(let u of s.slice(0,o)){let d=xa(u);if(!d)continue;let f=Ea(d.t),l=a[f]??cr();ka(l,d),a[f]=l}let c=s.slice(o);tr(t,c.length?`${c.join(`
42
+ `)}
43
+ `:""),tr(lr(t),JSON.stringify({v:1,days:a}))}catch{return}finally{or(r,{force:!0})}}var Aa=new Set(["sudo","command","time","nice","nohup","env","stdbuf","timeout"]),Ra=new Set(["-u","-g","-n","-s","-k"]),Ca=/^[a-z0-9][a-z0-9._-]*$/i,Oa=new Set(["git","npm","pnpm","yarn","npx","docker","kubectl","helm","cargo","go","brew","gh","pip","pip3","apt","apt-get","systemctl","terraform","aws","gcloud","az","bundle","rake","rails","prisma","poetry","uv","gem","composer"]),ur=/^[A-Za-z_][A-Za-z0-9_]*=/;function nr(t){return t.length===0||t[0]==="cd"||t.every(e=>ur.test(e))}function Ia(t){let e=[],n="",r=!1,s=null,o=()=>{r&&e.push(n),n="",r=!1};for(let i of t){if(s){i===s?s=null:n+=i;continue}if(i==="'"||i==='"'){s=i,r=!0;continue}if(i===" "||i===" "){o();continue}if(`|;&<>
44
+ `.includes(i)){if(o(),nr(e)){e=[];continue}return e}n+=i,r=!0}return o(),nr(e)?[]:e}function dr(t){let e=Ia(t).map(a=>a.replace(/^[({]+/,"")).filter(Boolean),n=0;for(;n<e.length;){let a=e[n];if(ur.test(a)){n+=1;continue}if(Aa.has(a)){for(n+=1;n<e.length;){let c=e[n];if(c.startsWith("-")){n+=Ra.has(c)?2:1;continue}if(/^\d+(?:\.\d+)?[smhd]?$/.test(c)){n+=1;continue}break}continue}break}if(n>=e.length)return"";let r=e[n],s=r.includes("/")?r.slice(r.lastIndexOf("/")+1):r,o=e[n+1];return(o&&!o.startsWith("-")&&Ca.test(o)&&Oa.has(s.toLowerCase())?`${s} ${o}`:s).slice(0,24)}function $a(){return ar(C(),_a)}function fr(t,e,n=$a(),r=!1,s,o,i){if(!Number.isSafeInteger(t)||!Number.isSafeInteger(e)||t<0||e<0||t+e===0)return;let a=s?`,"h":${JSON.stringify(s)}`:"",c=o?`,"k":${JSON.stringify(o)}`:"",u=i?`,"c":${JSON.stringify(i.slice(0,24))}`:"",d=`{"t":${Math.floor(Date.now()/1e3)},"r":${t},"f":${e}${r?',"m":1':""}${a}${c}${u}}
45
+ `;try{ga(C(),{recursive:!0,mode:448}),ma(n,d,{mode:384}),ha(n,384),Ta(n)}catch{return}}function pr(t,e,n){let r=n!=null?Math.min(t,n):t,s=n!=null?Math.min(e,n):e;return{raw:r,filtered:s}}var Da=[{host:"claude-code",vars:["CLAUDECODE","CLAUDE_CODE_ENTRYPOINT","CLAUDE_CODE","CLAUDE_CODE_VERSION","ANTHROPIC_CLAUDE_CODE"]},{host:"codex",vars:["CODEX_VERSION","CODEX_CLI","OPENAI_CODEX","CODEX_THREAD_ID","CODEX_SESSION_ID"]},{host:"cursor",vars:["CURSOR_VERSION","CURSOR_TRACE_ID"]},{host:"cline",vars:["CLINE_VERSION","CLINE_API_KEY"]},{host:"aider",vars:["AIDER_VERSION","AIDER_MODEL"]},{host:"gemini-cli",vars:["GEMINI_CLI_VERSION","GEMINI_API_KEY"]},{host:"windsurf",vars:["WINDSURF_VERSION","WINDSURF_USER"]},{host:"copilot",vars:["GITHUB_COPILOT_VERSION","COPILOT_INTEGRATION_ID"]}],Qd=[...Da.map(t=>t.host),"shell"];function mr(t){return null}import{createConnection as Wa}from"node:net";import{spawn as Ga}from"node:child_process";import{existsSync as xr,openSync as Rt,closeSync as br,unlinkSync as Ot,writeFileSync as It,mkdirSync as $t,readFileSync as qa,appendFileSync as Ja,rmSync as Ya,statSync as Xa}from"node:fs";import{dirname as Qa,join as Dt}from"node:path";import{fileURLToPath as ec}from"node:url";var Na=m.object({id:m.string().min(1).max(64),op:m.literal("filter"),cmd:m.string().min(1).max(2048),plan:m.enum(["trial","smart","pro"]),allowed:m.array(m.string().min(1).max(64)).max(512).optional(),installId:m.string().min(1).max(64).optional()}),Pa=m.object({id:m.string().min(1).max(64),op:m.literal("ping")}),Ma=m.object({id:m.string().min(1).max(64),op:m.literal("shutdown"),installId:m.string().min(1).max(64)}),La=m.object({id:m.string().min(1).max(64),op:m.literal("reload"),installId:m.string().min(1).max(64).optional()}),rf=m.discriminatedUnion("op",[Na,Pa,Ma,La]),sf=m.object({id:m.string(),ok:m.literal(!0),data:m.unknown()}),of=m.object({id:m.string(),ok:m.literal(!1),err:m.string(),retryAfterMs:m.number().int().nonnegative().optional()}),hr=m.object({filter:Ce.nullable(),cacheHit:m.boolean().optional()}),nt=`
46
+ `,af=64*1024;function St(t){return JSON.stringify(t)+nt}function*gr(t){let e=0;for(;;){let n=t.indexOf(nt,e);if(n<0)return;yield t.slice(e,n),e=n+1}}function ze(){return`${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}import Fa from"node:os";import{join as Ze}from"node:path";import{existsSync as ja,statSync as Ba,lstatSync as yr,unlinkSync as za,mkdirSync as Za,chmodSync as Ua}from"node:fs";import{createHash as Ha}from"node:crypto";var Tt=100;function Va(t){let e=Ha("sha256").update(C()).digest("hex").slice(0,8),n=Ze(Fa.tmpdir(),`tkr-${t}-${e}`),r=Ze(n,"d.sock");if(Buffer.byteLength(r)>Tt)throw new Error("Temporary directory path is too long for IPC");return _r(n,t),r}function Ka(t,e){try{let n=yr(t);return n.isDirectory()&&n.uid===e&&(n.mode&63)===0}catch{return!1}}function _r(t,e){Za(t,{recursive:!0,mode:448});let n=yr(t);if(!n.isDirectory()||n.uid!==e)throw new Error("Unsafe IPC directory");Ua(t,448)}function Ue(){if(process.platform==="win32")return{path:`\\\\.\\pipe\\tokmizer-${process.env.USERNAME??"tokmizer"}`,isPipe:!0};let t=typeof process.getuid=="function"?process.getuid():0,e=process.env.XDG_RUNTIME_DIR;if(e&&Ka(e,t)){let s=Ze(e,`tokmizer-${t}.sock`);if(Buffer.byteLength(s)<=Tt)return{path:s,isPipe:!1}}let n=Ze(C(),"run"),r=Ze(n,"daemon.sock");return Buffer.byteLength(r)>Tt?{path:Va(t),isPipe:!1}:(_r(n,t),{path:r,isPipe:!1})}async function At(){let{path:t,isPipe:e}=Ue();if(e||!ja(t))return;try{if(!Ba(t).isSocket())return}catch{return}let n=await import("node:net");if(!await new Promise(s=>{let o=n.createConnection(t),i=a=>{o.removeAllListeners();try{o.destroy()}catch{}s(a)};o.once("connect",()=>i(!0)),o.once("error",a=>{let c=a.code;i(c!=="ECONNREFUSED"&&c!=="ENOENT")}),setTimeout(()=>i(!0),250)}))try{za(t)}catch{}}var mf=5*6e4;var kr=500,tc=3e3,vr=1,nc=6e4,rc=256*1024;function Nt(){return Dt(C(),"daemon.spawn.fail")}function Pt(){return Dt(C(),"daemon.log")}function sc(){try{let t=Number(qa(Nt(),"utf8"));return Number.isFinite(t)&&Date.now()-t<nc}catch{return!1}}function oc(t){try{$t(C(),{recursive:!0});let e=Pt();try{Xa(e).size>rc&&Ot(e)}catch{}Ja(e,`${new Date().toISOString()} ${t}
47
+ `)}catch{}}function ic(t){try{$t(C(),{recursive:!0}),It(Nt(),String(Date.now()))}catch{}oc(`spawn failed: ${t.message}`)}function ac(){try{Ya(Nt(),{force:!0})}catch{}}async function rt(t,e){return new Promise((n,r)=>{let s=Wa(t),o=a=>{if(s.removeAllListeners("connect"),s.removeAllListeners("error"),clearTimeout(i),a){try{s.destroy()}catch{}r(a)}else n(s)},i=setTimeout(()=>o(new Error("connect timeout")),e);s.once("connect",()=>o(null)),s.once("error",a=>o(a))})}function cc(){return process.env.TOKMIZER_DAEMON_BIN?process.env.TOKMIZER_DAEMON_BIN:ec(new URL("../bin/tkr-daemon.js",import.meta.url))}async function Ct(t,e=3e3){let n=Math.ceil(e/75),r=process.platform==="win32";for(let s=0;s<n;s++){if(r)try{return(await rt(t,75)).destroy(),!0}catch{}else if(xr(t))return!0;await new Promise(o=>setTimeout(o,75))}return!1}async function lc(t){let e=cc();if(!xr(e))throw new Error(`tkr-daemon binary not found at ${e}`);let{path:n}=Ue(),r=process.platform==="win32"?C():Qa(n);try{$t(r,{recursive:!0})}catch{}let s=Dt(r,"daemon.spawn.lock"),o=null;try{o=Rt(s,"wx"),It(o,String(process.pid))}catch(i){if(i.code==="EEXIST"){if(await Ct(n,5e3))return;try{Ot(s)}catch{}try{o=Rt(s,"wx"),It(o,String(process.pid))}catch(c){if(c.code==="EEXIST"){await Ct(n,5e3);return}throw c}}else throw i}try{let i=null;try{i=Rt(Pt(),"a")}catch{}if(Ga(process.execPath,[e],{detached:!0,stdio:["ignore","ignore",i??"ignore"],env:{...process.env,TOKMIZER_DAEMON_INSTALL_ID:t}}).unref(),i!==null)try{br(i)}catch{}if(!await Ct(n,3e3))throw new Error("tkr-daemon failed to bind socket within 3s")}finally{if(o!==null){try{br(o)}catch{}try{Ot(s)}catch{}}}}async function uc(t={}){let{path:e}=t.socketPath?{path:t.socketPath}:Ue(),n=await xt();try{let r=await rt(e,kr);r.write(St({id:ze(),op:"shutdown",installId:n})),await new Promise(s=>setTimeout(s,150));try{r.destroy()}catch{}return!0}catch{return!1}}async function dc(t,e){let n=Date.now()+e;for(;Date.now()<n;){try{(await rt(t,250)).destroy()}catch{return!0}await new Promise(r=>setTimeout(r,100))}return!1}async function Mt(t={}){let{path:e}=t.socketPath?{path:t.socketPath}:Ue(),n=await xt(),r=null,s=0,o=!1;for(;s<=vr;)try{r=await rt(e,kr),ac();break}catch{if(s+=1,s>vr)throw new Error(`tkr-daemon unreachable at ${e}`);if(sc())throw new Error(`tkr-daemon spawn on cooldown (see ${Pt()})`);await At();try{await lc(n),o=!0}catch(d){throw ic(d),d}}if(!r)throw new Error("tkr-daemon: socket setup failed");let i=new Map,a="";r.setEncoding("utf8"),r.on("data",d=>{a+=d;let f=-1;for(let g=0;g<a.length;g++)a[g]===nt&&(f=g);if(f<0)return;let l=[];for(let g of gr(a.slice(0,f+1)))l.push(g);a=a.slice(f+1);for(let g of l)if(g)try{let k=JSON.parse(g),A=i.get(k.id);if(!A)continue;clearTimeout(A.timer),i.delete(k.id),A.resolve(k)}catch{}}),r.on("close",()=>{for(let d of i.values())clearTimeout(d.timer),d.reject(new Error("daemon socket closed"));i.clear()}),r.on("error",()=>{});function c(d){return new Promise((f,l)=>{if(r.destroyed||!r.writable){l(new Error("daemon socket closed"));return}let g=setTimeout(()=>{i.delete(d.id),l(new Error(`daemon request timeout (${d.op})`))},tc);i.set(d.id,{resolve:f,reject:l,timer:g}),r.write(St(d))})}let u={filter:async(d,f,l)=>{let g=await c({id:ze(),op:"filter",cmd:d.slice(0,2048),plan:f,...l&&l.length>0?{allowed:l.slice(0,512)}:{},installId:n});if(!g.ok)return null;let k=hr.safeParse(g.data);return k.success?k.data.filter:null},ping:async()=>{let d=await c({id:ze(),op:"ping"});if(!d.ok)throw new Error(d.err);return d.data},reload:async()=>{let d=await c({id:ze(),op:"reload",installId:n});if(!d.ok)throw new Error(d.err);return d.data},close:()=>{try{r.destroy()}catch{}}};if(!t.skipVersionCheck&&!o){let d=!1;try{d=(await u.ping()).version!==kt}catch(f){throw u.close(),f}if(d){try{await uc(t.socketPath?{socketPath:t.socketPath}:{})}catch{}u.close();let f=await dc(e,2e3);if(await At(),!f)throw new Error("stale daemon still running after shutdown request");return Mt({...t,skipVersionCheck:!0})}}return u}import{createPublicKey as xc,verify as kc}from"node:crypto";import{createCipheriv as Cf,createDecipheriv as fc,hkdfSync as pc,randomBytes as Of}from"node:crypto";var mc=Buffer.from("tokmizer-bundle-enc-v1"),hc=Buffer.from("rules-bundle");function gc(t){return Buffer.from(pc("sha256",Buffer.from(t,"utf8"),mc,hc,32))}function Er(t,e){let n=gc(e),r=Buffer.from(t,"base64url"),s=r.subarray(0,12),o=r.subarray(12,28),i=r.subarray(28),a=fc("aes-256-gcm",n,s);return a.setAuthTag(o),Buffer.concat([a.update(i),a.final()]).toString("utf8")}import{chmodSync as Df,readFileSync as yc,writeFileSync as Nf,mkdirSync as Pf,renameSync as Mf}from"node:fs";import{join as _c}from"node:path";var bc=m.object({payload:m.string().min(1),signature:m.string().min(1),enc:m.literal("v1"),fetchedAt:m.number().int().nonnegative()});function vc(){return _c(C(),"bundle-cache.json")}function wr(){try{let t=yc(vc(),"utf8"),e=bc.safeParse(JSON.parse(t));return e.success?e.data:null}catch{return null}}var Ec=m.object({bundleVersion:m.number().int().nonnegative(),signedAt:m.number().int(),filters:m.array(Ce)}),Jf=m.object({payload:m.string().min(1),signature:m.string().min(1),enc:m.literal("v1")}),wc=10080*60*1e3;function Sc(){let t=Number(process.env.TOKMIZER_MAX_BUNDLE_AGE_MS);return Number.isFinite(t)&&t>0?t:wc}function Tc(t,e){let n=Wn();if(!n||!n.includes("BEGIN PUBLIC KEY"))throw new Error("tkr-daemon: no valid signing public key configured (set TOKMIZER_RESP_SIGNING_PUBLIC_KEY_PEM at build time).");let r=xc({key:n,format:"pem"});if(!kc(null,Buffer.from(t.payload,"utf8"),r,Buffer.from(t.signature,"base64url")))throw new Error("tkr-daemon: rules bundle signature invalid");return JSON.parse(Er(t.payload,e))}function Ac(t,e){let n=Tc(t,e),r=Ec.parse(n);if(Date.now()-r.signedAt>Sc())throw new Error("tkr-daemon: rules bundle is stale");let s=new Map;for(let o of r.filters)s.set(o.slug,{...o,matchRegex:new RegExp(o.match_command)});return{bundleVersion:r.bundleVersion,signedAt:r.signedAt,ruleCount:s.size,startedAt:Date.now(),fetchedAt:Date.now(),selectFor:(o,i,a)=>Xe(o,s.values(),a?new Set(a):null,s)}}async function Sr(){try{let t=wr();if(!t)return null;let e=await Fe();return e?.signingSecret?Ac(t,e.signingSecret):null}catch{return null}}var Ie=null,He=null;async function Rc(){if(Ie)return Ie;if(He)return He;let t=Mt().then(e=>{if(He===t)return Ie=e,e;try{e.close()}catch{}return null}).catch(()=>null);return He=t,t}var Lt=null,Ft=!1;async function Cc(){return Ft||(Ft=!0,Lt=await Sr()),Lt}async function Tr(t,e,n){let r=await Cc();if(!r)return null;let s=r.selectFor(t,e,[...n]);return!s||!n.has(U(s.slug))?null:s}function Oc(t){return t?{...t,matchRegex:new RegExp(t.match_command)}:null}function Ar(t){_t(async(e,n)=>{let r=t==="free"?"trial":t,s=n??Ye(void 0),o=await Rc();if(!o)return Tr(e,r,s);try{let i=await o.filter(e,r,[...s]);return!i||!s.has(U(i.slug))?null:Oc(i)}catch{return Tr(e,r,s)}})}function Rr(){if(_t(null),Ie)try{Ie.close()}catch{}Ie=null,He=null,Lt=null,Ft=!1}import{readFileSync as Ic}from"node:fs";import{join as $c}from"node:path";function Cr(){try{return Ic($c(C(),"yolo-mode"),"utf8")==="on"}catch{return!1}}var Dc=new Set(["shell","bash","exec","run_shell_command","execute_shell_command"]);async function Nc(t){if(t.event!=="after_tool_call")return{action:"continue"};if(!Dc.has(t.tool))return{action:"continue"};let e=t.command??(t.args??[]).join(" ");if(!e)return{action:"continue"};let n=t.stdout??"",r=t.stderr??"",s=Cr();if(!n&&(!s||!r))return{action:"continue"};let o=await je();if(!o.enabled)return{action:"continue"};let i=await Fe();if(!i||!i.token)return{action:"continue"};let a=Zn(i);Ar(a);let c=Ye(i.allowedFilters,zn(i)),u=new Set(o.filters.disabled.map(U)),d=u.size>0?new Set([...c].filter(S=>!u.has(S))):c,f,l=null;try{f=await bt(e,n,d,{verbosity:o.outputVerbosity,yolo:s,exitCode:t.exit_code}),s&&r&&(l=await bt(e,r,d,{verbosity:o.outputVerbosity,yolo:s,exitCode:t.exit_code}))}finally{Rr()}let g=f.filteredBytes<f.rawBytes||l!=null&&l.filteredBytes<l.rawBytes,k=l?.output??r,A=k?f.output?`${f.output}
48
+ ${k}`:k:f.output,b=Buffer.byteLength(n,"utf8")+Buffer.byteLength(r,"utf8"),R=pr(b,g?Buffer.byteLength(A,"utf8"):b,mr("codex"));return fr(R.raw,R.filtered,void 0,!1,"codex","sh",dr(e)),await Xn({cmd:e,filterId:f.filterId,rawBytes:f.rawBytes,filteredBytes:f.filteredBytes,plan:a}),await Yn({cmd:e,tokensSaved:Math.max(0,Math.round((R.raw-R.filtered)/4)),rawTokens:Math.round(R.raw/4),optimized:f.filterId!=null,telemetryOptIn:o.telemetryOptIn,host:"codex"}),g?{action:"replace_output",replacement:A,reason:"tokmizer"}:{action:"continue"}}async function Pc(t){let e=JSON.stringify({action:"continue"});if(!t)return e;let n;try{n=JSON.parse(t)}catch{return e}if(n.hook_event_name==="PreToolUse")return Bn(n,"codex")??"";if(n.hook_event_name)return"";try{return JSON.stringify(await Nc(n))}catch(r){return process.stderr.write(`tkr-codex: ${r.message}
49
+ `),e}}async function Or(){let t=await Pc(await Cn());t&&process.stdout.write(t)}Or().catch(t=>{process.stderr.write(`tkr-codex-hook: ${t.message}
43
50
  `),process.stdout.write(JSON.stringify({action:"continue"})),process.exit(0)});