@preventive/triage 1.0.0-alpha.15 → 1.0.0-alpha.17

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/out/terminal.js CHANGED
@@ -1,136 +1,154 @@
1
- var Zh=Object.defineProperty;var Vh=(e,t)=>{for(var n in t)Zh(e,n,{get:t[n],enumerable:!0})};var wu=globalThis[Symbol.for("@rray/frontend")];if(!wu)throw new Error("@rray/frontend global not installed; view.js must run before lazy bundles import this wrapper");var{LitElement:xu,html:Oe,nothing:Oi,unsafeCSS:yu,render:yS,StateElement:bS,classMap:vS,repeat:bu,styleMap:kS}=wu;var J=(1n<<63n)-1n,Xe=-J-1n,Ze=(1n<<64n)-1n;var C=(e="")=>({stdout:e,stderr:"",exitCode:0}),y=(e,t=1)=>({stdout:"",stderr:e.endsWith(`
1
+ var wm=Object.defineProperty;var ym=(e,t)=>{for(var n in t)wm(e,n,{get:t[n],enumerable:!0})};var na=globalThis[Symbol.for("@rray/frontend")];if(!na)throw new Error("@rray/frontend global not installed; view.js must run before lazy bundles import this wrapper");var{LitElement:ra,html:De,nothing:Qo,unsafeCSS:oa,render:VE,StateElement:KE,classMap:JE,repeat:ia,styleMap:QE}=na;var F=(e="")=>({stdout:e,stderr:"",exitCode:0}),x=(e,t=1)=>({stdout:"",stderr:e.endsWith(`
2
2
  `)?e:e+`
3
- `,exitCode:t}),oe=(e,t=1)=>y(`usage: ${e}`,t);function P(e,t,n){let r=$(e.cwd,n,e.fs);return D(e,t,n,r.error),r}function D(e,t,n,r){if(r!=="No such file or directory"||typeof n!="string")return;let i=n.startsWith("/"),o=i?"/":e.cwd,s=n.replace(/^\/+/u,""),u=new Set;for(let c of new Set(["/",e.mount??"/",e.home??"/"])){if(c===o)continue;let f=$(c,s,e.fs);f.error||u.add(f.path)}if(!u.size)return;let a=i?"":` from cwd ${JSON.stringify(e.cwd)}`,l=`${i?"absolute":"relative"} path ${JSON.stringify(n)} was not found${a}`;e.notes?.add(`${t}: ${l}. ${Yh(e,u)}`)}function Yh(e,t){let n=[...t].sort(U),r=n.map(u=>JSON.stringify(u));if(n.length===1)return`A ${e.fs.isDir(n[0])?"dir":"file"} exists at ${r[0]}.`;let o=n.every(u=>!e.fs.isDir(u)&&e.fs.isFile(u))&&n.some(u=>!e.fs.sameFileContents(n[0],u)),s=`${r.slice(0,-1).join(", ")} and ${r.at(-1)}`;return`${n.length===2?"Both":"All"} of ${s} exist${o?", and they differ in contents":""}.`}function Pt(){let e=new Set;return{add:t=>e.add(t),collect(t,n){for(let r of n)r.startsWith(".")&&e.add(L(t,r))},emit(t,n,r,i=""){st(t,{command:n,action:"omitted",noun:["hidden entry","hidden entries"],explanation:r,context:i,paths:e})}}}var vu=/^(?<command>[^:]+): (?<operand>.+): (?<reason>no such file or directory|not a directory|is a directory)$/iu;function ku(e,t){for(let n of t.split(`
4
- `))vu.test(n)&&e.discarded?.add(n)}function Ci(e,t,n){let r=new Map;for(let i of e){if(t.includes(i))continue;let{command:o,operand:s,reason:u}=vu.exec(i).groups,a=/'([^']*)'$/u.exec(s)?.[1]??s;if([...n].some(c=>c.includes(JSON.stringify(a))))continue;let l=`${o}: ${u}`;r.has(l)||r.set(l,new Set),r.get(l).add(a)}return[...r].map(([i,o])=>`${i}: ${[...o].map(s=>JSON.stringify(s)).join(", ")}.`)}function Su(e,t){return e==="status"?null:{name:t,search:e==="search"}}function Eu(){let e=null,t=0;return{skip(n,r){!t&&n&&(e={...n,exitCode:r}),t++},flush(n){if(t&&e){let r=t===1?"the command":`the ${t} commands`,i=e.search&&e.exitCode===1?" A search that selects no lines exits 1, which is not a failure.":"";n.add(`${e.name}: exited ${e.exitCode}, so ${r} after && did not run.${i}`)}e=null,t=0}}}function st(e,t){Kh(e,t,t.paths.size,t.paths)}function Kh(e,{command:t,action:n,noun:r,explanation:i="",context:o=""},s,u){if(!s)return;let a=s<10?": "+[...u].sort(U).map(c=>JSON.stringify(c)).join(", "):"",l=Array.isArray(r)?r[s===1?0:1]:r;e.add(`${t}: ${n} ${s} ${l}${o}${a}.${i?" "+i:""}`)}var $u=Symbol("unsupported");function N(e){if(e==null)return null;try{return e[$u]??null}catch{return null}}function v(e,t,n,r,i=1){return Q(y(r,i),e,t,n,r)}function Q(e,t,n,r,i){return Object.defineProperty(e,$u,{value:{kind:t,command:n,detail:r,message:i},enumerable:!1,configurable:!0}),e}function K(e,t,n,r){let i=N(e);return i?v(i.kind,t,i.detail,n,r):y(n,r)}var w=class extends Error{constructor(t,n,r){super(r),this.name="UnsupportedError",Q(this,t,null,n,r)}};function dn(){let e=new Set,t=[];return{entries:t,add(n,r=n.command){let i=JSON.stringify([n.kind,r,n.detail]);e.has(i)||(e.add(i),t.push(Object.freeze(n)))}}}var{Buffer:Nu}=globalThis,Iu=Nu&&!Nu.TYPED_ARRAY_SUPPORT;var Au=e=>e&&(Iu||`${e}`.includes("[native code]"));!Iu&&Au(()=>{})&&(Au=()=>!1);function Fi(e,t){let n=e.length;for(let r=0;r<n;r++)t[r]=e.charCodeAt(r);return t}var pn=null,hn=!1,Ou=!1,Ue=new TextEncoder,Be=new TextDecoder("utf-8",{ignoreBOM:!0}),Ti=new TextDecoder("latin1",{ignoreBOM:!0});var _i=globalThis.Buffer;function dr(e){if(!(e&&e instanceof Uint8Array))throw new TypeError("Expected an Uint8Array")}var pr="Input is not a string",Li="Input is not well-formed Unicode";function bt(e,t){switch(t){case"uint8":if(e.constructor!==Uint8Array)throw new Error("Unexpected");return e;case"arraybuffer":if(e.byteLength!==e.buffer.byteLength)throw new Error("Unexpected");return e.buffer;case"buffer":return e.length<=64?_i.from(e):_i.from(e.buffer,e.byteOffset,e.byteLength)}throw new TypeError("Unexpected format")}function Cu(e,t){switch(t){case"uint8":return e.length<=64||e.byteOffset!==0||e.byteLength!==e.buffer.byteLength?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength);case"arraybuffer":return e.buffer.byteLength===e.byteLength?e.buffer:e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength);case"buffer":if(e.constructor!==_i)throw new Error("Unexpected");return e}throw new TypeError("Unexpected format")}var em=Be,tm=Be?new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}):null,{isWellFormed:Tu}=String.prototype;function nm(e,t,n){if(t||e.length===n.length)return n;if(Tu){if(Tu.call(e))return n;throw new TypeError(Li)}let r=0,i=n.length-3;for(;r<=i;){let o=n.indexOf(239,r);if(o===-1||o>i)break;if(r=o+1,n[o+1]===191&&n[o+2]===189){if(null)try{if(encodeURI(e)!==null)return n}catch{}else if(e===Lu(n))return n;throw new TypeError(Li)}}return n}function _u(e,t=!1){if(typeof e!="string")throw new TypeError(pr);return e.length===0?new Uint8Array:Ue||!null?nm(e,t,Ue.encode(e)):null(e,t)}function Lu(e,t=!1){return dr(e),e.byteLength===0?"":Be||!null?t?em.decode(e):tm.decode(e):null(e,t)}var Ru=(e,t="uint8")=>bt(_u(e,!1),t),I=(e,t="uint8")=>bt(_u(e,!0),t),Mu=e=>Lu(e,!1);function ee(e){try{return Ru(e)}catch(t){throw t instanceof TypeError?new w("feature","unpaired surrogate","unpaired UTF-16 surrogates cannot be encoded as UTF-8"):t}}function M(e){try{return Mu(e)}catch{throw new w("feature","partial UTF-8 byte sequence","byte output that is not valid UTF-8 cannot be represented by this string-based terminal")}}var Ve="C.UTF-8",hr="only the C.UTF-8 locale is supported",Ri=e=>typeof e=="string"&&/^C\.UTF-?8$/iu.test(e),rm=new Set(["LANG","LC_ALL","LC_CTYPE"]);function Pu(e){if(e.locale===void 0||Ri(e.locale))return Ve;throw new TypeError(`createTerminal: ${hr} (got ${JSON.stringify(e.locale)})`)}function Du(e,t){if(!(rm.has(e)?Ri(t)||e!=="LANG"&&t==="":Ri(t)||t==="C"||t==="POSIX"||t===""))throw new w("feature",e,`${e}: ${hr}`)}var Mi=e=>e==="C"||e==="POSIX",le=e=>Mi(e.locale);function se(e,t=`
5
- `){if(e==="")return[];let n=e.split(t);return n.at(-1)===""&&n.pop(),n}var ce=(e,t=`
6
- `)=>e.length===0?"":e.join(t)+t;function We(e,t=`
7
- `){let n=[];for(let r=0;r<e.length;){let i=e.indexOf(t,r),o=i<0?e.length:i+t.length;n.push(e.slice(r,o)),r=o}return n}function z(e,t=""){e.io?.read(e.stdinHandle?.identity),e.stdinLeft=t}function Ye(e,t,n,r="",i={}){let o=[],s="",u=r;for(let a of t){let l={name:a,content:"",kind:"file"},c;if(a==="/dev/stdin"&&n.stdinFile)n.io?.read(n.stdinHandle?.identity),l.content=n.stdinOrigin;else if(a==="-"||a==="/dev/stdin")l.content=u,l.shared=!0,u="",z(n);else if(a!=="/dev/null"){let f=P(n,e,a);f.error?(l.kind="missing",c=f.error):n.fs.isDir(f.path)?(l.kind="dir",i.noRead||(c="Is a directory")):l.content=n.fs.readFile(f.path)}if(o.push(l),c&&(s+=Pi(e,a,c,l.kind==="dir")),l.kind!=="file"&&(i.stopOnError||l.kind==="dir"&&i.stopOnDir))break}return{inputs:o.filter(a=>a.kind==="file"),entries:o,stderr:s,failed:s!==""}}var im={head:["cannot open '%s' for reading: %r","error reading '%s': Is a directory"],tail:["cannot open '%s' for reading: %r","error reading '%s': Is a directory"],sort:["cannot read: %s: %r","read failed: %s: Is a directory"],sed:["can't read %s: %r","read error on %s: Is a directory"],tac:["failed to open '%s' for reading: %r","%s: read error: Invalid argument"],base64:[null,"read error: Is a directory"],uniq:[null,"error reading '%s': Is a directory"]};function Pi(e,t,n,r=!1){let i=im[e]?.[r?1:0],o=i?i.replace(/%[sr]/gu,s=>s==="%s"?t:n):`${t}: ${n}`;return`${e}: ${o}
8
- `}function te(e,t,n,r,i){if(t.length===0){z(r);let o=[{name:null,content:n,kind:"file"}];return{inputs:o,entries:o,stderr:"",failed:!1}}return Ye(e,t,r,n,i)}function Uu(e,t){return e===null||e==="-"||e==="/dev/stdin"?t.stdinHandle?.path?JSON.stringify(t.stdinHandle.path):"standard input":JSON.stringify($(t.cwd,e,t.fs).path??e)}function mn(e,t,n,r){let i=te(e,t,n,r);return{content:i.inputs.map(o=>o.content).join(""),stderr:i.stderr,failed:i.failed}}var ue=(e,t)=>({stdout:e,stderr:t.stderr,exitCode:t.failed?1:0});function pe(e,t,n=e,{max:r=1/0,digitsOnly:i=!1}={}){if(typeof e!="string"||!(i?/^\d+$/u:/^[ \t\n\r\f\v]*\+?\d+$/u).test(e))return{error:y(`${t}: invalid count: ${n}`)};let o=Number(e);return o>r?{error:y(`${t}: out of range: ${n}`)}:{value:Math.min(o,Number.MAX_SAFE_INTEGER)}}function Bu(e,t){if(typeof e!="string")return{error:y(`${t}: invalid count: ${e}`)};let n=e[0]==="+"||e[0]==="-"?e[0]:"",r=n==="-"?e.slice(1):e,i=/^[ \t\n\r\v\f]*\+?(\d+)(b|[kKMGTPEZYRQ](?:i?B)?)?$/u.exec(r),o=!n&&/^(?:b|[kKMGTPEZYRQ](?:i?B)?)$/u.test(r);if(!i&&!o)return{error:y(`${t}: invalid count: ${e}`)};let s=i?.[2]??(o?r:""),u=Di(BigInt(i?.[1]??"1"),s,t,e);return u.error?u:{...u,sign:n}}function Di(e,t,n,r){let i=1n;t==="b"?i=512n:t&&(i=(t.length===2?1000n:1024n)**BigInt("KMGTPEZYRQ".indexOf(t[0].toUpperCase())+1));let o=e*i;return o>Ze?{error:y(`${n}: count out of range: ${r}`)}:{value:Number(o>BigInt(Number.MAX_SAFE_INTEGER)?BigInt(Number.MAX_SAFE_INTEGER):o)}}function G(e){try{let t=e?.message;return typeof t=="string"&&t!==""?t:String(e)}catch{return"threw a value with no message"}}function gn(e){let t=e.startsWith("/"),n=e.split("/").filter(Boolean),r=[];for(let i of n)if(i!=="."){if(i===".."){r.length>0&&r.at(-1)!==".."?r.pop():t||r.push("..");continue}r.push(i)}return t?"/"+r.join("/"):r.length===0?".":r.join("/")}function L(e,t){return t.startsWith("/")?gn(t):gn(e+"/"+t)}function $(e,t,n){let r={path:null,error:"No such file or directory"},i={path:null,error:"Not a directory"};if(t===""||t.includes("\0"))return r;let o=(t.startsWith("/")?t:e+"/"+t).split("/").filter(Boolean),s="/";for(let u of o){if(!n.isDir(s))return n.isFile(s)?i:r;u===".."?s=vt(s):u!=="."&&(s=Ce(s,u))}return!n.isDir(s)&&!n.isFile(s)?r:t.endsWith("/")&&!n.isDir(s)?i:{path:s,error:null}}function Ke(e,t,n,r=$(e,t,n)){if(r.path!==null)return null;if(t===""||t.includes("\0")||t.endsWith("/")||r.error!=="No such file or directory")return r.error;let i=t.lastIndexOf("/"),o=$(e,i<0?".":t.slice(0,i)||"/",n);return o.error??(n.isDir(o.path)?null:"Not a directory")}function vt(e){let t=gn(e);if(t==="/")return"/";let n=t.lastIndexOf("/");return n<0?".":n===0?"/":t.slice(0,n)}function kt(e){let t=gn(e);if(t==="/")return"/";let n=t.lastIndexOf("/");return t.slice(n+1)}function U(e,t){for(let n=0;n<Math.min(e.length,t.length);n++)if(e[n]!==t[n])return e.codePointAt(n)-t.codePointAt(n);return e.length-t.length}function Ce(e,t){return e==="/"?"/"+t:e+"/"+t}function ut(e,t){return e==="/"?t.slice(1):t.slice(e.length+1)}function zu(e,t="/"){let n=new Map;for(let[o,s]of om(e)){if(typeof s!="string")continue;let u=String(o);if(u.includes("\0"))throw new TypeError("createTerminal: source paths must not contain NUL characters");let a=gn("/"+u);n.set(t==="/"?a:a==="/"?t:t+a,s)}let r=new Map([["/",{dirs:[],files:[]}]]);Wu(r,t);for(let o of n.keys()){let s=o.lastIndexOf("/"),u=o.slice(0,s)||"/";Wu(r,u),r.get(u).files.push(o==="/"?"/":o.slice(s+1))}for(let o of r.values())o.dirs.sort(U),o.files.sort(U);let i={isFile:o=>n.has(o),isDir:o=>r.has(o),readFile:o=>n.get(o),fileSize:o=>n.has(o)&&!r.has(o)?ee(n.get(o)).length:void 0,sameFileContents:(o,s)=>n.get(o)===n.get(s),listDir:o=>{let s=r.get(o);if(!s)throw new Error(`not a directory: ${o}`);return s},walkFiles:o=>sm(i,o)};return i}function om(e){try{return Map.prototype.entries.call(e)}catch{return Object.entries(e??{})}}function*Fe(e,t,n=Number.POSITIVE_INFINITY,r=()=>!0){if(e.isFile(t)){yield{path:t,kind:"file",depth:0};return}if(!e.isDir(t))return;let i=[{path:t,kind:"dir",depth:0}];for(;i.length;){let o=i.pop();if(yield o,o.kind!=="dir"||o.depth>=n||!r(o.path))continue;let{dirs:s,files:u}=e.listDir(o.path),a=s.length-1,l=u.length-1;for(;a>=0||l>=0;){let c=l<0||a>=0&&U(s[a],u[l])>0,f=c?s[a--]:u[l--];i.push({path:Ce(o.path,f),kind:c?"dir":"file",depth:o.depth+1})}}}function*sm(e,t){for(let n of Fe(e,t))n.kind==="file"&&(yield n.path)}function Wu(e,t){let n=[],r=t;for(;r!=="/"&&!e.has(r);)n.push(r),r=r.slice(0,r.lastIndexOf("/"))||"/";for(let i=n.length-1;i>=0;i--){let o=n[i];e.set(o,{dirs:[],files:[]});let s=o.lastIndexOf("/");e.get(o.slice(0,s)||"/").dirs.push(o.slice(s+1))}}var at=e=>e==="/tmp"||e.startsWith("/tmp/");function qu(e){let t=new Map,n=new Set(["/tmp"]),r,i=e.listDir("/"),o={dirs:[...i.dirs,"tmp"].sort(U),files:i.files},s=cm(n,t),u=s.reshaped,a=(c,f)=>{if(!c.startsWith("/tmp/"))throw new Error("writable overlay paths must start with /tmp/");t.has(c)||u(),t.set(c,f)},l={observeIo:c=>{r=c},fileIdentity:c=>t.get(c),fileSize:c=>t.get(c)?.bytes.length??e.fileSize(c),readIdentity:c=>(r?.read(c),M(c.bytes)),isFile:c=>t.has(c)||e.isFile(c),isDir:c=>n.has(c)||e.isDir(c),readFile:c=>{let f=t.get(c);return r?.read(f??c),f?M(f.bytes):e.readFile(c)},sameFileContents:(c,f)=>fm(e,t,c,f),listDir:c=>c==="/"?o:n.has(c)?s.of(c):e.listDir(c),*walkFiles(c){for(let f of Fe(l,c))f.kind==="file"&&(yield f.path)},openWritable(c,f,d=!1){let p=L(c,f);if(p!=="/tmp"&&!p.startsWith("/tmp/"))return null;wn(l,c,f);let m=t.get(p);return m?d||(r?.write(m),m.bytes=new Uint8Array):(m={bytes:new Uint8Array},a(p,m)),dm(p,m,d,()=>r?.write(m))},makeWritableDir:(c,f)=>um(l,{dirs:n,files:t,reshaped:u},c,f),removeWritableDir:(c,f)=>lm(l,{dirs:n,reshaped:u},c,f),copyWritable(c,f,d){let p=L(c,d);if(!p.startsWith("/tmp/"))return!1;wn(l,c,d);let m=t.get(f);if(f===p||m&&m===t.get(p))throw new Error("source and destination are the same file");r?.read(m??f);let h=m?m.bytes:ee(e.readFile(f));return l.openWritable(c,d).writeBytes(h),!0},replaceWritable:(c,f,d,p)=>am(l,{files:t,put:a},c,f,d,p),removeWritable(c,f){let d=L(c,f);if(d!=="/tmp"&&!d.startsWith("/tmp/"))return!1;let p=$(c,f,l);if(p.error)throw xn(f,p.error);if(l.isDir(p.path))throw new Error(`${f}: Is a directory`);return t.delete(p.path),u(),!0}};return l}function um(e,t,n,r){let i=L(n,r);if(i!=="/tmp"&&!i.startsWith("/tmp/"))return!1;if(t.dirs.has(i))return!0;if(wn(e,n,r),t.files.has(i))throw new Error(`${r}: File exists`);return t.dirs.add(i),t.reshaped(),!0}function am(e,t,n,r,i,o){let s=L(n,r),u=o===void 0?null:L(n,o);if(!s.startsWith("/tmp/")||u!==null&&!u.startsWith("/tmp/"))return!1;wn(e,n,r);let a=t.files.get(s);if(!a)throw xn(r,"No such file or directory");u!==null&&wn(e,n,o);let l={bytes:ee(i)};return u!==null&&t.put(u,a),t.put(s,l),!0}function lm(e,t,n,r){let i=L(n,r);if(i!=="/tmp"&&!i.startsWith("/tmp/"))return!1;let o=$(n,r,e);if(o.error)throw xn(r,o.error);if(!t.dirs.has(o.path))throw new Error(`${r}: Not a directory`);if(o.path==="/tmp")throw new Error(`${r}: Device or resource busy`);let{dirs:s,files:u}=e.listDir(o.path);if(s.length||u.length)throw new Error(`${r}: Directory not empty`);return t.dirs.delete(o.path),t.reshaped(),!0}function cm(e,t){let n=new Map,r=(i,o)=>[...i].filter(s=>s.startsWith(o)&&!s.slice(o.length).includes("/")).map(s=>s.slice(o.length)).sort(U);return{reshaped:()=>{n=new Map},of(i){let o=n.get(i);if(o)return o;let s={dirs:r(e,i+"/"),files:r(t.keys(),i+"/")};return n.set(i,s),s}}}function fm(e,t,n,r){let i=t.get(n),o=t.get(r);if(!i&&!o)return e.sameFileContents(n,r);let s=(l,c)=>{if(c)return c.bytes;let f=e.readFile(l);return f.isWellFormed()?ee(f):null},u=s(n,i),a=s(r,o);return u!==null&&a!==null&&u.length===a.length&&u.every((l,c)=>l===a[c])}function wn(e,t,n){let r=$(t,n,e);if(r.path!==null){if(e.isDir(r.path))throw new Error(`${n}: Is a directory`);return}if(r.error!=="No such file or directory"||n.includes("\0")||n.endsWith("/"))throw xn(n,r.error);let i=n.lastIndexOf("/"),o=i<0?".":n.slice(0,i)||"/",s=$(t,o,e);if(s.error)throw xn(n,s.error);if(!e.isDir(s.path))throw new Error(`${n}: Not a directory`)}function xn(e,t){return Object.assign(new Error(`${e}: ${t}`),{path:e,fsError:t})}function dm(e,t,n,r){let i=0,o=s=>{let u=t.bytes,a=n?u.length:i,l=Math.max(u.length,a+s.length),c=u.buffer;c.byteLength<l&&(c=new ArrayBuffer(Math.max(l,c.byteLength*2)),new Uint8Array(c).set(u));let f=new Uint8Array(c,0,l);f.set(s,a),t.bytes=f,i=a+s.length};return{path:e,identity:t,get position(){return n?t.bytes.length:i},write(s){s!==""&&(r(),o(ee(s)))},writeBytes(s){s.length!==0&&(r(),o(s))}}}var ju=["cwd","home","user","inherit"];function Hu(e,t){let n=yn(t,"mount","/"),r=yn(t,"home",n),i=yn(t,"cwd",n);if(t.writable!==void 0&&t.writable!==!1&&t.writable!=="/tmp/")throw new TypeError("createTerminal: writable must be '/tmp/', false, or undefined");let o=t.writable==="/tmp/";if(o&&(n==="/"||n==="/tmp"||n.startsWith("/tmp/")))throw new Error("createTerminal: mount must not be /, /tmp, or inside /tmp when writable is '/tmp/'");let s=zu(e,n);return{fs:o?qu(s):s,cwd:i,home:r,mount:n,writable:o,locale:Pu(t)}}function Gu(e,t){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(`fork: options must be an object (got ${t===null?"null":Array.isArray(t)?"an array":typeof t})`);for(let n of Object.keys(t))if(!ju.includes(n))throw new Error(`fork: unknown option \`${n}\` (known: ${ju.join(", ")}; the sources, the mount, the /tmp/ overlay and the commands come from the parent)`);if(t.inherit!==void 0&&typeof t.inherit!="boolean")throw new TypeError(`fork: inherit must be true or false (got ${t.inherit===null?"null":typeof t.inherit})`);return{cwd:yn(t,"cwd",e.cwd,"fork",e.cwd),home:yn(t,"home",e.home,"fork",e.cwd),user:t.user??e.user,locale:e.locale,inherit:t.inherit??!0}}function yn(e,t,n,r="createTerminal",i="/"){let o=e[t]===void 0?n:e[t];if(typeof o!="string"||o.includes("\0"))throw new TypeError(`${r}: ${t} must be a string without NUL characters`);return L(i,o)}function fe(e,t=0,n=e.value.length){return{value:e.value.slice(t,n),mask:e.mask===null?null:e.mask.slice(t,n),...e.empty?{empty:e.empty.filter(r=>r>=t&&r<=n).map(r=>r-t)}:{}}}function bn(e){let t=/^([A-Za-z_][A-Za-z0-9_]*)=/u.exec(e.value);return!t||e.mask!==null&&/[12]/u.test(e.mask.slice(0,t[0].length))||e.empty?.some(n=>n<t[0].length)?null:{name:t[1],end:t[0].length}}var Xu=(e,t)=>e.mask===null?"0":e.mask[t];function mr(e,t=!1){let n=new Set;if(!e.value.includes("~"))return n;let r=e.value,i=u=>Xu(e,u)==="0",o=t?null:bn(e)?.end??null,s=u=>t===!0||o!==null&&u>=o;for(let u=0;u<r.length;u++){let a=u===0||u===o||s(u)&&r[u-1]===":"&&i(u-1),l=s(u)||t==="parameterAssign";if(!a||r[u]!=="~"||!i(u)||!pm(e,u,l))continue;let c=r[u+1];if(c&&c!=="/"&&c!==":"&&i(u+1))throw new w("feature","tilde prefix","named-user and directory-stack tilde prefixes are not supported");(c===void 0||i(u+1)&&(c==="/"||c===":"&&l))&&n.add(u)}return n}function pm(e,t,n){for(let r=t;r<=e.value.length;r++){if(e.empty?.includes(r))return!1;if(r===e.value.length)return!0;if(Xu(e,r)!=="0")return!1;if(e.value[r]==="/"||n&&e.value[r]===":")return!0}return!0}function Zu(...e){let t="",n="",r=[];for(let i of e){for(let o of i.empty??[])r.push(t.length+o);t+=i.value,n+=i.mask??"0".repeat(i.value.length)}return{value:t,mask:e.every(i=>i.mask===null)?null:n,...r.length?{empty:r}:{}}}var Dt=64;function Te(e,t){let n="";for(let r=t+1;r<e.length;r++){let i=e[r];if(i==="`")return{command:n,raw:e.slice(t,r+1),backtick:!0};if(i!=="\\"){n+=i;continue}let o=e[r+1];if(o==="`")throw new w("feature","\\`","nested backtick command substitution is not supported; use `$( )` instead");if(o==="$"||o==="\\"){n+=o,r++;continue}if(o===`
9
- `){r++;continue}n+=i}throw new Error("unterminated backtick substitution")}var Vu=()=>({value:"",quoted:!1,started:!1}),Yu=()=>new w("feature","command substitution depth",`command substitution nesting above ${Dt} is not supported`);function Ui(e,t,n,r,i){if(r>=Dt)throw Yu();let o={line:e,i:n+1,depth:r,helpers:i,parens:0,quote:null,word:Vu(),command:!0,target:null,heredocs:[]};for(;o.i<e.length;)if(hm(o))return{raw:e.slice(t,o.i+1),command:e.slice(n+1,o.i)};throw o.quote?new Error(`unterminated ${o.quote==="'"?"single":"double"} quote`):new Error("unterminated command substitution")}function lt(e,t,n=!1){e.word.value+=t,e.word.quoted||=n,e.word.started=!0}function Bi(e){let t=e.word;if(t.started){if(e.target)e.target.op==="heredoc"&&(e.target.delim=t.value,e.target.quotedDelim=t.quoted),e.target=null;else if(e.command&&!t.quoted){if(t.value==="case")throw new w("feature","case","`case` patterns inside command substitutions are not supported");e.command=["!","{","do","then","else","elif","if","while","until"].includes(t.value)||/^[A-Za-z_][A-Za-z0-9_]*=/u.test(t.value)}else e.command=!1;e.word=Vu()}}function hm(e){let{line:t,i:n,quote:r}=e,i=t[n];if(r&&i===r)return e.quote=null,e.word.quoted=!0,e.i++,!1;if(r==="'")return lt(e,i,!0),e.i++,!1;if(i==="\\")return mm(e),!1;if(i==="$")return gm(e),!1;if(i==="`")return wm(e),!1;if(r)return lt(e,i,!0),e.i++,!1;if(i==="'"||i==='"')return e.quote=i,e.word.started=!0,e.i++,!1;if(e.command&&!e.target&&!e.word.started&&t.startsWith("[[",n)&&/[ \t\n()<>;&|]|^$/u.test(t[n+2]??"")){let s=e.helpers.readConditional(t,n,e.helpers,e.depth+e.parens+1);return e.i+=s.raw.length,e.command=!1,!1}if(i==="#"&&!e.word.started){let s=t.indexOf(`
10
- `,n);return e.i=s===-1?t.length:s,!1}if(i===`
11
- `)return ym(e),!1;if(i===" "||i===" ")return Bi(e),e.i++,!1;let o;try{o=e.helpers.readOperator(t,n,!e.word.started)}catch(s){if(!(s instanceof w))throw s;return e.i++,!1}return o?xm(e,o):(lt(e,i),e.i++,!1)}function mm(e){let t=e.line[e.i+1];if(t===`
12
- `){e.i+=2;return}t!==void 0&&(!e.quote||'$`"\\'.includes(t))?(lt(e,t,!0),e.i+=2):(lt(e,"\\",!!e.quote),e.i++)}function gm(e){let{line:t,i:n}=e,r=e.helpers.skipContinuations(t,n+1);if(!e.quote&&t[r]==="'"){let s=e.helpers.decodeAnsiC(t,r+1);lt(e,s.text,!0),e.i=s.end;return}if(!e.quote&&t[r]==='"'){e.quote='"',e.word.started=!0,e.i=r+1;return}let o=e.helpers.readExpansion(t,n,e.depth+e.parens+1,e.quote==='"')?.raw??"$";lt(e,o,!!e.quote),e.i+=o.length}function wm(e){let t=e.i++;for(;e.i<e.line.length;){let n=e.line[e.i++];if(n==="`"){lt(e,e.line.slice(t,e.i),!!e.quote);return}n==="\\"&&e.i<e.line.length&&e.i++}throw new Error("unterminated backtick substitution")}function xm(e,t){Bi(e);let n=t.token;if(n.kind==="paren_close"){if(e.parens===0){if(e.heredocs.length)throw new w("feature","command substitution heredoc","a command substitution heredoc must finish before its closing parenthesis");return!0}e.parens--,e.command=!1}else if(n.kind==="paren_open"){if(e.depth+ ++e.parens>=Dt)throw Yu();e.command=!0}else n.kind==="redir"?(e.command=!1,n.op==="heredoc"&&e.heredocs.push(n),["dup","close"].includes(n.op)||(e.target=n)):e.command=!0;return e.i=t.end,!1}function ym(e){if(Bi(e),e.heredocs.some(t=>t.delim===null))throw new Error("heredoc requires a delimiter");e.heredocs.length&&(e.i=e.helpers.readHeredocBodies(e.line,e.i,e.heredocs),e.heredocs=[]),e.command=!0,e.i++}function ze(e){return Number.isInteger(e)&&e>=0&&e<=1114111&&(e<55296||e>57343)}var St=e=>e>65535?2:1,ke=(e,t)=>St(e.codePointAt(t));var bm=/^(?:[A-Za-z_][A-Za-z0-9_]*|[0-9]+|[?*@#$!-])(?![\s\S])/u,vm=/^(?:[A-Za-z_][A-Za-z0-9_]*|[0-9]+|[?*@#$!-])/u;function Et(e,t="unsupported or malformed parameter expansion"){return new w("feature","${",`${t}: \${${e}}`)}var Wi=e=>/^[0-9]+$/u.test(e)?e.replace(/^0+(?=[0-9])/u,""):e;function zi(e){let t=e.replaceAll(`\\
13
- `,"");if(t.startsWith("#")&&t.length>1&&bm.test(t.slice(1)))return{name:Wi(t.slice(1)),operator:"length"};if(/^#[A-Za-z_0-9]/u.test(t))throw Et(e);let n=vm.exec(t)?.[0];if(!n)throw Et(e);let r=t.slice(n.length);if(!r)return{name:Wi(n),operator:""};if(n==="#"&&/^[%:=+/]$/u.test(r))throw Et(e);let i=/^(?::[-+=?]|[-+=?]|##?|%%?|:|\/\/?)/u.exec(r)?.[0];if(!i)throw Et(e);return{name:Wi(n),operator:i,word:e.slice(km(e,n.length+i.length))}}function km(e,t){let n=0;for(;t>0;)e[n]==="\\"&&e[n+1]===`
14
- `?n+=2:(t--,n++);return n}var ct=(e,t)=>new w("feature",e,t),Ku=e=>{if(e>=64)throw ct("expansion depth","shell expansion nesting above 64 levels is not supported")};function Ju(e,t,n,r,i,o){Ku(r);let s=n+1,u=null;for(let a=s;a<e.length;a++){let l=e[a];if(u==="'"){l==="'"&&(u=null);continue}if(l==="\\"){a++;continue}if(l==='"'){u=u==='"'?null:'"';continue}if(l==="'"&&!u){u="'";continue}if(l==="`")throw ct("`","command substitution (backticks) is not supported");if(l==="$"){let c=a+1;for(;e[c]==="\\"&&e[c+1]===`
15
- `;)c+=2;if(e[c]==="'"&&!u){let d=o.decodeAnsiC(e,c+1),p=zi(e.slice(s,a)).operator;if(i&&/[-+?=]/u.test(p)&&/[$`"'\\}]/u.test(d.text))throw ct("${","active characters in ANSI-C quoted parameter operands are not supported");a=d.end-1;continue}let f=o.readExpansion(e,a,r+1,i||u==='"');if(f){a+=f.raw.length-1;continue}}if(l==="}"&&!u){let c=zi(e.slice(s,a));return{raw:e.slice(t,a+1),parameter:c}}}throw ct("${","unterminated parameter expansion")}function Qu(e,t,n,r,i){Ku(r);let o=0;for(let s=n+1;s<e.length;s++){let u=e[s];if(u==="\\"){s++;continue}if(u==="$"){let l=i.readExpansion(e,s,r+1,!0);if(l){s+=l.raw.length-1;continue}}if(u==="`")throw ct("`","command substitution (backticks) is not supported");if(u==='"'||u==="'")throw ct("$((","quotes in arithmetic expressions are not supported");if(u==="("&&o++,u!==")")continue;if(o){o--;continue}let a=s+1;for(;e[a]==="\\"&&e[a+1]===`
16
- `;)a+=2;if(e[a]!==")")throw ct("$((","arithmetic expansion requires a closing `))`");return{raw:e.slice(t,a+1),arithmetic:e.slice(n+1,s)}}throw ct("$((","unterminated arithmetic expansion")}var Sm=/^-[abcdefghknoprstuvwxzGLNORS]$/u,Em=new Set(["=","==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"]),$m=new Set(["end","&&","||",")"]),Nm=/^[A-Za-z_][A-Za-z0-9_]*$/u;function vn(e,t,n,r=0){let i={line:e,i:t+2,helpers:n,token:null,depth:0,terms:0,removed:0,expansionDepth:r};try{qe(i,!0);let o=ra(i);return i.token.kind!=="end"&&ft(`unexpected token \`${i.token.value??i.token.kind}\``),{raw:e.slice(t,i.i+i.removed),expression:o}}catch(o){if(o instanceof w||o.conditional)throw o;ft(o.message)}}function ra(e){let t=ea(e);for(;e.token.kind==="||";)qe(e,!0),t={kind:"or",left:t,right:ea(e)};return t}function ea(e){let t=qi(e);for(;e.token.kind==="&&";)qe(e,!0),t={kind:"and",left:t,right:qi(e)};return t}function qi(e){if(++e.terms>128)throw new w("feature","[[ complexity","conditional expressions above 128 terms are not supported");if(++e.depth>64)throw new w("feature","[[ nesting","conditional nesting above 64 levels is not supported");try{let t=e.token;if(t.kind==="("){qe(e,!0);let i=ra(e);return e.token.kind!==")"&&ft("expected `)`"),qe(e,!0),i}if(ia(t,"!"))return qe(e,!0),{kind:"not",expression:qi(e)};if(t.kind!=="word"&&ft("expected an operand"),qe(e),!t.quoted&&Sm.test(t.value)){let i=ta(e);return qe(e,!0),{kind:"unary",op:t.value,word:i}}if($m.has(e.token.kind))return{kind:"unary",op:"-n",word:t};let n=e.token;if((n.quoted||!Em.has(n.value))&&ft("conditional binary operator expected"),n.value==="=~")throw new w("feature","[[ =~","regular expression comparisons in [[ are not supported");qe(e);let r=ta(e);return qe(e,!0),{kind:"binary",op:n.value,left:t,right:r}}finally{e.depth--}}var ia=(e,t)=>e.kind==="word"&&!e.quoted&&e.value===t,ft=e=>{throw Object.assign(new Error(`[[ ${e}`),{conditional:!0})};function ta(e){return e.token.kind!=="word"&&ft("expected an operand"),e.token}function qe(e,t=!1){if(e.token=na(e),t)for(;e.token.kind==="newline";)e.token=na(e)}function na(e){for(;e.i<e.line.length;){let t=e.line[e.i];if(t===" "||t===" "){e.i++;continue}if(t==="\\"&&e.line[e.i+1]===`
17
- `){e.i+=2;continue}if(t==="#"){let i=e.line.indexOf(`
18
- `,e.i);e.i=i<0?e.line.length:i;continue}if(t===`
19
- `)return e.i++,{kind:"newline"};let n=e.line.slice(e.i,e.i+2);if(n==="<("||n===">(")throw new w("feature",n,`process substitution (\`${n}\u2026\`) is not supported`);if(n==="&&"||n==="||")return e.i+=2,{kind:n};if("()<>;&|".includes(t))return e.i++,{kind:t,value:t};let r=Am(e);return ia(r,"]]")?{kind:"end"}:r}ft("missing `]]`")}function Am(e){let t={kind:"word",value:"",mask:"",quoted:!1,empty:[]},n=null,r=0;for(;e.i<e.line.length;){let i=e.line[e.i];if(n&&i===n){t.value.length===r&&t.empty.push(r),t.quoted=!0,n=null,e.i++;continue}if(n==="'"){Se(t,i,"1"),e.i++;continue}if(i==="\\"){Im(e,t,n);continue}if(i==="$"){if(Om(e),!n&&e.line[e.i+1]==='"'){n='"',r=t.value.length,e.i+=2;continue}Cm(e,t,n);continue}if(i==="`"){let o=Te(e.line,e.i);Se(t,"`",n?"2":"0"),Se(t,o.raw.slice(1),"1"),e.i+=o.raw.length;continue}if(n){Se(t,i,"2"),e.i++;continue}if(i==="'"||i==='"'){n=i,r=t.value.length,e.i++;continue}if(i==="("&&t.mask.at(-1)==="0"&&/[?*+@!]/u.test(t.value.at(-1))&&!t.empty.includes(t.value.length))throw new w("feature","[[ extglob","extended glob patterns in [[ are not supported");if(/[ \t\n()<>;&|]/u.test(i))break;Se(t,i,"0"),e.i++}return n&&ft(`unterminated ${n==="'"?"single":"double"} quote`),!t.quoted&&!/[12]/u.test(t.mask)&&(t.mask=null),t.empty.length===0&&delete t.empty,t}function Se(e,t,n,r=n!=="0"){e.value+=t,e.mask+=n.repeat(t.length),e.quoted||=r}function Im(e,t,n){let r=e.line[e.i+1];if(r===`
20
- `){e.i+=2;return}r!==void 0&&(!n||'$`"\\'.includes(r))?(Se(t,r,"1"),e.i+=2):(Se(t,"\\",n?"2":"1"),e.i++)}function Om(e){for(;e.line[e.i+1]==="\\"&&e.line[e.i+2]===`
21
- `;)e.line=e.line.slice(0,e.i+1)+e.line.slice(e.i+3),e.removed+=2}function Cm(e,t,n){let r=n?"2":"0";if(!n&&e.line[e.i+1]==="'"){let o=e.helpers.decodeAnsiC(e.line,e.i+2);o.text===""&&t.empty.push(t.value.length),Se(t,o.text,"1"),e.i=o.end;return}let i=e.helpers.readExpansion(e.line,e.i,e.expansionDepth+1,!!n);if(!i){Se(t,"$","1"),e.i++;return}if(i.command!==void 0||i.parameter!==void 0||i.arithmetic!==void 0)Se(t,"$",r),Se(t,i.raw.slice(1),"1",!1);else{let o=e.line[e.i+i.raw.length],s=Nm.test(i.name)&&(o==="'"||o==='"')?"${"+i.name+"}":i.raw;Se(t,s,r)}e.i+=i.raw.length}var $t=/^[A-Za-z_][A-Za-z0-9_]*$/u,Fm=/[A-Za-z0-9_]/u,Tm=/[?#@*$!0-9-]/u;function ne(e,t){for(;e[t]==="\\"&&e[t+1]===`
22
- `;)t+=2;return t}function ji(e,t,n=null){let r=s=>s<e.length&&(n===null||n[s]===n[t]);if(!r(t+1))return null;let i=e[t+1];if(Tm.test(i))return{name:i,raw:e.slice(t,t+2)};if(!/[A-Za-z_]/u.test(i))return null;let o=t+2;for(;r(o)&&Fm.test(e[o]);)o++;return{name:e.slice(t+1,o),raw:e.slice(t,o)}}function _e(e,t,n=0,r=!1,i={}){let o=(a,l,c,f)=>_e(a,l,c,f,i),s=ne(e,t+1),u=e[s];if(u==="("){let a=ne(e,s+1);if(e[a]==="(")return Qu(e,t,a,n,{readExpansion:o});let l=Ui(e,t,s,n,{readExpansion:o,decodeAnsiC:Ut,readHeredocBodies:Sn,readOperator:wr,readConditional:vn,skipContinuations:ne});return i.validateSubstitution?.(l.command),l}if(u==="{")return Ju(e,t,s,n,r,{readExpansion:o,decodeAnsiC:Ut});if(u==="[")throw new w("feature","$[","arithmetic expansion (`$[\u2026]`) is not supported");return ji(e,t)}function gr(e,t,n={}){let r=(s,u,a,l)=>_e(s,u,a,l,n),i=ne(e,t+1),o=Ui(e,t,i,0,{readExpansion:r,decodeAnsiC:Ut,readHeredocBodies:Sn,readOperator:wr,readConditional:vn,skipContinuations:ne});return n.validateSubstitution?.(o.command),o}var oa={a:"\x07",b:"\b",e:"\x1B",E:"\x1B",f:"\f",n:`
23
- `,r:"\r",t:" ",v:"\v","\\":"\\","'":"'",'"':'"',"?":"?"};function _m(e,t){for(let n=t;n<e.length;n++)if(e[n]==="\\")n++;else if(e[n]==="'")return n;throw new Error("unterminated single quote")}function Ut(e,t){let n=_m(e,t),r=[],i=s=>{for(let u of I(s))r.push(u)};for(let s=t;s<n;s++){if(e[s]!=="\\"){let l=String.fromCodePoint(e.codePointAt(s));i(l),s+=l.length-1;continue}let u=e[s+1];if(u in oa){i(oa[u]),s++;continue}if(u==="x"&&e[s+2]==="{")throw new w("feature","ANSI-C hexadecimal escape","braced hexadecimal escapes in ANSI-C quotes are not supported");let a=/^(?:[0-7]{1,3}|x[0-9a-fA-F]{1,2}|u[0-9a-fA-F]{1,4}|U[0-9a-fA-F]{1,8})/u.exec(e.slice(s+1,n));if(a){let l=a[0],c=/^[0-7]/u.test(l),f=c?parseInt(l,8):parseInt(l.slice(1),16);if(c||l[0]==="x")r.push(f&255);else{if(!ze(f))throw new w("feature","ANSI-C Unicode escape","ANSI-C escapes outside Unicode scalar values are not supported");i(String.fromCodePoint(f))}s+=l.length;continue}if(u==="c"&&s+2<n){let l=e.codePointAt(s+2);if(l>127)throw new w("feature","ANSI-C control escape","ANSI-C control escapes require an ASCII character");r.push(l===63?127:l&31),s+=2,l===92&&e[s+1]==="\\"&&s++;continue}i("\\")}let o=r.indexOf(0);return{text:M(Uint8Array.from(o===-1?r:r.slice(0,o))),end:n+1}}function wr(e,t,n){let r=e[t];if(n&&/[0-9]/u.test(r)){let s="",u=t;for(;/[0-9]/u.test(e[u]??"");)s+=e[u],u=ne(e,u+1);return e[u]!==">"&&e[u]!=="<"||e[ne(e,u+1)]==="("?null:sa(e,u,Number(s))}let i=ne(e,t+1),o=e[i];switch(r){case"|":return o==="|"?Je("or",i+1):o==="&"?Je("pipe_err",i+1):Je("pipe",t+1);case"&":if(o==="&")return Je("and",i+1);if(o===">"){let s=ne(e,i+1),u=e[s]===">";return dt(1,u?"bothAppend":"both",(u?s:i)+1)}return Je("amp",t+1);case";":return o===";"?Je("dsemi",i+1):Je("semi",t+1);case"(":return Je("paren_open",t+1);case")":return Je("paren_close",t+1);case"<":case">":return sa(e,t,r==="<"?0:1);default:return null}}var Lm={semi:";",dsemi:";;",pipe:"|",pipe_err:"|&",and:"&&",or:"||",amp:"&",paren_open:"(",paren_close:")"},Rm={write:">",append:">>",read:"<",heredoc:"<<",herestring:"<<<",both:"&>",bothAppend:"&>>",dup:">&",close:">&-"};function kn(e){if(e.kind==="word")return e.quoted?`"${e.value}"`:e.value;if(e.kind==="redir"){let t=Rm[e.op];if(e.op==="both"||e.op==="bothAppend")return t;let n=e.fd===(e.op==="read"||e.op==="heredoc"||e.op==="herestring"?0:1)?"":String(e.fd);return e.op==="dup"?`${n}${e.fd===0?"<&":">&"}${e.toFd}`:e.op==="close"?`${n}${e.fd===0?"<&-":">&-"}`:n+t}return Lm[e.kind]}var Je=(e,t)=>({token:{kind:e},end:t}),dt=(e,t,n,r)=>({token:{kind:"redir",fd:e,op:t,...r},end:n});function sa(e,t,n){let r=e[t],i=ne(e,t+1),o=e[i];if(o==="&")return Mm(e,i,n,r==="<"?"<&":`${n===1&&r===">"?"":n}>&`);if(r==="<"){if(o===">")throw new w("feature","<>","read/write file redirects are not supported");if(o==="<"){let s=ne(e,i+1);if(e[s]==="<")return dt(n,"herestring",s+1);let u=e[s]==="-";return dt(n,"heredoc",(u?s:i)+1,{strip:u,delim:null,body:null})}return dt(n,"read",t+1)}return o===">"?dt(n,"append",i+1):dt(n,"write",(o==="|"?i:t)+1)}function Mm(e,t,n,r){let i=ne(e,t+1),o=e[i],s=e[ne(e,i+1)],u=s===void 0||/[ \t\n|&>;()<]/u.test(s);if(/[0-9]/u.test(o??"")&&u)return dt(n,"dup",i+1,{toFd:Number(o)});if(o==="-"&&u)return dt(n,"close",i+1);throw new w("feature","redirect target",`redirect \`${r}\` requires a file descriptor number (or \`-\`) followed by a token boundary`)}function Sn(e,t,n){let r=t+1;for(let i of n){let o=[],s=!1;for(;r<e.length;){let u,a="";for(;;){u=e.indexOf(`
24
- `,r);let l=u===-1?e.length:u;if(a+=e.slice(r,l),r=l+1,i.quotedDelim||u===-1||!Pm(a))break;a=a.slice(0,-1)}if(u===-1&&a==="")break;if(i.strip&&(a=a.replace(/^\t+/u,"")),a===i.delim){s=!0;break}if(o.push(a),u===-1)break}i.body=o.length===0?"":o.join(`
3
+ `,exitCode:t}),pe=(e,t=1)=>x(`usage: ${e}`,t);var sa=Symbol("unsupported");function O(e){if(e==null)return null;try{return e[sa]??null}catch{return null}}function v(e,t,n,r,o=1){return ie(x(r,o),e,t,n,r)}function ie(e,t,n,r,o){return Object.defineProperty(e,sa,{value:{kind:t,command:n,detail:r,message:o},enumerable:!1,configurable:!0}),e}function K(e,t,n,r){let o=O(e);return o?v(o.kind,t,o.detail,n,r):x(n,r)}var b=class extends Error{constructor(t,n,r){super(r),this.name="UnsupportedError",ie(this,t,null,n,r)}};function ei(){let e=new Set,t=[];return{entries:t,add(n,r=n.command){let o=JSON.stringify([n.kind,r,n.detail]);e.has(o)||(e.add(o),t.push(Object.freeze(n)))}}}var{Buffer:ua}=globalThis,la=ua&&!ua.TYPED_ARRAY_SUPPORT;var aa=e=>e&&(la||`${e}`.includes("[native code]"));!la&&aa(()=>{})&&(aa=()=>!1);function ti(e,t){let n=e.length;for(let r=0;r<n;r++)t[r]=e.charCodeAt(r);return t}var kn=null,Ot=!1,fa=!1,Ae=new TextEncoder,Oe=new TextDecoder("utf-8",{ignoreBOM:!0}),ni=new TextDecoder("latin1",{ignoreBOM:!0});var ri=globalThis.Buffer;function Zt(e){if(!(e&&e instanceof Uint8Array))throw new TypeError("Expected an Uint8Array")}var Yt="Input is not a string",oi="Input is not well-formed Unicode";function et(e,t){switch(t){case"uint8":if(e.constructor!==Uint8Array)throw new Error("Unexpected");return e;case"arraybuffer":if(e.byteLength!==e.buffer.byteLength)throw new Error("Unexpected");return e.buffer;case"buffer":return e.length<=64?ri.from(e):ri.from(e.buffer,e.byteOffset,e.byteLength)}throw new TypeError("Unexpected format")}function ca(e,t){switch(t){case"uint8":return e.length<=64||e.byteOffset!==0||e.byteLength!==e.buffer.byteLength?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength);case"arraybuffer":return e.buffer.byteLength===e.byteLength?e.buffer:e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength);case"buffer":if(e.constructor!==ri)throw new Error("Unexpected");return e}throw new TypeError("Unexpected format")}var km=Oe,vm=Oe?new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}):null,{isWellFormed:pa}=String.prototype;function Sm(e,t,n){if(t||e.length===n.length)return n;if(pa){if(pa.call(e))return n;throw new TypeError(oi)}let r=0,o=n.length-3;for(;r<=o;){let i=n.indexOf(239,r);if(i===-1||i>o)break;if(r=i+1,n[i+1]===191&&n[i+2]===189){if(null)try{if(encodeURI(e)!==null)return n}catch{}else if(e===ii(n))return n;throw new TypeError(oi)}}return n}function ha(e,t=!1){if(typeof e!="string")throw new TypeError(Yt);return e.length===0?new Uint8Array:Ae||!null?Sm(e,t,Ae.encode(e)):null(e,t)}function ii(e,t=!1){return Zt(e),e.byteLength===0?"":Oe||!null?t?km.decode(e):vm.decode(e):null(e,t)}var ma=(e,t="uint8")=>et(ha(e,!1),t),A=(e,t="uint8")=>et(ha(e,!0),t),si=e=>ii(e,!1),ga=e=>ii(e,!0);function B(e){try{return ma(e)}catch(t){throw t instanceof TypeError?new b("feature","unpaired surrogate","unpaired UTF-16 surrogates cannot be encoded as UTF-8"):t}}var Em=e=>e<128?1:e>=194&&e<=223?2:e>=224&&e<=239?3:e>=240&&e<=244?4:0;function*Nr(e){for(let t=0;t<e.length;){let n=Em(e[t]),r=n===1?e[t]:n===0?-1:Nm(e,t,n);yield r,t+=r<0?1:n}}var $m=[0,0,128,2048,65536];function Nm(e,t,n){if(t+n>e.length)return-1;let r=e[t]&127>>n;for(let o=1;o<n;o++){if((e[t+o]&192)!==128)return-1;r=r<<6|e[t+o]&63}return r<$m[n]||r>1114111||r>=55296&&r<=57343?-1:r}var ui=e=>ga(e);function me(e){let t;try{t=si(e)}catch{}return t}function vn(e){if(e.length===1)return e[0];let t=new Uint8Array(e.reduce((r,o)=>r+o.length,0)),n=0;for(let r of e)t.set(r,n),n+=r.length;return t}function W(e){try{return si(e)}catch{throw new b("feature","partial UTF-8 byte sequence","byte output that is not valid UTF-8 cannot be represented by this string-based terminal")}}function Ar(e){if(Object.keys(e).length>0)throw new TypeError("Unexpected extra options")}var g$=Object.getPrototypeOf(Uint8Array);var ya=globalThis.atob,ba=Uint8Array.prototype.toBase64,wa=8192,Am=ba&&ya;function ai(e,t=0,n=e.length){t|=0,n|=0;let r=n-t;if(r===0)return"";if(Am&&r>=256&&r<1e8&&e.toBase64===ba&&e.BYTES_PER_ELEMENT===1){let i=t===0&&n===e.length?e:e.subarray(t,n);return ya(i.toBase64())}if(r>wa){let i="";for(let s=t;s<n;){let u=Math.min(n,s+wa);i+=String.fromCharCode.apply(String,e.subarray(s,u)),s=u}return i}let o=t===0&&n===e.length?e:e.subarray(t,n);return String.fromCharCode.apply(String,o)}var Or=kn?e=>e.byteLength>=768&&!fa?kn.from(e.buffer,e.byteOffset,e.byteLength).latin1Slice(0,e.byteLength):Oe.decode(e):ni?e=>ni.decode(e):e=>ai(e instanceof Uint8Array?e:new Uint8Array(e.buffer,e.byteOffset,e.byteLength));var xa=e=>ti(e,new Uint8Array(e.length)),Om=Ot&&Ae?.encodeInto,Cr=Om?(e,t)=>{let n=new Uint8Array(e.length+4),r=Ae.encodeInto(e,n);if(r.read!==e.length||r.written!==e.length)throw new SyntaxError(t);return n.subarray(0,e.length)}:kn?(e,t)=>{let n=kn.from(e,"utf8");if(n.length!==e.length)throw new SyntaxError(t);return new Uint8Array(n.buffer,n.byteOffset,n.byteLength)}:(e,t)=>{let n=Ae.encode(e);if(n.length!==e.length)throw new SyntaxError(t);return n};var di={};ym(di,{E_CHAR:()=>Vt,E_LAST:()=>li,E_LENGTH:()=>Na,E_PADDING:()=>$a,fromBase64:()=>ci,toBase64:()=>fi});var ka=[..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"],va=[..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"],Sa={},Ea={},Vt="Invalid character in base64 input",$a="Invalid base64 padding",Na="Invalid base64 length",li="Invalid last chunk";function fi(e,t,n){let r=e.length/3|0,o=r*3,i="",s=0,u=t?va:ka,a=t?Ea:Sa;if(!a.pairs)if(a.pairs=[],Oe){a.codepairs=new Uint16Array(4096);let h=a.codepairs,m=new Uint8Array(h.buffer,h.byteOffset,h.byteLength);for(let g=0;g<64;g++){let w=u[g].charCodeAt(0);for(let y=0;y<64;y++)m[g<<7|y<<1]=m[y<<7|(g<<1)+1]=w}}else{let h=a.pairs;for(let m=0;m<64;m++)for(let g=0;g<64;g++)h.push(`${u[m]}${u[g]}`)}let{pairs:l,codepairs:f}=a;if(Oe){let h=new Uint16Array(r*2),m=0;for(let g=e.length-11;s<g;s+=12,m+=8){let w=e[s],y=e[s+1],k=e[s+2],S=e[s+3],I=e[s+4],M=e[s+5],C=e[s+6],H=e[s+7],Y=e[s+8],D=e[s+9],de=e[s+10],Xt=e[s+11];h[m]=f[w<<4|y>>4],h[m+1]=f[(y&15)<<8|k],h[m+2]=f[S<<4|I>>4],h[m+3]=f[(I&15)<<8|M],h[m+4]=f[C<<4|H>>4],h[m+5]=f[(H&15)<<8|Y],h[m+6]=f[D<<4|de>>4],h[m+7]=f[(de&15)<<8|Xt]}for(let g=e.length-2;s<g;s+=3,m+=2){let w=e[s],y=e[s+1],k=e[s+2];h[m]=f[w<<4|y>>4],h[m+1]=f[(y&15)<<8|k]}i=Or(h)}else for(;s<o;s+=3){let h=e[s],m=e[s+1],g=e[s+2];i+=l[h<<4|m>>4],i+=l[(m&15)<<8|g]}let c=0,d=2,p=e.length;for(;s<p;s++){let h=e[s];i+=u[c|h>>d],d===6&&(d=0,i+=u[h&63]),c=h<<6-d&63,d+=2}return d!==2&&(i+=u[c]),n&&(i+=["","==","="][p-o]),i}var Cm=Ae?128:65536;function ci(e,t){let n=e.length;for(;e[n-1]==="=";)n--;let r=e.length-n,o=n%4,i=n-o;if(o===1)throw new SyntaxError(Na);if(r>3||r!==0&&e.length%4!==0)throw new SyntaxError($a);let s=t?va:ka,u=t?Ea:Sa;u.fromMap||(u.fromMap=new Int8Array(Cm).fill(-1),s.forEach((h,m)=>u.fromMap[h.charCodeAt(0)]=m));let a=u.fromMap,l=new Uint8Array(Math.floor(n*3/4)),f=0,c=0;if(Ae){let h=Cr(e,Vt);for(;c<i;c+=4){let m=h[c],g=h[c+1],w=h[c+2],y=h[c+3],k=a[m]<<18|a[g]<<12|a[w]<<6|a[y];if(k<0)throw new SyntaxError(Vt);l[f]=k>>16,l[f+1]=k>>8&255,l[f+2]=k&255,f+=3}}else for(;c<i;c+=4){let h=e.charCodeAt(c),m=e.charCodeAt(c+1),g=e.charCodeAt(c+2),w=e.charCodeAt(c+3),y=a[h]<<18|a[m]<<12|a[g]<<6|a[w];if(y<0)throw new SyntaxError(Vt);l[f]=y>>16,l[f+1]=y>>8&255,l[f+2]=y&255,f+=3}if(o<2)return l;let d=a[e.charCodeAt(c++)]<<6|a[e.charCodeAt(c++)];if(d<0)throw new SyntaxError(Vt);if(l[f++]=d>>4,o<3){if(d&15)throw new SyntaxError(li);return l}let p=a[e.charCodeAt(c++)];if(p<0)throw new SyntaxError(Vt);if(l[f++]=d<<4&255|p>>2,p&3)throw new SyntaxError(li);return l}var{Buffer:Ct,atob:Ia,btoa:Ta}=globalThis,Fa=Ct&&!Ct.TYPED_ARRAY_SUPPORT,{toBase64:Aa}=Uint8Array.prototype,{E_CHAR:Sn,E_PADDING:Ir,E_LENGTH:Im,E_LAST:Tm}=di,Fm=Ta&&Ot,Lm=Ia&&Ot,_m=e=>e.constructor===Ct&&Ct.isBuffer(e),Rm=e=>_m(e)?e:Ct.from(e.buffer,e.byteOffset,e.byteLength);function pi(e,t){if(t)return e;let n=e.indexOf("=",e.length-3);return n===-1?e:e.slice(0,n)}function Mm(e,t){return t&&e.length%4!==0?e+"=".repeat(4-e.length%4):e}var Pm=e=>Aa&&e.toBase64===Aa;function hi(e,{padding:t=!0}={}){return Zt(e),Pm(e)?t?e.toBase64():e.toBase64({omitPadding:!t}):Fa?pi(Rm(e).base64Slice(0,e.byteLength),t):Fm?pi(Ta(ai(e)),t):fi(e,!1,t)}function $n(e,t){if(typeof t=="string"&&(t={format:t}),!t)return Oa(e,!1,"both","uint8",null);let{format:n="uint8",padding:r="both",...o}=t;return Oa(e,!1,r,n,o)}function Oa(e,t,n,r,o){if(typeof e!="string")throw new TypeError(Yt);o!==null&&Ar(o);let i=n==="both"?e.endsWith("="):void 0;if(n===!0||i===!0){if(e.length%4!==0)throw new SyntaxError(Ir);if(e[e.length-3]==="=")throw new SyntaxError(Ir)}else if(n===!1||i===!1){if(e.length%4===1)throw new SyntaxError(Im);if(n===!1&&e.endsWith("="))throw new SyntaxError("Did not expect padding in base64 input")}else throw new TypeError("Invalid padding option");return En(e,t,n,r)}var Dm=/[\t\n\f\r ]/;function Ca(e,t){let n=e.indexOf("=",e.length-3),r=n>=0?e.length-n:0,o=e.length-r,i=o%4,s=t.length-(o-i)/4*3;return i===0&&s===0||i===2&&s===1||i===3&&s===2}var En;Uint8Array.fromBase64?En=(e,t,n,r)=>{let o=t?"base64url":"base64",i;if(n===!0)i=Uint8Array.fromBase64(e,{alphabet:o,lastChunkHandling:"strict"});else try{let s=e.length%4>0?`${e}${"=".repeat(4-e.length%4)}`:e;i=Uint8Array.fromBase64(s,{alphabet:o,lastChunkHandling:"strict"})}catch(s){throw Dm.test(e)?new SyntaxError(Sn):s}if(!Ca(e,i))throw new SyntaxError(Sn);return et(i,r)}:Fa?En=(e,t,n,r)=>{let o=Ct.byteLength(e,"base64"),i=Ct.allocUnsafeSlow(o);if(i.base64Write(e)!==o)throw new SyntaxError(Ir);let s=t?pi(e,n===!1):Mm(e,n!==!0),u=t?i.base64urlSlice(0,i.length):i.base64Slice(0,i.length);if(s!==u)throw new SyntaxError(Ir);return ca(i,r)}:Lm?En=(e,t,n,r)=>{let o;if(t){if(/[\t\n\f\r +/]/.test(e))throw new SyntaxError(Sn);e=e.replaceAll("-","+").replaceAll("_","/")}try{o=xa(Ia(e))}catch{throw new SyntaxError(Sn)}if(!t&&!Ca(e,o))throw new SyntaxError(Sn);if(o.length%3!==0){let i=hi(o.subarray(-(o.length%3))),s=e.length%4===0?e.slice(-4):e.slice(-(e.length%4)).padEnd(4,"=");if(i!==s)throw new SyntaxError(Tm)}return et(o,r)}:En=(e,t,n,r)=>et(ci(e,t),r);function Nn(e){let t=e.startsWith("/"),n=e.split("/").filter(Boolean),r=[];for(let o of n)if(o!=="."){if(o===".."){r.length>0&&r.at(-1)!==".."?r.pop():t||r.push("..");continue}r.push(o)}return t?"/"+r.join("/"):r.length===0?".":r.join("/")}function Z(e,t){return t.startsWith("/")?Nn(t):Nn(e+"/"+t)}var Bm=40,Tr=(e,t)=>e.isLink?.(t)===!0;function E(e,t,n,{follow:r=!0}={}){let o=ze(e,t,n,{follow:r});return o.error?{path:null,error:o.error}:t.endsWith("/")&&!n.isDir(o.path)?{path:null,error:"Not a directory"}:{path:o.path,error:null}}function ze(e,t,n,{follow:r=!0,lenient:o=!1}={}){if(t===""||t.includes("\0"))return{path:"/",error:"No such file or directory",rest:[]};let i=(t.startsWith("/")?t:e+"/"+t).split("/").filter(Boolean),s=r||t.endsWith("/"),u=Bm,a="/";for(;i.length>0;){let f=i.shift();if(!n.isDir(a)){if(!o){let d=n.isFile(a)||Tr(n,a)?"Not a directory":"No such file or directory";return{path:a,error:d,rest:[f,...i]}}f===".."?a=ye(a):f!=="."&&(a=Te(a,f));continue}if(f===".."){a=ye(a);continue}if(f!=="."&&(a=Te(a,f)),!Tr(n,a)||n.isDir(a)||i.length===0&&!s)continue;if(u--===0)return{path:a,error:"Too many levels of symbolic links",rest:[...i]};let c=n.readLink(a);a=c.startsWith("/")?"/":ye(a),i.unshift(...c.split("/").filter(Boolean),...c.endsWith("/")?["."]:[])}let l=!n.isDir(a)&&!n.isFile(a)&&!Tr(n,a);return{path:a,error:l?"No such file or directory":null,rest:[]}}var se=(e,t,n,r=!0)=>n===""||n.includes("\0")?Z(t,n):ze(t,n,e,{follow:r,lenient:!0}).path;function tt(e,t,n,r=E(e,t,n)){if(r.path!==null)return null;if(t===""||t.includes("\0")||t.endsWith("/")||r.error!=="No such file or directory")return r.error;let o=ze(e,t,n);return o.rest.length>0?o.error:n.isDir(ye(o.path))?null:"Not a directory"}function ye(e){let t=Nn(e);if(t==="/")return"/";let n=t.lastIndexOf("/");return n<0?".":n===0?"/":t.slice(0,n)}function nt(e){let t=Nn(e);if(t==="/")return"/";let n=t.lastIndexOf("/");return t.slice(n+1)}function j(e,t){for(let n=0;n<Math.min(e.length,t.length);n++)if(e[n]!==t[n])return e.codePointAt(n)-t.codePointAt(n);return e.length-t.length}function Te(e,t){return e==="/"?"/"+t:e+"/"+t}function He(e,t){return e==="/"?t.slice(1):t.slice(e.length+1)}function _a(e,t="/"){let n=new Map,r=new Map;for(let[u,a]of Wm(e)){let l=String(u),f=qm(a,l);if(f===null)continue;if(l.includes("\0"))throw new TypeError("createTerminal: source paths must not contain NUL characters");let c=Nn("/"+l),d=t==="/"?c:c==="/"?t:t+c;f.link===void 0?(n.set(d,f.content),r.delete(d)):(r.set(d,f.link),n.delete(d))}let o=new Map([["/",{dirs:[],files:[],links:[]}]]);La(o,t);for(let[u,a]of[["files",n],["links",r]])for(let l of a.keys()){let f=l.lastIndexOf("/"),c=l.slice(0,f)||"/";La(o,c),o.get(c)[u].push(l==="/"?"/":l.slice(f+1))}for(let u of o.values())u.dirs.sort(j),u.files.sort(j),u.links.sort(j);let i=(u,a=!1)=>{let l=n.get(u);if(!(l instanceof Fr))return l;let f;try{f=l.decode()}catch(c){if(!(c instanceof SyntaxError))throw c;if(a)return;throw new b("feature","base64 source",`${JSON.stringify(u)} declares base64 that does not decode, so its bytes cannot be read`)}return n.set(u,f),f},s={isFile:u=>n.has(u),isDir:u=>o.has(u),isLink:u=>r.has(u),readLink:u=>r.get(u),readFile:u=>{let a=i(u);return a===void 0||typeof a=="string"?a:rt(a,JSON.stringify(u))},readBytes:(u,a=!1)=>{let l=i(u);return typeof l!="string"?l:a?A(l):B(l)},fileSize:u=>o.has(u)?void 0:r.has(u)?B(r.get(u)).length:n.has(u)?Um(n.get(u)):void 0,sameFileContents:(u,a)=>jm(i(u,!0),i(a,!0)),exactBytes:u=>mi(i(u,!0)),isBytes:u=>typeof n.get(u)=="object",isEmptyFile:u=>{let a=n.get(u);return typeof a=="string"?a==="":a?.length===0},listDir:u=>{let a=o.get(u);if(!a)throw new Error(`not a directory: ${u}`);return a},walkFiles:u=>Gm(s,u)};return s}var Um=e=>typeof e=="string"?B(e).length:e.length,mi=e=>typeof e=="string"?e.isWellFormed()?B(e):void 0:e;function rt(e,t,n="reading them as text"){let r=me(e);if(r===void 0)throw new b("feature","binary file",`${t} holds bytes that spell no text, and ${n} is not supported`);return r}var An=(e,t)=>e!==void 0&&t!==void 0&&e.length===t.length&&e.every((n,r)=>n===t[r]);function jm(e,t){return e===void 0||t===void 0?!1:typeof e=="string"&&typeof t=="string"?e===t:An(mi(e),mi(t))}function Wm(e){try{return Map.prototype.entries.call(e)}catch{return Object.entries(e??{})}}function qm(e,t){if(typeof e=="string")return{content:e};if(ArrayBuffer.isView(e))return{content:Hm(e,t)};if(e===null||typeof e!="object"||Array.isArray(e))return null;if(e instanceof ArrayBuffer)throw new TypeError(`createTerminal: source ${JSON.stringify(t)} is an ArrayBuffer; declare a file's bytes as a Uint8Array over it`);if(e.format!==void 0||e.data!==void 0)return{content:zm(e,t)};if(e.type===void 0&&e.target===void 0)return null;let n=JSON.stringify(t);if(e.type!=="link")throw new TypeError(`createTerminal: source ${n} declares type ${JSON.stringify(e.type??null)}; the only declaration is { type: 'link', target }`);let{target:r}=e;if(typeof r!="string"||r===""||r.includes("\0"))throw new TypeError(`createTerminal: link ${n} must declare a non-empty target without NUL characters`);return{link:r}}function zm(e,t){let n=JSON.stringify(t);if(e.format!=="base64")throw new TypeError(`createTerminal: source ${n} declares format ${JSON.stringify(e.format??null)}; the only format is { format: 'base64', data }`);if(typeof e.data!="string")throw new TypeError(`createTerminal: source ${n} must declare its base64 as a string in \`data\``);return new Fr(e.data)}var Fr=class{constructor(t){this.text=t;let n=t.endsWith("==")?2:t.endsWith("=")?1:0;this.length=Math.floor((t.length-n)*3/4)}decode(){return $n(this.text)}};function Hm(e,t){if(e.BYTES_PER_ELEMENT!==1)throw new TypeError(`createTerminal: source ${JSON.stringify(t)} is a ${e[Symbol.toStringTag]??"view"}; declare a file's bytes as a Uint8Array`);return new Uint8Array(e.buffer,e.byteOffset,e.byteLength).slice()}function*Fe(e,t,n=Number.POSITIVE_INFINITY,r=()=>!0){if(e.isFile(t)){yield{path:t,kind:"file",depth:0};return}if(!e.isDir(t)){Tr(e,t)&&(yield{path:t,kind:"link",depth:0});return}let o=[{path:t,kind:"dir",depth:0}];for(;o.length;){let i=o.pop();if(yield i,i.kind!=="dir"||i.depth>=n||!r(i.path))continue;let{dirs:s,files:u,links:a=[]}=e.listDir(i.path),l=s.length-1,f=u.length-1,c=a.length-1;for(;l>=0||f>=0||c>=0;){let d=l>=0?"dir":null,p=l>=0?s[l]:null;f>=0&&(p===null||j(u[f],p)>=0)&&(d="file",p=u[f]),c>=0&&(p===null||j(a[c],p)>=0)&&(d="link",p=a[c]),d==="dir"?l--:d==="file"?f--:c--,o.push({path:Te(i.path,p),kind:d,depth:i.depth+1})}}}function*Gm(e,t){for(let n of Fe(e,t))n.kind==="file"&&(yield n.path)}function La(e,t){let n=[],r=t;for(;r!=="/"&&!e.has(r);)n.push(r),r=r.slice(0,r.lastIndexOf("/"))||"/";for(let o=n.length-1;o>=0;o--){let i=n[o];e.set(i,{dirs:[],files:[],links:[]});let s=i.lastIndexOf("/");e.get(i.slice(0,s)||"/").dirs.push(i.slice(s+1))}}var It={__proto__:null,alpha:"A-Za-z",digit:"0-9",alnum:"0-9A-Za-z",upper:"A-Z",lower:"a-z",space:" \\t\\n\\v\\f\\r",blank:" \\t",punct:"!-\\/:-@\\[-`{-~",xdigit:"0-9A-Fa-f",cntrl:"\\x00-\\x1F\\x7F",print:"\\x20-\\x7E",graph:"\\x21-\\x7E",word:"0-9A-Za-z_"},gi={__proto__:null};for(let[e,t]of Object.entries(It)){let n=new RegExp(`[${t}]`,"u"),r=[];for(let o=0;o<128;o++){if(!n.test(String.fromCodePoint(o)))continue;let i=r.at(-1);i&&i[1]===o-1?i[1]=o:r.push([o,o])}gi[e]=r}var Lr=32767;function Ra(e,t){if(e>Lr||t!==void 0&&t>Lr)throw new Error("Regular expression too big")}function Ma(e,t,n=!1){let r=t+1;e[r]==="^"&&r++;let o=!0,i=!1;for(;r<e.length;){let s=e[r];if(s==="]"&&!o)return r;if(o=!1,s==="["&&":.=".includes(e[r+1]??"")){let l=e[r+1],f=e.indexOf(l+"]",r+2);if(f===-1)throw new Error("Unmatched [, [^, [:, [., or [=");if(l===":"&&!(e.slice(r+2,f)in It))throw new Error("Invalid character class name");if(l!==":"&&n&&/\P{ASCII}/u.test(e.slice(r+2,f)))throw new Error("Invalid collation character");r=f+2,i=l!==".";continue}if(s==="-"&&i&&r+1<e.length&&e[r+1]!=="]")throw new Error("Invalid range end");let u=s==="\\"&&r+1<e.length?2:1;if(e[r+u]==="-"&&e[r+u+1]!==void 0&&e[r+u+1]!=="]"){let l=r+u+1,f=e[l]==="["?e[l+1]:void 0;if(f===":"||f==="=")throw new Error("Invalid range end");let c=f==="."?e.indexOf(".]",l+2):-1;if(f==="."&&c===-1)throw new Error("Unmatched [, [^, [:, [., or [=");let d=f==="."?l+2:l+(e[l]==="\\"?1:0);if(n&&(e.codePointAt(r+u-1)>127||e.codePointAt(d)>127))throw new Error("Invalid collation character");r=c===-1?l+(e[l]==="\\"?2:1):c+2,i=!0;continue}r+=u,i=!1}throw new Error("Unmatched [, [^, [:, [., or [=")}function Kt(e,t,n={}){let r=/^\[:([a-z]+):\]/u.exec(e.slice(t));if(!r)return null;let o=n.classes?n.classes.body(r[1]):It[r[1]];if(o===void 0){if(n?.unknown!=="empty")throw new Error(`invalid character class \`[:${r[1]}:]\``);return{body:"",end:t+r[0].length}}return{body:o,end:t+r[0].length}}var _r={alpha:"1t:p,6:p,1b:0,a:0,4:0,5:m,1:u,1:cp,4:b,e:4,7:0,1:0,2e:0,16:4,1:1,2:3,1:0,6:0,1:2,1:0,1:j,1:2a,1:3u,8:4l,1:11,2:0,6:14,13:d,1:0,1:1,1:1,1:0,8:q,4:3,t:a,5:1j,1:g,4:2t,1:7,4:7,4:f,2:0,g:1b,d:2s,e:16,9:1,4:0,5:n,2:i,j:o,7:a,5:n,1:5,h:15,a:b,3:6,6:23,1:f,1:2,4:e,2:9,1:i,1:7,2:1,2:l,1:6,1:0,3:3,3:7,2:1,2:1,1:0,8:0,4:1,1:4,2:b,a:0,4:2,1:5,4:1,2:l,1:6,1:1,1:1,1:1,4:4,4:1,2:1,4:0,7:3,1:0,7:f,b:2,1:8,1:2,1:l,1:6,1:1,1:4,3:8,1:2,1:1,3:0,f:3,2:9,9:3,4:2,1:7,2:1,2:l,1:6,1:1,1:4,3:7,2:1,2:1,9:1,4:1,1:4,2:9,1:0,g:1,1:5,3:2,1:3,3:1,1:0,1:1,3:1,3:2,3:b,4:4,3:2,1:2,3:0,6:0,e:9,g:c,1:2,1:m,1:f,3:7,1:2,1:2,8:1,1:2,2:0,2:3,2:9,g:3,1:7,1:2,1:m,1:9,1:4,3:7,1:2,1:2,8:1,6:1,1:3,2:9,1:2,c:c,1:2,1:14,2:7,1:2,1:2,1:0,5:3,7:4,2:9,a:5,1:2,1:h,3:n,1:8,1:0,2:6,8:5,1:0,1:7,6:9,2:1,d:1l,5:6,6:0,2:9,13:1,1:0,1:4,1:n,1:0,1:i,1:2,2:4,1:0,6:0,2:9,2:3,w:0,v:9,m:7,1:z,4:i,4:f,1:z,1v:1i,1:0,2:e,6:25,2:11,1:0,5:0,2:16,1:98,1:3,2:6,1:0,1:3,2:14,1:3,2:w,1:3,2:6,1:0,1:3,2:e,1:1k,1:3,2:1u,11:f,g:2d,2:5,3:h7,2:g,1:p,5:22,3:a,7:j,b:k,c:j,c:c,1:2,1:1,c:1f,2:i,e:0,4:0,3:9,12:9,6:2g,7:16,5:1x,a:u,1:b,4:8,d:13,2:4,b:17,4:p,6:9,12:r,4:1q,2:j,b:9,6:9,d:0,n:1,b:2,1d:1f,1:e,1:7,3:9,12:15,2:1l,1:a,e:1i,9:9,3:1c,2:8,7:16,2:2,15:3,1:5,1:1,3:0,5:5b,13:d,b:7p,2:5,2:11,2:5,2:7,1:0,1:0,1:0,1:u,2:1g,1:6,1:0,3:2,1:6,3:3,2:5,4:c,5:2,1:6,38:0,d:0,g:c,2t:0,4:0,2:9,1:0,3:4,6:0,1:0,1:0,1:3,1:a,2:3,5:4,4:0,h:14,ml:1f,1ee:6c,6:3,3:1,c:11,1:0,5:0,2:1j,7:0,g:m,9:6,1:6,1:6,1:6,1:6,1:6,1:6,1:6,1:v,1b:0,d1:2,p:8,7:4,2:4,4:2d,6:2,1:2h,1:3,5:16,1:2l,h:v,1c:f,e8:533,1s:h3g,1v:19,2:7g,3:r,k:1a,5:7,3:34,13:8,2:2u,2:1r,5:1,1:0,1:4,o:j,1:w,o:1f,c:1v,1:0,a:9,o:5,3:0,1:19,5:y,d:s,3:1e,1:b,f:a,6:u,1:1i,9:d,2:9,6:m,3:1w,1:0,1:0,o:2,2:f,2:3,b:5,2:5,2:5,9:6,1:6,1:16,1:d,6:3e,5:9,6:8mb,c:m,4:1c,6is:a5,2:2x,12:6,c:4,5:b,1:c,1:4,1:0,1:1,1:1,1:2z,x:a2,i:1r,2:1h,14:b,38:4,1:3q,j:9,7:p,6:p,b:2g,3:5,2:5,2:5,2:2,z:b,1:p,1:i,1:1,1:e,2:d,y:3e,1x:1g,7f:s,3:1c,1b:v,d:t,5:16,5:t,2:z,4:7,1:4,16:4d,2:9,6:z,4:z,4:13,8:1f,c:a,1:e,1:6,1:1,1:a,1:e,1:6,1:1,1v:8m,9:l,a:7,o:5,1:15,1:8,1x:5,2:0,1:17,1:1,3:0,2:m,a:m,9:u,1t:i,1:1,a:l,a:p,1y:1j,6:1,1s:3,1:1,5:7,1:2,1:s,16:s,3:s,z:7,1:r,r:1h,a:l,a:i,d:h,32:20,1j:1e,d:1e,d:13,8:9,92:15,1:1,3:1,26:s,a:0,8:l,16:h,1a:k,r:m,9:1x,w:9,1:4,a:1k,9:0,d:o,7:9,6:1e,3:9,4:3,8:y,3:0,9:1r,1:3,9:c,1:0,z:h,1:x,2:0,6:3,1q:6,1:0,1:3,1:e,1:9,7:1k,7:9,6:3,1:7,2:1,2:l,1:6,1:1,1:4,3:7,2:1,2:1,3:0,6:0,5:6,4c:1t,1:2,1:3,5:9,5:2,u:1t,2:1,1:0,8:9,4m:1h,2:6,p:5,y:1q,1:0,3:0,b:9,12:1h,2:0,7:9,1i:q,2:d,5:9,6:6,55:1k,2v:21,l:7,2:0,2:7,1:1,1:t,1:1,2:1,2:3,d:9,1y:7,2:19,2:5,1:0,1:1,r:1e,2:9,h:1z,5:0,i:20,7b:8,1:18,1:6,1:0,f:9,o:t,2:l,1:d,21:6,1:1,1:17,3:0,1:1,1:2,1:0,2:1,8:9,6:5,1:1,1:10,1:1,1:3,1:0,7:9,8m:m,9:g,1:14,3:2,f:9,2e:0,27:pl,2u:32,h:5f,218:2o,f:tr,h:5,33t:g6,6nt:fs,7:u,1:9,6:26,1:9,6:t,i:1b,g:3,c:9,9:k,5:i,j4:1r,3k:22,4:1k,7:g,1s:1,1:0,c:1,e:4qf,8:yd,16:8,6w7:3,1:6,1:1,1:82,f:0,t:2,2:0,e:3,8:az,1s4:2y,5:c,3:8,7:9,4:0,4m9:2c,1:1y,1:1,2:0,2:1,2:3,1:b,1:0,1:6,1:1s,1:3,2:7,1:6,1:r,1:3,1:4,1:0,3:6,1:9f,2:o,1:o,1:u,1:o,1:u,1:o,1:u,1:o,1:u,1:o,1:7,2:1d,1ds:u,6:5,5x:6,1:g,2:6,1:1,1:4,5:1p,x:0,34:18,a:6,2:9,4:0,8x:t,i:17,4:9,d2:r,4:9,km:6,1:3,1:1,1:e,1:5g,1n:1v,3:0,3:0,4:9,x2:3,1:q,1:1,1:0,2:0,1:9,1:3,1:0,1:0,6:0,4:0,1:0,1:0,1:2,1:1,1:0,2:0,1:0,1:0,1:0,1:0,1:1,1:0,2:3,1:6,1:3,1:3,1:0,1:9,1:g,5:2,1:4,1:g,hg:p,6:p,6:p,21y:9,sm:wyn,w:37d,6:65,2:4g1,e:5rk,f:h9,1wi:f1,15u:3t6,5:38f",digit:"1c:9",alnum:"1c:9,7:p,6:p,1b:0,a:0,4:0,5:m,1:u,1:cp,4:b,e:4,7:0,1:0,2e:0,16:4,1:1,2:3,1:0,6:0,1:2,1:0,1:j,1:2a,1:3u,8:4l,1:11,2:0,6:14,13:d,1:0,1:1,1:1,1:0,8:q,4:3,t:a,5:1j,1:g,4:2t,1:7,4:7,4:f,2:0,g:1b,d:2s,e:16,9:1,4:0,5:n,2:i,j:o,7:a,5:n,1:5,h:15,a:b,3:6,6:23,1:f,1:2,4:e,2:9,1:i,1:7,2:1,2:l,1:6,1:0,3:3,3:7,2:1,2:1,1:0,8:0,4:1,1:4,2:b,a:0,4:2,1:5,4:1,2:l,1:6,1:1,1:1,1:1,4:4,4:1,2:1,4:0,7:3,1:0,7:f,b:2,1:8,1:2,1:l,1:6,1:1,1:4,3:8,1:2,1:1,3:0,f:3,2:9,9:3,4:2,1:7,2:1,2:l,1:6,1:1,1:4,3:7,2:1,2:1,9:1,4:1,1:4,2:9,1:0,g:1,1:5,3:2,1:3,3:1,1:0,1:1,3:1,3:2,3:b,4:4,3:2,1:2,3:0,6:0,e:9,g:c,1:2,1:m,1:f,3:7,1:2,1:2,8:1,1:2,2:0,2:3,2:9,g:3,1:7,1:2,1:m,1:9,1:4,3:7,1:2,1:2,8:1,6:1,1:3,2:9,1:2,c:c,1:2,1:14,2:7,1:2,1:2,1:0,5:3,7:4,2:9,a:5,1:2,1:h,3:n,1:8,1:0,2:6,8:5,1:0,1:7,6:9,2:1,d:1l,5:6,6:0,2:9,13:1,1:0,1:4,1:n,1:0,1:i,1:2,2:4,1:0,6:0,2:9,2:3,w:0,v:9,m:7,1:z,4:i,4:f,1:z,1v:1i,1:0,2:e,6:25,2:11,1:0,5:0,2:16,1:98,1:3,2:6,1:0,1:3,2:14,1:3,2:w,1:3,2:6,1:0,1:3,2:e,1:1k,1:3,2:1u,11:f,g:2d,2:5,3:h7,2:g,1:p,5:22,3:a,7:j,b:k,c:j,c:c,1:2,1:1,c:1f,2:i,e:0,4:0,3:9,12:9,6:2g,7:16,5:1x,a:u,1:b,4:8,d:13,2:4,b:17,4:p,6:9,12:r,4:1q,2:j,b:9,6:9,d:0,n:1,b:2,1d:1f,1:e,1:7,3:9,12:15,2:1l,1:a,e:1i,9:9,3:1c,2:8,7:16,2:2,15:3,1:5,1:1,3:0,5:5b,13:d,b:7p,2:5,2:11,2:5,2:7,1:0,1:0,1:0,1:u,2:1g,1:6,1:0,3:2,1:6,3:3,2:5,4:c,5:2,1:6,38:0,d:0,g:c,2t:0,4:0,2:9,1:0,3:4,6:0,1:0,1:0,1:3,1:a,2:3,5:4,4:0,h:14,ml:1f,1ee:6c,6:3,3:1,c:11,1:0,5:0,2:1j,7:0,g:m,9:6,1:6,1:6,1:6,1:6,1:6,1:6,1:6,1:v,1b:0,d1:2,p:8,7:4,2:4,4:2d,6:2,1:2h,1:3,5:16,1:2l,h:v,1c:f,e8:533,1s:h3g,1v:19,2:7g,3:r,k:1a,5:7,3:34,13:8,2:2u,2:1r,5:1,1:0,1:4,o:j,1:w,o:1f,c:1v,1:0,a:9,o:5,3:0,1:19,5:y,d:s,3:1e,1:b,f:a,6:u,1:1i,9:d,2:9,6:m,3:1w,1:0,1:0,o:2,2:f,2:3,b:5,2:5,2:5,9:6,1:6,1:16,1:d,6:3e,5:9,6:8mb,c:m,4:1c,6is:a5,2:2x,12:6,c:4,5:b,1:c,1:4,1:0,1:1,1:1,1:2z,x:a2,i:1r,2:1h,14:b,38:4,1:3q,j:9,7:p,6:p,b:2g,3:5,2:5,2:5,2:2,z:b,1:p,1:i,1:1,1:e,2:d,y:3e,1x:1g,7f:s,3:1c,1b:v,d:t,5:16,5:t,2:z,4:7,1:4,16:4d,2:9,6:z,4:z,4:13,8:1f,c:a,1:e,1:6,1:1,1:a,1:e,1:6,1:1,1v:8m,9:l,a:7,o:5,1:15,1:8,1x:5,2:0,1:17,1:1,3:0,2:m,a:m,9:u,1t:i,1:1,a:l,a:p,1y:1j,6:1,1s:3,1:1,5:7,1:2,1:s,16:s,3:s,z:7,1:r,r:1h,a:l,a:i,d:h,32:20,1j:1e,d:1e,d:13,8:9,92:15,1:1,3:1,26:s,a:0,8:l,16:h,1a:k,r:m,9:1x,w:9,1:4,a:1k,9:0,d:o,7:9,6:1e,3:9,4:3,8:y,3:0,9:1r,1:3,9:c,1:0,z:h,1:x,2:0,6:3,1q:6,1:0,1:3,1:e,1:9,7:1k,7:9,6:3,1:7,2:1,2:l,1:6,1:1,1:4,3:7,2:1,2:1,3:0,6:0,5:6,4c:1t,1:2,1:3,5:9,5:2,u:1t,2:1,1:0,8:9,4m:1h,2:6,p:5,y:1q,1:0,3:0,b:9,12:1h,2:0,7:9,1i:q,2:d,5:9,6:6,55:1k,2v:21,l:7,2:0,2:7,1:1,1:t,1:1,2:1,2:3,d:9,1y:7,2:19,2:5,1:0,1:1,r:1e,2:9,h:1z,5:0,i:20,7b:8,1:18,1:6,1:0,f:9,o:t,2:l,1:d,21:6,1:1,1:17,3:0,1:1,1:2,1:0,2:1,8:9,6:5,1:1,1:10,1:1,1:3,1:0,7:9,8m:m,9:g,1:14,3:2,f:9,2e:0,27:pl,2u:32,h:5f,218:2o,f:tr,h:5,33t:g6,6nt:fs,7:u,1:9,6:26,1:9,6:t,i:1b,g:3,c:9,9:k,5:i,j4:1r,3k:22,4:1k,7:g,1s:1,1:0,c:1,e:4qf,8:yd,16:8,6w7:3,1:6,1:1,1:82,f:0,t:2,2:0,e:3,8:az,1s4:2y,5:c,3:8,7:9,4:0,4m9:2c,1:1y,1:1,2:0,2:1,2:3,1:b,1:0,1:6,1:1s,1:3,2:7,1:6,1:r,1:3,1:4,1:0,3:6,1:9f,2:o,1:o,1:u,1:o,1:u,1:o,1:u,1:o,1:u,1:o,1:7,2:1d,1ds:u,6:5,5x:6,1:g,2:6,1:1,1:4,5:1p,x:0,34:18,a:6,2:9,4:0,8x:t,i:17,4:9,d2:r,4:9,km:6,1:3,1:1,1:e,1:5g,1n:1v,3:0,3:0,4:9,x2:3,1:q,1:1,1:0,2:0,1:9,1:3,1:0,1:0,6:0,4:0,1:0,1:0,1:2,1:1,1:0,2:0,1:0,1:0,1:0,1:0,1:1,1:0,2:3,1:6,1:3,1:3,1:0,1:9,1:g,5:2,1:4,1:g,hg:p,6:p,6:p,21y:9,sm:wyn,w:37d,6:65,2:4g1,e:5rk,f:h9,1wi:f1,15u:3t6,5:38f",upper:"1t:p,2t:m,1:6,x:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,2:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,2:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:1,1:0,1:0,3:1,1:0,1:1,1:2,2:3,1:1,1:2,3:1,1:1,1:0,1:0,1:1,1:0,2:0,1:1,1:2,1:0,1:1,3:0,7:1,1:1,1:1,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,2:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,2:1,1:0,1:2,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,7:1,1:1,2:0,1:3,1:0,1:0,1:0,1:0,81:0,1:0,3:0,8:0,6:0,1:2,1:0,1:1,1:g,1:8,z:0,2:2,3:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,5:0,2:0,1:1,2:1e,1c:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,9:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:1,1:0,1:0,1:0,1:0,1:0,1:0,2:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,2:11,289:11,1:0,5:0,k2:2d,1p6:16,2:2,8w:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,9:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,9:7,8:5,a:7,8:7,8:5,b:0,1:0,1:0,1:0,8:7,o:7,8:7,8:7,8:4,b:4,b:3,c:4,b:4,79:0,4:0,3:2,2:2,2:0,3:4,6:0,1:0,1:0,1:3,2:3,a:1,5:0,q:f,j:0,mq:p,1f4:1b,1c:0,1:2,2:0,1:0,1:0,1:3,1:0,2:0,8:2,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,8:0,1:0,4:0,nyl:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,j:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,3r:0,1:0,1:0,1:0,1:0,1:0,1:0,3:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,a:0,1:0,1:1,1:0,1:0,1:0,1:0,4:0,1:0,2:0,1:0,3:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:4,1:4,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:3,1:0,6:0,5:0,1:0,s:0,h7v:p,xx:13,3s:z,4c:a,1:e,1:6,1:1,1d6:1e,2ct:v,gw0:v,k2o:p,q:p,q:p,q:0,1:1,2:0,2:1,2:3,1:7,q:p,q:1,1:3,2:7,1:6,r:1,1:3,1:4,1:0,3:6,r:p,q:p,q:p,q:p,q:p,q:p,u:o,x:o,x:o,x:o,x:o,x:0,3ed:x,1la:p,6:p,6:p",lower:"2p:p,1b:0,a:0,4:0,10:n,1:7,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:1,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:1,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,2:0,1:0,1:2,2:0,1:0,2:0,3:1,4:0,2:0,3:2,2:0,2:0,1:0,1:0,2:0,1:1,1:0,2:0,3:0,1:0,2:1,2:2,5:1,1:1,1:1,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:1,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:1,1:1,1:0,3:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:6,2:0,2:1,1:0,4:0,1:0,1:0,1:0,1:1w,1:z,7:1,u:4,2o:0,17:0,1:0,3:0,2:3,i:0,r:y,1:1,3:2,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:4,1:0,2:0,2:1,1f:1b,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,9:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,2:0,1:0,1:0,1:0,1:0,1:0,1:1,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1c:14,287:16,1:3,l4:5,1oi:8,3b:5b,1t:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:8,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:8,8:5,a:7,8:7,8:5,a:7,8:7,8:d,2:7,8:7,8:7,8:4,1:1,6:0,3:2,1:1,8:3,2:1,8:7,a:2,1:1,3d:0,d:0,g:c,31:0,3:1,3:0,r:0,4:0,4:0,2:1,8:3,4:0,x:f,4:0,nf:p,1fq:1b,1:0,3:1,1:0,1:0,1:0,4:0,1:1,1:7,3:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:1,7:0,1:0,4:0,c:11,1:0,5:0,nwz:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,j:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:2,3p:0,1:0,1:0,1:0,1:0,1:0,1:2,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:9,1:0,1:0,2:0,1:0,1:0,1:0,1:0,4:0,1:0,2:0,1:2,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,5:0,5:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,4:0,1:0,6:0,1:0,1:0,1:0,1:0,o:2,1:0,1:2,mt:16,1:d,6:27,fnk:6,c:4,tl:p,y5:13,3s:z,4b:a,1:e,1:6,1:1,cj:0,2:2,1:15,1:8,zp:1e,2bx:v,gw0:v,k2i:p,q:6,1:h,q:p,q:3,1:0,1:6,1:a,q:p,q:p,q:p,q:p,q:p,q:p,q:p,q:p,q:r,s:o,1:5,q:o,1:5,q:o,1:5,q:o,1:5,q:o,1:5,1:0,1f8:9,1:j,6:5,79:1p,1pw:x",space:"9:4,i:0,4f3:0,1vj:6,1:2,t:1,1h:0,334:0",blank:"9:0,m:0,4f3:0,1vj:6,1:2,2c:0,334:0",punct:"x:e,a:6,q:5,q:3,x:9,1:9,1:3,1:4,n:0,v:0,cq:3,c:d,5:6,1:0,1:2d,1:15,5:0,8:0,5:1,1:0,32:0,3v:7,5s:5,15:1,2:2,1:u,e:0,1:0,2:0,2:0,18:1,b:f,b:4,1k:0,h:3,2u:0,8:3,8:3,g:1,1:d,1:0,1c:a,4g:8,2:3,3:2,o:1,j:0,2:e,q:2,2:0,15:0,7:1,6:7,16:9,c:2,7:5,24:0,g:0,3:3,f:1,a:0,23:0,g:0,10:9,1:1,1p:0,g:0,14:0,1x:0,g:0,y:1,b:2,1o:0,g:0,7:0,q:0,1:5,2d:0,y:a,1t:0,g:0,15:8,4:0,1j:0,g:0,31:1,g:0,1:0,8:6,h:9,28:0,15:0,22:0,7:5,1:1,a:1,2m:0,d:4,1:0,1e:u,a:l,1w:3,1i:e,1:c,2k:0,1:1,f:5,26:1,2j:0,gx:v,j:9,2u:0,h8:1,18:1,26:2,12:1,u:2,3h:1,j:d,1:3,1:0,i:9,6:f,89:2,4:0,3:1,44:0,3:x,u:1,1s:0,k:7,2:0,w:6,1:5,2:e,2:a,2w:0,f:0,l:10,17:1,1m:0,b:1,8:3,1j:0,3:4,1q:1,1s:7,8:o,4:0,6:0,2:2,5i:12,e:a,cd:0,1:2,b:2,d:2,d:2,d:1,8:0,3:s,2:1g,1:4,1:a,3:a,1:e,h:w,f:w,f:1,1:3,1:1,a:0,1:2,5:5,1:0,1:0,1:0,4:0,b:1,4:4,5:3,1:g,15:2,4:ie,p:a,l:2d,1g:1ah,2:v,1:2w,6d:5,4:2,7:6,34:0,e:0,3k:1a,1:19,y:p,1:2g,c:5x,q:f,1:3,3:o,9:6,5:1,5:2,2h:3,3:0,2i:0,44:f,w:z,b:0,g:u,1:db,534:1r,h3k:1i,1j:1,7h:2,2n:4,8:2,35:7,8:m,9:1,2v:1,3f:0,x:4,3:9,1m:3,24:0,9:1,g:h,6:2,1:0,1a:4,z:0,b:0,2b:0,c:d,g:1,3g:3,n:2,1x:0,1:0,s:1,g:1,4:0,2s:0,e:1,3j:2,aaa:4xr,fd:0,3s:g,aj:h,3j:0,18:t,6:1e,1:i,1:3,43:0,1:e,a:6,q:5,q:a,3e:6,1:6,a:4,76:2,4:18,3:8,1h:p,1:c,3:0,1b:19,6a:r,10:3,3f:0,1c:0,bi:0,kn:8,n:8,13:8,23:4,m:5,3:0,v:0,3g:1,2:f,2:19,1k:2,4:9,7:8,10:2,t:2,14:0,s:1,4:b,1u:6,o:7,o:7,p:3,c:6,96:5,9s:u,1a:0,27:2,t:9,v:j,14:7,1n:6,3e:7,4:j,a:0,e:0,1l:8,b:0,2t:1,b:3,1b:2,22:0,4:8,d:0,1:2,1:j,1s:1,1:5,2z:0,1r:1,28:1,g:0,o:6,3:4,5p:0,3:0,4:4,a:1,1:1,2r:1,2:0,6w:o,2v:0,1:2,s:c,21:1,1:0,35:0,e:5,6x:2,4u:8,22:1,4:3,49:0,1:0,28:1,a:8,28:4,1:4,2l:9,8l:0,1:4,k:i,3:1,5s:0,1:1,29:0,9r:1,20:e,34:1d,d:0,vk:4,29o:1,u5:g,6:e,aoo:1,3k:5,1m:f,4:1,l:6,m6:q,93:0,1:0,f5j:1,1:4,3mk:19,2:m,9:37,1o:6t,a:12,2:5d,l:1x,3e:j,c:j,c:2e,9:o,nc:0,p:0,v:0,p:0,v:0,p:0,v:0,p:0,v:0,p:0,1o:i3,f:4,1:e,1a8:6,o:0,9q:0,1p:3,f:0,do:3,rb:f,31:2,1:2,j:1,lt:1v,24:1o,c2:1,7i:17,4:2r,c:e,2:e,1:e,1:10,a:1b,q:5,q:5,q:z,1k:s,d:17,4:8,7:1,e:5,4a:rb,4:g,3:c,3:3a,4:2m,6:b,4:0,f:b,4:1j,8:9,6:13,8:t,2:1,26:9f,c:d,2:c,3:8,7:19,1:6,8:d,4:8,7:8,7:42,1:1i,gvna:0,u:2n,3k:6n,1e6o:1ekd,2:1ekd",xdigit:"1c:9,7:5,q:5",cntrl:"0:v,2n:w,688:1",print:"w:2m,x:k7,2:5,4:6,1:0,1:j,1:b0,1:11,2:1d,2:2,1:1i,8:q,4:5,b:7h,1:1n,2:2s,e:1m,2:1c,2:e,1:r,2:0,1:a,5:u,1:1,6:6j,1:7,2:1,2:l,1:6,1:0,3:3,2:8,2:1,2:3,8:0,4:1,1:4,2:o,2:2,1:5,4:1,2:l,1:6,1:1,1:1,1:1,2:0,1:4,4:1,2:2,3:0,7:3,1:0,7:g,a:2,1:8,1:2,1:l,1:6,1:1,1:4,2:9,1:2,1:2,2:0,f:3,2:b,7:6,1:2,1:7,2:1,2:l,1:6,1:1,1:4,2:8,2:1,2:2,7:2,4:1,1:4,2:h,a:1,1:5,3:2,1:3,3:1,1:0,1:1,3:1,3:2,3:b,4:4,3:2,1:3,2:0,6:0,e:k,5:c,1:2,1:m,1:f,2:8,1:2,1:3,7:1,1:2,2:0,2:3,2:9,7:l,1:2,1:m,1:9,1:4,2:8,1:2,1:3,7:1,6:1,1:3,2:9,1:2,c:c,1:2,1:1e,1:2,1:5,4:f,2:p,1:2,1:h,3:n,1:8,1:0,2:6,3:0,4:5,1:0,1:7,6:9,2:2,c:1l,4:s,11:1,1:0,1:4,1:n,1:0,1:m,2:4,1:0,1:6,1:9,2:3,w:1z,1:z,4:12,1:z,1:e,1:c,11:5h,1:0,5:0,2:ag,1:3,2:6,1:0,1:3,2:14,1:3,2:w,1:3,2:6,1:0,1:3,2:e,1:1k,1:3,2:1u,2:v,3:p,6:2d,2:5,2:ik,3:2g,7:l,9:n,9:j,c:c,1:2,1:1,c:2l,2:9,6:9,6:p,6:2g,7:16,5:1x,a:u,1:b,4:b,4:0,3:15,2:4,b:17,4:p,6:a,3:1p,2:1s,1:s,2:a,6:9,6:d,2:u,1d:24,3:1a,1:37,8:1n,3:e,3:1n,7:16,2:a,8:16,5:et,2:5,2:11,2:5,2:7,1:0,1:0,1:0,1:u,2:1g,1:e,1:d,2:5,1:i,2:2,1:8,1:13,2:1m,1:b,2:q,1:c,3:w,f:w,f:3v,4:ie,p:a,l:1eb,2:v,1:9o,5:18,1:0,5:0,2:1j,7:1,e:n,9:6,1:6,1:6,1:6,1:6,1:6,1:6,1:6,1:3h,y:p,1:2g,c:5x,q:27,1:2d,2:2u,5:16,1:2l,1:2b,b:1b,1:mlo,3:1i,9:9n,k:53,8:5m,5:1,1:0,1:4,o:1m,3:9,6:1j,8:1x,8:b,6:37,b:t,3:25,1:a,4:w,1:1i,9:d,2:9,2:2u,o:r,a:5,2:5,2:5,9:6,1:6,1:1n,4:3h,2:9,6:8mb,c:m,4:1c,1l0:57x,2:2x,12:6,c:4,5:p,1:4,1:0,1:1,1:1,1:3g,g:cc,2:1h,7:0,w:15,6:1e,1:i,1:3,4:4,1:3q,2:0,1:59,3:5,2:5,2:5,2:2,3:6,1:6,a:4,2:b,1:p,1:i,1:1,1:e,2:d,y:3e,5:2,4:18,3:2f,1:c,3:0,1b:19,3m:s,3:1c,f:r,4:z,9:t,5:16,5:t,1:10,4:d,16:4d,2:9,6:z,4:z,4:13,8:1f,b:b,1:e,1:6,1:1,1:a,1:e,1:6,1:1,1v:8m,9:l,a:7,o:5,1:15,1:8,1x:5,2:0,1:17,1:1,3:0,2:m,1:1z,8:8,1c:i,1:1,5:w,3:q,5:0,1s:1j,4:j,2:1d,1:1,5:7,1:2,1:s,2:2,4:9,7:8,7:1r,w:12,4:b,9:1h,3:s,2:q,5:p,7:3,c:6,28:20,1j:1e,d:1e,7:19,8:9,86:u,1:15,1:2,2:1,23:16,8:15,m:p,12:r,k:m,9:25,4:z,9:1v,a:0,2:o,7:9,6:1g,1:h,8:12,9:2n,1:j,b:h,1:1a,1q:6,1:0,1:3,1:e,1:a,6:1m,5:9,6:3,1:7,2:1,2:l,1:6,1:1,1:4,1:9,2:1,2:2,2:0,6:0,5:6,2:6,3:4,3v:2j,1:4,u:1z,8:9,4m:1h,2:11,y:1w,b:9,6:c,j:1l,6:9,1i:q,2:e,4:m,55:1n,2s:2a,c:7,2:0,2:7,1:1,1:t,1:1,2:b,9:9,1y:7,2:19,2:a,r:1z,8:2a,d:20,7:9,6u:8,1:18,1:d,a:s,3:v,2:l,1:d,21:6,1:1,1:17,3:0,1:1,1:8,8:9,6:5,1:1,1:10,1:1,1:5,7:9,8m:o,7:g,1:14,3:r,2e:0,f:1d,d:pm,2u:32,1:4,b:5f,218:2q,d:ut,33e:g6,6nt:fs,7:u,1:9,4:28,1:9,6:t,2:5,a:1x,a:9,1:6,1:k,5:i,j4:2i,2t:22,4:1k,7:g,1s:4,b:1,e:4qf,8:yd,16:8,6w7:3,1:6,1:1,1:82,f:0,t:2,2:0,e:3,8:az,1s4:2y,5:c,3:8,7:9,2:7,3mk:19,2:m,9:37,1o:6t,a:12,2:5d,l:1x,3e:j,c:j,c:2e,9:o,3r:2c,1:1y,1:1,2:0,2:1,2:3,1:b,1:0,1:6,1:1s,1:3,2:7,1:6,1:r,1:3,1:4,1:0,3:6,1:9f,2:83,2:jh,f:4,1:e,uo:u,6:5,5x:6,1:g,2:6,1:1,1:4,5:1p,x:0,34:18,3:d,2:9,4:1,8w:u,h:1l,5:0,cw:15,km:6,1:3,1:1,1:e,1:5g,2:f,15:23,4:9,4:1,lt:1v,24:1o,5e:3,1:q,1:1,1:0,2:0,1:9,1:3,1:0,1:0,6:0,4:0,1:0,1:0,1:2,1:1,1:0,2:0,1:0,1:0,1:0,1:0,1:1,1:0,2:3,1:6,1:3,1:3,1:0,1:9,1:g,5:2,1:4,1:g,1g:1,7i:17,4:2r,c:e,2:e,1:e,1:10,a:4t,1k:s,d:17,4:8,7:1,e:5,4a:rb,4:g,3:c,3:3a,4:2m,6:b,4:0,f:b,4:1j,8:9,6:13,8:t,2:1,26:9f,c:d,2:c,3:8,7:19,1:6,8:d,4:8,7:8,7:42,1:1i,11:9,sm:wyn,w:37d,6:65,2:4g1,e:5rk,f:h9,1wi:f1,15u:3t6,5:38f,f975:0,u:2n,3k:6n,1e6o:1ekd,2:1ekd",graph:"x:2l,x:k7,2:5,4:6,1:0,1:j,1:b0,1:11,2:1d,2:2,1:1i,8:q,4:5,b:7h,1:1n,2:2s,e:1m,2:1c,2:e,1:r,2:0,1:a,5:u,1:1,6:6j,1:7,2:1,2:l,1:6,1:0,3:3,2:8,2:1,2:3,8:0,4:1,1:4,2:o,2:2,1:5,4:1,2:l,1:6,1:1,1:1,1:1,2:0,1:4,4:1,2:2,3:0,7:3,1:0,7:g,a:2,1:8,1:2,1:l,1:6,1:1,1:4,2:9,1:2,1:2,2:0,f:3,2:b,7:6,1:2,1:7,2:1,2:l,1:6,1:1,1:4,2:8,2:1,2:2,7:2,4:1,1:4,2:h,a:1,1:5,3:2,1:3,3:1,1:0,1:1,3:1,3:2,3:b,4:4,3:2,1:3,2:0,6:0,e:k,5:c,1:2,1:m,1:f,2:8,1:2,1:3,7:1,1:2,2:0,2:3,2:9,7:l,1:2,1:m,1:9,1:4,2:8,1:2,1:3,7:1,6:1,1:3,2:9,1:2,c:c,1:2,1:1e,1:2,1:5,4:f,2:p,1:2,1:h,3:n,1:8,1:0,2:6,3:0,4:5,1:0,1:7,6:9,2:2,c:1l,4:s,11:1,1:0,1:4,1:n,1:0,1:m,2:4,1:0,1:6,1:9,2:3,w:1z,1:z,4:12,1:z,1:e,1:c,11:5h,1:0,5:0,2:ag,1:3,2:6,1:0,1:3,2:14,1:3,2:w,1:3,2:6,1:0,1:3,2:e,1:1k,1:3,2:1u,2:v,3:p,6:2d,2:5,2:hr,1:r,3:2g,7:l,9:n,9:j,c:c,1:2,1:1,c:2l,2:9,6:9,6:p,6:2g,7:16,5:1x,a:u,1:b,4:b,4:0,3:15,2:4,b:17,4:p,6:a,3:1p,2:1s,1:s,2:a,6:9,6:d,2:u,1d:24,3:1a,1:37,8:1n,3:e,3:1n,7:16,2:a,8:16,5:et,2:5,2:11,2:5,2:7,1:0,1:0,1:0,1:u,2:1g,1:e,1:d,2:5,1:i,2:2,1:8,8:0,3:s,2:1g,1:4,1:b,2:q,1:c,3:w,f:w,f:3v,4:ie,p:a,l:1eb,2:v,1:9o,5:18,1:0,5:0,2:1j,7:1,e:n,9:6,1:6,1:6,1:6,1:6,1:6,1:6,1:6,1:3h,y:p,1:2g,c:5x,q:f,1:1q,1:2d,2:2u,5:16,1:2l,1:2b,b:1b,1:mlo,3:1i,9:9n,k:53,8:5m,5:1,1:0,1:4,o:1m,3:9,6:1j,8:1x,8:b,6:37,b:t,3:25,1:a,4:w,1:1i,9:d,2:9,2:2u,o:r,a:5,2:5,2:5,9:6,1:6,1:1n,4:3h,2:9,6:8mb,c:m,4:1c,1l0:57x,2:2x,12:6,c:4,5:p,1:4,1:0,1:1,1:1,1:3g,g:cc,2:1h,7:0,w:15,6:1e,1:i,1:3,4:4,1:3q,2:0,1:59,3:5,2:5,2:5,2:2,3:6,1:6,a:4,2:b,1:p,1:i,1:1,1:e,2:d,y:3e,5:2,4:18,3:2f,1:c,3:0,1b:19,3m:s,3:1c,f:r,4:z,9:t,5:16,5:t,1:10,4:d,16:4d,2:9,6:z,4:z,4:13,8:1f,b:b,1:e,1:6,1:1,1:a,1:e,1:6,1:1,1v:8m,9:l,a:7,o:5,1:15,1:8,1x:5,2:0,1:17,1:1,3:0,2:m,1:1z,8:8,1c:i,1:1,5:w,3:q,5:0,1s:1j,4:j,2:1d,1:1,5:7,1:2,1:s,2:2,4:9,7:8,7:1r,w:12,4:b,9:1h,3:s,2:q,5:p,7:3,c:6,28:20,1j:1e,d:1e,7:19,8:9,86:u,1:15,1:2,2:1,23:16,8:15,m:p,12:r,k:m,9:25,4:z,9:1v,a:0,2:o,7:9,6:1g,1:h,8:12,9:2n,1:j,b:h,1:1a,1q:6,1:0,1:3,1:e,1:a,6:1m,5:9,6:3,1:7,2:1,2:l,1:6,1:1,1:4,1:9,2:1,2:2,2:0,6:0,5:6,2:6,3:4,3v:2j,1:4,u:1z,8:9,4m:1h,2:11,y:1w,b:9,6:c,j:1l,6:9,1i:q,2:e,4:m,55:1n,2s:2a,c:7,2:0,2:7,1:1,1:t,1:1,2:b,9:9,1y:7,2:19,2:a,r:1z,8:2a,d:20,7:9,6u:8,1:18,1:d,a:s,3:v,2:l,1:d,21:6,1:1,1:17,3:0,1:1,1:8,8:9,6:5,1:1,1:10,1:1,1:5,7:9,8m:o,7:g,1:14,3:r,2e:0,f:1d,d:pm,2u:32,1:4,b:5f,218:2q,d:ut,33e:g6,6nt:fs,7:u,1:9,4:28,1:9,6:t,2:5,a:1x,a:9,1:6,1:k,5:i,j4:2i,2t:22,4:1k,7:g,1s:4,b:1,e:4qf,8:yd,16:8,6w7:3,1:6,1:1,1:82,f:0,t:2,2:0,e:3,8:az,1s4:2y,5:c,3:8,7:9,2:7,3mk:19,2:m,9:37,1o:6t,a:12,2:5d,l:1x,3e:j,c:j,c:2e,9:o,3r:2c,1:1y,1:1,2:0,2:1,2:3,1:b,1:0,1:6,1:1s,1:3,2:7,1:6,1:r,1:3,1:4,1:0,3:6,1:9f,2:83,2:jh,f:4,1:e,uo:u,6:5,5x:6,1:g,2:6,1:1,1:4,5:1p,x:0,34:18,3:d,2:9,4:1,8w:u,h:1l,5:0,cw:15,km:6,1:3,1:1,1:e,1:5g,2:f,15:23,4:9,4:1,lt:1v,24:1o,5e:3,1:q,1:1,1:0,2:0,1:9,1:3,1:0,1:0,6:0,4:0,1:0,1:0,1:2,1:1,1:0,2:0,1:0,1:0,1:0,1:0,1:1,1:0,2:3,1:6,1:3,1:3,1:0,1:9,1:g,5:2,1:4,1:g,1g:1,7i:17,4:2r,c:e,2:e,1:e,1:10,a:4t,1k:s,d:17,4:8,7:1,e:5,4a:rb,4:g,3:c,3:3a,4:2m,6:b,4:0,f:b,4:1j,8:9,6:13,8:t,2:1,26:9f,c:d,2:c,3:8,7:19,1:6,8:d,4:8,7:8,7:42,1:1i,11:9,sm:wyn,w:37d,6:65,2:4g1,e:5rk,f:h9,1wi:f1,15u:3t6,5:38f,f975:0,u:2n,3k:6n,1e6o:1ekd,2:1ekd"},Pa="2p:q:-w:1,51:1:kn:1,68:n:-w:1,6w:7:-w:1,73:1:3d:1,75:o:-1:2,8h:1:-6g:1,8j:3:-1:2,8q:8:-1:2,97:n:-1:2,ai:3:-1:2,an:1:-8c:1,ao:1:5f:1,ar:2:-1:2,aw:1:-1:1,b0:1:-1:1,b6:1:-1:1,b9:1:2p:1,bd:1:-1:1,be:1:4j:1,bi:1:3m:1,bl:3:-1:2,bs:1:-1:1,bx:1:-1:1,c0:1:-1:1,c4:2:-1:2,c9:1:-1:1,cd:1:-1:1,cf:1:1k:1,cl:1:-1:1,cm:1:-2:1,co:1:-1:1,cp:1:-2:1,cr:1:-1:1,cs:1:-2:1,cu:8:-1:2,d9:1:-27:1,db:9:-1:2,du:1:-1:1,dv:1:-2:1,dx:1:-1:1,e1:k:-1:2,f7:9:-1:2,fw:1:-1:1,fz:2:8cf:1,g2:1:-1:1,g7:5:-1:2,gg:1:8bj:1,gh:1:8bg:1,gi:1:8bi:1,gj:1:-5u:1,gk:1:-5q:1,gm:2:-5p:1,gp:1:-5m:1,gr:1:-5n:1,gs:1:wnj:1,gw:1:-5p:1,gx:1:wnf:1,gz:1:-5r:1,h1:1:wmg:1,h2:1:wn8:1,h4:1:-5t:1,h5:1:-5v:1,h6:1:wn8:1,h7:1:8af:1,h8:1:wn5:1,hb:1:-5v:1,hd:1:8al:1,he:1:-5x:1,hh:1:-5y:1,hp:1:89z:1,hs:1:-62:1,hu:1:wn7:1,hv:1:-62:1,hz:1:wmi:1,i0:1:-62:1,i1:1:-1x:1,i2:2:-61:1,i4:1:-1z:1,ia:1:-63:1,il:1:wlx:1,im:1:wlu:1,n9:1:2c:1,oh:2:-1:2,on:1:-1:1,or:3:3m:1,q4:1:-12:1,q5:3:-11:1,q9:h:-w:1,qq:1:-v:1,qr:9:-w:1,r0:1:-1s:1,r1:2:-1r:1,r4:1:-1q:1,r5:1:-1l:1,r9:1:-1b:1,ra:1:-1i:1,rb:1:-8:1,rd:c:-1:2,s0:1:-2e:1,s1:1:-28:1,s2:1:7:1,s3:1:-38:1,s5:1:-2o:1,s8:1:-1:1,sb:1:-1:1,ts:w:-w:1,uo:g:-28:1,v5:h:-1:2,wb:r:-1:2,xu:7:-1:2,y7:1:-f:1,y9:1c:-1:2,129:12:-1c:1,3bk:17:2bk:1,3ct:3:2bk:1,3y0:6:-8:1,5mo:1:-4tq:1,5mp:1:-4tp:1,5mq:1:-4tg:1,5mr:2:-4te:1,5mt:1:-4tf:1,5mu:1:-4t8:1,5mv:1:-4rp:1,5mw:1:r7m:1,5tl:1:r9g:1,5tp:1:2xy:1,5u6:1:raw:1,5xd:23:-1:2,61n:1:-1n:1,61t:1c:-1:2,64g:8:8:1,64w:6:8:1,65c:8:8:1,65s:8:8:1,668:6:8:1,66p:4:8:2,674:8:8:1,67k:2:22:1,67m:4:2e:1,67q:2:2s:1,67s:2:3k:1,67u:2:34:1,67w:2:3i:1,680:8:8:1,68g:8:8:1,68w:8:8:1,69c:2:8:1,69f:1:9:1,69q:1:-5k5:1,69v:1:9:1,6a8:2:8:1,6ao:2:8:1,6at:1:7:1,6b7:1:9:1,6ku:1:-s:1,6ls:g:-g:1,6mc:1:-1:1,79s:q:-q:1,8q8:1c:-1c:1,8rl:1:-1:1,8rp:1:-8bv:1,8rq:1:-8bs:1,8rs:3:-1:2,8s3:1:-1:1,8s6:1:-1:1,8sh:1e:-1:2,8vg:2:-1:2,8vn:1:-1:1,8w0:12:-5ls:1,8x3:1:-5ls:1,8x9:1:-5ls:1,wu9:n:-1:2,ww1:e:-1:2,x0j:7:-1:2,x0z:v:-1:2,x2y:2:-1:2,x33:5:-1:2,x3g:1:-1:1,x3l:2:-1:2,x3o:1:1c:1,x3r:a:-1:2,x4l:8:-1:2,x54:2:-1:2,x5d:1:-1:1,x5j:2:-1:2,x6e:1:-1:1,xub:1:-ps:1,xv4:28:-tzk:1,1ef5:q:-w:1,1fe0:14:-14:1,1fiw:10:-14:1,1fo7:b:-13:1,1foj:f:-13:1,1foz:7:-13:1,1fp7:2:-13:1,1h34:1f:-1s:1,1jgg:w:-w:1,20dc:w:-w:1,2oma:y:-y:1",Da="1t:q:w:1,5c:n:w:1,60:7:w:1,74:o:1:2,8g:1:-5j:1,8i:3:1:2,8p:8:1:2,96:n:1:2,ag:1:-3d:1,ah:3:1:2,ap:1:5u:1,aq:2:1:2,au:1:5q:1,av:1:1:1,ax:2:5p:1,az:1:1:1,b2:1:27:1,b3:1:5m:1,b4:1:5n:1,b5:1:1:1,b7:1:5p:1,b8:1:5r:1,ba:1:5v:1,bb:1:5t:1,bc:1:1:1,bg:1:5v:1,bh:1:5x:1,bj:1:5y:1,bk:3:1:2,bq:1:62:1,br:1:1:1,bt:1:62:1,bw:1:1:1,by:1:62:1,bz:1:1:1,c1:2:61:1,c3:2:1:2,c7:1:63:1,c8:1:1:1,cc:1:1:1,ck:1:2:1,cl:1:1:1,cn:1:2:1,co:1:1:1,cq:1:2:1,cr:9:1:2,da:9:1:2,dt:1:2:1,du:2:1:2,dy:1:-2p:1,dz:1:-1k:1,e0:k:1:2,f4:1:-3m:1,f6:9:1:2,fu:1:8bv:1,fv:1:1:1,fx:1:-4j:1,fy:1:8bs:1,g1:1:1:1,g3:1:-5f:1,g4:1:1x:1,g5:1:1z:1,g6:5:1:2,og:2:1:2,om:1:1:1,ov:1:38:1,p2:1:12:1,p4:3:11:1,p8:1:1s:1,pa:2:1r:1,pd:h:w:1,pv:9:w:1,r3:1:8:1,rc:c:1:2,s4:1:-1o:1,s7:1:1:1,s9:1:-7:1,sa:1:1:1,sd:3:-3m:1,sg:g:28:1,sw:w:w:1,v4:h:1:2,wa:r:1:2,xs:1:f:1,xt:7:1:2,y8:1c:1:2,10x:12:1c:1,3a8:12:5ls:1,3bb:1:5ls:1,3bh:1:5ls:1,3vk:28:tzk:1,3xs:6:8:1,5n4:17:-2bk:1,5od:3:-2bk:1,5xc:23:1:2,61q:1:-5vj:1,61s:1c:1:2,64o:8:-8:1,654:6:-8:1,65k:8:-8:1,660:8:-8:1,66g:6:-8:1,66x:4:-8:2,67c:8:-8:1,688:8:-8:1,68o:8:-8:1,694:8:-8:1,69k:2:-8:1,69m:2:-22:1,69o:1:-9:1,6a0:4:-2e:1,6a4:1:-9:1,6ag:2:-8:1,6ai:2:-2s:1,6aw:2:-8:1,6ay:2:-34:1,6b0:1:-7:1,6bc:2:-3k:1,6be:2:-3i:1,6bg:1:-9:1,6jq:1:-5st:1,6ju:1:-6gv:1,6jv:1:-6di:1,6k2:1:s:1,6lc:g:g:1,6mb:1:1:1,792:q:q:1,8ow:1c:1c:1,8rk:1:1:1,8rm:1:-8af:1,8rn:1:-2xy:1,8ro:1:-89z:1,8rr:3:1:2,8rx:1:-8bg:1,8ry:1:-8al:1,8rz:1:-8bj:1,8s0:1:-8bi:1,8s2:1:1:1,8s5:1:1:1,8se:2:-8cf:1,8sg:1e:1:2,8vf:2:1:2,8vm:1:1:1,wu8:n:1:2,ww0:e:1:2,x0i:7:1:2,x0y:v:1:2,x2x:2:1:2,x31:1:-r9g:1,x32:5:1:2,x3f:1:1:1,x3h:1:-wmg:1,x3k:2:1:2,x3q:a:1:2,x4a:1:-wn8:1,x4b:1:-wnj:1,x4c:1:-wnf:1,x4d:1:-wn5:1,x4e:1:-wn8:1,x4g:1:-wlu:1,x4h:1:-wmi:1,x4i:1:-wlx:1,x4j:1:ps:1,x4k:8:1:2,x50:1:-1c:1,x51:1:-wn7:1,x52:1:-raw:1,x53:2:1:2,x5c:1:1:1,x5i:2:1:2,x6d:1:1:1,1ee9:q:w:1,1fcw:14:14:1,1fhs:10:14:1,1fn4:b:13:1,1fng:f:13:1,1fnw:7:13:1,1fo4:2:13:1,1h1c:1f:1s:1,1jfk:w:w:1,20cg:w:w:1,2olc:y:y:1";var ee="C.UTF-8",Rr="only the C.UTF-8 locale is supported",yi=e=>typeof e=="string"&&/^C\.UTF-?8$/iu.test(e),Xm=new Set(["LANG","LC_ALL","LC_CTYPE"]);function ja(e){if(e.locale===void 0||yi(e.locale))return ee;throw new TypeError(`createTerminal: ${Rr} (got ${JSON.stringify(e.locale)})`)}function Wa(e,t){if(!(Xm.has(e)?yi(t)||e!=="LANG"&&t==="":yi(t)||t==="C"||t==="POSIX"||t===""))throw new b("feature",e,`${e}: ${Rr}`)}var Mr=e=>e==="C"||e==="POSIX",le=e=>Mr(e.locale);function Ba(e){let t=[],n=-1;for(let r of e.split(",")){let[o,i]=r.split(":").map(u=>parseInt(u,36)),s=n+1+o;t.push([s,s+i]),n=s+i}return t}function Zm(e){let t=e.findIndex(([n])=>n>95);return[...e.slice(0,t),[95,95],...e.slice(t)]}function wi(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122?String.fromCodePoint(e):e<128?"\\x"+e.toString(16).padStart(2,"0"):String.fromCodePoint(e)}var Ym=e=>e.map(([t,n])=>t===n?wi(t):`${wi(t)}-${wi(n)}`).join("");function Vm(e,t){let n=e.length-1,r=0;for(;r<=n;){let o=r+n>>1;if(t<e[o][0])n=o-1;else if(t>e[o][1])r=o+1;else return!0}return!1}var Pr=e=>e==="upper"||e==="lower"?"alpha":e,Km=[181,305,383,453,456,459,498,837,962,976,977,981,982,1008,1009,1010,1013,7835,8126],Tt=/[\u1C80-\u1C88]/u;function Ua(e){let t=new Map;for(let n of e.split(",")){let[r,o,i,s]=n.split(":").map(u=>parseInt(u,36));for(let u=0;u<o;u++)t.set(r+u*s,r+u*s+i)}return t}var qa=(e,t)=>({up:e,low:t,folds:new Map});function Jm(){let e=new Map,t=new Map;for(let n=97;n<=122;n++)e.set(n,n-32),t.set(n-32,n);return qa(e,t)}function Qm(e){let t=[];for(let[n,r]of e.sort((o,i)=>o[0]-i[0])){let o=t.at(-1);o&&n<=o[1]+1?o[1]=Math.max(o[1],r):t.push([n,r])}return t}function za(e,t,n,r,o){let i=new Map,s=new Map,u=null,a=c=>(s.has(c)||s.set(c,n(c)),s.get(c)),l=()=>u??=o(),f={name:e,multibyte:t,ranges:a,body(c){return i.has(c)||i.set(c,r(c,a(c))),i.get(c)},has(c,d){let p=a(c);return p!==void 0&&Vm(p,d)},assertions(){if(f.js)return f.js;let c=f.body("space"),d=`[${f.body("word")}]`;return f.js={__proto__:null,"<":`(?<!${d})(?=${d})`,">":`(?<=${d})(?!${d})`,boundary:`(?:(?<!${d})(?=${d})|(?<=${d})(?!${d}))`,inside:`(?:(?<=${d})(?=${d})|(?<!${d})(?!${d}))`,word:d,nonWord:`[^${f.body("word")}]`,space:`[${c}]`,nonSpace:`[^${c}]`},f.js},up:c=>l().up.get(c)??c,low:c=>l().low.get(c)??c,fold(c){let{folds:d}=l(),p=d.get(c);if(p===void 0){let h=f.up(c),m=f.low(h),g=new Set([c,h]);m!==h&&f.up(m)===h&&g.add(m);for(let w of Km)f.up(w)===h&&g.add(w);p=[...g].sort((w,y)=>w-y),d.set(c,p)}return p},foldRange(c,d){let{up:p}=l(),h=p.get(c)??c,m=p.get(d)??d;if(h>m)return null;let g=[],w=[];for(let[S,I]of p){let M=S>=h&&S<=m;M!==(I>=h&&I<=m)&&(M?g:w).push(S)}let y=[],k=h;for(let S of g.sort((I,M)=>I-M))S>k&&y.push([k,S-1]),k=S+1;return k<=m&&y.push([k,m]),Qm([...y,...w.map(S=>[S,S])])}};return f}var e0=za("C",!1,e=>gi[e],e=>It[e],Jm),t0=za(ee,!0,e=>e==="word"?Zm(Ba(_r.alnum)):Object.hasOwn(_r,e)?Ba(_r[e]):void 0,(e,t)=>t===void 0?void 0:Ym(t),()=>qa(Ua(Pa),Ua(Da)));function re(e){if(e===ee)return t0;if(Mr(e))return e0;throw new b("feature","locale",`matching in the ${e} locale is not supported`)}var ue=(1n<<63n)-1n,ot=-ue-1n,it=(1n<<64n)-1n;function P(e,t,n,r){let o=E(e.cwd,n,e.fs,r);return R(e,t,n,o.error),o}function R(e,t,n,r){if(r!=="No such file or directory"||typeof n!="string")return;let o=n.startsWith("/"),i=o?"/":e.cwd,s=n.replace(/^\/+/u,""),u=new Set;for(let f of new Set(["/",e.mount??"/",e.home??"/"])){if(f===i)continue;let c=E(f,s,e.fs);c.error||u.add(c.path)}if(!u.size)return;let a=o?"":` from cwd ${JSON.stringify(e.cwd)}`,l=`${o?"absolute":"relative"} path ${JSON.stringify(n)} was not found${a}`;e.notes?.add(`${t}: ${l}. ${n0(e,u)}`)}function n0(e,t){let n=[...t].sort(j),r=n.map(u=>JSON.stringify(u));if(n.length===1)return`A ${e.fs.isDir(n[0])?"dir":"file"} exists at ${r[0]}.`;let i=n.every(u=>!e.fs.isDir(u)&&e.fs.isFile(u))&&n.some(u=>!e.fs.sameFileContents(n[0],u)),s=`${r.slice(0,-1).join(", ")} and ${r.at(-1)}`;return`${n.length===2?"Both":"All"} of ${s} exist${i?", and they differ in contents":""}.`}function Jt(){let e=new Set;return{add:t=>e.add(t),collect(t,n){for(let r of n)r.startsWith(".")&&e.add(Z(t,r))},emit(t,n,r,o=""){gt(t,{command:n,action:"omitted",noun:["hidden entry","hidden entries"],explanation:r,context:o,paths:e})}}}var Ha=/^(?<command>[^:]+): (?<operand>.+): (?<reason>no such file or directory|not a directory|is a directory)$/iu;function Ga(e,t){for(let n of t.split(`
4
+ `))Ha.test(n)&&e.discarded?.add(n)}function bi(e,t,n){let r=new Map;for(let o of e){if(t.includes(o))continue;let{command:i,operand:s,reason:u}=Ha.exec(o).groups,a=/'([^']*)'$/u.exec(s)?.[1]??s;if([...n].some(f=>f.includes(JSON.stringify(a))))continue;let l=`${i}: ${u}`;r.has(l)||r.set(l,new Set),r.get(l).add(a)}return[...r].map(([o,i])=>`${o}: ${[...i].map(s=>JSON.stringify(s)).join(", ")}.`)}function Xa(e,t){return e==="status"?null:{name:t,search:e==="search"}}function Za(){let e=null,t=0;return{skip(n,r){!t&&n&&(e={...n,exitCode:r}),t++},flush(n){if(t&&e){let r=t===1?"the command":`the ${t} commands`,o=e.search&&e.exitCode===1?" A search that selects no lines exits 1, which is not a failure.":"";n.add(`${e.name}: exited ${e.exitCode}, so ${r} after && did not run.${o}`)}e=null,t=0}}}function gt(e,t){r0(e,t,t.paths.size,t.paths)}function r0(e,{command:t,action:n,noun:r,explanation:o="",context:i=""},s,u){if(!s)return;let a=s<10?": "+[...u].sort(j).map(f=>JSON.stringify(f)).join(", "):"",l=Array.isArray(r)?r[s===1?0:1]:r;e.add(`${t}: ${n} ${s} ${l}${i}${a}.${o?" "+o:""}`)}function he(e,t=`
5
+ `){if(e==="")return[];let n=e.split(t);return n.at(-1)===""&&n.pop(),n}var ge=(e,t=`
6
+ `)=>e.length===0?"":e.join(t)+t;function Ge(e,t=`
7
+ `){let n=[];for(let r=0;r<e.length;){let o=e.indexOf(t,r),i=o<0?e.length:o+t.length;n.push(e.slice(r,i)),r=i}return n}function q(e,t="",n=!1,r=null){e.io?.read(e.stdinHandle?.identity),!n&&e.stdinBytes&&rt(e.stdinBytes,Dr(null,e)),e.stdinLeft=t,e.stdinBytes=r}function st(e,t,n,r="",o={}){let i=[],s="",u=r,a=o.read??"text",l=a==="bytes"||a==="loose-bytes",f=l?"bytes":"content",c=p=>l?a==="loose-bytes"?A(p):B(p):p,d=(p,h)=>{if(l){p.bytes=Be(n.fs,h,a==="loose-bytes");return}if(a==="text"||n.fs.isBytes?.(h)!==!0){p.content=n.fs.readFile(h);return}p.bytes=n.fs.readBytes(h),p.content=a==="maybe-text"?me(p.bytes):void 0};for(let p of t){let h={name:p,[f]:c(""),kind:"file"},m;if(p==="/dev/stdin"&&n.stdinFile)n.io?.read(n.stdinHandle?.identity),h[f]=c(n.stdinOrigin);else if(p==="-"||p==="/dev/stdin"){let g=u===r?n.stdinBytes??null:null;Object.assign(h,g===null?Ya(u,a,l):Va(g,a,l,e,n)),h.shared=!0,u="",q(n,"",!0)}else if(p!=="/dev/null"){let g=P(n,e,p);g.error?(h.kind="missing",m=g.error):n.fs.isDir(g.path)?(h.kind="dir",o.noRead||(m="Is a directory")):d(h,g.path)}if(i.push(h),m&&(s+=xi(e,p,m,h.kind==="dir")),h.kind!=="file"&&(o.stopOnError||h.kind==="dir"&&o.stopOnDir))break}return{inputs:i.filter(p=>p.kind==="file"),entries:i,stderr:s,failed:s!==""}}var o0={head:["cannot open '%s' for reading: %r","error reading '%s': Is a directory"],tail:["cannot open '%s' for reading: %r","error reading '%s': Is a directory"],sort:["cannot read: %s: %r","read failed: %s: Is a directory"],sed:["can't read %s: %r","read error on %s: Is a directory"],tac:["failed to open '%s' for reading: %r","%s: read error: Invalid argument"],base32:[null,"read error: Is a directory"],base64:[null,"read error: Is a directory"],uniq:[null,"error reading '%s': Is a directory"]};function xi(e,t,n,r=!1){let o=o0[e]?.[r?1:0],i=o?o.replace(/%[sr]/gu,s=>s==="%s"?t:n):`${t}: ${n}`;return`${e}: ${i}
8
+ `}function Be(e,t,n=!1){let r=e.readBytes?.(t,n);if(r!==void 0)return r;let o=e.readFile(t);if(o!==void 0)return n?A(o):B(o)}function wt(e,t){if(e.isBytes?.(t)!==!0)return{text:e.readFile(t),bytes:void 0};let n=e.readBytes(t);return{text:me(n),bytes:n}}function te(e,t,n,r,o){if(t.length===0){let i=r.stdinBytes??null;q(r,"",!0);let s=o?.read,u=s==="bytes"||s==="loose-bytes",a=[{name:null,kind:"file",...i===null?Ya(n,s,u):Va(i,s,u,e,r)}];return{inputs:a,entries:a,stderr:"",failed:!1}}return st(e,t,r,n,o)}var Ya=(e,t,n)=>n?{bytes:t==="loose-bytes"?A(e):B(e)}:{content:e};function Va(e,t,n,r,o){return n||t==="as-held"?{bytes:e}:t==="maybe-text"?{bytes:e,content:me(e)}:{content:rt(e,Dr(null,o))}}function Dr(e,t){return e===null||e==="-"||e==="/dev/stdin"?t.stdinHandle?.path?JSON.stringify(t.stdinHandle.path):"standard input":JSON.stringify(E(t.cwd,e,t.fs).path??e)}function Ka(e,t,n,r){let o=te(e,t,n,r);return{content:o.inputs.map(i=>i.content).join(""),stderr:o.stderr,failed:o.failed}}var ne=(e,t)=>({stdout:e,stderr:t.stderr,exitCode:t.failed?1:0});function be(e,t,n=e,{max:r=1/0,digitsOnly:o=!1}={}){if(typeof e!="string"||!(o?/^\d+$/u:/^[ \t\n\r\f\v]*\+?\d+$/u).test(e))return{error:x(`${t}: invalid count: ${n}`)};let i=Number(e);return i>r?{error:x(`${t}: out of range: ${n}`)}:{value:Math.min(i,Number.MAX_SAFE_INTEGER)}}function Ja(e,t){if(typeof e!="string")return{error:x(`${t}: invalid count: ${e}`)};let n=e[0]==="+"||e[0]==="-"?e[0]:"",r=n==="-"?e.slice(1):e,o=/^[ \t\n\r\v\f]*\+?(\d+)(b|[kKMGTPEZYRQ](?:i?B)?)?$/u.exec(r),i=!n&&/^(?:b|[kKMGTPEZYRQ](?:i?B)?)$/u.test(r);if(!o&&!i)return{error:x(`${t}: invalid count: ${e}`)};let s=o?.[2]??(i?r:""),u=ki(BigInt(o?.[1]??"1"),s,t,e);return u.error?u:{...u,sign:n}}function ki(e,t,n,r){let o=1n;t==="b"?o=512n:t&&(o=(t.length===2?1000n:1024n)**BigInt("KMGTPEZYRQ".indexOf(t[0].toUpperCase())+1));let i=e*o;return i>it?{error:x(`${n}: count out of range: ${r}`)}:{value:Number(i>BigInt(Number.MAX_SAFE_INTEGER)?BigInt(Number.MAX_SAFE_INTEGER):i)}}function V(e){try{let t=e?.message;return typeof t=="string"&&t!==""?t:String(e)}catch{return"threw a value with no message"}}var ut=e=>e==="/tmp"||e.startsWith("/tmp/");function Qa(e){let t=new Map,n=new Map,r=new Set(["/tmp"]),o,i=e.listDir("/"),s={dirs:[...i.dirs,"tmp"].sort(j),files:i.files,links:i.links??[]},u=f0(r,t,n),a=u.reshaped,l=(c,d)=>{if(!c.startsWith("/tmp/"))throw new Error("writable overlay paths must start with /tmp/");t.has(c)||a(),n.delete(c),t.set(c,d)},f={observeIo:c=>{o=c},fileIdentity:c=>t.get(c),fileSize:c=>t.get(c)?.bytes.length??(n.has(c)?B(n.get(c)).length:e.fileSize(c)),readIdentity:c=>(o?.read(c),W(c.bytes)),isFile:c=>t.has(c)||e.isFile(c),isDir:c=>r.has(c)||e.isDir(c),isLink:c=>n.has(c)||e.isLink?.(c)===!0,readLink:c=>n.get(c)??e.readLink?.(c),...i0(e,t,c=>o?.read(c)),sameFileContents:(c,d)=>c0(e,t,c,d),listDir:c=>c==="/"?s:r.has(c)?u.of(c):e.listDir(c),*walkFiles(c){for(let d of Fe(f,c))d.kind==="file"&&(yield d.path)},openWritable(c,d,p=!1){let h=se(f,c,d);if(h!=="/tmp"&&!h.startsWith("/tmp/"))return null;On(f,c,d);let m=t.get(h);return m?p||(o?.write(m),m.bytes=new Uint8Array):(m={bytes:new Uint8Array},l(h,m)),p0(h,m,p,()=>o?.write(m))},makeWritableDir:(c,d)=>s0(f,{dirs:r,files:t,links:n,reshaped:a},c,d),makeWritableLink:(c,d,p)=>u0(f,{links:n,reshaped:a},c,d,p),removeWritableDir:(c,d)=>l0(f,{dirs:r,reshaped:a},c,d),copyWritable(c,d,p){let h=se(f,c,p);if(!h.startsWith("/tmp/"))return!1;On(f,c,p);let m=t.get(d);if(d===h||m&&m===t.get(h))throw new Error("source and destination are the same file");o?.read(m??d);let g=m?m.bytes:Be(e,d);return f.openWritable(c,p).writeBytes(g),!0},replaceWritable:(c,d,p,h)=>a0(f,{files:t,links:n,put:l},c,d,p,h),removeWritable(c,d){let p=se(f,c,d,!1);if(p!=="/tmp"&&!p.startsWith("/tmp/"))return!1;let h=E(c,d,f,{follow:!1});if(h.error)throw Xe(d,h.error);if(f.isDir(h.path))throw new Error(`${d}: Is a directory`);return n.delete(h.path)||t.delete(h.path),a(),!0}};return f}function i0(e,t,n){return{readFile:r=>{let o=t.get(r);return n(o??r),o?rt(o.bytes,JSON.stringify(r)):e.readFile(r)},readBytes:(r,o=!1)=>{let i=t.get(r);return n(i??r),i?i.bytes:Be(e,r,o)},exactBytes:r=>t.get(r)?.bytes??e.exactBytes(r),isEmptyFile:r=>{let o=t.get(r);return o?o.bytes.length===0:e.isEmptyFile(r)},isBytes:r=>t.has(r)||e.isBytes?.(r)===!0}}function s0(e,t,n,r){let o=se(e,n,r,!1);if(o!=="/tmp"&&!o.startsWith("/tmp/"))return!1;if(t.dirs.has(o))return!0;if(On(e,n,r),t.files.has(o)||t.links.has(o))throw new Error(`${r}: File exists`);return t.dirs.add(o),t.reshaped(),!0}function u0(e,t,n,r,o){let i=se(e,n,r,!1);return i.startsWith("/tmp/")?(d0(e,n,r),t.links.set(i,o),t.reshaped(),!0):!1}function a0(e,t,n,r,o,i){let s=se(e,n,r,!1),u=i===void 0?null:se(e,n,i,!1);if(!s.startsWith("/tmp/")||u!==null&&!u.startsWith("/tmp/"))return!1;On(e,n,r);let a=t.files.get(s),l=t.links.get(s);if(!a&&l===void 0)throw Xe(r,"No such file or directory");u!==null&&On(e,n,i);let f={bytes:B(o)};return l===void 0?u!==null&&t.put(u,a):(t.links.delete(s),u!==null&&(t.links.set(u,l),t.files.delete(u))),t.put(s,f),!0}function l0(e,t,n,r){let o=se(e,n,r,!1);if(o!=="/tmp"&&!o.startsWith("/tmp/"))return!1;let i=E(n,r,e);if(i.error)throw Xe(r,i.error);if(!t.dirs.has(i.path))throw new Error(`${r}: Not a directory`);if(i.path==="/tmp")throw new Error(`${r}: Device or resource busy`);let{dirs:s,files:u,links:a}=e.listDir(i.path);if(s.length||u.length||a.length)throw new Error(`${r}: Directory not empty`);return t.dirs.delete(i.path),t.reshaped(),!0}function f0(e,t,n){let r=new Map,o=(i,s)=>[...i].filter(u=>u.startsWith(s)&&!u.slice(s.length).includes("/")).map(u=>u.slice(s.length)).sort(j);return{reshaped:()=>{r=new Map},of(i){let s=r.get(i);if(s)return s;let u={dirs:o(e,i+"/"),files:o(t.keys(),i+"/"),links:o(n.keys(),i+"/")};return r.set(i,u),u}}}function c0(e,t,n,r){let o=t.get(n),i=t.get(r);if(!o&&!i)return e.sameFileContents(n,r);let s=(u,a)=>a?a.bytes:e.exactBytes(u);return An(s(n,o),s(r,i))}function On(e,t,n){let r=ze(t,n,e);if(r.error===null){if(e.isDir(r.path))throw new Error(`${n}: Is a directory`);if(n.endsWith("/"))throw Xe(n,"Not a directory");return}if(r.rest.length>0||n.endsWith("/")||n.includes("\0"))throw Xe(n,r.error);if(!e.isDir(ye(r.path)))throw Xe(n,"No such file or directory")}function d0(e,t,n){if(n===""||n.includes("\0"))throw Xe(n,"No such file or directory");let r=ze(t,n,e,{follow:!1});if(r.error===null)throw Xe(n,"File exists");if(r.rest.length>0||n.endsWith("/"))throw Xe(n,r.error);if(!e.isDir(ye(r.path)))throw Xe(n,"Not a directory")}function Xe(e,t){return Object.assign(new Error(`${e}: ${t}`),{path:e,fsError:t})}function p0(e,t,n,r){let o=0,i=s=>{let u=t.bytes,a=n?u.length:o,l=Math.max(u.length,a+s.length),f=u.buffer;f.byteLength<l&&(f=new ArrayBuffer(Math.max(l,f.byteLength*2)),new Uint8Array(f).set(u));let c=new Uint8Array(f,0,l);c.set(s,a),t.bytes=c,o=a+s.length};return{path:e,identity:t,get position(){return n?t.bytes.length:o},write(s){s!==""&&(r(),i(B(s)))},writeBytes(s){s.length!==0&&(r(),i(s))}}}var el=["cwd","home","user","inherit"];function tl(e,t){let n=Cn(t,"mount","/"),r=Cn(t,"home",n),o=Cn(t,"cwd",n);if(t.writable!==void 0&&t.writable!==!1&&t.writable!=="/tmp/")throw new TypeError("createTerminal: writable must be '/tmp/', false, or undefined");let i=t.writable==="/tmp/";if(i&&(n==="/"||n==="/tmp"||n.startsWith("/tmp/")))throw new Error("createTerminal: mount must not be /, /tmp, or inside /tmp when writable is '/tmp/'");let s=_a(e,n);return{fs:i?Qa(s):s,cwd:o,home:r,mount:n,writable:i,locale:ja(t)}}function nl(e,t){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(`fork: options must be an object (got ${t===null?"null":Array.isArray(t)?"an array":typeof t})`);for(let n of Object.keys(t))if(!el.includes(n))throw new Error(`fork: unknown option \`${n}\` (known: ${el.join(", ")}; the sources, the mount, the /tmp/ overlay and the commands come from the parent)`);if(t.inherit!==void 0&&typeof t.inherit!="boolean")throw new TypeError(`fork: inherit must be true or false (got ${t.inherit===null?"null":typeof t.inherit})`);return{cwd:Cn(t,"cwd",e.cwd,"fork",e.cwd),home:Cn(t,"home",e.home,"fork",e.cwd),user:t.user??e.user,locale:e.locale,inherit:t.inherit??!0}}function Cn(e,t,n,r="createTerminal",o="/"){let i=e[t]===void 0?n:e[t];if(typeof i!="string"||i.includes("\0"))throw new TypeError(`${r}: ${t} must be a string without NUL characters`);return Z(o,i)}function xe(e,t=0,n=e.value.length){return{value:e.value.slice(t,n),mask:e.mask===null?null:e.mask.slice(t,n),...e.empty?{empty:e.empty.filter(r=>r>=t&&r<=n).map(r=>r-t)}:{}}}function In(e){let t=/^([A-Za-z_][A-Za-z0-9_]*)=/u.exec(e.value);return!t||e.mask!==null&&/[12]/u.test(e.mask.slice(0,t[0].length))||e.empty?.some(n=>n<t[0].length)?null:{name:t[1],end:t[0].length}}var rl=(e,t)=>e.mask===null?"0":e.mask[t];function ol(e,t=!1){let n=new Set;if(!e.value.includes("~"))return n;let r=e.value,o=u=>rl(e,u)==="0",i=t?null:In(e)?.end??null,s=u=>t===!0||i!==null&&u>=i;for(let u=0;u<r.length;u++){let a=u===0||u===i||s(u)&&r[u-1]===":"&&o(u-1),l=s(u)||t==="parameterAssign";if(!a||r[u]!=="~"||!o(u)||!h0(e,u,l))continue;let f=r[u+1];if(f&&f!=="/"&&f!==":"&&o(u+1))throw new b("feature","tilde prefix","named-user and directory-stack tilde prefixes are not supported");(f===void 0||o(u+1)&&(f==="/"||f===":"&&l))&&n.add(u)}return n}function h0(e,t,n){for(let r=t;r<=e.value.length;r++){if(e.empty?.includes(r))return!1;if(r===e.value.length)return!0;if(rl(e,r)!=="0")return!1;if(e.value[r]==="/"||n&&e.value[r]===":")return!0}return!0}function il(...e){let t="",n="",r=[];for(let o of e){for(let i of o.empty??[])r.push(t.length+i);t+=o.value,n+=o.mask??"0".repeat(o.value.length)}return{value:t,mask:e.every(o=>o.mask===null)?null:n,...r.length?{empty:r}:{}}}var Qt=64;function at(e,t){let n="";for(let r=t+1;r<e.length;r++){let o=e[r];if(o==="`")return{command:n,raw:e.slice(t,r+1),backtick:!0};if(o!=="\\"){n+=o;continue}let i=e[r+1];if(i==="`")throw new b("feature","\\`","nested backtick command substitution is not supported; use `$( )` instead");if(i==="$"||i==="\\"){n+=i,r++;continue}if(i===`
9
+ `){r++;continue}n+=o}throw new Error("unterminated backtick substitution")}var sl=()=>({value:"",quoted:!1,started:!1}),ul=()=>new b("feature","command substitution depth",`command substitution nesting above ${Qt} is not supported`);function vi(e,t,n,r,o){if(r>=Qt)throw ul();let i={line:e,i:n+1,depth:r,helpers:o,parens:0,quote:null,word:sl(),command:!0,target:null,heredocs:[]};for(;i.i<e.length;)if(m0(i))return{raw:e.slice(t,i.i+1),command:e.slice(n+1,i.i)};throw i.quote?new Error(`unterminated ${i.quote==="'"?"single":"double"} quote`):new Error("unterminated command substitution")}function yt(e,t,n=!1){e.word.value+=t,e.word.quoted||=n,e.word.started=!0}function Si(e){let t=e.word;if(t.started){if(e.target)e.target.op==="heredoc"&&(e.target.delim=t.value,e.target.quotedDelim=t.quoted),e.target=null;else if(e.command&&!t.quoted){if(t.value==="case")throw new b("feature","case","`case` patterns inside command substitutions are not supported");e.command=["!","{","do","then","else","elif","if","while","until"].includes(t.value)||/^[A-Za-z_][A-Za-z0-9_]*=/u.test(t.value)}else e.command=!1;e.word=sl()}}function m0(e){let{line:t,i:n,quote:r}=e,o=t[n];if(r&&o===r)return e.quote=null,e.word.quoted=!0,e.i++,!1;if(r==="'")return yt(e,o,!0),e.i++,!1;if(o==="\\")return g0(e),!1;if(o==="$")return w0(e),!1;if(o==="`")return y0(e),!1;if(r)return yt(e,o,!0),e.i++,!1;if(o==="'"||o==='"')return e.quote=o,e.word.started=!0,e.i++,!1;if(e.command&&!e.target&&!e.word.started&&t.startsWith("[[",n)&&/[ \t\n()<>;&|]|^$/u.test(t[n+2]??"")){let s=e.helpers.readConditional(t,n,e.helpers,e.depth+e.parens+1);return e.i+=s.raw.length,e.command=!1,!1}if(o==="#"&&!e.word.started){let s=t.indexOf(`
10
+ `,n);return e.i=s===-1?t.length:s,!1}if(o===`
11
+ `)return x0(e),!1;if(o===" "||o===" ")return Si(e),e.i++,!1;let i;try{i=e.helpers.readOperator(t,n,!e.word.started)}catch(s){if(!(s instanceof b))throw s;return e.i++,!1}return i?b0(e,i):(yt(e,o),e.i++,!1)}function g0(e){let t=e.line[e.i+1];if(t===`
12
+ `){e.i+=2;return}t!==void 0&&(!e.quote||'$`"\\'.includes(t))?(yt(e,t,!0),e.i+=2):(yt(e,"\\",!!e.quote),e.i++)}function w0(e){let{line:t,i:n}=e,r=e.helpers.skipContinuations(t,n+1);if(!e.quote&&t[r]==="'"){let s=e.helpers.decodeAnsiC(t,r+1);yt(e,s.text,!0),e.i=s.end;return}if(!e.quote&&t[r]==='"'){e.quote='"',e.word.started=!0,e.i=r+1;return}let i=e.helpers.readExpansion(t,n,e.depth+e.parens+1,e.quote==='"')?.raw??"$";yt(e,i,!!e.quote),e.i+=i.length}function y0(e){let t=e.i++;for(;e.i<e.line.length;){let n=e.line[e.i++];if(n==="`"){yt(e,e.line.slice(t,e.i),!!e.quote);return}n==="\\"&&e.i<e.line.length&&e.i++}throw new Error("unterminated backtick substitution")}function b0(e,t){Si(e);let n=t.token;if(n.kind==="paren_close"){if(e.parens===0){if(e.heredocs.length)throw new b("feature","command substitution heredoc","a command substitution heredoc must finish before its closing parenthesis");return!0}e.parens--,e.command=!1}else if(n.kind==="paren_open"){if(e.depth+ ++e.parens>=Qt)throw ul();e.command=!0}else n.kind==="redir"?(e.command=!1,n.op==="heredoc"&&e.heredocs.push(n),["dup","close"].includes(n.op)||(e.target=n)):e.command=!0;return e.i=t.end,!1}function x0(e){if(Si(e),e.heredocs.some(t=>t.delim===null))throw new Error("heredoc requires a delimiter");e.heredocs.length&&(e.i=e.helpers.readHeredocBodies(e.line,e.i,e.heredocs),e.heredocs=[]),e.command=!0,e.i++}function Ze(e){return Number.isInteger(e)&&e>=0&&e<=1114111&&(e<55296||e>57343)}var Ue=e=>e>65535?2:1,Le=(e,t)=>Ue(e.codePointAt(t));var k0=/^(?:[A-Za-z_][A-Za-z0-9_]*|[0-9]+|[?*@#$!-])(?![\s\S])/u,v0=/^(?:[A-Za-z_][A-Za-z0-9_]*|[0-9]+|[?*@#$!-])/u;function Ft(e,t="unsupported or malformed parameter expansion"){return new b("feature","${",`${t}: \${${e}}`)}var Ei=e=>/^[0-9]+$/u.test(e)?e.replace(/^0+(?=[0-9])/u,""):e;function $i(e){let t=e.replaceAll(`\\
13
+ `,"");if(t.startsWith("#")&&t.length>1&&k0.test(t.slice(1)))return{name:Ei(t.slice(1)),operator:"length"};if(/^#[A-Za-z_0-9]/u.test(t))throw Ft(e);let n=v0.exec(t)?.[0];if(!n)throw Ft(e);let r=t.slice(n.length);if(!r)return{name:Ei(n),operator:""};if(n==="#"&&/^[%:=+/]$/u.test(r))throw Ft(e);let o=/^(?::[-+=?]|[-+=?]|##?|%%?|:|\/\/?)/u.exec(r)?.[0];if(!o)throw Ft(e);return{name:Ei(n),operator:o,word:e.slice(S0(e,n.length+o.length))}}function S0(e,t){let n=0;for(;t>0;)e[n]==="\\"&&e[n+1]===`
14
+ `?n+=2:(t--,n++);return n}var bt=(e,t)=>new b("feature",e,t),al=e=>{if(e>=64)throw bt("expansion depth","shell expansion nesting above 64 levels is not supported")};function ll(e,t,n,r,o,i){al(r);let s=n+1,u=null;for(let a=s;a<e.length;a++){let l=e[a];if(u==="'"){l==="'"&&(u=null);continue}if(l==="\\"){a++;continue}if(l==='"'){u=u==='"'?null:'"';continue}if(l==="'"&&!u){u="'";continue}if(l==="`")throw bt("`","command substitution (backticks) is not supported");if(l==="$"){let f=a+1;for(;e[f]==="\\"&&e[f+1]===`
15
+ `;)f+=2;if(e[f]==="'"&&!u){let d=i.decodeAnsiC(e,f+1),p=$i(e.slice(s,a)).operator;if(o&&/[-+?=]/u.test(p)&&/[$`"'\\}]/u.test(d.text))throw bt("${","active characters in ANSI-C quoted parameter operands are not supported");a=d.end-1;continue}let c=i.readExpansion(e,a,r+1,o||u==='"');if(c){a+=c.raw.length-1;continue}}if(l==="}"&&!u){let f=$i(e.slice(s,a));return{raw:e.slice(t,a+1),parameter:f}}}throw bt("${","unterminated parameter expansion")}function fl(e,t,n,r,o){al(r);let i=0;for(let s=n+1;s<e.length;s++){let u=e[s];if(u==="\\"){s++;continue}if(u==="$"){let l=o.readExpansion(e,s,r+1,!0);if(l){s+=l.raw.length-1;continue}}if(u==="`")throw bt("`","command substitution (backticks) is not supported");if(u==='"'||u==="'")throw bt("$((","quotes in arithmetic expressions are not supported");if(u==="("&&i++,u!==")")continue;if(i){i--;continue}let a=s+1;for(;e[a]==="\\"&&e[a+1]===`
16
+ `;)a+=2;if(e[a]!==")")throw bt("$((","arithmetic expansion requires a closing `))`");return{raw:e.slice(t,a+1),arithmetic:e.slice(n+1,s)}}throw bt("$((","unterminated arithmetic expansion")}var E0=/^-[abcdefghknoprstuvwxzGLNORS]$/u,$0=new Set(["=","==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"]),N0=new Set(["end","&&","||",")"]),A0=/^[A-Za-z_][A-Za-z0-9_]*$/u;function Tn(e,t,n,r=0){let o={line:e,i:t+2,helpers:n,token:null,depth:0,terms:0,removed:0,expansionDepth:r};try{Ye(o,!0);let i=hl(o);return o.token.kind!=="end"&&xt(`unexpected token \`${o.token.value??o.token.kind}\``),{raw:e.slice(t,o.i+o.removed),expression:i}}catch(i){if(i instanceof b||i.conditional)throw i;xt(i.message)}}function hl(e){let t=cl(e);for(;e.token.kind==="||";)Ye(e,!0),t={kind:"or",left:t,right:cl(e)};return t}function cl(e){let t=Ni(e);for(;e.token.kind==="&&";)Ye(e,!0),t={kind:"and",left:t,right:Ni(e)};return t}function Ni(e){if(++e.terms>128)throw new b("feature","[[ complexity","conditional expressions above 128 terms are not supported");if(++e.depth>64)throw new b("feature","[[ nesting","conditional nesting above 64 levels is not supported");try{let t=e.token;if(t.kind==="("){Ye(e,!0);let o=hl(e);return e.token.kind!==")"&&xt("expected `)`"),Ye(e,!0),o}if(ml(t,"!"))return Ye(e,!0),{kind:"not",expression:Ni(e)};if(t.kind!=="word"&&xt("expected an operand"),Ye(e),!t.quoted&&E0.test(t.value)){let o=dl(e);return Ye(e,!0),{kind:"unary",op:t.value,word:o}}if(N0.has(e.token.kind))return{kind:"unary",op:"-n",word:t};let n=e.token;if((n.quoted||!$0.has(n.value))&&xt("conditional binary operator expected"),n.value==="=~")throw new b("feature","[[ =~","regular expression comparisons in [[ are not supported");Ye(e);let r=dl(e);return Ye(e,!0),{kind:"binary",op:n.value,left:t,right:r}}finally{e.depth--}}var ml=(e,t)=>e.kind==="word"&&!e.quoted&&e.value===t,xt=e=>{throw Object.assign(new Error(`[[ ${e}`),{conditional:!0})};function dl(e){return e.token.kind!=="word"&&xt("expected an operand"),e.token}function Ye(e,t=!1){if(e.token=pl(e),t)for(;e.token.kind==="newline";)e.token=pl(e)}function pl(e){for(;e.i<e.line.length;){let t=e.line[e.i];if(t===" "||t===" "){e.i++;continue}if(t==="\\"&&e.line[e.i+1]===`
17
+ `){e.i+=2;continue}if(t==="#"){let o=e.line.indexOf(`
18
+ `,e.i);e.i=o<0?e.line.length:o;continue}if(t===`
19
+ `)return e.i++,{kind:"newline"};let n=e.line.slice(e.i,e.i+2);if(n==="<("||n===">(")throw new b("feature",n,`process substitution (\`${n}\u2026\`) is not supported`);if(n==="&&"||n==="||")return e.i+=2,{kind:n};if("()<>;&|".includes(t))return e.i++,{kind:t,value:t};let r=O0(e);return ml(r,"]]")?{kind:"end"}:r}xt("missing `]]`")}function O0(e){let t={kind:"word",value:"",mask:"",quoted:!1,empty:[]},n=null,r=0;for(;e.i<e.line.length;){let o=e.line[e.i];if(n&&o===n){t.value.length===r&&t.empty.push(r),t.quoted=!0,n=null,e.i++;continue}if(n==="'"){_e(t,o,"1"),e.i++;continue}if(o==="\\"){C0(e,t,n);continue}if(o==="$"){if(I0(e),!n&&e.line[e.i+1]==='"'){n='"',r=t.value.length,e.i+=2;continue}T0(e,t,n);continue}if(o==="`"){let i=at(e.line,e.i);_e(t,"`",n?"2":"0"),_e(t,i.raw.slice(1),"1"),e.i+=i.raw.length;continue}if(n){_e(t,o,"2"),e.i++;continue}if(o==="'"||o==='"'){n=o,r=t.value.length,e.i++;continue}if(o==="("&&t.mask.at(-1)==="0"&&/[?*+@!]/u.test(t.value.at(-1))&&!t.empty.includes(t.value.length))throw new b("feature","[[ extglob","extended glob patterns in [[ are not supported");if(/[ \t\n()<>;&|]/u.test(o))break;_e(t,o,"0"),e.i++}return n&&xt(`unterminated ${n==="'"?"single":"double"} quote`),!t.quoted&&!/[12]/u.test(t.mask)&&(t.mask=null),t.empty.length===0&&delete t.empty,t}function _e(e,t,n,r=n!=="0"){e.value+=t,e.mask+=n.repeat(t.length),e.quoted||=r}function C0(e,t,n){let r=e.line[e.i+1];if(r===`
20
+ `){e.i+=2;return}r!==void 0&&(!n||'$`"\\'.includes(r))?(_e(t,r,"1"),e.i+=2):(_e(t,"\\",n?"2":"1"),e.i++)}function I0(e){for(;e.line[e.i+1]==="\\"&&e.line[e.i+2]===`
21
+ `;)e.line=e.line.slice(0,e.i+1)+e.line.slice(e.i+3),e.removed+=2}function T0(e,t,n){let r=n?"2":"0";if(!n&&e.line[e.i+1]==="'"){let i=e.helpers.decodeAnsiC(e.line,e.i+2);i.text===""&&t.empty.push(t.value.length),_e(t,i.text,"1"),e.i=i.end;return}let o=e.helpers.readExpansion(e.line,e.i,e.expansionDepth+1,!!n);if(!o){_e(t,"$","1"),e.i++;return}if(o.command!==void 0||o.parameter!==void 0||o.arithmetic!==void 0)_e(t,"$",r),_e(t,o.raw.slice(1),"1",!1);else{let i=e.line[e.i+o.raw.length],s=A0.test(o.name)&&(i==="'"||i==='"')?"${"+o.name+"}":o.raw;_e(t,s,r)}e.i+=o.raw.length}var Lt=/^[A-Za-z_][A-Za-z0-9_]*$/u,F0=/[A-Za-z0-9_]/u,L0=/[?#@*$!0-9-]/u;function ae(e,t){for(;e[t]==="\\"&&e[t+1]===`
22
+ `;)t+=2;return t}function Ai(e,t,n=null){let r=s=>s<e.length&&(n===null||n[s]===n[t]);if(!r(t+1))return null;let o=e[t+1];if(L0.test(o))return{name:o,raw:e.slice(t,t+2)};if(!/[A-Za-z_]/u.test(o))return null;let i=t+2;for(;r(i)&&F0.test(e[i]);)i++;return{name:e.slice(t+1,i),raw:e.slice(t,i)}}function ft(e,t,n=0,r=!1,o={}){let i=(a,l,f,c)=>ft(a,l,f,c,o),s=ae(e,t+1),u=e[s];if(u==="("){let a=ae(e,s+1);if(e[a]==="(")return fl(e,t,a,n,{readExpansion:i});let l=vi(e,t,s,n,{readExpansion:i,decodeAnsiC:en,readHeredocBodies:Ln,readOperator:Br,readConditional:Tn,skipContinuations:ae});return o.validateSubstitution?.(l.command),l}if(u==="{")return ll(e,t,s,n,r,{readExpansion:i,decodeAnsiC:en});if(u==="[")throw new b("feature","$[","arithmetic expansion (`$[\u2026]`) is not supported");return Ai(e,t)}function yl(e,t,n={}){let r=(s,u,a,l)=>ft(s,u,a,l,n),o=ae(e,t+1),i=vi(e,t,o,0,{readExpansion:r,decodeAnsiC:en,readHeredocBodies:Ln,readOperator:Br,readConditional:Tn,skipContinuations:ae});return n.validateSubstitution?.(i.command),i}var gl={a:"\x07",b:"\b",e:"\x1B",E:"\x1B",f:"\f",n:`
23
+ `,r:"\r",t:" ",v:"\v","\\":"\\","'":"'",'"':'"',"?":"?"};function _0(e,t){for(let n=t;n<e.length;n++)if(e[n]==="\\")n++;else if(e[n]==="'")return n;throw new Error("unterminated single quote")}function en(e,t){let n=_0(e,t),r=[],o=s=>{for(let u of A(s))r.push(u)};for(let s=t;s<n;s++){if(e[s]!=="\\"){let l=String.fromCodePoint(e.codePointAt(s));o(l),s+=l.length-1;continue}let u=e[s+1];if(u in gl){o(gl[u]),s++;continue}if(u==="x"&&e[s+2]==="{")throw new b("feature","ANSI-C hexadecimal escape","braced hexadecimal escapes in ANSI-C quotes are not supported");let a=/^(?:[0-7]{1,3}|x[0-9a-fA-F]{1,2}|u[0-9a-fA-F]{1,4}|U[0-9a-fA-F]{1,8})/u.exec(e.slice(s+1,n));if(a){let l=a[0],f=/^[0-7]/u.test(l),c=f?parseInt(l,8):parseInt(l.slice(1),16);if(f||l[0]==="x")r.push(c&255);else{if(!Ze(c))throw new b("feature","ANSI-C Unicode escape","ANSI-C escapes outside Unicode scalar values are not supported");o(String.fromCodePoint(c))}s+=l.length;continue}if(u==="c"&&s+2<n){let l=e.codePointAt(s+2);if(l>127)throw new b("feature","ANSI-C control escape","ANSI-C control escapes require an ASCII character");r.push(l===63?127:l&31),s+=2,l===92&&e[s+1]==="\\"&&s++;continue}o("\\")}let i=r.indexOf(0);return{text:W(Uint8Array.from(i===-1?r:r.slice(0,i))),end:n+1}}function Br(e,t,n){let r=e[t];if(n&&/[0-9]/u.test(r)){let s="",u=t;for(;/[0-9]/u.test(e[u]??"");)s+=e[u],u=ae(e,u+1);return e[u]!==">"&&e[u]!=="<"||e[ae(e,u+1)]==="("?null:wl(e,u,Number(s))}let o=ae(e,t+1),i=e[o];switch(r){case"|":return i==="|"?lt("or",o+1):i==="&"?lt("pipe_err",o+1):lt("pipe",t+1);case"&":if(i==="&")return lt("and",o+1);if(i===">"){let s=ae(e,o+1),u=e[s]===">";return kt(1,u?"bothAppend":"both",(u?s:o)+1)}return lt("amp",t+1);case";":return i===";"?lt("dsemi",o+1):lt("semi",t+1);case"(":return lt("paren_open",t+1);case")":return lt("paren_close",t+1);case"<":case">":return wl(e,t,r==="<"?0:1);default:return null}}var R0={semi:";",dsemi:";;",pipe:"|",pipe_err:"|&",and:"&&",or:"||",amp:"&",paren_open:"(",paren_close:")"},M0={write:">",append:">>",read:"<",heredoc:"<<",herestring:"<<<",both:"&>",bothAppend:"&>>",dup:">&",close:">&-"};function Fn(e){if(e.kind==="word")return e.quoted?`"${e.value}"`:e.value;if(e.kind==="redir"){let t=M0[e.op];if(e.op==="both"||e.op==="bothAppend")return t;let n=e.fd===(e.op==="read"||e.op==="heredoc"||e.op==="herestring"?0:1)?"":String(e.fd);return e.op==="dup"?`${n}${e.fd===0?"<&":">&"}${e.toFd}`:e.op==="close"?`${n}${e.fd===0?"<&-":">&-"}`:n+t}return R0[e.kind]}var lt=(e,t)=>({token:{kind:e},end:t}),kt=(e,t,n,r)=>({token:{kind:"redir",fd:e,op:t,...r},end:n});function wl(e,t,n){let r=e[t],o=ae(e,t+1),i=e[o];if(i==="&")return P0(e,o,n,r==="<"?"<&":`${n===1&&r===">"?"":n}>&`);if(r==="<"){if(i===">")throw new b("feature","<>","read/write file redirects are not supported");if(i==="<"){let s=ae(e,o+1);if(e[s]==="<")return kt(n,"herestring",s+1);let u=e[s]==="-";return kt(n,"heredoc",(u?s:o)+1,{strip:u,delim:null,body:null})}return kt(n,"read",t+1)}return i===">"?kt(n,"append",o+1):kt(n,"write",(i==="|"?o:t)+1)}function P0(e,t,n,r){let o=ae(e,t+1),i=e[o],s=e[ae(e,o+1)],u=s===void 0||/[ \t\n|&>;()<]/u.test(s);if(/[0-9]/u.test(i??"")&&u)return kt(n,"dup",o+1,{toFd:Number(i)});if(i==="-"&&u)return kt(n,"close",o+1);throw new b("feature","redirect target",`redirect \`${r}\` requires a file descriptor number (or \`-\`) followed by a token boundary`)}function Ln(e,t,n){let r=t+1;for(let o of n){let i=[],s=!1;for(;r<e.length;){let u,a="";for(;;){u=e.indexOf(`
24
+ `,r);let l=u===-1?e.length:u;if(a+=e.slice(r,l),r=l+1,o.quotedDelim||u===-1||!D0(a))break;a=a.slice(0,-1)}if(u===-1&&a==="")break;if(o.strip&&(a=a.replace(/^\t+/u,"")),a===o.delim){s=!0;break}if(i.push(a),u===-1)break}o.body=i.length===0?"":i.join(`
25
25
  `)+`
26
- `,s||(i.warning=`warning: here-document delimited by end-of-file (wanted \`${i.delim}')
27
- `)}return r-1}function Pm(e){let t=0;for(;t<e.length&&e[e.length-1-t]==="\\";)t++;return t%2===1}var Dm=new Set(["semi","amp","and","or","pipe","pipe_err","paren_open"]),Um=e=>e===" "||e===" ";function xr(e,t={}){return la(Hi(e,t),!1).tokens}function aa(e,t={}){let n=Hi(e,t);return{read:()=>la(n,!0),reset:()=>{n.tokens=[]}}}function la(e,t){for(;e.i<e.line.length;){let n=e.line[e.i];if(e.quote&&n===e.quote){ca(e),e.i++;continue}if(e.quote==="'"){re(e,n,"1"),e.i++;continue}if(n==="\\"){fa(e);continue}if(n==="$"){pa(e);continue}if(n==="`"){ha(e);continue}if(e.quote){re(e,n,"2"),e.i++;continue}if(n==="'"||n==='"'){Xi(e,n),e.i++;continue}let r=e.cur!==""||e.empty.length>0;if(!r&&e.line.startsWith("[[",e.i)&&/[ \t\n()<>;&|]|^$/u.test(e.line[e.i+2]??"")&&zm(e.tokens)){let o=vn(e.line,e.i,{readExpansion:e.readExpansion,decodeAnsiC:Ut});ua(e,{kind:"condition",expression:o.expression}),e.i+=o.raw.length;continue}if(n==="#"&&!r){jm(e);continue}if(n===`
28
- `){if(Hm(e),t)return{tokens:e.tokens,done:e.i>=e.line.length};continue}if(Um(n)){En(e),e.i++;continue}if(n==="("&&e.mask.at(-1)==="0"&&/[?*+@!]/u.test(e.cur.at(-1))&&!e.empty.includes(e.cur.length))throw new w("feature","extglob","extended glob patterns are not supported");if((n==="<"||n===">")&&e.line[ne(e.line,e.i+1)]==="("){qm(e);continue}let i=wr(e.line,e.i,!r);if(i?.token.kind==="paren_open"&&(i.token.wordAdjacent=r),i){En(e),ua(e,i.token),e.i=i.end;continue}re(e,n,"0"),e.i++}if(e.quote)throw new Error(`unterminated ${e.quote==="'"?"single":"double"} quote`);return En(e),e.heredocs.length>0&&Sn(e.line,e.line.length,e.heredocs),{tokens:e.tokens,done:!0}}function Hi(e,t={}){return{line:e,i:0,tokens:[],cur:"",mask:"",empty:[],quoted:!1,quoteStart:0,quote:null,heredocs:[],lastParenAt:-2,readExpansion:(n,r,i=0,o=!1)=>_e(n,r,i,o,t),readProcess:(n,r)=>gr(n,r,t)}}function Gi(e,t=!1){let n={...Hi(e),fragment:!0,fragmentQuoted:t};for(;n.i<n.line.length;){let r=n.line[n.i];if(n.quote&&r===n.quote){ca(n),n.i++;continue}if(n.quote==="'"){re(n,r,"1"),n.i++;continue}if(r==="\\"){fa(n);continue}if(r==="$"){pa(n);continue}if(r==="`"){ha(n);continue}if(n.quote){re(n,r,"2"),n.i++;continue}if(r==='"'||r==="'"&&!t){Xi(n,r),n.i++;continue}if(!t&&(r==="<"||r===">")&&n.line[ne(n.line,n.i+1)]==="(")throw new w("feature",`${r}(`,"process substitution in parameter operands is not supported");re(n,r,t?"2":"0"),n.i++}if(n.quote)throw new w("feature","${","unterminated quote in parameter operand");return En(n),n.tokens[0]??{value:"",mask:t?"":null}}var Bm=new Set(["semi","and","or","pipe","pipe_err","amp","paren_open"]),Wm=new Set(["!","{","if","then","else","elif","while","until","do"]);function zm(e){let t=!0,n=null,r=!1;for(let i of e){let o=Bm.has(i.kind)||i.kind==="paren_close"&&n?.kind==="paren_open";if(n=i,o){t=!0,r=!1;continue}if(i.kind==="redir"){t=!1,r=!["dup","close"].includes(i.op);continue}if(r){r=!1;continue}(!t||i.kind!=="word"||i.quoted||!Wm.has(i.value))&&(t=!1)}return t&&!r}function Xi(e,t){e.quoteStart=e.cur.length,e.quote=t}function ca(e){e.cur.length===e.quoteStart&&e.empty.push(e.cur.length),e.quote=null}function re(e,t,n,r=n!=="0"){e.cur+=t,e.mask+=n.repeat(t.length),e.quoted||=r}function En(e){if(e.cur!==""||e.empty.length>0){let t=e.empty.length>0||e.quoted,n={kind:"word",value:e.cur,mask:/[12]/u.test(e.mask)||t?e.mask:null,quoted:t,...e.empty.length?{empty:e.empty}:{}};e.tokens.push(n);let r=e.heredocs.find(i=>i.delim===null);r&&(r.delim=n.value,r.quotedDelim=t)}e.cur="",e.mask="",e.empty=[],e.quoted=!1}function ua(e,t){t.kind==="paren_open"&&(t.adjacent=ne(e.line,e.lastParenAt+1)===e.i,e.lastParenAt=e.i),t.kind==="redir"&&t.op==="heredoc"&&e.heredocs.push(t),e.tokens.push(t)}function fa(e){let t=e.line[e.i+1];if(t===`
29
- `){e.i+=2;return}t!==void 0&&(!(e.quote||e.fragmentQuoted)||'$`"\\'.includes(t)||e.fragment&&t==="}")?(re(e,t,"1"),e.i+=2):(re(e,"\\",e.quote||e.fragmentQuoted?"2":"1"),e.i++)}function da(e,t){let n=ne(e.line,t);n!==t&&(e.line=e.line.slice(0,t)+e.line.slice(n))}function pa(e){da(e,e.i+1);let{line:t}=e,n=e.quote==='"'||e.fragmentQuoted?"2":"0",r=t[e.i+1];if((n==="0"||e.fragmentQuoted&&!e.quote)&&r==="'"){let u=Ut(t,e.i+2);if(e.fragmentQuoted&&/[$`"\\]/u.test(u.text))throw new w("feature","${","active characters in ANSI-C quoted parameter operands are not supported");u.text===""&&e.empty.push(e.cur.length),re(e,u.text,"1"),e.i=u.end;return}if((n==="0"||e.fragmentQuoted&&!e.quote)&&r==='"'){Xi(e,'"'),e.i+=2;return}let i=e.readExpansion(t,e.i,0,n==="2");if(!i){re(e,"$","1"),e.i++;return}if(i.command!==void 0||i.parameter!==void 0||i.arithmetic!==void 0){re(e,"$",n),re(e,i.raw.slice(1),"1",!1),e.i+=i.raw.length;return}let o=t[e.i+i.raw.length],s=$t.test(i.name)&&(o==='"'||o==="'")?"${"+i.name+"}":i.raw;re(e,s,n),e.i+=i.raw.length}function qm(e){da(e,e.i+1);let{raw:t}=e.readProcess(e.line,e.i);re(e,e.line[e.i],"0"),re(e,t.slice(1),"1",!1),e.i+=t.length}function ha(e){let t=e.quote==='"'||e.fragmentQuoted?"2":"0",{raw:n}=Te(e.line,e.i);re(e,"`",t),re(e,n.slice(1),"1",!1),e.i+=n.length}function jm(e){for(;e.i<e.line.length&&e.line[e.i]!==`
30
- `;)e.i++}function Hm(e){En(e),e.heredocs.length>0&&(e.i=Sn(e.line,e.i,e.heredocs),e.heredocs=[]);let t=e.tokens.at(-1);t&&!Dm.has(t.kind)?e.tokens.push({kind:"semi",newline:!0}):(t?.kind==="semi"||t?.kind==="amp")&&(t.lineEnd=!0),e.i++}function yr(e,t,n){let r={aliases:new Set(t),hasCommand:n};return pt(e,r),r.aliases}var $n=(e,t)=>new Set([...e,...t]);function pt(e,t){let n=null;for(let r of e){let i=r.gate==="and"||r.gate==="or";if(i&&n!==null&&r.gate==="and"!=(n===0))continue;let o=i&&n===null?new Set(t.aliases):null,s=r.stages.length===1?r.stages[0]:null;n=s&&!s.isolate?Gm(s,t):null,r.negate&&n!==null&&(n=+(n===0)),o&&(t.aliases=$n(o,t.aliases),n=null)}return n}function Gm(e,t){if(e.group)return pt(e.group,t);if(e.conditional)return Xm(e.conditional,t);if(e.loop){if(e.loop.condition&&pt(e.loop.condition,t),e.loop.words===void 0||e.loop.words.length>0){let i=new Set(t.aliases);pt(e.loop.body,t),t.aliases=$n(i,t.aliases)}return null}let n=e.words[0]?.value;if(e.redirs.length===0&&(n==="true"||n==="false"))return+(n==="false");if(!["alias","unalias"].includes(n)||t.hasCommand(n))return null;let r=e.words.slice(1).map(i=>i.value);for(;r[0]?.startsWith("-")&&r[0]!=="-";){let i=r.shift();if(i==="--")break;if(!(n==="alias"?/^-p+$/u:/^-a+$/u).test(i))return null;if(n==="unalias")return t.aliases.clear(),null}for(let i of r)if(n==="unalias")t.aliases.delete(i);else{let o=i.indexOf("="),s=i.slice(0,o);o>0&&!/[ \t\n/$`=;'"\\|&()<>]/u.test(s)&&t.aliases.add(s)}return null}function Xm(e,t){let n=new Set;for(let r of e.branches){let i=pt(r.condition,t);if(i===0)return pt(r.body,t),t.aliases=$n(n,t.aliases),null;if(i===null){let o={...t,aliases:new Set(t.aliases)};pt(r.body,o),n=$n(n,o.aliases)}}return e.otherwise&&pt(e.otherwise,t),t.aliases=$n(n,t.aliases),null}var Le=class extends Error{constructor(t){super(t.message),this.finalError=t}},ht=e=>new Le(new Error(e));function he(e,t=e.i){for(;t>=e.raw.length&&!e.done;){let n=e.read();e.raw=n.tokens,e.done=n.done}return e.raw[t]}function ma(e,t,n){let r=t.validation??new Map;return{validateSubstitution(i){r.has(i)||(Zi(i,!0,e,{validation:r,syntaxOnly:!0},n),r.set(i,!0))}}}function Zi(e,t,n,r,i){try{return i(xr(e,ma(n,r,i)),t,n,r)}catch(o){throw o instanceof Le?o.finalError:o}}function ga(e,t,n,r){let i=aa(e,ma(n,{},r)),o=new Set,s=!1;return()=>{let u={aliases:o,aliasUsed:s,read:i.read,unit:!0},a=r([],t,n,u);return s=u.aliasUsed,o=yr(a,o,n),i.reset(),{steps:a,done:u.done}}}function*wa(e,t,n,r){let i=ga(e,t,n,r);for(;;){let o;try{o=i()}catch(s){throw s instanceof Le?s.finalError:s}if(o.steps.length>0&&(yield o.steps),o.done)return}}function xa(e,t,n,r){let i=ga(e,t,n,r),o=[];for(;;){let s;try{s=i()}catch(u){let a=u instanceof Le;return{units:o,error:a?u.finalError:u,incomplete:a}}if(s.steps.length>0&&o.push(s.steps),s.done)return{units:o,error:null,incomplete:!1}}}var Zm=["elif","else","fi"];function ba(e,t){let n=[],r;do{je(e);let o=t(e,"then");je(e);let s=t(e,Zm);n.push({condition:o,body:s}),r=e.raw[e.i-1].value}while(r==="elif");let i=null;return r==="else"&&(je(e),i=t(e,"fi")),{branches:n,otherwise:i}}function va(e,t){let{raw:n}=e,r=e.loop;e.loop="for";let i=he(e);if(i?.kind==="paren_open")throw new w("feature","for ((","arithmetic `for ((\u2026))` loops are not supported; use `for NAME in WORD...`");if(i===void 0||i.kind!=="word")throw new Error("for: expected a variable name");let o=i.value;if(i.quoted||!$t.test(o))throw new Error(`for: \`${o}\` is not a valid variable name`);e.i++;let s=he(e);s?.kind==="semi"&&e.i++;let u=he(e);if(s?.kind==="semi"&&!s.newline&&Bt(u,"in"))throw new Error("for: unexpected `in` after `;`");if(!Bt(u,"in")){if(Bt(u,"do")||u===void 0){let d=new w("feature","for NAME; do",`\`for ${o}; do \u2026\` iterates the positional parameters, which this shell does not have; write \`for ${o} in WORD...\``);throw u===void 0?new Le(d):d}throw new Error(`for: expected \`in\` after \`${o}\``)}e.i++;let a=[],l=!1;for(let d;(d=he(e))&&d.kind!=="semi";e.i++){if(d.kind!=="word")throw new Error(`for: unexpected \`${kn(d)}\` in word list`);Bt(d,"do")&&(l=!0),a.push(fe(d))}n[e.i]?.kind==="semi"&&e.i++;let c=he(e);if(!Bt(c,"do"))throw c===void 0?ht(l?"for: expected `;` or newline before `do`":"for: missing `do`"):l?new Error("for: expected `;` or newline before `do`"):new Error(`for: expected \`do\`, got \`${kn(c)}\``);e.i++,je(e);let f={name:o,words:a,body:t(e,"done")};return e.loop=r,f}function ka(e,t,n){let r=e.loop;e.loop=t,je(e);let i=n(e,"do");je(e);let o={until:t==="until",condition:i,body:n(e,"done")};return e.loop=r,o}function Sa(e,t,n){if(t.quoted||!$t.test(t.value))throw new w("feature","function",`shell functions named \`${t.value}\` are not supported`);e.i+=2,je(e);let r=he(e);if(!Bt(r,"{"))throw new w("feature","function",`\`${t.value}()\` needs a \`{ \u2026 }\` body`);e.i++,je(e);let i=n(e,"}");if(!Nt(i))throw new w("feature","function",`\`${t.value}()\` is supported only while its body reads and writes no variable`);return{name:t.value,body:i}}var Nt=e=>e.every(t=>t.stages.every(Vm));function Vm(e){return e.assigns.length>0||e.define?!1:e.test?br(e.test)&&e.redirs.every(ya):e.group?Nt(e.group):e.conditional?e.conditional.branches.every(t=>Nt(t.condition)&&Nt(t.body))&&Nt(e.conditional.otherwise??[]):e.loop?(e.loop.words??[]).every(Wt)&&Nt(e.loop.condition??[])&&Nt(e.loop.body):e.words.every(Wt)&&e.redirs.every(ya)}function br(e){return e.kind==="and"||e.kind==="or"?br(e.left)&&br(e.right):e.kind==="not"?br(e.expression):e.kind==="unary"?Wt(e.word):Wt(e.left)&&Wt(e.right)}var ya=e=>e.op==="text"?!e.expand||!/[$`]/u.test(e.body):e.word===void 0||Wt(e.word);function Wt(e){for(let t=0;t<e.value.length;t++){let n=e.value[t];if((n==="$"||n==="`")&&(e.mask===null||e.mask[t]!=="1"))return!1}return!0}function je(e){for(let t;(t=he(e))?.kind==="semi"&&t.newline;)e.i++}function Bt(e,t){return e!==void 0&&e.kind==="word"&&!e.quoted&&e.value===t}var Oa=(e,t=!1,n=()=>!1,r={})=>Zi(e,t,n,r,Ji),Ca=(e,t=!1,n=()=>!1)=>wa(e,t,n,Ji),kr=(e,t=!1,n=()=>!1)=>xa(e,t,n,Ji);function Ji(e,t,n,r){let i={raw:e,i:0,done:!r.read,read:r.read,unitOnly:r.unit,emptyStage:!1,writable:t,aliases:r.aliases??new Set,aliasUsed:r.aliasUsed??!1,hasCommand:n,syntaxOnly:r.syntaxOnly};try{let o=he(i)?At(i,null):[];if(i.emptyStage)throw new Error("empty pipeline stage");return r.aliasUsed=i.aliasUsed,r.done=i.done,o}catch(o){if(i.aliasUsed&&!(o instanceof w)){let s=new w("feature","alias expansion","alias expansion is not supported; input using aliases cannot be parsed");throw o instanceof Le?new Le(s):s}throw o}}function Yi(e,t,n){t.stages.push(n),!vr(n)&&!Ki(n)&&(e.emptyStage=!0)}var Ki=e=>e.words.length>0||e.assigns.length>0||e.redirs.length>0,vr=e=>e.group||e.loop||e.conditional||e.test||e.define,Ea=()=>({words:[],assigns:[],redirs:[]}),Vi=e=>({gate:e,stages:[],negate:!1,bang:!1}),$a=(e,t)=>e.bang&&e.stages.length===0&&zt(t)&&t.redirs.length===0,zt=e=>!vr(e)&&e.words.length===0&&e.assigns.length===0,Ym=new Set(["for","while","until","do","done","if","{","}","!"]),Km=new Set(["then","else","elif","fi","esac","in"]),Na=new Map([["case","`case` statements are not supported; gate on exit status with `&&` / `||` instead"],["select","`select` loops are not supported"],["function","shell functions are not supported"],["time","`time` is not supported"],["coproc","`coproc` is not supported"]]),Jm=new Set(["alias","declare","typeset","local","readonly","export","eval","let"]),Qm=new Set(["pipe","pipe_err","and","or","semi","amp"]),Aa=new Set(["semi","amp"]);function At(e,t){let{raw:n}=e,r=[Vi("first")];t===null&&(e.unit=r[0]);let i=0,o=Ea();for(let s;s=he(e);){if(s.kind==="condition"){if(!zt(o))throw new Error("unexpected `[[`");o.test=s.expression,e.i++;continue}if(s.kind==="paren_close"){if(t!==")")throw new Error("unexpected `)`");return e.i++,Ia(e,r,o,t)}if(s.kind==="paren_open"){eg(e,o);continue}if(Qm.has(s.kind)){if(s.kind==="pipe_err"&&(Ki(o)||vr(o))&&o.redirs.push({fd:2,op:"dup",toFd:1}),s.kind==="semi"&&$a(r.at(-1),o)||Yi(e,r.at(-1),o),s.kind==="amp"&&(r.at(-1).background=!0),o=Ea(),s.kind==="and"||s.kind==="or"?r.push(Vi(s.kind)):Aa.has(s.kind)&&r.push(Vi("seq")),t===null&&(s.newline||s.lineEnd)){if(e.unitOnly)return e.i++,r.pop(),r;e.aliases=yr(r.slice(i,-1),e.aliases,e.hasCommand),i=r.length-1,e.unit=r.at(-1)}e.i++;continue}if(s.kind==="dsemi")throw new Error("syntax error near unexpected token `;;`");if(s.kind==="redir"){if(s.warning&&(e.unit.warnings=(e.unit.warnings??"")+s.warning),o.define)throw new w("feature","function",`\`${o.define.name}()\` with a redirect of its own is not supported`);let a=og(e);a&&o.redirs.push(a);continue}if(o.group||o.define)throw new Error(`unexpected token after \`${o.isolate?")":"}"}\``);if(o.loop)throw new Error("unexpected token after `done`");if(o.conditional)throw new Error("unexpected token after `fi`");if(o.test)throw new Error("unexpected token after `]]`");if(!s.quoted&&o.words.length===0&&e.aliases.has(s.value)&&(e.aliasUsed=!0),!s.quoted&&zt(o)){if(Array.isArray(t)?t.includes(s.value):s.value===t)return e.i++,Ia(e,r,o,t);if(tg(s,e,r.at(-1),o))continue}let u=o.words.length===0?bn(s):null;u===null?o.words.push(fe(s)):o.assigns.push({name:u.name,word:fe(s,u.end)}),e.i++}if(t===")")throw ht("unmatched `(`");if(t==="}")throw ht("unmatched `{`");if(t==="do"||t==="done")throw ht(`${e.loop}: missing \`${t}\``);if(t)throw ht(`if: missing \`${t==="then"?"then":"fi"}\``);if(!e.emptyStage&&!vr(o)&&!Ki(o)&&["and","or","pipe","pipe_err"].includes(n.at(-1)?.kind))throw ht("empty pipeline stage");return Aa.has(n.at(-1)?.kind)?r.pop():$a(r.at(-1),o)||Yi(e,r.at(-1),o),r}function eg(e,t){let{raw:n,i:r}=e,i=he(e,r+1),o=n[r-1],s=t.words[0],u=t.words.at(-1);if(!(n[r-2]?.kind==="redir"&&!["dup","close"].includes(n[r-2].op))&&(t.words.length===0&&t.assigns.length>0||u&&u.value===o?.value&&(t.words.length===1||s.mask===null&&Jm.has(s.value)))&&n[r].wordAdjacent&&o?.kind==="word"&&!o.quoted&&/^[A-Za-z_][A-Za-z0-9_]*\+?=$/u.test(o.value))throw new w("feature","array assignment","shell array assignments are not supported");if(i?.kind==="paren_open"&&i.adjacent&&zt(t))throw new w("feature","((","arithmetic evaluation (`((\u2026))`) is not supported");if(t.words.length===1&&t.assigns.length===0&&t.redirs.length===0&&i?.kind==="paren_close"){t.define=Sa(e,t.words.pop(),At);return}if(!zt(t))throw new Error("unexpected `(`");e.i++,t.group=At(e,")"),t.isolate=!0}function tg(e,t,n,r){let i=e.value;if(Na.has(i))throw new w("feature",i,Na.get(i));if(Km.has(i))throw new Error(`syntax error near unexpected token \`${i}\``);if(!Ym.has(i))return!1;if(t.i++,i==="!"){if(n.stages.length>0||r.redirs.length>0)throw new Error("syntax error near unexpected token `!`");return n.negate=!n.negate,n.bang=!0,!0}if(i==="{")return je(t),r.group=At(t,"}"),r.isolate=!1,!0;if(i==="}")throw new Error("syntax error near unexpected token `}`");if(i==="done")throw new Error("unexpected `done`");if(i==="do")throw new Error("unexpected `do`");return i==="if"?r.conditional=ba(t,At):r.loop=i==="for"?va(t,At):ka(t,i,At),!0}var ng={")":"empty subshell `()`","}":"empty group `{ }`"},rg=(e,t)=>t==="do"?`${e.loop}: empty condition`:t==="done"?`${e.loop}: empty loop body`:t==="then"?"if: empty condition":"if: empty branch body";function Ia(e,t,n,r){let i=t.at(-1),o=zt(n)&&n.redirs.length===0&&i.stages.length===0;if(o&&t.length===1)throw new Error(ng[r]??rg(e,r));if(o&&i.bang)throw new Error("syntax error near unexpected token after `!`");return o&&i.gate==="seq"?t.pop():Yi(e,i,n),t}var ig=new Set(["/dev/null","/dev/stdout","/dev/stderr"]);function og(e){let t=e.raw[e.i++],n=kn(t);if(e.syntaxOnly){if(!["dup","close"].includes(t.op)){let u=he(e,e.i++);if(!u||u.kind!=="word")throw new Error(`redirect \`${n}\` requires a target`)}return t}if(t.fd>2)throw new w("feature",n,`only file descriptors 0, 1 and 2 are supported (got \`${n}\`)`);if(t.op==="dup"){if(t.fd===0&&t.toFd===0)return null;if(t.fd===0||t.toFd===0)throw new w("feature",n,`duplicating file descriptor 0 (\`${n}\`) is not supported`);return{fd:t.fd,op:"dup",toFd:t.toFd}}if(t.op==="close"){if(t.fd===0)throw new w("feature","0<&-","closing standard input is not supported");return{fd:t.fd,op:"close"}}let r=he(e,e.i++);if(!r||r.kind!=="word")throw new Error(`redirect \`${n}\` requires a target`);if(t.op==="heredoc"||t.op==="herestring"||t.op==="read"){if(t.fd!==0)throw new w("feature",n,`reading into file descriptor ${t.fd} (\`${n}\`) is not supported`);return t.op==="heredoc"?{fd:0,op:"text",body:t.body??"",expand:!t.quotedDelim}:{fd:0,op:t.op,word:fe(r)}}if(t.fd===0)throw new w("feature",n,`writing to file descriptor 0 (\`${n}\`) is not supported`);let i=t.op==="both"||t.op==="bothAppend",o=t.op==="append"||t.op==="bothAppend",s=fe(r);if(sg(s))return{fd:t.fd,op:"to",word:s,both:i,append:o,label:n};if(!e.writable&&!ig.has(s.value))throw Qi(n,s.value,e.writable);return{fd:t.fd,op:"to",target:s.value,both:i,append:o,label:n}}function sg(e){for(let t=0;t<e.value.length;t++){let n=e.value[t],r=e.mask===null?"0":e.mask[t];if((n==="$"||n==="`")&&r!=="1"||r==="0"&&(/[~*?[{]/u.test(n)||(n==="<"||n===">")&&e.value[t+1]==="("))return!0}return!1}function Qi(e,t,n){let r=n?"only `/tmp/` is writable":"the filesystem is read-only";return new w("feature",e,`\`${e}\` cannot write to \`${t}\`: ${r}`)}var ug=/^[a-zA-Z0-9][\w.+-]*$/u,eo=["run","pipe","hidden"],to=["stdout","stderr","exitCode"];function Fa(e,t){let n={__proto__:null},r=[],i=[];for(let[o,s]of ag(e)){let{run:u,pipe:a,hidden:l}=lg(o,s,t);l&&r.includes(o)||(n[o]=(c,f,d)=>cg(o,u,c,f,d),!l&&(r.push(o),a&&i.push(o)))}return{handlers:n,names:r,pipeNames:i}}function ag(e){if(e==null)return[];if(Array.isArray(e))throw new TypeError("createTerminal: opts.commands must be an object or a Map (got an array)");if(typeof e!="object")throw new TypeError(`createTerminal: opts.commands must be an object or a Map (got ${typeof e})`);if(typeof e.entries=="function")return[...e.entries()];let t=Object.getPrototypeOf(e);if(t!==Object.prototype&&t!==null)throw new TypeError("createTerminal: opts.commands must be a plain object or a Map (own enumerable properties only)");return Object.entries(e)}function lg(e,t,n){if(typeof e!="string")throw new TypeError(`createTerminal: command names must be strings (got ${typeof e})`);if(!ug.test(e))throw new Error(`createTerminal: invalid command name: ${JSON.stringify(e)}`);if(n(e))throw new Error(`createTerminal: ${e}: cannot redefine a built-in command`);if(typeof t=="function"){for(let i of Object.keys(t))if(eo.includes(i))throw new Error(`createTerminal: ${e}: \`${i}\` belongs on a { run } descriptor, not on the handler function`);return{run:t,pipe:!1,hidden:!1}}if(t===null||typeof t!="object")throw new TypeError(`createTerminal: ${e}: expected a function or a { run } object`);let r=t.run;if(typeof r!="function")throw new TypeError(`createTerminal: ${e}: \`run\` must be a function`);for(let i of Object.keys(t))if(!eo.includes(i))throw new Error(`createTerminal: ${e}: unknown option \`${i}\` (known: ${eo.join(", ")})`);return{run:r,pipe:!!t.pipe,hidden:!!t.hidden}}function cg(e,t,n,r,i){i.io?.bufferOutput(),z(i);let o={cwd:i.cwd,fs:i.fs,mount:i.mount,home:i.home,get notes(){return i.notes},command:e,stdinFile:i.stdinFile,stdinOrigin:i.stdinOrigin},s={name:e,args:r,stdin:n,cwd:o.cwd,fs:fg(o),readInputs:(u=[])=>{if(typeof u=="string")throw new TypeError(`readInputs: expected an array of paths, got a string: ${u}`);return te(e,[...u],n,o)}};return dg(t(s))}function fg(e){let t=n=>$(e.cwd,n,e.fs).path;return{resolve:n=>L(e.cwd,n),isFile:n=>e.fs.isFile(t(n)),isDir:n=>e.fs.isDir(t(n)),readFile:n=>e.fs.readFile(t(n)),listDir:n=>{let{path:r,error:i}=P(e,e.command,n);if(!e.fs.isDir(r))throw new Error(`${n}: ${i??"Not a directory"}`);let{dirs:o,files:s}=e.fs.listDir(r);return{dirs:[...o],files:[...s]}},walkFiles:n=>[...e.fs.walkFiles(t(n))]}}function dg(e){if(e==null)return C();if(typeof e=="string")return C(e);if(typeof e!="object")throw new TypeError(`invalid result: expected a string or an object (got ${typeof e})`);if(typeof e.then=="function")throw new TypeError("invalid result: commands are synchronous, a promise cannot be awaited");if(Array.isArray(e))throw new TypeError("invalid result: expected a string or an object, got an array (join the lines first)");let t=Object.keys(e);for(let o of t)if(!to.includes(o))throw new TypeError(`invalid result: unknown field \`${o}\` (known: ${to.join(", ")})`);if(t.length===0)throw new TypeError(`invalid result: an object with none of ${to.join(", ")} \u2014 return a string for plain output`);let{stdout:n="",stderr:r="",exitCode:i=0}=e;if(typeof n!="string")throw new TypeError(`invalid result: stdout must be a string (got ${typeof n})`);if(typeof r!="string")throw new TypeError(`invalid result: stderr must be a string (got ${typeof r})`);if(!Number.isInteger(i)||i<0)throw new TypeError(`invalid result: exitCode must be a non-negative integer (got ${i})`);return{stdout:n,stderr:r===""||r.endsWith(`
26
+ `,s||(o.warning=`warning: here-document delimited by end-of-file (wanted \`${o.delim}')
27
+ `)}return r-1}function D0(e){let t=0;for(;t<e.length&&e[e.length-1-t]==="\\";)t++;return t%2===1}var B0=new Set(["semi","amp","and","or","pipe","pipe_err","paren_open"]),U0=e=>e===" "||e===" ";function Ur(e,t={}){return kl(Oi(e,t),!1).tokens}function xl(e,t={}){let n=Oi(e,t);return{read:()=>kl(n,!0),reset:()=>{n.tokens=[]}}}function kl(e,t){for(;e.i<e.line.length;){let n=e.line[e.i];if(e.quote&&n===e.quote){vl(e),e.i++;continue}if(e.quote==="'"){fe(e,n,"1"),e.i++;continue}if(n==="\\"){Sl(e);continue}if(n==="$"){$l(e);continue}if(n==="`"){Nl(e);continue}if(e.quote){fe(e,n,"2"),e.i++;continue}if(n==="'"||n==='"'){Ii(e,n),e.i++;continue}let r=e.cur!==""||e.empty.length>0;if(!r&&e.line.startsWith("[[",e.i)&&/[ \t\n()<>;&|]|^$/u.test(e.line[e.i+2]??"")&&q0(e.tokens)){let i=Tn(e.line,e.i,{readExpansion:e.readExpansion,decodeAnsiC:en});bl(e,{kind:"condition",expression:i.expression}),e.i+=i.raw.length;continue}if(n==="#"&&!r){H0(e);continue}if(n===`
28
+ `){if(G0(e),t)return{tokens:e.tokens,done:e.i>=e.line.length};continue}if(U0(n)){_n(e),e.i++;continue}if(n==="("&&e.mask.at(-1)==="0"&&/[?*+@!]/u.test(e.cur.at(-1))&&!e.empty.includes(e.cur.length))throw new b("feature","extglob","extended glob patterns are not supported");if((n==="<"||n===">")&&e.line[ae(e.line,e.i+1)]==="("){z0(e);continue}let o=Br(e.line,e.i,!r);if(o?.token.kind==="paren_open"&&(o.token.wordAdjacent=r),o){_n(e),bl(e,o.token),e.i=o.end;continue}fe(e,n,"0"),e.i++}if(e.quote)throw new Error(`unterminated ${e.quote==="'"?"single":"double"} quote`);return _n(e),e.heredocs.length>0&&Ln(e.line,e.line.length,e.heredocs),{tokens:e.tokens,done:!0}}function Oi(e,t={}){return{line:e,i:0,tokens:[],cur:"",mask:"",empty:[],quoted:!1,quoteStart:0,quote:null,heredocs:[],lastParenAt:-2,readExpansion:(n,r,o=0,i=!1)=>ft(n,r,o,i,t),readProcess:(n,r)=>yl(n,r,t)}}function Ci(e,t=!1){let n={...Oi(e),fragment:!0,fragmentQuoted:t};for(;n.i<n.line.length;){let r=n.line[n.i];if(n.quote&&r===n.quote){vl(n),n.i++;continue}if(n.quote==="'"){fe(n,r,"1"),n.i++;continue}if(r==="\\"){Sl(n);continue}if(r==="$"){$l(n);continue}if(r==="`"){Nl(n);continue}if(n.quote){fe(n,r,"2"),n.i++;continue}if(r==='"'||r==="'"&&!t){Ii(n,r),n.i++;continue}if(!t&&(r==="<"||r===">")&&n.line[ae(n.line,n.i+1)]==="(")throw new b("feature",`${r}(`,"process substitution in parameter operands is not supported");fe(n,r,t?"2":"0"),n.i++}if(n.quote)throw new b("feature","${","unterminated quote in parameter operand");return _n(n),n.tokens[0]??{value:"",mask:t?"":null}}var j0=new Set(["semi","and","or","pipe","pipe_err","amp","paren_open"]),W0=new Set(["!","{","if","then","else","elif","while","until","do"]);function q0(e){let t=!0,n=null,r=!1;for(let o of e){let i=j0.has(o.kind)||o.kind==="paren_close"&&n?.kind==="paren_open";if(n=o,i){t=!0,r=!1;continue}if(o.kind==="redir"){t=!1,r=!["dup","close"].includes(o.op);continue}if(r){r=!1;continue}(!t||o.kind!=="word"||o.quoted||!W0.has(o.value))&&(t=!1)}return t&&!r}function Ii(e,t){e.quoteStart=e.cur.length,e.quote=t}function vl(e){e.cur.length===e.quoteStart&&e.empty.push(e.cur.length),e.quote=null}function fe(e,t,n,r=n!=="0"){e.cur+=t,e.mask+=n.repeat(t.length),e.quoted||=r}function _n(e){if(e.cur!==""||e.empty.length>0){let t=e.empty.length>0||e.quoted,n={kind:"word",value:e.cur,mask:/[12]/u.test(e.mask)||t?e.mask:null,quoted:t,...e.empty.length?{empty:e.empty}:{}};e.tokens.push(n);let r=e.heredocs.find(o=>o.delim===null);r&&(r.delim=n.value,r.quotedDelim=t)}e.cur="",e.mask="",e.empty=[],e.quoted=!1}function bl(e,t){t.kind==="paren_open"&&(t.adjacent=ae(e.line,e.lastParenAt+1)===e.i,e.lastParenAt=e.i),t.kind==="redir"&&t.op==="heredoc"&&e.heredocs.push(t),e.tokens.push(t)}function Sl(e){let t=e.line[e.i+1];if(t===`
29
+ `){e.i+=2;return}t!==void 0&&(!(e.quote||e.fragmentQuoted)||'$`"\\'.includes(t)||e.fragment&&t==="}")?(fe(e,t,"1"),e.i+=2):(fe(e,"\\",e.quote||e.fragmentQuoted?"2":"1"),e.i++)}function El(e,t){let n=ae(e.line,t);n!==t&&(e.line=e.line.slice(0,t)+e.line.slice(n))}function $l(e){El(e,e.i+1);let{line:t}=e,n=e.quote==='"'||e.fragmentQuoted?"2":"0",r=t[e.i+1];if((n==="0"||e.fragmentQuoted&&!e.quote)&&r==="'"){let u=en(t,e.i+2);if(e.fragmentQuoted&&/[$`"\\]/u.test(u.text))throw new b("feature","${","active characters in ANSI-C quoted parameter operands are not supported");u.text===""&&e.empty.push(e.cur.length),fe(e,u.text,"1"),e.i=u.end;return}if((n==="0"||e.fragmentQuoted&&!e.quote)&&r==='"'){Ii(e,'"'),e.i+=2;return}let o=e.readExpansion(t,e.i,0,n==="2");if(!o){fe(e,"$","1"),e.i++;return}if(o.command!==void 0||o.parameter!==void 0||o.arithmetic!==void 0){fe(e,"$",n),fe(e,o.raw.slice(1),"1",!1),e.i+=o.raw.length;return}let i=t[e.i+o.raw.length],s=Lt.test(o.name)&&(i==='"'||i==="'")?"${"+o.name+"}":o.raw;fe(e,s,n),e.i+=o.raw.length}function z0(e){El(e,e.i+1);let{raw:t}=e.readProcess(e.line,e.i);fe(e,e.line[e.i],"0"),fe(e,t.slice(1),"1",!1),e.i+=t.length}function Nl(e){let t=e.quote==='"'||e.fragmentQuoted?"2":"0",{raw:n}=at(e.line,e.i);fe(e,"`",t),fe(e,n.slice(1),"1",!1),e.i+=n.length}function H0(e){for(;e.i<e.line.length&&e.line[e.i]!==`
30
+ `;)e.i++}function G0(e){_n(e),e.heredocs.length>0&&(e.i=Ln(e.line,e.i,e.heredocs),e.heredocs=[]);let t=e.tokens.at(-1);t&&!B0.has(t.kind)?e.tokens.push({kind:"semi",newline:!0}):(t?.kind==="semi"||t?.kind==="amp")&&(t.lineEnd=!0),e.i++}function jr(e,t,n){let r={aliases:new Set(t),hasCommand:n};return vt(e,r),r.aliases}var Rn=(e,t)=>new Set([...e,...t]);function vt(e,t){let n=null;for(let r of e){let o=r.gate==="and"||r.gate==="or";if(o&&n!==null&&r.gate==="and"!=(n===0))continue;let i=o&&n===null?new Set(t.aliases):null,s=r.stages.length===1?r.stages[0]:null;n=s&&!s.isolate?X0(s,t):null,r.negate&&n!==null&&(n=+(n===0)),i&&(t.aliases=Rn(i,t.aliases),n=null)}return n}function X0(e,t){if(e.group)return vt(e.group,t);if(e.conditional)return Z0(e.conditional,t);if(e.loop){if(e.loop.condition&&vt(e.loop.condition,t),e.loop.words===void 0||e.loop.words.length>0){let o=new Set(t.aliases);vt(e.loop.body,t),t.aliases=Rn(o,t.aliases)}return null}let n=e.words[0]?.value;if(e.redirs.length===0&&(n==="true"||n==="false"))return+(n==="false");if(!["alias","unalias"].includes(n)||t.hasCommand(n))return null;let r=e.words.slice(1).map(o=>o.value);for(;r[0]?.startsWith("-")&&r[0]!=="-";){let o=r.shift();if(o==="--")break;if(!(n==="alias"?/^-p+$/u:/^-a+$/u).test(o))return null;if(n==="unalias")return t.aliases.clear(),null}for(let o of r)if(n==="unalias")t.aliases.delete(o);else{let i=o.indexOf("="),s=o.slice(0,i);i>0&&!/[ \t\n/$`=;'"\\|&()<>]/u.test(s)&&t.aliases.add(s)}return null}function Z0(e,t){let n=new Set;for(let r of e.branches){let o=vt(r.condition,t);if(o===0)return vt(r.body,t),t.aliases=Rn(n,t.aliases),null;if(o===null){let i={...t,aliases:new Set(t.aliases)};vt(r.body,i),n=Rn(n,i.aliases)}}return e.otherwise&&vt(e.otherwise,t),t.aliases=Rn(n,t.aliases),null}var Ve=class extends Error{constructor(t){super(t.message),this.finalError=t}},St=e=>new Ve(new Error(e));function ke(e,t=e.i){for(;t>=e.raw.length&&!e.done;){let n=e.read();e.raw=n.tokens,e.done=n.done}return e.raw[t]}function Al(e,t,n){let r=t.validation??new Map;return{validateSubstitution(o){r.has(o)||(Ti(o,!0,e,{validation:r,syntaxOnly:!0},n),r.set(o,!0))}}}function Ti(e,t,n,r,o){try{return o(Ur(e,Al(n,r,o)),t,n,r)}catch(i){throw i instanceof Ve?i.finalError:i}}function Y0(e,t,n,r){let o=xl(e,Al(n,{},r)),i=new Set,s=!1;return()=>{let u={aliases:i,aliasUsed:s,read:o.read,unit:!0},a=r([],t,n,u);return s=u.aliasUsed,i=jr(a,i,n),o.reset(),{steps:a,done:u.done}}}function*Ol(e,t,n,r){let o=Y0(e,t,n,r);for(;;){let i;try{i=o()}catch(s){throw s instanceof Ve?s.finalError:s}if(i.steps.length>0&&(yield i.steps),i.done)return}}var V0=["elif","else","fi"];function Il(e,t){let n=[],r;do{Ke(e);let i=t(e,"then");Ke(e);let s=t(e,V0);n.push({condition:i,body:s}),r=e.raw[e.i-1].value}while(r==="elif");let o=null;return r==="else"&&(Ke(e),o=t(e,"fi")),{branches:n,otherwise:o}}function Tl(e,t){let{raw:n}=e,r=e.loop;e.loop="for";let o=ke(e);if(o?.kind==="paren_open")throw new b("feature","for ((","arithmetic `for ((\u2026))` loops are not supported; use `for NAME in WORD...`");if(o===void 0||o.kind!=="word")throw new Error("for: expected a variable name");let i=o.value;if(o.quoted||!Lt.test(i))throw new Error(`for: \`${i}\` is not a valid variable name`);e.i++;let s=ke(e);s?.kind==="semi"&&e.i++;let u=ke(e);if(s?.kind==="semi"&&!s.newline&&tn(u,"in"))throw new Error("for: unexpected `in` after `;`");if(!tn(u,"in")){if(tn(u,"do")||u===void 0){let d=new b("feature","for NAME; do",`\`for ${i}; do \u2026\` iterates the positional parameters, which this shell does not have; write \`for ${i} in WORD...\``);throw u===void 0?new Ve(d):d}throw new Error(`for: expected \`in\` after \`${i}\``)}e.i++;let a=[],l=!1;for(let d;(d=ke(e))&&d.kind!=="semi";e.i++){if(d.kind!=="word")throw new Error(`for: unexpected \`${Fn(d)}\` in word list`);tn(d,"do")&&(l=!0),a.push(xe(d))}n[e.i]?.kind==="semi"&&e.i++;let f=ke(e);if(!tn(f,"do"))throw f===void 0?St(l?"for: expected `;` or newline before `do`":"for: missing `do`"):l?new Error("for: expected `;` or newline before `do`"):new Error(`for: expected \`do\`, got \`${Fn(f)}\``);e.i++,Ke(e);let c={name:i,words:a,body:t(e,"done")};return e.loop=r,c}function Fl(e,t,n){let r=e.loop;e.loop=t,Ke(e);let o=n(e,"do");Ke(e);let i={until:t==="until",condition:o,body:n(e,"done")};return e.loop=r,i}function Ll(e,t,n){if(t.quoted||!Lt.test(t.value))throw new b("feature","function",`shell functions named \`${t.value}\` are not supported`);e.i+=2,Ke(e);let r=ke(e);if(!tn(r,"{"))throw new b("feature","function",`\`${t.value}()\` needs a \`{ \u2026 }\` body`);e.i++,Ke(e);let o=n(e,"}");if(!_t(o))throw new b("feature","function",`\`${t.value}()\` is supported only while its body reads and writes no variable`);return{name:t.value,body:o}}var _t=e=>e.every(t=>t.stages.every(K0));function K0(e){return e.assigns.length>0||e.define?!1:e.test?Wr(e.test)&&e.redirs.every(Cl):e.group?_t(e.group):e.conditional?e.conditional.branches.every(t=>_t(t.condition)&&_t(t.body))&&_t(e.conditional.otherwise??[]):e.loop?(e.loop.words??[]).every(nn)&&_t(e.loop.condition??[])&&_t(e.loop.body):e.words.every(nn)&&e.redirs.every(Cl)}function Wr(e){return e.kind==="and"||e.kind==="or"?Wr(e.left)&&Wr(e.right):e.kind==="not"?Wr(e.expression):e.kind==="unary"?nn(e.word):nn(e.left)&&nn(e.right)}var Cl=e=>e.op==="text"?!e.expand||!/[$`]/u.test(e.body):e.word===void 0||nn(e.word);function nn(e){for(let t=0;t<e.value.length;t++){let n=e.value[t];if((n==="$"||n==="`")&&(e.mask===null||e.mask[t]!=="1"))return!1}return!0}function Ke(e){for(let t;(t=ke(e))?.kind==="semi"&&t.newline;)e.i++}function tn(e,t){return e!==void 0&&e.kind==="word"&&!e.quoted&&e.value===t}var Bl=(e,t=!1,n=()=>!1,r={})=>Ti(e,t,n,r,jl),Ul=(e,t=!1,n=()=>!1)=>Ol(e,t,n,jl);function jl(e,t,n,r){let o={raw:e,i:0,done:!r.read,read:r.read,unitOnly:r.unit,emptyStage:!1,writable:t,aliases:r.aliases??new Set,aliasUsed:r.aliasUsed??!1,hasCommand:n,syntaxOnly:r.syntaxOnly};try{let i=ke(o)?Rt(o,null):[];if(o.emptyStage)throw new Error("empty pipeline stage");return r.aliasUsed=o.aliasUsed,r.done=o.done,i}catch(i){if(o.aliasUsed&&!(i instanceof b)){let s=new b("feature","alias expansion","alias expansion is not supported; input using aliases cannot be parsed");throw i instanceof Ve?new Ve(s):s}throw i}}function Li(e,t,n){t.stages.push(n),!qr(n)&&!_i(n)&&(e.emptyStage=!0)}var _i=e=>e.words.length>0||e.assigns.length>0||e.redirs.length>0,qr=e=>e.group||e.loop||e.conditional||e.test||e.define,_l=()=>({words:[],assigns:[],redirs:[]}),Fi=e=>({gate:e,stages:[],negate:!1,bang:!1}),Rl=(e,t)=>e.bang&&e.stages.length===0&&rn(t)&&t.redirs.length===0,rn=e=>!qr(e)&&e.words.length===0&&e.assigns.length===0,J0=new Set(["for","while","until","do","done","if","{","}","!"]),Q0=new Set(["then","else","elif","fi","esac","in"]),Ml=new Map([["case","`case` statements are not supported; gate on exit status with `&&` / `||` instead"],["select","`select` loops are not supported"],["function","shell functions are not supported"],["time","`time` is not supported"],["coproc","`coproc` is not supported"]]),eg=new Set(["alias","declare","typeset","local","readonly","export","eval","let"]),tg=new Set(["pipe","pipe_err","and","or","semi","amp"]),Pl=new Set(["semi","amp"]);function Rt(e,t){let{raw:n}=e,r=[Fi("first")];t===null&&(e.unit=r[0]);let o=0,i=_l();for(let s;s=ke(e);){if(s.kind==="condition"){if(!rn(i))throw new Error("unexpected `[[`");i.test=s.expression,e.i++;continue}if(s.kind==="paren_close"){if(t!==")")throw new Error("unexpected `)`");return e.i++,Dl(e,r,i,t)}if(s.kind==="paren_open"){ng(e,i);continue}if(tg.has(s.kind)){if(s.kind==="pipe_err"&&(_i(i)||qr(i))&&i.redirs.push({fd:2,op:"dup",toFd:1}),s.kind==="semi"&&Rl(r.at(-1),i)||Li(e,r.at(-1),i),s.kind==="amp"&&(r.at(-1).background=!0),i=_l(),s.kind==="and"||s.kind==="or"?r.push(Fi(s.kind)):Pl.has(s.kind)&&r.push(Fi("seq")),t===null&&(s.newline||s.lineEnd)){if(e.unitOnly)return e.i++,r.pop(),r;e.aliases=jr(r.slice(o,-1),e.aliases,e.hasCommand),o=r.length-1,e.unit=r.at(-1)}e.i++;continue}if(s.kind==="dsemi")throw new Error("syntax error near unexpected token `;;`");if(s.kind==="redir"){if(s.warning&&(e.unit.warnings=(e.unit.warnings??"")+s.warning),i.define)throw new b("feature","function",`\`${i.define.name}()\` with a redirect of its own is not supported`);let a=ug(e);a&&i.redirs.push(a);continue}if(i.group||i.define)throw new Error(`unexpected token after \`${i.isolate?")":"}"}\``);if(i.loop)throw new Error("unexpected token after `done`");if(i.conditional)throw new Error("unexpected token after `fi`");if(i.test)throw new Error("unexpected token after `]]`");if(!s.quoted&&i.words.length===0&&e.aliases.has(s.value)&&(e.aliasUsed=!0),!s.quoted&&rn(i)){if(Array.isArray(t)?t.includes(s.value):s.value===t)return e.i++,Dl(e,r,i,t);if(rg(s,e,r.at(-1),i))continue}let u=i.words.length===0?In(s):null;u===null?i.words.push(xe(s)):i.assigns.push({name:u.name,word:xe(s,u.end)}),e.i++}if(t===")")throw St("unmatched `(`");if(t==="}")throw St("unmatched `{`");if(t==="do"||t==="done")throw St(`${e.loop}: missing \`${t}\``);if(t)throw St(`if: missing \`${t==="then"?"then":"fi"}\``);if(!e.emptyStage&&!qr(i)&&!_i(i)&&["and","or","pipe","pipe_err"].includes(n.at(-1)?.kind))throw St("empty pipeline stage");return Pl.has(n.at(-1)?.kind)?r.pop():Rl(r.at(-1),i)||Li(e,r.at(-1),i),r}function ng(e,t){let{raw:n,i:r}=e,o=ke(e,r+1),i=n[r-1],s=t.words[0],u=t.words.at(-1);if(!(n[r-2]?.kind==="redir"&&!["dup","close"].includes(n[r-2].op))&&(t.words.length===0&&t.assigns.length>0||u&&u.value===i?.value&&(t.words.length===1||s.mask===null&&eg.has(s.value)))&&n[r].wordAdjacent&&i?.kind==="word"&&!i.quoted&&/^[A-Za-z_][A-Za-z0-9_]*\+?=$/u.test(i.value))throw new b("feature","array assignment","shell array assignments are not supported");if(o?.kind==="paren_open"&&o.adjacent&&rn(t))throw new b("feature","((","arithmetic evaluation (`((\u2026))`) is not supported");if(t.words.length===1&&t.assigns.length===0&&t.redirs.length===0&&o?.kind==="paren_close"){t.define=Ll(e,t.words.pop(),Rt);return}if(!rn(t))throw new Error("unexpected `(`");e.i++,t.group=Rt(e,")"),t.isolate=!0}function rg(e,t,n,r){let o=e.value;if(Ml.has(o))throw new b("feature",o,Ml.get(o));if(Q0.has(o))throw new Error(`syntax error near unexpected token \`${o}\``);if(!J0.has(o))return!1;if(t.i++,o==="!"){if(n.stages.length>0||r.redirs.length>0)throw new Error("syntax error near unexpected token `!`");return n.negate=!n.negate,n.bang=!0,!0}if(o==="{")return Ke(t),r.group=Rt(t,"}"),r.isolate=!1,!0;if(o==="}")throw new Error("syntax error near unexpected token `}`");if(o==="done")throw new Error("unexpected `done`");if(o==="do")throw new Error("unexpected `do`");return o==="if"?r.conditional=Il(t,Rt):r.loop=o==="for"?Tl(t,Rt):Fl(t,o,Rt),!0}var og={")":"empty subshell `()`","}":"empty group `{ }`"},ig=(e,t)=>t==="do"?`${e.loop}: empty condition`:t==="done"?`${e.loop}: empty loop body`:t==="then"?"if: empty condition":"if: empty branch body";function Dl(e,t,n,r){let o=t.at(-1),i=rn(n)&&n.redirs.length===0&&o.stages.length===0;if(i&&t.length===1)throw new Error(og[r]??ig(e,r));if(i&&o.bang)throw new Error("syntax error near unexpected token after `!`");return i&&o.gate==="seq"?t.pop():Li(e,o,n),t}var sg=new Set(["/dev/null","/dev/stdout","/dev/stderr"]);function ug(e){let t=e.raw[e.i++],n=Fn(t);if(e.syntaxOnly){if(!["dup","close"].includes(t.op)){let u=ke(e,e.i++);if(!u||u.kind!=="word")throw new Error(`redirect \`${n}\` requires a target`)}return t}if(t.fd>2)throw new b("feature",n,`only file descriptors 0, 1 and 2 are supported (got \`${n}\`)`);if(t.op==="dup"){if(t.fd===0&&t.toFd===0)return null;if(t.fd===0||t.toFd===0)throw new b("feature",n,`duplicating file descriptor 0 (\`${n}\`) is not supported`);return{fd:t.fd,op:"dup",toFd:t.toFd}}if(t.op==="close"){if(t.fd===0)throw new b("feature","0<&-","closing standard input is not supported");return{fd:t.fd,op:"close"}}let r=ke(e,e.i++);if(!r||r.kind!=="word")throw new Error(`redirect \`${n}\` requires a target`);if(t.op==="heredoc"||t.op==="herestring"||t.op==="read"){if(t.fd!==0)throw new b("feature",n,`reading into file descriptor ${t.fd} (\`${n}\`) is not supported`);return t.op==="heredoc"?{fd:0,op:"text",body:t.body??"",expand:!t.quotedDelim}:{fd:0,op:t.op,word:xe(r)}}if(t.fd===0)throw new b("feature",n,`writing to file descriptor 0 (\`${n}\`) is not supported`);let o=t.op==="both"||t.op==="bothAppend",i=t.op==="append"||t.op==="bothAppend",s=xe(r);if(ag(s))return{fd:t.fd,op:"to",word:s,both:o,append:i,label:n};if(!e.writable&&!sg.has(s.value))throw Ri(n,s.value,e.writable);return{fd:t.fd,op:"to",target:s.value,both:o,append:i,label:n}}function ag(e){for(let t=0;t<e.value.length;t++){let n=e.value[t],r=e.mask===null?"0":e.mask[t];if((n==="$"||n==="`")&&r!=="1"||r==="0"&&(/[~*?[{]/u.test(n)||(n==="<"||n===">")&&e.value[t+1]==="("))return!0}return!1}function Ri(e,t,n){let r=n?"only `/tmp/` is writable":"the filesystem is read-only";return new b("feature",e,`\`${e}\` cannot write to \`${t}\`: ${r}`)}var lg=/^[a-zA-Z0-9][\w.+-]*$/u,Mi=["run","pipe","hidden"],Pi=["stdout","stderr","exitCode"];function ql(e,t){let n={__proto__:null},r=[],o=[];for(let[i,s]of fg(e)){let{run:u,pipe:a,hidden:l}=cg(i,s,t);l&&r.includes(i)||(n[i]=(f,c,d)=>dg(i,u,f,c,d),!l&&(r.push(i),a&&o.push(i)))}return{handlers:n,names:r,pipeNames:o}}function fg(e){if(e==null)return[];if(Array.isArray(e))throw new TypeError("createTerminal: opts.commands must be an object or a Map (got an array)");if(typeof e!="object")throw new TypeError(`createTerminal: opts.commands must be an object or a Map (got ${typeof e})`);if(typeof e.entries=="function")return[...e.entries()];let t=Object.getPrototypeOf(e);if(t!==Object.prototype&&t!==null)throw new TypeError("createTerminal: opts.commands must be a plain object or a Map (own enumerable properties only)");return Object.entries(e)}function cg(e,t,n){if(typeof e!="string")throw new TypeError(`createTerminal: command names must be strings (got ${typeof e})`);if(!lg.test(e))throw new Error(`createTerminal: invalid command name: ${JSON.stringify(e)}`);if(n(e))throw new Error(`createTerminal: ${e}: cannot redefine a built-in command`);if(typeof t=="function"){for(let o of Object.keys(t))if(Mi.includes(o))throw new Error(`createTerminal: ${e}: \`${o}\` belongs on a { run } descriptor, not on the handler function`);return{run:t,pipe:!1,hidden:!1}}if(t===null||typeof t!="object")throw new TypeError(`createTerminal: ${e}: expected a function or a { run } object`);let r=t.run;if(typeof r!="function")throw new TypeError(`createTerminal: ${e}: \`run\` must be a function`);for(let o of Object.keys(t))if(!Mi.includes(o))throw new Error(`createTerminal: ${e}: unknown option \`${o}\` (known: ${Mi.join(", ")})`);return{run:r,pipe:!!t.pipe,hidden:!!t.hidden}}function dg(e,t,n,r,o){o.io?.bufferOutput(),q(o);let i={cwd:o.cwd,fs:o.fs,mount:o.mount,home:o.home,get notes(){return o.notes},command:e,stdinFile:o.stdinFile,stdinOrigin:o.stdinOrigin},s=!0,u=()=>{s=!1},a={name:e,args:r,stdin:n,cwd:i.cwd,fs:pg(i),readInputs:(f=[])=>{if(typeof f=="string")throw new TypeError(`readInputs: expected an array of paths, got a string: ${f}`);return te(e,[...f],n,i)},run:f=>{if(!s)throw new Error("run: the command this belongs to has finished, and its turn with it");return o.runLine(f)}},l=t(a);return typeof l?.then!="function"?(u(),Wl(l)):l.then(Wl).finally(u)}function pg(e){let t=n=>E(e.cwd,n,e.fs).path;return{resolve:n=>Z(e.cwd,n),isFile:n=>e.fs.isFile(t(n)),isDir:n=>e.fs.isDir(t(n)),isLink:n=>e.fs.isLink?.(E(e.cwd,n,e.fs,{follow:!1}).path)===!0,readLink:n=>e.fs.readLink?.(E(e.cwd,n,e.fs,{follow:!1}).path),readFile:n=>e.fs.readFile(t(n)),isBytes:n=>e.fs.isBytes?.(t(n))===!0,readBytes:n=>Be(e.fs,t(n))?.slice(),listDir:n=>{let{path:r,error:o}=P(e,e.command,n);if(!e.fs.isDir(r))throw new Error(`${n}: ${o??"Not a directory"}`);let{dirs:i,files:s,links:u=[]}=e.fs.listDir(r);return{dirs:[...i],files:[...s],links:[...u]}},walkFiles:n=>[...e.fs.walkFiles(t(n))]}}function Wl(e){if(e==null)return F();if(typeof e=="string")return F(e);if(typeof e!="object")throw new TypeError(`invalid result: expected a string or an object (got ${typeof e})`);if(Array.isArray(e))throw new TypeError("invalid result: expected a string or an object, got an array (join the lines first)");let t=Object.keys(e);for(let i of t)if(!Pi.includes(i))throw new TypeError(`invalid result: unknown field \`${i}\` (known: ${Pi.join(", ")})`);if(t.length===0)throw new TypeError(`invalid result: an object with none of ${Pi.join(", ")} \u2014 return a string for plain output`);let{stdout:n="",stderr:r="",exitCode:o=0}=e;if(typeof n!="string")throw new TypeError(`invalid result: stdout must be a string (got ${typeof n})`);if(typeof r!="string")throw new TypeError(`invalid result: stderr must be a string (got ${typeof r})`);if(!Number.isInteger(o)||o<0)throw new TypeError(`invalid result: exitCode must be a non-negative integer (got ${o})`);return{stdout:n,stderr:r===""||r.endsWith(`
31
31
  `)?r:r+`
32
- `,exitCode:i}}function E(e,t={}){let n=Nn(t.short),r=Nn(t.long),i=Nn(t.valueShort),o=Nn(t.valueLong),s=Nn(t.repeatable),u=new Set,a=new Map,l=[],c=[],f=0;function d(p,m,h=!1){let g=(h?"--":"-")+p,x=(h?o:i).has(p)||s.has(p)&&(!h||p.length>1);if(x){let b=m??e[++f];if(m===null&&f>=e.length)throw new Error(g+" requires an argument");if(s.has(p)){let S=a.get(p);S?S.push(b):a.set(p,[b])}else a.set(p,b);c.push({name:p,value:b})}else{if(!(h?r:n).has(p))throw new w("option",g,"unknown option: "+g);if(h&&m!==null)throw new Error("option "+g+" doesn't allow an argument");u.add(p),c.push({name:p})}return x}for(;f<e.length;f++){let p=e[f];if(p==="--"){l.push(...e.slice(f+1));break}if(p.startsWith("--")&&p.length>2){let m=p.indexOf("=");d(m===-1?p.slice(2):p.slice(2,m),m===-1?null:p.slice(m+1),!0);continue}if(p.startsWith("-")&&p.length>1&&!(t.numericOperands&&pg(p,n,i,s))){for(let m=1;m<p.length&&!d(p[m],m+1<p.length?p.slice(m+1):null);m++);continue}if(t.stopAtFirstPositional){l.push(...e.slice(f));break}l.push(p)}return{flags:u,values:a,positional:l,order:c}}function pg(e,t,n,r){if(!/^-\d/u.test(e))return!1;let i=e[1];return!t.has(i)&&!n.has(i)&&!r.has(i)}function Nn(e){return e instanceof Set?e:new Set(e??[])}function Sr(e,t,n,r,i){let o=Ta(e,i.skip,i.skipFlag,0),s=Ta(e,i.len,i.lenFlag,Number.POSITIVE_INFINITY);if(o.error||s.error)return{error:o.error??s.error};let u=s.value,a=o.value,l=0,c=n,f=[],d={stderr:"",failed:!1};for(let h of t.length?t:[null]){let g=te(e,h===null?[]:[h],c,r,{noRead:u===0&&a===0}),x=g.entries[0]?.kind==="dir";if(d.stderr+=g.stderr,d.failed||=g.failed&&!(e==="hexdump"&&x),a&&x)return{error:v("feature",e,"skip across unreadable input",`${e}: skipping across a directory operand is not supported`)};if(x&&e==="xxd")return{error:y(d.stderr,2)};if(!g.inputs.length&&!x)continue;let b=g.inputs[0],S=b&&(b.shared||b.name===null);if(e==="hexdump"&&a&&S&&!r.stdinFile)return z(r,c),{error:y("hexdump: standard input: Illegal seek")};let A=S&&r.stdinFile&&i.skip!==void 0&&(e==="xxd"||e==="hexdump"&&o.value>0),V=I(A?r.stdinOrigin:b?.content??""),q=Math.min(a,V.length);a-=q,l+=q;let T=Math.min(u,V.length-q);if(f.push(V.subarray(q,q+T)),u-=T,S&&(c=M(V.subarray(q+T)),z(r,c)),A&&a&&(l=o.value,a=0),u===0&&a===0)break}if(a&&i.skipPastEofErrors)return{error:y(d.stderr+`${e}: cannot skip past end of combined input`)};let p=new Uint8Array(f.reduce((h,g)=>h+g.length,0)),m=0;for(let h of f)p.set(h,m),m+=h.length;return{bytes:p,start:l,r:d}}function Ta(e,t,n,r){if(t===void 0)return{value:r};if(e==="xxd"&&!/^(?:0[xX][\da-fA-F]+|0[0-7]*|[1-9]\d*)$/u.test(t))return{error:v("feature",e,`${n} ${t}`,`xxd: this offset/count spelling is not supported: ${t}`)};if(e==="hexdump")return/^[ \t\n\r\v\f]*[+\d-]/u.test(t)?!/^\d+$/u.test(t)||/^0\d/u.test(t)?{error:v("feature",e,`${n} ${t}`,`hexdump: this offset/count spelling is not supported: ${t}`)}:BigInt(t)>BigInt(Number.MAX_SAFE_INTEGER)?{error:v("feature",e,"large byte count","hexdump: counts beyond exact integer precision are not supported")}:{value:Number(t)}:{error:y(`${e}: ${n}: invalid count: ${t}`)};let i=/^[ \t\n\r\v\f]*\+?(0[xX][\da-fA-F]+|0[0-7]*|[1-9]\d*)(b|[kKMGTPEZYRQ](?:i?B)?)?$/u.exec(t);if(!i)return{error:y(`${e}: ${n}: invalid count: ${t}`)};let o=/^0\d/u.test(i[1])?"0o"+i[1].slice(1):i[1];return Di(BigInt(o),i[2],`${e}: ${n}`,t)}var Er=16,hg=47,mg=39;function Ra(e,t,n){let{flags:r,values:i,positional:o}=E(t,{short:["C","v"],valueShort:["n","s"]});if(o.includes("-"))return v("feature","hexdump","hyphen input operand","hexdump: a hyphen input operand is not supported; omit operands to read stdin");let s=Sr("hexdump",o,e,n,{skip:i.get("s"),len:i.get("n"),skipFlag:"-s",lenFlag:"-n"});return s.error?s.error:ue(ro(s.bytes,s.start,r.has("v"),r.has("C")?wg:gg),s.r)}function Ma(e,t,n){let{flags:r,values:i,positional:o}=E(t,{short:["v"],valueShort:["j","N"]});if(!r.size&&!i.size&&(o.length===1&&/^\+\d/u.test(o[0])||o.length===2&&/^\+?\d/u.test(o[1])))return v("feature","od","legacy offset operand","od: legacy offset operands are not supported; use -j OFFSET");let s=Sr("od",o,e,n,{skip:i.get("j"),len:i.get("N"),skipFlag:"-j",lenFlag:"-N",skipPastEofErrors:!0});return s.error?s.error:ue(ro(s.bytes,s.start,r.has("v"),xg),s.r)}function Pa(e,t,n){let{values:r,positional:i}=E(t,{valueShort:["s","l"]});if(i.length>2)return y("xxd: too many operands");if(i.length===2&&i[1]!=="-")return v("feature","xxd","output file","xxd: output files are not supported (filesystem is read-only)");let o=Sr("xxd",i.slice(0,1),e,n,{skip:r.get("s"),len:r.get("l"),skipFlag:"-s",lenFlag:"-l"});return o.error?o.error:ue(ro(o.bytes,o.start,!1,yg),o.r)}function ro(e,t,n,r){let i=[],o=null,s=!1;for(let a=0;a<e.length;a+=Er){let l=e.subarray(a,a+Er);r.compress&&!n&&o!==null&&l.length===Er&&kg(l,o)?s||(i.push("*"),s=!0):(i.push(r.row(t+a,l)),s=!1),o=l}let u=t+e.length;return(r.trailer==="always"||r.trailer==="nonzero"&&u>0)&&i.push(r.addr(u)),ce(i)}var gg={compress:!0,trailer:"nonzero",addr:_a,row:(e,t)=>(_a(e)+" "+Da(t).map(Sg).join(" ")).padEnd(hg)},wg={compress:!0,trailer:"nonzero",addr:io,row:bg},xg={compress:!0,trailer:"always",addr:La,row:(e,t)=>La(e)+" "+Da(t).map(Eg).join(" ")},yg={compress:!1,trailer:"never",row:(e,t)=>`${io(e)}: ${vg(t).join(" ").padEnd(mg)} ${Ua(t)}`};function _a(e){return e.toString(16).padStart(7,"0")}function io(e){return e.toString(16).padStart(8,"0")}function La(e){return e.toString(8).padStart(7,"0")}function bg(e,t){let n=[];for(let o=0;o<Er;o++)n.push(o<t.length?no(t[o]):" ");let r=n.slice(0,8).join(" "),i=n.slice(8).join(" ");return`${io(e)} ${r} ${i} |${Ua(t)}|`}function Da(e){let t=[];for(let n=0;n<e.length;n+=2)t.push(n+1<e.length?e[n]|e[n+1]<<8:e[n]);return t}function vg(e){let t=[];for(let n=0;n<e.length;n+=2)t.push(no(e[n])+(n+1<e.length?no(e[n+1]):""));return t}function Ua(e){let t="";for(let n of e)t+=n>=32&&n<=126?String.fromCodePoint(n):".";return t}function kg(e,t){return e.length===t.length&&e.every((n,r)=>n===t[r])}var no=e=>e.toString(16).padStart(2,"0"),Sg=e=>e.toString(16).padStart(4,"0"),Eg=e=>e.toString(8).padStart(6,"0");function Ba(e){if(Object.keys(e).length>0)throw new TypeError("Unexpected extra options")}var c$=Object.getPrototypeOf(Uint8Array);var za=globalThis.atob,qa=Uint8Array.prototype.toBase64,Wa=8192,$g=qa&&za;function oo(e,t=0,n=e.length){t|=0,n|=0;let r=n-t;if(r===0)return"";if($g&&r>=256&&r<1e8&&e.toBase64===qa&&e.BYTES_PER_ELEMENT===1){let o=t===0&&n===e.length?e:e.subarray(t,n);return za(o.toBase64())}if(r>Wa){let o="";for(let s=t;s<n;){let u=Math.min(n,s+Wa);o+=String.fromCharCode.apply(String,e.subarray(s,u)),s=u}return o}let i=t===0&&n===e.length?e:e.subarray(t,n);return String.fromCharCode.apply(String,i)}var ja=pn?e=>e.byteLength>=768&&!Ou?pn.from(e.buffer,e.byteOffset,e.byteLength).latin1Slice(0,e.byteLength):Be.decode(e):Ti?e=>Ti.decode(e):e=>oo(e instanceof Uint8Array?e:new Uint8Array(e.buffer,e.byteOffset,e.byteLength));var Ha=e=>Fi(e,new Uint8Array(e.length)),Ng=hn&&Ue?.encodeInto,Ga=Ng?(e,t)=>{let n=new Uint8Array(e.length+4),r=Ue.encodeInto(e,n);if(r.read!==e.length||r.written!==e.length)throw new SyntaxError(t);return n.subarray(0,e.length)}:pn?(e,t)=>{let n=pn.from(e,"utf8");if(n.length!==e.length)throw new SyntaxError(t);return new Uint8Array(n.buffer,n.byteOffset,n.byteLength)}:(e,t)=>{let n=Ue.encode(e);if(n.length!==e.length)throw new SyntaxError(t);return n};var lo={};Vh(lo,{E_CHAR:()=>qt,E_LAST:()=>so,E_LENGTH:()=>Ja,E_PADDING:()=>Ka,fromBase64:()=>ao,toBase64:()=>uo});var Xa=[..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"],Za=[..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"],Va={},Ya={},qt="Invalid character in base64 input",Ka="Invalid base64 padding",Ja="Invalid base64 length",so="Invalid last chunk";function uo(e,t,n){let r=e.length/3|0,i=r*3,o="",s=0,u=t?Za:Xa,a=t?Ya:Va;if(!a.pairs)if(a.pairs=[],Be){a.codepairs=new Uint16Array(4096);let m=a.codepairs,h=new Uint8Array(m.buffer,m.byteOffset,m.byteLength);for(let g=0;g<64;g++){let x=u[g].charCodeAt(0);for(let b=0;b<64;b++)h[g<<7|b<<1]=h[b<<7|(g<<1)+1]=x}}else{let m=a.pairs;for(let h=0;h<64;h++)for(let g=0;g<64;g++)m.push(`${u[h]}${u[g]}`)}let{pairs:l,codepairs:c}=a;if(Be){let m=new Uint16Array(r*2),h=0;for(let g=e.length-11;s<g;s+=12,h+=8){let x=e[s],b=e[s+1],S=e[s+2],A=e[s+3],V=e[s+4],q=e[s+5],T=e[s+6],Y=e[s+7],Ie=e[s+8],X=e[s+9],ve=e[s+10],Xh=e[s+11];m[h]=c[x<<4|b>>4],m[h+1]=c[(b&15)<<8|S],m[h+2]=c[A<<4|V>>4],m[h+3]=c[(V&15)<<8|q],m[h+4]=c[T<<4|Y>>4],m[h+5]=c[(Y&15)<<8|Ie],m[h+6]=c[X<<4|ve>>4],m[h+7]=c[(ve&15)<<8|Xh]}for(let g=e.length-2;s<g;s+=3,h+=2){let x=e[s],b=e[s+1],S=e[s+2];m[h]=c[x<<4|b>>4],m[h+1]=c[(b&15)<<8|S]}o=ja(m)}else for(;s<i;s+=3){let m=e[s],h=e[s+1],g=e[s+2];o+=l[m<<4|h>>4],o+=l[(h&15)<<8|g]}let f=0,d=2,p=e.length;for(;s<p;s++){let m=e[s];o+=u[f|m>>d],d===6&&(d=0,o+=u[m&63]),f=m<<6-d&63,d+=2}return d!==2&&(o+=u[f]),n&&(o+=["","==","="][p-i]),o}var Ag=Ue?128:65536;function ao(e,t){let n=e.length;for(;e[n-1]==="=";)n--;let r=e.length-n,i=n%4,o=n-i;if(i===1)throw new SyntaxError(Ja);if(r>3||r!==0&&e.length%4!==0)throw new SyntaxError(Ka);let s=t?Za:Xa,u=t?Ya:Va;u.fromMap||(u.fromMap=new Int8Array(Ag).fill(-1),s.forEach((m,h)=>u.fromMap[m.charCodeAt(0)]=h));let a=u.fromMap,l=new Uint8Array(Math.floor(n*3/4)),c=0,f=0;if(Ue){let m=Ga(e,qt);for(;f<o;f+=4){let h=m[f],g=m[f+1],x=m[f+2],b=m[f+3],S=a[h]<<18|a[g]<<12|a[x]<<6|a[b];if(S<0)throw new SyntaxError(qt);l[c]=S>>16,l[c+1]=S>>8&255,l[c+2]=S&255,c+=3}}else for(;f<o;f+=4){let m=e.charCodeAt(f),h=e.charCodeAt(f+1),g=e.charCodeAt(f+2),x=e.charCodeAt(f+3),b=a[m]<<18|a[h]<<12|a[g]<<6|a[x];if(b<0)throw new SyntaxError(qt);l[c]=b>>16,l[c+1]=b>>8&255,l[c+2]=b&255,c+=3}if(i<2)return l;let d=a[e.charCodeAt(f++)]<<6|a[e.charCodeAt(f++)];if(d<0)throw new SyntaxError(qt);if(l[c++]=d>>4,i<3){if(d&15)throw new SyntaxError(so);return l}let p=a[e.charCodeAt(f++)];if(p<0)throw new SyntaxError(qt);if(l[c++]=d<<4&255|p>>2,p&3)throw new SyntaxError(so);return l}var{Buffer:It,atob:nl,btoa:rl}=globalThis,il=It&&!It.TYPED_ARRAY_SUPPORT,{toBase64:Qa}=Uint8Array.prototype,{E_CHAR:An,E_PADDING:$r,E_LENGTH:Ig,E_LAST:Og}=lo,Cg=rl&&hn,Fg=nl&&hn,Tg=e=>e.constructor===It&&It.isBuffer(e),_g=e=>Tg(e)?e:It.from(e.buffer,e.byteOffset,e.byteLength);function co(e,t){if(t)return e;let n=e.indexOf("=",e.length-3);return n===-1?e:e.slice(0,n)}function Lg(e,t){return t&&e.length%4!==0?e+"=".repeat(4-e.length%4):e}var Rg=e=>Qa&&e.toBase64===Qa;function fo(e,{padding:t=!0}={}){return dr(e),Rg(e)?t?e.toBase64():e.toBase64({omitPadding:!t}):il?co(_g(e).base64Slice(0,e.byteLength),t):Cg?co(rl(oo(e)),t):uo(e,!1,t)}function po(e,t){if(typeof t=="string"&&(t={format:t}),!t)return el(e,!1,"both","uint8",null);let{format:n="uint8",padding:r="both",...i}=t;return el(e,!1,r,n,i)}function el(e,t,n,r,i){if(typeof e!="string")throw new TypeError(pr);i!==null&&Ba(i);let o=n==="both"?e.endsWith("="):void 0;if(n===!0||o===!0){if(e.length%4!==0)throw new SyntaxError($r);if(e[e.length-3]==="=")throw new SyntaxError($r)}else if(n===!1||o===!1){if(e.length%4===1)throw new SyntaxError(Ig);if(n===!1&&e.endsWith("="))throw new SyntaxError("Did not expect padding in base64 input")}else throw new TypeError("Invalid padding option");return In(e,t,n,r)}var Mg=/[\t\n\f\r ]/;function tl(e,t){let n=e.indexOf("=",e.length-3),r=n>=0?e.length-n:0,i=e.length-r,o=i%4,s=t.length-(i-o)/4*3;return o===0&&s===0||o===2&&s===1||o===3&&s===2}var In;Uint8Array.fromBase64?In=(e,t,n,r)=>{let i=t?"base64url":"base64",o;if(n===!0)o=Uint8Array.fromBase64(e,{alphabet:i,lastChunkHandling:"strict"});else try{let s=e.length%4>0?`${e}${"=".repeat(4-e.length%4)}`:e;o=Uint8Array.fromBase64(s,{alphabet:i,lastChunkHandling:"strict"})}catch(s){throw Mg.test(e)?new SyntaxError(An):s}if(!tl(e,o))throw new SyntaxError(An);return bt(o,r)}:il?In=(e,t,n,r)=>{let i=It.byteLength(e,"base64"),o=It.allocUnsafeSlow(i);if(o.base64Write(e)!==i)throw new SyntaxError($r);let s=t?co(e,n===!1):Lg(e,n!==!0),u=t?o.base64urlSlice(0,o.length):o.base64Slice(0,o.length);if(s!==u)throw new SyntaxError($r);return Cu(o,r)}:Fg?In=(e,t,n,r)=>{let i;if(t){if(/[\t\n\f\r +/]/.test(e))throw new SyntaxError(An);e=e.replaceAll("-","+").replaceAll("_","/")}try{i=Ha(nl(e))}catch{throw new SyntaxError(An)}if(!t&&!tl(e,i))throw new SyntaxError(An);if(i.length%3!==0){let o=fo(i.subarray(-(i.length%3))),s=e.length%4===0?e.slice(-4):e.slice(-(e.length%4)).padEnd(4,"=");if(o!==s)throw new SyntaxError(Og)}return bt(i,r)}:In=(e,t,n,r)=>bt(ao(e,t),r);var ho="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Pg=76;function ol(e,t,n){let{flags:r,positional:i,order:o}=E(t,{short:["d","i"],long:["decode","ignore-garbage"],valueShort:["w"],valueLong:["wrap"]}),s=Pg;for(let{name:f,value:d}of o){if(f!=="w"&&f!=="wrap")continue;if(!/^[ \t\n\r\f\v]*[+-]?\d+$/u.test(d)||BigInt(d)<0n)return y(`base64: invalid wrap size: ${d}`);let p=BigInt(d);s=p>J?0:Number(p)}if(i.length>1)return y(`base64: extra operand: ${i[1]}`);let u=te("base64",i,e,n);if(u.failed)return y(u.stderr);let a=u.inputs[0].content;if(r.has("d")||r.has("decode"))return Dg(a,r.has("i")||r.has("ignore-garbage"));let l=fo(ee(a));if(!s||l==="")return C(l);let c=[];for(let f=0;f<l.length;f+=s)c.push(l.slice(f,f+s));return C(c.join(`
32
+ `,exitCode:o}}function N(e,t={}){let n=Mn(t.short),r=Mn(t.long),o=Mn(t.valueShort),i=Mn(t.valueLong),s=Mn(t.repeatable),u=new Set,a=new Map,l=[],f=[],c=0;function d(p,h,m=!1){let g=(m?"--":"-")+p,w=(m?i:o).has(p)||s.has(p)&&(!m||p.length>1);if(w){let y=h??e[++c];if(h===null&&c>=e.length)throw new Error(g+" requires an argument");if(s.has(p)){let k=a.get(p);k?k.push(y):a.set(p,[y])}else a.set(p,y);f.push({name:p,value:y})}else{if(!(m?r:n).has(p))throw new b("option",g,"unknown option: "+g);if(m&&h!==null)throw new Error("option "+g+" doesn't allow an argument");u.add(p),f.push({name:p})}return w}for(;c<e.length;c++){let p=e[c];if(p==="--"){l.push(...e.slice(c+1));break}if(p.startsWith("--")&&p.length>2){let h=p.indexOf("=");d(h===-1?p.slice(2):p.slice(2,h),h===-1?null:p.slice(h+1),!0);continue}if(p.startsWith("-")&&p.length>1&&!(t.numericOperands&&hg(p,n,o,s))){for(let h=1;h<p.length&&!d(p[h],h+1<p.length?p.slice(h+1):null);h++);continue}if(t.stopAtFirstPositional){l.push(...e.slice(c));break}l.push(p)}return{flags:u,values:a,positional:l,order:f}}function hg(e,t,n,r){if(!/^-\d/u.test(e))return!1;let o=e[1];return!t.has(o)&&!n.has(o)&&!r.has(o)}function Mn(e){return e instanceof Set?e:new Set(e??[])}function mg(e){try{return typeof DecompressionStream=="function"&&!!new DecompressionStream(e)}catch{return!1}}function gg(e){try{return typeof CompressionStream=="function"&&!!new CompressionStream(e)}catch{return!1}}var zr=e=>mg(e)&&gg(e);async function zl(e,t){let{readable:n,writable:r}=e,o=r.getWriter(),i=(async()=>{try{await o.write(t),await o.close()}catch{}})(),s=n.getReader(),u=[],a=null;try{for(;;){let{done:c,value:d}=await s.read();if(c)break;u.push(d)}}catch(c){a=c?.cause?.message??c?.message??"corrupt input"}await i;let l=new Uint8Array(u.reduce((c,d)=>c+d.length,0)),f=0;for(let c of u)l.set(c,f),f+=c.length;return{bytes:l,error:a}}var Hr=(e,t)=>zl(new DecompressionStream(t),e),Pn=async(e,t)=>(await zl(new CompressionStream(t),e)).bytes;var Di="brotli",Gr=".br",Gl=zr(Di)?{brotli:yg}:{},Xl="con",Zl=Object.freeze(["0","1","2","3","4","5","6","7","8","9"]),wg=`Usage: brotli [OPTION]... [FILE]...
33
+ `;async function yg(e,t,n){let{flags:r,values:o,positional:i}=N(t,{short:[...Zl,"d","c","k","j","f","Z"],long:["decompress","stdout","keep","rm","force","best"],valueShort:["q"],valueLong:["quality"]}),s=bg(r,o);if(s!==void 0)return v("option","brotli",s,`brotli: ${s}: choosing a compression level is not supported`,1);let u={decompressing:r.has("d")||r.has("decompress"),stdout:r.has("c")||r.has("stdout"),remove:r.has("j")||r.has("rm"),force:r.has("f")||r.has("force")};if(u.stdout&&i.length>1)return{stdout:wg,stderr:"",exitCode:1};let a={ctx:n,events:[],stderr:"",status:0,gap:null};for(let f of i.length===0?["-"]:i)if(!await xg(f,e,u,a))break;if(a.gap)return a.gap;let l=[...a.events,...a.stderr?[{fd:2,text:a.stderr}]:[]];return{stdout:"",stderr:a.stderr,exitCode:a.status,events:l}}function bg(e,t){let n=[...Zl,"Z"].find(r=>e.has(r));return n!==void 0?"-"+n:e.has("best")?"--best":t.has("q")?"-q":t.has("quality")?"--quality":void 0}function xg(e,t,n,r){let{ctx:o}=r;if(e==="-"){let u=o.stdinBytes,a=o.stdinLeft;return q(o,"",!0),Hl(u??B(a),Xl,null,n,r)}let i=null;if(!n.stdout)if(!n.decompressing)i=e+Gr;else{if(e.length<=Gr.length)return Mt(r,`empty output file name for [${e}] input file`);if(e.endsWith(Gr))i=e.slice(0,-Gr.length);else return Mt(r,`input file [${e}] suffix mismatch`)}let s=P(o,"brotli",e);return s.error?Mt(r,`failed to open input file [${e}]: ${s.error}`):i!==null&&!n.force&&P(o,"brotli",i).error===null?Mt(r,`failed to open output file [${i}]: File exists`):o.fs.isDir(s.path)?Mt(r,`failed to read input [${e}]: Is a directory`):Hl(Be(o.fs,s.path),e,i,n,r)}async function Hl(e,t,n,r,o){let{ctx:i}=o,s=r.decompressing?await Hr(e,Di):{bytes:await Pn(e,Di),error:null};if(s.error)return Mt(o,`corrupt input [${t}]`);if(n===null)o.events.push({fd:1,bytes:s.bytes});else if(!kg(n,s.bytes,o))return!1;return r.remove&&t!==Xl&&i.fs.removeWritable(i.cwd,t),!0}function kg(e,t,n){let{ctx:r}=n,o;try{o=r.writable&&r.fs.openWritable?.(r.cwd,e)}catch(i){return Mt(n,`failed to open output file [${e}]: ${i.message}`)}return o?(o.writeBytes(t),!0):(n.gap??=v("feature","brotli","read-only target",`brotli: ${e}: file system is read-only`,1),!1)}function Mt(e,t){return e.stderr+=`${t}
34
+ `,e.status=1,!1}var Xr="gzip",vg=(e,t,n)=>Ui(e,["-d",...t],n),Yl=(e,t,n)=>Ui(e,["-d","-c",...t],n),Jl=zr(Xr)?{gzip:Ui,gunzip:vg,zcat:Yl,gzcat:Yl}:{},Vl=Object.freeze([31,139]),Sg=e=>e!==void 0&&e.length>=2&&e[0]===Vl[0]&&e[1]===Vl[1],Eg={__proto__:null,"unexpected end of file":"unexpected end of file","incorrect data check":"invalid compressed data--crc error"},$g=e=>Eg[e]??"invalid compressed data--format violated",Ql=Object.freeze({__proto__:null,".gz":"",".tgz":".tar",".taz":".tar","-gz":"",".z":"","-z":"",_z:""}),Ng=".gz",Kl=Object.freeze(["1","2","3","4","5","6","7","8","9"]);async function Ui(e,t,n){let{flags:r,positional:o}=N(t,{short:[...Kl,"d","c","k"],long:["decompress","uncompress","stdout","to-stdout","keep"]}),i=Kl.find(l=>r.has(l));if(i!==void 0)return v("option","gzip",`-${i}`,`gzip: -${i}: choosing a compression level is not supported`,1);let s={decompressing:["d","decompress","uncompress"].some(l=>r.has(l)),stdout:["c","stdout","to-stdout"].some(l=>r.has(l)),keep:r.has("k")||r.has("keep")},u={ctx:n,events:[],stderr:"",status:0,gap:null};if(o.length===0)await Ag(e,s,u);else for(let l of o)await Og(l,s,u);if(u.gap)return u.gap;let a=[...u.events,...u.stderr?[{fd:2,text:u.stderr}]:[]];return{stdout:"",stderr:u.stderr,exitCode:u.status,events:a}}async function Ag(e,t,n){let r=n.ctx.stdinBytes;return q(n.ctx,"",!0),t.decompressing&&r!==null?ef("stdin",r,{...t,stdout:!0},n):t.decompressing?Bi(n,e===""?"stdin: unexpected end of file":"stdin: not in gzip format"):ji(await Pn(r??B(e),Xr),n)}function Og(e,t,n){let{ctx:r}=n,o=P(r,"gzip",e);return o.error?Pt(n,`${e}: ${o.error}`,1):r.fs.isDir(o.path)?Pt(n,`${e} is a directory -- ignored`,2):t.decompressing?Lg(e,o.path,t,n):Cg(e,o.path,t,n)}async function Cg(e,t,n,r){let{ctx:o}=r,i=tf(e);if(!n.stdout&&i!==void 0)return Rg(r,`${e} already has ${i} suffix -- unchanged`);let s=Fg(await Pn(Be(o.fs,t),Xr),e.slice(e.lastIndexOf("/")+1),Ig(o));return n.stdout?ji(s,r):nf(e+Ng,s,e,n,r)}var Ig=e=>Math.floor(e.createdAt/1e3),Dn=10,Tg=8;function Fg(e,t,n){let r=B(t);if(e.length<Dn||e[3]!==0||r.includes(0))return e;let o=new Uint8Array(e.length+r.length+1);o.set(e.subarray(0,Dn)),o[3]=Tg;for(let i=0;i<4;i++)o[4+i]=n>>>8*i&255;return o.set(r,Dn),o.set(e.subarray(Dn),Dn+r.length+1),o}function Lg(e,t,n,r){let{ctx:o}=r,i=o.fs.isBytes?.(t)===!0?Be(o.fs,t):void 0;return ef(e,i,n,r,t)}async function ef(e,t,n,r,o=null){let{ctx:i}=r;if(!Sg(t))return Bi(r,`${e}: ${_g(t,o,i)?"unexpected end of file":"not in gzip format"}`);let s=await Hr(t,Xr),u=tf(e);(n.stdout?ji(s.bytes,r):u===void 0?Pt(r,`${e}: unknown suffix -- ignored`,2):nf(e.slice(0,-u.length)+Ql[u],s.bytes,e,n,r))&&s.error&&Bi(r,`${e}: ${$g(s.error)}`)}var tf=e=>Object.keys(Ql).find(t=>e.length>t.length&&e.endsWith(t));function _g(e,t,n){if(e!==void 0)return e.length<2;let r=n.fs.readFile(t);return r.length<2&&A(r).length<2}var ji=(e,t)=>(t.events.push({fd:1,bytes:e}),!0);function nf(e,t,n,r,o){let{ctx:i}=o;if(P(i,"gzip",e).error===null)return Pt(o,`${e} already exists; not overwritten`,2);let s;try{s=i.writable&&i.fs.openWritable?.(i.cwd,e)}catch(u){return Pt(o,`${e}: ${u.message}`,1)}return s?(s.writeBytes(t),r.keep||i.fs.removeWritable(i.cwd,n),!0):(o.gap??=v("feature","gzip","read-only target",`gzip: ${e}: file system is read-only`,1),!1)}var Bi=(e,t)=>Pt(e,t,1,`
35
+ `),Rg=(e,t)=>Pt(e,t,e.status);function Pt(e,t,n,r=""){return e.stderr+=`${r}gzip: ${t}
36
+ `,e.status=e.status===1?1:n,!1}var Mg=Object.freeze({__proto__:null,1:"SHA-1",256:"SHA-256",384:"SHA-384",512:"SHA-512"}),Pg=Object.freeze(["1","224","256","384","512","512224","512256"]),Dg=()=>{try{return typeof crypto?.subtle?.digest=="function"}catch{return!1}};async function Bg(e,t){let n=new Uint8Array(await crypto.subtle.digest(e,t));return Array.from(n,r=>r.toString(16).padStart(2,"0")).join("")}function Ug(e,t,n){let r=e==="shasum"?n.get("a")??"1":String(t);if(e==="shasum"&&!Pg.includes(r))return{error:x(`${e}: Unrecognized algorithm
37
+ Type shasum -h for help
38
+ `,1)};let o=Mg[r];return o===void 0?{error:v("feature",e,`SHA-${r}`,`${e}: this runtime's crypto does not digest SHA-${r}`,1)}:{algorithm:o}}function Bn(e,t){return async(n,r,o)=>{let{flags:i,order:s,positional:u,values:a}=N(r,{short:e==="shasum"?["b","t","c"]:["b","t","c","z"],long:e==="shasum"?["binary","text","check","tag"]:["binary","text","check","tag","zero"],valueShort:e==="shasum"?["a"]:[]});if(i.has("c")||i.has("check"))return v("feature",e,"-c",`${e}: reading a list of digests back is not supported`,1);let{algorithm:l,error:f}=Ug(e,t,a);if(f)return f;let{mode:c,error:d}=zg(e,i,s);if(d)return d;let p=te(e,u,n,o,{read:"bytes"}),h=await Promise.all(p.inputs.map(g=>Bg(l,g.bytes))),m=Hg(l,i,c);return ne(p.inputs.map((g,w)=>m(h[w],g.name??"-")).join(""),p)}}var jg=new Set(["b","binary"]),Wg=new Set(["t","text"]);function qg(e,t){let n=!1,r=null,o=!1;for(let{name:i}of t)jg.has(i)?(n=!0,r="binary"):Wg.has(i)?(o=!0,r="text"):i==="tag"&&(r="binary");return e==="shasum"?{binary:n,text:o&&!n,ambiguous:n&&o}:{binary:r==="binary",text:r==="text",ambiguous:!1}}function zg(e,t,n){let r=qg(e,n),o=e==="shasum"?`Type ${e} -h for help
39
+ `:`Try '${e} --help' for more information.
40
+ `;return r.ambiguous?{error:x(`${e}: Ambiguous file mode
41
+ ${o}`,1)}:t.has("tag")&&r.text?{error:x(`${e}: --tag does not support --text mode
42
+ ${o}`,1)}:{mode:r}}function Hg(e,t,n){let r=t.has("z")||t.has("zero")?"\0":`
43
+ `;if(t.has("tag")){let o=e.replace("-","");return(i,s)=>`${o} (${s}) = ${i}${r}`}return(o,i)=>`${o}${n.binary?" *":" "}${i}${r}`}var rf=Dg()?{sha1sum:Bn("sha1sum",1),sha256sum:Bn("sha256sum",256),sha384sum:Bn("sha384sum",384),sha512sum:Bn("sha512sum",512),shasum:Bn("shasum",1)}:{};var of={...Jl,...Gl,...rf};var Gg=new Uint8Array;function Zr(e,t,n,r,o){let i=sf(e,o.skip,o.skipFlag,0),s=sf(e,o.len,o.lenFlag,Number.POSITIVE_INFINITY);if(i.error||s.error)return{error:i.error??s.error};let u=s.value,a=i.value,l=0,f=n,c=r.stdinBytes,d=[],p={stderr:"",failed:!1};for(let g of t.length?t:[null]){let w=te(e,g===null?[]:[g],f,r,{read:"loose-bytes",noRead:u===0&&a===0}),y=w.entries[0]?.kind==="dir";if(p.stderr+=w.stderr,p.failed||=w.failed&&!(e==="hexdump"&&y),a&&y)return{error:v("feature",e,"skip across unreadable input",`${e}: skipping across a directory operand is not supported`)};if(y&&e==="xxd")return{error:x(p.stderr,2)};if(!w.inputs.length&&!y)continue;let k=w.inputs[0],S=k&&(k.shared||k.name===null);if(e==="hexdump"&&a&&S&&!r.stdinFile)return q(r,f,!0,c),{error:x("hexdump: standard input: Illegal seek")};let I=S&&r.stdinFile&&o.skip!==void 0&&(e==="xxd"||e==="hexdump"&&i.value>0),M=I?A(r.stdinOrigin):k?.bytes??Gg,C=Math.min(a,M.length);a-=C,l+=C;let H=Math.min(u,M.length-C);if(d.push(M.subarray(C,C+H)),u-=H,S){let Y=M.subarray(C+H),D=c!==null&&!I&&Y.length>0?Y:null;f=D===null?W(Y):me(Y)??"",q(r,f,!0,D)}if(I&&a&&(l=i.value,a=0),u===0&&a===0)break}if(a&&o.skipPastEofErrors)return{error:x(p.stderr+`${e}: cannot skip past end of combined input`)};let h=new Uint8Array(d.reduce((g,w)=>g+w.length,0)),m=0;for(let g of d)h.set(g,m),m+=g.length;return{bytes:h,start:l,r:p}}function sf(e,t,n,r){if(t===void 0)return{value:r};if(e==="xxd"&&!/^(?:0[xX][\da-fA-F]+|0[0-7]*|[1-9]\d*)$/u.test(t))return{error:v("feature",e,`${n} ${t}`,`xxd: this offset/count spelling is not supported: ${t}`)};if(e==="hexdump")return/^[ \t\n\r\v\f]*[+\d-]/u.test(t)?!/^\d+$/u.test(t)||/^0\d/u.test(t)?{error:v("feature",e,`${n} ${t}`,`hexdump: this offset/count spelling is not supported: ${t}`)}:BigInt(t)>BigInt(Number.MAX_SAFE_INTEGER)?{error:v("feature",e,"large byte count","hexdump: counts beyond exact integer precision are not supported")}:{value:Number(t)}:{error:x(`${e}: ${n}: invalid count: ${t}`)};let o=/^[ \t\n\r\v\f]*\+?(0[xX][\da-fA-F]+|0[0-7]*|[1-9]\d*)(b|[kKMGTPEZYRQ](?:i?B)?)?$/u.exec(t);if(!o)return{error:x(`${e}: ${n}: invalid count: ${t}`)};let i=/^0\d/u.test(o[1])?"0o"+o[1].slice(1):o[1];return ki(BigInt(i),o[2],`${e}: ${n}`,t)}var Yr=16,Xg=47,Zg=39;function lf(e,t,n){let{flags:r,values:o,positional:i}=N(t,{short:["C","v"],valueShort:["n","s"]});if(i.includes("-"))return v("feature","hexdump","hyphen input operand","hexdump: a hyphen input operand is not supported; omit operands to read stdin");let s=Zr("hexdump",i,e,n,{skip:o.get("s"),len:o.get("n"),skipFlag:"-s",lenFlag:"-n"});return s.error?s.error:ne(qi(s.bytes,s.start,r.has("v"),r.has("C")?Vg:Yg),s.r)}function ff(e,t,n){let{flags:r,values:o,positional:i}=N(t,{short:["v"],valueShort:["j","N"]});if(!r.size&&!o.size&&(i.length===1&&/^\+\d/u.test(i[0])||i.length===2&&/^\+?\d/u.test(i[1])))return v("feature","od","legacy offset operand","od: legacy offset operands are not supported; use -j OFFSET");let s=Zr("od",i,e,n,{skip:o.get("j"),len:o.get("N"),skipFlag:"-j",lenFlag:"-N",skipPastEofErrors:!0});return s.error?s.error:ne(qi(s.bytes,s.start,r.has("v"),Kg),s.r)}function cf(e,t,n){let{values:r,positional:o}=N(t,{valueShort:["s","l"]});if(o.length>2)return x("xxd: too many operands");if(o.length===2&&o[1]!=="-")return v("feature","xxd","output file","xxd: output files are not supported (filesystem is read-only)");let i=Zr("xxd",o.slice(0,1),e,n,{skip:r.get("s"),len:r.get("l"),skipFlag:"-s",lenFlag:"-l"});return i.error?i.error:ne(qi(i.bytes,i.start,!1,Jg),i.r)}function qi(e,t,n,r){let o=[],i=null,s=!1;for(let a=0;a<e.length;a+=Yr){let l=e.subarray(a,a+Yr);r.compress&&!n&&i!==null&&l.length===Yr&&tw(l,i)?s||(o.push("*"),s=!0):(o.push(r.row(t+a,l)),s=!1),i=l}let u=t+e.length;return(r.trailer==="always"||r.trailer==="nonzero"&&u>0)&&o.push(r.addr(u)),ge(o)}var Yg={compress:!0,trailer:"nonzero",addr:uf,row:(e,t)=>(uf(e)+" "+df(t).map(nw).join(" ")).padEnd(Xg)},Vg={compress:!0,trailer:"nonzero",addr:zi,row:Qg},Kg={compress:!0,trailer:"always",addr:af,row:(e,t)=>af(e)+" "+df(t).map(rw).join(" ")},Jg={compress:!1,trailer:"never",row:(e,t)=>`${zi(e)}: ${ew(t).join(" ").padEnd(Zg)} ${pf(t)}`};function uf(e){return e.toString(16).padStart(7,"0")}function zi(e){return e.toString(16).padStart(8,"0")}function af(e){return e.toString(8).padStart(7,"0")}function Qg(e,t){let n=[];for(let i=0;i<Yr;i++)n.push(i<t.length?Wi(t[i]):" ");let r=n.slice(0,8).join(" "),o=n.slice(8).join(" ");return`${zi(e)} ${r} ${o} |${pf(t)}|`}function df(e){let t=[];for(let n=0;n<e.length;n+=2)t.push(n+1<e.length?e[n]|e[n+1]<<8:e[n]);return t}function ew(e){let t=[];for(let n=0;n<e.length;n+=2)t.push(Wi(e[n])+(n+1<e.length?Wi(e[n+1]):""));return t}function pf(e){let t="";for(let n of e)t+=n>=32&&n<=126?String.fromCodePoint(n):".";return t}function tw(e,t){return e.length===t.length&&e.every((n,r)=>n===t[r])}var Wi=e=>e.toString(16).padStart(2,"0"),nw=e=>e.toString(16).padStart(4,"0"),rw=e=>e.toString(8).padStart(6,"0");var ow=76;function Vr(e,{encode:t,decode:n}){return(r,o,i)=>{let{flags:s,positional:u,order:a}=N(o,{short:["d","i"],long:["decode","ignore-garbage"],valueShort:["w"],valueLong:["wrap"]}),l=ow;for(let{name:p,value:h}of a){if(p!=="w"&&p!=="wrap")continue;if(!/^[ \t\n\r\f\v]*[+-]?\d+$/u.test(h)||BigInt(h)<0n)return x(`${e}: invalid wrap size: ${h}`);let m=BigInt(h);l=m>ue?0:Number(m)}if(u.length>1)return x(`${e}: extra operand: ${u[1]}`);let f=te(e,u,r,i,{read:"as-held"});if(f.failed)return x(f.stderr);let{content:c,bytes:d}=f.inputs[0];return s.has("d")||s.has("decode")?sw(e,n(c??ui(d),s.has("i")||s.has("ignore-garbage"))):iw(t(d??B(c)),l)}}function iw(e,t){if(!t||e==="")return F(e);let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return F(n.join(`
33
44
  `)+`
34
- `)}function Dg(e,t){let{bytes:n,valid:r}=Ug(e,t),i=M(n);if(r)return C(i);let o=`base64: invalid input
35
- `;return{stdout:i,stderr:o,exitCode:1,events:[...i?[{fd:1,text:i}]:[],{fd:2,text:o}]}}function Ug(e,t=!1){let n=e.replace(t?/[^A-Za-z0-9+/=]/gu:/\n/gu,"");try{return{bytes:po(n),valid:!0}}catch(r){if(!(r instanceof SyntaxError))throw r;return Bg(n)}}function Bg(e){let t=new Uint8Array(Math.ceil(e.length/4)*3),n=/[A-Za-z0-9+/]*/uy,r=0,i=0,o=!0;for(;i<e.length;){n.lastIndex=i;let s=n.exec(e)[0].length,u=s-s%4;if(u){let m=po(e.slice(i,i+u));t.set(m,r),r+=m.length,i+=u}if(i===e.length)break;let a=s%4;if(a<2){o=!1;break}let l=ho.indexOf(e[i]),c=ho.indexOf(e[i+1]),f=a===3?ho.indexOf(e[i+2]):0;t[r++]=l<<2|c>>4,a===3&&(t[r++]=c<<4|f>>2);let d=4-a,p=(a===2?c&15:f&3)===0;if(i+=a,i===e.length){o=p;break}if(!p||e.slice(i,i+d)!=="=".repeat(d)){o=!1;break}i+=d}return{bytes:t.subarray(0,r),valid:o}}var Wg=["n","N","i","s","w","F","v","l","c","q","u","a","H","I"],zg=["line-number","no-line-number","ignore-case","case-sensitive","word-regexp","fixed-strings","invert-match","files-with-matches","files-without-match","count","quiet","hidden","no-ignore","no-heading","with-filename","no-filename","text","unrestricted"],ul={short:Wg,long:zg,valueShort:["A","B","C"],valueLong:["after-context","before-context","context"],repeatable:["e","regexp"]},qg=new Map(Object.entries({"line-number":"n","no-line-number":"N","ignore-case":"i","case-sensitive":"s","word-regexp":"w","fixed-strings":"F","invert-match":"v","files-with-matches":"l","files-without-match":"L",count:"c",quiet:"q",text:"a",unrestricted:"u","with-filename":"H","no-filename":"I",regexp:"e","after-context":"A","before-context":"B",context:"C"})),jg=new Set(["no-heading","no-ignore"]),On=(e,t)=>new w("feature",e,`rg: ${t}`);function al(e){let t={patterns:[],context:[],mode:null,showName:null,ignoreCase:!1,lineNumbers:!1,word:!1,literal:!1,invert:!1,quiet:!1,text:!1,hidden:!1,unrestricted:0};for(let{name:i,value:o}of e.order)jg.has(i)||Hg(t,qg.get(i)??i,o,mo(i));let n=i=>t.context.findLast(([o])=>o===i)?.[1],r=i=>t.context.findLast(([o])=>o===i)?.[2]??"-"+i;if(t.after=sl(n("A")??n("C"),n("A")===void 0?r("C"):r("A")),t.before=sl(n("B")??n("C"),n("B")===void 0?r("C"):r("B")),t.unrestricted>=2&&(t.hidden=!0),t.unrestricted>=3)throw On("-uuu","searching binary files is not supported");return t}function Hg(e,t,n,r){switch(t){case"i":e.ignoreCase=!0;return;case"s":e.ignoreCase=!1;return;case"n":e.lineNumbers=!0;return;case"N":e.lineNumbers=!1;return;case"l":case"L":case"c":e.mode=t;return;case"H":e.showName="H";return;case"I":e.showName="h";return;case"w":e.word=!0;return;case"F":e.literal=!0;return;case"v":e.invert=!0;return;case"q":e.quiet=!0;return;case"a":e.text=!0;return;case"e":e.patterns.push(n);return;case"hidden":e.hidden=!0;return;case"u":e.unrestricted++;return;case"A":case"B":case"C":e.context.push([t,n,r]);return;default:throw On(mo(t),`${mo(t)} is not supported`)}}function sl(e,t){if(e===void 0)return 0;if(!/^\d+$/u.test(e))throw On(`${t} value`,`error parsing flag ${t}: value is not a valid number`);return Number(e)}var mo=e=>(e.length===1?"-":"--")+e;function ll(e,t){return t?e.flatMap(n=>["-e",n]):["-e",e.length===1?e[0]:e.map(n=>`(?:${n})`).join("|")]}var Gg=[[/\\[1-9]/u,"backreference"],[/\(\?<?[=!]/u,"look-around"],[/\\[QE]/u,String.raw`\Q…\E literal span`]];function Xg(e){for(let t=0;t<e.length;t++){let n=e[t];if(n===`
36
- `)return!0;if(n!=="\\")continue;let r=e[t+1];if(r==="n"||r==="x"&&/^x\{?0*a\}?/iu.test(e.slice(t+1)))return!0;t++}return!1}function cl(e,t){if(!t)for(let n of e){for(let[r,i]of Gg)if(r.test(n))throw On(i,`${i} is not supported; ripgrep's regex engine rejects it too`);if(Xg(n))throw On("newline in a pattern","a newline in a pattern is not supported; ripgrep rejects one outside multiline mode")}}var k=class extends Error{constructor(t,n=null,r=null){super(t),this.line=n,this.gap=r}},fl=new Set(["BEGIN","END","BEGINFILE","ENDFILE","function","func","if","else","while","for","do","break","continue","next","nextfile","exit","return","delete","in","getline","print","printf","switch","case","default"]),go={__proto__:null,length:[0,1],substr:[2,3],index:[2,2],split:[2,3],sub:[2,3],gsub:[2,3],gensub:[3,4],match:[2,3],sprintf:[1,1/0],sin:[1,1],cos:[1,1],atan2:[2,2],exp:[1,1],log:[1,1],sqrt:[1,1],int:[1,1],rand:[0,0],srand:[0,1],tolower:[1,1],toupper:[1,1],close:[1,2],fflush:[0,1],systime:[0,0],strtonum:[1,1],and:[2,1/0],or:[2,1/0],xor:[2,1/0],lshift:[2,2],rshift:[2,2],compl:[1,1],typeof:[1,1],isarray:[1,1]},Nr=new Map([["system","system() is not supported: this terminal runs no processes"],["strftime","strftime() is not supported (gawk extension)"],["mktime","mktime() is not supported (gawk extension)"],["asort","asort() is not supported (gawk extension)"],["asorti","asorti() is not supported (gawk extension)"],["patsplit","patsplit() is not supported (gawk extension)"]]),dl=new Set([...Object.keys(go),...Nr.keys()]),Cn=5e6,wo=100,ye=1e6,Ar="this terminal runs no processes";function Ir(e,t,n){switch(e){case"+":return t+n;case"-":return t-n;case"*":return t*n;case"/":return t/n;case"%":return t%n;default:return t**n}}var Fn={__proto__:null,alpha:"A-Za-z",digit:"0-9",alnum:"0-9A-Za-z",upper:"A-Z",lower:"a-z",space:" \\t\\n\\v\\f\\r",blank:" \\t",punct:"!-\\/:-@\\[-`{-~",xdigit:"0-9A-Fa-f",cntrl:"\\x00-\\x1F\\x7F",print:"\\x20-\\x7E",graph:"\\x21-\\x7E",word:"0-9A-Za-z_"},jt={__proto__:null};for(let[e,t]of Object.entries(Fn)){let n=new RegExp(`[${t}]`,"u"),r=[];for(let i=0;i<128;i++){if(!n.test(String.fromCodePoint(i)))continue;let o=r.at(-1);o&&o[1]===i-1?o[1]=i:r.push([i,i])}jt[e]=r}var Or=32767;function pl(e,t){if(e>Or||t!==void 0&&t>Or)throw new Error("Regular expression too big")}function hl(e,t){let n=t+1;e[n]==="^"&&n++;let r=!0,i=!1;for(;n<e.length;){let o=e[n];if(o==="]"&&!r)return n;if(r=!1,o==="["&&":.=".includes(e[n+1]??"")){let a=e[n+1],l=e.indexOf(a+"]",n+2);if(l===-1)throw new Error("Unmatched [, [^, [:, [., or [=");if(a===":"&&!(e.slice(n+2,l)in Fn))throw new Error("Invalid character class name");n=l+2,i=a!==".";continue}if(o==="-"&&i&&n+1<e.length&&e[n+1]!=="]")throw new Error("Invalid range end");let s=o==="\\"&&n+1<e.length?2:1;if(e[n+s]==="-"&&e[n+s+1]!==void 0&&e[n+s+1]!=="]"){let a=n+s+1,l=e[a]==="["?e[a+1]:void 0;if(l===":"||l==="=")throw new Error("Invalid range end");let c=l==="."?e.indexOf(".]",a+2):-1;if(l==="."&&c===-1)throw new Error("Unmatched [, [^, [:, [., or [=");n=c===-1?a+(e[a]==="\\"?2:1):c+2,i=!0;continue}n+=s,i=!1}throw new Error("Unmatched [, [^, [:, [., or [=")}function Ht(e,t,n={}){let r=/^\[:([a-z]+):\]/u.exec(e.slice(t));if(!r)return null;let i=Fn[r[1]];if(i===void 0){if(n?.unknown!=="empty")throw new Error(`invalid character class \`[:${r[1]}:]\``);return{body:"",end:t+r[0].length}}return{body:i,end:t+r[0].length}}var ml={__proto__:null,n:10,t:9,r:13,f:12,v:11,a:7,b:8},Zg='^$.[]|()*+?{}\\/"',xo=1e3,gl=e=>e!==void 0&&/[0-9a-fA-F]/u.test(e),wl=e=>e!==void 0&&e>="0"&&e<="7",yo=class{constructor(t,n){this.src=t,this.i=0,this.warn=n,this.groups=0}fail(t){throw new k(`invalid regex /${this.src}/: ${t}`)}peek(){return this.src[this.i]}literal(){let t=this.src.codePointAt(this.i);return this.i+=St(t),{type:"char",code:t}}parse(){return this.alternation(0)}alternation(t){let n=[this.concatenation(t)];for(;this.peek()==="|";)this.i++,n.push(this.concatenation(t));return n.length===1?n[0]:{type:"alt",nodes:n}}concatenation(t){let n=[];for(;!this.endsConcatenation(t);)n.push(this.quantified(this.atom(n.length===0,t)));return n.length===1?n[0]:{type:"cat",nodes:n}}endsConcatenation(t){let n=this.peek();return n===void 0||n==="|"||n===")"&&t>0}quantified(t){let n=t;for(;;){let r=this.peek();if(r==="*"){this.i++,n={type:"rep",node:n,min:0,max:null};continue}if(r==="+"){this.i++,n={type:"rep",node:n,min:1,max:null};continue}if(r==="?"){this.i++,n={type:"rep",node:n,min:0,max:1};continue}if(r==="{"){let i=/^\{(\d*)(?:(,)(\d*))?\}/u.exec(this.src.slice(this.i));if(!i&&/^\{[\d,]*\}/u.test(this.src.slice(this.i))&&this.fail("invalid content of {}"),!i||i[1]===""&&i[2]===void 0)return n;let o=i[1]===""?0:Number(i[1]),s=i[2]===void 0?o:i[3]===""?null:Number(i[3]);if(s!==null&&s<o&&this.fail(`invalid interval {${o},${s}}`),o>xo||s!==null&&s>xo)throw new k(`interval count above ${xo} is not supported`,null,"regex interval limit");this.i+=i[0].length,n={type:"rep",node:n,min:o,max:s};continue}return n}}atom(t,n){let r=this.peek();if(r==="("){this.i++;let i=++this.groups,o=this.alternation(n+1);return this.peek()!==")"&&this.fail("missing `)`"),this.i++,{type:"group",index:i,node:o}}return r==="["?this.bracket():r==="\\"?this.escape():(this.i++,r==="."?{type:"any"}:r==="^"||r==="$"?{type:"assert",kind:r}:((r==="*"||r==="+"||r==="?")&&!t&&this.fail(`unexpected \`${r}\``),this.i--,this.literal()))}escape(){this.i++;let t=this.peek();return t===void 0&&this.fail("trailing backslash"),this.i++,t==="y"?{type:"assert",kind:"y"}:t==="<"||t===">"||t==="B"?{type:"assert",kind:t}:t==="`"?{type:"assert",kind:"^"}:t==="'"?{type:"assert",kind:"$"}:t==="s"||t==="S"?{type:"set",negate:t==="S",items:jt.space}:t==="w"||t==="W"?{type:"set",negate:t==="W",items:jt.word}:(t==="b"&&this.warn?.("regexp escape sequence `\\b' is a backspace here, as in gawk; `\\y' is the word boundary"),{type:"char",code:this.escapedCode(t,!0)})}escapedCode(t,n){if(t in ml)return ml[t];if(wl(t)){let i=t;for(;i.length<3&&wl(this.peek());)i+=this.src[this.i++];return xl(i,8)}if(t==="x"&&gl(this.peek())){let i="";for(;i.length<2&&gl(this.peek());)i+=this.src[this.i++];return xl(i,16)}let r=this.src.codePointAt(this.i-1);return!Zg.includes(t)&&n&&this.warn?.(`regexp escape sequence \`\\${String.fromCodePoint(r)}' is not a known regexp operator`),this.i+=St(r)-1,r}bracket(){this.i++;let t=!1;this.peek()==="^"&&(t=!0,this.i++);let n=[],r=!0;for(;;){this.i>=this.src.length&&this.fail("unterminated bracket expression");let i=this.peek();if(i==="]"&&!r){this.i++;break}if(r=!1,i==="["&&this.src[this.i+1]===":"){let s=this.src.indexOf(":]",this.i+2);if(s!==-1){let u=this.src.slice(this.i+2,s);u in jt||this.fail(`invalid character class \`[:${u}:]\``),n.push(...jt[u]),this.i=s+2;continue}}let o=this.bracketChar();if(this.peek()==="-"&&this.src[this.i+1]!=="]"&&this.src[this.i+1]!==void 0){this.i++;let s=this.bracketChar();s<o&&this.fail("invalid range end"),n.push([o,s])}else n.push([o,o])}return{type:"set",negate:t,items:n}}bracketChar(){let t=this.peek();if(t==="["&&(this.src[this.i+1]==="."||this.src[this.i+1]==="=")){let r=this.src.indexOf(this.src[this.i+1]+"]",this.i+2);if(r!==-1&&r>this.i+2){Array.from(this.src.slice(this.i+2,r)).length!==1&&this.fail("invalid collation character");let i=this.src.codePointAt(this.i+2);return this.i=r+2,i}}if(t==="\\"){this.i++,this.peek()===void 0&&this.fail("trailing backslash");let r=this.src[this.i++];return this.escapedCode(r,!1)}let n=this.src.codePointAt(this.i);return this.i+=St(n),n}};function Xt(e,t=null){let n=new yo(e,t);return{ast:n.parse(),groups:n.groups}}function xl(e,t){let n=Number.parseInt(e,t);if(n>=128)throw new k("non-ASCII regex byte escapes are not supported",null,"regex byte escapes");return n}var Vg=e=>`\\u{${e.toString(16)}}`,Cr=e=>e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122?String.fromCodePoint(e):Vg(e),Yg={__proto__:null,"^":"^",$:"$",y:"\\b",B:"\\B","<":"(?<!\\w)(?=\\w)",">":"(?<=\\w)(?!\\w)"};function Gt(e){switch(e.type){case"char":return Cr(e.code);case"any":return".";case"set":return`[${e.negate?"^":""}${e.items.map(([t,n])=>t===n?Cr(t):`${Cr(t)}-${Cr(n)}`).join("")}]`;case"assert":return Yg[e.kind];case"group":return`(${Gt(e.node)})`;case"cat":return e.nodes.map(Gt).join("");case"alt":return`(?:${e.nodes.map(Gt).join("|")})`;case"rep":{let t=`(?:${Gt(e.node)})`;return e.max===null?e.min===0?`${t}*`:e.min===1?`${t}+`:`${t}{${e.min},}`:e.min===0&&e.max===1?`${t}?`:`${t}{${e.min},${e.max}}`}default:throw new k(`internal: unknown regex node ${e.type}`)}}var Kg=5e4,yl=e=>e>=48&&e<=57||e>=65&&e<=90||e===95||e>=97&&e<=122;function bl(e){let t=String.fromCodePoint(e);return[e,t.toLowerCase().codePointAt(0),t.toUpperCase().codePointAt(0)]}function Jg(e,t,n){let r=o=>{for(let s=0;s<e.length;s++)if(o>=e[s][0]&&o<=e[s][1])return!0;return!1};if(!n)return t?o=>!r(o):r;let i=o=>bl(o).some(r);return t?o=>!i(o):i}function vl(e,t){let n=[],r=l=>{if(n.length>=Kg)throw new k("regex too large",null,"regex state limit");return n.push(l),n.length-1};function i(l,c){switch(l.type){case"char":return r({op:"char",codes:t?bl(l.code):[l.code],next:c});case"any":return r({op:"any",next:c});case"set":return r({op:"set",test:Jg(l.items,l.negate,t),next:c});case"assert":return r({op:"assert",kind:l.kind,next:c});case"group":return i(l.node,c);case"cat":{let f=c;for(let d=l.nodes.length-1;d>=0;d--)f=i(l.nodes[d],f);return f}case"alt":{let f=l.nodes.map(p=>i(p,c)),d=f.at(-1);for(let p=f.length-2;p>=0;p--)d=r({op:"split",x:f[p],y:d});return d}case"rep":return o(l,c);default:throw new k(`internal: unknown regex node ${l.type}`)}}function o(l,c){let f=c;if(l.max===null){let d=r({op:"split",x:-1,y:c});n[d].x=i(l.node,d),f=d}else for(let d=l.max-l.min;d>0;d--)f=r({op:"split",x:i(l.node,f),y:c});for(let d=0;d<l.min;d++)f=i(l.node,f);return f}let s=i(e,r({op:"match"})),u="",a=s;for(;n[a].op==="char"&&n[a].codes.length===1&&n[a].codes[0]<128;)u+=String.fromCodePoint(n[a].codes[0]),a=n[a].next;return(n[a].op!=="match"||u==="")&&(u=null),{states:n,start:s,literal:u,gen:new Int32Array(n.length).fill(-1),stamp:0}}function Qg(e,t){if(t<=0)return-1;let n=e.codePointAt(t-1);return n>=56320&&n<=57343&&t>=2?e.codePointAt(t-2):n}function ew(e,t,n){if(e==="^")return n===0;if(e==="$")return n===t.length;let r=yl(Qg(t,n)),i=n<t.length&&yl(t.codePointAt(n));return e==="y"?r!==i:e==="B"?r===i:e==="<"?!r&&i:r&&!i}function tw(e,t){return e.op==="char"?e.codes.includes(t):e.op==="any"?!0:e.test(t)}function kl(e,t,n){if(e.literal!==null&&Number.isInteger(n)&&n>=0&&n<=t.length&&!Object.is(n,-0)){let p=t.indexOf(e.literal,n);return p<0?null:{start:p,end:p+e.literal.length}}let{states:r,gen:i}=e,o=t.length,s=[],u=(p,m,h,g,x)=>{for(s.push(m);s.length>0;){let b=s.pop();if(i[b]===x)continue;i[b]=x;let S=r[b];S.op==="split"?s.push(S.y,S.x):S.op==="assert"?ew(S.kind,t,g)&&s.push(S.next):p.push(b,h)}},a=[],l=[],c=null,f=n,d=++e.stamp;for(;;){c===null&&u(a,e.start,f,f,d);let p=f<o?t.codePointAt(f):-1,m=St(p);if(a.length===0){if(c!==null||f>=o)break;f+=m,d=++e.stamp;continue}let h=++e.stamp;for(let g=0;g<a.length;g+=2){let x=a[g],b=a[g+1];if(c!==null&&b>c.start)continue;let S=r[x];if(S.op==="match"){(c===null||b<c.start||b===c.start&&f>c.end)&&(c={start:b,end:f});continue}p!==-1&&tw(S,p)&&u(l,S.next,b,f+m,h)}if(a.length=0,[a,l]=[l,a],d=h,f>=o)break;f+=m}return c}var Fr=new Map,Sl=/[\u0080-\u{10FFFF}]/u,Qe=class{constructor(t,n,r){let{ast:i,groups:o}=Xt(t,r);this.src=t,this.ignoreCase=n,this.groupCount=o,this.source=Gt(i),this.flags=n?"siu":"su";try{this.js=new RegExp(this.source,this.flags)}catch(s){throw new k(`cannot compile regex /${t}/: ${s.message}`,null,"regex engine limit")}this.ast=i,this.nfa=null,this.capture=null,this.captureShape=El(i)}test(t){return this.checkLocale(t),this.js.test(t)}checkLocale(t){if(this.src.includes("[:")&&Sl.test(t))throw new k("POSIX character classes on non-ASCII input require locale support",null,"locale-sensitive character classes");if((this.ignoreCase||/\\[sSwWyB<>]/u.test(this.src))&&Sl.test(t+this.src))throw new k("non-ASCII case folding, classes and word boundaries require locale support",null,"locale-sensitive regex")}search(t,n=0){return this.checkLocale(t),this.nfa===null&&(this.nfa=vl(this.ast,this.ignoreCase)),kl(this.nfa,t,n)}groups(t,n,r){if(this.captureShape.unsafe)throw new k("capture extraction across repeated or alternative groups is not supported",null,"regex capture semantics");let i=this.capture??=new RegExp(this.source,this.flags+"dy");i.lastIndex=n;let o=i.exec(t);if(!o||o.index!==n||n+o[0].length!==r){let s=Array.from(t.slice(r)).length,u=new RegExp(`(?:${this.source})(?=.{${s}}(?![^]))`,this.flags+"dy");u.lastIndex=n,o=u.exec(t)}if(!o)throw new k("capture extraction for this match is not supported",null,"regex capture semantics");return o.indices.map((s,u)=>s===void 0?void 0:{text:o[u],start:s[0],end:s[1]})}};function El(e){let n=(e.nodes??(e.node?[e.node]:[])).map(El),r=n.reduce((s,u)=>s+u.groups,e.type==="group"?1:0),i=e.type==="assert"||(e.type==="group"||e.type==="cat")&&n.every(s=>s.nullable)||e.type==="alt"&&n.some(s=>s.nullable)||e.type==="rep"&&(e.min===0||n[0].nullable),o=e.type==="rep"&&(e.max===null||e.max>1)&&(r>1||r>0&&n[0].nullable);return{groups:r,nullable:i,unsafe:o||e.type==="alt"&&r>0||n.some(s=>s.unsafe)}}function Ee(e,t=!1,n=null){let r=(t?"i":"c")+e,i=Fr.get(r);if(i)return i;Fr.size>=500&&Fr.clear();let o=new Qe(e,t,n);return Fr.set(r,o),o}function bo(e,t,n){for(;;){let r=t.search(e,n);if(!r||r.start!==r.end)return r;if(r.end>=e.length)return null;n=r.end+ke(e,r.end)}}function vo(e,t){let n=[],r=0;for(;;){let i=bo(e,t,r);if(!i)break;n.push(e.slice(r,i.start)),r=i.end}return n.push(e.slice(r)),n}function Tn(e,t,n,r){let i=r!=="first",o=e.length,s="",u=0,a=-1,l=0;for(;u<=o;){let c=t.search(e,u);if(!c)break;let f=c.start===c.end;if(f&&c.start===a&&r!=="nth"){if(c.start>=o)break;let p=ke(e,c.start);s+=e.slice(u,c.start+p),u=c.start+p;continue}l++;let d=n(c.start,c.end,l);if(s+=e.slice(u,c.start)+(d===null?e.slice(c.start,c.end):d),a=c.end,f){if(c.end>=o){u=o;break}let p=ke(e,c.end);s+=e.slice(c.end,c.end+p),u=c.end+p}else u=c.end;if(!i)break}return{out:s+e.slice(u),count:l}}function Tr(e){let t="(){}+?|",n=!1,r=0,i=!1,o="";for(let s=0;s<e.length;s++){let u=e[s];if(i){if(u==="["&&(e[s+1]==="."||e[s+1]==="="))throw new w("feature","regex collating or equivalence class","grep: collating and equivalence classes are not supported");if(u==="["){let a=Ht(e,s);if(a){o+=a.body,s=a.end-1;continue}}o+=u,u==="]"&&(i=!1,n=!0);continue}if(u==="["){o+=u,i=!0,e[s+1]==="^"&&(o+="^",s++),e[s+1]==="]"&&(o+="\\]",s++);continue}if(u==="\\"){let a=e[++s];if(a===void 0)return{error:"trailing backslash (\\)"};if(t.includes(a)){if((a==="+"||a==="?")&&!n){o+="\\"+a,n=!0;continue}if(a==="("&&r++,a===")"&&r--===0)return{error:"Unmatched ) or \\)"};(a==="("||a==="|")&&(n=!1),(a===")"||a==="}")&&(n=!0),o+=a}else o+="^$\\.*[]/bBsSwW<>`'123456789".includes(a)?"\\"+a:a,n=!"bB<>`'".includes(a);continue}if(u==="*"){o+=n?"*":"\\*",n=!0;continue}if(u==="^"){n=!nw(e,s),o+=n?"\\^":"^";continue}if(u==="$"){n=!(s===e.length-1||e[s+1]==="\\"&&(e[s+2]===")"||e[s+2]==="|")),o+=n?"\\$":"$";continue}o+=t.includes(u)?"\\"+u:u,n=!0}return r>0?{error:"Unmatched ( or \\("}:{source:o}}function nw(e,t){if(t===0)return!0;if(t<2||e[t-2]!=="\\"||e[t-1]!=="("&&e[t-1]!=="|")return!1;let n=0;for(let r=t-3;r>=0&&e[r]==="\\";r--)n++;return n%2===0}function _r(e){if(!/\\[1-9]/u.test(e))return!1;let t=new Set,n=[],r=new Set,i=!1,o=0,s=!1,u=[],a=new Set,l=!1;for(let c=0;c<e.length;c++){let f=e[c];if(f==="\\"){let d=e[++c];if(!i&&/[1-9]/u.test(d??"")){let p=Number(d);if(!t.has(p))throw new Error("Invalid back reference");(!a.has(p)||r.has(p))&&(s=!0)}u=[];continue}if(i){f==="]"&&(i=!1);continue}if(f==="["){i=!0,u=[];continue}if(f==="(")n.push({id:++o,entry:new Set(a),branches:[],start:c}),u=[];else if(f==="|"){let d=n.at(-1);d&&d.branches.push(a),a=new Set(d?.entry),u=[]}else if(f===")"){let d=n.pop();if(!d)continue;a=d.branches.reduce((p,m)=>p.intersection(m),a),a.add(d.id),t.add(d.id),u=[...a.difference(d.entry)],l=rw(e.slice(d.start,c+1))}else if(f==="*"||f==="?"||f==="+"){if(f!=="?"&&l)for(let d of u)r.add(d);if(f!=="+")for(let d of u)a.delete(d)}else if(f==="{"){let d=/^\{(\d*)(?:,(\d*))?\}/u.exec(e.slice(c));if(d){Number(d[1])===0&&(a=a.difference(new Set(u)));let p=d[2]===void 0?Number(d[1]):d[2]===""?1/0:Number(d[2]);l&&p>1&&u.forEach(m=>r.add(m)),c+=d[0].length-1}else u=[]}else u=[]}return s}function rw(e){try{return new RegExp(`^(?:${e})$`,"su").test("")}catch{return!0}}var iw=e=>e.type==="set"&&e.items.every(([,t])=>t<128),ow=e=>e?.type==="char"&&e.code<128;function ko(e){return ow(e)||e.type==="any"||iw(e)?!0:e.type==="assert"?e.kind==="^"||e.kind==="$":e.type==="group"||e.type==="rep"?ko(e.node):e.type==="alt"||e.type==="cat"?e.nodes.every(ko):!1}function Lr(e,t){if([...t.matchAll(/\[:([a-z]+):\]/gu)].map(r=>r[1]).some(r=>r!=="space"&&r!=="blank")||/[\u0080-\u{10FFFF}]|\\[1-9bBwW<>]/u.test(t))return!1;try{return ko(Xt(e).ast)}catch{return!1}}function Rr(e){return/[\u0085\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000]/u.test(e)}function be(e){throw new w("feature","PCRE "+e,`PCRE ${e} is not supported`)}function $l(e){let t={captures:0,closed:new Set,names:new Map,stack:[],behind:0,references:!1,risky:!1},n="";for(let r=0;r<e.length;){let i=e[r];if(i==="\\"){let o=Nl(e,r,t,!1);n+=o.source,r=o.end;continue}if(i==="["){let o=aw(e,r,t);n+=o.source,r=o.end;continue}if(i==="("){let o=sw(e,r,t);n+=o.source,r=o.end;continue}if(i===")"){let o=t.stack.pop();o?.capture&&t.closed.add(o.capture),o?.behind&&t.behind--}if("*+?".includes(i)&&(t.behind&&be("variable-length lookbehind"),e[r+1]==="+"&&be("possessive repetition"),i!=="+"&&(t.risky=!0)),i==="|"&&(t.risky=!0),i==="{"){let o=uw(e,r,t);n+=o.source,r=o.end;continue}n+=i==="]"||i==="}"?"\\"+i:i,r++}return t.references&&t.risky&&be("conditional backreference"),n}function sw(e,t,n){let r=!1,i=null,o="(";if(e[t+1]==="*"&&be("control verb"),e[t+1]==="?"){let s=/^\(\?(?:[:=!]|<[=!]|<([A-Za-z_]\w*)>)/u.exec(e.slice(t));if(s||be("group"),o=s[0],r=o==="(?<="||o==="(?<!",!s[1]&&o!=="(?:"&&(n.risky=!0),s[1]){if(i=++n.captures,n.names.has(s[1]))throw new Error("duplicate PCRE capture name");n.names.set(s[1],i)}}else i=++n.captures;return r&&n.behind++,n.stack.push({capture:i,behind:r}),{source:o,end:t+o.length}}function uw(e,t,n){let r=/^\{(\d+)(?:,(\d*))?\}/u.exec(e.slice(t));if(!r)return/^\{[\d, \t]*\}/u.test(e.slice(t))&&be("repetition"),{source:"\\{",end:t+1};if(n.behind&&r[2]!==void 0&&r[1]!==r[2]&&be("variable-length lookbehind"),Number(r[1])>65535||Number(r[2])>65535)throw new Error("PCRE repetition count exceeds 65535");return Number(r[1])===0&&(n.risky=!0),e[t+r[0].length]==="+"&&be("possessive repetition"),{source:r[0],end:t+r[0].length}}function aw(e,t,n){let r=t+1,i="[";for(e[r]==="^"&&(i+="^",r++),e[r]==="]"&&(i+="\\]",r++);r<e.length&&e[r]!=="]";)if(e[r]==="["&&":.=".includes(e[r+1]??"")&&be("character class"),e[r]==="\\"){let o=Nl(e,r,n,!0);i+=o.source,r=o.end}else i+=e[r]==="["?"\\[":e[r],r++;return{source:i+(e[r]==="]"?"]":""),end:r+1}}function Nl(e,t,n,r){let i=e[t+1];if(i===void 0)throw new Error("trailing backslash");if(i==="Q"){let s=e.indexOf("\\E",t+2);return{source:RegExp.escape(e.slice(t+2,s<0?void 0:s)),end:s<0?e.length:s+2}}if(i==="E")return{source:"",end:t+2};if(i==="x"||i==="0"||r&&/[1-7]/u.test(i))return lw(e,t);if(i==="a"||i==="e")return{source:i==="a"?"\\u0007":"\\u001B",end:t+2};if("AzZ".includes(i)&&!r)return{source:i==="A"?"^":"$",end:t+2};if(/[1-9]/u.test(i)&&!r)return(/\d/u.test(e[t+2]??"")||!n.closed.has(Number(i)))&&be("forward or ambiguous backreference"),n.references=!0,{source:"\\"+i,end:t+2};if(i==="k"&&!r){let s=/^\\k<([A-Za-z_]\w*)>/u.exec(e.slice(t));return(!s||!n.closed.has(n.names.get(s[1])))&&be("named backreference"),n.references=!0,{source:s[0],end:t+s[0].length}}if("dDsSwWfnrtbB".includes(i))return{source:"\\"+i,end:t+2};/[A-Za-z0-9]/u.test(i)&&be("escape \\"+i);let o=String.fromCodePoint(e.codePointAt(t+1));return{source:RegExp.escape(o),end:t+1+o.length}}function lw(e,t){let n=e[t+1]==="x",r=(n?/^\\x(?:\{([\da-fA-F]+)\}|([\da-fA-F]{1,2}))/u:/^\\([0-7]{1,3})/u).exec(e.slice(t));if(!r)throw new Error("invalid PCRE character escape");let i=n?16:8,o=parseInt(r[1]??r[2],i);return ze(o)||be("character escape"),{source:`\\u{${o.toString(16)}}`,end:t+r[0].length}}function Eo(e){let t="",n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(i==="\\"){let o=e[++r]??"";t+=n?i+o:cw(o);continue}if(n&&i==="["){if(e[r+1]==="."||e[r+1]==="=")throw new w("feature","regex collating or equivalence class","grep: collating and equivalence classes are not supported");let o=Ht(e,r);if(o){t+=o.body,r=o.end-1;continue}}if(i==="["&&!n){t+="[",n=!0,e[r+1]==="^"&&(t+="^",r++),e[r+1]==="]"&&(t+="\\]",r++);continue}i==="]"&&(n=!1),t+=i}return t}function cw(e){return"^$\\.*+?()[]{}|/bBsSwW<>`'123456789".includes(e)?"\\"+e:RegExp.escape(e)}function fw(e){for(let t=0;t<e.length;t++)if(e[t]==="\\"){if("bBsSwW<>".includes(e[++t]??""))return!0}else if(".[*+?{".includes(e[t]))return!0;return!1}function Zt(e,t=!1){let n=t?{b:"\\y"}:{"<":"(?<!\\w)(?=\\w)",">":"(?<=\\w)(?!\\w)","`":"^","'":"$",s:"[ \\t\\n\\r\\f\\v]",S:"[^ \\t\\n\\r\\f\\v]"},r="",i=!1;for(let o=0;o<e.length;o++){let s=e[o];if(s==="\\"){let u=e[++o];r+=!i&&Object.hasOwn(n,u)?n[u]:s+u,!t&&!i&&/[1-9]/u.test(u)&&/\d/u.test(e[o+1]??"")&&(r+="(?:)")}else s==="["&&(i=!0),s==="]"&&(i=!1),r+=s}return r}var $o=/^\{(?=\d|,)(\d*)(?:,(\d*))?\}/u,dw=/^\\\{(?=\d|,)(\d*)(?:,(\d*))?\\\}/u;function Al(e,t,n){let r=(n?$o:dw).exec(e.slice(t));if(!r&&!n)throw new Error("invalid repetition count");r&&pl(Number(r[1]),r[2]===void 0||r[2]===""?void 0:Number(r[2]))}var Il={__proto__:null,"*":{min:0,max:1/0},"+":{min:1,max:1/0},"?":{min:0,max:1}};function pw(e){if(Il[e])return Il[e];let t=$o.exec(e),n=Number(t[1]);return{min:n,max:t[2]===void 0?n:t[2]===""?1/0:Number(t[2])}}var Ol=(e,t)=>e===0||t===0?0:e===1/0||t===1/0?1/0:e*t;function hw(e,t){let n=Math.max(t.min,1);if(n>t.max)return{min:0,max:0};if(e.min>0&&(t.min===0&&e.min>1||e.max!==1/0&&t.max>n&&(n+1)*e.min>n*e.max+1))return null;let r=Ol(t.max,e.max);return r!==1/0&&r>Or?null:{min:Ol(t.min,e.min),max:r}}function So(e){return e.max===1/0?e.min===0?"*":e.min===1?"+":`{${e.min},}`:e.min===0&&e.max===1?"?":e.min===e.max?`{${e.min}}`:`{${e.min},${e.max}}`}var mw=e=>!e.startsWith("(")&&!/^\\[1-9]/u.test(e);function gw(e,t){if(t.length===1)return e+So(t[0].bounds);let n=t[0].bounds,r=null;for(let i=1;i<t.length;i++){let{bounds:o,text:s}=t[i],u=r===null?hw(n,o):null;if(u){n=u;continue}if(!(r===null&&n.min===n.max&&mw(e))&&o.max>1)throw new Error("stacked quantifier needs ambiguous nesting");r=`(?:${r??e+So(n)})${s}`}return r??e+So(n)}function ww(e,t){let n=t+1;for(e[n]==="^"&&n++;n<e.length;n++){if(e[n]==="\\"){n++;continue}if(e[n]==="]")return n}return e.length-1}function xw(e){let t="",n=-1,r=-1,i=[],o=()=>{i.length>0&&(t=t.slice(0,n)+gw(t.slice(n,r),i)),i=[]},s=a=>{o(),n=t.length,r=-1,t+=a},u=[];for(let a=0;a<e.length;a++){let l=e[a];if(l==="\\"){s(l+(e[++a]??""));continue}if(l==="["){let f=ww(e,a);s(e.slice(a,f+1)),a=f;continue}if(l==="("){o(),u.push(t.length),n=-1,t+=l;continue}if(l===")"){o(),t+=l,n=u.pop()??-1,r=-1;continue}if(l==="|"||l==="^"||l==="$"){o(),t+=l,n=-1;continue}let c=l==="{"?$o.exec(e.slice(a)):null;if(l==="*"||l==="+"||l==="?"||c){let f=c?c[0]:l;if(a+=f.length-1,n<0){t+=f;continue}i.length===0&&(r=t.length),i.push({bounds:pw(f),text:f});continue}s(l)}return o(),t}function No(e,t){let n=-1;for(let r=0;r<e.length;r++){let i=r<=n,o=e[r];if(o==="\\"){let s=e[++r];if(s===void 0)throw new Error("trailing backslash");if(i||s&&"dDxXuUpPkKcC".includes(s))throw new w("feature","regex escape","grep: this regex escape is not supported with GNU semantics");!t&&s==="{"&&Al(e,r-1,!1)}else if(o==="["&&!i)n=hl(e,r);else{if(i)continue;if(t&&o==="{")Al(e,r,!0);else if(t&&o==="("&&e[r+1]==="?")throw new w("feature","regex extension","grep: ECMAScript group extensions are not supported in ERE")}}}function Cl(e,t){let n=[],r=t.has("i")?"isu":"su",i=t.has("x"),o=t.has("w")&&!i;if(t.has("P")&&new Set(e).size>1)return{error:y("grep: -P only supports a single pattern",2)};for(let s of e){!t.has("F")&&!t.has("P")&&No(s,t.has("E"));let u;if(t.has("F"))u=RegExp.escape(s);else if(t.has("P"))u=$l(s);else if(t.has("E"))u=Eo(s);else{let l=Tr(s);if(l.error)return{error:y(`grep: ${l.error}`,2)};u=l.source}let a=u;if(!t.has("F")&&!t.has("P")&&_r(a))return{error:v("feature","grep","conditional backreference","grep: backreferences with conditional or repeated-empty captures are not supported",2)};o&&(u=`(?<![A-Za-z0-9_])(?:${u})(?![A-Za-z0-9_])`),i&&(u=`^(?:${u})$`);try{let l=new RegExp(t.has("F")||t.has("P")?u:Zt(xw(u)),r);if(l.pcre=t.has("P"),l.localeSensitive=t.has("i")||o||!t.has("F")&&fw(a)||l.pcre&&/\\[dD]/u.test(a),l.asciiCompatible=!l.pcre&&l.localeSensitive&&!t.has("i")&&!o&&Lr(Zt(a,!0),s),l.spaceClass=/\[:(?:space|blank):\]|\\[sS]/u.test(s),l.unicodePattern=/[\u0080-\u{10FFFF}]/u.test(s),l.binaryLiteral=!i&&(t.has("F")||!/[\\.^$*+?()[\]{}|]/u.test(u)),t.has("o")&&!t.has("F")&&!t.has("P")&&!i){if(o||/\\[1-9]|\(\?/u.test(u))return{error:v("feature","grep","-o regex extent","grep: only-matching with backreferences, lookarounds or word constraints is not supported",2)};try{l.extent=new Qe(Zt(u,!0),t.has("i"))}catch{return{error:v("feature","grep","-o regex extent","grep: POSIX match extent for this pattern is not supported",2)}}}n.push(l)}catch(l){if(!t.has("P")&&yw(a,t))return{error:v("feature","grep","GNU regex syntax","grep: this GNU regular expression cannot be represented by the JavaScript matcher",2)};let c=t.has("F")?`fixed-string /${r}`:t.has("P")?`PCRE subset /${r}`:t.has("E")?`ERE / ECMAScript /${r}`:`BRE /${r}`;return{error:y(`grep: invalid pattern (${c}): ${l.message}`,2)}}}return{res:n}}function yw(e,t){if(!t.has("E")&&/(?<!\\)\{(?!\d*(?:,\d*)?\})/u.test(e))return!1;try{return Xt(Zt(e,!0)),!0}catch(n){return!!n.gap}}function Ao(e,t,n,r=!1,i=Ve){if(e.length===0)return null;if(!r&&e.some(l=>l.content.includes("\0")&&(n||t.some(c=>!c.binaryLiteral||c.test(l.content)))))return v("feature","grep","binary input","grep: binary input detection and output are not supported",2);let o=/[\u0080-\u{10FFFF}]/u;if(i!==Ve&&t.some(l=>l.localeSensitive)&&(t.some(l=>l.unicodePattern)||e.some(l=>o.test(l.content))))return v("feature","grep","locale",`grep: matching non-ASCII text in the ${i} locale is not supported`,2);let s=t.filter(l=>l.localeSensitive&&(!l.asciiCompatible||l.spaceClass));if(s.length===0)return null;let u=s.some(l=>!l.unicodePattern)&&e.some(l=>/[\u0080-\u{10FFFF}]/u.test(l.content)),a=s.some(l=>l.asciiCompatible&&l.spaceClass)&&e.some(l=>Rr(l.content));return s.some(l=>(u||l.unicodePattern)&&(!l.asciiCompatible||l.spaceClass&&a))?v("feature","grep","non-ASCII regex semantics","grep: locale-sensitive regular expression matching on non-ASCII input is not supported",2):null}var Io=/[*?[]/u,Oo=/\P{ASCII}/u,bw=/[.+*?^${}()|[\]\\/]/u;function $e(e,t={}){try{return vw(e,t)}catch(n){throw n instanceof w?n:new w("feature","glob pattern",`unsupported glob pattern: ${n.message}`)}}function vw(e,t){let n="^",r=!1;for(let i=0;i<e.length;i++){let o=e[i];if(o==="\\"&&i+1<e.length){let s=e[i+1];n+=Fl(s,t.ignoreCase),i++}else if(o==="*"){for(;e[i+1]==="*";)i++;n+=".*"}else if(o==="?")n+=".";else if(o==="["){let s=Tl(e,i,t);if(s?.voided)return/^(?!)$/u;s?(n+=s.source,i=s.end,r||=s.nonAsciiRange):n+="\\["}else n+=Fl(o,t.ignoreCase)}return Sw(new RegExp(n+"(?![\\s\\S])","us"),e,t,r)}function Fl(e,t){return t&&/[a-zA-Z]/u.test(e)?`[${e.toLowerCase()}${e.toUpperCase()}]`:bw.test(e)?"\\"+e:e}function kw(e,t,n){let r=new RegExp(`[${e}]`,"ui"),i=new RegExp(`[${t}]`,"u"),o="";for(let s=0;s<128;s++){let u=String.fromCodePoint(s);(r.test(u)||i.test(u))&&(o+="\\x"+s.toString(16).padStart(2,"0"))}return`[${n?"^":""}${o}]`}function Sw(e,t,n,r){let i=/[?[]/u.test(t),o=Oo.test(t);return{test(s){if(r||n.ignoreCase&&o||(i||n.ignoreCase)&&Oo.test(s))throw new w("feature","non-ASCII glob matching","locale-dependent glob matching of non-ASCII names is not supported");return e.test(s)}}}function Tl(e,t,n){let{ignoreCase:r}=n,i=t+1,o=!1;(e[i]==="!"||e[i]==="^")&&(o=!0,i++);let s="",u="",a=!1,l=!1,c=!1,f=!1,d="",p=0,m="",h=0;for(e[i]==="]"&&(s+="\\]",i++,a=!0,d="]");i<e.length&&e[i]!=="]";i++){let g=e[i];if(g==="["&&(e[i+1]==="."||e[i+1]==="="))throw new w("feature","glob collating or equivalence class","glob collating symbols and equivalence classes are not supported");if(g==="["&&e[i+1]===":"){let x=n.bash?Ew(e,i):Ht(e,i,{unknown:"empty"});if(x){if(!n.bash&&x.body==="")throw new w("feature","glob character class","unknown POSIX classes in command filename patterns are not supported");l&&(f=!0),r?u+=x.body:s+=x.body,i=x.end-1,a=!1,l=!1;continue}if(n.bash)continue}if(g==="-"&&a)h=p,m=d,s+="-",l=!0,a=!1;else{let x=g==="\\"&&i+1<e.length?e[++i]:g;p=s.length,d=x,l&&Oo.test(m+x)&&(c=!0),l&&x.codePointAt(0)<m.codePointAt(0)?s=s.slice(0,h):s+=/[\]\\^[-]/u.test(x)?`\\${x}`:x,a=!l,l=!1}}return i>=e.length?null:f?{voided:!0,end:i}:{source:r?kw(s,u,o):`[${o?"^":""}${s}]`,end:i,nonAsciiRange:c}}function Ew(e,t){let n=e.indexOf(":]",t+2);if(n===-1)return null;let r=e.slice(t+2,n).replace(/\\([\s\S]|$)/gu,"$1");return{body:r==="ascii"?"\\x00-\\x7F":Fn[r]??"",end:n+2}}function _l(e,t){return $e(t).test(e)}function Ll(e){let{value:t,mask:n}=e;if(n===null)return Io.test(t);for(let r=0;r<t.length;r++)if(n[r]==="0"&&Io.test(t[r]))return!0;return!1}function _n(e){let t=n=>!e.mask||e.mask[n]==="0";for(let n=0;n<e.value.length;n++){let r=e.value[n];if(t(n)){if(r==="\\")n++;else if(r==="[")n=$w(e,n,t);else if(/[?*+@!]/u.test(r)&&e.value[n+1]==="("&&t(n+1))return!0}}return!1}function $w(e,t,n){let{value:r}=e,i=t+1;for(/[!^]/u.test(r[i])&&n(i)&&i++,r[i]==="]"&&n(i)&&i++;i<r.length;i++)if(n(i))if(r[i]==="\\")i++;else{if(r[i]==="]")return i;if(r[i]==="["&&/[.:=]/u.test(r[i+1])&&n(i+1)){let o=r.indexOf(r[i+1]+"]",i+2);o!==-1&&(i=o+1)}}return t}var Nw=/[*?[\]^!\\:.=-]/u;function Vt(e){let{value:t,mask:n}=e;if(n===null)return t;let r="";for(let i=0;i<t.length;i++){let o=t[i];r+=n[i]!=="0"&&Nw.test(o)?"\\"+o:o}return r}function Rl(e,t){let n=Vt(e),r=n.match(/[^/]+|\/+/gu)??[],i=Pt(),o=new Set,s=[{path:"",marks:null}],u;try{for(let l=0;l<r.length;l++){let c=r[l];if(c.startsWith("/")||!Io.test(c)){s=s.map(f=>({...f,path:f.path+Iw(c)}));continue}s=Ow(s,c,l===r.length-1,t,o)}let a=s.filter(l=>$(t.cwd,l.path,t.fs).path!==null);for(let l of a)for(let c of l.marks??[])i.add(c);return u=a.filter(l=>l.marks===null).map(l=>l.path).sort(U),u}finally{if(u===void 0)for(let a of o)i.add(a);i.emit(t.notes,"glob","",` while expanding ${JSON.stringify(n)}`),u?.length===0&&r.some(Aw)&&t.notes.add(`glob: no paths matched ${JSON.stringify(n)}; the pattern was left literal.`)}}function Aw(e){for(let t=0;t<e.length;t++)if(e[t]==="\\")t++;else{if(e[t]==="*"||e[t]==="?")return!0;if(e[t]==="[")try{if(Tl(e,t,{bash:!0}))return!0}catch{return!0}}return!1}var Iw=e=>e.replace(/\\(.)/gu,"$1");function Ow(e,t,n,r,i){let o=$e(t,{bash:!0}),s=t.startsWith(".")||t.startsWith("\\."),u=[];for(let a of e){let l=$(r.cwd,a.path||".",r.fs).path;if(!r.fs.isDir(l))continue;let{dirs:c,files:f}=r.fs.listDir(l);for(let d of n?[...c,...f]:c){let p=!s&&d.startsWith(".");if(!p&&a.marks===null)o.test(d)&&u.push({path:a.path+d,marks:null});else if(Cw(o,d)){if(!p){u.push({path:a.path+d,marks:a.marks});continue}let m=L(l,d);i.add(m),u.push({path:a.path+d,marks:[...a.marks??[],m]})}}}return u}function Cw(e,t){try{return e.test(t)}catch{return!0}}var Fo=(e,t)=>e.some(n=>n.test(t)),To=()=>({stdout:"",stderr:"",exitCode:1});function _o(e,t,n,r){let i=0;if(r===1/0){for(let s of se(e))Fo(t,s)!==n&&i++;return i}let o=0;for(;o<e.length&&i<r;){let s=e.indexOf(`
37
- `,o);s<0&&(s=e.length),Fo(t,e.slice(o,s))!==n&&i++,o=s+1}return i}function Pl(e,t,n){let r=[],i=!1;for(let{name:o,content:s,recursive:u}of e){let a={...n,showName:n.showName??u,separate:i&&n.hasContext};Fw(se(s),t,o,a,r)&&(i=!0)}return i?C(ce(r)):To()}function Fw(e,t,n,r,i){let{invert:o,after:s,before:u,max:a,hasContext:l}=r,c=-1,f=0,d=0;for(let p=0;p<e.length&&!(f===a&&d===0);p++){let m=Fo(t,e[p])!==o,h=a!==void 0&&f>=a;if(m&&!h){f++,f===1&&r.separate&&i.push("--");let g=Math.max(0,p-u);l&&c>=0&&g>c+1&&i.push("--");for(let x=Math.max(g,c+1);x<p;x++)Co(e[x],n,x+1,t,r,!1,i);Co(e[p],n,p+1,t,r,!0,i),c=p,d=s;continue}d>0&&(Co(e[p],n,p+1,t,r,!1,i),c=p,d--)}return f>0}function Co(e,t,n,r,i,o,s){if(!i.only){s.push(Ml(e,t,n,o,i));return}if(o===i.invert)return;let u=0;for(;u<e.length;){let a=null;for(let l of r){let c;if(l.extent)c=l.extent.search(e,u);else{let f=l.scan??=new RegExp(l.source,l.flags+"g");f.lastIndex=u;let d=f.exec(e);if(d&&d[0]===""&&l.pcre)throw new w("feature","PCRE empty match extent","only-matching with empty PCRE matches is not supported");c=d?{start:d.index,end:d.index+d[0].length}:null}c&&(!a||c.start<a.start||c.start===a.start&&c.end>a.end)&&(a=c)}if(!a)break;if(a.end===a.start){u=a.end+ke(e,a.end);continue}s.push(Ml(e.slice(a.start,a.end),t,n,o,i)),u=a.end}}function Ml(e,t,n,r,i){let o=r?":":"-";return(i.showName?(t??"(standard input)")+o:"")+(i.showLine?n+o:"")+e}function Dl(e,t,{mode:n,invert:r,showName:i,max:o=1/0}){let s=[],u=!1,a=n==="c"?o:Math.min(1,o);for(let{name:l,content:c,recursive:f}of e){let d=_o(c,t,r,a);d>0&&(u=!0);let p=l??"(standard input)";n==="c"?s.push(i??f?p+":"+d:String(d)):d>0==(n==="l")&&s.push(p)}return{stdout:ce(s),stderr:"",exitCode:u?0:1}}function Ul(e,t,n){let r=e.order.filter(s=>["e","f","file"].includes(s.name)),i=e.positional;if(r.length===0)return i.length?{patterns:i[0].split(`
38
- `),rest:i.slice(1),stdin:t}:null;let o=new Set;for(let{name:s,value:u}of r){if(s==="e"){for(let c of u.split(`
39
- `))o.add(c);continue}let a=Ye("grep",[u],n,t);if(a.failed)return{error:y(a.stderr,2)};let l=a.inputs[0];for(let c of se(l.content))o.add(c);l.shared&&(t="")}return{patterns:[...o],rest:i,stdin:t}}var Bl="[-i] [-a|-I] [-s] [-v] [-n] [-r|-R] [-w] [-x] [-o] [-E|-F|-G|-P] [-l] [-L] [-c] [-q] [-m N] [-h] [-H] [-A N] [-B N] [-C N] [--include=GLOB] [--exclude=GLOB] [--exclude-dir=GLOB]",Tw=`grep ${Bl} PATTERN [PATH...]
40
- or: grep ${Bl} [-e PATTERN] [-f FILE] ... [PATH...]`,_w=["i","v","n","r","R","l","L","c","w","x","h","H","o","E","F","G","P","q","I","a","s"],Lw=["A","B","C","m"],Wl={short:_w,long:["text","no-messages"],valueShort:Lw,repeatable:["e","f","file","include","exclude","exclude-dir"]};function zl(e){try{return E(e,Wl).flags.has("q")}catch{return!1}}function Mr(e,t,n){let r;try{r=E(t,Wl)}catch(h){return K(h,"grep",`grep: ${h.message}`,2)}let{flags:i,values:o}=r,s=Ul(r,e,n);if(!s)return oe(Tw,2);if(s.error)return s.error;let{patterns:u,rest:a}=s;e=s.stdin;let l=Dw(i);if(l)return l;let c;try{c=Cl(u,i)}catch(h){return K(h,"grep",`grep: ${h.message}`,2)}if(c.error)return c.error;let f=Uw(o);if(f.error)return f.error;if(f.max===0&&(!i.has("L")||i.has("q")))return To();if(f.max!==0&&n.stdinFile&&(i.has("q")||i.has("l")||i.has("L")||o.has("m"))&&(a.length===0||a.includes("-")))return v("feature","grep","partial stdin reads","grep: early termination on shared file input is not supported",2);let d=i.has("r")||i.has("R"),p=Ww(r,n),m=r.order.findLast(h=>["a","I","text"].includes(h.name))?.name;p.ignoreBinary=m==="I"&&f.max!==0,p.forceText=m==="a"||m==="text",p.silent=i.has("s")||i.has("no-messages");try{return Rw(e,a,n,d,p,c,i,f)}finally{Pw(p,n.notes)}}function Rw(e,t,n,r,i,o,s,u){if(s.has("q"))return Mw(e,t,n,r,i,o.res,s.has("v"));let a=jl(r,e,t,n,i);u.max===0&&z(n,e);let l=a.inputs;i.name.length>0&&(l=l.filter(g=>Gl(g,i))),u.max!==0&&(l=l.map(g=>ql(g,i,o.res,s.has("v"))));let c=u.max===0?null:Ao(l,o.res,s.has("v"),i.forceText,n.locale);if(c)return c;let f=Bw(s,t.length),d=s.has("v"),p={showName:f,invert:d,showLine:s.has("n"),only:s.has("o"),...u},m=["l","L","c"].find(g=>s.has(g)),h;try{h=m?Dl(l,o.res,{...p,mode:m}):Pl(l,o.res,p)}catch(g){return g instanceof k&&g.gap?v("feature","grep",g.gap,`grep: ${g.message}`,2):K(g,"grep",`grep: ${g.message}`,2)}return a.failed?{stdout:h.stdout,stderr:a.stderr+h.stderr,exitCode:2}:h}function Mw(e,t,n,r,i,o,s){let u="",a=!1;for(let l of t.length?t.map(c=>[c]):[[]]){let c=jl(r,e,l,n,i);u+=c.stderr,a||=c.failed,(l.includes("-")||l.includes("/dev/stdin")&&!n.stdinFile)&&(e="");for(let f of c.inputs){if(!Gl(f,i))continue;let d=ql(f,i,o,s),p=Ao([d],o,s,i.forceText,n.locale);if(p)return p.stderr=u+p.stderr,p;if(_o(d.content,o,s,1)>0)return{stdout:"",stderr:u,exitCode:0}}}return{stdout:"",stderr:u,exitCode:a?2:1}}function ql(e,t,n,r){if(!e.content.includes("\0")||t.forceText)return e;if(!t.ignoreBinary)return/^[\0\n]+$/u.test(e.content)&&n.some(o=>o.test(""))===r?{...e,content:""}:e;if(I(e.content.slice(0,e.content.indexOf("\0"))).length>=96*1024)throw new w("feature","late binary detection","grep: binary detection after the initial input buffer is not supported");let i=e.name===null||e.name==="/dev/stdin"?t.stdinPath:L(t.cwd,e.name);return i?t.binary.add(i):t.binaryStdin=!0,{...e,content:""}}function Pw(e,t){let n="Binary input is treated as text with -a.";st(t,{command:"grep",action:"skipped",noun:["binary file","binary files"],paths:e.binary,explanation:n}),e.binaryStdin&&t.add("grep: skipped binary standard input. "+n),st(t,{command:"grep",action:"excluded",noun:["entry","entries"],paths:e.excluded,context:" by --include/--exclude/--exclude-dir rules"})}function Dw(e){if(e.has("h")&&e.has("H"))return v("option","grep","-h -H","grep: combining -h and -H is not supported");let t=["l","L","c"].filter(r=>e.has(r));if(t.length>1)return v("option","grep","combined output modes",`grep: ${t.map(r=>`-${r}`).join(" / ")} are mutually exclusive`);let n=["E","F","G","P"].filter(r=>e.has(r));return n.length>1?y(`grep: ${n.map(r=>`-${r}`).join(" / ")} are mutually exclusive`,2):null}function Uw(e){let t={A:0,B:0,m:void 0};for(let n of["C","A","B","m"]){if(!e.has(n))continue;let r=pe(e.get(n),"grep: -"+n);if(r.error)return n==="m"&&(r.error.exitCode=2),r;n==="C"?t.A=t.B=r.value:t[n]=r.value}return{after:t.A,before:t.B,max:t.m,hasContext:["A","B","C"].some(n=>e.has(n))}}function Bw(e,t){return e.has("h")?!1:e.has("H")||t>1?!0:void 0}function jl(e,t,n,r,i){if(!e){let a=te("grep",n,t,r);return{...a,stderr:i.silent?"":a.stderr,inputs:a.inputs.map(l=>l.name==="-"?{...l,name:null}:l)}}let o=[],s="",u=!1;for(let a of n.length?n:["."]){if(a==="-"||a==="/dev/stdin"||a==="/dev/null"){let d=Ye("grep",[a],r,t);o.push(...d.inputs.map(p=>({...p,name:a==="-"?null:a}))),(a==="-"||a==="/dev/stdin")&&(t="");continue}let{path:l,error:c}=P(r,"grep",a);if(r.fs.isFile(l)){o.push({name:a,content:r.fs.readFile(l)});continue}if(c){s+=`grep: ${a}: ${c}
41
- `,u=!0;continue}if(qw(a,i.dir)){i.excluded.add(l);continue}let f=d=>d===l||i.dir.length===0||!Hl(i.dir,kt(d))?!0:(i.excluded.add(d),!1);for(let d of Fe(r.fs,l,1/0,f)){if(d.kind!=="file")continue;let p=d.path;o.push({name:jw(n.length?a:"",l,p),content:r.fs.readFile(p),recursive:!0})}}return{inputs:o,stderr:i.silent?"":s,failed:u}}function Ww(e,t){let n=e.order.filter(i=>i.name==="include"||i.name==="exclude").map(i=>({include:i.name==="include",re:$e(i.value)})),r=(e.values.get("exclude-dir")??[]).map(i=>$e(i));return{name:n,dir:r,binary:new Set,excluded:new Set,cwd:t.cwd,stdinPath:t.stdinHandle?.path}}function Hl(e,t){return e.some(n=>n.test(t))}function Gl(e,t){return e.name===null||zw(kt(e.name),t.name)?!0:(t.excluded.add(L(t.cwd,e.name)),!1)}function zw(e,t){if(t.length===0)return!0;let n=null;for(let r of t)r.re.test(e)&&(n=r);return n?n.include:!t[0].include}function qw(e,t){return t.length===0||e.endsWith("/")?!1:Hl(t,e.slice(e.lastIndexOf("/")+1))}function jw(e,t,n){let r=ut(t,n);return e===""?r:e.endsWith("/")?e+r:e+"/"+r}var Ln=(e,t)=>v("feature","rg",e,`rg: ${t}`,2);function Xl(e,t,n){let r=N(e)??e.note;return r?v(r.kind,"rg",r.detail,t,2):v(n,"rg",e.detail??t.replace(/^rg: /u,""),t,2)}function Vl(e,t,n){let r,i;try{i=E(t,ul),r=al(i)}catch(f){return Xl(f,f.message.startsWith("rg: ")?f.message:`rg: ${f.message}`,"option")}let o=[...i.positional];if(!r.patterns.length){if(!o.length)return Ln("usage","a pattern is required");r.patterns.push(o.shift())}try{cl(r.patterns,r.literal)}catch(f){return Xl(f,f.message,"feature")}let u=!o.length&&!!n.stdinPiped?{roots:[],recursive:!1,stdin:!0}:Gw(o,n,r.hidden);if(u.error)return u.error;if(!i.flags.has("no-ignore")&&!r.unrestricted&&u.recursive){let f=Xw(u.roots,n);if(f)return Ln("ignore rules",`${JSON.stringify(f)} would change which files are searched, and its rules are not implemented`)}let a=r.text?null:Zw(o,n);if(a)return Ln("named binary file",`${JSON.stringify(a)} is binary, and reporting a binary match is not supported`);let l=Vw(o,u.roots,n);return l?Ln("byte-order mark",`${JSON.stringify(l)} begins with a byte-order mark, which ripgrep strips before matching`):(u.stdin||o.length?1:Hw(u,r,n))===0?{stdout:"",exitCode:2,stderr:`rg: No files were searched, which means ripgrep probably applied a filter you didn't expect.
45
+ `)}function sw(e,{bytes:t,valid:n}){let r=me(t),o=n?"":`${e}: invalid input
46
+ `;if(r!==void 0&&n)return F(r);let i=r===void 0?{fd:1,bytes:t}:{fd:1,text:r};return{stdout:r??"",stderr:o,exitCode:n?0:1,events:[...t.length?[i]:[],...o?[{fd:2,text:o}]:[]]}}var hf=[{},{},{}],mf=[[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"],[..."0123456789ABCDEFGHIJKLMNOPQRSTUV"],[..."0123456789ABCDEFGHJKMNPQRSTVWXYZ"]],Dt="Invalid character in base32 input",Hi="Invalid base32 padding",uw="Invalid base32 length",Kr="Invalid last chunk",aw=Ot;function gf(e,t,n){Zt(e);let r=Math.floor(e.length/5),o=r*5,i="",s=0,u=mf[t],a=hf[t];if(!a.pairs)if(a.pairs=[],Oe){a.codepairs=new Uint16Array(1024);let p=a.codepairs,h=new Uint8Array(p.buffer,p.byteOffset,p.byteLength);for(let m=0;m<32;m++){let g=u[m].charCodeAt(0);for(let w=0;w<32;w++)h[m<<6|w<<1]=h[w<<6|(m<<1)+1]=g}}else{let p=a.pairs;for(let h=0;h<32;h++)for(let m=0;m<32;m++)p.push(`${u[h]}${u[m]}`)}let{pairs:l,codepairs:f}=a;if(Oe){let p=new Uint16Array(r*4);for(let h=0;s<o;s+=5){let m=e[s],g=e[s+1],w=e[s+2],y=e[s+3],k=e[s+4],S=m<<2|g>>6,I=(g&63)<<4|w>>4,M=(w&15)<<6|y>>2,C=(y&3)<<8|k;p[h]=f[S],p[h+1]=f[I],p[h+2]=f[M],p[h+3]=f[C],h+=4}i=Or(p)}else if(aw)for(;s<o;s+=5){let p=e[s],h=e[s+1],m=e[s+2],g=e[s+3],w=e[s+4],y=p<<2|h>>6,k=(h&63)<<4|m>>4,S=(m&15)<<6|g>>2,I=(g&3)<<8|w;i+=`${l[y]}${l[k]}${l[S]}${l[I]}`}else for(;s<o;s+=5){let p=e[s],h=e[s+1],m=e[s+2],g=e[s+3],w=e[s+4],y=p<<2|h>>6,k=(h&63)<<4|m>>4,S=(m&15)<<6|g>>2,I=(g&3)<<8|w;i+=l[y],i+=l[k],i+=l[S],i+=l[I]}let c=0,d=3;for(;s<e.length;s++){let p=e[s];i+=u[c|p>>d],d>=5&&(d-=5,i+=u[p>>d&31]),c=p<<5-d&31,d+=3}return d!==3&&(i+=u[c]),n&&(i+=["","======","====","===","="][e.length-o]),i}var lw=Ae?128:65536;function wf(e,t){let n=e.length;for(;e[n-1]==="=";)n--;let r=e.length-n,o=n%8,i=n-o;if(![0,2,4,5,7].includes(o))throw new SyntaxError(uw);if(r>7||r!==0&&e.length%8!==0)throw new SyntaxError(Hi);let s=mf[t],u=hf[t];if(!u.fromMap){u.fromMap=new Int8Array(lw).fill(-1);let g=u.fromMap;s.forEach((w,y)=>{g[w.charCodeAt(0)]=g[w.toLowerCase().charCodeAt(0)]=y}),t===2&&(g[73]=g[76]=g[105]=g[108]=g[49],g[79]=g[111]=g[48])}let a=u.fromMap,l=new Uint8Array(Math.floor(n*5/8)),f=0,c=0;if(Ae){let g=Cr(e,Dt);for(;c<i;c+=8){let w=g[c],y=g[c+1],k=g[c+2],S=g[c+3],I=g[c+4],M=g[c+5],C=g[c+6],H=g[c+7],Y=a[w]<<15|a[y]<<10|a[k]<<5|a[S],D=a[I]<<15|a[M]<<10|a[C]<<5|a[H];if(Y<0||D<0)throw new SyntaxError(Dt);l[f]=Y>>12,l[f+1]=Y>>4&255,l[f+2]=Y<<4&255|D>>16,l[f+3]=D>>8&255,l[f+4]=D&255,f+=5}}else for(;c<i;c+=8){let g=e.charCodeAt(c),w=e.charCodeAt(c+1),y=e.charCodeAt(c+2),k=e.charCodeAt(c+3),S=e.charCodeAt(c+4),I=e.charCodeAt(c+5),M=e.charCodeAt(c+6),C=e.charCodeAt(c+7),H=a[g]<<15|a[w]<<10|a[y]<<5|a[k],Y=a[S]<<15|a[I]<<10|a[M]<<5|a[C];if(H<0||Y<0)throw new SyntaxError(Dt);l[f]=H>>12,l[f+1]=H>>4&255,l[f+2]=H<<4&255|Y>>16,l[f+3]=Y>>8&255,l[f+4]=Y&255,f+=5}if(o<2)return l;let d=a[e.charCodeAt(c++)]<<5|a[e.charCodeAt(c++)];if(d<0)throw new SyntaxError(Dt);if(l[f++]=d>>2,o<4){if(d&3)throw new SyntaxError(Kr);return l}let p=a[e.charCodeAt(c++)]<<5|a[e.charCodeAt(c++)];if(p<0)throw new SyntaxError(Dt);if(l[f++]=d<<6&255|p>>4,o<5){if(p&15)throw new SyntaxError(Kr);return l}let h=a[e.charCodeAt(c++)];if(h<0)throw new SyntaxError(Dt);if(l[f++]=p<<4&255|h>>1,o<7){if(h&1)throw new SyntaxError(Kr);return l}let m=a[e.charCodeAt(c++)]<<5|a[e.charCodeAt(c++)];if(m<0)throw new SyntaxError(Dt);if(l[f++]=h<<7&255|m>>3,m&7)throw new SyntaxError(Kr);return l}function yf(e,t,n,r,o){if(typeof e!="string")throw new TypeError(Yt);if(o!==null&&Ar(o),n===!0){if(e.length%8!==0)throw new SyntaxError(Hi)}else if(n===!1){if(e.endsWith("="))throw new SyntaxError("Did not expect padding in base32 input")}else if(n!=="both")throw new TypeError("Invalid padding option");return et(wf(e,t),r)}var Gi=e=>(t,n)=>{if(!n)return yf(t,e,"both","uint8",null);let{format:r="uint8",padding:o="both",...i}=n;return yf(t,e,o,r,i)},bf=Gi(0),PA=Gi(1),DA=Gi(2),xf=(e,{padding:t=!1}={})=>gf(e,0,t);var cw="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",Un=8,dw=Object.freeze([2,4,5,7,8]),kf=Vr("base32",{encode:e=>xf(e,{padding:!0}),decode:hw}),pw=/[a-z]/u;function hw(e,t=!1){let n=e.replace(t?/[^A-Z2-7=]/gu:/\n/gu,"");try{let r=bf(n,{padding:!0});if(!pw.test(n))return{bytes:r,valid:!0}}catch(r){if(!(r instanceof SyntaxError))throw r}return mw(n)}function mw(e){let t=new Uint8Array(Math.ceil(e.length/Un)*5),n=0,r=0,o=!0;for(;r<e.length;){if(e.length-r<Un){o=!1;break}let i=e.slice(r,r+Un),s=/^[A-Z2-7]*/u.exec(i)[0];if(n+=gw(i,s,t.subarray(n)),!dw.includes(s.length)||i.slice(s.length)!=="=".repeat(Un-s.length)){o=!1;break}r+=Un}return{bytes:t.subarray(0,n),valid:o}}function gw(e,t,n){let r=0,o=0,i=0;for(let s of t)o=o<<5|cw.indexOf(s),r+=5,!(r<8)&&(r-=8,n[i++]=o>>r&255);return i}var Xi="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",vf=Vr("base64",{encode:hi,decode:ww});function ww(e,t=!1){let n=e.replace(t?/[^A-Za-z0-9+/=]/gu:/\n/gu,"");try{return{bytes:$n(n,{padding:!0}),valid:!0}}catch(r){if(!(r instanceof SyntaxError))throw r;return yw(n)}}function yw(e){let t=new Uint8Array(Math.ceil(e.length/4)*3),n=/[A-Za-z0-9+/]*/uy,r=0,o=0,i=!0;for(;o<e.length;){n.lastIndex=o;let s=n.exec(e)[0].length,u=s-s%4;if(u){let p=$n(e.slice(o,o+u));t.set(p,r),r+=p.length,o+=u}if(o===e.length)break;let a=s%4;if(a<2){i=!1;break}let l=Xi.indexOf(e[o]),f=Xi.indexOf(e[o+1]),c=a===3?Xi.indexOf(e[o+2]):0;t[r++]=l<<2|f>>4,a===3&&(t[r++]=f<<4|c>>2);let d=4-a;if(o+=a,e.slice(o,o+d)!=="=".repeat(d)){i=!1;break}o+=d}return{bytes:t.subarray(0,r),valid:i}}var bw=["n","N","i","s","w","F","v","l","c","q","u","a","H","I"],xw=["line-number","no-line-number","ignore-case","case-sensitive","word-regexp","fixed-strings","invert-match","files-with-matches","files-without-match","count","quiet","hidden","no-ignore","no-heading","with-filename","no-filename","text","unrestricted"],Ef={short:bw,long:xw,valueShort:["A","B","C"],valueLong:["after-context","before-context","context"],repeatable:["e","regexp"]},kw=new Map(Object.entries({"line-number":"n","no-line-number":"N","ignore-case":"i","case-sensitive":"s","word-regexp":"w","fixed-strings":"F","invert-match":"v","files-with-matches":"l","files-without-match":"L",count:"c",quiet:"q",text:"a",unrestricted:"u","with-filename":"H","no-filename":"I",regexp:"e","after-context":"A","before-context":"B",context:"C"})),vw=new Set(["no-heading","no-ignore"]),jn=(e,t)=>new b("feature",e,`rg: ${t}`);function $f(e){let t={patterns:[],context:[],mode:null,showName:null,ignoreCase:!1,lineNumbers:!1,word:!1,literal:!1,invert:!1,quiet:!1,text:!1,hidden:!1,unrestricted:0};for(let{name:o,value:i}of e.order)vw.has(o)||Sw(t,kw.get(o)??o,i,Zi(o));let n=o=>t.context.findLast(([i])=>i===o)?.[1],r=o=>t.context.findLast(([i])=>i===o)?.[2]??"-"+o;if(t.after=Sf(n("A")??n("C"),n("A")===void 0?r("C"):r("A")),t.before=Sf(n("B")??n("C"),n("B")===void 0?r("C"):r("B")),t.unrestricted>=2&&(t.hidden=!0),t.unrestricted>=3)throw jn("-uuu","searching binary files is not supported");return t}function Sw(e,t,n,r){switch(t){case"i":e.ignoreCase=!0;return;case"s":e.ignoreCase=!1;return;case"n":e.lineNumbers=!0;return;case"N":e.lineNumbers=!1;return;case"l":case"L":case"c":e.mode=t;return;case"H":e.showName="H";return;case"I":e.showName="h";return;case"w":e.word=!0;return;case"F":e.literal=!0;return;case"v":e.invert=!0;return;case"q":e.quiet=!0;return;case"a":e.text=!0;return;case"e":e.patterns.push(n);return;case"hidden":e.hidden=!0;return;case"u":e.unrestricted++;return;case"A":case"B":case"C":e.context.push([t,n,r]);return;default:throw jn(Zi(t),`${Zi(t)} is not supported`)}}function Sf(e,t){if(e===void 0)return 0;if(!/^\d+$/u.test(e))throw jn(`${t} value`,`error parsing flag ${t}: value is not a valid number`);return Number(e)}var Zi=e=>(e.length===1?"-":"--")+e;function Nf(e,t){return t?e.flatMap(n=>["-e",n]):["-e",e.length===1?e[0]:e.map(n=>`(?:${n})`).join("|")]}var Ew=[[/\\[1-9]/u,"backreference"],[/\(\?<?[=!]/u,"look-around"],[/\\[QE]/u,String.raw`\Q…\E literal span`]];function $w(e){for(let t=0;t<e.length;t++){let n=e[t];if(n===`
47
+ `)return!0;if(n!=="\\")continue;let r=e[t+1];if(r==="n"||r==="x"&&/^x\{?0*a\}?/iu.test(e.slice(t+1)))return!0;t++}return!1}function Af(e,t){if(!t)for(let n of e){for(let[r,o]of Ew)if(r.test(n))throw jn(o,`${o} is not supported; ripgrep's regex engine rejects it too`);if($w(n))throw jn("newline in a pattern","a newline in a pattern is not supported; ripgrep rejects one outside multiline mode")}}var $=class extends Error{constructor(t,n=null,r=null){super(t),this.line=n,this.gap=r}},Of=new Set(["BEGIN","END","BEGINFILE","ENDFILE","function","func","if","else","while","for","do","break","continue","next","nextfile","exit","return","delete","in","getline","print","printf","switch","case","default"]),Yi={__proto__:null,length:[0,1],substr:[2,3],index:[2,2],split:[2,3],sub:[2,3],gsub:[2,3],gensub:[3,4],match:[2,3],sprintf:[1,1/0],sin:[1,1],cos:[1,1],atan2:[2,2],exp:[1,1],log:[1,1],sqrt:[1,1],int:[1,1],rand:[0,0],srand:[0,1],tolower:[1,1],toupper:[1,1],close:[1,2],fflush:[0,1],systime:[0,0],strtonum:[1,1],and:[2,1/0],or:[2,1/0],xor:[2,1/0],lshift:[2,2],rshift:[2,2],compl:[1,1],typeof:[1,1],isarray:[1,1]},Jr=new Map([["system","system() is not supported: this terminal runs no processes"],["strftime","strftime() is not supported (gawk extension)"],["mktime","mktime() is not supported (gawk extension)"],["asort","asort() is not supported (gawk extension)"],["asorti","asorti() is not supported (gawk extension)"],["patsplit","patsplit() is not supported (gawk extension)"]]),Cf=new Set([...Object.keys(Yi),...Jr.keys()]),Wn=5e6,Vi=100,Ce=1e6,Qr="this terminal runs no processes";function eo(e,t,n){switch(e){case"+":return t+n;case"-":return t-n;case"*":return t*n;case"/":return t/n;case"%":return t%n;default:return t**n}}var If={__proto__:null,n:10,t:9,r:13,f:12,v:11,a:7,b:8},Nw='^$.[]|()*+?{}\\/"',Ki=1e3,Tf=e=>e!==void 0&&/[0-9a-fA-F]/u.test(e),Ff=e=>e!==void 0&&e>="0"&&e<="7",Ji=class{constructor(t,n,r,o){this.src=t,this.i=0,this.warn=n,this.tables=r,this.ignoreCase=o,this.groups=0}fail(t){throw new $(`invalid regex /${this.src}/: ${t}`)}peek(){return this.src[this.i]}literal(){let t=this.src.codePointAt(this.i);return this.i+=Ue(t),this.charNode(t)}charNode(t){let n=this.ignoreCase?this.tables.fold(t):[t];return n.length===1?{type:"char",code:t}:{type:"set",negate:!1,items:n.map(r=>[r,r])}}parse(){return this.alternation(0)}alternation(t){let n=[this.concatenation(t)];for(;this.peek()==="|";)this.i++,n.push(this.concatenation(t));return n.length===1?n[0]:{type:"alt",nodes:n}}concatenation(t){let n=[];for(;!this.endsConcatenation(t);)n.push(this.quantified(this.atom(n.length===0,t)));return n.length===1?n[0]:{type:"cat",nodes:n}}endsConcatenation(t){let n=this.peek();return n===void 0||n==="|"||n===")"&&t>0}quantified(t){let n=t;for(;;){let r=this.peek();if(r==="*"){this.i++,n={type:"rep",node:n,min:0,max:null};continue}if(r==="+"){this.i++,n={type:"rep",node:n,min:1,max:null};continue}if(r==="?"){this.i++,n={type:"rep",node:n,min:0,max:1};continue}if(r==="{"){let o=/^\{(\d*)(?:(,)(\d*))?\}/u.exec(this.src.slice(this.i));if(!o&&/^\{[\d,]*\}/u.test(this.src.slice(this.i))&&this.fail("invalid content of {}"),!o||o[1]===""&&o[2]===void 0)return n;let i=o[1]===""?0:Number(o[1]),s=o[2]===void 0?i:o[3]===""?null:Number(o[3]);if(s!==null&&s<i&&this.fail(`invalid interval {${i},${s}}`),i>Ki||s!==null&&s>Ki)throw new $(`interval count above ${Ki} is not supported`,null,"regex interval limit");this.i+=o[0].length,n={type:"rep",node:n,min:i,max:s};continue}return n}}atom(t,n){let r=this.peek();if(r==="("){this.i++;let o=++this.groups,i=this.alternation(n+1);return this.peek()!==")"&&this.fail("missing `)`"),this.i++,{type:"group",index:o,node:i}}return r==="["?this.bracket():r==="\\"?this.escape():(this.i++,r==="."?{type:"any"}:r==="^"||r==="$"?{type:"assert",kind:r}:((r==="*"||r==="+"||r==="?")&&!t&&this.fail(`unexpected \`${r}\``),this.i--,this.literal()))}escape(){this.i++;let t=this.peek();return t===void 0&&this.fail("trailing backslash"),this.i++,t==="y"?{type:"assert",kind:"y"}:t==="<"||t===">"||t==="B"?{type:"assert",kind:t}:t==="`"?{type:"assert",kind:"^"}:t==="'"?{type:"assert",kind:"$"}:t==="s"||t==="S"?{type:"set",negate:t==="S",items:this.tables.ranges("space")}:t==="w"||t==="W"?{type:"set",negate:t==="W",items:this.tables.ranges("word")}:(t==="b"&&this.warn?.("regexp escape sequence `\\b' is a backspace here, as in gawk; `\\y' is the word boundary"),this.charNode(this.escapedCode(t,!0)))}escapedCode(t,n){if(t in If)return If[t];if(Ff(t)){let o=t;for(;o.length<3&&Ff(this.peek());)o+=this.src[this.i++];return Lf(o,8)}if(t==="x"&&Tf(this.peek())){let o="";for(;o.length<2&&Tf(this.peek());)o+=this.src[this.i++];return Lf(o,16)}let r=this.src.codePointAt(this.i-1);return!Nw.includes(t)&&n&&this.warn?.(`regexp escape sequence \`\\${String.fromCodePoint(r)}' is not a known regexp operator`),this.i+=Ue(r)-1,r}bracket(){this.i++;let t=!1;this.peek()==="^"&&(t=!0,this.i++);let n=[],r=!0;for(;;){this.i>=this.src.length&&this.fail("unterminated bracket expression");let o=this.peek();if(o==="]"&&!r){this.i++;break}if(r=!1,o==="["&&this.src[this.i+1]===":"){let s=this.src.indexOf(":]",this.i+2);if(s!==-1){let u=this.src.slice(this.i+2,s),a=this.tables.ranges(this.ignoreCase?Pr(u):u);a===void 0&&this.fail(`invalid character class \`[:${u}:]\``),n.push(...a),this.i=s+2;continue}}let i=this.bracketChar();if(this.peek()==="-"&&this.src[this.i+1]!=="]"&&this.src[this.i+1]!==void 0){this.i++;let s=this.bracketChar(),u=this.ignoreCase?this.tables.foldRange(i,s):s<i?null:[[i,s]];u===null&&this.fail("invalid range end"),n.push(...u)}else this.ignoreCase?n.push(...this.tables.fold(i).map(s=>[s,s])):n.push([i,i])}return{type:"set",negate:t,items:n}}bracketChar(){let t=this.peek();if(t==="["&&(this.src[this.i+1]==="."||this.src[this.i+1]==="=")){let r=this.src.indexOf(this.src[this.i+1]+"]",this.i+2);if(r!==-1&&r>this.i+2){Array.from(this.src.slice(this.i+2,r)).length!==1&&this.fail("invalid collation character");let o=this.src.codePointAt(this.i+2);return this.i=r+2,o}}if(t==="\\"){this.i++,this.peek()===void 0&&this.fail("trailing backslash");let r=this.src[this.i++];return this.escapedCode(r,!1)}let n=this.src.codePointAt(this.i);return this.i+=Ue(n),n}};function no(e,t=null,n=re(ee),r=!1){let o=new Ji(e,t,n,r);return{ast:o.parse(),groups:o.groups}}function Lf(e,t){let n=Number.parseInt(e,t);if(n>=128)throw new $("non-ASCII regex byte escapes are not supported",null,"regex byte escapes");return n}var Aw=e=>`\\u{${e.toString(16)}}`,to=e=>e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122?String.fromCodePoint(e):Aw(e);function Ow(e,t){if(e==="^"||e==="$")return e;let n=t.assertions();return e==="y"?n.boundary:e==="B"?n.inside:n[e]}function Qi(e,t=re(ee)){let n=r=>Qi(r,t);switch(e.type){case"char":return to(e.code);case"any":return".";case"set":return`[${e.negate?"^":""}${e.items.map(([r,o])=>r===o?to(r):`${to(r)}-${to(o)}`).join("")}]`;case"assert":return Ow(e.kind,t);case"group":return`(${n(e.node)})`;case"cat":return e.nodes.map(n).join("");case"alt":return`(?:${e.nodes.map(n).join("|")})`;case"rep":{let r=`(?:${n(e.node)})`;return e.max===null?e.min===0?`${r}*`:e.min===1?`${r}+`:`${r}{${e.min},}`:e.min===0&&e.max===1?`${r}?`:`${r}{${e.min},${e.max}}`}default:throw new $(`internal: unknown regex node ${e.type}`)}}var Cw=5e4;function Iw(e,t){let n=r=>{for(let o=0;o<e.length;o++)if(r>=e[o][0]&&r<=e[o][1])return!0;return!1};return t?r=>!n(r):n}function _f(e,t=re(ee)){let n=[],r=l=>{if(n.length>=Cw)throw new $("regex too large",null,"regex state limit");return n.push(l),n.length-1};function o(l,f){switch(l.type){case"char":return r({op:"char",codes:[l.code],next:f});case"any":return r({op:"any",next:f});case"set":return r({op:"set",test:Iw(l.items,l.negate),next:f});case"assert":return r({op:"assert",kind:l.kind,next:f});case"group":return o(l.node,f);case"cat":{let c=f;for(let d=l.nodes.length-1;d>=0;d--)c=o(l.nodes[d],c);return c}case"alt":{let c=l.nodes.map(p=>o(p,f)),d=c.at(-1);for(let p=c.length-2;p>=0;p--)d=r({op:"split",x:c[p],y:d});return d}case"rep":return i(l,f);default:throw new $(`internal: unknown regex node ${l.type}`)}}function i(l,f){let c=f;if(l.max===null){let d=r({op:"split",x:-1,y:f});n[d].x=o(l.node,d),c=d}else for(let d=l.max-l.min;d>0;d--)c=r({op:"split",x:o(l.node,c),y:f});for(let d=0;d<l.min;d++)c=o(l.node,c);return c}let s=o(e,r({op:"match"})),u="",a=s;for(;n[a].op==="char"&&n[a].codes.length===1&&n[a].codes[0]<128;)u+=String.fromCodePoint(n[a].codes[0]),a=n[a].next;return(n[a].op!=="match"||u==="")&&(u=null),{states:n,start:s,literal:u,isWord:l=>t.has("word",l),gen:new Int32Array(n.length).fill(-1),stamp:0}}function Tw(e,t){if(t<=0)return-1;let n=e.codePointAt(t-1);return n>=56320&&n<=57343&&t>=2?e.codePointAt(t-2):n}function Fw(e,t,n,r){if(e==="^")return n===0;if(e==="$")return n===t.length;let o=r(Tw(t,n)),i=n<t.length&&r(t.codePointAt(n));return e==="y"?o!==i:e==="B"?o===i:e==="<"?!o&&i:o&&!i}function Lw(e,t){return e.op==="char"?e.codes.includes(t):e.op==="any"?!0:e.test(t)}function Rf(e,t,n){if(e.literal!==null&&Number.isInteger(n)&&n>=0&&n<=t.length&&!Object.is(n,-0)){let p=t.indexOf(e.literal,n);return p<0?null:{start:p,end:p+e.literal.length}}let{states:r,gen:o}=e,i=t.length,s=[],u=(p,h,m,g,w)=>{for(s.push(h);s.length>0;){let y=s.pop();if(o[y]===w)continue;o[y]=w;let k=r[y];k.op==="split"?s.push(k.y,k.x):k.op==="assert"?Fw(k.kind,t,g,e.isWord)&&s.push(k.next):p.push(y,m)}},a=[],l=[],f=null,c=n,d=++e.stamp;for(;;){f===null&&u(a,e.start,c,c,d);let p=c<i?t.codePointAt(c):-1,h=Ue(p);if(a.length===0){if(f!==null||c>=i)break;c+=h,d=++e.stamp;continue}let m=++e.stamp;for(let g=0;g<a.length;g+=2){let w=a[g],y=a[g+1];if(f!==null&&y>f.start)continue;let k=r[w];if(k.op==="match"){(f===null||y<f.start||y===f.start&&c>f.end)&&(f={start:y,end:c});continue}p!==-1&&Lw(k,p)&&u(l,k.next,y,c+h,m)}if(a.length=0,[a,l]=[l,a],d=m,c>=i)break;c+=h}return f}var ro=new Map,ct=class{constructor(t,n,r,o=re(ee)){let{ast:i,groups:s}=no(t,r,o,n);this.src=t,this.ignoreCase=n,this.tables=o,this.groupCount=s,this.source=Qi(i,o),this.flags="su";try{this.js=new RegExp(this.source,this.flags)}catch(u){throw new $(`cannot compile regex /${t}/: ${u.message}`,null,"regex engine limit")}this.ast=i,this.nfa=null,this.capture=null,this.captureShape=Mf(i)}test(t){return this.checkCase(t),this.js.test(t)}checkCase(t){if(this.ignoreCase&&Tt.test(t+this.src))throw new $("case-insensitive matching over Cyrillic Extended-C letters is not supported",null,"locale-sensitive regex")}search(t,n=0){return this.checkCase(t),this.nfa===null&&(this.nfa=_f(this.ast,this.tables)),Rf(this.nfa,t,n)}groups(t,n,r){if(this.captureShape.unsafe)throw new $("capture extraction across repeated or alternative groups is not supported",null,"regex capture semantics");let o=this.capture??=new RegExp(this.source,this.flags+"dy");o.lastIndex=n;let i=o.exec(t);if(!i||i.index!==n||n+i[0].length!==r){let s=Array.from(t.slice(r)).length,u=new RegExp(`(?:${this.source})(?=.{${s}}(?![^]))`,this.flags+"dy");u.lastIndex=n,i=u.exec(t)}if(!i)throw new $("capture extraction for this match is not supported",null,"regex capture semantics");return i.indices.map((s,u)=>s===void 0?void 0:{text:i[u],start:s[0],end:s[1]})}};function Mf(e){let n=(e.nodes??(e.node?[e.node]:[])).map(Mf),r=n.reduce((s,u)=>s+u.groups,e.type==="group"?1:0),o=e.type==="assert"||(e.type==="group"||e.type==="cat")&&n.every(s=>s.nullable)||e.type==="alt"&&n.some(s=>s.nullable)||e.type==="rep"&&(e.min===0||n[0].nullable),i=e.type==="rep"&&(e.max===null||e.max>1)&&(r>1||r>0&&n[0].nullable);return{groups:r,nullable:o,unsafe:i||e.type==="alt"&&r>0||n.some(s=>s.unsafe)}}function Re(e,t=!1,n=null,r=re(ee)){let o=(t?"i":"c")+r.name+"\0"+e,i=ro.get(o);if(i)return i;ro.size>=500&&ro.clear();let s=new ct(e,t,n,r);return ro.set(o,s),s}function es(e,t,n){for(;;){let r=t.search(e,n);if(!r||r.start!==r.end)return r;if(r.end>=e.length)return null;n=r.end+Le(e,r.end)}}function ts(e,t){let n=[],r=0;for(;;){let o=es(e,t,r);if(!o)break;n.push(e.slice(r,o.start)),r=o.end}return n.push(e.slice(r)),n}function qn(e,t,n,r){let o=r!=="first",i=e.length,s="",u=0,a=-1,l=0;for(;u<=i;){let f=t.search(e,u);if(!f)break;let c=f.start===f.end;if(c&&f.start===a&&r!=="nth"){if(f.start>=i)break;let p=Le(e,f.start);s+=e.slice(u,f.start+p),u=f.start+p;continue}l++;let d=n(f.start,f.end,l);if(s+=e.slice(u,f.start)+(d===null?e.slice(f.start,f.end):d),a=f.end,c){if(f.end>=i){u=i;break}let p=Le(e,f.end);s+=e.slice(f.end,f.end+p),u=f.end+p}else u=f.end;if(!o)break}return{out:s+e.slice(u),count:l}}function oo(e,t){let n="(){}+?|",r=!1,o=0,i=!1,s="";for(let u=0;u<e.length;u++){let a=e[u];if(i){if(a==="["&&(e[u+1]==="."||e[u+1]==="="))throw new b("feature","regex collating or equivalence class","grep: collating and equivalence classes are not supported");if(a==="["){let l=Kt(e,u,{classes:t});if(l){s+=l.body,u=l.end-1;continue}}s+=a,a==="]"&&(i=!1,r=!0);continue}if(a==="["){s+=a,i=!0,e[u+1]==="^"&&(s+="^",u++),e[u+1]==="]"&&(s+="\\]",u++);continue}if(a==="\\"){let l=e[++u];if(l===void 0)return{error:"trailing backslash (\\)"};if(n.includes(l)){if((l==="+"||l==="?")&&!r){s+="\\"+l,r=!0;continue}if(l==="("&&o++,l===")"&&o--===0)return{error:"Unmatched ) or \\)"};(l==="("||l==="|")&&(r=!1),(l===")"||l==="}")&&(r=!0),s+=l}else s+="^$\\.*[]/bBsSwW<>`'123456789".includes(l)?"\\"+l:l,r=!"bB<>`'".includes(l);continue}if(a==="*"){s+=r?"*":"\\*",r=!0;continue}if(a==="^"){r=!_w(e,u),s+=r?"\\^":"^";continue}if(a==="$"){r=!(u===e.length-1||e[u+1]==="\\"&&(e[u+2]===")"||e[u+2]==="|")),s+=r?"\\$":"$";continue}s+=n.includes(a)?"\\"+a:a,r=!0}return o>0?{error:"Unmatched ( or \\("}:{source:s}}function _w(e,t){if(t===0)return!0;if(t<2||e[t-2]!=="\\"||e[t-1]!=="("&&e[t-1]!=="|")return!1;let n=0;for(let r=t-3;r>=0&&e[r]==="\\";r--)n++;return n%2===0}function io(e){if(!/\\[1-9]/u.test(e))return!1;let t=new Set,n=[],r=new Set,o=!1,i=0,s=!1,u=[],a=new Set,l=!1;for(let f=0;f<e.length;f++){let c=e[f];if(c==="\\"){let d=e[++f];if(!o&&/[1-9]/u.test(d??"")){let p=Number(d);if(!t.has(p))throw new Error("Invalid back reference");(!a.has(p)||r.has(p))&&(s=!0)}u=[];continue}if(o){c==="]"&&(o=!1);continue}if(c==="["){o=!0,u=[];continue}if(c==="(")n.push({id:++i,entry:new Set(a),branches:[],start:f}),u=[];else if(c==="|"){let d=n.at(-1);d&&d.branches.push(a),a=new Set(d?.entry),u=[]}else if(c===")"){let d=n.pop();if(!d)continue;a=d.branches.reduce((p,h)=>p.intersection(h),a),a.add(d.id),t.add(d.id),u=[...a.difference(d.entry)],l=Rw(e.slice(d.start,f+1))}else if(c==="*"||c==="?"||c==="+"){if(c!=="?"&&l)for(let d of u)r.add(d);if(c!=="+")for(let d of u)a.delete(d)}else if(c==="{"){let d=/^\{(\d*)(?:,(\d*))?\}/u.exec(e.slice(f));if(d){Number(d[1])===0&&(a=a.difference(new Set(u)));let p=d[2]===void 0?Number(d[1]):d[2]===""?1/0:Number(d[2]);l&&p>1&&u.forEach(h=>r.add(h)),f+=d[0].length-1}else u=[]}else u=[]}return s}function Rw(e){try{return new RegExp(`^(?:${e})$`,"su").test("")}catch{return!0}}var Mw="bBsSwW";function zn(e,t){let n="";for(let r=0;r<e.length;){let o=e[r];if(o==="["){let l=Pw(e,r,t);n+=l.text,r=l.end;continue}let i=o==="\\",s=e.codePointAt(r+(i?1:0)),u=(i?1:0)+Ue(s),a=i&&Mw.includes(e[r+1])?null:t.fold(s);n+=a===null||a.length===1?e.slice(r,r+u):`[${String.fromCodePoint(...a)}]`,r+=u}return n}function Pf(e,t){let n="";for(let r of e){let o=t.fold(r.codePointAt(0));n+=o.length===1?RegExp.escape(r):`[${String.fromCodePoint(...o)}]`}return n}function Pw(e,t,n){let r=t+1,o="[";e[r]==="^"&&(o+="^",r++);let i=!0;for(;;){let s=e[r];if(s==="]"&&!i)return{text:o+"]",end:r+1};if(i=!1,s==="["&&":.=".includes(e[r+1])){let l=e[r+1],f=e.indexOf(l+"]",r+2);o+=l===":"?`[:${Pr(e.slice(r+2,f))}:]`:e.slice(r,f+2),r=f+2;continue}let u=e.codePointAt(r),a=r+Ue(u);if(e[a]==="-"&&e[a+1]!==void 0&&e[a+1]!=="]"){let l=e.codePointAt(a+1),f=a+1+Ue(l);o+=Dw(u,l,e.slice(r,f),n),r=f;continue}o+=String.fromCodePoint(...n.fold(u)),r=a}}function Dw(e,t,n,r){let o=r.foldRange(e,t);if(o===null)throw new Error("Invalid range end");return o.length===1&&o[0][0]===e&&o[0][1]===t?n:o.map(([i,s])=>i===s?String.fromCodePoint(i):`${String.fromCodePoint(i)}-${String.fromCodePoint(s)}`).join("")}function Ie(e){throw new b("feature","PCRE "+e,`PCRE ${e} is not supported`)}function Df(e){let t={captures:0,closed:new Set,names:new Map,stack:[],behind:0,references:!1,risky:!1},n="";for(let r=0;r<e.length;){let o=e[r];if(o==="\\"){let i=Bf(e,r,t,!1);n+=i.source,r=i.end;continue}if(o==="["){let i=jw(e,r,t);n+=i.source,r=i.end;continue}if(o==="("){let i=Bw(e,r,t);n+=i.source,r=i.end;continue}if(o===")"){let i=t.stack.pop();i?.capture&&t.closed.add(i.capture),i?.behind&&t.behind--}if("*+?".includes(o)&&(t.behind&&Ie("variable-length lookbehind"),e[r+1]==="+"&&Ie("possessive repetition"),o!=="+"&&(t.risky=!0)),o==="|"&&(t.risky=!0),o==="{"){let i=Uw(e,r,t);n+=i.source,r=i.end;continue}n+=o==="]"||o==="}"?"\\"+o:o,r++}return t.references&&t.risky&&Ie("conditional backreference"),n}function Bw(e,t,n){let r=!1,o=null,i="(";if(e[t+1]==="*"&&Ie("control verb"),e[t+1]==="?"){let s=/^\(\?(?:[:=!]|<[=!]|<([A-Za-z_]\w*)>)/u.exec(e.slice(t));if(s||Ie("group"),i=s[0],r=i==="(?<="||i==="(?<!",!s[1]&&i!=="(?:"&&(n.risky=!0),s[1]){if(o=++n.captures,n.names.has(s[1]))throw new Error("duplicate PCRE capture name");n.names.set(s[1],o)}}else o=++n.captures;return r&&n.behind++,n.stack.push({capture:o,behind:r}),{source:i,end:t+i.length}}function Uw(e,t,n){let r=/^\{(\d+)(?:,(\d*))?\}/u.exec(e.slice(t));if(!r)return/^\{[\d, \t]*\}/u.test(e.slice(t))&&Ie("repetition"),{source:"\\{",end:t+1};if(n.behind&&r[2]!==void 0&&r[1]!==r[2]&&Ie("variable-length lookbehind"),Number(r[1])>65535||Number(r[2])>65535)throw new Error("PCRE repetition count exceeds 65535");return Number(r[1])===0&&(n.risky=!0),e[t+r[0].length]==="+"&&Ie("possessive repetition"),{source:r[0],end:t+r[0].length}}function jw(e,t,n){let r=t+1,o="[";for(e[r]==="^"&&(o+="^",r++),e[r]==="]"&&(o+="\\]",r++);r<e.length&&e[r]!=="]";)if(e[r]==="["&&":.=".includes(e[r+1]??"")&&Ie("character class"),e[r]==="\\"){let i=Bf(e,r,n,!0);o+=i.source,r=i.end}else o+=e[r]==="["?"\\[":e[r],r++;return{source:o+(e[r]==="]"?"]":""),end:r+1}}function Bf(e,t,n,r){let o=e[t+1];if(o===void 0)throw new Error("trailing backslash");if(o==="Q"){let s=e.indexOf("\\E",t+2);return{source:RegExp.escape(e.slice(t+2,s<0?void 0:s)),end:s<0?e.length:s+2}}if(o==="E")return{source:"",end:t+2};if(o==="x"||o==="0"||r&&/[1-7]/u.test(o))return Ww(e,t);if(o==="a"||o==="e")return{source:o==="a"?"\\u0007":"\\u001B",end:t+2};if("AzZ".includes(o)&&!r)return{source:o==="A"?"^":"$",end:t+2};if(/[1-9]/u.test(o)&&!r)return(/\d/u.test(e[t+2]??"")||!n.closed.has(Number(o)))&&Ie("forward or ambiguous backreference"),n.references=!0,{source:"\\"+o,end:t+2};if(o==="k"&&!r){let s=/^\\k<([A-Za-z_]\w*)>/u.exec(e.slice(t));return(!s||!n.closed.has(n.names.get(s[1])))&&Ie("named backreference"),n.references=!0,{source:s[0],end:t+s[0].length}}if("dDsSwWfnrtbB".includes(o))return{source:"\\"+o,end:t+2};/[A-Za-z0-9]/u.test(o)&&Ie("escape \\"+o);let i=String.fromCodePoint(e.codePointAt(t+1));return{source:RegExp.escape(i),end:t+1+i.length}}function Ww(e,t){let n=e[t+1]==="x",r=(n?/^\\x(?:\{([\da-fA-F]+)\}|([\da-fA-F]{1,2}))/u:/^\\([0-7]{1,3})/u).exec(e.slice(t));if(!r)throw new Error("invalid PCRE character escape");let o=n?16:8,i=parseInt(r[1]??r[2],o);return Ze(i)||Ie("character escape"),{source:`\\u{${i.toString(16)}}`,end:t+r[0].length}}function rs(e,t){let n="",r=!1;for(let o=0;o<e.length;o++){let i=e[o];if(i==="\\"){let s=e[++o]??"";n+=r?i+s:qw(s);continue}if(r&&i==="["){if(e[o+1]==="."||e[o+1]==="=")throw new b("feature","regex collating or equivalence class","grep: collating and equivalence classes are not supported");let s=Kt(e,o,{classes:t});if(s){n+=s.body,o=s.end-1;continue}}if(i==="["&&!r){n+="[",r=!0,e[o+1]==="^"&&(n+="^",o++),e[o+1]==="]"&&(n+="\\]",o++);continue}i==="]"&&(r=!1),n+=i}return n}function qw(e){return"^$\\.*+?()[]{}|/bBsSwW<>`'123456789".includes(e)?"\\"+e:RegExp.escape(e)}function zw(e){for(let t=0;t<e.length;t++)if(e[t]==="\\"){if("bBsSwW<>".includes(e[++t]??""))return!0}else if(".[*+?{".includes(e[t]))return!0;return!1}function Hn(e,t=!1,n=re(ee)){let r=n.assertions(),o=t?{b:"\\y"}:{"<":r["<"],">":r[">"],b:r.boundary,B:r.inside,w:r.word,W:r.nonWord,s:r.space,S:r.nonSpace,"`":"^","'":"$"},i="",s=!1;for(let u=0;u<e.length;u++){let a=e[u];if(a==="\\"){let l=e[++u];i+=!s&&Object.hasOwn(o,l)?o[l]:a+l,!t&&!s&&/[1-9]/u.test(l)&&/\d/u.test(e[u+1]??"")&&(i+="(?:)")}else a==="["&&(s=!0),a==="]"&&(s=!1),i+=a}return i}var os=/^\{(?=\d|,)(\d*)(?:,(\d*))?\}/u,Hw=/^\\\{(?=\d|,)(\d*)(?:,(\d*))?\\\}/u;function Uf(e,t,n){let r=(n?os:Hw).exec(e.slice(t));if(!r&&!n)throw new Error("invalid repetition count");r&&Ra(Number(r[1]),r[2]===void 0||r[2]===""?void 0:Number(r[2]))}var jf={__proto__:null,"*":{min:0,max:1/0},"+":{min:1,max:1/0},"?":{min:0,max:1}};function Gw(e){if(jf[e])return jf[e];let t=os.exec(e),n=Number(t[1]);return{min:n,max:t[2]===void 0?n:t[2]===""?1/0:Number(t[2])}}var Wf=(e,t)=>e===0||t===0?0:e===1/0||t===1/0?1/0:e*t;function Xw(e,t){let n=Math.max(t.min,1);if(n>t.max)return{min:0,max:0};if(e.min>0&&(t.min===0&&e.min>1||e.max!==1/0&&t.max>n&&(n+1)*e.min>n*e.max+1))return null;let r=Wf(t.max,e.max);return r!==1/0&&r>Lr?null:{min:Wf(t.min,e.min),max:r}}function ns(e){return e.max===1/0?e.min===0?"*":e.min===1?"+":`{${e.min},}`:e.min===0&&e.max===1?"?":e.min===e.max?`{${e.min}}`:`{${e.min},${e.max}}`}var Zw=e=>!e.startsWith("(")&&!/^\\[1-9]/u.test(e);function Yw(e,t){if(t.length===1)return e+ns(t[0].bounds);let n=t[0].bounds,r=null;for(let o=1;o<t.length;o++){let{bounds:i,text:s}=t[o],u=r===null?Xw(n,i):null;if(u){n=u;continue}if(!(r===null&&n.min===n.max&&Zw(e))&&i.max>1)throw new Error("stacked quantifier needs ambiguous nesting");r=`(?:${r??e+ns(n)})${s}`}return r??e+ns(n)}function Vw(e,t){let n=t+1;for(e[n]==="^"&&n++;n<e.length;n++){if(e[n]==="\\"){n++;continue}if(e[n]==="]")return n}return e.length-1}function Kw(e){let t="",n=-1,r=-1,o=[],i=()=>{o.length>0&&(t=t.slice(0,n)+Yw(t.slice(n,r),o)),o=[]},s=a=>{i(),n=t.length,r=-1,t+=a},u=[];for(let a=0;a<e.length;a++){let l=e[a];if(l==="\\"){s(l+(e[++a]??""));continue}if(l==="["){let c=Vw(e,a);s(e.slice(a,c+1)),a=c;continue}if(l==="("){i(),u.push(t.length),n=-1,t+=l;continue}if(l===")"){i(),t+=l,n=u.pop()??-1,r=-1;continue}if(l==="|"||l==="^"||l==="$"){i(),t+=l,n=-1;continue}let f=l==="{"?os.exec(e.slice(a)):null;if(l==="*"||l==="+"||l==="?"||f){let c=f?f[0]:l;if(a+=c.length-1,n<0){t+=c;continue}o.length===0&&(r=t.length),o.push({bounds:Gw(c),text:c});continue}s(l)}return i(),t}function is(e,t,n=!1){let r=-1;for(let o=0;o<e.length;o++){let i=o<=r,s=e[o];if(s==="\\"){let u=e[++o];if(u===void 0)throw new Error("trailing backslash");if(i||u&&"dDxXuUpPkKcC".includes(u))throw new b("feature","regex escape","grep: this regex escape is not supported with GNU semantics");!t&&u==="{"&&Uf(e,o-1,!1)}else if(s==="["&&!i)r=Ma(e,o,n);else{if(i)continue;if(t&&s==="{")Uf(e,o,!0);else if(t&&s==="("&&e[o+1]==="?")throw new b("feature","regex extension","grep: ECMAScript group extensions are not supported in ERE")}}}function Jw(e){for(let t=0;t<e.length;t++)if(e[t]==="\\"&&/[1-9]/u.test(e[++t]??""))return!0;return!1}function qf(e,t,n=ee){let r=re(n),o=[],i=t.has("x"),s=t.has("w")&&!i;if(t.has("P")&&new Set(e).size>1)return{error:x("grep: -P only supports a single pattern",2)};for(let u of e){let a=!t.has("F")&&!t.has("P");a&&is(u,t.has("E"),r.multibyte);let l=a&&Jw(u),f=t.has("i")&&!t.has("P")&&!l,c=t.has("i")&&!f?"isu":"su",d;if(t.has("F"))d=f?Pf(u,r):RegExp.escape(u);else if(t.has("P"))d=Df(u);else if(t.has("E"))d=rs(f?zn(u,r):u,r);else{let h=oo(f?zn(u,r):u,r);if(h.error)return{error:x(`grep: ${h.error}`,2)};d=h.source}let p=d;if(a&&io(p))return{error:v("feature","grep","conditional backreference","grep: backreferences with conditional or repeated-empty captures are not supported",2)};s&&(d=`(?<!${r.assertions().word})(?:${d})(?!${r.assertions().word})`),i&&(d=`^(?:${d})$`);try{let h=new RegExp(a?Hn(Kw(d),!1,r):d,c);h.pcre=t.has("P"),h.localeSensitive=h.pcre?t.has("i")||s||zw(p)||/\\[dD]/u.test(p):t.has("i")&&l,h.folded=f,h.extendedC=f&&Tt.test(u),h.unicodePattern=/[\u0080-\u{10FFFF}]/u.test(u);let m=t.has("F")||!Yf.test(u);if(h.binaryLiteral=!i&&!s&&m,m&&u.isWellFormed()&&(f||!t.has("i"))&&(h.literal={pattern:u,tables:r}),t.has("o")&&a&&!i){if(s||/\\[1-9]|\(\?/u.test(d))return{error:v("feature","grep","-o regex extent","grep: only-matching with backreferences, lookarounds or word constraints is not supported",2)};try{h.extent=new ct(Hn(d,!0,r),!1,null,r)}catch{return{error:v("feature","grep","-o regex extent","grep: POSIX match extent for this pattern is not supported",2)}}}o.push(h)}catch(h){if(!t.has("P")&&Qw(p,t))return{error:v("feature","grep","GNU regex syntax","grep: this GNU regular expression cannot be represented by the JavaScript matcher",2)};let m=t.has("F")?`fixed-string /${c}`:t.has("P")?`PCRE subset /${c}`:t.has("E")?`ERE / ECMAScript /${c}`:`BRE /${c}`;return{error:x(`grep: invalid pattern (${m}): ${h.message}`,2)}}}return{res:o}}function Qw(e,t){if(!t.has("E")&&/(?<!\\)\{(?!\d*(?:,\d*)?\})/u.test(e))return!1;try{return no(Hn(e,!0)),!0}catch(n){return!!n.gap}}function zf({pattern:e,tables:t},n){return[...e].map(r=>(n?t.fold(r.codePointAt(0)):[r.codePointAt(0)]).map(i=>B(String.fromCodePoint(i))))}function Hf(e,t){return t.every(n=>n.literal?(n.literalMask??=zf(n.literal,n.folded),!Xf(e,n.literalMask)):!1)}function Gf(e,t,n,r=ee){let o=re(r);return t.every(i=>(n||!Yf.test(i))&&i.isWellFormed()&&!Xf(e,zf({pattern:i,tables:o},!1)))}function Xf(e,t){for(let n=0;n+t.length<=e.length;n++)if(Zf(e,n,t,0))return!0;return!1}function Zf(e,t,n,r){return r===n.length?!0:n[r].some(o=>o.every((i,s)=>e[t+s]===i)&&Zf(e,t+o.length,n,r+1))}var Yf=/[\\.^$*+?()[\]{}|]/u;function ss(e,t,n,r=!1,o=ee){if(e.length===0)return null;if(e.some(a=>a.content===void 0))return v("feature","grep","binary input","grep: binary input detection and output are not supported",2);if(!r&&e.some(a=>a.content.includes("\0")&&(n||t.some(l=>!l.binaryLiteral||l.test(a.content)))))return v("feature","grep","binary input","grep: binary input detection and output are not supported",2);let i=/[\u0080-\u{10FFFF}]/u;if(o!==ee&&t.some(a=>a.localeSensitive||a.folded)&&(t.some(a=>a.unicodePattern)||e.some(a=>i.test(a.content))))return v("feature","grep","locale",`grep: matching non-ASCII text in the ${o} locale is not supported`,2);if(t.some(a=>a.extendedC)||t.some(a=>a.folded)&&e.some(a=>Tt.test(a.content)))return v("feature","grep","locale-sensitive regex","grep: case-insensitive matching over Cyrillic Extended-C letters is not supported",2);let s=t.filter(a=>a.localeSensitive);if(s.length===0||!(s.some(a=>a.unicodePattern)||e.some(a=>i.test(a.content))))return null;let u=s.some(a=>a.pcre)?"PCRE matching":"case-insensitive matching with backreferences";return v("feature","grep","non-ASCII regex semantics",`grep: ${u} on non-ASCII input is not supported`,2)}var us=/[*?[]/u,as=/\P{ASCII}/u,ey=/[.+*?^${}()|[\]\\/]/u;function Me(e,t={}){try{return ty(e,t)}catch(n){throw n instanceof b?n:new b("feature","glob pattern",`unsupported glob pattern: ${n.message}`)}}function ty(e,t){let n="^",r=!1;for(let o=0;o<e.length;o++){let i=e[o];if(i==="\\"&&o+1<e.length){let s=e[o+1];n+=Vf(s,t.ignoreCase),o++}else if(i==="*"){for(;e[o+1]==="*";)o++;n+=".*"}else if(i==="?")n+=".";else if(i==="["){let s=Kf(e,o,t);if(s?.voided)return/^(?!)$/u;s?(n+=s.source,o=s.end,r||=s.nonAsciiRange):n+="\\["}else n+=Vf(i,t.ignoreCase)}return ry(new RegExp(n+"(?![\\s\\S])","us"),e,t,r)}function Vf(e,t){return t&&/[a-zA-Z]/u.test(e)?`[${e.toLowerCase()}${e.toUpperCase()}]`:ey.test(e)?"\\"+e:e}function ny(e,t,n){let r=new RegExp(`[${e}]`,"ui"),o=new RegExp(`[${t}]`,"u"),i="";for(let s=0;s<128;s++){let u=String.fromCodePoint(s);(r.test(u)||o.test(u))&&(i+="\\x"+s.toString(16).padStart(2,"0"))}return`[${n?"^":""}${i}]`}function ry(e,t,n,r){let o=/[?[]/u.test(t),i=as.test(t);return{test(s){if(r||n.ignoreCase&&i||(o||n.ignoreCase)&&as.test(s))throw new b("feature","non-ASCII glob matching","locale-dependent glob matching of non-ASCII names is not supported");return e.test(s)}}}function Kf(e,t,n){let{ignoreCase:r}=n,o=t+1,i=!1;(e[o]==="!"||e[o]==="^")&&(i=!0,o++);let s="",u="",a=!1,l=!1,f=!1,c=!1,d="",p=0,h="",m=0;for(e[o]==="]"&&(s+="\\]",o++,a=!0,d="]");o<e.length&&e[o]!=="]";o++){let g=e[o];if(g==="["&&(e[o+1]==="."||e[o+1]==="="))throw new b("feature","glob collating or equivalence class","glob collating symbols and equivalence classes are not supported");if(g==="["&&e[o+1]===":"){let w=n.bash?oy(e,o):Kt(e,o,{unknown:"empty"});if(w){if(!n.bash&&w.body==="")throw new b("feature","glob character class","unknown POSIX classes in command filename patterns are not supported");l&&(c=!0),r?u+=w.body:s+=w.body,o=w.end-1,a=!1,l=!1;continue}if(n.bash)continue}if(g==="-"&&a)m=p,h=d,s+="-",l=!0,a=!1;else{let w=g==="\\"&&o+1<e.length?e[++o]:g;p=s.length,d=w,l&&as.test(h+w)&&(f=!0),l&&w.codePointAt(0)<h.codePointAt(0)?s=s.slice(0,m):s+=/[\]\\^[-]/u.test(w)?`\\${w}`:w,a=!l,l=!1}}return o>=e.length?null:c?{voided:!0,end:o}:{source:r?ny(s,u,i):`[${i?"^":""}${s}]`,end:o,nonAsciiRange:f}}function oy(e,t){let n=e.indexOf(":]",t+2);if(n===-1)return null;let r=e.slice(t+2,n).replace(/\\([\s\S]|$)/gu,"$1");return{body:r==="ascii"?"\\x00-\\x7F":It[r]??"",end:n+2}}function Jf(e,t){return Me(t).test(e)}function Qf(e){let{value:t,mask:n}=e;if(n===null)return us.test(t);for(let r=0;r<t.length;r++)if(n[r]==="0"&&us.test(t[r]))return!0;return!1}function Gn(e){let t=n=>!e.mask||e.mask[n]==="0";for(let n=0;n<e.value.length;n++){let r=e.value[n];if(t(n)){if(r==="\\")n++;else if(r==="[")n=iy(e,n,t);else if(/[?*+@!]/u.test(r)&&e.value[n+1]==="("&&t(n+1))return!0}}return!1}function iy(e,t,n){let{value:r}=e,o=t+1;for(/[!^]/u.test(r[o])&&n(o)&&o++,r[o]==="]"&&n(o)&&o++;o<r.length;o++)if(n(o))if(r[o]==="\\")o++;else{if(r[o]==="]")return o;if(r[o]==="["&&/[.:=]/u.test(r[o+1])&&n(o+1)){let i=r.indexOf(r[o+1]+"]",o+2);i!==-1&&(o=i+1)}}return t}var sy=/[*?[\]^!\\:.=-]/u;function on(e){let{value:t,mask:n}=e;if(n===null)return t;let r="";for(let o=0;o<t.length;o++){let i=t[o];r+=n[o]!=="0"&&sy.test(i)?"\\"+i:i}return r}function ec(e,t){let n=on(e),r=n.match(/[^/]+|\/+/gu)??[],o=Jt(),i=new Set,s=[{path:"",marks:null}],u;try{for(let l=0;l<r.length;l++){let f=r[l];if(f.startsWith("/")||!us.test(f)){s=s.map(c=>({...c,path:c.path+ay(f)}));continue}s=ly(s,f,l===r.length-1,t,i)}let a=s.filter(l=>E(t.cwd,l.path,t.fs,{follow:!1}).path!==null);for(let l of a)for(let f of l.marks??[])o.add(f);return u=a.filter(l=>l.marks===null).map(l=>l.path).sort(j),u}finally{if(u===void 0)for(let a of i)o.add(a);o.emit(t.notes,"glob","",` while expanding ${JSON.stringify(n)}`),u?.length===0&&r.some(uy)&&t.notes.add(`glob: no paths matched ${JSON.stringify(n)}; the pattern was left literal.`)}}function uy(e){for(let t=0;t<e.length;t++)if(e[t]==="\\")t++;else{if(e[t]==="*"||e[t]==="?")return!0;if(e[t]==="[")try{if(Kf(e,t,{bash:!0}))return!0}catch{return!0}}return!1}var ay=e=>e.replace(/\\(.)/gu,"$1");function ly(e,t,n,r,o){let i=Me(t,{bash:!0}),s=t.startsWith(".")||t.startsWith("\\."),u=[];for(let a of e){let l=E(r.cwd,a.path||".",r.fs).path;if(!r.fs.isDir(l))continue;let{dirs:f,files:c,links:d}=r.fs.listDir(l),p=n?d:d.filter(h=>r.fs.isDir(E(l,h,r.fs).path));for(let h of n?[...f,...c,...p]:[...f,...p]){let m=!s&&h.startsWith(".");if(!m&&a.marks===null)i.test(h)&&u.push({path:a.path+h,marks:null});else if(fy(i,h)){if(!m){u.push({path:a.path+h,marks:a.marks});continue}let g=Z(l,h);o.add(g),u.push({path:a.path+h,marks:[...a.marks??[],g]})}}}return u}function fy(e,t){try{return e.test(t)}catch{return!0}}var fs=(e,t)=>e.some(n=>n.test(t)),cs=()=>({stdout:"",stderr:"",exitCode:1});function ds(e,t,n,r){let o=0;if(r===1/0){for(let s of he(e))fs(t,s)!==n&&o++;return o}let i=0;for(;i<e.length&&o<r;){let s=e.indexOf(`
48
+ `,i);s<0&&(s=e.length),fs(t,e.slice(i,s))!==n&&o++,i=s+1}return o}function nc(e,t,n){let r=[],o=!1;for(let{name:i,content:s,recursive:u}of e){let a={...n,showName:n.showName??u,separate:o&&n.hasContext};cy(he(s),t,i,a,r)&&(o=!0)}return o?F(ge(r)):cs()}function cy(e,t,n,r,o){let{invert:i,after:s,before:u,max:a,hasContext:l}=r,f=-1,c=0,d=0;for(let p=0;p<e.length&&!(c===a&&d===0);p++){let h=fs(t,e[p])!==i,m=a!==void 0&&c>=a;if(h&&!m){c++,c===1&&r.separate&&o.push("--");let g=Math.max(0,p-u);l&&f>=0&&g>f+1&&o.push("--");for(let w=Math.max(g,f+1);w<p;w++)ls(e[w],n,w+1,t,r,!1,o);ls(e[p],n,p+1,t,r,!0,o),f=p,d=s;continue}d>0&&(ls(e[p],n,p+1,t,r,!1,o),f=p,d--)}return c>0}function ls(e,t,n,r,o,i,s){if(!o.only){s.push(tc(e,t,n,i,o));return}if(i===o.invert)return;let u=0;for(;u<e.length;){let a=null;for(let l of r){let f;if(l.extent)f=l.extent.search(e,u);else{let c=l.scan??=new RegExp(l.source,l.flags+"g");c.lastIndex=u;let d=c.exec(e);if(d&&d[0]===""&&l.pcre)throw new b("feature","PCRE empty match extent","only-matching with empty PCRE matches is not supported");f=d?{start:d.index,end:d.index+d[0].length}:null}f&&(!a||f.start<a.start||f.start===a.start&&f.end>a.end)&&(a=f)}if(!a)break;if(a.end===a.start){u=a.end+Le(e,a.end);continue}s.push(tc(e.slice(a.start,a.end),t,n,i,o)),u=a.end}}function tc(e,t,n,r,o){let i=r?":":"-";return(o.showName?(t??"(standard input)")+i:"")+(o.showLine?n+i:"")+e}function rc(e,t,{mode:n,invert:r,showName:o,max:i=1/0}){let s=[],u=!1,a=n==="c"?i:Math.min(1,i);for(let{name:l,content:f,recursive:c}of e){let d=ds(f,t,r,a);d>0&&(u=!0);let p=l??"(standard input)";n==="c"?s.push(o??c?p+":"+d:String(d)):d>0==(n==="l")&&s.push(p)}return{stdout:ge(s),stderr:"",exitCode:u?0:1}}function oc(e,t,n){let r=e.order.filter(s=>["e","f","file"].includes(s.name)),o=e.positional;if(r.length===0)return o.length?{patterns:o[0].split(`
49
+ `),rest:o.slice(1),stdin:t}:null;let i=new Set;for(let{name:s,value:u}of r){if(s==="e"){for(let f of u.split(`
50
+ `))i.add(f);continue}let a=st("grep",[u],n,t);if(a.failed)return{error:x(a.stderr,2)};let l=a.inputs[0];for(let f of he(l.content))i.add(f);l.shared&&(t="")}return{patterns:[...i],rest:o,stdin:t}}var ic="[-i] [-a|-I] [-s] [-v] [-n] [-r|-R] [-w] [-x] [-o] [-E|-F|-G|-P] [-l] [-L] [-c] [-q] [-m N] [-h] [-H] [-A N] [-B N] [-C N] [--include=GLOB] [--exclude=GLOB] [--exclude-dir=GLOB]",dy=`grep ${ic} PATTERN [PATH...]
51
+ or: grep ${ic} [-e PATTERN] [-f FILE] ... [PATH...]`,py=["i","v","n","r","R","l","L","c","w","x","h","H","o","E","F","G","P","q","I","a","s"],hy=["A","B","C","m"],lc={short:py,long:["text","no-messages"],valueShort:hy,repeatable:["e","f","file","include","exclude","exclude-dir"]};function fc(e){try{return N(e,lc).flags.has("q")}catch{return!1}}function so(e,t,n){let r;try{r=N(t,lc)}catch(m){return K(m,"grep",`grep: ${m.message}`,2)}let{flags:o,values:i}=r,s=oc(r,e,n);if(!s)return pe(dy,2);if(s.error)return s.error;let{patterns:u,rest:a}=s;e=s.stdin;let l=by(o);if(l)return l;let f;try{f=qf(u,o,n.locale)}catch(m){return K(m,"grep",`grep: ${m.message}`,2)}if(f.error)return f.error;let c=xy(i);if(c.error)return c.error;if(c.max===0&&(!o.has("L")||o.has("q")))return cs();if(c.max!==0&&n.stdinFile&&(o.has("q")||o.has("l")||o.has("L")||i.has("m"))&&(a.length===0||a.includes("-")))return v("feature","grep","partial stdin reads","grep: early termination on shared file input is not supported",2);let d=o.has("r")||o.has("R"),p=Sy(r,n),h=r.order.findLast(m=>["a","I","text"].includes(m.name))?.name;p.ignoreBinary=h==="I"&&c.max!==0,p.forceText=h==="a"||h==="text",p.silent=o.has("s")||o.has("no-messages"),p.follow=o.has("R");try{return my(e,a,n,d,p,f,o,c)}finally{yy(p,n.notes)}}function my(e,t,n,r,o,i,s,u){if(s.has("q"))return gy(e,t,n,r,o,i.res,s.has("v"));let a=dc(r,e,t,n,o);u.max===0&&q(n,e);let l=a.inputs;o.name.length>0&&(l=l.filter(g=>pc(g,o))),u.max!==0&&(l=l.map(g=>cc(g,o,i.res,s.has("v"))));let f=u.max===0?null:ss(l,i.res,s.has("v"),o.forceText,n.locale);if(f)return f;let c=ky(s,t.length),d=s.has("v"),p={showName:c,invert:d,showLine:s.has("n"),only:s.has("o"),...u},h=["l","L","c"].find(g=>s.has(g)),m;try{m=h?rc(l,i.res,{...p,mode:h}):nc(l,i.res,p)}catch(g){return g instanceof $&&g.gap?v("feature","grep",g.gap,`grep: ${g.message}`,2):K(g,"grep",`grep: ${g.message}`,2)}return a.failed?{stdout:m.stdout,stderr:a.stderr+m.stderr,exitCode:2}:m}function gy(e,t,n,r,o,i,s){let u="",a=!1;for(let l of t.length?t.map(f=>[f]):[[]]){let f=dc(r,e,l,n,o);u+=f.stderr,a||=f.failed,(l.includes("-")||l.includes("/dev/stdin")&&!n.stdinFile)&&(e="");for(let c of f.inputs){if(!pc(c,o))continue;let d=cc(c,o,i,s),p=ss([d],i,s,o.forceText,n.locale);if(p)return p.stderr=u+p.stderr,p;if(ds(d.content,i,s,1)>0)return{stdout:"",stderr:u,exitCode:0}}}return{stdout:"",stderr:u,exitCode:a?2:1}}function cc(e,t,n,r){if(e.content===void 0){if(!r&&Hf(e.bytes,n))return{...e,content:""};if(!t.ignoreBinary)return e;if(!wy(e.bytes,sc))throw new b("feature","late binary detection","grep: binary detection after the initial input buffer is not supported");return uc(e,t)}if(!e.content.includes("\0")||t.forceText)return e;if(!t.ignoreBinary)return/^[\0\n]+$/u.test(e.content)&&n.some(o=>o.test(""))===r?{...e,content:""}:e;if(A(e.content.slice(0,e.content.indexOf("\0"))).length>=sc)throw new b("feature","late binary detection","grep: binary detection after the initial input buffer is not supported");return uc(e,t)}var sc=96*1024;function uc(e,t){let n=e.name===null||e.name==="/dev/stdin"?t.stdinPath:Z(t.cwd,e.name);return n?t.binary.add(n):t.binaryStdin=!0,{...e,content:""}}function wy(e,t){if(e.length<=t)return!0;for(let n=t;n<=t+3&&n<=e.length;n++)if(me(e.subarray(0,n))!==void 0)return!1;return!0}function yy(e,t){let n="Binary input is treated as text with -a.";gt(t,{command:"grep",action:"skipped",noun:["binary file","binary files"],paths:e.binary,explanation:n}),e.binaryStdin&&t.add("grep: skipped binary standard input. "+n),gt(t,{command:"grep",action:"excluded",noun:["entry","entries"],paths:e.excluded,context:" by --include/--exclude/--exclude-dir rules"})}function by(e){if(e.has("h")&&e.has("H"))return v("option","grep","-h -H","grep: combining -h and -H is not supported");let t=["l","L","c"].filter(r=>e.has(r));if(t.length>1)return v("option","grep","combined output modes",`grep: ${t.map(r=>`-${r}`).join(" / ")} are mutually exclusive`);let n=["E","F","G","P"].filter(r=>e.has(r));return n.length>1?x(`grep: ${n.map(r=>`-${r}`).join(" / ")} are mutually exclusive`,2):null}function xy(e){let t={A:0,B:0,m:void 0};for(let n of["C","A","B","m"]){if(!e.has(n))continue;let r=be(e.get(n),"grep: -"+n);if(r.error)return n==="m"&&(r.error.exitCode=2),r;n==="C"?t.A=t.B=r.value:t[n]=r.value}return{after:t.A,before:t.B,max:t.m,hasContext:["A","B","C"].some(n=>e.has(n))}}function ky(e,t){return e.has("h")?!1:e.has("H")||t>1?!0:void 0}function dc(e,t,n,r,o){if(!e){let a=te("grep",n,t,r,{read:"maybe-text"});return{...a,stderr:o.silent?"":a.stderr,inputs:a.inputs.map(l=>l.name==="-"?{...l,name:null}:l)}}let i=[],s="",u=!1;for(let a of n.length?n:["."]){if(a==="-"||a==="/dev/stdin"||a==="/dev/null"){let d=st("grep",[a],r,t);i.push(...d.inputs.map(p=>({...p,name:a==="-"?null:a}))),(a==="-"||a==="/dev/stdin")&&(t="");continue}let{path:l,error:f}=P(r,"grep",a);if(r.fs.isFile(l)){i.push({name:a,...ps(r,l)});continue}if(f){s+=`grep: ${a}: ${f}
52
+ `,u=!0;continue}if(Ey(a,o.dir)){o.excluded.add(l);continue}let c=d=>d===l||o.dir.length===0||!hs(o.dir,nt(d))?!0:(o.excluded.add(d),!1);for(let d of Fe(r.fs,l,1/0,c)){if(d.kind==="link"){if(!o.follow)continue;let h=vy(d.path,ac(n.length?a:"",l,d.path),r,o);h?.input&&i.push(h.input),h?.error&&(s+=h.error,u=!0);continue}if(d.kind!=="file")continue;let p=d.path;i.push({name:ac(n.length?a:"",l,p),...ps(r,p),recursive:!0})}}return{inputs:i,stderr:o.silent?"":s,failed:u}}function vy(e,t,n,r){let o=E(n.cwd,e,n.fs),i=n.fs.isDir(o.path);if(!(i?r.dir.length===0||!hs(r.dir,nt(e)):hc(nt(e),r.name)))return r.excluded.add(e),null;if(i)throw new b("option","-R",`following a symbolic link to a directory is not supported: ${t}`);return o.error?{error:`grep: ${t}: ${o.error}
53
+ `}:{input:{name:t,...ps(n,o.path),recursive:!0}}}function ps(e,t){let{text:n,bytes:r}=wt(e.fs,t);return n===void 0?{content:void 0,bytes:r}:{content:n}}function Sy(e,t){let n=e.order.filter(o=>o.name==="include"||o.name==="exclude").map(o=>({include:o.name==="include",re:Me(o.value)})),r=(e.values.get("exclude-dir")??[]).map(o=>Me(o));return{name:n,dir:r,binary:new Set,excluded:new Set,cwd:t.cwd,stdinPath:t.stdinHandle?.path}}function hs(e,t){return e.some(n=>n.test(t))}function pc(e,t){return e.name===null||hc(nt(e.name),t.name)?!0:(t.excluded.add(Z(t.cwd,e.name)),!1)}function hc(e,t){if(t.length===0)return!0;let n=null;for(let r of t)r.re.test(e)&&(n=r);return n?n.include:!t[0].include}function Ey(e,t){return t.length===0||e.endsWith("/")?!1:hs(t,e.slice(e.lastIndexOf("/")+1))}function ac(e,t,n){let r=He(t,n);return e===""?r:e.endsWith("/")?e+r:e+"/"+r}var Xn=(e,t)=>v("feature","rg",e,`rg: ${t}`,2);function mc(e,t,n){let r=O(e)??e.note;return r?v(r.kind,"rg",r.detail,t,2):v(n,"rg",e.detail??t.replace(/^rg: /u,""),t,2)}function wc(e,t,n){let r,o;try{o=N(t,Ef),r=$f(o)}catch(d){return mc(d,d.message.startsWith("rg: ")?d.message:`rg: ${d.message}`,"option")}let i=[...o.positional];if(!r.patterns.length){if(!i.length)return Xn("usage","a pattern is required");r.patterns.push(i.shift())}try{Af(r.patterns,r.literal)}catch(d){return mc(d,d.message,"feature")}let u=!i.length&&!!n.stdinPiped?{roots:[],recursive:!1,stdin:!0}:Ay(i,n,r.hidden);if(u.error)return u.error;if(!o.flags.has("no-ignore")&&!r.unrestricted&&u.recursive){let d=Oy(u.roots,n);if(d)return Xn("ignore rules",`${JSON.stringify(d)} would change which files are searched, and its rules are not implemented`)}let a=$y(i,u,r,n),l=r.text?null:Cy(i,n);if(l)return Xn("named binary file",`${JSON.stringify(l)} is binary, and reporting a binary match is not supported`);let f=Ny(a,r,n);return f?Xn(f.detail,f.message):(u.stdin||i.length?1:a.length)===0?{stdout:"",exitCode:2,stderr:`rg: No files were searched, which means ripgrep probably applied a filter you didn't expect.
42
54
  Running with --debug will show why files are being skipped.
43
- `}:Yw(e,r,o,u,n)}function Hw(e,t,n){let r=0;for(let i of e.roots)for(let o of Fe(n.fs,i)){if(o.kind!=="file")continue;let s=ut(i==="/"?"/":i,o.path).split("/");(t.hidden||s.every(u=>!u.startsWith(".")))&&r++}return r}function Gw(e,t,n){let r=[],i=!1;for(let s of e){let u=$(t.cwd,s,t.fs);u.path!==null&&t.fs.isDir(u.path)&&r.push(u.path),s.split("/").some(a=>a.startsWith(".")&&a!=="."&&a!=="..")&&(i=!0)}e.length||r.push(t.cwd);let o=r.length>0;return!n&&o&&i&&e.length?{error:Ln("named hidden path","a hidden path named beside a directory is searched by ripgrep but skipped while walking, and both cannot apply at once")}:{roots:r,recursive:o}}function Xw(e,t){let n=l=>ut(t.cwd==="/"?"/":t.cwd,l)||l,r=(l,c=!0)=>{for(let f of e){for(let d of Fe(t.fs,f))if(kt(d.path)===l&&Lo(d.path,c,t))return d.path;for(let d=f;d!=="/";d=vt(d)){let p=$(vt(d),l,t.fs);if(p.path!==null&&Lo(p.path,c,t))return p.path}}return null},i=r(".ignore")??r(".rgignore");if(i)return n(i);let o=r(".git",!1);if(!o)return null;let s=$(o,"info/exclude",t.fs).path,u=s!==null&&Lo(s,!0,t)?s:null,a=r(".gitignore")??u;return a?n(a):null}function Lo(e,t,n){return!t||n.fs.isDir(e)?!0:(n.fs.readFile(e)??"").split(`
44
- `).some(r=>r.trim()!==""&&!r.trimStart().startsWith("#"))}function Zw(e,t){for(let n of e){let r=$(t.cwd,n,t.fs);if(!(r.path===null||t.fs.isDir(r.path))&&t.fs.readFile(r.path)?.includes("\0"))return n}return null}function Vw(e,t,n){let r=e.map(o=>$(n.cwd,o,n.fs).path).filter(Boolean),i=t.flatMap(o=>[...Fe(n.fs,o)].filter(s=>s.kind==="file").map(s=>s.path));for(let o of[...r,...i])if(!n.fs.isDir(o)&&n.fs.readFile(o)?.startsWith("\uFEFF"))return ut(n.cwd==="/"?"/":n.cwd,o)||o;return null}function Yw(e,t,n,r,i){let o=t.literal?["-F"]:["-P"];t.ignoreCase&&o.push("-i"),t.lineNumbers&&o.push("-n"),t.word&&o.push("-w"),t.invert&&o.push("-v"),t.quiet&&o.push("-q"),t.mode&&o.push("-"+t.mode),t.showName&&o.push("-"+t.showName),o.push(t.text?"-a":"-I"),t.after&&o.push("-A",String(t.after)),t.before&&o.push("-B",String(t.before)),r.recursive&&o.push("-r"),r.recursive&&!t.hidden&&o.push("--exclude=.*","--exclude-dir=.[!.]*","--exclude-dir=..?*"),o.push(...ll(t.patterns,t.literal)),r.stdin||o.push("--",...n.length?n:["."]);let s=new Set(i.notes),u=Mr(e,o,i);return t0(i.notes,s,r),e0(Kw(u,t),n,t.patterns)}function Kw(e,t){if(t.mode!=="c")return e;let n=e.stdout.split(`
55
+ `}:Iy(e,r,i,u,n)}function $y(e,t,n,r){let o=e.map(i=>E(r.cwd,i,r.fs).path).filter(Boolean).map(i=>({path:i,named:!0}));for(let i of t.roots)for(let s of Fe(r.fs,i)){if(s.kind!=="file")continue;let u=He(i==="/"?"/":i,s.path).split("/");(n.hidden||u.every(a=>!a.startsWith(".")))&&o.push({path:s.path,named:!1})}return o}function Ny(e,t,n){for(let{path:r,named:o}of e){if(n.fs.isDir(r))continue;let{text:i,bytes:s}=wt(n.fs,r);if(i!==void 0&&!i.startsWith("\uFEFF")||(s===void 0?i.includes("\0"):s.includes(0))&&!o&&!t.text)continue;let a=JSON.stringify(He(n.cwd==="/"?"/":n.cwd,r)||r);if(i===void 0){if(!t.invert&&!t.ignoreCase&&Gf(s,t.patterns,t.literal,n.locale))continue;return{detail:"unreadable bytes",message:`${a} holds bytes that are not text, and searching them is not supported`}}if(i.startsWith("\uFEFF"))return{detail:"byte-order mark",message:`${a} begins with a byte-order mark, which ripgrep strips before matching`}}return null}function Ay(e,t,n){let r=[],o=!1;for(let s of e){let u=E(t.cwd,s,t.fs);u.path!==null&&t.fs.isDir(u.path)&&r.push(u.path),s.split("/").some(a=>a.startsWith(".")&&a!=="."&&a!=="..")&&(o=!0)}e.length||r.push(t.cwd);let i=r.length>0;return!n&&i&&o&&e.length?{error:Xn("named hidden path","a hidden path named beside a directory is searched by ripgrep but skipped while walking, and both cannot apply at once")}:{roots:r,recursive:i}}function Oy(e,t){let n=l=>He(t.cwd==="/"?"/":t.cwd,l)||l,r=(l,f=!0)=>{for(let c of e){for(let d of Fe(t.fs,c))if(nt(d.path)===l&&ms(d.path,f,t))return d.path;for(let d=c;d!=="/";d=ye(d)){let p=E(ye(d),l,t.fs);if(p.path!==null&&ms(p.path,f,t))return p.path}}return null},o=r(".ignore")??r(".rgignore");if(o)return n(o);let i=r(".git",!1);if(!i)return null;let s=E(i,"info/exclude",t.fs).path,u=s!==null&&ms(s,!0,t)?s:null,a=r(".gitignore")??u;return a?n(a):null}function ms(e,t,n){if(!t||n.fs.isDir(e))return!0;let r=E("/",e,n.fs).path,{text:o}=wt(n.fs,r??e);return(o??" ").split(`
56
+ `).some(i=>i.trim()!==""&&!i.trimStart().startsWith("#"))}function Cy(e,t){for(let n of e){let r=E(t.cwd,n,t.fs);if(r.path===null||t.fs.isDir(r.path))continue;let{text:o,bytes:i}=wt(t.fs,r.path);if(i===void 0?o?.includes("\0"):i.includes(0))return n}return null}function Iy(e,t,n,r,o){let i=t.literal?["-F"]:["-P"];t.ignoreCase&&i.push("-i"),t.lineNumbers&&i.push("-n"),t.word&&i.push("-w"),t.invert&&i.push("-v"),t.quiet&&i.push("-q"),t.mode&&i.push("-"+t.mode),t.showName&&i.push("-"+t.showName),i.push(t.text?"-a":"-I"),t.after&&i.push("-A",String(t.after)),t.before&&i.push("-B",String(t.before)),r.recursive&&i.push("-r"),r.recursive&&!t.hidden&&i.push("--exclude=.*","--exclude-dir=.[!.]*","--exclude-dir=..?*"),i.push(...Nf(t.patterns,t.literal)),r.stdin||i.push("--",...n.length?n:["."]);let s=new Set(o.notes),u=so(e,i,o);return Ry(o.notes,s,r),_y(Ty(u,t),n,t.patterns)}function Ty(e,t){if(t.mode!=="c")return e;let n=e.stdout.split(`
45
57
  `).filter(r=>r!==""&&r!=="0"&&!r.endsWith(":0"));return{...e,stdout:n.length?n.join(`
46
58
  `)+`
47
- `:""}}var Zl=new Map([["No such file or directory",2],["Not a directory",20],["Is a directory",21]]),Jw=e=>e.replaceAll(/^(rg: .*: )([A-Z][a-z].*)$/gmu,(t,n,r)=>Zl.has(r)?`${n}${r} (os error ${Zl.get(r)})`:t),Qw=/^rg: (?:invalid pattern[^\n]*|trailing backslash)$/mu;function e0(e,t,n){let r=s=>t.length?s:s.replaceAll(/^\.\//gmu,""),i={...e,stdout:r(e.stdout),stderr:Jw(r(e.stderr).replaceAll(/^grep: /gmu,"rg: "))},o=N(e);return o?.detail==="non-ASCII regex semantics"?v("feature","rg","non-ASCII matching","rg: Unicode-aware matching on non-ASCII input is not supported",2):o?v(o.kind,"rg",o.detail,i.stderr.trimEnd()||o.message,e.exitCode):Qw.test(i.stderr)?v("feature","rg","regex parse error",`rg: regex parse error in ${JSON.stringify(n.join(" "))}; the reason ripgrep gives is not reproduced here`,2):i}function t0(e,t,n){let r=[];for(let i of e)!t.has(i)&&i.startsWith("grep: excluded ")&&r.push(i);for(let i of r)e.delete(i),n.recursive&&e.add(i.replace(/^grep: excluded (\d+) (entry|entries) by --include\/--exclude\/--exclude-dir rules/u,"rg: skipped $1 hidden $2").replace(/\.$/u,". Hidden entries are searched with --hidden."))}var Rn=e=>e.events??[...e.stdout?[{fd:1,text:e.stdout}]:[],...e.stderr?[{fd:2,text:e.stderr}]:[]],Ro=e=>e.unordered??(!e.events&&e.stdout!==""&&e.stderr!==""),R=(e="")=>({stdout:"",stderr:e,exitCode:0,events:e?[{fd:2,text:e}]:[],unordered:!1});function _(e,t){e.stdout+=t.stdout,e.stderr+=t.stderr,e.exitCode=t.exitCode,e.events.push(...Rn(t)),e.unordered||=Ro(t)}function Pr(e,t){t&&_(e.expansionOutput,Yt(R(t),{fds:e.expansionFds},e))}function Yt(e,t,n){let r=i=>n0(e,t,n,i);return n.io?n.io.output(e,t,r):r((i,o)=>o.write(i.text))}function n0(e,t,n,r){let i=e,o=t.fds[1],s=t.fds[2];(o===s&&o!=="null"&&o!=="closed"||(o?.identity&&s?.identity?o.identity===s.identity:o?.path&&o.path===s?.path))&&Ro(i)&&(i=v("feature",null,"combined output ordering","error: merging this command\u2019s stdout and stderr in order is not supported"),n.unsupported.add(N(i)));let a=[],l="",c="";for(let f of Rn(i)){let d=t.fds[f.fd];if(typeof d=="object"){r(f,d);continue}if(d!=="out"&&d!=="err"){f.fd===2&&ku(n,f.text);continue}a.push({fd:d==="out"?1:2,text:f.text}),d==="out"?c+=f.text:l+=f.text}return{...i,stdout:c,stderr:l,events:a,unordered:Ro(i)&&c!==""&&l!==""}}var r0=new Map([["ls",2],["grep",2],["egrep",2],["fgrep",2],["sort",2],["xxd",3],["sed",4],["diff",2],["patch",2],["xargs",123],["hexdump",0],["tree",0]]);function Mo(e,t,n){return n.closed.out&&t.stdout!==""?i0(e,t,n):t}function i0(e,t,n){let r=r0.get(n.registry.resolveCommand(e))??1,i=Rn(t).filter(a=>a.fd!==1),o=r===0?"":`${e}: write error: Bad file descriptor
48
- `;o&&i.push({fd:2,text:o});let s={...t,stdout:"",stderr:t.stderr+o,exitCode:r||t.exitCode,events:i,unordered:!1},u=N(t);return u?Q(s,u.kind,u.command,u.detail,u.message):s}var o0=new Map([["\0","0"],["\x07","a"],["\b","b"],["\f","f"],[`
49
- `,"n"],["\r","r"],[" ","t"],["\v","v"]]);function Z(e,t){let n=le(t),r=n?Array.from(ee(e),s=>String.fromCodePoint(s)):[...e];if(!n&&r.some(s=>s.codePointAt(0)>127&&/[\p{C}\p{Zl}\p{Zp}]/u.test(s)))throw new w("feature","filename quoting","quoting nonprinting Unicode filenames is not supported");if(e.includes("'")&&r.every(s=>/[-a-zA-Z0-9 %+,./:_\]']/u.test(s)||!n&&s.codePointAt(0)>127))return'"'+e+'"';let i=!1,o="'";for(let s of r){let u=s.codePointAt(0),a=o0.get(s)??(u<32||u===127||n&&u>127?u.toString(8).padStart(3,"0"):null);a!==null?(i||(o+="'$'"),i=!0,o+="\\"+a):s==="'"?(o+="'\\''",i=!1):(i&&(o+="''"),i=!1,o+=s)}return o+"'"}var s0=/^[#%+,\-./0-9@A-Z\]_a-z{}~]+$/u;function ie(e,t){return s0.test(e)&&!"#~".includes(e[0])?e:Z(e,t)}var u0=new Map([["\x07","a"],["\b","b"],["\f","f"],[`
50
- `,"n"],["\r","r"],[" ","t"],["\v","v"],['"','"'],["\\","\\"]]);function Po(e,t){let n=le(t),r="",i=!1;for(let o of e){let s=o.codePointAt(0),u=u0.get(o);if(u!==void 0)r+="\\"+u,i=!0;else if(o===" ")r+=o,i=!0;else if(s<32||s===127||s>127&&(n||/[\p{C}\p{Zl}\p{Zp}]/u.test(o))){for(let a of I(o))r+="\\"+a.toString(8).padStart(3,"0");i=!0}else r+=o}return i?`"${r}"`:e}var a0=new Set(["/dev/null","/dev/stdin","/dev/stdout","/dev/stderr"]);function Kl(e,t,n){let r=E(t,{short:["f","n","v","T","r","R"],long:["force","no-clobber","verbose","no-target-directory","recursive"],valueShort:["t"],valueLong:["target-directory"]}),i=l0(r,n);if(i.error)return y("cp: "+i.error);let{sources:o,target:s,directory:u}=i,{flags:a}=r,l=a.has("v")||a.has("verbose"),c=a.has("r")||a.has("R")||a.has("recursive"),f=o.map(m=>[m,u?s.replace(/\/+$/u,"")+"/"+c0(m):s]),d=a.has("n")||a.has("no-clobber"),p={ctx:n,result:R(),failed:!1,sources:new Set,copied:new Set,noClobber:d,force:a.has("f")||a.has("force"),verbose:l,recursive:c,outputOverlap:l&&p0(f,n,{recursive:c,noClobber:d})};for(let[m,h]of f){n.io.setReads([]);try{Jl(m,h,p)}catch(g){D(n,"cp",g?.path,g?.fsError);let x=N(g),b="cp: "+G(g);if(x)return n.unsupported.add({...x,command:x.command??"cp",message:b}),_(p.result,y(b)),p.result;Ot(p,b+`
51
- `,!0)}}return p.result.exitCode=p.failed?1:0,p.result}function l0({positional:e,flags:t,order:n},r){let i=n.filter(({name:c})=>c==="t"||c==="target-directory");if(i.length>1)return{error:"multiple target directories specified"};let o=i[0]?.value,s=t.has("T")||t.has("no-target-directory");if(e.length===0)return{error:"missing file operand"};if(o===void 0&&e.length===1)return{error:"missing destination file operand after "+Z(e[0],r)};if(o!==void 0&&s)return{error:"cannot combine --target-directory (-t) and --no-target-directory (-T)"};if(s&&e.length>2)return{error:"extra operand "+Z(e[2],r)};let u=o??e.at(-1),a=$(r.cwd,u,r.fs),l=!s&&r.fs.isDir(a.path);return!l&&(o!==void 0||e.length>2)?(D(r,"cp",u,a.error),{error:`${o===void 0?"target":"target directory"} ${Z(u,r)}: ${a.error??"Not a directory"}`}):{target:u,directory:l,sources:o===void 0?e.slice(0,-1):e}}var c0=e=>{let t=e.replace(/\/+$/u,"").split("/").at(-1);return t===".."?".":t};function Jl(e,t,n,r=null){let{ctx:i}=n;if(Yl(e,i.cwd)||Yl(t,i.cwd))throw new w("feature","special file","copying special files is not supported");let o=Z(e,i),s=Z(t,i),u=P(i,"cp",e),a=d=>Ot(n,"cp: "+d+`
52
- `,!0);if(u.error)return a(`cannot stat ${o}: ${u.error}`);if(i.fs.isDir(u.path))return n.recursive?f0(e,u.path,t,n,r??{source:o,target:s},r===null):a(`-r not specified; omitting directory ${o}`);if(r===null){if(n.sources.has(u.path))return Ot(n,`cp: warning: source file ${o} specified more than once
53
- `,!1,!0);n.sources.add(u.path)}let l=$(i.cwd,t,i.fs);if(l.error&&l.error!=="No such file or directory")return a(`cannot stat ${s}: ${l.error}`);if(n.noClobber&&l.path!==null)return;if(tc(u.path,l.path,i.fs))return a(`${o} and ${s} are the same file`);if(i.fs.isDir(l.path))return a(`cannot overwrite directory ${s} with non-directory ${o}`);let c=L(i.cwd,t);if(r===null&&n.copied.has(c))return a(`will not overwrite just-created ${s} with ${o}`);let f=Ke(i.cwd,t,i.fs,l);if(Ql(o,s,n),f)return D(i,"cp",t,f),a(`cannot create regular file ${s}: ${f}`);try{if(!i.fs.copyWritable?.(i.cwd,u.path,t))return a(`${n.force&&l.path!==null?"cannot remove":"cannot create regular file"} ${s}: Read-only file system`)}catch(d){if(N(d))throw d;D(i,"cp",d?.path,d?.fsError);let p=G(d);return a(`cannot create regular file ${s}: ${p.startsWith(t+": ")?p.slice(t.length+2):p}`)}r===null&&n.copied.add(c)}function f0(e,t,n,r,i,o){let{ctx:s}=r,u=Z(e,s),a=Z(n,s),l=x=>Ot(r,"cp: "+x+`
54
- `,!0),c=$(s.cwd,n,s.fs);if(c.error&&c.error!=="No such file or directory")return l(`cannot stat ${a}: ${c.error}`);let f=n.replace(/\/+$/u,"")||n;if(c.path===null){let x=Ke(s.cwd,f,s.fs);if(x)return D(s,"cp",f,x),l(`cannot create directory ${a}: ${x}`)}if(c.path!==null&&!s.fs.isDir(c.path))return l(`cannot overwrite non-directory ${a} with directory ${u}`);let d=L(s.cwd,f);if(d===t)return l(`${u} and ${a} are the same file`);if(d.startsWith(t==="/"?"/":t+"/"))return l(`cannot copy a directory, ${i.source}, into itself, ${i.target}`);if(o){if(r.sources.has(t))return Ot(r,`cp: warning: source directory ${u} specified more than once
55
- `,!1,!0);r.sources.add(t)}let{dirs:p,files:m}=s.fs.listDir(t);if(c.path===null&&!d0(e,n,f,r))return;let h=e.replace(/\/+$/u,""),g=n.replace(/\/+$/u,"");for(let x of[...p,...m].sort(U))s.io.setReads([]),Jl(`${h}/${x}`,`${g}/${x}`,r,i)}function d0(e,t,n,r){let{ctx:i}=r,o=Z(t,i),s=a=>(Ot(r,"cp: cannot create directory "+o+": "+a+`
56
- `,!0),!1),u=i.writable&&at(L(i.cwd,n));u&&ec(r);try{if(!u||!i.fs.makeWritableDir?.(i.cwd,n))return s("Read-only file system")}catch(a){if(N(a))throw a;D(i,"cp",a?.path,a?.fsError);let l=G(a);return s(l.startsWith(n+": ")?l.slice(n.length+2):l)}return Ql(Z(e,i),o,r),!0}function Ql(e,t,n){n.verbose&&(ec(n),Ot(n,`${e} -> ${t}
57
- `))}function ec(e){if(e.outputOverlap)throw new w("feature","copy output buffering","buffered verbose output sharing a copied file is not supported")}function tc(e,t,n){if(e===t)return!0;let r=n.fileIdentity?.(e);return r!==void 0&&r===n.fileIdentity(t)}function p0(e,t,{recursive:n,noClobber:r}){let i=t.outputFds[1];if(typeof i!="object")return!1;let o={ctx:t,recursive:n,noClobber:r,holds:s=>i.identity===void 0?i.path===s:i.identity===t.fs.fileIdentity?.(s),made:new Set,sources:new Set,copied:new Set};return e.some(([s,u])=>h0(s,u,o))}function h0(e,t,n){let{ctx:r}=n,i=$(r.cwd,e,r.fs),o=i.path??L(r.cwd,e),s=i.error==="No such file or directory"&&(n.made.has(o)||w0(o,n));if(i.error&&!s)return!1;let u=L(r.cwd,t);return(i.error===null?r.fs.isDir(i.path):!n.made.has(o))?!n.recursive||!y0(o,t,r)||n.sources.has(o)?!1:(n.sources.add(o),m0(o,u,n)):n.sources.has(o)||(n.sources.add(o),n.copied.has(u)||!x0(o,u,t,r,n.noClobber))?!1:(n.copied.add(u),n.made.add(u),n.holds(o)||n.holds(u))}function m0(e,t,n){let{ctx:r}=n,i=e==="/"?0:e.length;for(let o of g0(e,n)){let s=t+o.slice(i);if(!nc(o,s,$(r.cwd,s,r.fs),r,n.noClobber)&&(n.made.add(s),n.holds(o)||n.holds(s)))return!0}return!1}function g0(e,t){let n=e==="/"?"/":e+"/",r=t.ctx.fs.isDir(e)?[...t.ctx.fs.walkFiles(e)]:[];return new Set([...r,...[...t.made].filter(i=>i.startsWith(n))])}var w0=(e,t)=>[...t.made].some(n=>n.startsWith(e+"/"));function nc(e,t,n,r,i){return n.error&&n.error!=="No such file or directory"||i&&n.path!==null||tc(e,n.path,r.fs)||r.fs.isDir(n.path)?!0:!r.writable||!at(t)}function x0(e,t,n,r,i){let o=$(r.cwd,n,r.fs);return!nc(e,t,o,r,i)&&!Ke(r.cwd,n,r.fs,o)}function y0(e,t,n){let r=$(n.cwd,t,n.fs);if(r.error&&r.error!=="No such file or directory")return!1;let i=t.replace(/\/+$/u,"")||t;if(r.path===null&&Ke(n.cwd,i,n.fs)||r.path!==null&&!n.fs.isDir(r.path))return!1;let o=L(n.cwd,i);return o===e||o.startsWith(e==="/"?"/":e+"/")?!1:!!n.writable&&at(o)}function Yl(e,t){let n=e.startsWith("/")?e:t+"/"+e;return a0.has(n.replace(/\/\.(?=\/)/gu,"").replace(/\/+/gu,"/"))}function Ot(e,t,n=!1,r=!1){let i=n||r?R(t):{...R(),stdout:t,events:[{fd:1,text:t}]};_(e.result,e.ctx.flushOutput(i)),e.failed||=n}function rc(e,t,n){let{flags:r,positional:i}=E(t,{short:["f","v","r","R"],long:["force","verbose","recursive"]}),o=r.has("f")||r.has("force"),s=r.has("v")||r.has("verbose"),u=r.has("r")||r.has("R")||r.has("recursive");if(i.length===0)return o?C(""):y("rm: missing operand");let a={ctx:n,force:o,verbose:s,recursive:u,events:[],stdout:"",stderr:""};try{for(let l of i)b0(l,a)}catch(l){D(n,"rm",l?.path,l?.fsError);let c=K(l,"rm","rm: "+G(l));return c.events=[...a.events,{fd:2,text:c.stderr}],c.stdout=a.stdout,c.stderr=a.stderr+c.stderr,c}return{stdout:a.stdout,stderr:a.stderr,events:a.events,exitCode:a.stderr?1:0}}function b0(e,t){let{ctx:n}=t,r=$(n.cwd,e,n.fs),i=r.error;if(!(t.force&&(i==="No such file or directory"||i==="Not a directory"))){if(D(n,"rm",e,i),i===null&&n.fs.isDir(r.path))if(!t.recursive)i="Is a directory";else{if([".",".."].includes(e.replace(/\/+$/u,"").split("/").at(-1)))return Uo(t,`rm: refusing to remove '.' or '..' directory: skipping ${Z(e,n)}
58
- `);if(r.path==="/tmp")i="Device or resource busy";else if(!n.writable||!at(r.path))i="Read-only file system";else return ic(e,r.path,t)}Do(e,r.path,t,!1,i)}}function ic(e,t,n){let{ctx:r}=n,{dirs:i,files:o}=r.fs.listDir(t),s=e.replace(/\/+$/u,"");for(let u of[...i,...o].sort(U)){let a=Ce(t,u);r.fs.isDir(a)?ic(`${s}/${u}`,a,n):Do(`${s}/${u}`,a,n,!1,null)}Do(e,t,n,!0,null)}function Do(e,t,n,r,i){let{ctx:o}=n,s=n.verbose||i!==null||!o.writable||!t?.startsWith("/tmp/")?Z(e,o):"",u=()=>r?o.fs.removeWritableDir?.(o.cwd,e):o.fs.removeWritable?.(o.cwd,e);try{i===null&&!u()&&(i="Read-only file system")}catch(a){if(N(a))throw a;D(o,"rm",a?.path,a?.fsError);let l=G(a);i=a?.fsError??(l.startsWith(e+": ")?l.slice(e.length+2):l)}if(i)return Uo(n,`rm: cannot remove ${s}: ${i}
59
- `);n.verbose&&Uo(n,`removed ${r?"directory ":""}${s}
60
- `,1)}function Uo(e,t,n=2){n===1?e.stdout+=t:e.stderr+=t,e.events.push({fd:n,text:t})}function sc(e,t,n){let{flags:r,positional:i}=E(t,{short:["p","v"],long:["parents","verbose"]});if(i.length===0)return y("mkdir: missing operand");let o={ctx:n,events:[],stdout:"",stderr:"",parents:r.has("p")||r.has("parents"),verbose:r.has("v")||r.has("verbose")};try{for(let s of i)o.parents?v0(s,o):Bo(s,o,!0)}catch(s){D(n,"mkdir",s?.path,s?.fsError);let u=K(s,"mkdir","mkdir: "+G(s));return u.events=[...o.events,{fd:2,text:u.stderr}],u.stdout=o.stdout,u.stderr=o.stderr+u.stderr,u}return{stdout:o.stdout,stderr:o.stderr,events:o.events,exitCode:o.stderr?1:0}}function v0(e,t){let n=e.split("/"),r=[];for(let i=0;i<n.length;i++)n[i]!==""&&r.push(n.slice(0,i+1).join("/"));if(r.length===0){e===""&&Bo(e,t,!0);return}r[r.length-1]=e;for(let[i,o]of r.entries())if(!Bo(o,t,i===r.length-1))return}function Bo(e,t,n){let{ctx:r}=t,i=Z(e,r),o=l=>(oc(t,`mkdir: cannot create directory ${i}: ${l}
61
- `),!1),s=e.replace(/\/+$/u,"")||e,u=$(r.cwd,s,r.fs);if(u.error===null)return t.parents?r.fs.isDir(u.path)?!0:o(n?"File exists":"Not a directory"):o("File exists");let a=Ke(r.cwd,s,r.fs,u);if(a)return D(r,"mkdir",s,a),o(a);try{if(!r.fs.makeWritableDir?.(r.cwd,s))return o("Read-only file system")}catch(l){if(N(l))throw l;D(r,"mkdir",l?.path,l?.fsError);let c=G(l);return o(c.startsWith(s+": ")?c.slice(s.length+2):c)}return t.verbose&&oc(t,`mkdir: created directory ${i}
62
- `,1),!0}function oc(e,t,n=2){n===1?e.stdout+=t:e.stderr+=t,e.events.push({fd:n,text:t})}function uc(e,t,n){let{flags:r,positional:i}=E(t,{short:["c"],long:["no-create"]});if(i.length===0)return y("touch: missing file operand");let o=r.has("c")||r.has("no-create"),s={ctx:n,stderr:"",failed:!1,gap:null};for(let a of i)k0(a,o,s);let u={stdout:"",stderr:s.stderr,exitCode:s.failed?1:0};return s.gap?Q(u,"feature","touch","times",s.gap):u}function k0(e,t,n){let{ctx:r}=n,i=Z(e,r),o=$(r.cwd,e,r.fs);if(o.error===null)return S0(e,i,o.path,n);let s=t||e.endsWith("/");if(t&&o.error==="No such file or directory")return;if(D(r,"touch",e,o.error),s)return Mn(n,`setting times of ${i}: ${o.error}`);let u=Ke(r.cwd,e,r.fs,o);if(u)return Mn(n,`cannot touch ${i}: ${u}`);try{r.fs.openWritable?.(r.cwd,e,!0)||Mn(n,`cannot touch ${i}: Read-only file system`)}catch(a){if(N(a))throw a;D(r,"touch",a?.path,a?.fsError);let l=G(a);Mn(n,`cannot touch ${i}: ${l.startsWith(e+": ")?l.slice(e.length+2):l}`)}}function S0(e,t,n,r){let{ctx:i}=r;if(!i.writable||!at(n))return Mn(r,`setting times of ${t}: Read-only file system`);let o=`touch: setting the times of ${t} is not supported (every entry here carries the one time this filesystem keeps)`;r.gap??=o,r.stderr+=o+`
63
- `,r.failed=!0}function Mn(e,t){e.stderr+=`touch: ${t}
64
- `,e.failed=!0}var ac={cp:Kl,rm:rc,mkdir:sc,touch:uc};function E0(e,t,n){let{positional:r}=E(t),i=te("tac",r,e,n),o=[];for(let{content:s}of i.inputs)o.push(...We(s).toReversed());return ue(o.join(""),i)}var lc=1e6;function $0(e,t){let{flags:n,values:r,positional:i}=E(t,{short:["w"],valueShort:["s"],numericOperands:!0});if(i.length===0||i.length>3)return oe("seq [-w] [-s SEP] LAST | seq FIRST LAST | seq FIRST INCR LAST");let o=[];for(let p of i){if(!/^[+-]?\d+$/u.test(p))return Number.isFinite(Number(p))&&p.trim()!==""||/^[+-]?inf(?:inity)?$/iu.test(p)?v("feature","seq","non-integer operands","seq: non-integer operands are not supported"):y(`seq: invalid integer: ${p}`);o.push(BigInt(p))}let s=o.length===1?1n:o[0],u=o.length===3?o[1]:1n,a=o.at(-1);if(u===0n)return y("seq: increment must be non-zero");let c=(u>0?s<=a:s>=a)?(a>s?a-s:s-a)/(u>0n?u:-u)+1n:0;if(c>lc)return v("feature","seq","sequence limit",`seq: range too large: ${c} elements exceeds limit of ${lc}`);let f=n.has("w")?Math.max(...[i[0],i.at(-1)].map(p=>p.replace(/^\+/u,"").length)):0,d=[];for(let p=0,m=s;p<c;p++,m+=u)d.push(N0(String(m),f));return C(d.length===0?"":d.join(r.get("s")??`
59
+ `:""}}var gc=new Map([["No such file or directory",2],["Not a directory",20],["Is a directory",21]]),Fy=e=>e.replaceAll(/^(rg: .*: )([A-Z][a-z].*)$/gmu,(t,n,r)=>gc.has(r)?`${n}${r} (os error ${gc.get(r)})`:t),Ly=/^rg: (?:invalid pattern[^\n]*|trailing backslash)$/mu;function _y(e,t,n){let r=s=>t.length?s:s.replaceAll(/^\.\//gmu,""),o={...e,stdout:r(e.stdout),stderr:Fy(r(e.stderr).replaceAll(/^grep: /gmu,"rg: "))},i=O(e);return i?.detail==="non-ASCII regex semantics"?v("feature","rg","non-ASCII matching","rg: Unicode-aware matching on non-ASCII input is not supported",2):i?v(i.kind,"rg",i.detail,o.stderr.trimEnd()||i.message,e.exitCode):Ly.test(o.stderr)?v("feature","rg","regex parse error",`rg: regex parse error in ${JSON.stringify(n.join(" "))}; the reason ripgrep gives is not reproduced here`,2):o}function Ry(e,t,n){let r=[];for(let o of e)!t.has(o)&&o.startsWith("grep: excluded ")&&r.push(o);for(let o of r)e.delete(o),n.recursive&&e.add(o.replace(/^grep: excluded (\d+) (entry|entries) by --include\/--exclude\/--exclude-dir rules/u,"rg: skipped $1 hidden $2").replace(/\.$/u,". Hidden entries are searched with --hidden."))}var yc=e=>e.text??W(e.bytes),ws=(e,t)=>{e.bytes===void 0?t.write(e.text):t.writeBytes(e.bytes)},sn=e=>e.events??[...e.stdout?[{fd:1,text:e.stdout}]:[],...e.stderr?[{fd:2,text:e.stderr}]:[]],gs=e=>e.unordered??(!e.events&&e.stdout!==""&&e.stderr!==""),U=(e="")=>({stdout:"",stderr:e,exitCode:0,ignored:!1,events:e?[{fd:2,text:e}]:[],unordered:!1});function _(e,t){e.stdout+=t.stdout,e.stderr+=t.stderr,e.exitCode=t.exitCode,e.ignored=t.ignored??!1,e.events.push(...sn(t)),e.unordered||=gs(t)}function uo(e,t){t&&_(e.expansionOutput,un(U(t),{fds:e.expansionFds},e))}function un(e,t,n){let r=o=>My(e,t,n,o);return n.io?n.io.output(e,t,r):r(ws)}function My(e,t,n,r){let o=e,i=t.fds[1],s=t.fds[2];(i===s&&i!=="null"&&i!=="closed"||(i?.identity&&s?.identity?i.identity===s.identity:i?.path&&i.path===s?.path))&&gs(o)&&(o=v("feature",null,"combined output ordering","error: merging this command\u2019s stdout and stderr in order is not supported"),n.unsupported.add(O(o)));let a=[],l="",f="";for(let c of sn(o)){let d=t.fds[c.fd];if(typeof d=="object"){r(c,d);continue}if(t.deferred?.[c.fd]&&c.bytes!==void 0){a.push(c);continue}if(d!=="out"&&d!=="err"){c.fd===2&&Ga(n,yc(c));continue}let p=yc(c);a.push({fd:d==="out"?1:2,text:p}),d==="out"?f+=p:l+=p}return{...o,stdout:f,stderr:l,events:a,unordered:gs(o)&&f!==""&&l!==""}}var Py=new Map([["ls",2],["grep",2],["egrep",2],["fgrep",2],["sort",2],["xxd",3],["sed",4],["diff",2],["patch",2],["xargs",123],["hexdump",0],["tree",0]]),Dy=e=>e.stdout!==""||sn(e).some(t=>t.fd===1&&(t.bytes?.length??0)>0);function ys(e,t,n){return n.closed.out&&Dy(t)?By(e,t,n):t}function By(e,t,n){let r=Py.get(n.registry.resolveCommand(e))??1,o=sn(t).filter(a=>a.fd!==1),i=r===0?"":`${e}: write error: Bad file descriptor
60
+ `;i&&o.push({fd:2,text:i});let s={...t,stdout:"",stderr:t.stderr+i,exitCode:r||t.exitCode,events:o,unordered:!1},u=O(t);return u?ie(s,u.kind,u.command,u.detail,u.message):s}var Uy=new Map([["\0","0"],["\x07","a"],["\b","b"],["\f","f"],[`
61
+ `,"n"],["\r","r"],[" ","t"],["\v","v"]]);function X(e,t){let n=le(t),r=n?Array.from(B(e),s=>String.fromCodePoint(s)):[...e];if(!n&&r.some(s=>s.codePointAt(0)>127&&/[\p{C}\p{Zl}\p{Zp}]/u.test(s)))throw new b("feature","filename quoting","quoting nonprinting Unicode filenames is not supported");if(e.includes("'")&&r.every(s=>/[-a-zA-Z0-9 %+,./:_\]']/u.test(s)||!n&&s.codePointAt(0)>127))return'"'+e+'"';let o=!1,i="'";for(let s of r){let u=s.codePointAt(0),a=Uy.get(s)??(u<32||u===127||n&&u>127?u.toString(8).padStart(3,"0"):null);a!==null?(o||(i+="'$'"),o=!0,i+="\\"+a):s==="'"?(i+="'\\''",o=!1):(o&&(i+="''"),o=!1,i+=s)}return i+"'"}var jy=/^[#%+,\-./0-9@A-Z\]_a-z{}~]+$/u;function oe(e,t){return jy.test(e)&&!"#~".includes(e[0])?e:X(e,t)}var Wy=new Map([["\x07","a"],["\b","b"],["\f","f"],[`
62
+ `,"n"],["\r","r"],[" ","t"],["\v","v"],['"','"'],["\\","\\"]]);function bs(e,t){let n=le(t),r="",o=!1;for(let i of e){let s=i.codePointAt(0),u=Wy.get(i);if(u!==void 0)r+="\\"+u,o=!0;else if(i===" ")r+=i,o=!0;else if(s<32||s===127||s>127&&(n||/[\p{C}\p{Zl}\p{Zp}]/u.test(i))){for(let a of A(i))r+="\\"+a.toString(8).padStart(3,"0");o=!0}else r+=i}return o?`"${r}"`:e}var qy=new Set(["/dev/null","/dev/stdin","/dev/stdout","/dev/stderr"]);function xc(e,t,n){let r=N(t,{short:["f","n","v","T","r","R"],long:["force","no-clobber","verbose","no-target-directory","recursive"],valueShort:["t"],valueLong:["target-directory"]}),o=zy(r,n);if(o.error)return x("cp: "+o.error);let{sources:i,target:s,directory:u}=o,{flags:a}=r,l=a.has("v")||a.has("verbose"),f=a.has("r")||a.has("R")||a.has("recursive"),c=i.map(h=>[h,u?s.replace(/\/+$/u,"")+"/"+Xy(h):s]),d=a.has("n")||a.has("no-clobber"),p={ctx:n,result:U(),failed:!1,sources:new Set,copied:new Set,noClobber:d,force:a.has("f")||a.has("force"),verbose:l,recursive:f,outputOverlap:l&&Vy(c,n,{recursive:f,noClobber:d})};for(let[h,m]of c){n.io.setReads([]);try{Ec(h,m,p)}catch(g){R(n,"cp",g?.path,g?.fsError);let w=O(g),y="cp: "+V(g);if(w)return n.unsupported.add({...w,command:w.command??"cp",message:y}),_(p.result,x(y)),p.result;Bt(p,y+`
63
+ `,!0)}}return p.result.exitCode=p.failed?1:0,p.result}function zy({positional:e,flags:t,order:n},r){let o=n.filter(({name:f})=>f==="t"||f==="target-directory");if(o.length>1)return{error:"multiple target directories specified"};let i=o[0]?.value,s=t.has("T")||t.has("no-target-directory");if(e.length===0)return{error:"missing file operand"};if(i===void 0&&e.length===1)return{error:"missing destination file operand after "+X(e[0],r)};if(i!==void 0&&s)return{error:"cannot combine --target-directory (-t) and --no-target-directory (-T)"};if(s&&e.length>2)return{error:"extra operand "+X(e[2],r)};let u=i??e.at(-1),a=E(r.cwd,u,r.fs),l=!s&&r.fs.isDir(a.path);return!l&&(i!==void 0||e.length>2)?(R(r,"cp",u,a.error),{error:`${i===void 0?"target":"target directory"} ${X(u,r)}: ${a.error??"Not a directory"}`}):{target:u,directory:l,sources:i===void 0?e.slice(0,-1):e}}function Hy(e,t,n){let{ctx:r}=n,o=E(r.cwd,e,r.fs,{follow:!1}).path;if(o===null)return;let i=e.replace(/\/+$/u,""),s=t.replace(/\/+$/u,"");for(let u of Fe(r.fs,o)){if(u.kind!=="link")continue;let a=u.path===o?null:He(o,u.path);if(!kc(a===null?t:`${s}/${a}`,n)&&!(a!==null&&Gy(s,a,n)))throw vc(a===null?e:`${i}/${a}`)}}var kc=(e,t)=>t.noClobber&&E(t.ctx.cwd,e,t.ctx.fs,{follow:!1}).path!==null;function Gy(e,t,n){let{ctx:r}=n,o=t.split("/");for(let i=1;i<o.length;i++){let s=E(r.cwd,`${e}/${o.slice(0,i).join("/")}`,r.fs,{follow:!1});if(s.path!==null&&!r.fs.isDir(s.path))return!0}return!1}var vc=e=>new b("feature","symbolic link",`copying a symbolic link is not supported: ${e} (a recursive copy keeps the link, which cp does not make here)`),Sc=(e,t,n)=>n.path===null&&e.fs.isLink?.(E(e.cwd,t,e.fs,{follow:!1}).path)===!0,Xy=e=>{let t=e.replace(/\/+$/u,"").split("/").at(-1);return t===".."?".":t};function Ec(e,t,n,r=null){let{ctx:o}=n;if(bc(e,o.cwd)||bc(t,o.cwd))throw new b("feature","special file","copying special files is not supported");let i=X(e,o),s=X(t,o);if(n.recursive&&o.fs.isLink?.(E(o.cwd,e,o.fs,{follow:!1}).path)){if(!kc(t,n))throw vc(e);return}let u=P(o,"cp",e),a=d=>Bt(n,"cp: "+d+`
64
+ `,!0);if(u.error)return a(`cannot stat ${i}: ${u.error}`);if(o.fs.isDir(u.path))return n.recursive?Zy(e,u.path,t,n,r??{source:i,target:s},r===null):a(`-r not specified; omitting directory ${i}`);if(r===null){if(n.sources.has(u.path))return Bt(n,`cp: warning: source file ${i} specified more than once
65
+ `,!1,!0);n.sources.add(u.path)}let l=E(o.cwd,t,o.fs);if(l.error&&l.error!=="No such file or directory")return a(`cannot stat ${s}: ${l.error}`);if(n.noClobber&&l.path!==null)return;if(Ac(u.path,l.path,o.fs))return a(`${i} and ${s} are the same file`);if(o.fs.isDir(l.path))return a(`cannot overwrite directory ${s} with non-directory ${i}`);let f=se(o.fs,o.cwd,t);if(r===null&&n.copied.has(f))return a(`will not overwrite just-created ${s} with ${i}`);let c=tt(o.cwd,t,o.fs,l);if($c(i,s,n),Sc(o,t,l))return a(`not writing through dangling symlink ${s}`);if(c)return R(o,"cp",t,c),a(`cannot create regular file ${s}: ${c}`);try{if(!o.fs.copyWritable?.(o.cwd,u.path,t))return a(`${n.force&&l.path!==null?"cannot remove":"cannot create regular file"} ${s}: Read-only file system`)}catch(d){if(O(d))throw d;R(o,"cp",d?.path,d?.fsError);let p=V(d);return a(`cannot create regular file ${s}: ${p.startsWith(t+": ")?p.slice(t.length+2):p}`)}r===null&&n.copied.add(f)}function Zy(e,t,n,r,o,i){let{ctx:s}=r,u=X(e,s),a=X(n,s),l=y=>Bt(r,"cp: "+y+`
66
+ `,!0),f=E(s.cwd,n,s.fs,{follow:!1});if(f.error&&f.error!=="No such file or directory")return l(`cannot stat ${a}: ${f.error}`);let c=n.replace(/\/+$/u,"")||n;if(se(s.fs,s.cwd,c,!0)===t)return l(`${u} and ${a} are the same file`);if(f.path!==null&&!s.fs.isDir(f.path))return l(`cannot overwrite non-directory ${a} with directory ${u}`);let d=se(s.fs,s.cwd,c,!1);if(f.path===null){let y=tt(s.cwd,c,s.fs);if(y)return R(s,"cp",c,y),l(`cannot create directory ${a}: ${y}`);if(!s.writable||!ut(d))return l(`cannot create directory ${a}: Read-only file system`)}if(d.startsWith(t==="/"?"/":t+"/"))return l(`cannot copy a directory, ${o.source}, into itself, ${o.target}`);if(i){if(r.sources.has(t))return Bt(r,`cp: warning: source directory ${u} specified more than once
67
+ `,!1,!0);r.sources.add(t)}i&&Hy(e,n,r);let{dirs:p,files:h,links:m}=s.fs.listDir(t);if(f.path===null&&!Yy(e,n,c,d,r))return;let g=e.replace(/\/+$/u,""),w=n.replace(/\/+$/u,"");for(let y of[...p,...h,...m].sort(j))s.io.setReads([]),Ec(`${g}/${y}`,`${w}/${y}`,r,o)}function Yy(e,t,n,r,o){let{ctx:i}=o,s=X(t,i),u=l=>(Bt(o,"cp: cannot create directory "+s+": "+l+`
68
+ `,!0),!1),a=i.writable&&ut(r);a&&Nc(o);try{if(!a||!i.fs.makeWritableDir?.(i.cwd,n))return u("Read-only file system")}catch(l){if(O(l))throw l;R(i,"cp",l?.path,l?.fsError);let f=V(l);return u(f.startsWith(n+": ")?f.slice(n.length+2):f)}return $c(X(e,i),s,o),!0}function $c(e,t,n){n.verbose&&(Nc(n),Bt(n,`${e} -> ${t}
69
+ `))}function Nc(e){if(e.outputOverlap)throw new b("feature","copy output buffering","buffered verbose output sharing a copied file is not supported")}function Ac(e,t,n){if(e===t)return!0;let r=n.fileIdentity?.(e);return r!==void 0&&r===n.fileIdentity(t)}function Vy(e,t,{recursive:n,noClobber:r}){let o=t.outputFds[1];if(typeof o!="object")return!1;let i={ctx:t,recursive:n,noClobber:r,holds:s=>o.identity===void 0?o.path===s:o.identity===t.fs.fileIdentity?.(s),made:new Set,sources:new Set,copied:new Set};return e.some(([s,u])=>Ky(s,u,i))}function Ky(e,t,n){let{ctx:r}=n,o=E(r.cwd,e,r.fs),i=o.path??Z(r.cwd,e),s=o.error==="No such file or directory"&&(n.made.has(i)||eb(i,n));if(o.error&&!s)return!1;let u=se(r.fs,r.cwd,t);return(o.error===null?r.fs.isDir(o.path):!n.made.has(i))?!n.recursive||!nb(i,t,r)||n.sources.has(i)?!1:(n.sources.add(i),Jy(i,u,n)):n.sources.has(i)||(n.sources.add(i),n.copied.has(u)||!tb(i,u,t,r,n.noClobber))?!1:(n.copied.add(u),n.made.add(u),n.holds(i)||n.holds(u))}function Jy(e,t,n){let{ctx:r}=n,o=e==="/"?0:e.length;for(let i of Qy(e,n)){let s=t+i.slice(o);if(!Oc(i,s,E(r.cwd,s,r.fs),r,n.noClobber)&&(n.made.add(s),n.holds(i)||n.holds(s)))return!0}return!1}function Qy(e,t){let n=e==="/"?"/":e+"/",r=t.ctx.fs.isDir(e)?[...t.ctx.fs.walkFiles(e)]:[];return new Set([...r,...[...t.made].filter(o=>o.startsWith(n))])}var eb=(e,t)=>[...t.made].some(n=>n.startsWith(e+"/"));function Oc(e,t,n,r,o){return n.error&&n.error!=="No such file or directory"||o&&n.path!==null||Ac(e,n.path,r.fs)||r.fs.isDir(n.path)?!0:!r.writable||!ut(t)}function tb(e,t,n,r,o){let i=E(r.cwd,n,r.fs);return!Oc(e,t,i,r,o)&&!Sc(r,n,i)&&!tt(r.cwd,n,r.fs,i)}function nb(e,t,n){let r=E(n.cwd,t,n.fs,{follow:!1});if(r.error&&r.error!=="No such file or directory")return!1;let o=t.replace(/\/+$/u,"")||t;if(r.path!==null&&!n.fs.isDir(r.path)||r.path===null&&tt(n.cwd,o,n.fs))return!1;let i=se(n.fs,n.cwd,o,!1);return se(n.fs,n.cwd,o,!0)===e||i.startsWith(e==="/"?"/":e+"/")?!1:!!n.writable&&ut(i)}function bc(e,t){let n=e.startsWith("/")?e:t+"/"+e;return qy.has(n.replace(/\/\.(?=\/)/gu,"").replace(/\/+/gu,"/"))}function Bt(e,t,n=!1,r=!1){let o=n||r?U(t):{...U(),stdout:t,events:[{fd:1,text:t}]};_(e.result,e.ctx.flushOutput(o)),e.failed||=n}function Cc(e,t,n){let{flags:r,positional:o}=N(t,{short:["f","v","r","R"],long:["force","verbose","recursive"]}),i=r.has("f")||r.has("force"),s=r.has("v")||r.has("verbose"),u=r.has("r")||r.has("R")||r.has("recursive");if(o.length===0)return i?F(""):x("rm: missing operand");let a={ctx:n,force:i,verbose:s,recursive:u,events:[],stdout:"",stderr:""};try{for(let l of o)rb(l,a)}catch(l){R(n,"rm",l?.path,l?.fsError);let f=K(l,"rm","rm: "+V(l));return f.events=[...a.events,{fd:2,text:f.stderr}],f.stdout=a.stdout,f.stderr=a.stderr+f.stderr,f}return{stdout:a.stdout,stderr:a.stderr,events:a.events,exitCode:a.stderr?1:0}}function rb(e,t){let{ctx:n}=t,r=E(n.cwd,e,n.fs,{follow:!1}),o=r.error;if(!(t.force&&(o==="No such file or directory"||o==="Not a directory"))){if(R(n,"rm",e,o),o===null&&n.fs.isDir(r.path))if(!t.recursive)o="Is a directory";else{if([".",".."].includes(e.replace(/\/+$/u,"").split("/").at(-1)))return ks(t,`rm: refusing to remove '.' or '..' directory: skipping ${X(e,n)}
70
+ `);if(r.path==="/tmp")o="Device or resource busy";else if(!n.writable||!ut(r.path))o="Read-only file system";else return Ic(e,r.path,t,ob(n,e)?"Not a directory":null)}xs(e,r.path,t,!1,o)}}function ob(e,t){let n=t.replace(/\/+$/u,"");return n===t||n===""?!1:e.fs.isLink?.(E(e.cwd,n,e.fs,{follow:!1}).path)===!0}function Ic(e,t,n,r=null){let{ctx:o}=n,{dirs:i,files:s,links:u=[]}=o.fs.listDir(t),a=e.replace(/\/+$/u,"");for(let l of[...i,...s,...u].sort(j)){let f=Te(t,l);o.fs.isDir(f)?Ic(`${a}/${l}`,f,n):xs(`${a}/${l}`,f,n,!1,null)}xs(e,t,n,!0,r)}function xs(e,t,n,r,o){let{ctx:i}=n,s=n.verbose||o!==null||!i.writable||!t?.startsWith("/tmp/")?X(e,i):"",u=()=>r?i.fs.removeWritableDir?.(i.cwd,e):i.fs.removeWritable?.(i.cwd,e);try{o===null&&!u()&&(o="Read-only file system")}catch(a){if(O(a))throw a;R(i,"rm",a?.path,a?.fsError);let l=V(a);o=a?.fsError??(l.startsWith(e+": ")?l.slice(e.length+2):l)}if(o)return ks(n,`rm: cannot remove ${s}: ${o}
71
+ `);n.verbose&&ks(n,`removed ${r?"directory ":""}${s}
72
+ `,1)}function ks(e,t,n=2){n===1?e.stdout+=t:e.stderr+=t,e.events.push({fd:n,text:t})}function Fc(e,t,n){let{flags:r,positional:o}=N(t,{short:["p","v"],long:["parents","verbose"]});if(o.length===0)return x("mkdir: missing operand");let i={ctx:n,events:[],stdout:"",stderr:"",parents:r.has("p")||r.has("parents"),verbose:r.has("v")||r.has("verbose")};try{for(let s of o)i.parents?ib(s,i):vs(s,i,!0)}catch(s){R(n,"mkdir",s?.path,s?.fsError);let u=K(s,"mkdir","mkdir: "+V(s));return u.events=[...i.events,{fd:2,text:u.stderr}],u.stdout=i.stdout,u.stderr=i.stderr+u.stderr,u}return{stdout:i.stdout,stderr:i.stderr,events:i.events,exitCode:i.stderr?1:0}}function ib(e,t){let n=e.split("/"),r=[];for(let o=0;o<n.length;o++)n[o]!==""&&r.push(n.slice(0,o+1).join("/"));if(r.length===0){e===""&&vs(e,t,!0);return}r[r.length-1]=e;for(let[o,i]of r.entries())if(!vs(i,t,o===r.length-1))return}function vs(e,t,n){let{ctx:r}=t,o=X(e,r),i=l=>(Tc(t,`mkdir: cannot create directory ${o}: ${l}
73
+ `),!1),s=e.replace(/\/+$/u,"")||e,u=E(r.cwd,s,r.fs);if(u.error===null)return t.parents?r.fs.isDir(u.path)?!0:i(n?"File exists":"Not a directory"):i("File exists");if(E(r.cwd,s,r.fs,{follow:!1}).error===null)return i(!t.parents||n||u.error!=="Not a directory"?"File exists":"Not a directory");let a=tt(r.cwd,s,r.fs,u);if(a)return R(r,"mkdir",s,a),i(a);try{if(!r.fs.makeWritableDir?.(r.cwd,s))return i("Read-only file system")}catch(l){if(O(l))throw l;R(r,"mkdir",l?.path,l?.fsError);let f=V(l);return i(f.startsWith(s+": ")?f.slice(s.length+2):f)}return t.verbose&&Tc(t,`mkdir: created directory ${o}
74
+ `,1),!0}function Tc(e,t,n=2){n===1?e.stdout+=t:e.stderr+=t,e.events.push({fd:n,text:t})}function Lc(e,t,n){let{flags:r,positional:o}=N(t,{short:["c"],long:["no-create"]});if(o.length===0)return x("touch: missing file operand");let i=r.has("c")||r.has("no-create"),s={ctx:n,stderr:"",failed:!1,gap:null};for(let a of o)sb(a,i,s);let u={stdout:"",stderr:s.stderr,exitCode:s.failed?1:0};return s.gap?ie(u,"feature","touch","times",s.gap):u}function sb(e,t,n){let{ctx:r}=n,o=X(e,r),i=E(r.cwd,e,r.fs);if(i.error===null)return ub(e,o,i.path,n);let s=t||e.endsWith("/");if(t&&i.error==="No such file or directory")return;if(R(r,"touch",e,i.error),s)return Zn(n,`setting times of ${o}: ${i.error}`);let u=tt(r.cwd,e,r.fs,i);if(u)return Zn(n,`cannot touch ${o}: ${u}`);try{r.fs.openWritable?.(r.cwd,e,!0)||Zn(n,`cannot touch ${o}: Read-only file system`)}catch(a){if(O(a))throw a;R(r,"touch",a?.path,a?.fsError);let l=V(a);Zn(n,`cannot touch ${o}: ${l.startsWith(e+": ")?l.slice(e.length+2):l}`)}}function ub(e,t,n,r){let{ctx:o}=r;if(!o.writable||!ut(n))return Zn(r,`setting times of ${t}: Read-only file system`);let i=`touch: setting the times of ${t} is not supported (every entry here carries the one time this filesystem keeps)`;r.gap??=i,r.stderr+=i+`
75
+ `,r.failed=!0}function Zn(e,t){e.stderr+=`touch: ${t}
76
+ `,e.failed=!0}function Yn(e,t,n,r){if(t===""||t.includes("\0"))return{error:"No such file or directory"};if(r==="none")return ab(e,t,n);let o=t;if(r==="logical"){let s=n==="m"?{path:Z(e.cwd,t)}:Mc(e,t);if(s.error)return s;o=s.path+(t.endsWith("/")?"/":"")}let i=ze(e.cwd,o,e.fs,{lenient:n==="m"});return n==="m"?{path:i.rest.length?Z(i.path,i.rest.join("/")):i.path}:i.error==="No such file or directory"&&i.rest.length===0&&n!=="e"?{path:i.path}:i.error?{error:i.error}:t.endsWith("/")&&!e.fs.isDir(i.path)?{error:"Not a directory"}:{path:i.path}}function ab(e,t,n){if(n==="m")return{path:Z(e.cwd,t)};let r=Mc(e,t);if(r.error||n!=="e")return r;let o=E("/",r.path,e.fs);return o.error?{error:o.error}:r}function Mc(e,t){let n=(t.startsWith("/")?t:e.cwd+"/"+t).split("/").filter(Boolean),r="/";for(let o=0;o<n.length;o++){let i=n[o];if(i==="..")r=ye(r);else if(i!=="."){r=Te(r,i);let s=o+1;for(;n[s]===".";)s++;let u=n[s]===".."||s===n.length&&(o<n.length-1||t.endsWith("/"));if(u||o===n.length-1){let a=E("/",r+(u?"/":""),e.fs);if(a.error&&!(a.error==="No such file or directory"&&o===n.length-1))return a}}}return{path:r}}function Ss(e,t){let n=e.split("/").filter(Boolean),r=t.split("/").filter(Boolean),o=0;for(;o<n.length&&o<r.length&&n[o]===r[o];)o++;return[...n.slice(o).map(()=>".."),...r.slice(o)].join("/")||"."}var Pc=(e,t)=>e==="/"||t===e||t.startsWith(e+"/"),_c={e:"e","canonicalize-existing":"e",m:"m","canonicalize-missing":"m"},Rc={P:"physical",physical:"physical",L:"logical",logical:"logical",s:"none",strip:"none","no-symlinks":"none"};function lb(e,t,n,r){let o=t.get("relative-base"),i=t.get("relative-to")??o,s={};for(let[u,a]of[["target",i],["base",o]]){if(a===void 0)continue;let l=Yn(e,a,n,r),f=l.error??(n==="e"&&!e.fs.isDir(l.path)?"Not a directory":null);if(f)return R(e,"realpath",a,f),{error:x(`realpath: ${oe(a,e)}: ${f}`)};s[u]=l.path}return s.base&&!Pc(s.base,s.target)&&delete s.target,s}function Dc(e,t,n){let{flags:r,values:o,positional:i,order:s}=N(t,{short:["e","m","L","P","s","q","z"],long:["canonicalize-existing","canonicalize-missing","logical","physical","strip","no-symlinks","quiet","zero"],valueLong:["relative-to","relative-base"]});if(!i.length)return x("realpath: missing operand");let u="physical",a="E";for(let{name:h}of s)Object.hasOwn(_c,h)&&(a=_c[h]),Object.hasOwn(Rc,h)&&(u=Rc[h]);let l=lb(n,o,a,u);if(l.error)return l.error;let f=r.has("q")||r.has("quiet"),c=r.has("z")||r.has("zero")?"\0":`
77
+ `,d=U(),p=!1;for(let h of i){let m=Yn(n,h,a,u);if(m.error)R(n,"realpath",h,m.error),f||_(d,x(`realpath: ${oe(h,n)}: ${m.error}`)),p=!0;else{let g=l.target&&(!l.base||Pc(l.base,m.path))?Ss(l.target,m.path):m.path;_(d,F(g+c))}}return d.exitCode=p?1:0,d}var ao={symbolic:"s",force:"f","no-dereference":"n","no-target-directory":"T",verbose:"v",relative:"r",logical:"L",physical:"P"};function Uc(e,t,n){let r=N(t,{short:Object.values(ao),long:Object.keys(ao),valueShort:["t"],valueLong:["target-directory"]}),o=l=>r.flags.has(l)||r.flags.has(Object.keys(ao).find(f=>ao[f]===l)),i={force:o("f"),noDereference:o("n"),noTargetDirectory:o("T"),verbose:o("v"),relative:o("r")},s=r.order.findLast(({name:l})=>l==="t"||l==="target-directory")?.value??null,u=r.positional;if(s!==null&&i.noTargetDirectory)return x("ln: cannot combine --target-directory and --no-target-directory");if(i.relative&&!o("s"))return x("ln: cannot do --relative without --symbolic");if(u.length===0)return x("ln: missing file operand");if(!o("s"))return v("feature","ln","hard link",`ln: hard links are not supported: ${X(u[0],n)} (ln -s makes a symbolic one)`);let a={ctx:n,events:[],stdout:"",stderr:""};try{let l=fb(u,s,i,n);if(l.error)return l.error;for(let[f,c,d]of l)cb(f,c,i,a,d)}catch(l){R(n,"ln",l?.path,l?.fsError);let f=K(l,"ln","ln: "+V(l));return f.events=[...a.events,{fd:2,text:f.stderr}],f.stdout=a.stdout,f.stderr=a.stderr+f.stderr,f}return{stdout:a.stdout,stderr:a.stderr,events:a.events,exitCode:a.stderr?1:0}}function fb(e,t,n,r){let o=a=>X(a,r);if(t!==null){let a=E(r.cwd,t,r.fs);return a.error?(R(r,"ln",t,a.error),{error:x(`ln: failed to access ${o(t)}: ${a.error}`)}):r.fs.isDir(a.path)?e.map(l=>Es(t,l)):{error:x(`ln: target ${o(t)} is not a directory`)}}if(e.length===1)return n.noTargetDirectory?{error:x(`ln: missing destination file operand after ${o(e[0])}`)}:[Es(".",e[0])];if(e.length===2){let a=E(r.cwd,e[1],r.fs,{follow:!n.noDereference});if(n.noTargetDirectory||a.error!==null||!r.fs.isDir(a.path))return[[e[0],e[1]]]}if(n.noTargetDirectory)return{error:x(`ln: extra operand ${o(e[2])}`)};let i=e.at(-1),s=E(r.cwd,i,r.fs),u=s.error??(r.fs.isDir(s.path)?null:"Not a directory");return u?(R(r,"ln",i,u),{error:x(`ln: target ${o(i)}: ${u}`)}):e.slice(0,-1).map(a=>Es(i,a))}function Es(e,t){let n=t.replace(/\/+$/u,"").split("/").at(-1);return[t,e+(e.endsWith("/")?"":"/")+n,n===""]}function cb(e,t,n,r,o=!1){let{ctx:i}=r,s=X(t,i),u=n.relative?pb(i,e,t):e,a=f=>$s(r,`ln: failed to create symbolic link ${s}${f}
78
+ `);if(u==="")return a(` -> ${X(u,i)}: No such file or directory`);if(o)return a(": No such file or directory");if(n.force){let f=E(i.cwd,t,i.fs,{follow:!1});if(f.error===null){if(i.fs.isDir(f.path))return $s(r,`ln: ${oe(t,i)}: cannot overwrite directory
79
+ `);try{if(!i.fs.removeWritable?.(i.cwd,t))return a(": Read-only file system")}catch(c){if(O(c))throw c;return a(`: ${Bc(c,t)}`)}}}let l=db(i,t);if(l)return R(i,"ln",t,l),a(`: ${l}`);try{if(!i.fs.makeWritableLink?.(i.cwd,t,u))return a(": Read-only file system")}catch(f){if(O(f))throw f;return R(i,"ln",f?.path,f?.fsError),a(`: ${Bc(f,t)}`)}n.verbose&&$s(r,`${s} -> ${X(u,i)}
80
+ `,1)}function db(e,t){if(t===""||t.includes("\0"))return"No such file or directory";let n=t.replace(/\/+$/u,"");if(n==="")return"File exists";let r=E(e.cwd,n,e.fs,{follow:!1});if(r.error===null)return"File exists";if(r.error!=="No such file or directory"||t!==n)return r.error;let o=ze(e.cwd,n,e.fs);return o.rest.length>0?o.error:null}function pb(e,t,n){let r=Yn(e,ye(n),"m","physical"),o=Yn(e,t,"m","physical");return r.error||o.error?t:Ss(r.path,o.path)}function Bc(e,t){let n=V(e);return e?.fsError??(n.startsWith(t+": ")?n.slice(t.length+2):n)}function $s(e,t,n=2){n===1?e.stdout+=t:e.stderr+=t,e.events.push({fd:n,text:t})}var jc={cp:xc,rm:Cc,mkdir:Fc,touch:Lc,ln:Uc};function hb(e,t,n){let{positional:r}=N(t),o=te("tac",r,e,n),i=[];for(let{content:s}of o.inputs)i.push(...Ge(s).toReversed());return ne(i.join(""),o)}var Wc=1e6;function mb(e,t){let{flags:n,values:r,positional:o}=N(t,{short:["w"],valueShort:["s"],numericOperands:!0});if(o.length===0||o.length>3)return pe("seq [-w] [-s SEP] LAST | seq FIRST LAST | seq FIRST INCR LAST");let i=[];for(let p of o){if(!/^[+-]?\d+$/u.test(p))return Number.isFinite(Number(p))&&p.trim()!==""||/^[+-]?inf(?:inity)?$/iu.test(p)?v("feature","seq","non-integer operands","seq: non-integer operands are not supported"):x(`seq: invalid integer: ${p}`);i.push(BigInt(p))}let s=i.length===1?1n:i[0],u=i.length===3?i[1]:1n,a=i.at(-1);if(u===0n)return x("seq: increment must be non-zero");let f=(u>0?s<=a:s>=a)?(a>s?a-s:s-a)/(u>0n?u:-u)+1n:0;if(f>Wc)return v("feature","seq","sequence limit",`seq: range too large: ${f} elements exceeds limit of ${Wc}`);let c=n.has("w")?Math.max(...[o[0],o.at(-1)].map(p=>p.replace(/^\+/u,"").length)):0,d=[];for(let p=0,h=s;p<f;p++,h+=u)d.push(gb(String(h),c));return F(d.length===0?"":d.join(r.get("s")??`
65
81
  `)+`
66
- `)}function N0(e,t){if(e.length>=t)return e;let n=e.startsWith("-"),r=n?e.slice(1):e;return(n?"-":"")+r.padStart(t-(n?1:0),"0")}var fc=6,dc=" ",A0=" ".repeat(fc+dc.length);function I0(e,t,n){let{values:r,positional:i,order:o}=E(t,{valueShort:["b","v"],valueLong:["starting-line-number"]}),s=r.get("b")??"t";if(!["a","t","n"].includes(s)){let c=`nl: -b: only \`a\`, \`t\` and \`n\` are supported (got \`${s}\`)`;return s.startsWith("p")?v("option","nl","-b p",c):y(c)}let u=1n;for(let{name:c,value:f}of o)if(!(c!=="v"&&c!=="starting-line-number")){if(!/^[ \t\n\r\f\v]*[+-]?\d+$/u.test(f))return y(`nl: invalid starting line number: ${f}`);if(u=BigInt(f),u<Xe||u>J)return y(`nl: invalid starting line number: ${f}`)}let a=te("nl",i,e,n);if(a.inputs.some(({content:c})=>/(?:^|\n)(?:\\:){1,3}(?:\n|$)/u.test(c)))return v("feature","nl","logical pages","nl: logical page delimiters are not supported");let l=[];for(let{content:c}of a.inputs)for(let f of se(c))if(s==="a"||s==="t"&&f!==""){if(u>J)return{stdout:ce(l),stderr:a.stderr+`nl: line number overflow
67
- `,exitCode:1};l.push(`${String(u).padStart(fc)}${dc}${f}`),u++}else l.push(A0+f);return ue(ce(l),a)}function O0(e,t,n){let{flags:r,values:i,positional:o}=E(t,{short:["s"],valueShort:["d","f","c"]}),s=i.has("f"),u=i.has("c");if(s===u)return oe("cut -f LIST [-d DELIM] [-s] [file...] | cut -c LIST [file...]");if(u&&i.has("d"))return y("cut: -d is only valid with -f");if(u&&r.has("s"))return y("cut: -s is only valid with -f");let a=_0(s?i.get("f"):i.get("c"),s?"field":"position");if(a.error)return a.error;let l=i.get("d")===""?"\0":i.get("d")??" ";if(s&&I(l).length!==1)return y("cut: -d delimiter must be a single byte");let c=te("cut",o,e,n),f=[];for(let{content:d}of c.inputs)for(let p of s&&l===`
68
- `?d===""?[]:[d]:se(d)){if(s&&!p.includes(l)){r.has("s")||f.push(p);continue}f.push(s?L0(p,l,a.ranges):C0(p,a.ranges))}return ue(ce(f),c)}function C0(e,t){let n=I(e);return M(Uint8Array.from(pc(n,t)))}var F0={field:{zero:"fields are numbered from 1",range:"invalid field range",value:e=>`invalid field value '${e}'`,large:e=>`field number '${e}' is too large`},position:{zero:"byte/character positions are numbered from 1",range:"invalid byte or character range",value:e=>`invalid byte/character position '${e}'`,large:e=>`byte/character offset '${e}' is too large`}},T0=/^(\d*)(-?)(\d*)/u;function _0(e,t){let n=F0[t],r=s=>({error:y(`cut: ${s}`)}),i=[];for(let s of e.split(/[, \t]/u)){if(s==="")return r(n.zero);let[u,a,l,c]=T0.exec(s),f=s.slice(u.length);if(f!=="")return r(f.startsWith("-")?n.range:n.value(f));for(let m of[a,c])if(m!==""&&BigInt(m)>Ze)return r(n.large(m));if(a===""&&c===""&&l==="")return r(n.value(s));let d=a===""?1:Number(a),p=l===""?d:c===""?1/0:Number(c);if(d<1)return r(n.zero);if(p<d)return r("invalid decreasing range");i.push([d,p])}i.sort((s,u)=>s[0]-u[0]);let o=[];for(let s of i){let u=o.at(-1);u&&s[0]<=u[1]+1?u[1]=Math.max(u[1],s[1]):o.push(s)}return{ranges:o}}function pc(e,t){return t.flatMap(([n,r])=>Array.from(e.slice(n-1,r)))}function L0(e,t,n){let r=t===`
69
- `?se(e):e.split(t);return pc(r,n).join(t)}function R0(e,t,n){let{flags:r,positional:i}=E(t,{short:["c","d","s"]}),o=r.has("d"),s=r.has("s"),u=r.has("c");if(o&&s)return v("option","tr","-d -s","tr: -d combined with -s is not supported");if(s&&!o&&i.length===2)return v("feature","tr","translate and squeeze","tr: combined translation and squeezing is not supported");let a=o||s?1:2;if(i.length!==a)return oe("tr [-c] SET1 SET2 | tr [-c] -d SET | tr [-c] -s SET");if(/\P{ASCII}/u.test(e+i.join("")))return v("feature","tr","non-ASCII bytes","tr: translation of non-ASCII bytes is not supported");if(i.some(g=>/\[[:.=]|\[[^\]]*\*/u.test(g)))return v("feature","tr","set expressions","tr: character classes, equivalence classes and repetition expressions are not supported");if(i.some(g=>/\\[0-7]{2}|\\[1-7abfrv]/u.test(g)))return v("feature","tr","set escapes","tr: these set escape sequences are not supported");if(i.some(g=>/(?:^|[^\\])(?:\\\\)*\\$/u.test(g)))return v("feature","tr","trailing backslash","tr: an unescaped trailing backslash in a set is not supported");let l=cc(i[0]);if(l.error)return l.error;let c=new Set(l.chars),f=g=>u!==c.has(g);if(o)return z(n),C([...e].filter(g=>!f(g)).join(""));if(s)return z(n),C(M0(e,f));let d=cc(i[1]);if(d.error)return d.error;if(d.chars.length===0)return y("tr: when not truncating set1, string2 must be non-empty");z(n);let p=u?Array.from({length:256},(g,x)=>String.fromCodePoint(x)).filter(g=>!c.has(g)):l.chars,m=new Map,h=d.chars.at(-1);for(let g=0;g<p.length;g++)m.set(p[g],d.chars[g]??h);return C([...e].map(g=>m.get(g)??g).join(""))}function cc(e){let t=[],n=0,r=()=>{if(e[n]!=="\\")return e[n++];if(n+1>=e.length)return null;let i=e[n+1];return n+=2,i==="n"?`
70
- `:i==="t"?" ":i==="\\"?"\\":i==="0"?"\0":i};for(;n<e.length;){let i=r();if(e[n]==="-"&&n+1<e.length){n++;let o=r();if(o===null)return{error:y("tr: trailing backslash in set")};let s=i.codePointAt(0),u=o.codePointAt(0);if(u<s)return{error:y(`tr: range-endpoints of '${i}-${o}' are in reverse collating sequence order`)};for(let a=s;a<=u;a++)t.push(String.fromCodePoint(a))}else t.push(i)}return{chars:t}}function M0(e,t){let n="",r=null;for(let i of e)t(i)&&i===r||(n+=i,r=i);return n}function P0(e,t,n){let{positional:r}=E(t);if(r.length===0)return oe("which COMMAND...");let i=[],o=0;for(let s of r)n.hasCommand(s)?i.push(`/usr/bin/${s}`):(i.push(`${s} not found`),o=1);return{stdout:ce(i),stderr:"",exitCode:o}}function D0(e,t,n){let{positional:r}=E(t);return r.length>0?y(`whoami: extra operand: ${r[0]}`):C((n.user??"user")+`
71
- `)}function U0(e,t,n){let{flags:r,positional:i}=E(t,{short:["u"]});if(i.length>1)return y(`date: at most one +FORMAT argument is supported (got: ${i[1]})`);let o="%a %b %e %T %Z %Y";if(i.length===1){if(!i[0].startsWith("+"))return oe("date [-u] [+FORMAT]");o=i[0].slice(1)}return(o.match(/%./gu)??[]).some(s=>/%[-_0^#0-9:EOcCDgGhIjklNpPrRuUVwWxXy+]/u.test(s))?v("feature","date","format","date: this format directive or modifier is not supported"):C(Wo(new Date,o,r.has("u")||n.vars.has("TZ"))+`
72
- `)}var B0=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],W0=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],z0=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],q0=["January","February","March","April","May","June","July","August","September","October","November","December"];function Wo(e,t,n){let r="get"+(n?"UTC":""),[i,o,s,u,a,l,c]=["FullYear","Month","Date","Hours","Minutes","Seconds","Day"].map(p=>e[r+p]()),f=(p,m="0")=>String(p).padStart(2,m),d={__proto__:null,Y:String(i),m:f(o+1),d:f(s),e:f(s," "),H:f(u),M:f(a),S:f(l),T:[u,a,l].map(p=>f(p)).join(":"),F:[i,f(o+1),f(s)].join("-"),q:String(Math.floor(o/3)+1),s:String(Math.floor(e.getTime()/1e3)),a:B0[c],A:W0[c],b:z0[o],B:q0[o],Z:()=>j0(e,n),z:()=>H0(e,n),n:`
73
- `,t:" ","%":"%"};return t.replace(/%./gu,p=>{let m=d[p[1]];return typeof m=="function"?m():m??p})}function j0(e,t){if(t)return"UTC";try{return new Intl.DateTimeFormat("en-US",{timeZoneName:"short"}).formatToParts(e).find(i=>i.type==="timeZoneName")?.value??"Local"}catch{return"Local"}}function H0(e,t){if(t)return"+0000";let n=-e.getTimezoneOffset(),r=n>=0?"+":"-",i=Math.abs(n);return`${r}${String(Math.floor(i/60)).padStart(2,"0")}${String(i%60).padStart(2,"0")}`}var hc={rg:Vl,cut:O0,tac:E0,tr:R0,seq:$0,nl:I0,which:P0,hexdump:Ra,base64:ol,...ac},mc={whoami:D0,date:U0,od:Ma,xxd:Pa};var zo=new Map(Object.entries({all:"a","apparent-size":"A",bytes:"b",total:"c",null:"0","count-links":"l",summarize:"s","separate-dirs":"S","human-readable":"h","max-depth":"d","block-size":"B",dereference:"L","dereference-args":"D","no-dereference":"P"}));function wc(e,t){let n=E(e,{short:["0","a","A","b","c","h","H","k","l","m","s","S","L","D","P"],long:[...zo.keys()].filter(o=>!["d","B"].includes(zo.get(o))).concat(["inodes","si"]),valueShort:["d","B"],valueLong:["max-depth","block-size"]}),r={operands:n.positional.length?n.positional:["."],depth:1/0,flags:new Set,scale:null,stderr:""};for(let{name:o,value:s}of n.order){let u=zo.get(o)??o;r.flags.add(u),u==="d"&&(r.depth=G0(s)),u==="B"&&(r.scale=gc(s)),u==="b"&&(r.flags.add("A"),r.scale={unit:1n}),(u==="k"||u==="m")&&(r.scale={unit:u==="k"?1024n:1024n**2n}),(u==="h"||u==="si")&&(r.scale={base:u==="h"?1024n:1000n,unit:1n})}let{flags:i}=r;if(i.has("a")&&i.has("s"))throw new Error("cannot both summarize and show all entries");if(i.has("s")&&i.has("d")){if(r.depth!==0)throw new Error(`summarizing conflicts with --max-depth=${r.depth}`);r.stderr+=`du: warning: summarizing is the same as using --max-depth=0
74
- `}if(i.has("s")&&(r.depth=0),i.has("inodes")&&i.has("A")&&(r.stderr+=`du: warning: options --apparent-size and -b are ineffective with --inodes
75
- `),!r.scale){let o=t.vars.get("DU_BLOCK_SIZE")??t.vars.get("BLOCK_SIZE")??t.vars.get("BLOCKSIZE");try{r.scale=o===void 0?{unit:t.vars.has("POSIXLY_CORRECT")?512n:1024n}:gc(o)}catch(s){throw s instanceof w?s:new w("feature","invalid block size environment","invalid block size environment settings are not supported")}}return i.has("inodes")&&(r.scale={...r.scale,unit:1n,suffix:r.scale.suffix?.endsWith("B")?"B":""}),r.scale.base&&jo(t,r.scale.base),r}function jo(e,t=1024n){let n=e.vars.get("LC_ALL")||e.vars.get("LC_NUMERIC")||e.locale;if(!/^(?:C|POSIX|C\.UTF-?8)$/iu.test(n))throw new w("feature","numeric locale","human-readable sizes in this numeric locale are not supported");return{base:t,unit:1n}}function G0(e){let t=/^[ \t\n\r\v\f]*([+-]?)(0[xX][\da-fA-F]+|0[0-7]*|[1-9]\d*)$/u.exec(e);if(!t)throw new Error(`invalid maximum depth: ${e}`);let n=xc(t[2]);if(n>J||t[1]==="-"&&n!==0n)throw new Error(`invalid maximum depth: ${e}`);return Number(n)}function xc(e){return BigInt(/^0[0-7]+$/u.test(e)?"0o"+e:e)}function gc(e){let t=e&&["human-readable","si"].find(a=>a.startsWith(e));if(t)return{base:t==="si"?1000n:1024n,unit:1n};if(e.startsWith("'"))throw new w("feature","grouped block sizes","grouped block sizes are not supported");let n=/^[ \t\n\r\v\f]*\+?(0[xX][\da-fA-F]+|0[0-7]*|[1-9]\d*)?([kKmMgGtTPEZYRQ](?:i?B|D)?)?$/u.exec(e);if(!n||!n[1]&&e!==n[2])throw new Error(`invalid block size: ${e}`);let r=n[2]??"",i=r?"KMGTPEZYRQ".indexOf(r[0].toUpperCase())+1:0,o=/[BD]$/u.test(r)&&!r.endsWith("iB")?1000n:1024n,s=(n[1]?xc(n[1]):1n)*o**BigInt(i);if(s===0n||s>Ze)throw new Error(`invalid block size: ${e}`);let u=n[1]||!r?"":(i===1&&r.endsWith("B")&&o===1000n?"k":r[0].toUpperCase())+(r.endsWith("B")?o===1000n?"B":"iB":"");return{unit:s,suffix:u}}var qo=(e,t)=>(e+t-1n)/t;function Pn(e,{base:t,unit:n,suffix:r=""}){if(!t)return String(qo(e,n))+r;let i=1n,o=0;for(;e>=i*t;)i*=t,o++;if(!o)return String(e);let s=qo(e*10n,i),u;return s<100n?u=`${s/10n}.${s%10n}`:(s=qo(e,i),s===t?(o++,u="1.0"):u=String(s)),u+(o===1&&t===1000n?"k":"KMGTPEZYRQ"[o-1])}var Ho=4096,yc=Ho/512,X0=31556952*1e3/2;function bc(e,t){for(let c of["LS_BLOCK_SIZE","BLOCK_SIZE","BLOCKSIZE"])if(e.vars.has(c))throw new w("feature","block size environment",`${c} is not supported in a long listing`);let n=t?jo(e):null,r=e.user??"user",i=e.createdAt,o=Date.now(),s=i<=o&&o-i<X0,u=Wo(new Date(i),s?"%b %e %H:%M":"%b %e %Y",e.vars.has("TZ")),a=c=>n?Pn(BigInt(c),n):String(c),l=c=>Math.max(0,...c.map(f=>f.length));return{lines(c,f){let d=c.map(({name:g,abs:x,dir:b})=>{let S=b?Ho:e.fs.fileSize(x)??ee(e.fs.readFile(x)).length,A=b?yc:Math.ceil(S/Ho)*yc;return{name:g,dir:b,units:A,links:String(b?2+e.fs.listDir(x).dirs.length:1),size:a(S)}}),p=l(d.map(g=>g.links)),m=l(d.map(g=>g.size)),h=d.map(g=>`${g.dir?"drwx------":"-rw-------"} ${g.links.padStart(p)} ${r} ${r} ${g.size.padStart(m)} ${u} ${g.name}`);if(f){let g=d.reduce((x,b)=>x+b.units,0);h.unshift("total "+(n?Pn(BigInt(g)*512n,n):String(g/2)))}return h}}}function vc(e,t,n){let{flags:r,values:i,positional:o}=E(t,{short:["a","d","F"],long:["noreport"],valueShort:["L"]});if(o.length>1)return v("feature","tree","multiple roots","tree: multiple roots are not supported");let s=i.has("L")?pe(i.get("L"),"tree: -L",i.get("L"),{max:2147483647}):{value:Number.POSITIVE_INFINITY};if(s.error)return s.error;if(!s.value)return y("tree: -L must be greater than zero");let u=o[0]??".",{path:a,error:l}=P(n,"tree",u),c=!l&&n.fs.isDir(a),f={dirs:c&&Dr(n.fs,a,r).length?1:0,files:!l&&!c?1:0},d=r.has("F")&&!u.endsWith("/")?"/":"",p=[u+(c?d:" [error opening dir]")];if(c){let m=new Set,h=Pt();try{let g=Z0(n.fs,a,p,r,s.value,f,m,h);if(g)return g}finally{st(n.notes,{command:"tree",action:"depth limit omitted contents of",noun:["directory","directories"],paths:m}),h.emit(n.notes,"tree","Hidden entries are included with -a.")}}if(!r.has("noreport")){let m=`${f.dirs} ${f.dirs===1?"directory":"directories"}`,h=`${f.files} ${f.files===1?"file":"files"}`;p.push("",r.has("d")?m:`${m}, ${h}`)}return{stdout:p.join(`
82
+ `)}function gb(e,t){if(e.length>=t)return e;let n=e.startsWith("-"),r=n?e.slice(1):e;return(n?"-":"")+r.padStart(t-(n?1:0),"0")}var zc=6,Hc=" ",wb=" ".repeat(zc+Hc.length);function yb(e,t,n){let{values:r,positional:o,order:i}=N(t,{valueShort:["b","v"],valueLong:["starting-line-number"]}),s=r.get("b")??"t";if(!["a","t","n"].includes(s)){let f=`nl: -b: only \`a\`, \`t\` and \`n\` are supported (got \`${s}\`)`;return s.startsWith("p")?v("option","nl","-b p",f):x(f)}let u=1n;for(let{name:f,value:c}of i)if(!(f!=="v"&&f!=="starting-line-number")){if(!/^[ \t\n\r\f\v]*[+-]?\d+$/u.test(c))return x(`nl: invalid starting line number: ${c}`);if(u=BigInt(c),u<ot||u>ue)return x(`nl: invalid starting line number: ${c}`)}let a=te("nl",o,e,n);if(a.inputs.some(({content:f})=>/(?:^|\n)(?:\\:){1,3}(?:\n|$)/u.test(f)))return v("feature","nl","logical pages","nl: logical page delimiters are not supported");let l=[];for(let{content:f}of a.inputs)for(let c of he(f))if(s==="a"||s==="t"&&c!==""){if(u>ue)return{stdout:ge(l),stderr:a.stderr+`nl: line number overflow
83
+ `,exitCode:1};l.push(`${String(u).padStart(zc)}${Hc}${c}`),u++}else l.push(wb+c);return ne(ge(l),a)}function bb(e,t,n){let{flags:r,values:o,positional:i}=N(t,{short:["s"],valueShort:["d","f","c"]}),s=o.has("f"),u=o.has("c");if(s===u)return pe("cut -f LIST [-d DELIM] [-s] [file...] | cut -c LIST [file...]");if(u&&o.has("d"))return x("cut: -d is only valid with -f");if(u&&r.has("s"))return x("cut: -s is only valid with -f");let a=Sb(s?o.get("f"):o.get("c"),s?"field":"position");if(a.error)return a.error;let l=o.get("d")===""?"\0":o.get("d")??" ";if(s&&A(l).length!==1)return x("cut: -d delimiter must be a single byte");let f=te("cut",i,e,n),c=[];for(let{content:d}of f.inputs)for(let p of s&&l===`
84
+ `?d===""?[]:[d]:he(d)){if(s&&!p.includes(l)){r.has("s")||c.push(p);continue}c.push(s?Eb(p,l,a.ranges):xb(p,a.ranges))}return ne(ge(c),f)}function xb(e,t){let n=A(e);return W(Uint8Array.from(Gc(n,t)))}var kb={field:{zero:"fields are numbered from 1",range:"invalid field range",value:e=>`invalid field value '${e}'`,large:e=>`field number '${e}' is too large`},position:{zero:"byte/character positions are numbered from 1",range:"invalid byte or character range",value:e=>`invalid byte/character position '${e}'`,large:e=>`byte/character offset '${e}' is too large`}},vb=/^(\d*)(-?)(\d*)/u;function Sb(e,t){let n=kb[t],r=s=>({error:x(`cut: ${s}`)}),o=[];for(let s of e.split(/[, \t]/u)){if(s==="")return r(n.zero);let[u,a,l,f]=vb.exec(s),c=s.slice(u.length);if(c!=="")return r(c.startsWith("-")?n.range:n.value(c));for(let h of[a,f])if(h!==""&&BigInt(h)>it)return r(n.large(h));if(a===""&&f===""&&l==="")return r(n.value(s));let d=a===""?1:Number(a),p=l===""?d:f===""?1/0:Number(f);if(d<1)return r(n.zero);if(p<d)return r("invalid decreasing range");o.push([d,p])}o.sort((s,u)=>s[0]-u[0]);let i=[];for(let s of o){let u=i.at(-1);u&&s[0]<=u[1]+1?u[1]=Math.max(u[1],s[1]):i.push(s)}return{ranges:i}}function Gc(e,t){return t.flatMap(([n,r])=>Array.from(e.slice(n-1,r)))}function Eb(e,t,n){let r=t===`
85
+ `?he(e):e.split(t);return Gc(r,n).join(t)}function $b(e,t,n){let{flags:r,positional:o}=N(t,{short:["c","d","s"]}),i=r.has("d"),s=r.has("s"),u=r.has("c");if(i&&s)return v("option","tr","-d -s","tr: -d combined with -s is not supported");if(s&&!i&&o.length===2)return v("feature","tr","translate and squeeze","tr: combined translation and squeezing is not supported");let a=i||s?1:2;if(o.length!==a)return pe("tr [-c] SET1 SET2 | tr [-c] -d SET | tr [-c] -s SET");if(/\P{ASCII}/u.test(e+o.join("")))return v("feature","tr","non-ASCII bytes","tr: translation of non-ASCII bytes is not supported");if(o.some(g=>/\[[:.=]|\[[^\]]*\*/u.test(g)))return v("feature","tr","set expressions","tr: character classes, equivalence classes and repetition expressions are not supported");if(o.some(g=>/\\[0-7]{2}|\\[1-7abfrv]/u.test(g)))return v("feature","tr","set escapes","tr: these set escape sequences are not supported");if(o.some(g=>/(?:^|[^\\])(?:\\\\)*\\$/u.test(g)))return v("feature","tr","trailing backslash","tr: an unescaped trailing backslash in a set is not supported");let l=qc(o[0]);if(l.error)return l.error;let f=new Set(l.chars),c=g=>u!==f.has(g);if(i)return q(n),F([...e].filter(g=>!c(g)).join(""));if(s)return q(n),F(Nb(e,c));let d=qc(o[1]);if(d.error)return d.error;if(d.chars.length===0)return x("tr: when not truncating set1, string2 must be non-empty");q(n);let p=u?Array.from({length:256},(g,w)=>String.fromCodePoint(w)).filter(g=>!f.has(g)):l.chars,h=new Map,m=d.chars.at(-1);for(let g=0;g<p.length;g++)h.set(p[g],d.chars[g]??m);return F([...e].map(g=>h.get(g)??g).join(""))}function qc(e){let t=[],n=0,r=()=>{if(e[n]!=="\\")return e[n++];if(n+1>=e.length)return null;let o=e[n+1];return n+=2,o==="n"?`
86
+ `:o==="t"?" ":o==="\\"?"\\":o==="0"?"\0":o};for(;n<e.length;){let o=r();if(e[n]==="-"&&n+1<e.length){n++;let i=r();if(i===null)return{error:x("tr: trailing backslash in set")};let s=o.codePointAt(0),u=i.codePointAt(0);if(u<s)return{error:x(`tr: range-endpoints of '${o}-${i}' are in reverse collating sequence order`)};for(let a=s;a<=u;a++)t.push(String.fromCodePoint(a))}else t.push(o)}return{chars:t}}function Nb(e,t){let n="",r=null;for(let o of e)t(o)&&o===r||(n+=o,r=o);return n}function Ab(e,t,n){let{positional:r}=N(t);if(r.length===0)return pe("which COMMAND...");let o=[],i=0;for(let s of r)n.hasCommand(s)?o.push(`/usr/bin/${s}`):(o.push(`${s} not found`),i=1);return{stdout:ge(o),stderr:"",exitCode:i}}function Ob(e,t,n){let{positional:r}=N(t);return r.length>0?x(`whoami: extra operand: ${r[0]}`):F((n.user??"user")+`
87
+ `)}function Cb(e,t,n){let{flags:r,positional:o}=N(t,{short:["u"]});if(o.length>1)return x(`date: at most one +FORMAT argument is supported (got: ${o[1]})`);let i="%a %b %e %T %Z %Y";if(o.length===1){if(!o[0].startsWith("+"))return pe("date [-u] [+FORMAT]");i=o[0].slice(1)}return(i.match(/%./gu)??[]).some(s=>/%[-_0^#0-9:EOcCDgGhIjklNpPrRuUVwWxXy+]/u.test(s))?v("feature","date","format","date: this format directive or modifier is not supported"):F(Ns(new Date,i,r.has("u")||n.vars.has("TZ"))+`
88
+ `)}var Ib=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Tb=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],Fb=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Lb=["January","February","March","April","May","June","July","August","September","October","November","December"];function Ns(e,t,n){let r="get"+(n?"UTC":""),[o,i,s,u,a,l,f]=["FullYear","Month","Date","Hours","Minutes","Seconds","Day"].map(p=>e[r+p]()),c=(p,h="0")=>String(p).padStart(2,h),d={__proto__:null,Y:String(o),m:c(i+1),d:c(s),e:c(s," "),H:c(u),M:c(a),S:c(l),T:[u,a,l].map(p=>c(p)).join(":"),F:[o,c(i+1),c(s)].join("-"),q:String(Math.floor(i/3)+1),s:String(Math.floor(e.getTime()/1e3)),a:Ib[f],A:Tb[f],b:Fb[i],B:Lb[i],Z:()=>_b(e,n),z:()=>Rb(e,n),n:`
89
+ `,t:" ","%":"%"};return t.replace(/%./gu,p=>{let h=d[p[1]];return typeof h=="function"?h():h??p})}function _b(e,t){if(t)return"UTC";try{return new Intl.DateTimeFormat("en-US",{timeZoneName:"short"}).formatToParts(e).find(o=>o.type==="timeZoneName")?.value??"Local"}catch{return"Local"}}function Rb(e,t){if(t)return"+0000";let n=-e.getTimezoneOffset(),r=n>=0?"+":"-",o=Math.abs(n);return`${r}${String(Math.floor(o/60)).padStart(2,"0")}${String(o%60).padStart(2,"0")}`}var Xc={rg:wc,cut:bb,tac:hb,tr:$b,seq:mb,nl:yb,which:Ab,hexdump:lf,base64:vf,...jc},Zc={whoami:Ob,date:Cb,od:ff,xxd:cf,base32:kf,...of};var As=new Map(Object.entries({all:"a","apparent-size":"A",bytes:"b",total:"c",null:"0","count-links":"l",summarize:"s","separate-dirs":"S","human-readable":"h","max-depth":"d","block-size":"B",dereference:"L","dereference-args":"D","no-dereference":"P"})),Yc={P:"none",D:"args",H:"args",L:"all"};function Kc(e,t){let n=N(e,{short:["0","a","A","b","c","h","H","k","l","m","s","S","L","D","P"],long:[...As.keys()].filter(i=>!["d","B"].includes(As.get(i))).concat(["inodes","si"]),valueShort:["d","B"],valueLong:["max-depth","block-size"]}),r={operands:n.positional.length?n.positional:["."],depth:1/0,flags:new Set,links:"none",scale:null,stderr:""};for(let{name:i,value:s}of n.order){let u=As.get(i)??i;r.flags.add(u),Object.hasOwn(Yc,u)&&(r.links=Yc[u]),u==="d"&&(r.depth=Mb(s)),u==="B"&&(r.scale=Vc(s)),u==="b"&&(r.flags.add("A"),r.scale={unit:1n}),(u==="k"||u==="m")&&(r.scale={unit:u==="k"?1024n:1024n**2n}),(u==="h"||u==="si")&&(r.scale={base:u==="h"?1024n:1000n,unit:1n})}let{flags:o}=r;if(o.has("a")&&o.has("s"))throw new Error("cannot both summarize and show all entries");if(o.has("s")&&o.has("d")){if(r.depth!==0)throw new Error(`summarizing conflicts with --max-depth=${r.depth}`);r.stderr+=`du: warning: summarizing is the same as using --max-depth=0
90
+ `}if(o.has("s")&&(r.depth=0),o.has("inodes")&&o.has("A")&&(r.stderr+=`du: warning: options --apparent-size and -b are ineffective with --inodes
91
+ `),!r.scale){let i=t.vars.get("DU_BLOCK_SIZE")??t.vars.get("BLOCK_SIZE")??t.vars.get("BLOCKSIZE");try{r.scale=i===void 0?{unit:t.vars.has("POSIXLY_CORRECT")?512n:1024n}:Vc(i)}catch(s){throw s instanceof b?s:new b("feature","invalid block size environment","invalid block size environment settings are not supported")}}return o.has("inodes")&&(r.scale={...r.scale,unit:1n,suffix:r.scale.suffix?.endsWith("B")?"B":""}),r.scale.base&&Cs(t,r.scale.base),r}function Cs(e,t=1024n){let n=e.vars.get("LC_ALL")||e.vars.get("LC_NUMERIC")||e.locale;if(!/^(?:C|POSIX|C\.UTF-?8)$/iu.test(n))throw new b("feature","numeric locale","human-readable sizes in this numeric locale are not supported");return{base:t,unit:1n}}function Mb(e){let t=/^[ \t\n\r\v\f]*([+-]?)(0[xX][\da-fA-F]+|0[0-7]*|[1-9]\d*)$/u.exec(e);if(!t)throw new Error(`invalid maximum depth: ${e}`);let n=Jc(t[2]);if(n>ue||t[1]==="-"&&n!==0n)throw new Error(`invalid maximum depth: ${e}`);return Number(n)}function Jc(e){return BigInt(/^0[0-7]+$/u.test(e)?"0o"+e:e)}function Vc(e){let t=e&&["human-readable","si"].find(a=>a.startsWith(e));if(t)return{base:t==="si"?1000n:1024n,unit:1n};if(e.startsWith("'"))throw new b("feature","grouped block sizes","grouped block sizes are not supported");let n=/^[ \t\n\r\v\f]*\+?(0[xX][\da-fA-F]+|0[0-7]*|[1-9]\d*)?([kKmMgGtTPEZYRQ](?:i?B|D)?)?$/u.exec(e);if(!n||!n[1]&&e!==n[2])throw new Error(`invalid block size: ${e}`);let r=n[2]??"",o=r?"KMGTPEZYRQ".indexOf(r[0].toUpperCase())+1:0,i=/[BD]$/u.test(r)&&!r.endsWith("iB")?1000n:1024n,s=(n[1]?Jc(n[1]):1n)*i**BigInt(o);if(s===0n||s>it)throw new Error(`invalid block size: ${e}`);let u=n[1]||!r?"":(o===1&&r.endsWith("B")&&i===1000n?"k":r[0].toUpperCase())+(r.endsWith("B")?i===1000n?"B":"iB":"");return{unit:s,suffix:u}}var Vn=4096,Pb=60,lo=(e,t)=>t==="dir"?Vn:t==="link"&&e<Pb?0:Math.ceil(e/Vn)*Vn,Os=(e,t)=>(e+t-1n)/t;function Kn(e,{base:t,unit:n,suffix:r=""}){if(!t)return String(Os(e,n))+r;let o=1n,i=0;for(;e>=o*t;)o*=t,i++;if(!i)return String(e);let s=Os(e*10n,o),u;return s<100n?u=`${s/10n}.${s%10n}`:(s=Os(e,o),s===t?(i++,u="1.0"):u=String(s)),u+(i===1&&t===1000n?"k":"KMGTPEZYRQ"[i-1])}var Db=31556952*1e3/2;function Qc(e,t){for(let f of["LS_BLOCK_SIZE","BLOCK_SIZE","BLOCKSIZE"])if(e.vars.has(f))throw new b("feature","block size environment",`${f} is not supported in a long listing`);let n=t?Cs(e):null,r=e.user??"user",o=e.createdAt,i=Date.now(),s=o<=i&&i-o<Db,u=Ns(new Date(o),s?"%b %e %H:%M":"%b %e %Y",e.vars.has("TZ")),a=f=>n?Kn(BigInt(f),n):String(f),l=f=>Math.max(0,...f.map(c=>c.length));return{lines(f,c){let d=f.map(({name:g,abs:w,kind:y,target:k})=>{let S=y==="dir",I=S?Vn:e.fs.fileSize(w)??B(e.fs.readFile(w)).length,M=S?"drwx------":y==="link"?"lrwxrwxrwx":"-rw-------",C=lo(I,y)/512;return{name:y==="link"?`${g} -> ${k}`:g,mode:M,units:C,links:String(S?2+e.fs.listDir(w).dirs.length:1),size:a(I)}}),p=l(d.map(g=>g.links)),h=l(d.map(g=>g.size)),m=d.map(g=>`${g.mode} ${g.links.padStart(p)} ${r} ${r} ${g.size.padStart(h)} ${u} ${g.name}`);if(c){let g=d.reduce((w,y)=>w+y.units,0);m.unshift("total "+(n?Kn(BigInt(g)*512n,n):String(g/2)))}return m}}}function ed(e,t,n){let{flags:r,values:o,positional:i}=N(t,{short:["a","d","F"],long:["noreport"],valueShort:["L"]});if(i.length>1)return v("feature","tree","multiple roots","tree: multiple roots are not supported");let s=o.has("L")?be(o.get("L"),"tree: -L",o.get("L"),{max:2147483647}):{value:Number.POSITIVE_INFINITY};if(s.error)return s.error;if(!s.value)return x("tree: -L must be greater than zero");let u=i[0]??".",{path:a,error:l}=P(n,"tree",u),f=!l&&n.fs.isDir(a),c=E(n.cwd,u,n.fs,{follow:!1}),d=!!l&&!!c.error,p={dirs:f&&fo(n.fs,a,r).length?1:0,files:!d&&!f?1:0},h=[u+Bb(n,r,c,f)+(f?"":" [error opening dir]")];if(f){let m=new Set,g=Jt();try{let w=Ub(n.fs,a,h,r,s.value,p,m,g);if(w)return w}finally{gt(n.notes,{command:"tree",action:"depth limit omitted contents of",noun:["directory","directories"],paths:m}),g.emit(n.notes,"tree","Hidden entries are included with -a.")}}if(!r.has("noreport")){let m=`${p.dirs} ${p.dirs===1?"directory":"directories"}`,g=`${p.files} ${p.files===1?"file":"files"}`;h.push("",r.has("d")?m:`${m}, ${g}`)}return{stdout:h.join(`
76
92
  `)+`
77
- `,stderr:"",exitCode:l?2:0}}function Z0(e,t,n,r,i,o,s,u){let a=[{dir:t,prefix:"",items:Dr(e,t,r,u),i:0,depth:0}];for(;a.length;){let l=a.at(-1);if(l.i>=l.items.length){a.pop();continue}let{n:c,isDir:f}=l.items[l.i++];if([...c].some(h=>h.codePointAt(0)<32||h.codePointAt(0)===127||h==="\\"))return v("feature","tree","filename escaping","tree: listing names requiring escaping is not supported");let d=l.i===l.items.length;if(n.push(l.prefix+(d?"\u2514\u2500\u2500 ":"\u251C\u2500\u2500 ")+c+(f&&r.has("F")?"/":"")),o[f?"dirs":"files"]++,!f)continue;let p=Ce(l.dir,c);if(l.depth+1>=i){Dr(e,p,r).length&&s.add(p);continue}let m=Dr(e,p,r,u);a.push({dir:p,prefix:l.prefix+(d?" ":"\u2502\xA0\xA0 "),items:m,i:0,depth:l.depth+1})}}function Dr(e,t,n,r=null){let{dirs:i,files:o}=e.listDir(t);return r&&!n.has("a")&&r.collect(t,n.has("d")?i:[...i,...o]),[...i.map(s=>({n:s,isDir:!0})),...n.has("d")?[]:o.map(s=>({n:s,isDir:!1}))].filter(({n:s})=>n.has("a")||!s.startsWith(".")).sort((s,u)=>U(s.n,u.n))}var V0=new Set(["name","iname","type","path","ipath","mindepth","maxdepth"]),Dn=(e,t)=>e==="-"+t||e==="--"+t;function kc(e){let t={tokens:e,i:0,depth:{minDepth:0,maxDepth:Number.POSITIVE_INFINITY},hasAction:!1,batches:[],error:null},n=[];for(e[0]==="--"&&t.i++;t.i<e.length&&!/^(?:-.+|!|\()$/u.test(e[t.i]);)n.push(e[t.i++]);let r=Sc(t,0);if(t.error)return{error:t.error};if(!t.hasAction)for(let i of r)i.push({kind:"print"});return{starts:n.length?n:["."],...t.depth,groups:r,batches:t.batches}}function Sc(e,t){let n=[[]],r=!1;if(t>128)return e.error=v("feature","find","expression depth","find: expression nesting above 128 is not supported"),n;for(;e.i<e.tokens.length&&!e.error;){let i=e.tokens[e.i];if(i===")"){t||(e.error=y("find: unexpected closing parenthesis"));break}if(i==="-a"||Dn(i,"and")||i==="-o"||Dn(i,"or")){if(r||n.at(-1).length===0){e.error=y(`find: ${i} with no left-hand expression`);break}(i==="-o"||Dn(i,"or"))&&n.push([]),e.i++,r=i;continue}let o=Y0(e,t);o&&n.at(-1).push(o),r=!1}return!e.error&&r&&(e.error=y(`find: ${r} with no right-hand expression`)),!e.error&&t&&n.at(-1).length===0&&(e.error=y("find: expected an expression")),!e.error&&t&&(e.tokens[e.i]===")"?e.i++:e.error=y("find: missing closing parenthesis")),n}function Y0(e,t){let n=e.i,r=!1;for(;e.tokens[e.i]==="!"||e.tokens[e.i]==="-not";)r=!r,e.i++;let i=e.tokens[e.i++];if(i==="(")return{kind:"group",groups:Sc(e,t+1),negate:r};if(i===void 0||i===")"||i==="-a"||i==="-o"||Dn(i,"and")||Dn(i,"or"))return e.error=y(`find: -not or operator ${i??""} must be followed by a primary`),null;let o=i.startsWith("--")?i.slice(2):i.startsWith("-")?i.slice(1):null;if(["print","print0","prune","empty"].includes(o))return(o==="print"||o==="print0")&&(e.hasAction=!0),{kind:o,negate:r};if(o==="exec"){let s=ex(e.tokens,e.i-1,r);return s.error?(e.error=s.error,null):(e.i=s.nextI+1,e.hasAction=!0,s.pred.mode==="batch"&&e.batches.push(s.pred),s.pred)}if(V0.has(o)){if(e.i===e.tokens.length)return e.error=y(`find: ${i} requires a value`),null;let s=K0(o,e.tokens[e.i++],r,e.depth);return s.error?(e.error=s.error,null):s}return i===","?(e.error=v("feature","find","comma operator","find: comma expressions are not supported"),null):e.i-1>n&&!i.startsWith("-")?(e.error=y(`find: -not must be followed by a primary, got: ${i}`),null):(e.error=i==="--"||!i.startsWith("-")?y(`find: paths must precede expression: ${i}`):v("option","find",i,`find: unknown option: ${i}`),null)}function K0(e,t,n,r){if(e==="type"){let i=Q0(t);return i.error?i:{kind:e,negate:n,types:i.types}}if(e==="mindepth"||e==="maxdepth"){let i=pe(t,`find: -${e}`,t,{max:2147483647,digitsOnly:!0});return i.error?i:(r[e==="mindepth"?"minDepth":"maxDepth"]=i.value,{kind:"true",negate:n})}return{kind:e,negate:n,re:$e(t,{ignoreCase:e==="iname"||e==="ipath"})}}var J0="lbcps";function Q0(e){let t=e.split(","),n=t.find((o,s)=>t.indexOf(o)!==s);if(n!==void 0)return{error:y(`find: Duplicate file type '${n}' in the argument list to -type.`)};if(t.every(o=>o==="f"||o==="d"))return{types:t};let r=`find: -type/--type expects 'f' or 'd', got: ${e}`;return{error:t.every(o=>o.length===1&&("fd"+J0).includes(o))?v("option","find",`-type ${e}`,r):y(r)}}function ex(e,t,n){let r=t+1;for(;r<e.length&&e[r]!==";"&&!(e[r]==="+"&&e[r-1]==="{}");)r++;if(r>=e.length)return{error:y("find: -exec: missing terminator (`;` or `{} +`); quote or escape `;`")};if(r===t+1)return{error:y("find: -exec: requires a command")};let i=e.slice(t+1,r),o=e[r]===";"?"each":"batch";if(o==="batch"){if(i.slice(0,-1).some(u=>u.includes("{}")))return{error:y("find: -exec ... +: only one instance of `{}` is supported")};if(n)return{error:v("feature","find","-not -exec ... +","find: `-not -exec ... +` is not supported (the `+` form has no meaningful negation)")}}let s={kind:"exec",mode:o,cmd:i[0],args:i.slice(1),negate:n};return o==="batch"&&(s.collected=[]),{pred:s,nextI:r}}function Ec(e,t,n){let r=kc(t);if(r.error)return r.error;if(e!==""&&t.some(f=>f==="-exec"||f==="--exec"))return v("feature","find","-exec stdin","find: passing shared standard input to -exec is not supported");let{starts:i,minDepth:o,maxDepth:s,groups:u,batches:a}=r,l=R(),c=new Set;try{for(let f of i){let{path:d,error:p}=P(n,"find",f);if(p){Go(l,n.flushOutput(R(`find: '${f}': ${p}
78
- `))),l.exitCode=1;continue}let m=new Set;for(let h of Fe(n.fs,d,s,g=>!m.has(g))){let g=nx(f,d,h.path);if(h.depth>=o&&$c(u,{kind:h.kind,path:g,abs:h.path,prune:m},n,l),h.kind!=="dir"||h.depth!==s||m.has(h.path))continue;let{dirs:x,files:b}=n.fs.listDir(h.path);(x.length||b.length)&&c.add(g)}}for(let f of a){if(f.collected.length===0)continue;let d=f.args.slice(0,-1).concat(f.collected);Nc(f.cmd,d,n,l)||(l.exitCode=1)}}finally{st(n.notes,{command:"find",action:"depth limit omitted contents of",noun:["directory","directories"],paths:c})}return l}function $c(e,t,n,r){return e.some(i=>i.every(o=>tx(o,t,n,r)!==!!o.negate))}function tx(e,t,n,r){if(e.kind==="group")return $c(e.groups,t,n,r);if(e.kind==="true")return!0;if(e.kind==="type")return e.types.includes(t.kind==="file"?"f":"d");if(e.kind==="name"||e.kind==="iname")return e.re.test(t.path.replace(/\/+$/u,"").split("/").at(-1)||"/");if(e.kind==="prune")return t.kind==="dir"&&t.prune.add(t.abs),!0;if(e.kind==="empty"){if(t.kind==="file")return n.fs.readFile(t.abs)==="";let{dirs:i,files:o}=n.fs.listDir(t.abs);return i.length+o.length===0}return e.kind==="path"||e.kind==="ipath"?e.re.test(t.path):e.kind==="print"||e.kind==="print0"?(Go(r,n.flushOutput({stdout:t.path+(e.kind==="print"?`
79
- `:"\0"),stderr:"",exitCode:0})),!0):e.mode==="batch"?(e.collected.push(t.path),!0):Nc(e.cmd,e.args.map(i=>i.replaceAll("{}",t.path)),n,r)}function Nc(e,t,n,r){let i=n.dispatch(e,t,"");return Go(r,i),i.exitCode===0}function Go(e,t){let n=e.exitCode;_(e,t),e.exitCode=n}function nx(e,t,n){if(n===t)return e;let r=ut(t,n);return e.endsWith("/")?e+r:e+"/"+r}var Zo=1e5,rx=/^([+-]?\d+)\.\.([+-]?\d+)(?:\.\.([+-]?\d+))?$/u,ix=/^([A-Za-z])\.\.([A-Za-z])(?:\.\.([+-]?\d+))?$/u,Ac=2n**63n-1n,Ic=-(2n**63n),Xo=e=>{let t=BigInt(e);return t>Ac||t<Ic?null:t},Vo=(e,t)=>e.mask===null?"0":e.mask[t];function Un(e,t=Zo){if(!e.value.includes("{"))return[e];let n=Cc(e);for(let r=0;r<e.value.length;r++){if(e.value[r]!=="{"||Vo(e,r)!=="0")continue;let i=n.get(r);if(!i)continue;let{end:o,commas:s}=i,u=s.length?[]:ox(fe(e,r+1,o));if(s.length){let f=r+1;for(let d of[...s,o])u.push(fe(e,f,d)),f=d+1}if(u===null)continue;let a=fe(e,0,r),l=fe(e,o+1),c=[];for(let f of u)if(c.push(...Un(Zu(a,f,l),t)),c.length>t)throw new w("feature","brace expansion limit",`brace expansion \`${e.value}\` would produce more than ${t} words`);return c}return[e]}function Oc(e){if(!e.value.includes("{"))return!1;let t=Cc(e);for(let[n,{end:r,commas:i}]of t)if(Vo(e,n)==="0"&&(i.length>0||Fc(fe(e,n+1,r))!==null))return!0;return!1}function Cc(e){let t=[],n=new Map;for(let r=0;r<e.value.length;r++){if(Vo(e,r)!=="0")continue;let i=e.value[r];if(i==="{")t.push({start:r,commas:[]});else if(i==="}"&&t.length){let{start:o,commas:s}=t.pop();n.set(o,{end:r,commas:s})}else i===","&&t.length&&t.at(-1).commas.push(r)}return n}function Fc(e){if(e.mask!==null&&/[12]/u.test(e.mask))return null;let t=rx.exec(e.value),n=t??ix.exec(e.value);if(!n)return null;let[r,i]=t?[Xo(t[1]),Xo(t[2])]:[BigInt(n[1].codePointAt(0)),BigInt(n[2].codePointAt(0))],o=n[3]===void 0?1n:Xo(n[3]);if(r===null||i===null||o===null||o===Ic)return null;let s=i>=r?i-r:r-i;return s>Ac?null:{num:t,range:n,from:r,to:i,step:(o<0n?-o:o)||1n,span:s}}function ox(e){let t=Fc(e);if(t===null)return null;let{num:n,from:r,to:i,step:o,span:s}=t,u=s/o+1n;if(u>Zo)throw new w("feature","brace expansion limit",`brace expansion \`{${e.value}}\` would produce ${u} words (limit ${Zo})`);let a=n?sx(n[1],n[2]):0,l=[],c=i>=r?1n:-1n;for(let f=0n;f<u;f++){let d=r+c*f*o,p=n?ux(d,a):String.fromCodePoint(Number(d));l.push({value:p,mask:null})}return l}function sx(e,t){let n=r=>/^-?0\d/u.test(r);return n(e)||n(t)?Math.max(e.length,t.length):0}function ux(e,t){let n=String(e<0n?-e:e),r=e<0n?"-":"";return r+n.padStart(t-r.length,"0")}var Yo=new Set(["CDPATH","GLOBIGNORE","GLOBSORT","BASH_COMPAT","POSIXLY_CORRECT","PATH","RANDOM","SRANDOM","SECONDS","EPOCHSECONDS","EPOCHREALTIME","BASHOPTS","SHELLOPTS","OPTIND"]),He=class extends Map{constructor(t){super(t),this.unsetNames=new Set(t?.unsetNames)}set(t,n){if(this.expansionTargets?.has(t))throw new w("feature","temporary assignment side effects","modifying a temporary assignment target while expanding assignment values is not supported");if(Yo.has(t)||t==="TZ"&&!["UTC","UTC0",""].includes(n))throw new w("feature",t,`shell variable ${t} is not supported with this value`);return(t==="LANG"||t.startsWith("LC_"))&&Du(t,n),this.bound?.add(t),this.unsetNames?.delete(t),super.set(t,n)}delete(t){return this.unsetNames.add(t),super.delete(t)}};var Tc=new Set(["$","!","0","-","_"]),ax=new Set(["PPID","UID","EUID","BASHPID","BASH_SUBSHELL","BASH_VERSION","BASH_VERSINFO","BASH_REMATCH","DIRSTACK","PIPESTATUS","FUNCNAME","LINENO","REPLY","BASH","BASH_COMMAND","BASH_ARGV0","BASH_ARGC","BASH_ARGV","BASH_SOURCE","BASH_LINENO","BASH_ALIASES","BASH_CMDS","GROUPS","HOSTTYPE","OSTYPE","MACHTYPE","HOSTNAME","SHLVL","SHELL","TERM","PS4","OPTERR","HISTCMD","BASH_EXECUTION_STRING","BASH_LOADABLES_PATH","COMP_WORDBREAKS"]);function mt(e,t){if(Tc.has(e))throw Ko(e);let n=Jo(e,t);if(n)return n;if(_c(e))throw Ko(e);return{value:"",set:!1}}var _c=e=>Yo.has(e)||ax.has(e),Ko=e=>new w("feature",`$${e}`,`shell parameter ${e} is not supported`),Lc=(e,t)=>Jo(e,t)?.value??"";function Jo(e,t){return e==="?"?{value:String(t.lastExit),set:!0}:e==="#"?{value:"0",set:!0}:e==="@"?{value:"",set:!1,omit:!0}:e==="*"?{value:"",set:!1}:/^[1-9][0-9]*$/u.test(e)?{value:"",set:!1}:t.vars.has(e)?{value:t.vars.get(e),set:!0}:t.vars.unsetNames.has(e)?{value:"",set:!1}:e==="IFS"?{value:`
80
- `,set:!0}:e==="PWD"?{value:t.cwd,set:!0}:e==="HOME"?{value:t.home,set:!0}:e==="USER"||e==="LOGNAME"?{value:t.user,set:!0}:e==="LANG"?{value:t.locale,set:!0}:null}function Qo(e,t){if(Tc.has(e))throw new w("feature",`$${e}`,`shell parameter ${e} is not supported (this terminal runs no process)`);let n=Jo(e,t);if(n)return n;if(_c(e))throw Ko(e);return lx(t,`$${e}`,`warning: $${e} is unset (this shell has no environment variables; only \`for\` bindings and \`NAME=value\` assignments)`),{value:""}}function lx(e,t,n){Pr(e,n+`
81
- `),e.unsupported.add({kind:"feature",command:null,detail:t,message:n})}var Rc=16e6,Bn=e=>new w("feature","${",e);function Mc(e,t,n){if(_n(t))throw Bn("extended glob patterns in parameter expansion are not supported");let r=Vt({value:t.value,mask:t.mask??null}),i=n[0]==="#",o=Dc(r);if(o!==null)return i?e.startsWith(o)?e.slice(o.length):e:e.endsWith(o)?e.slice(0,e.length-o.length):e;let s=$e(r,{bash:!0}),u=n.length===2,a=i===u,l=a?e.length:0,c=0;for(;l>=0&&l<=e.length;){let f=i?e.slice(0,l):e.slice(l);if(c+=f.length+r.length,c>Rc)throw Bn("parameter pattern removal exceeds the matching work limit");if(s.test(f))return i?e.slice(l):e.slice(0,l);l=Ur(e,l,a)}return e}function Pc(e,t,n,r){let i="";if(!r&&/^[#%]/u.test(t.value)&&(!t.mask||t.mask[0]==="0")&&(i=t.value[0],t={value:t.value.slice(1),mask:t.mask?.slice(1)??null}),_n(t))throw Bn("extended glob patterns in parameter expansion are not supported");let o=Vt({value:t.value,mask:t.mask??null}),s={work:0},u=dx(n,s);if(!o)return i==="#"?u("")+e:i==="%"?e+u(""):e;if((/\\+$/u.exec(o)?.[0].length??0)%2)throw Bn("unescaped trailing backslashes in replacement patterns are not supported");let a=Dc(o),l=a===null?fx(e,o,i,s):cx(e,a,i),c=[],f=0;do{let d=l(f);if(!d)break;let[p,m]=d,h=u(e.slice(p,m));if(es(s,p-f),c.push(e.slice(f,p),h),f=m,!r)break;if(p===m){let g=Ur(e,f,!1);c.push(e.slice(f,g)),f=g}}while(f<e.length);return c.push(e.slice(f)),c.join("")}function cx(e,t,n){return r=>{let i=n==="%"?e.length-t.length:e.indexOf(t,r);return i<r||n==="#"&&i!==0||e.slice(i,i+t.length)!==t?null:[i,i+t.length]}}function fx(e,t,n,r){let i=$e(t,{bash:!0});return o=>{for(let s=o;s<=e.length;s=Ur(e,s,!1)){for(let u=e.length;u>=s;u=Ur(e,u,!0)){if(es(r,u-s+t.length),i.test(e.slice(s,u)))return[s,u];if(n==="%")break}if(n==="#")break}return null}}function es(e,t){if(e.work+=t,e.work>Rc)throw Bn("parameter replacement exceeds the matching work limit")}function dx(e,t){let n="";for(let r=0;r<e.value.length;r++){let i=e.value[r];e.mask?.[r]!==void 0&&e.mask[r]!=="0"&&(i==="&"||i==="\\")&&(n+="\\"),n+=i}return r=>{let i=[];for(let o=0;o<n.length;o++){let s=n[o],u=s==="\\"&&/[&\\]/u.test(n[o+1]??"")?n[++o]:s==="&"?r:s;es(t,u.length),i.push(u)}return i.join("")}}function Ur(e,t,n){let r=t+(n?-1:1);return r>0&&r<e.length&&/[\uDC00-\uDFFF]/u.test(e[r])&&/[\uD800-\uDBFF]/u.test(e[r-1])?r+(n?-1:1):r}function Dc(e){let t="";for(let n=0;n<e.length;n++){let r=e[n];if(r==="\\"&&n+1<e.length)t+=e[++n];else{if(/[*?[]/u.test(r))return null;t+=r}}return t}var Re=e=>BigInt.asIntN(64,e),j=(e,t)=>new w("feature","arithmetic "+e,"arithmetic expansion: "+t);function Uc(e){let t=10n,n=!1,r=0n,i=0;if(e[0]==="0"&&(i=1,t=8n,n=!0,(e[1]==="x"||e[1]==="X")&&(t=16n,i=2)),i===2&&e.length===2)throw j("number","hexadecimal constant has no digits");for(;i<e.length;i++){let o=e[i];if(o==="#"){if(n||r<2n||r>64n||i===e.length-1)throw j("number","invalid arithmetic base or integer constant");t=r,r=0n,n=!0;continue}let s=o.codePointAt(0),u=s>=48&&s<=57?s-48:s>=97&&s<=122?s-87:s>=65&&s<=90?s-(t<=36n?55:29):o==="@"?62:o==="_"?63:-1;if(u<0||BigInt(u)>=t)throw j("number","value too great for base in "+e.slice(0,40));r=Re(r*t+BigInt(u))}return r}function px(e,t){if(t<0n)throw j("exponent","exponent less than zero");let n=1n;for(let r=t,i=e;r!==0n;r>>=1n,i=Re(i*i))r&1n&&(n=Re(n*i));return n}function ts(e,t,n,r){switch(e){case"+":return Re(t+n);case"-":return Re(t-n);case"*":return Re(t*n);case"/":case"%":{if(n===0n&&r)throw j("division","division by zero");let i=n===0n?1n:n;return Re(e==="/"?t/i:t%i)}case"**":return px(t,n);case"<<":case">>":{if(n<0n||n>63n)throw j("shift count","shift counts outside 0..63 are not supported");return Re(e==="<<"?t<<n:t>>n)}case"&":return t&n;case"^":return t^n;case"|":return t|n;case"<":return BigInt(t<n);case"<=":return BigInt(t<=n);case">":return BigInt(t>n);case">=":return BigInt(t>=n);case"==":return BigInt(t===n);case"!=":return BigInt(t!==n);default:throw j("operator","unsupported operator "+e)}}var hx=new Set(["=","+=","-=","*=","/=","%=","<<=",">>=","&=","^=","|="]),mx=[["||"],["&&"],["|"],["^"],["&"],["==","!="],["<","<=",">",">="],["<<",">>"],["+","-"],["*","/","%"],["**"]],gx=new Map(mx.flatMap((e,t)=>e.map(n=>[n,t+3]))),wx=/^(?:<<=|>>=|\+\+|--|\*\*|&&|\|\||<<|>>|[+\-*/%&^|=!<>]=|[+\-*/%&^|=!~<>?:,()])/u;function xx(e){let t=[];for(let n=0;n<e.length;){if(t.length>=1e4)throw j("limit","expression token limit exceeded");let r=e.slice(n),i=/^[ \t\n]+/u.exec(r);if(i){n+=i[0].length;continue}let o=/^[0-9][A-Za-z0-9#@_]*/u.exec(r),s=/^[A-Za-z_][A-Za-z0-9_]*/u.exec(r),u=wx.exec(r);if(o)t.push({type:"number",value:Uc(o[0]),raw:o[0]});else if(s)t.push({type:"name",value:s[0],raw:s[0]});else if(u)t.push({type:"operator",value:u[0],raw:u[0]});else throw j(r[0]==="["||r[0]==="]"?"arrays":"syntax","unsupported expression token "+JSON.stringify(r[0]));n+=t.at(-1).raw.length}return t.push({type:"end",value:""}),t}function Bc(e){let t=new ns(xx(e));if(t.token.type==="end")return{type:"number",value:0n};let n=t.expression();if(t.token.type!=="end")throw j("syntax","unexpected token "+t.token.value);return n}var ns=class{constructor(t){this.tokens=t,this.at=0,this.depth=0}get token(){return this.tokens[this.at]}next(){return this.tokens[this.at++]}accept(t){return this.token.value===t?this.next():null}expect(t){if(!this.accept(t))throw j("syntax","expected "+t)}expression(t=0){if(++this.depth>128)throw j("limit","expression nesting limit exceeded");let n=this.prefix();for(;;){let r=this.token.value;if(r==="?"&&t<=2){this.next();let u=this.expression();this.expect(":"),n={type:"condition",test:n,consequent:u,alternate:this.expression(2)};continue}let i=hx.has(r),o=r===","?0:i?1:gx.get(r);if(o===void 0||o<t)break;if(this.next(),i&&n.type!=="name")throw j("assignment","attempted assignment to non-variable");let s=this.expression(o+(i||r==="**"?0:1));n={type:i?"assignment":"binary",op:r,left:n,right:s}}return this.depth--,n}prefix(){let t=this.next();if(["+","-","!","~"].includes(t.value))return{type:"unary",op:t.value,value:this.expression(14)};if(t.value==="++"||t.value==="--"){let n=this.next();if(n.type!=="name")throw j("increment","increment requires a scalar variable");return{type:"increment",op:t.value,name:n.value,post:!1}}if(t.value==="("){let n=this.expression();return this.expect(")"),{type:"group",value:n}}if(t.type!=="number"&&t.type!=="name")throw j("syntax","operand expected");return t.type==="name"&&(this.token.value==="++"||this.token.value==="--")?{type:"increment",op:this.next().value,name:t.value,post:!0}:t}};function Ct(e,t,n=0){return zc(e,{ctx:t,steps:1e4,characters:2e5},n,!0)}function zc(e,t,n,r){if(typeof e!="string")throw j("value","expression must be a string");if(t.characters-=e.length,e.length>1e5||t.characters<0)throw j("limit","expression size limit exceeded");if(n>128)throw j("limit","variable recursion limit exceeded");return qc(Bc(e),t,n+1,r)}function rs(e,t,n,r){if(!r)return 0n;let i;try{i=mt(e,t.ctx)}catch(o){throw j("variable",G(o))}return i.set&&i.value!==""?zc(i.value,t,n+1,!0):0n}function Wc(e,t,n,r){if(r)try{mt(e,n.ctx),n.ctx.vars.set(e,t.toString())}catch(i){throw j("assignment",G(i))}return t}function qc(e,t,n,r){if(--t.steps<0||n>128)throw j("limit","expression evaluation limit exceeded");let i=(o,s=r)=>qc(o,t,n+1,s);switch(e.type){case"number":return e.value;case"name":return rs(e.value,t,n,r);case"group":return i(e.value);case"unary":{let o=i(e.value);return e.op==="+"?o:e.op==="-"?Re(-o):e.op==="!"?BigInt(o===0n):~o}case"increment":{let o=rs(e.name,t,n,r),s=Wc(e.name,Re(o+(e.op==="++"?1n:-1n)),t,r);return e.post?o:s}case"assignment":{let o=e.left.value,s=e.op==="="?0n:rs(o,t,n,r),u=i(e.right);return Wc(o,e.op==="="?u:ts(e.op.slice(0,-1),s,u,r),t,r)}case"condition":{let o=i(e.test)!==0n,s=i(e.consequent,r&&o),u=i(e.alternate,r&&!o);return o?s:u}case"binary":{let o=i(e.left),s=r&&(e.op==="&&"?o!==0n:e.op==="||"?o===0n:!0),u=i(e.right,s);return e.op===","?u:e.op==="&&"?BigInt(o!==0n&&u!==0n):e.op==="||"?BigInt(o!==0n||u!==0n):ts(e.op,o,u,r)}default:throw j("syntax","unsupported expression")}}var Br=e=>new w("feature","${",e);function jc(e,t,n,r){if(e.name==="@"||e.name==="*")throw Br("substring and replacement of positional parameter lists are not supported");if(!t.set)return t;if(e.operator===":")try{return{value:yx(t.value,e.word,n,r)}}catch(l){throw l.halt=!0,l}let i=e.word,o=0;for(;i[o]==="\\"&&i[o+1]===`
82
- `;)o+=2;let s=Hc(i,"/",r.readExpansion,i[o]==="/"?o+1:0),u=r.expand(i.slice(0,s),{pattern:!0}),a=r.expand(s<i.length?i.slice(s+1):"",{replacement:!0});return{value:Pc(t.value,u,a,e.operator==="//")}}function yx(e,t,n,r){if(/\P{ASCII}/u.test(e))throw Br("locale-dependent slicing of non-ASCII parameters is not supported");let i=Hc(t,":",r.readExpansion),o=l=>Ct(r.expand(l,{arithmetic:!0}).value,n),s=o(t.slice(0,i)),u=BigInt(e.length);if(s<0n&&(s+=u),s<0n||s>u)return"";let a=u;if(i<t.length){let l=o(t.slice(i+1));if(a=l<0n?u+l:s+l,a>J)throw Br("substring length overflows the shell integer range");if(a<s){let c=new Error(`${t.slice(i+1)}: substring expression < 0`);throw c.exitCode=1,c.halt=!0,c}}return e.slice(Number(s),Number(a>u?u:a))}function Hc(e,t,n,r=0){let i=0,o=null,s=0;for(let u=r;u<e.length;u++){let a=e[u];if(o==="'"){a==="'"&&(o=null);continue}if(o==="ansi"){a==="\\"?u++:a==="'"&&(o=null);continue}if(a==="\\"){u++;continue}if(t===":"&&(a==="'"||a==='"'))throw Br("quoted substring arithmetic is not supported");if(a==='"'){o=o==='"'?null:'"';continue}if(a==="'"&&!o){o=a;continue}if(a==="$"){let l=n(e,u,0,t===":"||o==='"');if(l){u+=l.raw.length-1;continue}let c=u+1;for(;e[c]==="\\"&&e[c+1]===`
83
- `;)c+=2;if(!o&&e[c]==="'"){o="ansi",u=c;continue}}if(!o){if(t===":"){if(a==="(")i++;else if(a===")")i--;else if(i===0&&a==="?")s++;else if(i===0&&a===":"&&s){s--;continue}if(i!==0)continue}if(a===t)return u}}return e.length}var bx=/^[A-Za-z_][A-Za-z0-9_]*$/u;function Gc(e,t,n){let{lookup:r,expand:i}=n,{name:o,operator:s,word:u=""}=e,a=r(o,{quiet:s!==""});if(!s)return a;if(s==="length")return vx(o,a.value);if(s===":"||s.startsWith("/"))return jc(e,a,t,n);if(s[0]==="#"||s[0]==="%")return!a.value||!u?a:{value:Mc(a.value,i(u,{pattern:!0}),s)};let l=!a.set||s.startsWith(":")&&a.value==="",c=s[s.length-1];if(c==="+")return l?{value:"",...a.omit?{omit:!0}:{}}:i(u,{});if(!l)return a;if(c==="?")throw kx(o,u,s.startsWith(":"),i,t);if(c!=="=")return i(u,{});if(!bx.test(o)){let d=new Error(`$${o}: cannot assign in this way`);throw d.exitCode=1,d.halt=!0,d}let f=i(u,{assignment:!0});return t.vars.set(o,f.value),{value:t.vars.get(o)}}function vx(e,t){if(e==="*"||e==="@")return{value:"0"};if(/\P{ASCII}/u.test(t))throw Et("#"+e,"locale-dependent length of non-ASCII parameters is not supported");return{value:String(t.length)}}function kx(e,t,n,r,i){let o=t?Sx(r(t,{error:!0}),i):n?"parameter null or not set":"parameter not set",s=new Error(`${e}: ${o}`);return s.exitCode=1,s.halt=!0,s}function Sx(e,t){let n=t.vars.get("IFS")??`
93
+ `,stderr:"",exitCode:d?2:0}}function Bb(e,t,n,r){return t.has("F")?!n.error&&e.fs.isLink?.(n.path)===!0?"@":r&&!t.has("d")?"/":"":""}function Ub(e,t,n,r,o,i,s,u){let a=[{dir:t,prefix:"",items:fo(e,t,r,u),i:0,depth:0}];for(;a.length;){let l=a.at(-1);if(l.i>=l.items.length){a.pop();continue}let{n:f,isDir:c,target:d}=l.items[l.i++];if([...f+(d??"")].some(w=>w.codePointAt(0)<32||w.codePointAt(0)===127||w==="\\"))return v("feature","tree","filename escaping","tree: listing names requiring escaping is not supported");let p=l.i===l.items.length,h=c&&r.has("F")&&!r.has("d")?"/":"";if(n.push(l.prefix+(p?"\u2514\u2500\u2500 ":"\u251C\u2500\u2500 ")+f+(d===void 0?h:" -> "+d+h)),i[c?"dirs":"files"]++,!c||d!==void 0)continue;let m=Te(l.dir,f);if(l.depth+1>=o){fo(e,m,r).length&&s.add(m);continue}let g=fo(e,m,r,u);a.push({dir:m,prefix:l.prefix+(p?" ":"\u2502\xA0\xA0 "),items:g,i:0,depth:l.depth+1})}}function fo(e,t,n,r=null){let{dirs:o,files:i,links:s}=e.listDir(t),u=s.map(l=>{let f=E(t,l,e);return{n:l,isDir:!f.error&&e.isDir(f.path),target:e.readLink(Te(t,l))}}),a=n.has("d")?u.filter(({isDir:l})=>l):[...i.map(l=>({n:l,isDir:!1})),...u];return r&&!n.has("a")&&r.collect(t,[...o,...a.map(({n:l})=>l)]),[...o.map(l=>({n:l,isDir:!0})),...a].filter(({n:l})=>n.has("a")||!l.startsWith(".")).sort((l,f)=>j(l.n,f.n))}var jb=new Set(["name","iname","type","path","ipath","mindepth","maxdepth"]),Jn=(e,t)=>e==="-"+t||e==="--"+t;function nd(e){let t={tokens:e,i:0,depth:{minDepth:0,maxDepth:Number.POSITIVE_INFINITY},hasAction:!1,batches:[],error:null},n=[];for(e[0]==="--"&&t.i++;t.i<e.length&&!/^(?:-.+|!|\()$/u.test(e[t.i]);)n.push(e[t.i++]);let r=rd(t,0);if(t.error)return{error:t.error};if(!t.hasAction)for(let o of r)o.push({kind:"print"});return{starts:n.length?n:["."],...t.depth,groups:r,batches:t.batches}}function rd(e,t){let n=[[]],r=!1;if(t>128)return e.error=v("feature","find","expression depth","find: expression nesting above 128 is not supported"),n;for(;e.i<e.tokens.length&&!e.error;){let o=e.tokens[e.i];if(o===")"){t||(e.error=x("find: unexpected closing parenthesis"));break}if(o==="-a"||Jn(o,"and")||o==="-o"||Jn(o,"or")){if(r||n.at(-1).length===0){e.error=x(`find: ${o} with no left-hand expression`);break}(o==="-o"||Jn(o,"or"))&&n.push([]),e.i++,r=o;continue}let i=Wb(e,t);i&&n.at(-1).push(i),r=!1}return!e.error&&r&&(e.error=x(`find: ${r} with no right-hand expression`)),!e.error&&t&&n.at(-1).length===0&&(e.error=x("find: expected an expression")),!e.error&&t&&(e.tokens[e.i]===")"?e.i++:e.error=x("find: missing closing parenthesis")),n}function Wb(e,t){let n=e.i,r=!1;for(;e.tokens[e.i]==="!"||e.tokens[e.i]==="-not";)r=!r,e.i++;let o=e.tokens[e.i++];if(o==="(")return{kind:"group",groups:rd(e,t+1),negate:r};if(o===void 0||o===")"||o==="-a"||o==="-o"||Jn(o,"and")||Jn(o,"or"))return e.error=x(`find: -not or operator ${o??""} must be followed by a primary`),null;let i=o.startsWith("--")?o.slice(2):o.startsWith("-")?o.slice(1):null;if(["print","print0","prune","empty"].includes(i))return(i==="print"||i==="print0")&&(e.hasAction=!0),{kind:i,negate:r};if(i==="exec"){let s=Gb(e.tokens,e.i-1,r);return s.error?(e.error=s.error,null):(e.i=s.nextI+1,e.hasAction=!0,s.pred.mode==="batch"&&e.batches.push(s.pred),s.pred)}if(jb.has(i)){if(e.i===e.tokens.length)return e.error=x(`find: ${o} requires a value`),null;let s=qb(i,e.tokens[e.i++],r,e.depth);return s.error?(e.error=s.error,null):s}return o===","?(e.error=v("feature","find","comma operator","find: comma expressions are not supported"),null):e.i-1>n&&!o.startsWith("-")?(e.error=x(`find: -not must be followed by a primary, got: ${o}`),null):(e.error=o==="--"||!o.startsWith("-")?x(`find: paths must precede expression: ${o}`):v("option","find",o,`find: unknown option: ${o}`),null)}function qb(e,t,n,r){if(e==="type"){let o=Hb(t);return o.error?o:{kind:e,negate:n,types:o.types}}if(e==="mindepth"||e==="maxdepth"){let o=be(t,`find: -${e}`,t,{max:2147483647,digitsOnly:!0});return o.error?o:(r[e==="mindepth"?"minDepth":"maxDepth"]=o.value,{kind:"true",negate:n})}return{kind:e,negate:n,re:Me(t,{ignoreCase:e==="iname"||e==="ipath"})}}var td="fdl",zb="bcps";function Hb(e){let t=e.split(","),n=t.find((i,s)=>t.indexOf(i)!==s);if(n!==void 0)return{error:x(`find: Duplicate file type '${n}' in the argument list to -type.`)};if(t.every(i=>i.length===1&&td.includes(i)))return{types:t};let r=`find: -type/--type expects 'f', 'd' or 'l', got: ${e}`;return{error:t.every(i=>i.length===1&&(td+zb).includes(i))?v("option","find",`-type ${e}`,r):x(r)}}function Gb(e,t,n){let r=t+1;for(;r<e.length&&e[r]!==";"&&!(e[r]==="+"&&e[r-1]==="{}");)r++;if(r>=e.length)return{error:x("find: -exec: missing terminator (`;` or `{} +`); quote or escape `;`")};if(r===t+1)return{error:x("find: -exec: requires a command")};let o=e.slice(t+1,r),i=e[r]===";"?"each":"batch";if(i==="batch"){if(o.slice(0,-1).some(u=>u.includes("{}")))return{error:x("find: -exec ... +: only one instance of `{}` is supported")};if(n)return{error:v("feature","find","-not -exec ... +","find: `-not -exec ... +` is not supported (the `+` form has no meaningful negation)")}}let s={kind:"exec",mode:i,cmd:o[0],args:o.slice(1),negate:n};return i==="batch"&&(s.collected=[]),{pred:s,nextI:r}}var Xb={file:"f",dir:"d",link:"l"};async function od(e,t,n){let r=nd(t);if(r.error)return r.error;if(e!==""&&t.some(c=>c==="-exec"||c==="--exec"))return v("feature","find","-exec stdin","find: passing shared standard input to -exec is not supported");let{starts:o,minDepth:i,maxDepth:s,groups:u,batches:a}=r,l=U(),f=new Set;try{for(let c of o){let{path:d,error:p}=P(n,"find",c,{follow:!1});if(p){Is(l,n.flushOutput(U(`find: '${c}': ${p}
94
+ `))),l.exitCode=1;continue}let h=new Set;for(let m of Fe(n.fs,d,s,g=>!h.has(g))){let g=Yb(c,d,m.path);if(m.depth>=i&&await id(u,{kind:m.kind,path:g,abs:m.path,prune:h},n,l),m.kind!=="dir"||m.depth!==s||h.has(m.path))continue;let{dirs:w,files:y,links:k}=n.fs.listDir(m.path);(w.length||y.length||k.length)&&f.add(g)}}for(let c of a){if(c.collected.length===0)continue;let d=c.args.slice(0,-1).concat(c.collected);await sd(c.cmd,d,n,l)||(l.exitCode=1)}}finally{gt(n.notes,{command:"find",action:"depth limit omitted contents of",noun:["directory","directories"],paths:f})}return l}async function id(e,t,n,r){for(let o of e){let i=!0;for(let s of o)if(await Zb(s,t,n,r)===!!s.negate){i=!1;break}if(i)return!0}return!1}function Zb(e,t,n,r){if(e.kind==="group")return id(e.groups,t,n,r);if(e.kind==="true")return!0;if(e.kind==="type")return e.types.includes(Xb[t.kind]);if(e.kind==="name"||e.kind==="iname")return e.re.test(t.path.replace(/\/+$/u,"").split("/").at(-1)||"/");if(e.kind==="prune")return t.kind==="dir"&&t.prune.add(t.abs),!0;if(e.kind==="empty"){if(t.kind==="link")return!1;if(t.kind==="file")return n.fs.isEmptyFile(t.abs);let{dirs:o,files:i,links:s}=n.fs.listDir(t.abs);return o.length+i.length+s.length===0}return e.kind==="path"||e.kind==="ipath"?e.re.test(t.path):e.kind==="print"||e.kind==="print0"?(Is(r,n.flushOutput({stdout:t.path+(e.kind==="print"?`
95
+ `:"\0"),stderr:"",exitCode:0})),!0):e.mode==="batch"?(e.collected.push(t.path),!0):sd(e.cmd,e.args.map(o=>o.replaceAll("{}",t.path)),n,r)}async function sd(e,t,n,r){let o=await n.dispatch(e,t,"");return Is(r,o),o.exitCode===0}function Is(e,t){let n=e.exitCode;_(e,t),e.exitCode=n}function Yb(e,t,n){if(n===t)return e;let r=He(t,n);return e.endsWith("/")?e+r:e+"/"+r}var Fs=1e5,Vb=/^([+-]?\d+)\.\.([+-]?\d+)(?:\.\.([+-]?\d+))?$/u,Kb=/^([A-Za-z])\.\.([A-Za-z])(?:\.\.([+-]?\d+))?$/u,ud=2n**63n-1n,ad=-(2n**63n),Ts=e=>{let t=BigInt(e);return t>ud||t<ad?null:t},ld=(e,t)=>e.mask===null?"0":e.mask[t];function Ls(e,t=Fs){if(!e.value.includes("{"))return[e];let n=Jb(e);for(let r=0;r<e.value.length;r++){if(e.value[r]!=="{"||ld(e,r)!=="0")continue;let o=n.get(r);if(!o)continue;let{end:i,commas:s}=o,u=s.length?[]:ex(xe(e,r+1,i));if(s.length){let c=r+1;for(let d of[...s,i])u.push(xe(e,c,d)),c=d+1}if(u===null)continue;let a=xe(e,0,r),l=xe(e,i+1),f=[];for(let c of u)if(f.push(...Ls(il(a,c,l),t)),f.length>t)throw new b("feature","brace expansion limit",`brace expansion \`${e.value}\` would produce more than ${t} words`);return f}return[e]}function Jb(e){let t=[],n=new Map;for(let r=0;r<e.value.length;r++){if(ld(e,r)!=="0")continue;let o=e.value[r];if(o==="{")t.push({start:r,commas:[]});else if(o==="}"&&t.length){let{start:i,commas:s}=t.pop();n.set(i,{end:r,commas:s})}else o===","&&t.length&&t.at(-1).commas.push(r)}return n}function Qb(e){if(e.mask!==null&&/[12]/u.test(e.mask))return null;let t=Vb.exec(e.value),n=t??Kb.exec(e.value);if(!n)return null;let[r,o]=t?[Ts(t[1]),Ts(t[2])]:[BigInt(n[1].codePointAt(0)),BigInt(n[2].codePointAt(0))],i=n[3]===void 0?1n:Ts(n[3]);if(r===null||o===null||i===null||i===ad)return null;let s=o>=r?o-r:r-o;return s>ud?null:{num:t,range:n,from:r,to:o,step:(i<0n?-i:i)||1n,span:s}}function ex(e){let t=Qb(e);if(t===null)return null;let{num:n,from:r,to:o,step:i,span:s}=t,u=s/i+1n;if(u>Fs)throw new b("feature","brace expansion limit",`brace expansion \`{${e.value}}\` would produce ${u} words (limit ${Fs})`);let a=n?tx(n[1],n[2]):0,l=[],f=o>=r?1n:-1n;for(let c=0n;c<u;c++){let d=r+f*c*i,p=n?nx(d,a):String.fromCodePoint(Number(d));l.push({value:p,mask:null})}return l}function tx(e,t){let n=r=>/^-?0\d/u.test(r);return n(e)||n(t)?Math.max(e.length,t.length):0}function nx(e,t){let n=String(e<0n?-e:e),r=e<0n?"-":"";return r+n.padStart(t-r.length,"0")}var _s=new Set(["CDPATH","GLOBIGNORE","GLOBSORT","BASH_COMPAT","POSIXLY_CORRECT","PATH","RANDOM","SRANDOM","SECONDS","EPOCHSECONDS","EPOCHREALTIME","BASHOPTS","SHELLOPTS","OPTIND"]),Je=class extends Map{constructor(t){super(t),this.unsetNames=new Set(t?.unsetNames)}set(t,n){if(this.expansionTargets?.has(t))throw new b("feature","temporary assignment side effects","modifying a temporary assignment target while expanding assignment values is not supported");if(_s.has(t)||t==="TZ"&&!["UTC","UTC0",""].includes(n))throw new b("feature",t,`shell variable ${t} is not supported with this value`);return(t==="LANG"||t.startsWith("LC_"))&&Wa(t,n),this.bound?.add(t),this.unsetNames?.delete(t),super.set(t,n)}delete(t){return this.unsetNames.add(t),super.delete(t)}};var fd=new Set(["$","!","0","-","_"]),rx=new Set(["PPID","UID","EUID","BASHPID","BASH_SUBSHELL","BASH_VERSION","BASH_VERSINFO","BASH_REMATCH","DIRSTACK","PIPESTATUS","FUNCNAME","LINENO","REPLY","BASH","BASH_COMMAND","BASH_ARGV0","BASH_ARGC","BASH_ARGV","BASH_SOURCE","BASH_LINENO","BASH_ALIASES","BASH_CMDS","GROUPS","HOSTTYPE","OSTYPE","MACHTYPE","HOSTNAME","SHLVL","SHELL","TERM","PS4","OPTERR","HISTCMD","BASH_EXECUTION_STRING","BASH_LOADABLES_PATH","COMP_WORDBREAKS"]);function Et(e,t){if(fd.has(e))throw Rs(e);let n=Ms(e,t);if(n)return n;if(cd(e))throw Rs(e);return{value:"",set:!1}}var cd=e=>_s.has(e)||rx.has(e),Rs=e=>new b("feature",`$${e}`,`shell parameter ${e} is not supported`),dd=(e,t)=>Ms(e,t)?.value??"";function Ms(e,t){return e==="?"?{value:String(t.lastExit),set:!0}:e==="#"?{value:"0",set:!0}:e==="@"?{value:"",set:!1,omit:!0}:e==="*"?{value:"",set:!1}:/^[1-9][0-9]*$/u.test(e)?{value:"",set:!1}:t.vars.has(e)?{value:t.vars.get(e),set:!0}:t.vars.unsetNames.has(e)?{value:"",set:!1}:e==="IFS"?{value:`
96
+ `,set:!0}:e==="PWD"?{value:t.cwd,set:!0}:e==="HOME"?{value:t.home,set:!0}:e==="USER"||e==="LOGNAME"?{value:t.user,set:!0}:e==="LANG"?{value:t.locale,set:!0}:null}function Ps(e,t){if(fd.has(e))throw new b("feature",`$${e}`,`shell parameter ${e} is not supported (this terminal runs no process)`);let n=Ms(e,t);if(n)return n;if(cd(e))throw Rs(e);return ox(t,`$${e}`,`warning: $${e} is unset (this shell has no environment variables; only \`for\` bindings and \`NAME=value\` assignments)`),{value:""}}function ox(e,t,n){uo(e,n+`
97
+ `),e.unsupported.add({kind:"feature",command:null,detail:t,message:n})}var pd=16e6,Qn=e=>new b("feature","${",e);function hd(e,t,n){if(Gn(t))throw Qn("extended glob patterns in parameter expansion are not supported");let r=on({value:t.value,mask:t.mask??null}),o=n[0]==="#",i=gd(r);if(i!==null)return o?e.startsWith(i)?e.slice(i.length):e:e.endsWith(i)?e.slice(0,e.length-i.length):e;let s=Me(r,{bash:!0}),u=n.length===2,a=o===u,l=a?e.length:0,f=0;for(;l>=0&&l<=e.length;){let c=o?e.slice(0,l):e.slice(l);if(f+=c.length+r.length,f>pd)throw Qn("parameter pattern removal exceeds the matching work limit");if(s.test(c))return o?e.slice(l):e.slice(0,l);l=co(e,l,a)}return e}function md(e,t,n,r){let o="";if(!r&&/^[#%]/u.test(t.value)&&(!t.mask||t.mask[0]==="0")&&(o=t.value[0],t={value:t.value.slice(1),mask:t.mask?.slice(1)??null}),Gn(t))throw Qn("extended glob patterns in parameter expansion are not supported");let i=on({value:t.value,mask:t.mask??null}),s={work:0},u=ux(n,s);if(!i)return o==="#"?u("")+e:o==="%"?e+u(""):e;if((/\\+$/u.exec(i)?.[0].length??0)%2)throw Qn("unescaped trailing backslashes in replacement patterns are not supported");let a=gd(i),l=a===null?sx(e,i,o,s):ix(e,a,o),f=[],c=0;do{let d=l(c);if(!d)break;let[p,h]=d,m=u(e.slice(p,h));if(Ds(s,p-c),f.push(e.slice(c,p),m),c=h,!r)break;if(p===h){let g=co(e,c,!1);f.push(e.slice(c,g)),c=g}}while(c<e.length);return f.push(e.slice(c)),f.join("")}function ix(e,t,n){return r=>{let o=n==="%"?e.length-t.length:e.indexOf(t,r);return o<r||n==="#"&&o!==0||e.slice(o,o+t.length)!==t?null:[o,o+t.length]}}function sx(e,t,n,r){let o=Me(t,{bash:!0});return i=>{for(let s=i;s<=e.length;s=co(e,s,!1)){for(let u=e.length;u>=s;u=co(e,u,!0)){if(Ds(r,u-s+t.length),o.test(e.slice(s,u)))return[s,u];if(n==="%")break}if(n==="#")break}return null}}function Ds(e,t){if(e.work+=t,e.work>pd)throw Qn("parameter replacement exceeds the matching work limit")}function ux(e,t){let n="";for(let r=0;r<e.value.length;r++){let o=e.value[r];e.mask?.[r]!==void 0&&e.mask[r]!=="0"&&(o==="&"||o==="\\")&&(n+="\\"),n+=o}return r=>{let o=[];for(let i=0;i<n.length;i++){let s=n[i],u=s==="\\"&&/[&\\]/u.test(n[i+1]??"")?n[++i]:s==="&"?r:s;Ds(t,u.length),o.push(u)}return o.join("")}}function co(e,t,n){let r=t+(n?-1:1);return r>0&&r<e.length&&/[\uDC00-\uDFFF]/u.test(e[r])&&/[\uD800-\uDBFF]/u.test(e[r-1])?r+(n?-1:1):r}function gd(e){let t="";for(let n=0;n<e.length;n++){let r=e[n];if(r==="\\"&&n+1<e.length)t+=e[++n];else{if(/[*?[]/u.test(r))return null;t+=r}}return t}var je=e=>BigInt.asIntN(64,e),J=(e,t)=>new b("feature","arithmetic "+e,"arithmetic expansion: "+t);function wd(e){let t=10n,n=!1,r=0n,o=0;if(e[0]==="0"&&(o=1,t=8n,n=!0,(e[1]==="x"||e[1]==="X")&&(t=16n,o=2)),o===2&&e.length===2)throw J("number","hexadecimal constant has no digits");for(;o<e.length;o++){let i=e[o];if(i==="#"){if(n||r<2n||r>64n||o===e.length-1)throw J("number","invalid arithmetic base or integer constant");t=r,r=0n,n=!0;continue}let s=i.codePointAt(0),u=s>=48&&s<=57?s-48:s>=97&&s<=122?s-87:s>=65&&s<=90?s-(t<=36n?55:29):i==="@"?62:i==="_"?63:-1;if(u<0||BigInt(u)>=t)throw J("number","value too great for base in "+e.slice(0,40));r=je(r*t+BigInt(u))}return r}function ax(e,t){if(t<0n)throw J("exponent","exponent less than zero");let n=1n;for(let r=t,o=e;r!==0n;r>>=1n,o=je(o*o))r&1n&&(n=je(n*o));return n}function Bs(e,t,n,r){switch(e){case"+":return je(t+n);case"-":return je(t-n);case"*":return je(t*n);case"/":case"%":{if(n===0n&&r)throw J("division","division by zero");let o=n===0n?1n:n;return je(e==="/"?t/o:t%o)}case"**":return ax(t,n);case"<<":case">>":{if(n<0n||n>63n)throw J("shift count","shift counts outside 0..63 are not supported");return je(e==="<<"?t<<n:t>>n)}case"&":return t&n;case"^":return t^n;case"|":return t|n;case"<":return BigInt(t<n);case"<=":return BigInt(t<=n);case">":return BigInt(t>n);case">=":return BigInt(t>=n);case"==":return BigInt(t===n);case"!=":return BigInt(t!==n);default:throw J("operator","unsupported operator "+e)}}var lx=new Set(["=","+=","-=","*=","/=","%=","<<=",">>=","&=","^=","|="]),fx=[["||"],["&&"],["|"],["^"],["&"],["==","!="],["<","<=",">",">="],["<<",">>"],["+","-"],["*","/","%"],["**"]],cx=new Map(fx.flatMap((e,t)=>e.map(n=>[n,t+3]))),dx=/^(?:<<=|>>=|\+\+|--|\*\*|&&|\|\||<<|>>|[+\-*/%&^|=!<>]=|[+\-*/%&^|=!~<>?:,()])/u;function px(e){let t=[];for(let n=0;n<e.length;){if(t.length>=1e4)throw J("limit","expression token limit exceeded");let r=e.slice(n),o=/^[ \t\n]+/u.exec(r);if(o){n+=o[0].length;continue}let i=/^[0-9][A-Za-z0-9#@_]*/u.exec(r),s=/^[A-Za-z_][A-Za-z0-9_]*/u.exec(r),u=dx.exec(r);if(i)t.push({type:"number",value:wd(i[0]),raw:i[0]});else if(s)t.push({type:"name",value:s[0],raw:s[0]});else if(u)t.push({type:"operator",value:u[0],raw:u[0]});else throw J(r[0]==="["||r[0]==="]"?"arrays":"syntax","unsupported expression token "+JSON.stringify(r[0]));n+=t.at(-1).raw.length}return t.push({type:"end",value:""}),t}function yd(e){let t=new Us(px(e));if(t.token.type==="end")return{type:"number",value:0n};let n=t.expression();if(t.token.type!=="end")throw J("syntax","unexpected token "+t.token.value);return n}var Us=class{constructor(t){this.tokens=t,this.at=0,this.depth=0}get token(){return this.tokens[this.at]}next(){return this.tokens[this.at++]}accept(t){return this.token.value===t?this.next():null}expect(t){if(!this.accept(t))throw J("syntax","expected "+t)}expression(t=0){if(++this.depth>128)throw J("limit","expression nesting limit exceeded");let n=this.prefix();for(;;){let r=this.token.value;if(r==="?"&&t<=2){this.next();let u=this.expression();this.expect(":"),n={type:"condition",test:n,consequent:u,alternate:this.expression(2)};continue}let o=lx.has(r),i=r===","?0:o?1:cx.get(r);if(i===void 0||i<t)break;if(this.next(),o&&n.type!=="name")throw J("assignment","attempted assignment to non-variable");let s=this.expression(i+(o||r==="**"?0:1));n={type:o?"assignment":"binary",op:r,left:n,right:s}}return this.depth--,n}prefix(){let t=this.next();if(["+","-","!","~"].includes(t.value))return{type:"unary",op:t.value,value:this.expression(14)};if(t.value==="++"||t.value==="--"){let n=this.next();if(n.type!=="name")throw J("increment","increment requires a scalar variable");return{type:"increment",op:t.value,name:n.value,post:!1}}if(t.value==="("){let n=this.expression();return this.expect(")"),{type:"group",value:n}}if(t.type!=="number"&&t.type!=="name")throw J("syntax","operand expected");return t.type==="name"&&(this.token.value==="++"||this.token.value==="--")?{type:"increment",op:this.next().value,name:t.value,post:!0}:t}};function Ut(e,t,n=0){return xd(e,{ctx:t,steps:1e4,characters:2e5},n,!0)}function xd(e,t,n,r){if(typeof e!="string")throw J("value","expression must be a string");if(t.characters-=e.length,e.length>1e5||t.characters<0)throw J("limit","expression size limit exceeded");if(n>128)throw J("limit","variable recursion limit exceeded");return kd(yd(e),t,n+1,r)}function js(e,t,n,r){if(!r)return 0n;let o;try{o=Et(e,t.ctx)}catch(i){throw J("variable",V(i))}return o.set&&o.value!==""?xd(o.value,t,n+1,!0):0n}function bd(e,t,n,r){if(r)try{Et(e,n.ctx),n.ctx.vars.set(e,t.toString())}catch(o){throw J("assignment",V(o))}return t}function kd(e,t,n,r){if(--t.steps<0||n>128)throw J("limit","expression evaluation limit exceeded");let o=(i,s=r)=>kd(i,t,n+1,s);switch(e.type){case"number":return e.value;case"name":return js(e.value,t,n,r);case"group":return o(e.value);case"unary":{let i=o(e.value);return e.op==="+"?i:e.op==="-"?je(-i):e.op==="!"?BigInt(i===0n):~i}case"increment":{let i=js(e.name,t,n,r),s=bd(e.name,je(i+(e.op==="++"?1n:-1n)),t,r);return e.post?i:s}case"assignment":{let i=e.left.value,s=e.op==="="?0n:js(i,t,n,r),u=o(e.right);return bd(i,e.op==="="?u:Bs(e.op.slice(0,-1),s,u,r),t,r)}case"condition":{let i=o(e.test)!==0n,s=o(e.consequent,r&&i),u=o(e.alternate,r&&!i);return i?s:u}case"binary":{let i=o(e.left),s=r&&(e.op==="&&"?i!==0n:e.op==="||"?i===0n:!0),u=o(e.right,s);return e.op===","?u:e.op==="&&"?BigInt(i!==0n&&u!==0n):e.op==="||"?BigInt(i!==0n||u!==0n):Bs(e.op,i,u,r)}default:throw J("syntax","unsupported expression")}}var po=e=>new b("feature","${",e);async function vd(e,t,n,r){if(e.name==="@"||e.name==="*")throw po("substring and replacement of positional parameter lists are not supported");if(!t.set)return t;if(e.operator===":")try{return{value:await hx(t.value,e.word,n,r)}}catch(l){throw l.halt=!0,l}let o=e.word,i=0;for(;o[i]==="\\"&&o[i+1]===`
98
+ `;)i+=2;let s=Sd(o,"/",r.readExpansion,o[i]==="/"?i+1:0),u=await r.expand(o.slice(0,s),{pattern:!0}),a=await r.expand(s<o.length?o.slice(s+1):"",{replacement:!0});return{value:md(t.value,u,a,e.operator==="//")}}async function hx(e,t,n,r){if(/\P{ASCII}/u.test(e))throw po("locale-dependent slicing of non-ASCII parameters is not supported");let o=Sd(t,":",r.readExpansion),i=async l=>Ut((await r.expand(l,{arithmetic:!0})).value,n),s=await i(t.slice(0,o)),u=BigInt(e.length);if(s<0n&&(s+=u),s<0n||s>u)return"";let a=u;if(o<t.length){let l=await i(t.slice(o+1));if(a=l<0n?u+l:s+l,a>ue)throw po("substring length overflows the shell integer range");if(a<s){let f=new Error(`${t.slice(o+1)}: substring expression < 0`);throw f.exitCode=1,f.halt=!0,f}}return e.slice(Number(s),Number(a>u?u:a))}function Sd(e,t,n,r=0){let o=0,i=null,s=0;for(let u=r;u<e.length;u++){let a=e[u];if(i==="'"){a==="'"&&(i=null);continue}if(i==="ansi"){a==="\\"?u++:a==="'"&&(i=null);continue}if(a==="\\"){u++;continue}if(t===":"&&(a==="'"||a==='"'))throw po("quoted substring arithmetic is not supported");if(a==='"'){i=i==='"'?null:'"';continue}if(a==="'"&&!i){i=a;continue}if(a==="$"){let l=n(e,u,0,t===":"||i==='"');if(l){u+=l.raw.length-1;continue}let f=u+1;for(;e[f]==="\\"&&e[f+1]===`
99
+ `;)f+=2;if(!i&&e[f]==="'"){i="ansi",u=f;continue}}if(!i){if(t===":"){if(a==="(")o++;else if(a===")")o--;else if(o===0&&a==="?")s++;else if(o===0&&a===":"&&s){s--;continue}if(o!==0)continue}if(a===t)return u}}return e.length}var mx=/^[A-Za-z_][A-Za-z0-9_]*$/u;async function Ed(e,t,n){let{lookup:r,expand:o}=n,{name:i,operator:s,word:u=""}=e,a=r(i,{quiet:s!==""});if(!s)return a;if(s==="length")return gx(i,a.value);if(s===":"||s.startsWith("/"))return vd(e,a,t,n);if(s[0]==="#"||s[0]==="%")return!a.value||!u?a:{value:hd(a.value,await o(u,{pattern:!0}),s)};let l=!a.set||s.startsWith(":")&&a.value==="",f=s[s.length-1];if(f==="+")return l?{value:"",...a.omit?{omit:!0}:{}}:o(u,{});if(!l)return a;if(f==="?")throw await wx(i,u,s.startsWith(":"),o,t);if(f!=="=")return o(u,{});if(!mx.test(i)){let d=new Error(`$${i}: cannot assign in this way`);throw d.exitCode=1,d.halt=!0,d}let c=await o(u,{assignment:!0});return t.vars.set(i,c.value),{value:t.vars.get(i)}}function gx(e,t){if(e==="*"||e==="@")return{value:"0"};if(/\P{ASCII}/u.test(t))throw Ft("#"+e,"locale-dependent length of non-ASCII parameters is not supported");return{value:String(t.length)}}async function wx(e,t,n,r,o){let i=t?yx(await r(t,{error:!0}),o):n?"parameter null or not set":"parameter not set",s=new Error(`${e}: ${i}`);return s.exitCode=1,s.halt=!0,s}function yx(e,t){let n=t.vars.get("IFS")??`
84
100
  `;if(n==="")return e.value;if(n!==`
85
- `)throw Et("?","custom IFS separators in parameter errors are not supported");let r=new Set(e.empty),i=[],o=!1,s="",u=()=>{(s||o)&&i.push(s),s="",o=!1};for(let a=0;a<=e.value.length&&(r.has(a)&&(o=!0),a!==e.value.length);a++){let l=e.value[a],c=!e.mask||e.mask[a]==="0";c&&/[ \t\n]/u.test(l)?u():(s+=l,o||=!c)}return u(),i.join(" ")}function gt(e,t){return ae(e,{cwd:e.cwd,lastExit:e.lastExit,vars:new He(e.vars),functions:new Map(e.functions),loopDepth:0},t)}function ae(e,t,n){let r=Object.fromEntries(Object.keys(t).map(i=>[i,e[i]]));Object.assign(e,t);try{return n()}finally{Object.assign(e,r)}}function Wn(e,t){let n=[],r=e[0],i=r?.value==="export"&&!/[12]/u.test(r.mask??"")&&!r.empty?.length;for(let o of e)for(let s of Un(o)){let u=i&&s===o&&bn(o);if(u){let a=$x(s,u.end,t);n.push({value:a,mask:"1".repeat(a.length),q:!0})}else n.push(...Zc(Wr(s,t,s===o?!1:"word"),t,!0))}return{argv:Ex(n,t)}}function Ex(e,t){let n=[];for(let r of e){if(Ll(r)){let i=Rl(r,t);if(i.length>0){n.push(...i);continue}}(r.value!==""||r.q)&&n.push(r.value)}return n}function is(e,t){let{argv:n}=Wn([e],t);return n.length===1?{value:n[0]}:{error:`${e.value}: ambiguous redirect`}}function $x(e,t,n){let r=fe(e,t);return e.value.slice(0,t)+Ft(r,n,!0)}function Ft(e,t,n=!1){return Zc(Wr(e,t,n),t,!1,n)[0].value}var Jt=e=>e.vars.get("HOME")??e.home,Xc=(e,t)=>e.mask===null?"0":e.mask[t];function Wr(e,t,n=!1){let r=mr(e,n);if(r.size===0)return e;let i=e.value,o=Jt(t),s="",u="",a=[];for(let l=0;l<i.length;l++){if(e.empty?.includes(l)&&a.push(s.length),r.has(l)){let c=o==="/"&&i[l+1]==="/"?"":o;s+=c,u+="1".repeat(c.length);continue}s+=i[l],u+=Xc(e,l)}return e.empty?.includes(i.length)&&a.push(s.length),{value:s,mask:/[12]/u.test(u)?u:null,...a.length?{empty:a}:{}}}function os(e,t){return ae(t,{strictExpansion:!0},()=>ss(Wr(e,t),t))}function Zc(e,t,n,r=!1){let i=ss(e,t,r);return n?Ix(i,t):[i]}function ss(e,t,n=!1){let r={value:"",mask:"",empty:[],split:!1},i=(o,s)=>{r.value+=o,r.mask+=s};e.value===""&&e.mask!==null&&r.empty.push(0);for(let o=0;o<=e.value.length&&(e.empty?.includes(o)&&r.empty.push(r.value.length),o!==e.value.length);o++){let s=Xc(e,o),u=e.value[o];if(s==="0"&&(u==="<"||u===">")&&e.value[o+1]==="(")throw new w("feature",`${u}(`,`process substitution (\`${u}(\u2026)\`) is not supported`);let a=s!=="1"&&(u==="$"||u==="`"),l=e.value[o+1]==="("||e.value[o+1]==="{",c=a?Nx(e,o,u,s,l):null;if(!c){i(e.value[o],s);continue}o+=c.raw.length-1;let f=Ax(c,t,s==="2",n);if(f.literal){i(c.raw,s.repeat(c.raw.length));continue}if(!f.omit)if(s==="2")f.value===""&&r.empty.push(r.value.length),i(f.value,"2".repeat(f.value.length));else{r.split=!0;for(let d of f.empty??[])r.empty.push(r.value.length+d);f.q&&!f.value&&!f.empty?.length&&r.empty.push(r.value.length),i(f.value,f.mask??"0".repeat(f.value.length))}}return r.q=r.empty.length>0||/[12]/u.test(r.mask),r}function Nx(e,t,n,r,i){return n==="`"?Te(e.value,t):i?_e(e.value,t,0,r==="2"):ji(e.value,t,e.mask)}function Ax(e,t,n,r){if(e.command!==void 0)return{value:t.substitute(e.command,e.backtick)};if(e.arithmetic!==void 0)try{let i=ae(t,{strictExpansion:!0},()=>Ft(Gi(e.arithmetic,!0),t));return{value:String(Ct(i,t))}}catch(i){throw i.halt=!0,i}return e.parameter!==void 0?e.parameter.operator===""&&!t.strictExpansion&&!/^[0-9]{2,}$/u.test(e.parameter.name)?Qo(e.parameter.name,t):Gc(e.parameter,t,{lookup:i=>mt(i,t),readExpansion:_e,expand:(i,o={})=>{let s=o.pattern||o.error||o.replacement||o.arithmetic,u=Gi(i,o.arithmetic||!s&&n),a=!s&&(o.assignment||r),l=o.assignment?"parameterAssign":a?!0:"parameter";return ae(t,{strictExpansion:!0},()=>ss(o.arithmetic?u:Wr(u,t,l),t,a))}}):t.strictExpansion?mt(e.name,t):Qo(e.name,t)}function Ix(e,t){if(!e.split)return e.value!==""||e.q?[e]:[];let n=t.vars.get("IFS")??`
101
+ `)throw Ft("?","custom IFS separators in parameter errors are not supported");let r=new Set(e.empty),o=[],i=!1,s="",u=()=>{(s||i)&&o.push(s),s="",i=!1};for(let a=0;a<=e.value.length&&(r.has(a)&&(i=!0),a!==e.value.length);a++){let l=e.value[a],f=!e.mask||e.mask[a]==="0";f&&/[ \t\n]/u.test(l)?u():(s+=l,i||=!f)}return u(),o.join(" ")}function $t(e,t){return ce(e,{cwd:e.cwd,lastExit:e.lastExit,vars:new Je(e.vars),functions:new Map(e.functions),loopDepth:0,errexit:e.errexit,errexitOff:e.errexitOff},t)}async function ce(e,t,n){let r=Object.fromEntries(Object.keys(t).map(o=>[o,e[o]]));Object.assign(e,t);try{return await n()}finally{Object.assign(e,r)}}async function er(e,t){let n=[],r=e[0],o=r?.value==="export"&&!/[12]/u.test(r.mask??"")&&!r.empty?.length;for(let i of e)for(let s of Ls(i)){let u=o&&s===i&&In(i);if(u){let a=await xx(s,u.end,t);n.push({value:a,mask:"1".repeat(a.length),q:!0})}else n.push(...await Nd(ho(s,t,s===i?!1:"word"),t,!0))}return{argv:bx(n,t)}}function bx(e,t){let n=[];for(let r of e){if(Qf(r)){let o=ec(r,t);if(o.length>0){n.push(...o);continue}}(r.value!==""||r.q)&&n.push(r.value)}return n}async function Ws(e,t){let{argv:n}=await er([e],t);return n.length===1?{value:n[0]}:{error:`${e.value}: ambiguous redirect`}}async function xx(e,t,n){let r=xe(e,t);return e.value.slice(0,t)+await jt(r,n,!0)}async function jt(e,t,n=!1){return(await Nd(ho(e,t,n),t,!1,n))[0].value}var ln=e=>e.vars.get("HOME")??e.home,$d=(e,t)=>e.mask===null?"0":e.mask[t];function ho(e,t,n=!1){let r=ol(e,n);if(r.size===0)return e;let o=e.value,i=ln(t),s="",u="",a=[];for(let l=0;l<o.length;l++){if(e.empty?.includes(l)&&a.push(s.length),r.has(l)){let f=i==="/"&&o[l+1]==="/"?"":i;s+=f,u+="1".repeat(f.length);continue}s+=o[l],u+=$d(e,l)}return e.empty?.includes(o.length)&&a.push(s.length),{value:s,mask:/[12]/u.test(u)?u:null,...a.length?{empty:a}:{}}}function qs(e,t){return ce(t,{strictExpansion:!0},()=>zs(ho(e,t),t))}async function Nd(e,t,n,r=!1){let o=await zs(e,t,r);return n?Sx(o,t):[o]}async function zs(e,t,n=!1){let r={value:"",mask:"",empty:[],split:!1},o=(i,s)=>{r.value+=i,r.mask+=s};e.value===""&&e.mask!==null&&r.empty.push(0);for(let i=0;i<=e.value.length&&(e.empty?.includes(i)&&r.empty.push(r.value.length),i!==e.value.length);i++){let s=$d(e,i),u=e.value[i];if(s==="0"&&(u==="<"||u===">")&&e.value[i+1]==="(")throw new b("feature",`${u}(`,`process substitution (\`${u}(\u2026)\`) is not supported`);let a=s!=="1"&&(u==="$"||u==="`"),l=e.value[i+1]==="("||e.value[i+1]==="{",f=a?kx(e,i,u,s,l):null;if(!f){o(e.value[i],s);continue}i+=f.raw.length-1;let c=await vx(f,t,s==="2",n);if(c.literal){o(f.raw,s.repeat(f.raw.length));continue}if(!c.omit)if(s==="2")c.value===""&&r.empty.push(r.value.length),o(c.value,"2".repeat(c.value.length));else{r.split=!0;for(let d of c.empty??[])r.empty.push(r.value.length+d);c.q&&!c.value&&!c.empty?.length&&r.empty.push(r.value.length),o(c.value,c.mask??"0".repeat(c.value.length))}}return r.q=r.empty.length>0||/[12]/u.test(r.mask),r}function kx(e,t,n,r,o){return n==="`"?at(e.value,t):o?ft(e.value,t,0,r==="2"):Ai(e.value,t,e.mask)}async function vx(e,t,n,r){if(e.command!==void 0)return{value:await t.substitute(e.command,e.backtick)};if(e.arithmetic!==void 0)try{let o=await ce(t,{strictExpansion:!0},()=>jt(Ci(e.arithmetic,!0),t));return{value:String(Ut(o,t))}}catch(o){throw o.halt=!0,o}return e.parameter!==void 0?e.parameter.operator===""&&!t.strictExpansion&&!/^[0-9]{2,}$/u.test(e.parameter.name)?Ps(e.parameter.name,t):Ed(e.parameter,t,{lookup:o=>Et(o,t),readExpansion:ft,expand:(o,i={})=>{let s=i.pattern||i.error||i.replacement||i.arithmetic,u=Ci(o,i.arithmetic||!s&&n),a=!s&&(i.assignment||r),l=i.assignment?"parameterAssign":a?!0:"parameter";return ce(t,{strictExpansion:!0},()=>zs(i.arithmetic?u:ho(u,t,l),t,a))}}):t.strictExpansion?Et(e.name,t):Ps(e.name,t)}function Sx(e,t){if(!e.split)return e.value!==""||e.q?[e]:[];let n=t.vars.get("IFS")??`
86
102
  `;if(n!==""&&n!==`
87
- `)throw new w("feature","IFS","custom IFS separators are not supported");let r=[],i={value:"",mask:"",q:!1},o=()=>{(i.value!==""||i.q)&&r.push(i),i={value:"",mask:"",q:!1}},s=new Set(e.empty);for(let u=0;u<=e.value.length&&(s.has(u)&&(i.q=!0),u!==e.value.length);u++){let a=e.value[u],l=e.mask[u];if(n!==""&&l==="0"&&/[ \t\n]/u.test(a)){o();continue}i.value+=a,i.mask+=l,i.q||=l!=="0"}return o(),r}function Vc(e,t,n){let r=wc(t,n);if(!r.flags.has("A")&&!r.flags.has("inodes"))return v("feature","du","allocated disk size","du: allocated disk sizes are not available");let i={ctx:n,options:r,seen:new Set,result:R(),total:0n,failed:!1};r.stderr&&_(i.result,n.flushOutput(R(r.stderr)));for(let o of r.operands){let s=o.length>2?o.replace(/\/+$/u,"/"):o,u=P(n,"du",s);if(u.error){_(i.result,n.flushOutput(y(`du: cannot access ${Z(s,n)}: ${u.error}`))),i.failed=!0;continue}try{Ox(u.path,s,i)}catch(a){let l=N(a),c="du: "+G(a);if(l&&n.unsupported.add({...l,command:l.command??"du",message:c}),_(i.result,n.flushOutput(y(c))),i.failed=!0,l)return i.result}}return r.flags.has("c")&&us(i.total,"total",i),i.result.exitCode=i.failed?1:0,i.result}function Ox(e,t,n){let{ctx:r,options:i}=n;if(!i.flags.has("inodes")&&r.fs.isDir(e)&&Object.values(r.outputFds??{}).some(s=>typeof s=="object"&&s.path?.startsWith(e==="/"?"/":e+"/")))throw new w("feature","recursive metadata output overlap","output within a measured directory is not supported");let o=[{path:e,name:t,depth:0}];for(;o.length;){let s=o.pop();if(s.total!==void 0){s.depth<=i.depth&&us(s.total,s.name,n),s.parent&&!i.flags.has("S")&&(s.parent.total+=s.total);continue}let u=r.fs.isDir(s.path);if(u&&r.fs.isFile(s.path))throw new w("feature","ambiguous file type",`path is both a file and a directory: ${s.name}`);let a=u?s.path:r.fs.fileIdentity?.(s.path)??s.path;if(!i.flags.has("l")&&n.seen.has(a))continue;n.seen.add(a);let l=i.flags.has("inodes")?1n:u?0n:BigInt(r.fs.fileSize(s.path));if(n.total+=l,u){s.total=l,o.push(s);let c=r.fs.listDir(s.path),f=[...new Set([...c.dirs,...c.files])].sort(U),d=s.name.endsWith("/")?s.name:s.name+"/";for(let p=f.length-1;p>=0;p--)o.push({path:Ce(s.path,f[p]),name:d+f[p],depth:s.depth+1,parent:s})}else s.parent&&(s.parent.total+=l),(s.depth===0||i.flags.has("a")&&s.depth<=i.depth)&&us(l,s.name,n)}}function us(e,t,n){let r=`${Pn(e,n.options.scale)} ${t}${n.options.flags.has("0")?"\0":`
88
- `}`;_(n.result,n.ctx.flushOutput({...R(),stdout:r,events:[{fd:1,text:r}]}))}var Cx=/^%([-+ 0#']*)(\d+|\*)?'?(?:\.(\d+|\*)?)?[hlL]?(.)?/su,Fx="diouxXeEfFgGcs";function qr(e){let t=[],n="";for(let r=0;r<e.length;r++){if(e[r]!=="%"){n+=e[r];continue}if(e[r+1]==="%"){n+="%",r++;continue}if(/^%[^a-zA-Z%]*\$/u.test(e.slice(r)))throw new k("positional printf arguments are not supported",null,"positional format arguments");let i=Cx.exec(e.slice(r)),o=i[4];if(o==="a"||o==="A")throw new k("hexadecimal floating-point formats are not supported",null,"hexadecimal float format");if(o==="%"){n+="%",r+=i[0].length-1;continue}if(o===void 0||!Fx.includes(o)){n+=i[0],r+=i[0].length-1;continue}n!==""&&(t.push(n),n="");let s=i[1];t.push({minus:s.includes("-"),plus:s.includes("+"),space:s.includes(" "),zero:s.includes("0"),alt:s.includes("#"),width:i[2]===void 0?null:i[2]==="*"?"*":Number(i[2]),precision:i[3]===void 0?i[0].includes(".")?0:null:i[3]==="*"?"*":Number(i[3]),conv:o}),r+=i[0].length-1}return n!==""&&t.push(n),t}function wt(e,t,n,r){let i=n.width??0;if(i>ye)throw new k("format width exceeds the output limit",null,"format size limit");let o=i-e.length-[...t].length;return o<=0?e+t:n.minus?e+t+" ".repeat(o):n.zero&&r?e+"0".repeat(o)+t:" ".repeat(o)+e+t}var Jc=e=>e.plus?"+":e.space?" ":"",Qc=e=>e==="X"||e==="E"||e==="G"||e==="F";function Tt(e,t){if(t.precision>ye)throw new k("format precision exceeds the output limit",null,"format size limit");let{conv:n}=t;if(!Number.isFinite(e)){if(Number.isNaN(e))throw new k("formatting signed NaN is not supported",null,"signed NaN");let r=e<0?"-inf":"+inf";return Qc(n)?r.toUpperCase():r}return"ouxX".includes(n)&&(e>=2**64||e<-(2**63))?Yc(e,{...t,conv:"g"}):"diouxX".includes(n)?Tx(e,t):Yc(e,t)}function Tx(e,t){let{conv:n}=t,r=n==="d"||n==="i",i=r?Math.trunc(e)===0:e===0,o=BigInt(Math.trunc(e)),s=!1;o<0n&&(r?(s=!0,o=-o):o=BigInt.asUintN(64,o));let u=n==="o"?8:n==="x"||n==="X"?16:10,a=o.toString(u);n==="X"&&(a=a.toUpperCase()),t.precision!==null&&(t.precision===0&&i?a=t.alt&&!r?"0":"":a=a.padStart(t.precision,"0"));let l=s?"-":r&&a!==""?Jc(t):"";return t.alt&&!i&&(n==="o"&&(a="0"+a),(n==="x"||n==="X")&&(l+=n==="x"?"0x":"0X")),wt(l,a,t,t.precision===null)}var zr=100;function Yc(e,t){let{conv:n}=t;if(t.precision>zr)throw new k(`floating-point precision above ${zr} is not supported`,null,"float precision limit");let r=t.precision??6,i=e<0||Object.is(e,-0),o=Math.abs(e),s;return n==="e"||n==="E"?s=tf(o,r):n==="f"||n==="F"?s=nf(o,r):s=_x(o,r,t.alt),t.alt&&r===0&&n!=="g"&&n!=="G"&&(s=n==="e"||n==="E"?s.replace("e",".e"):s+"."),Qc(n)&&(s=s.toUpperCase()),wt(i?"-":Jc(t),s,t,!0)}function ef(e,t,n,r){let i=t.slice(r);if(!/^50*$/u.test(i))return e;let o=t.slice(0,n),s=o.at(-1);return Number(s)%2===0?o:e}function tf(e,t){let n=e.toExponential(zr),r=n.indexOf("."),i=n.indexOf("e"),[o,s]=e.toExponential(t).split("e"),u=ef(o,n.slice(0,i),t===0?r:r+1+t,r+1+t),a=Number(u===o?s:n.slice(i+1));return`${u}e${a<0?"-":"+"}${String(Math.abs(a)).padStart(2,"0")}`}function nf(e,t){if(e>=1e21)return BigInt(e).toString()+(t>0?"."+"0".repeat(t):"");let n=e.toFixed(zr),r=n.indexOf(".");return ef(e.toFixed(t),n,t===0?r:r+1+t,r+1+t)}function _x(e,t,n){let r=t===0?1:t;if(e===0)return n?"0."+"0".repeat(r-1):"0";let i=tf(e,r-1),o=i.indexOf("e"),s=Number(i.slice(o+1));if(s<-4||s>=r)return n?i.includes(".")?i:i.slice(0,o)+"."+i.slice(o):Kc(i.slice(0,o))+i.slice(o);let u=nf(e,r-1-s);return n?u.includes(".")?u:u+".":Kc(u)}var Kc=e=>e.includes(".")?e.replace(/\.?0+$/u,""):e;var Lx=/^[+-]?(?:0[bB][01]+|0[xX][\da-fA-F]+|0[0-7]*|[1-9]\d*)/u,Rx=/^[+-]?(?:0[xX](?:[\da-fA-F]+(?:\.[\da-fA-F]*)?|\.[\da-fA-F]+)(?:[pP][+-]?\d+)?|(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?|inf(?:inity)?|nan(?:\([\w]*\))?)/iu;function sf(e,t){if(e?.[0]!=="'"&&e?.[0]!=='"')return null;let n=e.slice(1);if(n==="")return null;let r=I(n),i=t.byteLocale?1:I(String.fromCodePoint(n.codePointAt(0))).length;return r.length>i&&(t.stderr+=`printf: warning: ${M(r.slice(i))}: character(s) following character constant have been ignored
89
- `),t.byteLocale?r[0]:n.codePointAt(0)}function uf(e,t,n){if(e===void 0||e==="")return"0";let r=e.replace(/^[ \t\n\r\f\v]+/u,""),i=t.exec(r)?.[0]??"";return(i.length!==r.length||i==="")&&(n.stderr+=`printf: ${af(e,n)}: ${i?"value not completely converted":"expected a numeric value"}
90
- `,n.failed=!0),i||"0"}var rf={"\x07":"\\a","\b":"\\b"," ":"\\t","\n":"\\n","\v":"\\v","\f":"\\f","\r":"\\r","\\":"\\\\","'":"\\'"},of=e=>"\\"+e.toString(8).padStart(3,"0");function af(e,t){let n="";for(let r of e){if(rf[r]!==void 0){n+=rf[r];continue}let i=r.codePointAt(0);if(i<32||i===127){n+=of(i);continue}n+=i>127&&t.byteLocale?I(r).map(of).join(""):r}return`'${n}'`}function jr(e,t,n){let r=sf(e,n);if(r!==null)return BigInt(r);let i=uf(e,Lx,n),o=i[0]==="-",s=i.replace(/^[+-]/u,""),u=BigInt(/^0[0-7]+$/u.test(s)?"0o"+s:s),a=o?-u:u;return(t?u>Ze:a<Xe||a>J)?(n.stderr+=`printf: ${af(e,n)}: Numerical result out of range
91
- `,n.failed=!0,t?Ze:o?Xe:J):t?BigInt.asUintN(64,a):a}function Hr(e,t){let{conv:n}=t,r=n==="d"||n==="i",i=e<0n,o=n==="o"?8:n==="x"||n==="X"?16:10,s=(i?-e:e).toString(o);n==="X"&&(s=s.toUpperCase()),e===0n&&t.precision===0&&(s=""),s=s.padStart(t.precision??0,"0");let u=i?"-":r?t.plus?"+":t.space?" ":"":"";return t.alt&&(n==="o"&&!s.startsWith("0")&&(s="0"+s),e!==0n&&(n==="x"||n==="X")&&(u=n==="x"?"0x":"0X")),wt(u,s,t,t.precision===null)}function lf(e,t,n){let r=sf(e,n),i=r===null?uf(e,Rx,n):String(r),o=i.replace(/^[+-]/u,"");if(/^(?:inf|nan)/iu.test(o)){let a=i.startsWith("-")?"-":t.plus?"+":t.space?" ":"",l=/^nan/iu.test(o)?"nan":"inf";return t.conv===t.conv.toUpperCase()&&(l=l.toUpperCase()),wt(a,l,t,!1)}let s=Bx(o),u=i.startsWith("-")?-s.value:s.value;if(t.precision>100||"gG".includes(t.conv)&&t.precision>96)throw new w("feature","float precision limit","floating-point precision exceeds the supported limit");try{let a=Tt(u,t);if(!s.exact){let[l,c]=Mx(s.value);for(let f of[l,c])if(Tt(i.startsWith("-")?-f:f,t)!==a)throw new w("feature","floating-point precision","floating-point formatting at this precision is not supported")}return a}catch(a){throw a.gap?new w("feature",a.gap,a.message):a}}var Qt=new DataView(new ArrayBuffer(8));function cf(e){return Qt.setFloat64(0,e),Qt.getBigUint64(0)}function Mx(e){let t=cf(e);Qt.setBigUint64(0,t-1n);let n=Qt.getFloat64(0);return Qt.setBigUint64(0,t+1n),[n,Qt.getFloat64(0)]}function Px(e){let t=cf(e),n=Number(t>>52n);return{coefficient:t&(1n<<52n)-1n|(n?1n<<52n:0n),exponent:n?n-1075:-1074}}function as(e,t){let n=e.replace(/^0+|0+$/gu,"");return{digits:n||"0",exponent:n?t+e.length-e.replace(/0+$/u,"").length:0}}function Dx({coefficient:e,exponent:t}){return t<0?as((e*5n**BigInt(-t)).toString(),t):as((e<<BigInt(t)).toString(),0)}function Ux(e,t){let n=e.exponent-t.exponent;return n>=0?e.coefficient<<BigInt(n)===t.coefficient:e.coefficient===t.coefficient<<BigInt(-n)}function Bx(e){let t=/^0x/iu.test(e),n,r;if(t)n=Wx(e),r=zx(n);else{let[u,a="0"]=e.split(/[eE]/u),[l,c=""]=u.split(".");n=as(l+c,Number(a)-c.length),r=Number(e)}if(!Number.isFinite(r))throw new w("feature","floating-point range","floating-point values outside the JavaScript number range are not supported");if(r===0){if(t?n.coefficient!==0n:n.digits!=="0")throw new w("feature","floating-point range","floating-point underflow is not supported");return{value:r,exact:!0}}let i=Px(r),o=Dx(i),s=t?Ux(n,i):n.digits===o.digits&&n.exponent===o.exponent;return{value:r,exact:s&&o.exponent>=-100&&o.digits.length<=101}}function Wx(e){let[t,n="0"]=e.slice(2).split(/[pP]/u),[r,i=""]=t.split("."),o=(r+i).replace(/^0+/u,"")||"0";if(o.length>4096)throw new w("feature","floating-point input limit","hexadecimal floating-point significands above 4096 digits are not supported");return{coefficient:BigInt("0x"+o),exponent:Number(n)-4*i.length}}function zx({coefficient:e,exponent:t}){if(e===0n)return 0;let n=e.toString(2).length,r=t+n-1;if(r>1023)return 1/0;if(r<-1075)return 0;let i=Math.max(0,n-53,-1074-t),o=e>>BigInt(i);if(i>0){let s=e-(o<<BigInt(i)),u=1n<<BigInt(i-1);(s>u||s===u&&o%2n!==0n)&&o++}return Number(o)*2**(t+i)}var ff={a:7,b:8,e:27,f:12,n:10,r:13,t:9,v:11,'"':34,"\\":92};function pf(e,t){let n=[];for(let r=0;r<e.length;)if(e[r]==="%"){if(e[r+1]==="%"||r+1===e.length){n.push([37]),r+=2;continue}let i=/^%([-+ #0']*)(\d+)?(?:\.(\d*))?([\s\S])?/u.exec(e.slice(r)),[,o,s,u,a]=i;if(!a||a==="%")throw new Error(`invalid directive: ${i[0]}`);if(!"nsF".includes(a))throw new w("feature","%"+a,`format %${a} is not supported`);if(o.includes("'"))throw new w("feature","grouped format","digit grouping in stat formats is not supported");let l={field:a,conv:"u",width:Number(s??0),precision:u===void 0?null:Number(u||0),minus:o.includes("-"),zero:o.includes("0"),plus:o.includes("+"),space:o.includes(" "),alt:o.includes("#")};if(l.width>ye||l.precision>ye)throw new w("feature","format size limit","format width or precision exceeds the output limit");n.push(l),r+=i[0].length}else if(e[r]==="\\"&&t){let i=e[r+1],o=/^(?:[0-7]{1,3}|x[\da-fA-F]{1,2})/u.exec(e.slice(r+1))?.[0];if(o){let s=o[0]==="x"?16:8;n.push([parseInt(s===16?o.slice(1):o,s)&255]),r+=o.length+1}else if(Object.hasOwn(ff,i))n.push([ff[i]]),r+=2;else throw new w("feature","format escape",`format escape ${JSON.stringify(e.slice(r,r+2))} is not supported`)}else{let i=r+1;for(;i<e.length&&e[i]!=="%"&&!(t&&e[i]==="\\");)i++;n.push(ee(e.slice(r,i))),r=i}return t||n.push([10]),n}function hf(e,t,n,r){let i=r.isDir(n);if(i&&r.isFile(n))throw new w("feature","ambiguous file type",`path is both a file and a directory: ${t}`);let o,s=e.map(l=>{if(!l.field)return l;if(l.field==="n")return df(t,l);if(l.field==="s"&&i)throw new w("feature","directory byte size",`directory byte sizes are not available: ${t}`);return o??=i?0:r.fileSize(n),l.field==="F"?df(i?"directory":o===0?"regular empty file":"regular file",l):ee(Hr(BigInt(o),l))}),u=new Uint8Array(s.reduce((l,c)=>l+c.length,0)),a=0;for(let l of s)u.set(l,a),a+=l.length;return M(u)}function df(e,t){let n=ee(e);t.precision!==null&&(n=n.subarray(0,t.precision));let r=Math.max(0,t.width-n.length);if(!r)return n;let i=new Uint8Array(n.length+r).fill(32);return i.set(n,t.minus?0:r),i}function mf(e,t,n){let{order:r,positional:i}=E(t,{short:["L","t"],long:["dereference","terse"],valueShort:["c"],valueLong:["format","printf","cached"]});if(!i.length)return y("stat: missing operand");let o;for(let l of r)if(l.name==="cached"){if(!l.value||!["always","never","default"].some(c=>c.startsWith(l.value)))return y(`stat: invalid cache mode: ${l.value}`)}else["c","format","printf"].includes(l.name)&&(o=l);if(!o)return v("feature","stat","default metadata","stat: default output requires filesystem metadata that is not available");let s=pf(o.value,o.name==="printf");if(s.some(l=>l.field==="s"||l.field==="F")&&jx(i,n))return v("feature","stat","metadata output overlap","stat: buffered output sharing a measured file is not supported");let u=R(),a=!1;for(let l of i){let c=qx(s,l,n);_(u,c),a||=c.exitCode!==0}return u.exitCode=a?1:0,u}function qx(e,t,n){if(t==="-"){let i=v("feature","stat","standard input metadata","stat: standard input metadata is not supported");return n.unsupported.add({kind:"feature",command:"stat",detail:"standard input metadata",message:i.stderr.trimEnd()}),i}let r=P(n,"stat",t);if(r.error)return y(`stat: cannot statx ${Z(t,n)}: ${r.error}`);try{return C(hf(e,t,r.path,n.fs))}catch(i){let o=K(i,"stat","stat: "+G(i)),s=N(o);return s&&n.unsupported.add(s),o}}function jx(e,t){let n=Object.values(t.outputFds).filter(r=>typeof r=="object");return n.length?e.some(r=>{let i=$(t.cwd,r,t.fs);return!i.error&&n.some(o=>o.path===i.path||o.identity!==void 0&&o.identity===t.fs.fileIdentity?.(i.path))}):!1}function wf(e,t,n,r){let i={error:"No such file or directory"},o={error:"Not a directory"};if(t===""||t.includes("\0"))return i;if(n==="m")return{path:L(e.cwd,t)};if(r&&n==="E")return Hx(e,t);let s=(t.startsWith("/")?t:e.cwd+"/"+t).split("/").filter(Boolean),u="/";for(let l of s){if(!e.fs.isDir(u))return e.fs.isFile(u)?o:i;l===".."?u=vt(u):l!=="."&&(u=Ce(u,l))}let a=e.fs.isDir(u)||e.fs.isFile(u);return!a&&n==="e"?i:a&&t.endsWith("/")&&!e.fs.isDir(u)?o:{path:u}}function Hx(e,t){let n=(t.startsWith("/")?t:e.cwd+"/"+t).split("/").filter(Boolean),r="/";for(let i=0;i<n.length;i++){let o=n[i];if(o==="..")r=vt(r);else if(o!=="."){r=Ce(r,o);let s=i+1;for(;n[s]===".";)s++;let u=n[s]===".."||s===n.length&&(i<n.length-1||t.endsWith("/"));if(u||i===n.length-1){let a=$("/",r+(u?"/":""),e.fs);if(a.error&&!(a.error==="No such file or directory"&&i===n.length-1))return a}}}return{path:r}}function Gx(e,t){let n=e.split("/").filter(Boolean),r=t.split("/").filter(Boolean),i=0;for(;i<n.length&&i<r.length&&n[i]===r[i];)i++;return[...n.slice(i).map(()=>".."),...r.slice(i)].join("/")||"."}var xf=(e,t)=>e==="/"||t===e||t.startsWith(e+"/"),gf={e:"e","canonicalize-existing":"e",m:"m","canonicalize-missing":"m"};function Xx(e,t,n,r){let i=t.get("relative-base"),o=t.get("relative-to")??i,s={};for(let[u,a]of[["target",o],["base",i]]){if(a===void 0)continue;let l=wf(e,a,n,r),c=l.error??(n==="e"&&!e.fs.isDir(l.path)?"Not a directory":null);if(c)return D(e,"realpath",a,c),{error:y(`realpath: ${ie(a,e)}: ${c}`)};s[u]=l.path}return s.base&&!xf(s.base,s.target)&&delete s.target,s}function yf(e,t,n){let{flags:r,values:i,positional:o,order:s}=E(t,{short:["e","m","L","P","s","q","z"],long:["canonicalize-existing","canonicalize-missing","logical","physical","strip","no-symlinks","quiet","zero"],valueLong:["relative-to","relative-base"]});if(!o.length)return y("realpath: missing operand");let u="E",a=!1;for(let{name:m}of s)Object.hasOwn(gf,m)&&(u=gf[m]),["s","strip","no-symlinks"].includes(m)?a=!0:["L","P","logical","physical"].includes(m)&&(a=!1);let l=Xx(n,i,u,a);if(l.error)return l.error;let c=r.has("q")||r.has("quiet"),f=r.has("z")||r.has("zero")?"\0":`
92
- `,d=R(),p=!1;for(let m of o){let h=wf(n,m,u,a);if(h.error)D(n,"realpath",m,h.error),c||_(d,y(`realpath: ${ie(m,n)}: ${h.error}`)),p=!0;else{let g=l.target&&(!l.base||xf(l.base,h.path))?Gx(l.target,h.path):h.path;_(d,C(g+f))}}return d.exitCode=p?1:0,d}var Zx=/[ \t\n\v\f\r]/gu,Vx=/[ \t\n\v\f\r]+/gu,bf=/[ \t\n\v\f\r]+$/u,vf=e=>e.replace(/[A-Z]/gu,t=>t.toLowerCase());function Gr({ignoreCase:e=!1,whitespace:t="none"}={}){let n=null;return t==="all"?n=r=>r.replace(Zx,""):t==="change"?n=r=>r.replace(bf,"").replace(Vx," "):t==="trailing"&&(n=r=>r.replace(bf,"")),e?n?r=>vf(n(r)):vf:n}function xt(e){let t=[];for(let n=0;n<e.length;){let r=e.indexOf(`
93
- `,n),i=r<0?e.length:r+1;t.push(e.slice(n,i)),n=i}return t}var en=/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(?: ?(.*?))?\n?$/u,_t=/^\*{15,}(?: (.*?))?\n?$/u,Xr=/^\*{3} (\d+)(?:,(\d+))? \*{4}\n?$/u,zn=/^--- (\d+)(?:,(\d+))? ----\n?$/u,tn=/^(\d+)(?:,(\d+))?([acd])(\d+)(?:,(\d+))?[ \t]*\r?\n?$/u;var Ne=class extends Error{constructor(t,n){super(n===void 0?t:`${t} at line ${n+1}`),this.name="PatchError",this.line=n}},kf=(e,t)=>t===0?Number(e):Number(e)-1,ls=e=>e!==void 0&&e.startsWith("\\"),cs=e=>e.replace(/\n$/u,"");function fs(e){let t=xt(e),n=[],r={old:null,new:null},i=!1;for(let o=0;o<t.length;){let s=t[o],u=Sf(s,i);if(i=s.startsWith("***************")?!1:s.startsWith("*** "),u){r=u.names??{...r,[u.slot]:u.name},o++;continue}let a=en.test(s)?"unified":_t.test(s)?"context":tn.test(s)?"normal":null;if(a===null){o++;continue}let l=[],c=ty[a];for(let f=c(t,o);f!==null&&(l.push(f.hunk),o=f.next,!(o>=t.length||Sf(t[o],!1)));f=c(t,o));n.push({old:r.old,new:r.new,format:a,hunks:l,blocks:Yx(l)}),r={old:null,new:null}}return n}function Sf(e,t){let n=/^diff --git (\S+) (\S+)\n?$/u.exec(e);if(n)return{names:{old:n[1],new:n[2]}};if(Xr.test(e)||zn.test(e))return null;let r=/^(\*\*\* |--- |\+\+\+ )(.*?)(?:\t.*)?\n?$/u.exec(e);return r?r[1]==="--- "?{slot:t?"new":"old",name:r[2]}:{slot:r[1]==="*** "?"old":"new",name:r[2]}:null}function Yx(e){let t=[];for(let n of e){let r=n.oldStart,i=n.newStart,o=null,s=()=>{o&&(t.push(o),r=o.a1,i=o.b1,o=null)};for(let{tag:u,text:a}of n.lines){if(u===" "){s(),r++,i++;continue}u==="-"&&o?.insert.length&&s(),o??={a0:r,a1:r,b0:i,b1:i,remove:[],insert:[]},u==="-"?(o.a1++,o.remove.push(a)):(o.b1++,o.insert.push(a))}s()}return t}function Kx(e,t){let n=en.exec(e[t]??"");if(!n)return null;let r=n[2]===void 0?1:Number(n[2]),i=n[4]===void 0?1:Number(n[4]),o={oldStart:kf(n[1],r),newStart:kf(n[3],i),label:n[5]||null,lines:[]},s=0,u=t+1,a=0;for(;a<r||s<i;u++){let l=e[u];if(l===void 0)throw new Ne("the patch ends inside a hunk",u);let c=l===`
94
- `?" ":l[0];if(c!==" "&&c!=="-"&&c!=="+")throw new Ne(`a hunk line begins with ${JSON.stringify(c)}`,u);let f=l===`
95
- `?l:l.slice(1);if(ls(e[u+1])&&(f=cs(f),u++),c!=="+"&&a++,c!=="-"&&s++,a>r||s>i)throw new Ne("a hunk has more lines than its header says",u);o.lines.push({tag:c,text:f})}return{hunk:o,next:u}}function Jx(e,t){let n=tn.exec(e[t]??"");if(!n)return null;let[,r,i,o,s,u]=n,a=o==="a"?0:Number(i??r)-Number(r)+1,l=o==="d"?0:Number(u??s)-Number(s)+1;if(a<0||l<0)throw new Ne("a change command counts backwards",t);let c={oldStart:o==="a"?Number(r):Number(r)-1,newStart:o==="d"?Number(s):Number(s)-1,label:null,lines:[]},f=t+1,d=(p,m,h)=>{for(let g=0;g<p;g++,f++){let x=e[f];if(x===void 0)throw new Ne("the patch ends inside a hunk",f);if(x[0]!==m)throw new Ne(`${JSON.stringify(m)} expected`,f);let b=x.slice(2);ls(e[f+1])&&(b=cs(b),f++),c.lines.push({tag:h,text:b})}};if(d(a,"<","-"),o==="c"){if(e[f]!==`---
96
- `)throw new Ne("'---' expected",f);f++}return d(l,">","+"),{hunk:c,next:f}}function Qx(e,t){let n=_t.exec(e[t]??"");if(!n)return null;let r=Xr.exec(e[t+1]??"");if(!r)throw new Ne("'*** ' range expected",t+1);let i=t+2,o=$f(e,i,zn,"-");i=o.next;let s=zn.exec(e[i]??"");if(!s)throw new Ne("'--- ' range expected",i);let u=$f(e,i+1,null,"+"),a=o.lines.length===0?u.lines.filter(d=>d.tag===" "):o.lines,l=u.lines.length===0?o.lines.filter(d=>d.tag===" "):u.lines,c=Ef(r,a.length),f=Ef(s,l.length);return{hunk:{oldStart:c,newStart:f,label:n[1]||null,lines:ey(a,l)},next:u.next}}var Ef=(e,t)=>t===0?Number(e[1]):Number(e[1])-1;function $f(e,t,n,r){let i=[],o=t;for(;o<e.length;o++){let s=e[o];if(n&&n.test(s)||_t.test(s)||Xr.test(s)||!n&&zn.test(s))break;if(ls(s)){i[i.length-1].text=cs(i.at(-1).text);continue}let u=s===`
97
- `?" ":s[0];if(u!==" "&&u!=="!"&&u!=="-"&&u!=="+")break;i.push({tag:u===" "?" ":r,text:s===`
98
- `?s:s.slice(2)})}return{lines:i,next:o}}function ey(e,t){let n=[],r=0,i=0;for(;r<e.length||i<t.length;){if(e[r]?.tag===" "&&t[i]?.tag===" "){n.push(e[r]),r++,i++;continue}for(;r<e.length&&e[r].tag!==" ";)n.push(e[r]),r++;for(;i<t.length&&t[i].tag!==" ";)n.push(t[i]),i++;e[r]?.tag===" "&&t[i]===void 0?(n.push(e[r]),r++):t[i]?.tag===" "&&e[r]===void 0&&(n.push(t[i]),i++)}return n}var ty={unified:Kx,context:Qx,normal:Jx};var Me=class extends Error{constructor(t){super(`the rendered diff does not say what the change set says (${t})`),this.name="FormatError"}};function ds(e,t,n,r){if(n.length===0){if(r!=="")throw new Me("there was nothing to print, and something was printed");return}let i;try{i=fs(r)}catch(s){throw new Me(`it does not read back (${s.message})`)}if(i.length!==1)throw new Me(`${i.length} files read back, not one`);let o=i[0].blocks;if(o.length!==n.length)throw new Me(`${o.length} blocks read back, not ${n.length}`);for(let[s,u]of o.entries()){let a=n[s];if(u.a0!==a.a0||u.a1!==a.a1||u.b0!==a.b0||u.b1!==a.b1)throw new Me(`block ${s+1} reads back somewhere else`)}for(let s of i[0].hunks){let u=s.oldStart,a=s.newStart;for(let{tag:l,text:c}of s.lines){let f=l==="+"?t[a]:e[u];if(c!==f)throw new Me(`a ${l==="+"?"added":l==="-"?"removed":"kept"} line is not the line it stands for`);l!=="+"&&u++,l!=="-"&&a++}}}function Cf(e,t,n,r){let i=[],o=0;for(;o<e.length;){let s=o;for(;s+1<e.length&&e[s+1].a0-e[s].a1<=2*t;)s++;let u=e[o],a=e[s];i.push({blocks:e.slice(o,s+1),a0:Math.max(0,u.a0-t),a1:Math.min(n,a.a1+t),b0:Math.max(0,u.b0-t),b1:Math.min(r,a.b1+t)}),o=s+1}return i}var ny=`
103
+ `)throw new b("feature","IFS","custom IFS separators are not supported");let r=[],o={value:"",mask:"",q:!1},i=()=>{(o.value!==""||o.q)&&r.push(o),o={value:"",mask:"",q:!1}},s=new Set(e.empty);for(let u=0;u<=e.value.length&&(s.has(u)&&(o.q=!0),u!==e.value.length);u++){let a=e.value[u],l=e.mask[u];if(n!==""&&l==="0"&&/[ \t\n]/u.test(a)){i();continue}o.value+=a,o.mask+=l,o.q||=l!=="0"}return i(),r}function Ad(e,t,n){let r=Kc(t,n),o={ctx:n,options:r,seen:new Set,result:U(),total:0n,failed:!1};r.stderr&&_(o.result,n.flushOutput(U(r.stderr)));for(let i of r.operands){let s=i.length>2?i.replace(/\/+$/u,"/"):i,u=P(n,"du",s,{follow:r.links!=="none"});if(u.error){_(o.result,n.flushOutput(x(`du: cannot access ${X(s,n)}: ${u.error}`))),o.failed=!0;continue}try{Ex(u.path,s,o)}catch(a){let l=O(a),f="du: "+V(a);if(l&&n.unsupported.add({...l,command:l.command??"du",message:f}),_(o.result,n.flushOutput(x(f))),o.failed=!0,l)return o.result}}return r.flags.has("c")&&Hs(o.total,"total",o),o.result.exitCode=o.failed?1:0,o.result}function Ex(e,t,n){let{ctx:r,options:o}=n;if(!o.flags.has("inodes")&&r.fs.isDir(e)&&Object.values(r.outputFds??{}).some(s=>typeof s=="object"&&s.path?.startsWith(e==="/"?"/":e+"/")))throw new b("feature","recursive metadata output overlap","output within a measured directory is not supported");let i=[{path:e,name:t,depth:0}];for(;i.length;){let s=i.pop();if(s.total!==void 0){s.depth<=o.depth&&Hs(s.total,s.name,n),s.parent&&!o.flags.has("S")&&(s.parent.total+=s.total);continue}let u=r.fs.isDir(s.path);if(u&&r.fs.isFile(s.path))throw new b("feature","ambiguous file type",`path is both a file and a directory: ${s.name}`);if(!u&&o.links==="all"&&r.fs.isLink?.(s.path))throw new b("option","dereference",`following symbolic links is not supported: ${s.name}`);let a=u?s.path:r.fs.fileIdentity?.(s.path)??s.path;if(!o.flags.has("l")&&n.seen.has(a))continue;n.seen.add(a);let l=u?"dir":r.fs.isLink?.(s.path)?"link":"file",f=u?0:r.fs.fileSize(s.path),c=o.flags.has("inodes")?1n:o.flags.has("A")?BigInt(f):BigInt(lo(f,l));if(n.total+=c,u){s.total=c,i.push(s);let d=r.fs.listDir(s.path),p=[...new Set([...d.dirs,...d.files,...d.links])].sort(j),h=s.name.endsWith("/")?s.name:s.name+"/";for(let m=p.length-1;m>=0;m--)i.push({path:Te(s.path,p[m]),name:h+p[m],depth:s.depth+1,parent:s})}else s.parent&&(s.parent.total+=c),(s.depth===0||o.flags.has("a")&&s.depth<=o.depth)&&Hs(c,s.name,n)}}function Hs(e,t,n){let r=`${Kn(e,n.options.scale)} ${t}${n.options.flags.has("0")?"\0":`
104
+ `}`;_(n.result,n.ctx.flushOutput({...U(),stdout:r,events:[{fd:1,text:r}]}))}var $x=/^%([-+ 0#']*)(\d+|\*)?'?(?:\.(\d+|\*)?)?[hlL]?(.)?/su,Nx="diouxXeEfFgGcs";function go(e){let t=[],n="";for(let r=0;r<e.length;r++){if(e[r]!=="%"){n+=e[r];continue}if(e[r+1]==="%"){n+="%",r++;continue}if(/^%[^a-zA-Z%]*\$/u.test(e.slice(r)))throw new $("positional printf arguments are not supported",null,"positional format arguments");let o=$x.exec(e.slice(r)),i=o[4];if(i==="a"||i==="A")throw new $("hexadecimal floating-point formats are not supported",null,"hexadecimal float format");if(i==="%"){n+="%",r+=o[0].length-1;continue}if(i===void 0||!Nx.includes(i)){n+=o[0],r+=o[0].length-1;continue}n!==""&&(t.push(n),n="");let s=o[1];t.push({minus:s.includes("-"),plus:s.includes("+"),space:s.includes(" "),zero:s.includes("0"),alt:s.includes("#"),width:o[2]===void 0?null:o[2]==="*"?"*":Number(o[2]),precision:o[3]===void 0?o[0].includes(".")?0:null:o[3]==="*"?"*":Number(o[3]),conv:i}),r+=o[0].length-1}return n!==""&&t.push(n),t}function Nt(e,t,n,r){let o=n.width??0;if(o>Ce)throw new $("format width exceeds the output limit",null,"format size limit");let i=o-e.length-[...t].length;return i<=0?e+t:n.minus?e+t+" ".repeat(i):n.zero&&r?e+"0".repeat(i)+t:" ".repeat(i)+e+t}var Id=e=>e.plus?"+":e.space?" ":"",Td=e=>e==="X"||e==="E"||e==="G"||e==="F";function Wt(e,t){if(t.precision>Ce)throw new $("format precision exceeds the output limit",null,"format size limit");let{conv:n}=t;if(!Number.isFinite(e)){if(Number.isNaN(e))throw new $("formatting signed NaN is not supported",null,"signed NaN");let r=e<0?"-inf":"+inf";return Td(n)?r.toUpperCase():r}return"ouxX".includes(n)&&(e>=2**64||e<-(2**63))?Od(e,{...t,conv:"g"}):"diouxX".includes(n)?Ax(e,t):Od(e,t)}function Ax(e,t){let{conv:n}=t,r=n==="d"||n==="i",o=r?Math.trunc(e)===0:e===0,i=BigInt(Math.trunc(e)),s=!1;i<0n&&(r?(s=!0,i=-i):i=BigInt.asUintN(64,i));let u=n==="o"?8:n==="x"||n==="X"?16:10,a=i.toString(u);n==="X"&&(a=a.toUpperCase()),t.precision!==null&&(t.precision===0&&o?a=t.alt&&!r?"0":"":a=a.padStart(t.precision,"0"));let l=s?"-":r&&a!==""?Id(t):"";return t.alt&&!o&&(n==="o"&&(a="0"+a),(n==="x"||n==="X")&&(l+=n==="x"?"0x":"0X")),Nt(l,a,t,t.precision===null)}var mo=100;function Od(e,t){let{conv:n}=t;if(t.precision>mo)throw new $(`floating-point precision above ${mo} is not supported`,null,"float precision limit");let r=t.precision??6,o=e<0||Object.is(e,-0),i=Math.abs(e),s;return n==="e"||n==="E"?s=Ld(i,r):n==="f"||n==="F"?s=_d(i,r):s=Ox(i,r,t.alt),t.alt&&r===0&&n!=="g"&&n!=="G"&&(s=n==="e"||n==="E"?s.replace("e",".e"):s+"."),Td(n)&&(s=s.toUpperCase()),Nt(o?"-":Id(t),s,t,!0)}function Fd(e,t,n,r){let o=t.slice(r);if(!/^50*$/u.test(o))return e;let i=t.slice(0,n),s=i.at(-1);return Number(s)%2===0?i:e}function Ld(e,t){let n=e.toExponential(mo),r=n.indexOf("."),o=n.indexOf("e"),[i,s]=e.toExponential(t).split("e"),u=Fd(i,n.slice(0,o),t===0?r:r+1+t,r+1+t),a=Number(u===i?s:n.slice(o+1));return`${u}e${a<0?"-":"+"}${String(Math.abs(a)).padStart(2,"0")}`}function _d(e,t){if(e>=1e21)return BigInt(e).toString()+(t>0?"."+"0".repeat(t):"");let n=e.toFixed(mo),r=n.indexOf(".");return Fd(e.toFixed(t),n,t===0?r:r+1+t,r+1+t)}function Ox(e,t,n){let r=t===0?1:t;if(e===0)return n?"0."+"0".repeat(r-1):"0";let o=Ld(e,r-1),i=o.indexOf("e"),s=Number(o.slice(i+1));if(s<-4||s>=r)return n?o.includes(".")?o:o.slice(0,i)+"."+o.slice(i):Cd(o.slice(0,i))+o.slice(i);let u=_d(e,r-1-s);return n?u.includes(".")?u:u+".":Cd(u)}var Cd=e=>e.includes(".")?e.replace(/\.?0+$/u,""):e;var Cx=/^[+-]?(?:0[bB][01]+|0[xX][\da-fA-F]+|0[0-7]*|[1-9]\d*)/u,Ix=/^[+-]?(?:0[xX](?:[\da-fA-F]+(?:\.[\da-fA-F]*)?|\.[\da-fA-F]+)(?:[pP][+-]?\d+)?|(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?|inf(?:inity)?|nan(?:\([\w]*\))?)/iu;function Pd(e,t){if(e?.[0]!=="'"&&e?.[0]!=='"')return null;let n=e.slice(1);if(n==="")return null;let r=A(n),o=t.byteLocale?1:A(String.fromCodePoint(n.codePointAt(0))).length;return r.length>o&&(t.stderr+=`printf: warning: ${W(r.slice(o))}: character(s) following character constant have been ignored
105
+ `),t.byteLocale?r[0]:n.codePointAt(0)}function Dd(e,t,n){if(e===void 0||e==="")return"0";let r=e.replace(/^[ \t\n\r\f\v]+/u,""),o=t.exec(r)?.[0]??"";return(o.length!==r.length||o==="")&&(n.stderr+=`printf: ${Bd(e,n)}: ${o?"value not completely converted":"expected a numeric value"}
106
+ `,n.failed=!0),o||"0"}var Rd={"\x07":"\\a","\b":"\\b"," ":"\\t","\n":"\\n","\v":"\\v","\f":"\\f","\r":"\\r","\\":"\\\\","'":"\\'"},Md=e=>"\\"+e.toString(8).padStart(3,"0");function Bd(e,t){let n="";for(let r of e){if(Rd[r]!==void 0){n+=Rd[r];continue}let o=r.codePointAt(0);if(o<32||o===127){n+=Md(o);continue}n+=o>127&&t.byteLocale?A(r).map(Md).join(""):r}return`'${n}'`}function wo(e,t,n){let r=Pd(e,n);if(r!==null)return BigInt(r);let o=Dd(e,Cx,n),i=o[0]==="-",s=o.replace(/^[+-]/u,""),u=BigInt(/^0[0-7]+$/u.test(s)?"0o"+s:s),a=i?-u:u;return(t?u>it:a<ot||a>ue)?(n.stderr+=`printf: ${Bd(e,n)}: Numerical result out of range
107
+ `,n.failed=!0,t?it:i?ot:ue):t?BigInt.asUintN(64,a):a}function yo(e,t){let{conv:n}=t,r=n==="d"||n==="i",o=e<0n,i=n==="o"?8:n==="x"||n==="X"?16:10,s=(o?-e:e).toString(i);n==="X"&&(s=s.toUpperCase()),e===0n&&t.precision===0&&(s=""),s=s.padStart(t.precision??0,"0");let u=o?"-":r?t.plus?"+":t.space?" ":"":"";return t.alt&&(n==="o"&&!s.startsWith("0")&&(s="0"+s),e!==0n&&(n==="x"||n==="X")&&(u=n==="x"?"0x":"0X")),Nt(u,s,t,t.precision===null)}function Ud(e,t,n){let r=Pd(e,n),o=r===null?Dd(e,Ix,n):String(r),i=o.replace(/^[+-]/u,"");if(/^(?:inf|nan)/iu.test(i)){let a=o.startsWith("-")?"-":t.plus?"+":t.space?" ":"",l=/^nan/iu.test(i)?"nan":"inf";return t.conv===t.conv.toUpperCase()&&(l=l.toUpperCase()),Nt(a,l,t,!1)}let s=Rx(i),u=o.startsWith("-")?-s.value:s.value;if(t.precision>100||"gG".includes(t.conv)&&t.precision>96)throw new b("feature","float precision limit","floating-point precision exceeds the supported limit");try{let a=Wt(u,t);if(!s.exact){let[l,f]=Tx(s.value);for(let c of[l,f])if(Wt(o.startsWith("-")?-c:c,t)!==a)throw new b("feature","floating-point precision","floating-point formatting at this precision is not supported")}return a}catch(a){throw a.gap?new b("feature",a.gap,a.message):a}}var fn=new DataView(new ArrayBuffer(8));function jd(e){return fn.setFloat64(0,e),fn.getBigUint64(0)}function Tx(e){let t=jd(e);fn.setBigUint64(0,t-1n);let n=fn.getFloat64(0);return fn.setBigUint64(0,t+1n),[n,fn.getFloat64(0)]}function Fx(e){let t=jd(e),n=Number(t>>52n);return{coefficient:t&(1n<<52n)-1n|(n?1n<<52n:0n),exponent:n?n-1075:-1074}}function Gs(e,t){let n=e.replace(/^0+|0+$/gu,"");return{digits:n||"0",exponent:n?t+e.length-e.replace(/0+$/u,"").length:0}}function Lx({coefficient:e,exponent:t}){return t<0?Gs((e*5n**BigInt(-t)).toString(),t):Gs((e<<BigInt(t)).toString(),0)}function _x(e,t){let n=e.exponent-t.exponent;return n>=0?e.coefficient<<BigInt(n)===t.coefficient:e.coefficient===t.coefficient<<BigInt(-n)}function Rx(e){let t=/^0x/iu.test(e),n,r;if(t)n=Mx(e),r=Px(n);else{let[u,a="0"]=e.split(/[eE]/u),[l,f=""]=u.split(".");n=Gs(l+f,Number(a)-f.length),r=Number(e)}if(!Number.isFinite(r))throw new b("feature","floating-point range","floating-point values outside the JavaScript number range are not supported");if(r===0){if(t?n.coefficient!==0n:n.digits!=="0")throw new b("feature","floating-point range","floating-point underflow is not supported");return{value:r,exact:!0}}let o=Fx(r),i=Lx(o),s=t?_x(n,o):n.digits===i.digits&&n.exponent===i.exponent;return{value:r,exact:s&&i.exponent>=-100&&i.digits.length<=101}}function Mx(e){let[t,n="0"]=e.slice(2).split(/[pP]/u),[r,o=""]=t.split("."),i=(r+o).replace(/^0+/u,"")||"0";if(i.length>4096)throw new b("feature","floating-point input limit","hexadecimal floating-point significands above 4096 digits are not supported");return{coefficient:BigInt("0x"+i),exponent:Number(n)-4*o.length}}function Px({coefficient:e,exponent:t}){if(e===0n)return 0;let n=e.toString(2).length,r=t+n-1;if(r>1023)return 1/0;if(r<-1075)return 0;let o=Math.max(0,n-53,-1074-t),i=e>>BigInt(o);if(o>0){let s=e-(i<<BigInt(o)),u=1n<<BigInt(o-1);(s>u||s===u&&i%2n!==0n)&&i++}return Number(i)*2**(t+o)}var Wd={a:7,b:8,e:27,f:12,n:10,r:13,t:9,v:11,'"':34,"\\":92};function zd(e,t){let n=[];for(let r=0;r<e.length;)if(e[r]==="%"){if(e[r+1]==="%"||r+1===e.length){n.push([37]),r+=2;continue}let o=/^%([-+ #0']*)(\d+)?(?:\.(\d*))?([\s\S])?/u.exec(e.slice(r)),[,i,s,u,a]=o;if(!a||a==="%")throw new Error(`invalid directive: ${o[0]}`);if(!"nsF".includes(a))throw new b("feature","%"+a,`format %${a} is not supported`);if(i.includes("'"))throw new b("feature","grouped format","digit grouping in stat formats is not supported");let l={field:a,conv:"u",width:Number(s??0),precision:u===void 0?null:Number(u||0),minus:i.includes("-"),zero:i.includes("0"),plus:i.includes("+"),space:i.includes(" "),alt:i.includes("#")};if(l.width>Ce||l.precision>Ce)throw new b("feature","format size limit","format width or precision exceeds the output limit");n.push(l),r+=o[0].length}else if(e[r]==="\\"&&t){let o=e[r+1],i=/^(?:[0-7]{1,3}|x[\da-fA-F]{1,2})/u.exec(e.slice(r+1))?.[0];if(i){let s=i[0]==="x"?16:8;n.push([parseInt(s===16?i.slice(1):i,s)&255]),r+=i.length+1}else if(Object.hasOwn(Wd,o))n.push([Wd[o]]),r+=2;else throw new b("feature","format escape",`format escape ${JSON.stringify(e.slice(r,r+2))} is not supported`)}else{let o=r+1;for(;o<e.length&&e[o]!=="%"&&!(t&&e[o]==="\\");)o++;n.push(B(e.slice(r,o))),r=o}return t||n.push([10]),n}function Hd(e,t,n,r){let o=r.isDir(n);if(o&&r.isFile(n))throw new b("feature","ambiguous file type",`path is both a file and a directory: ${t}`);let i=!o&&r.isLink?.(n)===!0,s,u=e.map(f=>{if(!f.field)return f;if(f.field==="n")return qd(t,f);if(f.field==="s"&&o)throw new b("feature","directory byte size",`directory byte sizes are not available: ${t}`);return s??=o?0:r.fileSize(n),f.field==="F"?qd(o?"directory":i?"symbolic link":s===0?"regular empty file":"regular file",f):B(yo(BigInt(s),f))}),a=new Uint8Array(u.reduce((f,c)=>f+c.length,0)),l=0;for(let f of u)a.set(f,l),l+=f.length;return W(a)}function qd(e,t){let n=B(e);t.precision!==null&&(n=n.subarray(0,t.precision));let r=Math.max(0,t.width-n.length);if(!r)return n;let o=new Uint8Array(n.length+r).fill(32);return o.set(n,t.minus?0:r),o}function Gd(e,t,n){let{order:r,positional:o}=N(t,{short:["L","t"],long:["dereference","terse"],valueShort:["c"],valueLong:["format","printf","cached"]});if(!o.length)return x("stat: missing operand");let i=r.some(({name:f})=>f==="L"||f==="dereference"),s;for(let f of r)if(f.name==="cached"){if(!f.value||!["always","never","default"].some(c=>c.startsWith(f.value)))return x(`stat: invalid cache mode: ${f.value}`)}else["c","format","printf"].includes(f.name)&&(s=f);if(!s)return v("feature","stat","default metadata","stat: default output requires filesystem metadata that is not available");let u=zd(s.value,s.name==="printf");if(u.some(f=>f.field==="s"||f.field==="F")&&Bx(o,n,i))return v("feature","stat","metadata output overlap","stat: buffered output sharing a measured file is not supported");let a=U(),l=!1;for(let f of o){let c=Dx(u,f,n,i);_(a,c),l||=c.exitCode!==0}return a.exitCode=l?1:0,a}function Dx(e,t,n,r){if(t==="-"){let i=v("feature","stat","standard input metadata","stat: standard input metadata is not supported");return n.unsupported.add({kind:"feature",command:"stat",detail:"standard input metadata",message:i.stderr.trimEnd()}),i}let o=P(n,"stat",t,{follow:r});if(o.error)return x(`stat: cannot statx ${X(t,n)}: ${o.error}`);try{return F(Hd(e,t,o.path,n.fs))}catch(i){let s=K(i,"stat","stat: "+V(i)),u=O(s);return u&&n.unsupported.add(u),s}}function Bx(e,t,n){let r=Object.values(t.outputFds).filter(o=>typeof o=="object");return r.length?e.some(o=>{let i=E(t.cwd,o,t.fs,{follow:n});return!i.error&&r.some(s=>s.path===i.path||s.identity!==void 0&&s.identity===t.fs.fileIdentity?.(i.path))}):!1}var Ux=/[ \t\n\v\f\r]/gu,jx=/[ \t\n\v\f\r]+/gu,Xd=/[ \t\n\v\f\r]+$/u,Zd=e=>e.replace(/[A-Z]/gu,t=>t.toLowerCase());function bo({ignoreCase:e=!1,whitespace:t="none"}={}){let n=null;return t==="all"?n=r=>r.replace(Ux,""):t==="change"?n=r=>r.replace(Xd,"").replace(jx," "):t==="trailing"&&(n=r=>r.replace(Xd,"")),e?n?r=>Zd(n(r)):Zd:n}function At(e){let t=[];for(let n=0;n<e.length;){let r=e.indexOf(`
108
+ `,n),o=r<0?e.length:r+1;t.push(e.slice(n,o)),n=o}return t}var cn=/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(?: ?(.*?))?\n?$/u,qt=/^\*{15,}(?: (.*?))?\n?$/u,xo=/^\*{3} (\d+)(?:,(\d+))? \*{4}\n?$/u,tr=/^--- (\d+)(?:,(\d+))? ----\n?$/u,dn=/^(\d+)(?:,(\d+))?([acd])(\d+)(?:,(\d+))?[ \t]*\r?\n?$/u;var Pe=class extends Error{constructor(t,n){super(n===void 0?t:`${t} at line ${n+1}`),this.name="PatchError",this.line=n}},Yd=(e,t)=>t===0?Number(e):Number(e)-1,Xs=e=>e!==void 0&&e.startsWith("\\"),Zs=e=>e.replace(/\n$/u,"");function Ys(e){let t=At(e),n=[],r={old:null,new:null},o=!1;for(let i=0;i<t.length;){let s=t[i],u=Vd(s,o);if(o=s.startsWith("***************")?!1:s.startsWith("*** "),u){r=u.names??{...r,[u.slot]:u.name},i++;continue}let a=cn.test(s)?"unified":qt.test(s)?"context":dn.test(s)?"normal":null;if(a===null){i++;continue}let l=[],f=Xx[a];for(let c=f(t,i);c!==null&&(l.push(c.hunk),i=c.next,!(i>=t.length||Vd(t[i],!1)));c=f(t,i));n.push({old:r.old,new:r.new,format:a,hunks:l,blocks:Wx(l)}),r={old:null,new:null}}return n}function Vd(e,t){let n=/^diff --git (\S+) (\S+)\n?$/u.exec(e);if(n)return{names:{old:n[1],new:n[2]}};if(xo.test(e)||tr.test(e))return null;let r=/^(\*\*\* |--- |\+\+\+ )(.*?)(?:\t.*)?\n?$/u.exec(e);return r?r[1]==="--- "?{slot:t?"new":"old",name:r[2]}:{slot:r[1]==="*** "?"old":"new",name:r[2]}:null}function Wx(e){let t=[];for(let n of e){let r=n.oldStart,o=n.newStart,i=null,s=()=>{i&&(t.push(i),r=i.a1,o=i.b1,i=null)};for(let{tag:u,text:a}of n.lines){if(u===" "){s(),r++,o++;continue}u==="-"&&i?.insert.length&&s(),i??={a0:r,a1:r,b0:o,b1:o,remove:[],insert:[]},u==="-"?(i.a1++,i.remove.push(a)):(i.b1++,i.insert.push(a))}s()}return t}function qx(e,t){let n=cn.exec(e[t]??"");if(!n)return null;let r=n[2]===void 0?1:Number(n[2]),o=n[4]===void 0?1:Number(n[4]),i={oldStart:Yd(n[1],r),newStart:Yd(n[3],o),label:n[5]||null,lines:[]},s=0,u=t+1,a=0;for(;a<r||s<o;u++){let l=e[u];if(l===void 0)throw new Pe("the patch ends inside a hunk",u);let f=l===`
109
+ `?" ":l[0];if(f!==" "&&f!=="-"&&f!=="+")throw new Pe(`a hunk line begins with ${JSON.stringify(f)}`,u);let c=l===`
110
+ `?l:l.slice(1);if(Xs(e[u+1])&&(c=Zs(c),u++),f!=="+"&&a++,f!=="-"&&s++,a>r||s>o)throw new Pe("a hunk has more lines than its header says",u);i.lines.push({tag:f,text:c})}return{hunk:i,next:u}}function zx(e,t){let n=dn.exec(e[t]??"");if(!n)return null;let[,r,o,i,s,u]=n,a=i==="a"?0:Number(o??r)-Number(r)+1,l=i==="d"?0:Number(u??s)-Number(s)+1;if(a<0||l<0)throw new Pe("a change command counts backwards",t);let f={oldStart:i==="a"?Number(r):Number(r)-1,newStart:i==="d"?Number(s):Number(s)-1,label:null,lines:[]},c=t+1,d=(p,h,m)=>{for(let g=0;g<p;g++,c++){let w=e[c];if(w===void 0)throw new Pe("the patch ends inside a hunk",c);if(w[0]!==h)throw new Pe(`${JSON.stringify(h)} expected`,c);let y=w.slice(2);Xs(e[c+1])&&(y=Zs(y),c++),f.lines.push({tag:m,text:y})}};if(d(a,"<","-"),i==="c"){if(e[c]!==`---
111
+ `)throw new Pe("'---' expected",c);c++}return d(l,">","+"),{hunk:f,next:c}}function Hx(e,t){let n=qt.exec(e[t]??"");if(!n)return null;let r=xo.exec(e[t+1]??"");if(!r)throw new Pe("'*** ' range expected",t+1);let o=t+2,i=Jd(e,o,tr,"-");o=i.next;let s=tr.exec(e[o]??"");if(!s)throw new Pe("'--- ' range expected",o);let u=Jd(e,o+1,null,"+"),a=i.lines.length===0?u.lines.filter(d=>d.tag===" "):i.lines,l=u.lines.length===0?i.lines.filter(d=>d.tag===" "):u.lines,f=Kd(r,a.length),c=Kd(s,l.length);return{hunk:{oldStart:f,newStart:c,label:n[1]||null,lines:Gx(a,l)},next:u.next}}var Kd=(e,t)=>t===0?Number(e[1]):Number(e[1])-1;function Jd(e,t,n,r){let o=[],i=t;for(;i<e.length;i++){let s=e[i];if(n&&n.test(s)||qt.test(s)||xo.test(s)||!n&&tr.test(s))break;if(Xs(s)){o[o.length-1].text=Zs(o.at(-1).text);continue}let u=s===`
112
+ `?" ":s[0];if(u!==" "&&u!=="!"&&u!=="-"&&u!=="+")break;o.push({tag:u===" "?" ":r,text:s===`
113
+ `?s:s.slice(2)})}return{lines:o,next:i}}function Gx(e,t){let n=[],r=0,o=0;for(;r<e.length||o<t.length;){if(e[r]?.tag===" "&&t[o]?.tag===" "){n.push(e[r]),r++,o++;continue}for(;r<e.length&&e[r].tag!==" ";)n.push(e[r]),r++;for(;o<t.length&&t[o].tag!==" ";)n.push(t[o]),o++;e[r]?.tag===" "&&t[o]===void 0?(n.push(e[r]),r++):t[o]?.tag===" "&&e[r]===void 0&&(n.push(t[o]),o++)}return n}var Xx={unified:qx,context:Hx,normal:zx};var We=class extends Error{constructor(t){super(`the rendered diff does not say what the change set says (${t})`),this.name="FormatError"}};function Vs(e,t,n,r){if(n.length===0){if(r!=="")throw new We("there was nothing to print, and something was printed");return}let o;try{o=Ys(r)}catch(s){throw new We(`it does not read back (${s.message})`)}if(o.length!==1)throw new We(`${o.length} files read back, not one`);let i=o[0].blocks;if(i.length!==n.length)throw new We(`${i.length} blocks read back, not ${n.length}`);for(let[s,u]of i.entries()){let a=n[s];if(u.a0!==a.a0||u.a1!==a.a1||u.b0!==a.b0||u.b1!==a.b1)throw new We(`block ${s+1} reads back somewhere else`)}for(let s of o[0].hunks){let u=s.oldStart,a=s.newStart;for(let{tag:l,text:f}of s.lines){let c=l==="+"?t[a]:e[u];if(f!==c)throw new We(`a ${l==="+"?"added":l==="-"?"removed":"kept"} line is not the line it stands for`);l!=="+"&&u++,l!=="-"&&a++}}}function rp(e,t,n,r){let o=[],i=0;for(;i<e.length;){let s=i;for(;s+1<e.length&&e[s+1].a0-e[s].a1<=2*t;)s++;let u=e[i],a=e[s];o.push({blocks:e.slice(i,s+1),a0:Math.max(0,u.a0-t),a1:Math.min(n,a.a1+t),b0:Math.max(0,u.b0-t),b1:Math.min(r,a.b1+t)}),i=s+1}return o}var Zx=`
99
114
  \
100
- `,et=(e,t)=>e+t+(t.endsWith(`
101
- `)?"":ny);function Nf(e,t){return t>e+1?`${e+1},${t}`:`${t>e?e+1:e}`}function Ff(e,t,n){let r="";for(let{a0:i,a1:o,b0:s,b1:u}of n){let a=i===o?"a":s===u?"d":"c";r+=Nf(i,o)+a+Nf(s,u)+`
102
- `;for(let l=i;l<o;l++)r+=et("< ",e[l]);a==="c"&&(r+=`---
103
- `);for(let l=s;l<u;l++)r+=et("> ",t[l])}return ds(e,t,n,r),r}function Af(e,t){return t<=e?`${e},0`:t===e+1?`${e+1}`:`${e+1},${t-e}`}function Tf(e,t,n,{context:r,label:i=null}){let o="";for(let s of Cf(n,r,e.length,t.length)){let u=i?i(s.a0):null;o+=`@@ -${Af(s.a0,s.a1)} +${Af(s.b0,s.b1)} @@${u===null?"":" "+u}
104
- `;let a=s.a0,l=s.b0;for(let{a0:c,a1:f,b1:d}of s.blocks){for(;a<c;a++,l++)o+=et(" ",e[a]);for(;a<f;a++)o+=et("-",e[a]);for(;l<d;l++)o+=et("+",t[l])}for(;a<s.a1;a++,l++)o+=et(" ",e[a])}return ds(e,t,n,o),o}function If(e,t){return t<=e?`${e}`:t===e+1?`${e+1}`:`${e+1},${t}`}function _f(e,t,n,{context:r,label:i=null}){let o="";for(let s of Cf(n,r,e.length,t.length)){let u=i?i(s.a0):null;o+=`***************${u===null?"":" "+u}
105
- `,o+=`*** ${If(s.a0,s.a1)} ****
106
- `,s.blocks.some(a=>a.a0<a.a1)&&(o+=Of(e,s.a0,s.a1,s.blocks,"a")),o+=`--- ${If(s.b0,s.b1)} ----
107
- `,s.blocks.some(a=>a.b0<a.b1)&&(o+=Of(t,s.b0,s.b1,s.blocks,"b"))}return ds(e,t,n,o),o}function Of(e,t,n,r,i){let o=i+"1",s=i+"0",u=i==="a"?"b":"a",a="",l=t;for(let c of r){for(;l<c[s];l++)a+=et(" ",e[l]);let f=c[u+"0"]<c[u+"1"]?"! ":i==="a"?"- ":"+ ";for(;l<c[o];l++)a+=et(f,e[l])}for(;l<n;l++)a+=et(" ",e[l]);return a}function ry(e){let t=[];for(let n=0;;){let r=n;for(;n<e.length&&e[n];)n++;if(t.push(n>r),n===e.length)return t;n++}}function ps(e,t,n){let r=t.length,i=ry(n),o=0,s=0,u=0,a=()=>{if(o===r||e[u]!==e[o])return!1;for(t[u++]=0,t[o++]=1,s++;o<r&&t[o];)o++;return!0},l=()=>{if(u===0||e[u-1]!==e[o-1])return!1;for(t[--u]=1,t[--o]=0,s--;u>0&&t[u-1];)u--;return!0};for(let c=0;c<r;c++){if(!t[c]){s++;continue}for(u=c,o=c;o<r&&t[o];o++);let f=-1;for(let d=-1;d!==o-u;){for(d=o-u;l(););for(f=i[s]?o:-1;a();)i[s]&&(f=o)}if(f!==-1)for(let d=o-f;d>0;d--)l();c=o-1}}function iy(e){let t=1;for(let n=e;n!==0;n>>=2)t<<=1;return Math.max(256,t)}function Lf(e,t,{ignoreCase:n=!1,whitespace:r="none",minimal:i=!1,slide:o=!0}={}){let s=Gr({ignoreCase:n,whitespace:r});if(s===null&&hs(e,t,null))return[];let{A:u,B:a}=oy(e,t,s),l=new Uint8Array(u.length),c=new Uint8Array(a.length);sy(u,a,l,c,i),o&&(ps(u,l,c),ps(a,c,l));let f=ly(l,c);return cy(e,t,f,s),f}function hs(e,t,n=null){if(e.length!==t.length)return!1;let r=n?(i,o)=>n(i)===n(o):(i,o)=>i===o;for(let i=0;i<e.length;i++)if(!r(e[i],t[i]))return!1;return!0}function oy(e,t,n){let r=new Map,i=u=>{let a=n?n(u):u,l=r.get(a);return l===void 0&&(l=r.size,r.set(a,l)),l},o=new Int32Array(e.length),s=new Int32Array(t.length);for(let u=0;u<e.length;u++)o[u]=i(e[u]);for(let u=0;u<t.length;u++)s[u]=i(t[u]);return{A:o,B:s}}function sy(e,t,n,r,i){let o=e.length+t.length+3,s={A:e,B:t,fd:new Int32Array(o),bd:new Int32Array(o),base:t.length+1,limit:iy(e.length+t.length)},u=[{xoff:0,xlim:e.length,yoff:0,ylim:t.length,minimal:i}],a={xmid:0,ymid:0,loMinimal:!1,hiMinimal:!1};for(;u.length;){let{xoff:l,xlim:c,yoff:f,ylim:d,minimal:p}=u.pop();for(;l<c&&f<d&&e[l]===t[f];)l++,f++;for(;l<c&&f<d&&e[c-1]===t[d-1];)c--,d--;if(l===c){for(;f<d;f++)r[f]=1;continue}if(f===d){for(;l<c;l++)n[l]=1;continue}uy(s,l,c,f,d,p,a),u.push({xoff:a.xmid,xlim:c,yoff:a.ymid,ylim:d,minimal:a.hiMinimal}),u.push({xoff:l,xlim:a.xmid,yoff:f,ylim:a.ymid,minimal:a.loMinimal})}}function uy(e,t,n,r,i,o,s){let{A:u,B:a,fd:l,bd:c,base:f,limit:d}=e,p=n-r,m=t-i,h=n-i,g=t-r,x=h,b=h,S=g,A=g,V=(g-h&1)!==0;l[f+g]=t,c[f+h]=n;for(let q=1;;q++){A>m?l[f+--A-1]=-1:++A,S<p?l[f+ ++S+1]=-1:--S;for(let T=S;T>=A;T-=2){let Y=l[f+T+1],Ie=l[f+T-1],X=Ie<Y?Y:Ie+1,ve=X-T;for(;X<n&&ve<i&&u[X]===a[ve];)X++,ve++;if(l[f+T]=X,V&&b<=T&&T<=x&&c[f+T]<=X){s.xmid=X,s.ymid=ve,s.loMinimal=s.hiMinimal=!0;return}}b>m?c[f+--b-1]=2147483647:++b,x<p?c[f+ ++x+1]=2147483647:--x;for(let T=x;T>=b;T-=2){let Y=c[f+T+1],Ie=c[f+T-1],X=Ie<Y?Ie:Y-1,ve=X-T;for(;t<X&&r<ve&&u[X-1]===a[ve-1];)X--,ve--;if(c[f+T]=X,!V&&A<=T&&T<=S&&X<=l[f+T]){s.xmid=X,s.ymid=ve,s.loMinimal=s.hiMinimal=!0;return}}if(!(o||q<d)){ay(e,{xoff:t,xlim:n,yoff:r,ylim:i,fmin:A,fmax:S,bmin:b,bmax:x},s);return}}}function ay(e,t,n){let{fd:r,bd:i,base:o}=e,{xoff:s,xlim:u,yoff:a,ylim:l,fmin:c,fmax:f,bmin:d,bmax:p}=t,m=0,h=-1;for(let b=f;b>=c;b-=2){let S=Math.min(r[o+b],u),A=S-b;l<A&&(S=l+b,A=l),h<S+A&&(h=S+A,m=S)}let g=0,x=2147483647;for(let b=p;b>=d;b-=2){let S=Math.max(s,i[o+b]),A=S-b;A<a&&(S=a+b,A=a),S+A<x&&(x=S+A,g=S)}u+l-x<h-(s+a)?(n.xmid=m,n.ymid=h-m,n.loMinimal=!0,n.hiMinimal=!1):(n.xmid=g,n.ymid=x-g,n.loMinimal=!1,n.hiMinimal=!0)}function ly(e,t){let n=[],r=t.length,i=e.length,o=0,s=0;for(;o<i||s<r;){if(o<i&&s<r&&!e[o]&&!t[s]){o++,s++;continue}let u=o,a=s;for(;o<i&&e[o];)o++;for(;s<r&&t[s];)s++;if(u===o&&a===s)throw new me("a kept line has no counterpart");n.push({a0:u,a1:o,b0:a,b1:s})}return n}function cy(e,t,n,r=null){let i=r?(u,a)=>r(u)===r(a):(u,a)=>u===a,o=0,s=0;for(let{a0:u,a1:a,b0:l,b1:c}of n){if(u<o||l<s||a<u||c<l||a>e.length||c>t.length)throw new me("a block is out of order or out of range");if(u===a&&l===c)throw new me("a block changes nothing");if(u-o!==l-s)throw new me("the kept lines before a block differ in count");for(;o<u;o++,s++)if(!i(e[o],t[s]))throw new me(`kept line ${o+1} does not match`);o=a,s=c}if(e.length-o!==t.length-s)throw new me("the kept lines after the last block differ in count");for(;o<e.length;o++,s++)if(!i(e[o],t[s]))throw new me(`kept line ${o+1} does not match`)}var me=class extends Error{constructor(t){super(`the computed change set does not reconstruct the second file (${t})`),this.name="DiffError"}};var fy={unified:Tf,context:_f},Rf=`Files differ
108
- `;function dy(e,t,n){if(e===t)return"";let r=Gr(n);return r===null?Rf:hs(xt(e),xt(t),r)?"":Rf}function qn(e,t,{format:n="unified",context:r=3,label:i=null,...o}={}){if(n==="brief")return dy(e,t,o);let s=xt(e),u=xt(t),{slide:a=n!=="normal"&&r>0,...l}=o,c=Lf(s,u,{...l,slide:a});return c.length===0?"":n==="normal"?Ff(s,u,c):fy[n](s,u,c,{context:r,label:i})}var py=[" 1970-01-01 00:00:00.000000000 +0000"," Thu Jan 1 00:00:00 1970"];function Mf(e,t,n,r,i){let{ctx:o,opts:s}=e,u=hy(s,t);if(u==="")return"";let a=f=>s.labels[f]??Po(n[f],o)+(r[f]?py[s.style==="context"?1:0]:""),l=f=>s.labels[f]??Po(n[f],o),c=i?`diff${s.switches} ${l(0)} ${l(1)}
109
- `:"";return s.style==="unified"?`${c}--- ${a(0)}
115
+ `,dt=(e,t)=>e+t+(t.endsWith(`
116
+ `)?"":Zx);function Qd(e,t){return t>e+1?`${e+1},${t}`:`${t>e?e+1:e}`}function op(e,t,n){let r="";for(let{a0:o,a1:i,b0:s,b1:u}of n){let a=o===i?"a":s===u?"d":"c";r+=Qd(o,i)+a+Qd(s,u)+`
117
+ `;for(let l=o;l<i;l++)r+=dt("< ",e[l]);a==="c"&&(r+=`---
118
+ `);for(let l=s;l<u;l++)r+=dt("> ",t[l])}return Vs(e,t,n,r),r}function ep(e,t){return t<=e?`${e},0`:t===e+1?`${e+1}`:`${e+1},${t-e}`}function ip(e,t,n,{context:r,label:o=null}){let i="";for(let s of rp(n,r,e.length,t.length)){let u=o?o(s.a0):null;i+=`@@ -${ep(s.a0,s.a1)} +${ep(s.b0,s.b1)} @@${u===null?"":" "+u}
119
+ `;let a=s.a0,l=s.b0;for(let{a0:f,a1:c,b1:d}of s.blocks){for(;a<f;a++,l++)i+=dt(" ",e[a]);for(;a<c;a++)i+=dt("-",e[a]);for(;l<d;l++)i+=dt("+",t[l])}for(;a<s.a1;a++,l++)i+=dt(" ",e[a])}return Vs(e,t,n,i),i}function tp(e,t){return t<=e?`${e}`:t===e+1?`${e+1}`:`${e+1},${t}`}function sp(e,t,n,{context:r,label:o=null}){let i="";for(let s of rp(n,r,e.length,t.length)){let u=o?o(s.a0):null;i+=`***************${u===null?"":" "+u}
120
+ `,i+=`*** ${tp(s.a0,s.a1)} ****
121
+ `,s.blocks.some(a=>a.a0<a.a1)&&(i+=np(e,s.a0,s.a1,s.blocks,"a")),i+=`--- ${tp(s.b0,s.b1)} ----
122
+ `,s.blocks.some(a=>a.b0<a.b1)&&(i+=np(t,s.b0,s.b1,s.blocks,"b"))}return Vs(e,t,n,i),i}function np(e,t,n,r,o){let i=o+"1",s=o+"0",u=o==="a"?"b":"a",a="",l=t;for(let f of r){for(;l<f[s];l++)a+=dt(" ",e[l]);let c=f[u+"0"]<f[u+"1"]?"! ":o==="a"?"- ":"+ ";for(;l<f[i];l++)a+=dt(c,e[l])}for(;l<n;l++)a+=dt(" ",e[l]);return a}function Yx(e){let t=[];for(let n=0;;){let r=n;for(;n<e.length&&e[n];)n++;if(t.push(n>r),n===e.length)return t;n++}}function Ks(e,t,n){let r=t.length,o=Yx(n),i=0,s=0,u=0,a=()=>{if(i===r||e[u]!==e[i])return!1;for(t[u++]=0,t[i++]=1,s++;i<r&&t[i];)i++;return!0},l=()=>{if(u===0||e[u-1]!==e[i-1])return!1;for(t[--u]=1,t[--i]=0,s--;u>0&&t[u-1];)u--;return!0};for(let f=0;f<r;f++){if(!t[f]){s++;continue}for(u=f,i=f;i<r&&t[i];i++);let c=-1;for(let d=-1;d!==i-u;){for(d=i-u;l(););for(c=o[s]?i:-1;a();)o[s]&&(c=i)}if(c!==-1)for(let d=i-c;d>0;d--)l();f=i-1}}function Vx(e){let t=1;for(let n=e;n!==0;n>>=2)t<<=1;return Math.max(256,t)}function up(e,t,{ignoreCase:n=!1,whitespace:r="none",minimal:o=!1,slide:i=!0}={}){let s=bo({ignoreCase:n,whitespace:r});if(s===null&&Js(e,t,null))return[];let{A:u,B:a}=Kx(e,t,s),l=new Uint8Array(u.length),f=new Uint8Array(a.length);Jx(u,a,l,f,o),i&&(Ks(u,l,f),Ks(a,f,l));let c=t2(l,f);return n2(e,t,c,s),c}function Js(e,t,n=null){if(e.length!==t.length)return!1;let r=n?(o,i)=>n(o)===n(i):(o,i)=>o===i;for(let o=0;o<e.length;o++)if(!r(e[o],t[o]))return!1;return!0}function Kx(e,t,n){let r=new Map,o=u=>{let a=n?n(u):u,l=r.get(a);return l===void 0&&(l=r.size,r.set(a,l)),l},i=new Int32Array(e.length),s=new Int32Array(t.length);for(let u=0;u<e.length;u++)i[u]=o(e[u]);for(let u=0;u<t.length;u++)s[u]=o(t[u]);return{A:i,B:s}}function Jx(e,t,n,r,o){let i=e.length+t.length+3,s={A:e,B:t,fd:new Int32Array(i),bd:new Int32Array(i),base:t.length+1,limit:Vx(e.length+t.length)},u=[{xoff:0,xlim:e.length,yoff:0,ylim:t.length,minimal:o}],a={xmid:0,ymid:0,loMinimal:!1,hiMinimal:!1};for(;u.length;){let{xoff:l,xlim:f,yoff:c,ylim:d,minimal:p}=u.pop();for(;l<f&&c<d&&e[l]===t[c];)l++,c++;for(;l<f&&c<d&&e[f-1]===t[d-1];)f--,d--;if(l===f){for(;c<d;c++)r[c]=1;continue}if(c===d){for(;l<f;l++)n[l]=1;continue}Qx(s,l,f,c,d,p,a),u.push({xoff:a.xmid,xlim:f,yoff:a.ymid,ylim:d,minimal:a.hiMinimal}),u.push({xoff:l,xlim:a.xmid,yoff:c,ylim:a.ymid,minimal:a.loMinimal})}}function Qx(e,t,n,r,o,i,s){let{A:u,B:a,fd:l,bd:f,base:c,limit:d}=e,p=n-r,h=t-o,m=n-o,g=t-r,w=m,y=m,k=g,S=g,I=(g-m&1)!==0;l[c+g]=t,f[c+m]=n;for(let M=1;;M++){S>h?l[c+--S-1]=-1:++S,k<p?l[c+ ++k+1]=-1:--k;for(let C=k;C>=S;C-=2){let H=l[c+C+1],Y=l[c+C-1],D=Y<H?H:Y+1,de=D-C;for(;D<n&&de<o&&u[D]===a[de];)D++,de++;if(l[c+C]=D,I&&y<=C&&C<=w&&f[c+C]<=D){s.xmid=D,s.ymid=de,s.loMinimal=s.hiMinimal=!0;return}}y>h?f[c+--y-1]=2147483647:++y,w<p?f[c+ ++w+1]=2147483647:--w;for(let C=w;C>=y;C-=2){let H=f[c+C+1],Y=f[c+C-1],D=Y<H?Y:H-1,de=D-C;for(;t<D&&r<de&&u[D-1]===a[de-1];)D--,de--;if(f[c+C]=D,!I&&S<=C&&C<=k&&D<=l[c+C]){s.xmid=D,s.ymid=de,s.loMinimal=s.hiMinimal=!0;return}}if(!(i||M<d)){e2(e,{xoff:t,xlim:n,yoff:r,ylim:o,fmin:S,fmax:k,bmin:y,bmax:w},s);return}}}function e2(e,t,n){let{fd:r,bd:o,base:i}=e,{xoff:s,xlim:u,yoff:a,ylim:l,fmin:f,fmax:c,bmin:d,bmax:p}=t,h=0,m=-1;for(let y=c;y>=f;y-=2){let k=Math.min(r[i+y],u),S=k-y;l<S&&(k=l+y,S=l),m<k+S&&(m=k+S,h=k)}let g=0,w=2147483647;for(let y=p;y>=d;y-=2){let k=Math.max(s,o[i+y]),S=k-y;S<a&&(k=a+y,S=a),k+S<w&&(w=k+S,g=k)}u+l-w<m-(s+a)?(n.xmid=h,n.ymid=m-h,n.loMinimal=!0,n.hiMinimal=!1):(n.xmid=g,n.ymid=w-g,n.loMinimal=!1,n.hiMinimal=!0)}function t2(e,t){let n=[],r=t.length,o=e.length,i=0,s=0;for(;i<o||s<r;){if(i<o&&s<r&&!e[i]&&!t[s]){i++,s++;continue}let u=i,a=s;for(;i<o&&e[i];)i++;for(;s<r&&t[s];)s++;if(u===i&&a===s)throw new ve("a kept line has no counterpart");n.push({a0:u,a1:i,b0:a,b1:s})}return n}function n2(e,t,n,r=null){let o=r?(u,a)=>r(u)===r(a):(u,a)=>u===a,i=0,s=0;for(let{a0:u,a1:a,b0:l,b1:f}of n){if(u<i||l<s||a<u||f<l||a>e.length||f>t.length)throw new ve("a block is out of order or out of range");if(u===a&&l===f)throw new ve("a block changes nothing");if(u-i!==l-s)throw new ve("the kept lines before a block differ in count");for(;i<u;i++,s++)if(!o(e[i],t[s]))throw new ve(`kept line ${i+1} does not match`);i=a,s=f}if(e.length-i!==t.length-s)throw new ve("the kept lines after the last block differ in count");for(;i<e.length;i++,s++)if(!o(e[i],t[s]))throw new ve(`kept line ${i+1} does not match`)}var ve=class extends Error{constructor(t){super(`the computed change set does not reconstruct the second file (${t})`),this.name="DiffError"}};var r2={unified:ip,context:sp},ap=`Files differ
123
+ `;function o2(e,t,n){if(e===t)return"";let r=bo(n);return r===null?ap:Js(At(e),At(t),r)?"":ap}function nr(e,t,{format:n="unified",context:r=3,label:o=null,...i}={}){if(n==="brief")return o2(e,t,i);let s=At(e),u=At(t),{slide:a=n!=="normal"&&r>0,...l}=i,f=up(s,u,{...l,slide:a});return f.length===0?"":n==="normal"?op(s,u,f):r2[n](s,u,f,{context:r,label:o})}var i2=[" 1970-01-01 00:00:00.000000000 +0000"," Thu Jan 1 00:00:00 1970"];function lp(e,t,n,r,o){let{ctx:i,opts:s}=e,u=s2(s,t);if(u==="")return"";let a=c=>s.labels[c]??bs(n[c],i)+(r[c]?i2[s.style==="context"?1:0]:""),l=c=>s.labels[c]??bs(n[c],i),f=o?`diff${s.switches} ${l(0)} ${l(1)}
124
+ `:"";return s.style==="unified"?`${f}--- ${a(0)}
110
125
  +++ ${a(1)}
111
- ${u}`:s.style==="context"?`${c}*** ${a(0)}
126
+ ${u}`:s.style==="context"?`${f}*** ${a(0)}
112
127
  --- ${a(1)}
113
- ${u}`:c+u}function hy(e,t){let n=e.showFunction?We(t[0]):null;return qn(t[0],t[1],{format:e.style??"normal",context:e.context,label:n?r=>gy(n,r):null,minimal:e.minimal,ignoreCase:e.ignoreCase,whitespace:e.whitespace})}var my=/^[A-Za-z$_]/u;function gy(e,t){for(let n=t-1;n>=0;n--){if(!my.test(e[n]))continue;let r=I(e[n].replace(/\n$/u,"")),i=Math.min(40,r.length);for(;i>0&&wy(r[i-1]);)i--;return xy(r.subarray(0,i))}return null}var wy=e=>e===32||e>=9&&e<=13;function xy(e){for(let t=e.length;t>Math.max(0,e.length-4);t--)try{return M(e.subarray(0,t))}catch{}return""}var yy=["q","s","r","N","a","i","w","b","Z","p","d","u","c","e","n","y","t","T","l","E","B","P","v","H"],by=["brief","report-identical-files","recursive","new-file","text","ignore-case","ignore-all-space","ignore-space-change","ignore-trailing-space","strip-trailing-cr","show-c-function","minimal","normal","unified","context","ed","rcs","side-by-side","expand-tabs","initial-tab","paginate","ignore-tab-expansion","ignore-blank-lines","unidirectional-new-file","version","help","suppress-common-lines","speed-large-files","ignore-file-name-case","no-ignore-file-name-case","no-dereference","left-column"],Pf=["U","C","x","X","S","F","W","I","D"],Df=["show-function-line","exclude-from","starting-file","from-file","to-file","ifdef","width","tabsize","horizon-lines","ignore-matching-lines","line-format","old-line-format","new-line-format","unchanged-line-format","old-group-format","new-group-format","unchanged-group-format","changed-group-format","color","palette"],vy=["L","label","x","exclude"],ky=new Map([["e","ed script output"],["ed","ed script output"],["n","RCS output"],["rcs","RCS output"],["y","side-by-side output"],["side-by-side","side-by-side output"],["W","side-by-side output"],["width","side-by-side output"],["suppress-common-lines","side-by-side output"],["left-column","side-by-side output"],["t","tab expansion"],["expand-tabs","tab expansion"],["T","initial tabs"],["initial-tab","initial tabs"],["tabsize","tab expansion"],["E","tab expansion"],["ignore-tab-expansion","tab expansion"],["B","ignoring blank lines"],["ignore-blank-lines","ignoring blank lines"],["I","ignoring matching lines"],["ignore-matching-lines","ignoring matching lines"],["D","merged #ifdef output"],["ifdef","merged #ifdef output"],["l","pagination"],["paginate","pagination"],["F","a custom function regex"],["show-function-line","a custom function regex"],["X","reading exclusions from a file"],["exclude-from","reading exclusions from a file"],["S","a starting file"],["starting-file","a starting file"],["from-file","comparing one file to many"],["to-file","comparing one file to many"],["P","one-sided new files"],["unidirectional-new-file","one-sided new files"],["v","a version banner"],["version","a version banner"],["help","a help text"],["H","large-file heuristics"],["speed-large-files","large-file heuristics"],["horizon-lines","the horizon setting"],["ignore-file-name-case","case-insensitive names"],["no-ignore-file-name-case","case-insensitive names"],["no-dereference","symbolic links"],["color","colored output"],["palette","colored output"],["line-format","custom line formats"],["old-line-format","custom line formats"],["new-line-format","custom line formats"],["unchanged-line-format","custom line formats"],["old-group-format","custom group formats"],["new-group-format","custom group formats"],["unchanged-group-format","custom group formats"],["changed-group-format","custom group formats"]]),jn=e=>y(`diff: ${e}
114
- diff: Try 'diff --help' for more information.`,2);function Sy(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n];if(r==="--"){t.push(...e.slice(n));break}if(r==="--unified"||r==="--context")t.push("-"+(r==="--unified"?"u":"c"));else if(r.startsWith("--unified=")||r.startsWith("--context="))t.push(r.startsWith("--u")?"-U":"-C",r.slice(10));else{if(r.startsWith("--color"))return{refused:"colored output",label:r};t.push(r)}}return{tokens:t}}function Uf(e){let t=Sy(e);if(t.refused)return{refused:v("option","diff",t.label.replace(/=.*/u,""),`diff: ${t.label}: ${t.refused} is not supported`,2)};let n;try{n=E(t.tokens,{short:yy,long:by,valueShort:Pf,valueLong:Df,repeatable:vy})}catch(i){let o=N(i);return o?{refused:v(o.kind,"diff",o.detail,`diff: ${i.message}`,2)}:{error:jn(i.message)}}let r={style:null,context:-1,labels:[],excludes:[],whitespace:"none",switches:Ny(e)};for(let{name:i,value:o}of n.order){let s=ky.get(i),u=(i.length===1?"-":"--")+i;if(s)return{refused:v("option","diff",u,`diff: ${u}: ${s} is not supported`,2)};let a=Ey(r,i,o);if(a)return{error:a}}return r.showFunction&&r.style===null&&(r.style="context"),r.context<0&&(r.context=3),n.positional.length<2?{error:jn(`missing operand after '${n.positional[0]??"diff"}'`)}:n.positional.length>2?{error:jn(`extra operand '${n.positional[2]}'`)}:{opts:r,operands:n.positional}}function Ey(e,t,n){let r=i=>e.style!==null&&e.style!==i?jn("conflicting output style options"):(e.style=i,null);switch(t){case"u":case"c":{let i=r(t==="u"?"unified":"context");return e.context<3&&(e.context=3),i}case"U":case"C":{let i=$y(n);if(i===null)return jn(`invalid context length '${n}'`);let o=r(t==="U"?"unified":"context");return e.context<i&&(e.context=i),o}case"normal":return r("normal");case"q":case"brief":return e.brief=!0,null;case"s":case"report-identical-files":return e.identical=!0,null;case"r":case"recursive":return e.recursive=!0,null;case"N":case"new-file":return e.newFile=!0,null;case"a":case"text":return e.text=!0,null;case"i":case"ignore-case":return e.ignoreCase=!0,null;case"w":case"ignore-all-space":return e.whitespace="all",null;case"b":case"ignore-space-change":return e.whitespace!=="all"&&(e.whitespace="change"),null;case"Z":case"ignore-trailing-space":return e.whitespace==="none"&&(e.whitespace="trailing"),null;case"strip-trailing-cr":return e.stripCr=!0,null;case"p":case"show-c-function":return e.showFunction=!0,null;case"d":case"minimal":return e.minimal=!0,null;case"L":case"label":return e.labels.length===2?y("diff: too many file label options",2):(e.labels.push(n),null);case"x":case"exclude":return e.excludes.push(n),null;default:return null}}function $y(e){if(e==="")return 0;let t=pe(e,"diff");return t.error?null:t.value}function Ny(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n];if(r==="--")break;!r.startsWith("-")||r==="-"||(t.push(r),Ay(r)&&n+1<e.length&&t.push(e[++n]))}return t.map(n=>" "+ie(n,{vars:new Map})).join("")}function Ay(e){if(e.startsWith("--"))return!e.includes("=")&&(Df.includes(e.slice(2))||e==="--label"||e==="--exclude");for(let t=1;t<e.length;t++){let n=e[t];if(Pf.includes(n)||n==="L")return t+1===e.length}return!1}function Vr(e,t,n){let{ctx:r,opts:i}=e,o=Cy(zf(e,t),zf(e,n));for(let[s,u,a]of o){let l=Zr(t,s),c=Zr(n,s),f=u?Wf(r,l):null,d=a?Wf(r,c):null;if(u&&a){Oy(e,[l,c],[f,d]);continue}i.newFile?Iy(e,[l,c],f??d):Pe(e,`Only in ${u?t:n}: ${s}
115
- `,1)}}function Iy(e,[t,n],r){r==="file"?Hn(e,t,n,!0):e.opts.recursive?Vr(e,t,n):Pe(e,`Common subdirectories: ${t} and ${n}
116
- `)}function Oy(e,[t,n],[r,i]){let{opts:o}=e;if(r==="dir"&&i==="dir")o.recursive?Vr(e,t,n):Pe(e,`Common subdirectories: ${t} and ${n}
117
- `);else if(r===i)Hn(e,t,n,!0);else{let s=(u,a)=>o.labels[u]??a;Pe(e,`File ${s(0,t)} is a ${Bf[r]} while file ${s(1,n)} is a ${Bf[i]}
118
- `,1)}}var Bf={dir:"directory",file:"regular file"};function Wf(e,t){let n=$(e.cwd,t,e.fs);return e.fs.isDir(n.path)?"dir":"file"}function zf(e,t){let{ctx:n,opts:r}=e,i=$(n.cwd,t,n.fs);if(i.error||!n.fs.isDir(i.path))return[];let{dirs:o,files:s}=n.fs.listDir(i.path),u=[...o,...s].sort(U);return r.excludes.length?u.filter(a=>!r.excludes.some(l=>_l(a,l))):u}function Cy(e,t){let n=[],r=0,i=0;for(;r<e.length||i<t.length;){let o=r===e.length?1:i===t.length?-1:U(e[r],t[i]);o===0?(n.push([e[r++],!0,!0]),i++):o<0?n.push([e[r++],!0,!1]):n.push([t[i++],!1,!0])}return n}function jf(e,t,n){let r=Uf(t);if(r.error)return r.error;if(r.refused)return r.refused;let{opts:i,operands:o}=r,s={ctx:n,opts:i,stdin:e,out:R(),status:0},[u,a]=o,l=o.map(c=>qf(s,c));if(l[0]==="dir"&&l[1]==="dir"&&Fy(s,u,a))return s.out;if(l[0]==="dir"&&l[1]==="dir")Vr(s,u,a);else if(l[0]==="dir"||l[1]==="dir"){let c=l[0]==="dir"?0:1,f=o[1-c];if(f==="-")return y("diff: cannot compare '-' to a directory",2);let d=Zr(o[c],kt(f)),p=c===0?[d,f]:[f,d];qf(s,d)==="missing"?Pe(s,`diff: ${d}: No such file or directory
119
- `,2,!0):Hn(s,p[0],p[1],!1)}else Hn(s,u,a,!1);return s.out.exitCode=s.status,s.out}function Zr(e,t){let n=e.replace(/\/+$/u,"");return(n===""?"/":n+"/")+t}function Fy(e,t,n){return $(e.ctx.cwd,t,e.ctx.fs).path===$(e.ctx.cwd,n,e.ctx.fs).path}function qf(e,t){if(t==="-")return"stdin";let n=$(e.ctx.cwd,t,e.ctx.fs);return n.error?"missing":e.ctx.fs.isDir(n.path)?"dir":"file"}function Pe(e,t,n=0,r=!1){_(e.out,r?R(t):{...R(),stdout:t,events:[{fd:1,text:t}]}),e.status=Math.max(e.status,n)}function Hn(e,t,n,r){let{opts:i}=e,o=[t,n].map(d=>Ly(e,d)),s=o.map(d=>d.content===null),u=i.newFile&&!(s[0]&&s[1]),a=!1;for(let d=0;d<2;d++)!s[d]||u||(Pe(e,`diff: ${[t,n][d]}: No such file or directory
120
- `,2,!0),a=!0);if(a)return;if(o[0].identity!==void 0&&o[0].identity===o[1].identity&&!s[0])return Yr(e,t,n);let l=o.map(d=>d.content??"");i.stripCr&&(l=l.map(Ty));let c=d=>i.labels[d]??[t,n][d];if(!i.text&&l.some(_y))return l[0]===l[1]?Yr(e,t,n):Pe(e,`${i.brief?"Files":"Binary files"} ${c(0)} and ${c(1)} differ
121
- `,1);if(i.brief)return qn(l[0],l[1],{format:"brief",ignoreCase:i.ignoreCase,whitespace:i.whitespace})===""?Yr(e,t,n):Pe(e,`Files ${c(0)} and ${c(1)} differ
122
- `,1);let f;try{f=Mf(e,l,[t,n],s,r)}catch(d){if(!(d instanceof me)&&!(d instanceof Me))throw d;let p=`diff: ${t} ${n}: ${d.message}`,m=d instanceof me?"change set verification":"diff rendering verification";_(e.out,v("feature","diff",m,p,2)),e.status=2;return}if(f==="")return Yr(e,t,n);Pe(e,f,1)}function Yr(e,t,n){e.opts.identical&&Pe(e,`Files ${t} and ${n} are identical
123
- `)}var Ty=e=>e.replace(/\r\n/gu,`
124
- `),_y=e=>e.includes("\0");function Ly(e,t){let{ctx:n}=e;if(t==="-")return z(n),{content:e.stdin,identity:n.stdinHandle?.identity??Symbol("stdin")};let r=P(n,"diff",t);return r.error||n.fs.isDir(r.path)?{content:null,identity:void 0}:{content:n.fs.readFile(r.path),identity:n.fs.fileIdentity?.(r.path)??r.path}}var nn=(e,t,n)=>{throw new H(`malformed patch at line ${Math.min(t,e.lines.length-1)+1}: ${n??""}`)};function Gn(e,t){return!!e.lines[t+1]?.startsWith("\\")}function Xf(e){let{lines:t}=e,n=e.pos,r=/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(?: (.*))?\n$/u.exec(t[n]??"");if(!r)return null;let i=n,o=Number(r[3]),s=Number(r[1]),u=r[2]===void 0?1:Number(r[2]),a=r[4]===void 0?1:Number(r[4]);u===0&&s++,a===0&&o++;let l=[],c=[],f=0,d=n,p=-1;for(n++;c.length<u||l.length<a;n+=1){let m=t[n]!==void 0;if(!m&&a-l.length>3)throw new H("unexpected end of file in patch");let h=m?t[n]:`
125
- `;m&&(d=n);let g=h[0],x=h;g===" "||g===`
126
- `?g=" ":x=h.slice(1),g!=="-"&&g!=="+"&&g!==" "&&nn(e,n,h);let b=!1;g!=="+"&&(c.length>=u&&nn(e,n,h),b=m&&c.length+1===u&&Gn(e,n),b&&(x=x.replace(/\n$/u,"")),c.push({tag:g,text:x}),g===" "&&f++),g!=="-"&&(l.length>=a&&nn(e,n,h),!b&&m&&l.length+1===a&&Gn(e,n)&&(b=!0,x=x.replace(/\n$/u,"")),l.push({tag:g,text:x})),g!==" "&&(p===-1&&(p=f),f=0),b&&n++}return p===-1&&nn(e,d,t[d]),e.pos=n,{oldStart:s,oldLines:c,newStart:o,newLines:l,prefix:p,suffix:f,fn:r[5]===void 0?null:" "+r[5],marks:null,line:i}}function ms(e){let{lines:t}=e,n=e.pos;if(!t[n]?.startsWith("********"))return null;let r=n,i=/^\*+( .*)?\n$/u.exec(t[n])?.[1]??null,o=/^\*\*\* (\d+)(?:,(\d+))?/u.exec(t[++n]??"");if(!o)throw new H(`unexpected '***' at line ${n+1}: ${t[n]??""}`);let s=Hf(o),u=[],a=f=>/^--- (\d+)(?:,(\d+))? ----/u.exec(t[f]??"")??/^--- (\d+)(?:,(\d+))?/u.exec(t[f]??"");for(n++;!a(n);n++){if(t[n]===void 0||u.length>=s.count)throw new H(`no '---' found in patch at line ${r+1}`);u.push(Gf(e,n,u.length+1===s.count)),u.at(-1).skip&&n++}let l=Hf(a(n)),c=[];for(n++;c.length<l.count;n++){let f=t[n];if(f===void 0||!/^[ !+\-\t\n]/u.test(f)||f.startsWith("***"))break;c.push(Gf(e,n,c.length+1===l.count)),c.at(-1).skip&&n++}return c.length!==0&&c.length<l.count&&nn(e,n,t[n]),e.pos=n,Ry({oldRange:s,oldSide:u,newRange:l,newSide:c,fn:i,line:r})}function Hf(e){let t=Number(e[1]),n=e[2]===void 0?t:Number(e[2]);return t===0&&e[2]===void 0?{first:1,count:0}:{first:t,count:n-t+1}}function Gf(e,t,n){let r=e.lines[t],i=r[0];i===" "||i===`
127
- `?i=" ":(r=r.slice(1),(r[0]===" "||r[0]===" ")&&(r=r.slice(1)));let o=n&&Gn(e,t);return{mark:i,text:o?r.replace(/\n$/u,""):r,skip:o}}function Ry({oldRange:e,oldSide:t,newRange:n,newSide:r,fn:i,line:o}){let s=r,u=t;if(t.length===0&&e.count&&(u=r.filter(p=>p.mark===" ")),r.length===0&&n.count&&(s=t.filter(p=>p.mark===" ")),u.length!==e.count||s.length!==n.count)throw new H(`replacement text or line numbers mangled in hunk at line ${o+1}`);let a=u.map(p=>({tag:p.mark===" "?" ":"-",text:p.text})),l=s.map(p=>({tag:p.mark===" "?" ":"+",text:p.text})),c=p=>{let m=0;for(let h of p){if(h.tag!==" ")break;m++}return m},f=Math.min(c(a),c(l)),d=Math.min(c(a.toReversed()),c(l.toReversed()));if(a.every(p=>p.tag===" ")&&l.every(p=>p.tag===" "))throw new H(`replacement text or line numbers mangled in hunk at line ${o+1}`);return{oldStart:e.first,oldLines:a,newStart:n.first,newLines:l,prefix:f,suffix:d,fn:i,marks:{old:u.map(p=>p.mark),new:s.map(p=>p.mark)},line:o}}function Zf(e){let{lines:t}=e,n=e.pos,r=/^(\d+)(?:,(\d+))?([acd])(\d+)(?:,(\d+))?[ \t]*\r?\n$/u.exec(t[n]??"");if(!r)return null;let i=n,o=Number(r[1]),s=r[3]==="a"?0:r[2]===void 0?1:Number(r[2])-o+1;r[3]==="a"&&o++;let u=Number(r[4]),a=r[5]===void 0?u:Number(r[5]);r[3]==="d"&&u++;let l=a-u+1;(s<0||l<0)&&nn(e,n,t[n]);let c=[],f=[];n++;for(let d=0;d<s;d++,n++){if(t[n]===void 0)throw new H(`unexpected end of file in patch at line ${n}`);if(!/^<[ \t]/u.test(t[n]))throw new H(`'<' followed by space or tab expected at line ${n+1} of patch`);let p=d+1===s&&Gn(e,n);f.push({tag:"-",text:p?t[n].slice(2).replace(/\n$/u,""):t[n].slice(2)}),p&&n++}if(r[3]==="c"){if(t[n]===void 0)throw new H(`unexpected end of file in patch at line ${n}`);if(!t[n].startsWith("-"))throw new H(`'---' expected at line ${n+1} of patch`);n++}for(let d=0;d<l;d++,n++){if(t[n]===void 0)throw new H(`unexpected end of file in patch at line ${n}`);if(!/^>[ \t]/u.test(t[n]))throw new H(`'>' followed by space or tab expected at line ${n+1} of patch`);let p=d+1===l&&Gn(e,n);c.push({tag:"+",text:p?t[n].slice(2).replace(/\n$/u,""):t[n].slice(2)}),p&&n++}return e.pos=n,{oldStart:o,oldLines:f,newStart:u,newLines:c,prefix:0,suffix:0,fn:null,marks:null,line:i}}function Kr(e){let t=(r,i,o)=>r.map(s=>({tag:s.tag===i?o:s.tag,text:s.text})),n=(r,i,o)=>r.map(s=>s===i?o:s);return{...e,oldStart:e.newStart,newStart:e.oldStart,oldLines:t(e.newLines,"+","-"),newLines:t(e.oldLines,"-","+"),marks:e.marks&&{old:n(e.marks.new,"+","-"),new:n(e.marks.old,"-","+")}}}var H=class extends Error{constructor(t){super(t),this.name="PatchFatal"}},rn=(e,t)=>{throw new w("feature",e,t)};function Qf(e){let t=We(e);return t.length&&!t.at(-1).endsWith(`
128
+ ${u}`:f+u}function s2(e,t){let n=e.showFunction?Ge(t[0]):null;return nr(t[0],t[1],{format:e.style??"normal",context:e.context,label:n?r=>a2(n,r):null,minimal:e.minimal,ignoreCase:e.ignoreCase,whitespace:e.whitespace})}var u2=/^[A-Za-z$_]/u;function a2(e,t){for(let n=t-1;n>=0;n--){if(!u2.test(e[n]))continue;let r=A(e[n].replace(/\n$/u,"")),o=Math.min(40,r.length);for(;o>0&&l2(r[o-1]);)o--;return f2(r.subarray(0,o))}return null}var l2=e=>e===32||e>=9&&e<=13;function f2(e){for(let t=e.length;t>Math.max(0,e.length-4);t--)try{return W(e.subarray(0,t))}catch{}return""}var c2=["q","s","r","N","a","i","w","b","Z","p","d","u","c","e","n","y","t","T","l","E","B","P","v","H"],d2=["brief","report-identical-files","recursive","new-file","text","ignore-case","ignore-all-space","ignore-space-change","ignore-trailing-space","strip-trailing-cr","show-c-function","minimal","normal","unified","context","ed","rcs","side-by-side","expand-tabs","initial-tab","paginate","ignore-tab-expansion","ignore-blank-lines","unidirectional-new-file","version","help","suppress-common-lines","speed-large-files","ignore-file-name-case","no-ignore-file-name-case","no-dereference","left-column"],fp=["U","C","x","X","S","F","W","I","D"],cp=["show-function-line","exclude-from","starting-file","from-file","to-file","ifdef","width","tabsize","horizon-lines","ignore-matching-lines","line-format","old-line-format","new-line-format","unchanged-line-format","old-group-format","new-group-format","unchanged-group-format","changed-group-format","color","palette"],p2=["L","label","x","exclude"],h2=new Map([["e","ed script output"],["ed","ed script output"],["n","RCS output"],["rcs","RCS output"],["y","side-by-side output"],["side-by-side","side-by-side output"],["W","side-by-side output"],["width","side-by-side output"],["suppress-common-lines","side-by-side output"],["left-column","side-by-side output"],["t","tab expansion"],["expand-tabs","tab expansion"],["T","initial tabs"],["initial-tab","initial tabs"],["tabsize","tab expansion"],["E","tab expansion"],["ignore-tab-expansion","tab expansion"],["B","ignoring blank lines"],["ignore-blank-lines","ignoring blank lines"],["I","ignoring matching lines"],["ignore-matching-lines","ignoring matching lines"],["D","merged #ifdef output"],["ifdef","merged #ifdef output"],["l","pagination"],["paginate","pagination"],["F","a custom function regex"],["show-function-line","a custom function regex"],["X","reading exclusions from a file"],["exclude-from","reading exclusions from a file"],["S","a starting file"],["starting-file","a starting file"],["from-file","comparing one file to many"],["to-file","comparing one file to many"],["P","one-sided new files"],["unidirectional-new-file","one-sided new files"],["v","a version banner"],["version","a version banner"],["help","a help text"],["H","large-file heuristics"],["speed-large-files","large-file heuristics"],["horizon-lines","the horizon setting"],["ignore-file-name-case","case-insensitive names"],["no-ignore-file-name-case","case-insensitive names"],["no-dereference","symbolic links"],["color","colored output"],["palette","colored output"],["line-format","custom line formats"],["old-line-format","custom line formats"],["new-line-format","custom line formats"],["unchanged-line-format","custom line formats"],["old-group-format","custom group formats"],["new-group-format","custom group formats"],["unchanged-group-format","custom group formats"],["changed-group-format","custom group formats"]]),rr=e=>x(`diff: ${e}
129
+ diff: Try 'diff --help' for more information.`,2);function m2(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n];if(r==="--"){t.push(...e.slice(n));break}if(r==="--unified"||r==="--context")t.push("-"+(r==="--unified"?"u":"c"));else if(r.startsWith("--unified=")||r.startsWith("--context="))t.push(r.startsWith("--u")?"-U":"-C",r.slice(10));else{if(r.startsWith("--color"))return{refused:"colored output",label:r};t.push(r)}}return{tokens:t}}function dp(e){let t=m2(e);if(t.refused)return{refused:v("option","diff",t.label.replace(/=.*/u,""),`diff: ${t.label}: ${t.refused} is not supported`,2)};let n;try{n=N(t.tokens,{short:c2,long:d2,valueShort:fp,valueLong:cp,repeatable:p2})}catch(o){let i=O(o);return i?{refused:v(i.kind,"diff",i.detail,`diff: ${o.message}`,2)}:{error:rr(o.message)}}let r={style:null,context:-1,labels:[],excludes:[],whitespace:"none",switches:y2(e)};for(let{name:o,value:i}of n.order){let s=h2.get(o),u=(o.length===1?"-":"--")+o;if(s)return{refused:v("option","diff",u,`diff: ${u}: ${s} is not supported`,2)};let a=g2(r,o,i);if(a)return{error:a}}return r.showFunction&&r.style===null&&(r.style="context"),r.context<0&&(r.context=3),n.positional.length<2?{error:rr(`missing operand after '${n.positional[0]??"diff"}'`)}:n.positional.length>2?{error:rr(`extra operand '${n.positional[2]}'`)}:{opts:r,operands:n.positional}}function g2(e,t,n){let r=o=>e.style!==null&&e.style!==o?rr("conflicting output style options"):(e.style=o,null);switch(t){case"u":case"c":{let o=r(t==="u"?"unified":"context");return e.context<3&&(e.context=3),o}case"U":case"C":{let o=w2(n);if(o===null)return rr(`invalid context length '${n}'`);let i=r(t==="U"?"unified":"context");return e.context<o&&(e.context=o),i}case"normal":return r("normal");case"q":case"brief":return e.brief=!0,null;case"s":case"report-identical-files":return e.identical=!0,null;case"r":case"recursive":return e.recursive=!0,null;case"N":case"new-file":return e.newFile=!0,null;case"a":case"text":return e.text=!0,null;case"i":case"ignore-case":return e.ignoreCase=!0,null;case"w":case"ignore-all-space":return e.whitespace="all",null;case"b":case"ignore-space-change":return e.whitespace!=="all"&&(e.whitespace="change"),null;case"Z":case"ignore-trailing-space":return e.whitespace==="none"&&(e.whitespace="trailing"),null;case"strip-trailing-cr":return e.stripCr=!0,null;case"p":case"show-c-function":return e.showFunction=!0,null;case"d":case"minimal":return e.minimal=!0,null;case"L":case"label":return e.labels.length===2?x("diff: too many file label options",2):(e.labels.push(n),null);case"x":case"exclude":return e.excludes.push(n),null;default:return null}}function w2(e){if(e==="")return 0;let t=be(e,"diff");return t.error?null:t.value}function y2(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n];if(r==="--")break;!r.startsWith("-")||r==="-"||(t.push(r),b2(r)&&n+1<e.length&&t.push(e[++n]))}return t.map(n=>" "+oe(n,{vars:new Map})).join("")}function b2(e){if(e.startsWith("--"))return!e.includes("=")&&(cp.includes(e.slice(2))||e==="--label"||e==="--exclude");for(let t=1;t<e.length;t++){let n=e[t];if(fp.includes(n)||n==="L")return t+1===e.length}return!1}function So(e,t,n){let{ctx:r,opts:o}=e,i=v2(mp(e,t),mp(e,n));for(let[s,u,a]of i){let l=vo(t,s),f=vo(n,s),c=u?hp(r,l):null,d=a?hp(r,f):null;if(u&&a){k2(e,[l,f],[c,d]);continue}o.newFile?x2(e,[l,f],c??d,[u,a]):Se(e,`Only in ${u?t:n}: ${s}
130
+ `,1)}}function x2(e,[t,n],r,o){ko(r)?e.opts.recursive?gp(e,[t,n],o.map(i=>i?r:null)):Se(e,`Common subdirectories: ${t} and ${n}
131
+ `):or(e,t,n,!0,o)}function k2(e,[t,n],[r,o]){let{opts:i}=e,s=[r,o].indexOf("gone");if(s!==-1&&ko([r,o][1-s])){let u=[t,n][s];return Se(e,`diff: ${u}: ${E(e.ctx.cwd,u,e.ctx.fs).error}
132
+ `,2,!0)}if(ko(r)&&ko(o))i.recursive?gp(e,[t,n],[r,o]):Se(e,`Common subdirectories: ${t} and ${n}
133
+ `);else if(r===o||s!==-1)or(e,t,n,!0,[!0,!0]);else{let u=(a,l)=>i.labels[a]??l;Se(e,`File ${u(0,t)} is a ${pp[r]} while file ${u(1,n)} is a ${pp[o]}
134
+ `,1)}}var pp={dir:"directory",link:"directory",file:"regular file"},ko=e=>e==="dir"||e==="link";function hp(e,t){let n=E(e.cwd,t,e.fs);return n.error?"gone":e.fs.isDir(n.path)?e.fs.isLink?.(E(e.cwd,t,e.fs,{follow:!1}).path)?"link":"dir":"file"}function gp(e,[t,n],[r,o]){for(let[i,s]of[[r,t],[o,n]])if(i==="link")throw new b("feature","symbolic link to a directory",`comparing what a symbolic link to a directory holds is not supported: ${s}`);So(e,t,n)}function mp(e,t){let{ctx:n,opts:r}=e,o=E(n.cwd,t,n.fs);if(o.error||!n.fs.isDir(o.path))return[];let{dirs:i,files:s,links:u}=n.fs.listDir(o.path),a=[...i,...s,...u].sort(j);return r.excludes.length?a.filter(l=>!r.excludes.some(f=>Jf(l,f))):a}function v2(e,t){let n=[],r=0,o=0;for(;r<e.length||o<t.length;){let i=r===e.length?1:o===t.length?-1:j(e[r],t[o]);i===0?(n.push([e[r++],!0,!0]),o++):i<0?n.push([e[r++],!0,!1]):n.push([t[o++],!1,!0])}return n}function xp(e,t,n){let r=dp(t);if(r.error)return r.error;if(r.refused)return r.refused;let{opts:o,operands:i}=r,s={ctx:n,opts:o,stdin:e,out:U(),status:0},[u,a]=i,l=i.map(f=>wp(s,f));if(l[0]==="dir"&&l[1]==="dir"&&S2(s,u,a))return s.out;if(l[0]==="dir"&&l[1]==="dir")So(s,u,a);else if(l[0]==="dir"||l[1]==="dir"){let f=l[0]==="dir"?0:1,c=i[1-f];if(c==="-")return x("diff: cannot compare '-' to a directory",2);if(l[1-f]==="missing"){let d=E(s.ctx.cwd,c,s.ctx.fs).error;o.newFile&&d==="No such file or directory"?So(s,u,a):Se(s,`diff: ${c}: ${d}
135
+ `,2,!0)}else{let d=vo(i[f],nt(c)),p=f===0?[d,c]:[c,d];wp(s,d)==="missing"?Se(s,`diff: ${d}: No such file or directory
136
+ `,2,!0):or(s,p[0],p[1],!1)}}else or(s,u,a,!1);return s.out.exitCode=s.status,s.out}function vo(e,t){let n=e.replace(/\/+$/u,"");return(n===""?"/":n+"/")+t}function S2(e,t,n){return E(e.ctx.cwd,t,e.ctx.fs).path===E(e.ctx.cwd,n,e.ctx.fs).path}function wp(e,t){if(t==="-")return"stdin";let n=E(e.ctx.cwd,t,e.ctx.fs);return n.error?"missing":e.ctx.fs.isDir(n.path)?"dir":"file"}function Se(e,t,n=0,r=!1){_(e.out,r?U(t):{...U(),stdout:t,events:[{fd:1,text:t}]}),e.status=Math.max(e.status,n)}function or(e,t,n,r,o=null){let{opts:i}=e,s=[t,n].map(p=>N2(e,p)),u=s.map(p=>p.content===null),a=i.newFile&&!(u[0]&&u[1]),l=!1;for(let p=0;p<2;p++)!u[p]||(o?!o[p]:a)||(Se(e,`diff: ${[t,n][p]}: ${s[p].error??"No such file or directory"}
137
+ `,2,!0),l=!0);if(l)return;if(s[0].identity!==void 0&&s[0].identity===s[1].identity&&!u[0])return ir(e,t,n);let f=p=>i.labels[p]??[t,n][p];if(!i.text&&s.some($2))return yp(s)?ir(e,t,n):Se(e,`${i.brief?"Files":"Binary files"} ${f(0)} and ${f(1)} differ
138
+ `,1);if(s.some(p=>p.content===void 0)){if(yp(s))return ir(e,t,n);if(i.brief&&!i.ignoreCase&&!i.stripCr&&i.whitespace==="none")return Se(e,`Files ${f(0)} and ${f(1)} differ
139
+ `,1)}for(let[p,h]of s.entries())h.content===void 0&&rt(h.bytes,JSON.stringify(f(p)));let c=s.map(p=>p.content??"");if(i.stripCr&&(c=c.map(E2)),i.brief)return nr(c[0],c[1],{format:"brief",ignoreCase:i.ignoreCase,whitespace:i.whitespace})===""?ir(e,t,n):Se(e,`Files ${f(0)} and ${f(1)} differ
140
+ `,1);let d;try{d=lp(e,c,[t,n],u,r)}catch(p){if(!(p instanceof ve)&&!(p instanceof We))throw p;let h=`diff: ${t} ${n}: ${p.message}`,m=p instanceof ve?"change set verification":"diff rendering verification";_(e.out,v("feature","diff",m,h,2)),e.status=2;return}if(d==="")return ir(e,t,n);Se(e,d,1)}function ir(e,t,n){e.opts.identical&&Se(e,`Files ${t} and ${n} are identical
141
+ `)}var E2=e=>e.replace(/\r\n/gu,`
142
+ `),$2=e=>e.content===void 0?e.bytes.includes(0):e.content?.includes("\0")===!0,yp=([e,t])=>e.content!==void 0&&t.content!==void 0?e.content===t.content:An(e.bytes??bp,t.bytes??bp),bp=new Uint8Array;function N2(e,t){let{ctx:n}=e;if(t==="-")return q(n),{content:e.stdin,identity:n.stdinHandle?.identity??Symbol("stdin")};let r=P(n,"diff",t);if(r.error||n.fs.isDir(r.path))return{content:null,bytes:null,identity:void 0,error:r.error};let{text:o,bytes:i}=wt(n.fs,r.path);return{content:o,bytes:i,identity:n.fs.fileIdentity?.(r.path)??r.path}}var pn=(e,t,n)=>{throw new Q(`malformed patch at line ${Math.min(t,e.lines.length-1)+1}: ${n??""}`)};function sr(e,t){return!!e.lines[t+1]?.startsWith("\\")}function Sp(e){let{lines:t}=e,n=e.pos,r=/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(?: (.*))?\n$/u.exec(t[n]??"");if(!r)return null;let o=n,i=Number(r[3]),s=Number(r[1]),u=r[2]===void 0?1:Number(r[2]),a=r[4]===void 0?1:Number(r[4]);u===0&&s++,a===0&&i++;let l=[],f=[],c=0,d=n,p=-1;for(n++;f.length<u||l.length<a;n+=1){let h=t[n]!==void 0;if(!h&&a-l.length>3)throw new Q("unexpected end of file in patch");let m=h?t[n]:`
143
+ `;h&&(d=n);let g=m[0],w=m;g===" "||g===`
144
+ `?g=" ":w=m.slice(1),g!=="-"&&g!=="+"&&g!==" "&&pn(e,n,m);let y=!1;g!=="+"&&(f.length>=u&&pn(e,n,m),y=h&&f.length+1===u&&sr(e,n),y&&(w=w.replace(/\n$/u,"")),f.push({tag:g,text:w}),g===" "&&c++),g!=="-"&&(l.length>=a&&pn(e,n,m),!y&&h&&l.length+1===a&&sr(e,n)&&(y=!0,w=w.replace(/\n$/u,"")),l.push({tag:g,text:w})),g!==" "&&(p===-1&&(p=c),c=0),y&&n++}return p===-1&&pn(e,d,t[d]),e.pos=n,{oldStart:s,oldLines:f,newStart:i,newLines:l,prefix:p,suffix:c,fn:r[5]===void 0?null:" "+r[5],marks:null,line:o}}function Qs(e){let{lines:t}=e,n=e.pos;if(!t[n]?.startsWith("********"))return null;let r=n,o=/^\*+( .*)?\n$/u.exec(t[n])?.[1]??null,i=/^\*\*\* (\d+)(?:,(\d+))?/u.exec(t[++n]??"");if(!i)throw new Q(`unexpected '***' at line ${n+1}: ${t[n]??""}`);let s=kp(i),u=[],a=c=>/^--- (\d+)(?:,(\d+))? ----/u.exec(t[c]??"")??/^--- (\d+)(?:,(\d+))?/u.exec(t[c]??"");for(n++;!a(n);n++){if(t[n]===void 0||u.length>=s.count)throw new Q(`no '---' found in patch at line ${r+1}`);u.push(vp(e,n,u.length+1===s.count)),u.at(-1).skip&&n++}let l=kp(a(n)),f=[];for(n++;f.length<l.count;n++){let c=t[n];if(c===void 0||!/^[ !+\-\t\n]/u.test(c)||c.startsWith("***"))break;f.push(vp(e,n,f.length+1===l.count)),f.at(-1).skip&&n++}return f.length!==0&&f.length<l.count&&pn(e,n,t[n]),e.pos=n,A2({oldRange:s,oldSide:u,newRange:l,newSide:f,fn:o,line:r})}function kp(e){let t=Number(e[1]),n=e[2]===void 0?t:Number(e[2]);return t===0&&e[2]===void 0?{first:1,count:0}:{first:t,count:n-t+1}}function vp(e,t,n){let r=e.lines[t],o=r[0];o===" "||o===`
145
+ `?o=" ":(r=r.slice(1),(r[0]===" "||r[0]===" ")&&(r=r.slice(1)));let i=n&&sr(e,t);return{mark:o,text:i?r.replace(/\n$/u,""):r,skip:i}}function A2({oldRange:e,oldSide:t,newRange:n,newSide:r,fn:o,line:i}){let s=r,u=t;if(t.length===0&&e.count&&(u=r.filter(p=>p.mark===" ")),r.length===0&&n.count&&(s=t.filter(p=>p.mark===" ")),u.length!==e.count||s.length!==n.count)throw new Q(`replacement text or line numbers mangled in hunk at line ${i+1}`);let a=u.map(p=>({tag:p.mark===" "?" ":"-",text:p.text})),l=s.map(p=>({tag:p.mark===" "?" ":"+",text:p.text})),f=p=>{let h=0;for(let m of p){if(m.tag!==" ")break;h++}return h},c=Math.min(f(a),f(l)),d=Math.min(f(a.toReversed()),f(l.toReversed()));if(a.every(p=>p.tag===" ")&&l.every(p=>p.tag===" "))throw new Q(`replacement text or line numbers mangled in hunk at line ${i+1}`);return{oldStart:e.first,oldLines:a,newStart:n.first,newLines:l,prefix:c,suffix:d,fn:o,marks:{old:u.map(p=>p.mark),new:s.map(p=>p.mark)},line:i}}function Ep(e){let{lines:t}=e,n=e.pos,r=/^(\d+)(?:,(\d+))?([acd])(\d+)(?:,(\d+))?[ \t]*\r?\n$/u.exec(t[n]??"");if(!r)return null;let o=n,i=Number(r[1]),s=r[3]==="a"?0:r[2]===void 0?1:Number(r[2])-i+1;r[3]==="a"&&i++;let u=Number(r[4]),a=r[5]===void 0?u:Number(r[5]);r[3]==="d"&&u++;let l=a-u+1;(s<0||l<0)&&pn(e,n,t[n]);let f=[],c=[];n++;for(let d=0;d<s;d++,n++){if(t[n]===void 0)throw new Q(`unexpected end of file in patch at line ${n}`);if(!/^<[ \t]/u.test(t[n]))throw new Q(`'<' followed by space or tab expected at line ${n+1} of patch`);let p=d+1===s&&sr(e,n);c.push({tag:"-",text:p?t[n].slice(2).replace(/\n$/u,""):t[n].slice(2)}),p&&n++}if(r[3]==="c"){if(t[n]===void 0)throw new Q(`unexpected end of file in patch at line ${n}`);if(!t[n].startsWith("-"))throw new Q(`'---' expected at line ${n+1} of patch`);n++}for(let d=0;d<l;d++,n++){if(t[n]===void 0)throw new Q(`unexpected end of file in patch at line ${n}`);if(!/^>[ \t]/u.test(t[n]))throw new Q(`'>' followed by space or tab expected at line ${n+1} of patch`);let p=d+1===l&&sr(e,n);f.push({tag:"+",text:p?t[n].slice(2).replace(/\n$/u,""):t[n].slice(2)}),p&&n++}return e.pos=n,{oldStart:i,oldLines:c,newStart:u,newLines:f,prefix:0,suffix:0,fn:null,marks:null,line:o}}function Eo(e){let t=(r,o,i)=>r.map(s=>({tag:s.tag===o?i:s.tag,text:s.text})),n=(r,o,i)=>r.map(s=>s===o?i:s);return{...e,oldStart:e.newStart,newStart:e.oldStart,oldLines:t(e.newLines,"+","-"),newLines:t(e.oldLines,"-","+"),marks:e.marks&&{old:n(e.marks.new,"+","-"),new:n(e.marks.old,"-","+")}}}var Q=class extends Error{constructor(t){super(t),this.name="PatchFatal"}},hn=(e,t)=>{throw new b("feature",e,t)};function Cp(e){let t=Ge(e);return t.length&&!t.at(-1).endsWith(`
128
146
  `)&&(t[t.length-1]+=`
129
- `),{lines:t,pos:0,base:0,empty:e===""}}var My=/^\d+(?:,\d+)?[acd]\d+(?:,\d+)?[ \t]*\r?\n$/u,Vf=/^(?:\d+(?:,\d+)?)?(?:[acdi]|s\/\.\/\/)[ \t]*\n$/u,Yf=/^[0-9a-fA-F]+/u;function ed(e,{needHeader:t,strip:n,format:r}){let{lines:i}=e,o={names:{old:null,new:null,index:null},stamps:{old:-1,new:-1},timestrs:{old:null,new:null},says:[0,0],git:!1,rename:[!1,!1],copy:[!1,!1],extended:!1},s=t&&r!=="normal"&&r!=="ed",u=!1,a=-1,l=!1,c=!1;for(let f=e.pos;;f++){if(f>=i.length)return u&&rn("ed script","ed scripts are not supported"),o.extended?{...o,type:"unified",start:f,hunkLine:f,empty:!0}:null;let d=i[f],p=d.replace(/^[ \tX]+/u,""),m=/^\d/u.test(p)&&My.test(p);!s&&a<0&&(Vf.test(p)||m)&&(a=f,u=Vf.test(p));let h=Py(d,o,n,c);if(h==="binary"&&rn("git binary patch","git binary diffs are not supported"),h==="prereq"&&rn("Prereq","Prereq: lines are not supported"),h==="git"&&o.extended)return{...o,type:"unified",start:f,hunkLine:f,empty:!0};h&&(s=!1);let g=d.startsWith("********");if(/^[ \t]+(?:@@ -\d|\*{8})/u.test(d)&&rn("indented patch","indented patches are not supported"),!s){if(d.endsWith(`\r
130
- `)&&(d.startsWith("@@ -")||c)&&rn("CRLF patch","patches with CRLF line endings are not supported"),(r===null||r==="ed")&&a>=0&&d===`.
131
- `&&rn("ed script","ed scripts are not supported"),(r===null||r==="unified")&&d.startsWith("@@ -"))return Uy(o,f,d);if((r===null||r==="context")&&c&&d.startsWith("*** "))return By(e,o,f,d);if((r===null||r==="normal")&&l&&(d.startsWith("< ")||d.startsWith("> ")))return{...o,type:"normal",start:f-1,hunkLine:f-1}}c=g,l=m}}function Py(e,t,n,r){if(!r&&e.startsWith("*** ")||e.startsWith("+++ "))return gs(t,"old",e.slice(4),n);if(e.startsWith("Index:"))return t.names.index=nd(e.slice(6),n,!1).name,"index";if(e.startsWith("Prereq:"))return"prereq";if(e.startsWith("diff --git ")){let o=Kf(e.slice(11),n),s=o.name===null?null:Kf(o.rest,n);return t.names.old=s&&s.rest.trim()===""?o.name:null,t.names.new=t.names.old===null?null:s.name,t.git=!0,t.stamps.old=t.stamps.new=-1,"git"}if(t.git){let o=Dy(e,t);if(o)return o}let i=e;for(;i.startsWith("- ");)i=i.slice(2);return i.startsWith("--- ")?gs(t,"new",i.slice(4),n):null}function Dy(e,t){if(e.startsWith("index ")){let n=Yf.exec(e.slice(6)),r=n?e.slice(6+n[0].length):"",i=r.startsWith("..")?Yf.exec(r.slice(2)):null;return i?(t.says[0]=/^0+$/u.test(n[0])?2:0,t.says[1]=/^0+$/u.test(i[0])?2:0,t.extended=!0,"index"):null}return e.startsWith("old mode ")||e.startsWith("new mode ")?(t.extended=!0,"mode"):e.startsWith("deleted file mode ")?(t.says[1]=2,t.extended=!0,"mode"):e.startsWith("new file mode ")?(t.says[0]=2,t.extended=!0,"mode"):e.startsWith("rename from ")?(t.rename[0]=!0,t.extended=!0,"rename"):e.startsWith("rename to ")?(t.rename[1]=!0,t.extended=!0,"rename"):e.startsWith("copy from ")?(t.copy[0]=!0,t.extended=!0,"copy"):e.startsWith("copy to ")?(t.copy[1]=!0,t.extended=!0,"copy"):e.startsWith("GIT binary patch")?"binary":null}function gs(e,t,n,r){let i=nd(n,r,!0);return i.stamp!==void 0&&(e.stamps[t]=i.stamp),i.name!==void 0&&(e.names[t]=i.name,e.timestrs[t]=i.timestr),"name"}function Uy(e,t,n){let r={names:{...e.names,old:e.names.new,new:e.names.old},stamps:{old:e.stamps.new,new:e.stamps.old},timestrs:{old:e.timestrs.new,new:e.timestrs.old}},i=/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))?/u.exec(n),o=[...e.says];return i&&i[1]==="0"&&(o[0]=1+(r.stamps.old===0?1:0)),i&&i[3]==="0"&&(o[1]=1+(r.stamps.new===0?1:0)),{...e,...r,says:o,type:"unified",start:t,hunkLine:t}}function By(e,t,n,r){let i=[...t.says];/^\*\*\* 0(?!\d)/u.test(r)&&(i[0]=1+(t.stamps.old===0?1:0));let o={...e,pos:n-1};try{let s=ms(o);s&&s.newLines.length===0&&s.newStart===1&&(i[1]=1+(t.stamps.new===0?1:0))}catch{}return{...t,says:i,type:"context",start:n-1,hunkLine:n-1}}function td(e,t){return t==="unified"?Xf(e):t==="context"?ms(e):Zf(e)}function nd(e,t,n){let r=e.replace(/^[ \t\n\v\f\r]+/u,""),i,o;if(r.startsWith('"')){let a=id(r);if(!a)return{};i=a.value,o=a.rest}else{let a=0;for(;a<r.length;a++){if(!/[ \t\n\v\f\r]/u.test(r[a]))continue;let l=a;for(;r[l]!==" "&&/[ \t\n\v\f\r]/u.test(r[l+1]??"");)l++;if(!(r[l]!==" "&&r.indexOf(n?" ":`
132
- `,l+1)!==-1))break}i=r.slice(0,a),o=r.slice(a)}if(i==="/dev/null")return{stamp:0};let s=rd(i,t);if(s===null)return{};let u=o.replace(/\r?\n$/u,"");return{name:s,timestr:u,stamp:n&&u!==""?Wy(u):-1}}function Wy(e){let t=/^\s*(\d{4})-(\d\d)-(\d\d)[ T](\d\d):(\d\d):(\d\d)(?:\.\d+)?\s*(?:([+-])(\d\d):?(\d\d))?/u.exec(e),n;if(t){let[,r,i,o,s,u,a,l,c,f]=t;n=Date.UTC(Number(r),Number(i)-1,Number(o),Number(s),Number(u),Number(a))/1e3,l&&(n-=(l==="-"?-1:1)*(Number(c)*3600+Number(f)*60))}else{let r=/^\s*[A-Z][a-z]{2} ([A-Z][a-z]{2}) +(\d+) (\d\d):(\d\d):(\d\d) (\d{4})/u.exec(e);if(!r)return-1;let i=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],[,o,s,u,a,l,c]=r;n=Date.UTC(Number(c),i.indexOf(o),Number(s),Number(u),Number(a),Number(l))/1e3}return n>-25*3600&&n<26*3600?0:n}function rd(e,t){let n=t,r=0;for(let i=0;i<e.length;i++)if(e[i]==="/"){for(;e[i+1]==="/";)i++;(t<0||--n>=0)&&(r=i+1)}return(t<0||n<=0)&&r<e.length?e.slice(r):null}function Kf(e,t){let n=e.replace(/^[ \t\n\v\f\r]+/u,""),r,i;if(n.startsWith('"')){let o=id(n);if(!o)return{name:null,rest:""};r=o.value,i=o.rest}else{let o=n.search(/[ \t\n\v\f\r]/u);r=o<0?n:n.slice(0,o),i=o<0?"":n.slice(o)}return{name:rd(r,t),rest:i}}var Jf={a:"\x07",b:"\b",f:"\f",n:`
133
- `,r:"\r",t:" ",v:"\v","\\":"\\",'"':'"'};function id(e){let t="";for(let n=1;n<e.length;n++){let r=e[n];if(r==='"')return{value:t,rest:e.slice(n+1)};if(r!=="\\"){t+=r;continue}let i=e[++n];if(i===void 0)return null;if(/[0-7]/u.test(i)){let o=/^[0-7]{1,3}/u.exec(e.slice(n))[0];t+=String.fromCodePoint(Number.parseInt(o,8)),n+=o.length-1}else if(i in Jf)t+=Jf[i];else return null}return null}function od(e,t){let n=o=>o.split("/").length-1,r=o=>o.slice(o.lastIndexOf("/")+1).length,i=-1;for(let o=0;o<e.length;o++){let s=e[o];if(s===null||t[o])continue;if(i===-1){i=o;continue}let[u,a]=[n(s),n(e[i])];if(u!==a){u<a&&(i=o);continue}let[l,c]=[r(s),r(e[i])];if(l!==c){l<c&&(i=o);continue}s.length<e[i].length&&(i=o)}return i}function ws(e,t){let{opts:n}=e;return(n.noReverse||!(n.force&&n.silent))&&e.say(t),n.noReverse?(e.say(` Skipping patch.
147
+ `),{lines:t,pos:0,base:0,empty:e===""}}var O2=/^\d+(?:,\d+)?[acd]\d+(?:,\d+)?[ \t]*\r?\n$/u,$p=/^(?:\d+(?:,\d+)?)?(?:[acdi]|s\/\.\/\/)[ \t]*\n$/u,Np=/^[0-9a-fA-F]+/u;function Ip(e,{needHeader:t,strip:n,format:r}){let{lines:o}=e,i={names:{old:null,new:null,index:null},stamps:{old:-1,new:-1},timestrs:{old:null,new:null},says:[0,0],git:!1,rename:[!1,!1],copy:[!1,!1],extended:!1},s=t&&r!=="normal"&&r!=="ed",u=!1,a=-1,l=!1,f=!1;for(let c=e.pos;;c++){if(c>=o.length)return u&&hn("ed script","ed scripts are not supported"),i.extended?{...i,type:"unified",start:c,hunkLine:c,empty:!0}:null;let d=o[c],p=d.replace(/^[ \tX]+/u,""),h=/^\d/u.test(p)&&O2.test(p);!s&&a<0&&($p.test(p)||h)&&(a=c,u=$p.test(p));let m=C2(d,i,n,f);if(m==="binary"&&hn("git binary patch","git binary diffs are not supported"),m==="prereq"&&hn("Prereq","Prereq: lines are not supported"),m==="git"&&i.extended)return{...i,type:"unified",start:c,hunkLine:c,empty:!0};m&&(s=!1);let g=d.startsWith("********");if(/^[ \t]+(?:@@ -\d|\*{8})/u.test(d)&&hn("indented patch","indented patches are not supported"),!s){if(d.endsWith(`\r
148
+ `)&&(d.startsWith("@@ -")||f)&&hn("CRLF patch","patches with CRLF line endings are not supported"),(r===null||r==="ed")&&a>=0&&d===`.
149
+ `&&hn("ed script","ed scripts are not supported"),(r===null||r==="unified")&&d.startsWith("@@ -"))return T2(i,c,d);if((r===null||r==="context")&&f&&d.startsWith("*** "))return F2(e,i,c,d);if((r===null||r==="normal")&&l&&(d.startsWith("< ")||d.startsWith("> ")))return{...i,type:"normal",start:c-1,hunkLine:c-1}}f=g,l=h}}function C2(e,t,n,r){if(!r&&e.startsWith("*** ")||e.startsWith("+++ "))return eu(t,"old",e.slice(4),n);if(e.startsWith("Index:"))return t.names.index=Fp(e.slice(6),n,!1).name,"index";if(e.startsWith("Prereq:"))return"prereq";if(e.startsWith("diff --git ")){let i=Ap(e.slice(11),n),s=i.name===null?null:Ap(i.rest,n);return t.names.old=s&&s.rest.trim()===""?i.name:null,t.names.new=t.names.old===null?null:s.name,t.git=!0,t.stamps.old=t.stamps.new=-1,"git"}if(t.git){let i=I2(e,t);if(i)return i}let o=e;for(;o.startsWith("- ");)o=o.slice(2);return o.startsWith("--- ")?eu(t,"new",o.slice(4),n):null}function I2(e,t){if(e.startsWith("index ")){let n=Np.exec(e.slice(6)),r=n?e.slice(6+n[0].length):"",o=r.startsWith("..")?Np.exec(r.slice(2)):null;return o?(t.says[0]=/^0+$/u.test(n[0])?2:0,t.says[1]=/^0+$/u.test(o[0])?2:0,t.extended=!0,"index"):null}return e.startsWith("old mode ")||e.startsWith("new mode ")?(t.extended=!0,"mode"):e.startsWith("deleted file mode ")?(t.says[1]=2,t.extended=!0,"mode"):e.startsWith("new file mode ")?(t.says[0]=2,t.extended=!0,"mode"):e.startsWith("rename from ")?(t.rename[0]=!0,t.extended=!0,"rename"):e.startsWith("rename to ")?(t.rename[1]=!0,t.extended=!0,"rename"):e.startsWith("copy from ")?(t.copy[0]=!0,t.extended=!0,"copy"):e.startsWith("copy to ")?(t.copy[1]=!0,t.extended=!0,"copy"):e.startsWith("GIT binary patch")?"binary":null}function eu(e,t,n,r){let o=Fp(n,r,!0);return o.stamp!==void 0&&(e.stamps[t]=o.stamp),o.name!==void 0&&(e.names[t]=o.name,e.timestrs[t]=o.timestr),"name"}function T2(e,t,n){let r={names:{...e.names,old:e.names.new,new:e.names.old},stamps:{old:e.stamps.new,new:e.stamps.old},timestrs:{old:e.timestrs.new,new:e.timestrs.old}},o=/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))?/u.exec(n),i=[...e.says];return o&&o[1]==="0"&&(i[0]=1+(r.stamps.old===0?1:0)),o&&o[3]==="0"&&(i[1]=1+(r.stamps.new===0?1:0)),{...e,...r,says:i,type:"unified",start:t,hunkLine:t}}function F2(e,t,n,r){let o=[...t.says];/^\*\*\* 0(?!\d)/u.test(r)&&(o[0]=1+(t.stamps.old===0?1:0));let i={...e,pos:n-1};try{let s=Qs(i);s&&s.newLines.length===0&&s.newStart===1&&(o[1]=1+(t.stamps.new===0?1:0))}catch{}return{...t,says:o,type:"context",start:n-1,hunkLine:n-1}}function Tp(e,t){return t==="unified"?Sp(e):t==="context"?Qs(e):Ep(e)}function Fp(e,t,n){let r=e.replace(/^[ \t\n\v\f\r]+/u,""),o,i;if(r.startsWith('"')){let a=_p(r);if(!a)return{};o=a.value,i=a.rest}else{let a=0;for(;a<r.length;a++){if(!/[ \t\n\v\f\r]/u.test(r[a]))continue;let l=a;for(;r[l]!==" "&&/[ \t\n\v\f\r]/u.test(r[l+1]??"");)l++;if(!(r[l]!==" "&&r.indexOf(n?" ":`
150
+ `,l+1)!==-1))break}o=r.slice(0,a),i=r.slice(a)}if(o==="/dev/null")return{stamp:0};let s=Lp(o,t);if(s===null)return{};let u=i.replace(/\r?\n$/u,"");return{name:s,timestr:u,stamp:n&&u!==""?L2(u):-1}}function L2(e){let t=/^\s*(\d{4})-(\d\d)-(\d\d)[ T](\d\d):(\d\d):(\d\d)(?:\.\d+)?\s*(?:([+-])(\d\d):?(\d\d))?/u.exec(e),n;if(t){let[,r,o,i,s,u,a,l,f,c]=t;n=Date.UTC(Number(r),Number(o)-1,Number(i),Number(s),Number(u),Number(a))/1e3,l&&(n-=(l==="-"?-1:1)*(Number(f)*3600+Number(c)*60))}else{let r=/^\s*[A-Z][a-z]{2} ([A-Z][a-z]{2}) +(\d+) (\d\d):(\d\d):(\d\d) (\d{4})/u.exec(e);if(!r)return-1;let o=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],[,i,s,u,a,l,f]=r;n=Date.UTC(Number(f),o.indexOf(i),Number(s),Number(u),Number(a),Number(l))/1e3}return n>-25*3600&&n<26*3600?0:n}function Lp(e,t){let n=t,r=0;for(let o=0;o<e.length;o++)if(e[o]==="/"){for(;e[o+1]==="/";)o++;(t<0||--n>=0)&&(r=o+1)}return(t<0||n<=0)&&r<e.length?e.slice(r):null}function Ap(e,t){let n=e.replace(/^[ \t\n\v\f\r]+/u,""),r,o;if(n.startsWith('"')){let i=_p(n);if(!i)return{name:null,rest:""};r=i.value,o=i.rest}else{let i=n.search(/[ \t\n\v\f\r]/u);r=i<0?n:n.slice(0,i),o=i<0?"":n.slice(i)}return{name:Lp(r,t),rest:o}}var Op={a:"\x07",b:"\b",f:"\f",n:`
151
+ `,r:"\r",t:" ",v:"\v","\\":"\\",'"':'"'};function _p(e){let t="";for(let n=1;n<e.length;n++){let r=e[n];if(r==='"')return{value:t,rest:e.slice(n+1)};if(r!=="\\"){t+=r;continue}let o=e[++n];if(o===void 0)return null;if(/[0-7]/u.test(o)){let i=/^[0-7]{1,3}/u.exec(e.slice(n))[0];t+=String.fromCodePoint(Number.parseInt(i,8)),n+=i.length-1}else if(o in Op)t+=Op[o];else return null}return null}function Rp(e,t){let n=i=>i.split("/").length-1,r=i=>i.slice(i.lastIndexOf("/")+1).length,o=-1;for(let i=0;i<e.length;i++){let s=e[i];if(s===null||t[i])continue;if(o===-1){o=i;continue}let[u,a]=[n(s),n(e[o])];if(u!==a){u<a&&(o=i);continue}let[l,f]=[r(s),r(e[o])];if(l!==f){l<f&&(o=i);continue}s.length<e[o].length&&(o=i)}return o}function tu(e,t){let{opts:n}=e;return(n.noReverse||!(n.force&&n.silent))&&e.say(t),n.noReverse?(e.say(` Skipping patch.
134
152
  `),e.skipRest=!0,!1):n.force?(n.silent||e.say(` Applying it anyway.
135
153
  `),!1):n.batch?(e.say(e.reverse?` Ignoring -R.
136
154
  `:` Assuming -R.
@@ -138,118 +156,118 @@ diff: Try 'diff --help' for more information.`,2);function Sy(e){let t=[];for(le
138
156
  `:` Assume -R? [n]
139
157
  `),e.say(`Apply anyway? [n]
140
158
  `),n.silent||e.say(`Skipping patch.
141
- `),e.skipRest=!0,!1)}function sd(e,t,n,r,i){let o=e.reverse?1:0,s=t.says,u=(i?0:1)<s[o^(i?1:0)];if(i&&s[o^(r?1:0)]===1&&s[1-o^(r?1:0)]===2)return!1;if(u){let a=r?"delete":i?"empty out":"create",l=r?"does not exist":i?"is already empty":"already exists";ws(e,`The next patch${e.reverse?", when reversed,":""} would ${a} the file ${e.quote(n)},
142
- which ${l}!`)&&(e.reverse=!e.reverse)}return u}function ud(e,t,n,r){let i=[t.names.old,t.names.new,t.names.index];(i[0]!==null||i[1]!==null)&&i[2]!==null&&(i[2]=null);let o=-1;if(n===null){let u=i.map(c=>c===null?null:r(c)),a=u.map(c=>c===null||!c.exists);o=od(i,a);let l=i.findIndex(c=>c!==null);if(l!==-1&&(o===-1||!u[o].isDir)){let c=o===-1;sd(e,t,i[c?l:o],c,c||u[o].size===0)&&c&&(o=l)}o===-1&&t.says[e.reverse?1:0]&&(o=od(i,i.map(()=>!1)))}if((t.rename[0]||t.rename[1]||t.copy[0]||t.copy[1])&&n===null&&!((o===0||o===1)&&i[0]!==null&&i[1]!==null)&&(e.say(`Cannot ${t.rename[0]||t.rename[1]?"rename":"copy"} file without two valid file names
143
- `),e.skipRest=!0),o===-1){if(n===null)return null;let u=r(n);return(!u.exists||!u.isDir)&&sd(e,t,n,!u.exists,!u.exists||u.size===0),n}return i[o]}function ld(e){return{input:e,frozen:0,inOffset:0,outOffset:0,out:[]}}var zy=(e,t)=>t<1||t>e.input.length?"":e.input[t-1];function qy(e,t){let n=r=>r.replace(/\n$/u,"").replace(/[ \t]+$/u,"").replace(/[ \t]+/gu," ");return n(e)===n(t)}function Jr(e,t,n,r,i,o,s){let u=t.oldLines,a=u.length-o;for(let l=n+r+i,c=i;c<a;c++,l++){let f=zy(e,l),d=u[c].text;if(s?!qy(f,d):f!==d)return!1}return!0}function ad(e,t,n,r){let i=t.oldStart+e.inOffset,o=t.oldLines.length,s=Math.max(t.prefix,t.suffix),u=n+t.prefix-s,a=n+t.suffix-s,l=e.input.length,c=l-(o-a)+1,f=e.frozen+1,d=c-i,p=i-f,m=Math.max(d,p);if(!o)return i;i<=p&&(p=i-1);let h=x=>(e.inOffset+=x,i+x);if(u<0&&t.oldStart<=1){if(a<0&&(o!==l||t.prefix<e.frozen))return 0;let x=1-i;return e.frozen<=t.prefix&&x<=d&&Jr(e,t,i,x,0,a,r)?h(x):0}else u<0&&(u=0);if(a<0){let x=i-(l-o+1);return x<=p&&Jr(e,t,i,-x,u,0,r)?h(-x):0}let g=d<0?i-c:p<0?i-f:0;for(let x=g;x<=m;x++){if(x<=d&&Jr(e,t,i,x,u,a,r))return h(x);if(x<=p&&Jr(e,t,i,-x,u,a,r))return h(-x)}return 0}function Qr(e,t){if(e.frozen>t)return!1;for(;e.frozen<t;)e.frozen<e.input.length&&e.out.push(e.input[e.frozen]),e.frozen++;return!0}function jy(e,t,n){let r=n-1,i=t.newLines,o=t.oldLines,s=0,u=0,a=()=>{throw new H(`Out-of-sync patch, lines ${t.line+1+u+1},${t.line+1+o.length+s+1} -- mangled text or line numbers, maybe?`)};for(;u<o.length;)if(o[u].tag==="-"){if(!Qr(e,r+u))return!1;e.frozen++,u++}else{if(s>=i.length)break;if(i[s].tag==="+"){if(!Qr(e,r+u))return!1;e.out.push(i[s++].text)}else i[s].tag===o[u].tag?(u++,s++):a()}for(;s<i.length&&i[s].tag==="+";s++){if(!Qr(e,r+u))return!1;e.out.push(i[s].text)}return e.outOffset+=i.length-o.length,!0}var cd=e=>e.frozen>=e.input.length||Qr(e,e.input.length),fd=e=>e.map((t,n)=>n<e.length-1&&!t.endsWith(`
159
+ `),e.skipRest=!0,!1)}function Mp(e,t,n,r,o){let i=e.reverse?1:0,s=t.says,u=(o?0:1)<s[i^(o?1:0)];if(o&&s[i^(r?1:0)]===1&&s[1-i^(r?1:0)]===2)return!1;if(u){let a=r?"delete":o?"empty out":"create",l=r?"does not exist":o?"is already empty":"already exists";tu(e,`The next patch${e.reverse?", when reversed,":""} would ${a} the file ${e.quote(n)},
160
+ which ${l}!`)&&(e.reverse=!e.reverse)}return u}function Pp(e,t,n,r){let o=[t.names.old,t.names.new,t.names.index];(o[0]!==null||o[1]!==null)&&o[2]!==null&&(o[2]=null);let i=-1;if(n===null){let u=o.map(f=>f===null?null:r(f)),a=u.map(f=>f===null||!f.exists);i=Rp(o,a);let l=o.findIndex(f=>f!==null);if(l!==-1&&(i===-1||!u[i].isDir)){let f=i===-1;Mp(e,t,o[f?l:i],f,f||u[i].size===0)&&f&&(i=l)}i===-1&&t.says[e.reverse?1:0]&&(i=Rp(o,o.map(()=>!1)))}if((t.rename[0]||t.rename[1]||t.copy[0]||t.copy[1])&&n===null&&!((i===0||i===1)&&o[0]!==null&&o[1]!==null)&&(e.say(`Cannot ${t.rename[0]||t.rename[1]?"rename":"copy"} file without two valid file names
161
+ `),e.skipRest=!0),i===-1){if(n===null)return null;let u=r(n);return(!u.exists||!u.isDir)&&Mp(e,t,n,!u.exists,!u.exists||u.size===0),n}return o[i]}function Bp(e){return{input:e,frozen:0,inOffset:0,outOffset:0,out:[]}}var _2=(e,t)=>t<1||t>e.input.length?"":e.input[t-1];function R2(e,t){let n=r=>r.replace(/\n$/u,"").replace(/[ \t]+$/u,"").replace(/[ \t]+/gu," ");return n(e)===n(t)}function $o(e,t,n,r,o,i,s){let u=t.oldLines,a=u.length-i;for(let l=n+r+o,f=o;f<a;f++,l++){let c=_2(e,l),d=u[f].text;if(s?!R2(c,d):c!==d)return!1}return!0}function Dp(e,t,n,r){let o=t.oldStart+e.inOffset,i=t.oldLines.length,s=Math.max(t.prefix,t.suffix),u=n+t.prefix-s,a=n+t.suffix-s,l=e.input.length,f=l-(i-a)+1,c=e.frozen+1,d=f-o,p=o-c,h=Math.max(d,p);if(!i)return o;o<=p&&(p=o-1);let m=w=>(e.inOffset+=w,o+w);if(u<0&&t.oldStart<=1){if(a<0&&(i!==l||t.prefix<e.frozen))return 0;let w=1-o;return e.frozen<=t.prefix&&w<=d&&$o(e,t,o,w,0,a,r)?m(w):0}else u<0&&(u=0);if(a<0){let w=o-(l-i+1);return w<=p&&$o(e,t,o,-w,u,0,r)?m(-w):0}let g=d<0?o-f:p<0?o-c:0;for(let w=g;w<=h;w++){if(w<=d&&$o(e,t,o,w,u,a,r))return m(w);if(w<=p&&$o(e,t,o,-w,u,a,r))return m(-w)}return 0}function No(e,t){if(e.frozen>t)return!1;for(;e.frozen<t;)e.frozen<e.input.length&&e.out.push(e.input[e.frozen]),e.frozen++;return!0}function M2(e,t,n){let r=n-1,o=t.newLines,i=t.oldLines,s=0,u=0,a=()=>{throw new Q(`Out-of-sync patch, lines ${t.line+1+u+1},${t.line+1+i.length+s+1} -- mangled text or line numbers, maybe?`)};for(;u<i.length;)if(i[u].tag==="-"){if(!No(e,r+u))return!1;e.frozen++,u++}else{if(s>=o.length)break;if(o[s].tag==="+"){if(!No(e,r+u))return!1;e.out.push(o[s++].text)}else o[s].tag===i[u].tag?(u++,s++):a()}for(;s<o.length&&o[s].tag==="+";s++){if(!No(e,r+u))return!1;e.out.push(o[s].text)}return e.outOffset+=o.length-i.length,!0}var Up=e=>e.frozen>=e.input.length||No(e,e.input.length),jp=e=>e.map((t,n)=>n<e.length-1&&!t.endsWith(`
144
162
  `)?t+`
145
- `:t).join("");function dd(e,t,n,r,i){let{opts:o}=e,s={count:0,failed:0,mismatch:!1,applyAnyway:!1};for(let u=n();u;u=n()){s.count++;let a=e.skipRest?{hunk:e.reverse?Kr(u):u,where:0,fuzz:0}:Hy(e,r,e.reverse?Kr(u):u,s),{hunk:l,where:c,fuzz:f}=a,d=(c||l.oldStart)+r.outOffset,p=c===1&&t.says[e.reverse?1:0]===2&&r.input.length>0;if(e.skipRest||p||!c||!jy(r,l,c))e.skipRejectFile||i.add(l,s.failed===0,r.outOffset,e.reverse),s.failed++,!e.skipRest&&!o.silent&&e.say(`Hunk #${s.count} FAILED at ${d}.
146
- `);else if(!o.silent&&(f||r.inOffset)){let m=r.inOffset?` (offset ${r.inOffset} line${r.inOffset===1?"":"s"})`:"";e.say(`Hunk #${s.count} succeeded at ${d}${f?` with fuzz ${f}`:""}${m}.
147
- `)}}return s}function Hy(e,t,n,r){let{opts:i}=e,o=0,s=n,u=0,a=Math.min(i.fuzz,Math.max(s.prefix,s.suffix));do if(u=ad(t,s,o,i.loose),(!u||o||t.inOffset)&&(r.mismatch=!0),r.count===1&&!u&&!(i.force||r.applyAnyway)&&e.reverse===e.reverseFlag){let l=Kr(s);u=ad(t,l,o,i.loose),u&&ws(e,`${e.reverse?"Unreversed":"Reversed (or previously applied)"} patch detected!`)?(e.reverse=!e.reverse,s=l):u&&(r.applyAnyway=!0,o--,u=0)}while(!e.skipRest&&!u&&++o<=a);return{hunk:s,where:u,fuzz:o}}var Xn=(e,t)=>e+t;function md(e,t){let n="",r=(o,s)=>`${o} ${e.names[s]??"/dev/null"}${e.timestrs[s]??""}
148
- `,i=e.names.index===null?"":`Index: ${e.names.index}
149
- `;return{get text(){return n},add(o,s,u,a){let l=a?["new","old"]:["old","new"];t==="unified"?(s&&(n+=i+r("---",l[0])+r("+++",l[1])),n+=Gy(o,u)):(s&&(n+=i+r("***",l[0])+r("---",l[1])),n+=Xy(o,u,t))}}}var pd=(e,t)=>t===0?`${e-1},0`:t===1?`${e}`:`${e},${t}`;function Gy(e,t){let n=e.newLines,r=e.oldLines,i=`@@ -${pd(e.oldStart+t,r.length)} +${pd(e.newStart+t,n.length)} @@${e.fn??""}
150
- `,o=0,s=0;for(;;s++,o++){for(;s<r.length&&r[s].tag==="-";s++)i+=Xn("-",r[s].text);for(;o<n.length&&n[o].tag==="+";o++)i+=Xn("+",n[o].text);if(s>=r.length)break;i+=Xn(" ",r[s].text)}return i}function hd(e,t){let n=e+t-1;return n<e?"0":n===e?`${e}`:`${e},${n}`}function Xy(e,t,n){let r=n!=="normal",i=e.marks??(n==="normal"?Zy(e):Vy(e)),o=`***************${e.fn??""}
151
- `;return o+=`*** ${hd(e.oldStart+t,e.oldLines.length)}${r?" ****":""}
152
- `,e.oldLines.forEach((s,u)=>{o+=Xn(i.old[u]+" ",s.text)}),o+=`--- ${hd(e.newStart+t,e.newLines.length)}${r?" ----":" -----"}
153
- `,e.newLines.forEach((s,u)=>{o+=Xn(i.new[u]+" ",s.text)}),o}var Zy=e=>({old:e.oldLines.map(t=>t.tag),new:e.newLines.map(t=>t.tag)});function Vy(e){let t=e.newLines.map(o=>o.tag),n=e.oldLines.map(o=>o.tag),r=0,i=0;for(;i<n.length;)if(n[i]==="-")if(r<t.length&&t[r]==="+"){do n[i++]="!";while(i<n.length&&n[i]==="-");do t[r++]="!";while(r<t.length&&t[r]==="+")}else do i++;while(i<n.length&&n[i]==="-");else if(r<t.length&&t[r]==="+")do r++;while(r<t.length&&t[r]==="+");else i++,r++;return{old:n,new:t}}var Yy=["R","N","f","t","s","b","l","E","T","Z","e","u","c","n","v"],Ky=["reverse","forward","force","batch","silent","quiet","backup","ignore-whitespace","remove-empty-files","dry-run","verbose","unified","context","normal","ed","binary","no-backup-if-mismatch","backup-if-mismatch","posix","follow-symlinks","help","version","set-time","set-utc"],Jy=["p","i","o","d","r","F","z","B","Y","V","g","D","x"],Qy=["strip","input","output","directory","reject-file","fuzz","suffix","prefix","basename-prefix","version-control","get","reject-format","quoting-style","read-only","merge","debug"],gd=new Map([["T","setting file times"],["Z","setting file times"],["set-time","setting file times"],["set-utc","setting file times"],["e","ed scripts"],["ed","ed scripts"],["v","a version banner"],["version","a version banner"],["help","a help text"],["verbose","verbose output"],["B","backup prefixes"],["prefix","backup prefixes"],["Y","backup prefixes"],["basename-prefix","backup prefixes"],["V","numbered backups"],["version-control","numbered backups"],["g","version control"],["get","version control"],["D","merged #ifdef output"],["x","debugging output"],["debug","debugging output"],["posix","POSIX mode"],["follow-symlinks","symbolic links"],["quoting-style","quoting styles"],["read-only","read-only handling"],["merge","merging"]]),wd=e=>y(`patch: ${e}
154
- patch: Try 'patch --help' for more information.`,2);function yd(e){for(let r of e){if(r==="--")break;let i=r.replace(/=.*/u,"");if(i==="--merge"||i==="--read-only")return{refused:v("option","patch",i,`patch: ${i}: ${gd.get(i.slice(2))} is not supported`,2)}}let t;try{t=E(e,{short:Yy,long:Ky,valueShort:Jy,valueLong:Qy})}catch(r){let i=N(r);return i?{refused:v(i.kind,"patch",i.detail,`patch: ${r.message}`,2)}:{error:wd(r.message)}}let n={strip:-1,input:null,output:null,directory:null,rejectFile:null,fuzz:2,suffix:".orig",format:null,rejectFormat:null,reverse:!1,noReverse:!1,force:!1,batch:!1,silent:!1,backup:!1,backupIfMismatch:!0,loose:!1,removeEmpty:!1,dryRun:!1};for(let{name:r,value:i}of t.order){let o=(r.length===1?"-":"--")+r,s=gd.get(r);if(s)return{refused:v("option","patch",o,`patch: ${o}: ${s} is not supported`,2)};let u=eb(n,r,i);if(u)return{error:u}}return t.positional.length>2?{error:wd(`${t.positional[2]}: extra operand`)}:{opts:n,operands:t.positional}}function xd(e,t){if(!/^[+-]?\d+$/u.test(e))return{error:y(`patch: **** ${t} ${ie(e,{vars:new Map})} is not a number`,2)};let n=Number(e);return n<0?{error:y(`patch: **** ${t} ${e} is negative`,2)}:{value:Math.min(n,Number.MAX_SAFE_INTEGER)}}function eb(e,t,n){switch(t){case"p":case"strip":{let r=xd(n,"strip count");return r.error?r.error:(e.strip=r.value,null)}case"F":case"fuzz":{let r=xd(n,"fuzz factor");return r.error?r.error:(e.fuzz=r.value,null)}case"i":case"input":return e.input=n,null;case"o":case"output":return e.output=n,null;case"d":case"directory":return e.directory=n,null;case"r":case"reject-file":return e.rejectFile=n,null;case"z":case"suffix":return n===""?y("patch: **** backup suffix is empty",2):(e.suffix=n,null);case"R":case"reverse":return e.reverse=!0,null;case"N":case"forward":return e.noReverse=!0,null;case"f":case"force":return e.force=!0,null;case"t":case"batch":return e.batch=!0,null;case"s":case"silent":case"quiet":return e.silent=!0,null;case"b":case"backup":return e.backup=!0,null;case"l":case"ignore-whitespace":return e.loose=!0,null;case"E":case"remove-empty-files":return e.removeEmpty=!0,null;case"dry-run":return e.dryRun=!0,null;case"u":case"unified":return e.format="unified",null;case"c":case"context":return e.format="context",null;case"n":case"normal":return e.format="normal",null;case"no-backup-if-mismatch":return e.backupIfMismatch=!1,null;case"backup-if-mismatch":return e.backupIfMismatch=!0,null;case"reject-format":return n!=="unified"&&n!=="context"?y(`patch: **** unknown reject format ${n}`,2):(e.rejectFormat=n,null);default:return null}}function vd(e,t,n){let r=yd(t);if(r.error)return r.error;if(r.refused)return r.refused;let{opts:i,operands:o}=r,s={ctx:n,opts:i,dir:n.cwd,events:[],stdout:"",stderr:"",skipRest:!1,skipRejectFile:!1,reverse:i.reverse,reverseFlag:i.reverse,someFailed:!1,rejectsMade:new Set,output:""},u=i.output==="-"?2:1;s.quote=a=>ie(a,n),s.say=a=>{u===1?s.stdout+=a:s.stderr+=a,s.events.push({fd:u,text:a})};try{if(i.directory!==null){let l=$(n.cwd,i.directory,n.fs);if(l.error||!n.fs.isDir(l.path))throw new H(`Can't change to directory ${ie(i.directory,n)} : ${l.error??"Not a directory"}`);s.dir=l.path}let a=tb(s,e,i.input??o[1]??null);nb(s,Qf(a),o[0]??null),i.output!==null&&i.output!=="-"&&ti(s,i.output,s.output,!1)}catch(a){if(!(a instanceof H)){let c=N(a);if(!c)throw a;let f=`patch: ${a.message}`,d={stdout:s.stdout,stderr:s.stderr+f+`
155
- `,events:[...s.events,{fd:2,text:f+`
156
- `}],exitCode:2};return Q(d,c.kind,"patch",c.detail,f)}let l=`patch: **** ${a.message}
157
- `;return{stdout:s.stdout,stderr:s.stderr+l,events:[...s.events,{fd:2,text:l}],exitCode:2}}return{stdout:s.stdout,stderr:s.stderr,events:s.events,exitCode:s.someFailed?1:0}}function tb(e,t,n){if(n===null)return z(e.ctx),t;if(n==="-")return z(e.ctx),t;let r=P(e.ctx,"patch",n);if(r.error||e.ctx.fs.isDir(r.path))throw new H(`Can't open patch file ${ie(n,e.ctx)} : ${r.error??"Is a directory"}`);return e.ctx.fs.readFile(r.path)}function nb(e,t,n){let{opts:r}=e;for(;;){if(t.base!==0&&t.base>=t.lines.length)return;let i=ed(t,{needHeader:n===null,strip:r.strip,format:r.format});if(i===null){if(t.base===0&&!t.empty)throw new H("Only garbage was found in the patch input.");return}e.skipRest=!1,e.skipRejectFile=!1,e.reverse=e.reverseFlag;let o=ud(e,i,n,s=>ni(e,s));o===null&&(o=rb(e,t,i)),e.skipRest&&(e.someFailed=!0),t.pos=i.start,ib(e,t,i,o),t.base=t.pos}}function rb(e,t,n){let{opts:r}=e;if(r.silent||(e.say(`can't find file to patch at input line ${n.hunkLine+1}
163
+ `:t).join("");function Wp(e,t,n,r,o){let{opts:i}=e,s={count:0,failed:0,mismatch:!1,applyAnyway:!1};for(let u=n();u;u=n()){s.count++;let a=e.skipRest?{hunk:e.reverse?Eo(u):u,where:0,fuzz:0}:P2(e,r,e.reverse?Eo(u):u,s),{hunk:l,where:f,fuzz:c}=a,d=(f||l.oldStart)+r.outOffset,p=f===1&&t.says[e.reverse?1:0]===2&&r.input.length>0;if(e.skipRest||p||!f||!M2(r,l,f))e.skipRejectFile||o.add(l,s.failed===0,r.outOffset,e.reverse),s.failed++,!e.skipRest&&!i.silent&&e.say(`Hunk #${s.count} FAILED at ${d}.
164
+ `);else if(!i.silent&&(c||r.inOffset)){let h=r.inOffset?` (offset ${r.inOffset} line${r.inOffset===1?"":"s"})`:"";e.say(`Hunk #${s.count} succeeded at ${d}${c?` with fuzz ${c}`:""}${h}.
165
+ `)}}return s}function P2(e,t,n,r){let{opts:o}=e,i=0,s=n,u=0,a=Math.min(o.fuzz,Math.max(s.prefix,s.suffix));do if(u=Dp(t,s,i,o.loose),(!u||i||t.inOffset)&&(r.mismatch=!0),r.count===1&&!u&&!(o.force||r.applyAnyway)&&e.reverse===e.reverseFlag){let l=Eo(s);u=Dp(t,l,i,o.loose),u&&tu(e,`${e.reverse?"Unreversed":"Reversed (or previously applied)"} patch detected!`)?(e.reverse=!e.reverse,s=l):u&&(r.applyAnyway=!0,i--,u=0)}while(!e.skipRest&&!u&&++i<=a);return{hunk:s,where:u,fuzz:i}}var ur=(e,t)=>e+t;function Hp(e,t){let n="",r=(i,s)=>`${i} ${e.names[s]??"/dev/null"}${e.timestrs[s]??""}
166
+ `,o=e.names.index===null?"":`Index: ${e.names.index}
167
+ `;return{get text(){return n},add(i,s,u,a){let l=a?["new","old"]:["old","new"];t==="unified"?(s&&(n+=o+r("---",l[0])+r("+++",l[1])),n+=D2(i,u)):(s&&(n+=o+r("***",l[0])+r("---",l[1])),n+=B2(i,u,t))}}}var qp=(e,t)=>t===0?`${e-1},0`:t===1?`${e}`:`${e},${t}`;function D2(e,t){let n=e.newLines,r=e.oldLines,o=`@@ -${qp(e.oldStart+t,r.length)} +${qp(e.newStart+t,n.length)} @@${e.fn??""}
168
+ `,i=0,s=0;for(;;s++,i++){for(;s<r.length&&r[s].tag==="-";s++)o+=ur("-",r[s].text);for(;i<n.length&&n[i].tag==="+";i++)o+=ur("+",n[i].text);if(s>=r.length)break;o+=ur(" ",r[s].text)}return o}function zp(e,t){let n=e+t-1;return n<e?"0":n===e?`${e}`:`${e},${n}`}function B2(e,t,n){let r=n!=="normal",o=e.marks??(n==="normal"?U2(e):j2(e)),i=`***************${e.fn??""}
169
+ `;return i+=`*** ${zp(e.oldStart+t,e.oldLines.length)}${r?" ****":""}
170
+ `,e.oldLines.forEach((s,u)=>{i+=ur(o.old[u]+" ",s.text)}),i+=`--- ${zp(e.newStart+t,e.newLines.length)}${r?" ----":" -----"}
171
+ `,e.newLines.forEach((s,u)=>{i+=ur(o.new[u]+" ",s.text)}),i}var U2=e=>({old:e.oldLines.map(t=>t.tag),new:e.newLines.map(t=>t.tag)});function j2(e){let t=e.newLines.map(i=>i.tag),n=e.oldLines.map(i=>i.tag),r=0,o=0;for(;o<n.length;)if(n[o]==="-")if(r<t.length&&t[r]==="+"){do n[o++]="!";while(o<n.length&&n[o]==="-");do t[r++]="!";while(r<t.length&&t[r]==="+")}else do o++;while(o<n.length&&n[o]==="-");else if(r<t.length&&t[r]==="+")do r++;while(r<t.length&&t[r]==="+");else o++,r++;return{old:n,new:t}}var W2=["R","N","f","t","s","b","l","E","T","Z","e","u","c","n","v"],q2=["reverse","forward","force","batch","silent","quiet","backup","ignore-whitespace","remove-empty-files","dry-run","verbose","unified","context","normal","ed","binary","no-backup-if-mismatch","backup-if-mismatch","posix","follow-symlinks","help","version","set-time","set-utc"],z2=["p","i","o","d","r","F","z","B","Y","V","g","D","x"],H2=["strip","input","output","directory","reject-file","fuzz","suffix","prefix","basename-prefix","version-control","get","reject-format","quoting-style","read-only","merge","debug"],Gp=new Map([["T","setting file times"],["Z","setting file times"],["set-time","setting file times"],["set-utc","setting file times"],["e","ed scripts"],["ed","ed scripts"],["v","a version banner"],["version","a version banner"],["help","a help text"],["verbose","verbose output"],["B","backup prefixes"],["prefix","backup prefixes"],["Y","backup prefixes"],["basename-prefix","backup prefixes"],["V","numbered backups"],["version-control","numbered backups"],["g","version control"],["get","version control"],["D","merged #ifdef output"],["x","debugging output"],["debug","debugging output"],["posix","POSIX mode"],["follow-symlinks","symbolic links"],["quoting-style","quoting styles"],["read-only","read-only handling"],["merge","merging"]]),Xp=e=>x(`patch: ${e}
172
+ patch: Try 'patch --help' for more information.`,2);function Yp(e){for(let r of e){if(r==="--")break;let o=r.replace(/=.*/u,"");if(o==="--merge"||o==="--read-only")return{refused:v("option","patch",o,`patch: ${o}: ${Gp.get(o.slice(2))} is not supported`,2)}}let t;try{t=N(e,{short:W2,long:q2,valueShort:z2,valueLong:H2})}catch(r){let o=O(r);return o?{refused:v(o.kind,"patch",o.detail,`patch: ${r.message}`,2)}:{error:Xp(r.message)}}let n={strip:-1,input:null,output:null,directory:null,rejectFile:null,fuzz:2,suffix:".orig",format:null,rejectFormat:null,reverse:!1,noReverse:!1,force:!1,batch:!1,silent:!1,backup:!1,backupIfMismatch:!0,loose:!1,removeEmpty:!1,dryRun:!1};for(let{name:r,value:o}of t.order){let i=(r.length===1?"-":"--")+r,s=Gp.get(r);if(s)return{refused:v("option","patch",i,`patch: ${i}: ${s} is not supported`,2)};let u=G2(n,r,o);if(u)return{error:u}}return t.positional.length>2?{error:Xp(`${t.positional[2]}: extra operand`)}:{opts:n,operands:t.positional}}function Zp(e,t){if(!/^[+-]?\d+$/u.test(e))return{error:x(`patch: **** ${t} ${oe(e,{vars:new Map})} is not a number`,2)};let n=Number(e);return n<0?{error:x(`patch: **** ${t} ${e} is negative`,2)}:{value:Math.min(n,Number.MAX_SAFE_INTEGER)}}function G2(e,t,n){switch(t){case"p":case"strip":{let r=Zp(n,"strip count");return r.error?r.error:(e.strip=r.value,null)}case"F":case"fuzz":{let r=Zp(n,"fuzz factor");return r.error?r.error:(e.fuzz=r.value,null)}case"i":case"input":return e.input=n,null;case"o":case"output":return e.output=n,null;case"d":case"directory":return e.directory=n,null;case"r":case"reject-file":return e.rejectFile=n,null;case"z":case"suffix":return n===""?x("patch: **** backup suffix is empty",2):(e.suffix=n,null);case"R":case"reverse":return e.reverse=!0,null;case"N":case"forward":return e.noReverse=!0,null;case"f":case"force":return e.force=!0,null;case"t":case"batch":return e.batch=!0,null;case"s":case"silent":case"quiet":return e.silent=!0,null;case"b":case"backup":return e.backup=!0,null;case"l":case"ignore-whitespace":return e.loose=!0,null;case"E":case"remove-empty-files":return e.removeEmpty=!0,null;case"dry-run":return e.dryRun=!0,null;case"u":case"unified":return e.format="unified",null;case"c":case"context":return e.format="context",null;case"n":case"normal":return e.format="normal",null;case"no-backup-if-mismatch":return e.backupIfMismatch=!1,null;case"backup-if-mismatch":return e.backupIfMismatch=!0,null;case"reject-format":return n!=="unified"&&n!=="context"?x(`patch: **** unknown reject format ${n}`,2):(e.rejectFormat=n,null);default:return null}}function Kp(e,t,n){let r=Yp(t);if(r.error)return r.error;if(r.refused)return r.refused;let{opts:o,operands:i}=r,s={ctx:n,opts:o,dir:n.cwd,events:[],stdout:"",stderr:"",skipRest:!1,skipRejectFile:!1,reverse:o.reverse,reverseFlag:o.reverse,someFailed:!1,rejectsMade:new Set,output:""},u=o.output==="-"?2:1;s.quote=a=>oe(a,n),s.say=a=>{u===1?s.stdout+=a:s.stderr+=a,s.events.push({fd:u,text:a})};try{if(o.directory!==null){let l=E(n.cwd,o.directory,n.fs);if(l.error||!n.fs.isDir(l.path))throw new Q(`Can't change to directory ${oe(o.directory,n)} : ${l.error??"Not a directory"}`);s.dir=l.path}let a=X2(s,e,o.input??i[1]??null);Z2(s,Cp(a),i[0]??null),o.output!==null&&o.output!=="-"&&Oo(s,o.output,s.output,!1)}catch(a){if(!(a instanceof Q)){let f=O(a);if(!f)throw a;let c=`patch: ${a.message}`,d={stdout:s.stdout,stderr:s.stderr+c+`
173
+ `,events:[...s.events,{fd:2,text:c+`
174
+ `}],exitCode:2};return ie(d,f.kind,"patch",f.detail,c)}let l=`patch: **** ${a.message}
175
+ `;return{stdout:s.stdout,stderr:s.stderr+l,events:[...s.events,{fd:2,text:l}],exitCode:2}}return{stdout:s.stdout,stderr:s.stderr,events:s.events,exitCode:s.someFailed?1:0}}function X2(e,t,n){if(n===null)return q(e.ctx),t;if(n==="-")return q(e.ctx),t;let r=P(e.ctx,"patch",n);if(r.error||e.ctx.fs.isDir(r.path))throw new Q(`Can't open patch file ${oe(n,e.ctx)} : ${r.error??"Is a directory"}`);return e.ctx.fs.readFile(r.path)}function Z2(e,t,n){let{opts:r}=e;for(;;){if(t.base!==0&&t.base>=t.lines.length)return;let o=Ip(t,{needHeader:n===null,strip:r.strip,format:r.format});if(o===null){if(t.base===0&&!t.empty)throw new Q("Only garbage was found in the patch input.");return}e.skipRest=!1,e.skipRejectFile=!1,e.reverse=e.reverseFlag;let i=Pp(e,o,n,s=>Co(e,s));i===null&&(i=Y2(e,t,o)),e.skipRest&&(e.someFailed=!0),t.pos=o.start,V2(e,t,o,i),t.base=t.pos}}function Y2(e,t,n){let{opts:r}=e;if(r.silent||(e.say(`can't find file to patch at input line ${n.hunkLine+1}
158
176
  `),n.type!=="normal"&&e.say(r.strip===-1?`Perhaps you should have used the -p or --strip option?
159
177
  `:`Perhaps you used the wrong -p or --strip option?
160
178
  `)),t.base<n.start){e.say(`The text leading up to this was:
161
179
  --------------------------
162
- `);for(let i=t.base;i<n.start;i++)e.say("|"+t.lines[i]);e.say(`--------------------------
180
+ `);for(let o=t.base;o<n.start;o++)e.say("|"+t.lines[o]);e.say(`--------------------------
163
181
  `)}return r.force||r.batch?e.say(`No file to patch. Skipping patch.
164
182
  `):(e.say(`File to patch:
165
183
  `),e.say(`Skip this patch? [y]
166
184
  `),r.silent||e.say(`Skipping patch.
167
- `)),e.skipRest=!0,null}function ib(e,t,n,r){let{opts:i}=e,o=n.copy[0]||n.copy[1]||n.rename[0]||n.rename[1],s=null;e.skipRest||(s=i.output??(o?n.names[e.reverse?"old":"new"]:r));let u={exists:!1,isDir:!1,content:""};e.skipRest||(u=ni(e,r),u.isDir&&(e.say(`File ${ie(r,e.ctx)} is not a regular file -- refusing to patch
168
- `),e.skipRest=!0,e.someFailed=!0)),!e.skipRest&&!i.dryRun&&i.output===null&&(Zn(e,s),o&&r!==s&&Zn(e,r));let a=ld(We(u.exists?u.content:""));if(!e.skipRest&&!i.silent){let p=r!==s,m=!p&&(n.rename[0]||n.rename[1]),h=n.copy[0]||n.copy[1]?"copied":n.rename[0]||n.rename[1]?"renamed":"read",g=m?n.names[r===n.names.old?"new":"old"]:r,x=p||m?` (${m?"already ":""}${h} from ${g})`:"";e.say(`${i.dryRun?"checking":"patching"} file ${ie(s,e.ctx)}${x}
169
- `)}let l=md(n,i.rejectFormat??n.type),f=dd(e,n,()=>n.empty?null:td(t,n.type),a,l);!e.skipRest&&!cd(a)&&(e.say(`misordered hunks! output would be garbled
185
+ `)),e.skipRest=!0,null}function V2(e,t,n,r){let{opts:o}=e,i=n.copy[0]||n.copy[1]||n.rename[0]||n.rename[1],s=null;e.skipRest||(s=o.output??(i?n.names[e.reverse?"old":"new"]:r));let u={exists:!1,isDir:!1,content:""};e.skipRest||(u=Co(e,r),(u.isDir||u.link)&&(e.say(`File ${oe(r,e.ctx)} is not a regular file -- refusing to patch
186
+ `),e.skipRest=!0,e.someFailed=!0)),!e.skipRest&&!o.dryRun&&o.output===null&&(ar(e,s),i&&r!==s&&ar(e,r));let a=Bp(Ge(u.exists?u.content:""));if(!e.skipRest&&!o.silent){let p=r!==s,h=!p&&(n.rename[0]||n.rename[1]),m=n.copy[0]||n.copy[1]?"copied":n.rename[0]||n.rename[1]?"renamed":"read",g=h?n.names[r===n.names.old?"new":"old"]:r,w=p||h?` (${h?"already ":""}${m} from ${g})`:"";e.say(`${o.dryRun?"checking":"patching"} file ${oe(s,e.ctx)}${w}
187
+ `)}let l=Hp(n,o.rejectFormat??n.type),c=Wp(e,n,()=>n.empty?null:Tp(t,n.type),a,l);!e.skipRest&&!Up(a)&&(e.say(`misordered hunks! output would be garbled
170
188
  Skipping patch.
171
- `),e.skipRest=!0);let d=fd(a.out);i.output!==null&&!e.skipRest&&(i.output==="-"?(e.stdout+=d,e.events.push({fd:1,text:d})):e.output+=d),!e.skipRest&&i.output===null&&ob(e,n,{inname:r,outname:s,input:u,content:d,result:f,empty:a.out.length===0,renaming:o}),f.failed&&!e.skipRejectFile&&sb(e,s,f,l.text)}function ob(e,t,n){let{opts:r}=e,{inname:i,outname:o,input:s,content:u,result:a,empty:l,renaming:c}=n,f=r.backup||r.backupIfMismatch&&(a.mismatch||a.failed>0),d=t.says[e.reverse?0:1]===2;if(l&&(r.removeEmpty||d)){r.dryRun||bd(e,o,f);return}if(!l&&d&&(e.someFailed=!0,r.silent||e.say(`Not deleting file ${ie(o,e.ctx)} as content differs from patch
172
- `)),!r.dryRun){if(a.failed<a.count||c)ti(e,o,u,f),c&&i!==o&&(t.rename[0]||t.rename[1])&&bd(e,i,!1);else if(f){if(!s.exists)throw new H(`Can't reopen file ${ie(o,e.ctx)} : No such file or directory`);ti(e,ei(e,o),s.content,!1)}}}function sb(e,t,n,r){let{opts:i}=e;if(e.someFailed=!0,e.say(`${n.failed} out of ${n.count} hunk${n.count===1?"":"s"} ${e.skipRest?"ignored":"FAILED"}`),t===null||i.rejectFile==="-"){e.say(`
173
- `);return}let o=i.rejectFile??t+".rej";if(i.dryRun){e.say(`
174
- `);return}e.say(` -- saving rejects to file ${ie(o,e.ctx)}
175
- `),Zn(e,o);let s=e.rejectsMade.has(L(e.dir,o));e.rejectsMade.add(L(e.dir,o));let u=s?ni(e,o).content:"";ti(e,o,u+r,!1)}var ei=(e,t)=>t+e.opts.suffix;function ni(e,t){let n=$(e.dir,t,e.ctx.fs);if(n.error)return{exists:!1,isDir:!1,size:0,content:""};if(e.ctx.fs.isDir(n.path))return{exists:!0,isDir:!0,size:0,content:""};let r=e.ctx.fs.readFile(n.path);return{exists:!0,isDir:!1,size:r.length,content:r}}function Zn(e,t){let n=L(e.dir,t);if(!(e.ctx.writable&&n.startsWith("/tmp/")))throw new w("feature","read-only target",`${t}: file system is read-only`)}function ti(e,t,n,r){let{ctx:i}=e;Zn(e,t);let o=$(e.dir,t,i.fs);try{if(!o.error){i.fs.replaceWritable(e.dir,t,n,r?ei(e,t):void 0);return}r&&i.fs.openWritable(e.dir,ei(e,t)),i.fs.openWritable(e.dir,t).write(n)}catch(s){throw new H(`Can't create file ${ie(t,e.ctx)} : ${s?.fsError??s.message}`)}}function bd(e,t,n){let{ctx:r}=e;Zn(e,t);let i=ni(e,t);i.exists&&(n&&r.fs.openWritable(e.dir,ei(e,t)).write(i.content),r.fs.removeWritable(e.dir,t))}var kd={du:Vc,stat:mf,realpath:yf,diff:jf,patch:vd};function ub(e,t,n){return E(t),C(n.cwd+`
176
- `)}function ab(e,t,n){let{positional:r}=E(t);if(r.length>1)return y("cd: too many arguments");if(!r.length&&n.vars.unsetNames.has("HOME"))return y("cd: HOME not set");let i=r[0]??Jt(n);if(i==="-"){if(!n.vars.has("OLDPWD"))return y("cd: OLDPWD not set");i=n.vars.get("OLDPWD")}let o=r[0]==="-"?i+`
177
- `:"";if(i==="")return C(o);let{path:s,error:u}=P(n,"cd",i);return u?y(`cd: ${i}: ${u}`):n.fs.isDir(s)?(n.vars.set("OLDPWD",n.cwd),n.vars.set("PWD",s),n.cwd=s,C(o)):y(`cd: ${i}: Not a directory`)}function lb(e,t,n){let{flags:r,positional:i}=E(t,{short:["1","l","a","A","R","d","r","F","h"]}),o=r.has("l")?bc(n,r.has("h")):null,s=(i.length?i:["."]).toSorted(U);r.has("r")&&s.reverse();let u=[],a=[],l=[],c=Pt(),f=r.has("a")||r.has("A"),d=(g,x)=>r.has("F")&&n.fs.isDir(x)&&!g.endsWith("/")?g+"/":g,p=(g,x,b)=>({raw:g,abs:x,dir:b,name:d(g,x)}),m=(g,x)=>o?o.lines(g,x):g.map(b=>b.name);for(let g of s){let{path:x,error:b}=P(n,"ls",g);b?a.push(`ls: cannot access '${g}': ${b}`):r.has("d")||n.fs.isFile(x)?l.push(p(g,x,n.fs.isDir(x))):u.push(g)}let h=l.length?[m(l,!1).join(`
178
- `)]:[];for(let g of u){let x=[g];for(;x.length;){let b=x.pop(),S=L(n.cwd,b),A=n.fs.listDir(S);f||c.collect(S,[...A.dirs,...A.files]);let V=(Y,Ie)=>Y.filter(X=>f||!X.startsWith(".")).map(X=>p(X,L(S,X),Ie)),q=[...V(A.dirs,!0),...V(A.files,!1)];r.has("a")&&q.push(p(".",S,!0),p("..",L(S,".."),!0)),q.sort((Y,Ie)=>U(Y.raw,Ie.raw)),r.has("r")&&q.reverse();let T=m(q,!0);if((s.length>1||r.has("R"))&&T.unshift(b+":"),T.length&&h.push(T.join(`
179
- `)),!!r.has("R"))for(let Y of q.toReversed())Y.raw==="."||Y.raw===".."||!n.fs.isDir(Y.abs)||x.push(b.endsWith("/")?b+Y.raw:b+"/"+Y.raw)}}return c.emit(n.notes,"ls","Hidden entries are included with -a."),{stdout:h.length?h.join(`
189
+ `),e.skipRest=!0);let d=jp(a.out);o.output!==null&&!e.skipRest&&(o.output==="-"?(e.stdout+=d,e.events.push({fd:1,text:d})):e.output+=d),!e.skipRest&&o.output===null&&K2(e,n,{inname:r,outname:s,input:u,content:d,result:c,empty:a.out.length===0,renaming:i}),c.failed&&!e.skipRejectFile&&J2(e,s,c,l.text)}function K2(e,t,n){let{opts:r}=e,{inname:o,outname:i,input:s,content:u,result:a,empty:l,renaming:f}=n,c=r.backup||r.backupIfMismatch&&(a.mismatch||a.failed>0),d=t.says[e.reverse?0:1]===2;if(l&&(r.removeEmpty||d)){r.dryRun||Vp(e,i,c);return}if(!l&&d&&(e.someFailed=!0,r.silent||e.say(`Not deleting file ${oe(i,e.ctx)} as content differs from patch
190
+ `)),!r.dryRun){if(a.failed<a.count||f)Oo(e,i,u,c),f&&o!==i&&(t.rename[0]||t.rename[1])&&Vp(e,o,!1);else if(c){if(!s.exists)throw new Q(`Can't reopen file ${oe(i,e.ctx)} : No such file or directory`);Oo(e,Ao(e,i),s.content,!1)}}}function J2(e,t,n,r){let{opts:o}=e;if(e.someFailed=!0,e.say(`${n.failed} out of ${n.count} hunk${n.count===1?"":"s"} ${e.skipRest?"ignored":"FAILED"}`),t===null||o.rejectFile==="-"){e.say(`
191
+ `);return}let i=o.rejectFile??t+".rej";if(o.dryRun){e.say(`
192
+ `);return}e.say(` -- saving rejects to file ${oe(i,e.ctx)}
193
+ `),ar(e,i);let s=e.rejectsMade.has(Z(e.dir,i));e.rejectsMade.add(Z(e.dir,i));let u=s?Co(e,i).content:"";Oo(e,i,u+r,!1)}var Ao=(e,t)=>t+e.opts.suffix;function Co(e,t){let n=E(e.dir,t,e.ctx.fs,{follow:!1}),r=!n.error&&e.ctx.fs.isLink?.(n.path)===!0,o=E(e.dir,t,e.ctx.fs);if(o.error)return{exists:!1,isDir:!1,link:r,size:0,content:""};if(e.ctx.fs.isDir(o.path))return{exists:!0,isDir:!0,link:r,size:0,content:""};let i=e.ctx.fs.readFile(o.path);return{exists:!0,isDir:!1,link:r,size:i.length,content:i}}function ar(e,t){let n=se(e.ctx.fs,e.dir,t,!1);if(!(e.ctx.writable&&n.startsWith("/tmp/")))throw new b("feature","read-only target",`${t}: file system is read-only`)}function Oo(e,t,n,r){let{ctx:o}=e;ar(e,t);let i=E(e.dir,t,o.fs);try{if(!i.error){o.fs.replaceWritable(e.dir,t,n,r?Ao(e,t):void 0);return}r&&o.fs.openWritable(e.dir,Ao(e,t)),o.fs.openWritable(e.dir,t).write(n)}catch(s){throw new Q(`Can't create file ${oe(t,e.ctx)} : ${s?.fsError??s.message}`)}}function Vp(e,t,n){let{ctx:r}=e;ar(e,t);let o=Co(e,t);o.exists&&(n&&r.fs.openWritable(e.dir,Ao(e,t)).write(o.content),r.fs.removeWritable(e.dir,t))}var Jp={du:Ad,stat:Gd,realpath:Dc,diff:xp,patch:Kp};function Q2(e,t,n){return N(t),F(n.cwd+`
194
+ `)}function ek(e,t,n){let{positional:r}=N(t);if(r.length>1)return x("cd: too many arguments");if(!r.length&&n.vars.unsetNames.has("HOME"))return x("cd: HOME not set");let o=r[0]??ln(n);if(o==="-"){if(!n.vars.has("OLDPWD"))return x("cd: OLDPWD not set");o=n.vars.get("OLDPWD")}let i=r[0]==="-"?o+`
195
+ `:"";if(o==="")return F(i);let{path:s,error:u}=P(n,"cd",o);return u?x(`cd: ${o}: ${u}`):n.fs.isDir(s)?s!==Z(n.cwd,o)?v("feature","cd","symbolic link cwd",`cd: ${o}: a working directory reached through a symbolic link is not supported (it leads to ${s})`):(n.vars.set("OLDPWD",n.cwd),n.vars.set("PWD",s),n.cwd=s,F(i)):x(`cd: ${o}: Not a directory`)}var tk={dir:"/",link:"@",file:""};function nk(e,t,n){let{flags:r,positional:o}=N(t,{short:["1","l","a","A","R","d","r","F","h"]}),i=r.has("l")?Qc(n,r.has("h")):null,s=(o.length?o:["."]).toSorted(j);r.has("r")&&s.reverse();let u=[],a=[],l=[],f=Jt(),c=r.has("a")||r.has("A"),d=y=>n.fs.isDir(y)?"dir":n.fs.isLink?.(y)?"link":"file",p=y=>r.has("F")?tk[y]:"",h=(y,k,S)=>({raw:y,abs:k,kind:S,name:S==="link"&&i?y:y+(y.endsWith("/")?"":p(S)),target:S==="link"?n.fs.readLink(k)+p(d(E(n.cwd,k,n.fs).path??"")):null}),m=(y,k)=>i?i.lines(y,k):y.map(S=>S.name),g=!(r.has("l")||r.has("F")||r.has("d"));for(let y of s){let{path:k,error:S}=P(n,"ls",y,{follow:!1}),I=S||!g||!n.fs.isLink?.(k)?k:E(n.cwd,y,n.fs).path;S?a.push(`ls: cannot access '${y}': ${S}`):r.has("d")||n.fs.isFile(k)||!n.fs.isDir(I)?l.push(h(y,k,d(k))):u.push({path:y,abs:I})}let w=l.length?[m(l,!1).join(`
196
+ `)]:[];for(let y of u){let k=[y];for(;k.length;){let{path:S,abs:I}=k.pop(),M=n.fs.listDir(I);c||f.collect(I,[...M.dirs,...M.files,...M.links]);let C=(D,de)=>D.filter(Xt=>c||!Xt.startsWith(".")).map(Xt=>h(Xt,Z(I,Xt),de)),H=[...C(M.dirs,"dir"),...C(M.files,"file"),...C(M.links,"link")];r.has("a")&&H.push(h(".",I,"dir"),h("..",Z(I,".."),"dir")),H.sort((D,de)=>j(D.raw,de.raw)),r.has("r")&&H.reverse();let Y=m(H,!0);if((s.length>1||r.has("R"))&&Y.unshift(S+":"),Y.length&&w.push(Y.join(`
197
+ `)),!!r.has("R"))for(let D of H.toReversed())D.raw==="."||D.raw===".."||!n.fs.isDir(D.abs)||k.push({path:S.endsWith("/")?S+D.raw:S+"/"+D.raw,abs:D.abs})}}return f.emit(n.notes,"ls","Hidden entries are included with -a."),{stdout:w.length?w.join(`
180
198
 
181
199
  `)+`
182
200
  `:"",stderr:a.length?a.join(`
183
201
  `)+`
184
- `:"",exitCode:a.length?2:0}}function cb(e,t){let{positional:n}=E(t);if(n.length===0)return oe("basename PATH [SUFFIX]");if(n.length>2)return y(`basename: extra operand: ${n[2]}`);let r=n[0].replace(/\/+$/u,""),i=r===""?n[0]===""?"":"/":r.slice(r.lastIndexOf("/")+1);return C(fb(i,n[1])+`
185
- `)}function fb(e,t){return!t||t===e||!e.endsWith(t)?e:e.slice(0,-t.length)}function db(e,t){let{positional:n}=E(t);return n.length===0?oe("dirname PATH"):C(n.map(r=>{let i=r.replace(/\/+$/u,""),o=i.lastIndexOf("/");return o<0?r.startsWith("/")?"/":".":i.slice(0,o).replace(/\/+$/u,"")||"/"}).join(`
202
+ `:"",exitCode:a.length?2:0}}function rk(e,t){let{positional:n}=N(t);if(n.length===0)return pe("basename PATH [SUFFIX]");if(n.length>2)return x(`basename: extra operand: ${n[2]}`);let r=n[0].replace(/\/+$/u,""),o=r===""?n[0]===""?"":"/":r.slice(r.lastIndexOf("/")+1);return F(ok(o,n[1])+`
203
+ `)}function ok(e,t){return!t||t===e||!e.endsWith(t)?e:e.slice(0,-t.length)}function ik(e,t){let{positional:n}=N(t);return n.length===0?pe("dirname PATH"):F(n.map(r=>{let o=r.replace(/\/+$/u,""),i=o.lastIndexOf("/");return i<0?r.startsWith("/")?"/":".":o.slice(0,i).replace(/\/+$/u,"")||"/"}).join(`
186
204
  `)+`
187
- `)}var Sd={pwd:ub,cd:ab,ls:lb,find:Ec,tree:vc,basename:cb,dirname:db,...kd};function $d(e,t,n){let{flags:r,positional:i}=E(t,{short:["n","b","s","v","E","T","A","e","t"]}),o=u=>hb(u,r),s=pb(i,e,n,o,r.size!==0);return ue(o(s.content),s)}function pb(e,t,n,r,i){let o=n.outputFds[1];if(!o?.path&&!n.outputFds[2]?.path)return mn("cat",e,t,n);let s="",u=t,a="";for(let l of e.length?e:["-"]){let c=l==="-",f=c||l==="/dev/stdin",d=f?n.stdinHandle?.path:$(n.cwd,l,n.fs).path,p=f?n.stdinHandle?.identity:n.fs.fileIdentity?.(d);if(a&&Ed(d,p,n.outputFds[2]))throw new w("feature","cat input modified by diagnostics","cat: reading an input after writing diagnostics to the same file is not supported");if(Ed(d,p,o)){if((c?I(n.stdinHandle.content).length-I(u).length:0)<o.position+I(r(s)).length){a+=`cat: ${l}: input file is output file
188
- `;continue}let g=c?u:f?n.stdinOrigin:n.fs.readFile(d);if(i&&g!=="")throw new w("feature","cat transforms its input file","cat: transforming an input file through its own output descriptor is not supported")}let m=mn("cat",[l],u,n);s+=m.content,a+=m.stderr,(c||l==="/dev/stdin"&&!n.stdinFile)&&(u="")}return{content:s,stderr:a,failed:a!==""}}function Ed(e,t,n){return!e||!n?.path?!1:t!==void 0&&n.identity!==void 0?t===n.identity:e===n.path}function hb(e,t){if(!t.size)return e;let n=t.has("E")||t.has("A")||t.has("e"),r=t.has("T")||t.has("A")||t.has("t"),i=t.has("v")||t.has("A")||t.has("e")||t.has("t"),o=t.has("s")?mb(e):e,s=0;return We(o).map(a=>{let l=a.endsWith(`
189
- `),c=l?a.slice(0,-1):a,f=(t.has("b")?c!=="":t.has("n"))?`${String(++s).padStart(6)} `:"";return i?c=[...I(c)].map(d=>Nd(d,r)).join(""):(r&&(c=c.replaceAll(" ","^I")),n&&l&&c.endsWith("\r")&&(c=c.slice(0,-1)+"^M")),f+c+(l?n?`$
205
+ `)}var Qp={pwd:Q2,cd:ek,ls:nk,find:od,tree:ed,basename:rk,dirname:ik,...Jp};function r1(e,t,n){let{flags:r,positional:o}=N(t,{short:["n","b","s","v","E","T","A","e","t"]}),i=u=>ak(u,r),s=sk(o,e,n,i,r.size!==0);if(s.bytes===void 0)return ne(i(s.content),s);if(r.size)throw new b("feature","binary file","cat: formatting bytes that spell no text is not supported");return{stdout:"",stderr:s.stderr,exitCode:s.failed?1:0,events:[{fd:1,bytes:s.bytes},...s.stderr?[{fd:2,text:s.stderr}]:[]]}}function e1(e,t,n){let r=te("cat",e,t,n,{read:"maybe-text"});return{parts:r.inputs.map(o=>o.content??o.bytes),stderr:r.stderr,failed:r.failed}}var t1=e=>e.every(t=>typeof t=="string")?{content:e.join("")}:{bytes:vn([...e.map(t=>typeof t=="string"?B(t):t),new Uint8Array])};function sk(e,t,n,r,o){let i=n.outputFds[1];if(!i?.path&&!n.outputFds[2]?.path){let f=e1(e,t,n);return{...t1(f.parts),stderr:f.stderr,failed:f.failed}}let s=[],u="",a=t,l="";for(let f of e.length?e:["-"]){let c=f==="-",d=c||f==="/dev/stdin",p=d?n.stdinHandle?.path:E(n.cwd,f,n.fs).path,h=d?n.stdinHandle?.identity:n.fs.fileIdentity?.(p);if(l&&n1(p,h,n.outputFds[2]))throw new b("feature","cat input modified by diagnostics","cat: reading an input after writing diagnostics to the same file is not supported");if(n1(p,h,i)){if((c?A(n.stdinHandle.content).length-A(a).length:0)<i.position+uk(s,u,r)){l+=`cat: ${f}: input file is output file
206
+ `;continue}let w=c?a:d?n.stdinOrigin:n.fs.readFile(p);if(o&&w!=="")throw new b("feature","cat transforms its input file","cat: transforming an input file through its own output descriptor is not supported")}let m=e1([f],a,n);s.push(...m.parts),u+=m.parts.filter(g=>typeof g=="string").join(""),l+=m.stderr,(c||f==="/dev/stdin"&&!n.stdinFile)&&(a="")}return{...t1(s),stderr:l,failed:l!==""}}var uk=(e,t,n)=>e.every(r=>typeof r=="string")?A(n(t)).length:e.reduce((r,o)=>r+(typeof o=="string"?A(o).length:o.length),0);function n1(e,t,n){return!e||!n?.path?!1:t!==void 0&&n.identity!==void 0?t===n.identity:e===n.path}function ak(e,t){if(!t.size)return e;let n=t.has("E")||t.has("A")||t.has("e"),r=t.has("T")||t.has("A")||t.has("t"),o=t.has("v")||t.has("A")||t.has("e")||t.has("t"),i=t.has("s")?lk(e):e,s=0;return Ge(i).map(a=>{let l=a.endsWith(`
207
+ `),f=l?a.slice(0,-1):a,c=(t.has("b")?f!=="":t.has("n"))?`${String(++s).padStart(6)} `:"";return o?f=[...A(f)].map(d=>o1(d,r)).join(""):(r&&(f=f.replaceAll(" ","^I")),n&&l&&f.endsWith("\r")&&(f=f.slice(0,-1)+"^M")),c+f+(l?n?`$
190
208
  `:`
191
- `:"")}).join("")}function Nd(e,t){return e===9?t?"^I":" ":e>=128?"M-"+Nd(e-128,!0):e<32?"^"+String.fromCodePoint(e+64):e===127?"^?":String.fromCodePoint(e)}function mb(e){return e.replace(/(^|\n)\n+/gu,`$1
192
- `)}var ri="sed: supported commands are p, P, n, N, d, D, a, i, c, g, G, h, H, x, w, q, =, y, :, b, t, T, { }, and s/regexp/replacement/[NgiIpw]",xs=1e6,ii=16*1024*1024,Ad=64*1024*1024;function ge(e="script"){throw new w("feature",e,ri)}function oi(e){return e.gap?v("feature","sed",e.gap,`sed: ${e.message}`):e instanceof RangeError?v("feature","sed","regex runtime limit",`sed: ${e.message}`):K(e,"sed",`sed: ${e.message.replace(/^sed: /u,"")}`,e.exitCode)}function Id(e){let t=[],n=null;for(let r=0;r<e.length;r++){let i=e[r];if(i==="--"){t.push(...e.slice(r));break}if(i==="--in-place"||i.startsWith("--in-place=")){n=i==="--in-place"?"":i.slice(11);continue}if(i.startsWith("--")||!i.startsWith("-")){t.push(i),(i==="--expression"||i==="--file")&&r+1<e.length&&t.push(e[++r]);continue}let o=i;for(let s=1;s<i.length;s++){let u=i[s];if(u==="i"){n=i.slice(s+1),o=i.slice(0,s);break}if(u==="e"||u==="f"){t.push(i),s+1===i.length&&r+1<e.length&&t.push(e[++r]),o="";break}if(!"nErsz".includes(u))break}o&&(o!=="-"||i==="-")&&t.push(o)}return{tokens:t,inPlace:n}}function Od(e,t,n,r,i){if(e.files.length===0)return y("sed: no input files",4);let o=R(),s=new Set([...t,"s"]),u=!1;for(let a of e.files){let l=gb(a,n);if(l.error){if(_(o,n.flushOutput(l.error)),l.error.exitCode!==2)return si(o,l.error);u=!0;continue}let c=i({...e,files:[l.path]},s),{content:f,...d}=c;if(_(o,d),c.failed||N(c))return si(o,c);let p=wb(a,r),m;try{m=n.fs.replaceWritable(n.cwd,a,f,p)}catch(h){D(n,"sed",h?.path,h?.fsError);let g=K(h,"sed",`sed: ${h.message}`,4);return _(o,g),si(o,g)}if(!m){let h=ys(p??a);return _(o,h),si(o,h)}if(c.quit)break}return u&&(o.exitCode=2),o}function gb(e,t){if(e==="/dev/null"||e==="/dev/stdin"&&!t.stdinFile||e==="/dev/stdout"&&!t.outputFds[1]?.path||e==="/dev/stderr"&&!t.outputFds[2]?.path)return{error:y(`sed: couldn't edit ${e}: not a regular file`,4)};if(e==="/dev/stdin"||e==="/dev/stdout"||e==="/dev/stderr")return{error:ys(e)};let n=P(t,"sed",e);return n.error?{error:y(Pi("sed",e,n.error).trimEnd(),2)}:t.fs.isDir(n.path)?{error:y(`sed: couldn't edit ${e}: not a regular file`,4)}:!t.writable||!n.path.startsWith("/tmp/")?{error:ys(e)}:n}function wb(e,t){if(!(t===""||t==="*"))return t.includes("*")?t.replaceAll("*",()=>e):e+t}function ys(e){return v("feature","sed","-i",`sed: ${e}: file system is read-only`)}function si(e,t){let n=N(t);return n?Q(e,n.kind,n.command,n.detail,n.message):e}function bs(e,t){let n=!1;return(r,i)=>{e((n?t:"")+r+(i??"")),n=i===""}}function Cd(e,t){let n=new Map,r=0,i,o,s,u=()=>e.io.setReads([i,o?.identity]);function a(c,f){if(f==="")return;l(f),u();let d=e.outputFds[c];if(d?.path){d.write(f);return}if(d==="closed"){let p=new Error("write error: Bad file descriptor");throw p.exitCode=4,p}s[c===1?"stdout":"stderr"]+=f,s.events.push({fd:c,text:f})}function l(c){if(r+=c.length,r>Ad)throw new w("feature","output limit","sed: output limit exceeded")}return{start(c){return s=R(),o=c,i=void 0,u(),s},record(c){i=c?.identity,u()},finish(){i=void 0,o=null,u()},stream:a,account:l,openWrite(c){if(n.has(c))return n.get(c);let f;if(c==="/dev/null")f=()=>{};else if(c==="/dev/stdout"||c==="/dev/stderr")f=p=>a(c==="/dev/stdout"?1:2,p);else{let p;try{p=e.writable&&e.fs.openWritable(e.cwd,c)}catch(m){throw D(e,"sed",m?.path,m?.fsError),m.exitCode=4,m}if(!p)throw new w("feature","output file",`sed: ${c}: Read-only file system`);f=m=>{l(m),u(),p.write(m)}}let d=bs(f,t);return n.set(c,d),d}}}function Vn(e,t){let n=t.stdinHandle;if(!n)return e;let r=t.io.bufferReads(()=>t.fs.readIdentity(n.identity));if(r===n.content)return e;if(e!==n.content)throw new w("feature","modified redirected input","sed: reading an input file changed after partial consumption is not supported");return t.stdinHandle={...n,content:r},t.stdinOrigin=t.stdinLeft=r,r}function Fd(e,t,n,r,i,o){let s=e.length?e:["-"],u={stderr:"",failed:!1},a=0,l=0,c=t,f=null;function d(){for(;f===null||f.pos===f.content.length;){if(a===s.length)return!1;f=null;let m=s[a++];m==="-"?c=Vn(c,n):m==="/dev/stdin"&&n.stdinHandle&&(n.stdinOrigin=n.io.bufferReads(()=>n.fs.readIdentity(n.stdinHandle.identity)));let h=Ye("sed",[m],n,c);if(u.stderr+=h.stderr,u.failed||=h.failed,f=h.inputs.length?{...h.inputs[0],identity:xb(m,n),pos:0,first:!0}:null,h.stderr&&o&&o(h.stderr),h.entries.some(g=>g.kind==="dir"))return u.directory=!0,a=s.length,!1;f?.shared&&z(n,c),i&&(l=0)}return!0}function p(){if(!d())return null;let m=f.pos,h=f.content.indexOf(r,m),g=h<0?"":r,x=f.content.slice(m,h<0?f.content.length:h);f.pos=h<0?f.content.length:h+r.length,f.shared&&(c=f.content.slice(f.pos),z(n,c));let b=f.first;f.first=!1;let S;return{text:x,terminator:g,line:++l,reset:b,identity:f.identity,last:()=>S??=f.pos<f.content.length?!1:i||!d()}}return{next:p,status:u,get identity(){return f?.identity}}}function xb(e,t){return e==="-"||e==="/dev/stdin"?t.stdinHandle?.identity:t.fs.fileIdentity?.(L(t.cwd,e))}var ui={n:`
193
- `,t:" ",r:"\r",a:"\x07",f:"\f",v:"\v"};function Yn(e,t="substitute command"){let n=e.script[e.i++];if(n===void 0||n===`
194
- `)throw new Error(`unterminated ${t}`);if(n.codePointAt(0)>127)throw new Error("delimiter character is not a single-byte character");return n}function ai(e,t,n,r="substitute command"){let i="",o=!1;for(;e.i<e.script.length;){let s=e.script[e.i++];if(s===`
195
- `)throw new Error(`unterminated ${r}`);if(s===t&&!o)return i;if(s==="\\"){let u=e.script[e.i++];if(u===void 0||u===`
196
- `&&o)throw new Error(`unterminated ${r}`);if(u===`
197
- `){i+=u;continue}i+=!o&&u===t&&(n||u!=="&")?u:s+u;continue}if(n&&s==="["&&!o){o=!0,i+=s,e.script[e.i]==="^"&&(i+=e.script[e.i++]),e.script[e.i]==="]"&&(i+=e.script[e.i++]);continue}if(n&&o&&s==="["&&/[:.=]/u.test(e.script[e.i]??"")){let u=e.script.indexOf(e.script[e.i]+"]",e.i+1);if(u<0)throw new Error("unterminated character class");if(e.script.slice(e.i,u).includes(`
198
- `))throw new Error(`unterminated ${r}`);i+=s+e.script.slice(e.i,u+2),e.i=u+2;continue}n&&s==="]"&&(o=!1),i+=s}throw new Error(`unterminated ${r}`)}function Td(e){let t=Yn(e),n=ai(e,t,!0),r=ai(e,t,!1),i=vb(r),o=yb(e);if(n===""&&(o.ignoreCase||o.multiline))throw new Error("cannot specify modifiers on empty regexp");o.multiline&&_d(o.multiline);let s=ks(n,e.extended,!1,o.ignoreCase,e.locale);for(let u of i)if(typeof u=="number"&&u>s.re?.groupCount)throw new Error(`invalid reference \\${u} in replacement`);return{...s,parts:i,...o}}function yb(e){let t={global:!1,print:!1,nth:null};for(;e.i<e.script.length;){let n=e.script[e.i];if(/[;\n#}]/u.test(n))break;if(e.i++,!/[ \t]/u.test(n)){if(n==="\r"&&e.script[e.i]===`
199
- `)break;if(/\d/u.test(n)){if(t.nth!==null)throw new Error("multiple number options to substitute command");let r=/^\d*/u.exec(e.script.slice(e.i))[0];if(e.i+=r.length,t.nth=Number(n+r),t.nth===0)throw new Error("number option to substitute command may not be zero");Number.isSafeInteger(t.nth)||ge("substitution occurrence limit")}else if(n==="g"||n==="p"){let r=n==="g"?"global":"print";if(t[r])throw new Error("multiple substitution flags");t[r]=!0}else if(n==="w"){Object.assign(t,vs(e));break}else if(n==="i"||n==="I")t.ignoreCase=!0;else if(n==="m"||n==="M")t.multiline=n;else if(n==="e")_d(n);else throw new Error(`unknown option to substitute command: '${n}'`)}}return t}function _d(e){let t=e==="e"?"command evaluation":"multiline regex matching";throw new w("feature",`substitution flag ${e}`,`sed: substitution flag '${e}' (${t}) is not supported`)}function vs(e){let t=/^[ \t]*([^\n]*)/u.exec(e.script.slice(e.i));e.i+=t[0].length;let n=t[1].split("\0",1)[0];if(n==="")throw new Error("missing filename in r/R/w/W commands");return e.openWrite?{writer:e.openWrite(n)}:{writeName:n}}function ks(e,t,n=!1,r=!1,i=Ve){if(!e){if(r)throw new Error("cannot specify modifiers on empty regexp");return{re:null}}No(e,t);let o=e.replace(/\\(.)/gu,(a,l)=>(l==="o"&&ge("regex escape"),Object.hasOwn(ui,l)?ui[l]:a)),s=t?{source:Eo(o)}:Tr(o);if(s.error)throw new Error(s.error);bb(s.source,t),_r(s.source);for(let[,a]of s.source.matchAll(/\\(.)/gu))/[1-9]/u.test(a)&&ge("regex backreferences");let u=new Qe(Zt(s.source,!0),r);return{re:u,noSub:n,locale:i,compatible:!r&&Lr(u.src,e),spaceClass:/\[:(?:space|blank):\]|\\[sS]/u.test(e)}}function bb(e,t){let n=!1,r=0,i=!1,o=!1;for(let s=0;s<e.length;s++){let u=e[s];if(u==="\\"){let a=e[++s];n||(i=!"bB<>`'".includes(a),o=!1);continue}if(n){u==="]"&&(n=!1,i=!0,o=!1);continue}if(u==="["){n=!0;continue}if(u==="("){r++,i=!1,o=!1;continue}if(u===")"){if(--r<0)throw new Error("unmatched )")}else if(u==="|"||u==="^"||u==="$"){i=!1,o=!1;continue}else if("*+?{".includes(u)){let a=u==="{"?/^\{(?=\d|,)(\d*)(?:,(\d*))?\}/u.exec(e.slice(s)):null;if(u==="{"&&a===null)throw new Error("invalid repetition count");if(!i||!t&&o&&(u==="*"||u==="{"))throw new Error("Invalid preceding regular expression");a&&(s+=a[0].length-1),o=!0;continue}i=!0,o=!1}if(r>0)throw new Error("unmatched (")}function vb(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n];if(r==="&"){t.push(0);continue}if(r!=="\\"){t.push(r);continue}let i=e[++n];/[0-9]/u.test(i)?t.push(Number(i)):i==="\\"||i==="&"?t.push(i):Object.hasOwn(ui,i)?t.push(ui[i]):ge("replacement escape")}return t}function Ss(e,t){if(/[\u0080-\u{10FFFF}]/u.test(e+t.re.src)){if(t.locale!==Ve)throw new w("feature","locale",`matching non-ASCII text in the ${t.locale} locale is not supported`);(!t.compatible||t.spaceClass&&Rr(e))&&ge("non-ASCII regex semantics")}}function Es(e,t,n=null){let r=e.re===null?t.last:e;if(!r)throw new Error("no previous regular expression");if(t.last=r,n!==null&&r.noSub){if(n>r.re.groupCount)throw new Error(`invalid reference \\${n} in replacement`);r.noSub=!1}return r}function $s(e,t,n){let r=t.parts.reduce((l,c)=>typeof c=="number"?Math.max(l,c):l,0),i=Es(t,n,r);Ss(e,i);let o=t.parts.some(l=>typeof l=="number"&&l>0&&l<=i.re.groupCount),s=0,u=t.nth&&!t.global?{search:(l,c)=>s?null:i.re.search(l,c)}:i.re;return{out:Tn(e,u,(l,c,f)=>{if(t.nth&&f<t.nth)return null;s++;let d=o?i.re.groups(e,l,c):null;return t.parts.map(p=>typeof p=="string"?p:p===0?e.slice(l,c):d?.[p]?.text??"").join("")},t.global||t.nth?"global":"first").out,count:s}}var Ld={a:7,f:12,n:10,r:13,t:9,v:11,"\n":10},Rd={d:10,o:8,x:16};function Pd(e,t){for(;/[ \t]/u.test(e.script[e.i]??"");)e.i++;if(e.i===e.script.length)throw new Error("expected \\ after 'a', 'c' or 'i'");if(t.text=null,e.textState.pending={command:t,raw:""},e.script[e.i]==="\\"){let n=e.script[++e.i];if(n===void 0)return;e.i++,n!==`
200
- `&&(e.textState.pending.raw=n)}As(e)}function As(e){let t=e.textState.pending;if(!t)return;let n=t.raw;for(;e.i<e.script.length&&e.script[e.i]!==`
209
+ `:"")}).join("")}function o1(e,t){return e===9?t?"^I":" ":e>=128?"M-"+o1(e-128,!0):e<32?"^"+String.fromCodePoint(e+64):e===127?"^?":String.fromCodePoint(e)}function lk(e){return e.replace(/(^|\n)\n+/gu,`$1
210
+ `)}var Io="sed: supported commands are p, P, n, N, d, D, a, i, c, g, G, h, H, x, w, q, =, y, :, b, t, T, { }, and s/regexp/replacement/[NgiIpw]",nu=1e6,To=16*1024*1024,i1=64*1024*1024;function Ee(e="script"){throw new b("feature",e,Io)}function Fo(e){return e.gap?v("feature","sed",e.gap,`sed: ${e.message}`):e instanceof RangeError?v("feature","sed","regex runtime limit",`sed: ${e.message}`):K(e,"sed",`sed: ${e.message.replace(/^sed: /u,"")}`,e.exitCode)}function s1(e){let t=[],n=null;for(let r=0;r<e.length;r++){let o=e[r];if(o==="--"){t.push(...e.slice(r));break}if(o==="--in-place"||o.startsWith("--in-place=")){n=o==="--in-place"?"":o.slice(11);continue}if(o.startsWith("--")||!o.startsWith("-")){t.push(o),(o==="--expression"||o==="--file")&&r+1<e.length&&t.push(e[++r]);continue}let i=o;for(let s=1;s<o.length;s++){let u=o[s];if(u==="i"){n=o.slice(s+1),i=o.slice(0,s);break}if(u==="e"||u==="f"){t.push(o),s+1===o.length&&r+1<e.length&&t.push(e[++r]),i="";break}if(!"nErsz".includes(u))break}i&&(i!=="-"||o==="-")&&t.push(i)}return{tokens:t,inPlace:n}}function u1(e,t,n,r,o){if(e.files.length===0)return x("sed: no input files",4);let i=U(),s=new Set([...t,"s"]),u=!1;for(let a of e.files){let l=fk(a,n);if(l.error){if(_(i,n.flushOutput(l.error)),l.error.exitCode!==2)return Lo(i,l.error);u=!0;continue}let f=o({...e,files:[l.path]},s),{content:c,...d}=f;if(_(i,d),f.failed||O(f))return Lo(i,f);let p=ck(a,r),h;try{h=n.fs.replaceWritable(n.cwd,a,c,p)}catch(m){R(n,"sed",m?.path,m?.fsError);let g=K(m,"sed",`sed: ${m.message}`,4);return _(i,g),Lo(i,g)}if(!h){let m=ru(p??a);return _(i,m),Lo(i,m)}if(f.quit)break}return u&&(i.exitCode=2),i}function fk(e,t){if(e==="/dev/null"||e==="/dev/stdin"&&!t.stdinFile||e==="/dev/stdout"&&!t.outputFds[1]?.path||e==="/dev/stderr"&&!t.outputFds[2]?.path)return{error:x(`sed: couldn't edit ${e}: not a regular file`,4)};if(e==="/dev/stdin"||e==="/dev/stdout"||e==="/dev/stderr")return{error:ru(e)};let n=P(t,"sed",e);if(n.error)return{error:x(xi("sed",e,n.error).trimEnd(),2)};if(t.fs.isDir(n.path))return{error:x(`sed: couldn't edit ${e}: not a regular file`,4)};let r=E(t.cwd,e,t.fs,{follow:!1}).path;return!t.writable||!r.startsWith("/tmp/")?{error:ru(e)}:n}function ck(e,t){if(!(t===""||t==="*"))return t.includes("*")?t.replaceAll("*",()=>e):e+t}function ru(e){return v("feature","sed","-i",`sed: ${e}: file system is read-only`)}function Lo(e,t){let n=O(t);return n?ie(e,n.kind,n.command,n.detail,n.message):e}function ou(e,t){let n=!1;return(r,o)=>{e((n?t:"")+r+(o??"")),n=o===""}}function a1(e,t){let n=new Map,r=0,o,i,s,u=()=>e.io.setReads([o,i?.identity]);function a(f,c){if(c==="")return;l(c),u();let d=e.outputFds[f];if(d?.path){d.write(c);return}if(d==="closed"){let p=new Error("write error: Bad file descriptor");throw p.exitCode=4,p}s[f===1?"stdout":"stderr"]+=c,s.events.push({fd:f,text:c})}function l(f){if(r+=f.length,r>i1)throw new b("feature","output limit","sed: output limit exceeded")}return{start(f){return s=U(),i=f,o=void 0,u(),s},record(f){o=f?.identity,u()},finish(){o=void 0,i=null,u()},stream:a,account:l,openWrite(f){if(n.has(f))return n.get(f);let c;if(f==="/dev/null")c=()=>{};else if(f==="/dev/stdout"||f==="/dev/stderr")c=p=>a(f==="/dev/stdout"?1:2,p);else{let p;try{p=e.writable&&e.fs.openWritable(e.cwd,f)}catch(h){throw R(e,"sed",h?.path,h?.fsError),h.exitCode=4,h}if(!p)throw new b("feature","output file",`sed: ${f}: Read-only file system`);c=h=>{l(h),u(),p.write(h)}}let d=ou(c,t);return n.set(f,d),d}}}function lr(e,t){let n=t.stdinHandle;if(!n)return e;let r=t.io.bufferReads(()=>t.fs.readIdentity(n.identity));if(r===n.content)return e;if(e!==n.content)throw new b("feature","modified redirected input","sed: reading an input file changed after partial consumption is not supported");return t.stdinHandle={...n,content:r},t.stdinOrigin=t.stdinLeft=r,r}function l1(e,t,n,r,o,i){let s=e.length?e:["-"],u={stderr:"",failed:!1},a=0,l=0,f=t,c=null;function d(){for(;c===null||c.pos===c.content.length;){if(a===s.length)return!1;c=null;let h=s[a++];h==="-"?f=lr(f,n):h==="/dev/stdin"&&n.stdinHandle&&(n.stdinOrigin=n.io.bufferReads(()=>n.fs.readIdentity(n.stdinHandle.identity)));let m=st("sed",[h],n,f);if(u.stderr+=m.stderr,u.failed||=m.failed,c=m.inputs.length?{...m.inputs[0],identity:dk(h,n),pos:0,first:!0}:null,m.stderr&&i&&i(m.stderr),m.entries.some(g=>g.kind==="dir"))return u.directory=!0,a=s.length,!1;c?.shared&&q(n,f),o&&(l=0)}return!0}function p(){if(!d())return null;let h=c.pos,m=c.content.indexOf(r,h),g=m<0?"":r,w=c.content.slice(h,m<0?c.content.length:m);c.pos=m<0?c.content.length:m+r.length,c.shared&&(f=c.content.slice(c.pos),q(n,f));let y=c.first;c.first=!1;let k;return{text:w,terminator:g,line:++l,reset:y,identity:c.identity,last:()=>k??=c.pos<c.content.length?!1:o||!d()}}return{next:p,status:u,get identity(){return c?.identity}}}function dk(e,t){return e==="-"||e==="/dev/stdin"?t.stdinHandle?.identity:t.fs.fileIdentity?.(E(t.cwd,e,t.fs).path??Z(t.cwd,e))}var _o={n:`
211
+ `,t:" ",r:"\r",a:"\x07",f:"\f",v:"\v"};function fr(e,t="substitute command"){let n=e.script[e.i++];if(n===void 0||n===`
212
+ `)throw new Error(`unterminated ${t}`);if(n.codePointAt(0)>127)throw new Error("delimiter character is not a single-byte character");return n}function Ro(e,t,n,r="substitute command"){let o="",i=!1;for(;e.i<e.script.length;){let s=e.script[e.i++];if(s===`
213
+ `)throw new Error(`unterminated ${r}`);if(s===t&&!i)return o;if(s==="\\"){let u=e.script[e.i++];if(u===void 0||u===`
214
+ `&&i)throw new Error(`unterminated ${r}`);if(u===`
215
+ `){o+=u;continue}o+=!i&&u===t&&(n||u!=="&")?u:s+u;continue}if(n&&s==="["&&!i){i=!0,o+=s,e.script[e.i]==="^"&&(o+=e.script[e.i++]),e.script[e.i]==="]"&&(o+=e.script[e.i++]);continue}if(n&&i&&s==="["&&/[:.=]/u.test(e.script[e.i]??"")){let u=e.script.indexOf(e.script[e.i]+"]",e.i+1);if(u<0)throw new Error("unterminated character class");if(e.script.slice(e.i,u).includes(`
216
+ `))throw new Error(`unterminated ${r}`);o+=s+e.script.slice(e.i,u+2),e.i=u+2;continue}n&&s==="]"&&(i=!1),o+=s}throw new Error(`unterminated ${r}`)}function f1(e){let t=fr(e),n=Ro(e,t,!0),r=Ro(e,t,!1),o=mk(r),i=pk(e);if(n===""&&(i.ignoreCase||i.multiline))throw new Error("cannot specify modifiers on empty regexp");i.multiline&&c1(i.multiline);let s=su(n,e.extended,!1,i.ignoreCase,e.locale);for(let u of o)if(typeof u=="number"&&u>s.re?.groupCount)throw new Error(`invalid reference \\${u} in replacement`);return{...s,parts:o,...i}}function pk(e){let t={global:!1,print:!1,nth:null};for(;e.i<e.script.length;){let n=e.script[e.i];if(/[;\n#}]/u.test(n))break;if(e.i++,!/[ \t]/u.test(n)){if(n==="\r"&&e.script[e.i]===`
217
+ `)break;if(/\d/u.test(n)){if(t.nth!==null)throw new Error("multiple number options to substitute command");let r=/^\d*/u.exec(e.script.slice(e.i))[0];if(e.i+=r.length,t.nth=Number(n+r),t.nth===0)throw new Error("number option to substitute command may not be zero");Number.isSafeInteger(t.nth)||Ee("substitution occurrence limit")}else if(n==="g"||n==="p"){let r=n==="g"?"global":"print";if(t[r])throw new Error("multiple substitution flags");t[r]=!0}else if(n==="w"){Object.assign(t,iu(e));break}else if(n==="i"||n==="I")t.ignoreCase=!0;else if(n==="m"||n==="M")t.multiline=n;else if(n==="e")c1(n);else throw new Error(`unknown option to substitute command: '${n}'`)}}return t}function c1(e){let t=e==="e"?"command evaluation":"multiline regex matching";throw new b("feature",`substitution flag ${e}`,`sed: substitution flag '${e}' (${t}) is not supported`)}function iu(e){let t=/^[ \t]*([^\n]*)/u.exec(e.script.slice(e.i));e.i+=t[0].length;let n=t[1].split("\0",1)[0];if(n==="")throw new Error("missing filename in r/R/w/W commands");return e.openWrite?{writer:e.openWrite(n)}:{writeName:n}}function su(e,t,n=!1,r=!1,o=ee){if(!e){if(r)throw new Error("cannot specify modifiers on empty regexp");return{re:null}}let i=re(o);is(e,t,i.multibyte);let s=e.replace(/\\(.)/gu,(f,c)=>(c==="o"&&Ee("regex escape"),Object.hasOwn(_o,c)?_o[c]:f)),u=r?zn(s,i):s,a=t?{source:rs(u,i)}:oo(u,i);if(a.error)throw new Error(a.error);hk(a.source,t),io(a.source);for(let[,f]of a.source.matchAll(/\\(.)/gu))/[1-9]/u.test(f)&&Ee("regex backreferences");return{re:new ct(Hn(a.source,!0,i),!1,null,i),noSub:n,locale:o,ignoreCase:r,pattern:s}}function hk(e,t){let n=!1,r=0,o=!1,i=!1;for(let s=0;s<e.length;s++){let u=e[s];if(u==="\\"){let a=e[++s];n||(o=!"bB<>`'".includes(a),i=!1);continue}if(n){u==="]"&&(n=!1,o=!0,i=!1);continue}if(u==="["){n=!0;continue}if(u==="("){r++,o=!1,i=!1;continue}if(u===")"){if(--r<0)throw new Error("unmatched )")}else if(u==="|"||u==="^"||u==="$"){o=!1,i=!1;continue}else if("*+?{".includes(u)){let a=u==="{"?/^\{(?=\d|,)(\d*)(?:,(\d*))?\}/u.exec(e.slice(s)):null;if(u==="{"&&a===null)throw new Error("invalid repetition count");if(!o||!t&&i&&(u==="*"||u==="{"))throw new Error("Invalid preceding regular expression");a&&(s+=a[0].length-1),i=!0;continue}o=!0,i=!1}if(r>0)throw new Error("unmatched (")}function mk(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n];if(r==="&"){t.push(0);continue}if(r!=="\\"){t.push(r);continue}let o=e[++n];/[0-9]/u.test(o)?t.push(Number(o)):o==="\\"||o==="&"?t.push(o):Object.hasOwn(_o,o)?t.push(_o[o]):Ee("replacement escape")}return t}function uu(e,t){if(/[\u0080-\u{10FFFF}]/u.test(e+t.re.src)){if(t.locale!==ee)throw new b("feature","locale",`matching non-ASCII text in the ${t.locale} locale is not supported`);t.ignoreCase&&Tt.test(e+t.pattern)&&Ee("case folding of Cyrillic Extended-C letters")}}function au(e,t,n=null){let r=e.re===null?t.last:e;if(!r)throw new Error("no previous regular expression");if(t.last=r,n!==null&&r.noSub){if(n>r.re.groupCount)throw new Error(`invalid reference \\${n} in replacement`);r.noSub=!1}return r}function lu(e,t,n){let r=t.parts.reduce((l,f)=>typeof f=="number"?Math.max(l,f):l,0),o=au(t,n,r);uu(e,o);let i=t.parts.some(l=>typeof l=="number"&&l>0&&l<=o.re.groupCount),s=0,u=t.nth&&!t.global?{search:(l,f)=>s?null:o.re.search(l,f)}:o.re;return{out:qn(e,u,(l,f,c)=>{if(t.nth&&c<t.nth)return null;s++;let d=i?o.re.groups(e,l,f):null;return t.parts.map(p=>typeof p=="string"?p:p===0?e.slice(l,f):d?.[p]?.text??"").join("")},t.global||t.nth?"global":"first").out,count:s}}var d1={a:7,f:12,n:10,r:13,t:9,v:11,"\n":10},p1={d:10,o:8,x:16};function m1(e,t){for(;/[ \t]/u.test(e.script[e.i]??"");)e.i++;if(e.i===e.script.length)throw new Error("expected \\ after 'a', 'c' or 'i'");if(t.text=null,e.textState.pending={command:t,raw:""},e.script[e.i]==="\\"){let n=e.script[++e.i];if(n===void 0)return;e.i++,n!==`
218
+ `&&(e.textState.pending.raw=n)}cu(e)}function cu(e){let t=e.textState.pending;if(!t)return;let n=t.raw;for(;e.i<e.script.length&&e.script[e.i]!==`
201
219
  `;){let r=e.script[e.i++];if(r==="\\"){if(e.i===e.script.length){t.raw=n+`
202
- `;return}n+=r+e.script[e.i++]}else n+=r}t.command.text=kb(n+`
203
- `),e.textState.pending=null}function Is(e){e?.pending&&(e.pending.command.text=e.pending.raw||null,e.pending=null)}function kb(e){return M(Ns(e))}function Ns(e){let t=I(e),n=[];for(let r=0;r<t.length;r++){let i=t[r];if(i!==92||r+1===t.length){n.push(i);continue}let o=String.fromCodePoint(t[++r]);if(Object.hasOwn(Ld,o)){n.push(Ld[o]);continue}if(Object.hasOwn(Rd,o)){let s=Rd[o],u=s===16?2:3,a=0,l=0;for(;a<u&&r+1<t.length;){let c=t[r+1],f=c>=48&&c<=57?c-48:(c|32)>=97&&(c|32)<=102?(c|32)-87:-1;if(f<0||f>=s)break;l=l*s+f,a++,r++}n.push(a?l&255:o.codePointAt(0))}else if(o==="c"){if(++r===t.length)continue;let s=t[r];if(s===92&&t[++r]!==92)throw new Error("recursive escaping after \\c not allowed");n.push((s>=97&&s<=122?s-32:s)^64)}else n.push(o.codePointAt(0))}return Uint8Array.from(n)}function Dd(e){let t=Yn(e,"'y' command"),n=Ns(Md(e,t)),r=Ns(Md(e,t)),i=e.byteLocale?n:[...M(n)],o=e.byteLocale?r:[...M(r)];if(i.length!==o.length)throw new Error("'y' command strings have different lengths");let s=e.byteLocale?Uint8Array.from({length:256},(u,a)=>a):new Map;for(let u=0;u<i.length;u++)e.byteLocale?s[i[u]]=o[u]:s.has(i[u])||s.set(i[u],o[u]);return{translation:s,byteLocale:e.byteLocale}}function Md(e,t){let n="";for(;e.i<e.script.length;){let r=e.script[e.i++];if(r===`
204
- `)break;if(r===t)return n;if(r!=="\\"){n+=r;continue}let i=e.script[e.i++];if(i===void 0)break;n+=i===t||i===`
205
- `?i:r+i}throw new Error("unterminated 'y' command")}function Ud(e,t){if(t.byteLocale)return M(I(e).map(r=>t.translation[r]));let n="";for(let r of e)n+=t.translation.get(r)??r;return n}function Os(e,t=!1,n=Ve,r=null){let i={script:e,i:0,extended:t,locale:n,byteLocale:Mi(n),textState:r??{},openWrite:r?.openWrite},o=[];for(As(i);i.i<e.length;){if(/[;\n\r\f\v \t]/u.test(e[i.i])){i.i++;continue}e[i.i]==="#"&&ge("comments");let s=Bd(i),u=null;if(s&&e[i.i]===","&&(i.i++,u=Bd(i,!0),u===null))throw new Error("missing second address");e[i.i]==="~"&&ge("step address");let a=s?.type==="line"&&s.value===0;if(a&&u?.type!=="regex")throw new Error("line numbers must be >= 1");let l=!1;if(e[i.i]==="!"){for(l=!0,i.i++;/[ \t]/u.test(e[i.i]??"");)i.i++;if(e[i.i]==="!")throw new Error("multiple '!'s")}let c=e[i.i++],f={kind:c,start:s,end:u,active:a,negated:l};if(c&&"pPnNdD=gGhHx".includes(c))o.push(f);else if(c==="w"){o.push({...f,...vs(i)});continue}else if(c===":"||c==="b"||c==="t"||c==="T"){o.push({...f,label:Sb(i,f)});continue}else if(c==="s")o.push({...f,...Td(i)});else if(c==="a"||c==="i"||c==="c")Pd(i,f),o.push(f);else if(c==="y")o.push({...f,...Dd(i)});else if(c==="q"){if(u!==null)throw new Error("command only uses one address");let d=/^[ \t]*(\d*)/u.exec(e.slice(i.i));i.i+=d[0].length;let p=BigInt.asIntN(32,BigInt(d[1]||"0"));o.push({...f,exitCode:p===-1n?0:Number(BigInt.asUintN(8,p))})}else if(c==="{"){i.textState.blockDepth=(i.textState.blockDepth??0)+1,o.push(f);continue}else if(c==="}"){if(!i.textState.blockDepth)throw new Error("unexpected '}'");if(s!==null)throw new Error("'}' doesn't want any addresses");i.textState.blockDepth--,o.push(f)}else{if(c===void 0)throw new Error("missing command");if("QlLFzrRWev".includes(c))ge();else throw new Error(`unknown command: '${c}'`)}for(;/[ \t]/u.test(e[i.i]??"");)i.i++;if(e[i.i]==="#"&&ge("comments"),i.i<e.length&&!/[;\n}]/u.test(e[i.i]))throw new Error("extra characters after command")}return r===null&&Is(i.textState),o}function Cs(e,t){let n=[];for(let r=0;r<e.length;r++){let i=e[r];if(i.kind==="{"&&n.push(i),i.kind==="}"){if(n.length===0)throw new Error("unexpected '}'");n.pop().jump=r}}if(n.length)throw new Error("unmatched '{'");return Is(t),Eb(e),e}function Sb(e,t){if(t.kind===":"&&t.start!==null)throw new Error("':' doesn't want any addresses");let n=/^[ \t]*([^ \t\n;}#]*)/u.exec(e.script.slice(e.i));e.i+=n[0].length;let r=n[1].split("\0",1)[0];if(t.kind===":"&&r==="")throw new Error("':' lacks a label");return r}function Eb(e){let t=new Map;for(let n=0;n<e.length;n++)e[n].kind===":"&&t.set(e[n].label,n);for(let n=e.length-1;n>=0;n--){let r=e[n];if(!["b","t","T"].includes(r.kind))continue;let i=r.label===""?e.length:t.get(r.label);if(i===void 0)throw Object.assign(new Error(`can't find label for jump to \`${r.label}'`),{exitCode:4});r.jump=i}}function Bd(e,t=!1){for(;/[ \t]/u.test(e.script[e.i]??"");)e.i++;e.script[e.i]==="~"&&ge("step address");let n=/^(\d+|\+[ \t]*\d+)/u.exec(e.script.slice(e.i)),r=null;if(n){let i=n[0][0]==="+";if(i&&!t)throw new Error("relative address requires a range");let o=Number(n[0].replace(/[ \t]/gu,""));Number.isSafeInteger(o)||ge("address limit"),e.i+=n[0].length,r={type:i?"offset":"line",value:o}}else if(e.script[e.i]==="$")e.i++,r={type:"last"};else if(e.script[e.i]==="/"||e.script[e.i]==="\\"){e.script[e.i]==="\\"&&e.i++;let i=Yn(e,"address regex"),o=ai(e,i,!0,"address regex"),s=!1;for(;;){for(;/[ \t]/u.test(e.script[e.i]??"");)e.i++;let u=e.script[e.i];if(u!=="I"&&u!=="M")break;if(o==="")throw new Error("cannot specify modifiers on empty regexp");u==="M"&&ge("address regex flags"),s=!0,e.i++}r={type:"regex",...ks(o,e.extended,!0,s,e.locale)}}for(;/[ \t]/u.test(e.script[e.i]??"");)e.i++;return r}function Wd(e,t,n,r,i){let{start:o,end:s}=e;if(o===null)return!0;if(s===null)return li(o,t,n,r,i);if(!e.active){if(o.type==="line"){if(e.closed||n<o.value)return!1}else if(!li(o,t,n,r,i))return!1;if(e.active=!0,s.type==="regex")return!0;if(s.type==="offset"&&(e.until=n+s.value),s.type==="line")return e.active=n<s.value,e.closed=!e.active,n<=s.value||li(o,t,n,r,i)}return s.type==="line"?(e.active=n<s.value,e.closed=!e.active,n<=s.value):((s.type==="offset"?n>=e.until:li(s,t,n,r,i))&&(e.active=!1,e.closed=!0),!0)}function li(e,t,n,r,i){if(e.type==="line")return n===e.value;if(e.type==="last")return typeof r=="function"?r():r;let o=Es(e,i);return Ss(t,o),o.re.search(t)!==null}function Fs(e,t,n,r=!1){let{output:i,delimiter:o}=e,s=t.has("n")||t.has("quiet")||t.has("silent"),u=t.has("s")||t.has("separate"),a=Fd(e.files,e.stdin,n,o,u,p=>i.stream(2,p)),l=i.start(a),c=[],f=bs(r?p=>{i.account(p),c.push(p)}:p=>i.stream(1,p),o),d={delimiter:o,quiet:s,separate:u,hold:e.hold,regexState:e.regexState,budget:e.budget,emit:f,input:a,output:i};try{let p=$b(e.commands,d);l.quit=p!==null,l.exitCode=a.status.failed?a.status.directory?4:2:p??0,l.failed=a.status.failed}catch(p){let m=oi(p);_(l,m);let h=N(m);h&&Q(l,h.kind,h.command,h.detail,h.message),l.failed=!0}finally{i.finish()}return r&&(l.content=c.join("")),l}function $b(e,t){let n=!0;for(let r=t.input.next();r;r=t.input.next()){if(n||t.separate&&r.reset){t.hold.text="";for(let s of e)s.active=s.start?.type==="line"&&s.start.value===0,s.closed=!1;n=!1}t.output.record(r);let i={...r,...t,append:[],exitCode:null,replaced:!1},o=Nb(e,i);if(!t.quiet&&!o&&t.emit(i.text,i.terminator),i.exitCode!==null&&t.emit(""),zd(i),i.exitCode!==null)return i.exitCode;t.output.record(null)}return null}function Nb(e,t){for(let n=0;n<e.length;n++){if(++t.budget.steps>xs)throw new w("feature","execution limit",`sed: execution limit reached after ${xs} commands (infinite loop?)`);let r=e[n];if(r.kind==="}"||r.kind===":")continue;if(Wd(r,t.text,t.line,t.last,t.regexState)===!!r.negated){r.kind==="{"&&(n=r.jump);continue}let o=r.kind;if(o!=="{"){if(o==="b"||o==="t"||o==="T"){let s=o==="b"||(o==="t"?t.replaced:!t.replaced);o!=="b"&&(t.replaced=!1),s&&(n=r.jump-1);continue}if(o==="q"){t.exitCode=r.exitCode;break}if(o==="d")return!0;if(o==="D"){let s=t.text.indexOf(t.delimiter);if(s<0)return!0;t.text=t.text.slice(s+t.delimiter.length),n=-1;continue}if(o==="n"||o==="N"){if(!Ob(t,o==="N"))return!0;continue}if(o==="c")return!r.active&&r.text!==null&&t.emit(r.text.slice(0,-1),t.delimiter),!0;if(Ab(r,t),t.text.length>ii)throw new w("feature","pattern space limit","sed: pattern space limit exceeded")}}return!1}function Ab(e,t){let{kind:n}=e;if(n==="a"){t.append.push(e.text);return}if(n==="i")e.text!==null&&t.emit(e.text.slice(0,-1),t.delimiter);else if(n==="p")t.emit(t.text,t.terminator);else if(n==="P"){let r=t.text.indexOf(t.delimiter);t.emit(r<0?t.text:t.text.slice(0,r),r<0?t.terminator:t.delimiter)}else if(n==="=")t.emit(String(t.line),t.delimiter);else if(n==="w")e.writer(t.text,t.terminator);else if("gGhHx".includes(n))Ib(n,t);else if(n==="y")t.text=Ud(t.text,e);else{let r=$s(t.text,e,t.regexState);if(t.text=r.out,!r.count)return;t.replaced=!0,e.print&&t.emit(t.text,t.terminator),e.writer&&e.writer(t.text,t.terminator)}}function Ib(e,t){let n=t.hold;if(e==="x"){let{text:r,terminator:i}=t;Object.assign(t,n),Object.assign(n,{text:r,terminator:i})}else{let r=e==="h"||e==="H"?t:n,i=r===n?t:n;i.text=e==="G"||e==="H"?i.text+t.delimiter+r.text:r.text,i.terminator=r.terminator}if(n.text.length>ii)throw new w("feature","hold space limit","sed: hold space limit exceeded")}function Ob(e,t){if(!t&&!e.quiet&&e.emit(e.text,e.terminator),e.last())return t&&!e.quiet&&e.emit(e.text,e.terminator),!1;zd(e);let n=e.input.next();if(!n)return t&&!e.quiet&&e.emit(e.text,e.delimiter),!1;let r=t?e.text+e.delimiter+n.text:n.text;if(r.length>ii)throw new w("feature","pattern space limit","sed: pattern space limit exceeded");return Object.assign(e,n,{text:r,replaced:!1}),e.output.record(n),!0}function zd(e){if(e.append.length!==0){e.emit("");for(let t of e.append)e.emit(t??"");e.append.length=0}}function qd(e,t,n){try{let{tokens:r,inPlace:i}=Id(t),o=E(r,{short:["n","E","r","s","z"],long:["regexp-extended","quiet","silent","separate","null-data","zero-terminated"],repeatable:["e","expression","f","file"]}),s=o.flags.has("z")||o.flags.has("null-data")||o.flags.has("zero-terminated")?"\0":`
206
- `,u=Cd(n,s),a=Cb(o,e,n,u.openWrite);return a===null?y(ri):a.error?a.error:(Object.assign(a,{output:u,delimiter:s,hold:{text:"",terminator:s},regexState:{last:null},budget:{steps:0}}),a.stdin=Vn(a.stdin,n),i===null?Fs(a,o.flags,n):Od(a,o.flags,n,i,(l,c)=>Fs(l,c,n,!0)))}catch(r){return oi(r)}}function Cb({order:e,positional:t},n,r,i){let o=[],s={openWrite:i},u=!1,a=!1;for(let{name:l,value:c}of e){if((l==="E"||l==="r"||l==="regexp-extended")&&(u=!0),!["e","expression","f","file"].includes(l))continue;a=!0;let f=c;if(l==="f"||l==="file"){n=Vn(n,r);let d=n,p=r.io.bufferReads(()=>Ye("sed",[c],r,d));if(p.failed)return{error:y(p.stderr,4)};f=p.inputs[0].content,p.inputs[0].shared&&(n="")}for(let d of Os(f,u,r.locale,s))o.push(d)}return a?{commands:Cs(o,s),files:t,stdin:n}:t.length===0?null:{commands:Cs(Os(t[0],u,r.locale,s),s),files:t.slice(1),stdin:n}}var Fb=new Set(["-b","-c","-g","-h","-k","-p","-r","-s","-t","-u","-v","-w","-x","-G","-L","-N","-O","-R","-S","-o"]),Tb=new Set(["-nt","-ot","-ef","<",">"]),Jn={__proto__:null,"-eq":(e,t)=>e===t,"-ne":(e,t)=>e!==t,"-lt":(e,t)=>e<t,"-le":(e,t)=>e<=t,"-gt":(e,t)=>e>t,"-ge":(e,t)=>e>=t},_b=String(J).length,Lb=new Set(["/dev/stdin","/dev/stdout","/dev/stderr"]);function Gd(e,t,n){return Zd("test",t,n)}function Xd(e,t,n){return t.at(-1)!=="]"?y("[: missing `]'",2):Zd("[",t.slice(0,-1),n)}function Zd(e,t,n){try{return{...C(),exitCode:Ts(t,n)?0:1}}catch(r){return K(r,e,`${e}: ${r.message}`,2)}}function Ts(e,t){let[n,r,i]=e;if(e.length===0)return!1;if(e.length===1)return n!=="";if(e.length===2){if(n==="!")return r==="";if(n==="-n")return r!=="";if(n==="-z")return r==="";if(["-a","-e","-f","-d"].includes(n))return _s(n,r,t);throw Fb.has(n)&&Kn(n),new Error(`${n}: unary operator expected`)}if(e.length===3){if(r==="="||r==="==")return n===i;if(r==="!=")return n!==i;if(Object.hasOwn(Jn,r))return Jn[r](jd(n),jd(i));Tb.has(r)&&Kn(r),(r==="-a"||r==="-o")&&Kn("compound expressions")}if(e.length<=4){if(n==="!")return!Ts(e.slice(1),t);if(n==="("&&e.at(-1)===")")return Ts(e.slice(1,-1),t)}throw e.some(o=>["-a","-o","!","(",")"].includes(o))&&Kn("compound expressions"),new Error(e.length>3?"too many arguments":`${r}: binary operator expected`)}function jd(e){let t=/^[ \t\n\r\f\v]*([+-]?)(\d+)[ \t]*$/u.exec(e);if(t&&t[0].length===e.length){let n=t[2].replace(/^0+/u,"")||"0";if(n.length<=_b){let r=BigInt(t[1]+n);if(r>=Xe&&r<=J)return r}}throw new Error(`${e}: integer expression expected`)}function _s(e,t,n){let r={isDir:s=>s==="/dev"||s==="/dev/fd"||n.fs.isDir(s),isFile:s=>s==="/dev/null"||Hd(s)||n.fs.isFile(s)},{path:i,error:o}=$(n.cwd,t,r);return o?!1:(Hd(i)&&Kn("stream device metadata"),e==="-e"||e==="-a"?!0:e==="-d"?r.isDir(i):i!=="/dev/null"&&n.fs.isFile(i))}function Hd(e){return Lb.has(e)||/^\/dev\/fd\/\d+$/u.test(e)}function Kn(e){throw new w("feature",e,`${e} is not supported`)}function Yd(e){let t=e.replace(/^[ \t\n\r\v\f]+|[ \t\n\r\v\f]+$/gu,""),n=/^[+-]?\d+$/u.test(t)?BigInt(t):null,r=n!==null&&n>=Xe&&n<=J?n:null;return{arg:t,n:r}}var on=e=>({...e,halt:!0});function Rb(e,t,n){let r=t[0]==="--"?t.slice(1):t;if(r.length===0)return on({...C(),exitCode:n.lastExit});let{arg:i,n:o}=Yd(r[0]);return o===null?on(y(`exit: ${i}: numeric argument required`,2)):r.length>1?on(y("exit: too many arguments")):on({...C(),exitCode:Number((o%256n+256n)%256n)})}function Vd(e){return(t,n,r)=>{let i=n[0]==="--"?n.slice(1):n;if(i.length>1)return on(y(`${e}: too many arguments`));let{arg:o,n:s}=Yd(i[0]??"1");return s===null?on(y(`${e}: ${o}: numeric argument required`,128)):s<=0?{...y(`${e}: ${o}: loop count out of range`),control:r.loopDepth?{type:"break",levels:r.loopDepth}:void 0}:r.loopDepth===0?y(`${e}: only meaningful in a \`for\`, \`while\` or \`until\` loop`,0):{...C(),control:{type:e,levels:Number(s>BigInt(r.loopDepth)?BigInt(r.loopDepth):s)}}}}function Mb(e,t,n){let r=t[0]==="--",i=r?t.slice(1):t;if(i.length===0||!r&&i[0]==="-p")return v("option","export","-p","export: listing the environment is not supported (there is none)");let o="";for(let s of i){let u=s.indexOf("="),a=u>0&&s[u-1]==="+",l=u===-1?s:s.slice(0,a?u-1:u);if(!r&&s.startsWith("-"))return v("option","export",s,`export: option \`${s}\` is not supported`);if(!$t.test(l)){o+=`export: \`${l}': not a valid identifier
207
- `;continue}u!==-1?n.vars.set(l,(a?Lc(l,n):"")+s.slice(u+1)):n.vars.has(l)&&n.vars.set(l,n.vars.get(l))}return{stdout:"",stderr:o,exitCode:o?1:0}}function Pb(e,t,n){let r=t[0]==="-v"?1:0,i=t[r]==="--";i&&r++;let o=t.slice(r);for(let s of o){if(!i&&s.startsWith("-"))return v("option","unset",s,`unset: option \`${s}\` is not supported`);if(s.includes("["))return v("feature","unset","array subscript","unset: array subscripts are not supported");if(s==="LANG")return v("feature","unset","LANG",`unset: LANG: ${hr}`);n.vars.delete(s)}return C()}var Ls={exit:Rb,break:Vd("break"),continue:Vd("continue"),export:Mb,unset:Pb},Kd=new Map([["return"," (there are no shell functions)"],["source"," (nothing can be sourced into this shell)"],[".","","`.` (source)"],"eval","exec",["read"," (there is no interactive input)"],["shift"," (there are no positional parameters)"],"set","shopt",["local"," (there are no shell functions)"],["declare","; use `NAME=value`"],["typeset","; use `NAME=value`"],["readonly","; use `NAME=value`"],["let"," (no arithmetic)"],["type","; use `which`"],["command","; run the command directly"],"builtin","hash","alias","unalias","trap",["wait"," (nothing runs in the background)"],["kill"," (there are no processes)"],["jobs"," (there are no processes)"],["bg"," (there are no processes)"],["fg"," (there are no processes)"],["disown"," (there are no processes)"],"suspend","times","ulimit","umask",["pushd","; use `cd`"],["popd","; use `cd -`"],"dirs","history","help","logout","getopts","mapfile","readarray","caller","enable","compgen","complete","bind","fc"].map(e=>{let[t,n="",r="`"+t+"`"]=Array.isArray(e)?e:[e];return[t,r+" is not supported"+n]}));function Jd(e,t){let n=0,r=!0,i=!1;for(;n<t.length&&/^-[neE]+$/u.test(t[n]);n++)for(let s of t[n].slice(1))s==="n"?r=!1:i=s==="e";let o=t.slice(n).join(" ");if(i){let s=Db(o);o=s.text,s.stop&&(r=!1)}return C(r?o+`
208
- `:o)}function Db(e){let t={a:7,b:8,e:27,E:27,f:12,n:10,r:13,t:9,v:11,"\\":92},n=[],r=o=>{for(let s of I(o))n.push(s)},i=o=>({text:M(Uint8Array.from(n)),stop:o});for(let o=0;o<e.length;o++){if(e[o]!=="\\"||o+1>=e.length){let l=e.indexOf("\\",o+1),c=l<0?e.length:l;r(e.slice(o,c)),o=c-1;continue}let s=e[++o];if(s==="c")return i(!0);if(s in t){n.push(t[s]);continue}if(s==="0"){let l="";for(;l.length<3&&/[0-7]/u.test(e[o+1]??"");)l+=e[++o];n.push(l===""?0:parseInt(l,8)&255);continue}let u=s==="x"?2:s==="u"?4:s==="U"?8:0;if(u>0&&/[0-9a-fA-F]/u.test(e[o+1]??"")){let l="";for(;l.length<u&&/[0-9a-fA-F]/u.test(e[o+1]??"");)l+=e[++o];let c=parseInt(l,16);if(s==="x")n.push(c);else{if(!ze(c))throw new w("feature","echo Unicode escape","echo: escapes outside Unicode scalar values are not supported");r(String.fromCodePoint(c))}continue}let a=o+ke(e,o);r("\\"+e.slice(o,a)),o=a-1}return i(!1)}var Qd={a:7,b:8,e:27,E:27,f:12,n:10,r:13,t:9,v:11,"\\":92};function Rs(e,t,n,r){let i=e[t+1],o=t+2;if(i===void 0)return{bytes:[92],end:t+1};if(n&&i==="c")return{bytes:[],end:o,stop:!0};if(Object.hasOwn(Qd,i))return{bytes:[Qd[i]],end:o};if(!n&&`'"?`.includes(i))return{bytes:[i.codePointAt(0)],end:o};if(/[0-7]/u.test(i)){let u=n&&i==="0"?4:3;for(;o<t+1+u&&/[0-7]/u.test(e[o]??"");)o++;return{bytes:[parseInt(e.slice(t+1,o),8)&255],end:o}}let s=i==="x"?2:i==="u"?4:i==="U"?8:0;if(s){for(;o<t+2+s&&/[\da-fA-F]/u.test(e[o]??"");)o++;if(o===t+2||i!=="x"&&o!==t+2+s)return r.stderr+=`printf: missing hexadecimal number in escape
209
- `,r.failed=!0,r.stop=!0,{bytes:[],end:e.length,stop:!0};let u=parseInt(e.slice(t+2,o),16);if(i==="x")return{bytes:[u],end:o};if(!ze(u))throw new w("feature","Unicode escape","escapes outside Unicode scalar values are not supported");if(r.byteLocale&&u>127)throw new w("feature","Unicode escape in C locale","non-ASCII Unicode escapes in the C locale are not supported");return{bytes:I(String.fromCodePoint(u)),end:o}}return o=t+1+ke(e,t+1),{bytes:I(e.slice(t,o)),end:o}}function ep(e,t){let n=[];for(let r=0;r<e.length;)if(e[r]==="\\"){let i=Rs(e,r,!0,t);for(let o of i.bytes)n.push(o);if(r=i.end,i.stop){t.stop=!0;break}}else{let i=e.indexOf("\\",r),o=i<0?e.length:i;for(let s of I(e.slice(r,o)))n.push(s);r=o}return Uint8Array.from(n)}var Bb=/^%([-+ #0']*)(\d+|\*)?(?:\.(-?\d+|\*)?)?([hlLjzt]*)(.)?/su,Wb=8e6;function tp(e,t,n){let r=t[0]==="--"?t.slice(1):t;if(r.length===0)return oe("printf format [arguments]");if(t[0]!=="--"&&/^-./su.test(t[0])){let s=t[0].startsWith("-v")?"-v":t[0];return v("option","printf",s,`printf: option ${s} is not supported`,2)}let i={args:r.slice(1),index:0,chunks:[],size:0,stderr:"",failed:!1,stop:!1,byteLocale:le(n)},o;try{if(r.some(s=>s.includes("\0")))throw new w("feature","NUL in argument","NUL bytes in command arguments are not supported");do{let s=i.index;if(qb(r[0],i),i.index===s)break}while(!i.stop&&i.index<i.args.length);o=C()}catch(s){o=K(s,"printf",`printf: ${s.message}`)}try{o.stdout=zb(i)}catch(s){let u=N(o);u&&n.unsupported.add(u,"printf");let a=K(s,"printf",`printf: ${s.message}`);a.stderr=o.stderr+a.stderr,o=a}return o.stderr=i.stderr+o.stderr,i.failed&&o.exitCode===0&&(o.exitCode=1),o}function Lt(e,t){if(e.size+t.length>Wb)throw new w("feature","format size limit","formatted output exceeds the output limit");t.length&&e.chunks.push(t),e.size+=t.length}function zb(e){let t=new Uint8Array(e.size),n=0;for(let r of e.chunks)t.set(r,n),n+=r.length;return M(t)}var Ms=e=>e.args[e.index++];function qb(e,t){for(let n=0;n<e.length&&!t.stop;)if(e[n]==="\\"){let r=Rs(e,n,!1,t);Lt(t,r.bytes),n=r.end}else if(e[n]==="%"){if(e[n+1]==="%"){Lt(t,[37]),n+=2;continue}let r=jb(e.slice(n),t);n+=r.length;let i=Ms(t);if("sbc".includes(r.conv))Hb(i??"",r,t);else{let o="diouxX".includes(r.conv)?Hr(jr(i,"ouxX".includes(r.conv),t),r):lf(i,r,t);Lt(t,I(o))}}else{let r=n+1;for(;r<e.length&&e[r]!=="%"&&e[r]!=="\\";)r++;Lt(t,I(e.slice(n,r))),n=r}}function jb(e,t){if(/^%[-+ #0'\d.*]*\$/u.test(e))throw new w("feature","positional format arguments","positional format arguments are not supported");let n=Bb.exec(e),[,r,i,o,s,u]=n;if(u===void 0)throw new Error("missing format character");if(!"sbcdiouxXeEfFgG".includes(u))throw"aAqQnCS(p%I".includes(u)?new w("feature","%"+u,`format %${u} is not supported`):new Error(`invalid format character: ${u}`);if(s&&"sbc".includes(u))throw new w("feature","format length modifier","length modifiers on string and character formats are not supported");let a={conv:u,length:n[0].length,minus:r.includes("-"),plus:r.includes("+"),space:r.includes(" "),zero:r.includes("0"),alt:r.includes("#"),width:Number(i==="*"?jr(Ms(t),!1,t):i??0),precision:o==="*"?Number(jr(Ms(t),!1,t)):o===void 0?n[0].includes(".")?0:null:Number(o)};if(i==="*"&&Math.abs(a.width)>2147483647||o==="*"&&(a.precision<-2147483648||a.precision>2147483647))throw new w("feature","format size limit","star width or precision outside the signed 32-bit range is not supported");if(a.width<0&&(a.minus=!0,a.width=-a.width),a.precision<0&&(a.precision=null),a.width>ye||a.precision>ye)throw new w("feature","format size limit","format width or precision exceeds the output limit");return a}function Hb(e,t,n){let r=t.conv==="b"?ep(e,n):I(e);t.conv==="c"?r=r.length?r.subarray(0,1):new Uint8Array(1):t.precision!==null&&(r=r.subarray(0,t.precision));let i=Math.max(0,t.width-r.length),o=i?new Uint8Array(i).fill(32):[];t.minus||Lt(n,o),Lt(n,r),t.minus&&Lt(n,o)}function Gb(e,t){if(!e.includes(`
210
- `))return e;let n=le(t);if(!n&&/[\u0080-\u009F\u2028\u2029]/u.test(e))throw new w("feature","filename quoting","wc: locale-sensitive filename quoting is not supported");let r=n?Array.from(I(e),u=>String.fromCodePoint(u)):[...e],i={7:"\\a",8:"\\b",9:"\\t",10:"\\n",11:"\\v",12:"\\f",13:"\\r"},o=!1,s="'";for(let u of r){let a=u.codePointAt(0);a<32||a===127||n&&a>127?(o||(s+="'$'"),s+=i[a]??"\\"+a.toString(8).padStart(3,"0"),o=!0):(u==="'"?s+="'\\''":s+=(o?"''":"")+u,o=!1)}return s+"'"}function np(e,t,n,r,i){let o=[];for(let s of["l","w","m","c"])n[s]&&o.push(String(e[s]).padStart(r));return o.join(" ")+(t?" "+Gb(t,i):"")}var Xb=["**=","**","++","--","+=","-=","*=","/=","%=","^=","==","!=","<=",">=","&&","||","!~",">>","|&","+","-","*","/","%","^","!",">","<","|","?",":","~","$","=","(",")","{","}","[","]",";",","],Zb=new Set(["number","string","name","builtin"]),Vb=new Set([")","]","++","--"]),Yb=/^(?:0[xX][0-9a-fA-F]+|\d+\.?\d*(?:[eE][+-]?\d+)?|\.\d+(?:[eE][+-]?\d+)?)/u,Kb=e=>e!==void 0&&/[A-Za-z_]/u.test(e),Jb=e=>e!==void 0&&/[A-Za-z0-9_]/u.test(e),rp=e=>e!==void 0&&e>="0"&&e<="9";function sp(e,t=null){let n=[],r=1,i=0,o=(u,a)=>n.push({type:u,value:a,line:r}),s=()=>{let u=n.at(-1);return u?Zb.has(u.type)?!1:!(u.type==="punct"&&Vb.has(u.value)):!0};for(;i<e.length;){let u=e[i];if(u===`
211
- `){n.at(-1)?.type!=="newline"&&o("newline",`
212
- `),r++,i++;continue}if(u===" "||u===" "||u==="\r"){i++;continue}if(u==="\\"&&(e[i+1]===`
213
- `||e[i+1]==="\r"&&e[i+2]===`
214
- `)){i+=e[i+1]===`
215
- `?2:3,r++;continue}if(u==="#"){for(;i<e.length&&e[i]!==`
216
- `;)i++;continue}if(u==='"'){let c=up(e,i+1,t,r);o("string",c.value),i=c.end;continue}if(u==="/"&&s()){let c=t1(e,i+1,r);o("regex",c.value),i=c.end;continue}if(rp(u)||u==="."&&rp(e[i+1])){let c=Qb(e,i);o("number",c.value),i=c.end;continue}if(Kb(u)){let c=i+1;for(;Jb(e[c]);)c++;let f=e.slice(i,c);if(e.slice(c,c+2)==="::")throw new k("namespaces are not supported",r,"namespaces");i=c,fl.has(f)?o("keyword",f==="func"?"function":f):dl.has(f)?o("builtin",f):o(e[c]==="("?"funcname":"name",f);continue}let a=i,l=Xb.find(c=>e.startsWith(c,a));if(u==="@")throw new k("typed regexes, indirect calls and source directives are not supported",r,"@ extensions");if(!l)throw new k(`unexpected character \`${u}\``,r);o("punct",l),i+=l.length}return o("eof",""),n}function Qb(e,t){let n=Yb.exec(e.slice(t))[0],r=n;return/^0[xX]/u.test(n)?r=String(Number.parseInt(n.slice(2),16)):/^0[0-7]+$/u.test(n)&&(r=String(Number.parseInt(n,8))),{value:r,end:t+n.length}}var ip={__proto__:null,n:`
217
- `,t:" ",r:"\r",a:"\x07",b:"\b",f:"\f",v:"\v",'"':'"',"\\":"\\"};function e1(e,t,n){let r=e[t+1];if(r===void 0)return{text:"\\",end:t+1};if(r in ip)return{text:ip[r],end:t+2};if(r>="0"&&r<="7"){let i=t+1;for(;i<t+4&&e[i]>="0"&&e[i]<="7";)i++;return{byte:Number.parseInt(e.slice(t+1,i),8)&255,end:i}}if(r==="x"&&/[0-9a-fA-F]/u.test(e[t+2]??"")){let i=t+2;for(;i<t+4&&/[0-9a-fA-F]/u.test(e[i]??"");)i++;return{byte:Number.parseInt(e.slice(t+2,i),16),end:i}}if(r.codePointAt(0)>127)throw new k("non-ASCII characters after an escape are not supported",null,"non-ASCII string escape");return n?.(`escape sequence \`\\${r}' treated as plain \`${r}'`),{text:r,end:t+2}}function up(e,t,n,r=null){let i=[],o=t;for(;o<e.length;){let s=e[o];if(r!==null){if(s==='"')return{value:M(Uint8Array.from(i)),end:o+1};if(s===`
218
- `)break;if(s==="\\"&&e[o+1]===`
219
- `){o+=2;continue}}if(s==="\\"){let u=e1(e,o,n);op(i,u),o=u.end}else{let u=String.fromCodePoint(e.codePointAt(o));op(i,{text:u}),o+=u.length}}if(r!==null)throw new k("unterminated string",r);return{value:M(Uint8Array.from(i)),end:o}}function t1(e,t,n){let r=t,i=!1;for(;r<e.length;){let o=e[r];if(o===`
220
- `)break;if(o==="\\"){r+=2;continue}if(i){if(o==="["&&e[r+1]===":"){let s=e.indexOf(":]",r+2);if(s!==-1){r=s+2;continue}}o==="]"&&(i=!1),r++;continue}if(o==="["){i=!0,r++,e[r]==="^"&&r++,e[r]==="]"&&r++;continue}if(o==="/")return{value:e.slice(t,r),end:r+1};r++}throw new k("unterminated regexp",n)}function Qn(e,t=null){return up(e,0,t).value}function op(e,t){if(t.byte===void 0)for(let n of I(t.text))e.push(n);else e.push(t.byte)}var n1=new Set(["=","+=","-=","*=","/=","%=","^=","**="]),ap=new Set(["<","<=","==","!=",">",">="]),tr=e=>e.type==="var"||e.type==="index"||e.type==="field";function lp(e){let t=e.tok;return fp(e)||t.type==="regex"||t.type==="keyword"&&t.value==="getline"||t.type==="punct"&&["!","-","+"].includes(t.value)}function sn(e,t){let n=[we(e,t)];for(;e.accept(",");)e.skipNewlines(),n.push(we(e,t));return n}function we(e,t){let n=r1(e,t),r=e.tok;if(r.type==="punct"&&n1.has(r.value)){tr(n)||e.fail(`cannot assign to ${n.type==="regex"?"a regex":"a non-variable"} (left side of \`${r.value}\`)`),e.next();let i=we(e,t);return{type:"assign",op:r.value==="**="?"^=":r.value,target:n,value:i}}return n}function r1(e,t){let n=Ps(e,t);if(!e.accept("?"))return n;e.skipNewlines();let r=we(e,t);return e.skipNewlines(),e.expect(":"),e.skipNewlines(),{type:"cond",test:n,consequent:r,alternate:we(e,t)}}var i1=[["or",["||"]],["and",["&&"]],["in",["in"]],["match",["~","!~"]],["compare",[...ap]],["concat",[]],["binary",["+","-"]],["binary",["*","/","%"]]],o1=new Map(i1.flatMap(([e,t],n)=>t.map(r=>[r,{type:e,precedence:n}]))),s1={type:"concat",precedence:5};function Ps(e,t,n=0){let r=ci(e,t),i=1/0;for(;;){let o=e.tok;n<=4&&i>4&&!t.noGt&&(e.is("|")||e.is("|&"))&&e.fail(`command pipelines (\`"cmd" | getline\`) are not supported: ${Ar}`,'"cmd" | getline');let s=fp(e)?s1:o.type==="punct"||o.type==="keyword"&&o.value==="in"?o1.get(o.value):void 0;if(!s||s.precedence<n||s.precedence>i||t.noGt&&e.is(">"))return r;let{type:u,precedence:a}=s,l=u==="concat"?null:e.next().value;if(i=a,(u==="or"||u==="and")&&e.skipNewlines(),u==="in"){r={type:u,keys:[r],array:cp(e)};continue}let c=Ps(e,t,a+1);(l==="/"||l==="%")&&er(c)===0&&er(r)!==null&&e.fail(l==="/"?"division by zero attempted":"division by zero attempted in `%`"),u==="compare"&&u1(e,t)&&e.fail(`comparison operators do not chain (\`a ${l} b ${e.tok.value} c\`); parenthesize the first comparison`),u==="binary"||u==="compare"?r={type:u,op:l,left:r,right:c}:u==="match"?r={type:u,negate:l==="!~",left:r,right:c}:r={type:u,left:r,right:c}}}function cp(e){return e.tok.type!=="name"&&e.fail(`expected an array name after \`in\` but found \`${e.tok.value}\``),e.next().value}var u1=(e,t)=>e.tok.type==="punct"&&ap.has(e.tok.value)&&!(t.noGt&&e.tok.value===">");function fp(e){let t=e.tok;return t.type==="number"||t.type==="string"||t.type==="name"||t.type==="funcname"||t.type==="builtin"?!0:t.type==="punct"&&["$","(","++","--"].includes(t.value)}function dp(e,t){return Ps(e,t,5)}function er(e){if(e.type==="num")return e.value;if(e.type==="neg"||e.type==="plus"){let r=er(e.expr);return r===null?null:e.type==="neg"?-r:r}if(e.type!=="binary")return null;let t=er(e.left),n=er(e.right);return t===null||n===null?null:Ir(e.op,t,n)}var a1={__proto__:null,"!":"not","-":"neg","+":"plus"};function ci(e,t,n=!1){if(n&&(e.is("$")||e.is("++")||e.is("--")))return fi(e,t);let r=e.tok.type==="punct"&&a1[e.tok.value];return r?(e.next(),{type:r,expr:ci(e,t,n)}):n?hp(e,t):l1(e,t)}function l1(e,t){let n=pp(e,t);return!e.is("^")&&!e.is("**")?n:(e.next(),{type:"binary",op:"^",left:n,right:ci(e,t)})}function pp(e,t){let n=fi(e,t);for(;(e.is("++")||e.is("--"))&&tr(n);)n={type:"postinc",op:e.next().value,target:n};return n}function fi(e,t){if(e.accept("$"))return{type:"field",index:ci(e,t,!0)};if(e.is("++")||e.is("--")){let n=e.next().value,r=fi(e,t);return tr(r)||e.fail(`\`${n}\` needs a variable, field or array element`),{type:"preinc",op:n,target:r}}return hp(e,t)}function hp(e,t){let n=e.tok;switch(n.type){case"number":return e.next(),{type:"num",value:Number(n.value)};case"string":return e.next(),{type:"str",value:n.value};case"regex":return e.next(),{type:"regex",source:n.value,re:c1(e,n.value)};case"name":return f1(e);case"funcname":return d1(e);case"builtin":return h1(e);case"keyword":return n.value==="getline"?m1(e,t):e.unexpected();case"punct":return n.value==="("?p1(e):e.unexpected();default:return e.unexpected()}}function c1(e,t){try{return Ee(t,!1,n=>e.warn(n))}catch(n){return e.fail(n.message,n.gap??null)}}function Ds(e){if(!e.accept("["))return null;let t=sn(e,{});return e.expect("]"),e.is("[")&&e.fail("arrays of arrays are not supported","arrays of arrays"),t}function f1(e){let t=e.next().value,n=Ds(e);return n!==null?{type:"index",name:t,subs:n}:(e.is("(")&&e.funcs.has(t)&&e.fail(`function \`${t}\` called with space between name and \`(\``),{type:"var",name:t})}function d1(e){return{type:"call",name:e.next().value,args:mp(e)}}function mp(e){e.expect("(");let t=e.is(")")?[]:sn(e,{});return e.expect(")"),t}function p1(e){let t=0;for(;e.parens.get(e.i+1)===e.parens.get(e.i)-1;)e.next(),t++;e.next();let n=sn(e,{});if(e.expect(")"),n.length===1){for(;t-- >0;)e.expect(")");return n[0]}return e.isKw("in")||e.fail("a parenthesized list must be followed by `in ARRAY`"),e.next(),{type:"in",keys:n,array:cp(e)}}function h1(e){let t=e.next().value;if(Nr.has(t)&&e.fail(Nr.get(t),`${t}()`),!e.is("(")){if(t==="length")return{type:"builtin",name:t,args:[]};e.fail(`\`${t}\` needs parentheses: ${t}(...)`)}let n=mp(e),[r,i]=go[t];return(n.length<r||n.length>i)&&e.fail(`${t}() called with ${n.length} argument${n.length===1?"":"s"}; it takes ${r===i?r:`${r} to ${i===1/0?"any number":i}`}`),(t==="sub"||t==="gsub")&&n[2]&&!tr(n[2])&&e.fail(`${t}(): substitution into a temporary value is not supported`,"substitution into temporary value"),t==="split"&&n[1].type!=="var"&&e.fail("split(): second argument must be an array name"),t==="match"&&n[2]&&n[2].type!=="var"&&e.fail("match(): third argument must be an array name"),{type:"builtin",name:t,args:n}}function m1(e,t){e.next();let n=null;(e.tok.type==="name"||e.is("$"))&&(n=fi(e,t),tr(n)||e.fail("getline: target must be a variable, field or array element"));let r=null;return e.accept("<")&&(r=pp(e,t)),{type:"getline",target:n,file:r}}var g1=new Set(["/dev/stdout","/dev/stderr","/dev/null"]),Us=class{constructor(t,n){this.toks=t,this.i=0,this.warnings=n,this.funcs=new Set,this.parens=new Map;let r=[];for(let i=0;i+1<t.length;i++){let o=t[i],s=t[i+1];o.type==="punct"&&(o.value==="("?r.push(i):o.value===")"&&r.length>0&&this.parens.set(r.pop(),i)),o.type==="keyword"&&o.value==="function"&&(s.type==="name"||s.type==="funcname")&&this.funcs.add(s.value)}this.loopDepth=0,this.switchDepth=0,this.context="main"}get tok(){return this.toks[this.i]}peek(t){return this.toks[Math.min(this.i+t,this.toks.length-1)]}is(t,n="punct"){return this.tok.type===n&&this.tok.value===t}isKw(t){return this.is(t,"keyword")}next(){return this.toks[this.i++]}accept(t,n="punct"){return this.is(t,n)?this.next():null}expect(t,n="punct"){return this.is(t,n)||this.fail(`expected \`${t}\` but found ${Rt(this.tok)}`),this.next()}skipNewlines(){for(;this.tok.type==="newline";)this.i++}skipTerminators(){for(;this.tok.type==="newline"||this.is(";");)this.i++}fail(t,n=null){throw new k(t,this.tok.line,n)}warn(t){this.warnings.push(t)}unexpected(){this.fail(`unexpected ${Rt(this.tok)}`)}};function Rt(e){return e.type==="eof"?"end of program":e.type==="newline"?"newline":e.type==="string"?`string "${e.value}"`:e.type==="regex"?`regex /${e.value}/`:`\`${e.value}\``}var gp={__proto__:null,BEGIN:"begin",END:"end",BEGINFILE:"beginFile",ENDFILE:"endFile"};function yp(e){let t=[],n=new Us(sp(e,i=>t.push(i)),t),r={begin:[],end:[],beginFile:[],endFile:[],rules:[],functions:new Map,warnings:t};for(n.skipNewlines();n.tok.type!=="eof";)n.is(";")&&n.fail("each rule must have a pattern or an action part"),w1(n,r),n.accept(";"),n.skipNewlines();return r}function w1(e,t){if(e.isKw("function")){x1(e,t);return}if(e.tok.type==="keyword"&&e.tok.value in gp){let o=e.next().value;e.is("{")||e.fail(`${o} requires an action: ${o} { ... }`),t[gp[o]].push(...nr(e,o.toLowerCase()));return}if(e.is("{")){t.rules.push({pattern:null,action:nr(e,"main")});return}let n=we(e,{}),r=n;e.accept(",")&&(e.skipNewlines(),r={type:"range",from:n,to:we(e,{})});let i=e.is("{")?nr(e,"main"):null;i===null&&!(e.tok.type==="newline"||e.tok.type==="eof"||e.is(";"))&&e.unexpected(),t.rules.push({pattern:r,action:i})}function x1(e,t){e.next();let n=e.tok;n.type==="builtin"&&e.fail(`cannot redefine builtin function \`${n.value}\``),n.type!=="name"&&n.type!=="funcname"&&e.fail(`expected a function name but found ${Rt(n)}`),e.next();let r=n.value;t.functions.has(r)&&e.fail(`function \`${r}\` is defined twice`),e.expect("(");let i=[];for(;!e.is(")");){let o=e.tok;if(o.type!=="name"&&e.fail(`expected a parameter name but found ${Rt(o)}`),(o.value===r||i.includes(o.value))&&e.fail(`duplicate parameter \`${o.value}\` in function \`${r}\``),i.push(e.next().value),!e.accept(","))break;e.skipNewlines()}e.expect(")"),e.skipNewlines(),t.functions.set(r,{params:i,body:nr(e,"function")})}function nr(e,t=e.context){let n=e.context;e.context=t,e.expect("{");let r=[];for(e.skipTerminators();!e.is("}");)e.tok.type==="eof"&&e.fail("missing `}` at end of program"),r.push(Bs(e)),e.skipTerminators();return e.next(),e.context=n,r}function rr(e){if(e.is(";")||e.tok.type==="newline"){e.next();return}e.is("}")||e.tok.type==="eof"||e.unexpected()}var y1={__proto__:null,if:b1,while:v1,do:k1,for:S1,switch:E1,break:e=>un(e,"break"),continue:e=>un(e,"continue"),next:e=>un(e,"next"),nextfile:e=>un(e,"nextfile"),exit:e=>un(e,"exit"),return:e=>un(e,"return"),delete:N1,print:e=>xp(e,"print"),printf:e=>xp(e,"printf")};function Bs(e){if(e.is("{"))return{type:"block",body:nr(e)};if(e.is(";"))return e.next(),{type:"empty"};let t=e.tok.type==="keyword"?y1[e.tok.value]:void 0;if(t)return t(e);let n=we(e,{});return rr(e),{type:"expr",expr:n}}function an(e,t){e.skipNewlines(),t&&e.loopDepth++;let n=Bs(e);return t&&e.loopDepth--,n}function di(e){e.next(),e.expect("(");let t=we(e,{});return e.expect(")"),t}function b1(e){let t=di(e),n=an(e,!1),r=e.i;return e.skipNewlines(),e.isKw("else")?(e.next(),{type:"if",test:t,consequent:n,alternate:an(e,!1)}):(e.i=r,{type:"if",test:t,consequent:n,alternate:null})}function v1(e){return{type:"while",test:di(e),body:an(e,!0)}}function k1(e){e.next();let t=an(e,!0);e.skipTerminators(),e.isKw("while")||e.fail("`do` body must be followed by `while (...)`");let n=di(e);return rr(e),{type:"do",body:t,test:n}}function S1(e){if(e.next(),e.expect("("),e.tok.type==="name"&&e.peek(1).type==="keyword"&&e.peek(1).value==="in"&&e.peek(2).type==="name"&&e.peek(3).value===")"){let i=e.next().value;e.next();let o=e.next().value;return e.next(),{type:"forin",name:i,array:o,body:an(e,!0)}}let t=e.is(";")?null:we(e,{});e.expect(";"),e.skipNewlines();let n=e.is(";")?null:we(e,{});e.expect(";"),e.skipNewlines();let r=e.is(")")?null:we(e,{});return e.expect(")"),{type:"for",init:t,test:n,step:r,body:an(e,!0)}}function E1(e){let t=di(e);e.skipNewlines(),e.expect("{");let n=[],r=new Set;for(e.switchDepth++,e.skipTerminators();!e.is("}");e.skipTerminators()){let i=null;e.accept("case","keyword")?i=$1(e):e.accept("default","keyword")||e.fail(`expected \`case\` or \`default\` in switch body but found ${Rt(e.tok)}`);let o=i===null?"default":i.type==="regex"?`/${i.source}/`:String(i.value);r.has(o)&&e.fail(`duplicate case values in switch body: ${o}`),r.add(o),e.expect(":");let s=[];for(e.skipTerminators();!e.is("}")&&!e.isKw("case")&&!e.isKw("default");)e.tok.type==="eof"&&e.fail("missing `}` at end of program"),s.push(Bs(e)),e.skipTerminators();n.push({test:i,body:s})}return e.switchDepth--,e.next(),{type:"switch",expr:t,cases:n}}function $1(e){let t=e.accept("-")?-1:(e.accept("+"),1),n=e.tok;return n.type==="number"?(e.next(),{type:"num",value:t*Number(n.value)}):t===1&&n.type==="string"?(e.next(),{type:"str",value:n.value}):t===1&&n.type==="regex"?(e.next(),{type:"regex",source:n.value,re:Ee(n.value,!1,r=>e.warn(r))}):e.fail(`case value must be a number, string or regex constant, found ${Rt(n)}`)}function un(e,t){t==="break"&&e.loopDepth===0&&e.switchDepth===0&&e.fail("`break` is not allowed outside a loop or switch"),t==="continue"&&e.loopDepth===0&&e.fail("`continue` is not allowed outside a loop"),t==="next"&&e.context!=="main"&&e.context!=="function"&&e.fail(`\`next\` cannot be used in a ${e.context.toUpperCase()} action`),t==="nextfile"&&(e.context==="begin"||e.context==="end"||e.context==="endfile")&&e.fail(`\`nextfile\` cannot be used in a ${e.context.toUpperCase()} action`),t==="return"&&e.context!=="function"&&e.fail("`return` is only allowed inside a function"),e.next();let n={type:t};return(t==="exit"||t==="return")&&(n.value=lp(e)?we(e,{}):null),rr(e),n}function N1(e){e.next(),e.tok.type!=="name"&&e.fail(`\`delete\` needs an array name but found ${Rt(e.tok)}`);let t=e.next().value,n=Ds(e);return rr(e),{type:"delete",name:t,subs:n}}var wp=e=>e.is(";")||e.is("}")||e.is(">")||e.is(">>")||e.is("|")||e.is("|&")||e.tok.type==="newline"||e.tok.type==="eof";function xp(e,t){e.next();let n=null;if(e.is("(")){let i=e.i;e.next();let o=e.is(")")?[]:sn(e,{});e.accept(")")&&wp(e)?n=o:e.i=i}n===null&&(n=wp(e)?[]:sn(e,{noGt:!0})),t==="printf"&&n.length===0&&e.fail("printf needs a format string");let r=null;return(e.is("|")||e.is("|&"))&&e.fail(`output pipes (\`${t} ... | "cmd"\`) are not supported: ${Ar}`,`${t} | "cmd"`),(e.accept(">")||e.accept(">>"))&&(r=dp(e,{noGt:!0}),r.type==="str"&&!g1.has(r.value)&&e.fail(Ws(r.value),`${t} > FILE`)),rr(e),{type:t,args:n,dest:r}}function Ws(e){return`cannot redirect output to \`${e}\`: the filesystem is read-only (only /dev/stdout, /dev/stderr and /dev/null). To print a comparison, parenthesize it: print (a > b)`}var W=class{constructor(t){this.s=t,this.number=void 0,this.numeric=void 0}},ir="[ \\t\\n\\r\\f\\v]*",kp="[+-]?(?:\\d+\\.?\\d*|\\.\\d+)(?:[eE][+-]?\\d+)?",A1=new RegExp(`^${ir}${kp}${ir}$`,"u"),I1=new RegExp(`^${ir}(${kp})`,"u"),Sp=new RegExp(`^${ir}([+-])(inf|nan)${ir}$`,"iu"),zs=e=>A1.test(e)||Sp.test(e);function bp(e){let t=I1.exec(e);if(t)return Number(t[1]);let n=Sp.exec(e);return n?n[2].toLowerCase()==="nan"?Number.NaN:n[1]==="-"?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY:0}var qs=()=>new k("attempt to use an array in a scalar context");function B(e){if(typeof e=="number")return e;if(e===void 0)return 0;if(e instanceof W)return e.number??=bp(e.s);if(typeof e=="string")return bp(e);throw qs()}var pi=new Map;function Ep(e,t){if(Number.isNaN(e))throw new k("formatting signed NaN is not supported",null,"signed NaN");if(!Number.isFinite(e))return e<0?"-inf":"+inf";if(Number.isInteger(e))return Math.abs(e)<2**53?String(e):BigInt(e).toString();let n=pi.get(t);if(n===void 0){pi.size>64&&pi.clear(),n=qr(t);let r=n.filter(i=>typeof i!="string");if(r.length>1||r.some(i=>!"diouxXeEfFgG".includes(i.conv)||i.width==="*"||i.precision==="*"))throw new k("this numeric conversion format is not supported",null,"numeric conversion format");pi.set(t,n)}return n.map(r=>typeof r=="string"?r:Tt(e,r)).join("")}var $p=e=>typeof e=="string"?e:e instanceof W?e.s:"%.6g",O1=e=>$p(e.globals.get("CONVFMT")),C1=e=>$p(e.globals.get("OFMT"));function F(e,t){if(typeof e=="string")return tt(t,e);if(e instanceof W)return tt(t,e.s);if(typeof e=="number")return Ep(e,O1(t));if(e===void 0)return"";throw qs()}function tt(e,t){if(e.byteLocale&&/[\u0080-\u{10FFFF}]/u.test(t))throw new k("non-ASCII AWK text in a byte locale is not supported",null,"byte locale text");return t}function Mt(e,t=!1){return[...e].map(n=>{let r=t?n.toUpperCase():n.toLowerCase();if([...r].length!==1)throw new k("Unicode case expansion is not supported",null,"Unicode case mapping");return r}).join("")}function Np(e,t){return typeof e=="number"?Ep(e,C1(t)):F(e,t)}var js=e=>e.numeric??=zs(e.s),vp=e=>typeof e=="number"||e===void 0||e instanceof W&&js(e),De=e=>xe(e.globals.get("IGNORECASE"));function hi(e,t,n){if(vp(e)&&vp(t)){let o=B(e),s=B(t);return o<s?-1:o>s?1:o===s?0:Number.NaN}let r=F(e,n),i=F(t,n);return De(n)&&(r=Mt(r),i=Mt(i)),U(r,i)}function xe(e){if(typeof e=="number")return e!==0&&!Number.isNaN(e);if(typeof e=="string")return e!=="";if(e instanceof W)return js(e)?B(e)!==0:e.s!=="";if(e===void 0)return!1;throw qs()}var Hs=(e,t)=>Number.isSafeInteger(e)?String(e):F(e,t);function Gs(e){return e instanceof Map?"array":e===void 0?"untyped":typeof e=="number"?"number":e instanceof W&&js(e)?"strnum":"string"}function Ap(e,t,n){let{text:r}=e;if(e.pos>=r.length)return null;if(t==="")return F1(e);let i,o;if(t.length===1){let u=r.indexOf(t,e.pos);o=u===-1?r.length:u,i=u===-1?r.length:u+1}else{let u=bo(r,Ee(t,n),e.pos);o=u?.start??r.length,i=u?.end??r.length}let s=r.slice(e.pos,o);return e.pos=i,{rec:s,rt:r.slice(o,i)}}function F1(e){let{text:t}=e,n=e.pos;for(;t[n]===`
221
- `;)n++;if(n>=t.length)return e.pos=n,null;let r=/\n\n+/gu;r.lastIndex=n;let i=r.exec(t);if(!i){e.pos=t.length;let o=t.slice(n).replace(/\n+$/u,"");return{rec:o,rt:t.slice(n+o.length)}}return e.pos=i.index+i[0].length,{rec:t.slice(n,i.index),rt:i[0]}}function Vs(e,t,n,r){if(e==="")return[];if(t instanceof Qe)return vo(e,t);if(t===" "){let o=e.replace(/^[ \t\n]+|[ \t\n]+$/gu,"");return o===""?[]:o.split(/[ \t\n]+/u)}if(t==="")return[...e];if(t.length===1&&(!n||t===`
222
- `))return e.split(t);if(n&&t==="^")throw new k('paragraph splitting with FS="^" is not supported',null,"paragraph FS caret");let i=t.length===1?`[${"^$.[]|()*+?{}\\".includes(t)?"\\"+t:t}
223
- ]`:t;return vo(e,Ee(i,r))}function Ip(e){let t=e.split(/[ \t]+/u).filter(Boolean);return t.map((n,r)=>{let i=/^(?:(\+?\d+):)?(\+?\d+|\*)$/u.exec(n),o=i?.[1]===void 0?0:Number(i[1]),s=i?.[2]==="*"?4294967295:Number(i?.[2]);if(!i||i[1]!==void 0&&o===0||o>4294967295||!(s>0&&s<=4294967295)||i[2]==="*"&&r!==t.length-1)throw new k(`invalid FIELDWIDTHS value \`${e}'`);return{skip:o,width:s}})}function T1(e,t){let n=[...e],r=[],i=0;for(let{skip:o,width:s}of t){if(i>=n.length)break;i+=o,r.push(n.slice(i,i+s).join("")),i+=s}return r}function _1(e,t){let n=[],r=0;for(;r<e.length;){let i=t.search(e.slice(r));if(n.length>0&&i?.end===0&&(r+=ke(e,r),i=t.search(e.slice(r))),!i)break;n.push(e.slice(r+i.start,r+i.end)),r+=i.end}return n}function Op(e,t){let n=De(e);return e.fieldMode==="FIELDWIDTHS"?T1(t,e.widths):e.fieldMode==="FPAT"?_1(t,Ee(F(e.globals.get("FPAT"),e),n,e.warn)):Vs(t,F(e.globals.get("FS"),e),F(e.globals.get("RS"),e)==="",n)}var L1=/^([A-Za-z_][A-Za-z0-9_]*)=([^]*)$/u,Zs=e=>e!==void 0&&e.type==="exit",mi=class{constructor(t,n){this.ctx=t,this.stdin=n,this.idx=1,this.src=null,this.sawFile=!1,this.exitSignal=void 0,this.readers=new Map}next(t){for(;this.exitSignal===void 0;){if(this.src){let n=Ap(this.src,F(t.globals.get("RS"),t),De(t));if(n!==null)return t.globals.set("NR",B(t.globals.get("NR"))+1),t.globals.set("FNR",B(t.globals.get("FNR"))+1),t.globals.set("RT",n.rt),n.rec;this.closeFile(t);continue}if(!this.open(t))return null}return null}open(t){for(;this.idx<Math.trunc(B(t.globals.get("ARGC")));){if(++t.steps>Cn)throw new k("input operand scan exceeded execution limit",null,"execution limit");let n=F(t.globals.get("ARGV").get(String(this.idx++)),t);if(n==="")continue;t.globals.set("ARGIND",this.idx-1);let r=L1.exec(n);if(r){t.assign(r[1],new W(Qn(r[2],t.warn)));continue}this.sawFile=!0;let{text:i,error:o}=this.readOperand(n);if(o==="Is a directory"){this.failFile(t,n,o),this.exitSignal===void 0&&t.warn(`command line argument \`${n}' is a directory: skipped`);continue}if(o){let s=this.failFile(t,n,o);if(s!==void 0&&s.type==="nextfile")continue;if(this.exitSignal!==void 0)return!1;throw new k(`${n}: ${o}`)}if(this.use(t,n,i))return!0}return this.sawFile||this.exitSignal!==void 0?!1:(this.sawFile=!0,this.use(t,"-",this.takeStdin()))}readOperand(t){if(t==="/dev/null")return{text:""};if(t==="-"||t==="/dev/stdin")return{text:t==="/dev/stdin"&&this.ctx.stdinFile?this.ctx.stdinOrigin:this.takeStdin()};let{path:n,error:r}=P(this.ctx,"awk",t);return this.ctx.fs.isDir(n)?{error:"Is a directory"}:r?{error:r}:{text:this.ctx.fs.readFile(n)}}takeStdin(){let t=this.stdin;return this.stdin="",z(this.ctx),t}use(t,n,r){this.src={text:r,pos:0},t.globals.set("FILENAME",n),t.globals.set("FNR",0),t.globals.set("ERRNO","");let i=t.fileRule("begin");return Zs(i)?(this.exitSignal=i,this.src=null,!1):i!==void 0&&i.type==="nextfile"?(this.closeFile(t),!1):(tt(t,r),!0)}failFile(t,n,r){if(t.globals.set("ERRNO",r),!t.hasFileRules)return;t.globals.set("FILENAME",n),t.globals.set("FNR",0);let i=t.fileRule("begin");return Zs(i)&&(this.exitSignal=i),i}closeFile(t){this.src=null;let n=t.fileRule("end");Zs(n)&&(this.exitSignal=n)}readNamed(t,n){let r=this.readers.get(n);if(!r){let{text:o,error:s}=this.readOperand(n);if(s)return t.globals.set("ERRNO",s),{status:-1};r={text:tt(t,o),pos:0},this.readers.set(n,r)}let i=Ap(r,F(t.globals.get("RS"),t),De(t));return i===null?{status:0}:(t.globals.set("RT",i.rt),{status:1,record:i.rec})}close(t,n){return this.readers.delete(n)?0:(t.globals.set("ERRNO","close of redirection that was never opened"),-1)}};var R1=(e,t)=>({isRef:!0,scope:e,name:t}),or=e=>typeof e=="object"&&e!==null&&e.isRef===!0,sr=class extends Error{constructor(t){super(t.type),this.signal=t}},Tp=e=>new k(`attempt to use array \`${e}\` in a scalar context`);function gi(e,t){let n=e.frame;return n!==void 0&&n.has(t)?n:e.globals}function M1(e){let t=e;for(;or(t);)t=t.scope.get(t.name);return t instanceof Map?t:void 0}function ln(e,t){let n=gi(e,t).get(t);return or(n)?M1(n):n}var P1=new Set(["FS","FIELDWIDTHS","FPAT"]);function wi(e,t,n){let r=gi(e,t);if(r.get(t)instanceof Map)throw Tp(t);if(r===e.globals){if(t==="NF"){U1(e,n);return}if(t==="FIELDWIDTHS"&&(e.widths=Ip(F(n,e))),(t==="FPAT"||(t==="FS"||t==="RS")&&F(n,e).length>1)&&Ee(F(n,e),De(e),e.warn),P1.has(t)){e.fieldMode=t;let i=e.globals.get("PROCINFO");i instanceof Map&&i.set("FS",t)}}r.set(t,n)}function nt(e,t){let n=gi(e,t),r=t,i=n,o=i.get(r);if(o instanceof Map)return o;let s=or(o);for(;or(o);)i=o.scope,r=o.name,o=i.get(r);if(!(o instanceof Map)){if(o!==void 0)throw new k(`attempt to use scalar \`${r}\` as an array`);o=new Map,i.set(r,o)}return s&&n.set(t,o),o}function xi(e,t,n=new W(t)){e.record=t,e.recordValue=n,e.fields=[void 0,...Op(e,t).map(r=>new W(r))],e.nf=e.fields.length-1,e.globals.set("NF",e.nf)}function _p(e){let t=F(e.globals.get("OFS"),e);e.record=e.fields.slice(1).map(n=>F(n,e)).join(t),e.recordValue=e.record}function Lp(e,t){return t===0?e.recordValue:t<=e.nf?e.fields[t]:void 0}function D1(e,t,n){if(t===0){let r=F(n,e);xi(e,r,typeof n=="number"?r:n);return}for(;e.nf<t;)e.fields[++e.nf]="";e.fields[t]=n,e.globals.set("NF",e.nf),_p(e)}function U1(e,t){let n=Math.trunc(B(t));if(n<0)throw new k(`NF set to negative value ${n}`);for(;e.nf<n;)e.fields[++e.nf]="";e.fields.length=n+1,e.nf=n,e.globals.set("NF",n),_p(e)}function Rp(e,t){let n=B(O(e,t));if(!(n>=0))throw new k(`attempt to access field ${Number.isNaN(n)?n:Math.trunc(n)}`);return Math.trunc(n)}function ur(e,t){if(t.length===1)return Hs(O(e,t[0]),e);let n=F(e.globals.get("SUBSEP"),e);return t.map(r=>Hs(O(e,r),e)).join(n)}function Ys(e,t){return t.type==="var"?t:t.type==="index"?{type:"index",arr:nt(e,t.name),key:ur(e,t.subs)}:{type:"field",i:Rp(e,t.index)}}function Mp(e,t){return t.type==="var"?Pp(ln(e,t.name),t.name):t.type==="index"?t.arr.get(t.key):Lp(e,t.i)}function Ks(e,t,n){t.type==="var"?wi(e,t.name,n):t.type==="index"?t.arr.set(t.key,n):D1(e,t.i,n)}function Js(e,t,n){Ks(e,Ys(e,t),n)}function Cp(e,t,n){if(n===0&&(e==="/"||e==="%"))throw new k(e==="/"?"division by zero attempted":"division by zero attempted in `%`");return Ir(e,t,n)}var B1={__proto__:null,"<":e=>e<0,"<=":e=>e<=0,"==":e=>e===0,"!=":e=>e!==0,">":e=>e>0,">=":e=>e>=0};function rt(e,t){let n=De(e);return t.type==="regex"?n?Ee(t.source,!0):t.re:Ee(F(O(e,t),e),n,e.warn)}function Pp(e,t){if(e instanceof Map)throw Tp(t);return e}function Fp(e,t,n){let r=Ys(e,t.target),i=B(Mp(e,r)),o=t.op==="++"?i+1:i-1;return Ks(e,r,o),n?i:o}function O(e,t){switch(t.type){case"num":case"str":return t.value;case"regex":return rt(e,t).test(e.record)?1:0;case"var":return Pp(ln(e,t.name),t.name);case"index":{let n=nt(e,t.name),r=ur(e,t.subs),i=n.get(r);return i===void 0&&n.set(r,void 0),i}case"field":return Lp(e,Rp(e,t.index));case"assign":{let n=Ys(e,t.target),r=O(e,t.value);if(r instanceof Map)throw new k("attempt to use an array in a scalar context");return t.op!=="="&&(r=Cp(t.op[0],B(Mp(e,n)),B(r))),Ks(e,n,r),r}case"cond":return O(e,xe(O(e,t.test))?t.consequent:t.alternate);case"or":return xe(O(e,t.left))||xe(O(e,t.right))?1:0;case"and":return xe(O(e,t.left))&&xe(O(e,t.right))?1:0;case"not":return xe(O(e,t.expr))?0:1;case"neg":return-B(O(e,t.expr));case"plus":return B(O(e,t.expr));case"binary":return Cp(t.op,B(O(e,t.left)),B(O(e,t.right)));case"concat":return F(O(e,t.left),e)+F(O(e,t.right),e);case"compare":return B1[t.op](hi(O(e,t.left),O(e,t.right),e))?1:0;case"match":{let n=F(O(e,t.left),e);return rt(e,t.right).test(n)===t.negate?0:1}case"in":return nt(e,t.array).has(ur(e,t.keys))?1:0;case"preinc":return Fp(e,t,!1);case"postinc":return Fp(e,t,!0);case"call":return W1(e,t);case"builtin":return e.callBuiltin(e,t);case"getline":return q1(e,t);default:throw new k(`unknown expression: ${t.type}`)}}function W1(e,t){let n=e.program.functions.get(t.name);if(n===void 0)throw new k(`function \`${t.name}\` not defined`);if(t.args.length>n.params.length)throw new k(`function \`${t.name}\` called with ${t.args.length} arguments, but it accepts only ${n.params.length}`);if(e.callDepth>=wo)throw new k(`function call nesting deeper than ${wo} levels (runaway recursion?)`,null,"call depth limit");let r=e.frame,i=new Map;for(let o=0;o<n.params.length;o++)i.set(n.params[o],o<t.args.length?z1(e,t.args[o]):void 0);e.frame=i,e.callDepth++;try{let o=e.execStmts(e,n.body);if(o===void 0||o.type==="return")return o?.value;throw new sr(o)}finally{e.frame=r,e.callDepth--}}function z1(e,t){if(t.type!=="var")return O(e,t);let n=gi(e,t.name),r=n.get(t.name);return r instanceof Map||or(r)?r:r===void 0?R1(n,t.name):r}function q1(e,t){let n;if(t.file===null){if(n=e.input.next(e),n===null)return 0}else{let r=e.input.readNamed(e,F(O(e,t.file),e));if(r.status!==1)return r.status;n=r.record}return t.target===null?xi(e,n):Js(e,t.target,new W(n)),1}var Ge=(e,t)=>B(O(e,t)),Qs=2**32;function Up(e){return Number(BigInt.asUintN(32,BigInt(Math.trunc(e))))}var Bp=()=>({seed:1,state:Up(1)});function j1(e){e.rng.state=(e.rng.state+1831565813)%Qs;let t=e.rng.state;t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61);let n=t^t>>>14;return(n<0?n+Qs:n)/Qs}function H1(e,t){let n=e.rng.seed,r=t.length>0?Ge(e,t[0]):Math.floor(Date.now()/1e3);return e.rng.seed=r,e.rng.state=Up(r),n}function G1(e,t){let n=Ge(e,t[0]);return n<0&&e.warn(`log: received negative argument ${F(n,e)}`),Math.log(n)}function X1(e,t){let n=Ge(e,t[0]);return n<0&&e.warn(`sqrt: called with negative argument ${F(n,e)}`),Math.sqrt(n)}function Z1(e,t){let n=Ge(e,t[0]),r=Math.exp(n);return Number.isFinite(n)&&!Number.isFinite(r)&&e.warn(`exp: argument ${F(n,e)} is out of range`),r}function V1(e,t){let n=O(e,t[0]);if(typeof n=="number")return n;let r=n instanceof W?n.s:F(n,e),i=/^0[xX]([0-9a-fA-F]*)/u.exec(r);if(i)return i[1]===""?0:Number.parseInt(i[1],16);let o=/^0[0-7]+(?![.\deE0-9])/u.exec(r);return o?Number.parseInt(o[0],8):B(new W(r))}function ar(e,t,n,r){let i=Ge(e,n);if(i<0)throw new k(`${t}: argument ${r} negative value ${F(i,e)} is not allowed`);if(!Number.isFinite(i))throw new k(`${t}: argument ${r} is not a finite number`);return BigInt.asUintN(64,BigInt(Math.trunc(i)))}function tu(e){let t=e;for(;t>0n&&BigInt(Number(t))!==t;)t&=(1n<<BigInt(t.toString(2).length-1))-1n;return Number(t)}function eu(e,t){return(n,r)=>{if(r.length<2)throw new k(`${e}: called with less than two arguments`);let i=ar(n,e,r[0],1);for(let o=1;o<r.length;o++)i=t(i,ar(n,e,r[o],o+1));return tu(i)}}function Dp(e,t){return(n,r)=>{let i=ar(n,e,r[0],1),o=ar(n,e,r[1],2)%64n;return tu(BigInt.asUintN(64,t?i<<o:i>>o))}}var Wp={__proto__:null,sin:(e,t)=>Math.sin(Ge(e,t[0])),cos:(e,t)=>Math.cos(Ge(e,t[0])),atan2:(e,t)=>Math.atan2(Ge(e,t[0]),Ge(e,t[1])),exp:Z1,log:G1,sqrt:X1,int:(e,t)=>Math.trunc(Ge(e,t[0])),rand:j1,srand:H1,systime:()=>Math.floor(Date.now()/1e3),strtonum:V1,and:eu("and",(e,t)=>e&t),or:eu("or",(e,t)=>e|t),xor:eu("xor",(e,t)=>e^t),lshift:Dp("lshift",!0),rshift:Dp("rshift",!1),compl:(e,t)=>tu(BigInt.asUintN(64,~ar(e,"compl",t[0],1)))};var yi=new Map;function Y1(e){let t=yi.get(e);return t||(yi.size>=256&&yi.clear(),t=qr(e),yi.set(e,t)),t}function bi(e,t,n){let r=0,i=()=>{if(r>=n.length)throw new k("printf: not enough arguments to satisfy format string");return n[r++]},o="";for(let s of Y1(t)){if(typeof s=="string"){o+=s;continue}let u={...s};if(s.width==="*"){let a=Math.trunc(B(i()));a<0?(u.minus=!0,u.width=-a):u.width=a}if(s.precision==="*"){let a=Math.trunc(B(i()));u.precision=a<0?null:a}if(u.width>ye||u.precision>ye)throw new k(`printf: field width or precision above ${ye} is not supported`,null,"format size limit");o+=K1(e,u,i())}return o}function K1(e,t,n){if(t.conv==="s"){let r=F(n,e);return t.precision!==null&&(r=[...r].slice(0,t.precision).join("")),wt("",r,t,!1)}return t.conv==="c"?wt("",tt(e,J1(n)),t,!1):Tt(B(n),t)}function J1(e){if(typeof e=="number"||e instanceof W&&zs(e.s)){let r=Math.trunc(B(e));if(!ze(r))throw new k("printf: character code outside Unicode scalar values is not supported",null,"character code");return String.fromCodePoint(r)}let n=e instanceof W?e.s:e??"";return n===""?"\0":String.fromCodePoint(n.codePointAt(0))}var de=(e,t)=>F(O(e,t),e),zp=(e,t)=>B(O(e,t)),Q1={type:"field",index:{type:"num",value:0}};function ev(e,t){let n="";for(let r=0;r<e.length;r++){let i=e[r];if(i==="\\"){if(e[r+1]==="\\"&&e[r+2]==="\\"&&(e[r+3]==="&"||e[r+3]==="\\")){n+="\\"+e[r+3],r+=3;continue}if(e[r+1]==="\\"&&e[r+2]==="&"){n+="\\"+t,r+=2;continue}if(e[r+1]==="&"){n+="&",r++;continue}}n+=i==="&"?t:i}return n}function qp(e,t,n){let r=rt(e,t[0]),i=de(e,t[1]),o=t[2]??Q1,s=de(e,o),{out:u,count:a}=Tn(s,r,(l,c)=>ev(i,s.slice(l,c)),n?"global":"first");return a>0&&Js(e,o,u),a}function tv(e,t){let n="";for(let r=0;r<e.length;r++){let i=e[r];if(i==="\\"&&r+1===e.length)throw new k("gensub with a trailing replacement backslash is not supported",null,"gensub trailing backslash");if(i==="\\"&&r+1<e.length){let o=e[++r];o>="0"&&o<="9"?n+=t[Number(o)]?.text??"":n+=o;continue}n+=i==="&"?t[0].text:i}return n}function nv(e,t){let n=rt(e,t[0]),r=de(e,t[1]),i=O(e,t[2]),o=F(i,e),s=o.startsWith("g")||o.startsWith("G"),u=0;s||(u=Math.trunc(B(i)),u<1&&(e.warn(`gensub: third argument \`${o}' treated as 1`),u=1));let a=t[3]?de(e,t[3]):e.record,l=/(?:^|[^\\])(?:\\\\)*\\[1-9]/u.test(r);return Tn(a,n,(c,f,d)=>!s&&d!==u?null:tv(r,l?n.groups(a,c,f):[{text:a.slice(c,f)}]),s?"global":"nth").out}function rv(e,t){let n=de(e,t[0]),r=rt(e,t[1]),i=r.search(n,0),o=i?Array.from(n.slice(0,i.start)).length+1:0;if(e.globals.set("RSTART",o),e.globals.set("RLENGTH",i?Array.from(n.slice(i.start,i.end)).length:-1),t[2]){let s=nt(e,t[2].name);if(s.clear(),i){let u=F(e.globals.get("SUBSEP"),e);r.groups(n,i.start,i.end).forEach((a,l)=>{a!==void 0&&(s.set(String(l),new W(a.text)),s.set(`${l}${u}start`,Array.from(n.slice(0,a.start)).length+1),s.set(`${l}${u}length`,[...a.text].length))})}}return o}function iv(e,t){let n=de(e,t[0]),r=nt(e,t[1].name),i;t[2]===void 0?i=F(e.globals.get("FS"),e):t[2].type==="regex"?i=rt(e,t[2]):i=de(e,t[2]);let o=Vs(n,i,!1,De(e));return r.clear(),o.forEach((s,u)=>r.set(String(u+1),new W(s))),o.length}function ov(e,t){let n=[...de(e,t[0])],r=Math.trunc(zp(e,t[1])),i=Number.isNaN(r)?1:Math.max(r,1),o=n.length+1;if(t[2]){let s=Math.trunc(zp(e,t[2]));if(!(s>=1))return"";o=Math.min(o,i+s)}return o>i?n.slice(i-1,o-1).join(""):""}function sv(e,t){if(t.length===0)return[...e.record].length;if(t[0].type==="var"){let n=ln(e,t[0].name);return n instanceof Map?n.size:[...F(n,e)].length}return[...de(e,t[0])].length}function uv(e,t){let n=de(e,t[0]),r=de(e,t[1]);De(e)&&(n=Mt(n),r=Mt(r));let i=n.indexOf(r);return i<0?0:Array.from(n.slice(0,i)).length+1}function av(e,t){let n=de(e,t[0]);return n==="/dev/stdout"||n==="/dev/stderr"||n==="/dev/null"?0:e.input.close(e,n)}var lv=(e,t)=>t[0].type==="var"?Gs(ln(e,t[0].name)):Gs(O(e,t[0])),cv={__proto__:null,...Wp,length:sv,substr:ov,index:uv,split:iv,sub:(e,t)=>qp(e,t,!1),gsub:(e,t)=>qp(e,t,!0),gensub:nv,match:rv,sprintf:(e,t)=>bi(e,de(e,t[0]),t.slice(1).map(n=>O(e,n))),tolower:(e,t)=>Mt(de(e,t[0])),toupper:(e,t)=>Mt(de(e,t[0]),!0),close:av,fflush:()=>0,typeof:lv,isarray:(e,t)=>t[0].type==="var"&&ln(e,t[0].name)instanceof Map?1:0};function jp(e,t){let n=cv[t.name];if(!n)throw new k(`function \`${t.name}\` is not supported`,null,`${t.name}()`);return n(e,t.args)}var ki={type:"break"},ru={type:"continue"},fv={type:"next"},dv={type:"nextfile"},pv={type:"exit"};function Hp(e,t,n,r){let i=new Map([["0","awk"]]);r.forEach((u,a)=>i.set(String(a+1),new W(u)));let o=new Map([["FS"," "],["OFS"," "],["ORS",`
220
+ `;return}n+=r+e.script[e.i++]}else n+=r}t.command.text=gk(n+`
221
+ `),e.textState.pending=null}function du(e){e?.pending&&(e.pending.command.text=e.pending.raw||null,e.pending=null)}function gk(e){return W(fu(e))}function fu(e){let t=A(e),n=[];for(let r=0;r<t.length;r++){let o=t[r];if(o!==92||r+1===t.length){n.push(o);continue}let i=String.fromCodePoint(t[++r]);if(Object.hasOwn(d1,i)){n.push(d1[i]);continue}if(Object.hasOwn(p1,i)){let s=p1[i],u=s===16?2:3,a=0,l=0;for(;a<u&&r+1<t.length;){let f=t[r+1],c=f>=48&&f<=57?f-48:(f|32)>=97&&(f|32)<=102?(f|32)-87:-1;if(c<0||c>=s)break;l=l*s+c,a++,r++}n.push(a?l&255:i.codePointAt(0))}else if(i==="c"){if(++r===t.length)continue;let s=t[r];if(s===92&&t[++r]!==92)throw new Error("recursive escaping after \\c not allowed");n.push((s>=97&&s<=122?s-32:s)^64)}else n.push(i.codePointAt(0))}return Uint8Array.from(n)}function g1(e){let t=fr(e,"'y' command"),n=fu(h1(e,t)),r=fu(h1(e,t)),o=e.byteLocale?n:[...W(n)],i=e.byteLocale?r:[...W(r)];if(o.length!==i.length)throw new Error("'y' command strings have different lengths");let s=e.byteLocale?Uint8Array.from({length:256},(u,a)=>a):new Map;for(let u=0;u<o.length;u++)e.byteLocale?s[o[u]]=i[u]:s.has(o[u])||s.set(o[u],i[u]);return{translation:s,byteLocale:e.byteLocale}}function h1(e,t){let n="";for(;e.i<e.script.length;){let r=e.script[e.i++];if(r===`
222
+ `)break;if(r===t)return n;if(r!=="\\"){n+=r;continue}let o=e.script[e.i++];if(o===void 0)break;n+=o===t||o===`
223
+ `?o:r+o}throw new Error("unterminated 'y' command")}function w1(e,t){if(t.byteLocale)return W(A(e).map(r=>t.translation[r]));let n="";for(let r of e)n+=t.translation.get(r)??r;return n}function pu(e,t=!1,n=ee,r=null){let o={script:e,i:0,extended:t,locale:n,byteLocale:Mr(n),textState:r??{},openWrite:r?.openWrite},i=[];for(cu(o);o.i<e.length;){if(/[;\n\r\f\v \t]/u.test(e[o.i])){o.i++;continue}e[o.i]==="#"&&Ee("comments");let s=y1(o),u=null;if(s&&e[o.i]===","&&(o.i++,u=y1(o,!0),u===null))throw new Error("missing second address");e[o.i]==="~"&&Ee("step address");let a=s?.type==="line"&&s.value===0;if(a&&u?.type!=="regex")throw new Error("line numbers must be >= 1");let l=!1;if(e[o.i]==="!"){for(l=!0,o.i++;/[ \t]/u.test(e[o.i]??"");)o.i++;if(e[o.i]==="!")throw new Error("multiple '!'s")}let f=e[o.i++],c={kind:f,start:s,end:u,active:a,negated:l};if(f&&"pPnNdD=gGhHx".includes(f))i.push(c);else if(f==="w"){i.push({...c,...iu(o)});continue}else if(f===":"||f==="b"||f==="t"||f==="T"){i.push({...c,label:wk(o,c)});continue}else if(f==="s")i.push({...c,...f1(o)});else if(f==="a"||f==="i"||f==="c")m1(o,c),i.push(c);else if(f==="y")i.push({...c,...g1(o)});else if(f==="q"){if(u!==null)throw new Error("command only uses one address");let d=/^[ \t]*(\d*)/u.exec(e.slice(o.i));o.i+=d[0].length;let p=BigInt.asIntN(32,BigInt(d[1]||"0"));i.push({...c,exitCode:p===-1n?0:Number(BigInt.asUintN(8,p))})}else if(f==="{"){o.textState.blockDepth=(o.textState.blockDepth??0)+1,i.push(c);continue}else if(f==="}"){if(!o.textState.blockDepth)throw new Error("unexpected '}'");if(s!==null)throw new Error("'}' doesn't want any addresses");o.textState.blockDepth--,i.push(c)}else{if(f===void 0)throw new Error("missing command");if("QlLFzrRWev".includes(f))Ee();else throw new Error(`unknown command: '${f}'`)}for(;/[ \t]/u.test(e[o.i]??"");)o.i++;if(e[o.i]==="#"&&Ee("comments"),o.i<e.length&&!/[;\n}]/u.test(e[o.i]))throw new Error("extra characters after command")}return r===null&&du(o.textState),i}function hu(e,t){let n=[];for(let r=0;r<e.length;r++){let o=e[r];if(o.kind==="{"&&n.push(o),o.kind==="}"){if(n.length===0)throw new Error("unexpected '}'");n.pop().jump=r}}if(n.length)throw new Error("unmatched '{'");return du(t),yk(e),e}function wk(e,t){if(t.kind===":"&&t.start!==null)throw new Error("':' doesn't want any addresses");let n=/^[ \t]*([^ \t\n;}#]*)/u.exec(e.script.slice(e.i));e.i+=n[0].length;let r=n[1].split("\0",1)[0];if(t.kind===":"&&r==="")throw new Error("':' lacks a label");return r}function yk(e){let t=new Map;for(let n=0;n<e.length;n++)e[n].kind===":"&&t.set(e[n].label,n);for(let n=e.length-1;n>=0;n--){let r=e[n];if(!["b","t","T"].includes(r.kind))continue;let o=r.label===""?e.length:t.get(r.label);if(o===void 0)throw Object.assign(new Error(`can't find label for jump to \`${r.label}'`),{exitCode:4});r.jump=o}}function y1(e,t=!1){for(;/[ \t]/u.test(e.script[e.i]??"");)e.i++;e.script[e.i]==="~"&&Ee("step address");let n=/^(\d+|\+[ \t]*\d+)/u.exec(e.script.slice(e.i)),r=null;if(n){let o=n[0][0]==="+";if(o&&!t)throw new Error("relative address requires a range");let i=Number(n[0].replace(/[ \t]/gu,""));Number.isSafeInteger(i)||Ee("address limit"),e.i+=n[0].length,r={type:o?"offset":"line",value:i}}else if(e.script[e.i]==="$")e.i++,r={type:"last"};else if(e.script[e.i]==="/"||e.script[e.i]==="\\"){e.script[e.i]==="\\"&&e.i++;let o=fr(e,"address regex"),i=Ro(e,o,!0,"address regex"),s=!1;for(;;){for(;/[ \t]/u.test(e.script[e.i]??"");)e.i++;let u=e.script[e.i];if(u!=="I"&&u!=="M")break;if(i==="")throw new Error("cannot specify modifiers on empty regexp");u==="M"&&Ee("address regex flags"),s=!0,e.i++}r={type:"regex",...su(i,e.extended,!0,s,e.locale)}}for(;/[ \t]/u.test(e.script[e.i]??"");)e.i++;return r}function b1(e,t,n,r,o){let{start:i,end:s}=e;if(i===null)return!0;if(s===null)return Mo(i,t,n,r,o);if(!e.active){if(i.type==="line"){if(e.closed||n<i.value)return!1}else if(!Mo(i,t,n,r,o))return!1;if(e.active=!0,s.type==="regex")return!0;if(s.type==="offset"&&(e.until=n+s.value),s.type==="line")return e.active=n<s.value,e.closed=!e.active,n<=s.value||Mo(i,t,n,r,o)}return s.type==="line"?(e.active=n<s.value,e.closed=!e.active,n<=s.value):((s.type==="offset"?n>=e.until:Mo(s,t,n,r,o))&&(e.active=!1,e.closed=!0),!0)}function Mo(e,t,n,r,o){if(e.type==="line")return n===e.value;if(e.type==="last")return typeof r=="function"?r():r;let i=au(e,o);return uu(t,i),i.re.search(t)!==null}function mu(e,t,n,r=!1){let{output:o,delimiter:i}=e,s=t.has("n")||t.has("quiet")||t.has("silent"),u=t.has("s")||t.has("separate"),a=l1(e.files,e.stdin,n,i,u,p=>o.stream(2,p)),l=o.start(a),f=[],c=ou(r?p=>{o.account(p),f.push(p)}:p=>o.stream(1,p),i),d={delimiter:i,quiet:s,separate:u,hold:e.hold,regexState:e.regexState,budget:e.budget,emit:c,input:a,output:o};try{let p=bk(e.commands,d);l.quit=p!==null,l.exitCode=a.status.failed?a.status.directory?4:2:p??0,l.failed=a.status.failed}catch(p){let h=Fo(p);_(l,h);let m=O(h);m&&ie(l,m.kind,m.command,m.detail,m.message),l.failed=!0}finally{o.finish()}return r&&(l.content=f.join("")),l}function bk(e,t){let n=!0;for(let r=t.input.next();r;r=t.input.next()){if(n||t.separate&&r.reset){t.hold.text="";for(let s of e)s.active=s.start?.type==="line"&&s.start.value===0,s.closed=!1;n=!1}t.output.record(r);let o={...r,...t,append:[],exitCode:null,replaced:!1},i=xk(e,o);if(!t.quiet&&!i&&t.emit(o.text,o.terminator),o.exitCode!==null&&t.emit(""),x1(o),o.exitCode!==null)return o.exitCode;t.output.record(null)}return null}function xk(e,t){for(let n=0;n<e.length;n++){if(++t.budget.steps>nu)throw new b("feature","execution limit",`sed: execution limit reached after ${nu} commands (infinite loop?)`);let r=e[n];if(r.kind==="}"||r.kind===":")continue;if(b1(r,t.text,t.line,t.last,t.regexState)===!!r.negated){r.kind==="{"&&(n=r.jump);continue}let i=r.kind;if(i!=="{"){if(i==="b"||i==="t"||i==="T"){let s=i==="b"||(i==="t"?t.replaced:!t.replaced);i!=="b"&&(t.replaced=!1),s&&(n=r.jump-1);continue}if(i==="q"){t.exitCode=r.exitCode;break}if(i==="d")return!0;if(i==="D"){let s=t.text.indexOf(t.delimiter);if(s<0)return!0;t.text=t.text.slice(s+t.delimiter.length),n=-1;continue}if(i==="n"||i==="N"){if(!Sk(t,i==="N"))return!0;continue}if(i==="c")return!r.active&&r.text!==null&&t.emit(r.text.slice(0,-1),t.delimiter),!0;if(kk(r,t),t.text.length>To)throw new b("feature","pattern space limit","sed: pattern space limit exceeded")}}return!1}function kk(e,t){let{kind:n}=e;if(n==="a"){t.append.push(e.text);return}if(n==="i")e.text!==null&&t.emit(e.text.slice(0,-1),t.delimiter);else if(n==="p")t.emit(t.text,t.terminator);else if(n==="P"){let r=t.text.indexOf(t.delimiter);t.emit(r<0?t.text:t.text.slice(0,r),r<0?t.terminator:t.delimiter)}else if(n==="=")t.emit(String(t.line),t.delimiter);else if(n==="w")e.writer(t.text,t.terminator);else if("gGhHx".includes(n))vk(n,t);else if(n==="y")t.text=w1(t.text,e);else{let r=lu(t.text,e,t.regexState);if(t.text=r.out,!r.count)return;t.replaced=!0,e.print&&t.emit(t.text,t.terminator),e.writer&&e.writer(t.text,t.terminator)}}function vk(e,t){let n=t.hold;if(e==="x"){let{text:r,terminator:o}=t;Object.assign(t,n),Object.assign(n,{text:r,terminator:o})}else{let r=e==="h"||e==="H"?t:n,o=r===n?t:n;o.text=e==="G"||e==="H"?o.text+t.delimiter+r.text:r.text,o.terminator=r.terminator}if(n.text.length>To)throw new b("feature","hold space limit","sed: hold space limit exceeded")}function Sk(e,t){if(!t&&!e.quiet&&e.emit(e.text,e.terminator),e.last())return t&&!e.quiet&&e.emit(e.text,e.terminator),!1;x1(e);let n=e.input.next();if(!n)return t&&!e.quiet&&e.emit(e.text,e.delimiter),!1;let r=t?e.text+e.delimiter+n.text:n.text;if(r.length>To)throw new b("feature","pattern space limit","sed: pattern space limit exceeded");return Object.assign(e,n,{text:r,replaced:!1}),e.output.record(n),!0}function x1(e){if(e.append.length!==0){e.emit("");for(let t of e.append)e.emit(t??"");e.append.length=0}}function k1(e,t,n){try{let{tokens:r,inPlace:o}=s1(t),i=N(r,{short:["n","E","r","s","z"],long:["regexp-extended","quiet","silent","separate","null-data","zero-terminated"],repeatable:["e","expression","f","file"]}),s=i.flags.has("z")||i.flags.has("null-data")||i.flags.has("zero-terminated")?"\0":`
224
+ `,u=a1(n,s),a=Ek(i,e,n,u.openWrite);return a===null?x(Io):a.error?a.error:(Object.assign(a,{output:u,delimiter:s,hold:{text:"",terminator:s},regexState:{last:null},budget:{steps:0}}),a.stdin=lr(a.stdin,n),o===null?mu(a,i.flags,n):u1(a,i.flags,n,o,(l,f)=>mu(l,f,n,!0)))}catch(r){return Fo(r)}}function Ek({order:e,positional:t},n,r,o){let i=[],s={openWrite:o},u=!1,a=!1;for(let{name:l,value:f}of e){if((l==="E"||l==="r"||l==="regexp-extended")&&(u=!0),!["e","expression","f","file"].includes(l))continue;a=!0;let c=f;if(l==="f"||l==="file"){n=lr(n,r);let d=n,p=r.io.bufferReads(()=>st("sed",[f],r,d));if(p.failed)return{error:x(p.stderr,4)};c=p.inputs[0].content,p.inputs[0].shared&&(n="")}for(let d of pu(c,u,r.locale,s))i.push(d)}return a?{commands:hu(i,s),files:t,stdin:n}:t.length===0?null:{commands:hu(pu(t[0],u,r.locale,s),s),files:t.slice(1),stdin:n}}var $k=new Set(["-b","-c","-g","-k","-p","-r","-s","-t","-u","-v","-w","-x","-G","-N","-O","-R","-S","-o"]),Nk=new Set(["-nt","-ot","-ef","<",">"]),dr={__proto__:null,"-eq":(e,t)=>e===t,"-ne":(e,t)=>e!==t,"-lt":(e,t)=>e<t,"-le":(e,t)=>e<=t,"-gt":(e,t)=>e>t,"-ge":(e,t)=>e>=t},Ak=String(ue).length,Ok=new Set(["/dev/stdin","/dev/stdout","/dev/stderr"]);function E1(e,t,n){return N1("test",t,n)}function $1(e,t,n){return t.at(-1)!=="]"?x("[: missing `]'",2):N1("[",t.slice(0,-1),n)}function N1(e,t,n){try{return{...F(),exitCode:gu(t,n)?0:1}}catch(r){return K(r,e,`${e}: ${r.message}`,2)}}function gu(e,t){let[n,r,o]=e;if(e.length===0)return!1;if(e.length===1)return n!=="";if(e.length===2){if(n==="!")return r==="";if(n==="-n")return r!=="";if(n==="-z")return r==="";if(["-a","-e","-f","-d","-h","-L"].includes(n))return wu(n,r,t);throw $k.has(n)&&cr(n),new Error(`${n}: unary operator expected`)}if(e.length===3){if(r==="="||r==="==")return n===o;if(r==="!=")return n!==o;if(Object.hasOwn(dr,r))return dr[r](v1(n),v1(o));Nk.has(r)&&cr(r),(r==="-a"||r==="-o")&&cr("compound expressions")}if(e.length<=4){if(n==="!")return!gu(e.slice(1),t);if(n==="("&&e.at(-1)===")")return gu(e.slice(1,-1),t)}throw e.some(i=>["-a","-o","!","(",")"].includes(i))&&cr("compound expressions"),new Error(e.length>3?"too many arguments":`${r}: binary operator expected`)}function v1(e){let t=/^[ \t\n\r\f\v]*([+-]?)(\d+)[ \t]*$/u.exec(e);if(t&&t[0].length===e.length){let n=t[2].replace(/^0+/u,"")||"0";if(n.length<=Ak){let r=BigInt(t[1]+n);if(r>=ot&&r<=ue)return r}}throw new Error(`${e}: integer expression expected`)}function wu(e,t,n){let r={isDir:u=>u==="/dev"||u==="/dev/fd"||n.fs.isDir(u),isFile:u=>u==="/dev/null"||S1(u)||n.fs.isFile(u),isLink:u=>n.fs.isLink?.(u)===!0,readLink:u=>n.fs.readLink?.(u)},o=e==="-h"||e==="-L",{path:i,error:s}=E(n.cwd,t,r,{follow:!o});return s?!1:(S1(i)&&cr("stream device metadata"),o?r.isLink(i):e==="-e"||e==="-a"?!0:e==="-d"?r.isDir(i):i!=="/dev/null"&&n.fs.isFile(i))}function S1(e){return Ok.has(e)||/^\/dev\/fd\/\d+$/u.test(e)}function cr(e){throw new b("feature",e,`${e} is not supported`)}function C1(e){let t=e.replace(/^[ \t\n\r\v\f]+|[ \t\n\r\v\f]+$/gu,""),n=/^[+-]?\d+$/u.test(t)?BigInt(t):null,r=n!==null&&n>=ot&&n<=ue?n:null;return{arg:t,n:r}}var mn=e=>({...e,halt:!0});function Ck(e,t,n){let r=t[0]==="--"?t.slice(1):t;if(r.length===0)return mn({...F(),exitCode:n.lastExit});let{arg:o,n:i}=C1(r[0]);return i===null?mn(x(`exit: ${o}: numeric argument required`,2)):r.length>1?mn(x("exit: too many arguments")):mn({...F(),exitCode:Number((i%256n+256n)%256n)})}function A1(e){return(t,n,r)=>{let o=n[0]==="--"?n.slice(1):n;if(o.length>1)return mn(x(`${e}: too many arguments`));let{arg:i,n:s}=C1(o[0]??"1");return s===null?mn(x(`${e}: ${i}: numeric argument required`,128)):s<=0?{...x(`${e}: ${i}: loop count out of range`),control:r.loopDepth?{type:"break",levels:r.loopDepth}:void 0}:r.loopDepth===0?x(`${e}: only meaningful in a \`for\`, \`while\` or \`until\` loop`,0):{...F(),control:{type:e,levels:Number(s>BigInt(r.loopDepth)?BigInt(r.loopDepth):s)}}}}function Ik(e,t,n){let r=t[0]==="--",o=r?t.slice(1):t;if(o.length===0||!r&&o[0]==="-p")return v("option","export","-p","export: listing the environment is not supported (there is none)");let i="";for(let s of o){let u=s.indexOf("="),a=u>0&&s[u-1]==="+",l=u===-1?s:s.slice(0,a?u-1:u);if(!r&&s.startsWith("-"))return v("option","export",s,`export: option \`${s}\` is not supported`);if(!Lt.test(l)){i+=`export: \`${l}': not a valid identifier
225
+ `;continue}u!==-1?n.vars.set(l,(a?dd(l,n):"")+s.slice(u+1)):n.vars.has(l)&&n.vars.set(l,n.vars.get(l))}return{stdout:"",stderr:i,exitCode:i?1:0}}function Tk(e,t,n){let r=t[0]==="-v"?1:0,o=t[r]==="--";o&&r++;let i=t.slice(r);for(let s of i){if(!o&&s.startsWith("-"))return v("option","unset",s,`unset: option \`${s}\` is not supported`);if(s.includes("["))return v("feature","unset","array subscript","unset: array subscripts are not supported");if(s==="LANG")return v("feature","unset","LANG",`unset: LANG: ${Rr}`);n.vars.delete(s)}return F()}function Fk(e,t,n){let r=null;for(let o=0;o<t.length;o++){let i=t[o];if(i==="-e"||i==="+e")r=i==="-e";else if((i==="-o"||i==="+o")&&t[o+1]==="errexit")r=i==="-o",o++;else return O1()}return r===null?O1():(n.errexit=r,F())}var O1=()=>v("feature","set","set","set: `set` is supported only as `set -e` or `set +e`",127),yu={exit:Ck,break:A1("break"),continue:A1("continue"),export:Ik,set:Fk,unset:Tk},I1=new Map([["return"," (there are no shell functions)"],["source"," (nothing can be sourced into this shell)"],[".","","`.` (source)"],"eval","exec",["read"," (there is no interactive input)"],["shift"," (there are no positional parameters)"],"shopt",["local"," (there are no shell functions)"],["declare","; use `NAME=value`"],["typeset","; use `NAME=value`"],["readonly","; use `NAME=value`"],["let"," (no arithmetic)"],["type","; use `which`"],["command","; run the command directly"],"builtin","hash","alias","unalias","trap",["wait"," (nothing runs in the background)"],["kill"," (there are no processes)"],["jobs"," (there are no processes)"],["bg"," (there are no processes)"],["fg"," (there are no processes)"],["disown"," (there are no processes)"],"suspend","times","ulimit","umask",["pushd","; use `cd`"],["popd","; use `cd -`"],"dirs","history","help","logout","getopts","mapfile","readarray","caller","enable","compgen","complete","bind","fc"].map(e=>{let[t,n="",r="`"+t+"`"]=Array.isArray(e)?e:[e];return[t,r+" is not supported"+n]}));function T1(e,t){let n=0,r=!0,o=!1;for(;n<t.length&&/^-[neE]+$/u.test(t[n]);n++)for(let s of t[n].slice(1))s==="n"?r=!1:o=s==="e";let i=t.slice(n).join(" ");if(o){let s=Lk(i);i=s.text,s.stop&&(r=!1)}return F(r?i+`
226
+ `:i)}function Lk(e){let t={a:7,b:8,e:27,E:27,f:12,n:10,r:13,t:9,v:11,"\\":92},n=[],r=i=>{for(let s of A(i))n.push(s)},o=i=>({text:W(Uint8Array.from(n)),stop:i});for(let i=0;i<e.length;i++){if(e[i]!=="\\"||i+1>=e.length){let l=e.indexOf("\\",i+1),f=l<0?e.length:l;r(e.slice(i,f)),i=f-1;continue}let s=e[++i];if(s==="c")return o(!0);if(s in t){n.push(t[s]);continue}if(s==="0"){let l="";for(;l.length<3&&/[0-7]/u.test(e[i+1]??"");)l+=e[++i];n.push(l===""?0:parseInt(l,8)&255);continue}let u=s==="x"?2:s==="u"?4:s==="U"?8:0;if(u>0&&/[0-9a-fA-F]/u.test(e[i+1]??"")){let l="";for(;l.length<u&&/[0-9a-fA-F]/u.test(e[i+1]??"");)l+=e[++i];let f=parseInt(l,16);if(s==="x")n.push(f);else{if(!Ze(f))throw new b("feature","echo Unicode escape","echo: escapes outside Unicode scalar values are not supported");r(String.fromCodePoint(f))}continue}let a=i+Le(e,i);r("\\"+e.slice(i,a)),i=a-1}return o(!1)}var F1={a:7,b:8,e:27,E:27,f:12,n:10,r:13,t:9,v:11,"\\":92};function bu(e,t,n,r){let o=e[t+1],i=t+2;if(o===void 0)return{bytes:[92],end:t+1};if(n&&o==="c")return{bytes:[],end:i,stop:!0};if(Object.hasOwn(F1,o))return{bytes:[F1[o]],end:i};if(!n&&`'"?`.includes(o))return{bytes:[o.codePointAt(0)],end:i};if(/[0-7]/u.test(o)){let u=n&&o==="0"?4:3;for(;i<t+1+u&&/[0-7]/u.test(e[i]??"");)i++;return{bytes:[parseInt(e.slice(t+1,i),8)&255],end:i}}let s=o==="x"?2:o==="u"?4:o==="U"?8:0;if(s){for(;i<t+2+s&&/[\da-fA-F]/u.test(e[i]??"");)i++;if(i===t+2||o!=="x"&&i!==t+2+s)return r.stderr+=`printf: missing hexadecimal number in escape
227
+ `,r.failed=!0,r.stop=!0,{bytes:[],end:e.length,stop:!0};let u=parseInt(e.slice(t+2,i),16);if(o==="x")return{bytes:[u],end:i};if(!Ze(u))throw new b("feature","Unicode escape","escapes outside Unicode scalar values are not supported");if(r.byteLocale&&u>127)throw new b("feature","Unicode escape in C locale","non-ASCII Unicode escapes in the C locale are not supported");return{bytes:A(String.fromCodePoint(u)),end:i}}return i=t+1+Le(e,t+1),{bytes:A(e.slice(t,i)),end:i}}function L1(e,t){let n=[];for(let r=0;r<e.length;)if(e[r]==="\\"){let o=bu(e,r,!0,t);for(let i of o.bytes)n.push(i);if(r=o.end,o.stop){t.stop=!0;break}}else{let o=e.indexOf("\\",r),i=o<0?e.length:o;for(let s of A(e.slice(r,i)))n.push(s);r=i}return Uint8Array.from(n)}var Rk=/^%([-+ #0']*)(\d+|\*)?(?:\.(-?\d+|\*)?)?([hlLjzt]*)(.)?/su,Mk=8e6;function _1(e,t,n){let r=t[0]==="--"?t.slice(1):t;if(r.length===0)return pe("printf format [arguments]");if(t[0]!=="--"&&/^-./su.test(t[0])){let s=t[0].startsWith("-v")?"-v":t[0];return v("option","printf",s,`printf: option ${s} is not supported`,2)}let o={args:r.slice(1),index:0,chunks:[],size:0,stderr:"",failed:!1,stop:!1,byteLocale:le(n)},i;try{if(r.some(s=>s.includes("\0")))throw new b("feature","NUL in argument","NUL bytes in command arguments are not supported");do{let s=o.index;if(Dk(r[0],o),o.index===s)break}while(!o.stop&&o.index<o.args.length);i=F()}catch(s){i=K(s,"printf",`printf: ${s.message}`)}try{i.stdout=Pk(o)}catch(s){let u=O(i);u&&n.unsupported.add(u,"printf");let a=K(s,"printf",`printf: ${s.message}`);a.stderr=i.stderr+a.stderr,i=a}return i.stderr=o.stderr+i.stderr,o.failed&&i.exitCode===0&&(i.exitCode=1),i}function zt(e,t){if(e.size+t.length>Mk)throw new b("feature","format size limit","formatted output exceeds the output limit");t.length&&e.chunks.push(t),e.size+=t.length}function Pk(e){let t=new Uint8Array(e.size),n=0;for(let r of e.chunks)t.set(r,n),n+=r.length;return W(t)}var xu=e=>e.args[e.index++];function Dk(e,t){for(let n=0;n<e.length&&!t.stop;)if(e[n]==="\\"){let r=bu(e,n,!1,t);zt(t,r.bytes),n=r.end}else if(e[n]==="%"){if(e[n+1]==="%"){zt(t,[37]),n+=2;continue}let r=Bk(e.slice(n),t);n+=r.length;let o=xu(t);if("sbc".includes(r.conv))Uk(o??"",r,t);else{let i="diouxX".includes(r.conv)?yo(wo(o,"ouxX".includes(r.conv),t),r):Ud(o,r,t);zt(t,A(i))}}else{let r=n+1;for(;r<e.length&&e[r]!=="%"&&e[r]!=="\\";)r++;zt(t,A(e.slice(n,r))),n=r}}function Bk(e,t){if(/^%[-+ #0'\d.*]*\$/u.test(e))throw new b("feature","positional format arguments","positional format arguments are not supported");let n=Rk.exec(e),[,r,o,i,s,u]=n;if(u===void 0)throw new Error("missing format character");if(!"sbcdiouxXeEfFgG".includes(u))throw"aAqQnCS(p%I".includes(u)?new b("feature","%"+u,`format %${u} is not supported`):new Error(`invalid format character: ${u}`);if(s&&"sbc".includes(u))throw new b("feature","format length modifier","length modifiers on string and character formats are not supported");let a={conv:u,length:n[0].length,minus:r.includes("-"),plus:r.includes("+"),space:r.includes(" "),zero:r.includes("0"),alt:r.includes("#"),width:Number(o==="*"?wo(xu(t),!1,t):o??0),precision:i==="*"?Number(wo(xu(t),!1,t)):i===void 0?n[0].includes(".")?0:null:Number(i)};if(o==="*"&&Math.abs(a.width)>2147483647||i==="*"&&(a.precision<-2147483648||a.precision>2147483647))throw new b("feature","format size limit","star width or precision outside the signed 32-bit range is not supported");if(a.width<0&&(a.minus=!0,a.width=-a.width),a.precision<0&&(a.precision=null),a.width>Ce||a.precision>Ce)throw new b("feature","format size limit","format width or precision exceeds the output limit");return a}function Uk(e,t,n){let r=t.conv==="b"?L1(e,n):A(e);t.conv==="c"?r=r.length?r.subarray(0,1):new Uint8Array(1):t.precision!==null&&(r=r.subarray(0,t.precision));let o=Math.max(0,t.width-r.length),i=o?new Uint8Array(o).fill(32):[];t.minus||zt(n,i),zt(n,r),t.minus&&zt(n,i)}function jk(e,t){if(!e.includes(`
228
+ `))return e;let n=le(t);if(!n&&/[\u0080-\u009F\u2028\u2029]/u.test(e))throw new b("feature","filename quoting","wc: locale-sensitive filename quoting is not supported");let r=n?Array.from(A(e),u=>String.fromCodePoint(u)):[...e],o={7:"\\a",8:"\\b",9:"\\t",10:"\\n",11:"\\v",12:"\\f",13:"\\r"},i=!1,s="'";for(let u of r){let a=u.codePointAt(0);a<32||a===127||n&&a>127?(i||(s+="'$'"),s+=o[a]??"\\"+a.toString(8).padStart(3,"0"),i=!0):(u==="'"?s+="'\\''":s+=(i?"''":"")+u,i=!1)}return s+"'"}function R1(e,t,n,r,o){let i=[];for(let s of["l","w","m","c"])n[s]&&i.push(String(e[s]).padStart(r));return i.join(" ")+(t?" "+jk(t,o):"")}var Wk=["**=","**","++","--","+=","-=","*=","/=","%=","^=","==","!=","<=",">=","&&","||","!~",">>","|&","+","-","*","/","%","^","!",">","<","|","?",":","~","$","=","(",")","{","}","[","]",";",","],qk=new Set(["number","string","name","builtin"]),zk=new Set([")","]","++","--"]),Hk=/^(?:0[xX][0-9a-fA-F]+|\d+\.?\d*(?:[eE][+-]?\d+)?|\.\d+(?:[eE][+-]?\d+)?)/u,Gk=e=>e!==void 0&&/[A-Za-z_]/u.test(e),Xk=e=>e!==void 0&&/[A-Za-z0-9_]/u.test(e),M1=e=>e!==void 0&&e>="0"&&e<="9";function B1(e,t=null){let n=[],r=1,o=0,i=(u,a)=>n.push({type:u,value:a,line:r}),s=()=>{let u=n.at(-1);return u?qk.has(u.type)?!1:!(u.type==="punct"&&zk.has(u.value)):!0};for(;o<e.length;){let u=e[o];if(u===`
229
+ `){n.at(-1)?.type!=="newline"&&i("newline",`
230
+ `),r++,o++;continue}if(u===" "||u===" "||u==="\r"){o++;continue}if(u==="\\"&&(e[o+1]===`
231
+ `||e[o+1]==="\r"&&e[o+2]===`
232
+ `)){o+=e[o+1]===`
233
+ `?2:3,r++;continue}if(u==="#"){for(;o<e.length&&e[o]!==`
234
+ `;)o++;continue}if(u==='"'){let f=U1(e,o+1,t,r);i("string",f.value),o=f.end;continue}if(u==="/"&&s()){let f=Vk(e,o+1,r);i("regex",f.value),o=f.end;continue}if(M1(u)||u==="."&&M1(e[o+1])){let f=Zk(e,o);i("number",f.value),o=f.end;continue}if(Gk(u)){let f=o+1;for(;Xk(e[f]);)f++;let c=e.slice(o,f);if(e.slice(f,f+2)==="::")throw new $("namespaces are not supported",r,"namespaces");o=f,Of.has(c)?i("keyword",c==="func"?"function":c):Cf.has(c)?i("builtin",c):i(e[f]==="("?"funcname":"name",c);continue}let a=o,l=Wk.find(f=>e.startsWith(f,a));if(u==="@")throw new $("typed regexes, indirect calls and source directives are not supported",r,"@ extensions");if(!l)throw new $(`unexpected character \`${u}\``,r);i("punct",l),o+=l.length}return i("eof",""),n}function Zk(e,t){let n=Hk.exec(e.slice(t))[0],r=n;return/^0[xX]/u.test(n)?r=String(Number.parseInt(n.slice(2),16)):/^0[0-7]+$/u.test(n)&&(r=String(Number.parseInt(n,8))),{value:r,end:t+n.length}}var P1={__proto__:null,n:`
235
+ `,t:" ",r:"\r",a:"\x07",b:"\b",f:"\f",v:"\v",'"':'"',"\\":"\\"};function Yk(e,t,n){let r=e[t+1];if(r===void 0)return{text:"\\",end:t+1};if(r in P1)return{text:P1[r],end:t+2};if(r>="0"&&r<="7"){let o=t+1;for(;o<t+4&&e[o]>="0"&&e[o]<="7";)o++;return{byte:Number.parseInt(e.slice(t+1,o),8)&255,end:o}}if(r==="x"&&/[0-9a-fA-F]/u.test(e[t+2]??"")){let o=t+2;for(;o<t+4&&/[0-9a-fA-F]/u.test(e[o]??"");)o++;return{byte:Number.parseInt(e.slice(t+2,o),16),end:o}}if(r.codePointAt(0)>127)throw new $("non-ASCII characters after an escape are not supported",null,"non-ASCII string escape");return n?.(`escape sequence \`\\${r}' treated as plain \`${r}'`),{text:r,end:t+2}}function U1(e,t,n,r=null){let o=[],i=t;for(;i<e.length;){let s=e[i];if(r!==null){if(s==='"')return{value:W(Uint8Array.from(o)),end:i+1};if(s===`
236
+ `)break;if(s==="\\"&&e[i+1]===`
237
+ `){i+=2;continue}}if(s==="\\"){let u=Yk(e,i,n);D1(o,u),i=u.end}else{let u=String.fromCodePoint(e.codePointAt(i));D1(o,{text:u}),i+=u.length}}if(r!==null)throw new $("unterminated string",r);return{value:W(Uint8Array.from(o)),end:i}}function Vk(e,t,n){let r=t,o=!1;for(;r<e.length;){let i=e[r];if(i===`
238
+ `)break;if(i==="\\"){r+=2;continue}if(o){if(i==="["&&e[r+1]===":"){let s=e.indexOf(":]",r+2);if(s!==-1){r=s+2;continue}}i==="]"&&(o=!1),r++;continue}if(i==="["){o=!0,r++,e[r]==="^"&&r++,e[r]==="]"&&r++;continue}if(i==="/")return{value:e.slice(t,r),end:r+1};r++}throw new $("unterminated regexp",n)}function pr(e,t=null){return U1(e,0,t).value}function D1(e,t){if(t.byte===void 0)for(let n of A(t.text))e.push(n);else e.push(t.byte)}var Kk=new Set(["=","+=","-=","*=","/=","%=","^=","**="]),j1=new Set(["<","<=","==","!=",">",">="]),mr=e=>e.type==="var"||e.type==="index"||e.type==="field";function W1(e){let t=e.tok;return z1(e)||t.type==="regex"||t.type==="keyword"&&t.value==="getline"||t.type==="punct"&&["!","-","+"].includes(t.value)}function gn(e,t){let n=[$e(e,t)];for(;e.accept(",");)e.skipNewlines(),n.push($e(e,t));return n}function $e(e,t){let n=Jk(e,t),r=e.tok;if(r.type==="punct"&&Kk.has(r.value)){mr(n)||e.fail(`cannot assign to ${n.type==="regex"?"a regex":"a non-variable"} (left side of \`${r.value}\`)`),e.next();let o=$e(e,t);return{type:"assign",op:r.value==="**="?"^=":r.value,target:n,value:o}}return n}function Jk(e,t){let n=ku(e,t);if(!e.accept("?"))return n;e.skipNewlines();let r=$e(e,t);return e.skipNewlines(),e.expect(":"),e.skipNewlines(),{type:"cond",test:n,consequent:r,alternate:$e(e,t)}}var Qk=[["or",["||"]],["and",["&&"]],["in",["in"]],["match",["~","!~"]],["compare",[...j1]],["concat",[]],["binary",["+","-"]],["binary",["*","/","%"]]],ev=new Map(Qk.flatMap(([e,t],n)=>t.map(r=>[r,{type:e,precedence:n}]))),tv={type:"concat",precedence:5};function ku(e,t,n=0){let r=Po(e,t),o=1/0;for(;;){let i=e.tok;n<=4&&o>4&&!t.noGt&&(e.is("|")||e.is("|&"))&&e.fail(`command pipelines (\`"cmd" | getline\`) are not supported: ${Qr}`,'"cmd" | getline');let s=z1(e)?tv:i.type==="punct"||i.type==="keyword"&&i.value==="in"?ev.get(i.value):void 0;if(!s||s.precedence<n||s.precedence>o||t.noGt&&e.is(">"))return r;let{type:u,precedence:a}=s,l=u==="concat"?null:e.next().value;if(o=a,(u==="or"||u==="and")&&e.skipNewlines(),u==="in"){r={type:u,keys:[r],array:q1(e)};continue}let f=ku(e,t,a+1);(l==="/"||l==="%")&&hr(f)===0&&hr(r)!==null&&e.fail(l==="/"?"division by zero attempted":"division by zero attempted in `%`"),u==="compare"&&nv(e,t)&&e.fail(`comparison operators do not chain (\`a ${l} b ${e.tok.value} c\`); parenthesize the first comparison`),u==="binary"||u==="compare"?r={type:u,op:l,left:r,right:f}:u==="match"?r={type:u,negate:l==="!~",left:r,right:f}:r={type:u,left:r,right:f}}}function q1(e){return e.tok.type!=="name"&&e.fail(`expected an array name after \`in\` but found \`${e.tok.value}\``),e.next().value}var nv=(e,t)=>e.tok.type==="punct"&&j1.has(e.tok.value)&&!(t.noGt&&e.tok.value===">");function z1(e){let t=e.tok;return t.type==="number"||t.type==="string"||t.type==="name"||t.type==="funcname"||t.type==="builtin"?!0:t.type==="punct"&&["$","(","++","--"].includes(t.value)}function H1(e,t){return ku(e,t,5)}function hr(e){if(e.type==="num")return e.value;if(e.type==="neg"||e.type==="plus"){let r=hr(e.expr);return r===null?null:e.type==="neg"?-r:r}if(e.type!=="binary")return null;let t=hr(e.left),n=hr(e.right);return t===null||n===null?null:eo(e.op,t,n)}var rv={__proto__:null,"!":"not","-":"neg","+":"plus"};function Po(e,t,n=!1){if(n&&(e.is("$")||e.is("++")||e.is("--")))return Do(e,t);let r=e.tok.type==="punct"&&rv[e.tok.value];return r?(e.next(),{type:r,expr:Po(e,t,n)}):n?X1(e,t):ov(e,t)}function ov(e,t){let n=G1(e,t);return!e.is("^")&&!e.is("**")?n:(e.next(),{type:"binary",op:"^",left:n,right:Po(e,t)})}function G1(e,t){let n=Do(e,t);for(;(e.is("++")||e.is("--"))&&mr(n);)n={type:"postinc",op:e.next().value,target:n};return n}function Do(e,t){if(e.accept("$"))return{type:"field",index:Po(e,t,!0)};if(e.is("++")||e.is("--")){let n=e.next().value,r=Do(e,t);return mr(r)||e.fail(`\`${n}\` needs a variable, field or array element`),{type:"preinc",op:n,target:r}}return X1(e,t)}function X1(e,t){let n=e.tok;switch(n.type){case"number":return e.next(),{type:"num",value:Number(n.value)};case"string":return e.next(),{type:"str",value:n.value};case"regex":return e.next(),{type:"regex",source:n.value,re:iv(e,n.value)};case"name":return sv(e);case"funcname":return uv(e);case"builtin":return lv(e);case"keyword":return n.value==="getline"?fv(e,t):e.unexpected();case"punct":return n.value==="("?av(e):e.unexpected();default:return e.unexpected()}}function iv(e,t){try{return Re(t,!1,n=>e.warn(n))}catch(n){return e.fail(n.message,n.gap??null)}}function vu(e){if(!e.accept("["))return null;let t=gn(e,{});return e.expect("]"),e.is("[")&&e.fail("arrays of arrays are not supported","arrays of arrays"),t}function sv(e){let t=e.next().value,n=vu(e);return n!==null?{type:"index",name:t,subs:n}:(e.is("(")&&e.funcs.has(t)&&e.fail(`function \`${t}\` called with space between name and \`(\``),{type:"var",name:t})}function uv(e){return{type:"call",name:e.next().value,args:Z1(e)}}function Z1(e){e.expect("(");let t=e.is(")")?[]:gn(e,{});return e.expect(")"),t}function av(e){let t=0;for(;e.parens.get(e.i+1)===e.parens.get(e.i)-1;)e.next(),t++;e.next();let n=gn(e,{});if(e.expect(")"),n.length===1){for(;t-- >0;)e.expect(")");return n[0]}return e.isKw("in")||e.fail("a parenthesized list must be followed by `in ARRAY`"),e.next(),{type:"in",keys:n,array:q1(e)}}function lv(e){let t=e.next().value;if(Jr.has(t)&&e.fail(Jr.get(t),`${t}()`),!e.is("(")){if(t==="length")return{type:"builtin",name:t,args:[]};e.fail(`\`${t}\` needs parentheses: ${t}(...)`)}let n=Z1(e),[r,o]=Yi[t];return(n.length<r||n.length>o)&&e.fail(`${t}() called with ${n.length} argument${n.length===1?"":"s"}; it takes ${r===o?r:`${r} to ${o===1/0?"any number":o}`}`),(t==="sub"||t==="gsub")&&n[2]&&!mr(n[2])&&e.fail(`${t}(): substitution into a temporary value is not supported`,"substitution into temporary value"),t==="split"&&n[1].type!=="var"&&e.fail("split(): second argument must be an array name"),t==="match"&&n[2]&&n[2].type!=="var"&&e.fail("match(): third argument must be an array name"),{type:"builtin",name:t,args:n}}function fv(e,t){e.next();let n=null;(e.tok.type==="name"||e.is("$"))&&(n=Do(e,t),mr(n)||e.fail("getline: target must be a variable, field or array element"));let r=null;return e.accept("<")&&(r=G1(e,t)),{type:"getline",target:n,file:r}}var cv=new Set(["/dev/stdout","/dev/stderr","/dev/null"]),Su=class{constructor(t,n){this.toks=t,this.i=0,this.warnings=n,this.funcs=new Set,this.parens=new Map;let r=[];for(let o=0;o+1<t.length;o++){let i=t[o],s=t[o+1];i.type==="punct"&&(i.value==="("?r.push(o):i.value===")"&&r.length>0&&this.parens.set(r.pop(),o)),i.type==="keyword"&&i.value==="function"&&(s.type==="name"||s.type==="funcname")&&this.funcs.add(s.value)}this.loopDepth=0,this.switchDepth=0,this.context="main"}get tok(){return this.toks[this.i]}peek(t){return this.toks[Math.min(this.i+t,this.toks.length-1)]}is(t,n="punct"){return this.tok.type===n&&this.tok.value===t}isKw(t){return this.is(t,"keyword")}next(){return this.toks[this.i++]}accept(t,n="punct"){return this.is(t,n)?this.next():null}expect(t,n="punct"){return this.is(t,n)||this.fail(`expected \`${t}\` but found ${Ht(this.tok)}`),this.next()}skipNewlines(){for(;this.tok.type==="newline";)this.i++}skipTerminators(){for(;this.tok.type==="newline"||this.is(";");)this.i++}fail(t,n=null){throw new $(t,this.tok.line,n)}warn(t){this.warnings.push(t)}unexpected(){this.fail(`unexpected ${Ht(this.tok)}`)}};function Ht(e){return e.type==="eof"?"end of program":e.type==="newline"?"newline":e.type==="string"?`string "${e.value}"`:e.type==="regex"?`regex /${e.value}/`:`\`${e.value}\``}var Y1={__proto__:null,BEGIN:"begin",END:"end",BEGINFILE:"beginFile",ENDFILE:"endFile"};function J1(e){let t=[],n=new Su(B1(e,o=>t.push(o)),t),r={begin:[],end:[],beginFile:[],endFile:[],rules:[],functions:new Map,warnings:t};for(n.skipNewlines();n.tok.type!=="eof";)n.is(";")&&n.fail("each rule must have a pattern or an action part"),dv(n,r),n.accept(";"),n.skipNewlines();return r}function dv(e,t){if(e.isKw("function")){pv(e,t);return}if(e.tok.type==="keyword"&&e.tok.value in Y1){let i=e.next().value;e.is("{")||e.fail(`${i} requires an action: ${i} { ... }`),t[Y1[i]].push(...gr(e,i.toLowerCase()));return}if(e.is("{")){t.rules.push({pattern:null,action:gr(e,"main")});return}let n=$e(e,{}),r=n;e.accept(",")&&(e.skipNewlines(),r={type:"range",from:n,to:$e(e,{})});let o=e.is("{")?gr(e,"main"):null;o===null&&!(e.tok.type==="newline"||e.tok.type==="eof"||e.is(";"))&&e.unexpected(),t.rules.push({pattern:r,action:o})}function pv(e,t){e.next();let n=e.tok;n.type==="builtin"&&e.fail(`cannot redefine builtin function \`${n.value}\``),n.type!=="name"&&n.type!=="funcname"&&e.fail(`expected a function name but found ${Ht(n)}`),e.next();let r=n.value;t.functions.has(r)&&e.fail(`function \`${r}\` is defined twice`),e.expect("(");let o=[];for(;!e.is(")");){let i=e.tok;if(i.type!=="name"&&e.fail(`expected a parameter name but found ${Ht(i)}`),(i.value===r||o.includes(i.value))&&e.fail(`duplicate parameter \`${i.value}\` in function \`${r}\``),o.push(e.next().value),!e.accept(","))break;e.skipNewlines()}e.expect(")"),e.skipNewlines(),t.functions.set(r,{params:o,body:gr(e,"function")})}function gr(e,t=e.context){let n=e.context;e.context=t,e.expect("{");let r=[];for(e.skipTerminators();!e.is("}");)e.tok.type==="eof"&&e.fail("missing `}` at end of program"),r.push(Eu(e)),e.skipTerminators();return e.next(),e.context=n,r}function wr(e){if(e.is(";")||e.tok.type==="newline"){e.next();return}e.is("}")||e.tok.type==="eof"||e.unexpected()}var hv={__proto__:null,if:mv,while:gv,do:wv,for:yv,switch:bv,break:e=>wn(e,"break"),continue:e=>wn(e,"continue"),next:e=>wn(e,"next"),nextfile:e=>wn(e,"nextfile"),exit:e=>wn(e,"exit"),return:e=>wn(e,"return"),delete:kv,print:e=>K1(e,"print"),printf:e=>K1(e,"printf")};function Eu(e){if(e.is("{"))return{type:"block",body:gr(e)};if(e.is(";"))return e.next(),{type:"empty"};let t=e.tok.type==="keyword"?hv[e.tok.value]:void 0;if(t)return t(e);let n=$e(e,{});return wr(e),{type:"expr",expr:n}}function yn(e,t){e.skipNewlines(),t&&e.loopDepth++;let n=Eu(e);return t&&e.loopDepth--,n}function Bo(e){e.next(),e.expect("(");let t=$e(e,{});return e.expect(")"),t}function mv(e){let t=Bo(e),n=yn(e,!1),r=e.i;return e.skipNewlines(),e.isKw("else")?(e.next(),{type:"if",test:t,consequent:n,alternate:yn(e,!1)}):(e.i=r,{type:"if",test:t,consequent:n,alternate:null})}function gv(e){return{type:"while",test:Bo(e),body:yn(e,!0)}}function wv(e){e.next();let t=yn(e,!0);e.skipTerminators(),e.isKw("while")||e.fail("`do` body must be followed by `while (...)`");let n=Bo(e);return wr(e),{type:"do",body:t,test:n}}function yv(e){if(e.next(),e.expect("("),e.tok.type==="name"&&e.peek(1).type==="keyword"&&e.peek(1).value==="in"&&e.peek(2).type==="name"&&e.peek(3).value===")"){let o=e.next().value;e.next();let i=e.next().value;return e.next(),{type:"forin",name:o,array:i,body:yn(e,!0)}}let t=e.is(";")?null:$e(e,{});e.expect(";"),e.skipNewlines();let n=e.is(";")?null:$e(e,{});e.expect(";"),e.skipNewlines();let r=e.is(")")?null:$e(e,{});return e.expect(")"),{type:"for",init:t,test:n,step:r,body:yn(e,!0)}}function bv(e){let t=Bo(e);e.skipNewlines(),e.expect("{");let n=[],r=new Set;for(e.switchDepth++,e.skipTerminators();!e.is("}");e.skipTerminators()){let o=null;e.accept("case","keyword")?o=xv(e):e.accept("default","keyword")||e.fail(`expected \`case\` or \`default\` in switch body but found ${Ht(e.tok)}`);let i=o===null?"default":o.type==="regex"?`/${o.source}/`:String(o.value);r.has(i)&&e.fail(`duplicate case values in switch body: ${i}`),r.add(i),e.expect(":");let s=[];for(e.skipTerminators();!e.is("}")&&!e.isKw("case")&&!e.isKw("default");)e.tok.type==="eof"&&e.fail("missing `}` at end of program"),s.push(Eu(e)),e.skipTerminators();n.push({test:o,body:s})}return e.switchDepth--,e.next(),{type:"switch",expr:t,cases:n}}function xv(e){let t=e.accept("-")?-1:(e.accept("+"),1),n=e.tok;return n.type==="number"?(e.next(),{type:"num",value:t*Number(n.value)}):t===1&&n.type==="string"?(e.next(),{type:"str",value:n.value}):t===1&&n.type==="regex"?(e.next(),{type:"regex",source:n.value,re:Re(n.value,!1,r=>e.warn(r))}):e.fail(`case value must be a number, string or regex constant, found ${Ht(n)}`)}function wn(e,t){t==="break"&&e.loopDepth===0&&e.switchDepth===0&&e.fail("`break` is not allowed outside a loop or switch"),t==="continue"&&e.loopDepth===0&&e.fail("`continue` is not allowed outside a loop"),t==="next"&&e.context!=="main"&&e.context!=="function"&&e.fail(`\`next\` cannot be used in a ${e.context.toUpperCase()} action`),t==="nextfile"&&(e.context==="begin"||e.context==="end"||e.context==="endfile")&&e.fail(`\`nextfile\` cannot be used in a ${e.context.toUpperCase()} action`),t==="return"&&e.context!=="function"&&e.fail("`return` is only allowed inside a function"),e.next();let n={type:t};return(t==="exit"||t==="return")&&(n.value=W1(e)?$e(e,{}):null),wr(e),n}function kv(e){e.next(),e.tok.type!=="name"&&e.fail(`\`delete\` needs an array name but found ${Ht(e.tok)}`);let t=e.next().value,n=vu(e);return wr(e),{type:"delete",name:t,subs:n}}var V1=e=>e.is(";")||e.is("}")||e.is(">")||e.is(">>")||e.is("|")||e.is("|&")||e.tok.type==="newline"||e.tok.type==="eof";function K1(e,t){e.next();let n=null;if(e.is("(")){let o=e.i;e.next();let i=e.is(")")?[]:gn(e,{});e.accept(")")&&V1(e)?n=i:e.i=o}n===null&&(n=V1(e)?[]:gn(e,{noGt:!0})),t==="printf"&&n.length===0&&e.fail("printf needs a format string");let r=null;return(e.is("|")||e.is("|&"))&&e.fail(`output pipes (\`${t} ... | "cmd"\`) are not supported: ${Qr}`,`${t} | "cmd"`),(e.accept(">")||e.accept(">>"))&&(r=H1(e,{noGt:!0}),r.type==="str"&&!cv.has(r.value)&&e.fail($u(r.value),`${t} > FILE`)),wr(e),{type:t,args:n,dest:r}}function $u(e){return`cannot redirect output to \`${e}\`: the filesystem is read-only (only /dev/stdout, /dev/stderr and /dev/null). To print a comparison, parenthesize it: print (a > b)`}var G=class{constructor(t){this.s=t,this.number=void 0,this.numeric=void 0}},yr="[ \\t\\n\\r\\f\\v]*",th="[+-]?(?:\\d+\\.?\\d*|\\.\\d+)(?:[eE][+-]?\\d+)?",vv=new RegExp(`^${yr}${th}${yr}$`,"u"),Sv=new RegExp(`^${yr}(${th})`,"u"),nh=new RegExp(`^${yr}([+-])(inf|nan)${yr}$`,"iu"),Nu=e=>vv.test(e)||nh.test(e);function Q1(e){let t=Sv.exec(e);if(t)return Number(t[1]);let n=nh.exec(e);return n?n[2].toLowerCase()==="nan"?Number.NaN:n[1]==="-"?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY:0}var Au=()=>new $("attempt to use an array in a scalar context");function z(e){if(typeof e=="number")return e;if(e===void 0)return 0;if(e instanceof G)return e.number??=Q1(e.s);if(typeof e=="string")return Q1(e);throw Au()}var Uo=new Map;function rh(e,t){if(Number.isNaN(e))throw new $("formatting signed NaN is not supported",null,"signed NaN");if(!Number.isFinite(e))return e<0?"-inf":"+inf";if(Number.isInteger(e))return Math.abs(e)<2**53?String(e):BigInt(e).toString();let n=Uo.get(t);if(n===void 0){Uo.size>64&&Uo.clear(),n=go(t);let r=n.filter(o=>typeof o!="string");if(r.length>1||r.some(o=>!"diouxXeEfFgG".includes(o.conv)||o.width==="*"||o.precision==="*"))throw new $("this numeric conversion format is not supported",null,"numeric conversion format");Uo.set(t,n)}return n.map(r=>typeof r=="string"?r:Wt(e,r)).join("")}var oh=e=>typeof e=="string"?e:e instanceof G?e.s:"%.6g",Ev=e=>oh(e.globals.get("CONVFMT")),$v=e=>oh(e.globals.get("OFMT"));function L(e,t){if(typeof e=="string")return pt(t,e);if(e instanceof G)return pt(t,e.s);if(typeof e=="number")return rh(e,Ev(t));if(e===void 0)return"";throw Au()}function pt(e,t){if(e.byteLocale&&/[\u0080-\u{10FFFF}]/u.test(t))throw new $("non-ASCII AWK text in a byte locale is not supported",null,"byte locale text");return t}function Gt(e,t=!1){return[...e].map(n=>{let r=t?n.toUpperCase():n.toLowerCase();if([...r].length!==1)throw new $("Unicode case expansion is not supported",null,"Unicode case mapping");return r}).join("")}function ih(e,t){return typeof e=="number"?rh(e,$v(t)):L(e,t)}var Ou=e=>e.numeric??=Nu(e.s),eh=e=>typeof e=="number"||e===void 0||e instanceof G&&Ou(e),qe=e=>Ne(e.globals.get("IGNORECASE"));function jo(e,t,n){if(eh(e)&&eh(t)){let i=z(e),s=z(t);return i<s?-1:i>s?1:i===s?0:Number.NaN}let r=L(e,n),o=L(t,n);return qe(n)&&(r=Gt(r),o=Gt(o)),j(r,o)}function Ne(e){if(typeof e=="number")return e!==0&&!Number.isNaN(e);if(typeof e=="string")return e!=="";if(e instanceof G)return Ou(e)?z(e)!==0:e.s!=="";if(e===void 0)return!1;throw Au()}var Cu=(e,t)=>Number.isSafeInteger(e)?String(e):L(e,t);function Iu(e){return e instanceof Map?"array":e===void 0?"untyped":typeof e=="number"?"number":e instanceof G&&Ou(e)?"strnum":"string"}function sh(e,t,n){let{text:r}=e;if(e.pos>=r.length)return null;if(t==="")return Nv(e);let o,i;if(t.length===1){let u=r.indexOf(t,e.pos);i=u===-1?r.length:u,o=u===-1?r.length:u+1}else{let u=es(r,Re(t,n),e.pos);i=u?.start??r.length,o=u?.end??r.length}let s=r.slice(e.pos,i);return e.pos=o,{rec:s,rt:r.slice(i,o)}}function Nv(e){let{text:t}=e,n=e.pos;for(;t[n]===`
239
+ `;)n++;if(n>=t.length)return e.pos=n,null;let r=/\n\n+/gu;r.lastIndex=n;let o=r.exec(t);if(!o){e.pos=t.length;let i=t.slice(n).replace(/\n+$/u,"");return{rec:i,rt:t.slice(n+i.length)}}return e.pos=o.index+o[0].length,{rec:t.slice(n,o.index),rt:o[0]}}function Lu(e,t,n,r){if(e==="")return[];if(t instanceof ct)return ts(e,t);if(t===" "){let i=e.replace(/^[ \t\n]+|[ \t\n]+$/gu,"");return i===""?[]:i.split(/[ \t\n]+/u)}if(t==="")return[...e];if(t.length===1&&(!n||t===`
240
+ `))return e.split(t);if(n&&t==="^")throw new $('paragraph splitting with FS="^" is not supported',null,"paragraph FS caret");let o=t.length===1?`[${"^$.[]|()*+?{}\\".includes(t)?"\\"+t:t}
241
+ ]`:t;return ts(e,Re(o,r))}function uh(e){let t=e.split(/[ \t]+/u).filter(Boolean);return t.map((n,r)=>{let o=/^(?:(\+?\d+):)?(\+?\d+|\*)$/u.exec(n),i=o?.[1]===void 0?0:Number(o[1]),s=o?.[2]==="*"?4294967295:Number(o?.[2]);if(!o||o[1]!==void 0&&i===0||i>4294967295||!(s>0&&s<=4294967295)||o[2]==="*"&&r!==t.length-1)throw new $(`invalid FIELDWIDTHS value \`${e}'`);return{skip:i,width:s}})}function Av(e,t){let n=[...e],r=[],o=0;for(let{skip:i,width:s}of t){if(o>=n.length)break;o+=i,r.push(n.slice(o,o+s).join("")),o+=s}return r}function Ov(e,t){let n=[],r=0;for(;r<e.length;){let o=t.search(e.slice(r));if(n.length>0&&o?.end===0&&(r+=Le(e,r),o=t.search(e.slice(r))),!o)break;n.push(e.slice(r+o.start,r+o.end)),r+=o.end}return n}function ah(e,t){let n=qe(e);return e.fieldMode==="FIELDWIDTHS"?Av(t,e.widths):e.fieldMode==="FPAT"?Ov(t,Re(L(e.globals.get("FPAT"),e),n,e.warn)):Lu(t,L(e.globals.get("FS"),e),L(e.globals.get("RS"),e)==="",n)}var Cv=/^([A-Za-z_][A-Za-z0-9_]*)=([^]*)$/u,Fu=e=>e!==void 0&&e.type==="exit",Wo=class{constructor(t,n){this.ctx=t,this.stdin=n,this.idx=1,this.src=null,this.sawFile=!1,this.exitSignal=void 0,this.readers=new Map}next(t){for(;this.exitSignal===void 0;){if(this.src){let n=sh(this.src,L(t.globals.get("RS"),t),qe(t));if(n!==null)return t.globals.set("NR",z(t.globals.get("NR"))+1),t.globals.set("FNR",z(t.globals.get("FNR"))+1),t.globals.set("RT",n.rt),n.rec;this.closeFile(t);continue}if(!this.open(t))return null}return null}open(t){for(;this.idx<Math.trunc(z(t.globals.get("ARGC")));){if(++t.steps>Wn)throw new $("input operand scan exceeded execution limit",null,"execution limit");let n=L(t.globals.get("ARGV").get(String(this.idx++)),t);if(n==="")continue;t.globals.set("ARGIND",this.idx-1);let r=Cv.exec(n);if(r){t.assign(r[1],new G(pr(r[2],t.warn)));continue}this.sawFile=!0;let{text:o,error:i}=this.readOperand(n);if(i==="Is a directory"){this.failFile(t,n,i),this.exitSignal===void 0&&t.warn(`command line argument \`${n}' is a directory: skipped`);continue}if(i){let s=this.failFile(t,n,i);if(s!==void 0&&s.type==="nextfile")continue;if(this.exitSignal!==void 0)return!1;throw new $(`${n}: ${i}`)}if(this.use(t,n,o))return!0}return this.sawFile||this.exitSignal!==void 0?!1:(this.sawFile=!0,this.use(t,"-",this.takeStdin()))}readOperand(t){if(t==="/dev/null")return{text:""};if(t==="-"||t==="/dev/stdin")return{text:t==="/dev/stdin"&&this.ctx.stdinFile?this.ctx.stdinOrigin:this.takeStdin()};let{path:n,error:r}=P(this.ctx,"awk",t);return this.ctx.fs.isDir(n)?{error:"Is a directory"}:r?{error:r}:{text:this.ctx.fs.readFile(n)}}takeStdin(){let t=this.stdin;return this.stdin="",q(this.ctx),t}use(t,n,r){this.src={text:r,pos:0},t.globals.set("FILENAME",n),t.globals.set("FNR",0),t.globals.set("ERRNO","");let o=t.fileRule("begin");return Fu(o)?(this.exitSignal=o,this.src=null,!1):o!==void 0&&o.type==="nextfile"?(this.closeFile(t),!1):(pt(t,r),!0)}failFile(t,n,r){if(t.globals.set("ERRNO",r),!t.hasFileRules)return;t.globals.set("FILENAME",n),t.globals.set("FNR",0);let o=t.fileRule("begin");return Fu(o)&&(this.exitSignal=o),o}closeFile(t){this.src=null;let n=t.fileRule("end");Fu(n)&&(this.exitSignal=n)}readNamed(t,n){let r=this.readers.get(n);if(!r){let{text:i,error:s}=this.readOperand(n);if(s)return t.globals.set("ERRNO",s),{status:-1};r={text:pt(t,i),pos:0},this.readers.set(n,r)}let o=sh(r,L(t.globals.get("RS"),t),qe(t));return o===null?{status:0}:(t.globals.set("RT",o.rt),{status:1,record:o.rec})}close(t,n){return this.readers.delete(n)?0:(t.globals.set("ERRNO","close of redirection that was never opened"),-1)}};var Iv=(e,t)=>({isRef:!0,scope:e,name:t}),br=e=>typeof e=="object"&&e!==null&&e.isRef===!0,xr=class extends Error{constructor(t){super(t.type),this.signal=t}},ch=e=>new $(`attempt to use array \`${e}\` in a scalar context`);function qo(e,t){let n=e.frame;return n!==void 0&&n.has(t)?n:e.globals}function Tv(e){let t=e;for(;br(t);)t=t.scope.get(t.name);return t instanceof Map?t:void 0}function bn(e,t){let n=qo(e,t).get(t);return br(n)?Tv(n):n}var Fv=new Set(["FS","FIELDWIDTHS","FPAT"]);function zo(e,t,n){let r=qo(e,t);if(r.get(t)instanceof Map)throw ch(t);if(r===e.globals){if(t==="NF"){_v(e,n);return}if(t==="FIELDWIDTHS"&&(e.widths=uh(L(n,e))),(t==="FPAT"||(t==="FS"||t==="RS")&&L(n,e).length>1)&&Re(L(n,e),qe(e),e.warn,e.tables),Fv.has(t)){e.fieldMode=t;let o=e.globals.get("PROCINFO");o instanceof Map&&o.set("FS",t)}}r.set(t,n)}function ht(e,t){let n=qo(e,t),r=t,o=n,i=o.get(r);if(i instanceof Map)return i;let s=br(i);for(;br(i);)o=i.scope,r=i.name,i=o.get(r);if(!(i instanceof Map)){if(i!==void 0)throw new $(`attempt to use scalar \`${r}\` as an array`);i=new Map,o.set(r,i)}return s&&n.set(t,i),i}function Ho(e,t,n=new G(t)){e.record=t,e.recordValue=n,e.fields=[void 0,...ah(e,t).map(r=>new G(r))],e.nf=e.fields.length-1,e.globals.set("NF",e.nf)}function dh(e){let t=L(e.globals.get("OFS"),e);e.record=e.fields.slice(1).map(n=>L(n,e)).join(t),e.recordValue=e.record}function ph(e,t){return t===0?e.recordValue:t<=e.nf?e.fields[t]:void 0}function Lv(e,t,n){if(t===0){let r=L(n,e);Ho(e,r,typeof n=="number"?r:n);return}for(;e.nf<t;)e.fields[++e.nf]="";e.fields[t]=n,e.globals.set("NF",e.nf),dh(e)}function _v(e,t){let n=Math.trunc(z(t));if(n<0)throw new $(`NF set to negative value ${n}`);for(;e.nf<n;)e.fields[++e.nf]="";e.fields.length=n+1,e.nf=n,e.globals.set("NF",n),dh(e)}function hh(e,t){let n=z(T(e,t));if(!(n>=0))throw new $(`attempt to access field ${Number.isNaN(n)?n:Math.trunc(n)}`);return Math.trunc(n)}function kr(e,t){if(t.length===1)return Cu(T(e,t[0]),e);let n=L(e.globals.get("SUBSEP"),e);return t.map(r=>Cu(T(e,r),e)).join(n)}function _u(e,t){return t.type==="var"?t:t.type==="index"?{type:"index",arr:ht(e,t.name),key:kr(e,t.subs)}:{type:"field",i:hh(e,t.index)}}function mh(e,t){return t.type==="var"?gh(bn(e,t.name),t.name):t.type==="index"?t.arr.get(t.key):ph(e,t.i)}function Ru(e,t,n){t.type==="var"?zo(e,t.name,n):t.type==="index"?t.arr.set(t.key,n):Lv(e,t.i,n)}function Mu(e,t,n){Ru(e,_u(e,t),n)}function lh(e,t,n){if(n===0&&(e==="/"||e==="%"))throw new $(e==="/"?"division by zero attempted":"division by zero attempted in `%`");return eo(e,t,n)}var Rv={__proto__:null,"<":e=>e<0,"<=":e=>e<=0,"==":e=>e===0,"!=":e=>e!==0,">":e=>e>0,">=":e=>e>=0};function mt(e,t){let n=qe(e);return t.type==="regex"?n?Re(t.source,!0,null,e.tables):t.re:Re(L(T(e,t),e),n,e.warn,e.tables)}function gh(e,t){if(e instanceof Map)throw ch(t);return e}function fh(e,t,n){let r=_u(e,t.target),o=z(mh(e,r)),i=t.op==="++"?o+1:o-1;return Ru(e,r,i),n?o:i}function T(e,t){switch(t.type){case"num":case"str":return t.value;case"regex":return mt(e,t).test(e.record)?1:0;case"var":return gh(bn(e,t.name),t.name);case"index":{let n=ht(e,t.name),r=kr(e,t.subs),o=n.get(r);return o===void 0&&n.set(r,void 0),o}case"field":return ph(e,hh(e,t.index));case"assign":{let n=_u(e,t.target),r=T(e,t.value);if(r instanceof Map)throw new $("attempt to use an array in a scalar context");return t.op!=="="&&(r=lh(t.op[0],z(mh(e,n)),z(r))),Ru(e,n,r),r}case"cond":return T(e,Ne(T(e,t.test))?t.consequent:t.alternate);case"or":return Ne(T(e,t.left))||Ne(T(e,t.right))?1:0;case"and":return Ne(T(e,t.left))&&Ne(T(e,t.right))?1:0;case"not":return Ne(T(e,t.expr))?0:1;case"neg":return-z(T(e,t.expr));case"plus":return z(T(e,t.expr));case"binary":return lh(t.op,z(T(e,t.left)),z(T(e,t.right)));case"concat":return L(T(e,t.left),e)+L(T(e,t.right),e);case"compare":return Rv[t.op](jo(T(e,t.left),T(e,t.right),e))?1:0;case"match":{let n=L(T(e,t.left),e);return mt(e,t.right).test(n)===t.negate?0:1}case"in":return ht(e,t.array).has(kr(e,t.keys))?1:0;case"preinc":return fh(e,t,!1);case"postinc":return fh(e,t,!0);case"call":return Mv(e,t);case"builtin":return e.callBuiltin(e,t);case"getline":return Dv(e,t);default:throw new $(`unknown expression: ${t.type}`)}}function Mv(e,t){let n=e.program.functions.get(t.name);if(n===void 0)throw new $(`function \`${t.name}\` not defined`);if(t.args.length>n.params.length)throw new $(`function \`${t.name}\` called with ${t.args.length} arguments, but it accepts only ${n.params.length}`);if(e.callDepth>=Vi)throw new $(`function call nesting deeper than ${Vi} levels (runaway recursion?)`,null,"call depth limit");let r=e.frame,o=new Map;for(let i=0;i<n.params.length;i++)o.set(n.params[i],i<t.args.length?Pv(e,t.args[i]):void 0);e.frame=o,e.callDepth++;try{let i=e.execStmts(e,n.body);if(i===void 0||i.type==="return")return i?.value;throw new xr(i)}finally{e.frame=r,e.callDepth--}}function Pv(e,t){if(t.type!=="var")return T(e,t);let n=qo(e,t.name),r=n.get(t.name);return r instanceof Map||br(r)?r:r===void 0?Iv(n,t.name):r}function Dv(e,t){let n;if(t.file===null){if(n=e.input.next(e),n===null)return 0}else{let r=e.input.readNamed(e,L(T(e,t.file),e));if(r.status!==1)return r.status;n=r.record}return t.target===null?Ho(e,n):Mu(e,t.target,new G(n)),1}var Qe=(e,t)=>z(T(e,t)),Pu=2**32;function yh(e){return Number(BigInt.asUintN(32,BigInt(Math.trunc(e))))}var bh=()=>({seed:1,state:yh(1)});function Bv(e){e.rng.state=(e.rng.state+1831565813)%Pu;let t=e.rng.state;t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61);let n=t^t>>>14;return(n<0?n+Pu:n)/Pu}function Uv(e,t){let n=e.rng.seed,r=t.length>0?Qe(e,t[0]):Math.floor(Date.now()/1e3);return e.rng.seed=r,e.rng.state=yh(r),n}function jv(e,t){let n=Qe(e,t[0]);return n<0&&e.warn(`log: received negative argument ${L(n,e)}`),Math.log(n)}function Wv(e,t){let n=Qe(e,t[0]);return n<0&&e.warn(`sqrt: called with negative argument ${L(n,e)}`),Math.sqrt(n)}function qv(e,t){let n=Qe(e,t[0]),r=Math.exp(n);return Number.isFinite(n)&&!Number.isFinite(r)&&e.warn(`exp: argument ${L(n,e)} is out of range`),r}function zv(e,t){let n=T(e,t[0]);if(typeof n=="number")return n;let r=n instanceof G?n.s:L(n,e),o=/^0[xX]([0-9a-fA-F]*)/u.exec(r);if(o)return o[1]===""?0:Number.parseInt(o[1],16);let i=/^0[0-7]+(?![.\deE0-9])/u.exec(r);return i?Number.parseInt(i[0],8):z(new G(r))}function vr(e,t,n,r){let o=Qe(e,n);if(o<0)throw new $(`${t}: argument ${r} negative value ${L(o,e)} is not allowed`);if(!Number.isFinite(o))throw new $(`${t}: argument ${r} is not a finite number`);return BigInt.asUintN(64,BigInt(Math.trunc(o)))}function Bu(e){let t=e;for(;t>0n&&BigInt(Number(t))!==t;)t&=(1n<<BigInt(t.toString(2).length-1))-1n;return Number(t)}function Du(e,t){return(n,r)=>{if(r.length<2)throw new $(`${e}: called with less than two arguments`);let o=vr(n,e,r[0],1);for(let i=1;i<r.length;i++)o=t(o,vr(n,e,r[i],i+1));return Bu(o)}}function wh(e,t){return(n,r)=>{let o=vr(n,e,r[0],1),i=vr(n,e,r[1],2)%64n;return Bu(BigInt.asUintN(64,t?o<<i:o>>i))}}var xh={__proto__:null,sin:(e,t)=>Math.sin(Qe(e,t[0])),cos:(e,t)=>Math.cos(Qe(e,t[0])),atan2:(e,t)=>Math.atan2(Qe(e,t[0]),Qe(e,t[1])),exp:qv,log:jv,sqrt:Wv,int:(e,t)=>Math.trunc(Qe(e,t[0])),rand:Bv,srand:Uv,systime:()=>Math.floor(Date.now()/1e3),strtonum:zv,and:Du("and",(e,t)=>e&t),or:Du("or",(e,t)=>e|t),xor:Du("xor",(e,t)=>e^t),lshift:wh("lshift",!0),rshift:wh("rshift",!1),compl:(e,t)=>Bu(BigInt.asUintN(64,~vr(e,"compl",t[0],1)))};var Go=new Map;function Hv(e){let t=Go.get(e);return t||(Go.size>=256&&Go.clear(),t=go(e),Go.set(e,t)),t}function Xo(e,t,n){let r=0,o=()=>{if(r>=n.length)throw new $("printf: not enough arguments to satisfy format string");return n[r++]},i="";for(let s of Hv(t)){if(typeof s=="string"){i+=s;continue}let u={...s};if(s.width==="*"){let a=Math.trunc(z(o()));a<0?(u.minus=!0,u.width=-a):u.width=a}if(s.precision==="*"){let a=Math.trunc(z(o()));u.precision=a<0?null:a}if(u.width>Ce||u.precision>Ce)throw new $(`printf: field width or precision above ${Ce} is not supported`,null,"format size limit");i+=Gv(e,u,o())}return i}function Gv(e,t,n){if(t.conv==="s"){let r=L(n,e);return t.precision!==null&&(r=[...r].slice(0,t.precision).join("")),Nt("",r,t,!1)}return t.conv==="c"?Nt("",pt(e,Xv(n)),t,!1):Wt(z(n),t)}function Xv(e){if(typeof e=="number"||e instanceof G&&Nu(e.s)){let r=Math.trunc(z(e));if(!Ze(r))throw new $("printf: character code outside Unicode scalar values is not supported",null,"character code");return String.fromCodePoint(r)}let n=e instanceof G?e.s:e??"";return n===""?"\0":String.fromCodePoint(n.codePointAt(0))}var we=(e,t)=>L(T(e,t),e),kh=(e,t)=>z(T(e,t)),Zv={type:"field",index:{type:"num",value:0}};function Yv(e,t){let n="";for(let r=0;r<e.length;r++){let o=e[r];if(o==="\\"){if(e[r+1]==="\\"&&e[r+2]==="\\"&&(e[r+3]==="&"||e[r+3]==="\\")){n+="\\"+e[r+3],r+=3;continue}if(e[r+1]==="\\"&&e[r+2]==="&"){n+="\\"+t,r+=2;continue}if(e[r+1]==="&"){n+="&",r++;continue}}n+=o==="&"?t:o}return n}function vh(e,t,n){let r=mt(e,t[0]),o=we(e,t[1]),i=t[2]??Zv,s=we(e,i),{out:u,count:a}=qn(s,r,(l,f)=>Yv(o,s.slice(l,f)),n?"global":"first");return a>0&&Mu(e,i,u),a}function Vv(e,t){let n="";for(let r=0;r<e.length;r++){let o=e[r];if(o==="\\"&&r+1===e.length)throw new $("gensub with a trailing replacement backslash is not supported",null,"gensub trailing backslash");if(o==="\\"&&r+1<e.length){let i=e[++r];i>="0"&&i<="9"?n+=t[Number(i)]?.text??"":n+=i;continue}n+=o==="&"?t[0].text:o}return n}function Kv(e,t){let n=mt(e,t[0]),r=we(e,t[1]),o=T(e,t[2]),i=L(o,e),s=i.startsWith("g")||i.startsWith("G"),u=0;s||(u=Math.trunc(z(o)),u<1&&(e.warn(`gensub: third argument \`${i}' treated as 1`),u=1));let a=t[3]?we(e,t[3]):e.record,l=/(?:^|[^\\])(?:\\\\)*\\[1-9]/u.test(r);return qn(a,n,(f,c,d)=>!s&&d!==u?null:Vv(r,l?n.groups(a,f,c):[{text:a.slice(f,c)}]),s?"global":"nth").out}function Jv(e,t){let n=we(e,t[0]),r=mt(e,t[1]),o=r.search(n,0),i=o?Array.from(n.slice(0,o.start)).length+1:0;if(e.globals.set("RSTART",i),e.globals.set("RLENGTH",o?Array.from(n.slice(o.start,o.end)).length:-1),t[2]){let s=ht(e,t[2].name);if(s.clear(),o){let u=L(e.globals.get("SUBSEP"),e);r.groups(n,o.start,o.end).forEach((a,l)=>{a!==void 0&&(s.set(String(l),new G(a.text)),s.set(`${l}${u}start`,Array.from(n.slice(0,a.start)).length+1),s.set(`${l}${u}length`,[...a.text].length))})}}return i}function Qv(e,t){let n=we(e,t[0]),r=ht(e,t[1].name),o;t[2]===void 0?o=L(e.globals.get("FS"),e):t[2].type==="regex"?o=mt(e,t[2]):o=we(e,t[2]);let i=Lu(n,o,!1,qe(e));return r.clear(),i.forEach((s,u)=>r.set(String(u+1),new G(s))),i.length}function eS(e,t){let n=[...we(e,t[0])],r=Math.trunc(kh(e,t[1])),o=Number.isNaN(r)?1:Math.max(r,1),i=n.length+1;if(t[2]){let s=Math.trunc(kh(e,t[2]));if(!(s>=1))return"";i=Math.min(i,o+s)}return i>o?n.slice(o-1,i-1).join(""):""}function tS(e,t){if(t.length===0)return[...e.record].length;if(t[0].type==="var"){let n=bn(e,t[0].name);return n instanceof Map?n.size:[...L(n,e)].length}return[...we(e,t[0])].length}function nS(e,t){let n=we(e,t[0]),r=we(e,t[1]);qe(e)&&(n=Gt(n),r=Gt(r));let o=n.indexOf(r);return o<0?0:Array.from(n.slice(0,o)).length+1}function rS(e,t){let n=we(e,t[0]);return n==="/dev/stdout"||n==="/dev/stderr"||n==="/dev/null"?0:e.input.close(e,n)}var oS=(e,t)=>t[0].type==="var"?Iu(bn(e,t[0].name)):Iu(T(e,t[0])),iS={__proto__:null,...xh,length:tS,substr:eS,index:nS,split:Qv,sub:(e,t)=>vh(e,t,!1),gsub:(e,t)=>vh(e,t,!0),gensub:Kv,match:Jv,sprintf:(e,t)=>Xo(e,we(e,t[0]),t.slice(1).map(n=>T(e,n))),tolower:(e,t)=>Gt(we(e,t[0])),toupper:(e,t)=>Gt(we(e,t[0]),!0),close:rS,fflush:()=>0,typeof:oS,isarray:(e,t)=>t[0].type==="var"&&bn(e,t[0].name)instanceof Map?1:0};function Sh(e,t){let n=iS[t.name];if(!n)throw new $(`function \`${t.name}\` is not supported`,null,`${t.name}()`);return n(e,t.args)}var Yo={type:"break"},ju={type:"continue"},sS={type:"next"},uS={type:"nextfile"},aS={type:"exit"};function Eh(e,t,n,r){let o=new Map([["0","awk"]]);r.forEach((u,a)=>o.set(String(a+1),new G(u)));let i=new Map([["FS"," "],["OFS"," "],["ORS",`
224
242
  `],["RS",`
225
- `],["RT",""],["NR",0],["NF",0],["FNR",0],["FILENAME",""],["SUBSEP",""],["CONVFMT","%.6g"],["OFMT","%.6g"],["RSTART",0],["RLENGTH",-1],["ERRNO",""],["IGNORECASE",0],["FIELDWIDTHS",""],["FPAT","[^[:space:]]+"],["ENVIRON",new vi("ENVIRON")],["PROCINFO",new vi("PROCINFO",[["FS","FS"]])],["ARGC",r.length+1],["ARGV",i],["ARGIND",0]]),s={program:e,globals:o,frame:void 0,callDepth:0,record:"",recordValue:new W(""),fields:[void 0],nf:0,fieldMode:"FS",out:[],errOut:[],steps:0,exitCode:0,ranges:[],rng:Bp(),input:new mi(t,n),byteLocale:le(t),hasFileRules:e.beginFile.length>0,callBuiltin:jp,execStmts:Si,assign:(u,a)=>wi(s,u,a),warn:u=>s.errOut.push(`awk: warning: ${u}
226
- `),fileRule:u=>hv(s,u)};return s}var vi=class extends Map{constructor(t,n=[]){super(n),this.systemName=t}check(t){if(!this.systemName||this.systemName==="PROCINFO"&&t==="FS")return;let n=this.systemName==="ENVIRON"?"ENVIRON":`PROCINFO[${t??"*"}]`;throw new k(`${n} is not supported without the corresponding environment or process metadata`,null,n)}get(t){return this.check(t),super.get(t)}has(t){return this.check(t),super.has(t)}set(t,n){return this.check(t),super.set(t,n)}delete(t){return this.check(t),super.delete(t)}clear(){return this.check(),super.clear()}get size(){return this.check(),super.size}keys(){return this.check(),super.keys()}values(){return this.check(),super.values()}entries(){return this.check(),super.entries()}[Symbol.iterator](){return this.check(),super[Symbol.iterator]()}};function Gp(e){let{program:t}=e,n=nu(e,t.begin,"BEGIN"),r=t.rules.length>0||t.end.length>0||t.beginFile.length>0||t.endFile.length>0;return!Xp(n)&&r&&mv(e),nu(e,t.end,"END"),e.exitCode}var Xp=e=>e!==void 0&&e.type==="exit";function nu(e,t,n){let r=Zp(e,t);if(r!==void 0&&(r.type==="next"||r.type==="nextfile"&&(n==="BEGIN"||n==="END")))throw new k(`\`${r.type}' cannot be called from a ${n} rule`);return r}function hv(e,t){let n=t==="begin"?e.program.beginFile:e.program.endFile;return n.length===0?void 0:nu(e,n,t==="begin"?"BEGINFILE":"ENDFILE")}function mv(e){for(;;){let t=e.input.next(e);if(t===null)return e.input.exitSignal;xi(e,t);let n=gv(e);if(Xp(n))return n;n!==void 0&&n.type==="nextfile"&&e.input.closeFile(e)}}function gv(e){let{rules:t}=e.program;for(let n=0;n<t.length;n++){let r=t[n];if(!wv(e,r,n))continue;if(r.action===null){iu(e,null,e.record+F(e.globals.get("ORS"),e));continue}let i=Zp(e,r.action);if(i!==void 0)return i}}function Zp(e,t){try{return Si(e,t)}catch(n){if(!(n instanceof sr))throw n;return n.signal}}function wv(e,t,n){let{pattern:r}=t;if(r===null)return!0;if(r.type!=="range")return xe(O(e,r));if(!e.ranges[n]){if(!xe(O(e,r.from)))return!1;e.ranges[n]=!0}return xe(O(e,r.to))&&(e.ranges[n]=!1),!0}function Si(e,t){for(let n of t){let r=lr(e,n);if(r!==void 0)return r}}function lr(e,t){if(++e.steps>Cn)throw new k(`execution stopped after ${Cn} statements (infinite loop?)`,null,"execution limit");switch(t.type){case"block":return Si(e,t.body);case"empty":return;case"expr":O(e,t.expr);return;case"print":return vv(e,t);case"printf":return kv(e,t);case"if":return xe(O(e,t.test))?lr(e,t.consequent):t.alternate===null?void 0:lr(e,t.alternate);case"while":case"do":case"for":return xv(e,t);case"forin":return yv(e,t);case"switch":return bv(e,t);case"break":return ki;case"continue":return ru;case"next":return fv;case"nextfile":return dv;case"exit":return Sv(e,t);case"return":return{type:"return",value:t.value===null?void 0:O(e,t.value)};case"delete":{let n=nt(e,t.name);t.subs===null?n.clear():n.delete(ur(e,t.subs));return}default:throw new k(`unknown statement: ${t.type}`)}}function xv(e,t){t.init&&O(e,t.init);let n=!0;for(;t.type==="do"&&n||t.test===null||xe(O(e,t.test));){n=!1;let r=lr(e,t.body);if(r===ki)return;if(r!==void 0&&r!==ru)return r;t.step&&O(e,t.step)}}function yv(e,t){let n=nt(e,t.array);for(let r of Array.from(n.keys())){wi(e,t.name,new W(r));let i=lr(e,t.body);if(i===ki)return;if(i!==void 0&&i!==ru)return i}}function bv(e,t){let n=O(e,t.expr),r=o=>o.test.type==="regex"?rt(e,o.test).test(F(n,e)):hi(n,o.test.value,e)===0,i=t.cases.findIndex(o=>o.test!==null&&r(o));if(i===-1&&(i=t.cases.findIndex(o=>o.test===null)),i!==-1)for(let o=i;o<t.cases.length;o++){let s=Si(e,t.cases[o].body);if(s===ki)return;if(s!==void 0)return s}}function iu(e,t,n){if(t===null){e.out.push(n);return}let r=F(O(e,t),e);if(r==="/dev/stdout")e.out.push(n);else if(r==="/dev/stderr")e.errOut.push(n);else if(r!=="/dev/null")throw new k(Ws(r),null,"output redirection")}function vv(e,t){let n=F(e.globals.get("ORS"),e),r;if(t.args.length===0)r=e.record;else{let i=F(e.globals.get("OFS"),e);r=t.args.map(o=>Np(O(e,o),e)).join(i)}iu(e,t.dest,r+n)}function kv(e,t){let n=t.args.map(r=>O(e,r));iu(e,t.dest,bi(e,F(n[0],e),n.slice(1)))}function Sv(e,t){if(t.value!==null){let n=Math.trunc(B(O(e,t.value)));e.exitCode=(n%256+256)%256}return pv}var Ev="awk [-F fs] [-v var=value] 'program' [file ...] | awk [-F fs] [-v var=value] -f progfile [file ...]",$v=/^([A-Za-z_][A-Za-z0-9_]*)=([^]*)$/u;function Vp(e,t,n){let{values:r,positional:i}=E(Av(t),{valueShort:["F"],repeatable:["v","f"],stopAtFirstPositional:!0}),o=Iv(r.get("f")??[],i,n);if(o.error)return o.error;let s;try{tt({byteLocale:le(n)},o.text),s=yp(o.text)}catch(f){if(f instanceof RangeError)return v("feature","awk","parser depth limit",`awk: program too deeply nested (${f.message})`);if(N(f))return K(f,"awk",`awk: ${f.message}`);if(!(f instanceof k))throw f;let d=f.line===null?`awk: ${f.message}`:`awk: syntax error at line ${f.line}: ${f.message}`;return f.gap===null?y(d):v("feature","awk",f.gap,d)}let u=Hp(s,n,e,o.operands);for(let f of s.warnings)u.warn(f);let a,l=null;try{r.has("F")&&u.assign("FS",Qn(r.get("F"),u.warn));for(let f of r.get("v")??[]){let d=$v.exec(f);if(!d)return y(`awk: -v: expected var=value but got \`${f}\``);u.assign(d[1],new W(Qn(d[2],u.warn)))}a=Gp(u)}catch(f){let d=N(f);if(!(f instanceof k)&&!(f instanceof RangeError)&&!d)throw f;u.errOut.push(`awk: ${f.message}
227
- `),a=2,f instanceof RangeError&&(l={detail:"runtime limit",message:`awk: ${f.message}`}),f.gap&&(l={detail:f.gap,message:`awk: ${f.message}`}),d&&(l={detail:d.detail,message:`awk: ${f.message}`})}let c={stdout:u.out.join(""),stderr:u.errOut.join(""),exitCode:a};return l===null?c:Q(c,"feature","awk",l.detail,l.message)}var Nv=/^-[Fvf]\S*\s/su;function Av(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n];if(r==="-F"||r==="-v"||r==="-f"){t.push(r),n+1<e.length&&t.push(e[++n]);continue}if(Nv.test(r)){t.push(r.slice(0,2),r.slice(2));continue}if(!r.startsWith("-")||r==="-"||r==="--"){t.push(...e.slice(n));break}t.push(r)}return t}function Iv(e,t,n){if(e.length===0)return t.length===0?{error:oe(Ev,2)}:{text:t[0],operands:t.slice(1)};let r=[];for(let i of e){let{path:o,error:s}=P(n,"awk",i);if(s||!n.fs.isFile(o))return{error:y(`awk: cannot open program file \`${i}\`: ${s??"Is a directory"}`,2)};r.push(n.fs.readFile(o))}return{text:r.join(`
228
- `),operands:t}}function Kp(e,t,n){let{flags:r,values:i,positional:o}=E(t,{short:["n","r","u","f","b","z"],valueShort:["t"],repeatable:["k"]}),s=i.get("t");if(s!==void 0&&I(s).length!==1)return y(`sort: multi-character tab '${s}'`,2);let u={n:r.has("n"),f:r.has("f"),b:r.has("b"),r:r.has("r")},a=Lv(i.get("k")??[],u);if(a.error)return a.error;let l=te("sort",o,e,n,{stopOnError:!0});if(l.failed)return{stdout:"",stderr:l.stderr,exitCode:2};let c=r.has("z")?"\0":`
229
- `,f=l.inputs.flatMap(({content:m})=>se(m,c)),d=a.specs.length?a.specs:[{start:1,...u}],p=Dv(f,d,s,r.has("u"),u.r);return ue(ce(p,c),l)}var Ov="nrfb",Cv="bdfghiMnRrV",Fv=/^[ \t]*\+?(\d+)/u,Tv=(e,t)=>y(`sort: ${e}: invalid count at start of '${t}'`,2),Ei=(e,t)=>y(`sort: ${e}: invalid field specification '${t}'`,2);function _v(e){let t=0,n=null,r=u=>{let a=Fv.exec(e.slice(t));return a===null?(n=Tv(u,e.slice(t)),null):(t+=a[0].length,Number(a[1]))},i=u=>{let a=r(u);if(a===null)return null;let l=null;if(e[t]==="."&&(t++,l=r("invalid number after '.'"),l===null))return null;let c=t;for(;t<e.length&&/[a-zA-Z]/u.test(e[t]);)t++;return{field:a,offset:l,mods:e.slice(c,t)}},o=i("invalid number at field start");if(o===null)return{error:n};let s=null;return e[t]===","&&(t++,s=i("invalid number after ','"),s===null)?{error:n}:o.field===0||s?.field===0?{error:Ei("field number is zero",e)}:o.offset===0?{error:Ei("character offset is zero",e)}:t!==e.length?{error:Ei("stray character in field spec",e)}:{from:o,to:s}}function Lv(e,t){let n=[];for(let r of e){let i=_v(r);if(i.error)return{error:i.error};let{from:o,to:s}=i,u=o.mods+(s?.mods??"");for(let l of u)if(!Ov.includes(l))return Cv.includes(l)?{error:v("option","sort",`-k${r}`,`sort: unknown key option \`${l}\` in ${r}`,2)}:{error:Ei("stray character in field spec",r)};if(o.offset!==null||(s?.offset??0)!==0)return{error:v("option","sort",`-k${r}`,`sort: invalid key specification: ${r} (character offsets are not supported)`,2)};let a=u.length>0;n.push({start:o.field,end:s?.field,n:a?u.includes("n"):t.n,r:a?u.includes("r"):t.r,f:a?u.includes("f"):t.f,b:a?o.mods.includes("b"):t.b})}return{specs:n}}function Rv(e,t){let n=[];if(t!==void 0){let i=0;for(;;){let o=e.indexOf(t,i);if(o===-1){n.push([i,e.length]);break}n.push([i,o]),i=o+t.length}return n}let r=0;do{let i=r;for(;r<e.length&&/[ \t]/u.test(e[r]);)r++;for(;r<e.length&&!/[ \t]/u.test(e[r]);)r++;n.push([i,r])}while(r<e.length);return n}function Mv(e,t,n){if(t.start>n.length)return"";let r=n[t.start-1][0],i=t.end===void 0||t.end>n.length?e.length:n[t.end-1][1];if(t.b)for(;r<i&&/[ \t]/u.test(e[r]);)r++;return e.slice(r,Math.max(r,i))}var Pv=e=>e.replace(/[a-z]/gu,t=>t.toUpperCase());function Dv(e,t,n,r,i){let o=t.every(l=>l.start===1&&l.end===void 0);if(o&&t.length===1&&!t[0].n&&!t[0].f&&!t[0].b)return e.sort(e.some(l=>/[\u{10000}-\u{10FFFF}]/u.test(l))?U:void 0),t[0].r&&e.reverse(),r?e.filter((l,c)=>c===0||l!==e[c-1]):e;let s=e.map(l=>{let c=o?[[0,l.length]]:Rv(l,n);return{line:l,keys:t.map(f=>{let d=Mv(l,f,c);return f.n?Uv(d):f.f?Pv(d):d})}}),u=(l,c)=>{for(let f=0;f<t.length;f++){let d=t[f],p=d.n?Bv(l.keys[f],c.keys[f]):U(l.keys[f],c.keys[f]);if(p!==0)return d.r?-p:p}return r?0:(i?-1:1)*U(l.line,c.line)};s.sort(u);let a=[];for(let l=0;l<s.length;l++)r&&l>0&&u(s[l-1],s[l])===0||a.push(s[l].line);return a}function Uv(e){let t=/^[ \t]*(-?)(?:(\d+)(?:\.(\d*))?|\.(\d+))/u.exec(e),n=(t?.[2]??"").replace(/^0+/u,"")||"0",r=(t?.[3]??t?.[4]??"").replace(/0+$/u,"");return{integer:n,fraction:r,negative:t?.[1]==="-"&&(n!=="0"||r!=="")}}var Yp=(e,t)=>e<t?-1:e>t?1:0;function Bv(e,t){if(e.negative!==t.negative)return e.negative?-1:1;let n=e.integer.length-t.integer.length||Yp(e.integer,t.integer)||Yp(e.fraction,t.fraction);return e.negative?-n:n}function Qp(e,t,n){let{flags:r,values:i,positional:o}=E(t,{short:["r","0"],valueShort:["n","I"],stopAtFirstPositional:!0}),[s="echo",...u]=o,a=i.get("I"),l=i.has("n")?pe(i.get("n"),"xargs: -n"):{value:void 0};if(l.error)return l.error;if(l.value===0)return y("xargs: -n: must be at least 1");if(a==="")return y("xargs: -I: replacement string must not be empty");if(a!==void 0&&l.value!==void 0)return v("option","xargs","-I -n","xargs: combining replacement and chunk limits is not supported");if(z(n),!r.has("0")&&e.includes("\0"))return v("feature","xargs","NUL input","xargs: NUL input requires -0");let c;if(r.has("0"))c=se(e,"\0");else if(a===void 0)c=Wv(e);else{if(/["'\\]/u.test(e))return v("feature","xargs","-I input quoting","xargs: quoted or escaped replacement lines are not supported");c=se(e).map(h=>h.replace(/^[ \t\r\f\v]+/u,"")).filter(Boolean)}if(c.length===0&&(r.has("r")||a!==void 0))return C();let f=a===void 0?l.value??Math.max(1,c.length):1,d=0,p="",m="";for(let h=0;h<Math.max(1,c.length);h+=f){let g=c[h],x=a===void 0?[...u,...c.slice(h,h+f)]:u.map(S=>S.replaceAll(a,g)),b=n.dispatch(s,x,"");if(m+=b.stdout,p+=b.stderr,b.exitCode===255)return{stdout:m,stderr:p+"xargs: "+s+`: exited with status 255; aborting
230
- `,exitCode:124};if(b.exitCode===127&&!n.hasCommand(n.registry.resolveCommand(s)))return{stdout:m,stderr:p,exitCode:127};b.exitCode!==0&&(d=123)}return{stdout:m,stderr:p,exitCode:d}}var Jp=e=>new Error(`unmatched ${e==="'"?"single":"double"} quote; by default quotes are special to xargs unless you use the -0 option`);function Wv(e){let t=[],n=null,r=!1,i="";for(let o=0;o<e.length;o++){let s=e[o];if(!(!r&&/[ \t\n\r\f\v]/u.test(s)))if(n)if(s===n)n=null;else{if(s===`
231
- `)throw Jp(n);i+=s}else if(s==='"'||s==="'")n=s,r=!0;else if(s==="\\"){if(o+1>=e.length)break;i+=e[++o],r=!0}else s===" "||s===" "||s===`
232
- `?(r&&t.push(i),i="",r=!1):(i+=s,r=!0)}if(n)throw Jp(n);return r&&t.push(i),t}function eh(e,t,n,r){let{values:i,positional:o,order:s}=E(qv(n),{short:["q","v"],valueShort:["c","n"]}),u=s.findLast(x=>x.name==="n"||x.name==="c")?.name??"n",a=Bu(i.get(u)??"10",e+": -"+u);if(a.error)return a.error;let l=s.findLast(x=>x.name==="q"||x.name==="v"),c=l?l.name==="v":null,f=e==="head",d=a.sign==="+";if(f&&a.value===0&&a.sign!=="-")return th(e,t,o,r,()=>"",{unit:u,banner:c,leftover:x=>x,readOptions:{noRead:!0}});if(!f&&a.value===0&&!d){if(!r.stdinFile&&(!o.length||o.includes("-")||o.includes("/dev/stdin"))){let x=oh(e,t,"",u,"standard input");x&&r.notes.add(x)}return C()}let p=x=>f?[0,a.sign==="-"?Math.max(0,x-a.value):a.value]:[d?Math.min(x,Math.max(0,a.value-1)):Math.max(0,x-a.value),x],m=x=>{if(u==="c")return ih(x,p);let b=f?a.sign==="-":!d,S=f||b?a.value:Math.max(0,a.value-1),A=rh(x,S,b);return f?x.slice(0,A):x.slice(A)},h=f?zv(a,u,r):void 0;return th(e,t,o,r,m,{unit:u,banner:c,leftover:h,readOptions:!f&&d?{stopOnDir:!0}:void 0})}function zv(e,t,n){return e.sign==="-"||t==="n"&&!n.stdinFile?()=>"":t==="c"?r=>ih(r,i=>[Math.min(e.value,i),i]):r=>r.slice(rh(r,e.value))}function rh(e,t,n=!1){if(n){if(t===0)return e.length;let i=e.length-Number(e.endsWith(`
233
- `));for(let o=0;o<t;o++)if(i<=0||(i=e.lastIndexOf(`
234
- `,i-1),i<0))return 0;return i+1}let r=0;for(let i=0;i<t&&r<e.length;i++){let o=e.indexOf(`
235
- `,r);r=o===-1?e.length:o+1}return r}function qv(e){return/^-\d+$/u.test(e[0]??"")?["-n",e[0].slice(1),...e.slice(1)]:e}function ih(e,t){let n=I(e),[r,i]=t(n.length);return r===0&&i>=n.length?e:M(n.subarray(r,i))}function th(e,t,n,r,i,{unit:o,banner:s,leftover:u=()=>"",readOptions:a}){let l=te(e,n,t,r,a),c=s??n.length>1,f=l.entries.filter(h=>h.kind!=="missing"),d=[],p=[],m=null;for(let h=0;h<f.length;h++){let{name:g,kind:x,shared:b}=f[h],{content:S}=f[h];(b||g===null)&&(m!==null&&(S=m),m=u(S),z(r,m));let A=x==="dir"?"":i(S);if(x==="file"&&A!==S){let q=oh(e,S,A,o,Uu(g,r));q&&p.push(q)}let V=g===null||g==="-"?"standard input":g;d.push(c?`${h>0?`
236
- `:""}==> ${V} <==
237
- ${A}`:A)}for(let h of p)r.notes.add(h);return ue(d.join(""),l)}function jv(e){let t=+(e.length>0&&!e.endsWith(`
243
+ `],["RT",""],["NR",0],["NF",0],["FNR",0],["FILENAME",""],["SUBSEP",""],["CONVFMT","%.6g"],["OFMT","%.6g"],["RSTART",0],["RLENGTH",-1],["ERRNO",""],["IGNORECASE",0],["FIELDWIDTHS",""],["FPAT","[^[:space:]]+"],["ENVIRON",new Zo("ENVIRON")],["PROCINFO",new Zo("PROCINFO",[["FS","FS"]])],["ARGC",r.length+1],["ARGV",o],["ARGIND",0]]),s={program:e,globals:i,frame:void 0,callDepth:0,record:"",recordValue:new G(""),fields:[void 0],nf:0,fieldMode:"FS",out:[],errOut:[],steps:0,exitCode:0,ranges:[],rng:bh(),input:new Wo(t,n),byteLocale:le(t),tables:re(t.locale),hasFileRules:e.beginFile.length>0,callBuiltin:Sh,execStmts:Vo,assign:(u,a)=>zo(s,u,a),warn:u=>s.errOut.push(`awk: warning: ${u}
244
+ `),fileRule:u=>lS(s,u)};return s}var Zo=class extends Map{constructor(t,n=[]){super(n),this.systemName=t}check(t){if(!this.systemName||this.systemName==="PROCINFO"&&t==="FS")return;let n=this.systemName==="ENVIRON"?"ENVIRON":`PROCINFO[${t??"*"}]`;throw new $(`${n} is not supported without the corresponding environment or process metadata`,null,n)}get(t){return this.check(t),super.get(t)}has(t){return this.check(t),super.has(t)}set(t,n){return this.check(t),super.set(t,n)}delete(t){return this.check(t),super.delete(t)}clear(){return this.check(),super.clear()}get size(){return this.check(),super.size}keys(){return this.check(),super.keys()}values(){return this.check(),super.values()}entries(){return this.check(),super.entries()}[Symbol.iterator](){return this.check(),super[Symbol.iterator]()}};function $h(e){let{program:t}=e,n=Uu(e,t.begin,"BEGIN"),r=t.rules.length>0||t.end.length>0||t.beginFile.length>0||t.endFile.length>0;return!Nh(n)&&r&&fS(e),Uu(e,t.end,"END"),e.exitCode}var Nh=e=>e!==void 0&&e.type==="exit";function Uu(e,t,n){let r=Ah(e,t);if(r!==void 0&&(r.type==="next"||r.type==="nextfile"&&(n==="BEGIN"||n==="END")))throw new $(`\`${r.type}' cannot be called from a ${n} rule`);return r}function lS(e,t){let n=t==="begin"?e.program.beginFile:e.program.endFile;return n.length===0?void 0:Uu(e,n,t==="begin"?"BEGINFILE":"ENDFILE")}function fS(e){for(;;){let t=e.input.next(e);if(t===null)return e.input.exitSignal;Ho(e,t);let n=cS(e);if(Nh(n))return n;n!==void 0&&n.type==="nextfile"&&e.input.closeFile(e)}}function cS(e){let{rules:t}=e.program;for(let n=0;n<t.length;n++){let r=t[n];if(!dS(e,r,n))continue;if(r.action===null){Wu(e,null,e.record+L(e.globals.get("ORS"),e));continue}let o=Ah(e,r.action);if(o!==void 0)return o}}function Ah(e,t){try{return Vo(e,t)}catch(n){if(!(n instanceof xr))throw n;return n.signal}}function dS(e,t,n){let{pattern:r}=t;if(r===null)return!0;if(r.type!=="range")return Ne(T(e,r));if(!e.ranges[n]){if(!Ne(T(e,r.from)))return!1;e.ranges[n]=!0}return Ne(T(e,r.to))&&(e.ranges[n]=!1),!0}function Vo(e,t){for(let n of t){let r=Sr(e,n);if(r!==void 0)return r}}function Sr(e,t){if(++e.steps>Wn)throw new $(`execution stopped after ${Wn} statements (infinite loop?)`,null,"execution limit");switch(t.type){case"block":return Vo(e,t.body);case"empty":return;case"expr":T(e,t.expr);return;case"print":return gS(e,t);case"printf":return wS(e,t);case"if":return Ne(T(e,t.test))?Sr(e,t.consequent):t.alternate===null?void 0:Sr(e,t.alternate);case"while":case"do":case"for":return pS(e,t);case"forin":return hS(e,t);case"switch":return mS(e,t);case"break":return Yo;case"continue":return ju;case"next":return sS;case"nextfile":return uS;case"exit":return yS(e,t);case"return":return{type:"return",value:t.value===null?void 0:T(e,t.value)};case"delete":{let n=ht(e,t.name);t.subs===null?n.clear():n.delete(kr(e,t.subs));return}default:throw new $(`unknown statement: ${t.type}`)}}function pS(e,t){t.init&&T(e,t.init);let n=!0;for(;t.type==="do"&&n||t.test===null||Ne(T(e,t.test));){n=!1;let r=Sr(e,t.body);if(r===Yo)return;if(r!==void 0&&r!==ju)return r;t.step&&T(e,t.step)}}function hS(e,t){let n=ht(e,t.array);for(let r of Array.from(n.keys())){zo(e,t.name,new G(r));let o=Sr(e,t.body);if(o===Yo)return;if(o!==void 0&&o!==ju)return o}}function mS(e,t){let n=T(e,t.expr),r=i=>i.test.type==="regex"?mt(e,i.test).test(L(n,e)):jo(n,i.test.value,e)===0,o=t.cases.findIndex(i=>i.test!==null&&r(i));if(o===-1&&(o=t.cases.findIndex(i=>i.test===null)),o!==-1)for(let i=o;i<t.cases.length;i++){let s=Vo(e,t.cases[i].body);if(s===Yo)return;if(s!==void 0)return s}}function Wu(e,t,n){if(t===null){e.out.push(n);return}let r=L(T(e,t),e);if(r==="/dev/stdout")e.out.push(n);else if(r==="/dev/stderr")e.errOut.push(n);else if(r!=="/dev/null")throw new $($u(r),null,"output redirection")}function gS(e,t){let n=L(e.globals.get("ORS"),e),r;if(t.args.length===0)r=e.record;else{let o=L(e.globals.get("OFS"),e);r=t.args.map(i=>ih(T(e,i),e)).join(o)}Wu(e,t.dest,r+n)}function wS(e,t){let n=t.args.map(r=>T(e,r));Wu(e,t.dest,Xo(e,L(n[0],e),n.slice(1)))}function yS(e,t){if(t.value!==null){let n=Math.trunc(z(T(e,t.value)));e.exitCode=(n%256+256)%256}return aS}var bS="awk [-F fs] [-v var=value] 'program' [file ...] | awk [-F fs] [-v var=value] -f progfile [file ...]",xS=/^([A-Za-z_][A-Za-z0-9_]*)=([^]*)$/u;function Oh(e,t,n){let{values:r,positional:o}=N(vS(t),{valueShort:["F"],repeatable:["v","f"],stopAtFirstPositional:!0}),i=SS(r.get("f")??[],o,n);if(i.error)return i.error;let s;try{pt({byteLocale:le(n)},i.text),s=J1(i.text)}catch(c){if(c instanceof RangeError)return v("feature","awk","parser depth limit",`awk: program too deeply nested (${c.message})`);if(O(c))return K(c,"awk",`awk: ${c.message}`);if(!(c instanceof $))throw c;let d=c.line===null?`awk: ${c.message}`:`awk: syntax error at line ${c.line}: ${c.message}`;return c.gap===null?x(d):v("feature","awk",c.gap,d)}let u=Eh(s,n,e,i.operands);for(let c of s.warnings)u.warn(c);let a,l=null;try{r.has("F")&&u.assign("FS",pr(r.get("F"),u.warn));for(let c of r.get("v")??[]){let d=xS.exec(c);if(!d)return x(`awk: -v: expected var=value but got \`${c}\``);u.assign(d[1],new G(pr(d[2],u.warn)))}a=$h(u)}catch(c){let d=O(c);if(!(c instanceof $)&&!(c instanceof RangeError)&&!d)throw c;u.errOut.push(`awk: ${c.message}
245
+ `),a=2,c instanceof RangeError&&(l={detail:"runtime limit",message:`awk: ${c.message}`}),c.gap&&(l={detail:c.gap,message:`awk: ${c.message}`}),d&&(l={detail:d.detail,message:`awk: ${c.message}`})}let f={stdout:u.out.join(""),stderr:u.errOut.join(""),exitCode:a};return l===null?f:ie(f,"feature","awk",l.detail,l.message)}var kS=/^-[Fvf]\S*\s/su;function vS(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n];if(r==="-F"||r==="-v"||r==="-f"){t.push(r),n+1<e.length&&t.push(e[++n]);continue}if(kS.test(r)){t.push(r.slice(0,2),r.slice(2));continue}if(!r.startsWith("-")||r==="-"||r==="--"){t.push(...e.slice(n));break}t.push(r)}return t}function SS(e,t,n){if(e.length===0)return t.length===0?{error:pe(bS,2)}:{text:t[0],operands:t.slice(1)};let r=[];for(let o of e){let{path:i,error:s}=P(n,"awk",o);if(s||!n.fs.isFile(i))return{error:x(`awk: cannot open program file \`${o}\`: ${s??"Is a directory"}`,2)};r.push(n.fs.readFile(i))}return{text:r.join(`
246
+ `),operands:t}}function Ih(e,t,n){let{flags:r,values:o,positional:i}=N(t,{short:["n","r","u","f","b","z"],valueShort:["t","o"],valueLong:["output"],repeatable:["k","o","output"]}),s=[...o.get("o")??[],...o.get("output")??[]];if(s.length>1)return x("sort: multiple output files specified",2);let u=o.get("t");if(u!==void 0&&A(u).length!==1)return x(`sort: multi-character tab '${u}'`,2);let a={n:r.has("n"),f:r.has("f"),b:r.has("b"),r:r.has("r")},l=IS(o.get("k")??[],a);if(l.error)return l.error;let f=te("sort",i,e,n,{stopOnError:!0});if(f.failed)return{stdout:"",stderr:f.stderr,exitCode:2};let c=r.has("z")?"\0":`
247
+ `,d=f.inputs.flatMap(({content:g})=>he(g,c)),p=l.specs.length?l.specs:[{start:1,...a}],h=_S(d,p,u,r.has("u"),a.r),m=ge(h,c);return s.length===0?ne(m,f):ES(s[0],m,n,f)}function ES(e,t,n,r){if(e==="/dev/null")return ne("",r);if(e==="/dev/stdout")return ne(t,r);n.io?.setReads([]);let o;try{o=n.writable&&n.fs.openWritable(n.cwd,e),o&&o.write(t)}catch(i){return R(n,"sort",i?.path,i?.fsError),K(i,"sort",`sort: open failed: ${i.message}`,2)}return o?ne("",r):v("feature","sort","-o",`sort: open failed: ${e}: Read-only file system`,2)}var $S="nrfb",NS="bdfghiMnRrV",AS=/^[ \t]*\+?(\d+)/u,OS=(e,t)=>x(`sort: ${e}: invalid count at start of '${t}'`,2),Ko=(e,t)=>x(`sort: ${e}: invalid field specification '${t}'`,2);function CS(e){let t=0,n=null,r=u=>{let a=AS.exec(e.slice(t));return a===null?(n=OS(u,e.slice(t)),null):(t+=a[0].length,Number(a[1]))},o=u=>{let a=r(u);if(a===null)return null;let l=null;if(e[t]==="."&&(t++,l=r("invalid number after '.'"),l===null))return null;let f=t;for(;t<e.length&&/[a-zA-Z]/u.test(e[t]);)t++;return{field:a,offset:l,mods:e.slice(f,t)}},i=o("invalid number at field start");if(i===null)return{error:n};let s=null;return e[t]===","&&(t++,s=o("invalid number after ','"),s===null)?{error:n}:i.field===0||s?.field===0?{error:Ko("field number is zero",e)}:i.offset===0?{error:Ko("character offset is zero",e)}:t!==e.length?{error:Ko("stray character in field spec",e)}:{from:i,to:s}}function IS(e,t){let n=[];for(let r of e){let o=CS(r);if(o.error)return{error:o.error};let{from:i,to:s}=o,u=i.mods+(s?.mods??"");for(let l of u)if(!$S.includes(l))return NS.includes(l)?{error:v("option","sort",`-k${r}`,`sort: unknown key option \`${l}\` in ${r}`,2)}:{error:Ko("stray character in field spec",r)};if(i.offset!==null||(s?.offset??0)!==0)return{error:v("option","sort",`-k${r}`,`sort: invalid key specification: ${r} (character offsets are not supported)`,2)};let a=u.length>0;n.push({start:i.field,end:s?.field,n:a?u.includes("n"):t.n,r:a?u.includes("r"):t.r,f:a?u.includes("f"):t.f,b:a?i.mods.includes("b"):t.b})}return{specs:n}}function TS(e,t){let n=[];if(t!==void 0){let o=0;for(;;){let i=e.indexOf(t,o);if(i===-1){n.push([o,e.length]);break}n.push([o,i]),o=i+t.length}return n}let r=0;do{let o=r;for(;r<e.length&&/[ \t]/u.test(e[r]);)r++;for(;r<e.length&&!/[ \t]/u.test(e[r]);)r++;n.push([o,r])}while(r<e.length);return n}function FS(e,t,n){if(t.start>n.length)return"";let r=n[t.start-1][0],o=t.end===void 0||t.end>n.length?e.length:n[t.end-1][1];if(t.b)for(;r<o&&/[ \t]/u.test(e[r]);)r++;return e.slice(r,Math.max(r,o))}var LS=e=>e.replace(/[a-z]/gu,t=>t.toUpperCase());function _S(e,t,n,r,o){let i=t.every(l=>l.start===1&&l.end===void 0);if(i&&t.length===1&&!t[0].n&&!t[0].f&&!t[0].b)return e.sort(e.some(l=>/[\u{10000}-\u{10FFFF}]/u.test(l))?j:void 0),t[0].r&&e.reverse(),r?e.filter((l,f)=>f===0||l!==e[f-1]):e;let s=e.map(l=>{let f=i?[[0,l.length]]:TS(l,n);return{line:l,keys:t.map(c=>{let d=FS(l,c,f);return c.n?RS(d):c.f?LS(d):d})}}),u=(l,f)=>{for(let c=0;c<t.length;c++){let d=t[c],p=d.n?MS(l.keys[c],f.keys[c]):j(l.keys[c],f.keys[c]);if(p!==0)return d.r?-p:p}return r?0:(o?-1:1)*j(l.line,f.line)};s.sort(u);let a=[];for(let l=0;l<s.length;l++)r&&l>0&&u(s[l-1],s[l])===0||a.push(s[l].line);return a}function RS(e){let t=/^[ \t]*(-?)(?:(\d+)(?:\.(\d*))?|\.(\d+))/u.exec(e),n=(t?.[2]??"").replace(/^0+/u,"")||"0",r=(t?.[3]??t?.[4]??"").replace(/0+$/u,"");return{integer:n,fraction:r,negative:t?.[1]==="-"&&(n!=="0"||r!=="")}}var Ch=(e,t)=>e<t?-1:e>t?1:0;function MS(e,t){if(e.negative!==t.negative)return e.negative?-1:1;let n=e.integer.length-t.integer.length||Ch(e.integer,t.integer)||Ch(e.fraction,t.fraction);return e.negative?-n:n}async function Fh(e,t,n){let{flags:r,values:o,positional:i}=N(t,{short:["r","0"],valueShort:["n","I"],stopAtFirstPositional:!0}),[s="echo",...u]=i,a=o.get("I"),l=o.has("n")?be(o.get("n"),"xargs: -n"):{value:void 0};if(l.error)return l.error;if(l.value===0)return x("xargs: -n: must be at least 1");if(a==="")return x("xargs: -I: replacement string must not be empty");if(a!==void 0&&l.value!==void 0)return v("option","xargs","-I -n","xargs: combining replacement and chunk limits is not supported");if(q(n),!r.has("0")&&e.includes("\0"))return v("feature","xargs","NUL input","xargs: NUL input requires -0");let f;if(r.has("0"))f=he(e,"\0");else if(a===void 0)f=PS(e);else{if(/["'\\]/u.test(e))return v("feature","xargs","-I input quoting","xargs: quoted or escaped replacement lines are not supported");f=he(e).map(m=>m.replace(/^[ \t\r\f\v]+/u,"")).filter(Boolean)}if(f.length===0&&(r.has("r")||a!==void 0))return F();let c=a===void 0?l.value??Math.max(1,f.length):1,d=0,p="",h="";for(let m=0;m<Math.max(1,f.length);m+=c){let g=f[m],w=a===void 0?[...u,...f.slice(m,m+c)]:u.map(k=>k.replaceAll(a,g)),y=await n.dispatch(s,w,"");if(h+=y.stdout,p+=y.stderr,y.exitCode===255)return{stdout:h,stderr:p+"xargs: "+s+`: exited with status 255; aborting
248
+ `,exitCode:124};if(y.exitCode===127&&!n.hasCommand(n.registry.resolveCommand(s)))return{stdout:h,stderr:p,exitCode:127};y.exitCode!==0&&(d=123)}return{stdout:h,stderr:p,exitCode:d}}var Th=e=>new Error(`unmatched ${e==="'"?"single":"double"} quote; by default quotes are special to xargs unless you use the -0 option`);function PS(e){let t=[],n=null,r=!1,o="";for(let i=0;i<e.length;i++){let s=e[i];if(!(!r&&/[ \t\n\r\f\v]/u.test(s)))if(n)if(s===n)n=null;else{if(s===`
249
+ `)throw Th(n);o+=s}else if(s==='"'||s==="'")n=s,r=!0;else if(s==="\\"){if(i+1>=e.length)break;o+=e[++i],r=!0}else s===" "||s===" "||s===`
250
+ `?(r&&t.push(o),o="",r=!1):(o+=s,r=!0)}if(n)throw Th(n);return r&&t.push(o),t}function Lh(e,t,n,r){let{values:o,positional:i,order:s}=N(BS(n),{short:["q","v"],valueShort:["c","n"]}),u=s.findLast(w=>w.name==="n"||w.name==="c")?.name??"n",a=Ja(o.get(u)??"10",e+": -"+u);if(a.error)return a.error;let l=s.findLast(w=>w.name==="q"||w.name==="v"),f=l?l.name==="v":null,c=e==="head",d=a.sign==="+";if(c&&a.value===0&&a.sign!=="-")return _h(e,t,i,r,()=>"",{unit:u,banner:f,leftover:w=>w,readOptions:{noRead:!0}});if(!c&&a.value===0&&!d){if(!r.stdinFile&&(!i.length||i.includes("-")||i.includes("/dev/stdin"))){let w=Dh(e,t,"",u,"standard input");w&&r.notes.add(w)}return F()}let p=w=>c?[0,a.sign==="-"?Math.max(0,w-a.value):a.value]:[d?Math.min(w,Math.max(0,a.value-1)):Math.max(0,w-a.value),w],h=w=>{if(u==="c")return Ph(w,p);let y=c?a.sign==="-":!d,k=c||y?a.value:Math.max(0,a.value-1),S=Mh(w,k,y);return c?w.slice(0,S):w.slice(S)},m=c?DS(a,u,r):void 0;return _h(e,t,i,r,h,{unit:u,banner:f,leftover:m,readOptions:!c&&d?{stopOnDir:!0}:void 0})}function DS(e,t,n){return e.sign==="-"||t==="n"&&!n.stdinFile?()=>"":t==="c"?r=>Ph(r,o=>[Math.min(e.value,o),o]):r=>r.slice(Mh(r,e.value))}function Mh(e,t,n=!1){if(n){if(t===0)return e.length;let o=e.length-Number(e.endsWith(`
251
+ `));for(let i=0;i<t;i++)if(o<=0||(o=e.lastIndexOf(`
252
+ `,o-1),o<0))return 0;return o+1}let r=0;for(let o=0;o<t&&r<e.length;o++){let i=e.indexOf(`
253
+ `,r);r=i===-1?e.length:i+1}return r}function BS(e){return/^-\d+$/u.test(e[0]??"")?["-n",e[0].slice(1),...e.slice(1)]:e}function Ph(e,t){let n=A(e),[r,o]=t(n.length);return r===0&&o>=n.length?e:W(n.subarray(r,o))}function _h(e,t,n,r,o,{unit:i,banner:s,leftover:u=()=>"",readOptions:a}){let l=te(e,n,t,r,a),f=s??n.length>1,c=l.entries.filter(m=>m.kind!=="missing"),d=[],p=[],h=null;for(let m=0;m<c.length;m++){let{name:g,kind:w,shared:y}=c[m],{content:k}=c[m];(y||g===null)&&(h!==null&&(k=h),h=u(k),q(r,h));let S=w==="dir"?"":o(k);if(w==="file"&&S!==k){let M=Dh(e,k,S,i,Dr(g,r));M&&p.push(M)}let I=g===null||g==="-"?"standard input":g;d.push(f?`${m>0?`
254
+ `:""}==> ${I} <==
255
+ ${S}`:S)}for(let m of p)r.notes.add(m);return ne(d.join(""),l)}function US(e){let t=+(e.length>0&&!e.endsWith(`
238
256
  `));for(let n=e.indexOf(`
239
257
  `);n!==-1;n=e.indexOf(`
240
- `,n+1))t++;return t}function oh(e,t,n,r,i){let o=r==="c"?l=>I(l).length:jv,s=o(n),u=o(t);if(s>=u)return null;let a=(r==="c"?"byte":"line")+(u===1?"":"s");return`${e}: selected ${s} of ${u} ${a} from ${i}.`}function Hv(e,t,n){let{flags:r,positional:i}=E(t,{short:["l","w","c","m"]}),o=Xv(r),s=te("wc",i,e,n),u=i.length>1||Object.values(o).filter(Boolean).length>1,a=[],l={l:0,w:0,m:0,c:0};for(let{name:f,content:d,kind:p,shared:m}of s.entries.filter(h=>h.kind!=="missing")){let h=Zv(d,n,o,u);a.push({counts:h,name:f,kind:p,shared:m}),l.l+=h.l,l.w+=h.w,l.m+=h.m,l.c+=h.c}let c=u?Gv(a,n.stdinFile):1;return i.length>1&&a.push({counts:l,name:"total"}),ue(ce(a.map(f=>np(f.counts,f.name,o,c,n))),s)}function Gv(e,t){let n=0,r=1;for(let{name:i,kind:o,shared:s,counts:u}of e)o==="dir"||(i===null||s)&&!t?r=7:n+=u.c;return Math.max(r,String(n).length)}function Xv(e){return e.size===0?{l:!0,w:!0,m:!1,c:!0}:{l:e.has("l"),w:e.has("w"),m:e.has("m"),c:e.has("c")}}function Zv(e,t,n,r){let i=le(t),o=n.c||r||n.m&&i?I(e).length:0;return{l:n.l?(e.match(/\n/gu)??[]).length:0,w:n.w?(e.match(i?/[^\t\n\v\f\r ]+/gu:/[^\t\n\v\f\r \u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u2060\u3000]+/gu)??[]).length:0,m:n.m?i?o:e.length-(e.match(/[\u{10000}-\u{10FFFF}]/gu)??[]).length:0,c:o}}function Vv(e,t){let n=0;for(let r=0;r<t&&n<e.length;r++){for(;n<e.length&&/[ \t]/u.test(e[n]);)n++;for(;n<e.length&&!/[ \t]/u.test(e[n]);)n++}return e.slice(n)}function Yv(e,t,n){let{flags:r,values:i,positional:o}=E(t,{short:["c","d","u","i","D"],valueShort:["f","s","w"]});if(o.length>2)return y(`uniq: extra operand: ${o[2]}`);if(o.length===2&&o[1]!=="-")return v("feature","uniq","output file","uniq: output files are not supported (filesystem is read-only)");let s=pe(i.get("f")??"0","uniq: -f");if(s.error)return s.error;let u=pe(i.get("s")??"0","uniq: -s");if(u.error)return u.error;let a=i.has("w")?pe(i.get("w"),"uniq: -w"):{value:void 0};if(a.error)return a.error;let l=r.has("D"),c=r.has("c");if(l&&c)return y("uniq: printing all duplicated lines and repeat counts is meaningless");let f=mn("uniq",o.slice(0,1),e,n),d=r.has("d"),p=r.has("u"),m=r.has("i"),h=A=>{let V=s.value>0?Vv(A,s.value):A;if(u.value===0&&a.value===void 0){let T=V.toWellFormed();return m?T.replace(/[A-Z]/gu,Y=>Y.toLowerCase()):T}let q=I(V).subarray(u.value,a.value===void 0?void 0:u.value+a.value);return(m?q.map(T=>T>=65&&T<=90?T+32:T):q).join(",")},g=se(f.content),x=[],b=0,S=g.length?h(g[0]):null;for(let A=1;A<=g.length;A++){let V=A===g.length?null:h(g[A]);if(A<g.length&&V===S)continue;let q=A-b,T=q>=2;(l?T:!(d&&p)&&(d?T:!p||!T))&&(l?x.push(...g.slice(b+(p?1:0),A)):x.push(c?String(q).padStart(7)+" "+g[b]:g[b])),b=A,S=V}return ue(ce(x),f)}function nh(){return C()}function Kv(){return{stdout:"",stderr:"",exitCode:1}}var ou={grep:Mr,head:(e,t,n)=>eh("head",e,t,n),tail:(e,t,n)=>eh("tail",e,t,n),wc:Hv,sort:Kp,uniq:Yv,echo:Jd,printf:tp,xargs:Qp,awk:Vp},sh={true:nh,false:Kv,":":nh};var ah={test:Gd,cat:$d,...ou,...Sd,...hc},uh=(e,t)=>(n,r,i)=>{let o=ou.grep(n,[t,...r],i),s=N(o);return s?Q(o,s.kind,e,s.detail,s.message):o},lh={__proto__:null,sed:qd,egrep:uh("egrep","-E"),fgrep:uh("fgrep","-F"),"[":Xd,...mc,...sh,...Ls,...ah},Jv=new Set(["cd",":",...Object.keys(Ls)]),Qv=e=>!!lh[e],ek=["ls","cd","cat","grep","rg","find","head","tail","wc","tree","du","stat","realpath","sort","uniq","cut","tr","awk","nl","tac","hexdump","base64","xargs","echo","printf","test","cp","rm","mkdir","touch","diff","patch","pwd","seq","which","basename","dirname"],tk=rk(),nk=["grep","head","tail","wc","sort","uniq","cut","xargs","awk","tr","nl","tac","hexdump","cat","base64","diff","patch"];function rk(){let e=new Set(Object.keys(ah)),t=[];for(let n of ek)e.delete(n)&&t.push(n);return t.push(...[...e].sort()),t}var ch=Object.freeze(["/usr/local/bin/","/usr/bin/","/bin/","/sbin/"]);function fh(e,t){for(let n of ch)if(e.startsWith(n)){let r=e.slice(n.length);if(t(r))return r}return e}var ik=new Set(["test","[","true","false"]),ok=new Set(["grep","egrep","fgrep"]);function sk(e,t){let n=fh(e[0],t);return ik.has(n)?"status":ok.has(n)?zl(e.slice(1))?"status":"search":"work"}function su(e){let t=Fa(e,Qv),n=Object.freeze({__proto__:null,...lh,...t.handlers}),r=o=>!!n[o],i=Object.freeze([...tk,...t.names]);return Object.freeze({commands:n,names:i,pipeNames:Object.freeze([...nk,...t.pipeNames]),binPrefixes:ch,has:r,shellOnly:o=>Jv.has(o),resolveCommand:o=>fh(o,r),chainRole:o=>sk(o,r),known:i.join(", ")})}var dh=su();function ph(e,t){let n=Kd.get(e);return n!==void 0?v("feature",e,e,`${e}: ${n}`,127):v("command",e,e,`${e}: command not found. Available: ${t.known}`,127)}function mh(e,t,n){let r=ck(e);if(!r)return[];let{start:i,pipe:o,quote:s,words:u}=r;for(;uk.has(u[0]);)u.shift();if(ak.has(u[0]))return[];if(u[0]==="for"&&u.length<=2)return[];let a=e.slice(i),l=hh(a,s);if(!l)return[];let c=u.length===0,f=c?"":n.resolveCommand(hh(u[0],null)?.value??""),d=c?lk(l.value,o,n,t.functions):o?[]:dk(l,t,f==="cd"),p=e.slice(0,i),m=o&&a===""&&p.endsWith("|")?" ":"";return d.map(h=>p+m+a+fk(h.slice(l.value.length),s))}var uk=new Set(["!","{","do","then","else","elif","if","while","until"]),ak=new Set(["done","fi","}","esac"]);function lk(e,t,n,r){let i=t?n.pipeNames:n.names;for(let s of n.binPrefixes)if(e.startsWith(s))return i.filter(u=>u.startsWith(e.slice(s.length))).map(u=>s+u);if(e.startsWith("/")||e.startsWith("./"))return[];let o=[...r.keys()].filter(s=>!i.includes(s));return[...i,...o].filter(s=>s.startsWith(e))}function ck(e){let t=0,n=!1,r=null,i=!1,o=-1,s=[];for(let u=0;u<e.length;u++){let a=e[u];if(r==="'"){a===r&&(r=null);continue}if(a==="\\"&&(!r||'$`"\\\n'.includes(e[u+1]))){if(u+1===e.length)return null;e[++u]!==`
241
- `&&(i=!0);continue}if(a==="`"||a==="$"&&e[u+1]==="(")return null;if(r){a===r&&(r=null);continue}if(a==="'"||a==='"'){r=a,i=!0;continue}if(a==="#"&&!i){let f=e.indexOf(`
242
- `,u);if(f===-1)return null;u=f-1;continue}if(a===" "||a===" "){i&&s.push(e.slice(t,u)),t=u+1,i=!1;continue}let l=a==="|"&&e[u+1]==="|",c=a==="&"&&e[u+1]==="&";if(a==="|"||c||a===";"||a===`
243
- `||a==="("||a===")"&&o===u-1){(l||c)&&u++,a==="("&&(o=u),t=u+1,n=a==="|"&&!l,s.length=0,i=!1;continue}i=!0}return{start:t,pipe:n,quote:r,words:s}}function hh(e,t){if(e==="")return{value:"",mask:null};try{let n=xr(e+(t??""));if(n.length!==1||n[0].kind!=="word")return null;let r=n[0];for(let i=0;i<r.value.length;i++){let o=r.mask?.[i]??"0";if(o!=="1"&&r.value[i]==="$"||o==="0"&&"*?[{".includes(r.value[i]))return null}return r}catch{return null}}function fk(e,t){return t==="'"?e.replaceAll("'","'\\''")+"'":t==='"'?e.replace(/[\\$`"]/gu,"\\$&")+'"':e.replace(/[\s\\'"`$&|;()<>*?[\]{}!#~]/gu,n=>n===`
258
+ `,n+1))t++;return t}function Dh(e,t,n,r,o){let i=r==="c"?l=>A(l).length:US,s=i(n),u=i(t);if(s>=u)return null;let a=(r==="c"?"byte":"line")+(u===1?"":"s");return`${e}: selected ${s} of ${u} ${a} from ${o}.`}function jS(e,t,n){let{flags:r,positional:o}=N(t,{short:["l","w","c","m"]}),i=qS(r),s=te("wc",o,e,n,{read:"as-held"}),u=o.length>1||Object.values(i).filter(Boolean).length>1,a=[],l={l:0,w:0,m:0,c:0};for(let{name:c,content:d,bytes:p,kind:h,shared:m}of s.entries.filter(g=>g.kind!=="missing")){let g=zS(p??d,n,i,u);a.push({counts:g,name:c,kind:h,shared:m}),l.l+=g.l,l.w+=g.w,l.m+=g.m,l.c+=g.c}let f=u?WS(a,n.stdinFile):1;return o.length>1&&a.push({counts:l,name:"total"}),ne(ge(a.map(c=>R1(c.counts,c.name,i,f,n))),s)}function WS(e,t){let n=0,r=1;for(let{name:o,kind:i,shared:s,counts:u}of e)i==="dir"||(o===null||s)&&!t?r=7:n+=u.c;return Math.max(r,String(n).length)}function qS(e){return e.size===0?{l:!0,w:!0,m:!1,c:!0}:{l:e.has("l"),w:e.has("w"),m:e.has("m"),c:e.has("c")}}function zS(e,t,n,r){let o=le(t),i=n.c||r||n.m&&o?HS(e):0;return{l:n.l?GS(e):0,w:n.w?JS(e,t):0,m:n.m?o?i:XS(e):0,c:i}}var HS=e=>typeof e=="string"?A(e).length:e.length;function GS(e){let t=0,n=typeof e=="string"?`
259
+ `:10;for(let r=e.indexOf(n);r>=0;r=e.indexOf(n,r+1))t++;return t}function XS(e){if(typeof e=="string")return e.length-(e.match(/[\u{10000}-\u{10FFFF}]/gu)??[]).length;let t=0;for(let n of Nr(e))n>=0&&t++;return t}var ZS=new Set([9,10,11,12,13,32]),YS=new Set([160,8199,8239,8288]),qu=1,zu=0,Hu=2,VS=Uint8Array.from({length:128},(e,t)=>ZS.has(t)?qu:t>32&&t<127?Hu:zu),KS=(e,t)=>t.has("print",e)?t.has("space",e)||YS.has(e)?qu:Hu:zu;function JS(e,t){let n=re(t.locale),r=0,o=!1;for(let i of QS(e,t)){let s=i<0?zu:i<128?VS[i]:KS(i,n);s===qu?(o&&r++,o=!1):s===Hu&&(o=!0)}return o?r+1:r}function*QS(e,t){if(typeof e!="string"){yield*le(t)?e:Nr(e);return}if(le(t)){yield*A(e);return}for(let n=0;n<e.length;){let r=e.codePointAt(n);yield r>=55296&&r<=57343?65533:r,n+=r>65535?2:1}}function eE(e,t){let n=0;for(let r=0;r<t&&n<e.length;r++){for(;n<e.length&&/[ \t]/u.test(e[n]);)n++;for(;n<e.length&&!/[ \t]/u.test(e[n]);)n++}return e.slice(n)}function tE(e,t,n){let{flags:r,values:o,positional:i}=N(t,{short:["c","d","u","i","D"],valueShort:["f","s","w"]});if(i.length>2)return x(`uniq: extra operand: ${i[2]}`);if(i.length===2&&i[1]!=="-")return v("feature","uniq","output file","uniq: output files are not supported (filesystem is read-only)");let s=be(o.get("f")??"0","uniq: -f");if(s.error)return s.error;let u=be(o.get("s")??"0","uniq: -s");if(u.error)return u.error;let a=o.has("w")?be(o.get("w"),"uniq: -w"):{value:void 0};if(a.error)return a.error;let l=r.has("D"),f=r.has("c");if(l&&f)return x("uniq: printing all duplicated lines and repeat counts is meaningless");let c=Ka("uniq",i.slice(0,1),e,n),d=r.has("d"),p=r.has("u"),h=r.has("i"),m=S=>{let I=s.value>0?eE(S,s.value):S;if(u.value===0&&a.value===void 0){let C=I.toWellFormed();return h?C.replace(/[A-Z]/gu,H=>H.toLowerCase()):C}let M=A(I).subarray(u.value,a.value===void 0?void 0:u.value+a.value);return(h?M.map(C=>C>=65&&C<=90?C+32:C):M).join(",")},g=he(c.content),w=[],y=0,k=g.length?m(g[0]):null;for(let S=1;S<=g.length;S++){let I=S===g.length?null:m(g[S]);if(S<g.length&&I===k)continue;let M=S-y,C=M>=2;(l?C:!(d&&p)&&(d?C:!p||!C))&&(l?w.push(...g.slice(y+(p?1:0),S)):w.push(f?String(M).padStart(7)+" "+g[y]:g[y])),y=S,k=I}return ne(ge(w),c)}function Rh(){return F()}function nE(){return{stdout:"",stderr:"",exitCode:1}}var Gu={grep:so,head:(e,t,n)=>Lh("head",e,t,n),tail:(e,t,n)=>Lh("tail",e,t,n),wc:jS,sort:Ih,uniq:tE,echo:T1,printf:_1,xargs:Fh,awk:Oh},Bh={true:Rh,false:nE,":":Rh};var qh={test:E1,cat:r1,...Gu,...Qp,...Xc},Uh=(e,t)=>(n,r,o)=>{let i=Gu.grep(n,[t,...r],o),s=O(i);return s?ie(i,s.kind,e,s.detail,s.message):i},Xu={__proto__:null,sed:k1,egrep:Uh("egrep","-E"),fgrep:Uh("fgrep","-F"),"[":$1,...Zc,...Bh,...yu,...qh},zh=new Set(["cd",":",...Object.keys(yu)]),rE=e=>!!Xu[e],oE=new Set(["basename","cp","dirname","ln","mkdir","patch","rm","touch"]),Hh=Object.fromEntries(Object.entries(qh).filter(([e])=>!oE.has(e))),iE=["ls","cd","cat","grep","rg","find","head","tail","wc","tree","du","stat","realpath","sort","uniq","cut","tr","awk","nl","tac","hexdump","base64","xargs","echo","printf","test","diff","pwd","seq","which"],jh=Object.keys(Xu).filter(e=>!zh.has(e)&&!Object.hasOwn(Hh,e)).sort(),sE=new Set(["base32","brotli","egrep","fgrep","gunzip","gzcat","gzip","od","sed","sha1sum","sha256sum","sha384sum","sha512sum","shasum","xxd","zcat"]),Wh=aE(),uE=["grep","head","tail","wc","sort","uniq","cut","xargs","awk","tr","nl","tac","hexdump","cat","base64","diff","patch"];function aE(){let e=new Set(Object.keys(Hh)),t=[];for(let n of iE)e.delete(n)&&t.push(n);return t.push(...[...e].sort()),t}var Gh=Object.freeze(["/usr/local/bin/","/usr/bin/","/bin/","/sbin/"]);function Xh(e,t){for(let n of Gh)if(e.startsWith(n)){let r=e.slice(n.length);if(t(r))return r}return e}var lE=new Set(["test","[","true","false"]),fE=new Set(["grep","egrep","fgrep"]);function cE(e,t){let n=Xh(e[0],t);return lE.has(n)?"status":fE.has(n)?fc(e.slice(1))?"status":"search":"work"}function Zu(e){let t=ql(e,rE),n=Object.freeze({__proto__:null,...Xu,...t.handlers}),r=i=>!!n[i],o=Object.freeze([...Wh,...jh,...t.names]);return Object.freeze({commands:n,names:o,pipeNames:Object.freeze([...uE,...jh.filter(i=>sE.has(i)),...t.pipeNames]),binPrefixes:Gh,has:r,shellOnly:i=>zh.has(i),resolveCommand:i=>Xh(i,r),chainRole:i=>cE(i,r),known:[...Wh,...t.names].join(", ")})}var Zh=Zu();function Yh(e,t){let n=I1.get(e);return n!==void 0?v("feature",e,e,`${e}: ${n}`,127):v("command",e,e,`${e}: command not found. Available: ${t.known}`,127)}function Kh(e,t,n){let r=mE(e);if(!r)return[];let{start:o,pipe:i,quote:s,words:u}=r;for(;dE.has(u[0]);)u.shift();if(pE.has(u[0]))return[];if(u[0]==="for"&&u.length<=2)return[];let a=e.slice(o),l=Vh(a,s);if(!l)return[];let f=u.length===0,c=f?"":n.resolveCommand(Vh(u[0],null)?.value??""),d=f?hE(l.value,i,n,t.functions):i?[]:wE(l,t,c==="cd"),p=e.slice(0,o),h=i&&a===""&&p.endsWith("|")?" ":"";return d.map(m=>p+h+a+gE(m.slice(l.value.length),s))}var dE=new Set(["!","{","do","then","else","elif","if","while","until"]),pE=new Set(["done","fi","}","esac"]);function hE(e,t,n,r){let o=t?n.pipeNames:n.names;for(let s of n.binPrefixes)if(e.startsWith(s))return o.filter(u=>u.startsWith(e.slice(s.length))).map(u=>s+u);if(e.startsWith("/")||e.startsWith("./"))return[];let i=[...r.keys()].filter(s=>!o.includes(s));return[...o,...i].filter(s=>s.startsWith(e))}function mE(e){let t=0,n=!1,r=null,o=!1,i=-1,s=[];for(let u=0;u<e.length;u++){let a=e[u];if(r==="'"){a===r&&(r=null);continue}if(a==="\\"&&(!r||'$`"\\\n'.includes(e[u+1]))){if(u+1===e.length)return null;e[++u]!==`
260
+ `&&(o=!0);continue}if(a==="`"||a==="$"&&e[u+1]==="(")return null;if(r){a===r&&(r=null);continue}if(a==="'"||a==='"'){r=a,o=!0;continue}if(a==="#"&&!o){let c=e.indexOf(`
261
+ `,u);if(c===-1)return null;u=c-1;continue}if(a===" "||a===" "){o&&s.push(e.slice(t,u)),t=u+1,o=!1;continue}let l=a==="|"&&e[u+1]==="|",f=a==="&"&&e[u+1]==="&";if(a==="|"||f||a===";"||a===`
262
+ `||a==="("||a===")"&&i===u-1){(l||f)&&u++,a==="("&&(i=u),t=u+1,n=a==="|"&&!l,s.length=0,o=!1;continue}o=!0}return{start:t,pipe:n,quote:r,words:s}}function Vh(e,t){if(e==="")return{value:"",mask:null};try{let n=Ur(e+(t??""));if(n.length!==1||n[0].kind!=="word")return null;let r=n[0];for(let o=0;o<r.value.length;o++){let i=r.mask?.[o]??"0";if(i!=="1"&&r.value[o]==="$"||i==="0"&&"*?[{".includes(r.value[o]))return null}return r}catch{return null}}function gE(e,t){return t==="'"?e.replaceAll("'","'\\''")+"'":t==='"'?e.replace(/[\\$`"]/gu,"\\$&")+'"':e.replace(/[\s\\'"`$&|;()<>*?[\]{}!#~]/gu,n=>n===`
244
263
  `?`'
245
- '`:"\\"+n)}function dk(e,t,n=!1){let r=e.value,i=r.startsWith("~")&&(e.mask?.[0]??"0")==="0"&&!e.empty?.some(p=>p<=1)&&(r.length===1||(e.mask?.[1]??"0")==="0");if(i&&r==="~")return t.fs.isDir($(t.cwd,Jt(t),t.fs).path)?["~/"]:[];if(i&&!r.startsWith("~/"))return[];let o=r.lastIndexOf("/"),s=r.slice(0,o+1),u=r.slice(o+1),a=i?Jt(t)+s.slice(1):s||".",l=$(t.cwd,a,t.fs).path;if(!t.fs.isDir(l))return[];let{dirs:c,files:f}=t.fs.listDir(l),d=c.map(p=>p+"/");return n||d.push(...f),d.filter(p=>p.startsWith(u)&&(u.startsWith(".")||!p.startsWith("."))).filter(p=>s!==""||u===""||!p.startsWith("-")).map(p=>s===""&&p.startsWith("-")?"./"+p:s+p)}function Ai(e,t){let n=dn(),{units:r,error:i,incomplete:o}=kr(e,t),s=[],u=null;try{bh(s,r)}catch(c){if(!N(c))throw c;u=c}let a=i??u,l=a===null?null:N(a);return l&&n.add(l),{ok:a===null,incomplete:o,error:a===null?null:a.message,list:s,unsupported:Object.freeze(n.entries)}}var uu={seq:";",and:"&&",or:"||"},yh=e=>bh([],e);function bh(e,t){for(let n of t)for(let r of n)e.push(vh(r,e.length===0?uu[r.gate]:uu[r.gate]??";"));return e}var yt=e=>e.map(t=>vh(t,uu[t.gate]));function vh(e,t){let{type:n,...r}=e.stages.length===1?gh(e.stages[0]):e.stages.length===0?{type:"command",argv:[]}:{type:"pipeline",stages:e.stages.map(gh)};return{type:n,...t?{op:t}:{},...e.negate?{negate:!0}:{},...e.background?{background:!0}:{},...e.warnings?{warnings:e.warnings}:{},...r}}function gh(e){let t=pk(e);return e.assigns.length>0&&(t.assignments=e.assigns.map(n=>({name:n.name,value:it(n.word,gk)}))),e.redirs.length>0&&(t.redirects=e.redirs.map(Nk)),t}function pk(e){return e.group?{type:e.isolate?"subshell":"group",list:yt(e.group)}:e.define?{type:"function",name:e.define.name,list:yt(e.define.body)}:e.loop?hk(e.loop):e.conditional?mk(e.conditional):e.test?{type:"test",expression:Ni(e.test)}:{type:"command",argv:e.words.flatMap(kh)}}function hk(e){return e.words?{type:"for",name:e.name,words:e.words.flatMap(kh),list:yt(e.body)}:{type:e.until?"until":"while",condition:yt(e.condition),list:yt(e.body)}}function mk(e){let t={type:"if",branches:e.branches.map(n=>({condition:yt(n.condition),list:yt(n.body)}))};return e.otherwise&&(t.otherwise=yt(e.otherwise)),t}var au={split:!0,glob:!0},gk={assignment:!0},$i={},wk={glob:!0},xk=new Set(["==","=","!="]);function it(e,t=au,n=!1){if(!$k(e))return e.value;let r=yk(e,n?{...t,braces:!0}:t);return r.length===1?r[0]:{type:"parts",parts:r}}var kh=e=>{let t=Sh(e);return t===null?[it(e,au,!0)]:t.map(n=>it(n))};function wh(e){let t=Sh(e);return t?.length===1?it(t[0]):it(e,au,!0)}function Sh(e){try{return Un(e)}catch(t){if(N(t))return null;throw t}}function yk(e,t){let{value:n}=e,r=e.mask??"0".repeat(n.length),i=new Set(e.empty??[]),o=[],s="",u=!1,a=0,l=p=>{let m=o.at(-1);typeof p=="string"&&typeof m=="string"?o[o.length-1]=m+p:o.push(p)},c=p=>{s!==""&&l(bk(e,s,u,a,p,t)),s=""},f=t.glob===!0&&t.split!==!0,d=mr(e,t.assignment===!0);for(let p=0;p<=n.length&&(i.has(p)&&(c(p),l("")),p!==n.length);p++){if(d.has(p)){c(p),l({type:"variable",name:"HOME",multi:!1});continue}if(r[p]==="0"&&(n[p]==="<"||n[p]===">")&&n[p+1]==="("){let h=Sk(n,p);c(p),l(h.part),p=h.end-1;continue}if(r[p]!=="1"&&(n[p]==="$"||n[p]==="`")){let h=Ek(n,p,r[p]==="2",t);if(h){c(p),l(f&&r[p]!=="2"?vk(h.part):h.part),p=h.end-1;continue}}s!==""&&r[p]!=="0"!==u&&c(p),s===""&&(a=p),u=r[p]!=="0",s+=n[p]}return c(n.length),o}function bk(e,t,n,r,i,o){return n?t:o.braces&&/[{},]/u.test(t)&&Oc(e)?{type:"brace",source:t}:o.glob&&kk(e,r,i)?{type:"pattern",pattern:t,multi:o.split===!0}:t}var vk=e=>e.type==="variable"||e.type==="substitution"?{type:"pattern",pattern:e,multi:!1}:e;function kk(e,t,n){for(let r=t;r<n;r++){let i=e.value[r];if(i==="*"||i==="?"||i==="["&&Eh(e,r))return!0}return!1}function xh(e,t){let{units:n,error:r}=kr(e,!0);return{type:"substitution",list:r===null?yh(n):[],...r===null?{}:{error:r.message},...t}}function Sk(e,t){let{raw:n,command:r}=gr(e,t);return{part:{type:"process",op:e[t],list:yh(kr(r,!0).units)},end:t+n.length}}function Ek(e,t,n,r){let i=r.split===!0,o={multi:i&&!n};if(e[t]==="`"){let{raw:d,command:p}=Te(e,t);return{part:xh(p,o),end:t+d.length}}let s=_e(e,t,0,n);if(!s)return null;let u=t+s.raw.length;if(s.command!==void 0)return{part:xh(s.command,o),end:u};if(s.arithmetic!==void 0)return{part:{type:"arithmetic",source:s.arithmetic},end:u};let{name:a,operator:l,word:c}=s.parameter??{name:s.name,operator:""},f={type:"variable",name:a,...l?{operator:l}:{},...c===void 0?{}:{operand:c},...o};return a==="@"&&i&&(f.multi=!0),{part:f,end:u}}function $k(e){for(let t=0;t<e.value.length;t++){let n=e.value[t],r=e.mask===null?"0":e.mask[t];if((n==="$"||n==="`")&&r!=="1")return!0;if(r==="0"&&("~*?{".includes(n)||(n==="<"||n===">")&&e.value[t+1]==="("||n==="["&&Eh(e,t)))return!0}return!1}function Eh(e,t){for(let n=t+1;n<e.value.length;n++)if(e.value[n]==="]"&&(e.mask===null||e.mask[n]==="0"))return!0;return!1}function Nk(e){return e.op==="dup"?{fd:e.fd,op:">&",toFd:e.toFd}:e.op==="close"?{fd:e.fd,op:">&-"}:e.op==="text"?{fd:0,op:"<<",text:e.body,expand:e.expand}:e.op==="herestring"?{fd:0,op:"<<<",text:it(e.word,$i)}:e.op==="read"?{fd:0,op:"<",target:wh(e.word)}:{fd:e.fd,op:(e.both?"&>":">")+(e.append?">":""),target:e.target??wh(e.word)}}function Ni(e){return e.kind==="and"||e.kind==="or"?{type:e.kind,left:Ni(e.left),right:Ni(e.right)}:e.kind==="not"?{type:"not",expression:Ni(e.expression)}:e.kind==="unary"?{type:"unary",op:e.op,word:it(e.word,$i)}:{type:"binary",op:e.op,left:it(e.left,$i),right:it(e.right,xk.has(e.op)?wk:$i)}}function Ah(e,t){let n=Ai(e,t);if(!n.ok)throw new Error(n.error);return ot(n.list,{defined:new Map,open:new Set})}function ot(e,t){let n=[];for(let r of e){if(r.type==="function"){if(r.op==="&&"||r.op==="||")throw Ae("a function defined behind a gate");t.defined.set(r.name,r.list);continue}(r.op==="&&"||r.op==="||")&&n.push(r.op),n.push(Ok(r,t)),r.background&&n.push("&")}return n}function Ih(e,t,n=0){let r=Tk(e,t);if(r.type!=="command"||typeof r.argv[0]!="string")return r;let i=t.defined.get(r.argv[0]);if(i===void 0)return r;if(n>16||t.open.has(r.argv[0]))throw Ae("a function that calls itself");return Ih({type:"group",name:r.argv[0],list:i,redirects:r.redirects,assignments:r.assignments},t,n+1)}var Ak={if:"`if`",test:"`[[ \u2026 ]]`",pipeline:"a pipeline of pipelines",function:"a function defined in a pipeline"},Ik=new Set(["command","subshell","group","for","while","until"]);function Ok(e,t){if(e.negate)throw Ae("`!`");let n=e.type==="pipeline"?e.stages:[e],r=[],i=0;for(let[o,s]of n.entries()){let u=Ih(s,t);if(!Ik.has(u.type))throw Ae(Ak[u.type]);if(u.type==="command"&&u.argv.length===0&&!u.assignments)throw Ae("a command with no name");let a=u.redirects??[],l=Mk(a,o);l&&(r.push(Pk(l,t)),i++);let c=Ck(u,t);Lk(c,i)||(r.push(c),i++);for(let f of a)f!==l&&r.push(Uk(f,t))}return r}function Ck(e,t){if(e.assignments&&e.argv===void 0)throw Ae("an assignment on a call of more than one command");if(e.type==="subshell")return{type:"parens",summary:ot(e.list,{defined:new Map(t.defined),open:t.open})};if(e.type==="group")return{type:"braces",summary:Fk(e,t)};if(e.type==="for")return{type:"for",name:e.name,words:e.words.map(r=>cn(r,t)),summary:ot(e.list,t)};if(e.type==="while"||e.type==="until")return{type:e.type,condition:ot(e.condition,t),summary:ot(e.list,t)};let n=e.argv.map(r=>cn(r,t));return e.assignments&&n.unshift(Rk(e.assignments,t)),n}function Fk(e,t){if(e.name===void 0)return ot(e.list,t);t.open.add(e.name);try{return ot(e.list,t)}finally{t.open.delete(e.name)}}function Tk(e,t){if(e.type!=="subshell"&&e.type!=="group"||e.list.length!==1)return e;let[n]=e.list;return n.type!=="command"||n.negate||n.background||e.type==="subshell"&&(n.assignments||typeof n.argv[0]!="string"||_k.has(n.argv[0])||t.defined.has(n.argv[0]))||(e.redirects??[]).length>0&&(n.redirects??[]).length>0||e.assignments&&n.assignments?e:{...n,...e.assignments||n.assignments?{assignments:e.assignments??n.assignments}:{},redirects:[...n.redirects??[],...e.redirects??[]]}}var _k=new Set(["cd","pushd","popd","exit","exec","export","unset","set","shopt","shift","source",".","eval","read","readonly","declare","typeset","local","alias","unalias","trap","umask","ulimit","let","return","break","continue","hash","getopts","disown","bind","enable"]),Lk=(e,t)=>t>0&&e.length===1&&e[0]==="cat",Rk=(e,t)=>({type:"assignments",assignments:e.map(n=>({name:n.name,value:cn(n.value,t)}))});function Mk(e,t){let n=e.filter(r=>r.op==="<"||r.op==="<<"||r.op==="<<<");if(n.length===0)return null;if(t>0)throw Ae("a pipeline stage reading its own input");if(n.length>1)throw Ae("a command reading from two places");return n[0]}function Pk(e,t){if(e.op==="<")return["cat",cn(e.target,t)];if(e.op==="<<<")return Dk(cn(e.text,t));if(e.expand&&/[$`\\]/u.test(e.text))throw Ae("a here-document its delimiter leaves to expand");return Oh(e.text)}var Dk=e=>typeof e=="string"?Oh(`${e}
246
- `):["printf","%s\\n",e];function Oh(e){let t=e.endsWith(`
247
- `)?e.slice(0,-1):null;return t!==null&&!t.startsWith("-")?["echo",t]:["printf","%s",e]}function Uk(e,t){let{fd:n,op:r}=e,i=r.startsWith("&")||n===1?"":String(n);return r===">&"?[`${i}>&${e.toFd}`]:r===">&-"?[`${i}>&-`]:[i+r,cn(e.target,t)]}var cn=(e,t)=>{if(typeof e=="string")return e;let n=Bk(e);return n!==null?n:e.type==="parts"?{type:"parts",parts:e.parts.map(r=>$h(r,t))}:$h(e,t)};function $h(e,t){if(typeof e=="string"||e.type==="pattern")return e;if(e.type==="variable"){if(Nh.test(e.operand??""))throw Ae(lu(e),"a literal word");return e}if(e.type==="process")return{type:"process",op:e.op,summary:ot(e.list,t)};if(e.type==="arithmetic"){if(Nh.test(e.source))throw Ae(lu(e),"a literal word");return e}if(e.type!=="substitution")throw Ae(lu(e),"a literal word");if(e.error)throw new Error(e.error);return{type:"shell",summary:ot(e.list,t),multi:e.multi}}function Bk(e){let t="";for(let n of e.type==="parts"?e.parts:[e]){if(typeof n=="string"){t+=n;continue}if(n.multi)return null;let r=Wk(n);if(r===null)return null;t+=r}return t}function Wk(e){if(e.type!=="substitution"||e.list.length!==1)return null;let[t]=e.list;if(t.type!=="command"||t.negate||t.assignments||t.argv.length!==1||t.argv[0]!=="cat")return null;let[n,...r]=t.redirects??[];return r.length>0||n?.op!=="<<"||n.expand?null:n.text.replace(/\n+$/u,"")}var lu=e=>typeof e=="string"?e:e.type==="pattern"?e.pattern:e.type==="brace"?e.source:e.type==="variable"?`\${${e.name}${e.operator??""}${e.operand??""}}`:e.type==="arithmetic"?"$((\u2026))":"$(\u2026)",Nh=/\$\(|`/u,Ae=(e,t="a simple chain")=>new Error(`summarize: ${e} is not ${t}`);var Ch=e=>({parse:t=>Ai(t,e.writable),summarize:t=>Ah(t,e.writable)});function Fh(e,t,n,r=!1){let i=(t.substitutionDepth??0)+1;if(i>Dt)throw new w("feature","command substitution nesting limit",`command substitution nesting beyond ${Dt} levels is not supported`);let o=t.expansionFds[2],u=ae(t,{substitutionDepth:i,outputFds:{1:"out",2:typeof o=="object"||o==="closed"?o:"err"},closed:{out:!1,err:o==="closed"}},()=>gt(t,()=>{let f;try{f=Oa(e,t.writable,t.registry.has)}catch(p){let m=N(p);if(!m){if(r)return y(`error: command substitution: ${p.message}`,2);throw new w("feature","command substitution syntax",`runtime command substitution syntax errors are not supported: ${p.message}`)}return t.unsupported.add(m),y(`error: ${p.message}`,1)}let d=f.length===1&&!f[0].negate&&f[0].stages.length===1?f[0].stages[0]:null;return d&&!d.group&&!d.loop&&!d.conditional&&!d.test&&d.words.length===0&&d.assigns.length===0&&d.redirs.length===1&&d.redirs[0].op==="read"&&d.words.push({value:"cat",mask:null}),n(f,t,{text:t.stdinLeft})}));t.lastExit=t.substitutionExit=u.exitCode;let a=u.stdout,l=u.stderr;if(a.includes("\0")){let f=a.length;a=a.replaceAll("\0","");let d=f-a.length;t.notes.add(`command substitution: discarded ${d} NUL ${d===1?"byte":"bytes"}.`),l+=`warning: command substitution: ignored null byte in input
248
- `}Pr(t,l);let c=a.length;for(;c>0&&a[c-1]===`
249
- `;)c--;return a.slice(0,c)}function Th(e,t){return{stdout:"",stderr:"",exitCode:fn(e,t)?0:1}}var cu=(e,t)=>os(e,t).value;function fn(e,t){let{kind:n}=e;if(n==="not")return!fn(e.expression,t);if(n==="and")return fn(e.left,t)&&fn(e.right,t);if(n==="or")return fn(e.left,t)||fn(e.right,t);let{op:r}=e;if(n==="unary"){let u=cu(e.word,t);if(r==="-n")return u!=="";if(r==="-z")return u==="";if(["-a","-e","-f","-d"].includes(r))return _s(r,u,t);if(r==="-v")return zk(u,t);cr(r)}["<",">","-nt","-ot","-ef"].includes(r)&&cr(r);let i=cu(e.left,t);if(Object.hasOwn(Jn,r)){let u=cu(e.right,t);return Jn[r](Ct(i,t),Ct(u,t))}let o=os(e.right,t);_n(o)&&cr("extglob");let s=$e(Vt(o),{bash:!0}).test(i);return r==="!="?!s:s}function zk(e,t){return e.includes("[")&&cr("-v array subscript"),/^[ \t\n\r\f\v]*[+-]?0+[ \t]*$/u.test(e)&&cr("-v positional parameter"),/^[A-Za-z_][A-Za-z0-9_]*$/u.test(e)?mt(e,t).set:!1}function cr(e){throw new w("feature",`[[ ${e}`,`${e} in [[ is not supported`)}function Lh(e,t,n,r){return e.define?(t.functions.set(e.define.name,e.define.body),R()):e.test?Th(e.test,t):e.group?Xk(e,t,n,r):e.loop?e.loop.words?Hk(e.loop,t,r):qk(e.loop,t,r):Gk(e.conditional,t,n,r)}var Rh=1e4,_h={kind:"feature",command:null,detail:"loop limit",message:`a loop running more than ${Rh} times is not supported`};function qk(e,t,n){let r=R(),i={text:t.stdinLeft};t.loopDepth++;try{for(let o=0;;o++){if(o===Rh){t.unsupported.add(_h),_(r,y(`error: ${_h.message}`,1));break}let s=r.exitCode,u=n(e.condition,t,i,!0);if(_(r,u),r.exitCode=s,u.halt||u.control)return{...r,halt:u.halt,control:u.control,blame:u.blame};if(u.exitCode===0==!!e.until)break;let a=n(e.body,t,i);if(_(r,a),r.blame=a.blame,a.halt)return{...r,halt:!0};if(a.control?.levels>1)return{...r,control:{...a.control,levels:a.control.levels-1}};if(a.control?.type==="break")break}}finally{t.loopDepth--}return r}var jk={value:"for",mask:null};function Hk(e,t,n){let r=Wn([jk,...e.words],t),i=R(),o={text:t.stdinLeft};t.loopDepth++;try{for(let s of r.argv.slice(1)){t.vars.set(e.name,s);let u=n(e.body,t,o);if(_(i,u),i.blame=u.blame,u.halt)return{...i,halt:!0};if(u.control?.levels>1)return{...i,control:{...u.control,levels:u.control.levels-1}};if(u.control?.type==="break")break}}finally{t.loopDepth--}return i}function Gk(e,t,n,r){let i=R(),o={text:n};for(let u of e.branches){let a=r(u.condition,t,o,!0);if(_(i,a),a.halt||a.control)return{...i,halt:a.halt,control:a.control,blame:a.blame};if(a.exitCode!==0)continue;let l=r(u.body,t,o);return _(i,l),{...i,halt:l.halt,control:l.control,blame:l.blame}}if(!e.otherwise)return i.exitCode=0,i;let s=r(e.otherwise,t,o);return _(i,s),{...i,halt:s.halt,control:s.control,blame:s.blame}}function Xk(e,t,n,r){let i={text:n};return e.isolate?{...gt(t,()=>r(e.group,t,i)),halt:!1,control:void 0}:r(e.group,t,i)}var Zk=new Set(["sort","cat"]),Vk=new Set(["wc","tac"]);function fu(e){let t=null,n=null,r=o=>{t&&!t.bufferReads&&t.reads.push(o)},i=o=>{if(o!==void 0)for(let s=t;s;s=s.parent){if(!s.reads.includes(o)||s===t&&n?.scope===s&&(n.unsupported||s.buffered||n.fd===1&&(Zk.has(s.name)||Vk.has(s.name)&&!s.reads.slice(1).includes(o))))continue;if(s.failure)throw s.failure;let u=s===t&&n?.fd===2,a=u?"input modified by diagnostics":"streaming self-output",l=u?"reading input while diagnostics write to the same file is not supported":"writing to an actively read input file is not supported";throw s.failure=Q(new w("feature",a,l),"feature",s.name,a,l),s.failure}};return e.observeIo?.({read:r,write:i}),{read:r,bufferOutput(){t&&(t.buffered=!0)},bufferReads(o){if(!t)return o();let s=t,u=s.bufferReads;s.bufferReads=!0;try{return o()}finally{s.bufferReads=u}},setReads(o){t&&(t.reads=o)},run(o,s){let u=t;t={name:o,reads:[],parent:u};try{return s()}finally{t=u}},output(o,s,u){let a=n;n={scope:t,fd:null,unsupported:!!N(o)};try{for(let l of Rn(o))l.text!==""&&(n.fd=l.fd,i(s.fds[l.fd]?.identity));return u((l,c)=>{n.fd=l.fd,c.write(l.text)})}finally{n=a}}}}function pu(e,t){let n={1:t.outputFds[1]?.path?t.outputFds[1]:"out",2:t.outputFds[2]?.path?t.outputFds[2]:"err"};return Yt(e,{fds:n},t)}function fr(e,t,n,r=!1){if(e.some(u=>u.background))throw new w("feature","&","background processes (`&`) are not supported");let i=R(),o=null,s=null;for(let u of e){if(u.warnings&&_(i,Yt({...R(u.warnings),exitCode:i.exitCode},{fds:t.outputFds},t)),u.gate==="and"&&i.exitCode!==0){(s??=Eu()).skip(r?null:o,i.exitCode);continue}if(u.gate==="or"&&i.exitCode===0)continue;s?.flush(t.notes);let a=Yk(u.stages,t,n);if(_(i,a),u.negate&&!a.halt&&(i.exitCode=a.exitCode===0?1:0),o=u.negate?null:a.blame,t.lastExit=i.exitCode,a.halt||a.control){Object.assign(i,{halt:a.halt,control:a.control});break}}return s?.flush(t.notes),t.stdinLeft=n.text,Object.assign(i,{blame:o})}function Yk(e,t,n){let r=R(),i=n.text;for(let o=0;o<e.length;o++){let s=e[o],u=o===0,a="",l={...t.outputFds};o<e.length-1&&(l[1]={write(p){a+=p}});let c=i,f=()=>Kk(s,t,c,u&&t.stdinFile,l,u?t.stdinPiped:!0),d=e.length>1?gt(t,f):f();u&&(n.text=d.inputLeft),_(r,d),i=a,r.blame=d.blame,e.length===1&&(r.halt=d.halt,r.control=d.control)}return r}function Kk(e,t,n,r,i,o){let s={fds:i,stdin:n,stdinFile:r,stdinPiped:o,stdinOrigin:r?t.stdinOrigin:null,stdinHandle:r?t.stdinHandle:null};return ae(t,{substitutionExit:null,expansionOutput:R(),expansionFds:i},()=>du(s,t,()=>{let u=!e.group&&!e.loop&&!e.conditional&&!e.test&&!e.define,a,l;try{u&&(a=Wn(e.words,t),a.argv.length===0?rS(e.assigns,t):a.temps=iS(e.assigns,t))}catch(h){l=Ii(t,h)}if(l)return _(t.expansionOutput,Mh(l,s,t)),{...t.expansionOutput,inputLeft:t.stdinLeft,halt:l.halt};let c=Jk(e,t,t.stdinLeft,r,i);t.expansionFds=c.fds;let f=!1,d=null,p=du(c,t,()=>Qk(t,()=>{if(c.error)return c.error;if(!u){let b=Lh(e,t,c.stdin,fr);return f=!0,d=b.blame??null,b}let h=a.argv.length>0?a.argv[0]:null,g=h===null?void 0:t.functions.get(h);if(g){if(f=!0,t.calling.has(h)){let b=v("feature",h,"function recursion",`${h}: a function calling itself is not supported`);return t.unsupported.add(N(b)),b}t.calling.add(h);try{return ae(t,{loopDepth:0},()=>Ph(a.temps,t,()=>fr(g,t,{text:c.stdin})))}finally{t.calling.delete(h)}}let x=nS(t,a);return a.argv.length&&(d=Su(t.registry.chainRole(a.argv),a.argv[0])),x})),m=c.inherited?t.stdinLeft:c.parentLeft;return _(t.expansionOutput,f?p:Mh(p,c,t)),{...t.expansionOutput,inputLeft:m,halt:p.halt,control:p.control,blame:d}}))}function Mh(e,t,n){try{return Yt(e,t,n)}catch(r){return Yt(Ii(n,r),t,n)}}function Jk(e,t,n,r,i){let o={...i},s=n,u=r,a=u?t.stdinOrigin:null,l=u?t.stdinHandle:null,c=!0,f=n,d=!1,p=h=>({error:h,fds:o,stdin:s,stdinFile:u,stdinPiped:d||t.stdinPiped,stdinOrigin:u?a:null,stdinHandle:u?l:null,inherited:c,parentLeft:f}),m=h=>{let g=ae(t,{expansionFds:o},()=>du({fds:o,stdin:s,stdinFile:u,stdinOrigin:a,stdinHandle:l},t,h));return s=t.stdinLeft,c&&(f=s),g};try{for(let h of e.redirs)if(h.op==="dup"){if(o[h.toFd]===void 0||o[h.toFd]==="closed")return p(y(`error: ${h.toFd}: Bad file descriptor`));o[h.fd]=o[h.toFd]}else if(h.op==="close")o[h.fd]="closed";else if(h.op==="to"){let g=h.target===void 0?m(()=>is(h.word,t)):{value:h.target};if(g.error)return p(y(`error: ${g.error}`));let x=g.value==="/dev/null"?"null":g.value==="/dev/stdout"?o[1]:g.value==="/dev/stderr"?o[2]:t.writable?t.fs.openWritable(t.cwd,g.value,h.append):null;if(x===null){let b=Qi(h.label,g.value,t.writable);return t.unsupported.add(N(b)),p(y(`error: ${b.message}`))}if(x==="closed")return p(y(`error: ${g.value}: No such file or directory`));o[h.fd]=x,h.both&&(o[2]=x)}else if(h.op==="text")s=h.expand?m(()=>Ft(eS(h.body),t)):h.body,u=!1,c=!1;else if(h.op==="herestring")s=m(()=>Ft(h.word,t))+`
250
- `,u=!1,c=!1;else{let g=m(()=>is(h.word,t)),x=g.error?{error:y(`error: ${g.error}`)}:tS(g.value,t,u?a:s);if(x.error)return p(x.error);s=x.content,(g.value!=="/dev/stdin"||u)&&(c=!1),g.value!=="/dev/stdin"&&(u=g.value!=="/dev/null",a=u?s:null,l=x.handle,d=u)}if(u&&l){let h=t.io.bufferReads(()=>t.fs.readIdentity(l.identity));if(h!==l.content){if(c||s!==l.content)throw new w("feature","modified redirected input","reading an inherited input file after it changes is not supported");s=a=h,l={...l,content:h}}}}catch(h){return p(Ii(t,h))}return p()}function Ii(e,t){D(e,"shell",t?.path,t?.fsError);let n=N(t);return n&&e.unsupported.add(n),{...y(`error: ${G(t)}`,1),...t?.halt?{halt:!0}:{}}}function Qk(e,t){try{return t()}catch(n){return Ii(e,n)}}function du(e,t,n){let r={outputFds:e.fds,closed:{out:e.fds[1]==="closed",err:e.fds[2]==="closed"},stdinFile:!!e.stdinFile,stdinPiped:e.stdinPiped??t.stdinPiped,stdinOrigin:e.stdinOrigin,stdinHandle:e.stdinHandle};return t.stdinLeft=e.stdin,ae(t,r,n)}function eS(e){let t="",n="";for(let r=0;r<e.length;r++){let i=e[r],o=e[r+1];if(i==="\\"&&(o==="$"||o==="\\"||o==="`")){t+=o,n+="1",r++;continue}if(i==="`"){let s=Te(e,r);t+=s.raw,n+="2"+"1".repeat(s.raw.length-1),r+=s.raw.length-1;continue}if(i==="$"){let s=_e(e,r,0,!0);if(s?.command!==void 0||s?.parameter!==void 0||s?.arithmetic!==void 0){t+=s.raw,n+="2"+"1".repeat(s.raw.length-1),r+=s.raw.length-1;continue}}t+=i,n+="2"}return{value:t,mask:n}}function tS(e,t,n){if(e==="/dev/null")return{content:""};if(e==="/dev/stdin")return{content:n};let{path:r,error:i}=P(t,"shell",e);if(i)return{error:y(`error: ${e}: ${i}`)};if(t.fs.isFile(r)){let o=t.fs.readFile(r);return{content:o,handle:t.writable&&r.startsWith("/tmp/")?{path:r,content:o,identity:t.fs.fileIdentity(r)}:null}}return{error:y(`error: ${e}: Is a directory`)}}function nS(e,t){let{argv:n}=t;return n.length===0?{stdout:"",stderr:"",exitCode:e.substitutionExit??0}:Ph(t.temps,e,()=>e.invoke(n[0],n.slice(1),e.stdinLeft))}function rS(e,t){for(let n of e)t.vars.set(n.name,Ft(n.word,t,!0))}function iS(e,t){if(e.length===0)return null;let n=t.vars,r=new He(n),i=new Set(e.map(o=>o.name));r.bound=new Set;try{ae(t,{vars:r},()=>{for(let o of e){r.expansionTargets=i;let s=Ft(o.word,t,!0);r.expansionTargets=null,r.set(o.name,s)}})}finally{r.expansionTargets=null;for(let o of r.bound)i.has(o)||n.set(o,r.get(o))}return{vars:r,names:i}}function Ph(e,t,n){if(!e)return n();let r=t.vars,i=new He(r),o=e.names;for(let s of o)i.set(s,e.vars.get(s));t.vars=i;try{return i.bound=new Set,n()}finally{t.vars=r;for(let[s,u]of i)(!o.has(s)||i.bound?.has(s))&&r.set(s,u);for(let s of i.unsetNames)o.has(s)||r.delete(s)}}function Uh(e,t={}){let{fs:n,cwd:r,home:i,mount:o,writable:s,locale:u}=Hu(e,t),a=t.commands===void 0?dh:su(t.commands),l={fs:n,io:fu(n),mount:o,writable:s,registry:a,createdAt:Date.now()};return zh(Wh(l,{cwd:r,home:i,user:t.user??"user",locale:u,...Bh()}),"createTerminal")}var Bh=()=>({vars:new He,functions:new Map,lastExit:0}),oS=e=>({vars:new He(e.vars),functions:new Map(e.functions),lastExit:e.lastExit});function sS(e,t={}){let{cwd:n,home:r,user:i,locale:o,inherit:s}=Gu(e,t),u=s?oS(e):Bh();return zh(Wh(e,{cwd:n,home:r,user:i,locale:o,...u}),"fork")}function Wh({fs:e,io:t,mount:n,writable:r,registry:i,createdAt:o},s){let u={fs:e,io:t,mount:n,writable:r,registry:i,createdAt:o,...s,calling:new Set,outputFds:{1:"out",2:"err"},loopDepth:0,closed:{out:!1,err:!1},stdinFile:!1,stdinPiped:!1,stdinOrigin:null,stdinHandle:null,stdinLeft:"",unsupported:dn(),notes:new Set};return u.dispatch=(a,l,c)=>ae(u,{stdinLeft:u.stdinLeft,stdinFile:!1,stdinPiped:!1,stdinOrigin:null,stdinHandle:null},()=>gt(u,()=>Dh(a,l,c,u,!0))),u.flushOutput=a=>pu(a,u),u.hasCommand=a=>i.has(a)&&!i.shellOnly(a),u.invoke=(a,l,c)=>Dh(a,l,c,u),u.substitute=(a,l)=>Fh(a,u,fr,l),u}function zh(e,t){if(!e.fs.isDir(e.cwd))throw new Error(`${t}: cwd is not a directory: ${e.cwd}`);return{run:n=>aS(n,e),cwd:()=>e.cwd,complete:n=>mh(n,e,e.registry),fork:n=>sS(e,n),...Ch(e)}}function Dh(e,t,n,r,i=!1){let o=r.registry,s=o.resolveCommand(e),u=()=>{if((i||e!==s)&&o.shellOnly(s))return v("command",e,e,`${e}: shell builtin cannot be invoked as an external command`,127);let l=o.commands[s];return l?l(n,t,r):ph(e,o)},a=l=>pu(uS(r,Mo(e,l,r),s),r);try{return r.io.run(s,()=>a(u()))}catch(l){D(r,e,l?.path,l?.fsError);let c=`${e}: ${G(l)}`,f=N(l);return f&&r.unsupported.add({...f,command:f.command??e,message:c},f.command??s),a(y(c))}}function uS(e,t,n){let r=N(t);return r&&e.unsupported.add(r,n),t}function aS(e,t){let n=dn();return ae(t,{unsupported:n,notes:new Set,discarded:new Set,stdinFile:!1,stdinPiped:!1,stdinOrigin:null,stdinHandle:null,closed:{out:!1,err:!1},outputFds:{1:"out",2:"err"}},()=>{let r={stdout:"",stderr:"",exitCode:0},i={text:""};try{for(let o of Ca(e,t.writable,t.registry.has)){let s=fr(o,t,i);if(r.stdout+=s.stdout,r.stderr+=s.stderr,r.exitCode=s.exitCode,s.halt||s.control)break}}catch(o){let s=N(o);s&&n.add(s),t.lastExit=o.exitCode??(s?1:2),r.stderr+=`error: ${o.message}
251
- `,r.exitCode=t.lastExit}return lS(r,t,n)})}var lS=(e,t,n)=>({stdout:e.stdout,stderr:e.stderr,exitCode:e.exitCode,cwd:t.cwd,unsupported:Object.freeze(n.entries),notes:Object.freeze([...t.notes,...Ci(t.discarded,e.stderr,t.notes)])});var cS={unified:[[/^--- /u,"bold"],[/^\+\+\+ /u,"bold"],[en,"cyan"],[/^\+/u,"green"],[/^-/u,"red"],[/^\\ /u,"gray"]],context:[[_t,"cyan"],[/^\*{3} \d/u,"cyan"],[/^--- \d/u,"cyan"],[/^\*{3} /u,"bold"],[/^--- /u,"bold"],[/^! /u,"yellow"],[/^\+ /u,"green"],[/^- /u,"red"]],normal:[[tn,"cyan"],[/^< /u,"red"],[/^> /u,"green"],[/^---$/u,"gray"]]};function fS(e){return e.some(t=>_t.test(t))?"context":e.some(t=>en.test(t))?"unified":e.some(t=>tn.test(t))?"normal":null}function qh(e){let t=e.split(`
252
- `),n=cS[fS(t)];return n===void 0?null:t.map(r=>n.find(([i])=>i.test(r))?.[1]??null)}var dS={bold:"head",cyan:"hunk",green:"add",red:"del",yellow:"chg",gray:"meta"};function jh(e){let t=qh(e);return t===null?null:e.split(`
253
- `).map((n,r)=>({text:n,kind:t[r]===null?"":dS[t[r]]??""}))}function Hh({stdout:e,stderr:t,unsupported:n}){return n.filter(r=>!t.includes(r.message)&&!e.includes(r.message)).map(r=>r.message)}var Gh=`:host{display:flex;flex-direction:column;position:relative;height:100%;min-height:0;background:var(--bg, #0c0c0c);color:var(--text, #e6edf3);font-family:ui-monospace,SF Mono,Menlo,Consolas,monospace;font-size:13px;line-height:1.45}.output{flex:1 1 auto;overflow-y:auto;overscroll-behavior:none;-webkit-app-region:no-drag;app-region:no-drag;scrollbar-gutter:stable;padding:12px 14px 6px;cursor:text}.banner{color:var(--muted, #8b949e);margin-bottom:8px}.banner .cmd{color:var(--accent, #58a6ff)}.banner .cmd:hover{text-decoration:underline}.line{white-space:pre-wrap;overflow-wrap:break-word}.cwd{color:var(--accent, #58a6ff)}.sigil{color:var(--muted, #8b949e);margin:0 6px 0 4px}.stdout,.stderr{margin:0 0 4px;font:inherit;white-space:pre-wrap;overflow-wrap:break-word}.stderr{color:var(--critical, #d8413a)}.diff-head{color:var(--text, #e6edf3);font-weight:600}.diff-hunk{color:var(--accent, #58a6ff)}.diff-add{color:var(--green, #3fb950)}.diff-del{color:var(--critical, #d8413a)}.diff-chg{color:var(--yellow, #d29922)}.diff-meta{color:var(--muted, #8b949e)}.form{flex:0 0 auto;display:flex;align-items:center;padding:8px 14px 10px;border-top:1px solid var(--border, #2c2c2c)}.form:focus-within{border-top-color:var(--accent, #58a6ff)}.form .cwd{flex:0 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;user-select:none}.form .sigil{flex:0 0 auto;user-select:none}.input-wrap{flex:1 1 auto;min-width:0;position:relative;display:flex;align-items:center}.input{width:100%;background:transparent;border:none;outline:none;color:inherit;font:inherit;padding:0;position:relative}.ghost{position:absolute;inset:0;display:flex;align-items:center;font:inherit;white-space:pre;overflow:hidden;pointer-events:none;user-select:none;color:var(--muted, #8b949e);opacity:.55}.ghost-pad{color:transparent}.notes{position:absolute;top:8px;right:14px;z-index:2;display:flex;flex-direction:column;align-items:flex-end;gap:6px;max-width:min(52%,320px);pointer-events:none}.note{box-sizing:border-box;padding:5px 9px;border:1px solid var(--border, #2c2c2c);border-radius:5px;background:var(--bg, #0c0c0c);color:var(--muted, #8b949e);font-size:12px;line-height:1.4;text-align:left;overflow-wrap:break-word;animation:note-in .14s ease-out,note-out .4s ease-in var(--dwell-out, 5.6s) forwards}.note-gap{border-color:var(--warning, #d97706);color:var(--text, #e6edf3)}@keyframes note-in{0%{opacity:0;transform:translateY(-4px)}to{opacity:1;transform:none}}@keyframes note-out{to{opacity:0;transform:translateY(-4px)}}@media(prefers-reduced-motion:reduce){.note{animation:none}}
254
- `;var mu="/sources",hS={mount:mu,home:"/",writable:"/tmp/"};function mS(e){let n=["ls","find /",`grep -r ${gS(e)} .`];if(!e||e.size===0)return n;let r=null;for(let i of e.keys()){let o=wS(i);(r===null||o.length<r.length)&&(r=o)}return r&&n.push(`cat ${r} | head -n 20`),n}var hu=["TODO","FIXME","XXX","HACK","NOTE","BUG","export","import","require","//"];function gS(e){if(!e||e.size===0)return hu[0];for(let t of hu)for(let n of e.values())if(n.includes(t))return t;return hu[0]}function wS(e){return e.startsWith("./")?e.slice(2):e.startsWith("/")?e.slice(1):e}var gu=class e extends xu{static properties={sources:{attribute:!1},_lines:{state:!0},_input:{state:!0},_cwd:{state:!0},_ghost:{state:!0},_notes:{state:!0}};static styles=yu(Gh);#n=null;#c=null;#t=[];#e=-1;#o="";#i=null;#s=null;static#h=200;#r=new Map;#m=0;static#g=3;static#w=400;constructor(){super(),this.sources=null,this._lines=[],this._input="",this._cwd=mu,this._ghost="",this._notes=[]}willUpdate(t){t.has("sources")&&this.sources!==this.#c&&(this.#n=this.sources?Uh(this.sources,hS):null,this._cwd=this.#n?this.#n.cwd():mu,this._lines=[{kind:"banner",commands:mS(this.sources)}],this.#t=[],this.#e=-1,this.#o="",this.#i=null,this._input="",this.#l(),this.#c=this.sources),t.has("_input")&&(this.#a(),this.#d())}connectedCallback(){super.connectedCallback(),this.updateComplete.then(()=>this.#f())}disconnectedCallback(){super.disconnectedCallback(),this.#a(),this.#l()}firstUpdated(){this.#u()}updated(t){(t.has("_lines")||t.has("sources"))&&this.#f()}#u(){let t=this.renderRoot.querySelector(".input");t&&t.focus()}#f(){let t=this.renderRoot.querySelector(".output");t&&(t.scrollTop=t.scrollHeight)}#x=t=>{if(t.preventDefault(),!this.#n)return;let n=this._input,r=n.trim();if(r==="clear"){this._lines=[],this.#l(),this._input="",r.length>0&&(this.#t=[...this.#t,n]),this.#e=-1;return}let i=this._cwd,o=this.#n.run(n);this._cwd=o.cwd;let s=[...this._lines,{kind:"prompt",cwd:i,text:n}];o.stdout&&s.push({kind:"stdout",text:o.stdout,diff:jh(o.stdout)}),o.stderr&&s.push({kind:"stderr",text:o.stderr}),this._lines=s,this.#k(o),r.length>0&&(this.#t=[...this.#t,n]),this.#e=-1,this._input=""};#y=t=>{if(t.key==="Tab"&&!t.shiftKey){t.preventDefault(),this.#b();return}this.#i=null,t.key==="ArrowUp"?(t.preventDefault(),this.#A()):t.key==="ArrowDown"&&(t.preventDefault(),this.#I()),this.#a(),this.#d()};#b(){if(!this.#n)return;let t=this.#i;if(t&&t.items[t.index]===this._input){t.index=(t.index+1)%t.items.length,this._input=t.items[t.index];return}let n=this.#n.complete(this._input);if(n.length===0){this.#i=null;return}this._input=n[0],this.#i=n.length>1?{items:n,index:0}:null}#a(){this._ghost="",this.#s!==null&&(clearTimeout(this.#s),this.#s=null)}#d(){this.#s=setTimeout(()=>{this.#s=null,this.#v()},e.#h)}#v(){if(!this.#n||this.#i)return;let t=this._input,n=t.slice(-1),r=t===""||n===" "||n==="|",i=/[\w./]/u.test(n);if(!r&&!i)return;let o=this.#n.complete(t);if(o.length===0)return;let s=o[0];!s.startsWith(t)||s===t||i&&o.includes(t)||(this._ghost=s.slice(t.length))}#k(t){let n=t.notes.map(r=>({text:r,kind:"note"}));for(let r of Hh(t))n.push({text:`silenced: ${r}`,kind:"gap"});this.#S(n)}#S(t){if(t.length===0)return;let n=[...this._notes];for(let{text:r,kind:i}of t){let o=n.findIndex(s=>s.text===r);o!==-1&&this.#p(n,o),n.push({id:++this.#m,text:r,kind:i,dwell:e.#E(r)})}for(;n.length>e.#g;)this.#p(n,0);for(let r of n)this.#r.has(r.id)||this.#r.set(r.id,setTimeout(()=>this.#N(r.id),r.dwell));this._notes=n}static#E(t){return Math.min(1e4,3200+t.length*55)}#p(t,n){let[r]=t.splice(n,1);this.#$(r.id)}#$(t){let n=this.#r.get(t);n!==void 0&&(clearTimeout(n),this.#r.delete(t))}#N(t){this.#r.delete(t),this._notes=this._notes.filter(n=>n.id!==t)}#l(){for(let t of this.#r.values())clearTimeout(t);this.#r.clear(),this._notes=[]}#A(){this.#t.length!==0&&(this.#e<0?(this.#o=this._input,this.#e=this.#t.length-1):this.#e=Math.max(0,this.#e-1),this._input=this.#t[this.#e])}#I(){if(this.#e<0)return;let t=this.#e+1;t>=this.#t.length?(this.#e=-1,this._input=this.#o,this.#o=""):(this.#e=t,this._input=this.#t[t])}#O=t=>{this._input=t.target.value};#C=t=>{this._input=t,this.#e=-1,this.#o="",this.#u()};#F=()=>{let t=this.renderRoot.getSelection?.()??document.getSelection();t&&!t.isCollapsed||this.#u()};render(){return Oe`<div class="notes" role="log" aria-atomic="false">${bu(this._notes,t=>t.id,t=>Oe`<div class="note ${t.kind==="gap"?"note-gap":""}" style="--dwell-out:${t.dwell-e.#w}">${t.text}</div>`)}</div><div class="output" @click="${this.#F}">${this._lines.map(t=>this.#T(t))}</div><form class="form" @submit="${this.#x}"><span class="cwd">${this._cwd}</span><span class="sigil">$</span><div class="input-wrap">${this._ghost?Oe`<div class="ghost" aria-hidden="true"><span class="ghost-pad">${this._input}</span>${this._ghost}</div>`:Oi} <input class="input" type="text" aria-label="Terminal command" autocomplete="off" autocapitalize="off" autocorrect="off" spellcheck="false" .value="${this._input}" @input="${this.#O}" @keydown="${this.#y}"></div></form>`}#T(t){return t.kind==="banner"?Oe`<div class="banner">Virtual shell over the bundle source tree. Try ${t.commands.map((n,r)=>Oe`${r>0?", ":""}\`<span class="cmd" @click="${()=>this.#C(n)}">${n}</span>\``)}. ↑/↓ for history, Tab to complete.</div>`:t.kind==="prompt"?Oe`<div class="line"><span class="cwd">${t.cwd}</span><span class="sigil">$</span>${t.text}</div>`:t.kind==="stdout"?this.#_(t):t.kind==="stderr"?Oe`<pre class="stderr">${t.text}</pre>`:Oi}#_(t){if(!t.diff)return Oe`<pre class="stdout">${t.text}</pre>`;let n=t.diff.flatMap((r,i)=>{let o=r.kind?Oe`<span class="diff-${r.kind}">${r.text}</span>`:r.text;return i===0?[o]:[`
255
- `,o]});return Oe`<pre class="stdout">${n}</pre>`}};customElements.define("bundle-terminal",gu);function iR(e,t){let n=document.createElement("bundle-terminal");return n.dataset.integrity=t??"",n.sources=e,n}export{iR as createTerminalElement};
264
+ '`:"\\"+n)}function wE(e,t,n=!1){let r=e.value,o=r.startsWith("~")&&(e.mask?.[0]??"0")==="0"&&!e.empty?.some(h=>h<=1)&&(r.length===1||(e.mask?.[1]??"0")==="0");if(o&&r==="~")return t.fs.isDir(E(t.cwd,ln(t),t.fs).path)?["~/"]:[];if(o&&!r.startsWith("~/"))return[];let i=r.lastIndexOf("/"),s=r.slice(0,i+1),u=r.slice(i+1),a=o?ln(t)+s.slice(1):s||".",l=E(t.cwd,a,t.fs).path;if(!t.fs.isDir(l))return[];let{dirs:f,files:c,links:d}=t.fs.listDir(l),p=f.map(h=>h+"/");for(let h of d)t.fs.isDir(E(l,h,t.fs).path)?p.push(h+"/"):n||p.push(h);return n||p.push(...c),p.filter(h=>h.startsWith(u)&&(u.startsWith(".")||!h.startsWith("."))).filter(h=>s!==""||u===""||!h.startsWith("-")).map(h=>s===""&&h.startsWith("-")?"./"+h:s+h)}async function Jh(e,t,n,r=!1){let o=(t.substitutionDepth??0)+1;if(o>Qt)throw new b("feature","command substitution nesting limit",`command substitution nesting beyond ${Qt} levels is not supported`);let i=t.expansionFds[2],u=await ce(t,{substitutionDepth:o,outputFds:{1:"out",2:typeof i=="object"||i==="closed"?i:"err"},errexitOff:!0,closed:{out:!1,err:i==="closed"}},()=>$t(t,()=>{let c;try{c=Bl(e,t.writable,t.registry.has)}catch(p){let h=O(p);if(!h){if(r)return x(`error: command substitution: ${p.message}`,2);throw new b("feature","command substitution syntax",`runtime command substitution syntax errors are not supported: ${p.message}`)}return t.unsupported.add(h),x(`error: ${p.message}`,1)}let d=c.length===1&&!c[0].negate&&c[0].stages.length===1?c[0].stages[0]:null;return d&&!d.group&&!d.loop&&!d.conditional&&!d.test&&d.words.length===0&&d.assigns.length===0&&d.redirs.length===1&&d.redirs[0].op==="read"&&d.words.push({value:"cat",mask:null}),n(c,t,{text:t.stdinLeft,bytes:t.stdinBytes})}));t.lastExit=t.substitutionExit=u.exitCode;let a=u.stdout,l=u.stderr;if(a.includes("\0")){let c=a.length;a=a.replaceAll("\0","");let d=c-a.length;t.notes.add(`command substitution: discarded ${d} NUL ${d===1?"byte":"bytes"}.`),l+=`warning: command substitution: ignored null byte in input
265
+ `}uo(t,l);let f=a.length;for(;f>0&&a[f-1]===`
266
+ `;)f--;return a.slice(0,f)}async function Qh(e,t){return{stdout:"",stderr:"",exitCode:await xn(e,t)?0:1}}var Yu=async(e,t)=>(await qs(e,t)).value;async function xn(e,t){let{kind:n}=e;if(n==="not")return!await xn(e.expression,t);if(n==="and")return await xn(e.left,t)&&await xn(e.right,t);if(n==="or")return await xn(e.left,t)||await xn(e.right,t);let{op:r}=e;if(n==="unary"){let u=await Yu(e.word,t);if(r==="-n")return u!=="";if(r==="-z")return u==="";if(["-a","-e","-f","-d"].includes(r))return wu(r,u,t);if(r==="-v")return yE(u,t);Er(r)}["<",">","-nt","-ot","-ef"].includes(r)&&Er(r);let o=await Yu(e.left,t);if(Object.hasOwn(dr,r)){let u=await Yu(e.right,t);return dr[r](Ut(o,t),Ut(u,t))}let i=await qs(e.right,t);Gn(i)&&Er("extglob");let s=Me(on(i),{bash:!0}).test(o);return r==="!="?!s:s}function yE(e,t){return e.includes("[")&&Er("-v array subscript"),/^[ \t\n\r\f\v]*[+-]?0+[ \t]*$/u.test(e)&&Er("-v positional parameter"),/^[A-Za-z_][A-Za-z0-9_]*$/u.test(e)?Et(e,t).set:!1}function Er(e){throw new b("feature",`[[ ${e}`,`${e} in [[ is not supported`)}function tm(e,t,n,r){return e.define?(t.functions.set(e.define.name,e.define.body),U()):e.test?Qh(e.test,t):e.group?SE(e,t,n,r):e.loop?e.loop.words?kE(e.loop,t,r):bE(e.loop,t,r):vE(e.conditional,t,n,r)}var nm=1e4,em={kind:"feature",command:null,detail:"loop limit",message:`a loop running more than ${nm} times is not supported`};async function bE(e,t,n){let r=U(),o={text:t.stdinLeft,bytes:t.stdinBytes};t.loopDepth++;try{for(let i=0;;i++){if(i===nm){t.unsupported.add(em),_(r,x(`error: ${em.message}`,1));break}let s=r.ignored,u=r.exitCode,a=await n(e.condition,t,o,!0);if(_(r,a),r.exitCode=u,r.ignored=s,a.halt||a.control)return{...r,halt:a.halt,control:a.control,blame:a.blame};if(a.exitCode===0==!!e.until)break;let l=await n(e.body,t,o);if(_(r,l),r.blame=l.blame,l.halt)return{...r,halt:!0};if(l.control?.levels>1)return{...r,control:{...l.control,levels:l.control.levels-1}};if(l.control?.type==="break")break}}finally{t.loopDepth--}return r}var xE={value:"for",mask:null};async function kE(e,t,n){let r=await er([xE,...e.words],t),o=U(),i={text:t.stdinLeft,bytes:t.stdinBytes};t.loopDepth++;try{for(let s of r.argv.slice(1)){t.vars.set(e.name,s);let u=await n(e.body,t,i);if(_(o,u),o.blame=u.blame,u.halt)return{...o,halt:!0};if(u.control?.levels>1)return{...o,control:{...u.control,levels:u.control.levels-1}};if(u.control?.type==="break")break}}finally{t.loopDepth--}return o}async function vE(e,t,n,r){let o=U(),i={text:n,bytes:t.stdinBytes};for(let u of e.branches){let a=await r(u.condition,t,i,!0);if(_(o,a),a.halt||a.control)return{...o,halt:a.halt,control:a.control,blame:a.blame};if(a.exitCode!==0)continue;let l=await r(u.body,t,i);return _(o,l),{...o,halt:l.halt,control:l.control,blame:l.blame}}if(!e.otherwise)return o.exitCode=0,o.ignored=!1,o;let s=await r(e.otherwise,t,i);return _(o,s),{...o,halt:s.halt,control:s.control,blame:s.blame}}async function SE(e,t,n,r){let o={text:n,bytes:t.stdinBytes};return e.isolate?{...await $t(t,()=>r(e.group,t,o)),halt:!1,control:void 0,ignored:!1}:r(e.group,t,o)}var EE=new Set(["sort","cat"]),$E=new Set(["wc","tac"]);function Vu(e){let t=null,n=null,r=i=>{t&&!t.bufferReads&&t.reads.push(i)},o=i=>{if(i!==void 0)for(let s=t;s;s=s.parent){if(!s.reads.includes(i)||s===t&&n?.scope===s&&(n.unsupported||s.buffered||n.fd===1&&(EE.has(s.name)||$E.has(s.name)&&!s.reads.slice(1).includes(i))))continue;if(s.failure)throw s.failure;let u=s===t&&n?.fd===2,a=u?"input modified by diagnostics":"streaming self-output",l=u?"reading input while diagnostics write to the same file is not supported":"writing to an actively read input file is not supported";throw s.failure=ie(new b("feature",a,l),"feature",s.name,a,l),s.failure}};return e.observeIo?.({read:r,write:o}),{read:r,bufferOutput(){t&&(t.buffered=!0)},bufferReads(i){if(!t)return i();let s=t,u=s.bufferReads;s.bufferReads=!0;try{return i()}finally{s.bufferReads=u}},setReads(i){t&&(t.reads=i)},async run(i,s){let u=t;t={name:i,reads:[],parent:u};try{return await s()}finally{t=u}},output(i,s,u){let a=n;n={scope:t,fd:null,unsupported:!!O(i)};try{for(let l of sn(i))l.text!==""&&(n.fd=l.fd,o(s.fds[l.fd]?.identity));return u((l,f)=>{n.fd=l.fd,ws(l,f)})}finally{n=a}}}}function Ju(e,t){let n={1:t.outputFds[1]?.path?t.outputFds[1]:"out",2:t.outputFds[2]?.path?t.outputFds[2]:"err"},r={1:rm(t.outputFds[1]),2:rm(t.outputFds[2])};return un(e,{fds:n,deferred:r},t)}var rm=e=>e!=="out"&&e!=="err"&&!e?.path;async function $r(e,t,n,r=!1){if(e.some(u=>u.background))throw new b("feature","&","background processes (`&`) are not supported");let o=U(),i=null,s=null;for(let[u,a]of e.entries()){if(a.warnings&&_(o,un({...U(a.warnings),exitCode:o.exitCode,ignored:o.ignored},{fds:t.outputFds},t)),a.gate==="and"&&o.exitCode!==0){(s??=Za()).skip(r?null:i,o.exitCode);continue}if(a.gate==="or"&&o.exitCode===0)continue;s?.flush(t.notes);let l=r||a.negate||NE(e,u),f=await(l?ce(t,{errexitOff:!0},()=>om(a.stages,t,n)):om(a.stages,t,n));if(_(o,f),a.negate&&!f.halt&&(o.exitCode=f.exitCode===0?1:0),l&&(o.ignored=!0),i=a.negate?null:f.blame,t.lastExit=o.exitCode,f.halt||f.control){Object.assign(o,{halt:f.halt,control:f.control});break}if(o.exitCode!==0&&!o.ignored&&t.errexit&&!t.errexitOff){o.halt=!0;break}}return s?.flush(t.notes),t.stdinLeft=n.text,t.stdinBytes=n.bytes??null,Object.assign(o,{blame:i})}var NE=(e,t)=>["and","or"].includes(e[t+1]?.gate);async function om(e,t,n){let r=U(),o=n.text,i=n.bytes??null;for(let s=0;s<e.length;s++){let u=e[s],a=s===0,l=s<e.length-1?AE():null,f={...t.outputFds};l&&(f[1]=l);let c=i,d=o,p=()=>OE(u,t,{stdin:d,stdinBytes:c,stdinFile:a&&t.stdinFile,fds:f,stdinPiped:a?t.stdinPiped:!0}),h=e.length>1?{...await $t(t,p),ignored:!1}:await p();a&&(n.text=h.inputLeft,n.bytes=h.bytesLeft??null),_(r,h);let m=l?.carried()??{text:""};i=m.bytes??null,o=m.text??me(m.bytes)??"",r.blame=h.blame,e.length===1&&(r.halt=h.halt,r.control=h.control)}return r}function AE(){let e="",t=null;return{write(n){t===null?e+=n:n!==""&&t.push(B(n))},writeBytes(n){t===null&&(t=e===""?[]:[B(e)],e=""),t.push(n)},carried:()=>t===null?{text:e}:{bytes:vn([...t,new Uint8Array])}}}function OE(e,t,{stdin:n,stdinBytes:r,stdinFile:o,fds:i,stdinPiped:s}){let u={fds:i,stdin:n,stdinBytes:r,stdinFile:o,stdinPiped:s,stdinOrigin:o?t.stdinOrigin:null,stdinHandle:o?t.stdinHandle:null};return ce(t,{substitutionExit:null,expansionOutput:U(),expansionFds:i},()=>Ku(u,t,async()=>{let a=!e.group&&!e.loop&&!e.conditional&&!e.test&&!e.define,l,f;try{a&&(l=await er(e.words,t),l.argv.length===0?await _E(e.assigns,t):l.temps=await RE(e.assigns,t))}catch(w){f=Jo(t,w)}if(f)return _(t.expansionOutput,im(f,u,t)),{...t.expansionOutput,inputLeft:t.stdinLeft,bytesLeft:t.stdinBytes,halt:f.halt};let c=await CE(e,t,t.stdinLeft,o,i);t.expansionFds=c.fds;let d=!1,p=null,h=await Ku(c,t,()=>IE(t,async()=>{if(c.error)return c.error;if(!a){let S=await tm(e,t,c.stdin,$r);return d=!0,p=S.blame??null,S}let w=l.argv.length>0?l.argv[0]:null,y=w===null?void 0:t.functions.get(w);if(y){if(d=!0,t.calling.has(w)){let S=v("feature",w,"function recursion",`${w}: a function calling itself is not supported`);return t.unsupported.add(O(S)),S}t.calling.add(w);try{return await ce(t,{loopDepth:0},async()=>({...await sm(l.temps,t,()=>$r(y,t,{text:c.stdin,bytes:c.stdinBytes})),ignored:!1}))}finally{t.calling.delete(w)}}let k=await LE(t,l);return l.argv.length&&(p=Xa(t.registry.chainRole(l.argv),l.argv[0])),k})),m=c.inherited?t.stdinLeft:c.parentLeft,g=c.inherited?t.stdinBytes:c.parentBytes;return _(t.expansionOutput,d?h:im(h,c,t)),{...t.expansionOutput,inputLeft:m,bytesLeft:g,halt:h.halt,control:h.control,blame:p}}))}function im(e,t,n){try{return un(e,t,n)}catch(r){return un(Jo(n,r),t,n)}}async function CE(e,t,n,r,o){let i={...o},s=n,u=r,a=u?t.stdinOrigin:null,l=u?t.stdinHandle:null,f=!0,c=n,d=!1,p=t.stdinBytes,h=p,m=!1,g=y=>({error:y,fds:i,stdin:s,stdinBytes:m?null:p,stdinFile:u,stdinPiped:d||t.stdinPiped,stdinOrigin:u?a:null,stdinHandle:u?l:null,inherited:f,parentLeft:c,parentBytes:h}),w=async y=>{let k=await ce(t,{expansionFds:i},()=>Ku({fds:i,stdin:s,stdinBytes:p,stdinFile:u,stdinOrigin:a,stdinHandle:l},t,y));return s=t.stdinLeft,p=t.stdinBytes,f&&(c=s,h=p),k};try{for(let y of e.redirs)if(y.op==="dup"){if(i[y.toFd]===void 0||i[y.toFd]==="closed")return g(x(`error: ${y.toFd}: Bad file descriptor`));i[y.fd]=i[y.toFd]}else if(y.op==="close")i[y.fd]="closed";else if(y.op==="to"){let k=y.target===void 0?await w(()=>Ws(y.word,t)):{value:y.target};if(k.error)return g(x(`error: ${k.error}`));let S=k.value==="/dev/null"?"null":k.value==="/dev/stdout"?i[1]:k.value==="/dev/stderr"?i[2]:t.writable?t.fs.openWritable(t.cwd,k.value,y.append):null;if(S===null){let I=Ri(y.label,k.value,t.writable);return t.unsupported.add(O(I)),g(x(`error: ${I.message}`))}if(S==="closed")return g(x(`error: ${k.value}: No such file or directory`));i[y.fd]=S,y.both&&(i[2]=S)}else if(y.op==="text")s=y.expand?await w(()=>jt(TE(y.body),t)):y.body,u=!1,f=!1,m=!0;else if(y.op==="herestring")s=await w(()=>jt(y.word,t))+`
267
+ `,u=!1,f=!1,m=!0;else{let k=await w(()=>Ws(y.word,t)),S=k.error?{error:x(`error: ${k.error}`)}:FE(k.value,t,u?a:s);if(S.error)return g(S.error);s=S.content,m=k.value!=="/dev/stdin",(k.value!=="/dev/stdin"||u)&&(f=!1),k.value!=="/dev/stdin"&&(u=k.value!=="/dev/null",a=u?s:null,l=S.handle,d=u)}if(u&&l){let y=t.io.bufferReads(()=>t.fs.readIdentity(l.identity));if(y!==l.content){if(f||s!==l.content)throw new b("feature","modified redirected input","reading an inherited input file after it changes is not supported");s=a=y,l={...l,content:y}}}}catch(y){return g(Jo(t,y))}return g()}function Jo(e,t){R(e,"shell",t?.path,t?.fsError);let n=O(t);return n&&e.unsupported.add(n),{...x(`error: ${V(t)}`,1),...t?.halt?{halt:!0}:{}}}async function IE(e,t){try{return await t()}catch(n){return Jo(e,n)}}function Ku(e,t,n){let r={outputFds:e.fds,closed:{out:e.fds[1]==="closed",err:e.fds[2]==="closed"},stdinFile:!!e.stdinFile,stdinPiped:e.stdinPiped??t.stdinPiped,stdinOrigin:e.stdinOrigin,stdinHandle:e.stdinHandle};return t.stdinLeft=e.stdin,t.stdinBytes=e.stdinBytes??null,ce(t,r,n)}function TE(e){let t="",n="";for(let r=0;r<e.length;r++){let o=e[r],i=e[r+1];if(o==="\\"&&(i==="$"||i==="\\"||i==="`")){t+=i,n+="1",r++;continue}if(o==="`"){let s=at(e,r);t+=s.raw,n+="2"+"1".repeat(s.raw.length-1),r+=s.raw.length-1;continue}if(o==="$"){let s=ft(e,r,0,!0);if(s?.command!==void 0||s?.parameter!==void 0||s?.arithmetic!==void 0){t+=s.raw,n+="2"+"1".repeat(s.raw.length-1),r+=s.raw.length-1;continue}}t+=o,n+="2"}return{value:t,mask:n}}function FE(e,t,n){if(e==="/dev/null")return{content:""};if(e==="/dev/stdin")return{content:n};let{path:r,error:o}=P(t,"shell",e);if(o)return{error:x(`error: ${e}: ${o}`)};if(t.fs.isFile(r)){let i=t.fs.readFile(r);return{content:i,handle:t.writable&&r.startsWith("/tmp/")?{path:r,content:i,identity:t.fs.fileIdentity(r)}:null}}return{error:x(`error: ${e}: Is a directory`)}}function LE(e,t){let{argv:n}=t;return n.length===0?{stdout:"",stderr:"",exitCode:e.substitutionExit??0}:sm(t.temps,e,()=>e.invoke(n[0],n.slice(1),e.stdinLeft))}async function _E(e,t){for(let n of e)t.vars.set(n.name,await jt(n.word,t,!0))}async function RE(e,t){if(e.length===0)return null;let n=t.vars,r=new Je(n),o=new Set(e.map(i=>i.name));r.bound=new Set;try{await ce(t,{vars:r},async()=>{for(let i of e){r.expansionTargets=o;let s=await jt(i.word,t,!0);r.expansionTargets=null,r.set(i.name,s)}})}finally{r.expansionTargets=null;for(let i of r.bound)o.has(i)||n.set(i,r.get(i))}return{vars:r,names:o}}async function sm(e,t,n){if(!e)return n();let r=t.vars,o=new Je(r),i=e.names;for(let s of i)o.set(s,e.vars.get(s));t.vars=o;try{return o.bound=new Set,await n()}finally{t.vars=r;for(let[s,u]of o)(!i.has(s)||o.bound?.has(s))&&r.set(s,u);for(let s of o.unsetNames)i.has(s)||r.delete(s)}}function am(e,t={}){let{fs:n,cwd:r,home:o,mount:i,writable:s,locale:u}=tl(e,t),a=t.commands===void 0?Zh:Zu(t.commands),l={fs:n,io:Vu(n),mount:i,writable:s,registry:a,createdAt:Date.now(),lock:{turn:Promise.resolve()}};return cm(fm(l,{cwd:r,home:o,user:t.user??"user",locale:u,...lm()}),"createTerminal")}var lm=()=>({vars:new Je,functions:new Map,lastExit:0,errexit:!1}),ME=e=>({vars:new Je(e.vars),functions:new Map(e.functions),lastExit:e.lastExit,errexit:e.errexit});function PE(e,t={}){let{cwd:n,home:r,user:o,locale:i,inherit:s}=nl(e,t),u=s?ME(e):lm();return cm(fm(e,{cwd:n,home:r,user:o,locale:i,...u}),"fork")}function fm({fs:e,io:t,mount:n,writable:r,registry:o,createdAt:i,lock:s},u){let a={fs:e,io:t,mount:n,writable:r,registry:o,createdAt:i,lock:s,...u,calling:new Set,outputFds:{1:"out",2:"err"},loopDepth:0,closed:{out:!1,err:!1},stdinFile:!1,stdinPiped:!1,stdinOrigin:null,stdinHandle:null,stdinLeft:"",stdinBytes:null,unsupported:ei(),notes:new Set};return a.dispatch=(l,f,c)=>ce(a,{stdinLeft:a.stdinLeft,stdinBytes:a.stdinBytes,stdinFile:!1,stdinPiped:!1,stdinOrigin:null,stdinHandle:null},()=>$t(a,()=>um(l,f,c,a,!0))),a.flushOutput=l=>Ju(l,a),a.hasCommand=l=>o.has(l)&&!o.shellOnly(l),a.invoke=(l,f,c)=>um(l,f,c,a),a.substitute=(l,f)=>Jh(l,a,$r,f),a.runLine=l=>dm(l,a),a}function cm(e,t){if(!e.fs.isDir(e.cwd))throw new Error(`${t}: cwd is not a directory: ${e.cwd}`);return{run:n=>BE(e,n),cwd:()=>e.cwd,complete:n=>Kh(n,e,e.registry),fork:n=>PE(e,n)}}async function um(e,t,n,r,o=!1){let i=r.registry,s=i.resolveCommand(e),u=()=>{if((o||e!==s)&&i.shellOnly(s))return v("command",e,e,`${e}: shell builtin cannot be invoked as an external command`,127);let l=i.commands[s];return l?l(n,t,r):Yh(e,i)},a=l=>Ju(DE(r,ys(e,l,r),s),r);try{return await r.io.run(s,async()=>a(await u()))}catch(l){R(r,e,l?.path,l?.fsError);let f=`${e}: ${V(l)}`,c=O(l);return c&&r.unsupported.add({...c,command:c.command??e,message:f},c.command??s),a(x(f))}}function DE(e,t,n){let r=O(t);return r&&e.unsupported.add(r,n),t}function BE(e,t){let{lock:n}=e,r=n.turn.then(()=>dm(t,e));return n.turn=r.then(()=>null,()=>null),r}function dm(e,t){let n=ei();return ce(t,{unsupported:n,notes:new Set,discarded:new Set,stdinFile:!1,stdinPiped:!1,stdinOrigin:null,stdinHandle:null,stdinBytes:null,closed:{out:!1,err:!1},outputFds:{1:"out",2:"err"}},async()=>{let r={stdout:"",stderr:"",exitCode:0},o={text:""};try{for(let i of Ul(e,t.writable,t.registry.has)){let s=await $r(i,t,o);if(r.stdout+=s.stdout,r.stderr+=s.stderr,r.exitCode=s.exitCode,s.halt||s.control)break}}catch(i){let s=O(i);s&&n.add(s),t.lastExit=i.exitCode??(s?1:2),r.stderr+=`error: ${i.message}
268
+ `,r.exitCode=t.lastExit}return UE(r,t,n)})}var UE=(e,t,n)=>({stdout:e.stdout,stderr:e.stderr,exitCode:e.exitCode,cwd:t.cwd,unsupported:Object.freeze(n.entries),notes:Object.freeze([...t.notes,...bi(t.discarded,e.stderr,t.notes)])});var jE={unified:[[/^--- /u,"bold"],[/^\+\+\+ /u,"bold"],[cn,"cyan"],[/^\+/u,"green"],[/^-/u,"red"],[/^\\ /u,"gray"]],context:[[qt,"cyan"],[/^\*{3} \d/u,"cyan"],[/^--- \d/u,"cyan"],[/^\*{3} /u,"bold"],[/^--- /u,"bold"],[/^! /u,"yellow"],[/^\+ /u,"green"],[/^- /u,"red"]],normal:[[dn,"cyan"],[/^< /u,"red"],[/^> /u,"green"],[/^---$/u,"gray"]]};function WE(e){return e.some(t=>qt.test(t))?"context":e.some(t=>cn.test(t))?"unified":e.some(t=>dn.test(t))?"normal":null}function pm(e){let t=e.split(`
269
+ `),n=jE[WE(t)];return n===void 0?null:t.map(r=>n.find(([o])=>o.test(r))?.[1]??null)}var qE={bold:"head",cyan:"hunk",green:"add",red:"del",yellow:"chg",gray:"meta"};function hm(e){let t=pm(e);return t===null?null:e.split(`
270
+ `).map((n,r)=>({text:n,kind:t[r]===null?"":qE[t[r]]??""}))}function mm({stdout:e,stderr:t,unsupported:n}){return n.filter(r=>!t.includes(r.message)&&!e.includes(r.message)).map(r=>r.message)}var gm=`:host{display:flex;flex-direction:column;position:relative;height:100%;min-height:0;background:var(--bg, #0c0c0c);color:var(--text, #e6edf3);font-family:ui-monospace,SF Mono,Menlo,Consolas,monospace;font-size:13px;line-height:1.45}.output{flex:1 1 auto;overflow-y:auto;overscroll-behavior:none;-webkit-app-region:no-drag;app-region:no-drag;scrollbar-gutter:stable;padding:12px 14px 6px;cursor:text}.banner{color:var(--muted, #8b949e);margin-bottom:8px;user-select:none}.banner .cmd{color:var(--accent, #58a6ff)}.banner .cmd:hover{text-decoration:underline}.line{white-space:pre-wrap;overflow-wrap:break-word}.cwd{color:var(--accent, #58a6ff)}.sigil{color:var(--muted, #8b949e)}.stdout,.stderr{margin:0 0 4px;font:inherit;white-space:pre-wrap;overflow-wrap:break-word}.stderr{color:var(--critical, #d8413a)}.diff-head{color:var(--text, #e6edf3);font-weight:600}.diff-hunk{color:var(--accent, #58a6ff)}.diff-add{color:var(--green, #3fb950)}.diff-del{color:var(--critical, #d8413a)}.diff-chg{color:var(--yellow, #d29922)}.diff-meta{color:var(--muted, #8b949e)}.form{flex:0 0 auto;display:flex;align-items:center;padding:8px 14px 10px;border-top:1px solid var(--border, #2c2c2c)}.form:focus-within{border-top-color:var(--accent, #58a6ff)}.form[aria-busy=true] .sigil{opacity:.4}.form[aria-busy=true] .input{caret-color:transparent}.form .cwd{flex:0 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;user-select:none}.form .sigil{flex:0 0 auto;user-select:none;margin:0 1ch}.input-wrap{flex:1 1 auto;min-width:0;position:relative;display:flex;align-items:center}.input{width:100%;background:transparent;border:none;outline:none;color:inherit;font:inherit;padding:0;position:relative}.ghost{position:absolute;inset:0;display:flex;align-items:center;font:inherit;white-space:pre;overflow:hidden;pointer-events:none;user-select:none;color:var(--muted, #8b949e);opacity:.55}.ghost-pad{color:transparent}.notes{position:absolute;top:8px;right:14px;z-index:2;display:flex;flex-direction:column;align-items:flex-end;gap:6px;max-width:min(52%,320px);pointer-events:none}.note{box-sizing:border-box;padding:5px 9px;border:1px solid var(--border, #2c2c2c);border-radius:5px;background:var(--bg, #0c0c0c);color:var(--muted, #8b949e);font-size:12px;line-height:1.4;text-align:left;overflow-wrap:break-word;animation:note-in .14s ease-out,note-out .4s ease-in var(--dwell-out, 5.6s) forwards}.note-gap{border-color:var(--warning, #d97706);color:var(--text, #e6edf3)}@keyframes note-in{0%{opacity:0;transform:translateY(-4px)}to{opacity:1;transform:none}}@keyframes note-out{to{opacity:0;transform:translateY(-4px)}}@media(prefers-reduced-motion:reduce){.note{animation:none}}
271
+ `;var ea="/sources",HE={mount:ea,home:"/",writable:"/tmp/"};function GE(e){let n=["ls","find /",`grep -r ${XE(e)} .`];if(!e||e.size===0)return n;let r=null;for(let[o,i]of e){if(typeof i!="string")continue;let s=ZE(o);(r===null||s.length<r.length)&&(r=s)}return r&&n.push(`cat ${r} | head -n 20`),n}var Qu=["TODO","FIXME","XXX","HACK","NOTE","BUG","export","import","require","//"];function XE(e){if(!e||e.size===0)return Qu[0];for(let t of Qu)for(let n of e.values())if(typeof n=="string"&&n.includes(t))return t;return Qu[0]}function ZE(e){return e.startsWith("./")?e.slice(2):e.startsWith("/")?e.slice(1):e}var ta=class e extends ra{static properties={sources:{attribute:!1},_lines:{state:!0},_input:{state:!0},_cwd:{state:!0},_ghost:{state:!0},_notes:{state:!0},_running:{state:!0}};static styles=oa(gm);#n=null;#f=null;#t=[];#e=-1;#i="";#o=null;#s=null;static#h=200;#r=new Map;#m=0;static#g=3;static#w=400;constructor(){super(),this.sources=null,this._lines=[],this._input="",this._cwd=ea,this._ghost="",this._notes=[],this._running=!1}willUpdate(t){t.has("sources")&&this.sources!==this.#f&&(this.#n=this.sources?am(this.sources,HE):null,this._cwd=this.#n?this.#n.cwd():ea,this._lines=[{kind:"banner",commands:GE(this.sources)}],this.#t=[],this.#e=-1,this.#i="",this.#o=null,this._input="",this.#l(),this.#f=this.sources),t.has("_input")&&(this.#a(),this.#d())}connectedCallback(){super.connectedCallback(),this.updateComplete.then(()=>this.#c())}disconnectedCallback(){super.disconnectedCallback(),this.#a(),this.#l()}firstUpdated(){this.#u()}updated(t){(t.has("_lines")||t.has("sources"))&&this.#c()}#u(){let t=this.renderRoot.querySelector(".input");t&&t.focus()}#c(){let t=this.renderRoot.querySelector(".output");t&&(t.scrollTop=t.scrollHeight)}#y=async t=>{if(t.preventDefault(),!this.#n||this._running)return;let n=this._input,r=n.trim();if(r==="clear"){this._lines=[],this.#l(),this._input="",r.length>0&&(this.#t=[...this.#t,n]),this.#e=-1;return}let o=this._cwd;r.length>0&&(this.#t=[...this.#t,n]),this.#e=-1,this._input="";let i;this._running=!0;try{i=await this.#n.run(n)}catch(u){this._lines=[...this._lines,{kind:"prompt",cwd:o,text:n},{kind:"stderr",text:`${u?.message??u}
272
+ `}];return}finally{this._running=!1}this._cwd=i.cwd;let s=[...this._lines,{kind:"prompt",cwd:o,text:n}];i.stdout&&s.push({kind:"stdout",text:i.stdout,diff:hm(i.stdout)}),i.stderr&&s.push({kind:"stderr",text:i.stderr}),this._lines=s,this.#v(i)};#b=t=>{if(t.key==="Tab"&&!t.shiftKey){t.preventDefault(),this.#x();return}this.#o=null,t.key==="ArrowUp"?(t.preventDefault(),this.#A()):t.key==="ArrowDown"&&(t.preventDefault(),this.#O()),this.#a(),this.#d()};#x(){if(!this.#n)return;let t=this.#o;if(t&&t.items[t.index]===this._input){t.index=(t.index+1)%t.items.length,this._input=t.items[t.index];return}let n=this.#n.complete(this._input);if(n.length===0){this.#o=null;return}this._input=n[0],this.#o=n.length>1?{items:n,index:0}:null}#a(){this._ghost="",this.#s!==null&&(clearTimeout(this.#s),this.#s=null)}#d(){this.#s=setTimeout(()=>{this.#s=null,this.#k()},e.#h)}#k(){if(!this.#n||this.#o)return;let t=this._input,n=t.slice(-1),r=t===""||n===" "||n==="|",o=/[\w./]/u.test(n);if(!r&&!o)return;let i=this.#n.complete(t);if(i.length===0)return;let s=i[0];!s.startsWith(t)||s===t||o&&i.includes(t)||(this._ghost=s.slice(t.length))}#v(t){let n=t.notes.map(r=>({text:r,kind:"note"}));for(let r of mm(t))n.push({text:`silenced: ${r}`,kind:"gap"});this.#S(n)}#S(t){if(t.length===0)return;let n=[...this._notes];for(let{text:r,kind:o}of t){let i=n.findIndex(s=>s.text===r);i!==-1&&this.#p(n,i),n.push({id:++this.#m,text:r,kind:o,dwell:e.#E(r)})}for(;n.length>e.#g;)this.#p(n,0);for(let r of n)this.#r.has(r.id)||this.#r.set(r.id,setTimeout(()=>this.#N(r.id),r.dwell));this._notes=n}static#E(t){return Math.min(1e4,3200+t.length*55)}#p(t,n){let[r]=t.splice(n,1);this.#$(r.id)}#$(t){let n=this.#r.get(t);n!==void 0&&(clearTimeout(n),this.#r.delete(t))}#N(t){this.#r.delete(t),this._notes=this._notes.filter(n=>n.id!==t)}#l(){for(let t of this.#r.values())clearTimeout(t);this.#r.clear(),this._notes=[]}#A(){this.#t.length!==0&&(this.#e<0?(this.#i=this._input,this.#e=this.#t.length-1):this.#e=Math.max(0,this.#e-1),this._input=this.#t[this.#e])}#O(){if(this.#e<0)return;let t=this.#e+1;t>=this.#t.length?(this.#e=-1,this._input=this.#i,this.#i=""):(this.#e=t,this._input=this.#t[t])}#C=t=>{this._input=t.target.value};#I=t=>{this._input=t,this.#e=-1,this.#i="",this.#u()};#T=()=>{let t=this.renderRoot.getSelection?.()??document.getSelection();t&&!t.isCollapsed||this.#u()};render(){return De`<div class="notes" role="log" aria-atomic="false">${ia(this._notes,t=>t.id,t=>De`<div class="note ${t.kind==="gap"?"note-gap":""}" style="--dwell-out: ${t.dwell-e.#w}ms">${t.text}</div>`)}</div><div class="output" @click="${this.#T}">${this._lines.map(t=>this.#F(t))}</div><form class="form" @submit="${this.#y}" aria-busy="${this._running?"true":"false"}"><span class="cwd">${this._cwd}</span><span class="sigil">$</span><div class="input-wrap">${this._ghost?De`<div class="ghost" aria-hidden="true"><span class="ghost-pad">${this._input}</span>${this._ghost}</div>`:Qo} <input class="input" type="text" aria-label="Terminal command" autocomplete="off" autocapitalize="off" autocorrect="off" spellcheck="false" .value="${this._input}" @input="${this.#C}" @keydown="${this.#b}"></div></form>`}#F(t){return t.kind==="banner"?De`<div class="banner">Virtual shell over the bundle source tree. Try ${t.commands.map((n,r)=>De`${r>0?", ":""}\`<span class="cmd" @click="${()=>this.#I(n)}">${n}</span>\``)}. ↑/↓ for history, Tab to complete.</div>`:t.kind==="prompt"?De`<div class="line"><span class="cwd">${t.cwd}</span>${" "}<span class="sigil">$</span>${" "}${t.text}</div>`:t.kind==="stdout"?this.#L(t):t.kind==="stderr"?De`<pre class="stderr">${t.text}</pre>`:Qo}#L(t){if(!t.diff)return De`<pre class="stdout">${t.text}</pre>`;let n=t.diff.flatMap((r,o)=>{let i=r.kind?De`<span class="diff-${r.kind}">${r.text}</span>`:r.text;return o===0?[i]:[`
273
+ `,i]});return De`<pre class="stdout">${n}</pre>`}};customElements.define("bundle-terminal",ta);function L_(e,t){let n=document.createElement("bundle-terminal");return n.dataset.integrity=t??"",n.sources=e,n}export{L_ as createTerminalElement};