@tokmizer/plugin 0.9.52 → 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,47 +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 _r=Object.defineProperty;var br=(t,e)=>{for(var n in e)_r(t,n,{get:e[n],enumerable:!0})};import{readdir as Is,readFile as Os}from"node:fs/promises";import{join as Jt,dirname as Ds}from"node:path";import{fileURLToPath as Ns}from"node:url";var m={};br(m,{BRAND:()=>Vr,DIRTY:()=>te,EMPTY_PATH:()=>Er,INVALID:()=>v,NEVER:()=>Cs,OK:()=>O,ParseStatus:()=>C,Schema:()=>w,ZodAny:()=>J,ZodArray:()=>W,ZodBigInt:()=>re,ZodBoolean:()=>se,ZodBranded:()=>Oe,ZodCatch:()=>he,ZodDate:()=>ie,ZodDefault:()=>me,ZodDiscriminatedUnion:()=>Ke,ZodEffects:()=>L,ZodEnum:()=>fe,ZodError:()=>D,ZodFirstPartyTypeKind:()=>x,ZodFunction:()=>Ge,ZodIntersection:()=>le,ZodIssueCode:()=>p,ZodLazy:()=>ue,ZodLiteral:()=>de,ZodMap:()=>Ee,ZodNaN:()=>Se,ZodNativeEnum:()=>pe,ZodNever:()=>F,ZodNull:()=>ae,ZodNullable:()=>U,ZodNumber:()=>ne,ZodObject:()=>N,ZodOptional:()=>P,ZodParsedType:()=>y,ZodPipeline:()=>De,ZodPromise:()=>X,ZodReadonly:()=>ge,ZodRecord:()=>We,ZodSchema:()=>w,ZodSet:()=>we,ZodString:()=>q,ZodSymbol:()=>xe,ZodTransformer:()=>L,ZodTuple:()=>Z,ZodType:()=>w,ZodUndefined:()=>oe,ZodUnion:()=>ce,ZodUnknown:()=>K,ZodVoid:()=>ke,addIssueToContext:()=>h,any:()=>es,array:()=>ss,bigint:()=>Yr,boolean:()=>Gt,coerce:()=>Rs,custom:()=>Vt,date:()=>qr,datetimeRegex:()=>Ut,defaultErrorMap:()=>H,discriminatedUnion:()=>cs,effect:()=>vs,enum:()=>ys,function:()=>ms,getErrorMap:()=>_e,getParsedType:()=>z,instanceof:()=>Wr,intersection:()=>ls,isAborted:()=>He,isAsync:()=>be,isDirty:()=>Ve,isValid:()=>Y,late:()=>Kr,lazy:()=>hs,literal:()=>gs,makeIssue:()=>Ie,map:()=>fs,nan:()=>Gr,nativeEnum:()=>_s,never:()=>ns,null:()=>Qr,nullable:()=>ks,number:()=>Wt,object:()=>is,objectUtil:()=>ot,oboolean:()=>As,onumber:()=>Ts,optional:()=>xs,ostring:()=>Ss,pipeline:()=>ws,preprocess:()=>Es,promise:()=>bs,quotelessJson:()=>vr,record:()=>ds,set:()=>ps,setErrorMap:()=>kr,strictObject:()=>os,string:()=>Kt,symbol:()=>Jr,transformer:()=>vs,tuple:()=>us,undefined:()=>Xr,union:()=>as,unknown:()=>ts,util:()=>S,void:()=>rs});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 ot;(function(t){t.mergeShapes=(e,n)=>({...e,...n})})(ot||(ot={}));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"]),vr=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 xr=(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=xr;var Ft=H;function kr(t){Ft=t}function _e(){return Ft}var Ie=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}},Er=[];function h(t,e){let n=_e(),r=Ie({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 C=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"}),te=t=>({status:"dirty",value:t}),O=t=>({status:"valid",value:t}),He=t=>t.status==="aborted",Ve=t=>t.status==="dirty",Y=t=>t.status==="valid",be=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}},Bt=(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 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 C,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(be(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 Bt(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 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:z(e)},s=this._parse({data:e,path:r.path,parent:r}),i=await(be(s)?s:Promise.resolve(s));return Bt(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 X.create(this,this._def)}or(e){return ce.create([this,e],this._def)}and(e){return le.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 me({...E(this._def),innerType:this,defaultValue:n,typeName:x.ZodDefault})}brand(){return new Oe({typeName:x.ZodBranded,type:this,...E(this._def)})}catch(e){let n=typeof e=="function"?e:()=>e;return new he({...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 De.create(this,e)}readonly(){return ge.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}},wr=/^c[^\s-]{8,}$/i,Sr=/^[0-9a-z]+$/,Tr=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Ar=/^[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,Rr=/^[a-z0-9_-]{21}$/i,Cr=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Ir=/^[-+]?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)?)??$/,Or=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Dr="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",at,Nr=/^(?:(?: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])$/,$r=/^(?:(?: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])$/,Pr=/^(([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]))$/,Mr=/^(([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])$/,Lr=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Fr=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,zt="((\\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])))",Br=new RegExp(`^${zt}$`);function Zt(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 jr(t){return new RegExp(`^${Zt(t)}$`)}function Ut(t){let e=`${zt}T${Zt(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 zr(t,e){return!!((e==="v4"||!e)&&Nr.test(t)||(e==="v6"||!e)&&Pr.test(t))}function Zr(t,e){if(!Cr.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 Ur(t,e){return!!((e==="v4"||!e)&&$r.test(t)||(e==="v6"||!e)&&Mr.test(t))}var q=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 C,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")Or.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")at||(at=new RegExp(Dr,"u")),at.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")Ar.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")Rr.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")wr.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")Sr.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")Tr.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"?Ut(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"?Br.test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{code:p.invalid_string,validation:"date",message:i.message}),r.dirty()):i.kind==="time"?jr(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"?Ir.test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"duration",code:p.invalid_string,message:i.message}),r.dirty()):i.kind==="ip"?zr(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"?Zr(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"?Ur(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"?Lr.test(e.data)||(s=this._getOrReturnCtx(e,s),h(s,{validation:"base64",code:p.invalid_string,message:i.message}),r.dirty()):i.kind==="base64url"?Fr.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}};q.create=t=>new q({checks:[],typeName:x.ZodString,coerce:t?.coerce??!1,...E(t)});function Hr(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 ne=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 C;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"?Hr(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)}};ne.create=t=>new ne({checks:[],typeName:x.ZodNumber,coerce:t?.coerce||!1,...E(t)});var re=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 C;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}};re.create=t=>new re({checks:[],typeName:x.ZodBigInt,coerce:t?.coerce??!1,...E(t)});var se=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)}};se.create=t=>new se({typeName:x.ZodBoolean,coerce:t?.coerce||!1,...E(t)});var ie=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 C,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}};ie.create=t=>new ie({checks:[],coerce:t?.coerce||!1,typeName:x.ZodDate,...E(t)});var xe=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)}};xe.create=t=>new xe({typeName:x.ZodSymbol,...E(t)});var oe=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)}};oe.create=t=>new oe({typeName:x.ZodUndefined,...E(t)});var ae=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)}};ae.create=t=>new ae({typeName:x.ZodNull,...E(t)});var J=class extends w{constructor(){super(...arguments),this._any=!0}_parse(e){return O(e.data)}};J.create=t=>new J({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 ke=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)}};ke.create=t=>new ke({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=>C.mergeArray(r,o));let i=[...n.data].map((o,a)=>s.type._parseSync(new M(n,o,n.path,a)));return C.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 ve(t){if(t instanceof N){let e={};for(let n in t.shape){let r=t.shape[n];e[n]=P.create(ve(r))}return new N({...t._def,shape:()=>e})}else return t instanceof W?new W({...t._def,type:ve(t.element)}):t instanceof P?P.create(ve(t.unwrap())):t instanceof U?U.create(ve(t.unwrap())):t instanceof Z?Z.create(t.items.map(e=>ve(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 f=i[u],d=s.data[u];l.push({key:{status:"valid",value:u},value:f._parse(new M(s,d,s.path,u)),alwaysSet:u in s.data})}if(this._def.catchall instanceof F){let u=this._def.unknownKeys;if(u==="passthrough")for(let f of a)l.push({key:{status:"valid",value:f},value:{status:"valid",value:s.data[f]}});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 f of a){let d=s.data[f];l.push({key:{status:"valid",value:f},value:u._parse(new M(s,d,s.path,f)),alwaysSet:f in s.data})}}return s.common.async?Promise.resolve().then(async()=>{let u=[];for(let f of l){let d=await f.key,c=await f.value;u.push({key:d,value:c,alwaysSet:f.alwaysSet})}return u}).then(u=>C.mergeObjectSync(r,u)):C.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 ve(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 Ht(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 ce=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},f=l._parseSync({data:n.data,path:n.path,parent:u});if(f.status==="valid")return f;f.status==="dirty"&&!i&&(i={result:f,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}};ce.create=(t,e)=>new ce({options:t,typeName:x.ZodUnion,...E(e)});var V=t=>t instanceof ue?V(t.schema):t instanceof L?V(t.innerType()):t instanceof de?[t.value]:t instanceof fe?t.options:t instanceof pe?S.objectValues(t.enum):t instanceof me?V(t._def.innerType):t instanceof oe?[void 0]:t instanceof ae?[null]:t instanceof P?[void 0,...V(t.unwrap())]:t instanceof U?[null,...V(t.unwrap())]:t instanceof Oe||t instanceof ge?V(t.unwrap()):t instanceof he?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 ct(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=ct(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=ct(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 le=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=ct(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}))}};le.create=(t,e,n)=>new le({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=>C.mergeArray(n,o)):C.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?C.mergeObjectAsync(n,s):C.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:q.create(),valueType:e,typeName:x.ZodRecord,...E(n)})}},Ee=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,f=await l.value;if(u.status==="aborted"||f.status==="aborted")return v;(u.status==="dirty"||f.status==="dirty")&&n.dirty(),a.set(u.value,f.value)}return{status:n.value,value:a}})}else{let a=new Map;for(let l of o){let u=l.key,f=l.value;if(u.status==="aborted"||f.status==="aborted")return v;(u.status==="dirty"||f.status==="dirty")&&n.dirty(),a.set(u.value,f.value)}return{status:n.value,value:a}}}};Ee.create=(t,e,n)=>new Ee({valueType:e,keyType:t,typeName:x.ZodMap,...E(n)});var we=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 f of l){if(f.status==="aborted")return v;f.status==="dirty"&&n.dirty(),u.add(f.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)}};we.create=(t,e)=>new we({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 Ie({data:a,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,_e(),H].filter(u=>!!u),issueData:{code:p.invalid_arguments,argumentsError:l}})}function s(a,l){return Ie({data:a,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,_e(),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 X){let a=this;return O(async function(...l){let u=new D([]),f=await a._def.args.parseAsync(l,i).catch(g=>{throw u.addIssue(r(l,g)),u}),d=await Reflect.apply(o,this,f);return await a._def.returns._def.type.parseAsync(d,i).catch(g=>{throw u.addIssue(s(d,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 f=Reflect.apply(o,this,u.data),d=a._def.returns.safeParse(f,i);if(!d.success)throw new D([s(f,d.error)]);return d.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)})}},ue=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})}};ue.create=(t,e)=>new ue({getter:t,typeName:x.ZodLazy,...E(e)});var de=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}};de.create=(t,e)=>new de({value:t,typeName:x.ZodLiteral,...E(e)});function Ht(t,e){return new fe({values:t,typeName:x.ZodEnum,...E(e)})}var fe=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})}};fe.create=Ht;var pe=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}};pe.create=(t,e)=>new pe({values:t,typeName:x.ZodNativeEnum,...E(e)});var X=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})))}};X.create=(t,e)=>new X({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"?te(l.value):n.value==="dirty"?te(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"?te(a.value):n.value==="dirty"?te(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(!Y(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=>Y(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 me=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}};me.create=(t,e)=>new me({innerType:t,typeName:x.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...E(e)});var he=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 be(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}};he.create=(t,e)=>new he({innerType:t,typeName:x.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...E(e)});var Se=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}}};Se.create=t=>new Se({typeName:x.ZodNaN,...E(t)});var Vr=Symbol("zod_brand"),Oe=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}},De=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(),te(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})}},ge=class extends w{_parse(e){let n=this._def.innerType._parse(e),r=s=>(Y(s)&&(s.value=Object.freeze(s.value)),s);return be(n)?n.then(s=>r(s)):r(n)}unwrap(){return this._def.innerType}};ge.create=(t,e)=>new ge({innerType:t,typeName:x.ZodReadonly,...E(e)});function jt(t,e){let n=typeof t=="function"?t(e):typeof t=="string"?{message:t}:t;return typeof n=="string"?{message:n}:n}function Vt(t,e={},n){return t?J.create().superRefine((r,s)=>{let i=t(r);if(i instanceof Promise)return i.then(o=>{if(!o){let a=jt(e,r),l=a.fatal??n??!0;s.addIssue({code:"custom",...a,fatal:l})}});if(!i){let o=jt(e,r),a=o.fatal??n??!0;s.addIssue({code:"custom",...o,fatal:a})}}):J.create()}var Kr={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 Wr=(t,e={message:`Input not instance of ${t.name}`})=>Vt(n=>n instanceof t,e),Kt=q.create,Wt=ne.create,Gr=Se.create,Yr=re.create,Gt=se.create,qr=ie.create,Jr=xe.create,Xr=oe.create,Qr=ae.create,es=J.create,ts=K.create,ns=F.create,rs=ke.create,ss=W.create,is=N.create,os=N.strictCreate,as=ce.create,cs=Ke.create,ls=le.create,us=Z.create,ds=We.create,fs=Ee.create,ps=we.create,ms=Ge.create,hs=ue.create,gs=de.create,ys=fe.create,_s=pe.create,bs=X.create,vs=L.create,xs=P.create,ks=U.create,Es=L.createWithPreprocess,ws=De.create,Ss=()=>Kt().optional(),Ts=()=>Wt().optional(),As=()=>Gt().optional(),Rs={string:(t=>q.create({...t,coerce:!0})),number:(t=>ne.create({...t,coerce:!0})),boolean:(t=>se.create({...t,coerce:!0})),bigint:(t=>re.create({...t,coerce:!0})),date:(t=>ie.create({...t,coerce:!0}))};var Cs=v;var Te=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 $s=Ds(Ns(import.meta.url)),Yt=process.env.TOKMIZER_FILTERS_DIR||Jt($s,"..","..","filters"),Q=null,qt=!1;function Ps(){return process.env.TOKMIZER_DEV==="1"||process.env.TOKMIZER_DEV==="true"}async function Xt(){if(Q)return Q;if(!Ps())return!qt&&process.env.TOKMIZER_DEBUG==="1"&&(process.stderr.write(`tokmizer: disk loader disabled (set TOKMIZER_DEV=1 to re-enable for local dev).
4
- `),qt=!0),Q=new Map,Q;let t=new Map,e,n;try{e=(await import("smol-toml")).parse,n=(await Is(Yt)).filter(r=>r.endsWith(".toml"))}catch{return Q=t,Q}for(let r of n){let s=await Os(Jt(Yt,r),"utf8"),o=e(s).filters;if(o)for(let[a,l]of Object.entries(o)){let u=Te.parse({slug:a,...l});t.set(a,{...u,matchRegex:new RegExp(u.match_command)})}}return Q=t,Q}import{createHash as Ms}from"node:crypto";var Ls=m.enum(["normal","compact","minimal"]),Fs=m.enum(["off","light","balanced","max"]),Ne=m.object({enabled:m.boolean().default(!0),telemetryOptIn:m.boolean().default(!0),outputVerbosity:Ls.default("compact"),reducer:Fs.default("off"),filters:m.object({enableAll:m.boolean().default(!0),disabled:m.array(m.string().max(64)).max(100).default([])}).default({enableAll:!0,disabled:[]})}),Bs=["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"],js=/^[0-9a-f]{16}$/,Qt=new Map;function B(t){let e=Qt.get(t);return e||(e=Ms("sha256").update(`tkr:${t}`).digest("hex").slice(0,16),Qt.set(t,e)),e}var en=null;function Ye(t,e=!1){return e||!t||t.length===0?(en??=new Set(Bs.map(B)),new Set(en)):new Set(t.map(n=>js.test(n)?n:B(n)))}var Ae=new Map,zs=256,tn=new WeakMap;function Zs(t){if(!t)return"*";let e=tn.get(t);return e===void 0&&(e=[...t].join(","),tn.set(t,e)),e}function qe(t,e,n){let r=`${t}::${Zs(n)}`,s=Ae.get(r);if(s!==void 0)return s;let i=null;for(let o of e)n&&!n.has(B(o.slug))||o.matchRegex.test(t)&&(!i||o.priority>i.priority)&&(i=o);if(Ae.size>=zs){let o=Ae.keys().next().value;o&&Ae.delete(o)}return Ae.set(r,i),i}function nn(){Ae.clear()}var Us=/\x1b\[[0-9;?]*[ -/]*[@-~]/g,Hs=/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g;function ye(t){return t.replace(Us,"").replace(Hs,"")}function rn(t,e){return e.length===0?t:t.filter(n=>!e.some(r=>r.test(n)))}function sn(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 on(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 Vs=/^\s*(?:[✓✔√]|ok )/,ee=/✕|✗|×|\bFAIL\b|\bERROR\b|\bFATAL\b|\bError|\berror|Expected|Received|\bfailed\b|^\s*Tests?:|^\s*Test Suites?:/;function an(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)Vs.test(a)&&!ee.test(a)?(o.push(a),s+=1):(i(o),o=[],s=0,r.push(a));return i(o),r}var Ks=/(?:\/[\w.@+-]+){3,}/g;function cn(t){return t.map(e=>e.replace(Ks,n=>{let r=n.split("/").filter(Boolean);return r.length<=2?n:`\u2026/${r.slice(-2).join("/")}`}))}var Ws=/^(\s*)(?:export\s+)?(?:async\s+)?(?:function|interface|type|const|let|var|def|fn|impl|trait|struct|enum)\s+[\w$]+/,Gs=/\{\s*$/;var Ys=/^\s*(?:(?:public|private|protected|static|async|get|set|readonly|override)\s+)*([\w$]+)\s*\(([^)]*)\)\s*(?::\s*[^{]+)?\{\s*$/,qs=new Set(["if","for","while","switch","catch","do","with","return","else","function","await","yield"]);function Js(t){let e=Ys.exec(t);return!e||qs.has(e[1])?!1:!/=>|\bfunction\b/.test(e[2])}var Xs=/^\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 ei(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 ti=/^\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=ti.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(Ws.test(r)&&Gs.test(r)||Js(r)||Xs.test(r)){let s={inBlockComment:!1,inTemplate:!1},i=0,o=n,a=!1;for(;o<t.length&&o-n<200;)if(i+=ei(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,f=/^\s*/.exec(t[n+1]??"")?.[0]??" ";e.push(r),e.push(`${f}\u2026 ${u} ${u===1?"line":"lines"} folded \u2026`);for(let d=0;d<u-1;d++)e.push("");e.push(t[o-1]),n=o;continue}}e.push(r),n+=1}return e}var ni=/\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 Qe(t){let e=t.slice(0,4096);return!(!ni.test(e)||e.split(`
5
- `).length<6)}var ri=/^\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*/,si=/^\s*(?:\[(?:DEBUG|TRACE|INFO|VERBOSE)\]|(?:DEBUG|TRACE|INFO|VERBOSE)(?!\s*:))(?=\s|:|$)(?!\s*[+\-*\/%&|^?]*=)/,ii=new RegExp(ee.source,"i"),oi=/\bWARN(?:ING)?\b/i;function ln(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(si.test(s.replace(ri,""))&&!ii.test(s)&&!oi.test(s)){n+=1;continue}r(),e.push(s)}return r(),e}function un(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 dn(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 fn=new Map;function $(t,e){fn.set(t,e)}function pn(t){return fn.get(t)}var ai=/^[dbclps\-][rwxsStT\-]{9}[@.+]?(?:\s|$)/,ci=/^[./~][^\s]*:$/,ut=1e3;function li(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 ui(t){if(!ai.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 di(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 fi(t){let e=[],n=[],r=!1;for(let c of t){if(/^total\s+\d+/.test(c))continue;if(ci.test(c.trim()))return t;let g=ui(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?"":li(c.size);a.push(_?`${g.padEnd(o)} ${_}`:g)}if(a.length>ut){let c=a.length-ut;a=[...a.slice(0,ut),`\u2026 ${c} more lines omitted`]}let l=n.length===1?"file":"files",u=e.length===1?"dir":"dirs",f=di(n),d=`${n.length} ${l}, ${e.length} ${u}`+(f?` (${f})`:"");return a.push(d),a}$("smart-ls",fi);$("smart-read",t=>Xe(t));var mn=1e3;function pi(t){let e=t.filter(f=>f.trim()!=="");if(e.length===0||e.filter(f=>!/\s/.test(f.trim())).length<e.length*.6)return t;let r=new Map,s=[],i=0;for(let f of e){let d=f.trim();if(d.startsWith("find:")){s.push(d);continue}let c=d.replace(/^\.\//,"").replace(/\/+$/,""),g=c.lastIndexOf("/"),_=g>=0?c.slice(0,g):"",k=g>=0?c.slice(g+1):c;if(!k)continue;let R=r.get(_)??[];R.push(/\s/.test(k)?`"${k}"`:k),r.set(_,R),i+=1}if(i===0)return t;let o=new Set([""]);for(let f of r.keys()){if(f==="")continue;let d=f.split("/");for(let c=1;c<=d.length;c+=1)o.add(d.slice(0,c).join("/"))}let a=[...o].sort(),l=a.filter(f=>f!=="").length,u=[`${i}F ${l}D:`,""];for(let f of a){let d=f===""?0:f.split("/").length,c=f===""?".":f.slice(f.lastIndexOf("/")+1),g=r.get(f)??[],_=g.length?` ${g.join(" ")}`:"";u.push(`${" ".repeat(d)}${c}/${_}`)}if(u.length+s.length>mn){let f=Math.max(0,mn-s.length),d=u.length-f;return[...u.slice(0,f),`\u2026 ${d} more lines omitted`,...s]}return[...u,...s]}$("smart-find",pi);var dt=1e3,hn=200,mi=60,hi=190,gi=/^([^\s:]+):(\d+):(.*)$/,yi=/^([^:]+?)-(\d+)-(.*)$/,_i=/^([^\s:]+):(.*)$/,gn=/(?:^|\/)(?:__tests__|tests?|spec|fixtures?|__mocks__|__snapshots__)\/|\.(?:test|spec)\.[^/]+$/i;function yn(t){let e=t.trim();return e.length>hn?`${e.slice(0,hn)}\u2026`:e}function bi(t){let e=[],n="";for(let r of t){let s=n?`${n}, ${r}`:r;s.length>hi&&n?(e.push(`${n},`),n=r):n=s}return n&&e.push(n),e}function vi(t){let e=t.filter(d=>d.trim()!=="");if(e.length===0)return t;let n=new Map,r=new Map,s=null,i=0,o=0;for(let d of e){if(d==="--"){s&&n.get(s).push({separator:!0});continue}if(/^[A-Za-z]:[\\/]/.test(d))return t;let c=gi.exec(d),g=yi.exec(d);if(c&&g)return t;let _=c||g?null:_i.exec(d),k=(c??g??_)?.[1];if(!k)return t;let R=c?{line:c[2],content:c[3],context:!1}:g?{line:g[2],content:g[3],context:!0}:{line:"",content:_[2],context:!1},A=n.get(k)??[];A.push(R),n.set(k,A),R.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((d,c)=>{let g=gn.test(d)?1:0,_=gn.test(c)?1:0;return g-_||(d<c?-1:d>c?1:0)}),l=[];for(let d of a){l.push(`${d} (${r.get(d)??0}):`);for(let c of n.get(d))"separator"in c?l.push(" --"):c.line?l.push(` ${c.line}${c.context?"-":":"} ${yn(c.content)}`):l.push(` ${yn(c.content)}`)}let u=a.length>1&&l.length>mi?bi(a.map(d=>`${d} (${r.get(d)??0})`)):[],f=[`${i}m ${a.length}f:`,...u,"",...l];if(f.length>dt){let d=f.length-dt;return[...f.slice(0,dt),`\u2026 ${d} more lines omitted`]}return f}$("smart-grep",vi);var _n=/^(?:([|\\/ ._-]*\*[|\\/* ._-]* ))?commit [0-9a-f]{7,40}\b/,xi=/^[|\\/* ._-]*$/,ki=/^ {4}/,Ei=2;function wi(t){if(!t.some(u=>_n.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 f=u.slice(0,s),d=xi.test(f),c=d?u.slice(s):u,g=ki.test(c),_=o&&g?null:_n.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<=Ei?e.push(u):(r+=1,i=d?f:"");continue}l(),e.push(u)}return l(),e}$("smart-log",wi);var Si=/^[\s=]+$/,Ti=/^\s*=+\s+(.*?)\s+=+\s*$/,Ai=512;$("strip-banners",t=>{let e=[];for(let n of t){if(Si.test(n))continue;let r=n.length<=Ai?Ti.exec(n):null;e.push(r?r[1]:n)}return e});function Ri(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",Ri);function Ci(t){return t==="compact"?.6:t==="minimal"?.3:1}var Ii=20;function Oi(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 bn=new WeakMap;function Di(t){let e=bn.get(t);if(e)return e;let n=t.strip_lines_matching.map(s=>new RegExp(s)),r={def:t,stripRegexes:n};return bn.set(t,r),r}function vn(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=Di(e),i=t;e.strip_ansi&&(i=ye(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(d=>ee.test(d)||!s.stripRegexes.some(c=>c.test(d))):rn(a,s.stripRegexes)),r!=="normal"&&!e.preserve_exact&&(a=un(a),a=dn(a)),r==="minimal"&&!e.preserve_exact&&(a=ln(a),(e.slug==="vitest"||e.slug==="npm-test")&&(a=Oi(a))),!e.preserve_exact&&(n.smartCode||n.smartCode===void 0&&r!=="normal"&&Qe(i))&&(a=Xe(a)),e.transform){let d=pn(e.transform);d&&(a=d(a))}let l=e.slug==="read-tool";if(!l){let d=lt(a);d.some(Boolean)&&(a=a.filter((c,g)=>!d[g]))}e.mask_abs_paths&&(a=cn(a)),e.fold_passing&&(a=an(a,e.fold_passing_threshold??5)),e.truncate_lines_at&&(a=sn(a,e.truncate_lines_at));let u=null;if(e.max_lines){let d=e.scale_with_level?Ci(n.verbosity):1,c=Math.min(e.max_lines,Math.max(Ii,Math.round(e.max_lines*d))),g=l?lt(a):null,_=g?g.filter(k=>!k).length:a.length;if(_>c){let k=c;if(g){let A=0;for(k=0;k<a.length&&A<c;)g[k]||(A+=1),k+=1}let R=_-c;if(e.keep_failures){let A=a.slice(k),j=A.filter(G=>!ee.test(G)),Ze=A.reduce((G,Ue,I)=>G+(!ee.test(Ue)&&!g?.[k+I]?1:0),0);u=j.length>0?j.join(`
8
- `):null,a=[...a.slice(0,k),...Ze>0?[Je(Ze)]:[],...A.filter(G=>ee.test(G))]}else if(l)u=a.slice(k).join(`
9
- `),a=[...a.slice(0,k),Je(R)];else{let{kept:A,dropped:j}=on(a,c);u=j.length>0?j.join(`
10
- `):null,a=A}}}let f=a.join(`
11
- `);return o&&f.length>0&&(f+=`
12
- `),f.trim().length===0&&e.on_empty&&(f=e.on_empty),{text:f,droppedTail:u}}var Ni=[/\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 xn(t){if(!t)return!1;for(let e of ye(t).split(`
13
- `))if(!/^\s*[✓✔√]\s/.test(e)&&Ni.some(n=>n.test(e)))return!0;return!1}var $i=new Set(["sudo","command","time","nice","nohup","env","stdbuf","timeout"]),Pi=/^[A-Za-z_][A-Za-z0-9_]*=/,pt=/^([a-z]+)-tool(?::\s|$)/;function Re(t){let e=t.trim(),n=e.split(/\s+/),r=0;for(;r<n.length;){let a=n[r];if(Pi.test(a)){r++;continue}if($i.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 Mi=new Set(["cd","export","source","set","unset","mkdir","true",":","pushd","popd","alias","ulimit","umask","echo","printf","sleep","touch","rm","cp","mv","chmod","ln"]);function kn(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 Li(t){let e=kn(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=kn(t,!0).map(n=>n.trim()).filter(Boolean);if(e.length===0)return null;for(let n of e.slice(0,-1)){let r=Re(n).split(/\s+/)[0]??"";if(!Mi.has(r))return null}return Li(e[e.length-1])}function En(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 wn(t){let e=pt.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=mt(n),s=r?Re(r):null;return s&&s!==t?[s,t]:[t]}var Sn=`
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 ht(t){let e=Buffer.from(t,"utf8");if(e.length<=256)return t;let n=256-Buffer.byteLength(Sn,"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")+Sn+e.subarray(s).toString("utf8")}var Fi=/^ID {2,}TITLE {2,}BRANCH {2,}STATE {2,}CREATED *$/,Bi=/^… \([1-9]\d* more lines omitted\)$/,ji=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?Z$/;function zi(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 Zi(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=>Fi.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(Bi.test(g))continue;if(/…|\.\.\./.test(g))return t;let _;if(s>=0){if(/[^\x20-\x7e]/.test(g))return t;let k=i.map((R,A)=>g.slice(R,i[A+1]));if(k.slice(0,-1).some(R=>R[0]===" "||!R.endsWith(" "))||(_=k.map(R=>R.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])||!ji.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,f=[];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"),R=`TITLE ${_} = ${k}`;g*(Buffer.byteLength(c)-Buffer.byteLength(_))<=Buffer.byteLength(R)+1||(u.set(c,_),f.push(R))}if(f.length===0)return a;for(let{index:c,cells:g}of o)r[c]=g.map((_,k)=>k===1?u.get(_)??_:_).join(" ");let d=[...r,"",...f].join(`
25
- `)+n;return Buffer.byteLength(d)<Buffer.byteLength(a)?d:a}function gt(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=zi(t,e==="minimal")}else n==="gh"&&(r=Zi(t,e==="minimal"));return Buffer.byteLength(r)<Buffer.byteLength(t)?r:t}var Ui=/^(?:\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|$)/,Hi=/^\[tkr: previous log line repeated \d+ additional times\]$/m;function Tn(t){if(Buffer.byteLength(t)<2048||Qe(t)||Hi.test(t))return t;let e=t.split(`
26
- `),n=[];for(let r=0;r<e.length;){let s=e[r],i=r+1;if(Ui.test(s))for(;i<e.length&&e[i]===s;)i+=1;let o=i-r,a=`[tkr: previous log line repeated ${o-1} additional times]`;if(o>=3&&Buffer.byteLength(a)+1<(o-1)*(Buffer.byteLength(s)+1))n.push(s,a);else for(let l=r;l<i;l+=1)n.push(s);r=i}return n.join(`
27
- `)}var An=null;function yt(t){An=t}async function Vi(t,e){let n=await Xt();return qe(t,n.values(),e)}var Ki=/^(?:grep|rg|find|eslint|ruff|flake8|mypy|prettier|biome|black|stylelint)(?:\s|$)|^git\s+(?:diff|grep)\b/,Wi=2048;async function _t(t,e,n,r={}){let s=Buffer.byteLength(e,"utf8"),{exitCode:i,yolo:o=!1,...a}=r,l=Re(En(t.startsWith("bash-tool: ")?t.slice(11):t)),u=i!=null&&i!==0&&!(i===1&&Ki.test(l)),f=An??Vi,d=null;for(let I of wn(t))if(d=await f(I,n),d)break;!d&&s>=Wi&&!pt.test(t)&&(d=await f(`bash-tool: ${t}`,n));let c=mt(t.startsWith("bash-tool: ")?t.slice(11):t),g=d?.slug==="git-log"&&c!=null&&/^git\s+log(?:\s|$)/.test(Re(c)),_=i==null&&(g?/^(?:fatal|error):/im.test(ye(e)):xn(e)),k=d?.transform==="smart-read"&&s<=16384&&(e.endsWith(`
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
28
  `)?e.slice(0,-1):e).split(`
29
- `).length<=200,R=s<=16384&&c!=null&&/^(?:head|tail)(?:\s|$)|^sed\s+(?:(?:-[Eru]+|--(?:regexp-extended|unbuffered|sandbox))\s+)*(?:-[Enruse]*n[Enruse]*(?:\s|$)|--(?:quiet|silent)(?:\s|$))/.test(Re(c));if(!o&&(R||k&&a.smartCode!==!0))return{output:e,filterId:d?.slug??null,rawBytes:s,filteredBytes:s,debugBypass:u||_,droppedTail:null};if(!d||(u||_)&&d.preserve_exact&&!o)return{output:e,filterId:null,rawBytes:s,filteredBytes:s,debugBypass:u||_,...o?{droppedTail:null}:{}};let A=I=>{if(!o)return I;let st=I.filteredBytes>s||s>0&&I.output.length===0?e:I.output,it=!I.debugBypass&&!d?.preserve_exact?gt(st,"minimal",I.filterId??""):st,Lt=ht(it)===it?it:ht(st);return{...I,output:Lt,filteredBytes:Buffer.byteLength(Lt,"utf8"),droppedTail:null}};if(u||_){let I=o?vn(e,{...d,keep_failures:!0,transform:void 0,max_lines:void 0,truncate_lines_at:void 0,on_empty:void 0},{verbosity:"minimal",smartCode:!1}):d.strip_ansi&&!d.preserve_exact?ye(e):e;return!o&&a.verbosity==="minimal"&&d.transform!=="smart-read"&&(I=Tn(I)),A({output:I,filterId:d.slug,rawBytes:s,filteredBytes:Buffer.byteLength(I,"utf8"),debugBypass:!0})}let{text:j,droppedTail:Ze}=ft(e,d,o?{...a,verbosity:"minimal"}:a),G=!o&&!d.preserve_exact?gt(j,a.verbosity,d.slug):j,Ue=Buffer.byteLength(G,"utf8");return e.trim().length>0&&Ue>=s?A({output:e,filterId:d.slug,rawBytes:s,filteredBytes:s,debugBypass:!1,droppedTail:null}):A({output:G,filterId:d.slug,rawBytes:s,filteredBytes:Ue,debugBypass:!1,droppedTail:Ze})}async function Rn(){let t=[];for await(let e of process.stdin)t.push(e);return Buffer.concat(t).toString("utf8")}import{existsSync as ao}from"node:fs";import{fileURLToPath as co}from"node:url";import{dirname as lo,join as uo}from"node:path";import{appendFileSync as Qi,chmodSync as eo,mkdirSync as to,existsSync as no,readFileSync as mu,rmSync as hu}from"node:fs";import{dirname as ro,join as so}from"node:path";import Gi from"node:os";import{join as Cn}from"node:path";function T(){return process.env.TOKMIZER_HOME||Cn(Gi.homedir(),".tokmizer")}function $e(){return Cn(T(),"install-id")}import{readFileSync as Yi,renameSync as qi,statSync as Ji,writeFileSync as Xi}from"node:fs";function et(t,e,n){try{if(Ji(t).size<=e)return;let r=Yi(t,"utf8").split(`
30
- `).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}`;Xi(o,s.length?`${s.join(`
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(`
31
31
  `)}
32
- `:"",{mode:384}),qi(o,t)}catch{}}var io="usage.jsonl";var In=2*1024*1024;function oo(){return so(T(),io)}function On(t,e,n=oo()){try{let r=ro(n);no(r)||to(r,{recursive:!0,mode:448});let s=t.replace(/[^A-Za-z0-9._-]/g,"").slice(0,64)||"unknown";Qi(n,`{"t":${Math.floor(Date.now()/1e3)},"s":"${s}","o":${e?1:0}}
33
- `,{mode:384}),eo(n,384),et(n,In,In/2)}catch{}}var fo=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"]),po=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"]),Dn=new Set(["sh","bash","zsh","dash","ksh","fish","python","python3","python2","node","ruby","perl","php","awk","sed","deno","bun"]),Nn=/(?:^|\s)(?:--follow|-[0-9a-zA-Z]*f[a-zA-Z]*)(?:\s|=|$)/,mo=new Set(["docker","podman","kubectl","nerdctl","docker-compose","stern","flyctl"]);function ho(t,e){let n=bt(e);return n==="tail"||n==="journalctl"?Nn.test(t):n==="stern"?!0:mo.has(n)?/\blogs?\b/.test(t)&&Nn.test(t):!1}var $n=/^[A-Za-z_][A-Za-z0-9_]*\+?=/,go=/^[A-Za-z_][A-Za-z0-9_-]*\s*\(\s*\)/,yo=/(?:^|[;&|\n({])\s*[A-Za-z_][A-Za-z0-9_-]*\s*\(\s*\)/;function bt(t){let e=t.lastIndexOf("/");return e===-1?t:t.slice(e+1)}function _o(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 Pn(t){let e=[],n="",r=0,s=!1,i=!1,o=!1,a=!1,l=0,u=0,f=()=>{n.length>0&&(e.push({kind:"cmd",text:n}),n="")},d=c=>{f(),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]==="&"){d("&&"),r+=2;continue}if(c==="&"&&t[r+1]!==">"){let _=n.replace(/\s+$/,""),k=_[_.length-1];if(k!==">"&&k!=="<"&&k!=="&"){d("&"),r+=1;continue}}if(c==="|"&&t[r+1]==="|"){d("||"),r+=2;continue}if(c==="|"&&t[r+1]==="&"){d("|&"),r+=2;continue}if(c===";"&&t[r+1]===";"){let _=t[r+2]==="&";d(_?";;&":";;"),r+=_?3:2;continue}if(c===";"){d(";"),r+=1;continue}if(c===`
34
- `){d(`
35
- `),r+=1;continue}if(c==="|"){d("|"),r+=1;continue}}n+=c,r+=1}return s||i||o||l!==0||u!==0||a?[{kind:"cmd",text:t,unsafe:!0}]:(f(),e)}function bo(t){return t.trim().split(/\s+/)[0]??""}function vo(){try{let t=lo(co(import.meta.url)),e=uo(t,"..","bin","tkr-exec.js");return ao(e)?`node '${e.replace(/'/g,"'\\''")}'`:null}catch{return null}}function xo(t,e="tkr-exec"){if(t.includes("<<")||yo.test(t))return t;let n=Pn(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=bo(o),l=n[s+1],u=l?.kind==="sep"&&(l.text==="|"||l.text==="|&"),f=l?.kind==="sep"&&l.text==="&";if(fo.has(a)||po.has(a)||Dn.has(a)||Dn.has(bt(a))||$n.test(a)||a.startsWith("(")||a.startsWith("#")||a.startsWith("<")||a.startsWith(">")||go.test(o)||ho(o,a)||a.endsWith(")")||u||f||_o(i.text)||i.text.includes("<(")||i.text.includes(">(")||a==="node"&&o.includes("tkr-exec.js")){r.push(i.text);continue}let d=i.text.match(/^\s*/)?.[0]??"",c=i.text.match(/\s*$/)?.[0]??"";r.push(`${d}${e} ${o}${c}`)}return r.join("")}var ko=new Set(["command","workdir","timeout_ms","yield_time_ms","max_output_tokens","shell","login","tty","description"]),Eo=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"]),wo=new Set(["log","diff","show","status","blame","ls-files","rev-parse","describe","shortlog"]),So={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 To(t){if(/\$|`|<\(|>\(|\\\r?\n/.test(t)||/>/.test(t.replace(/2>&1|[12]?>\s*\/dev\/null/g,"")))return!1;for(let e of Pn(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=>$n.test(i)))return!1;let r=bt(n[0]);if(r!==n[0])return!1;let s=So[r];if(s&&n.slice(1).some(i=>s.test(i)))return!1;if(!(r==="git"?wo.has(n[1]??""):Eo.has(r)))return!1}return!0}function Mn(t,e,n=vo()){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=>!ko.has(o))||e==="codex"&&!To(s)||!n)return null;let i=xo(s,n);return On(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 Ao}from"node:path";import{mkdir as Au,readFile as Ro,writeFile as Ru,unlink as Cu,rename as Iu}from"node:fs/promises";var Co="state.json";function Io(){try{let t=Intl.DateTimeFormat().resolvedOptions().timeZone;return t&&t.length>0?t:"Etc/UTC"}catch{return"Etc/UTC"}}function Oo(t){return t?.dir??T()}async function Pe(t){let e=Oo(t);try{let n=await Ro(Ao(e,Co),"utf8"),r=JSON.parse(n);return{...r,lastSettingsRevision:r.lastSettingsRevision??0,timeZone:r.timeZone??Io(),bonusActive:r.bonusActive??!1,...r.bonusResetAt!==void 0?{bonusResetAt:r.bonusResetAt}:{}}}catch{return null}}function Do(){let t=Number(process.env.TOKMIZER_OFFLINE_GRACE_MS);return Number.isFinite(t)&&t>0?t:6048e5}function Ln(t,e=Date.now()){let n=t.lastHeartbeatOkAt;if(typeof n=="number"&&e-n>Do())return!0;if(t.subEndsAt){let r=Date.parse(t.subEndsAt);if(Number.isFinite(r)&&e>r)return!0}return!1}function Fn(t,e=Date.now()){return t.plan}import{readFile as No,writeFile as Pu,mkdir as Mu,chmod as Lu,rm as Fu,rename as Bu,readdir as ju}from"node:fs/promises";import{join as $o}from"node:path";var Po="settings-cache.json",Bn=Ne.parse({}),Hu=Ne.partial().extend({filters:Ne.shape.filters.removeDefault().partial().optional()});async function Me(){try{let t=await No($o(T(),Po),"utf8"),e=JSON.parse(t);return Ne.parse({...Bn,...e})}catch{return Bn}}var Mo=[[/(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 Le(t){let e=t;for(let[n,r]of Mo)e=e.replace(n,r);return e}import{join as Hn}from"node:path";import{appendFileSync as Uo,chmodSync as Ho,existsSync as Vo,mkdirSync as Ko,readFileSync as cd,renameSync as ld,rmdirSync as ud,statSync as Wo,unlinkSync as dd,utimesSync as fd,writeFileSync as pd}from"node:fs";import{createHash as Gu,randomUUID as Lo}from"node:crypto";import{readFile as jn,writeFile as zn,mkdir as Fo}from"node:fs/promises";async function vt(){try{let n=(await jn($e(),"utf8")).trim();if(/^[0-9a-f-]{36}$/i.test(n))return n}catch{}await Fo(T(),{recursive:!0});let t=Lo();try{return await zn($e(),t,{mode:384,flag:"wx"}),t}catch{try{let e=(await jn($e(),"utf8")).trim();if(/^[0-9a-f-]{36}$/i.test(e))return e}catch{}return await zn($e(),t,{mode:384}),t}}import{createRequire as Bo}from"node:module";var jo=Bo(import.meta.url);function zo(){for(let t of["../package.json","../../package.json"])try{let e=jo(t).version;if(typeof e=="string"&&e)return e}catch{}return"0.0.0"}var xt=zo();var Zn=`-----BEGIN PUBLIC KEY-----
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===`
34
+ `){f(`
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-----
36
36
  MCowBQYDK2VwAyEAj/kMlXlhTIGHRKxOKMuGFa1S1ybxxwgdYcAE0YM9fgU=
37
37
  -----END PUBLIC KEY-----
38
- `;var rd=300*1e3;function Un(){return((process.env.TOKMIZER_DEV==="1"?process.env.TOKMIZER_RESP_SIGNING_PUBLIC_KEY_PEM:void 0)??Zn).replace(/\\n/g,`
39
- `)}var Go=512*1024;function Vn(){return Hn(T(),"spool")}function Yo(t){return Hn(Vn(),`${t}.jsonl`)}function tt(t,e){try{Ko(Vn(),{recursive:!0,mode:448});let n=Yo(t);if(Vo(n)&&Wo(n).size>=Go)return;Uo(n,JSON.stringify(e)+`
40
- `,{mode:384}),Ho(n,384)}catch{return}}var Jo=/^[a-z0-9][a-z0-9._-]*$/i,Xo=/^[a-z][a-z-]+$/,Qo=/^[A-Za-z_][A-Za-z0-9_]*=/,ea=new Set(["gh","glab","gup","hub","gist"]),ta=/^(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,na=24,ra=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 Kn(t){let e=t.toLowerCase();return e.startsWith("git")||ea.has(e)}function kt(t){let e=t.trim().split(/\s+/).filter(a=>a.length>0),n=0;for(;n<e.length&&Qo.test(e[n]??"");)n+=1;let r=e[n];if(!r||!Jo.test(r)||r.length>na||Kn(r)||ta.test(r)||Le(r)!==r)return"";let s=e[n+1];return s&&Kn(s)?"":(s&&ra.has(r.toLowerCase())&&Xo.test(s)?`${r} ${s}`:r).slice(0,64)}async function Wn(t){if(!t.telemetryOptIn)return;let e=kt(t.cmd),n=e&&Le(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 Gn(t){if(t.plan!=="pro"||!(await Me()).telemetryOptIn)return;let e=kt(t.cmd);!e||Le(e)!==e||tt("learn",{cmd:e,filterId:t.filterId==null?null:B(t.filterId),rawBytes:t.rawBytes,filteredBytes:t.filteredBytes})}import{appendFileSync as sa,chmodSync as ia,mkdirSync as oa}from"node:fs";import{join as aa}from"node:path";var ca="stats.jsonl";var Yn=2*1024*1024;var la=new Set(["sudo","command","time","nice","nohup","env","stdbuf","timeout"]),ua=new Set(["-u","-g","-n","-s","-k"]),da=/^[a-z0-9][a-z0-9._-]*$/i,fa=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"]),Jn=/^[A-Za-z_][A-Za-z0-9_]*=/;function qn(t){return t.length===0||t[0]==="cd"||t.every(e=>Jn.test(e))}function pa(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(`|;&<>
41
- `.includes(o)){if(i(),qn(e)){e=[];continue}return e}n+=o,r=!0}return i(),qn(e)?[]:e}function Xn(t){let e=pa(t).map(a=>a.replace(/^[({]+/,"")).filter(Boolean),n=0;for(;n<e.length;){let a=e[n];if(Jn.test(a)){n+=1;continue}if(la.has(a)){for(n+=1;n<e.length;){let l=e[n];if(l.startsWith("-")){n+=ua.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("-")&&da.test(i)&&fa.has(s.toLowerCase())?`${s} ${i}`:s).slice(0,24)}function ma(){return aa(T(),ca)}function Qn(t,e,n=ma(),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))}`:"",f=`{"t":${Math.floor(Date.now()/1e3)},"r":${t},"f":${e}${r?',"m":1':""}${a}${l}${u}}
42
- `;try{oa(T(),{recursive:!0,mode:448}),sa(n,f,{mode:384}),ia(n,384),et(n,Yn,Yn/2)}catch{return}}function er(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 ha=[{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"]}],Ld=[...ha.map(t=>t.host),"shell"];function tr(t){return null}import{createConnection as Ca}from"node:net";import{spawn as Ia}from"node:child_process";import{existsSync as cr,openSync as Tt,closeSync as or,unlinkSync as Rt,writeFileSync as Ct,mkdirSync as It,readFileSync as Oa,appendFileSync as Da,rmSync as Na,statSync as $a}from"node:fs";import{dirname as Pa,join as Ot}from"node:path";import{fileURLToPath as Ma}from"node:url";var ga=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()}),ya=m.object({id:m.string().min(1).max(64),op:m.literal("ping")}),_a=m.object({id:m.string().min(1).max(64),op:m.literal("shutdown"),installId:m.string().min(1).max(64)}),ba=m.object({id:m.string().min(1).max(64),op:m.literal("reload"),installId:m.string().min(1).max(64).optional()}),zd=m.discriminatedUnion("op",[ga,ya,_a,ba]),Zd=m.object({id:m.string(),ok:m.literal(!0),data:m.unknown()}),Ud=m.object({id:m.string(),ok:m.literal(!1),err:m.string(),retryAfterMs:m.number().int().nonnegative().optional()}),nr=m.object({filter:Te.nullable(),cacheHit:m.boolean().optional()}),nt=`
43
- `,Hd=64*1024;function Et(t){return JSON.stringify(t)+nt}function*rr(t){let e=0;for(;;){let n=t.indexOf(nt,e);if(n<0)return;yield t.slice(e,n),e=n+1}}function Fe(){return`${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}import va from"node:os";import{join as Be}from"node:path";import{existsSync as xa,statSync as ka,lstatSync as sr,unlinkSync as Ea,mkdirSync as wa,chmodSync as Sa}from"node:fs";import{createHash as Ta}from"node:crypto";var wt=100;function Aa(t){let e=Ta("sha256").update(T()).digest("hex").slice(0,8),n=Be(va.tmpdir(),`tkr-${t}-${e}`),r=Be(n,"d.sock");if(Buffer.byteLength(r)>wt)throw new Error("Temporary directory path is too long for IPC");return ir(n,t),r}function Ra(t,e){try{let n=sr(t);return n.isDirectory()&&n.uid===e&&(n.mode&63)===0}catch{return!1}}function ir(t,e){wa(t,{recursive:!0,mode:448});let n=sr(t);if(!n.isDirectory()||n.uid!==e)throw new Error("Unsafe IPC directory");Sa(t,448)}function je(){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&&Ra(e,t)){let s=Be(e,`tokmizer-${t}.sock`);if(Buffer.byteLength(s)<=wt)return{path:s,isPipe:!1}}let n=Be(T(),"run"),r=Be(n,"daemon.sock");return Buffer.byteLength(r)>wt?{path:Aa(t),isPipe:!1}:(ir(n,t),{path:r,isPipe:!1})}async function St(){let{path:t,isPipe:e}=je();if(e||!xa(t))return;try{if(!ka(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{Ea(t)}catch{}}var Jd=5*6e4;var lr=500,La=3e3,ar=1,Fa=6e4,Ba=256*1024;function Dt(){return Ot(T(),"daemon.spawn.fail")}function Nt(){return Ot(T(),"daemon.log")}function ja(){try{let t=Number(Oa(Dt(),"utf8"));return Number.isFinite(t)&&Date.now()-t<Fa}catch{return!1}}function za(t){try{It(T(),{recursive:!0});let e=Nt();try{$a(e).size>Ba&&Rt(e)}catch{}Da(e,`${new Date().toISOString()} ${t}
44
- `)}catch{}}function Za(t){try{It(T(),{recursive:!0}),Ct(Dt(),String(Date.now()))}catch{}za(`spawn failed: ${t.message}`)}function Ua(){try{Na(Dt(),{force:!0})}catch{}}async function rt(t,e){return new Promise((n,r)=>{let s=Ca(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 Ha(){return process.env.TOKMIZER_DAEMON_BIN?process.env.TOKMIZER_DAEMON_BIN:Ma(new URL("../bin/tkr-daemon.js",import.meta.url))}async function At(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(cr(t))return!0;await new Promise(i=>setTimeout(i,75))}return!1}async function Va(t){let e=Ha();if(!cr(e))throw new Error(`tkr-daemon binary not found at ${e}`);let{path:n}=je(),r=process.platform==="win32"?T():Pa(n);try{It(r,{recursive:!0})}catch{}let s=Ot(r,"daemon.spawn.lock"),i=null;try{i=Tt(s,"wx"),Ct(i,String(process.pid))}catch(o){if(o.code==="EEXIST"){if(await At(n,5e3))return;try{Rt(s)}catch{}try{i=Tt(s,"wx"),Ct(i,String(process.pid))}catch(l){if(l.code==="EEXIST"){await At(n,5e3);return}throw l}}else throw o}try{let o=null;try{o=Tt(Nt(),"a")}catch{}if(Ia(process.execPath,[e],{detached:!0,stdio:["ignore","ignore",o??"ignore"],env:{...process.env,TOKMIZER_DAEMON_INSTALL_ID:t}}).unref(),o!==null)try{or(o)}catch{}if(!await At(n,3e3))throw new Error("tkr-daemon failed to bind socket within 3s")}finally{if(i!==null){try{or(i)}catch{}try{Rt(s)}catch{}}}}async function Ka(t={}){let{path:e}=t.socketPath?{path:t.socketPath}:je(),n=await vt();try{let r=await rt(e,lr);r.write(Et({id:Fe(),op:"shutdown",installId:n})),await new Promise(s=>setTimeout(s,150));try{r.destroy()}catch{}return!0}catch{return!1}}async function Wa(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 $t(t={}){let{path:e}=t.socketPath?{path:t.socketPath}:je(),n=await vt(),r=null,s=0,i=!1;for(;s<=ar;)try{r=await rt(e,lr),Ua();break}catch{if(s+=1,s>ar)throw new Error(`tkr-daemon unreachable at ${e}`);if(ja())throw new Error(`tkr-daemon spawn on cooldown (see ${Nt()})`);await St();try{await Va(n),i=!0}catch(f){throw Za(f),f}}if(!r)throw new Error("tkr-daemon: socket setup failed");let o=new Map,a="";r.setEncoding("utf8"),r.on("data",f=>{a+=f;let d=-1;for(let g=0;g<a.length;g++)a[g]===nt&&(d=g);if(d<0)return;let c=[];for(let g of rr(a.slice(0,d+1)))c.push(g);a=a.slice(d+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 f of o.values())clearTimeout(f.timer),f.reject(new Error("daemon socket closed"));o.clear()}),r.on("error",()=>{});function l(f){return new Promise((d,c)=>{let g=setTimeout(()=>{o.delete(f.id),c(new Error(`daemon request timeout (${f.op})`))},La);o.set(f.id,{resolve:d,reject:c,timer:g}),r.write(Et(f))})}let u={filter:async(f,d,c)=>{let g=await l({id:Fe(),op:"filter",cmd:f.slice(0,2048),plan:d,...c&&c.length>0?{allowed:c.slice(0,512)}:{},installId:n});if(!g.ok)return null;let _=nr.safeParse(g.data);return _.success?_.data.filter:null},ping:async()=>{let f=await l({id:Fe(),op:"ping"});if(!f.ok)throw new Error(f.err);return f.data},reload:async()=>{let f=await l({id:Fe(),op:"reload",installId:n});if(!f.ok)throw new Error(f.err);return f.data},close:()=>{try{r.end()}catch{}}};if(!t.skipVersionCheck&&!i){let f=!1;try{f=(await u.ping()).version!==xt}catch{}if(f){try{await Ka(t.socketPath?{socketPath:t.socketPath}:{})}catch{}u.close();let d=await Wa(e,2e3);if(await St(),!d)throw new Error("stale daemon still running after shutdown request");return $t({...t,skipVersionCheck:!0})}}return u}import{createPublicKey as rc,verify as sc}from"node:crypto";import{createCipheriv as pf,createDecipheriv as Ga,hkdfSync as Ya,randomBytes as mf}from"node:crypto";var qa=Buffer.from("tokmizer-bundle-enc-v1"),Ja=Buffer.from("rules-bundle");function Xa(t){return Buffer.from(Ya("sha256",Buffer.from(t,"utf8"),qa,Ja,32))}function ur(t,e){let n=Xa(e),r=Buffer.from(t,"base64url"),s=r.subarray(0,12),i=r.subarray(12,28),o=r.subarray(28),a=Ga("aes-256-gcm",n,s);return a.setAuthTag(i),Buffer.concat([a.update(o),a.final()]).toString("utf8")}import{chmodSync as yf,readFileSync as Qa,writeFileSync as _f,mkdirSync as bf,renameSync as vf}from"node:fs";import{join as ec}from"node:path";var tc=m.object({payload:m.string().min(1),signature:m.string().min(1),enc:m.literal("v1"),fetchedAt:m.number().int().nonnegative()});function nc(){return ec(T(),"bundle-cache.json")}function dr(){try{let t=Qa(nc(),"utf8"),e=tc.safeParse(JSON.parse(t));return e.success?e.data:null}catch{return null}}var ic=m.object({bundleVersion:m.number().int().nonnegative(),signedAt:m.number().int(),filters:m.array(Te)}),$f=m.object({payload:m.string().min(1),signature:m.string().min(1),enc:m.literal("v1")}),oc=10080*60*1e3;function ac(){let t=Number(process.env.TOKMIZER_MAX_BUNDLE_AGE_MS);return Number.isFinite(t)&&t>0?t:oc}function cc(t,e){let n=Un();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=rc({key:n,format:"pem"});if(!sc(null,Buffer.from(t.payload,"utf8"),r,Buffer.from(t.signature,"base64url")))throw new Error("tkr-daemon: rules bundle signature invalid");return JSON.parse(ur(t.payload,e))}function lc(t,e){let n=cc(t,e),r=ic.parse(n);if(Date.now()-r.signedAt>ac())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 nn(),{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 fr(){try{let t=dr();if(!t)return null;let e=await Pe();return e?.signingSecret?lc(t,e.signingSecret):null}catch{return null}}var Ce=null,ze=null;async function uc(){if(Ce)return Ce;if(ze)return ze;let t=$t().then(e=>{if(ze===t)return Ce=e,e;try{e.close()}catch{}return null}).catch(()=>null);return ze=t,t}var Pt=null,Mt=!1;async function dc(){return Mt||(Mt=!0,Pt=await fr()),Pt}async function pr(t,e,n){let r=await dc();if(!r)return null;let s=r.selectFor(t,e,[...n]);return!s||!n.has(B(s.slug))?null:s}function fc(t){return t?{...t,matchRegex:new RegExp(t.match_command)}:null}function mr(t){yt(async(e,n)=>{let r=t==="free"?"trial":t,s=n??Ye(void 0),i=await uc();if(!i)return pr(e,r,s);try{let o=await i.filter(e,r,[...s]);return!o||!s.has(B(o.slug))?null:fc(o)}catch{return pr(e,r,s)}})}function hr(){if(yt(null),Ce)try{Ce.close()}catch{}Ce=null,ze=null,Pt=null,Mt=!1}import{readFileSync as pc}from"node:fs";import{join as mc}from"node:path";function gr(){try{return pc(mc(T(),"yolo-mode"),"utf8")==="on"}catch{return!1}}var hc=new Set(["shell","bash","exec","run_shell_command","execute_shell_command"]);async function gc(t){if(t.event!=="after_tool_call")return{action:"continue"};if(!hc.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=gr();if(!n&&(!s||!r))return{action:"continue"};let i=await Me();if(!i.enabled)return{action:"continue"};let o=await Pe();if(!o||!o.token)return{action:"continue"};let a=Fn(o);mr(a);let l=Ye(o.allowedFilters,Ln(o)),u=new Set(i.filters.disabled.map(B)),f=u.size>0?new Set([...l].filter(j=>!u.has(j))):l,d,c=null;try{d=await _t(e,n,f,{verbosity:i.outputVerbosity,yolo:s,exitCode:t.exit_code}),s&&r&&(c=await _t(e,r,f,{verbosity:i.outputVerbosity,yolo:s,exitCode:t.exit_code}))}finally{hr()}let g=d.filteredBytes<d.rawBytes||c!=null&&c.filteredBytes<c.rawBytes,_=c?.output??r,k=_?d.output?`${d.output}
45
- ${_}`:_:d.output,R=Buffer.byteLength(n,"utf8")+Buffer.byteLength(r,"utf8"),A=er(R,g?Buffer.byteLength(k,"utf8"):R,tr("codex"));return Qn(A.raw,A.filtered,void 0,!1,"codex","sh",Xn(e)),await Gn({cmd:e,filterId:d.filterId,rawBytes:d.rawBytes,filteredBytes:d.filteredBytes,plan:a}),await Wn({cmd:e,tokensSaved:Math.max(0,Math.round((A.raw-A.filtered)/4)),rawTokens:Math.round(A.raw/4),optimized:d.filterId!=null,telemetryOptIn:i.telemetryOptIn,host:"codex"}),g?{action:"replace_output",replacement:k,reason:"tokmizer"}:{action:"continue"}}async function yc(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 Mn(n,"codex")??"";if(n.hook_event_name)return"";try{return JSON.stringify(await gc(n))}catch(r){return process.stderr.write(`tkr-codex: ${r.message}
46
- `),e}}async function yr(){let t=await yc(await Rn());t&&process.stdout.write(t)}yr().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}
47
50
  `),process.stdout.write(JSON.stringify({action:"continue"})),process.exit(0)});