@preventive/triage 1.0.0-alpha.13 → 1.0.0-alpha.15
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/brotli-fallback.js +3 -3
- package/out/client-admin.js +2 -2
- package/out/client-sync.js +14 -14
- package/out/graph.js +30 -5
- package/out/index.html +47 -7
- package/out/prism.js +2 -2
- package/out/stasis.svg +45 -0
- package/out/terminal.js +255 -43
- package/out/view.css +1 -1
- package/out/view.js +147 -110
- package/package.json +27 -4
- package/report/index.js +253 -0
- package/report/src/finding-id.js +80 -0
- package/report/src/finding.js +300 -0
- package/report/src/labels.js +33 -0
- package/report/src/md-structure.js +471 -0
- package/report/src/md-text.js +167 -0
- package/report/src/meta.js +51 -0
- package/report/src/parse-codex.js +147 -0
- package/report/src/parse-deepsec.js +197 -0
- package/report/src/parse-deepview-fields.js +375 -0
- package/report/src/parse-deepview-md.js +185 -0
- package/report/src/parse-md-id.js +137 -0
- package/report/src/parse-md.js +253 -0
- package/report/src/parse-piolium-id.js +79 -0
- package/report/src/parse-piolium-rows.js +131 -0
- package/report/src/parse-piolium-tokens.js +175 -0
- package/report/src/parse-piolium.js +400 -0
- package/report/src/utf8.js +21 -0
- package/report/src/write-md-finding.js +273 -0
- package/report/src/write-md.js +291 -0
- package/server-e2e/bus-receiver.ts +1 -0
- package/server-e2e/hub.ts +37 -6
- package/server-e2e/index.ts +3 -2
- package/server-e2e/objstore/handlers.ts +6 -5
- package/server-e2e/objstore/init.ts +1 -1
- package/server-e2e/objstore/rest-mint.ts +2 -2
- package/server-e2e/objstore/rest.ts +2 -2
- package/server-e2e/pubsub.ts +8 -5
- package/server-e2e/sync-handlers.ts +54 -28
package/out/terminal.js
CHANGED
|
@@ -1,43 +1,255 @@
|
|
|
1
|
-
var
|
|
2
|
-
`)?
|
|
3
|
-
`,exitCode:
|
|
4
|
-
`);
|
|
5
|
-
`)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
`,o=!0;continue}n.push({name:i,content:r.fs.readFile(u)})}return{inputs:n,stderr:s,failed:o}}function E(t,e,r,n){return e.length===0?{inputs:[{name:null,content:r}],stderr:"",failed:!1}:U(t,e,n)}function R(t,e,r,n){let s=E(t,e,r,n);return{content:s.inputs.map(o=>o.content).join(""),stderr:s.stderr,failed:s.failed}}var T=(t,e)=>({stdout:t,stderr:e.stderr,exitCode:e.failed?1:0});function _(t,e){if(typeof t!="string"||!/^\d+$/u.test(t))return{error:d(`${e}: invalid count: ${t}`)};let r=Number(t);return Number.isSafeInteger(r)?{value:r}:{error:d(`${e}: out of range: ${t}`)}}function Qt(t,e,r){let{positional:n}=m(e),s=E("tac",n,t,r),o=[];for(let{content:i}of s.inputs)o.push(...v(i).toReversed());return T($(o),s)}var at=1e6;function te(t,e){let{positional:r}=m(e);if(r.length===0||r.length>3)return k("seq LAST | seq FIRST LAST | seq FIRST INCR LAST");let n=[];for(let l of r){if(!/^-?\d+$/u.test(l))return d(`seq: invalid integer: ${l}`);n.push(Number(l))}let s,o,i;if(n.length===1?(s=1,o=1,i=n[0]):n.length===2?(s=n[0],i=n[1],o=s<=i?1:-1):[s,o,i]=n,o===0)return d("seq: increment must be non-zero");let c=(o>0?s<=i:s>=i)?Math.floor(Math.abs(i-s)/Math.abs(o))+1:0;if(c>at)return d(`seq: range too large: ${c} elements exceeds limit of ${at}`);let a=[];if(o>0)for(let l=s;l<=i;l+=o)a.push(String(l));else for(let l=s;l>=i;l+=o)a.push(String(l));return w($(a))}function ee(t,e,r){let{values:n,positional:s}=m(e,{valueShort:["b"]}),o=n.get("b")??"t";if(o!=="a"&&o!=="t")return d(`nl: -b: only \`a\` and \`t\` are supported (got \`${o}\`)`);let i=E("nl",s,t,r),u=[],c=0;for(let{content:a}of i.inputs)for(let l of v(a))o==="a"||l!==""?(c++,u.push(`${String(c).padStart(6)} ${l}`)):u.push(l);return T($(u),i)}function ne(t,e,r){let{values:n,positional:s}=m(e,{valueShort:["d","f","c"]}),o=n.has("f"),i=n.has("c");if(o===i)return k("cut -f LIST [-d DELIM] [file...] | cut -c LIST [file...]");if(i&&n.has("d"))return d("cut: -d is only valid with -f");let u=re(o?n.get("f"):n.get("c"));if(u.error)return u.error;let c=n.get("d")??" ";if(o&&c.length!==1)return d("cut: -d delimiter must be a single character");let a=E("cut",s,t,r),l=[];for(let{content:f}of a.inputs)for(let h of v(f))l.push(o?se(h,c,u.ranges):ft([...h],u.ranges).join(""));return T($(l),a)}function re(t){let e=[];for(let r of t.split(",")){if(r==="")return{error:d(`cut: empty list item in \`${t}\``)};if(/^\d+$/u.test(r)){let i=Number(r);if(i<1)return{error:d("cut: list items must be >= 1")};e.push([i,i]);continue}let n=r.match(/^(\d*)-(\d*)$/u);if(!n||n[1]===""&&n[2]==="")return{error:d(`cut: invalid list item: ${r}`)};let s=n[1]===""?1:Number(n[1]),o=n[2]===""?Number.POSITIVE_INFINITY:Number(n[2]);if(s<1)return{error:d("cut: list items must be >= 1")};if(o<s)return{error:d(`cut: reversed range: ${r}`)};e.push([s,o])}return{ranges:e}}function ft(t,e){let r=new Set,n=[];for(let[s,o]of e)for(let i=s;i<=Math.min(o,t.length);i++)r.has(i)||(r.add(i),n.push(i));return n.sort((s,o)=>s-o),n.map(s=>t[s-1])}function se(t,e,r){let n=t.split(e);return n.length===1?t:ft(n,r).join(e)}function oe(t,e){let{flags:r,positional:n}=m(e,{short:["d","s"]}),s=r.has("d"),o=r.has("s");if(s&&o)return d("tr: -d combined with -s is not supported");let i=s||o?1:2;if(n.length!==i)return k("tr SET1 SET2 | tr -d SET | tr -s SET");let u=lt(n[0]);if(u.error)return u.error;if(s){let f=new Set(u.chars);return w([...t].filter(h=>!f.has(h)).join(""))}if(o)return w(ie(t,new Set(u.chars)));let c=lt(n[1]);if(c.error)return c.error;if(c.chars.length===0)return d("tr: SET2 must not be empty");let a=new Map,l=c.chars.at(-1);for(let f=0;f<u.chars.length;f++)a.set(u.chars[f],c.chars[f]??l);return w([...t].map(f=>a.get(f)??f).join(""))}function lt(t){let e=[...t],r=[],n=0,s=()=>{if(e[n]!=="\\")return e[n++];if(n+1>=e.length)return null;let o=e[n+1];return n+=2,o==="n"?`
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
`)
|
|
12
|
-
|
|
13
|
-
`,
|
|
14
|
-
`)
|
|
15
|
-
|
|
16
|
-
`)}function
|
|
17
|
-
`)
|
|
18
|
-
`,
|
|
19
|
-
`)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
`)+`
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
`))}let o=n.
|
|
30
|
-
`);return s?w(o+(o?`
|
|
31
|
-
|
|
32
|
-
`)?`
|
|
33
|
-
|
|
34
|
-
`):t
|
|
35
|
-
|
|
36
|
-
`)+e}function un(t,e,r){let{values:n,positional:s}=m(e,{valueShort:["n"]});Nt(n,s);let o=_(n.get("n")??"10","head: -n");return o.error?o.error:Ft("head",t,s,r,i=>i.slice(0,o.value))}function cn(t,e,r){let{values:n,positional:s}=m(e,{valueShort:["n"]});Nt(n,s);let o=_(n.get("n")??"10","tail: -n");return o.error?o.error:Ft("tail",t,s,r,i=>o.value===0?[]:i.slice(-o.value))}function Nt(t,e){t.has("n")||e[0]&&/^-\d+$/u.test(e[0])&&t.set("n",e.shift().slice(1))}function Ft(t,e,r,n,s){let o=E(t,r,e,n),i=o.inputs.length>1,u=[];for(let c=0;c<o.inputs.length;c++){let{name:a,content:l}=o.inputs[c],f=s(v(l)).join(`
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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(`
|
|
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(`
|
|
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(`
|
|
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(`
|
|
33
|
+
`)+`
|
|
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.
|
|
42
|
+
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(`
|
|
45
|
+
`).filter(r=>r!==""&&r!=="0"&&!r.endsWith(":0"));return{...e,stdout:n.length?n.join(`
|
|
46
|
+
`)+`
|
|
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")??`
|
|
65
|
+
`)+`
|
|
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(`
|
|
76
|
+
`)+`
|
|
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")??`
|
|
84
|
+
`;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")??`
|
|
86
|
+
`;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=`
|
|
99
|
+
\
|
|
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)}
|
|
110
|
+
+++ ${a(1)}
|
|
111
|
+
${u}`:s.style==="context"?`${c}*** ${a(0)}
|
|
112
|
+
--- ${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
|
+
`)&&(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.
|
|
134
|
+
`),e.skipRest=!0,!1):n.force?(n.silent||e.say(` Applying it anyway.
|
|
135
|
+
`),!1):n.batch?(e.say(e.reverse?` Ignoring -R.
|
|
136
|
+
`:` Assuming -R.
|
|
137
|
+
`),!0):(e.say(e.reverse?` Ignore -R? [n]
|
|
138
|
+
`:` Assume -R? [n]
|
|
139
|
+
`),e.say(`Apply anyway? [n]
|
|
140
|
+
`),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(`
|
|
144
|
+
`)?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}
|
|
158
|
+
`),n.type!=="normal"&&e.say(r.strip===-1?`Perhaps you should have used the -p or --strip option?
|
|
159
|
+
`:`Perhaps you used the wrong -p or --strip option?
|
|
160
|
+
`)),t.base<n.start){e.say(`The text leading up to this was:
|
|
161
|
+
--------------------------
|
|
162
|
+
`);for(let i=t.base;i<n.start;i++)e.say("|"+t.lines[i]);e.say(`--------------------------
|
|
163
|
+
`)}return r.force||r.batch?e.say(`No file to patch. Skipping patch.
|
|
164
|
+
`):(e.say(`File to patch:
|
|
165
|
+
`),e.say(`Skip this patch? [y]
|
|
166
|
+
`),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
|
|
170
|
+
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(`
|
|
180
|
+
|
|
181
|
+
`)+`
|
|
182
|
+
`:"",stderr:a.length?a.join(`
|
|
183
|
+
`)+`
|
|
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(`
|
|
186
|
+
`)+`
|
|
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?`$
|
|
190
|
+
`:`
|
|
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]!==`
|
|
201
|
+
`;){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",`
|
|
224
|
+
`],["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(`
|
|
238
|
+
`));for(let n=e.indexOf(`
|
|
239
|
+
`);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===`
|
|
244
|
+
`?`'
|
|
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};
|