@sreetej510/pi-hpc-tools 0.1.1 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,7 +19,7 @@ ever leaving your local project.
19
19
  |---|---|
20
20
  | `/hpc:on` | Enable the HPC tools for the current project |
21
21
  | `/hpc:off` | Disable the HPC tools for the current project |
22
- | `/hpc:config` | Configure host/user/password/plink path |
22
+ | `/hpc:config` | Set credentials: `/hpc:config username@host password` |
23
23
 
24
24
  ## Configuration
25
25
 
@@ -28,6 +28,12 @@ Credentials are resolved in this order:
28
28
  1. Environment variables: `HPC_USERNAME` (or `HPC_USER`), `HPC_HOST`, `HPC_PASSWORD`.
29
29
  2. `hpc-config.json` (in `~/.pi/agent/.pi/` or `~/.pi/`), written by `/hpc:config`:
30
30
 
31
+ ```bash
32
+ /hpc:config myuser@hpc-login.example.edu your-password
33
+ ```
34
+
35
+ Passwords with spaces work — everything after `username@host` is treated as the password.
36
+
31
37
  ```json
32
38
  {
33
39
  "username": "...",
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ var hf=Object.defineProperty;var lt=(e,t)=>{for(var n in t)hf(e,n,{get:t[n],enumerable:!0})};import{existsSync as zn,mkdirSync as bf,readFileSync as Ao,writeFileSync as Tf}from"node:fs";import{dirname as Ef,join as kf}from"node:path";import{homedir as Oo}from"node:os";import{join as aa}from"node:path";var Kn=["ls_hpc","read_file_hpc","grep_hpc"],je=1e3,oa=12e4,Co=10,ia=aa(Oo(),".pi","agent"),sa=[aa(ia,".pi","hpc-config.json"),aa(Oo(),".pi","hpc-config.json")],ma="C:/Users/sreet/plink/plink.exe";var Ro=!1,vo=null,Mo=!1,So=!1;function Mt(){return Ro}function pa(e){Ro=e}function ua(){return vo}function ft(e){vo=e}function Gn(){return Mo}function wo(e){Mo=e}function _n(){return So}function Hn(e){So=e}function Pf(e){let t=Ef(e);zn(t)||bf(t,{recursive:!0})}function Lo(e,t){return(e.enabledProjects??[]).includes(t)}function qo(e,t){let n=Be();if(!n)return;let r=new Set(n.enabledProjects??[]);t?r.add(e):r.delete(e),ca({...n,enabledProjects:[...r]})}function tn(){let e=process.env.HPC_USERNAME||process.env.HPC_USER,t=process.env.HPC_HOST,n=process.env.HPC_PASSWORD;if(e&&t&&n)return{username:e,host:t,password:n};for(let r of sa)try{if(!zn(r))continue;let a=JSON.parse(Ao(r,"utf-8"));if(a.username&&a.host&&a.password)return a}catch{}return null}function ca(e){let t=sa[0];Pf(t),Tf(t,JSON.stringify(e,null,2),"utf-8"),ft(e)}function Be(){return ua()||ft(tn()),ua()}function jo(e){return e.replace(/\\/g,"/")}function Of(){try{let e=kf(ia,"settings.json");if(zn(e))return JSON.parse(Ao(e,"utf-8"))}catch{}return{}}function Fo(){let e=Of().shellPath;return e||(process.platform==="win32"?"C:\\Program Files\\Git\\bin\\bash.exe":"bash")}function Do(){if(process.env.PLINK_PATH)return jo(process.env.PLINK_PATH);let e=Be();return e?.plinkPath?jo(e.plinkPath):zn(ma)?ma:"plink"}var St="Usage: /hpc:config username@host password (password may contain spaces)";function No(e){let t=e.trim();if(!t)return{ok:!1,reason:"empty"};let n=t.split(/\s+/),r=n[0],a=r.indexOf("@");return a>0&&a<r.length-1?n.length<2?{ok:!1,reason:"invalid"}:{ok:!0,username:r.slice(0,a),host:r.slice(a+1),password:n.slice(1).join(" ")}:n.length>=3?{ok:!0,username:n[0],host:n[1],password:n.slice(2).join(" ")}:{ok:!1,reason:"invalid"}}import{DEFAULT_MAX_BYTES as z$,DEFAULT_MAX_LINES as B$,formatSize as bo,truncateHead as W$}from"@earendil-works/pi-coding-agent";var p={};lt(p,{Assign:()=>Cf,Clone:()=>on,Create:()=>jd,Discard:()=>Ad,Metrics:()=>ve,Update:()=>Ld});var ve={assign:0,create:0,clone:0,discard:0,update:0};function Cf(e,t){return ve.assign+=1,{...e,...t}}var i={};lt(i,{Entries:()=>Vf,EntriesRegExp:()=>Wf,Every:()=>Hf,EveryAll:()=>zf,GraphemeCount:()=>Kf,HasPropertyKey:()=>Bf,IsArray:()=>rn,IsBigInt:()=>nn,IsBoolean:()=>Vo,IsClassInstance:()=>Nf,IsConstructor:()=>jf,IsDeepEqual:()=>xa,IsEqual:()=>M,IsFunction:()=>Zo,IsGreaterEqualThan:()=>Qo,IsGreaterThan:()=>qf,IsInteger:()=>fa,IsLessEqualThan:()=>Jo,IsLessThan:()=>Ff,IsMaxLength:()=>Gf,IsMinLength:()=>_f,IsMultipleOf:()=>Df,IsNull:()=>Vn,IsNumber:()=>Zn,IsObject:()=>an,IsObjectNotArray:()=>Af,IsString:()=>Jn,IsSymbol:()=>Lf,IsUndefined:()=>da,IsUnsafePropertyKey:()=>Xo,IsValueLike:()=>Uf,Keys:()=>Wn,ShiftLeft:()=>Qn,Symbols:()=>Zf,Values:()=>Jf});function dt(e,t,n){return e>=t&&e<=n}function Rf(e){return e===8205}function vf(e){return dt(e,55296,56319)}function Uo(e){return dt(e,127462,127487)}function Go(e){return dt(e,65024,65039)}function _o(e){return dt(e,768,879)||dt(e,6832,6911)||dt(e,7616,7679)||dt(e,65056,65071)}function Bn(e){return e>65535?2:1}function Ko(e,t){for(;t<e.length;){let n=e.codePointAt(t);if(_o(n)||Go(n))t+=Bn(n);else break}return t}function la(e,t){let n=e.codePointAt(t),r=t+Bn(n);for(r=Ko(e,r);r<e.length-1&&e[r]==="\u200D";){let a=e.codePointAt(r+1);r+=1+Bn(a),r=Ko(e,r)}return Uo(n)&&r<e.length&&Uo(e.codePointAt(r))&&(r+=Bn(e.codePointAt(r))),r}function Ho(e){return vf(e)||_o(e)||Go(e)||Rf(e)}function zo(e){let t=0,n=0;for(;n<e.length;)n=la(e,n),t++;return t}function Mf(e,t){if(t===0)return!0;let n=0,r=0;for(;r<e.length;)if(r=la(e,r),n++,n>=t)return!0;return!1}function Sf(e,t){let n=0,r=0;for(;r<e.length;)if(r=la(e,r),n++,n>t)return!1;return!0}function Bo(e,t){if(t===0)return!0;let n=0;for(;n<e.length;){if(Ho(e.charCodeAt(n)))return Mf(e,t);if(n++,n>=t)return!0}return!1}function Wo(e,t){let n=0;for(;n<e.length;){if(Ho(e.charCodeAt(n)))return Sf(e,t);if(n++,n>t)return!1}return!0}function rn(e){return Array.isArray(e)}function nn(e){return M(typeof e,"bigint")}function Vo(e){return M(typeof e,"boolean")}function jf(e){if(da(e)||!Zo(e))return!1;let t=Function.prototype.toString.call(e);return!!(/^class\s/.test(t)||/\[native code\]/.test(t))}function Zo(e){return M(typeof e,"function")}function fa(e){return Number.isInteger(e)}function Vn(e){return M(e,null)}function Zn(e){return Number.isFinite(e)}function Af(e){return an(e)&&!rn(e)}function an(e){return M(typeof e,"object")&&!Vn(e)}function Jn(e){return M(typeof e,"string")}function Lf(e){return M(typeof e,"symbol")}function da(e){return M(e,void 0)}function M(e,t){return e===t}function qf(e,t){return e>t}function Ff(e,t){return e<t}function Jo(e,t){return e<=t}function Qo(e,t){return e>=t}function Df(e,t){if(nn(e)||nn(t))return BigInt(e)%BigInt(t)===0n;let n=1e-10;if(!Zn(e)||fa(e)&&1/t%1===0)return!0;let r=e%t;return Math.min(Math.abs(r),Math.abs(r-t),Math.abs(r+t))<n}function Nf(e){if(!an(e))return!1;let t=globalThis.Object.getPrototypeOf(e);return Vn(t)?!1:M(typeof t.constructor,"function")&&!(M(t.constructor,globalThis.Object)||M(t.constructor.name,"Object"))}function Uf(e){return nn(e)||Vo(e)||Vn(e)||Zn(e)||Jn(e)||da(e)}function Kf(e){return zo(e)}function Gf(e,t){return Wo(e,t)}function _f(e,t){return Bo(e,t)}function Hf(e,t,n){for(let r=t;r<e.length;r++)if(!n(e[r],r))return!1;return!0}function zf(e,t,n){let r=!0;for(let a=t;a<e.length;a++)n(e[a],a)||(r=!1);return r}function Qn(e,t,n){return M(e.length,0)?n():t(e[0],e.slice(1))}function Xo(e){return M(e,"__proto__")||M(e,"constructor")||M(e,"prototype")}function Bf(e,t){return Xo(t)?Object.prototype.hasOwnProperty.call(e,t):t in e}function Wf(e){return Wn(e).map(t=>[new RegExp(`^${t}$`),e[t]])}function Vf(e){return Object.entries(e)}function Wn(e){return Object.getOwnPropertyNames(e)}function Zf(e){return Object.getOwnPropertySymbols(e)}function Jf(e){return Object.values(e)}function Qf(e,t){if(!an(t))return!1;let n=Wn(e);return M(n.length,Wn(t).length)&&n.every(r=>xa(e[r],t[r]))}function Xf(e,t){return rn(t)&&M(e.length,t.length)&&e.every((n,r)=>xa(e[r],t[r]))}function xa(e,t){return rn(e)?Xf(e,t):an(e)?Qf(e,t):M(e,t)}var Xe={};lt(Xe,{IsBigInt64Array:()=>fd,IsBigUint64Array:()=>dd,IsBoolean:()=>ed,IsDate:()=>Id,IsFloat32Array:()=>cd,IsFloat64Array:()=>ld,IsInt16Array:()=>sd,IsInt32Array:()=>pd,IsInt8Array:()=>ad,IsMap:()=>gd,IsNumber:()=>td,IsRegExp:()=>xd,IsSet:()=>yd,IsString:()=>nd,IsTypeArray:()=>rd,IsUint16Array:()=>md,IsUint32Array:()=>ud,IsUint8Array:()=>od,IsUint8ClampedArray:()=>id});function ed(e){return e instanceof Boolean}function td(e){return e instanceof Number}function nd(e){return e instanceof String}function rd(e){return globalThis.ArrayBuffer.isView(e)}function ad(e){return e instanceof globalThis.Int8Array}function od(e){return e instanceof globalThis.Uint8Array}function id(e){return e instanceof globalThis.Uint8ClampedArray}function sd(e){return e instanceof globalThis.Int16Array}function md(e){return e instanceof globalThis.Uint16Array}function pd(e){return e instanceof globalThis.Int32Array}function ud(e){return e instanceof globalThis.Uint32Array}function cd(e){return e instanceof globalThis.Float32Array}function ld(e){return e instanceof globalThis.Float64Array}function fd(e){return e instanceof globalThis.BigInt64Array}function dd(e){return e instanceof globalThis.BigUint64Array}function xd(e){return e instanceof globalThis.RegExp}function Id(e){return e instanceof globalThis.Date}function yd(e){return e instanceof globalThis.Set}function gd(e){return e instanceof globalThis.Map}function hd(e){return i.HasPropertyKey(e,"~kind")||i.HasPropertyKey(e,"~unsafe")}function bd(e){let t={},n=Object.getOwnPropertyDescriptors(e);for(let r of Object.keys(n)){if(i.IsUnsafePropertyKey(r))continue;let a=n[r];i.HasPropertyKey(a,"value")&&Object.defineProperty(t,r,{...a,value:xt(a.value)})}return t}function Td(e){let t={};for(let n of i.Keys(e))i.IsUnsafePropertyKey(n)||(t[n]=xt(e[n]));for(let n of i.Symbols(e))t[n]=xt(e[n]);return t}function Ed(e){return i.IsClassInstance(e)?e:hd(e)?bd(e):Td(e)}function kd(e){return e.map(t=>xt(t))}function Pd(e){return e.slice()}function Od(e){return new RegExp(e.source,e.flags)}function Cd(e){return new Map(xt([...e.entries()]))}function Rd(e){return new Set(xt([...e.values()]))}function xt(e){return Xe.IsTypeArray(e)?Pd(e):Xe.IsRegExp(e)?Od(e):Xe.IsMap(e)?Cd(e):Xe.IsSet(e)?Rd(e):i.IsArray(e)?kd(e):i.IsObject(e)?Ed(e):e}function on(e){return ve.clone+=1,xt(e)}var It={};lt(It,{Get:()=>Sd,Reset:()=>vd,Set:()=>Md});var We={immutableTypes:!1,maxErrors:8,useAcceleration:!0,exactOptionalPropertyTypes:!1,enumerableKind:!1,correctiveParse:!1,unionPrioritySort:!0};function vd(){We.immutableTypes=!1,We.maxErrors=8,We.useAcceleration=!0,We.exactOptionalPropertyTypes=!1,We.enumerableKind=!1,We.correctiveParse=!1,We.unionPrioritySort=!0}function Md(e){for(let t of i.Keys(e)){let n=e[t];n!==void 0&&Object.defineProperty(We,t,{value:n})}}function Sd(){return We}function wd(e,t){for(let n of Object.keys(t))Object.defineProperty(e,n,{configurable:!0,writable:!0,enumerable:!1,value:t[n]});return e}function Yo(e,t){return{...e,...t}}function jd(e,t,n={}){ve.create+=1;let r=It.Get(),a=Yo(t,n),s=r.enumerableKind?Yo(a,e):wd(a,e);return r.immutableTypes?Object.freeze(s):s}function Ad(e,t){ve.discard+=1;let n={},r=Object.getOwnPropertyDescriptors(on(e)),a=new Set(t);for(let s of Object.keys(r))a.has(s)||Object.defineProperty(n,s,r[s]);return n}function Ld(e,t,n){ve.update+=1;let r=It.Get(),a=on(e);for(let s of Object.keys(t))Object.defineProperty(a,s,{configurable:!0,writable:!0,enumerable:r.enumerableKind,value:t[s]});for(let s of Object.keys(n))Object.defineProperty(a,s,{configurable:!0,enumerable:!0,writable:!0,value:n[s]});return a}function x(e,t){return i.IsObject(e)&&i.HasPropertyKey(e,"~kind")&&i.IsEqual(e["~kind"],t)}function Q(e){return i.IsObject(e)}function y(e,t,n){return p.Create({"~kind":"Deferred"},{type:"deferred",action:e,parameters:t,options:n},{})}function Ye(e){return x(e,"Deferred")}function qd(e){return p.Update(e,{"~readonly":!0},{})}function sn(e,t){return p.Update(qd(e),{},t)}function ei(e,t,n,r){let a=l(e,t,n);return sn(a,r)}function Fd(e){return p.Update(e,{"~optional":!0},{})}function mn(e,t){return p.Update(Fd(e),{},t)}function ti(e,t,n,r){let a=l(e,t,n);return mn(a,r)}function he(e,t){return p.Create({"~kind":"Array"},{type:"array",items:e},t)}function U(e){return x(e,"Array")}function Xn(e){return p.Discard(e,["~kind","type","items"])}function Ae(e,t,n={}){return p.Create({"~kind":"Constructor"},{type:"constructor",parameters:e,instanceType:t},n)}function ee(e){return x(e,"Constructor")}function ni(e){return p.Discard(e,["~kind","type","parameters","instanceType"])}function Le(e,t,n={}){return p.Create({"~kind":"Function"},{type:"function",parameters:e,returnType:t},n)}function te(e){return x(e,"Function")}function ri(e){return p.Discard(e,["~kind","type","parameters","returnType"])}function Ve(e,t){return p.Create({"~kind":"Ref"},{$ref:e},t)}function ne(e){return x(e,"Ref")}function et(e,t){return p.Create({"~kind":"Generic"},{type:"generic",parameters:e,expression:t})}function wt(e){return x(e,"Generic")}function jt(e){return p.Create({"~kind":"Any"},{},e)}function W(e){return x(e,"Any")}var ai="(?!)";function L(e){return p.Create({"~kind":"Never"},{not:{}},e)}function tt(e){return x(e,"Never")}function qe(e,t={}){return y("AddOptional",[e],t)}function yt(e,t={}){return mn(e,t)}function oi(e){return yt(e)}function me(e){return Q(e)&&i.HasPropertyKey(e,"~optional")}function ii(e){return i.Keys(e).filter(t=>!me(e[t]))}function Yn(e){return i.Keys(e)}function er(e){return i.Values(e)}function h(e,t={}){let n=ii(e),r=n.length>0?{required:n}:{};return p.Create({"~kind":"Object"},{type:"object",...r,properties:e},t)}function S(e){return x(e,"Object")}function si(e){return p.Discard(e,["~kind","type","properties","required"])}function re(e){return p.Create({"~kind":"Unknown"},{},e)}function X(e){return x(e,"Unknown")}function Fe(e,t,n){let r=i.Keys(e).reduce((a,s)=>({...a,[s]:p.Update(e[s],{},{$id:s})}),{});return p.Create({"~kind":"Cyclic"},{$defs:r,$ref:t},n)}function oe(e){return x(e,"Cyclic")}function mi(e){return p.Update(e,{"~unsafe":null},{})}function tr(e){return i.IsObjectNotArray(e)&&i.HasPropertyKey(e,"~unsafe")&&i.IsNull(e["~unsafe"])}var De={};lt(De,{Match:()=>Dd});function Dd(e,t){return t[e.length]?.(...e)??(()=>{throw Error("Invalid Arguments")})()}function pn(...e){let[t,n]=De.Match(e,{2:(r,a)=>[r,a,a],1:r=>[r,re(),re()]});return p.Create({"~kind":"Infer"},{type:"infer",name:t,extends:n},{})}function z(e){return x(e,"Infer")}function gt(e,t,n,r={}){return p.Create({"~kind":"Dependent"},{if:e,then:t,else:n},r)}function _(e){return x(e,"Dependent")}function pi(e){return p.Discard(e,["~kind","if","then","else"])}function ui(e){return i.IsObjectNotArray(e)}function ci(e){return i.Keys(e).filter(n=>isNaN(n)).reduce((n,r)=>[...n,e[r]],[])}function li(e){return i.IsString(e)||i.IsNumber(e)}function fi(e,t){let n=ui(e)?ci(e):e;return p.Create({"~kind":"Enum"},{enum:n},t)}function ue(e){return x(e,"Enum")}function pe(e,t={}){return p.Create({"~kind":"Intersect"},{allOf:e},t)}function C(e){return x(e,"Intersect")}function di(e){return p.Discard(e,["~kind","allOf"])}function B(){throw new Error("Unreachable")}var xi;(function(e){e[e.Array=0]="Array",e[e.BigInt=1]="BigInt",e[e.Boolean=2]="Boolean",e[e.Date=3]="Date",e[e.Constructor=4]="Constructor",e[e.Function=5]="Function",e[e.Null=6]="Null",e[e.Number=7]="Number",e[e.Object=8]="Object",e[e.RegExp=9]="RegExp",e[e.String=10]="String",e[e.Symbol=11]="Symbol",e[e.TypeArray=12]="TypeArray",e[e.Undefined=13]="Undefined"})(xi||(xi={}));var dT=BigInt("14695981039346656037"),[xT,IT]=[BigInt("1099511628211"),BigInt("18446744073709551616")],yT=Array.from({length:256}).map((e,t)=>BigInt(t)),Ii=new Float64Array(1),gT=new DataView(Ii.buffer),$T=new Uint8Array(Ii.buffer);var hT=new TextEncoder;var un=class{constructor(t,n){this.type=t,this.decode=n}Encode(t){let n=this.type,r=nr(n)?m=>this.decode(n["~codec"].decode(m)):this.decode,a=nr(n)?m=>n["~codec"].encode(t(m)):t,s={decode:r,encode:a};return p.Update(this.type,{"~codec":s},{})}},cn=class{constructor(t){this.type=t}Decode(t){return new un(this.type,t)}};function rr(e){return new cn(e)}function gi(e,t){return rr(e).Decode(t).Encode(()=>{throw Error("Encode not implemented")})}function $i(e,t){return rr(e).Decode(()=>{throw Error("Decode not implemented")}).Encode(t)}function nr(e){return Q(e)&&i.HasPropertyKey(e,"~codec")&&i.IsObject(e["~codec"])&&i.HasPropertyKey(e["~codec"],"encode")&&i.HasPropertyKey(e["~codec"],"decode")}function hi(e){return At(e)}function $t(e){return Q(e)&&i.HasPropertyKey(e,"~immutable")}function Ne(e,t={}){return y("AddReadonly",[e],t)}function ht(e,t={}){return sn(e,t)}function bi(e){return ht(e)}function bt(e){return Q(e)&&i.HasPropertyKey(e,"~readonly")}function Gd(e,t){let n=Ia(e)?[...e["~refine"],t]:[t];return p.Update(e,{"~refine":n},{})}function Ti(...e){let[t,n,r]=De.Match(e,{3:(a,s,m)=>[a,s,m],2:(a,s)=>[a,s,()=>"Refine Error"]});return Gd(t,{check:n,error:r})}function _d(e){return i.IsObjectNotArray(e)&&i.HasPropertyKey(e,"check")&&i.HasPropertyKey(e,"error")&&i.IsFunction(e.check)&&i.IsFunction(e.error)}function Ia(e){return Q(e)&&i.HasPropertyKey(e,"~refine")&&i.IsArray(e["~refine"])&&i.Every(e["~refine"],0,t=>_d(t))}var Ei="-?(?:0|[1-9][0-9]*)n";function ln(e){return p.Create({"~kind":"BigInt"},{type:"bigint"},e)}function Ue(e){return x(e,"BigInt")}function ar(e){return p.Create({"~kind":"Boolean"},{type:"boolean"},e)}function ke(e){return x(e,"Boolean")}function fn(e){return p.Create({"~kind":"Identifier"},{name:e})}function ki(e){return x(e,"Identifier")}var or="-?(?:0|[1-9][0-9]*)";function Tt(e){return p.Create({"~kind":"Integer"},{type:"integer"},e)}function ce(e){return x(e,"Integer")}var ya=class extends Error{constructor(t){super("Invalid Literal value"),Object.defineProperty(this,"cause",{value:{value:t},writable:!1,configurable:!1,enumerable:!1})}};function Hd(e){return i.IsBigInt(e)?"bigint":i.IsBoolean(e)?"boolean":i.IsNumber(e)?"number":i.IsString(e)?"string":(()=>{throw new ya(e)})()}function R(e,t){return p.Create({"~kind":"Literal"},{type:Hd(e),const:e},t)}function ir(e){return i.IsBigInt(e)||i.IsBoolean(e)||i.IsNumber(e)||i.IsString(e)}function Pi(e){return w(e)&&i.IsNumber(e.const)}function Oi(e){return w(e)&&i.IsString(e.const)}function w(e){return x(e,"Literal")}function Lt(e){return p.Create({"~kind":"Null"},{type:"null"},e)}function qt(e){return x(e,"Null")}var sr="-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?";function ye(e){return p.Create({"~kind":"Number"},{type:"number"},e)}function V(e){return x(e,"Number")}function Ft(e){return p.Create({"~kind":"Symbol"},{type:"symbol"},e)}function nt(e){return x(e,"Symbol")}function Et(...e){let[t,n,r]=De.Match(e,{3:(a,s,m)=>[a,s,m],2:(a,s)=>[a,s,s],1:a=>[a,re(),re()]});return p.Create({"~kind":"Parameter"},{name:t,extends:n,equals:r},{})}function Ci(e){return x(e,"Parameter")}var mr=".*";function Pe(e){return p.Create({"~kind":"String"},{type:"string"},e)}function le(e){return x(e,"String")}function k(e,t={}){return p.Create({"~kind":"Union"},{anyOf:e},t)}function I(e){return x(e,"Union")}function Ri(e){return p.Discard(e,["~kind","anyOf"])}function dn(e){let t=vi(e);return i.IsEqual(t.length,2)?t[0]:[]}function zd(e){return!0}function Mi(e){return i.ShiftLeft(e,(t,n)=>Bd(t)?Mi(n):!1,()=>!0)}function Si(e){return i.IsEqual(e.length,0)?!1:Mi(e)}function Bd(e){return I(e)?Si(e.anyOf):w(e)?zd(e.const):!1}function pr(e){return Si(e)}function ur(e){return p.Create({"~kind":"TemplateLiteral"},{type:"string",pattern:e},{})}function wi(e,t,n=[]){return i.ShiftLeft(e,(r,a)=>wi(a,t,[...n,`${r}${t}`]),()=>n)}function Wd(e,t){return i.IsEqual(e.length,0)?[`${t}`]:wi(e,t)}function ji(e,t,n=[]){return i.ShiftLeft(t,(r,a)=>ji(e,a,[...n,...Ai(e,r)]),()=>n)}function Ai(e,t){return I(t)?ji(e,t.anyOf):w(t)?Wd(e,t.const):B()}function Li(e,t){return i.ShiftLeft(t,(n,r)=>Li(Ai(e,n),r),()=>e)}function Vd(e){return e.map(t=>R(t))}function Zd(e){let t=Li([],e),n=Vd(t);return k(n)}function Jd(e){return i.IsEqual(e.length,0)?B():i.IsEqual(e.length,1)&&w(e[0])?e[0]:Zd(e)}function ga(e){let t=dn(e);return i.IsEqual(t.length,0)?Pe():pr(t)?Jd(t):ur(e)}function qi(e){let t=ga(e);return Z(t)?Pe():t}function xe(e,t){let n="object",r={[e]:t};return p.Create({"~kind":"Record"},{type:n,patternProperties:r})}function Fi(e){return xe(Me,e)}function Di(e){return h({true:e,false:e})}function J(e,t={}){let[n,r,a]=[e,e.length,!1];return p.Create({"~kind":"Tuple"},{type:"array",additionalItems:a,items:n,minItems:r},t)}function F(e){return x(e,"Tuple")}function Ni(e){return p.Discard(e,["~kind","type","items","minItems","additionalItems"])}function Qd(e){return p.Discard(e,["~readonly"])}function $a(e,t){return p.Update(Qd(e),{},t)}function Ui(e,t,n,r){let a=l(e,t,n);return $a(a,r)}function Ki(e,t={}){return y("RemoveReadonly",[e],t)}function Gi(e,t={}){return $a(e,t)}function Xd(e){return p.Discard(e,["~optional"])}function ha(e,t){return p.Update(Xd(e),{},t)}function _i(e,t,n,r){let a=l(e,t,n);return ha(a,r)}function Hi(e,t={}){return y("RemoveOptional",[e],t)}function cr(e,t={}){return ha(e,t)}function ba(e){return e.reduceRight((n,r,a)=>({[a]:r,...n}),{})}function zi(e){let t=ba(e.items);return h(t)}function Yd(e,t){return bt(e)?!!bt(t):!1}function ex(e,t){return me(e)?!!me(t):!1}function tx(e,t){let n=Yd(e,t),r=ex(e,t),a=K([e,t]),s=Gi(cr(a));return n&&r?ht(yt(s)):n&&!r?ht(s):!n&&r?yt(s):s}function nx(e,t,n){return n in e?n in t?tx(e[n],t[n]):e[n]:n in t?t[n]:L()}function rx(e,t){return[...new Set([...i.Keys(t),...i.Keys(e)])].reduce((r,a)=>({...r,[a]:nx(e,t,a)}),{})}function Bi(e){return S(e)?e.properties:F(e)?ba(e.items):B()}function Wi(e,t){let n=Bi(e),r=Bi(t),a=rx(n,r);return h(a)}function Vi(e,t){let n=Dt(e,t);return i.IsEqual(n,In)?e:i.IsEqual(n,yn)||i.IsEqual(n,xn)?t:L()}function Zi(e){return S(e)||F(e)}function ax(e,t){let n=I(e),r=I(t);return n||r}function ox(e,t){let n=Oe(e),r=Oe(t),a=ax(n,r),s=Zi(n),m=Zi(r);return a?K([n,r]):s&&m?Wi(n,r):s&&!m?n:!s&&m?r:Vi(n,r)}function Ji(e,t,n=[]){return i.ShiftLeft(t,(r,a)=>Ji(e,a,[...n,ox(e,r)]),()=>i.IsEqual(n.length,0)?[e]:n)}function Qi(e,t,n=[]){return i.ShiftLeft(e,(r,a)=>Qi(a,t,[...n,...gn([r],t)]),()=>n)}function gn(e,t=[]){return i.ShiftLeft(e,(n,r)=>I(n)?gn(r,Qi(n.anyOf,t)):gn(r,Ji(n,t)),()=>t)}function ix(e,t){let n=ie({},e,t);return $.IsExtendsTrueLike(n)?[]:[e]}function sx(e,t){return e.reduce((n,r)=>[...n,...ix(r,t)],[])}function lr(e,t){let n=Oe(e),r=I(n)?n.anyOf:[n],a=sx(r,t);return ge(a)}function Se(e,t,n){let r=pe([e,t]),a=lr(n,e);return ge([r,a])}function be(e){let t=e.map(n=>R(n));return ge(t)}function K(e){let t=gn(e),n=Ta(t);return Ze(n)}function Ie(e){let t=qi(e);return Oe(t)}function ge(e){let t=Ta(e);return Ze(t)}function Oe(e){return _(e)?Se(e.if,e.then,e.else):ue(e)?be(e.enum):C(e)?K(e.allOf):Z(e)?Ie(e.pattern):I(e)?ge(e.anyOf):e}function Ze(e){return i.IsEqual(e.length,1)?e[0]:i.IsEqual(e.length,0)?L():k(e)}function Xi(e,t){let n=be(e);return rt(n,t)}function Yi(e,t){return xe(at,t)}function es(e,t){let n=K(e);return rt(n,t)}function ts(e,t){return i.IsString(e)||i.IsNumber(e)?h({[e]:t}):i.IsEqual(e,!1)?h({false:t}):i.IsEqual(e,!0)?h({true:t}):h({})}function ns(e,t){return xe(Nt,t)}function rs(e,t){return i.HasPropertyKey(e,"pattern")&&(i.IsString(e.pattern)||e.pattern instanceof RegExp)?xe(e.pattern.toString(),t):xe(Me,t)}function as(e,t){let n=dn(e);return pr(n)?rt(Ie(e),t):xe(e,t)}function mx(e){return I(e)?$n(e.anyOf):[e]}function $n(e){return e.reduce((t,n)=>[...t,...mx(n)],[])}function px(e){return e.some(t=>le(t)||V(t)||ce(t))}function ux(e,t){return i.IsEqual(px(e),!0)?xe(Me,t):void 0}function cx(e,t){return e.reduce((n,r)=>w(r)&&(i.IsString(r.const)||i.IsNumber(r.const))?{...n,[r.const]:t}:n,{})}function lx(e,t){let n=cx(e,t);return h(n)}function os(e,t){let n=$n(e),r=ux(n,t);return Q(r)?r:lx(n,t)}function rt(e,t){return W(e)?Fi(t):ke(e)?Di(t):ue(e)?Xi(e.enum,t):ce(e)?Yi(e,t):C(e)?es(e.allOf,t):w(e)?ts(e.const,t):V(e)?ns(e,t):I(e)?os(e.anyOf,t):le(e)?rs(e,t):Z(e)?as(e.pattern,t):h({})}function Ea(e,t,n){return T([e])?p.Update(rt(e,t),{},n):fr(e,t,n)}function is(e,t,n,r,a){let s=l(e,t,n),m=l(e,t,r);return Ea(s,m,a)}var at=`^${or}$`,Nt=`^${sr}$`,Me=`^${mr}$`;function fr(e,t,n={}){return y("Record",[e,t],n)}function dr(e,t,n={}){return Ea(e,t,n)}function ss(e,t){return xe(e,t)}function xr(e){return i.IsEqual(e,Me)?Pe():i.IsEqual(e,at)?Tt():i.IsEqual(e,Nt)?ye():ga(e)}function Ce(e){return i.Keys(e.patternProperties)[0]}function Ut(e){let t=Ce(e);return xr(t)}function fe(e){return e.patternProperties[Ce(e)]}function se(e){return x(e,"Record")}function kt(e){return p.Create({"~kind":"Rest"},{type:"rest",items:e},{})}function ot(e){return x(e,"Rest")}function Ir(e){return p.Create({"~kind":"This"},{$ref:"#"},e)}function yr(e){return x(e,"This")}function Kt(e){return p.Create({"~kind":"Undefined"},{type:"undefined"},e)}function Gt(e){return x(e,"Undefined")}function gr(e){return p.Create({"~kind":"Void"},{type:"void"},e)}function Ke(e){return x(e,"Void")}function dx(e,t){return i.IsEqual(e,"Array")?he(t[0]):i.IsEqual(e,"Capitalize")?hr(t[0]):i.IsEqual(e,"ConstructorParameters")?Pr(t[0]):i.IsEqual(e,"Evaluate")?pp(t[0]):i.IsEqual(e,"Exclude")?Or(t[0],t[1]):i.IsEqual(e,"Extract")?Cr(t[0],t[1]):i.IsEqual(e,"Index")?En(t[0],t[1]):i.IsEqual(e,"InstanceType")?Rr(t[0]):i.IsEqual(e,"Lowercase")?br(t[0]):i.IsEqual(e,"NonNullable")?vr(t[0]):i.IsEqual(e,"Omit")?Mr(t[0],t[1]):i.IsEqual(e,"Parameters")?Sr(t[0]):i.IsEqual(e,"Partial")?wr(t[0]):i.IsEqual(e,"Pick")?jr(t[0],t[1]):i.IsEqual(e,"Readonly")?Ar(t[0]):i.IsEqual(e,"KeyOf")?kn(t[0]):i.IsEqual(e,"Record")?fr(t[0],t[1]):i.IsEqual(e,"Required")?Lr(t[0]):i.IsEqual(e,"ReturnType")?qr(t[0]):i.IsEqual(e,"Uncapitalize")?Tr(t[0]):i.IsEqual(e,"Uppercase")?Er(t[0]):Tn(Ve(e),t)}function Pt(){throw Error("Unreachable")}var xx=(e,t=[])=>e.reduce((n,r)=>i.IsArray(r)&&i.IsEqual(r.length,2)?[...n,r[0]]:[...n,r],[]),Je=e=>{let[t,n]=e;return xx([...t,...n])};function ls(e){return Et(e[0],e[2],e[4])}function fs(e){return Et(e[0],e[2],e[2])}function ds(e){return Et(e[0],re(),e[2])}function xs(e){return Et(e,re(),re())}function Is(e){return Je(e)}function ys(e){return e[1]}function gs(e){return Je(e)}function $s(e){return e[1]}function hs(e){return dx(e[0],e[1])}function bs(e){return null}function Ts(e){return Pe()}function Es(e){return ye()}function ks(e){return ar()}function Ps(e){return Kt()}function Os(e){return Lt()}function Cs(e){return Tt()}function Rs(e){return ln()}function vs(e){return re()}function Ms(e){return jt()}function Ss(e){return h({})}function ws(e){return L()}function js(e){return Ft()}function As(e){return gr()}function Ls(e){return Ir()}function qs(e){return R(BigInt(e))}function Fs(e){return R(i.IsEqual(e,"true"))}function Ds(e){return R(parseFloat(e))}function Ns(e){return R(e)}function Us(e){return e[1]}function Ks(e){return R(e)}function Gs(e){return i.IsEqual(e.length,3)?[e[0],e[1],...e[2]]:[e[0]]}function _s(e){return e[1]}function Hs(e){return $r(e)}function zs(e){return i.IsEqual(e.length,6)?gt(e[1],e[3],e[5]):gt(e[1],e[3],re())}function Bs(e){return e.length>0}function Ws(e){return e.reduce((t,n)=>i.IsEqual(n.length,3)?[...t,[n[1]]]:[...t,[]],[])}function Vs(e){return i.IsEqual(e.length,6)?[e[1],e[3],e[5]]:[]}function Zs(e){return i.IsArray(e)&&i.IsEqual(e.length,3)?e[1]:e}function Js(e){return i.IsEqual(e.length,2)?e[1]:[]}function ms(e,t){return t.reduce((n,r)=>{let a=r;return i.IsEqual(a.length,1)?En(n,a[0]):i.IsEqual(a.length,0)?he(n):Pt()},e)}function ps(e,t){return i.IsEqual(t.length,3)?kr(e,t[0],t[1],t[2]):e}function Ix(e,t){return i.IsArray(t)&&i.IsEqual(t.length,0)?e:Fr(e,t)}function Qs(e){let[t,n,r,a,s]=e;return Ix(ps(t?kn(ms(n,r)):ms(n,r),a),s)}function ka(e,t){return i.IsEqual(t.length,3)?(()=>{let[n,r,a]=t,s=ka(r,a);if(i.IsEqual(n,"&"))return C(s)?pe([e,...s.allOf]):pe([e,s]);if(i.IsEqual(n,"|"))return I(s)?k([e,...s.anyOf]):k([e,s]);Pt()})():e}function Xs(e){let[t,n]=e;return ka(t,n)}function Ys(e){let[t,n]=e;return ka(t,n)}function em(e){return mp(e[1])}function tm(e){return e[1]}function nm(e){return et(e[0],e[2])}function rm(e){return i.IsEqual(e.length,4)?pn(e[1],e[3]):i.IsEqual(e.length,2)?pn(e[1],re()):Pt()}function am(e){return`${e}`}function om(e){return ce(e[3])?at:V(e[3])?Nt:nt(e[3])?Me:le(e[3])?Me:Pt()}function im(e){return e.length>0}function sm(e){return e.length>0}function mm(e){let[t,n,r,a,s]=e;return{[n]:t&&r?Ne(qe(s)):t&&!r?Ne(s):!t&&r?qe(s):s}}function pm(e){return Je(e)}function um(e){return e.reduce((t,n)=>i.HasPropertyKey(n,at)||i.HasPropertyKey(n,Nt)||i.HasPropertyKey(n,Me)?[t[0],p.Assign(t[1],n)]:[p.Assign(t[0],n),t[1]],[{},{}])}function cm(e){return um(e[1])}function lm(e){let[t,n]=e,r=i.IsEqual(i.Keys(n).length,0)?{}:{patternProperties:n};return h(t,r)}function fm(e){return i.IsEqual(e.length,5)?Ne(qe(e[4])):i.IsEqual(e.length,3)?e[2]:i.IsEqual(e.length,4)?i.IsEqual(e[2],"readonly")?Ne(e[3]):qe(e[3]):Pt()}function dm(e){return Ne(qe(e[1]))}function xm(e){return Ne(e[1])}function Im(e){return qe(e[0])}function ym(e){return i.IsEqual(e.length,2)?kt(e[1]):i.IsEqual(e.length,1)?e[0]:Pt()}function gm(e){return Je(e)}function $m(e){return J(e[1])}function hm(e){return Ne(qe(e[4]))}function bm(e){return Ne(e[3])}function Tm(e){return qe(e[3])}function Em(e){return e[2]}function km(e){return i.IsEqual(e.length,2)?kt(e[1]):i.IsEqual(e.length,1)?e[0]:Pt()}function Pm(e){return Je(e)}function Om(e){return Le(e[1],e[4])}function Cm(e){return Ae(e[2],e[5])}function us(e,t){return i.IsEqual(e,"remove")?Ki(t):i.IsEqual(e,"add")?Ne(t):t}function Rm(e){return i.IsEqual(e.length,2)&&i.IsEqual(e[0],"-")?"remove":i.IsEqual(e.length,2)&&i.IsEqual(e[0],"+")||i.IsEqual(e.length,1)?"add":"none"}function cs(e,t){return i.IsEqual(e,"remove")?Hi(t):i.IsEqual(e,"add")?qe(t):t}function vm(e){return i.IsEqual(e.length,2)&&i.IsEqual(e[0],"-")?"remove":i.IsEqual(e.length,2)&&i.IsEqual(e[0],"+")||i.IsEqual(e.length,1)?"add":"none"}function Mm(e){return i.IsEqual(e.length,2)?[e[1]]:[]}function Sm(e){return i.IsArray(e[6])&&i.IsEqual(e[6].length,1)?hn(fn(e[3]),e[5],e[6][0],us(e[1],cs(e[8],e[10]))):hn(fn(e[3]),e[5],Ve(e[3]),us(e[1],cs(e[8],e[10])))}function wm(e){return Ve(e)}function jm(e){return BigInt(e)}function Am(e){return parseFloat(e)}function Lm(e){return i.IsEqual(e,"true")}function qm(e){return null}function Fm(e){return{[e[0]]:e[2]}}function Dm(e){return Je(e)}function yx(e){return e.reduce((t,n)=>p.Assign(t,n),{})}function Nm(e){return yx(e[1])}function Um(e){return Je(e)}function Km(e){return e[1]}function Gm(e){return ln()}function _m(e){return Pe()}function Hm(e){return ye()}function zm(e){return Tt()}function Bm(e){return L()}function Wm(e){return R(e)}function Vm(e){return k(e[1])}function Zm(e){return e.length===3?[...e[0],...e[2]]:e.length===1?[...e[0]]:[]}function Jm(e){return[e[0],...e[1]]}function Qm(e){return e[1]}function Xm(e){return Je(e)}function Ym(e){return i.IsEqual(e.length,2)?e[1]:[]}function ep(e){let t=e[2],n=e[3],[r,a]=e[4],s=i.IsEqual(i.Keys(a).length,0)?{}:{patternProperties:a};return{[e[1]]:et(t,bn(n,r,s))}}function tp(e){let t=e[2],[n,r]=e[3],a=i.IsEqual(i.Keys(r).length,0)?{}:{patternProperties:r};return{[e[1]]:bn(t,n,a)}}function np(e){return{[e[1]]:et(e[2],e[4])}}function rp(e){return{[e[1]]:e[3]}}function ap(e){return null}function op(e){return um(Je(e))}function ip(e){return e[1]}function sp(e){let t=e[0],n=e[1];return up(p.Assign(t,n[0]))}function Pn(e){return M(e.length,2)}function P(e,t,n){return Pn(e)?t(e[0],e[1]):n()}function hx(e,t){return M(t.indexOf(e),0)?[e,t.slice(e.length)]:[]}function G(e,t){for(let n=0;n<e.length;n++){let r=hx(e[n],t);if(Pn(r))return r}return[]}function Pa(e,t){return Array.from({length:t-e+1},(n,r)=>String.fromCharCode(e+r))}var cp=[...Pa(97,122),...Pa(65,90)],Oa="0",Ca=Pa(49,57),_t=[Oa,...Ca],lp=" ",Ht=`
2
+ `;var it="_",Dr=".",fp="$",Nr="-";var dp="//",xp="/*",Tx="*/";function Ip(e){let t=e.indexOf(Tx);return M(t,-1)?"":e.slice(t+2)}function yp(e){let t=e.indexOf(Ht);return M(t,-1)?"":e.slice(t)}function Ex(e){return e.replace(/^[ \t\r\f\v]+/,"")}function Ur(e){let t=Ex(e);return t.startsWith(xp)?Ur(Ip(t.slice(2))):t.startsWith(dp)?Ur(yp(t.slice(2))):t}function ae(e){let t=e.trimStart();return t.startsWith(xp)?ae(Ip(t.slice(2))):t.startsWith(dp)?ae(yp(t.slice(2))):t}function Kr(e,t){return P(G([e],t),(n,r)=>[n,r],()=>["",t])}function kx(e,t){return e.includes(t)}function zt(e,t,n,r=""){return P(G(e,n),(a,s)=>kx(t,a)?zt(e,t,s,r):zt(e,t,s,`${r}${a}`),()=>[r,n])}function Px(e){return G(Ca,e)}var Ox=[..._t,it];function Cx(e){return zt(Ox,[it],e)}function Rx(e){return P(G([Oa],e),(t,n)=>[t,n],()=>P(Px(e),(t,n)=>P(Cx(n),(r,a)=>[`${t}${r}`,a],()=>[]),()=>[]))}function Gr(e){return Rx(ae(e))}function vx(e){return Kr(Nr,e)}function Mx(e){return P(vx(e),(t,n)=>P(Gr(n),(r,a)=>[`${t}${r}`,a],()=>[]),()=>[])}function gp(e){return Mx(ae(e))}function Sx(e){return P(gp(e),(t,n)=>P(G(["n"],n),(r,a)=>[`${t}`,a],()=>[]),()=>[])}function Ra(e){return Sx(e)}function va(e,t){return G([e],t)}function u(e,t){return M(e,"")?["",t]:e.startsWith(Ht)?va(e,Ur(t)):e.startsWith(lp)?va(e,t):va(e,ae(t))}var $p=[...cp,it,fp];function wx(e){return G($p,e)}var jx=[...$p,..._t];function hp(e,t=""){return P(G(jx,e),(n,r)=>hp(r,`${t}${n}`),()=>[t,e])}function Ax(e){return P(wx(e),(t,n)=>P(hp(n),(r,a)=>[`${t}${r}`,a],()=>[]),()=>[])}function H(e){return Ax(ae(e))}var Lx=[..._t,it];function qx(e){return Pn(G([Dr],e))}function bp(e){return P(zt(Lx,[it],e),(t,n)=>M(t,"")?[]:[t,n],()=>[])}function Fx(e){return P(G([Dr],e),(t,n)=>P(bp(n),(r,a)=>[`0${t}${r}`,a],()=>[]),()=>[])}function Dx(e){return P(Gr(e),(t,n)=>P(G([Dr],n),(r,a)=>P(bp(a),(s,m)=>[`${t}${r}${s}`,m],()=>[`${t}`,a]),()=>[`${t}`,n]),()=>[])}function Nx(e){return qx(e)?Fx(e):Dx(e)}function Tp(e){return Nx(ae(e))}function Ux(e){return Kr(Nr,e)}function Kx(e){return P(Ux(e),(t,n)=>P(Tp(n),(r,a)=>[`${t}${r}`,a],()=>[]),()=>[])}function _r(e){return Kx(ae(e))}function Gx(e){return M(e,"")?[]:[e.slice(0,1),e.slice(1)]}function Ep(e,t){return Qn(e,(n,r)=>t.startsWith(n)?!0:Ep(r,t),()=>!1)}function st(e,t,n=""){return P(Gx(t),(r,a)=>Ep(e,t)?[n,t]:st(e,a,`${n}${r}`),()=>[])}function _x(e,t,n){return P(G([e],n),(r,a)=>P(st([t],a),(s,m)=>P(G([t],m),(c,f)=>[`${s}`,f],()=>[]),()=>[]),()=>[])}function Hx(e,t,n){return P(G([e],n),(r,a)=>P(st([Ht,t],a),(s,m)=>P(G([t],m),(c,f)=>[`${s}`,f],()=>[]),()=>[]),()=>[])}function kp(e,t,n,r){return n?_x(e,t,ae(r)):Hx(e,t,ae(r))}function zx(e,t){return G(e,t)}function Bx(e,t){return kp(e,e,!1,t)}function Wx(e,t){return P(zx(e,t),(n,r)=>Bx(n,`${n}${r}`),()=>[])}function Hr(e,t){return Wx(e,ae(t))}function Pp(e,t){return P(st(e,t),(n,r)=>M(n,"")?[]:[n,r],()=>[])}var o=(e,t,n=()=>[])=>e.length===2?t(e):n(),Zx=e=>o(o(H(e),([t,n])=>o(u("extends",n),([r,a])=>o(O(a),([s,m])=>o(u("=",m),([c,f])=>o(O(f),([E,g])=>[[t,r,s,c,E],g]))))),([t,n])=>[ls(t),n]),Jx=e=>o(o(H(e),([t,n])=>o(u("extends",n),([r,a])=>o(O(a),([s,m])=>[[t,r,s],m]))),([t,n])=>[fs(t),n]),Qx=e=>o(o(H(e),([t,n])=>o(u("=",n),([r,a])=>o(O(a),([s,m])=>[[t,r,s],m]))),([t,n])=>[ds(t),n]),Xx=e=>o(H(e),([t,n])=>[xs(t),n]),Rp=e=>o(o(Zx(e),([t,n])=>[t,n],()=>o(Jx(e),([t,n])=>[t,n],()=>o(Qx(e),([t,n])=>[t,n],()=>o(Xx(e),([t,n])=>[t,n],()=>[])))),([t,n])=>[t,n]),vp=(e,t=[])=>o(o(Rp(e),([n,r])=>o(u(",",r),([a,s])=>[[n,a],s])),([n,r])=>vp(r,[...t,n]),()=>[t,e]),Yx=e=>o(o(vp(e),([t,n])=>o(o(o(Rp(n),([r,a])=>[[r],a]),([r,a])=>[r,a],()=>o([[],n],([r,a])=>[r,a],()=>[])),([r,a])=>[[t,r],a])),([t,n])=>[Is(t),n]),wa=e=>o(o(u("<",e),([t,n])=>o(Yx(n),([r,a])=>o(u(">",a),([s,m])=>[[t,r,s],m]))),([t,n])=>[ys(t),n]),Mp=(e,t=[])=>o(o(O(e),([n,r])=>o(u(",",r),([a,s])=>[[n,a],s])),([n,r])=>Mp(r,[...t,n]),()=>[t,e]),eI=e=>o(o(Mp(e),([t,n])=>o(o(o(O(n),([r,a])=>[[r],a]),([r,a])=>[r,a],()=>o([[],n],([r,a])=>[r,a],()=>[])),([r,a])=>[[t,r],a])),([t,n])=>[gs(t),n]),tI=e=>o(o(u("<",e),([t,n])=>o(eI(n),([r,a])=>o(u(">",a),([s,m])=>[[t,r,s],m]))),([t,n])=>[$s(t),n]),nI=e=>o(o(H(e),([t,n])=>o(tI(n),([r,a])=>[[t,r],a])),([t,n])=>[hs(t),n]),Sp=e=>o(o(o(u(";",e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>o([[],e],([t,n])=>[t,n],()=>[])),([t,n])=>[bs(t),n]),wp=e=>o(u("string",e),([t,n])=>[Ts(t),n]),jp=e=>o(u("number",e),([t,n])=>[Es(t),n]),rI=e=>o(u("boolean",e),([t,n])=>[ks(t),n]),aI=e=>o(u("undefined",e),([t,n])=>[Ps(t),n]),oI=e=>o(u("null",e),([t,n])=>[Os(t),n]),Ap=e=>o(u("integer",e),([t,n])=>[Cs(t),n]),iI=e=>o(u("bigint",e),([t,n])=>[Rs(t),n]),sI=e=>o(u("unknown",e),([t,n])=>[vs(t),n]),mI=e=>o(u("any",e),([t,n])=>[Ms(t),n]),pI=e=>o(u("object",e),([t,n])=>[Ss(t),n]),uI=e=>o(u("never",e),([t,n])=>[ws(t),n]),Lp=e=>o(u("symbol",e),([t,n])=>[js(t),n]),cI=e=>o(u("void",e),([t,n])=>[As(t),n]),lI=e=>o(u("this",e),([t,n])=>[Ls(t),n]),fI=e=>o(o(u("${",e),([t,n])=>o(O(n),([r,a])=>o(u("}",a),([s,m])=>[[t,r,s],m]))),([t,n])=>[Us(t),n]),Ma=e=>o(st(["${","`"],e),([t,n])=>[Ks(t),n]),qp=e=>o(o(o(Ma(e),([t,n])=>o(fI(n),([r,a])=>o(qp(a),([s,m])=>[[t,r,s],m]))),([t,n])=>[t,n],()=>o(o(Ma(e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>o(o(Ma(e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>[]))),([t,n])=>[Gs(t),n]),ja=e=>o(o(u("`",e),([t,n])=>o(qp(n),([r,a])=>o(u("`",a),([s,m])=>[[t,r,s],m]))),([t,n])=>[_s(t),n]),dI=e=>o(ja(e),([t,n])=>[Hs(t),n]),xI=e=>o(o(o(u("if",e),([t,n])=>o(O(n),([r,a])=>o(u("then",a),([s,m])=>o(O(m),([c,f])=>o(u("else",f),([E,g])=>o(O(g),([q,Y])=>[[t,r,s,c,E,q],Y])))))),([t,n])=>[t,n],()=>o(o(u("if",e),([t,n])=>o(O(n),([r,a])=>o(u("then",a),([s,m])=>o(O(m),([c,f])=>[[t,r,s,c],f])))),([t,n])=>[t,n],()=>[])),([t,n])=>[zs(t),n]),II=e=>o(Ra(e),([t,n])=>[qs(t),n]),yI=e=>o(o(u("true",e),([t,n])=>[t,n],()=>o(u("false",e),([t,n])=>[t,n],()=>[])),([t,n])=>[Fs(t),n]),gI=e=>o(_r(e),([t,n])=>[Ds(t),n]),$I=e=>o(Hr(["'",'"'],e),([t,n])=>[Ns(t),n]),hI=e=>o(o(o(u("keyof",e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>o([[],e],([t,n])=>[t,n],()=>[])),([t,n])=>[Bs(t),n]),Fp=(e,t=[])=>o(o(o(u("[",e),([n,r])=>o(O(r),([a,s])=>o(u("]",s),([m,c])=>[[n,a,m],c]))),([n,r])=>[n,r],()=>o(o(u("[",e),([n,r])=>o(u("]",r),([a,s])=>[[n,a],s])),([n,r])=>[n,r],()=>[])),([n,r])=>Fp(r,[...t,n]),()=>[t,e]),bI=e=>o(Fp(e),([t,n])=>[Ws(t),n]),TI=e=>o(o(o(u("extends",e),([t,n])=>o(O(n),([r,a])=>o(u("?",a),([s,m])=>o(O(m),([c,f])=>o(u(":",f),([E,g])=>o(O(g),([q,Y])=>[[t,r,s,c,E,q],Y])))))),([t,n])=>[t,n],()=>o([[],e],([t,n])=>[t,n],()=>[])),([t,n])=>[Vs(t),n]),EI=e=>o(o(o(u("(",e),([t,n])=>o(O(n),([r,a])=>o(u(")",a),([s,m])=>[[t,r,s],m]))),([t,n])=>[t,n],()=>o(wp(e),([t,n])=>[t,n],()=>o(jp(e),([t,n])=>[t,n],()=>o(rI(e),([t,n])=>[t,n],()=>o(aI(e),([t,n])=>[t,n],()=>o(oI(e),([t,n])=>[t,n],()=>o(Ap(e),([t,n])=>[t,n],()=>o(iI(e),([t,n])=>[t,n],()=>o(sI(e),([t,n])=>[t,n],()=>o(mI(e),([t,n])=>[t,n],()=>o(pI(e),([t,n])=>[t,n],()=>o(uI(e),([t,n])=>[t,n],()=>o(Lp(e),([t,n])=>[t,n],()=>o(cI(e),([t,n])=>[t,n],()=>o(lI(e),([t,n])=>[t,n],()=>o(II(e),([t,n])=>[t,n],()=>o(yI(e),([t,n])=>[t,n],()=>o(gI(e),([t,n])=>[t,n],()=>o($I(e),([t,n])=>[t,n],()=>o(dI(e),([t,n])=>[t,n],()=>o(xI(e),([t,n])=>[t,n],()=>o(qI(e),([t,n])=>[t,n],()=>o(GI(e),([t,n])=>[t,n],()=>o(VI(e),([t,n])=>[t,n],()=>o(WI(e),([t,n])=>[t,n],()=>o(XI(e),([t,n])=>[t,n],()=>o(nI(e),([t,n])=>[t,n],()=>o(YI(e),([t,n])=>[t,n],()=>[])))))))))))))))))))))))))))),([t,n])=>[Zs(t),n]),kI=e=>o(o(o(u("with",e),([t,n])=>o(Yp(n),([r,a])=>[[t,r],a])),([t,n])=>[t,n],()=>o([[],e],([t,n])=>[t,n],()=>[])),([t,n])=>[Js(t),n]),Dp=e=>o(o(hI(e),([t,n])=>o(EI(n),([r,a])=>o(bI(a),([s,m])=>o(TI(m),([c,f])=>o(kI(f),([E,g])=>[[t,r,s,c,E],g]))))),([t,n])=>[Qs(t),n]),Np=e=>o(o(o(u("&",e),([t,n])=>o(Dp(n),([r,a])=>o(Np(a),([s,m])=>[[t,r,s],m]))),([t,n])=>[t,n],()=>o([[],e],([t,n])=>[t,n],()=>[])),([t,n])=>[t,n]),Up=e=>o(o(Dp(e),([t,n])=>o(Np(n),([r,a])=>[[t,r],a])),([t,n])=>[Xs(t),n]),Kp=e=>o(o(o(u("|",e),([t,n])=>o(Up(n),([r,a])=>o(Kp(a),([s,m])=>[[t,r,s],m]))),([t,n])=>[t,n],()=>o([[],e],([t,n])=>[t,n],()=>[])),([t,n])=>[t,n]),zr=e=>o(o(Up(e),([t,n])=>o(Kp(n),([r,a])=>[[t,r],a])),([t,n])=>[Ys(t),n]),PI=e=>o(o(u("readonly",e),([t,n])=>o(zr(n),([r,a])=>[[t,r],a])),([t,n])=>[em(t),n]),OI=e=>o(o(u("|",e),([t,n])=>o(zr(n),([r,a])=>[[t,r],a])),([t,n])=>[tm(t),n]),CI=e=>o(o(wa(e),([t,n])=>o(u("=",n),([r,a])=>o(O(a),([s,m])=>[[t,r,s],m]))),([t,n])=>[nm(t),n]),RI=e=>o(o(o(u("infer",e),([t,n])=>o(H(n),([r,a])=>o(u("extends",a),([s,m])=>o(zr(m),([c,f])=>[[t,r,s,c],f])))),([t,n])=>[t,n],()=>o(o(u("infer",e),([t,n])=>o(H(n),([r,a])=>[[t,r],a])),([t,n])=>[t,n],()=>[])),([t,n])=>[rm(t),n]),O=e=>o(o(RI(e),([t,n])=>[t,n],()=>o(OI(e),([t,n])=>[t,n],()=>o(PI(e),([t,n])=>[t,n],()=>o(zr(e),([t,n])=>[t,n],()=>[])))),([t,n])=>[t,n]),vI=e=>o(_r(e),([t,n])=>[am(t),n]),MI=e=>o(H(e),([t,n])=>[t,n]),SI=e=>o(Hr(["'",'"'],e),([t,n])=>[t,n]),wI=e=>o(o(u("[",e),([t,n])=>o(H(n),([r,a])=>o(u(":",a),([s,m])=>o(o(Ap(m),([c,f])=>[c,f],()=>o(jp(m),([c,f])=>[c,f],()=>o(wp(m),([c,f])=>[c,f],()=>o(Lp(m),([c,f])=>[c,f],()=>[])))),([c,f])=>o(u("]",f),([E,g])=>[[t,r,s,c,E],g]))))),([t,n])=>[om(t),n]),Gp=e=>o(o(vI(e),([t,n])=>[t,n],()=>o(MI(e),([t,n])=>[t,n],()=>o(SI(e),([t,n])=>[t,n],()=>o(wI(e),([t,n])=>[t,n],()=>[])))),([t,n])=>[t,n]),jI=e=>o(o(o(u("readonly",e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>o([[],e],([t,n])=>[t,n],()=>[])),([t,n])=>[im(t),n]),AI=e=>o(o(o(u("?",e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>o([[],e],([t,n])=>[t,n],()=>[])),([t,n])=>[sm(t),n]),_p=e=>o(o(jI(e),([t,n])=>o(Gp(n),([r,a])=>o(AI(a),([s,m])=>o(u(":",m),([c,f])=>o(O(f),([E,g])=>[[t,r,s,c,E],g]))))),([t,n])=>[mm(t),n]),Hp=e=>o(o(o(u(",",e),([t,n])=>o(u(`
3
+ `,n),([r,a])=>[[t,r],a])),([t,n])=>[t,n],()=>o(o(u(";",e),([t,n])=>o(u(`
4
+ `,n),([r,a])=>[[t,r],a])),([t,n])=>[t,n],()=>o(o(u(",",e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>o(o(u(";",e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>o(o(u(`
5
+ `,e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>[]))))),([t,n])=>[t,n]),zp=(e,t=[])=>o(o(_p(e),([n,r])=>o(Hp(r),([a,s])=>[[n,a],s])),([n,r])=>zp(r,[...t,n]),()=>[t,e]),LI=e=>o(o(zp(e),([t,n])=>o(o(o(_p(n),([r,a])=>[[r],a]),([r,a])=>[r,a],()=>o([[],n],([r,a])=>[r,a],()=>[])),([r,a])=>[[t,r],a])),([t,n])=>[pm(t),n]),Aa=e=>o(o(u("{",e),([t,n])=>o(LI(n),([r,a])=>o(u("}",a),([s,m])=>[[t,r,s],m]))),([t,n])=>[cm(t),n]),qI=e=>o(Aa(e),([t,n])=>[lm(t),n]),FI=e=>o(o(o(H(e),([t,n])=>o(u("?",n),([r,a])=>o(u(":",a),([s,m])=>o(u("readonly",m),([c,f])=>o(O(f),([E,g])=>[[t,r,s,c,E],g]))))),([t,n])=>[t,n],()=>o(o(H(e),([t,n])=>o(u(":",n),([r,a])=>o(u("readonly",a),([s,m])=>o(O(m),([c,f])=>[[t,r,s,c],f])))),([t,n])=>[t,n],()=>o(o(H(e),([t,n])=>o(u("?",n),([r,a])=>o(u(":",a),([s,m])=>o(O(m),([c,f])=>[[t,r,s,c],f])))),([t,n])=>[t,n],()=>o(o(H(e),([t,n])=>o(u(":",n),([r,a])=>o(O(a),([s,m])=>[[t,r,s],m]))),([t,n])=>[t,n],()=>[])))),([t,n])=>[fm(t),n]),DI=e=>o(o(u("readonly",e),([t,n])=>o(O(n),([r,a])=>o(u("?",a),([s,m])=>[[t,r,s],m]))),([t,n])=>[dm(t),n]),NI=e=>o(o(u("readonly",e),([t,n])=>o(O(n),([r,a])=>[[t,r],a])),([t,n])=>[xm(t),n]),UI=e=>o(o(O(e),([t,n])=>o(u("?",n),([r,a])=>[[t,r],a])),([t,n])=>[Im(t),n]),Op=e=>o(o(FI(e),([t,n])=>[t,n],()=>o(DI(e),([t,n])=>[t,n],()=>o(NI(e),([t,n])=>[t,n],()=>o(UI(e),([t,n])=>[t,n],()=>o(O(e),([t,n])=>[t,n],()=>[]))))),([t,n])=>[t,n]),Bp=e=>o(o(o(u("...",e),([t,n])=>o(Op(n),([r,a])=>[[t,r],a])),([t,n])=>[t,n],()=>o(o(Op(e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>[])),([t,n])=>[ym(t),n]),Wp=(e,t=[])=>o(o(Bp(e),([n,r])=>o(u(",",r),([a,s])=>[[n,a],s])),([n,r])=>Wp(r,[...t,n]),()=>[t,e]),KI=e=>o(o(Wp(e),([t,n])=>o(o(o(Bp(n),([r,a])=>[[r],a]),([r,a])=>[r,a],()=>o([[],n],([r,a])=>[r,a],()=>[])),([r,a])=>[[t,r],a])),([t,n])=>[gm(t),n]),GI=e=>o(o(u("[",e),([t,n])=>o(KI(n),([r,a])=>o(u("]",a),([s,m])=>[[t,r,s],m]))),([t,n])=>[$m(t),n]),_I=e=>o(o(H(e),([t,n])=>o(u("?",n),([r,a])=>o(u(":",a),([s,m])=>o(u("readonly",m),([c,f])=>o(O(f),([E,g])=>[[t,r,s,c,E],g]))))),([t,n])=>[hm(t),n]),HI=e=>o(o(H(e),([t,n])=>o(u(":",n),([r,a])=>o(u("readonly",a),([s,m])=>o(O(m),([c,f])=>[[t,r,s,c],f])))),([t,n])=>[bm(t),n]),zI=e=>o(o(H(e),([t,n])=>o(u("?",n),([r,a])=>o(u(":",a),([s,m])=>o(O(m),([c,f])=>[[t,r,s,c],f])))),([t,n])=>[Tm(t),n]),BI=e=>o(o(H(e),([t,n])=>o(u(":",n),([r,a])=>o(O(a),([s,m])=>[[t,r,s],m]))),([t,n])=>[Em(t),n]),Cp=e=>o(o(_I(e),([t,n])=>[t,n],()=>o(HI(e),([t,n])=>[t,n],()=>o(zI(e),([t,n])=>[t,n],()=>o(BI(e),([t,n])=>[t,n],()=>[])))),([t,n])=>[t,n]),Vp=e=>o(o(o(u("...",e),([t,n])=>o(Cp(n),([r,a])=>[[t,r],a])),([t,n])=>[t,n],()=>o(o(Cp(e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>[])),([t,n])=>[km(t),n]),Zp=(e,t=[])=>o(o(Vp(e),([n,r])=>o(u(",",r),([a,s])=>[[n,a],s])),([n,r])=>Zp(r,[...t,n]),()=>[t,e]),Jp=e=>o(o(Zp(e),([t,n])=>o(o(o(Vp(n),([r,a])=>[[r],a]),([r,a])=>[r,a],()=>o([[],n],([r,a])=>[r,a],()=>[])),([r,a])=>[[t,r],a])),([t,n])=>[Pm(t),n]),WI=e=>o(o(u("(",e),([t,n])=>o(Jp(n),([r,a])=>o(u(")",a),([s,m])=>o(u("=>",m),([c,f])=>o(O(f),([E,g])=>[[t,r,s,c,E],g]))))),([t,n])=>[Om(t),n]),VI=e=>o(o(u("new",e),([t,n])=>o(u("(",n),([r,a])=>o(Jp(a),([s,m])=>o(u(")",m),([c,f])=>o(u("=>",f),([E,g])=>o(O(g),([q,Y])=>[[t,r,s,c,E,q],Y])))))),([t,n])=>[Cm(t),n]),ZI=e=>o(o(o(u("+",e),([t,n])=>o(u("readonly",n),([r,a])=>[[t,r],a])),([t,n])=>[t,n],()=>o(o(u("-",e),([t,n])=>o(u("readonly",n),([r,a])=>[[t,r],a])),([t,n])=>[t,n],()=>o(o(u("readonly",e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>o([[],e],([t,n])=>[t,n],()=>[])))),([t,n])=>[Rm(t),n]),JI=e=>o(o(o(u("+",e),([t,n])=>o(u("?",n),([r,a])=>[[t,r],a])),([t,n])=>[t,n],()=>o(o(u("-",e),([t,n])=>o(u("?",n),([r,a])=>[[t,r],a])),([t,n])=>[t,n],()=>o(o(u("?",e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>o([[],e],([t,n])=>[t,n],()=>[])))),([t,n])=>[vm(t),n]),QI=e=>o(o(o(u("as",e),([t,n])=>o(O(n),([r,a])=>[[t,r],a])),([t,n])=>[t,n],()=>o([[],e],([t,n])=>[t,n],()=>[])),([t,n])=>[Mm(t),n]),XI=e=>o(o(u("{",e),([t,n])=>o(ZI(n),([r,a])=>o(u("[",a),([s,m])=>o(H(m),([c,f])=>o(u("in",f),([E,g])=>o(O(g),([q,Y])=>o(QI(Y),([we,ut])=>o(u("]",ut),([de,en])=>o(JI(en),([Un,Re])=>o(u(":",Re),([ct,vt])=>o(O(vt),([ra,xf])=>o(Sp(xf),([If,yf])=>o(u("}",yf),([gf,$f])=>[[t,r,s,c,E,q,we,de,Un,ct,ra,If,gf],$f]))))))))))))),([t,n])=>[Sm(t),n]),YI=e=>o(H(e),([t,n])=>[wm(t),n]),ey=e=>o(Ra(e),([t,n])=>[jm(t),n]),ty=e=>o(_r(e),([t,n])=>[Am(t),n]),ny=e=>o(o(u("true",e),([t,n])=>[t,n],()=>o(u("false",e),([t,n])=>[t,n],()=>[])),([t,n])=>[Lm(t),n]),ry=e=>o(Hr(['"',"'"],e),([t,n])=>[t,n]),ay=e=>o(u("null",e),([t,n])=>[qm(t),n]),oy=e=>o(u("undefined",e),([t,n])=>[void 0,n]),Qp=e=>o(o(Gp(e),([t,n])=>o(u(":",n),([r,a])=>o(La(a),([s,m])=>[[t,r,s],m]))),([t,n])=>[Fm(t),n]),Xp=(e,t=[])=>o(o(Qp(e),([n,r])=>o(Hp(r),([a,s])=>[[n,a],s])),([n,r])=>Xp(r,[...t,n]),()=>[t,e]),iy=e=>o(o(Xp(e),([t,n])=>o(o(o(Qp(n),([r,a])=>[[r],a]),([r,a])=>[r,a],()=>o([[],n],([r,a])=>[r,a],()=>[])),([r,a])=>[[t,r],a])),([t,n])=>[Dm(t),n]),Yp=e=>o(o(u("{",e),([t,n])=>o(iy(n),([r,a])=>o(u("}",a),([s,m])=>[[t,r,s],m]))),([t,n])=>[Nm(t),n]),eu=(e,t=[])=>o(o(La(e),([n,r])=>o(u(",",r),([a,s])=>[[n,a],s])),([n,r])=>eu(r,[...t,n]),()=>[t,e]),sy=e=>o(o(eu(e),([t,n])=>o(o(o(La(n),([r,a])=>[[r],a]),([r,a])=>[r,a],()=>o([[],n],([r,a])=>[r,a],()=>[])),([r,a])=>[[t,r],a])),([t,n])=>[Um(t),n]),my=e=>o(o(u("[",e),([t,n])=>o(sy(n),([r,a])=>o(u("]",a),([s,m])=>[[t,r,s],m]))),([t,n])=>[Km(t),n]),La=e=>o(o(ey(e),([t,n])=>[t,n],()=>o(ty(e),([t,n])=>[t,n],()=>o(ny(e),([t,n])=>[t,n],()=>o(ry(e),([t,n])=>[t,n],()=>o(ay(e),([t,n])=>[t,n],()=>o(oy(e),([t,n])=>[t,n],()=>o(Yp(e),([t,n])=>[t,n],()=>o(my(e),([t,n])=>[t,n],()=>[])))))))),([t,n])=>[t,n]),py=e=>o(u("-?(?:0|[1-9][0-9]*)n",e),([t,n])=>[Gm(t),n]),uy=e=>o(u(".*",e),([t,n])=>[_m(t),n]),cy=e=>o(u("-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?",e),([t,n])=>[Hm(t),n]),ly=e=>o(u("-?(?:0|[1-9][0-9]*)",e),([t,n])=>[zm(t),n]),fy=e=>o(u("(?!)",e),([t,n])=>[Bm(t),n]),dy=e=>o(Pp(["-?(?:0|[1-9][0-9]*)n",".*","-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?","-?(?:0|[1-9][0-9]*)","(?!)","(",")","$","|"],e),([t,n])=>[Wm(t),n]),xy=e=>o(o(py(e),([t,n])=>[t,n],()=>o(uy(e),([t,n])=>[t,n],()=>o(cy(e),([t,n])=>[t,n],()=>o(ly(e),([t,n])=>[t,n],()=>o(fy(e),([t,n])=>[t,n],()=>o(Iy(e),([t,n])=>[t,n],()=>o(dy(e),([t,n])=>[t,n],()=>[]))))))),([t,n])=>[t,n]),Iy=e=>o(o(u("(",e),([t,n])=>o(qa(n),([r,a])=>o(u(")",a),([s,m])=>[[t,r,s],m]))),([t,n])=>[Vm(t),n]),tu=e=>o(o(o(Sa(e),([t,n])=>o(u("|",n),([r,a])=>o(tu(a),([s,m])=>[[t,r,s],m]))),([t,n])=>[t,n],()=>o(o(Sa(e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>o([[],e],([t,n])=>[t,n],()=>[]))),([t,n])=>[Zm(t),n]),Sa=e=>o(o(xy(e),([t,n])=>o(qa(n),([r,a])=>[[t,r],a])),([t,n])=>[Jm(t),n]),qa=e=>o(o(tu(e),([t,n])=>[t,n],()=>o(Sa(e),([t,n])=>[t,n],()=>[])),([t,n])=>[t,n]),vi=e=>o(o(u("^",e),([t,n])=>o(qa(n),([r,a])=>o(u("$",a),([s,m])=>[[t,r,s],m]))),([t,n])=>[Qm(t),n]),nu=(e,t=[])=>o(o(O(e),([n,r])=>o(u(",",r),([a,s])=>[[n,a],s])),([n,r])=>nu(r,[...t,n]),()=>[t,e]),yy=e=>o(o(nu(e),([t,n])=>o(o(o(O(n),([r,a])=>[[r],a]),([r,a])=>[r,a],()=>o([[],n],([r,a])=>[r,a],()=>[])),([r,a])=>[[t,r],a])),([t,n])=>[Xm(t),n]),ru=e=>o(o(o(u("extends",e),([t,n])=>o(yy(n),([r,a])=>[[t,r],a])),([t,n])=>[t,n],()=>o([[],e],([t,n])=>[t,n],()=>[])),([t,n])=>[Ym(t),n]),gy=e=>o(o(u("interface",e),([t,n])=>o(H(n),([r,a])=>o(wa(a),([s,m])=>o(ru(m),([c,f])=>o(Aa(f),([E,g])=>[[t,r,s,c,E],g]))))),([t,n])=>[ep(t),n]),$y=e=>o(o(u("interface",e),([t,n])=>o(H(n),([r,a])=>o(ru(a),([s,m])=>o(Aa(m),([c,f])=>[[t,r,s,c],f])))),([t,n])=>[tp(t),n]),hy=e=>o(o(u("type",e),([t,n])=>o(H(n),([r,a])=>o(wa(a),([s,m])=>o(u("=",m),([c,f])=>o(O(f),([E,g])=>[[t,r,s,c,E],g]))))),([t,n])=>[np(t),n]),by=e=>o(o(u("type",e),([t,n])=>o(H(n),([r,a])=>o(u("=",a),([s,m])=>o(O(m),([c,f])=>[[t,r,s,c],f])))),([t,n])=>[rp(t),n]),Ty=e=>o(o(o(u("export",e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>o([[],e],([t,n])=>[t,n],()=>[])),([t,n])=>[ap(t),n]),Ey=e=>o(o(o(u(";",e),([t,n])=>o(u(`
6
+ `,n),([r,a])=>[[t,r],a])),([t,n])=>[t,n],()=>o(o(u(";",e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>o(o(u(`
7
+ `,e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>[]))),([t,n])=>[t,n]),au=(e,t=[])=>o(o(Fa(e),([n,r])=>o(Ey(r),([a,s])=>[[n,a],s])),([n,r])=>au(r,[...t,n]),()=>[t,e]),ky=e=>o(o(au(e),([t,n])=>o(o(o(Fa(n),([r,a])=>[[r],a]),([r,a])=>[r,a],()=>o([[],n],([r,a])=>[r,a],()=>[])),([r,a])=>[[t,r],a])),([t,n])=>[op(t),n]),Fa=e=>o(o(Ty(e),([t,n])=>o(o(gy(n),([r,a])=>[r,a],()=>o($y(n),([r,a])=>[r,a],()=>o(hy(n),([r,a])=>[r,a],()=>o(by(n),([r,a])=>[r,a],()=>[])))),([r,a])=>o(Sp(a),([s,m])=>[[t,r,s],m]))),([t,n])=>[ip(t),n]),Py=e=>o(o(Fa(e),([t,n])=>o(ky(n),([r,a])=>[[t,r],a])),([t,n])=>[sp(t),n]),ou=e=>o(o(Py(e),([t,n])=>[t,n],()=>o(CI(e),([t,n])=>[t,n],()=>o(O(e),([t,n])=>[t,n],()=>[]))),([t,n])=>[t,n]);function iu(e){let t=ja(`\`${e}\``);return i.IsEqual(t.length,2)?t[0]:B()}function Cy(e){return e.join("|")}function Ry(e){return e.slice(1,e.length-1)}function vy(e,t,n){return mt(t,`${n}${e}`)}function My(e,t){return mt(e,`${t}${Ei}`)}function Sy(e,t){return mt(e,`${t}${or}`)}function wy(e,t){return mt(e,`${t}${sr}`)}function jy(e,t){return On(k([R("false"),R("true")]),e,t)}function Ay(e,t){return mt(e,`${t}${mr}`)}function Ly(e,t,n){return mt(t,`${n}${Ry(e)}`)}function qy(e,t,n){let r=Cn(e,{});return On(r,t,n)}function Fy(e,t,n){let r=be(e);return On(r,t,n)}function su(e,t,n,r=[]){return i.ShiftLeft(e,(a,s)=>su(s,t,n,[...r,On(a,[],"")]),()=>mt(t,`${n}(${Cy(r)})`))}function On(e,t,n){return ue(e)?Fy(e.enum,t,n):ce(e)?Sy(t,n):w(e)?vy(e.const,t,n):Ue(e)?My(t,n):ke(e)?jy(t,n):V(e)?wy(t,n):le(e)?Ay(t,n):Z(e)?Ly(e.pattern,t,n):pu(e)?qy(e.parameters[0],t,n):I(e)?su(e.anyOf,t,n):ai}function mt(e,t){return i.ShiftLeft(e,(n,r)=>On(n,r,t),()=>t)}function Dy(e){return`^${mt(e,"")}$`}function mu(e){let t=Dy(e);return ur(t)}function Cn(e,t){return T(e)?p.Update(mu(e),{},t):$r(e,t)}function uu(e,t,n,r){let a=Te(e,t,n);return Cn(a,r)}function $r(e,t={}){return y("TemplateLiteral",[e],t)}function pu(e){return Q(e)&&i.HasPropertyKey(e,"action")&&i.IsEqual(e.action,"TemplateLiteral")}function cu(e){return Cn(e,{})}function Ny(e){let t=iu(e);return cu(t)}function lu(e,t={}){let n=i.IsString(e)?Ny(e):cu(e);return p.Update(n,{},t)}function Z(e){return x(e,"TemplateLiteral")}var $={};lt($,{ExtendsFalse:()=>b,ExtendsTrue:()=>d,ExtendsUnion:()=>Da,IsExtendsFalse:()=>Uy,IsExtendsTrue:()=>du,IsExtendsTrueLike:()=>Bt,IsExtendsUnion:()=>fu,Match:()=>N});function Da(e){return p.Create({"~kind":"ExtendsUnion"},{inferred:e})}function fu(e){return i.IsObject(e)&&i.HasPropertyKey(e,"~kind")&&i.HasPropertyKey(e,"inferred")&&i.IsEqual(e["~kind"],"ExtendsUnion")&&i.IsObject(e.inferred)}function d(e){return p.Create({"~kind":"ExtendsTrue"},{inferred:e})}function du(e){return i.IsObject(e)&&i.HasPropertyKey(e,"~kind")&&i.HasPropertyKey(e,"inferred")&&i.IsEqual(e["~kind"],"ExtendsTrue")&&i.IsObject(e.inferred)}function b(){return p.Create({"~kind":"ExtendsFalse"},{})}function Uy(e){return i.IsObject(e)&&i.HasPropertyKey(e,"~kind")&&i.IsEqual(e["~kind"],"ExtendsFalse")}function Bt(e){return fu(e)||du(e)}function N(e,t,n){return Bt(e)?t(e.inferred):n()}function Ky(e,t,n,r){return N(v(e,n,r),a=>d(p.Assign(p.Assign(e,a),{[t]:n})),()=>b())}function Gy(e,t){return d(e)}function _y(e,t,n,r,a){return N(v(e,t,n),s=>N(v(s,t,r),m=>d(m),()=>b()),()=>N(v(e,t,a),s=>d(s),()=>b()))}function Hy(e,t,n){let r=be(n);return v(e,t,r)}function xu(e,t,n){return i.ShiftLeft(n,(r,a)=>N(v(e,t,r),s=>xu(s,t,a),()=>b()),()=>d(e))}function zy(e,t,n){let r=Ie(n);return v(e,t,r)}function Iu(e,t,n){return i.ShiftLeft(n,(r,a)=>N(v(e,t,r),s=>d(s),()=>Iu(e,t,a)),()=>b())}function j(e,t,n){return W(n)?Gy(e,t):_(n)?_y(e,t,n.if,n.then,n.else):ue(n)?Hy(e,t,n.enum):z(n)?Ky(e,n.name,t,n.extends):C(n)?xu(e,t,n.allOf):Z(n)?zy(e,t,n.pattern):I(n)?Iu(e,t,n.anyOf):X(n)?d(e):b()}function yu(e,t,n){return z(n)?j(e,t,n):W(n)?d(e):X(n)?d(e):Da(e)}function By(e,t){let n=$t(e),r=$t(t);return n&&r||!n&&r?!0:!(n&&!r)}function gu(e,t,n,r){return U(r)?By(t,r)?v(e,n,r.items):b():j(e,t,r)}function $u(e,t,n){return Ue(n)?d(e):j(e,t,n)}function hu(e,t,n){return ke(n)?d(e):j(e,t,n)}function Wy(e,t,n,r,a){let s=z(r)?t:r,m=z(r)?r:t,c=me(t),f=me(r);return!c&&f?b():N(v(e,s,m),E=>Rn(E,n,a),()=>b())}function Vy(e,t,n,r){return i.ShiftLeft(r,(a,s)=>Wy(e,t,n,a,s),()=>me(t)?d(e):b())}function Zy(e,t,n){return i.ShiftLeft(t,(r,a)=>Vy(e,r,a,n),()=>d(e))}function Rn(e,t,n){return Zy(e,t,n)}function Br(e,t,n){return Ke(n)?d(e):v(e,t,n)}function bu(e,t,n,r){return W(r)?d(e):X(r)?d(e):ee(r)?N(Rn(e,t,r.parameters),a=>Br(a,n,r.instanceType),()=>b()):b()}function Tu(e,t,n,r,a){return N(v(e,t,a),()=>v(e,n,a),()=>v(e,r,a))}function Eu(e,t,n){let r=be(t);return v(e,r,n)}function ku(e,t,n,r){return W(r)?d(e):X(r)?d(e):te(r)?N(Rn(e,t,r.parameters),a=>Br(a,n,r.returnType),()=>b()):b()}function Pu(e,t,n){return ce(n)?d(e):V(n)?d(e):j(e,t,n)}function Ou(e,t,n){let r=K(t);return v(e,r,n)}function Wr(e,t,n){return t===n?d(e):b()}function Jy(e,t,n){return w(n)?Wr(e,t,n.const):Ue(n)?d(e):j(e,R(t),n)}function Qy(e,t,n){return w(n)?Wr(e,t,n.const):ke(n)?d(e):j(e,R(t),n)}function Xy(e,t,n){return w(n)?Wr(e,t,n.const):V(n)?d(e):j(e,R(t),n)}function Yy(e,t,n){return w(n)?Wr(e,t,n.const):le(n)?d(e):j(e,R(t),n)}function Cu(e,t,n){return i.IsBigInt(t.const)?Jy(e,t.const,n):i.IsBoolean(t.const)?Qy(e,t.const,n):i.IsNumber(t.const)?Xy(e,t.const,n):i.IsString(t.const)?Yy(e,t.const,n):B()}function Ru(e,t,n){return z(n)?j(e,t,n):d(e)}function vu(e,t,n){return qt(n)?d(e):j(e,t,n)}function Mu(e,t,n){return V(n)?d(e):j(e,t,n)}function eg(e,t,n){return me(t)?me(n)?d(e):b():d(e)}function tg(e,t,n){return z(n)&&tt(n.extends)?b():N(v(e,t,n),r=>eg(r,t,n),()=>b())}function ng(e,t){return e.reduce((n,r)=>r in t?Bt(t[r])?{...n,...t[r].inferred}:B():B(),{})}function rg(e,t,n){let r={};for(let m of i.Keys(n))r[m]=m in t?tg({},t[m],n[m]):me(n[m])?z(n[m])?d(p.Assign(e,{[n[m].name]:n[m].extends})):d(e):b();let a=i.Values(r).every(m=>Bt(m)),s=a?ng(i.Keys(r),r):{};return a?d(s):b()}function ag(e,t,n){let r=rg(e,t,n);return Bt(r)?d(p.Assign(e,r.inferred)):b()}function og(e,t,n){return ag(e,t,n)}function ig(e,t){return i.Keys(t).reduce((n,r)=>({...n,[r]:i.HasPropertyKey(e,r)?I(n[r])?k([...n[r].anyOf,t[r]]):k([e[r],t[r]]):t[r]}),e)}function Su(e,t,n,r){return i.ShiftLeft(t,(a,s)=>N(v({},e[a],n),m=>Su(e,s,n,ig(r,m)),()=>b()),()=>d(r))}function sg(e,t,n,r){let a=i.Keys(t);return Su(t,a,r,e)}function wu(e,t,n){return se(n)?sg(e,t,Ce(n),fe(n)):S(n)?og(e,t,n.properties):j(e,h(t),n)}function mg(e,t){return i.IsEqual(i.Keys(t).length,0)?d(e):b()}function pg(e,t,n,r,a){return v(e,n,a)}function ju(e,t,n,r){return se(r)?pg(e,xr(t),n,xr(Ce(r)),fe(r)):S(r)?mg(e,r.properties):W(r)?d(e):X(r)?d(e):b()}function Au(e,t,n){return le(n)?d(e):j(e,t,n)}function Lu(e,t,n){return nt(n)?d(e):j(e,t,n)}function qu(e,t,n){let r=Ie(t);return v(e,r,n)}function Na(e,t){return p.Create({"~kind":"Inferrable"},{name:e,type:t},{})}function vn(e){return i.IsObject(e)&&i.HasPropertyKey(e,"~kind")&&i.HasPropertyKey(e,"name")&&i.HasPropertyKey(e,"type")&&i.IsEqual(e["~kind"],"Inferrable")&&i.IsString(e.name)&&i.IsObject(e.type)}function Ua(e){return ot(e)?z(e.items)?U(e.items.extends)?Na(e.items.name,e.items.extends.items):X(e.items.extends)?Na(e.items.name,e.items.extends):void 0:B():void 0}function Vr(e){return z(e)?Na(e.name,e.extends):void 0}function Ka(e,t,n=[]){return i.ShiftLeft(e,(r,a)=>N(v({},r,t),()=>Ka(a,t,[...n,r]),()=>{}),()=>n)}function Fu(e,t,n,r){let a=Ka(n,r);return i.IsArray(a)?d(p.Assign(e,{[t]:J(a)})):b()}function Zr(e,t,n,r){let a=Ka(n,r);return i.IsArray(a)?d(p.Assign(e,{[t]:k(a)})):b()}function ug(e){return[...e].reverse()}function Ga(e,t){return t?ug(e):e}function cg(e){let t=e.length>0?e[0]:void 0,n=Q(t)?Ua(t):void 0;return Q(n)}function lg(e,t,n,r,a,s){return N(v(e,n,a),m=>Du(m,t,r,s),()=>b())}function fg(e,t,n,r,a){let s=Ua(r);return vn(s)?Fu(e,s.name,Ga(n,t),s.type):i.ShiftLeft(n,(m,c)=>lg(e,t,m,c,r,a),()=>b())}function dg(e,t,n,r){return i.ShiftLeft(r,(a,s)=>fg(e,t,n,a,s),()=>i.IsEqual(n.length,0)?d(e):b())}function Du(e,t,n,r){return dg(e,t,n,r)}function xg(e,t,n){let r=pt(e,D([],[]),n),a=cg(r);return Du(e,a,Ga(t,a),Ga(r,a))}function Nu(e,t,n){let r=Vr(n);return vn(r)?Zr(e,r.name,t,r.type):i.ShiftLeft(t,(a,s)=>N(v(e,a,n),m=>Nu(m,s,n),()=>b()),()=>d(e))}function Uu(e,t,n){let r=pt(e,D([],[]),t);return F(n)?xg(e,r,n.items):U(n)?Nu(e,r,n.items):j(e,J(r),n)}function Ku(e,t,n){return Ke(n)?d(e):Gt(n)?d(e):j(e,t,n)}function Gu(e,t,n){return i.ShiftLeft(n,(r,a)=>N(v(e,t,r),s=>d(s),()=>Gu(e,t,a)),()=>b())}function _a(e,t,n){return i.ShiftLeft(t,(r,a)=>N(Gu(e,r,n),s=>_a(s,a,n),()=>b()),()=>d(e))}function _u(e,t,n){let r=Vr(n);return vn(r)?Zr(e,r.name,t,r.type):I(n)?_a(e,t,n.anyOf):_a(e,t,[n])}function Hu(e,t,n){return z(n)?j(e,t,n):W(n)?d(e):X(n)?d(e):b()}function zu(e,t,n){return Ke(n)?d(e):j(e,t,n)}function v(e,t,n){return W(t)?yu(e,t,n):U(t)?gu(e,t,t.items,n):Ue(t)?$u(e,t,n):ke(t)?hu(e,t,n):ee(t)?bu(e,t.parameters,t.instanceType,n):_(t)?Tu(e,t.if,t.then,t.else,n):ue(t)?Eu(e,t.enum,n):te(t)?ku(e,t.parameters,t.returnType,n):ce(t)?Pu(e,t,n):C(t)?Ou(e,t.allOf,n):w(t)?Cu(e,t,n):tt(t)?Ru(e,t,n):qt(t)?vu(e,t,n):V(t)?Mu(e,t,n):S(t)?wu(e,t.properties,n):se(t)?ju(e,Ce(t),fe(t),n):le(t)?Au(e,t,n):nt(t)?Lu(e,t,n):Z(t)?qu(e,t.pattern,n):F(t)?Uu(e,t.items,n):Gt(t)?Ku(e,t,n):I(t)?_u(e,t.anyOf,n):X(t)?Hu(e,t,n):Ke(t)?zu(e,t,n):b()}function Ig(e,t){return K([...e,h(t)])}function Ha(e,t,n){return T(e)?p.Update(Ig(e,t),{},n):bn(e,t,n)}function Bu(e,t,n,r,a){let s=Te(e,t,n),m=Mn(e,t,r);return Ha(s,m,a)}function bn(e,t,n={}){return y("Interface",[e,t],n)}function Wt(e){return Q(e)&&i.HasPropertyKey(e,"action")&&i.IsEqual(e.action,"Interface")}function Wu(e,t,n={}){return Ha(e,t,n)}function yg(e,t,n){return e.includes(n)?!0:Sn([...e,n],t,t[n])}function Vu(e,t,n){let r=er(n);return Ot(e,t,r)}function Ot(e,t,n){return i.ShiftLeft(n,(r,a)=>Sn(e,t,r)?!0:Ot(e,t,a),()=>!1)}function Sn(e,t,n){return ne(n)?yg(e,t,n.$ref):U(n)?Sn(e,t,n.items):ee(n)?Ot(e,t,[...n.parameters,n.instanceType]):te(n)?Ot(e,t,[...n.parameters,n.returnType]):Wt(n)?Vu(e,t,n.parameters[1]):C(n)?Ot(e,t,n.allOf):S(n)?Vu(e,t,n.properties):I(n)?Ot(e,t,n.anyOf):F(n)?Ot(e,t,n.items):se(n)?Sn(e,t,fe(n)):!1}function Zu(e,t,n){return Sn(e,t,n)}function gg(e,t){return t.reduce((n,r)=>Zu([r],e,e[r])?[...n,r]:n,[])}function Ju(e){let t=Yn(e);return gg(e,t)}function $g(e,t,n){return n.includes(t)?n:t in e?wn(e,e[t],[...n,t]):B()}function Qu(e,t,n){let r=er(t);return Vt(e,r,n)}function Vt(e,t,n){return t.reduce((r,a)=>wn(e,a,r),n)}function wn(e,t,n){return ne(t)?$g(e,t.$ref,n):U(t)?wn(e,t.items,n):ee(t)?Vt(e,[...t.parameters,t.instanceType],n):te(t)?Vt(e,[...t.parameters,t.returnType],n):Wt(t)?Qu(e,t.parameters[1],n):C(t)?Vt(e,t.allOf,n):S(t)?Qu(e,t.properties,n):I(t)?Vt(e,t.anyOf,n):F(t)?Vt(e,t.items,n):se(t)?wn(e,fe(t),n):n}function Xu(e,t,n){return wn(e,n,[t])}function hg(e){return jt()}function bg(e){return i.Keys(e).reduce((t,n)=>({...t,[n]:Ct(e[n])}),{})}function jn(e){return e.reduce((t,n)=>[...t,Ct(n)],[])}function Ct(e){return ne(e)?hg(e.$ref):U(e)?he(Ct(e.items),Xn(e)):ee(e)?Ae(jn(e.parameters),Ct(e.instanceType)):te(e)?Le(jn(e.parameters),Ct(e.returnType)):C(e)?pe(jn(e.allOf)):S(e)?h(bg(e.properties)):se(e)?dr(Ut(e),Ct(fe(e))):I(e)?k(jn(e.anyOf)):F(e)?J(jn(e.items)):e}function Tg(e,t){return t in e?Ct(e[t]):re()}function Yu(e){return Tg(e.$defs,e.$ref)}function Eg(e,t,n){let r=Te(e,D([],[]),t),a=Mn({},D([],[]),n);return K([...r,h(a)])}function kg(e,t){return i.Keys(e).filter(r=>t.includes(r)).reduce((r,a)=>{let s=e[a],m=Wt(s)?Eg(e,s.parameters[0],s.parameters[1]):s;return{...r,[a]:m}},{})}function ec(e,t,n){let r=Xu(e,t,n),a=kg(e,r);return Fe(a,t)}function tc(e,t){return t in e?ne(e[t])?tc(e,e[t].$ref):e[t]:L()}function Ge(e,t){return tc(e,t)}function nc(e){return oe(e)?Yu(e):tr(e)?re():e}function ie(e,t,n){let r=nc(t),a=nc(n);return v(e,r,a)}var xn="equal",Pg="disjoint",In="left-inside",yn="right-inside";function Dt(e,t){let n=[X(e)?$.ExtendsFalse():ie({},e,t),X(e)?$.ExtendsTrue({}):ie({},t,e)];return $.IsExtendsTrueLike(n[0])&&$.IsExtendsTrueLike(n[1])?xn:$.IsExtendsTrueLike(n[0])&&$.IsExtendsFalse(n[1])?In:$.IsExtendsFalse(n[0])&&$.IsExtendsTrueLike(n[1])?yn:Pg}function Og(e,t){return t.filter(n=>Dt(e,n)!==yn)}function Cg(e,t){let n=t.some(r=>{let a=Dt(e,r);return i.IsEqual(a,In)||i.IsEqual(a,xn)});return i.IsEqual(n,!1)}function Rg(e,t){let n=Oe(e);return W(n)?[n]:Cg(n,t)?[...Og(n,t),n]:t}function vg(e){return e.reduce((t,n)=>S(n)?[...t,n]:tt(n)?t:Rg(n,t),[])}function Ta(e){let t=vg(e);return $n(t)}function za(e,t){return p.Update(Oe(e),{},t)}function rc(e,t,n,r){let a=l(e,t,n);return za(a,r)}function An(e,t=[]){return Ye(e)&&i.IsEqual(e.action,"Conditional")?ne(e.parameters[0])?An(e.parameters[2],An(e.parameters[3],[...t,e.parameters[0].$ref])):An(e.parameters[2],An(e.parameters[3],t)):Ye(e)&&i.IsEqual(e.action,"Mapped")&&Ye(e.parameters[1])&&i.IsEqual(e.parameters[1].action,"KeyOf")&&ne(e.parameters[1].parameters[0])?[...t,e.parameters[1].parameters[0].$ref]:t}function Mg(e,t){return e.reduce((n,r)=>[...n,t.includes(r.name)],[])}function ic(e,t,n=[]){return i.ShiftLeft(e,(r,a)=>i.ShiftLeft(t,(s,m)=>ic(a,m,[...n,[s,r]]),()=>n),()=>n)}function Sg(e){return I(e)?[...e.anyOf]:[e]}function wg(e,t){return e.reduce((n,r)=>[...n,[...r,t]],[])}function ac(e,t){return t.reduce((n,r)=>[...n,...wg(e,r)],[])}function oc(e){return e.reduce((t,n)=>i.IsEqual(n[0],!0)?ac(t,Sg(n[1])):ac(t,[n[1]]),[[]])}function sc(e,t,n){let r=An(n),a=Mg(e,r),s=ic(t,a);return Ye(n)&&i.IsEqual(n.action,"Conditional")||Ye(n)&&i.IsEqual(n.action,"Mapped")?oc(s):[t]}function jg(){return["(not-resolvable)",L()]}function Ag(){return["(not-generic)",L()]}function Lg(e,t,n){return[e,et(t,n)]}function qg(e,t,n){return t in e?mc(e,t,e[t],n):jg()}function mc(e,t,n,r){return wt(n)?Lg(t,n.parameters,n.expression):ne(n)?qg(e,n.$ref,r):Ag()}function pc(e,t,n){return mc(e,"(anonymous)",t,n)}function Fg(e,t,n){if(z(t)||Zt(t)||$.IsExtendsTrueLike(ie({},t,n)))return;let r={parameter:e,expect:n,actual:t};throw new Error(`Argument for parameter ${e} does not satisfy constraint`,{cause:r})}function uc(e,t,n,r,a){let s=l(e,t,a);return Fg(n,s,r),p.Assign(e,{[n]:s})}function Dg(e,t,n,r,a){let s=l(e,t,n.extends),m=l(e,t,n.equals);return i.ShiftLeft(a,(c,f)=>Ba(uc(e,t,n.name,s,c),t,r,f),()=>Ba(uc(e,t,n.name,s,m),t,r,[]))}function Ba(e,t,n,r){return i.ShiftLeft(n,(a,s)=>Dg(e,t,a,s,r),()=>e)}function cc(e,t,n,r){return Ba(e,t,n,r)}function Ng(e){return i.IsGreaterThan(e.callstack.length,0)?e.callstack[e.callstack.length-1]:""}function Ug(e,t){return i.IsEqual(Ng(e),t)}function Kg(e,t,n,r,a,s){let m=cc(e,t,r,s),c=l(m,D([...t.callstack,n.$ref],t.visited),a);return l(m,D([],[]),c)}function Gg(e,t,n,r,a,s){return s.reduce((m,c)=>[...m,Kg(e,t,n,r,a,c)],[])}function _g(e,t,n,r,a,s){let m=sc(r,s,a),c=Gg(e,t,n,r,a,m);return i.IsEqual(c.length,1)?c[0]:ge(c)}function Jr(e,t,n,r){let a=Te(e,t,r),s=pc(e,n,r),m=s[0],c=s[1];return wt(c)?Ug(t,m)?Tn(Ve(m),a):_g(e,t,Ve(m),c.parameters,c.expression,a):Tn(n,a)}function Tn(e,t){return p.Create({"~kind":"Call"},{type:"call",target:e,arguments:t},{})}function lc(e,t){return Jr({},D([],[]),e,t)}function Zt(e){return x(e,"Call")}function Hg(e){return p.Discard(e,["~immutable"])}function fc(e,t){return p.Update(Hg(e),{},t)}function dc(e,t,n,r){let a=l(e,t,n);return fc(a,r)}function xc(e,t){return e(t)}function Ic(e,t){return i.IsString(t)?R(xc(e,t)):R(t)}function yc(e,t){let n=Ie(t);return Qe(e,n)}function gc(e,t){let n=t.map(r=>Qe(e,r));return k(n)}function Qe(e,t){return w(t)?Ic(e,t.const):Z(t)?yc(e,t.pattern):I(t)?gc(e,t.anyOf):t}function hr(e,t={}){return y("Capitalize",[e],t)}function $c(e,t={}){return Wa(e,t)}function br(e,t={}){return y("Lowercase",[e],t)}function hc(e,t={}){return Va(e,t)}function Tr(e,t={}){return y("Uncapitalize",[e],t)}function bc(e,t={}){return Za(e,t)}function Er(e,t={}){return y("Uppercase",[e],t)}function Tc(e,t={}){return Ja(e,t)}var zg=e=>e[0].toUpperCase()+e.slice(1),Bg=e=>e.toLowerCase(),Wg=e=>e[0].toLowerCase()+e.slice(1),Vg=e=>e.toUpperCase();function Wa(e,t){return T([e])?p.Update(Qe(zg,e),{},t):hr(e,t)}function Va(e,t){return T([e])?p.Update(Qe(Bg,e),{},t):br(e,t)}function Za(e,t){return T([e])?p.Update(Qe(Wg,e),{},t):Tr(e,t)}function Ja(e,t){return T([e])?p.Update(Qe(Vg,e),{},t):Er(e,t)}function Ec(e,t,n,r){let a=l(e,t,n);return Wa(a,r)}function kc(e,t,n,r){let a=l(e,t,n);return Va(a,r)}function Pc(e,t,n,r){let a=l(e,t,n);return Za(a,r)}function Oc(e,t,n,r){let a=l(e,t,n);return Ja(a,r)}function kr(e,t,n,r,a={}){return y("Conditional",[e,t,n,r],a)}function Cc(e,t,n,r,a={}){return Qa({},D([],[]),e,t,n,r,a)}function Zg(e,t,n,r,a,s){let m=ie(e,n,r);return $.IsExtendsUnion(m)?k([l(m.inferred,t,a),l(e,t,s)]):$.IsExtendsTrue(m)?l(m.inferred,t,a):l(e,t,s)}function Qa(e,t,n,r,a,s,m){return T([n,r])?p.Update(Zg(e,t,n,r,a,s),{},m):kr(n,r,a,s,m)}function Rc(e,t,n,r,a,s,m){let c=l(e,t,n),f=l(e,t,r);return Qa(e,t,c,f,a,s,m)}function Pr(e,t={}){return y("ConstructorParameters",[e],t)}function vc(e,t={}){return Xa(e,t)}function Jg(e){let t=ee(e)?e.parameters:[],n=pt({},D([],[]),t);return J(n)}function Xa(e,t){return T([e])?p.Update(Jg(e),{},t):Pr(e,t)}function Mc(e,t,n,r){let a=l(e,t,n);return Xa(a,r)}function Or(e,t,n={}){return y("Exclude",[e,t],n)}function Sc(e,t,n={}){return Ln(e,t,n)}function Ln(e,t,n){return T([e,t])?p.Update(lr(e,t),{},n):Or(e,t,n)}function wc(e,t,n,r,a){let s=l(e,t,n),m=l(e,t,r);return Ln(s,m,a)}function Cr(e,t,n={}){return y("Extract",[e,t],n)}function jc(e,t,n={}){return Ya(e,t,n)}function Qg(e,t){let n=ie({},e,t);return $.IsExtendsTrueLike(n)?[e]:[]}function Xg(e,t){return e.reduce((n,r)=>[...n,...Qg(r,t)],[])}function Ac(e,t){let n=Oe(e),r=I(n)?n.anyOf:[n],a=Xg(r,t);return ge(a)}function Ya(e,t,n){return T([e,t])?p.Update(Ac(e,t),{},n):Cr(e,t,n)}function Lc(e,t,n,r,a){let s=l(e,t,n),m=l(e,t,r);return Ya(s,m,a)}function Yg(e){return e.reduce((t,n)=>ir(n)?[...t,R(n)]:t,[])}function Jt(e){let t=Yg(e);return k(t)}function En(e,t,n={}){return y("Index",[e,t],n)}function qc(e,t,n={}){let r=i.IsArray(t)?Jt(t):t;return eo(e,r,n)}function Fc(e,t){let n=Ge(e,t);return Ee(n)}function Dc(e,t,n){let r=Se(e,t,n);return Ee(r)}function e$(e,t){let n=i.Keys(e).filter(g=>!i.HasPropertyKey(t,g)),r=i.Keys(t).filter(g=>!i.HasPropertyKey(e,g)),a=i.Keys(e).filter(g=>i.HasPropertyKey(t,g)),s=n.reduce((g,q)=>({...g,[q]:e[q]}),{}),m=r.reduce((g,q)=>({...g,[q]:t[q]}),{}),c=a.reduce((g,q)=>({...g,[q]:K([e[q],t[q]])}),{}),f=p.Assign(s,m);return p.Assign(f,c)}function Nc(e){return e.reduce((t,n)=>e$(t,Ee(n)),{})}function Uc(e){let t=zi(J(e));return Ee(t)}function t$(e,t){return i.Keys(e).filter(a=>a in t).reduce((a,s)=>({...a,[s]:ge([e[s],t[s]])}),{})}function Kc(e,t){return i.ShiftLeft(e,(n,r)=>Kc(r,t$(t,Ee(n))),()=>t)}function Gc(e){return i.ShiftLeft(e,(t,n)=>Kc(n,Ee(t)),()=>B())}function Ee(e){return oe(e)?Fc(e.$defs,e.$ref):_(e)?Dc(e.if,e.then,e.else):C(e)?Nc(e.allOf):I(e)?Gc(e.anyOf):F(e)?Uc(e.items):S(e)?e.properties:{}}function Qt(e){let t=Ee(e);return h(t)}var n$=new RegExp("^(?:0|[1-9][0-9]*)$");function Xt(e){let t=`${e}`;return n$.test(t)?parseInt(t):e}function r$(e){return R(Xt(e))}function _c(e){return e.map(t=>Hc(t))}function Hc(e){return C(e)?pe(_c(e.allOf)):I(e)?k(_c(e.anyOf)):w(e)?r$(e.const):e}function zc(e,t){let n=Hc(t),r=ie({},n,ye());return $.IsExtendsTrueLike(r)?e:w(t)&&i.IsEqual(t.const,"length")?ye():L()}function Bc(e,t){let n=Ge(e,t);return $e(n)}function Wc(e,t,n){let r=Se(e,t,n);return $e(r)}function Vc(e){let t=be(e);return $e(t)}function Zc(e){let t=K(e);return $e(t)}function Jc(e){return[`${e}`]}function Qc(e){let t=Ie(e);return $e(t)}function Xc(e){return e.reduce((t,n)=>[...t,...$e(n)],[])}function $e(e){return oe(e)?Bc(e.$defs,e.$ref):_(e)?Wc(e.if,e.then,e.else):ue(e)?Vc(e.enum):C(e)?Zc(e.allOf):w(e)?Jc(e.const):Z(e)?Qc(e.pattern):I(e)?Xc(e.anyOf):[]}function Yt(e){return $e(e)}function qn(e,t){return t.map(n=>Fn(e,n))}function Fn(e,t){return U(t)?he(Fn(e,t.items)):ee(t)?Ae(qn(e,t.parameters),Fn(e,t.instanceType)):te(t)?Le(qn(e,t.parameters),Fn(e,t.returnType)):F(t)?J(qn(e,t.items)):I(t)?k(qn(e,t.anyOf)):C(t)?pe(qn(e,t.allOf)):yr(t)?h(e):t}function Yc(e,t){return Fn(e,t)}function a$(e,t){let n=t in e?e[t]:L();return Yc(e,n)}function el(e,t){return t.reduce((n,r)=>[...n,a$(e,r)],[])}function o$(e,t){let n=Yt(t),r=el(e,n);return ge(r)}var i$=new RegExp(at);function s$(e){return e.filter(n=>i$.test(n))}function m$(e){let t=Yn(e),n=s$(t),r=el(e,n);return ge(r)}function tl(e,t){return V(t)?m$(e):o$(e,t)}function p$(e){return R(Xt(e))}function nl(e){return e.map(t=>to(t))}function to(e){return C(e)?pe(nl(e.allOf)):I(e)?k(nl(e.anyOf)):w(e)?p$(e.const):e}function u$(e,t){return e.reduceRight((n,r,a)=>{let s=ie({},R(a),t);return $.IsExtendsTrueLike(s)?[r,...n]:n},[])}function c$(e,t){let n=to(t),r=u$(e,n);return Ze(r)}function l$(e){return Ze(e)}function rl(e,t){return w(t)&&i.IsEqual(t.const,"length")?R(e.length):V(t)||ce(t)?l$(e):c$(e,t)}function al(e,t){return U(e)?zc(e.items,t):S(e)?tl(e.properties,t):F(e)?rl(e.items,t):L()}function f$(e){return oe(e)||_(e)||C(e)||I(e)?Qt(e):e}function eo(e,t,n){return T([e,t])?p.Update(al(f$(e),t),{},n):En(e,t,n)}function ol(e,t,n,r,a){let s=l(e,t,n),m=l(e,t,r);return eo(s,m,a)}function Rr(e,t={}){return y("InstanceType",[e],t)}function il(e,t={}){return no(e,t)}function d$(e){return ee(e)?e.instanceType:L()}function no(e,t){return T([e])?p.Update(d$(e),{},t):Rr(e,t)}function sl(e,t,n,r={}){let a=l(e,t,n);return no(a,r)}function kn(e,t={}){return y("KeyOf",[e],t)}function ml(e,t={}){return ro(e,t)}function pl(){return k([ye(),Pe(),Ft()])}function ul(e){return ye()}function x$(e){return e.reduce((n,r)=>ir(r)?[...n,R(Xt(r))]:B(),[])}function cl(e){let t=i.Keys(e),n=x$(t);return Ze(n)}function ll(e){return Ut(e)}function fl(e){let t=e.map((n,r)=>R(r));return Ze(t)}function dl(e){return W(e)?pl():U(e)?ul(e.items):S(e)?cl(e.properties):se(e)?ll(e):F(e)?fl(e.items):L()}function I$(e){return oe(e)||_(e)||C(e)||I(e)?Qt(e):e}function ro(e,t){return T([e])?p.Update(dl(I$(e)),{},t):kn(e,t)}function xl(e,t,n,r){let a=l(e,t,n);return ro(a,r)}function hn(e,t,n,r,a={}){return y("Mapped",[e,t,n,r],a)}function Il(e,t,n,r,a={}){return ao({},D([],[]),e,t,n,r,a)}function y$(e){let t=Ie(e);return Qr(t)}function g$(e){return e.reduce((t,n)=>[...t,...Qr(n)],[])}function $$(e){let t=be(e);return Qr(t)}function h$(e){return i.IsNumber(e)?[R(`${e}`)]:[R(e)]}function Qr(e){return ue(e)?$$(e.enum):w(e)?h$(e.const):Z(e)?y$(e.pattern):I(e)?g$(e.anyOf):[e]}function yl(e){return Qr(e)}function b$(e){return Z(e)?Ie(e.pattern):e}function T$(e,t,n,r,a,s){let m=p.Assign(e,{[n.name]:r}),c=l(m,t,a),f=b$(c),E=l(m,t,s);return Pi(f)||Oi(f)?{[f.const]:E}:{}}function E$(e,t,n,r,a,s){return r.reduce((m,c)=>[...m,T$(e,t,n,c,a,s)],[])}function k$(e){return e.reduce((t,n)=>[...t,h(n)],[])}function gl(e,t,n,r,a,s){let m=yl(r),c=E$(e,t,n,m,a,s),f=k$(c);return K(f)}function ao(e,t,n,r,a,s,m){return T([r])?p.Update(gl(e,t,n,r,a,s),{},m):hn(n,r,a,s,m)}function $l(e,t,n,r,a,s,m){let c=l(e,t,r);return ao(e,t,n,c,a,s,m)}function P$(e,t,n){let r=p.Assign(e,t);return i.Keys(t).filter(s=>n.includes(s)).reduce((s,m)=>({...s,[m]:ec(r,m,t[m])}),{})}function O$(e,t,n){let r=p.Assign(e,t);return i.Keys(t).filter(s=>!n.includes(s)).reduce((s,m)=>({...s,[m]:l(r,D([],[]),t[m])}),{})}function C$(e,t,n){let r=Ju(t),a=P$(e,t,r),s=O$(e,t,r),m={...a,...s};return p.Update(m,{},n)}function Xr(e,t,n,r){return C$(e,n,r)}function vr(e,t={}){return y("NonNullable",[e],t)}function hl(e,t={}){return oo(e,t)}function R$(e){let t=k([Lt(),Kt()]);return Ln(e,t,{})}function oo(e,t){return T([e])?p.Update(R$(e),{},t):vr(e,t)}function bl(e,t,n,r){let a=l(e,t,n);return oo(a,r)}function Mr(e,t,n={}){return y("Omit",[e,t],n)}function Tl(e,t,n={}){let r=i.IsArray(t)?Jt(t):t;return io(e,r,n)}function Yr(e){let t=Qt(e);return S(t)?t.properties:B()}function v$(e,t){return i.Keys(e).reduce((r,a)=>t.includes(a)?r:{...r,[a]:e[a]},{})}function El(e,t){let n=Yr(e),r=Yt(t),a=v$(n,r);return h(a)}function io(e,t,n){return T([e,t])?p.Update(El(e,t),{},n):Mr(e,t,n)}function kl(e,t,n,r,a){let s=l(e,t,n),m=l(e,t,r);return io(s,m,a)}function Sr(e,t={}){return y("Parameters",[e],t)}function Pl(e,t={}){return so(e,t)}function M$(e){let t=te(e)?e.parameters:[],n=pt({},D([],[]),t);return J(n)}function so(e,t){return T([e])?p.Update(M$(e),{},t):Sr(e,t)}function Ol(e,t,n,r){let a=l(e,t,n);return so(a,r)}function wr(e,t={}){return y("Partial",[e],t)}function Cl(e,t={}){return mo(e,t)}function Rl(e,t){let n=Ge(e,t),r=_e(n);return Fe(p.Assign(e,{[t]:r}),t)}function vl(e,t,n){let r=Se(e,t,n);return _e(r)}function Ml(e){let t=K(e);return _e(t)}function Sl(e){let t=e.map(n=>_e(n));return k(t)}function wl(e){let t=i.Keys(e).reduce((r,a)=>({...r,[a]:yt(e[a])}),{});return h(t)}function _e(e){return oe(e)?Rl(e.$defs,e.$ref):_(e)?vl(e.if,e.then,e.else):C(e)?Ml(e.allOf):I(e)?Sl(e.anyOf):S(e)?wl(e.properties):h({})}function mo(e,t){return T([e])?p.Update(_e(e),{},t):wr(e,t)}function jl(e,t,n,r){let a=l(e,t,n);return mo(a,r)}function jr(e,t,n={}){return y("Pick",[e,t],n)}function Al(e,t,n={}){let r=i.IsArray(t)?Jt(t):t;return po(e,r,n)}function S$(e,t){return i.Keys(e).reduce((r,a)=>t.includes(a)?p.Assign(r,{[a]:e[a]}):r,{})}function Ll(e,t){let n=Yr(e),r=Yt(t),a=S$(n,r);return h(a)}function po(e,t,n){return T([e,t])?p.Update(Ll(e,t),{},n):jr(e,t,n)}function ql(e,t,n,r,a){let s=l(e,t,n),m=l(e,t,r);return po(s,m,a)}function Ar(e,t={}){return y("ReadonlyObject",[e],t)}function uo(e,t={}){return co(e,t)}var Fl=uo;function Dl(e){return At(he(e))}function Nl(e,t){let n=Ge(e,t),r=He(n);return Fe(p.Assign(e,{[t]:r}),t)}function Ul(e,t,n){let r=Se(e,t,n);return He(r)}function Kl(e){let t=K(e);return He(t)}function Gl(e){let t=i.Keys(e).reduce((r,a)=>({...r,[a]:ht(e[a])}),{});return h(t)}function _l(e){return At(J(e))}function Hl(e){let t=e.map(n=>He(n));return k(t)}function He(e){return U(e)?Dl(e.items):oe(e)?Nl(e.$defs,e.$ref):_(e)?Ul(e.if,e.then,e.else):C(e)?Kl(e.allOf):S(e)?Gl(e.properties):F(e)?_l(e.items):I(e)?Hl(e.anyOf):e}function co(e,t){return T([e])?p.Update(He(e),{},t):Ar(e)}function zl(e,t,n,r){let a=l(e,t,n);return co(a,r)}function Bl(e,t,n,r){return t.visited.includes(r)?n:r in e?l(e,D(t.callstack,[...t.visited,r]),e[r]):n}function Wl(e,t){let n=Ge(e,t),r=ze(n);return Fe(p.Assign(e,{[t]:r}),t)}function Vl(e,t,n){let r=Se(e,t,n);return ze(r)}function Zl(e){let t=K(e);return ze(t)}function Jl(e){let t=e.map(n=>ze(n));return k(t)}function Ql(e){let t=i.Keys(e).reduce((r,a)=>({...r,[a]:cr(e[a])}),{});return h(t)}function ze(e){return oe(e)?Wl(e.$defs,e.$ref):_(e)?Vl(e.if,e.then,e.else):C(e)?Zl(e.allOf):I(e)?Jl(e.anyOf):S(e)?Ql(e.properties):h({})}function Lr(e,t={}){return y("Required",[e],t)}function Xl(e,t={}){return lo(e,t)}function lo(e,t){return T([e])?p.Update(ze(e),{},t):Lr(e,t)}function Yl(e,t,n,r){let a=l(e,t,n);return lo(a,r)}function qr(e,t={}){return y("ReturnType",[e],t)}function ef(e,t={}){return fo(e,t)}function w$(e){return te(e)?e.returnType:L()}function fo(e,t){return T([e])?p.Update(w$(e),{},t):qr(e,t)}function tf(e,t,n,r={}){let a=l(e,t,n);return fo(a,r)}function Fr(e,t){return y("With",[e,t],{})}function nf(e,t){return xo(e,t)}function xo(e,t){return T([e])?p.Update(e,{},t):Fr(e,t)}function rf(e,t,n,r){let a=l(e,t,n);return xo(a,r)}function j$(e){return ot(e)?F(e.items)?Io(e.items.items):z(e.items)?[e]:ne(e.items)?[e]:[L()]:[e]}function Io(e){return e.reduce((n,r)=>[...n,...j$(r)],[])}function D(e,t){return{callstack:e,visited:t}}function T(e){return i.ShiftLeft(e,(t,n)=>ne(t)?!1:T(n),()=>!0)}function Mn(e,t,n){return i.Keys(n).reduce((r,a)=>({...r,[a]:l(e,t,n[a])}),{})}function pt(e,t,n){let r=Te(e,t,n);return Io(r)}function Te(e,t,n){return n.map(r=>l(e,t,r))}function A$(e,t){let n=me(e)?mn(t,{}):t,r=bt(e)?sn(n,{}):n;return $t(e)?Dn(r,{}):r}function L$(e,t,n,r,a){return i.IsEqual(n,"AddImmutable")?af(e,t,r[0],a):i.IsEqual(n,"RemoveImmutable")?dc(e,t,r[0],a):i.IsEqual(n,"AddReadonly")?ei(e,t,r[0],a):i.IsEqual(n,"RemoveReadonly")?Ui(e,t,r[0],a):i.IsEqual(n,"AddOptional")?ti(e,t,r[0],a):i.IsEqual(n,"RemoveOptional")?_i(e,t,r[0],a):i.IsEqual(n,"Capitalize")?Ec(e,t,r[0],a):i.IsEqual(n,"Conditional")?Rc(e,t,r[0],r[1],r[2],r[3],a):i.IsEqual(n,"ConstructorParameters")?Mc(e,t,r[0],a):i.IsEqual(n,"Evaluate")?rc(e,t,r[0],a):i.IsEqual(n,"Exclude")?wc(e,t,r[0],r[1],a):i.IsEqual(n,"Extract")?Lc(e,t,r[0],r[1],a):i.IsEqual(n,"Index")?ol(e,t,r[0],r[1],a):i.IsEqual(n,"InstanceType")?sl(e,t,r[0],a):i.IsEqual(n,"Interface")?Bu(e,t,r[0],r[1],a):i.IsEqual(n,"KeyOf")?xl(e,t,r[0],a):i.IsEqual(n,"Lowercase")?kc(e,t,r[0],a):i.IsEqual(n,"Mapped")?$l(e,t,r[0],r[1],r[2],r[3],a):i.IsEqual(n,"Module")?Xr(e,t,r[0],a):i.IsEqual(n,"NonNullable")?bl(e,t,r[0],a):i.IsEqual(n,"Pick")?ql(e,t,r[0],r[1],a):i.IsEqual(n,"Parameters")?Ol(e,t,r[0],a):i.IsEqual(n,"Partial")?jl(e,t,r[0],a):i.IsEqual(n,"Omit")?kl(e,t,r[0],r[1],a):i.IsEqual(n,"ReadonlyObject")?zl(e,t,r[0],a):i.IsEqual(n,"Record")?is(e,t,r[0],r[1],a):i.IsEqual(n,"Required")?Yl(e,t,r[0],a):i.IsEqual(n,"ReturnType")?tf(e,t,r[0],a):i.IsEqual(n,"TemplateLiteral")?uu(e,t,r[0],a):i.IsEqual(n,"Uncapitalize")?Pc(e,t,r[0],a):i.IsEqual(n,"Uppercase")?Oc(e,t,r[0],a):i.IsEqual(n,"With")?rf(e,t,r[0],r[1]):y(n,r,a)}function q$(e,t,n){let r=ne(n)?Bl(e,t,n,n.$ref):U(n)?he(l(e,t,n.items),Xn(n)):Zt(n)?Jr(e,t,n.target,n.arguments):ee(n)?Ae(Te(e,t,n.parameters),l(e,t,n.instanceType),ni(n)):te(n)?Le(Te(e,t,n.parameters),l(e,t,n.returnType),ri(n)):_(n)?gt(l(e,t,n.if),l(e,t,n.then),l(e,t,n.else),pi(n)):C(n)?pe(Te(e,t,n.allOf),di(n)):S(n)?h(Mn(e,t,n.properties),si(n)):se(n)?ss(Ce(n),l(e,t,fe(n))):ot(n)?kt(l(e,t,n.items)):F(n)?J(pt(e,t,n.items),Ni(n)):I(n)?k(Te(e,t,n.anyOf),Ri(n)):n;return A$(n,r)}function l(e,t,n){return Ye(n)?L$(e,t,n.action,n.parameters,n.options):q$(e,t,n)}function yo(e,t){return l(e,D([],[]),t)}function F$(e){return p.Update(e,{"~immutable":!0},{})}function Dn(e,t){return p.Update(F$(e),{},t)}function af(e,t,n,r){let a=l(e,t,n);return Dn(a,r)}function mp(e,t={}){return y("AddImmutable",[e],t)}function At(e,t={}){return Dn(e,t)}function pp(e,t={}){return y("Evaluate",[e],t)}function of(e,t={}){return za(e,t)}function up(e,t={}){return y("Module",[e],t)}function sf(e,t={}){return Xr({},D([],[]),e,t)}function mf(...e){let[t,n,r]=De.Match(e,{2:(m,c)=>i.IsString(m)?[{},m,c]:[m,c,{}],3:(m,c,f)=>[m,c,f],1:m=>[{},m,{}]}),a=ou(n),s=i.IsArray(a)&&i.IsEqual(a.length,2)?l(t,D([],[]),a[0]):L();return p.Update(s,{},r)}var A={};lt(A,{Any:()=>jt,Array:()=>he,BigInt:()=>ln,Boolean:()=>ar,Call:()=>lc,Capitalize:()=>$c,Codec:()=>rr,Conditional:()=>Cc,Constructor:()=>Ae,ConstructorParameters:()=>vc,Cyclic:()=>Fe,Decode:()=>gi,DecodeBuilder:()=>cn,Dependent:()=>gt,Encode:()=>$i,EncodeBuilder:()=>un,Enum:()=>fi,Evaluate:()=>of,Exclude:()=>Sc,Extends:()=>ie,ExtendsResult:()=>$,Extract:()=>jc,Function:()=>Le,Generic:()=>et,Identifier:()=>fn,Immutable:()=>hi,Index:()=>qc,Infer:()=>pn,InstanceType:()=>il,Instantiate:()=>yo,Integer:()=>Tt,Interface:()=>Wu,Intersect:()=>pe,IsAny:()=>W,IsArray:()=>U,IsBigInt:()=>Ue,IsBoolean:()=>ke,IsCall:()=>Zt,IsCodec:()=>nr,IsConstructor:()=>ee,IsCyclic:()=>oe,IsDependent:()=>_,IsEnum:()=>ue,IsEnumValue:()=>li,IsFunction:()=>te,IsGeneric:()=>wt,IsIdentifier:()=>ki,IsImmutable:()=>$t,IsInfer:()=>z,IsInteger:()=>ce,IsIntersect:()=>C,IsKind:()=>x,IsLiteral:()=>w,IsNever:()=>tt,IsNull:()=>qt,IsNumber:()=>V,IsObject:()=>S,IsOptional:()=>me,IsParameter:()=>Ci,IsReadonly:()=>bt,IsRecord:()=>se,IsRef:()=>ne,IsRefine:()=>Ia,IsRest:()=>ot,IsSchema:()=>Q,IsString:()=>le,IsSymbol:()=>nt,IsTemplateLiteral:()=>Z,IsThis:()=>yr,IsTuple:()=>F,IsUndefined:()=>Gt,IsUnion:()=>I,IsUnknown:()=>X,IsUnsafe:()=>tr,IsVoid:()=>Ke,KeyOf:()=>ml,Literal:()=>R,Lowercase:()=>hc,Mapped:()=>Il,Module:()=>sf,Never:()=>L,NonNullable:()=>hl,Null:()=>Lt,Number:()=>ye,Object:()=>h,Omit:()=>Tl,Optional:()=>oi,Parameter:()=>Et,Parameters:()=>Pl,Partial:()=>Cl,Pick:()=>Al,Readonly:()=>bi,ReadonlyObject:()=>uo,ReadonlyType:()=>Fl,Record:()=>dr,RecordKey:()=>Ut,RecordPattern:()=>Ce,RecordValue:()=>fe,Ref:()=>Ve,Refine:()=>Ti,Required:()=>Xl,Rest:()=>kt,ReturnType:()=>ef,Script:()=>mf,String:()=>Pe,Symbol:()=>Ft,TemplateLiteral:()=>lu,This:()=>Ir,Tuple:()=>J,Uncapitalize:()=>bc,Undefined:()=>Kt,Union:()=>k,Unknown:()=>re,Unsafe:()=>mi,Uppercase:()=>Tc,Void:()=>gr,With:()=>nf});function Rt(e){return`'${e.replace(/'/g,`'"'"'`)}'`}function go(e){return`'${e.replace(/'/g,"'\\''")}'`}async function ea(e,t,n){let r=Be();if(!r)throw new Error(`HPC not configured. ${St}`);let s=`${go(Do())} -batch -pw ${go(r.password)} ${r.username}@${r.host} ${go(t)}`,m=n?.timeout??6e4,c=await e.exec(Fo(),["-c",s],{signal:n?.signal,timeout:m});return{stdout:c.stdout??"",stderr:c.stderr??"",exitCode:c.code??0,killed:c.killed}}function $o(e){let t=`${e.stdout}
8
+ ${e.stderr}`;return e.exitCode!==0||/FATAL ERROR/i.test(t)}function ho(e){return e.killed?"HPC command timed out.":(e.stderr||e.stdout).trim()||`HPC command failed (exit ${e.exitCode})`}function D$(e){return/(?:^|\s)-F(?:\s|$)/.test(e)||/--fixed-strings/.test(e)}function N$(e){return/(?:^|\s)-E(?:\s|$)/.test(e)||/--extended-regexp/.test(e)}function U$(e){return!!(e.includes("|")||/[()[\]+]/.test(e)||/(?:^|[^\\])\?/.test(e))}function K$(e){return(e.split("/").pop()??e).includes(".")&&!e.endsWith("/")}function pf(e,t,n,r){let a=e.trim();return a=a.replace(/-(?:A|B|C)\s*\d+/g,"").trim(),!D$(a)&&!N$(a)&&U$(t)&&(a+=" -E"),r.context!==void 0&&r.context>0?a+=` -C ${r.context}`:(r.after&&r.after>0&&(a+=` -A ${r.after}`),r.before&&r.before>0&&(a+=` -B ${r.before}`)),r.recursive!==!1&&!K$(n)?/\s-r\b/.test(a)||(a+=" -r"):a=a.replace(/\s*-r\b/g,"").trim(),a.replace(/\s+/g," ").trim()}import{keyHint as G$}from"@earendil-works/pi-coding-agent";import{Text as uf}from"@earendil-works/pi-tui";function _$(e){let t=e.content.find(n=>n.type==="text");return t?.type==="text"?t.text??"":""}function H$(e,t,n){if(t.isPartial)return n.fg("warning","Connecting to HPC...");let r=e.details??{},a=_$(e).trim(),s=r.exitCode;if(r.error||s!==void 0&&s!==0)return n.fg("error",a||`HPC command failed (exit ${s??"?"})`);if(!a)return n.fg("dim","(no output)");let m=a.split(`
9
+ `),c=t.expanded?m.length:Co,f=m.slice(0,c),E=m.length-c,g=`
10
+ ${f.map(q=>n.fg("toolOutput",q)).join(`
11
+ `)}`;return E>0&&(g+=`${n.fg("muted",`
12
+ ... (${E} more lines,`)} ${G$("app.tools.expand","to expand")})`),r.truncatedForAgent&&(g+=`
13
+ ${n.fg("warning","[Truncated for agent \u2014 narrow path or pattern]")}`),g}function ta(e,t,n){let r=n.lastComponent??new uf("",0,0);return r.setText(e),r}function cf(e,t,n,r){let a=r.lastComponent??new uf("",0,0);return a.setText(H$(e,t,n)),a}function lf(e){if(Gn())return;wo(!0);let t=cf;e.registerTool({name:"ls_hpc",label:"List HPC Directory",description:"List files and directories on the remote HPC system. Use recursive=true to list all files under a directory.",promptSnippet:"List or browse files on remote HPC",promptGuidelines:["Use ls_hpc when the user wants to explore directories on the remote HPC filesystem.","Use ls_hpc with recursive=true to enumerate files under a directory tree."],parameters:A.Object({path:A.Optional(A.String({description:"Directory on HPC. Defaults to home (~)."})),options:A.Optional(A.String({description:"Extra ls flags (e.g. -lh). Default: -la. Ignored when recursive=true."})),recursive:A.Optional(A.Boolean({description:"List all files recursively under path. Default: false."}))}),renderCall(n,r,a){let s=n.path||"~",m=n.recursive?" (recursive)":"",c=r.fg("toolTitle",r.bold("ls_hpc "))+r.fg("accent",s)+r.fg("muted",m);return ta(c,r,a)},renderResult:t,async execute(n,r,a,s){s?.({content:[{type:"text",text:"Listing on HPC..."}],details:void 0});let m=r.path||"~",c=r.recursive??!1,f=r.options||"-la",E=c?`find ${Rt(m)} -type f 2>/dev/null | head -n 50000 | sort`:`ls ${f} ${Rt(m)} 2>&1`,g=await ea(e,E,{signal:a});if($o(g))return{content:[{type:"text",text:ho(g)}],details:{exitCode:g.exitCode,path:m,recursive:c,error:!0},isError:!0};let q=(g.stdout||"").trim()||"(empty)";return{content:[{type:"text",text:q}],details:{exitCode:g.exitCode,path:m,recursive:c,lineCount:q.split(`
14
+ `).length}}}}),e.registerTool({name:"read_file_hpc",label:"Read HPC File",description:`Read a file from remote HPC. Supports offset/limit line range (max ${je} lines per call).`,promptSnippet:"Read file contents from remote HPC",promptGuidelines:["Use read_file_hpc to view source or config files stored on HPC.",`Use offset and limit to paginate large files (max ${je} lines per read).`],parameters:A.Object({path:A.String({description:"Absolute or relative file path on HPC."}),offset:A.Optional(A.Integer({description:"0-based starting line. Default: 0.",minimum:0})),limit:A.Optional(A.Integer({description:`Max lines to read (capped at ${je}). Default: ${je}.`,minimum:1,maximum:je}))}),renderCall(n,r,a){let s=n.path,m=n.offset??0,c=n.limit??je,f=r.fg("toolTitle",r.bold("read_file_hpc "))+r.fg("accent",s)+r.fg("warning",`:${m+1}${c?`-${m+c}`:""}`);return ta(f,r,a)},renderResult:t,async execute(n,r,a,s){s?.({content:[{type:"text",text:"Reading from HPC..."}],details:void 0});let m=r.path,c=Math.max(0,r.offset??0),f=r.limit??je;f>je&&(f=je);let E=c+1,g=c+f,q=`sed -n '${E},${g}p' ${Rt(m)} 2>&1`,Y=await ea(e,q,{signal:a}),we=Y.stdout??"",ut=Y.stderr??"";if(Y.exitCode!==0)return{content:[{type:"text",text:`Error reading ${m}:
15
+ ${ut||we||"(no output)"}`}],details:{exitCode:Y.exitCode,path:m,error:!0}};if(!we.trim())return{content:[{type:"text",text:`No content in lines ${E}-${g} of ${m}`}],details:{path:m,offset:c,limit:f,empty:!0}};let de=we.split(`
16
+ `).length;return{content:[{type:"text",text:`${m} (lines ${E}-${c+de}):
17
+ `+we}],details:{path:m,offset:c,limit:f,lines:de}}}}),e.registerTool({name:"grep_hpc",label:"Search HPC Files",description:"Search file contents on HPC with grep. Patterns with | (alternation) auto-use grep -E. Use options '-F' for literal/fixed-string search. Max runtime 2 minutes.",promptSnippet:"Grep/search text in remote HPC files",promptGuidelines:["Use grep_hpc to find strings or regex patterns in HPC files.","For alternation (foo|bar), use one pattern with | \u2014 grep -E is added automatically.","Use options '-F' when the pattern must be matched literally (no regex).","Use after/before/context for surrounding lines (like grep -A/-B/-C)."],parameters:A.Object({pattern:A.String({description:"Search pattern. Use | for alternation (e.g. foo|bar)."}),path:A.Optional(A.String({description:"File or directory on HPC. Default: ."})),options:A.Optional(A.String({description:"Extra grep flags (e.g. -i, -l, -E). Default base: -rn."})),file_pattern:A.Optional(A.String({description:"Glob for filenames to search, e.g. '*.csv' or '*.py' (uses grep --include, case-insensitive via find when non-recursive)."})),after:A.Optional(A.Integer({description:"Lines after match (grep -A).",minimum:0})),before:A.Optional(A.Integer({description:"Lines before match (grep -B).",minimum:0})),context:A.Optional(A.Integer({description:"Lines before and after (grep -C). Overrides after/before.",minimum:0})),recursive:A.Optional(A.Boolean({description:"Search recursively (-r). Default true for directories."}))}),renderCall(n,r,a){let s=r.fg("toolTitle",r.bold("grep_hpc "));return s+=r.fg("accent",`"${n.pattern}"`),n.path&&(s+=r.fg("toolOutput",` in ${n.path}`)),n.file_pattern&&(s+=r.fg("toolOutput",` (${n.file_pattern})`)),ta(s,r,a)},renderResult:t,async execute(n,r,a,s){s?.({content:[{type:"text",text:"Searching on HPC..."}],details:void 0});let m=r.pattern,c=r.path||".",f=pf(r.options||"-n",m,c,{recursive:r.recursive,context:r.context,after:r.after,before:r.before}),E=Rt(m),g=Rt(c),q;if(r.file_pattern){let Re=r.file_pattern.trim(),ct=Rt(Re),vt=f.replace(/--include(?:=\S+|\s+\S+)?/g,"").trim();if(r.recursive===!1){let ra=Re.includes("*")||Re.includes("?")?`-iname ${ct}`:`-name ${ct}`;q=`find ${g} -maxdepth 1 -type f ${ra} -exec grep -Hn ${vt} -e ${E} {} + 2>&1`}else/\s-r\b/.test(vt)||(vt+=" -r"),q=`grep ${vt} --include=${ct} -e ${E} ${g} 2>&1`}else q=`grep ${f} -e ${E} ${g} 2>&1`;q+=" || true";let Y=await ea(e,q,{signal:a,timeout:oa});if(Y.killed)return{content:[{type:"text",text:`grep_hpc timed out after ${oa/1e3}s. Narrow the path, use file_pattern, or refine the pattern.`}],details:{path:c,pattern:m,timedOut:!0,error:!0}};if($o(Y))return{content:[{type:"text",text:ho(Y)}],details:{path:c,pattern:m,file_pattern:r.file_pattern,exitCode:Y.exitCode,error:!0},isError:!0};let we=(Y.stdout||"").trim(),ut=(Y.stderr||"").trim();if(!we){let Re=r.file_pattern?`${c} (files: ${r.file_pattern})`:c;return ut&&/no such file|not found|cannot access/i.test(ut)?{content:[{type:"text",text:`grep_hpc failed:
18
+ ${ut}`}],details:{path:c,pattern:m,error:!0},isError:!0}:{content:[{type:"text",text:`No matches for ${JSON.stringify(m)} in ${Re}${f.includes("-E")?" (extended regex)":""}`}],details:{path:c,pattern:m,file_pattern:r.file_pattern,matches:0,grepOptions:f}}}let de=W$(we,{maxLines:B$,maxBytes:z$}),en=de.content,Un={path:c,pattern:m,grepOptions:f,matches:we.split(`
19
+ `).filter(Re=>Re.trim()).length,exitCode:Y.exitCode};if(de.truncated){Un.truncatedForAgent=!0;let Re=de.totalLines-de.outputLines,ct=de.totalBytes-de.outputBytes;en+=` | [Output truncated for agent: showing ${de.outputLines} of ${de.totalLines} lines (${bo(de.outputBytes)} of ${bo(de.totalBytes)}). ${Re} lines (${bo(ct)}) omitted. Narrow search path or pattern.]`}return{content:[{type:"text",text:en}],details:Un}}})}var V$=new Set(Kn);function Z$(e){return V$.has(e)}function To(e){return e.getActiveTools().map(n=>typeof n=="string"?n:n.name)}function Eo(){return Mt()&&!!Be()}function J$(e){return Kn.some(t=>To(e).includes(t))}function na(e){return Eo()!==J$(e)}function Q$(e){Gn()||lf(e)}function X$(e,t){let n=To(e);if(t){if(n.length===0){Hn(!0);return}let r=new Set(n);for(let a of Kn)r.add(a);e.setActiveTools([...r])}else{let r=n.filter(a=>!Z$(a));r.length!==n.length&&e.setActiveTools(r)}Hn(na(e))}function Nn(e){let t=Eo();t&&Q$(e),X$(e,t)}function ff(e,t=0){let n=Eo(),r=To(e);if(n&&r.length===0&&t<8){queueMicrotask(()=>ff(e,t+1));return}Nn(e)}function df(e){for(let t of[0,50,150,400])setTimeout(()=>{(_n()||na(e))&&Nn(e)},t)}function ko(e,t,n){pa(n),qo(t,n),Nn(e)}function Po(e,t){let n=tn();ft(n),pa(n?Lo(n,t):!1),Hn(!0),ff(e)}function Y$(e){ft(tn()),e.registerCommand("hpc:on",{description:"Enable HPC tools for this project folder",handler:async(t,n)=>{let r=Be();if(!r){n.ui.notify(`HPC not configured. ${St}`,"error"),n.ui.notify("Or set HPC_USERNAME, HPC_HOST, and HPC_PASSWORD.","info");return}ko(e,n.cwd,!0),n.ui.notify(`HPC tools ON in this project (${r.username}@${r.host})`,"info"),n.ui.setStatus("hpc","HPC: ON")}}),e.registerCommand("hpc:off",{description:"Disable HPC tools for this project folder (other tools unchanged)",handler:async(t,n)=>{ko(e,n.cwd,!1),n.ui.notify("HPC tools OFF in this project","info"),n.ui.setStatus("hpc","HPC: OFF")}}),e.registerCommand("hpc:config",{description:St,handler:async(t,n)=>{let r=No(t??"");if(!r.ok){n.ui.notify(St,r.reason==="empty"?"info":"error"),r.reason==="empty"&&n.ui.notify("Or set HPC_USERNAME, HPC_HOST, and HPC_PASSWORD.","info");return}let{username:a,host:s,password:m}=r;ca({username:a,host:s,password:m}),n.ui.notify(`HPC configured: ${a}@${s}`,"info"),n.ui.setStatus("hpc",`HPC: ${Mt()?"ON":"OFF"}`)}}),e.on("session_start",async(t,n)=>{Po(e,n.cwd),(t.reason==="resume"||t.reason==="reload"||t.reason==="startup")&&df(e),Be()?n.ui.setStatus("hpc",`HPC: ${Mt()?"ON":"OFF"}`):Mt()&&n.ui.setStatus("hpc","HPC: ON (not configured)")}),e.on("session_tree",async(t,n)=>{Po(e,n.cwd)}),e.on("before_agent_start",async()=>{!_n()&&!na(e)||Nn(e)})}export{Y$ as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sreetej510/pi-hpc-tools",
3
- "version": "0.1.1",
3
+ "version": "0.1.4",
4
4
  "description": "Pi extension for exploring a remote HPC/SSH host (via plink) with ls/read/grep tools, gated per-project by /hpc:on and /hpc:off.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -15,24 +15,24 @@
15
15
  "remote"
16
16
  ],
17
17
  "files": [
18
- "src",
18
+ "dist",
19
19
  "README.md",
20
20
  "LICENSE"
21
21
  ],
22
22
  "pi": {
23
23
  "extensions": [
24
- "./src/index.ts"
24
+ "./dist/index.js"
25
25
  ]
26
26
  },
27
27
  "scripts": {
28
+ "build": "node ../../scripts/build-extension.mjs",
29
+ "prepublishOnly": "npm run build",
28
30
  "check": "biome check . && npm run typecheck",
29
31
  "format": "biome check --write .",
30
32
  "typecheck": "tsc --noEmit"
31
33
  },
32
- "dependencies": {
33
- "typebox": "^1.3.3"
34
- },
35
34
  "devDependencies": {
35
+ "typebox": "^1.3.3",
36
36
  "@biomejs/biome": "^2.5.3",
37
37
  "@earendil-works/pi-coding-agent": "^0.80.3",
38
38
  "@earendil-works/pi-tui": "^0.80.3",
package/src/config.ts DELETED
@@ -1,97 +0,0 @@
1
- /** hpc-config.json load/save + per-project enable state + shell/plink resolution. */
2
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
- import { dirname, join } from "node:path";
4
- import { AGENT_DIR, CONFIG_PATHS, DEFAULT_PLINK } from "./constants.js";
5
- import { getCurrentConfig, setCurrentConfig } from "./state.js";
6
- import type { HPCConfig } from "./types.js";
7
-
8
- function ensureDir(filePath: string): void {
9
- const dir = dirname(filePath);
10
- if (!existsSync(dir)) {
11
- mkdirSync(dir, { recursive: true });
12
- }
13
- }
14
-
15
- export function isProjectEnabled(config: HPCConfig, cwd: string): boolean {
16
- return (config.enabledProjects ?? []).includes(cwd);
17
- }
18
-
19
- export function setProjectEnabled(cwd: string, enabled: boolean): void {
20
- const config = getHPCConfig();
21
- if (!config) return;
22
- const projects = new Set(config.enabledProjects ?? []);
23
- if (enabled) {
24
- projects.add(cwd);
25
- } else {
26
- projects.delete(cwd);
27
- }
28
- saveConfig({ ...config, enabledProjects: [...projects] });
29
- }
30
-
31
- export function loadConfig(): HPCConfig | null {
32
- const username = process.env.HPC_USERNAME || process.env.HPC_USER;
33
- const host = process.env.HPC_HOST;
34
- const password = process.env.HPC_PASSWORD;
35
- if (username && host && password) {
36
- return { username, host, password };
37
- }
38
-
39
- for (const configPath of CONFIG_PATHS) {
40
- try {
41
- if (!existsSync(configPath)) continue;
42
- const config = JSON.parse(readFileSync(configPath, "utf-8")) as HPCConfig;
43
- if (config.username && config.host && config.password) {
44
- return config;
45
- }
46
- } catch {
47
- // try next path
48
- }
49
- }
50
- return null;
51
- }
52
-
53
- export function saveConfig(config: HPCConfig): void {
54
- const configPath = CONFIG_PATHS[0];
55
- ensureDir(configPath);
56
- writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
57
- setCurrentConfig(config);
58
- }
59
-
60
- export function getHPCConfig(): HPCConfig | null {
61
- if (!getCurrentConfig()) {
62
- setCurrentConfig(loadConfig());
63
- }
64
- return getCurrentConfig();
65
- }
66
-
67
- /** Forward-slash path for Git Bash (C:/Users/...). */
68
- export function toSlashPath(p: string): string {
69
- return p.replace(/\\/g, "/");
70
- }
71
-
72
- function getAgentSettings(): { shellPath?: string } {
73
- try {
74
- const settingsPath = join(AGENT_DIR, "settings.json");
75
- if (existsSync(settingsPath)) {
76
- return JSON.parse(readFileSync(settingsPath, "utf-8")) as { shellPath?: string };
77
- }
78
- } catch {
79
- // ignore
80
- }
81
- return {};
82
- }
83
-
84
- /** Shell from settings.json shellPath — must match user bash (Git Bash on Windows). */
85
- export function getShellExecutable(): string {
86
- const fromSettings = getAgentSettings().shellPath;
87
- if (fromSettings) return fromSettings;
88
- return process.platform === "win32" ? "C:\\Program Files\\Git\\bin\\bash.exe" : "bash";
89
- }
90
-
91
- export function getPlinkCommand(): string {
92
- if (process.env.PLINK_PATH) return toSlashPath(process.env.PLINK_PATH);
93
- const cfg = getHPCConfig();
94
- if (cfg?.plinkPath) return toSlashPath(cfg.plinkPath);
95
- if (existsSync(DEFAULT_PLINK)) return DEFAULT_PLINK;
96
- return "plink";
97
- }
package/src/constants.ts DELETED
@@ -1,13 +0,0 @@
1
- import { homedir } from "node:os";
2
- import { join } from "node:path";
3
-
4
- export const HPC_TOOL_NAMES = ["ls_hpc", "read_file_hpc", "grep_hpc"] as const;
5
- export const MAX_READ_LINES = 1000;
6
- export const GREP_TIMEOUT_MS = 120_000;
7
- export const UI_PREVIEW_LINES = 10;
8
-
9
- export const AGENT_DIR = join(homedir(), ".pi", "agent");
10
- export const CONFIG_PATHS = [join(AGENT_DIR, ".pi", "hpc-config.json"), join(homedir(), ".pi", "hpc-config.json")];
11
-
12
- /** Default plink on this machine (Git bash path). Override via PLINK_PATH or hpc-config.json plinkPath. */
13
- export const DEFAULT_PLINK = "C:/Users/sreet/plink/plink.exe";
package/src/exec.ts DELETED
@@ -1,49 +0,0 @@
1
- /** Remote command execution over plink + shell quoting helpers. */
2
- import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
3
- import { getHPCConfig, getPlinkCommand, getShellExecutable } from "./config.js";
4
- import type { HpcExecResult } from "./types.js";
5
-
6
- /** Single-quote escape for remote shell command strings. */
7
- export function shQuote(value: string): string {
8
- return `'${value.replace(/'/g, `'"'"'`)}'`;
9
- }
10
-
11
- export function bashQuote(value: string): string {
12
- return `'${value.replace(/'/g, `'\\''`)}'`;
13
- }
14
-
15
- export async function execOnHPC(
16
- pi: ExtensionAPI,
17
- remoteCommand: string,
18
- opts?: { timeout?: number; signal?: AbortSignal },
19
- ): Promise<HpcExecResult> {
20
- const config = getHPCConfig();
21
- if (!config) {
22
- throw new Error("HPC not configured. Use /hpc:config username@host password");
23
- }
24
-
25
- const plink = bashQuote(getPlinkCommand());
26
- const localCmd = `${plink} -batch -pw ${bashQuote(config.password)} ${config.username}@${config.host} ${bashQuote(remoteCommand)}`;
27
- const connectTimeoutMs = opts?.timeout ?? 60_000;
28
- const result = await pi.exec(getShellExecutable(), ["-c", localCmd], {
29
- signal: opts?.signal,
30
- timeout: connectTimeoutMs,
31
- });
32
-
33
- return {
34
- stdout: result.stdout ?? "",
35
- stderr: result.stderr ?? "",
36
- exitCode: result.code ?? 0,
37
- killed: result.killed,
38
- };
39
- }
40
-
41
- export function isHpcFailure(result: HpcExecResult): boolean {
42
- const text = `${result.stdout}\n${result.stderr}`;
43
- return result.exitCode !== 0 || /FATAL ERROR/i.test(text);
44
- }
45
-
46
- export function formatHpcFailure(result: HpcExecResult): string {
47
- if (result.killed) return "HPC command timed out.";
48
- return (result.stderr || result.stdout).trim() || `HPC command failed (exit ${result.exitCode})`;
49
- }
@@ -1,57 +0,0 @@
1
- /** grep_hpc option-string building heuristics. */
2
-
3
- function grepUsesFixedStrings(options: string): boolean {
4
- return /(?:^|\s)-F(?:\s|$)/.test(options) || /--fixed-strings/.test(options);
5
- }
6
-
7
- function grepUsesExtendedRegex(options: string): boolean {
8
- return /(?:^|\s)-E(?:\s|$)/.test(options) || /--extended-regexp/.test(options);
9
- }
10
-
11
- /** Heuristic: | alternation and common ERE syntax need grep -E. */
12
- function patternNeedsExtendedRegex(pattern: string): boolean {
13
- if (pattern.includes("|")) return true;
14
- if (/[()[\]+]/.test(pattern)) return true;
15
- if (/(?:^|[^\\])\?/.test(pattern)) return true;
16
- return false;
17
- }
18
-
19
- function isLikelyFilePath(path: string): boolean {
20
- const base = path.split("/").pop() ?? path;
21
- return base.includes(".") && !path.endsWith("/");
22
- }
23
-
24
- export function buildGrepOptions(
25
- baseOptions: string,
26
- pattern: string,
27
- searchPath: string,
28
- params: {
29
- recursive?: boolean;
30
- context?: number;
31
- after?: number;
32
- before?: number;
33
- },
34
- ): string {
35
- let opts = baseOptions.trim();
36
- opts = opts.replace(/-(?:A|B|C)\s*\d+/g, "").trim();
37
-
38
- if (!grepUsesFixedStrings(opts) && !grepUsesExtendedRegex(opts) && patternNeedsExtendedRegex(pattern)) {
39
- opts += " -E";
40
- }
41
-
42
- if (params.context !== undefined && params.context > 0) {
43
- opts += ` -C ${params.context}`;
44
- } else {
45
- if (params.after && params.after > 0) opts += ` -A ${params.after}`;
46
- if (params.before && params.before > 0) opts += ` -B ${params.before}`;
47
- }
48
-
49
- const useRecursive = params.recursive !== false && !isLikelyFilePath(searchPath);
50
- if (!useRecursive) {
51
- opts = opts.replace(/\s*-r\b/g, "").trim();
52
- } else if (!/\s-r\b/.test(opts)) {
53
- opts += " -r";
54
- }
55
-
56
- return opts.replace(/\s+/g, " ").trim();
57
- }
package/src/index.ts DELETED
@@ -1,116 +0,0 @@
1
- /**
2
- * HPC Tools Extension for pi
3
- *
4
- * Remote file exploration via plink:
5
- * plink -batch -pw "password" username@host "command"
6
- *
7
- * Commands: /hpc:on, /hpc:off, /hpc:config
8
- * Tools (active only after /hpc:on in this project): ls_hpc, read_file_hpc, grep_hpc
9
- * On/off state is stored in hpc-config.json as enabledProjects: ["/path/to/project", ...]
10
- *
11
- * File layout:
12
- * index.ts extension entry point (this file) — commands + lifecycle events
13
- * constants.ts tool names, timeouts, config file paths
14
- * types.ts shared TypeScript types
15
- * state.ts shared mutable module state (enabled flag, config cache, sync flags)
16
- * config.ts hpc-config.json load/save, per-project enable state, shell/plink resolution
17
- * exec.ts plink invocation + shell quoting helpers
18
- * grep-options.ts grep_hpc option-string building heuristics
19
- * render.ts tool call/result rendering
20
- * tool-sync.ts keeps HPC tools' active/inactive state in sync with /hpc:on|off
21
- * tools.ts registers ls_hpc / read_file_hpc / grep_hpc
22
- */
23
- import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
24
- import { getHPCConfig, loadConfig, saveConfig } from "./config.js";
25
- import { getHpcEnabled, getPendingToolSync, setCurrentConfig } from "./state.js";
26
- import { isHpcSyncNeeded, onProjectContext, scheduleDelayedHpcSync, setHpcEnabled, syncHpcTools } from "./tool-sync.js";
27
-
28
- export default function hpcToolsExtension(pi: ExtensionAPI) {
29
- setCurrentConfig(loadConfig());
30
-
31
- pi.registerCommand("hpc:on", {
32
- description: "Enable HPC tools for this project folder",
33
- handler: async (_args, ctx) => {
34
- const config = getHPCConfig();
35
- if (!config) {
36
- ctx.ui.notify("HPC not configured. Use /hpc:config username@host password", "error");
37
- return;
38
- }
39
- setHpcEnabled(pi, ctx.cwd, true);
40
- ctx.ui.notify(`HPC tools ON in this project (${config.username}@${config.host})`, "info");
41
- ctx.ui.setStatus("hpc", `HPC: ON`);
42
- },
43
- });
44
-
45
- pi.registerCommand("hpc:off", {
46
- description: "Disable HPC tools for this project folder (other tools unchanged)",
47
- handler: async (_args, ctx) => {
48
- setHpcEnabled(pi, ctx.cwd, false);
49
- ctx.ui.notify("HPC tools OFF in this project", "info");
50
- ctx.ui.setStatus("hpc", `HPC: OFF`);
51
- },
52
- });
53
-
54
- pi.registerCommand("hpc:config", {
55
- description: "Set HPC credentials: /hpc:config username@host password",
56
- handler: async (args, ctx) => {
57
- if (!args?.trim()) {
58
- ctx.ui.notify("Usage: /hpc:config username@host password", "info");
59
- ctx.ui.notify(" or: /hpc:config username host password", "info");
60
- return;
61
- }
62
-
63
- const parts = args.trim().split(/\s+/);
64
- let username: string;
65
- let host: string;
66
- let password: string;
67
-
68
- if (parts.length === 2) {
69
- const at = parts[0].indexOf("@");
70
- if (at === -1) {
71
- ctx.ui.notify("Use username@host password", "error");
72
- return;
73
- }
74
- username = parts[0].slice(0, at);
75
- host = parts[0].slice(at + 1);
76
- password = parts[1];
77
- } else if (parts.length >= 3) {
78
- username = parts[0];
79
- host = parts[1];
80
- password = parts.slice(2).join(" ");
81
- } else {
82
- ctx.ui.notify("Usage: /hpc:config username@host password", "error");
83
- return;
84
- }
85
-
86
- saveConfig({ username, host, password });
87
- ctx.ui.notify(`HPC configured: ${username}@${host}`, "info");
88
- ctx.ui.setStatus("hpc", `HPC: ${getHpcEnabled() ? "ON" : "OFF"}`);
89
- },
90
- });
91
-
92
- pi.on("session_start", async (event, ctx) => {
93
- // New, resume, reload, fork — re-apply per-project hpc-state.json
94
- onProjectContext(pi, ctx.cwd);
95
- if (event.reason === "resume" || event.reason === "reload" || event.reason === "startup") {
96
- scheduleDelayedHpcSync(pi);
97
- }
98
-
99
- const config = getHPCConfig();
100
- if (config) {
101
- ctx.ui.setStatus("hpc", `HPC: ${getHpcEnabled() ? "ON" : "OFF"}`);
102
- } else if (getHpcEnabled()) {
103
- ctx.ui.setStatus("hpc", `HPC: ON (not configured)`);
104
- }
105
- });
106
-
107
- pi.on("session_tree", async (_event, ctx) => {
108
- // Navigating branches in an existing session — active tools may be restored from history
109
- onProjectContext(pi, ctx.cwd);
110
- });
111
-
112
- pi.on("before_agent_start", async () => {
113
- if (!getPendingToolSync() && !isHpcSyncNeeded(pi)) return;
114
- syncHpcTools(pi);
115
- });
116
- }
package/src/render.ts DELETED
@@ -1,68 +0,0 @@
1
- /** Tool call/result rendering — matches built-in ls/grep/read formatting. */
2
- import { keyHint } from "@earendil-works/pi-coding-agent";
3
- import { Text } from "@earendil-works/pi-tui";
4
- import { UI_PREVIEW_LINES } from "./constants.js";
5
- import type { HpcToolRenderResult } from "./types.js";
6
-
7
- function getToolText(result: HpcToolRenderResult): string {
8
- const block = result.content.find((c) => c.type === "text");
9
- return block?.type === "text" ? (block.text ?? "") : "";
10
- }
11
-
12
- /** Match built-in ls/grep/read renderResult formatting (in-place expand via Ctrl+O). */
13
- export function formatHpcResult(
14
- result: HpcToolRenderResult,
15
- options: { expanded: boolean; isPartial: boolean },
16
- theme: import("@earendil-works/pi-coding-agent").Theme,
17
- ): string {
18
- if (options.isPartial) {
19
- return theme.fg("warning", "Connecting to HPC...");
20
- }
21
-
22
- const details = result.details ?? {};
23
- const output = getToolText(result).trim();
24
- const exitCode = details.exitCode as number | undefined;
25
-
26
- if (details.error || (exitCode !== undefined && exitCode !== 0)) {
27
- return theme.fg("error", output || `HPC command failed (exit ${exitCode ?? "?"})`);
28
- }
29
-
30
- if (!output) {
31
- return theme.fg("dim", "(no output)");
32
- }
33
-
34
- const lines = output.split("\n");
35
- const maxLines = options.expanded ? lines.length : UI_PREVIEW_LINES;
36
- const displayLines = lines.slice(0, maxLines);
37
- const remaining = lines.length - maxLines;
38
-
39
- let text = `\n${displayLines.map((line) => theme.fg("toolOutput", line)).join("\n")}`;
40
- if (remaining > 0) {
41
- text += `${theme.fg("muted", `\n... (${remaining} more lines,`)} ${keyHint("app.tools.expand", "to expand")})`;
42
- }
43
- if (details.truncatedForAgent) {
44
- text += `\n${theme.fg("warning", "[Truncated for agent — narrow path or pattern]")}`;
45
- }
46
- return text;
47
- }
48
-
49
- export function hpcRenderCall(
50
- callText: string,
51
- theme: import("@earendil-works/pi-coding-agent").Theme,
52
- context: { lastComponent?: unknown },
53
- ): Text {
54
- const text = (context.lastComponent as Text | undefined) ?? new Text("", 0, 0);
55
- text.setText(callText);
56
- return text;
57
- }
58
-
59
- export function hpcRenderResult(
60
- result: HpcToolRenderResult,
61
- options: { expanded: boolean; isPartial: boolean },
62
- theme: import("@earendil-works/pi-coding-agent").Theme,
63
- context: { lastComponent?: unknown },
64
- ): Text {
65
- const text = (context.lastComponent as Text | undefined) ?? new Text("", 0, 0);
66
- text.setText(formatHpcResult(result, options, theme));
67
- return text;
68
- }
package/src/state.ts DELETED
@@ -1,43 +0,0 @@
1
- /**
2
- * Shared mutable module state, centralized here so every other file mutates
3
- * it through explicit getters/setters instead of each holding its own copy.
4
- */
5
- import type { HPCConfig } from "./types.js";
6
-
7
- let hpcEnabled = false;
8
- let currentConfig: HPCConfig | null = null;
9
- let toolsRegistered = false;
10
- /** Sync HPC tool visibility after built-ins are in the active set. */
11
- let pendingToolSync = false;
12
-
13
- export function getHpcEnabled(): boolean {
14
- return hpcEnabled;
15
- }
16
-
17
- export function setHpcEnabledFlag(enabled: boolean): void {
18
- hpcEnabled = enabled;
19
- }
20
-
21
- export function getCurrentConfig(): HPCConfig | null {
22
- return currentConfig;
23
- }
24
-
25
- export function setCurrentConfig(config: HPCConfig | null): void {
26
- currentConfig = config;
27
- }
28
-
29
- export function getToolsRegistered(): boolean {
30
- return toolsRegistered;
31
- }
32
-
33
- export function setToolsRegistered(registered: boolean): void {
34
- toolsRegistered = registered;
35
- }
36
-
37
- export function getPendingToolSync(): boolean {
38
- return pendingToolSync;
39
- }
40
-
41
- export function setPendingToolSync(pending: boolean): void {
42
- pendingToolSync = pending;
43
- }
package/src/tool-sync.ts DELETED
@@ -1,114 +0,0 @@
1
- /** Keeps the ls_hpc/read_file_hpc/grep_hpc tools' active/inactive state in sync with /hpc:on|off. */
2
- import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
3
- import { getHPCConfig, isProjectEnabled, loadConfig, setProjectEnabled } from "./config.js";
4
- import { HPC_TOOL_NAMES } from "./constants.js";
5
- import {
6
- getHpcEnabled,
7
- getPendingToolSync,
8
- getToolsRegistered,
9
- setCurrentConfig,
10
- setHpcEnabledFlag,
11
- setPendingToolSync,
12
- } from "./state.js";
13
- import { registerHPCTools } from "./tools.js";
14
-
15
- const HPC_TOOL_SET = new Set<string>(HPC_TOOL_NAMES);
16
-
17
- function isHpcToolName(name: string): boolean {
18
- return HPC_TOOL_SET.has(name);
19
- }
20
-
21
- /** pi.getActiveTools() returns tool name strings (not { name } objects). */
22
- function getActiveToolNames(pi: ExtensionAPI): string[] {
23
- const active = pi.getActiveTools() as Array<string | { name: string }>;
24
- return active.map((t) => (typeof t === "string" ? t : t.name));
25
- }
26
-
27
- function wantHpcEnabled(): boolean {
28
- return getHpcEnabled() && Boolean(getHPCConfig());
29
- }
30
-
31
- function hasHpcInActive(pi: ExtensionAPI): boolean {
32
- return HPC_TOOL_NAMES.some((n) => getActiveToolNames(pi).includes(n));
33
- }
34
-
35
- export function isHpcSyncNeeded(pi: ExtensionAPI): boolean {
36
- return wantHpcEnabled() !== hasHpcInActive(pi);
37
- }
38
-
39
- function ensureHpcToolsRegistered(pi: ExtensionAPI): void {
40
- if (getToolsRegistered()) return;
41
- registerHPCTools(pi);
42
- }
43
-
44
- /**
45
- * Toggle only the three HPC tools on the current active set.
46
- * ON: add HPC tools to whatever is already active (keeps all other tools).
47
- * OFF: remove HPC tools from whatever is active (keeps all other tools).
48
- */
49
- function applyHpcToolVisibility(pi: ExtensionAPI, enabled: boolean): void {
50
- const current = getActiveToolNames(pi);
51
-
52
- if (enabled) {
53
- if (current.length === 0) {
54
- setPendingToolSync(true);
55
- return;
56
- }
57
- const next = new Set(current);
58
- for (const name of HPC_TOOL_NAMES) next.add(name);
59
- pi.setActiveTools([...next]);
60
- } else {
61
- const withoutHpc = current.filter((n) => !isHpcToolName(n));
62
- if (withoutHpc.length !== current.length) {
63
- pi.setActiveTools(withoutHpc);
64
- }
65
- }
66
-
67
- setPendingToolSync(isHpcSyncNeeded(pi));
68
- }
69
-
70
- /** Apply project hpc-state.json to the active tool list (resume / session switch). */
71
- export function syncHpcTools(pi: ExtensionAPI): void {
72
- const want = wantHpcEnabled();
73
- if (want) {
74
- ensureHpcToolsRegistered(pi);
75
- }
76
- applyHpcToolVisibility(pi, want);
77
- }
78
-
79
- export function scheduleHpcSync(pi: ExtensionAPI, attempt = 0): void {
80
- const want = wantHpcEnabled();
81
- const active = getActiveToolNames(pi);
82
-
83
- if (want && active.length === 0 && attempt < 8) {
84
- queueMicrotask(() => scheduleHpcSync(pi, attempt + 1));
85
- return;
86
- }
87
-
88
- syncHpcTools(pi);
89
- }
90
-
91
- /** Resume/reload restores active tools from the session file after session_start. */
92
- export function scheduleDelayedHpcSync(pi: ExtensionAPI): void {
93
- for (const delayMs of [0, 50, 150, 400]) {
94
- setTimeout(() => {
95
- if (getPendingToolSync() || isHpcSyncNeeded(pi)) {
96
- syncHpcTools(pi);
97
- }
98
- }, delayMs);
99
- }
100
- }
101
-
102
- export function setHpcEnabled(pi: ExtensionAPI, cwd: string, enabled: boolean): void {
103
- setHpcEnabledFlag(enabled);
104
- setProjectEnabled(cwd, enabled);
105
- syncHpcTools(pi);
106
- }
107
-
108
- export function onProjectContext(pi: ExtensionAPI, cwd: string): void {
109
- const config = loadConfig();
110
- setCurrentConfig(config);
111
- setHpcEnabledFlag(config ? isProjectEnabled(config, cwd) : false);
112
- setPendingToolSync(true);
113
- scheduleHpcSync(pi);
114
- }
package/src/tools.ts DELETED
@@ -1,295 +0,0 @@
1
- /** Registers the ls_hpc / read_file_hpc / grep_hpc tools. */
2
-
3
- import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
4
- import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, truncateHead } from "@earendil-works/pi-coding-agent";
5
- import { Type } from "typebox";
6
- import { GREP_TIMEOUT_MS, MAX_READ_LINES } from "./constants.js";
7
- import { execOnHPC, formatHpcFailure, isHpcFailure, shQuote } from "./exec.js";
8
- import { buildGrepOptions } from "./grep-options.js";
9
- import { hpcRenderCall, hpcRenderResult } from "./render.js";
10
- import { getToolsRegistered, setToolsRegistered } from "./state.js";
11
-
12
- export function registerHPCTools(pi: ExtensionAPI): void {
13
- if (getToolsRegistered()) return;
14
- setToolsRegistered(true);
15
-
16
- const sharedRender = hpcRenderResult;
17
-
18
- pi.registerTool({
19
- name: "ls_hpc",
20
- label: "List HPC Directory",
21
- description:
22
- "List files and directories on the remote HPC system. Use recursive=true to list all files under a directory.",
23
- promptSnippet: "List or browse files on remote HPC",
24
- promptGuidelines: [
25
- "Use ls_hpc when the user wants to explore directories on the remote HPC filesystem.",
26
- "Use ls_hpc with recursive=true to enumerate files under a directory tree.",
27
- ],
28
- parameters: Type.Object({
29
- path: Type.Optional(Type.String({ description: "Directory on HPC. Defaults to home (~)." })),
30
- options: Type.Optional(
31
- Type.String({ description: "Extra ls flags (e.g. -lh). Default: -la. Ignored when recursive=true." }),
32
- ),
33
- recursive: Type.Optional(Type.Boolean({ description: "List all files recursively under path. Default: false." })),
34
- }),
35
- renderCall(args, theme, context) {
36
- const path = (args.path as string) || "~";
37
- const rec = args.recursive ? " (recursive)" : "";
38
- const callText = theme.fg("toolTitle", theme.bold("ls_hpc ")) + theme.fg("accent", path) + theme.fg("muted", rec);
39
- return hpcRenderCall(callText, theme, context);
40
- },
41
- renderResult: sharedRender,
42
- async execute(_toolCallId, params, signal, onUpdate) {
43
- onUpdate?.({ content: [{ type: "text", text: "Listing on HPC..." }], details: undefined });
44
- const path = params.path || "~";
45
- const recursive = params.recursive ?? false;
46
- const options = params.options || "-la";
47
-
48
- const command = recursive
49
- ? `find ${shQuote(path)} -type f 2>/dev/null | head -n 50000 | sort`
50
- : `ls ${options} ${shQuote(path)} 2>&1`;
51
-
52
- const result = await execOnHPC(pi, command, { signal });
53
-
54
- if (isHpcFailure(result)) {
55
- return {
56
- content: [{ type: "text", text: formatHpcFailure(result) }],
57
- details: { exitCode: result.exitCode, path, recursive, error: true },
58
- isError: true,
59
- };
60
- }
61
-
62
- const text = (result.stdout || "").trim() || "(empty)";
63
- return {
64
- content: [{ type: "text", text }],
65
- details: { exitCode: result.exitCode, path, recursive, lineCount: text.split("\n").length },
66
- };
67
- },
68
- });
69
-
70
- pi.registerTool({
71
- name: "read_file_hpc",
72
- label: "Read HPC File",
73
- description: `Read a file from remote HPC. Supports offset/limit line range (max ${MAX_READ_LINES} lines per call).`,
74
- promptSnippet: "Read file contents from remote HPC",
75
- promptGuidelines: [
76
- "Use read_file_hpc to view source or config files stored on HPC.",
77
- `Use offset and limit to paginate large files (max ${MAX_READ_LINES} lines per read).`,
78
- ],
79
- parameters: Type.Object({
80
- path: Type.String({ description: "Absolute or relative file path on HPC." }),
81
- offset: Type.Optional(Type.Integer({ description: "0-based starting line. Default: 0.", minimum: 0 })),
82
- limit: Type.Optional(
83
- Type.Integer({
84
- description: `Max lines to read (capped at ${MAX_READ_LINES}). Default: ${MAX_READ_LINES}.`,
85
- minimum: 1,
86
- maximum: MAX_READ_LINES,
87
- }),
88
- ),
89
- }),
90
- renderCall(args, theme, context) {
91
- const path = args.path as string;
92
- const offset = (args.offset as number | undefined) ?? 0;
93
- const limit = (args.limit as number | undefined) ?? MAX_READ_LINES;
94
- const callText =
95
- theme.fg("toolTitle", theme.bold("read_file_hpc ")) +
96
- theme.fg("accent", path) +
97
- theme.fg("warning", `:${offset + 1}${limit ? `-${offset + limit}` : ""}`);
98
- return hpcRenderCall(callText, theme, context);
99
- },
100
- renderResult: sharedRender,
101
- async execute(_toolCallId, params, signal, onUpdate) {
102
- onUpdate?.({ content: [{ type: "text", text: "Reading from HPC..." }], details: undefined });
103
- const filePath = params.path;
104
- const offset = Math.max(0, params.offset ?? 0);
105
- let limit = params.limit ?? MAX_READ_LINES;
106
- if (limit > MAX_READ_LINES) limit = MAX_READ_LINES;
107
-
108
- const startLine = offset + 1;
109
- const endLine = offset + limit;
110
- const command = `sed -n '${startLine},${endLine}p' ${shQuote(filePath)} 2>&1`;
111
-
112
- const result = await execOnHPC(pi, command, { signal });
113
- const output = result.stdout ?? "";
114
- const err = result.stderr ?? "";
115
-
116
- if (result.exitCode !== 0) {
117
- return {
118
- content: [{ type: "text", text: `Error reading ${filePath}:\n${err || output || "(no output)"}` }],
119
- details: { exitCode: result.exitCode, path: filePath, error: true },
120
- };
121
- }
122
-
123
- if (!output.trim()) {
124
- return {
125
- content: [{ type: "text", text: `No content in lines ${startLine}-${endLine} of ${filePath}` }],
126
- details: { path: filePath, offset, limit, empty: true },
127
- };
128
- }
129
-
130
- const lineCount = output.split("\n").length;
131
- const header = `${filePath} (lines ${startLine}-${offset + lineCount}):\n`;
132
- return {
133
- content: [{ type: "text", text: header + output }],
134
- details: { path: filePath, offset, limit, lines: lineCount },
135
- };
136
- },
137
- });
138
-
139
- pi.registerTool({
140
- name: "grep_hpc",
141
- label: "Search HPC Files",
142
- description:
143
- "Search file contents on HPC with grep. Patterns with | (alternation) auto-use grep -E. Use options '-F' for literal/fixed-string search. Max runtime 2 minutes.",
144
- promptSnippet: "Grep/search text in remote HPC files",
145
- promptGuidelines: [
146
- "Use grep_hpc to find strings or regex patterns in HPC files.",
147
- "For alternation (foo|bar), use one pattern with | — grep -E is added automatically.",
148
- "Use options '-F' when the pattern must be matched literally (no regex).",
149
- "Use after/before/context for surrounding lines (like grep -A/-B/-C).",
150
- ],
151
- parameters: Type.Object({
152
- pattern: Type.String({ description: "Search pattern. Use | for alternation (e.g. foo|bar)." }),
153
- path: Type.Optional(Type.String({ description: "File or directory on HPC. Default: ." })),
154
- options: Type.Optional(
155
- Type.String({
156
- description: "Extra grep flags (e.g. -i, -l, -E). Default base: -rn.",
157
- }),
158
- ),
159
- file_pattern: Type.Optional(
160
- Type.String({
161
- description:
162
- "Glob for filenames to search, e.g. '*.csv' or '*.py' (uses grep --include, case-insensitive via find when non-recursive).",
163
- }),
164
- ),
165
- after: Type.Optional(Type.Integer({ description: "Lines after match (grep -A).", minimum: 0 })),
166
- before: Type.Optional(Type.Integer({ description: "Lines before match (grep -B).", minimum: 0 })),
167
- context: Type.Optional(
168
- Type.Integer({ description: "Lines before and after (grep -C). Overrides after/before.", minimum: 0 }),
169
- ),
170
- recursive: Type.Optional(Type.Boolean({ description: "Search recursively (-r). Default true for directories." })),
171
- }),
172
- renderCall(args, theme, context) {
173
- let callText = theme.fg("toolTitle", theme.bold("grep_hpc "));
174
- callText += theme.fg("accent", `"${args.pattern as string}"`);
175
- if (args.path) callText += theme.fg("toolOutput", ` in ${args.path as string}`);
176
- if (args.file_pattern) callText += theme.fg("toolOutput", ` (${args.file_pattern as string})`);
177
- return hpcRenderCall(callText, theme, context);
178
- },
179
- renderResult: sharedRender,
180
- async execute(_toolCallId, params, signal, onUpdate) {
181
- onUpdate?.({ content: [{ type: "text", text: "Searching on HPC..." }], details: undefined });
182
-
183
- const pattern = params.pattern;
184
- const searchPath = params.path || ".";
185
- const grepOpts = buildGrepOptions(params.options || "-n", pattern, searchPath, {
186
- recursive: params.recursive,
187
- context: params.context,
188
- after: params.after,
189
- before: params.before,
190
- });
191
- const quotedPattern = shQuote(pattern);
192
- const quotedPath = shQuote(searchPath);
193
-
194
- let command: string;
195
- if (params.file_pattern) {
196
- const glob = params.file_pattern.trim();
197
- const quotedGlob = shQuote(glob);
198
- let fileGrepOpts = grepOpts.replace(/--include(?:=\S+|\s+\S+)?/g, "").trim();
199
-
200
- if (params.recursive === false) {
201
- const namePred = glob.includes("*") || glob.includes("?") ? `-iname ${quotedGlob}` : `-name ${quotedGlob}`;
202
- command = `find ${quotedPath} -maxdepth 1 -type f ${namePred} -exec grep -Hn ${fileGrepOpts} -e ${quotedPattern} {} + 2>&1`;
203
- } else {
204
- if (!/\s-r\b/.test(fileGrepOpts)) fileGrepOpts += " -r";
205
- command = `grep ${fileGrepOpts} --include=${quotedGlob} -e ${quotedPattern} ${quotedPath} 2>&1`;
206
- }
207
- } else {
208
- command = `grep ${grepOpts} -e ${quotedPattern} ${quotedPath} 2>&1`;
209
- }
210
- command += " || true";
211
-
212
- const result = await execOnHPC(pi, command, { signal, timeout: GREP_TIMEOUT_MS });
213
-
214
- if (result.killed) {
215
- return {
216
- content: [
217
- {
218
- type: "text",
219
- text: `grep_hpc timed out after ${GREP_TIMEOUT_MS / 1000}s. Narrow the path, use file_pattern, or refine the pattern.`,
220
- },
221
- ],
222
- details: { path: searchPath, pattern, timedOut: true, error: true },
223
- };
224
- }
225
-
226
- if (isHpcFailure(result)) {
227
- return {
228
- content: [{ type: "text", text: formatHpcFailure(result) }],
229
- details: {
230
- path: searchPath,
231
- pattern,
232
- file_pattern: params.file_pattern,
233
- exitCode: result.exitCode,
234
- error: true,
235
- },
236
- isError: true,
237
- };
238
- }
239
-
240
- const output = (result.stdout || "").trim();
241
- const stderr = (result.stderr || "").trim();
242
- if (!output) {
243
- const scope = params.file_pattern ? `${searchPath} (files: ${params.file_pattern})` : searchPath;
244
- if (stderr && /no such file|not found|cannot access/i.test(stderr)) {
245
- return {
246
- content: [{ type: "text", text: `grep_hpc failed:\n${stderr}` }],
247
- details: { path: searchPath, pattern, error: true },
248
- isError: true,
249
- };
250
- }
251
- return {
252
- content: [
253
- {
254
- type: "text",
255
- text: `No matches for ${JSON.stringify(pattern)} in ${scope}${grepOpts.includes("-E") ? " (extended regex)" : ""}`,
256
- },
257
- ],
258
- details: {
259
- path: searchPath,
260
- pattern,
261
- file_pattern: params.file_pattern,
262
- matches: 0,
263
- grepOptions: grepOpts,
264
- },
265
- };
266
- }
267
-
268
- const truncation = truncateHead(output, {
269
- maxLines: DEFAULT_MAX_LINES,
270
- maxBytes: DEFAULT_MAX_BYTES,
271
- });
272
-
273
- let agentText = truncation.content;
274
- const details: Record<string, unknown> = {
275
- path: searchPath,
276
- pattern,
277
- grepOptions: grepOpts,
278
- matches: output.split("\n").filter((l) => l.trim()).length,
279
- exitCode: result.exitCode,
280
- };
281
-
282
- if (truncation.truncated) {
283
- details.truncatedForAgent = true;
284
- const omittedLines = truncation.totalLines - truncation.outputLines;
285
- const omittedBytes = truncation.totalBytes - truncation.outputBytes;
286
- agentText += ` | [Output truncated for agent: showing ${truncation.outputLines} of ${truncation.totalLines} lines (${formatSize(truncation.outputBytes)} of ${formatSize(truncation.totalBytes)}). ${omittedLines} lines (${formatSize(omittedBytes)}) omitted. Narrow search path or pattern.]`;
287
- }
288
-
289
- return {
290
- content: [{ type: "text", text: agentText }],
291
- details,
292
- };
293
- },
294
- });
295
- }
package/src/types.ts DELETED
@@ -1,19 +0,0 @@
1
- export interface HPCConfig {
2
- username: string;
3
- host: string;
4
- password: string;
5
- plinkPath?: string;
6
- enabledProjects?: string[];
7
- }
8
-
9
- export type HpcToolRenderResult = {
10
- content: Array<{ type: string; text?: string }>;
11
- details?: Record<string, unknown>;
12
- };
13
-
14
- export type HpcExecResult = {
15
- stdout: string;
16
- stderr: string;
17
- exitCode: number;
18
- killed?: boolean;
19
- };