megareviewer 0.2.5 → 0.2.7

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.
@@ -62,7 +62,7 @@ Error generating stack: `+e.message+`
62
62
  `)}return o.write(`payload.value = newResult;`),o.write(`return payload;`),o.compile()},o,s=ie,c=!Xe.jitless,l=c&&ae.value,u=t.catchall,d;e._zod.parse=(i,f)=>{d??=r.value;let p=i.value;return s(p)?c&&l&&f?.async===!1&&f.jitless!==!0?(o||=a(t.shape),i=o(i,f),u?Dr([],p,i,f,d,e,f?.abortEarly===!0):i):n(i,f):(i.issues.push({expected:`object`,code:`invalid_type`,input:p,inst:e}),i)}});function Ar(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;let i=e.filter(e=>!D(e));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>k(e,r,Ze())))}),t)}var jr=M(`$ZodUnion`,(e,t)=>{Tn.init(e,t),j(e,`optin`,e=>e.def.options.some(e=>e._zod.optin===`defaulted`)?`defaulted`:e.def.options.some(e=>e._zod.optin!==void 0)?`optional`:void 0),j(e,`optout`,e=>e.def.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),j(e,`values`,e=>{if(e.def.options.every(e=>e._zod.values))return new Set(e.def.options.flatMap(e=>Array.from(e._zod.values)))}),j(e,`pattern`,e=>{if(e.def.options.every(e=>e._zod.pattern)){let t=e.def.options.map(e=>e._zod.pattern);return RegExp(`^(${t.map(e=>_(e.source)).join(`|`)})$`)}});let n=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(r,i)=>{if(n)return n(r,i);let a=!1,o=[];for(let e of t.options){let t=e._zod.run({value:r.value,issues:[]},i);if(t instanceof Promise)o.push(t),a=!0;else{if(t.issues.length===0)return t;o.push(t)}}return a?Promise.all(o).then(t=>Ar(t,r,e,i)):Ar(o,r,e,i)}}),Mr=M(`$ZodIntersection`,(e,t)=>{Tn.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||a instanceof Promise?Promise.all([i,a]).then(([t,n])=>Pr(e,t,n)):Pr(e,i,a)}});function Nr(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(oe(e)&&oe(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};Object.prototype.hasOwnProperty.call(i,`__proto__`)&&delete i.__proto__;for(let n of r){if(n===`__proto__`)continue;let r=Nr(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=Nr(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function Pr(e,t,n){let r=new Map,i,a=new Map,o=(e,t)=>{let n;if(e.code===`unrecognized_keys`&&!e.path?.length)i??=e,n=e.keys;else if(e.code===`invalid_key`&&e.origin===`record`&&e.path?.length===1){let t=String(e.path[0]);a.has(t)||a.set(t,e),n=[t]}else return!1;for(let e of n)r.has(e)||r.set(e,{}),r.get(e)[t]=!0;return!0};for(let n of t.issues)o(n,`l`)||e.issues.push(n);for(let t of n.issues)o(t,`r`)||e.issues.push(t);let s=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(s.length){let t=i?s.filter(e=>i.keys.includes(e)):[];t.length&&e.issues.push({...i,keys:t});for(let n of s)!t.includes(n)&&a.has(n)&&e.issues.push(a.get(n))}let c=Nr(t.value,n.value);if(!c.valid){if(D(e))return e;throw Error(`Unmergable intersection. Error path: ${JSON.stringify(c.mergeErrorPath)}`)}return e.value=c.data,e}var Fr=M(`$ZodRecord`,(e,t)=>{Tn.init(e,t);let n=Xe.memoizer;n?.attach(e),e._zod.parse=(r,i)=>{let a=r.value;if(!oe(a))return r.issues.push({expected:`record`,code:`invalid_type`,input:a,inst:e}),r;let o=[],s=t.keyType._zod.values;if(s&&!t.partial){r.value=n?n.alloc(e,r,{},i):{};let c=new Set;for(let n of s)if(typeof n==`string`||typeof n==`number`||typeof n==`symbol`){if(c.add(typeof n==`number`?n.toString():n),n===`__proto__`)continue;let s=t.keyType._zod.run({value:n,issues:[]},i);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(s.issues.length){r.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>k(e,i,Ze())),input:n,path:[n],inst:e});continue}let l=s.value;if(l===`__proto__`)continue;let u=t.valueType._zod.run({value:a[n],issues:[]},i);u instanceof Promise?o.push(u.then(e=>{e.issues.length&&r.issues.push(...we(n,e.issues)),r.value[l]=e.value})):(u.issues.length&&r.issues.push(...we(n,u.issues)),r.value[l]=u.value)}let l;for(let e in a)if(!c.has(e)){if(t.mode===`loose`){if(e===`__proto__`)continue;r.value[e]=a[e]}else l??=[],l.push(e)}l&&l.length>0&&r.issues.push({code:`unrecognized_keys`,input:a,inst:e,keys:l,continue:!0})}else{r.value=n?n.alloc(e,r,{},i):{};let c;for(let n of Reflect.ownKeys(a)){if(n===`__proto__`||!Object.prototype.propertyIsEnumerable.call(a,n))continue;let l=t.keyType._zod.run({value:n,issues:[]},i);if(l instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(typeof n==`string`&&en.test(n)&&l.issues.length){let e=t.keyType._zod.run({value:Number(n),issues:[]},i);if(e instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);e.issues.length===0&&(l=e)}if(l.issues.length){t.mode===`loose`?r.value[n]=a[n]:s?(c??=[],c.push(n)):r.issues.push({code:`invalid_key`,origin:`record`,issues:l.issues.map(e=>k(e,i,Ze())),input:n,path:[n],inst:e});continue}let u=l.value;if(u===`__proto__`)continue;let d=t.valueType._zod.run({value:a[n],issues:[]},i);d instanceof Promise?o.push(d.then(e=>{e.issues.length&&r.issues.push(...we(n,e.issues)),r.value[u]=e.value})):(d.issues.length&&r.issues.push(...we(n,d.issues)),r.value[u]=d.value)}c&&c.length>0&&r.issues.push({code:`unrecognized_keys`,input:a,inst:e,keys:c,continue:!0})}return o.length?Promise.all(o).then(()=>r):r}}),Ir=M(`$ZodEnum`,(e,t)=>{Tn.init(e,t);let n=d(t.entries),r=new Set(n);e._zod.values=r,j(e,`pattern`,e=>{let t=d(e.def.entries).filter(e=>ce.has(typeof e));return RegExp(t.length?`^(${t.map(e=>le(e.toString())).join(`|`)})$`:`^[^\\s\\S]$`)}),e._zod.parse=(t,i)=>{let a=t.value;return r.has(a)||t.issues.push({code:`invalid_value`,values:n,input:a,inst:e}),t}}),Lr=M(`$ZodTransform`,(e,t)=>{Tn.init(e,t),e._zod.optin=`optional`,Xe.memoizer?.guard(e),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Ye(e.constructor.name);let i=t.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(e=>(n.value=e,n));if(i instanceof Promise)throw new Je;return n.value=i,n}});function Rr(e,t){return e.value=t.issues.length?void 0:t.value,e}var zr=M(`$ZodOptional`,(e,t)=>{Tn.init(e,t),j(e,`optin`,e=>e.def.innerType._zod.optin===`defaulted`?`defaulted`:`optional`),e._zod.optout=`optional`,j(e,`values`,e=>{let t=e.def.innerType._zod.values;return t?new Set([...t,void 0]):void 0}),j(e,`pattern`,e=>{let t=e.def.innerType._zod.pattern;return t?RegExp(`^(${_(t.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(e.value===void 0){if(t.innerType._zod.optin!==`defaulted`)return e;let r=t.innerType._zod.run({value:e.value,issues:[]},n);return r instanceof Promise?r.then(t=>Rr(e,t)):Rr(e,r)}return t.innerType._zod.run(e,n)}}),Br=M(`$ZodExactOptional`,(e,t)=>{zr.init(e,t),j(e,`values`,e=>e.def.innerType._zod.values),j(e,`pattern`,e=>e.def.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),Vr=M(`$ZodNullable`,(e,t)=>{Tn.init(e,t),j(e,`optin`,e=>e.def.innerType._zod.optin),j(e,`optout`,e=>e.def.innerType._zod.optout),j(e,`pattern`,e=>{let t=e.def.innerType._zod.pattern;return t?RegExp(`^(${_(t.source)}|null)$`):void 0}),j(e,`values`,e=>e.def.innerType._zod.values?new Set([...e.def.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),Hr=M(`$ZodDefault`,(e,t)=>{Tn.init(e,t),e._zod.optin=`defaulted`,j(e,`values`,e=>e.def.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>Ur(e,t)):Ur(r,t)}});function Ur(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}var Wr=M(`$ZodPrefault`,(e,t)=>{Tn.init(e,t),e._zod.optin=`defaulted`,j(e,`values`,e=>e.def.innerType._zod.values),e._zod.parse=(e,n)=>(n.direction===`backward`||e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),Gr=M(`$ZodNonOptional`,(e,t)=>{Tn.init(e,t),j(e,`values`,e=>{let t=e.def.innerType._zod.values;return t?new Set([...t].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>Kr(t,e)):Kr(i,e)}});function Kr(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}function qr(e,t,n,r){return t.issues.length?(e.value=n.catchValue({...t,value:e.value,error:{issues:t.issues.map(e=>k(e,r,Ze()))},input:e.value}),e):(e.value=t.value,t.memo&&(e.memo=!0),e)}var Jr=M(`$ZodCatch`,(e,t)=>{Tn.init(e,t),j(e,`optin`,e=>e.def.innerType._zod.optin===`defaulted`?`defaulted`:`optional`),j(e,`optout`,e=>e.def.innerType._zod.optout),j(e,`values`,e=>e.def.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run({value:e.value,issues:[]},n);return r instanceof Promise?r.then(r=>qr(e,r,t,n)):qr(e,r,t,n)}}),Yr=M(`$ZodPipe`,(e,t)=>{Tn.init(e,t),j(e,`values`,e=>e.def.in._zod.values),j(e,`optin`,e=>e.def.in._zod.optin),j(e,`optout`,e=>e.def.out._zod.optout),j(e,`propValues`,e=>e.def.in._zod.propValues),e._zod.parse=(e,n)=>{if(n.direction===`backward`){let r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>Xr(e,t.in,n)):Xr(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>Xr(e,t.out,n)):Xr(r,t.out,n)}});function Xr(e,t,n){return e.issues.some(e=>e.code!==`unrecognized_keys`)?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}var Zr=M(`$ZodReadonly`,(e,t)=>{Tn.init(e,t),j(e,`propValues`,e=>e.def.innerType._zod.propValues),j(e,`values`,e=>e.def.innerType._zod.values),j(e,`optin`,e=>e.def.innerType?._zod?.optin),j(e,`optout`,e=>e.def.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(Qr):Qr(r)}});function Qr(e){return e.memo||(e.value=Object.freeze(e.value)),e}var $r=M(`$ZodCustom`,(e,t)=>{an.init(e,t),Tn.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>ei(t,n,r,e));ei(i,n,r,e)}});function ei(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(je(e))}}var ti=class extends Error{constructor(){super(`Cannot parse a reference cycle that closes through a transform`),this.name=`ZodCyclicError`}},ni=`~memo`,ri=[];function ii(e){return typeof e==`object`&&!!e}function ai(e){return e.map(e=>e.path?{...e,path:e.path.slice()}:{...e})}var oi=new WeakMap,si=0,ci=1,li=2;function ui(e,t,n){let r=oi.get(e);if(r!==void 0)return r?li:si;if(t.has(e))return li;t.add(e);let i=si,a=e=>{if(i!==li&&e?._zod){let r=ui(e,t,n);r>i&&(i=r)}},o=(e,r)=>{let i=si;for(let a of Reflect.ownKeys(e)){let o=Object.getOwnPropertyDescriptor(e,a);if(r&&!o.enumerable)continue;let s=o.get?ci:o.value?._zod?ui(o.value,t,n):si;s>i&&(i=s)}return i},s=e=>{e>i&&(i=e)},c=e._zod.def;switch(c.type){case`object`:{let e=b(c);s(e?o(e,!0):ci),a(c.catchall);break}case`array`:a(c.element);break;case`tuple`:for(let e of c.items)a(e);a(c.rest);break;case`record`:case`map`:a(c.keyType),a(c.valueType);break;case`set`:a(c.valueType);break;case`union`:for(let e of c.options)a(e);break;case`intersection`:a(c.left),a(c.right);break;case`optional`:case`nullable`:case`default`:case`prefault`:case`catch`:case`readonly`:case`nonoptional`:case`promise`:case`success`:a(c.innerType);break;case`pipe`:a(c.in),a(c.out);break;case`function`:a(c.input),a(c.output);break;case`lazy`:{let r=c._cachedInner??(n?e._zod.innerType:void 0);s(r?ui(r,t,!1):ci);break}case`template_literal`:case`string`:case`number`:case`int`:case`boolean`:case`bigint`:case`symbol`:case`undefined`:case`null`:case`void`:case`never`:case`any`:case`unknown`:case`date`:case`nan`:case`enum`:case`literal`:case`file`:case`transform`:case`custom`:break;default:for(let e in c){let t=Object.getOwnPropertyDescriptor(c,e);if(!t||t.get)continue;let n=t.value;if(n&&typeof n==`object`){if(n._zod)a(n);else if(Array.isArray(n))for(let e of n)a(e)}}}return t.delete(e),di(e,i)}function di(e,t){return t!==ci&&oi.set(e,t===li),t}function fi(e,t){let n=e.buckets.get(t);return n||(n=new WeakMap,e.buckets.set(t,n)),n}var pi,mi=[],hi={alloc(e,t,n){let r=pi;if(!r)return n;pi=void 0;let i={value:n,issues:null};return r.set(t.value,i),mi.push(i),n},guard(e){var t;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let t=e._zod.parse,n=(e,n)=>{if(n.direction!==`backward`&&_i(n,e.value))throw new ti;return t(e,n)};e._zod.parse=n,e._zod.run===t&&(e._zod.run=n)})},attach(e){var t;let n,r=!1,i,a;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let t=e._zod.parse,o=(s,c)=>{if(n===void 0){let i=ui(e,new Set,!1);if(i===si)return e._zod.parse=t,e._zod.run===o&&(e._zod.run=t),t(s,c);i===li||r?n=!0:r=!0}let l=s.value;if(!ii(l))return t(s,c);let u=c[ni];u||(u={buckets:new WeakMap,backEdges:void 0},c[ni]=u);let d;i===c?d=a:(d=fi(u,e),i=c,a=d);let f=d.get(l);if(f)return s.value=f.value,f.issues?f.issues.length&&s.issues.push(...ai(f.issues)):(s.memo=!0,u.backEdges??(u.backEdges=new WeakSet),u.backEdges.add(f.value)),s;pi=d;let p=mi.length,m=t(s,c);pi=void 0;let h=mi.length>p?mi.pop():void 0;return m instanceof Promise?m.then(e=>(h&&(h.issues=e.issues.length?ai(e.issues):ri),e)):(h&&(h.issues=m.issues.length?ai(m.issues):ri),m)};e._zod.parse=o,e._zod.run===t&&(e._zod.run=o)})}};function gi(){return hi}function _i(e,t){let n=e[ni]?.backEdges;return n!==void 0&&ii(t)&&n.has(t)}var vi=()=>{let e={string:{unit:`characters`,verb:`to have`},file:{unit:`bytes`,verb:`to have`},array:{unit:`items`,verb:`to have`},set:{unit:`items`,verb:`to have`},map:{unit:`entries`,verb:`to have`}};function t(t){return e[t]??null}let n={regex:`input`,email:`email address`,url:`URL`,emoji:`emoji`,uuid:`UUID`,uuidv4:`UUIDv4`,uuidv6:`UUIDv6`,nanoid:`nanoid`,guid:`GUID`,cuid:`cuid`,cuid2:`cuid2`,ulid:`ULID`,xid:`XID`,ksuid:`KSUID`,datetime:`ISO datetime`,date:`ISO date`,time:`ISO time`,duration:`ISO duration`,ipv4:`IPv4 address`,ipv6:`IPv6 address`,mac:`MAC address`,cidrv4:`IPv4 range`,cidrv6:`IPv6 range`,base64:`base64-encoded string`,base64url:`base64url-encoded string`,json_string:`JSON string`,e164:`E.164 number`,currency_code:`currency code`,credit_card:`credit card number`,iban:`IBAN`,jwt:`JWT`,template_literal:`input`},r={nan:`NaN`};function i(e,t){return e===`number`&&typeof t==`number`&&!Number.isFinite(t)?String(t):r[e]??e}return e=>{switch(e.code){case`invalid_type`:return`Invalid input: expected ${i(e.expected)}, received ${i(Ae(e.input),e.input)}`;case`invalid_value`:return e.values.length===1?`Invalid input: expected ${de(e.values[0])}`:`Invalid option: expected one of ${f(e.values,`|`)}`;case`too_big`:{let n=e.exact?`exactly `:e.inclusive?`<=`:`<`,r=t(e.origin);return r?`Too big: expected ${e.origin??`value`} to have ${n}${e.maximum.toString()} ${r.unit??`elements`}`:`Too big: expected ${e.origin??`value`} to be ${n}${e.maximum.toString()}`}case`too_small`:{let n=e.exact?`exactly `:e.inclusive?`>=`:`>`,r=t(e.origin);return r?`Too small: expected ${e.origin} to have ${n}${e.minimum.toString()} ${r.unit}`:`Too small: expected ${e.origin} to be ${n}${e.minimum.toString()}`}case`invalid_format`:{let t=e;return t.format===`starts_with`?`Invalid string: must start with "${t.prefix}"`:t.format===`ends_with`?`Invalid string: must end with "${t.suffix}"`:t.format===`includes`?`Invalid string: must include "${t.includes}"`:t.format===`regex`?`Invalid string: must match pattern ${t.pattern}`:`Invalid ${n[t.format]??e.format}`}case`not_multiple_of`:return`Invalid number: must be a multiple of ${e.divisor}`;case`unrecognized_keys`:return`Unrecognized key${e.keys.length>1?`s`:``}: ${f(e.keys,`, `)}`;case`invalid_key`:return`Invalid key in ${e.origin}`;case`invalid_union`:return e.options&&Array.isArray(e.options)&&e.options.length>0?`Invalid discriminator value. Expected ${e.options.map(e=>`'${e}'`).join(` | `)}`:e.inclusive===!1?`Invalid input: more than one option matched`:`Invalid input`;case`invalid_element`:return`Invalid value in ${e.origin}`;default:return`Invalid input`}}};function yi(){return{localeError:vi()}}var bi,xi=class{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let n=t[0];return this._map.set(e,n),n&&typeof n==`object`&&`id`in n&&this._idmap.set(n.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};delete n.id;let r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}};function Si(){return new xi}(bi=globalThis).__zod_globalRegistry??(bi.__zod_globalRegistry=Si());var Ci=globalThis.__zod_globalRegistry;function wi(e){return e.checks&&=[...e.checks],e}function Ti(e,t){return new e(wi({type:`string`,...E(t)}))}function Ei(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...E(t)})}function Di(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...E(t)})}function Oi(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...E(t)})}function ki(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...E(t)})}function Ai(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...E(t)})}function ji(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...E(t)})}function Mi(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...E(t)})}function Ni(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...E(t)})}function Pi(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...E(t)})}function Fi(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...E(t)})}function Ii(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...E(t)})}function Li(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...E(t)})}function Ri(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...E(t)})}function zi(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...E(t)})}function Bi(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...E(t)})}function Vi(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...E(t)})}function Hi(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...E(t)})}function Ui(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...E(t)})}function Wi(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...E(t)})}function Gi(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...E(t)})}function Ki(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...E(t)})}function qi(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...E(t)})}function Ji(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...E(t)})}function Yi(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...E(t)})}function Xi(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...E(t)})}function Zi(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...E(t)})}function Qi(e,t){return new e(wi({type:`number`,checks:[],...E(t)}))}function $i(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...E(t)})}function ea(e,t){return new e({type:`boolean`,...E(t)})}function ta(e){return new e({type:`unknown`})}function na(e,t){return new e({type:`never`,...E(t)})}function ra(e,t){return new cn({check:`less_than`,...E(t),value:e,inclusive:!1})}function ia(e,t){return new cn({check:`less_than`,...E(t),value:e,inclusive:!0})}function aa(e,t){return new ln({check:`greater_than`,...E(t),value:e,inclusive:!1})}function oa(e,t){return new ln({check:`greater_than`,...E(t),value:e,inclusive:!0})}function sa(e,t){return new un({check:`multiple_of`,...E(t),value:e})}function ca(e,t){return new fn({check:`max_length`,...E(t),maximum:e})}function la(e,t){return new pn({check:`min_length`,...E(t),minimum:e})}function P(e,t){return new mn({check:`length_equals`,...E(t),length:e})}function F(e,t){return new gn({check:`string_format`,format:`regex`,...E(t),pattern:e})}function ua(e){return new _n({check:`string_format`,format:`lowercase`,...E(e)})}function da(e){return new vn({check:`string_format`,format:`uppercase`,...E(e)})}function fa(e,t){return new yn({check:`string_format`,format:`includes`,...E(t),includes:e})}function pa(e,t){return new bn({check:`string_format`,format:`starts_with`,...E(t),prefix:e})}function ma(e,t){return new xn({check:`string_format`,format:`ends_with`,...E(t),suffix:e})}function ha(e){return new Sn({check:`overwrite`,tx:e})}function ga(e){return ha(t=>t.normalize(e))}function _a(){return ha(e=>e.trim())}function va(){return ha(e=>e.toLowerCase())}function ya(){return ha(e=>e.toUpperCase())}function ba(){return ha(e=>ne(e))}function xa(e,t,n){return new e({type:`array`,element:t,...E(n)})}function Sa(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...E(n)})}function Ca(e,t){let n=wa(t=>(t.addIssue=e=>{if(typeof e==`string`)t.issues.push(je(e,t.value,n._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,`input`in r||(r.input=t.value),r.inst??=n,r.continue??=!n._zod.def.abort,t.issues.push(je(r))}},e(t.value,t)),t);return n}function wa(e,t){let n=new an({check:`custom`,...E(t)});return n._zod.check=e,n}function Ta(e,...t){for(let n of t)for(let t of Reflect.ownKeys(n))Object.prototype.propertyIsEnumerable.call(n,t)&&y(e,t,n[t]);return e}function Ea(e){let t=e?.target??`draft-2020-12`;return t===`draft-4`&&(t=`draft-04`),t===`draft-7`&&(t=`draft-07`),{processors:e.processors??{},metadataRegistry:e?.metadata??Ci,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:new Map,sharedDefsExtractedFor:void 0,sharedEmitDoneFor:void 0,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,intersections:[],deferred:[],external:e?.external??void 0}}function Da(e,t,n,r,i){let a=typeof t.unrepresentable==`function`?t.unrepresentable({zodSchema:e,path:r.path,message:i}):t.unrepresentable;if(a===`any`)return!1;if(a===void 0||a===`throw`)throw Error(i);return Object.assign(n,a),!0}function Oa(e,t,n={path:[],schemaPath:[]}){var r;let i=e._zod.def,a=t.seen.get(e);if(a)return a.count++,n.schemaPath.includes(e)&&(a.cycle=n.path),a.schema;let o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o),t.sharedDefsExtractedFor=void 0,t.sharedEmitDoneFor=void 0;let s=e._zod.toJSONSchema?.();if(s)o.schema=s;else{let r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,r);else{let n=o.schema,a=t.processors[i.type];if(!a)throw Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);a(e,t,n,r)}let a=e._zod.parent;a&&(o.ref||=a,Oa(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&Ta(o.schema,c),t.io===`input`&&Ra(e)&&(delete o.schema.examples,delete o.schema.default),t.io===`input`&&`_prefault`in o.schema&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function ka(e){return e.replace(/~/g,`~0`).replace(/\//g,`~1`)}function Aa(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);if(e.external&&e.sharedDefsExtractedFor===e.external)return;let r=new Map;for(let t of e.seen.entries()){let n=e.metadataRegistry.get(t[0])?.id;if(n){let e=r.get(n);if(e&&e!==t[0])throw Error(`Duplicate schema id "${n}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(n,t[0])}}let i=t=>{let r=e.target===`draft-2020-12`?`$defs`:`definitions`;if(e.external){let n=e.external.registry.get(t[0])?.id,i=e.external.uri??(e=>e);if(n)return{ref:i(n)};let a=t[1].defId??t[1].schema.id??`schema${e.counter++}`;return t[1].defId=a,{defId:a,ref:`${i(`__shared`)}#/${r}/${ka(a)}`}}let i=`#/${r}/`;if(t[1]===n&&!t[1].schema.id)return{ref:`#`};let a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+ka(a)}},a=e=>{if(e[1].schema.$ref)return;let t=e[1],{ref:n,defId:r}=i(e);t.def={...t.schema},r&&(t.defId=r);let a=t.schema;for(let e in a)delete a[e];a.$ref=n};if(e.cycles===`throw`)for(let t of e.seen.entries()){let e=t[1];if(e.cycle)throw Error(`Cycle detected: #/${e.cycle?.join(`/`)}/<root>
63
63
 
64
64
  Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0])a(n);else{if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}(e.metadataRegistry.get(n[0])?.id||r.cycle||r.count>1&&e.reused===`ref`)&&a(n)}}e.external&&(e.sharedDefsExtractedFor=e.external)}function ja(e){let t=e.anyOf;if(!Array.isArray(t)||t.length===0||e.type!==void 0)return;let n=[];for(let e of t){if(!e||typeof e!=`object`)return;ja(e);let t=Object.keys(e);if(t.length!==1||t[0]!==`type`)return;let r=e.type;for(let e of Array.isArray(r)?r:[r]){if(typeof e!=`string`)return;n.includes(e)||n.push(e)}}delete e.anyOf,e.type=n.length===1?n[0]:n}var Ma=new Set([`type`,`properties`,`required`,`additionalProperties`]),Na=[`oneOf`,`anyOf`];function Pa(e){let t=e.additionalProperties;return t===void 0||t===!1||typeof t!=`object`||!t?null:Object.keys(t).length?t:null}function Fa(e){let t=[];for(let n of e){if(typeof n!=`object`||n.type!==`object`)return null;for(let e in n)if(!Ma.has(e))return null;t.push(n)}let n={},r=new Set;for(let e of t){for(let r in e.properties){if(Object.prototype.hasOwnProperty.call(n,r))continue;let e=[];for(let n of t){let t=n.properties?.[r]??Pa(n);t!=null&&(e.some(e=>JSON.stringify(e)===JSON.stringify(t))||e.push(t))}y(n,r,e.length===1?e[0]:Fa(e)??{allOf:e})}for(let t of e.required??[])r.add(t)}let i={type:`object`,properties:n};if(r.size&&(i.required=[...r]),t.every(e=>e.additionalProperties===!1))i.additionalProperties=!1;else{let e=[];for(let n of t){let t=Pa(n);t&&!e.some(e=>JSON.stringify(e)===JSON.stringify(t))&&e.push(t)}e.length===1?i.additionalProperties=e[0]:e.length>1&&(i.additionalProperties={allOf:e})}return i}function Ia(e){let t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(let t of Ma)if(t in e)return;let n=t.filter(e=>Na.some(t=>Array.isArray(e[t]))),r=null;if(!n.length)r=Fa(t);else{let e=n[0],i=Na.find(t=>Array.isArray(e[t]));if(Object.keys(e).length!==1)return;let a=t.filter(t=>t!==e),o=e[i].map(e=>Fa([...a,e]));if(o.some(e=>!e))return;r={[i]:o}}r&&(delete e.allOf,Ta(e,r))}function La(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):Ta(i,s),Ta(i,a),t._zod.parent===o)for(let e in i)e!==`$ref`&&e!==`allOf`&&(e in a||delete i[e]);if(s.$ref&&n.def)for(let e in i)e!==`$ref`&&e!==`allOf`&&e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e!==`$ref`&&e!==`allOf`&&e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(let t of[...e.seen.entries()].reverse())r(t[0]);if(e.target!==`openapi-3.0`)for(let t of e.seen.entries())ja(t[1].def??t[1].schema);for(let t of e.deferred)t();if(e.intersections.length){let t=new Map;for(let n of e.seen.values())for(let e of[n.schema,n.def]){let n=e?.allOf;if(!Array.isArray(n))continue;let r=t.get(n);r?r.push(e):t.set(n,[e])}for(let n of e.intersections)for(let e of t.get(n)??[])Ia(e)}}let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}Ta(i,n.defId?n.schema:n.def??n.schema);let a=e.metadataRegistry.get(t)?.id;a!==void 0&&i.id===a&&delete i.id;let o=e.external?.defs??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,y(o,e.defId,e.def))}e.external&&(e.sharedEmitDoneFor=e.external),e.external||Object.keys(o).length>0&&(e.target===`draft-2020-12`?i.$defs=o:i.definitions=o);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,"~standard",{value:{...t[`~standard`],jsonSchema:{input:Ba(t,`input`,e.processors),output:Ba(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function Ra(e,t){let n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return Ra(r.element,n);if(r.type===`set`)return Ra(r.valueType,n);if(r.type===`lazy`)return Ra(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type==="default"||r.type===`prefault`||r.type===`catch`)return Ra(r.innerType,n);if(r.type===`intersection`)return Ra(r.left,n)||Ra(r.right,n);if(r.type===`record`||r.type===`map`)return Ra(r.keyType,n)||Ra(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:Ra(r.in,n)||Ra(r.out,n);if(r.type===`object`){for(let e in r.shape)if(Ra(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(Ra(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(Ra(e,n))return!0;return!!(r.rest&&Ra(r.rest,n))}return!1}var za=(e,t={})=>n=>{let r=Ea({...n,processors:t});return Oa(e,r),Aa(r,e),La(r,e)},Ba=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=Ea({...i??{},target:a,io:t,processors:n});return Oa(e,o),Aa(o,e),La(o,e)},Va=(e,t,n)=>{(e[t]===void 0||n>e[t])&&(e[t]=n)},Ha=(e,t,n)=>{(e[t]===void 0||n<e[t])&&(e[t]=n)},Ua=(e,t)=>{Va(e,`minimum`,t),Ha(e,`maximum`,t)},Wa=(e,t)=>{e.multipleOf??=[],e.multipleOf.includes(t)||e.multipleOf.push(t)},Ga=(e,t)=>{e.patterns??=new Set,e.patterns.add(t)},Ka=(e,t)=>{e.mime=e.mime?e.mime.filter(e=>t.includes(e)):[...t]},qa=(e,t)=>{e.format=t,t.includes(`int`)&&(e.isInt=!0)},Ja=(e,t)=>Va(e,`minimum`,t.minimum),Ya=(e,t)=>Ha(e,`maximum`,t.maximum),Xa=e=>(t,n)=>{qa(t,n.format);let[r,i]=e[n.format];Va(t,`minimum`,r),Ha(t,`maximum`,i)},Za={greater_than:(e,t)=>Va(e,t.inclusive?`minimum`:`exclusiveMinimum`,t.value),less_than:(e,t)=>Ha(e,t.inclusive?`maximum`:`exclusiveMaximum`,t.value),multiple_of:(e,t)=>Wa(e,t.value),number_format:Xa(pe),bigint_format:Xa(me),min_length:Ja,max_length:Ya,length_equals:(e,t)=>Ua(e,t.length),min_size:Ja,max_size:Ya,size_equals:(e,t)=>Ua(e,t.size),string_format:(e,t)=>{qa(e,t.format),t.pattern&&Ga(e,t.pattern),(t.format===`base64`||t.format===`base64url`)&&(e.contentEncoding=t.format),(t.local||t.precision===-1)&&(e.laxFormat=!0)},mime_type:(e,t)=>Ka(e,t.mime)};function Qa(e){let t={},n=e._zod.def,r=e._zod.traits.has(`$ZodCheck`)?[e,...n.checks??[]]:n.checks??[];for(let e of r)Za[e._zod.def.check]?.(t,e._zod.def);let i=e._zod.bag;i.minimum!==void 0&&Va(t,`minimum`,i.minimum),i.exclusiveMinimum!==void 0&&Va(t,`exclusiveMinimum`,i.exclusiveMinimum),i.maximum!==void 0&&Ha(t,`maximum`,i.maximum),i.exclusiveMaximum!==void 0&&Ha(t,`exclusiveMaximum`,i.exclusiveMaximum),i.multipleOf!==void 0&&Wa(t,i.multipleOf),i.format!==void 0&&(t.format??=i.format,i.format.includes(`int`)&&(t.isInt=!0)),i.mime&&Ka(t,i.mime);for(let e of i.patterns??[])Ga(t,e);return t}var $a={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},eo=new Map([[sr,Ut],[lr,Wt]]),to=e=>eo.get(e)??e,no=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l,laxFormat:u}=Qa(e);if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=$a[s]??s,i.format===``&&delete i.format,(s===`time`||u)&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c].map(to);e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},ro=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,multipleOf:s,exclusiveMaximum:c,exclusiveMinimum:l,isInt:u}=Qa(e);i.type=u?`integer`:`number`;let d=typeof l==`number`&&l>=(a??-1/0),f=typeof c==`number`&&c<=(o??1/0),p=t.target===`draft-04`||t.target===`openapi-3.0`;if(d?p?(i.minimum=l,i.exclusiveMinimum=!0):i.exclusiveMinimum=l:typeof a==`number`&&(i.minimum=a),f?p?(i.maximum=c,i.exclusiveMaximum=!0):i.exclusiveMaximum=c:typeof o==`number`&&(i.maximum=o),s){let n=new Set;for(let a of s)Number.isFinite(a)&&a!==0?n.add(Math.abs(a)):Da(e,t,i,r,`A multipleOf divisor of ${a} cannot be represented in JSON Schema`);let[a,...o]=n;a!==void 0&&(i.multipleOf=a),o.length&&(i.allOf=[...i.allOf??[],...o.map(e=>({multipleOf:e}))])}},io=(e,t,n,r)=>{n.type=`boolean`},ao=(e,t,n,r)=>{n.not={}},oo=(e,t,n,r)=>{let i=e._zod.def,a=d(i.entries);a.length===0?n.not={}:(a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a)},so=(e,t,n,r)=>{Da(e,t,n,r,`Custom types cannot be represented in JSON Schema`)},co=(e,t,n,r)=>{Da(e,t,n,r,`Transforms cannot be represented in JSON Schema`)},lo=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=Qa(e);typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=Oa(a.element,t,{...r,path:[...r.path,`items`]})};function uo(e){let t=e._zod.def;return t.type===`pipe`&&t.in._zod.traits.has(`$ZodTransform`)?uo(t.out):t.type===`catch`?uo(t.innerType):e._zod.optin}var fo=(e,t,n,r)=>{let i=n,a=e._zod.def,o=a.shape;if(Object.getOwnPropertySymbols(o).length&&Da(e,t,i,r,`Symbol keys cannot be represented in JSON Schema`))return;i.type=`object`,i.properties={};for(let e in o)y(i.properties,e,Oa(o[e],t,{...r,path:[...r.path,`properties`,e]}));let s=[];for(let e of Object.keys(o)){let n=a.shape[e];(t.io===`input`?uo(n)===void 0:n._zod.optout===void 0)&&s.push(e)}s.length>0&&(i.required=s),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=Oa(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},po=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>Oa(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},mo=(e,t,n,r)=>{let i=e._zod.def,a=Oa(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=Oa(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1,c=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]];n.allOf=c,t.intersections.push(c)};function ho(e,t,n){if(t.$ref){if(n.has(t))return t;n.add(t);let r=e.get(t)?.def;if(!r)return t;let i=ho(e,r,n);return i===r?t:i}for(let r of[`anyOf`,`oneOf`]){let i=t[r];if(!Array.isArray(i))continue;let a=i.map(t=>ho(e,t,n));a.some((e,t)=>e!==i[t])&&(t={...t,[r]:a})}let r=Array.isArray(t.type)?t.type:[t.type],i=!r.includes(`string`)&&r.some(e=>e===`number`||e===`integer`),a=t.enum??(t.const===void 0?void 0:[t.const]);if(!i&&!a?.some(e=>typeof e==`number`))return t;let{minimum:o,maximum:s,exclusiveMinimum:c,exclusiveMaximum:l,multipleOf:u,format:d,id:f,...p}=t;return p.enum?p.enum=p.enum.map(e=>typeof e==`number`?String(e):e):typeof p.const==`number`&&(p.const=String(p.const)),i&&(p.type=`string`,a||(p.pattern=(r.includes(`number`)?en:$t).source)),p}var go=new WeakMap;function _o(e){let t=new Map;for(let n of e.seen.values())n.def&&!t.has(n.schema)&&t.set(n.schema,n);let n=new Map;for(let r of go.get(e)??[]){let i=e.seen.get(r),a=(i?.def??i?.schema)?.propertyNames;if(!a||a===!0||n.has(a))continue;let o=ho(t,a,new Set);o!==a&&n.set(a,o)}if(n.size)for(let t of e.seen.values())for(let e of[t.schema,t.def]){let t=e&&n.get(e.propertyNames);t&&(e.propertyNames=t)}}var vo=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=Qa(o).patterns;if(a.mode===`loose`&&s&&s.size>0){let e=Oa(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)y(i.patternProperties,to(t).source,e)}else{if(t.target===`draft-07`||t.target===`draft-2020-12`){i.propertyNames=Oa(a.keyType,t,{...r,path:[...r.path,`propertyNames`]});let n=go.get(t);n||(n=[],go.set(t,n),t.deferred.push(()=>_o(t))),n.push(e)}i.additionalProperties=Oa(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]})}let c=o._zod.values,l=t.io===`input`&&uo(a.valueType)!==void 0;if(c&&!a.partial&&!l){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e.map(String))}},yo=(e,t,n,r)=>{let i=e._zod.def,a=Oa(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},bo=(e,t,n,r)=>{let i=e._zod.def;Oa(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},xo=Symbol();function So(e,t,n,r,i){let a=!1,o=JSON.stringify(e,(e,t)=>typeof t==`bigint`?(a=!0,null):t);return a?(Da(t,n,r,i,`BigInt defaults cannot be represented in JSON Schema`),xo):JSON.parse(o)}var Co=(e,t,n,r)=>{let i=e._zod.def;Oa(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o=So(i.defaultValue,e,t,n,r);o!==xo&&(n.default=o)},wo=(e,t,n,r)=>{let i=e._zod.def;Oa(i.innerType,t,r);let a=t.seen.get(e);if(a.ref=i.innerType,t.io!==`input`)return;let o=So(i.defaultValue,e,t,n,r);o!==xo&&(n._prefault=o)},To=(e,t,n,r)=>{let i=e._zod.def;Oa(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{Da(e,t,n,r,`Dynamic catch values are not supported in JSON Schema`);return}n.default=o},Eo=(e,t,n,r)=>{let i=e._zod.def,a=i.in._zod.traits.has(`$ZodTransform`),o=t.io===`input`?a?i.out:i.in:i.out;Oa(o,t,r);let s=t.seen.get(e);s.ref=o},Do=(e,t,n,r)=>{let i=e._zod.def;Oa(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},Oo=(e,t,n,r)=>{let i=e._zod.def;Oa(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},ko=new WeakSet([Object.prototype,Error.prototype]);function Ao(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,get(){let e=n(this);return Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0}),e},set(e){Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0})}})}var jo=M(`ZodError`,(e,t)=>{rt.init(e,t),e.name=`ZodError`;let n=Object.getPrototypeOf(e);ko.has(n)||(ko.add(n),Ao(n,`format`,e=>t=>ot(e,t)),Ao(n,`flatten`,e=>t=>at(e,t)),Ao(n,`addIssue`,e=>t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,p,2)}),Ao(n,`addIssues`,e=>t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,p,2)}),Object.defineProperty(n,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},void 0,{Parent:Error}),Mo=ct(jo),No=lt(jo),Po=ut(jo),Fo=ft(jo),Io=vt(jo),Lo=yt(jo),Ro=bt(jo),zo=xt(jo),Bo=St(jo),Vo=Ct(jo),Ho=wt(jo),Uo=Tt(jo);function Wo(){Xe.localeError||Ze(yi())}function Go(){Xe.memoizer||Ze({memoizer:gi()})}var Ko=M(`ZodType`,(e,t)=>(Wo(),Tn.init(e,t),e.def=t,e.type=t.type,e),{check(...e){let t=this.def;return this.clone(w(t,{checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return ue(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(ic(e,t))},superRefine(e,t){return this.check(ac(e,t))},overwrite(e){return this.check(ha(e))},optional(){return Bs(this)},exactOptional(){return Hs(this)},nullable(){return Ws(this)},nullish(){return Bs(Ws(this))},nonoptional(e){return Xs(this,e)},array(){return z(this)},or(e){return js([this,e])},and(e){return Ns(this,e)},transform(e){return ec(this,Rs(e))},default(e){return Ks(this,e)},prefault(e){return Js(this,e)},catch(e){return Qs(this,e)},pipe(e){return ec(this,e)},readonly(){return nc(this)},describe(e){let t=this.clone();return Ci.add(t,{description:e}),t},meta(...e){if(e.length===0)return Ci.get(this);let t=this.clone();return Ci.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e,...t){return t.length===0?e(this):e(this,...t)},get"~standard"(){return Pe(this,`~standard`,{...On(this),jsonSchema:{input:Ba(this,`input`),output:Ba(this,`output`)}})},set"~standard"(e){Ne(this,`~standard`,e)},parse:function e(t,n){return Mo(this,t,n,{callee:e})},parseAsync:async function e(t,n){return await No(this,t,n,{callee:e})},safeParse(e,t){return Po(this,e,t)},async safeParseAsync(e,t){return Fo(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){Ne(this,`spa`,e)},validate(e,t){return ht(this,e,t)},validateAsync(e,t){return _t(this,e,t)},encode:function e(t,n){return Io(this,t,n,{callee:e})},decode:function e(t,n){return Lo(this,t,n,{callee:e})},encodeAsync:async function e(t,n){return await Ro(this,t,n,{callee:e})},decodeAsync:async function e(t,n){return await zo(this,t,n,{callee:e})},safeEncode(e,t){return Bo(this,e,t)},safeDecode(e,t){return Vo(this,e,t)},async safeEncodeAsync(e,t){return Ho(this,e,t)},async safeDecodeAsync(e,t){return Uo(this,e,t)},toJSONSchema(e){return za(this,{})(e)},get description(){return Ci.get(this)?.description},get _def(){return this._zod.def}}),qo=M(`_ZodString`,(e,t)=>{kn.init(e,t),Ko.init(e,t),e._zod.processJSONSchema=(t,n,r)=>no(e,t,n,r)},Fe({format:e=>Qa(e).format??null,minLength:e=>Qa(e).minimum??null,maxLength:e=>Qa(e).maximum??null},{regex(...e){return this.check(F(...e))},includes(...e){return this.check(fa(...e))},startsWith(...e){return this.check(pa(...e))},endsWith(...e){return this.check(ma(...e))},min(...e){return this.check(la(...e))},max(...e){return this.check(ca(...e))},length(...e){return this.check(P(...e))},nonempty(...e){return this.check(la(1,...e))},lowercase(e){return this.check(ua(e))},uppercase(e){return this.check(da(e))},trim(){return this.check(_a())},normalize(...e){return this.check(ga(...e))},toLowerCase(){return this.check(va())},toUpperCase(){return this.check(ya())},slugify(){return this.check(ba())}})),I=M(`ZodString`,(e,t)=>{kn.init(e,t),qo.init(e,t)},{email(e){return this.check(Ei(Qo,e))},url(e){return this.check(Mi(ts,e))},jwt(e){return this.check(qi(_s,e))},emoji(e){return this.check(Ni(rs,e))},guid(e){return this.check(Di($o,e))},uuid(e){return this.check(Oi(es,e))},uuidv4(e){return this.check(ki(es,e))},uuidv6(e){return this.check(Ai(es,e))},uuidv7(e){return this.check(ji(es,e))},nanoid(e){return this.check(Pi(is,e))},cuid(e){return this.check(Fi(as,e))},cuid2(e){return this.check(Ii(os,e))},ulid(e){return this.check(Li(ss,e))},base64(e){return this.check(Wi(ms,e))},base64url(e){return this.check(Gi(hs,e))},xid(e){return this.check(Ri(cs,e))},ksuid(e){return this.check(zi(ls,e))},ipv4(e){return this.check(Bi(us,e))},ipv6(e){return this.check(Vi(ds,e))},cidrv4(e){return this.check(Hi(fs,e))},cidrv6(e){return this.check(Ui(ps,e))},e164(e){return this.check(Ki(gs,e))},datetime(e){return this.check(Ji(Jo,e))},date(e){return this.check(Yi(Yo,e))},time(e){return this.check(Xi(Xo,e))},duration(e){return this.check(Zi(Zo,e))}});function L(e){return Ti(I,e)}var R=M(`ZodStringFormat`,(e,t)=>{An.init(e,t),qo.init(e,t)}),Jo=M(`ZodISODateTime`,(e,t)=>{Yn.init(e,t),R.init(e,t)}),Yo=M(`ZodISODate`,(e,t)=>{Xn.init(e,t),R.init(e,t)}),Xo=M(`ZodISOTime`,(e,t)=>{Zn.init(e,t),R.init(e,t)}),Zo=M(`ZodISODuration`,(e,t)=>{Qn.init(e,t),R.init(e,t)}),Qo=M(`ZodEmail`,(e,t)=>{Nn.init(e,t),R.init(e,t)}),$o=M(`ZodGUID`,(e,t)=>{jn.init(e,t),R.init(e,t)}),es=M(`ZodUUID`,(e,t)=>{Mn.init(e,t),R.init(e,t)}),ts=M(`ZodURL`,(e,t)=>{Vn.init(e,t),R.init(e,t)});function ns(e){return Mi(ts,e)}var rs=M(`ZodEmoji`,(e,t)=>{Hn.init(e,t),R.init(e,t)}),is=M(`ZodNanoID`,(e,t)=>{Un.init(e,t),R.init(e,t)}),as=M(`ZodCUID`,(e,t)=>{Wn.init(e,t),R.init(e,t)}),os=M(`ZodCUID2`,(e,t)=>{Gn.init(e,t),R.init(e,t)}),ss=M(`ZodULID`,(e,t)=>{Kn.init(e,t),R.init(e,t)}),cs=M(`ZodXID`,(e,t)=>{qn.init(e,t),R.init(e,t)}),ls=M(`ZodKSUID`,(e,t)=>{Jn.init(e,t),R.init(e,t)}),us=M(`ZodIPv4`,(e,t)=>{$n.init(e,t),R.init(e,t)}),ds=M(`ZodIPv6`,(e,t)=>{nr.init(e,t),R.init(e,t)}),fs=M(`ZodCIDRv4`,(e,t)=>{rr.init(e,t),R.init(e,t)}),ps=M(`ZodCIDRv6`,(e,t)=>{ar.init(e,t),R.init(e,t)}),ms=M(`ZodBase64`,(e,t)=>{cr.init(e,t),R.init(e,t)}),hs=M(`ZodBase64URL`,(e,t)=>{dr.init(e,t),R.init(e,t)}),gs=M(`ZodE164`,(e,t)=>{fr.init(e,t),R.init(e,t)}),_s=M(`ZodJWT`,(e,t)=>{mr.init(e,t),R.init(e,t)}),vs=M(`ZodNumber`,(e,t)=>{hr.init(e,t),Ko.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ro(e,t,n,r),e.isFinite=!0},Fe({minValue:e=>{let{minimum:t,exclusiveMinimum:n}=Qa(e);return Math.max(t??-1/0,n??-1/0)},maxValue:e=>{let{maximum:t,exclusiveMaximum:n}=Qa(e);return Math.min(t??1/0,n??1/0)},isInt:e=>{let{isInt:t,multipleOf:n}=Qa(e);return!!t||!!n?.some(Number.isSafeInteger)},format:e=>Qa(e).format??null},{gt(e,t){return this.check(aa(e,t))},gte(e,t){return this.check(oa(e,t))},min(e,t){return this.check(oa(e,t))},lt(e,t){return this.check(ra(e,t))},lte(e,t){return this.check(ia(e,t))},max(e,t){return this.check(ia(e,t))},int(e){return this.check(xs(e))},safe(e){return this.check(xs(e))},positive(e){return this.check(aa(0,e))},nonnegative(e){return this.check(oa(0,e))},negative(e){return this.check(ra(0,e))},nonpositive(e){return this.check(ia(0,e))},multipleOf(e,t){return this.check(sa(e,t))},step(e,t){return this.check(sa(e,t))},finite(){return this}}));function ys(e){return Qi(vs,e)}var bs=M(`ZodNumberFormat`,(e,t)=>{gr.init(e,t),vs.init(e,t)});function xs(e){return $i(bs,e)}var Ss=M(`ZodBoolean`,(e,t)=>{_r.init(e,t),Ko.init(e,t),e._zod.processJSONSchema=(t,n,r)=>io(e,t,n,r)});function Cs(e){return ea(Ss,e)}var ws=M(`ZodUnknown`,(e,t)=>{vr.init(e,t),Ko.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function Ts(){return ta(ws)}var Es=M(`ZodNever`,(e,t)=>{yr.init(e,t),Ko.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ao(e,t,n,r)});function Ds(e){return na(Es,e)}var Os=M(`ZodArray`,(e,t)=>{Go(),Cr.init(e,t),Ko.init(e,t),e._zod.processJSONSchema=(t,n,r)=>lo(e,t,n,r),e.element=t.element},{min(e,t){return this.check(la(e,t))},nonempty(e){return this.check(la(1,e))},max(e,t){return this.check(ca(e,t))},length(e,t){return this.check(P(e,t))},unwrap(){return this.element}});function z(e,t){return xa(Os,e,t)}var ks=M(`ZodObject`,(e,t)=>{Go(),kr.init(e,t),Ko.init(e,t),e._zod.processJSONSchema=(t,n,r)=>fo(e,t,n,r),Ve(e,`shape`,e=>e._zod.def.shape,!1)},{keyof(){return V(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(w(this._zod.def,{catchall:e}))},passthrough(){return this.clone(w(this._zod.def,{catchall:Ts()}))},loose(){return this.clone(w(this._zod.def,{catchall:Ts()}))},strict(){return this.clone(w(this._zod.def,{catchall:Ds()}))},strip(){return this.clone(w(this._zod.def,{catchall:void 0}))},extend(e){return ve(this,e)},safeExtend(e){return be(this,e)},merge(e){return xe(this,e)},pick(e){return he(this,e)},omit(e){return _e(this,e)},partial(...e){return Se(zs,this,e[0])},exactPartial(...e){return Se(Vs,this,e[0],`exactPartial`)},required(...e){return Ce(Ys,this,e[0])}});function B(e,t){return new ks({type:`object`,shape:e??{},...E(t)})}var As=M(`ZodUnion`,(e,t)=>{jr.init(e,t),Ko.init(e,t),e._zod.processJSONSchema=(t,n,r)=>po(e,t,n,r),e.options=t.options});function js(e,t){return new As({type:`union`,options:e,...E(t)})}var Ms=M(`ZodIntersection`,(e,t)=>{Mr.init(e,t),Ko.init(e,t),e._zod.processJSONSchema=(t,n,r)=>mo(e,t,n,r)});function Ns(e,t){return new Ms({type:`intersection`,left:e,right:t})}var Ps=M(`ZodRecord`,(e,t)=>{Go(),Fr.init(e,t),Ko.init(e,t),e._zod.processJSONSchema=(t,n,r)=>vo(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function Fs(e,t,n){return!t||!t._zod?new Ps({type:`record`,keyType:L(),valueType:e,...E(t)}):new Ps({type:`record`,keyType:e,valueType:t,...E(n)})}var Is=M(`ZodEnum`,(e,t)=>{Ir.init(e,t),Ko.init(e,t),e._zod.processJSONSchema=(t,n,r)=>oo(e,t,n,r),e.enum=t.entries,e.options=[...e._zod.values];let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new Is({...t,checks:[],...E(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new Is({...t,checks:[],...E(r),entries:i})}});function V(e,t){return new Is({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,...E(t)})}var Ls=M(`ZodTransform`,(e,t)=>{Go(),Lr.init(e,t),Ko.init(e,t),e._zod.processJSONSchema=(t,n,r)=>co(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Ye(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(je(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,`input`in t||(t.input=n.value),t.inst??=e,n.issues.push(je(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function Rs(e){return new Ls({type:`transform`,transform:e})}var zs=M(`ZodOptional`,(e,t)=>{zr.init(e,t),Ko.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Oo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Bs(e){return new zs({type:`optional`,innerType:e})}var Vs=M(`ZodExactOptional`,(e,t)=>{Br.init(e,t),Ko.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Oo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Hs(e){return new Vs({type:`optional`,innerType:e})}var Us=M(`ZodNullable`,(e,t)=>{Vr.init(e,t),Ko.init(e,t),e._zod.processJSONSchema=(t,n,r)=>yo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Ws(e){return new Us({type:`nullable`,innerType:e})}var Gs=M(`ZodDefault`,(e,t)=>{Hr.init(e,t),Ko.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Co(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Ks(e,t){return new Gs({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():se(t)}})}var qs=M(`ZodPrefault`,(e,t)=>{Wr.init(e,t),Ko.init(e,t),e._zod.processJSONSchema=(t,n,r)=>wo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Js(e,t){return new qs({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():se(t)}})}var Ys=M(`ZodNonOptional`,(e,t)=>{Gr.init(e,t),Ko.init(e,t),e._zod.processJSONSchema=(t,n,r)=>bo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Xs(e,t){return new Ys({type:`nonoptional`,innerType:e,...E(t)})}var Zs=M(`ZodCatch`,(e,t)=>{Jr.init(e,t),Ko.init(e,t),e._zod.processJSONSchema=(t,n,r)=>To(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Qs(e,t){return new Zs({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:Ue(t)})}var $s=M(`ZodPipe`,(e,t)=>{Yr.init(e,t),Ko.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Eo(e,t,n,r),e.in=t.in,e.out=t.out});function ec(e,t){return new $s({type:`pipe`,in:e,out:t})}var tc=M(`ZodReadonly`,(e,t)=>{Zr.init(e,t),Ko.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Do(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function nc(e){return new tc({type:`readonly`,innerType:e})}var rc=M(`ZodCustom`,(e,t)=>{$r.init(e,t),Ko.init(e,t),e._zod.processJSONSchema=(t,n,r)=>so(e,t,n,r)});function ic(e,t={}){return Sa(rc,e,t)}function ac(e,t){return Ca(e,t)}function oc(e){return Ji(Jo,e)}var H=i(),sc=u(),cc=L().regex(/^h_[0-9a-f]{16}(-[2-9]|-[1-9][0-9]+)?$/).brand(),lc=js([cc,L().regex(/^h_[0-9a-f]{16}(-[2-9]|-[1-9][0-9]+)?\.[1-9][0-9]*$/).brand()]),uc=V([`added`,`deleted`,`modified`,`renamed`]),dc=ys().int().positive(),fc=B({kind:V([`context`,`add`,`del`]),oldLine:dc.nullable(),newLine:dc.nullable(),text:L(),noNewlineAtEnd:Cs()}).readonly(),pc=ys().int().nonnegative(),mc=B({id:cc,path:L().min(1),oldStart:pc,oldLines:pc,newStart:pc,newLines:pc,sectionHeading:L().nullable(),lines:z(fc).readonly()}).readonly(),hc=B({path:L().min(1),oldPath:L().min(1).nullable(),status:uc,binary:Cs(),oldMode:L().nullable(),newMode:L().nullable(),language:L().nullable(),hunks:z(mc).readonly(),additions:pc,deletions:pc}).readonly(),gc=V([`generated`,`whitespace`,`rename`,`move`,`formatting`]),_c=B({path:L().min(1),hunkId:cc.nullable(),kind:gc,detail:L().min(1)}).readonly(),vc=B({id:lc,hunkId:cc,start:ys().int().nonnegative(),end:ys().int().positive(),definitions:z(L()).readonly()}).readonly(),yc=B({fromPartId:lc,toPartId:lc,symbol:L().min(1),line:ys().int().positive(),use:V([`call`,`type`,`request`])}).readonly(),bc=B({path:L().min(1),line:dc,use:V([`call`,`type`]),excerpt:B({start:dc,lines:z(L()).max(5).readonly()}).readonly()}).readonly(),xc=B({partId:lc,symbol:L().min(1),uses:z(bc).max(50).readonly(),more:ys().int().nonnegative()}).readonly(),Sc=e=>cc.parse(e.replace(/\.[0-9]+$/,``)),Cc=(e,t)=>{let n=e.lines.slice(0,t.start),r=e.lines.slice(t.start,t.end),i=(e,t)=>e.filter(e=>e.kind!==t).length,a=i(r,`add`),o=i(r,`del`),s=(e,t,n,r)=>Math.max(e+ +(t===0)+n-+(r===0),0);return{...e,oldStart:s(e.oldStart,e.oldLines,i(n,`add`),a),oldLines:a,newStart:s(e.newStart,e.newLines,i(n,`del`),o),newLines:o,lines:r}},wc=e=>{let t=new Map;for(let n of e)t.set(n.hunkId,[...t.get(n.hunkId)??[],n]);return t},Tc=(e,t)=>e.hunks.flatMap(e=>{let n=t.get(e.id);return n===void 0?[{id:e.id,hunk:e}]:n.map(t=>({id:t.id,hunk:Cc(e,t)}))}),Ec=e=>e.slice(e.lastIndexOf(`/`)+1),Dc=e=>e.split(`/`).slice(0,-1),Oc=new Set([`__tests__`,`test`,`tests`,`spec`]),kc=e=>{let t=Ec(e);return/\.(test|spec)\.[^.]+$/i.test(t)||/_(test|spec)\.[^.]+$/i.test(t)||/^test_.*\.py$/i.test(t)||/Tests?\.(java|kt)$/.test(t)||Dc(e).some(e=>Oc.has(e.toLowerCase()))},Ac=`get|post|put|patch|delete|head|options|all`,jc=String.raw`(?:app|router|server|mux|r|e|g|fastify|\w*(?:Router|router|App))`,Mc=String.raw`["'\`](\/[^"'\`]*)["'\`]`,Nc=[e=>[...e.matchAll(new RegExp(String.raw`@[\w.]+\.(${Ac})\(\s*${Mc}`,`gi`))].map(([,e=``,t=``])=>({method:e.toUpperCase(),path:t})),e=>{let t=new RegExp(String.raw`@[\w.]+\.route\(\s*${Mc}(.*)`).exec(e);if(t===null)return[];let[,n=``,r=``]=t,i=[...(/methods\s*=\s*[[(]([^\])]*)/.exec(r)?.[1]??``).matchAll(/["'](\w+)["']/g)].map(([,e=``])=>e.toUpperCase());return(i.length>0?i:[`GET`]).map(e=>({method:e,path:n}))},e=>[...e.matchAll(new RegExp(String.raw`(?<![\w@.])${jc}\.(${Ac})\(\s*${Mc}`,`gi`))].map(([,e=``,t=``])=>({method:e.toUpperCase(),path:t})),e=>{let t=new RegExp(String.raw`@(Get|Post|Put|Patch|Delete|Request)Mapping\(\s*(?:(?:value|path)\s*=\s*)?${Mc}`).exec(e);if(t===null)return[];let[,n=``,r=``]=t;return[{method:n===`Request`?`ALL`:n.toUpperCase(),path:r}]},e=>{let t=/\bHandle(?:Func)?\(\s*"(?:([A-Z]+) )?(\/[^"]*)"/.exec(e);if(t===null)return[];let[,n=`ALL`,r=``]=t;return[{method:n,path:r}]}],Pc=e=>Nc.flatMap(t=>t(e));String.raw`(?<![\w])(?:[fFrRuU]{1,2})?(?<quote>["'\`])(?:\$\{[^}]*\})?(?<path>\/[^"'\`]*)\k<quote>`;var Fc=B({from:L().min(1),to:L().min(1)}).readonly();new TextEncoder;var Ic=e=>({ok:!0,value:e}),Lc=e=>({ok:!1,error:e});new TextEncoder,new TextDecoder;var Rc=oc(),zc=L().regex(/^[0-9a-f]{40}$/),Bc=ns({protocol:/^https?$/}),Vc=L().regex(/^d[1-9][0-9]*$/).brand(),Hc=V([`api`,`data`,`dependency`,`security`,`error-handling`,`performance`,`concurrency`,`configuration`,`behavior`,`other`]),Uc=B({id:Vc,title:L().min(1),category:Hc,whyItMatters:L(),hunkIds:z(cc).readonly()}).readonly(),Wc=V([`pending`,`approved`,`rejected`]),Gc=B({decisionId:Vc,verdict:Wc,comment:L(),updatedAt:Rc}).readonly(),Kc=B({key:L().min(1),url:Bc,summary:L(),description:L(),type:L(),status:L()}).readonly(),qc=V([`description`,`ticket`,`commits`,`branch`]),Jc=B({summary:L(),sources:z(B({kind:qc,ref:L().nullable()}).readonly()).readonly()}).readonly(),Yc=B({summary:L(),behaviorChanges:z(L()).readonly()}).readonly(),Xc=B({kind:V([`unrequested`,`missing`,`contradicts`]),description:L(),hunkIds:z(cc).readonly()}).readonly(),Zc=B({stated:Jc.nullable(),inferred:Yc,mismatches:z(Xc).readonly()}).readonly(),Qc=V([`github`,`bitbucket`]),$c=B({repo:B({host:Qc,owner:L().min(1),repo:L().min(1)}).readonly(),number:ys().int().positive()}).readonly(),el=B({id:L().min(1),name:L()}).readonly(),tl=B({sha:zc,message:L(),author:L()}).readonly(),nl=B({ref:$c,url:Bc,title:L(),description:L(),author:el,sourceBranch:L().min(1),targetBranch:L().min(1),baseSha:zc,headSha:zc,commits:z(tl).readonly(),diff:L(),createdAt:Rc,updatedAt:Rc}).readonly(),rl=B({ref:$c,url:Bc,title:L(),author:el,updatedAt:Rc,role:V([`reviewer`,`author`])}).readonly(),il=B({hunkId:cc,riskClass:V([`mechanical`,`logic`,`contract`]),reason:L(),source:V([`proof`,`rule`,`model`,`fallback`])}).readonly(),al=L().regex(/^s[1-9][0-9]*$/).brand(),ol=B({steps:z(B({id:al,title:L().min(1),explanation:L(),partIds:z(lc).readonly(),kind:V([`flow`,`supporting`]),via:z(lc).readonly(),entries:z(lc).readonly(),codeTitle:L().nullable(),merged:z(B({title:L(),reason:L()}).readonly()).readonly()}).readonly()).readonly(),builtBy:V([`model`,`code`])}).readonly(),sl=V([`collect`,`prep`,`intent`,`risk`,`decisions`,`tour`]),cl=V([`pending`,`running`,`done`,`failed`,`skipped`]),ll=L().regex(/^a_[0-9a-f]{16}$/).brand(),ul=B({ref:$c,headSha:zc,pipelineVersion:L().min(1)}).readonly(),dl=V([`intent`,`risk`,`decisions`,`tour`]),fl=ys().int().nonnegative(),pl=B({pass:dl,inputTokens:fl,cacheReadTokens:fl,cacheWriteTokens:fl,outputTokens:fl,costUsd:ys().nonnegative()}).readonly(),ml=B({stage:sl,code:L().min(1),message:L()}).readonly(),hl=V([`running`,`complete`,`failed`]),gl=B({done:ys().int().nonnegative(),total:ys().int().nonnegative()}).readonly(),_l=V([`read`,`none`,`missing-commit`]),vl=B({id:ll,key:ul,status:hl,stages:Fs(sl,cl).readonly(),filesFetched:gl.nullable().default(null),pullRequest:nl.nullable(),files:z(hc).readonly(),tickets:z(Kc).readonly(),missingTicketKeys:z(L()).readonly(),proofs:z(_c).readonly(),parts:z(vc).readonly(),callGraph:z(yc).readonly(),fileLinks:z(Fc).readonly(),generated:z(L()).readonly(),checkout:_l,unchangedCallers:z(xc).readonly(),intent:Zc.nullable(),risk:z(il).readonly(),decisions:z(Uc).readonly(),tour:ol.nullable(),warnings:z(L()).readonly(),usage:z(pl).readonly(),error:ml.nullable(),createdAt:Rc,updatedAt:Rc}).readonly(),U=new Set([`routes`,`pages`,`app`,`screens`,`views`]),yl=e=>/\.(tsx|jsx)$/.test(e)&&e.split(`/`).slice(0,-1).some(e=>U.has(e)),bl=(e,t,n)=>{let r=t.lines.flatMap(e=>e.kind===`add`?[e.text]:[]),i=r.flatMap(Pc);if(i.length>0)return{kind:`route`,routes:xl(i)};let a=n.filter(e=>/^[A-Z]/.test(e));return yl(e.path)&&a.length>0?{kind:`page`,names:a}:n.includes(`main`)||r.some(e=>/^\s*if\s+__name__\s*==\s*["']__main__["']/.test(e))?{kind:`command`,name:`main`,path:e.path}:null},xl=e=>{let t=new Set;return e.filter(e=>{let n=`${e.method} ${e.path}`;return!t.has(n)&&(t.add(n),!0)})};B({kind:V([`not-found`,`unauthorized`,`forbidden`,`rate-limited`,`too-large`,`rejected`,`network`,`invalid-response`,`unexpected`]),message:L(),retryAfterSeconds:ys().nonnegative().nullable()}).readonly(),B({kind:V([`not-configured`,`unauthorized`,`network`,`invalid-response`,`unexpected`]),message:L()}).readonly(),B({kind:V([`refusal`,`max-tokens`,`invalid-output`,`too-large`,`rate-limited`,`overloaded`,`unauthorized`,`network`,`unexpected`]),message:L()}).readonly();var Sl=V([`approve`,`request_changes`,`comment`]),Cl=L().regex(/^(summary|decision:d[1-9][0-9]*|hunk:h_[0-9a-f]{16}(-[2-9]|-[1-9][0-9]+)?:(new|old):[1-9][0-9]*)$/).brand(),wl=B({hunkId:cc,side:V([`new`,`old`]),line:ys().int().positive(),body:L()}).readonly(),Tl=B({key:Cl,path:L().min(1),line:ys().int().positive(),side:V([`new`,`old`]),body:L().min(1)}).readonly(),El=B({verdict:Sl,summary:L(),comments:z(Tl).readonly()}).readonly(),Dl=B({url:Bc.nullable(),publishedAt:Rc,postedCommentIds:Fs(Cl,L().min(1)).readonly()}).readonly(),Ol={"github.com":{kind:`github`,pullSegment:`pull`},"bitbucket.org":{kind:`bitbucket`,pullSegment:`pull-requests`}},kl=/^[A-Za-z0-9._-]+$/,Al=/^[1-9][0-9]*$/,jl=e=>e!==void 0&&kl.test(e)&&e!==`.`&&e!==`..`,Ml=e=>{let t;try{t=new URL(e.trim())}catch{return Lc(`unsupported-url`)}let n=Ol[t.hostname];if(n===void 0||t.protocol!==`https:`||t.port!==``||t.username!==``||t.password!==``)return Lc(`unsupported-url`);let[r,i,a,o,s]=t.pathname.split(`/`);return r!==``||!jl(i)||!jl(a)||o!==n.pullSegment||s===void 0||!Al.test(s)||!Number.isSafeInteger(Number(s))?Lc(`unsupported-url`):Ic({repo:{host:n.kind,owner:i.toLowerCase(),repo:a.toLowerCase()},number:Number(s)})},Nl=e=>{let{host:t,owner:n,repo:r}=e.repo;switch(t){case`github`:return`https://github.com/${n}/${r}/pull/${e.number}`;case`bitbucket`:return`https://bitbucket.org/${n}/${r}/pull-requests/${e.number}`}},Pl=B({stepId:L(),title:L(),explanation:L()}).readonly(),Fl=B({stepId:L(),intoStepId:L(),reason:L()}).readonly();B({steps:z(Pl).readonly(),merges:z(Fl).readonly()}).readonly(),B({kind:V([`missing`,`duplicate`,`unknown`]),id:lc}).readonly();var Il=`x-megareviewer-token`,Ll=`token`,Rl=B({configured:Cs(),user:el.nullable(),error:L().nullable()}).readonly(),zl=B({version:L(),hosts:B({github:Rl,bitbucket:Rl}).readonly(),jira:B({configured:Cs()}).readonly(),model:B({enabled:Cs()}).readonly()}).readonly(),Bl=B({items:z(rl).readonly(),errors:z(B({host:Qc,message:L()}).readonly()).readonly()}).readonly(),Vl=B({url:L().min(1)}).readonly(),Hl=B({analysisId:ll}).readonly(),Ul=B({analysis:vl,verdicts:z(Gc).readonly(),publication:Dl.nullable(),isAuthor:Cs(),stale:Cs()}).readonly(),Wl=B({verdict:Wc,comment:L()}).readonly(),Gl={hunkComments:z(wl).readonly().optional(),verdict:Sl.nullable().optional()},Kl=B({summary:L(),...Gl}).readonly(),ql=B({summary:L(),allowStale:Cs(),...Gl}).readonly(),Jl=B({stage:sl,status:cl}).readonly(),Yl=B({}).readonly(),Xl=B({error:B({code:V([`bad-request`,`unsupported-url`,`host-not-configured`,`unauthorized`,`not-found`,`stale-analysis`,`analysis-not-complete`,`host-error`,`model-error`,`internal`]),message:L()}).readonly()}).readonly(),Zl=B({id:ll}).readonly(),Ql=B({id:ll,decisionId:Vc}).readonly(),$l=B({}).readonly(),eu={getStatus:{method:`GET`,path:`/api/status`,params:$l,request:null,response:zl},listPullRequests:{method:`GET`,path:`/api/pull-requests`,params:$l,request:null,response:Bl},startAnalysis:{method:`POST`,path:`/api/analyses`,params:$l,request:Vl,response:Hl},getAnalysis:{method:`GET`,path:`/api/analyses/:id`,params:Zl,request:null,response:Ul},retryAnalysis:{method:`POST`,path:`/api/analyses/:id/retry`,params:Zl,request:null,response:Hl},putVerdict:{method:`PUT`,path:`/api/analyses/:id/verdicts/:decisionId`,params:Ql,request:Wl,response:Gc},previewPublication:{method:`POST`,path:`/api/analyses/:id/publication/preview`,params:Zl,request:Kl,response:El},publish:{method:`POST`,path:`/api/analyses/:id/publication`,params:Zl,request:ql,response:Dl}},tu={method:`GET`,path:`/api/analyses/:id/events`,params:Zl,events:{updated:Jl,done:Yl}},nu=(e,t)=>e.replace(/:([A-Za-z]+)/g,(n,r)=>{let i=t[r];if(i===void 0)throw Error(`missing path param ${r} for ${e}`);return encodeURIComponent(i)}),ru=`The server sent a response this page doesn't understand, so the server and the UI may be different versions. Reload the page.`,iu=`Can't reach megareviewer. Check that it's still running in your terminal.`,au=e=>{let t=async(t,n,r)=>{let i;try{i=await e.fetch(nu(t.path,n),{method:t.method,headers:{[Il]:e.token,...r===void 0?{}:{"content-type":`application/json`}},...r===void 0?{}:{body:JSON.stringify(r)}})}catch{return Lc({code:`unreachable`,message:iu})}let a=await i.json().catch(()=>void 0);if(!i.ok){i.status===401&&e.onUnauthorized();let t=Xl.safeParse(a);return t.success?Lc(t.data.error):Lc({code:i.status>=500?`unreachable`:`internal`,message:i.status>=500?iu:ru})}let o=t.response.safeParse(a);return o.success?Ic(o.data):Lc({code:`internal`,message:ru})};return{getStatus:()=>t(eu.getStatus,{}),listPullRequests:()=>t(eu.listPullRequests,{}),startAnalysis:e=>t(eu.startAnalysis,{},e),getAnalysis:e=>t(eu.getAnalysis,{id:e}),retryAnalysis:e=>t(eu.retryAnalysis,{id:e}),putVerdict:(e,n,r)=>t(eu.putVerdict,{id:e,decisionId:n},r),previewPublication:(e,n)=>t(eu.previewPublication,{id:e},n),publish:(e,n)=>t(eu.publish,{id:e},n)}},W=2,ou=(e,t,n,r=e=>new EventSource(e))=>{let i=new URLSearchParams({[Ll]:t}),a=r(`${nu(tu.path,{id:e})}?${i}`),o=!1,s=!1,c=()=>{s=!0,a.close()};return a.addEventListener(`open`,()=>{o&&(o=!1,n({type:`changed`}))}),a.addEventListener(`error`,()=>{o=!0,!(s||a.readyState!==W)&&(s=!0,n({type:`closed`}))}),a.addEventListener(`updated`,()=>n({type:`changed`})),a.addEventListener(`done`,()=>{c(),n({type:`done`})}),()=>{s||c()}},su=(0,H.createContext)(null),cu=()=>{let e=(0,H.useContext)(su);if(e===null)throw Error(`useApi needs an ApiContext provider`);return e},lu={data:null,error:null,loading:!0},uu=e=>{let[t,n]=(0,H.useState)(lu),[r,i]=(0,H.useState)(0);(0,H.useEffect)(()=>{let t=!0;return n(e=>({...e,loading:!0})),e().then(e=>{t&&n(t=>e.ok?{data:e.value,error:null,loading:!1}:{data:t.data,error:e.error,loading:!1})}),()=>{t=!1}},[e,r]);let a=(0,H.useCallback)(()=>i(e=>e+1),[]);return{...t,refresh:a}},du=()=>{let{client:e}=cu(),{data:t,...n}=uu((0,H.useCallback)(()=>e.getStatus(),[e]));return{status:t,...n}},fu=()=>{let{client:e}=cu(),{data:t,...n}=uu((0,H.useCallback)(()=>e.listPullRequests(),[e]));return{pullRequests:t,...n}},pu=e=>{let{client:t,subscribe:n}=cu(),[r,i]=(0,H.useState)({view:null,error:null,loading:!0}),a=(0,H.useRef)(0),o=(0,H.useRef)(null),s=(0,H.useCallback)(async()=>{a.current+=1;let n=a.current,r=await t.getAnalysis(e);n===a.current&&(r.ok&&(o.current=r.value),i(e=>r.ok?{view:r.value,error:null,loading:!1}:{view:e.view,error:r.error,loading:!1}))},[t,e]);return(0,H.useEffect)(()=>{o.current=null,i({view:null,error:null,loading:!0}),s();let t,r=n(e,e=>{if(clearTimeout(t),e.type===`changed`){t=setTimeout(()=>void s(),100);return}let n=o.current;(n===null||n.analysis.status===`running`)&&s()});return()=>{clearTimeout(t),r(),a.current+=1}},[e,s,n]),{...r,refetch:s}},mu=e=>{let[t,n]=(0,H.useState)({pending:!1,error:null}),r=(0,H.useCallback)(async(...t)=>{n({pending:!0,error:null});let r=await e(...t);return n({pending:!1,error:r.ok?null:r.error}),r},[e]),i=(0,H.useCallback)(()=>n({pending:!1,error:null}),[]);return{...t,run:r,reset:i}},hu=e=>{let t=e.trim();return t===``||/[.!?]$/.test(t)?t:`${t}.`},gu={"bad-request":e=>`megareviewer rejected the request: ${hu(e)}`,"unsupported-url":()=>`Only github.com and bitbucket.org pull request links are supported.`,"host-not-configured":e=>`${hu(e)} Run npx megareviewer doctor to see how to set it up.`,unauthorized:()=>`This session has ended. Open megareviewer from the link printed in your terminal.`,"not-found":e=>hu(e),"stale-analysis":()=>`The pull request has new commits since this analysis.`,"analysis-not-complete":()=>`The analysis isn't complete yet.`,"host-error":e=>`The git host returned an error: ${hu(e)}`,"model-error":e=>`The model call failed: ${hu(e)}`,internal:e=>hu(e)||`Something went wrong.`,unreachable:e=>hu(e)},_u=e=>gu[e.code](e.message),vu={page:`not-found`},yu=(e,t)=>{let n=RegExp(`^/${t}/([^/]+)/?$`).exec(e);if(n?.[1]===void 0)return null;try{return decodeURIComponent(n[1])}catch{return null}},bu=(e,t)=>{if(e===`/`)return{page:`picker`};let n=yu(e,`review`);if(n!==null){let e=ll.safeParse(n);return e.success?{page:`review`,analysisId:e.data}:vu}let r=t.dev?yu(e,`dev`):null;return r===null?vu:{page:`playground`,name:r}},xu=e=>`/review/${encodeURIComponent(e)}`,Su=e=>(window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)),Cu=()=>(0,H.useSyncExternalStore)(Su,()=>window.location.pathname),wu=e=>{window.history.pushState(null,``,e),window.dispatchEvent(new PopStateEvent(`popstate`))},Tu=[[`year`,31536e3],[`month`,2592e3],[`week`,604800],[`day`,86400],[`hour`,3600],[`minute`,60]],Eu=new Intl.RelativeTimeFormat(`en`,{numeric:`auto`}),Du=(e,t)=>{let n=Math.round((Date.parse(e)-t)/1e3);for(let[e,t]of Tu)if(Math.abs(n)>=t)return Eu.format(Math.trunc(n/t),e);return`just now`},Ou=t((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),G=t(((e,t)=>{t.exports=Ou()}))(),ku={github:`GitHub`,bitbucket:`Bitbucket`},Au=3,ju=({title:e,action:t,empty:n,items:r,nowMs:i,startingUrl:a,onOpen:o})=>{let s=(0,H.useId)();return(0,G.jsxs)(`section`,{className:`pr-list`,"aria-labelledby":s,children:[(0,G.jsxs)(`div`,{className:`pr-list-header`,children:[(0,G.jsx)(`h2`,{id:s,children:e}),t]}),r===null?(0,G.jsx)(`ul`,{className:`pr-rows`,"aria-busy":`true`,"aria-label":`Loading ${e.toLowerCase()}`,children:Array.from({length:Au},(e,t)=>(0,G.jsx)(`li`,{className:`pr-row skeleton`},t))}):r.length===0?(0,G.jsx)(`p`,{className:`empty`,children:n}):(0,G.jsx)(`ul`,{className:`pr-rows`,children:r.map(e=>{let{repo:t,number:n}=e.ref;return(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{type:`button`,className:`pr-row`,"data-pr-row":``,"aria-busy":a===e.url,onClick:()=>o(e.url),children:[(0,G.jsx)(`span`,{className:`pr-host`,children:ku[t.host]}),(0,G.jsxs)(`span`,{className:`pr-repo`,children:[t.owner,`/`,t.repo,` #`,n]}),(0,G.jsx)(`span`,{className:`pr-title`,children:e.title}),(0,G.jsx)(`span`,{className:`pr-meta`,children:a===e.url?`Starting…`:(0,G.jsxs)(G.Fragment,{children:[e.author.name,` ·`,` `,(0,G.jsx)(`time`,{dateTime:e.updatedAt,children:Du(e.updatedAt,i)})]})})]})},e.url)})})]})},Mu=(e,t,n,r)=>t.configured?t.user===null?{name:e,state:`error`,text:t.error??`Couldn't read the signed-in user`}:{name:e,state:`ok`,text:t.user.name}:{name:e,state:n?`optional`:`missing`,text:`Not configured: ${r}`},Nu=e=>{let{github:t,bitbucket:n}=e.hosts;return[Mu(`GitHub`,t,n.configured,`set GITHUB_TOKEN or run gh auth login`),Mu(`Bitbucket`,n,t.configured,`set BITBUCKET_EMAIL and BITBUCKET_API_TOKEN`),e.jira.configured?{name:`Jira`,state:`ok`,text:`Configured`}:{name:`Jira`,state:`optional`,text:`Not configured: set JIRA_BASE_URL, JIRA_EMAIL and JIRA_API_TOKEN to read linked tickets`},e.model.enabled?{name:`Claude`,state:`ok`,text:`On`}:{name:`Claude`,state:`optional`,text:`Off: start megareviewer with --ai to add intent, decisions and a guided tour from Claude`}]},Pu=({status:e})=>(0,G.jsx)(`section`,{className:`setup`,"aria-label":`Setup`,children:(0,G.jsx)(`dl`,{className:`setup-items`,children:Nu(e).map(e=>(0,G.jsxs)(`div`,{className:`setup-item state-${e.state}`,children:[(0,G.jsx)(`dt`,{children:e.name}),(0,G.jsx)(`dd`,{children:e.text})]},e.name))})}),Fu=_u({code:`unsupported-url`,message:``}),Iu=({inputRef:e,pending:t,error:n,onSubmit:r})=>{let[i,a]=(0,H.useState)(``),[o,s]=(0,H.useState)(null),c=(0,H.useId)(),l=i.trim()===``,u=!l&&Ml(i).ok,d=n!==null&&o===i?_u(n):null,f=l||u?d:Fu;return(0,G.jsxs)(`form`,{className:`url-form`,onSubmit:e=>{e.preventDefault(),u&&!t&&(s(i),r(i.trim()))},noValidate:!0,children:[(0,G.jsx)(`label`,{htmlFor:`${c}-url`,children:`Pull request URL`}),(0,G.jsxs)(`div`,{className:`url-form-row`,children:[(0,G.jsx)(`input`,{ref:e,id:`${c}-url`,className:`input`,type:`url`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:`https://github.com/owner/repo/pull/123`,value:i,onChange:e=>a(e.target.value),"aria-invalid":!l&&!u,"aria-describedby":`${c}-hint`}),(0,G.jsx)(`button`,{type:`submit`,className:`button primary`,disabled:!u||t,children:t?`Starting…`:`Analyze`})]}),(0,G.jsx)(`p`,{id:`${c}-hint`,className:f===null?`hint`:`hint field-error`,role:`status`,children:f??(0,G.jsxs)(G.Fragment,{children:[`Paste a GitHub or Bitbucket Cloud pull request link. Press `,(0,G.jsx)(`kbd`,{children:`/`}),` to focus.`]})})]})},Lu=e=>e instanceof HTMLElement&&(e.isContentEditable||[`INPUT`,`TEXTAREA`,`SELECT`].includes(e.tagName)),Ru=({status:e,now:t=Date.now})=>{let{client:n}=cu(),{pullRequests:r,error:i,loading:a,refresh:o}=fu(),s=mu(n.startAnalysis),[c,l]=(0,H.useState)(null),u=(0,H.useRef)(null),d=(0,H.useRef)(null);(0,H.useEffect)(()=>{let e=e=>{e.key!==`/`||e.metaKey||e.ctrlKey||e.altKey||Lu(e.target)||(e.preventDefault(),u.current?.focus())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[]);let f=async(e,t)=>{if(s.pending)return;l(t);let n=await s.run({url:e});n.ok&&wu(xu(n.value.analysisId))},p=e=>{if(e.key!==`ArrowDown`&&e.key!==`ArrowUp`)return;let t=[...d.current?.querySelectorAll(`[data-pr-row]`)??[]],n=e.target instanceof HTMLElement?t.indexOf(e.target):-1;n!==-1&&(e.preventDefault(),t[n+(e.key===`ArrowDown`?1:-1)]?.focus())},m=r?.items??null,h=s.pending&&c?.from===`row`?c.url:null,g=t();return(0,G.jsxs)(`div`,{className:`picker`,children:[(0,G.jsxs)(`section`,{className:`analyze`,"aria-labelledby":`analyze-heading`,children:[(0,G.jsx)(`h1`,{id:`analyze-heading`,children:`Review a pull request`}),(0,G.jsx)(Iu,{inputRef:u,pending:s.pending&&c?.from===`form`,error:c?.from===`form`?s.error:null,onSubmit:e=>void f(e,{from:`form`})})]}),e!==null&&(0,G.jsx)(Pu,{status:e}),(0,G.jsxs)(`div`,{className:`pr-lists`,ref:d,onKeyDown:p,children:[i!==null&&(0,G.jsxs)(`p`,{className:`banner danger`,role:`alert`,children:[`Couldn't list pull requests. `,_u(i)]}),r?.errors.map(e=>(0,G.jsxs)(`p`,{className:`banner danger`,role:`alert`,children:[`Couldn't list `,ku[e.host],` pull requests: `,e.message]},e.host)),c?.from===`row`&&s.error!==null&&(0,G.jsxs)(`p`,{className:`banner danger`,role:`alert`,children:[`Couldn't start the analysis. `,_u(s.error)]}),(0,G.jsx)(ju,{title:`Waiting for your review`,empty:`Nothing is waiting for your review.`,action:(0,G.jsx)(`button`,{type:`button`,className:`button`,onClick:o,disabled:a,children:a?`Refreshing…`:`Refresh`}),items:m?.filter(e=>e.role===`reviewer`)??null,nowMs:g,startingUrl:h,onOpen:e=>void f(e,{from:`row`,url:e})}),(0,G.jsx)(ju,{title:`Your pull requests`,empty:`You have no open pull requests.`,items:m?.filter(e=>e.role===`author`)??null,nowMs:g,startingUrl:h,onOpen:e=>void f(e,{from:`row`,url:e})})]})]})},zu=({to:e,onClick:t,...n})=>(0,G.jsx)(`a`,{href:e,onClick:n=>{t?.(n);let r=n.metaKey||n.ctrlKey||n.shiftKey||n.altKey;n.defaultPrevented||n.button!==0||r||(n.preventDefault(),wu(e))},...n}),Bu=/[\p{L}\p{N}_]+|\s+|[^\p{L}\p{N}_\s]/gu,Vu=e=>e.match(Bu)??[],Hu=e=>{let t=new Map,n=0;for(;n<e.length;){if(e[n]?.kind!==`del`){n++;continue}let r=n;for(;e[n]?.kind===`del`;)n++;let i=n;for(;e[n]?.kind===`add`;)n++;let a=Math.min(i-r,n-i);for(let n=0;n<a;n++){let a=Uu(e[r+n]?.text??``,e[i+n]?.text??``);a!==null&&(t.set(r+n,a.old),t.set(i+n,a.new))}}return t},Uu=(e,t)=>{if(e.length>500||t.length>500)return null;let n=Vu(e),r=Vu(t),{inOld:i,inNew:a}=Gu(n,r),o=n.reduce((e,t,n)=>e+(i[n]?t.length:0),0),s=e.length+t.length;return s>0&&2*o/s<.3?null:{old:Wu(n,i),new:Wu(r,a)}},Wu=(e,t)=>{let n=[],r=0;return e.forEach((e,i)=>{let a=r+e.length;if(!t[i]){let e=n.at(-1);e?.end===r?n[n.length-1]={start:e.start,end:a}:n.push({start:r,end:a})}r=a}),n},Gu=(e,t)=>{let n=e.map(()=>!1),r=t.map(()=>!1),i=new Map([[1,0]]),a=[],o=(e,t)=>a[e]?.[t+e+1]??0,s=0;search:for(let n=0;n<=e.length+t.length;n++){let r=new Int32Array(2*n+3);for(let e=-n-1;e<=n+1;e++)r[e+n+1]=i.get(e)??0;a.push(r);for(let r=-n;r<=n;r+=2){let a=r===-n||r!==n&&(i.get(r-1)??0)<(i.get(r+1)??0)?i.get(r+1)??0:(i.get(r-1)??0)+1,o=a-r;for(;a<e.length&&o<t.length&&e[a]===t[o];)a++,o++;if(i.set(r,a),a>=e.length&&o>=t.length){s=n;break search}}}let c=e.length,l=t.length;for(let e=s;e>=0;e--){let t=c-l,i=t===-e||t!==e&&o(e,t-1)<o(e,t+1)?t+1:t-1,a=o(e,i),s=a-i;for(;c>a&&l>s;)c--,l--,n[c]=!0,r[l]=!0;c=a,l=s}return{inOld:n,inNew:r}},Ku=e=>{let t=e.map(e=>e.text.endsWith(`\r`)),n=t.includes(!0)&&t.includes(!1);return e.map((e,r)=>({line:e,text:t[r]?e.text.slice(0,-1):e.text,carriageReturn:n&&t[r]===!0}))},qu=e=>({added:e.lines.filter(e=>e.kind===`add`).length,deleted:e.lines.filter(e=>e.kind===`del`).length}),Ju=(e,t)=>t<=1?`${e}`:`${e}–${e+t-1}`,Yu=e=>e.newLines>0?`lines ${Ju(e.newStart,e.newLines)}`:`deleted lines ${Ju(e.oldStart,e.oldLines)}`,Xu=({risk:e})=>{let t=(0,H.useId)();return(0,G.jsxs)(`span`,{className:`risk`,children:[(0,G.jsx)(`button`,{type:`button`,className:`risk-badge risk-${e.riskClass}`,"aria-describedby":t,children:e.riskClass}),(0,G.jsx)(`span`,{role:`tooltip`,id:t,className:`risk-reason`,children:e.reason})]})},Zu=e=>e===``?[]:[{text:e,light:null,dark:null,italic:!1,bold:!1}],Qu=(e,t,n=[])=>{let r=[],i=0;for(let a of e){let e=i+a.text.length,o=new Set([i,e]);for(let r of[...t,...n])r.start>i&&r.start<e&&o.add(r.start),r.end>i&&r.end<e&&o.add(r.end);let s=[...o].sort((e,t)=>e-t);for(let n=0;n+1<s.length;n++){let o=s[n]??i,c=s[n+1]??e;r.push({...a,text:a.text.slice(o-i,c-i),changed:t.some(e=>e.start<=o&&c<=e.end)})}i=e}return r},$u=`modulepreload`,K=function(e){return`/`+e},q={},J=function(e){return e.pathname.endsWith(`.css`)},Y=function(e,t,n){if(t in e)return e[t];let r=n();if(!r){e[t]=void 0;return}let i=r.then(()=>{e[t]=void 0},n=>{throw e[t]=void 0,n});return e[t]=i,i},X=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=K(t,n);let r=s(t),i=J(r);return Y(q,r.href,()=>{if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let t=document.createElement(`link`);if(t.rel=i?`stylesheet`:$u,i||(t.as=`script`),t.crossOrigin=``,t.href=r.href,a&&t.setAttribute(`nonce`,a),document.head.appendChild(t),i)return new Promise((e,n)=>{t.addEventListener(`load`,e),t.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${r}`)))})})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},ed={c:()=>X(()=>import(`./c-Cz4nF6n_.js`),__vite__mapDeps([0,1])),cpp:()=>X(()=>import(`./cpp-DzjeI0uH.js`),__vite__mapDeps([2,3,1])),csharp:()=>X(()=>import(`./csharp-dmMxLVLW.js`),[]),css:()=>X(()=>import(`./css-DgaLhXQH.js`),__vite__mapDeps([4,5])),diff:()=>X(()=>import(`./diff-woXpYk--.js`),[]),docker:()=>X(()=>import(`./docker-IyjqRm3v.js`),[]),go:()=>X(()=>import(`./go-rLFTqkRN.js`),[]),graphql:()=>X(()=>import(`./graphql-BHtseKAV.js`),__vite__mapDeps([6,7,8,9,10,11])),html:()=>X(()=>import(`./html-BWDvXlHg.js`),__vite__mapDeps([12,13,5,8])),ini:()=>X(()=>import(`./ini-B5eOa1yu.js`),[]),java:()=>X(()=>import(`./java-_ATy9zCa.js`),__vite__mapDeps([14,15])),javascript:()=>X(()=>import(`./javascript-CpIGwZ_Y.js`),__vite__mapDeps([16,8])),json:()=>X(()=>import(`./json-C3WlssX3.js`),__vite__mapDeps([17,18])),jsonc:()=>X(()=>import(`./jsonc-CYpm1nAK.js`),[]),jsx:()=>X(()=>import(`./jsx-C4yDKi0A.js`),__vite__mapDeps([19,10])),kotlin:()=>X(()=>import(`./kotlin-DhhofPvG.js`),[]),make:()=>X(()=>import(`./make-Dixweg8N.js`),[]),markdown:()=>X(()=>import(`./markdown-BYOwaDjH.js`),[]),php:()=>X(()=>import(`./php-CUj1wjLQ.js`),__vite__mapDeps([20,5,8,13,18,21,15,22])),python:()=>X(()=>import(`./python-gzcpVVnB.js`),[]),ruby:()=>X(()=>import(`./ruby-DAHFNlv9.js`),__vite__mapDeps([23,1,3,5,8,7,9,10,11,13,21,15,22,24,25])),rust:()=>X(()=>import(`./rust-DpiIf5JO.js`),[]),scss:()=>X(()=>import(`./scss-8bKmll0B.js`),__vite__mapDeps([26,5])),shellscript:()=>X(()=>import(`./shellscript-CVTB3cr6.js`),__vite__mapDeps([27,24])),sql:()=>X(()=>import(`./sql-CfM2IJm3.js`),__vite__mapDeps([28,22])),svelte:()=>X(()=>import(`./svelte-DAcAPYhA.js`),__vite__mapDeps([29,5,8,9])),swift:()=>X(()=>import(`./swift-CyEgAFGc.js`),[]),toml:()=>X(()=>import(`./toml-CcmNWLt0.js`),[]),tsx:()=>X(()=>import(`./tsx-CGosfAUg.js`),__vite__mapDeps([30,11])),typescript:()=>X(()=>import(`./typescript-Bb1J8qyy.js`),__vite__mapDeps([31,9])),vue:()=>X(()=>import(`./vue-DfeOw4hL.js`),__vite__mapDeps([32,5,8,9,13,18])),xml:()=>X(()=>import(`./xml-DuKfbPI6.js`),__vite__mapDeps([33,21,15])),yaml:()=>X(()=>import(`./yaml-DDA_XMNu.js`),__vite__mapDeps([34,25]))},td={c_sharp:`csharp`},nd={bash:`shellscript`,c:`c`,cc:`cpp`,cjs:`javascript`,cpp:`cpp`,cs:`csharp`,css:`css`,cts:`typescript`,cxx:`cpp`,diff:`diff`,go:`go`,gql:`graphql`,graphql:`graphql`,h:`c`,hh:`cpp`,hpp:`cpp`,htm:`html`,html:`html`,ini:`ini`,java:`java`,js:`javascript`,json:`json`,jsonc:`jsonc`,jsx:`jsx`,kt:`kotlin`,kts:`kotlin`,md:`markdown`,mjs:`javascript`,mts:`typescript`,patch:`diff`,php:`php`,py:`python`,pyi:`python`,rb:`ruby`,rs:`rust`,scss:`scss`,sh:`shellscript`,sql:`sql`,svelte:`svelte`,swift:`swift`,toml:`toml`,ts:`typescript`,tsx:`tsx`,vue:`vue`,xml:`xml`,yaml:`yaml`,yml:`yaml`,zsh:`shellscript`},rd={Dockerfile:`docker`,GNUmakefile:`make`,Makefile:`make`},id=e=>{let t=e.language===null?null:td[e.language]??e.language;if(t!==null&&t in ed)return t;let n=e.path.slice(e.path.lastIndexOf(`/`)+1),r=n.lastIndexOf(`.`),i=r>0?n.slice(r+1).toLowerCase():``;return rd[n]??nd[i]??null},ad=e=>({old:od(e,`add`),new:od(e,`del`)}),od=(e,t)=>e.filter(({line:e})=>e.kind!==t).map(({text:e})=>e).join(`
65
- `),sd=(e,t,n)=>{let r=0,i=0;return e.map(({line:e,text:a})=>{let o=e.kind===`del`?t?.[r]:n?.[i];return e.kind!==`add`&&r++,e.kind!==`del`&&i++,o!==void 0&&o.map(e=>e.text).join(``)===a?o:Zu(a)})},cd=1e3,ld={light:`github-light-default`,dark:`github-dark-default`},ud={"#6e7781":`#57606a`,"#8250df":`#6639ba`},dd=1,fd=2,pd=(e,t)=>{let n=[];for(let{content:r,variants:i}of e){let e=i.light?.color?.toLowerCase()??null,a=i.dark?.color?.toLowerCase()??null,o=e===t.light&&a===t.dark,s=i.light?.fontStyle??0,c={text:r,light:o||e===null?null:ud[e]??e,dark:o?null:a,italic:s>0&&(s&dd)!==0,bold:s>0&&(s&fd)!==0},l=n.at(-1);l!==void 0&&l.light===c.light&&l.dark===c.dark&&l.italic===c.italic&&l.bold===c.bold?n[n.length-1]={...l,text:l.text+c.text}:n.push(c)}return n},md=(0,H.createContext)((()=>{let e=null,t=new Map,n=async()=>{let[{createHighlighterCore:e},{createJavaScriptRegexEngine:t}]=await Promise.all([X(()=>import(`./core-B1-dUh-r.js`),[]),X(()=>import(`./engine-javascript-D-6se_EF.js`),[])]);return e({themes:[X(()=>import(`./github-light-default-BXViO-2h.js`),[]),X(()=>import(`./github-dark-default-DXG-b-1a.js`),[])],langs:[],engine:t()})},r=(e,n)=>{let r=t.get(n)??(async()=>{let t=ed[n];return t!==void 0&&(await e.loadLanguage(...(await t()).default),!0)})();return t.set(n,r),r};return{highlight:async(i,a)=>{if(!(a in ed))return null;try{e??=n();let t=await e;if(!await r(t,a))return null;let o={light:t.getTheme(ld.light).fg.toLowerCase(),dark:t.getTheme(ld.dark).fg.toLowerCase()};return t.codeToTokensWithThemes(i,{lang:a,themes:ld,tokenizeMaxLineLength:cd}).map(e=>pd(e,o))}catch{return e=null,t.delete(a),null}}}})()),hd=new WeakMap,gd=(e,t,n)=>{let r=hd.get(e)??new Map;hd.set(e,r);let i=`${n}\0${t.id}\0${t.oldStart},${t.newStart},${t.lines.length}`,a=r.get(i);if(a!==void 0)return a;let o=Ku(t.lines),s=ad(o),c=o.some(({line:e})=>e.kind!==`add`),l=o.some(({line:e})=>e.kind!==`del`),u=(t,r)=>r?e.highlight(t,n):Promise.resolve(null),d={promise:Promise.all([u(s.old,c),u(s.new,l)]).then(([e,t])=>{let n=sd(o,e,t);return d.value=n,n}),value:null};return r.set(i,d),d},_d=`1200px 0px`,vd=null,yd=new Map,bd=(e,t)=>(vd??=new IntersectionObserver(e=>{for(let t of e)t.isIntersecting&&(yd.get(t.target)?.(),yd.delete(t.target),vd?.unobserve(t.target))},{rootMargin:_d}),yd.set(e,t),vd.observe(e),()=>{yd.delete(e),vd?.unobserve(e)}),xd=e=>{let[t,n]=(0,H.useState)(()=>typeof IntersectionObserver>`u`);return(0,H.useEffect)(()=>{let r=e.current;if(!(t||r===null))return bd(r,()=>n(!0))},[e,t]),t},Sd=(e,t,n=!0)=>{let r=(0,H.useContext)(md),i=id(t),a=i===null||!n?null:gd(r,e,i),[o,s]=(0,H.useState)();return(0,H.useEffect)(()=>{if(a===null||a.value!==null)return;let e=!0;return a.promise.then(t=>{e&&s({entry:a,tokens:t})}),()=>{e=!1}},[a]),a?.value??(o?.entry===a?o.tokens:null)},Cd={context:` `,add:`+`,del:`-`},wd=20,Td=({status:e})=>(0,G.jsx)(`span`,{className:`file-status status-${e}`,children:e}),Ed=({file:e})=>(0,G.jsx)(`span`,{className:`file-path`,children:e.oldPath!==null&&e.oldPath!==e.path?(0,G.jsxs)(G.Fragment,{children:[e.oldPath,` `,(0,G.jsx)(`span`,{"aria-hidden":`true`,children:`→`}),(0,G.jsx)(`span`,{className:`visually-hidden`,children:`renamed to`}),` `,e.path]}):e.path}),Dd=e=>{let t=e.map(e=>e.split(`/`));return t.map(e=>{for(let n=1;n<e.length;n++){let r=e.slice(-n).join(`/`);if(t.filter(e=>e.slice(-n).join(`/`)===r).length<=1)return r}return e.join(`/`)})},Od=e=>e.flatMap((t,n)=>[n===0?``:n===e.length-1?` and `:`, `,t]),kd=({callers:e,onFollow:t})=>{let[n,r]=(0,H.useState)(!1),i=Dd(e.map(e=>e.path)),a=(e,n)=>(0,G.jsxs)(`button`,{type:`button`,className:`hunk-link`,title:e.path,onClick:()=>t(e.partId),children:[i[n],` ↑`]},e.path),o=e.flatMap((e,t)=>e.test?[]:[a(e,t)]),s=e.flatMap((e,t)=>e.test?[a(e,t)]:[]),c=(0,G.jsx)(`button`,{type:`button`,className:`link-button`,"aria-expanded":!1,onClick:()=>r(!0),children:s.length===1?`1 test`:`${s.length} tests`},`tests`),l=[...o,...s.length===0?[]:n?s:[c]];return(0,G.jsxs)(`p`,{className:`hunk-callers`,children:[(0,G.jsx)(`span`,{className:`hunk-callers-label`,children:`Called from`}),` `,Od(l)]})},Ad=(e,t)=>`${e} ${t}${e===1?``:`s`}`,jd=({callers:e,named:t})=>{let[n,r]=(0,H.useState)(!1),i=(0,H.useId)(),{uses:a,more:o}=e,s=a.filter(e=>kc(e.path)).length,c=a.length-s,l=`${[...c>0?[Ad(c,`place`)]:[],...s>0?[Ad(s,`test`)]:[]].join(` and `)}${o>0?`, and ${o} more`:``}`;return(0,G.jsxs)(`div`,{className:`hunk-unchanged`,children:[(0,G.jsx)(`p`,{className:`hunk-outside`,children:(0,G.jsxs)(`button`,{type:`button`,className:`link-button`,"aria-expanded":n,"aria-controls":i,onClick:()=>r(!n),children:[t&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`code`,{children:e.symbol}),` `]}),t?`used`:`Used`,` unchanged in `,l]})}),n&&(0,G.jsxs)(`ul`,{id:i,className:`unchanged-uses`,children:[a.map(e=>(0,G.jsxs)(`li`,{children:[(0,G.jsxs)(`p`,{className:`unchanged-place`,children:[(0,G.jsx)(`span`,{className:`unchanged-path`,children:e.path}),`:`,e.line,e.use===`type`&&(0,G.jsx)(`span`,{className:`unchanged-kind`,children:` type`})]}),(0,G.jsx)(`pre`,{className:`unchanged-excerpt`,children:e.excerpt.lines.map((t,n)=>{let r=e.excerpt.start+n;return(0,G.jsxs)(`span`,{className:r===e.line?`unchanged-line used`:`unchanged-line`,children:[(0,G.jsx)(`span`,{className:`unchanged-number`,children:r}),t]},r)})})]},`${e.path}:${e.line}`)),o>0&&(0,G.jsxs)(`li`,{className:`muted`,children:[`and `,o,` more`]})]})]})},Md=e=>e.length<=1?e.join(``):`${e.slice(0,-1).join(`, `)} and ${e.at(-1)}`,Nd=({names:e})=>e.length===0?null:(0,G.jsxs)(G.Fragment,{children:[Od(e.map(e=>(0,G.jsx)(`code`,{children:e},e))),` · `]}),Pd=({part:e})=>(0,G.jsxs)(`span`,{className:`hunk-part`,children:[(0,G.jsx)(Nd,{names:e.definitions}),`part `,e.n,` of `,e.of,e.elsewhere.length>0&&` · rest of this hunk in ${e.elsewhere.length===1?`step`:`steps`} ${Md(e.elsewhere.map(String))}`]}),Fd=({neighbor:e,of:t,direction:n,onFollow:r})=>(0,G.jsxs)(`button`,{type:`button`,className:`part-fold ${n}`,disabled:r===void 0,onClick:()=>r?.(e.id),children:[(0,G.jsx)(`span`,{"aria-hidden":`true`,children:n===`previous`?`↑`:`↓`}),` `,(0,G.jsx)(Nd,{names:e.definitions}),`part `,e.n,` of `,t,e.step===null?``:` · step ${e.step}`]}),Id=e=>e.kind===`del`?e.oldLine===null?null:{side:`old`,line:e.oldLine}:e.newLine===null?null:{side:`new`,line:e.newLine},Ld=(e,t)=>e.side===t.side&&e.line===t.line,Rd=(0,H.memo)(function({id:e,part:t,hunk:n,file:r,risk:i,proofs:a=[],highlighted:o=!1,focused:s=!1,onFocus:c,lineLimit:l,callers:u=[],unchanged:d=[],onFollow:f,reviewed:p,onReviewed:m,comments:h=[],openComment:g=null,onOpenComment:_,onComment:v,afterHeader:y,belowLine:b,inLine:x}){let S=e??n.id,ee=(0,H.useRef)(null),[te,C]=(0,H.useState)(!1),w=(0,H.useMemo)(()=>Ku(n.lines),[n]),T=(0,H.useMemo)(()=>Hu(w.map(({line:e,text:t})=>({kind:e.kind,text:t}))),[w]),ne=Sd(n,r,xd(ee)),re=l===void 0||te||w.length<=l?w:w.slice(0,l);(0,H.useEffect)(()=>{let e=ee.current;s&&e!==null&&!e.contains(document.activeElement)&&(e.focus({preventScroll:!0}),e.scrollIntoView({block:`start`}))},[s]);let ie=qu(n),ae=[`hunk-card`,o&&`highlighted`,i&&`risk-${i.riskClass}`];return(0,G.jsxs)(`section`,{ref:ee,className:ae.filter(Boolean).join(` `),"aria-label":`${r.path}, ${Yu(n)}`,tabIndex:0,onFocus:()=>c?.(S),children:[(0,G.jsxs)(`header`,{className:`hunk-header`,children:[(0,G.jsx)(Ed,{file:r}),(0,G.jsx)(Td,{status:r.status}),t==null?n.sectionHeading!==null&&(0,G.jsx)(`code`,{className:`hunk-heading`,children:n.sectionHeading}):(0,G.jsx)(Pd,{part:t}),(0,G.jsxs)(`span`,{className:`hunk-counts`,children:[(0,G.jsxs)(`span`,{className:`count-added`,children:[`+`,ie.added]}),` `,(0,G.jsxs)(`span`,{className:`count-deleted`,children:[`−`,ie.deleted]})]}),a.map(e=>(0,G.jsxs)(`span`,{className:`hunk-proof`,title:`Mechanical proof`,children:[`✓ `,e.detail]},e.kind)),i?.riskClass===`contract`&&(0,G.jsx)(`span`,{className:`hunk-contract-reason model-text`,children:i.reason}),i!==null&&(0,G.jsx)(Xu,{risk:i}),m!==void 0&&(0,G.jsxs)(`label`,{className:`hunk-reviewed`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:p===!0,onChange:e=>m(S,e.target.checked)}),`Reviewed`]})]}),u.length>0&&f!==void 0&&(0,G.jsx)(kd,{callers:u,onFollow:f}),d.map(e=>(0,G.jsx)(jd,{callers:e,named:d.length>1},e.symbol)),y,t?.previous!=null&&(0,G.jsx)(Fd,{neighbor:t.previous,of:t.of,direction:`previous`,onFollow:f}),(0,G.jsx)(`div`,{className:`hunk-body`,style:{containIntrinsicSize:`auto ${re.length*wd}px`},children:(0,G.jsxs)(`table`,{className:`diff-table`,children:[(0,G.jsx)(`thead`,{className:`visually-hidden`,children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{scope:`col`,children:`Old line`}),(0,G.jsx)(`th`,{scope:`col`,children:`New line`}),(0,G.jsx)(`th`,{scope:`col`,children:`Change`}),(0,G.jsx)(`th`,{scope:`col`,children:`Code`})]})}),(0,G.jsx)(`tbody`,{children:re.map((e,t)=>{let n=Id(e.line),r=n===null?void 0:h.find(e=>Ld(e,n)),i=n!==null&&g!==null&&Ld(g,n),a=e.line.kind===`del`?null:e.line.newLine,o=a===null?void 0:b?.get(a);return(0,G.jsxs)(H.Fragment,{children:[(0,G.jsx)(Bd,{line:e,tokens:ne?.[t]??null,changed:T.get(t)??null,marks:a===null?void 0:x?.get(a),onNumber:n===null||_===void 0||v===void 0?void 0:()=>_(S,n)}),n!==null&&(r!==void 0||i)&&(0,G.jsx)(zd,{place:n,body:r?.body??``,focus:i,onChange:v===void 0?void 0:e=>v(S,{...n,body:e}),onDone:()=>_?.(S,null)}),o!==void 0&&(0,G.jsx)(`tr`,{className:`line-below`,children:(0,G.jsx)(`td`,{colSpan:4,children:o})})]},t)})})]})}),re.length<w.length&&(0,G.jsxs)(`button`,{type:`button`,className:`button show-all`,onClick:()=>C(!0),children:[`Show all `,w.length,` lines`]}),t?.next!=null&&(0,G.jsx)(Fd,{neighbor:t.next,of:t.of,direction:`next`,onFollow:f})]})}),zd=({place:e,body:t,focus:n,onChange:r,onDone:i})=>{let a=(0,H.useRef)(null);(0,H.useEffect)(()=>{n&&a.current?.focus()},[n]);let o=`Comment on ${e.side===`old`?`old `:``}line ${e.line}`;return(0,G.jsx)(`tr`,{className:`line-comment`,children:(0,G.jsx)(`td`,{colSpan:4,children:r===void 0?(0,G.jsxs)(`p`,{className:`posted-text`,children:[(0,G.jsxs)(`span`,{className:`visually-hidden`,children:[o,`: `]}),t]}):(0,G.jsx)(`textarea`,{ref:a,className:`input`,rows:2,"aria-label":o,placeholder:`What should change here?`,value:t,onChange:e=>r(e.target.value),onBlur:i,onKeyDown:e=>{e.key===`Escape`&&(e.stopPropagation(),a.current?.blur())}})})})},Bd=(0,H.memo)(function({line:{line:e,text:t,carriageReturn:n},tokens:r,changed:i,marks:a=[],onNumber:o}){let s=e.kind===`del`?`del`:`ins`,c=(t,n)=>t!==null&&o!==void 0&&n===`old`==(e.kind===`del`)?(0,G.jsx)(`button`,{type:`button`,className:`line-number-button`,"aria-label":`Comment on ${n===`old`?`old `:``}line ${t}`,onClick:o,children:t}):t;return(0,G.jsxs)(`tr`,{className:`diff-line line-${e.kind}`,children:[(0,G.jsx)(`td`,{className:`line-number`,children:c(e.oldLine,`old`)}),(0,G.jsx)(`td`,{className:`line-number`,children:c(e.newLine,`new`)}),(0,G.jsx)(`td`,{className:`line-marker`,children:Cd[e.kind]}),(0,G.jsxs)(`td`,{className:`line-code`,children:[Vd(Qu(r??Zu(t),i??[],a),a,s),n&&(0,G.jsx)(`span`,{className:`line-note`,title:`This line ends in CRLF`,children:`CRLF`}),e.noNewlineAtEnd&&(0,G.jsx)(`span`,{className:`line-note`,children:`No newline at end of file`})]})]})}),Vd=(e,t,n)=>{let r=[],i=null,a=()=>{i!==null&&r.push((0,G.jsx)(H.Fragment,{children:i.mark.render(i.code)},`mark-${i.mark.start}`)),i=null},o=0;return e.forEach((e,s)=>{let c=o;o+=e.text.length;let l=[`token`,e.italic&&`italic`,e.bold&&`bold`,e.changed&&`changed`].filter(Boolean).join(` `),u=e.light===null&&e.dark===null?void 0:{"--token-light":e.light??void 0,"--token-dark":e.dark??void 0},d=e.changed?n:`span`,f=(0,G.jsx)(d,{className:l,style:u,children:e.text},s),p=t.find(e=>c>=e.start&&c<e.end);p===void 0?(a(),r.push(f)):i?.mark===p?i.code.push(f):(a(),i={mark:p,code:[f]})}),a(),r},Hd=(e,t)=>{let n=new Set,r=e=>{let r=t.filter(t=>!n.has(t)&&e(t));for(let e of r)n.add(e);return r},i=e.flatMap(e=>{let t=r(t=>t.path===e.path&&t.hunkId===null).map(t=>({key:`${e.path}\0${t.kind}`,path:e.path,file:e,hunk:null,proofs:[t],summary:Ud(t,e)})),n=e.hunks.flatMap(t=>{let n=r(e=>e.hunkId===t.id);if(n.length===0)return[];let{added:i,deleted:a}=qu(t),o=n.map(e=>e.detail).join(`; `);return[{key:t.id,path:e.path,file:e,hunk:t,proofs:n,summary:`${e.path} — ${o} (+${i} −${a})`}]});return[...t,...n]}),a=t.filter(e=>!n.has(e)).map((e,t)=>({key:`orphan-${t}`,path:e.path,file:null,hunk:null,proofs:[e],summary:`${e.path} — ${e.detail}`}));return[...i,...a]},Ud=(e,t)=>e.kind===`rename`&&t.oldPath!==null?`${t.oldPath} → ${t.path} — renamed, content unchanged`:`${t.path} — ${e.detail}`,Wd=({files:e,proofs:t,risk:n})=>{let r=(0,H.useId)(),i=(0,H.useMemo)(()=>Hd(e,t),[e,t]),[a,o]=(0,H.useState)(new Set),s=i.filter(e=>e.hunk!==null).map(e=>e.key),c=s.length>0&&s.every(e=>a.has(e));if(i.length===0)return null;let l=e=>o(t=>{let n=new Set(t);return n.delete(e)||n.add(e),n});return(0,G.jsxs)(`section`,{className:`mechanical-group`,"aria-labelledby":r,children:[(0,G.jsxs)(`div`,{className:`mechanical-header`,children:[(0,G.jsxs)(`h2`,{id:r,children:[`Mechanical changes `,(0,G.jsx)(`span`,{className:`mechanical-count`,children:i.length})]}),s.length>0&&(0,G.jsx)(`button`,{type:`button`,className:`button`,onClick:()=>o(new Set(c?[]:s)),children:c?`Collapse all`:`Expand all`})]}),(0,G.jsx)(`ul`,{className:`mechanical-rows`,children:i.map(e=>{let t=a.has(e.key);return(0,G.jsxs)(`li`,{className:`mechanical-row`,children:[e.hunk===null||e.file===null?(0,G.jsx)(`span`,{className:`mechanical-summary`,children:e.summary}):(0,G.jsx)(`button`,{type:`button`,className:`mechanical-summary mechanical-toggle`,"aria-expanded":t,onClick:()=>l(e.key),children:e.summary}),t&&e.hunk!==null&&e.file!==null&&(0,G.jsx)(Rd,{hunk:e.hunk,file:e.file,risk:n.find(t=>t.hunkId===e.hunk?.id)??null,proofs:e.proofs,lineLimit:500})]},e.key)})})]})},Gd=(0,H.memo)(function({hunk:e,file:t,risk:n,proofs:r,focused:i=!1,onFocus:a}){let o=(0,H.useRef)(null),[s,c]=(0,H.useState)(!1),{added:l,deleted:u}=qu(e);return(0,H.useEffect)(()=>{let e=o.current;i&&e!==null&&e!==document.activeElement&&(e.focus({preventScroll:!0}),e.scrollIntoView({block:`start`}))},[i]),(0,G.jsxs)(`div`,{className:`collapsed-hunk`,children:[(0,G.jsxs)(`button`,{ref:o,type:`button`,className:`mechanical-summary mechanical-toggle`,"aria-expanded":s,onClick:()=>c(e=>!e),onFocus:()=>a?.(e.id),children:[t.path,`, `,Yu(e),` — `,r.map(e=>e.detail).join(`; `),` (+`,l,` −`,u,`)`]}),s&&(0,G.jsx)(Rd,{hunk:e,file:t,risk:n,proofs:r,lineLimit:500})]})}),Kd={added:`added`,deleted:`deleted`,modified:`changed`,renamed:`changed`},qd=e=>e.flatMap(e=>{let t=e.oldMode!==null||e.newMode!==null,n=!e.binary&&!t&&e.hunks.length===0&&e.status!==`renamed`;return[...e.binary?[{key:`${e.path}\0binary`,file:e,text:`binary file ${Kd[e.status]}`}]:[],...t?[{key:`${e.path}\0mode`,file:e,text:`mode ${e.oldMode??`unknown`} → ${e.newMode??`unknown`}`}]:[],...n?[{key:`${e.path}\0empty`,file:e,text:e.status===`modified`?`changed, no lines to show`:`empty file ${e.status}`}]:[]]}),Jd=({files:e})=>{let t=(0,H.useId)(),n=qd(e);return n.length===0?null:(0,G.jsxs)(`section`,{className:`file-notices`,"aria-labelledby":t,children:[(0,G.jsx)(`h2`,{id:t,children:`Changes without lines to show`}),(0,G.jsx)(`ul`,{children:n.map(({key:e,file:t,text:n})=>(0,G.jsxs)(`li`,{className:`file-notice`,children:[(0,G.jsx)(Ed,{file:t}),(0,G.jsx)(Td,{status:t.status}),(0,G.jsx)(`span`,{children:n})]},e))})]})},Yd=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),Xd=(e,t)=>{if(t===``)return null;let n=RegExp(`(?<![\\w$])${Yd(t)}(?![\\w$])`).exec(e);return n===null?null:{start:n.index,end:n.index+t.length}},Zd=(e,t,n)=>{let r=new Map;for(let i of e){let e=new Set;for(let a of i){let i=t.get(a);if(i===void 0||r.has(a))continue;let o=new Map;for(let[t,r]of[...i].sort(([e],[t])=>e-t)){let i=new Map;for(let e of r)i.set(e.symbol,[...i.get(e.symbol)??[],e]);let s=[];for(let[r,o]of i){let i=o.some(t=>!e.has(t.toPartId));for(let t of o)e.add(t.toPartId);let c=n(a,t),l=i||c===void 0?null:Xd(c,r);s.push(l===null?{kind:`chip`,symbol:r,calls:o}:{kind:`mention`,symbol:r,calls:o,at:l})}o.set(t,s)}r.set(a,o)}}return r},Qd={api:`API`,data:`Data`,dependency:`Dependency`,security:`Security`,"error-handling":`Error handling`,performance:`Performance`,concurrency:`Concurrency`,configuration:`Configuration`,behavior:`Behavior`,other:`Other`},$d={waiting:``,saving:`Saving…`,saved:`Saved`,failed:`Not saved`},ef=e=>`decision-${e}`,tf=(0,H.memo)(function({decision:e,draft:t,status:n,selected:r,readOnly:i,commentRef:a,onSelect:o,onVerdict:s,onComment:c}){let l=(0,H.useId)(),u=n=>s(e.id,t.verdict===n?`pending`:n);return(0,G.jsxs)(`article`,{id:ef(e.id),className:`decision verdict-${t.verdict}${r?` selected`:``}`,"aria-labelledby":`${l}-title`,tabIndex:-1,onFocus:()=>o(e.id),children:[(0,G.jsxs)(`div`,{className:`decision-head`,children:[(0,G.jsx)(`span`,{className:`badge category`,children:Qd[e.category]}),(0,G.jsx)(`h3`,{id:`${l}-title`,className:`decision-title model-text`,children:e.title})]}),(0,G.jsx)(`p`,{className:`decision-why model-text`,children:e.whyItMatters}),(0,G.jsxs)(`div`,{className:`decision-controls`,children:[(0,G.jsxs)(`div`,{className:`verdict-buttons`,children:[(0,G.jsxs)(`button`,{type:`button`,className:`button verdict approve`,"aria-pressed":t.verdict===`approved`,"aria-label":`Approve: ${e.title}`,disabled:i,onClick:()=>u(`approved`),children:[(0,G.jsx)(`span`,{"aria-hidden":`true`,children:`✓`}),` Approve`]}),(0,G.jsxs)(`button`,{type:`button`,className:`button verdict reject`,"aria-pressed":t.verdict===`rejected`,"aria-label":`Reject: ${e.title}`,disabled:i,onClick:()=>u(`rejected`),children:[(0,G.jsx)(`span`,{"aria-hidden":`true`,children:`✗`}),` Reject`]})]}),(0,G.jsxs)(`label`,{className:`visually-hidden`,htmlFor:`${l}-comment`,children:[`Comment on: `,e.title]}),(0,G.jsx)(`textarea`,{id:`${l}-comment`,ref:r?a:void 0,className:`input comment`,rows:1,placeholder:i?``:`Comment (optional)`,value:t.comment,readOnly:i,onChange:t=>c(e.id,t.target.value)}),n!==null&&$d[n]!==``&&(0,G.jsx)(`span`,{className:`save-status ${n}`,role:`status`,children:$d[n]})]})]})}),nf=({decision:e,onGo:t})=>(0,G.jsxs)(`p`,{className:`decision-mention`,children:[`Decision:`,` `,(0,G.jsx)(`button`,{type:`button`,className:`link-button model-text`,onClick:()=>t(e.id),children:e.title})]}),rf=`a[href], button:not(:disabled), textarea:not(:disabled), input:not(:disabled), [tabindex]:not([tabindex="-1"])`,af=({title:e,onClose:t,children:n,className:r=``})=>{let i=(0,H.useId)(),a=(0,H.useRef)(null);return(0,H.useEffect)(()=>{let e=document.activeElement;return(a.current?.querySelector(`[data-autofocus]`)??a.current?.querySelector(rf))?.focus(),()=>{e instanceof HTMLElement&&e.focus()}},[]),(0,G.jsx)(`div`,{className:`dialog-backdrop`,children:(0,G.jsxs)(`div`,{ref:a,className:`dialog ${r}`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`${i}-title`,onKeyDown:e=>{if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),t();return}if(e.key!==`Tab`)return;let n=[...a.current?.querySelectorAll(rf)??[]],r=n[0],i=n.at(-1);r!==void 0&&i!==void 0&&(e.shiftKey&&document.activeElement===r?(e.preventDefault(),i.focus()):!e.shiftKey&&document.activeElement===i&&(e.preventDefault(),r.focus()))},children:[(0,G.jsxs)(`div`,{className:`dialog-header`,children:[(0,G.jsx)(`h2`,{id:`${i}-title`,children:e}),(0,G.jsx)(`button`,{type:`button`,className:`button quiet`,"aria-label":`Close`,onClick:t,children:`✕`})]}),n]})})},of=e=>`hunk-${e}`,sf=({id:e,deps:t,belowLine:n,inLine:r,focused:i=!1,nested:a=!1})=>{let[o]=t.index.items([e]);if(o===void 0)return null;let{hunk:s,file:c,risk:l,proofs:u=[]}=o;return u.length>0?(0,G.jsx)(Gd,{hunk:s,file:c,risk:l,proofs:u,focused:i,onFocus:a?void 0:t.onFocusHunk}):(0,G.jsx)(Rd,{id:e,part:t.partHeaderOf(e),hunk:s,file:c,risk:l,highlighted:t.highlighted.has(e),focused:i,onFocus:a?void 0:t.onFocusHunk,callers:a?void 0:t.callersOf(e),unchanged:a?void 0:t.unchangedOf(e),onFollow:t.onFollow,reviewed:t.reviewed.has(e),onReviewed:t.onReviewed,comments:t.commentsOf(e),openComment:!a&&t.openComment?.partId===e?t.openComment.place:null,onOpenComment:a?void 0:t.onOpenComment,onComment:a?void 0:t.onComment,afterHeader:a?void 0:t.decisionsOn(e),belowLine:n,inLine:r})},cf=({call:e,index:t})=>{let n=t.items([e.toPartId])[0],r=t.mechanical.has(e.toPartId)?`mechanical`:n?.risk.riskClass??`logic`;return(0,G.jsxs)(G.Fragment,{children:[e.request===!0&&(0,G.jsx)(`span`,{className:`call-kind`,children:`sends`}),e.request===!0&&` `,(0,G.jsx)(`code`,{className:`call-symbol`,children:e.symbol}),` `,(0,G.jsx)(`span`,{className:`call-file`,children:n?.file.path}),` `,(0,G.jsx)(`span`,{className:`call-risk risk-${r}`,children:r})]})},lf=/^#{1,6}\s+/,uf=e=>{let t=e.split(`
66
- `).map(e=>e.trim()).filter(e=>e!==``);return t.find(e=>!lf.test(e))??t[0]?.replace(lf,``)??``},df=({analysis:e,modelOn:t,mismatchAt:n,onMismatch:r,onDetails:i})=>{let{intent:a,pullRequest:o}=e,s=a?.mismatches??[],c=s.length===0?0:n%s.length,l=s[c],u=o===null?``:uf(o.description);return(0,G.jsxs)(`div`,{className:`intent-line`,children:[a===null?t&&e.status===`running`?(0,G.jsx)(`p`,{className:`intent-text muted`,"aria-busy":`true`,children:`Working out the intent…`}):o===null?null:(0,G.jsxs)(`p`,{className:`intent-text`,children:[(0,G.jsx)(`span`,{className:`intent-label`,children:`Asked:`}),` `,u===``?(0,G.jsx)(`span`,{className:`muted`,children:`The pull request has no description.`}):(0,G.jsx)(`span`,{className:`pr-description-line`,children:u})]}):(0,G.jsxs)(`p`,{className:`intent-text`,children:[(0,G.jsx)(`span`,{className:`intent-label${s.length===0?` agrees`:``}`,children:s.length>0||a.stated===null?`From the code:`:`✓ Does what was asked:`}),` `,(0,G.jsx)(`span`,{className:`model-text`,children:a.inferred.summary})]}),l!==void 0&&(0,G.jsxs)(`button`,{type:`button`,className:`mismatch-chip`,title:l.description,onClick:()=>r(c),children:[(0,G.jsx)(`span`,{"aria-hidden":`true`,children:`⚠`}),(0,G.jsx)(`span`,{className:`mismatch-chip-text model-text`,children:l.description}),(0,G.jsxs)(`span`,{className:`mismatch-chip-count`,children:[c+1,` of `,s.length]})]}),(a!==null||o!==null)&&(0,G.jsx)(`button`,{type:`button`,className:`button quiet details-button`,onClick:i,children:`Details`})]})},ff={description:`Description`,commits:`Commits`,branch:`Branch name`},pf={unrequested:`Unrequested`,missing:`Missing`,contradicts:`Contradicts`},Z=({ticketKey:e,ticket:t})=>t===void 0?(0,G.jsxs)(`li`,{className:`chip`,title:`Jira didn't return this ticket, or Jira isn't configured`,children:[e,` · not fetched`]}):(0,G.jsx)(`li`,{className:`chip`,children:(0,G.jsxs)(`a`,{href:t.url,target:`_blank`,rel:`noreferrer`,title:t.summary,children:[t.key,` · `,t.status]})}),mf=({stated:e,ticketOf:t,unfetched:n})=>(0,G.jsxs)(G.Fragment,{children:[e!==null&&(0,G.jsx)(`ul`,{className:`chips`,"aria-label":`Sources`,children:e.sources.map(e=>e.kind===`ticket`&&e.ref!==null?(0,G.jsx)(Z,{ticketKey:e.ref,ticket:t.get(e.ref)},`ticket:${e.ref}`):e.kind===`ticket`?null:(0,G.jsx)(`li`,{className:`chip`,children:ff[e.kind]},e.kind))}),n.length>0&&(0,G.jsx)(`ul`,{className:`chips`,"aria-label":`Tickets mentioned but not fetched`,children:n.map(e=>(0,G.jsx)(Z,{ticketKey:e,ticket:void 0},e))})]}),hf=`No stated intent: the PR has no description or linked tickets.`,gf=({intent:e,tickets:t,missingTicketKeys:n,onSelectMismatch:r})=>{let{stated:i,inferred:a,mismatches:o}=e,s=new Map(t.map(e=>[e.key,e])),c=new Set(i?.sources.flatMap(e=>e.ref??[])??[]),l=n.filter(e=>!c.has(e)),u=(0,G.jsx)(mf,{stated:i,ticketOf:s,unfetched:l}),d=o.length===0?i:null,{behaviorChanges:f}=a;return(0,G.jsxs)(`div`,{className:`intent-panel`,children:[o.length===0?(0,G.jsxs)(`div`,{className:`intent-line`,children:[(0,G.jsxs)(`p`,{children:[i===null?(0,G.jsx)(`span`,{className:`intent-label`,children:`From the code:`}):(0,G.jsx)(`span`,{className:`intent-label agrees`,children:`✓ Does what was asked:`}),` `,(0,G.jsx)(`span`,{className:`model-text`,children:a.summary})]}),i===null&&(0,G.jsx)(`p`,{className:`muted`,children:hf}),u]}):(0,G.jsxs)(`div`,{className:`intent-columns`,children:[(0,G.jsxs)(`div`,{className:`intent-column`,children:[(0,G.jsx)(`h3`,{children:`Stated`}),i===null?(0,G.jsx)(`p`,{className:`muted`,children:hf}):(0,G.jsx)(`p`,{className:`model-text`,children:i.summary}),u]}),(0,G.jsxs)(`div`,{className:`intent-column`,children:[(0,G.jsx)(`h3`,{children:`Inferred from the code`}),(0,G.jsx)(`p`,{className:`model-text`,children:a.summary})]}),(0,G.jsxs)(`div`,{className:`intent-column`,children:[(0,G.jsx)(`h3`,{children:`Mismatches`}),(0,G.jsx)(`ul`,{className:`mismatches`,children:o.map((e,t)=>(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{type:`button`,className:`mismatch`,onClick:()=>r(t),children:[(0,G.jsx)(`span`,{className:`badge mismatch-${e.kind}`,children:pf[e.kind]}),(0,G.jsx)(`span`,{className:`model-text`,children:e.description})]})},t))})]})]}),(d!==null||f.length>0)&&(0,G.jsxs)(`details`,{className:`intent-details`,children:[(0,G.jsxs)(`summary`,{children:[`Details`,f.length>0&&` (${f.length})`]}),d!==null&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`h3`,{children:`Asked`}),(0,G.jsx)(`p`,{className:`model-text`,children:d.summary})]}),f.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`h3`,{children:`Behavior changes`}),(0,G.jsx)(`ul`,{className:`behavior-changes`,children:f.map((e,t)=>(0,G.jsx)(`li`,{className:`model-text`,children:e},t))})]})]})]})},_f=[{group:`decisions`,title:`Decisions`},{group:`mismatches`,title:`Mismatches`},{group:`contract`,title:`Contract changes`},{group:`unchanged`,title:`Used unchanged`},{group:`routes`,title:`Routes`},{group:`symbols`,title:`Symbols`},{group:`steps`,title:`Steps`},{group:`files`,title:`Files`}],vf={"!":[`decisions`,`mismatches`,`contract`],"@":[`symbols`],"/":[`files`]},yf=e=>e.slice(e.lastIndexOf(`/`)+1),bf=8,xf=(e,t,n)=>{let r=e=>{let t=n.parts.get(e);return t===void 0?``:`${t.file.path}, ${Yu(t.hunk)}`},i=new Map;for(let t of e.callGraph){let e=n.parts.get(t.fromPartId);if(t.use!==`request`||e===void 0||!n.parts.has(t.toPartId))continue;let r=`route:${t.symbol}:${t.toPartId}`,a=i.get(r)??{route:t.toPartId,symbol:t.symbol,files:new Set};a.files.add(e.file.path),i.set(r,a)}let a=[...i].map(([e,{route:t,symbol:r,files:i}])=>({key:e,group:`routes`,label:r,detail:`${yf(n.parts.get(t)?.file.path??``)}, requested in ${[...i].sort((e,t)=>Number(kc(e))-Number(kc(t))).map(yf).join(`, `)}`,target:{kind:`hunk`,partId:t}})),o=new Map;for(let t of e.callGraph){if(t.use===`request`)continue;let e=`symbol:${t.symbol}:${t.toPartId}`;!o.has(e)&&n.parts.has(t.toPartId)&&o.set(e,{key:e,group:`symbols`,label:t.symbol,detail:r(t.toPartId),target:{kind:`hunk`,partId:t.toPartId}})}return[...e.decisions.map(e=>({key:`decision:${e.id}`,group:`decisions`,label:e.title,detail:Qd[e.category],target:{kind:`decision`,decisionId:e.id}})),...(e.intent?.mismatches??[]).map((e,t)=>({key:`mismatch:${t}`,group:`mismatches`,label:e.description,detail:e.kind,target:{kind:`mismatch`,index:t}})),...e.risk.flatMap(e=>{let[t]=e.riskClass===`contract`?n.partsOf(e.hunkId):[];return t===void 0?[]:[{key:`contract:${e.hunkId}`,group:`contract`,label:e.reason,detail:r(t),target:{kind:`hunk`,partId:t}}]}),...e.unchangedCallers.flatMap(({partId:e,symbol:t,uses:r,more:i})=>{let a=n.parts.get(e);if(a===void 0)return[];let o=[...new Set(r.map(e=>e.path))],s=r.length+i;return[{key:`unchanged:${t}:${e}`,group:`unchanged`,label:t,detail:`${yf(a.file.path)}, used unchanged in ${s===1?`1 place`:`${s} places`}: ${o.sort((e,t)=>Number(kc(e))-Number(kc(t))).map(yf).join(`, `)}`,target:{kind:`hunk`,partId:e}}]}),...a,...o.values(),...t.map((e,t)=>({key:`step:${e.id}`,group:`steps`,label:e.title,detail:e.codeTitle===null?`Step ${t+1}`:`Step ${t+1} · ${e.codeTitle}`,target:{kind:`step`,stepId:e.id}})),...[...e.files].sort((e,t)=>e.path<t.path?-1:+(e.path>t.path)).map(e=>{let t=e.hunks.find(e=>!n.mechanical.has(e.id))??e.hunks[0],r=t===void 0?void 0:n.partsOf(t.id)[0];return{key:`file:${e.path}`,group:`files`,label:e.path,detail:e.status,target:r===void 0?{kind:`mechanical`}:{kind:`hunk`,partId:r}}})]},Sf=(e,t)=>{let n=t.trimStart(),r=vf[n.charAt(0)],i=(r===void 0?n:n.slice(1)).toLowerCase().split(/\s+/).filter(Boolean);return _f.filter(({group:e})=>r===void 0||r.includes(e)).map(({group:t,title:n})=>({group:t,title:n,items:e.filter(e=>e.group===t).filter(e=>{let t=`${e.label} ${e.detail}`.toLowerCase();return i.every(e=>t.includes(e))}).slice(0,bf)})).filter(({items:e})=>e.length>0)},Cf=({items:e,onPick:t,onClose:n})=>{let[r,i]=(0,H.useState)(``),[a,o]=(0,H.useState)(0),s=(0,H.useMemo)(()=>Sf(e,r),[e,r]),c=s.flatMap(e=>e.items),l=Math.min(a,Math.max(c.length-1,0)),u=c[l];return(0,G.jsxs)(af,{title:`Jump to`,onClose:n,className:`jump-palette`,children:[(0,G.jsx)(`input`,{type:`search`,className:`input`,"aria-label":`Jump to`,placeholder:`A decision, function, step or file · ! findings · @ symbols · / files`,value:r,onChange:e=>{i(e.target.value),o(0)},onKeyDown:e=>{if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault();let t=e.key===`ArrowDown`?1:-1;o(Math.min(Math.max(l+t,0),Math.max(c.length-1,0)))}else e.key===`Enter`&&(e.preventDefault(),u!==void 0&&t(u.target))},"data-autofocus":!0}),c.length===0?(0,G.jsx)(`p`,{className:`muted`,children:`Nothing matches.`}):(0,G.jsx)(`div`,{className:`palette-results`,children:s.map(e=>(0,G.jsxs)(`section`,{"aria-label":e.title,children:[(0,G.jsx)(`h3`,{className:`palette-group`,children:e.title}),(0,G.jsx)(`ul`,{className:`palette-list`,children:e.items.map(e=>(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{type:`button`,className:`palette-item${e===u?` active`:``}`,"aria-current":e===u?`true`:void 0,onClick:()=>t(e.target),children:[(0,G.jsx)(`span`,{className:`palette-label model-text`,children:e.label}),(0,G.jsx)(`span`,{className:`palette-detail`,children:e.detail})]})},e.key))})]},e.group))})]})},wf=e=>e===`map`?`map`:e===`overview`||e===`tree`?`overview`:void 0,Tf=(e,t)=>e.path<t.path?-1:+(e.path>t.path),Ef=`Not classified yet.`,Df=e=>{let t=wc(e.parts),n=new Map,r=new Map;for(let i of e.files){for(let e of i.hunks){let n=t.get(e.id)??[],i=n.map(e=>e.id);r.set(e.id,n.length>0?i:[e.id])}for(let e of Tc(i,t)){let r=t.get(e.hunk.id)??[],a=r.findIndex(t=>t.id===e.id),o=r[a];n.set(e.id,{hunk:e.hunk,file:i,place:o===void 0?null:{n:a+1,of:r.length,definitions:o.definitions,siblings:r.map(e=>e.id)}})}}let i=new Map(e.risk.map(e=>[e.hunkId,e])),a=new Map;for(let t of e.proofs)t.hunkId!==null&&a.set(t.hunkId,[...a.get(t.hunkId)??[],t]);let o=new Set(a.keys()),s=e=>{let t=Sc(e);return i.get(t)??{hunkId:t,riskClass:`logic`,reason:Ef,source:`fallback`}};return{parts:n,mechanical:o,items:e=>e.flatMap(e=>{let t=n.get(e);return t===void 0?[]:[{...t,id:e,hunkId:Sc(e),risk:s(e),proofs:a.get(e)??[]}]}),partsOf:e=>r.get(e)??[]}},Of=(e,t)=>[...e.files].sort(Tf).flatMap(e=>e.hunks.flatMap(e=>t.partsOf(e.id))).filter(e=>!t.mechanical.has(e)),kf=(e,t)=>{let n=e.tour?.steps??[],r=new Set(n.flatMap(e=>e.partIds)),i=Of(e,t).filter(e=>!r.has(e));return i.length===0?n:[...n,{id:al.parse(`s${n.length+1}`),title:`Changes the tour left out`,explanation:`The tour didn't include these changes, so they're shown here in file order.`,partIds:i,kind:`supporting`,via:[],entries:[],codeTitle:null,merged:[]}]},Af=(e,t,n)=>e.tour===null?[{kind:`files`,partIds:If(Of(e,n),n)}]:t.map((e,t)=>({kind:`step`,step:e,number:t+1,partIds:If(e.partIds,n)})),jf=e=>e.kind===`step`?e.step.id:`files`,Mf=(e,t,n)=>{let r=new Map(t.map((e,t)=>[e,t])),i=new Map,a=new Map,o=new Map,s=[],c=(e,t,n)=>e.set(t,[...e.get(t)??[],n]);for(let t of e){let[e,...l]=[...new Set(t.hunkIds)].flatMap(n.partsOf).filter(e=>r.has(e)&&!n.mechanical.has(e)).sort((e,t)=>(r.get(e)??0)-(r.get(t)??0));if(e===void 0)s.push(t);else{c(i,e,t),o.set(t.id,e);for(let e of l)c(a,e,t)}}return{cards:i,mentions:a,cardHunk:o,unplaced:s}},Nf=(e,t)=>{let n=new Map;for(let{fromPartId:r,toPartId:i,symbol:a,line:o,use:s}of e){if(!t.parts.has(r)||!t.parts.has(i))continue;let e=n.get(r)??new Map,c=s===`request`?{symbol:a,toPartId:i,line:o,request:!0}:{symbol:a,toPartId:i,line:o};e.set(o,[...e.get(o)??[],c]),n.set(r,e)}return n},Pf=e=>Math.min(60,Math.max(12,e.lines.length)),Ff=e=>{let t=new Set,n=0;for(let r of e)r.hunkId===null?n+=1:t.add(r.hunkId);return t.size+n},If=(e,t)=>{let n=[],r=new Set(e),i=e=>t.parts.get(e)?.file,a=(e,n)=>{let i=n===null?e.hunks.length:e.hunks.findIndex(e=>e.id===Sc(n));return e.hunks.slice(0,i).map(e=>e.id).filter(e=>t.mechanical.has(e)&&!r.has(e))},o=new Map;for(let t of e){let e=i(t);if(e!==void 0){let i=a(e,t);for(let e of i)r.add(e);n.push(...i)}n.push(t),e!==void 0&&o.set(e,n.length)}for(let[e,t]of[...o].sort((e,t)=>t[1]-e[1])){let i=a(e,null);for(let e of i)r.add(e);n.splice(t,0,...i)}return n},Lf=(e,t)=>{let n={contract:0,logic:0,mechanical:0},r=e.files.flatMap(e=>e.hunks.map(e=>e.id));for(let e of t.items(r.flatMap(e=>t.partsOf(e).slice(0,1))))n[t.mechanical.has(e.hunk.id)?`mechanical`:e.risk.riskClass]+=1;return n.mechanical+=e.proofs.filter(e=>e.hunkId===null).length,n},Rf=(e,t)=>{let n=new Set([...t.parts].flatMap(([e,{file:n}])=>t.mechanical.has(e)?[]:[n.path]));return e.proofs.filter(e=>e.hunkId===null||!n.has(e.path))},zf=(e,t,n)=>{let r=new Map(n.map((e,t)=>[e,t])),i=e=>r.get(e)??n.length,a=new Map;for(let{fromPartId:n,toPartId:r}of e){let e=t.parts.get(n);if(e===void 0||!t.parts.has(r)||n===r)continue;let o=a.get(r)??new Map,s=o.get(e.file.path);(s===void 0||i(n)<i(s))&&o.set(e.file.path,n),a.set(r,o)}return new Map([...a].map(([e,t])=>[e,[...t].map(([e,t])=>({path:e,partId:t,test:kc(e)})).sort((e,t)=>Number(e.test)-Number(t.test)||i(e.partId)-i(t.partId))]))},Bf=(e,t)=>e.flatMap(e=>e.partIds).filter(e=>!t.mechanical.has(e)),Vf=(e,t)=>{let n=new Set(e),r=new Set;for(let[e,{place:i}]of t.parts)(n.has(e)||i!==null&&n.has(Sc(e)))&&r.add(e);return r},Q=(e,t,n,r)=>{let i=Sc(t),a=i!==t&&e.includes(i),o=a?r.partsOf(i).filter(e=>e!==t):[];return[...e.filter(e=>e!==t&&!(a&&e===i)),...o,...n?[t]:[]]},Hf=(e,t)=>{let n=new Map;for(let r of e){let e=Sc(r);n.set(e,(n.get(e)??!0)&&t.has(r))}return{done:[...n.values()].filter(Boolean).length,total:n.size}},Uf=(e,t)=>{let n=new Map;for(let t of e)if(t.kind===`step`)for(let e of t.partIds)n.has(e)||n.set(e,t.number);let r=e=>{let r=e===void 0?null:t.parts.get(e)?.place??null;return e===void 0||r===null?null:{id:e,n:r.n,definitions:r.definitions,step:n.get(e)??null}},i=new Map;for(let[e,{place:a}]of t.parts){if(a===null)continue;let t=n.get(e),o=[...new Set(a.siblings.flatMap(e=>{let r=n.get(e);return r===void 0||r===t?[]:[r]}))].sort((e,t)=>e-t);i.set(e,{definitions:a.definitions,n:a.n,of:a.of,elsewhere:o,previous:r(a.siblings[a.n-2]),next:r(a.siblings[a.n])})}return i},Wf=(e,t)=>{let n=new Map;for(let r of e){let e=t.partsOf(r.hunkId).find(e=>t.parts.get(e)?.hunk.lines.some(e=>{let t=Id(e);return t!==null&&t.side===r.side&&t.line===r.line}));e!==void 0&&n.set(e,[...n.get(e)??[],r])}return n},Gf=c(),Kf={context:` `,add:`+`,del:`-`},qf=(e,t)=>{let n=RegExp(`(?<![\\w$])${t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}(?![\\w$])`),r=RegExp(`\\b(def|class|function|func|fn|const|let|var|type|interface|enum|struct)\\s+${n.source}`),i=e.lines.map((e,t)=>({line:e,at:t})).filter(({line:e})=>e.kind!==`del`);return(i.find(({line:e})=>r.test(e.text))??i.find(({line:e})=>n.test(e.text)))?.at??0},Jf=null,Yf=({mark:e,deps:t,children:n})=>{let r=(0,H.useId)(),i=(0,H.useRef)(null),a=(0,H.useRef)(null),[o,s]=(0,H.useState)(null),[c]=e.calls,l=()=>{a.current!==null&&clearTimeout(a.current),a.current=null,s(null)},u=()=>{let e=i.current?.getBoundingClientRect();e!==void 0&&(Jf!==l&&Jf?.(),Jf=l,s({top:e.bottom+4,left:e.left}))};if((0,H.useEffect)(()=>{if(o===null)return;let e=()=>{let e=i.current?.getBoundingClientRect();if(e===void 0||e.bottom<0||e.top>window.innerHeight)return l();s({top:e.bottom+4,left:e.left})};return window.addEventListener(`scroll`,e,!0),()=>window.removeEventListener(`scroll`,e,!0)},[o]),(0,H.useEffect)(()=>()=>{a.current!==null&&clearTimeout(a.current)},[]),c===void 0)return n;let d=(e=>t.index.mechanical.has(e)?`mechanical`:t.index.items([e])[0]?.risk.riskClass??`logic`)(c.toPartId);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`button`,{ref:i,type:`button`,className:`call-mention risk-${d}`,"aria-describedby":o===null?void 0:r,onMouseEnter:()=>{a.current!==null&&clearTimeout(a.current),a.current=setTimeout(u,300)},onMouseLeave:l,onFocus:u,onBlur:l,onKeyDown:e=>{e.key===`Escape`&&o!==null&&(e.stopPropagation(),l())},onClick:()=>{l(),t.onFollow(c.toPartId)},children:n}),o!==null&&(0,Gf.createPortal)((0,G.jsx)(`div`,{id:r,role:`tooltip`,className:`peek`,style:{top:o.top,left:o.left},children:e.calls.map(n=>(0,G.jsx)(Xf,{hunkId:n.toPartId,symbol:e.symbol,deps:t},n.toPartId))}),document.body)]})},Xf=({hunkId:e,symbol:t,deps:n})=>{let[r]=n.index.items([e]);if(r===void 0)return null;let{hunk:i,file:a}=r,o=n.index.mechanical.has(e)?`mechanical`:r.risk.riskClass,s=qf(i,t),c=i.lines.slice(s,s+12),l=n.stepOf(e);return(0,G.jsxs)(`div`,{className:`peek-hunk`,children:[(0,G.jsxs)(`p`,{className:`peek-head`,children:[(0,G.jsx)(`code`,{className:`call-symbol`,children:t}),` `,(0,G.jsx)(`span`,{children:a.path}),` `,(0,G.jsx)(`span`,{className:`muted`,children:Yu(i)}),` `,(0,G.jsx)(`span`,{className:`call-risk risk-${o}`,children:o}),l!==null&&(0,G.jsxs)(`span`,{className:`peek-step muted`,children:[` · `,l]})]}),(0,G.jsx)(`pre`,{className:`peek-code`,children:c.map((e,t)=>(0,G.jsxs)(`span`,{className:`peek-line line-${e.kind}`,children:[Kf[e.kind],` `,e.text]},t))})]})},Zf=e=>`step-${e}`,Qf=`mechanical-changes`,$f=(e,t)=>`${e.join(`>`)}@${t.line}:${t.symbol}>${t.toPartId}`,ep=(0,H.memo)(function({render:e}){return e()},(e,t)=>e.signature===t.signature),$=({call:e,chain:t,deps:n,openCalls:r,onToggleCall:i})=>{let a=$f(t,e);if(t.includes(e.toPartId))return(0,G.jsx)(`li`,{className:`call`,children:(0,G.jsxs)(`span`,{className:`call-chip above`,children:[(0,G.jsx)(cf,{call:e,index:n.index}),(0,G.jsx)(`span`,{className:`call-note`,children:`open above`})]})});let o=r.has(a);return(0,G.jsxs)(`li`,{className:`call`,children:[(0,G.jsxs)(`button`,{type:`button`,className:`call-chip`,"aria-expanded":o,onClick:()=>i(a),children:[(0,G.jsx)(`span`,{className:`call-arrow`,"aria-hidden":`true`,children:o?`▾`:`▸`}),(0,G.jsx)(cf,{call:e,index:n.index})]}),o&&(0,G.jsx)(`div`,{className:`inline-call`,children:(0,G.jsx)(sp,{id:e.toPartId,chain:[...t,e.toPartId],deps:n,openCalls:r,onToggleCall:i})})]})},tp=({mark:e,chain:t,deps:n,openCalls:r,onToggleCall:i})=>{let[a,o]=(0,H.useState)(!1),s=(0,H.useRef)(null),c=e.calls.filter(e=>!t.includes(e.toPartId)&&r.has($f(t,e))),l=(e,t)=>{let n=[...e.closest(`ul`)?.querySelectorAll(`.call-choice`)??[]];n[(n.indexOf(e)+t+n.length)%n.length]?.focus()};return(0,G.jsxs)(`li`,{className:`call`,children:[(0,G.jsxs)(`button`,{ref:s,type:`button`,className:`call-chip ambiguous`,"aria-expanded":a,onClick:()=>o(e=>!e),children:[(0,G.jsx)(`span`,{className:`call-arrow`,"aria-hidden":`true`,children:a?`▾`:`▸`}),(0,G.jsx)(`code`,{className:`call-symbol`,children:e.symbol}),` `,(0,G.jsxs)(`span`,{className:`call-file`,children:[`→ `,e.calls.length,` places`]})]}),a&&(0,G.jsx)(`ul`,{className:`call-choices`,"aria-label":`Where ${e.symbol} goes`,children:e.calls.map(e=>{let a=t.includes(e.toPartId),c=n.index.parts.get(e.toPartId);return(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{type:`button`,className:`call-choice`,disabled:a,"aria-pressed":r.has($f(t,e)),onClick:()=>{i($f(t,e)),o(!1),s.current?.focus()},onKeyDown:e=>{e.key===`ArrowDown`||e.key===`ArrowUp`?(e.preventDefault(),e.stopPropagation(),l(e.currentTarget,e.key===`ArrowDown`?1:-1)):e.key===`Escape`&&(e.stopPropagation(),o(!1),s.current?.focus())},children:[(0,G.jsx)(cf,{call:e,index:n.index}),c!==void 0&&(0,G.jsxs)(`span`,{className:`call-note`,children:[` `,Yu(c.hunk)]}),a&&(0,G.jsx)(`span`,{className:`call-note`,children:` open above`})]})},e.toPartId)})}),c.map(e=>(0,G.jsx)(`div`,{className:`inline-call`,children:(0,G.jsx)(sp,{id:e.toPartId,chain:[...t,e.toPartId],deps:n,openCalls:r,onToggleCall:i})},e.toPartId))]})},np=({marks:e,chain:t,deps:n,openCalls:r,onToggleCall:i})=>(0,G.jsx)(`ul`,{className:`calls`,children:e.map(e=>{let[a,...o]=e.calls;if(a===void 0)return null;let s={chain:t,deps:n,openCalls:r,onToggleCall:i};return o.length>0?(0,G.jsx)(tp,{mark:e,...s},`${e.symbol}*`):(0,G.jsx)($,{call:a,...s},`${e.symbol}>${a.toPartId}`)})}),rp=e=>{let t=new Map;for(let n of e)t.set(n.symbol,[...t.get(n.symbol)??[],n]);return[...t].map(([e,t])=>({kind:`chip`,symbol:e,calls:t}))},ip=(e,t)=>{let n=e.at(-1);if(n===void 0)return;if(e.length===1)return t.plan.get(n);let r=t.calls.get(n);return r===void 0?void 0:new Map([...r].map(([e,t])=>[e,rp(t)]))},ap=(e,t,n,r)=>{let i=ip(e,t);if(i!==void 0)return new Map([...i].flatMap(([i,a])=>{let o=a.filter(e=>e.kind===`chip`);return o.length===0?[]:[[i,(0,G.jsx)(np,{marks:o,chain:e,deps:t,openCalls:n,onToggleCall:r},i)]]}))},op=(e,t)=>new Map([...t.plan.get(e)??[]].flatMap(([e,n])=>{let r=n.flatMap(e=>e.kind===`mention`?[{start:e.at.start,end:e.at.end,render:n=>(0,G.jsx)(Yf,{mark:e,deps:t,children:n})}]:[]);return r.length===0?[]:[[e,r]]})),sp=({id:e,chain:t,deps:n,openCalls:r,onToggleCall:i})=>(0,G.jsx)(sf,{id:e,deps:n,nested:!0,belowLine:ap(t,n,r,i)}),cp=({via:e,deps:t})=>{let n=e.flatMap(e=>{let n=t.index.parts.get(e);return n===void 0?[]:[{id:e,...n}]});return n.length===0?null:(0,G.jsxs)(`div`,{className:`step-via`,children:[(0,G.jsx)(`span`,{className:`step-via-label`,children:`Passes through`}),(0,G.jsx)(`ul`,{className:`hunk-links`,"aria-label":`Passes through`,children:n.map(({id:e,file:n,hunk:r})=>(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{type:`button`,className:`hunk-link`,onClick:()=>t.onFollow(e),children:[n.path.slice(n.path.lastIndexOf(`/`)+1),` `,Yu(r),` ↑`]})},e))})]})},lp=({analysis:e,sections:t,deps:n,contractOnly:r,isContract:i,openCalls:a,onToggleCall:o,before:s,trailingProofs:c,mechanicalCount:l,scrollRequest:u,signatureOf:d})=>{(0,H.useEffect)(()=>{if(u===null)return;let e=document.getElementById(u.id);if(e===null)return;let t=e.querySelector(`:scope > .hunk-card, :scope > div > .mechanical-toggle`)??e,n=e.classList.contains(`decision`);e.scrollIntoView({block:n?`center`:`start`}),t.focus({preventScroll:!0})},[u]);let f=e=>r?e.filter(i):e,p=t.some(e=>f(e.partIds).length>0);return(0,G.jsxs)(`section`,{className:`main-area map`,"aria-label":`Changes`,children:[e.tour?.builtBy===`code`&&e.stages.tour===`done`&&(0,G.jsx)(`p`,{className:`banner`,children:`The model couldn't title the tour, so its steps keep the code's titles.`}),s,r&&!p&&(0,G.jsx)(`p`,{className:`muted`,children:`No contract changes in this pull request. Turn off “Contract changes only” to see the rest.`}),t.map(t=>{let i=f(t.partIds);if(r&&i.length===0)return null;let s=jf(t);return(0,G.jsxs)(`section`,{id:Zf(s),className:`map-step`,"aria-labelledby":`${Zf(s)}-title`,tabIndex:-1,children:[t.kind===`step`?(0,G.jsxs)(`header`,{className:t.step.kind===`supporting`?`step-heading supporting`:`step-heading`,children:[(0,G.jsxs)(`h2`,{id:`${Zf(s)}-title`,className:`model-text`,children:[(0,G.jsx)(`span`,{className:`step-number`,children:t.number}),` `,t.step.title]}),t.step.codeTitle!==null&&(0,G.jsx)(`p`,{className:`step-code-title`,children:t.step.codeTitle}),(0,G.jsx)(`p`,{className:`model-text`,children:t.step.explanation}),t.step.merged.map(e=>(0,G.jsxs)(`p`,{className:`step-merged`,children:[`Also reads `,e.title,`: `,(0,G.jsx)(`span`,{className:`model-text`,children:e.reason})]},e.title)),(0,G.jsx)(cp,{via:t.step.via,deps:n})]}):(0,G.jsxs)(`header`,{className:`step-heading`,children:[(0,G.jsx)(`h2`,{id:`${Zf(s)}-title`,children:`Changes by file`}),(0,G.jsx)(`p`,{className:`muted`,children:e.status===`running`?`The guided tour appears when the analysis finishes.`:`There's no guided tour, so the changes are shown by file.`})]}),i.map(e=>(0,G.jsx)(`div`,{id:of(e),className:`map-hunk`,"data-hunk-id":e,children:(0,G.jsx)(ep,{signature:d(e),render:()=>(0,G.jsx)(sf,{id:e,deps:n,belowLine:ap([e],n,a,o),inLine:op(e,n)})})},e))]},s)}),!r&&(0,G.jsxs)(`div`,{id:`mechanical-changes`,className:`map-mechanical`,tabIndex:-1,children:[l===0&&e.stages.prep===`done`&&(0,G.jsx)(`p`,{className:`muted`,children:`No mechanical changes in this pull request.`}),(0,G.jsx)(Wd,{files:e.files,proofs:c,risk:e.risk}),(0,G.jsx)(Jd,{files:e.files})]})]})},up=64,dp=56,fp=24,pp=16,mp=120,hp=300,gp=7.8,_p=6.6,vp=6.7,yp=72,bp=20,xp=380,Sp=e=>e.slice(e.lastIndexOf(`/`)+1),Cp=e=>e===1?`1 use`:`${e} uses`,wp=e=>e.kind===`outside`?`${e.paths.length>1?`${e.paths.length} files · `:``}outside the PR · ${Cp(e.uses)}`:`${e.kind===`group`?`${e.paths.length} files · `:``}+${e.added} −${e.deleted}${e.entries.length>0?` · ${e.entries.join(`, `)}`:``}`,Tp=e=>{let t=e.badges.reduce((e,t)=>e+Sp(t).length*vp+14,0),n=Math.min(Math.max(e.label.length*gp+yp,wp(e).length*_p+bp,t+bp),xp),r=mp+Math.sqrt(e.added+e.deleted)*9;return Math.round(Math.max(n,Math.min(r,hp)))},Ep=72,Dp=(e,t)=>{let n=e.map(e=>e.reduce((e,t,n)=>e+Tp(t)+(n>0?fp:0),0)),r=Math.max(0,...n)+32,i=r+(t?Ep:0),a=new Map;return e.forEach((e,t)=>{let i=(r-(n[t]??0))/2;for(let n of e){let e=Tp(n);a.set(n.key,{x:i,y:pp+t*120,width:e}),i+=e+fp}}),{boxes:a,width:i,height:e.length===0?0:32+e.length*up+(e.length-1)*dp}},Op=e=>e.outside?`outside`:e.uses.includes(`call`)?`call`:e.uses.includes(`request`)?`request`:e.uses.every(e=>e===`import`)?`import`:`type`,kp=(e,t)=>{let n=e=>{let n=t.get(e);return n===void 0?0:n.x+n.width/2},r=(e,r,i)=>{let a=t.get(r),o=[...e].sort((e,t)=>n(i(e))-n(i(t)));return new Map(o.map((e,t)=>[e,a===void 0?0:a.x+a.width*(.5+(o.length===1?0:(t/(o.length-1)-.5)*.5))]))},i=e.filter(e=>!e.back&&!e.outside),a=new Map,o=new Map;for(let e of t.keys()){for(let[t,n]of r(i.filter(t=>t.from===e),e,e=>e.to))a.set(t,n);for(let[t,n]of r(i.filter(t=>t.to===e),e,e=>e.from))o.set(t,n)}return{out:a,into:o}},Ap=(e,t,n,r,i=e.x+e.width/2,a=t.x+t.width/2)=>{if(n){let n=e.x+e.width,i=t.x+t.width,a=e.y+up/2,o=t.y+up/2,s=r-Ep/2;return`M ${n} ${a} C ${s} ${a} ${s} ${o} ${i} ${o}`}if(e.y>t.y){let n=e.y,r=t.y+up,o=Math.max(dp/2,(n-r)/2);return`M ${i} ${n} C ${i} ${n-o} ${a} ${r+o} ${a} ${r}`}let o=e.y+up,s=t.y,c=Math.max(dp/2,(s-o)/2);return`M ${i} ${o} C ${i} ${o+c} ${a} ${s-c} ${a} ${s}`},jp={import:`imports`,call:`calls`,type:`uses types from`,request:`sends requests to`},Mp=(e,t)=>{let n=e.uses.map(e=>jp[e]).join(`, `),r=e.symbols.length>0?`: ${e.symbols.join(`, `)}`:``;return`${t(e.from)} ${n} ${t(e.to)}${r}`},Np=(e,t)=>{let{done:n,total:r}=Hf(e.partIds,t);return{done:n,total:r,all:n===r}},Pp=({node:e,box:t,reviewed:n,active:r,onOpen:i,onFocus:a})=>{let o=Np(e,n),s=e.kind===`group`,c=e.kind===`outside`,l=(c?[e.label,wp(e)]:[e.label,s?`${e.paths.length} files`:null,...e.entries,e.risk,e.generated?`generated`:null,o.all?`reviewed`:`${o.done} of ${o.total} hunks reviewed`]).filter(e=>e!==null).join(`, `);return(0,G.jsxs)(`button`,{type:`button`,className:`overview-node ${c?`outside`:`risk-${e.risk}`}${e.generated?` generated`:``}${s?` group`:``}${r?` active`:``}`,"data-key":e.key,"aria-label":l,title:e.paths.length===1?e.paths[0]:void 0,style:t===void 0?{width:Tp(e)}:{left:t.x,top:t.y,width:t.width,height:up},onClick:()=>i(e),onFocus:()=>a(e),onMouseEnter:()=>a(e),onMouseLeave:()=>a(null),children:[(0,G.jsxs)(`span`,{className:`overview-node-head`,children:[(0,G.jsx)(`span`,{className:`overview-label`,children:e.label}),c?null:o.all?(0,G.jsx)(`span`,{className:`overview-tick`,role:`img`,"aria-label":`reviewed`,children:`✓`}):(0,G.jsxs)(`span`,{className:`overview-count`,children:[o.done,`/`,o.total]})]}),(0,G.jsx)(`span`,{className:`overview-meta`,children:wp(e)}),e.badges.length>0&&(0,G.jsx)(`span`,{className:`overview-badges`,children:e.badges.map(e=>(0,G.jsx)(`span`,{className:`overview-badge`,children:Sp(e)},e))})]})},Fp=({overview:e,reviewed:t,focusKey:n,onOpen:r,onCollapse:i,expandedGroups:a,onFocusNode:o})=>{let s=(0,H.useId)(),c=(0,H.useRef)(null),[l,u]=(0,H.useState)(null),{boxes:d,width:f,height:p}=(0,H.useMemo)(()=>Dp(e.rows,e.edges.some(e=>e.back)),[e]),m=(0,H.useMemo)(()=>kp(e.edges,d),[e.edges,d]),h=(0,H.useMemo)(()=>new Map([...e.rows.flat(),...e.strip].map(e=>[e.key,e.label])),[e]),g=e=>h.get(e)??e,_=(0,H.useMemo)(()=>[...e.rows,e.strip].filter(e=>e.length>0),[e]);(0,H.useEffect)(()=>u(null),[e]);let v=(0,H.useRef)(-1);(0,H.useEffect)(()=>{if(n===null||v.current===n.n)return;let t=e.placeOf.get(n.key)??n.key,r=c.current?.querySelector(`[data-key="${CSS.escape(t)}"]`);r==null||t.startsWith(`group:`)||(v.current=n.n,r.focus(),r.scrollIntoView?.({block:`nearest`,inline:`nearest`}))},[n,e]);let y=e=>c.current?.querySelector(`[data-key="${CSS.escape(e)}"]`)?.focus(),b=e=>{let t=e.target.dataset.key;if(t===void 0)return;let n=_.findIndex(e=>e.some(e=>e.key===t)),r=_[n]?.findIndex(e=>e.key===t)??-1,i=e=>{let t=c.current?.querySelector(`[data-key="${CSS.escape(e.key)}"]`)?.getBoundingClientRect();return t===void 0?0:t.left+t.width/2},a;if(e.key===`ArrowRight`)a=_[n]?.[r+1];else if(e.key===`ArrowLeft`)a=_[n]?.[r-1];else if(e.key===`ArrowDown`||e.key===`ArrowUp`){let t=_[n+(e.key===`ArrowDown`?1:-1)]??[],o=_[n]?.[r],s=o===void 0?0:i(o);a=[...t].sort((e,t)=>Math.abs(i(e)-s)-Math.abs(i(t)-s))[0]}else return;e.preventDefault(),a!==void 0&&y(a.key)},x=l?.kind===`node`?l.node.key:null,S=e=>e.from===x||e.to===x,ee=e=>{e!==null&&o(e.key),u(e===null?null:{kind:`node`,node:e})},te=e=>({node:e,reviewed:t,active:x===e.key,onOpen:r,onFocus:ee});return(0,G.jsxs)(`section`,{className:`overview`,"aria-label":`Overview of the changed files`,ref:c,onKeyDown:b,children:[(0,G.jsxs)(`p`,{className:`overview-legend muted`,children:[`Files that nothing in the pull request calls are on top; each file sits below its callers. Solid lines are calls, dash-dot ones HTTP requests to a route, dashed ones imports, dotted ones types. Tests show on the files they call.`,e.edges.some(e=>e.outside)&&` Faded files are outside the pull request, under the files whose changes they use.`]}),a.length>0&&(0,G.jsx)(`p`,{className:`overview-expanded`,children:a.map(e=>(0,G.jsxs)(`button`,{type:`button`,className:`button quiet`,onClick:()=>i(e),children:[`Collapse `,e.slice(6),`/`]},e))}),e.rows.length>0?(0,G.jsx)(`div`,{className:`overview-scroll`,children:(0,G.jsxs)(`div`,{className:`overview-diagram`,style:{width:f,height:p},children:[(0,G.jsxs)(`svg`,{className:`overview-edges`,width:f,height:p,"aria-hidden":`true`,children:[(0,G.jsx)(`defs`,{children:(0,G.jsx)(`marker`,{id:`${s}-arrow`,viewBox:`0 0 8 8`,refX:`7`,refY:`4`,markerWidth:`7`,markerHeight:`7`,orient:`auto-start-reverse`,children:(0,G.jsx)(`path`,{d:`M 0 0 L 8 4 L 0 8 z`,className:`overview-arrow`})})}),e.edges.map(e=>{let t=d.get(e.from),n=d.get(e.to);if(t===void 0||n===void 0)return null;let r=Ap(t,n,e.back,f,m.out.get(e),m.into.get(e)),i=S(e)||l?.kind===`edge`&&l.edge===e,a=l!==null&&!i;return(0,G.jsxs)(`g`,{className:`overview-edge ${Op(e)}${i?` lit`:``}${a?` dim`:``}`,onMouseEnter:()=>u({kind:`edge`,edge:e}),onMouseLeave:()=>u(null),children:[(0,G.jsx)(`path`,{d:r,className:`overview-edge-hit`}),(0,G.jsx)(`path`,{d:r,className:`overview-edge-line`,markerEnd:`url(#${s}-arrow)`}),(0,G.jsx)(`title`,{children:Mp(e,g)})]},`${e.from}>${e.to}`)})]}),e.rows.flat().map(e=>(0,G.jsx)(Pp,{box:d.get(e.key),...te(e)},e.key))]})}):(0,G.jsx)(`p`,{className:`muted`,children:`No changed file calls or imports another.`}),e.strip.length>0&&(0,G.jsxs)(`section`,{className:`overview-strip`,"aria-label":`Not linked`,children:[(0,G.jsx)(`h3`,{children:`Not linked`}),(0,G.jsx)(`div`,{className:`overview-strip-nodes`,children:e.strip.map(e=>(0,G.jsx)(Pp,{...te(e)},e.key))})]}),(0,G.jsx)(`p`,{className:`overview-detail`,"aria-live":`polite`,children:l===null?`Hover or focus a file to see its flows and tests.`:l.kind===`edge`?Mp(l.edge,g):Ip(l.node,e.edges,g)})]})},Ip=(e,t,n)=>{let r=t.filter(t=>t.from===e.key).map(e=>{let t=e.symbols.length>0?` (${e.symbols.join(`, `)})`:``;return`${n(e.to)}${t}`});return e.kind===`outside`?`${e.paths.length>1?`${e.label}: ${e.paths.length} files`:e.paths[0]} · outside the pull request · uses ${r.join(`, `)}.`:`${[e.kind===`group`?`${e.label}: ${e.paths.length} files, Enter expands`:e.paths[0],e.flows.length>0?`read in ${e.flows.join(`; `)}`:`in no flow`,...r.length>0?[`reaches ${r.join(`, `)}`]:[],...e.badges.length>0?[`tested in ${e.badges.map(Sp).join(`, `)}`]:[]].join(` · `)}.`},Lp={mechanical:0,logic:1,contract:2},Rp=[`import`,`call`,`type`,`request`],zp=e=>e.slice(e.lastIndexOf(`/`)+1),Bp=e=>e.slice(0,Math.max(e.lastIndexOf(`/`),0)),Vp=(e,t)=>e<t?-1:+(e>t),Hp=e=>/\.(md|mdx|rst|adoc)$/i.test(e),Up=/(^|[/_.-])(fakes?|mocks?|stubs?|fixtures?|testing|test[_-]?(utils?|helpers?|support))([/_.-]|$)/i,Wp=e=>Bp(e).split(`/`).slice(0,3).join(`/`),Gp=e=>`group:${e}`,Kp=e=>{let t=new Map(e.map(e=>[e,e.split(`/`)])),n=(e,n)=>(t.get(e)??[]).slice(-n).join(`/`),r=new Map;for(let i of e){let a=t.get(i)?.length??1,o=1;for(;o<a&&e.some(e=>e!==i&&n(e,o)===n(i,o));)o+=1;r.set(i,n(i,o))}return r},qp=`\0routes`,Jp=e=>`${e.method} ${e.path}`,Yp=e=>{let[t]=e;return e.length===1&&t!==void 0?`${t.method} ${t.path}`:`${e.length} routes`},Xp=(e,t)=>{let n=wc(e.parts),r=new Map(e.files.flatMap(e=>Tc(e,n).map(({id:t,hunk:n})=>[t,{file:e,hunk:n}]))),i=new Map,a=(e,t)=>{let n=i.get(e)??[];n.includes(t)||i.set(e,[...n,t])},o=new Map;for(let e of t){let t=new Map;for(let n of e.entries){let e=r.get(n)?.file.path;e!==void 0&&t.set(e,[...t.get(e)??[],n])}for(let[n,i]of t){let t=i.flatMap(e=>{let t=r.get(e),n=t===void 0?null:bl(t.file,t.hunk,[]);return n?.kind===`route`?n.routes:[]});if(t.length>0&&(a(n,qp),o.set(n,[...o.get(n)??[],...t])),!(new Set(t.map(Jp)).size===i.length&&t.length>0))for(let t of(e.codeTitle??e.title).split(`; `)){t.startsWith(`Page: `)&&a(n,t);let e=/^Command: (\S+) in (.+)$/.exec(t);e!==null&&e[2]===zp(n)&&a(n,`Command: ${e[1]}`)}}}return new Map([...i].map(([e,t])=>{let n=[...new Map((o.get(e)??[]).map(e=>[Jp(e),e])).values()];return[e,t.map(e=>e===qp?Yp(n):e)]}))},Zp=(e,t)=>{let n=new Map,r=new Map,i=[],a=new Set,o=[],s=0,c=e=>{n.set(e,s),r.set(e,s),s+=1,i.push(e),a.add(e);for(let i of t(e))n.has(i)?a.has(i)&&r.set(e,Math.min(r.get(e)??0,n.get(i)??0)):(c(i),r.set(e,Math.min(r.get(e)??0,r.get(i)??0)));if(r.get(e)!==n.get(e))return;let l=[];for(let t=i.pop();t!==void 0&&(a.delete(t),l.push(t),t!==e);t=i.pop());l.length>1&&o.push(l)};for(let t of e)n.has(t)||c(t);return o},Qp=(e,t,n=new Set)=>{let r=new Set(e.proofs.flatMap(e=>e.hunkId??[])),i=new Map(e.risk.map(e=>[e.hunkId,e.riskClass])),a=[...new Set(t.flatMap(e=>e.partIds))],o=new Map(a.map((e,t)=>[e,t])),s=e=>o.get(e)??a.length,c=new Set(e.generated),l=e.files.filter(e=>e.hunks.some(e=>!r.has(e.id))),u=new Map(l.flatMap(e=>e.hunks.map(t=>[t.id,e.path]))),d=new Map(l.map(t=>{let n=t.hunks.flatMap(e=>e.lines),a=Tc(t,wc(e.parts)).map(e=>e.id).filter(e=>!r.has(Sc(e))).sort((e,t)=>s(e)-s(t)),o=t.hunks.map(e=>r.has(e.id)?`mechanical`:i.get(e.id)??`logic`).reduce((e,t)=>Lp[t]>Lp[e]?t:e,`mechanical`);return[t.path,{added:n.filter(e=>e.kind===`add`).length,deleted:n.filter(e=>e.kind===`del`).length,partIds:a,risk:o,rank:a.reduce((e,t)=>Math.min(e,s(t)),1/0)}]})),f=e=>d.get(e)?.rank??1/0,p=(e,t)=>f(e)-f(t)||Vp(e,t),m=l.map(e=>e.path).sort(p),h=new Map,g=(e,t,n,r)=>{if(e===t||!d.has(e)||!d.has(t))return;let i=h.get(e)??new Map,a=i.get(t)??{uses:new Set,symbols:new Set};a.uses.add(n),r!==void 0&&a.symbols.add(r),i.set(t,a),h.set(e,i)};for(let{from:t,to:n}of e.fileLinks)g(t,n,`import`);for(let t of e.callGraph){let e=u.get(Sc(t.fromPartId)),n=u.get(Sc(t.toPartId));e!==void 0&&n!==void 0&&g(e,n,t.use,t.symbol)}let _=e=>[...h.get(e)?.keys()??[]],v=e=>m.filter(t=>h.get(t)?.has(e)===!0),y=new Set(m.filter(kc));for(let e=!0;e;){e=!1;for(let t of m){let n=v(t);!y.has(t)&&Up.test(t)&&n.length>0&&n.every(e=>y.has(e))&&(y.add(t),e=!0)}}let b=m.filter(e=>!y.has(e)&&Hp(e)),x=m.filter(e=>!y.has(e)&&!Hp(e)),S=new Set(x),ee=new Map;for(let e of[...y].sort(p)){let t=[],n=new Set([e]),r=e=>{for(let i of _(e))n.has(i)||(n.add(i),S.has(i)?t.push(i):r(i))};r(e),ee.set(e,t)}let te=new Map;for(let[e,t]of ee)for(let n of t)te.set(n,[...te.get(n)??[],e]);let C=x.length>40,w=new Map;for(let e of x){let t=Wp(e),r=C&&!n.has(Gp(t))?Gp(t):e;w.set(r,[...w.get(r)??[],e])}for(let[e,t]of[...w]){let[n]=t;e.startsWith(`group:`)&&t.length===1&&n!==void 0&&(w.delete(e),w.set(n,[n]))}let T=new Map;for(let[e,t]of w)for(let n of t)T.set(n,e);let ne=e=>Math.min(...(w.get(e)??[e]).map(f)),re=(e,t)=>ne(e)-ne(t)||Vp(e,t),ie=[...w.keys()].sort(re),ae=new Map;for(let[e,t]of h)for(let[n,r]of t){let t=T.get(e),i=T.get(n);if(t===void 0||i===void 0||t===i)continue;let a=ae.get(t)??new Map,o=a.get(i)??{uses:new Set,symbols:new Set};for(let e of r.uses)o.uses.add(e);for(let e of r.symbols)o.symbols.add(e);a.set(i,o),ae.set(t,a)}let oe=new Map;for(let{partId:t,symbol:n,uses:r}of e.unchangedCallers??[]){let e=u.get(Sc(t)),i=e===void 0?void 0:T.get(e);if(i!==void 0)for(let e of r){let r=oe.get(e.path)??{targets:new Map,uses:0,partIds:new Set},a=r.targets.get(i)??{uses:new Set,symbols:new Set};a.uses.add(e.use),a.symbols.add(n),r.targets.set(i,a),r.uses+=1,r.partIds.add(t),oe.set(e.path,r)}}let se=[...oe.keys()].sort((e,t)=>Number(kc(e))-Number(kc(t))||Vp(e,t)),ce=new Map;for(let e of se){let t=se.length>10?`outside:${Wp(e)}/`:`outside:${e}`;ce.set(t,[...ce.get(t)??[],e])}for(let[e,t]of[...ce]){let[n]=t;e.endsWith(`/`)&&t.length===1&&n!==void 0&&(ce.delete(e),ce.set(`outside:${n}`,[n]))}let le=new Map;for(let[e,t]of ce){let n=new Map;for(let e of t)for(let[t,r]of oe.get(e)?.targets??[]){let e=n.get(t)??{uses:new Set,symbols:new Set};for(let t of r.uses)e.uses.add(t);for(let t of r.symbols)e.symbols.add(t);n.set(t,e)}le.set(e,n)}let ue=new Set([...[...ae].flatMap(([e,t])=>t.size>0?[e,...t.keys()]:[]),...[...le.values()].flatMap(e=>[...e.keys()])]),E=ie.filter(e=>ue.has(e)),de=new Set,fe=(e,t)=>`${e}\u0000${t}`,pe=e=>[...ae.get(e)?.keys()??[]].filter(t=>!de.has(fe(e,t)));for(let e=Zp(E,pe);e.length>0;e=Zp(E,pe))for(let t of e){let[e]=[...t].sort(re);for(let n of t)e!==void 0&&pe(n).includes(e)&&de.add(fe(n,e))}let me=new Map(E.map(e=>[e,[]]));for(let e of E)for(let t of pe(e))me.get(t)?.push(e);let he=new Map,ge=e=>{let t=he.get(e);if(t!==void 0)return t;let n=Math.max(-1,...(me.get(e)??[]).map(ge))+1;return he.set(e,n),n},_e=[],ve=(e,t)=>{for(;_e.length<=t;)_e.push([]);_e[t]?.push(e)};for(let e of E)ve(e,ge(e));for(let[e,t]of le){let n=[...t.keys()];me.set(e,n),he.set(e,Math.max(...n.map(ge))+1),ve(e,he.get(e)??0)}let ye=()=>new Map(_e.flatMap(e=>e.map((t,n)=>[t,n-(e.length-1)/2]))),be=e=>pe(e),xe=(e,t)=>{for(let n of e){let e=ye(),r=n=>{let r=t(n).map(t=>e.get(t)??0);return r.length===0?e.get(n)??0:r.reduce((e,t)=>e+t,0)/r.length},i=new Map(n.map(e=>[e,r(e)]));n.sort((e,t)=>(i.get(e)??0)-(i.get(t)??0)||re(e,t))}},Se=e=>me.get(e)??[];xe(_e.slice(1),Se),xe(_e.slice(0,-1).reverse(),be),xe(_e.slice(1),Se);let Ce=Kp(m),D=Xp(e,t),O=new Map;for(let e of t)if(e.kind===`flow`)for(let t of new Set(e.partIds.flatMap(e=>u.get(Sc(e))??[])))O.set(t,[...O.get(t)??[],e.title]);let we=e=>[...new Set(e)],Te=Kp(se),Ee=(e,t)=>{let n=ce.get(e)??[],[r]=n;return{key:e,kind:`outside`,paths:n,label:e.endsWith(`/`)||r===void 0?e.slice(8):Te.get(r)??r,added:0,deleted:0,risk:`logic`,generated:!1,entries:[],flows:[],partIds:[...new Set(n.flatMap(e=>[...oe.get(e)?.partIds??[]]))],uses:n.reduce((e,t)=>e+(oe.get(t)?.uses??0),0),badges:[],row:t}},De=(e,t)=>{if(ce.has(e))return Ee(e,t);let n=w.get(e)??[e],r=n.flatMap(e=>d.get(e)??[]),i=e.startsWith(`group:`);return{key:e,kind:i?`group`:`file`,paths:n,label:i?`${e.slice(6)||`.`}/`:Ce.get(e)??e,added:r.reduce((e,t)=>e+t.added,0),deleted:r.reduce((e,t)=>e+t.deleted,0),risk:r.map(e=>e.risk).reduce((e,t)=>Lp[t]>Lp[e]?t:e,`mechanical`),generated:n.every(e=>c.has(e)),entries:we(n.flatMap(e=>D.get(e)??[])),flows:we(n.flatMap(e=>O.get(e)??[])),partIds:r.flatMap(e=>e.partIds).sort((e,t)=>s(e)-s(t)),badges:we(n.flatMap(e=>te.get(e)??[])).sort(p),uses:0,row:t}},k=_e.map((e,t)=>e.map(e=>De(e,t))),A=[...ie.filter(e=>!ue.has(e)),...b,...[...y].filter(e=>(ee.get(e)??[]).length===0)].sort(re).map(e=>De(e,-1)),Oe=new Map;for(let e of[...k.flat(),...A])if(e.kind!==`outside`)for(let t of e.paths)Oe.set(t,e.key);for(let[e,t]of ee){let[n]=t,r=n===void 0?void 0:T.get(n);r!==void 0&&Oe.set(e,r)}return{rows:k,edges:[...[...ae].map(e=>[e,!1]),...[...le].map(e=>[e,!0])].flatMap(([[e,t],n])=>[...t].map(([t,r])=>({from:e,to:t,uses:Rp.filter(e=>r.uses.has(e)),symbols:[...r.symbols].sort(Vp),back:de.has(fe(e,t)),outside:n}))),strip:A,placeOf:Oe,grouped:C}},$p={collect:`Collect`,prep:`Prepare`,intent:`Intent`,risk:`Risk`,decisions:`Decisions`,tour:`Tour`},em={pending:`waiting`,running:`running`,done:`done`,failed:`failed`,skipped:`skipped`},tm={pending:`○`,running:`◐`,done:`●`,failed:`✗`,skipped:`–`},nm=({stages:e,filesFetched:t})=>(0,G.jsx)(`ol`,{className:`progress-strip`,"aria-label":`Analysis progress`,children:sl.options.map(n=>{let r=e[n];return(0,G.jsxs)(`li`,{className:`stage ${r}`,children:[(0,G.jsx)(`span`,{"aria-hidden":`true`,children:tm[r]}),` `,$p[n],(0,G.jsxs)(`span`,{className:`visually-hidden`,children:[`: `,em[r]]}),n===`collect`&&r===`running`&&t!==null&&(0,G.jsxs)(`span`,{className:`stage-detail`,children:[` `,`· `,t.done,` of `,t.total,` files`]})]},n)})}),rm=e=>$p[e],im={approve:`Approve`,request_changes:`Request changes`,comment:`Comment`},am=(e,t,n)=>`${e} ${e===1?t:n}`,om=({analysisId:e,isAuthor:t,pendingCount:n,hunkComments:r,chooseVerdict:i,onClose:a,onPublished:o})=>{let{client:s}=cu(),c=(0,H.useId)(),[l,u]=(0,H.useState)(``),[d,f]=(0,H.useState)(`comment`),p=i&&!t?d:null,[m,h]=(0,H.useState)(null),[g,_]=(0,H.useState)(null),[v,y]=(0,H.useState)(!1),[b,x]=(0,H.useState)(!1),S=mu(s.publish),ee=(0,H.useRef)(!1);(0,H.useEffect)(()=>{let t=!0,n=setTimeout(()=>void s.previewPublication(e,{summary:l,hunkComments:r,verdict:p}).then(e=>{t&&(ee.current=!0,h(e.ok?e.value:null),_(e.ok?null:e.error))}),ee.current?400:0);return()=>{t=!1,clearTimeout(n)}},[e,s,l,r,p]);let te=async t=>{x(t),y(!1);let n=await S.run(e,{summary:l,allowStale:t,hunkComments:r,verdict:p});n.ok?o(n.value):n.error.code===`stale-analysis`&&(S.reset(),y(!0))};return(0,G.jsxs)(af,{title:`Publish the review`,onClose:a,className:`publish-dialog`,children:[(0,G.jsx)(`label`,{htmlFor:`${c}-summary`,children:`Summary`}),(0,G.jsx)(`textarea`,{id:`${c}-summary`,className:`input summary-field`,rows:4,"data-autofocus":!0,placeholder:`What you'd like the author to know overall (optional)`,value:l,onChange:e=>u(e.target.value)}),i&&!t&&(0,G.jsxs)(`fieldset`,{className:`verdict-choice`,children:[(0,G.jsx)(`legend`,{children:`Verdict`}),[`approve`,`request_changes`,`comment`].map(e=>(0,G.jsxs)(`label`,{children:[(0,G.jsx)(`input`,{type:`radio`,name:`${c}-verdict`,checked:d===e,onChange:()=>f(e)}),im[e]]},e))]}),(0,G.jsxs)(`section`,{className:`preview`,"aria-labelledby":`${c}-preview`,"aria-busy":m===null,children:[(0,G.jsx)(`h3`,{id:`${c}-preview`,children:`What will be posted`}),g===null?m===null?(0,G.jsx)(`p`,{className:`muted`,children:`Building the preview…`}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`p`,{children:[`Verdict:`,` `,(0,G.jsx)(`strong`,{className:`publication-verdict ${m.verdict}`,children:im[m.verdict]})]}),t&&m.verdict===`comment`&&(0,G.jsx)(`p`,{className:`muted`,children:`You opened this pull request, so the review is posted as a comment: hosts don't let authors approve their own pull requests or request changes on them.`}),n>0&&(0,G.jsxs)(`p`,{className:`banner warning`,children:[am(n,`decision isn't`,`decisions aren't`),` reviewed yet. The summary lists `,n===1?`it`:`them`,` as not reviewed.`]}),(0,G.jsx)(`h4`,{children:am(m.comments.length,`inline comment`,`inline comments`)}),m.comments.length>0&&(0,G.jsx)(`ul`,{className:`preview-comments`,children:m.comments.map(e=>(0,G.jsxs)(`li`,{children:[(0,G.jsxs)(`code`,{children:[e.path,`:`,e.line,e.side===`old`?` (old side)`:``]}),(0,G.jsx)(`p`,{className:`posted-text`,children:e.body})]},e.key))}),(0,G.jsx)(`h4`,{children:`Summary comment`}),(0,G.jsx)(`p`,{className:`posted-text`,children:m.summary})]}):(0,G.jsxs)(`p`,{className:`banner danger`,role:`alert`,children:[`Couldn't build the preview. `,_u(g)]})]}),v?(0,G.jsxs)(`div`,{className:`banner warning`,role:`alert`,children:[(0,G.jsx)(`p`,{children:`This PR changed since the analysis. Publish anyway?`}),(0,G.jsxs)(`div`,{className:`dialog-actions`,children:[(0,G.jsx)(`button`,{type:`button`,className:`button`,onClick:()=>y(!1),children:`Cancel`}),(0,G.jsx)(`button`,{type:`button`,className:`button primary`,onClick:()=>void te(!0),children:`Publish anyway`})]})]}):(0,G.jsxs)(G.Fragment,{children:[S.error!==null&&(0,G.jsxs)(`div`,{className:`banner danger`,role:`alert`,children:[(0,G.jsxs)(`p`,{children:[`Couldn't publish. `,_u(S.error)]}),(0,G.jsx)(`p`,{className:`muted`,children:`Retrying is safe: comments that were already posted aren't posted again.`})]}),(0,G.jsxs)(`div`,{className:`dialog-actions`,children:[(0,G.jsx)(`button`,{type:`button`,className:`button`,onClick:a,children:`Cancel`}),(0,G.jsx)(`button`,{type:`button`,className:`button primary`,disabled:S.pending||m===null,onClick:()=>void te(b),children:S.pending?`Publishing…`:S.error===null?`Publish`:`Retry`})]})]})]})},sm=2,cm=({view:e,intent:t,tools:n,reanalyzing:r,reanalyzeError:i,onReanalyze:a,onPublish:o})=>{let{analysis:s,publication:c,stale:l}=e,{pullRequest:u,warnings:d}=s,{ref:f}=s.key;return(0,G.jsxs)(`header`,{className:`review-header`,children:[(0,G.jsxs)(`div`,{className:`review-title`,children:[(0,G.jsxs)(`p`,{className:`pr-meta`,children:[(0,G.jsxs)(`a`,{href:u?.url??Nl(f),target:`_blank`,rel:`noreferrer`,children:[f.repo.owner,`/`,f.repo.repo,` #`,f.number]}),u!==null&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`span`,{children:[` · `,u.author.name||u.author.id]}),(0,G.jsxs)(`span`,{children:[` · `,(0,G.jsx)(`code`,{children:u.sourceBranch}),` → `,(0,G.jsx)(`code`,{children:u.targetBranch})]})]})]}),(0,G.jsx)(`h1`,{className:`model-text`,children:u?.title??`Collecting the pull request…`}),t]}),(0,G.jsxs)(`div`,{className:`review-actions`,children:[n,c===null?(0,G.jsx)(`button`,{type:`button`,className:`button primary`,disabled:s.status!==`complete`,onClick:o,children:`Publish…`}):(0,G.jsxs)(`p`,{className:`published`,role:`status`,children:[(0,G.jsx)(`span`,{"aria-hidden":`true`,children:`✓`}),` `,c.url===null?`Published`:(0,G.jsx)(`a`,{href:c.url,target:`_blank`,rel:`noreferrer`,children:`Published`})]})]}),l&&(0,G.jsxs)(`div`,{className:`banner warning stale-banner`,role:`status`,children:[(0,G.jsx)(`span`,{children:`This PR has new commits since the analysis.`}),(0,G.jsx)(`button`,{type:`button`,className:`button`,disabled:r,onClick:a,children:r?`Starting…`:`Re-analyze`}),i!==null&&(0,G.jsx)(`span`,{className:`field-error`,role:`alert`,children:_u(i)})]}),d.length>0&&d.length<=sm&&(0,G.jsx)(`ul`,{className:`warnings`,"aria-label":`Warnings`,children:d.map(e=>(0,G.jsx)(`li`,{className:`banner warning`,children:e},e))}),d.length>sm&&(0,G.jsxs)(`details`,{className:`warnings banner warning`,children:[(0,G.jsxs)(`summary`,{children:[d.length,` warnings`]}),(0,G.jsx)(`ul`,{children:d.map(e=>(0,G.jsx)(`li`,{children:e},e))})]})]})},lm=e=>{let[t,n]=(0,H.useState)(new Set);return(0,H.useEffect)(()=>{if(typeof IntersectionObserver>`u`)return;n(new Set);let t=new Set,r=new Map,i=new IntersectionObserver(e=>{for(let n of e){let e=r.get(n.target);e!==void 0&&(n.isIntersecting?t.add(e):t.delete(e))}n(new Set(t))});for(let t of e){let e=document.getElementById(of(t));e!==null&&(r.set(e,t),i.observe(e))}return()=>i.disconnect()},[e]),t},um=({sections:e,index:t,decisionsOn:n,totals:r,reviewed:i,contractOnly:a,onContractOnly:o,mechanicalCount:s,onGo:c,onInView:l})=>{let u=(0,H.useId)(),d=(0,H.useRef)(null),[f,p]=(0,H.useState)([]),m=e.flatMap(e=>e.partIds).filter(e=>!a||t.items([e])[0]?.risk.riskClass===`contract`),h=m.join(`,`);(0,H.useEffect)(()=>p(m),[h]);let g=lm(f),_=(0,H.useRef)(l);return _.current=l,(0,H.useEffect)(()=>{_.current(f.filter(e=>g.has(e)));let e=d.current,t=e?.querySelector(`.rail-bar.in-view`);if(e==null||t==null)return;let n=t.offsetTop;(n<e.scrollTop||n>e.scrollTop+e.clientHeight-40)&&(e.scrollTop=Math.max(0,n-e.clientHeight/3))},[g,f]),(0,G.jsxs)(`aside`,{ref:d,className:`risk-rail`,"aria-labelledby":`${u}-title`,children:[(0,G.jsxs)(`div`,{className:`rail-header`,children:[(0,G.jsx)(`h2`,{id:`${u}-title`,children:`Map`}),(0,G.jsxs)(`p`,{className:`risk-totals`,children:[(0,G.jsxs)(`span`,{className:r.contract>0?`risk-total-contract`:void 0,children:[r.contract,` contract`]}),` `,`· `,r.logic,` logic · `,r.mechanical,` mechanical`]}),(0,G.jsxs)(`label`,{className:`contract-only`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:a,onChange:e=>o(e.target.checked)}),`Contract changes only`]})]}),(0,G.jsxs)(`ol`,{className:`rail-steps`,children:[e.map(e=>{let r=jf(e),o=e.partIds.filter(e=>!t.mechanical.has(e)),s=o.length>0&&o.every(e=>i.has(e));return(0,G.jsxs)(`li`,{children:[(0,G.jsxs)(`button`,{type:`button`,className:e.kind===`step`&&e.step.kind===`supporting`?`rail-step supporting`:`rail-step`,onClick:()=>c({kind:`section`,key:r}),children:[e.kind===`step`&&(0,G.jsx)(`span`,{className:`rail-step-number`,children:e.number}),` `,(0,G.jsx)(`span`,{className:`rail-step-title model-text`,title:e.kind===`step`?e.step.codeTitle===null?e.step.title:`${e.step.title} · ${e.step.codeTitle}`:void 0,children:e.kind===`step`?e.step.title:`Changes by file`}),s&&(0,G.jsx)(`span`,{className:`rail-tick`,role:`img`,"aria-label":`reviewed`,children:`✓`})]}),(0,G.jsx)(`ul`,{className:`rail-bars`,children:t.items(e.partIds).map(({id:e,hunk:r,file:o,risk:s})=>{let l=t.mechanical.has(e),u=l?`mechanical`:s.riskClass,d=!l&&i.has(e),f=n(e),p=u===`contract`&&s.source===`rule`,m=[u,f.length>0&&`${f.length} ${f.length===1?`decision`:`decisions`}`],h=[`rail-hunk`,g.has(e)&&`in-view`,a&&u!==`contract`&&`dimmed`];return(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{type:`button`,className:h.filter(Boolean).join(` `),"aria-label":`${o.path}, ${Yu(r)}, ${u}${d?`, reviewed`:``}`,"aria-current":g.has(e)?`location`:void 0,onClick:()=>c({kind:`hunk`,partId:e}),children:[(0,G.jsxs)(`span`,{className:`rail-bar risk-${u}${d?` reviewed`:``}`,style:{height:Pf(r)},children:[p&&(0,G.jsx)(`span`,{className:`rail-mark mark-rule`,title:s.reason,children:(0,G.jsxs)(`span`,{className:`visually-hidden`,children:[`Rule: `,s.reason]})}),f.map(e=>(0,G.jsx)(`span`,{className:`rail-mark mark-decision`,title:e.title,children:(0,G.jsxs)(`span`,{className:`visually-hidden`,children:[`Decision: `,e.title]})},e.id))]}),(0,G.jsxs)(`span`,{className:`rail-hunk-text`,children:[(0,G.jsxs)(`span`,{className:`rail-hunk-file`,children:[o.path.split(`/`).at(-1),` `,Yu(r).replace(/^lines /,``)]}),(0,G.jsx)(`span`,{className:`rail-hunk-meta`,children:m.filter(Boolean).join(` · `)})]}),d&&(0,G.jsx)(`span`,{className:`rail-bar-tick`,"aria-hidden":`true`,children:`✓`})]})},e)})})]},r)}),(0,G.jsx)(`li`,{children:(0,G.jsx)(`button`,{type:`button`,className:`rail-step mechanical`,onClick:()=>c({kind:`mechanical`}),children:(0,G.jsxs)(`span`,{className:`rail-step-title`,children:[`Proved mechanical (`,s,`)`]})})})]}),(0,G.jsxs)(`ul`,{className:`rail-legend`,"aria-label":`Legend`,children:[(0,G.jsxs)(`li`,{children:[(0,G.jsx)(`span`,{className:`legend-swatch risk-contract`}),` Contract`]}),(0,G.jsxs)(`li`,{children:[(0,G.jsx)(`span`,{className:`legend-swatch risk-logic`}),` Logic`]}),(0,G.jsxs)(`li`,{children:[(0,G.jsx)(`span`,{className:`legend-swatch risk-mechanical`}),` Mechanical`]}),(0,G.jsxs)(`li`,{children:[(0,G.jsx)(`span`,{className:`rail-mark mark-decision`}),` Decision`]}),(0,G.jsxs)(`li`,{children:[(0,G.jsx)(`span`,{className:`rail-mark mark-rule`}),` Contract rule`]})]})]})},dm=[`map`,`overview`],fm=new Set([`move-file`,`open-file`]),pm=[{keys:[`j`],action:`next-hunk`,description:`Next hunk`,layouts:[`map`]},{keys:[`k`],action:`previous-hunk`,description:`Previous hunk`,layouts:[`map`]},{keys:[`n`],action:`next-step`,description:`Next tour step`,layouts:[`map`]},{keys:[`p`],action:`previous-step`,description:`Previous tour step`,layouts:[`map`]},{keys:[`o`],action:`open-call`,description:`Open or close the hunk's first call`,layouts:[`map`]},{keys:[`x`],action:`toggle-reviewed`,description:`Mark the hunk reviewed and go to the next`,layouts:[`map`]},{keys:[`]`],action:`next-unreviewed`,description:`Next unreviewed hunk`,layouts:[`map`]},{keys:[`[`],action:`previous-unreviewed`,description:`Previous unreviewed hunk`,layouts:[`map`]},{keys:[`a`],action:`approve`,description:`Approve the selected decision`,layouts:[`map`]},{keys:[`r`],action:`reject`,description:`Reject the selected decision`,layouts:[`map`]},{keys:[`c`],action:`comment`,description:`Comment on the selected decision, or on the focused hunk`,layouts:[`map`]},{keys:[`Escape`],action:`escape`,description:`Clear the selection, go back to where a link was followed from, or back to the overview`,layouts:[`map`]},{keys:[`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`],action:`move-file`,description:`Move between files`,layouts:[`overview`]},{keys:[`Enter`],action:`open-file`,description:`Open the file's code in the map, or a group of files in place`,layouts:[`overview`]},{keys:[`⌘K`,`t`],action:`jump`,description:`Jump to anything`,layouts:dm},{keys:[`v`],action:`toggle-layout`,description:`Map or overview`,layouts:dm},{keys:[`?`],action:`help`,description:`Show these shortcuts`,layouts:dm}],mm=e=>new Map(pm.filter(({layouts:t,action:n})=>t.includes(e)&&!fm.has(n)).flatMap(({keys:e,action:t})=>e.map(e=>[e,t]))),hm={map:mm(`map`),overview:mm(`overview`)},gm=e=>e instanceof HTMLElement&&(e.isContentEditable||[`INPUT`,`TEXTAREA`,`SELECT`].includes(e.tagName)),_m=(e,t)=>gm(e.target)||e.altKey?null:e.metaKey||e.ctrlKey?e.key.toLowerCase()===`k`&&!e.shiftKey?`jump`:null:hm[t].get(e.key)??null,vm=(e,t,n)=>{let r=(0,H.useRef)(n);(0,H.useEffect)(()=>{r.current=n}),(0,H.useEffect)(()=>{if(!e)return;let n=e=>{let n=_m(e,t);n!==null&&(e.preventDefault(),r.current(n))};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,t])},ym={Escape:`Esc`,ArrowRight:`→`,ArrowLeft:`←`,ArrowUp:`↑`,ArrowDown:`↓`},bm=[{title:`Map`,layouts:[`map`]},{title:`Overview`,layouts:[`overview`]},{title:`Both layouts`,layouts:[`map`,`overview`]}],xm=({onClose:e})=>(0,G.jsxs)(af,{title:`Keyboard shortcuts`,onClose:e,className:`shortcuts-dialog`,children:[bm.map(({title:e,layouts:t})=>(0,G.jsxs)(`section`,{"aria-label":e,children:[(0,G.jsx)(`h3`,{children:e}),(0,G.jsx)(`dl`,{className:`shortcut-list`,children:pm.filter(e=>e.layouts.length===t.length&&t.every(t=>e.layouts.includes(t))).map(({keys:e,description:t})=>(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:e.map(e=>(0,G.jsx)(`kbd`,{children:ym[e]??e},e))}),(0,G.jsx)(`dd`,{children:t})]},t))})]},e)),(0,G.jsx)(`p`,{className:`muted`,children:`Shortcuts don't work while you're typing in a text field.`})]}),Sm=({pullRequest:e,tickets:t,missingTicketKeys:n})=>{let r=e.description.trim();return(0,G.jsxs)(`div`,{className:`intent-panel stated-intent`,children:[r===``?(0,G.jsx)(`p`,{className:`muted`,children:`The pull request has no description.`}):(0,G.jsx)(`p`,{className:`pr-description`,children:r}),(t.length>0||n.length>0)&&(0,G.jsxs)(`ul`,{className:`chips`,"aria-label":`Tickets`,children:[t.map(e=>(0,G.jsx)(`li`,{className:`chip`,children:(0,G.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,children:[e.key,` · `,e.summary]})},e.key)),n.map(e=>(0,G.jsxs)(`li`,{className:`chip`,title:`Jira didn't return this ticket, or Jira isn't configured`,children:[e,` · not fetched`]},e))]}),e.commits.length>0&&(0,G.jsxs)(`details`,{className:`intent-details`,children:[(0,G.jsxs)(`summary`,{children:[`Commits (`,e.commits.length,`)`]}),(0,G.jsx)(`ol`,{className:`commit-list`,children:e.commits.map(e=>(0,G.jsxs)(`li`,{children:[(0,G.jsx)(`code`,{children:e.sha.slice(0,7)}),` `,e.message.split(`
67
- `)[0]]},e.sha))})]})]})},Cm=`megareviewer:`,wm=e=>{try{let t=window.localStorage.getItem(Cm+e);return t===null?void 0:JSON.parse(t)}catch{return}},Tm=(e,t)=>{try{window.localStorage.setItem(Cm+e,JSON.stringify(t))}catch{}},Em=(e,t,n)=>{let[r,i]=(0,H.useState)(()=>({key:e,value:n(wm(e))??t}));return[r.key===e?r.value:n(wm(e))??t,(0,H.useCallback)(r=>i(i=>{let a=r(i.key===e?i.value:n(wm(e))??t);return Tm(e,a),{key:e,value:a}}),[e,t,n])]},Dm=e=>typeof e==`boolean`?e:void 0,Om=e=>Array.isArray(e)&&e.every(e=>typeof e==`string`)?e:void 0,km={intent:`Intent`,risk:`Risk`,decisions:`Decisions`,tour:`Tour`},Am=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${Math.round(e/1e3)}k`:`${e}`,jm=e=>`$${e.toFixed(2)}`,Mm=e=>e.inputTokens+e.cacheWriteTokens,Nm=({usage:e})=>{let t=(0,H.useId)();if(e.length===0)return null;let n=t=>e.reduce((e,n)=>e+t(n),0);return(0,G.jsxs)(`footer`,{className:`usage-footer`,children:[(0,G.jsxs)(`button`,{type:`button`,className:`usage`,"aria-describedby":`${t}-breakdown`,children:[`Usage: `,Am(n(Mm)),` tokens in ·`,` `,Am(n(e=>e.cacheReadTokens)),` cache read ·`,` `,Am(n(e=>e.outputTokens)),` out · `,jm(n(e=>e.costUsd))]}),(0,G.jsxs)(`table`,{id:`${t}-breakdown`,className:`usage-breakdown`,role:`tooltip`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{scope:`col`,children:`Pass`}),(0,G.jsx)(`th`,{scope:`col`,children:`In`}),(0,G.jsx)(`th`,{scope:`col`,children:`Cache read`}),(0,G.jsx)(`th`,{scope:`col`,children:`Out`}),(0,G.jsx)(`th`,{scope:`col`,children:`Cost`})]})}),(0,G.jsx)(`tbody`,{children:e.map(e=>(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{scope:`row`,children:km[e.pass]}),(0,G.jsx)(`td`,{children:Am(Mm(e))}),(0,G.jsx)(`td`,{children:Am(e.cacheReadTokens)}),(0,G.jsx)(`td`,{children:Am(e.outputTokens)}),(0,G.jsx)(`td`,{children:jm(e.costUsd)})]},e.pass))})]})]})},Pm={verdict:`pending`,comment:``},Fm=(e,t)=>{let{client:n}=cu(),r=(0,H.useRef)(new Map),i=(0,H.useRef)(new Map),a=(0,H.useRef)(new Map),o=(0,H.useRef)(new Map),s=(0,H.useRef)(new Set),[,c]=(0,H.useReducer)(e=>e+1,0),[l,u]=(0,H.useState)(new Map),[d,f]=(0,H.useState)(null),p=(0,H.useRef)(t);(0,H.useEffect)(()=>{p.current=t},[t]);let m=(0,H.useCallback)((e,t)=>{let n=i.current.get(e)??t.find(t=>t.decisionId===e);return n===void 0?Pm:{verdict:n.verdict,comment:n.comment}},[]),h=(0,H.useCallback)(e=>r.current.get(e)??m(e,p.current),[m]),g=e=>r.current.get(e)??m(e,t),_=(0,H.useCallback)((e,t)=>{u(n=>new Map(n).set(e,t))},[]),v=(0,H.useCallback)(async(t,o)=>{let s=h(t),l=(a.current.get(t)??0)+1;a.current.set(t,l),_(t,`saving`);let u=await n.putVerdict(e,t,s);if(a.current.get(t)===l){if(u.ok)i.current.set(t,{verdict:u.value.verdict,comment:u.value.comment}),_(t,`saved`),f(e=>e?.decisionId===t?null:e);else if(_(t,`failed`),f({decisionId:t,what:o,message:_u(u.error)}),o===`verdict`){let e=r.current.get(t)??s;r.current.set(t,{...e,verdict:m(t,p.current).verdict}),c()}}},[e,n,h,m,_]),y=(0,H.useCallback)((e,t)=>{let n=v(e,t);return s.current.add(n),n.finally(()=>s.current.delete(n)),n},[v]),b=(0,H.useCallback)(async()=>{for(let[e,t]of o.current)clearTimeout(t),y(e,`comment`);o.current.clear(),await Promise.all(s.current)},[y]),x=(0,H.useCallback)((e,t)=>{r.current.set(e,{...h(e),verdict:t}),clearTimeout(o.current.get(e)),o.current.delete(e),c(),y(e,`verdict`)},[h,y]),S=(0,H.useCallback)((e,t)=>{r.current.set(e,{...h(e),comment:t}),clearTimeout(o.current.get(e)),o.current.set(e,setTimeout(()=>{o.current.delete(e),y(e,`comment`)},500)),_(e,`waiting`),c()},[h,y,_]);return(0,H.useEffect)(()=>{let e=o.current;return()=>{for(let[t,n]of e)clearTimeout(n),y(t,`comment`);e.clear()}},[y]),{draftOf:g,setVerdict:x,setComment:S,statusOf:e=>l.get(e)??null,flush:b,failure:d,dismissFailure:()=>f(null)}},Im=[],Lm=[],Rm=e=>wl.array().safeParse(e).data,zm=({analysisId:e})=>{let[t,n]=(0,H.useState)(0),r=(0,H.useCallback)(()=>n(e=>e+1),[]);return(0,G.jsx)(Bm,{analysisId:e,restart:r},`${e}/${t}`)},Bm=({analysisId:e,restart:t})=>{let{view:n,error:r,refetch:i}=pu(e);return n===null?r?.code===`not-found`?(0,G.jsxs)(`div`,{className:`narrow`,children:[(0,G.jsx)(`h1`,{children:`Analysis not found`}),(0,G.jsx)(`p`,{children:_u(r)}),(0,G.jsx)(`p`,{children:(0,G.jsx)(zu,{to:`/`,children:`Pick a pull request to review`})})]}):r===null?(0,G.jsx)(Vm,{}):(0,G.jsxs)(`div`,{className:`narrow`,children:[(0,G.jsxs)(`p`,{className:`banner danger`,role:`alert`,children:[`Couldn't load the analysis. `,_u(r)]}),(0,G.jsx)(`button`,{type:`button`,className:`button`,onClick:()=>void i(),children:`Try again`})]}):(0,G.jsx)(Xm,{view:n,refetch:i,restart:t})},Vm=()=>(0,G.jsxs)(`div`,{className:`review-page`,role:`status`,"aria-busy":`true`,"aria-label":`Loading the analysis`,children:[(0,G.jsx)(`div`,{className:`skeleton skeleton-title`}),(0,G.jsxs)(`div`,{className:`review-body map`,children:[(0,G.jsx)(`div`,{className:`skeleton skeleton-main`}),(0,G.jsx)(`div`,{className:`skeleton skeleton-rail`})]})]}),Hm=[],Um=({analysis:e})=>{let{checkout:t,pullRequest:n}=e;if(t===`read`||n===null)return null;let{ref:r,headSha:i}=n;return(0,G.jsxs)(`p`,{className:`checkout-note muted`,children:[`Code outside the pull request that calls what it changes isn't shown:`,` `,t===`missing-commit`?(0,G.jsxs)(G.Fragment,{children:[`the local checkout doesn't have the head commit `,(0,G.jsx)(`code`,{children:i.slice(0,7)}),`. Run`,` `,(0,G.jsx)(`code`,{children:`git fetch`}),` in it`,r.repo.host===`github`&&(0,G.jsxs)(G.Fragment,{children:[`, or `,(0,G.jsxs)(`code`,{children:[`git fetch origin pull/`,r.number,`/head`]}),` for a pull request from a fork`]}),`, then open the pull request again.`]}):(0,G.jsxs)(G.Fragment,{children:[`megareviewer didn't run in a checkout of `,r.repo.owner,`/`,r.repo.repo,`. Start it in one, or pass `,(0,G.jsx)(`code`,{children:`--checkout <dir>`}),`, then open the pull request again.`]})]})},Wm=[],Gm=[],Km=e=>[...e??[]].map(([e,t])=>`${e}${t.map(e=>e.kind[0]+e.symbol).join()}`).join(`;`),qm=new WeakMap,Jm=0,Ym=e=>{let t=qm.get(e);return t===void 0?(Jm+=1,qm.set(e,Jm),Jm):t},Xm=({view:e,refetch:t,restart:n})=>{let{client:r}=cu(),i=du().status?.model.enabled!==!1,{analysis:a,publication:o,isAuthor:s}=e,c=a.id,l=a.status===`complete`,u=o!==null||!l,d=(0,H.useMemo)(()=>Df(a),[a]),f=(0,H.useMemo)(()=>kf(a,d),[a,d]),p=(0,H.useMemo)(()=>Af(a,f,d),[a,f,d]),m=(0,H.useMemo)(()=>p.flatMap(e=>e.partIds),[p]),h=(0,H.useMemo)(()=>Rf(a,d),[a,d]),g=Ff(h),_=(0,H.useMemo)(()=>Lf(a,d),[a,d]),v=(0,H.useMemo)(()=>new Set(a.risk.flatMap(e=>e.riskClass===`contract`?[e.hunkId]:[])),[a.risk]),y=(0,H.useCallback)(e=>v.has(Sc(e)),[v]),b=(0,H.useMemo)(()=>Mf(a.decisions,m,d),[a.decisions,m,d]),x=(0,H.useMemo)(()=>{let e=new Map;for(let t of a.decisions)for(let n of new Set(t.hunkIds.flatMap(d.partsOf)))e.set(n,[...e.get(n)??[],t]);return e},[a.decisions,d]),S=(0,H.useMemo)(()=>a.callGraph.filter(e=>e.use!==`type`),[a.callGraph]),ee=(0,H.useMemo)(()=>Nf(S,d),[S,d]),[te,C]=(0,H.useState)([]),w=(0,H.useMemo)(()=>Qp(a,f,new Set(te)),[a,f,te]),[T,ne]=Em(`review-layout`,`map`,wf),[re,ie]=Em(`contract-only:${c}`,!1,Dm),ae=(0,H.useMemo)(()=>Zd(p.map(e=>e.partIds.filter(e=>!re||y(e))),ee,(e,t)=>d.parts.get(e)?.hunk.lines.find(e=>e.kind!==`del`&&e.newLine===t)?.text),[p,ee,d,re,y]),oe=(0,H.useMemo)(()=>zf(S,d,m),[S,d,m]),se=(0,H.useCallback)(e=>oe.get(e)??Wm,[oe]),ce=(0,H.useMemo)(()=>{let e=new Map;for(let t of a.unchangedCallers)e.set(t.partId,[...e.get(t.partId)??[],t]);return e},[a.unchangedCallers]),le=(0,H.useCallback)(e=>ce.get(e)??Gm,[ce]),ue=(0,H.useMemo)(()=>{let e=new Map;for(let t of p)if(t.kind===`step`)for(let n of t.partIds)e.has(n)||e.set(n,`step ${t.number}: ${t.step.title}`);return t=>e.get(t)??null},[p]),[E,de]=(0,H.useState)(null),[fe,pe]=(0,H.useState)(null),me=(0,H.useRef)(null),[he,ge]=(0,H.useState)(null),[_e,ve]=(0,H.useState)([]),[ye,be]=(0,H.useState)(null),[xe,Se]=(0,H.useState)(new Set),[Ce,D]=(0,H.useState)(0),[O,we]=(0,H.useState)(new Set),[Te,Ee]=(0,H.useState)(null),[De,k]=(0,H.useState)(null),A=(0,H.useRef)([]),[Oe,ke]=(0,H.useState)(!1),[Ae,je]=(0,H.useState)(!1),[Me,Ne]=(0,H.useState)(!1),[Pe,Fe]=(0,H.useState)(!1),Ie=(0,H.useRef)(null),Le=(0,H.useCallback)(e=>{Ie.current=e},[]),[Re,ze]=Em(`reviewed-hunks`,Im,Om),Be=(0,H.useMemo)(()=>Vf(Re,d),[Re,d]),j=(0,H.useMemo)(()=>Bf(p,d),[p,d]),Ve=Hf(j,Be),He=(0,H.useCallback)((e,t)=>ze(n=>Q(n,e,t,d).slice(-5e3)),[ze,d]),Ue=(0,H.useMemo)(()=>Uf(p,d),[p,d]),We=(0,H.useCallback)(e=>Ue.get(e)??null,[Ue]),[Ge,Ke]=Em(`hunk-comments:${c}`,Lm,Rm),[qe,M]=(0,H.useState)(null),Je=(0,H.useMemo)(()=>Wf(Ge,d),[Ge,d]),Ye=(0,H.useCallback)(e=>Je.get(e)??Lm,[Je]),Xe=(0,H.useCallback)((e,t)=>Ke(n=>{let r=Sc(e),i=e=>e.hunkId===r&&e.side===t.side&&e.line===t.line,a={hunkId:r,...t};return n.some(i)?t.body===``?n.filter(e=>!i(e)):n.map(e=>i(e)?a:e):t.body===``?n:[...n,a]}),[Ke]),Ze=(0,H.useCallback)((e,t)=>M(t===null?null:{partId:e,place:t}),[]),Qe=Fm(c,e.verdicts),$e=e=>Ee(t=>({id:e,n:(t?.n??0)+1})),et=e=>!re||y(e),tt=()=>{if(T===`overview`)return null;let e=A.current;return E!==null&&(e.length===0||e.includes(E))?E:e[0]??E},nt=(0,H.useCallback)(e=>{de(e);let t=b.cards.get(e)??Hm;be(e=>t.some(t=>t.id===e)?e:t[0]?.id??null)},[b]),rt=e=>{let t=w.placeOf.get(e);t!==void 0&&(t.startsWith(`group:`)&&C(e=>[...e,t]),pe(t=>({key:e,n:(t?.n??0)+1})))},it=(e,t=T)=>{if(t===`overview`){let t=d.parts.get(e)?.file.path;t!==void 0&&rt(t)}else et(e)||ie(()=>!1),$e(m.includes(e)?of(e):Qf)},at=e=>{let t=a.decisions.find(t=>t.id===e),n=b.cardHunk.get(e);Se(new Set((t?.hunkIds??[]).flatMap(d.partsOf))),T===`overview`?n!==void 0&&it(n):(n!==void 0&&!et(n)&&ie(()=>!1),$e(ef(e))),be(e)},ot=e=>{let t=a.intent?.mismatches[e];if(t===void 0)return;let n=t.hunkIds.flatMap(d.partsOf).sort((e,t)=>m.indexOf(e)-m.indexOf(t));Se(new Set(n)),D(e+1);let[r]=n;r!==void 0&&it(r)},st=e=>{let t=p.find(t=>jf(t)===e);if(t!==void 0){if(T===`overview`){let e=t.partIds.find(e=>!d.mechanical.has(e));e!==void 0&&it(e)}else re&&!t.partIds.some(y)&&ie(()=>!1),de(null),k(t.partIds.find(et)??null),$e(Zf(e))}},ct=()=>{re&&ie(()=>!1),$e(Qf)},lt=e=>{let t=tt();t!==null&&ve(e=>[...e,t]),it(e)},ut=()=>{let e=tt();ne(()=>`overview`),ge(null),e!==null&&it(e,`overview`)},dt=e=>{if(e.kind===`group`){C(t=>[...t,e.key]);return}let[t]=e.partIds;t!==void 0&&(ne(()=>`map`),ge(e.key),de(t),it(t,`map`))},ft=()=>{if(T===`map`)return ut();let e=[...w.rows.flat(),...w.strip].find(e=>e.key===me.current);if(e!==void 0&&e.kind===`file`)return dt(e);ne(()=>`map`)},pt=m.filter(et),mt=e=>{if(pt.length===0)return;let t=E===null?-1:pt.indexOf(E),n=De??A.current.find(et)??null,r=n===null?-1:pt.indexOf(n),i=t===-1?r===-1?e===1?0:pt.length-1:e===1?r:r-1:t+e;k(null);let a=pt[Math.min(Math.max(i,0),pt.length-1)];a!==void 0&&$e(of(a))},ht=e=>{let t=p.filter(e=>e.partIds.some(et)),n=tt()??De,r=t[t.findIndex(e=>n!==null&&e.partIds.includes(n))+e];r!==void 0&&st(jf(r))},gt=e=>{let t=j.filter(et),n=tt(),r=n===null?e===1?-1:t.length:t.indexOf(n);for(let n=r+e;n>=0&&n<t.length;n+=e){let e=t[n];if(e!==void 0&&!Be.has(e))return it(e)}},_t=(e,t)=>{if(u)return;let n=Qe.draftOf(e).verdict;Qe.setVerdict(e,n===t?`pending`:t)},vt=(0,H.useCallback)(e=>we(t=>{let n=new Set(t);return n.delete(e)||n.add(e),n}),[]);vm(!Oe&&!Ae&&!Me&&!Pe,T,e=>{let t=tt();switch(e){case`next-hunk`:return mt(1);case`previous-hunk`:return mt(-1);case`next-step`:return ht(1);case`previous-step`:return ht(-1);case`open-call`:{let e=[...t===null?[]:ae.get(t)??[]].sort(([e],[t])=>e-t).flatMap(([,e])=>e),n=e.find(e=>e.kind===`chip`)?.calls[0];if(t!==null&&n!==void 0)return vt($f([t],n));let r=e[0]?.calls[0];r!==void 0&&lt(r.toPartId);return}case`approve`:ye!==null&&_t(ye,`approved`);return;case`reject`:ye!==null&&_t(ye,`rejected`);return;case`toggle-reviewed`:t!==null&&!d.mechanical.has(t)&&(He(t,!Be.has(t)),mt(1));return;case`next-unreviewed`:return gt(1);case`previous-unreviewed`:return gt(-1);case`jump`:Ne(!0);return;case`toggle-layout`:return ft();case`comment`:{if(ye!==null&&Ie.current!==null){Ie.current.focus();return}let e=t===null?void 0:d.parts.get(t),n=e?.hunk.lines.find(e=>e.kind!==`context`);if(u||e===void 0||n===void 0)return;let r=Id(n);r!==null&&t!==null&&M({partId:t,place:r});return}case`escape`:{if(xe.size>0)return Se(new Set);let e=_e.at(-1);if(T!==`map`)return;e===void 0?he!==null&&(ne(()=>`overview`),pe(e=>({key:he,n:(e?.n??0)+1})),ge(null)):(ve(e=>e.slice(0,-1)),it(e));return}case`help`:je(!0);return}});let yt=a.pullRequest?.url??Nl(a.key.ref),bt=mu(r.startAnalysis),xt=mu(r.retryAnalysis),St=e=>{e===c?n():wu(xu(e))},Ct=async()=>{await Qe.flush(),ke(!0)},wt=a.decisions.filter(e=>Qe.draftOf(e.id).verdict===`pending`).length,Tt=Qe.failure===null?``:a.decisions.find(e=>e.id===Qe.failure?.decisionId)?.title??``,Et=e=>(0,G.jsx)(tf,{decision:e,draft:Qe.draftOf(e.id),status:Qe.statusOf(e.id),selected:ye===e.id,readOnly:u,commentRef:Le,onSelect:be,onVerdict:Qe.setVerdict,onComment:Qe.setComment},e.id),Dt=e=>{let t=b.cards.get(e)??Hm,n=b.mentions.get(e)??Hm;return t.length===0&&n.length===0?null:(0,G.jsxs)(`div`,{className:`hunk-decisions`,children:[t.map(Et),n.map(e=>(0,G.jsx)(nf,{decision:e,onGo:kt.goToDecision},e.id))]})},Ot=(0,H.useRef)({follow:lt,goToDecision:at});Ot.current={follow:lt,goToDecision:at};let kt=(0,H.useMemo)(()=>({follow:e=>Ot.current.follow(e),goToDecision:e=>Ot.current.goToDecision(e)}),[]),At=e=>{let t=[Ym(a),u,Be.has(e),xe.has(e),Km(ae.get(e)),qe?.partId===e?`${qe.place.side}${qe.place.line}`:``,...Ye(e).map(e=>`${e.side}${e.line}${e.body}`)];for(let n of b.cards.get(e)??Hm){let e=Qe.draftOf(n.id);t.push(n.id,e.verdict,e.comment,Qe.statusOf(n.id)),t.push(ye===n.id)}let n=[...O].filter(t=>t.startsWith(`${e}@`)||t.startsWith(`${e}>`));return n.length>0&&t.push(...n,...Re,...xe),t.join(`\0`)},jt={index:d,calls:ee,plan:ae,callersOf:se,unchangedOf:le,stepOf:ue,onFollow:kt.follow,reviewed:Be,onReviewed:He,partHeaderOf:We,highlighted:xe,commentsOf:Ye,openComment:qe,onOpenComment:Ze,onComment:u?void 0:Xe,onFocusHunk:nt,decisionsOn:Dt},Mt=(0,G.jsxs)(G.Fragment,{children:[i&&a.status===`running`&&a.stages.decisions!==`done`&&(0,G.jsx)(`p`,{className:`muted`,children:`Finding the decisions the code makes…`}),a.stages.decisions===`done`&&!l&&o===null&&a.decisions.length>0&&(0,G.jsx)(`p`,{className:`muted`,children:`You can give verdicts once the analysis is complete.`}),b.unplaced.length>0&&(0,G.jsx)(`section`,{className:`unplaced-decisions`,"aria-label":`Decisions on no change shown here`,children:b.unplaced.map(Et)})]}),Nt=(0,H.useMemo)(()=>xf(a,f,d),[a,f,d]),Pt=e=>{switch(Ne(!1),e.kind){case`decision`:return at(e.decisionId);case`mismatch`:return ot(e.index);case`hunk`:return Se(new Set),it(e.partId);case`step`:return st(e.stepId);case`mechanical`:T!==`map`&&ne(()=>`map`),ct();return}},Ft=e=>{if(e.kind===`hunk`)return it(e.partId);if(e.kind===`section`)return st(e.key);ct()},It=(0,H.useCallback)(e=>{A.current=e},[]);return(0,G.jsxs)(`div`,{className:`review-page layout-${T}`,children:[(0,G.jsx)(cm,{view:e,intent:(0,G.jsx)(df,{analysis:a,modelOn:i,mismatchAt:Ce,onMismatch:ot,onDetails:()=>Fe(!0)}),tools:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`fieldset`,{className:`layout-toggle`,children:[(0,G.jsx)(`legend`,{className:`visually-hidden`,children:`Layout`}),(0,G.jsx)(`button`,{type:`button`,className:`button`,"aria-pressed":T===`map`,onClick:()=>T!==`map`&&ft(),children:`Map`}),(0,G.jsx)(`button`,{type:`button`,className:`button`,"aria-pressed":T===`overview`,onClick:()=>T!==`overview`&&ft(),children:`Overview`})]}),(0,G.jsxs)(`button`,{type:`button`,className:`button jump-button`,onClick:()=>Ne(!0),children:[`Jump to… `,(0,G.jsx)(`kbd`,{children:`⌘K`})]}),(0,G.jsxs)(`p`,{className:`review-progress`,"aria-live":`polite`,children:[Ve.done,` of `,Ve.total,` `,Ve.total===1?`hunk`:`hunks`,` reviewed`]})]}),reanalyzing:bt.pending,reanalyzeError:bt.error,onReanalyze:async()=>{let e=await bt.run({url:yt});e.ok&&St(e.value.analysisId)},onPublish:()=>void Ct()}),!l&&(0,G.jsx)(nm,{stages:a.stages,filesFetched:a.filesFetched}),a.error!==null&&(0,G.jsxs)(`div`,{className:`banner danger failed-banner`,role:`alert`,children:[(0,G.jsxs)(`p`,{children:[`The analysis failed at the `,rm(a.error.stage).toLowerCase(),` stage:`,` `,a.error.message]}),xt.error!==null&&(0,G.jsxs)(`p`,{children:[`Couldn't retry. `,_u(xt.error)]}),(0,G.jsx)(`button`,{type:`button`,className:`button`,disabled:xt.pending,onClick:async()=>{let e=await xt.run(c);e.ok&&St(e.value.analysisId)},children:xt.pending?`Retrying…`:`Retry`})]}),Qe.failure!==null&&(0,G.jsxs)(`div`,{className:`banner danger verdict-failure`,role:`alert`,children:[(0,G.jsxs)(`p`,{children:[`Couldn't save your `,Qe.failure.what,` on “`,Tt,`”.`,` `,Qe.failure.message]}),(0,G.jsx)(`button`,{type:`button`,className:`button quiet`,onClick:Qe.dismissFailure,children:`Dismiss`})]}),a.stages.prep===`done`?T===`map`?(0,G.jsxs)(`div`,{className:`review-body map`,children:[(0,G.jsx)(lp,{analysis:a,sections:p,deps:jt,contractOnly:re,isContract:y,openCalls:O,onToggleCall:vt,before:Mt,trailingProofs:h,mechanicalCount:g,scrollRequest:Te,signatureOf:At}),(0,G.jsx)(um,{sections:p,index:d,decisionsOn:e=>x.get(e)??Hm,totals:_,reviewed:Be,contractOnly:re,onContractOnly:e=>ie(()=>e),mechanicalCount:g,onGo:Ft,onInView:It})]}):(0,G.jsx)(`div`,{className:`review-body overview-body`,children:(0,G.jsx)(Fp,{overview:w,reviewed:Be,focusKey:fe,onOpen:dt,expandedGroups:te,onCollapse:e=>C(t=>t.filter(t=>t!==e)),onFocusNode:e=>{me.current=e}})}):(0,G.jsx)(`section`,{className:`main-area`,"aria-busy":a.status===`running`,children:(0,G.jsx)(`p`,{className:`muted`,children:a.status===`running`?`Reading the diff…`:`The diff couldn't be read, so there are no changes to show.`})}),(0,G.jsx)(Nm,{usage:a.usage}),Oe&&(0,G.jsx)(om,{analysisId:c,isAuthor:s,pendingCount:wt,hunkComments:Ge,chooseVerdict:a.decisions.length===0,onClose:()=>ke(!1),onPublished:()=>{ke(!1),t()}}),Ae&&(0,G.jsx)(xm,{onClose:()=>je(!1)}),Me&&(0,G.jsx)(Cf,{items:Nt,onPick:Pt,onClose:()=>Ne(!1)}),Pe&&(0,G.jsxs)(af,{title:a.intent===null?`What was asked`:`Intent`,onClose:()=>Fe(!1),className:`intent-dialog`,children:[a.intent===null?a.pullRequest!==null&&(0,G.jsx)(Sm,{pullRequest:a.pullRequest,tickets:a.tickets,missingTicketKeys:a.missingTicketKeys}):(0,G.jsx)(gf,{intent:a.intent,tickets:a.tickets,missingTicketKeys:a.missingTicketKeys,onSelectMismatch:e=>{Fe(!1),ot(e)}}),(0,G.jsx)(Um,{analysis:a})]}),(0,G.jsxs)(`p`,{className:`shortcut-hint muted`,children:[`Press `,(0,G.jsx)(`kbd`,{children:`?`}),` for keyboard shortcuts.`]})]})},Zm=(e,t)=>{if(t!==null)return{tone:`danger`,label:`Disconnected`,detail:_u(t)};if(e===null)return{tone:`muted`,label:`Connecting…`,detail:``};let n=`megareviewer ${e.version}`,{github:r,bitbucket:i}=e.hosts;if(!r.configured&&!i.configured)return{tone:`warning`,label:`Setup needed`,detail:n};let a=[{name:`GitHub`,error:r.error},{name:`Bitbucket`,error:i.error}].flatMap(({name:e,error:t})=>t===null?[]:[{name:e,error:t}]);if(a.length>0){let e=a.map(({name:e})=>e).join(` and `);return{tone:`warning`,label:a.length===1?`${e} problem`:`${e} problems`,detail:[...a.map(({name:e,error:t})=>`${e}: ${t}`),n].join(`
68
- `)}}return{tone:`ok`,label:`Ready`,detail:n}},Qm=({status:e,error:t})=>{let n=Zm(e,t);return(0,G.jsxs)(`header`,{className:`app-header`,children:[(0,G.jsx)(zu,{to:`/`,className:`brand`,children:`megareviewer`}),(0,G.jsxs)(`span`,{className:`status-indicator`,role:`status`,title:n.detail,children:[(0,G.jsx)(`span`,{className:`status-dot tone-${n.tone}`,"aria-hidden":`true`}),n.label]})]})},$m=()=>(0,G.jsxs)(`div`,{className:`narrow`,children:[(0,G.jsx)(`h1`,{children:`Page not found`}),(0,G.jsxs)(`p`,{children:[`There's nothing at this address. `,(0,G.jsx)(zu,{to:`/`,children:`Go to your pull requests`}),`.`]})]}),eh=(e,t)=>Object.entries(e).find(([e])=>/([^/]+)\/playground\.tsx$/.exec(e)?.[1]===t)?.[1]??null,th=({modules:e,name:t})=>{let n=eh(e,t),[r,i]=(0,H.useState)();return(0,H.useEffect)(()=>{let e=!0;return n?.().then(n=>{e&&i({name:t,Component:n.default})}),()=>{e=!1}},[n,t]),n===null?(0,G.jsxs)(`p`,{children:[`No playground named “`,t,`”.`]}):r?.name===t?(0,G.jsx)(r.Component,{}):(0,G.jsx)(`p`,{className:`muted`,children:`Loading playground…`})},nh=({reason:e})=>(0,G.jsxs)(`main`,{className:`page narrow`,children:[(0,G.jsx)(`h1`,{children:`Open megareviewer from your terminal`}),e===`missing`?(0,G.jsxs)(`p`,{children:[`This page needs the link megareviewer printed when it started. It looks like`,` `,(0,G.jsx)(`code`,{children:`http://127.0.0.1:4823/?token=…`}),`. Copy it from your terminal and open it.`]}):(0,G.jsx)(`p`,{children:`This page's session has ended, usually because megareviewer was restarted. Open the new link printed in your terminal.`}),(0,G.jsxs)(`p`,{className:`muted`,children:[`Not running? Start it with `,(0,G.jsx)(`code`,{children:`npx megareviewer`}),`.`]})]}),rh=({token:e,fetch:t,openEventStream:n,playgrounds:r})=>{let[i,a]=(0,H.useState)(!1),o=e.value,s=(0,H.useMemo)(()=>o===null?null:{client:au({fetch:t,token:o,onUnauthorized:()=>{e.clear(),a(!0)}}),subscribe:(e,t)=>ou(e,o,t,n)},[t,n,e,o]);return i?(0,G.jsx)(nh,{reason:`ended`}):s===null?(0,G.jsx)(nh,{reason:`missing`}):(0,G.jsx)(su.Provider,{value:s,children:(0,G.jsx)(ih,{playgrounds:r})})},ih=({playgrounds:e})=>{let t=bu(Cu(),{dev:e!==null}),n=du();return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Qm,{status:n.status,error:n.error}),(0,G.jsx)(`main`,{className:`page`,children:t.page===`picker`?(0,G.jsx)(Ru,{status:n.status}):t.page===`review`?(0,G.jsx)(zm,{analysisId:t.analysisId}):t.page===`playground`&&e!==null?(0,G.jsx)(th,{modules:e,name:t.name}):(0,G.jsx)($m,{})})]})},ah=class extends H.Component{state={error:null};static getDerivedStateFromError(e){return{error:e instanceof Error?e:Error(String(e))}}render(){let{error:e}=this.state;if(e===null)return this.props.children;let t=this.props.onReload??(()=>window.location.reload());return(0,G.jsxs)(`main`,{className:`page narrow`,role:`alert`,children:[(0,G.jsx)(`h1`,{children:`Something went wrong`}),(0,G.jsx)(`p`,{children:`megareviewer hit a bug while showing this page.`}),(0,G.jsx)(`pre`,{className:`error-detail`,children:String(e)}),(0,G.jsx)(`button`,{type:`button`,className:`button primary`,onClick:t,children:`Reload`})]})}},oh=`token`,sh=`megareviewer.token`,ch=e=>{let t=(()=>{try{return e.sessionStorage}catch{return null}})(),n=e=>{try{return t===null?null:e(t)}catch{return null}},r=new URL(e.location.href),i=r.searchParams.get(oh),a;return i!==null&&i!==``?(a=i,n(e=>e.setItem(sh,i))):a=n(e=>e.getItem(sh)),r.searchParams.has(oh)&&(r.searchParams.delete(oh),e.history.replaceState(e.history.state,``,`${r.pathname}${r.search}${r.hash}`)),{get value(){return a},clear(){a=null,n(e=>e.removeItem(sh))}}},lh=null,uh=document.getElementById(`root`);if(uh===null)throw Error(`index.html has no #root`);(0,sc.createRoot)(uh).render((0,G.jsx)(H.StrictMode,{children:(0,G.jsx)(ah,{children:(0,G.jsx)(rh,{token:ch(window),fetch:window.fetch.bind(window),playgrounds:lh})})}));export{n as t};
65
+ `),sd=(e,t,n)=>{let r=0,i=0;return e.map(({line:e,text:a})=>{let o=e.kind===`del`?t?.[r]:n?.[i];return e.kind!==`add`&&r++,e.kind!==`del`&&i++,o!==void 0&&o.map(e=>e.text).join(``)===a?o:Zu(a)})},cd=1e3,ld={light:`github-light-default`,dark:`github-dark-default`},ud={"#6e7781":`#57606a`,"#8250df":`#6639ba`},dd=1,fd=2,pd=(e,t)=>{let n=[];for(let{content:r,variants:i}of e){let e=i.light?.color?.toLowerCase()??null,a=i.dark?.color?.toLowerCase()??null,o=e===t.light&&a===t.dark,s=i.light?.fontStyle??0,c={text:r,light:o||e===null?null:ud[e]??e,dark:o?null:a,italic:s>0&&(s&dd)!==0,bold:s>0&&(s&fd)!==0},l=n.at(-1);l!==void 0&&l.light===c.light&&l.dark===c.dark&&l.italic===c.italic&&l.bold===c.bold?n[n.length-1]={...l,text:l.text+c.text}:n.push(c)}return n},md=(0,H.createContext)((()=>{let e=null,t=new Map,n=async()=>{let[{createHighlighterCore:e},{createJavaScriptRegexEngine:t}]=await Promise.all([X(()=>import(`./core-CCOtHs-X.js`),[]),X(()=>import(`./engine-javascript-D-6se_EF.js`),[])]);return e({themes:[X(()=>import(`./github-light-default-BXViO-2h.js`),[]),X(()=>import(`./github-dark-default-DXG-b-1a.js`),[])],langs:[],engine:t()})},r=(e,n)=>{let r=t.get(n)??(async()=>{let t=ed[n];return t!==void 0&&(await e.loadLanguage(...(await t()).default),!0)})();return t.set(n,r),r};return{highlight:async(i,a)=>{if(!(a in ed))return null;try{e??=n();let t=await e;if(!await r(t,a))return null;let o={light:t.getTheme(ld.light).fg.toLowerCase(),dark:t.getTheme(ld.dark).fg.toLowerCase()};return t.codeToTokensWithThemes(i,{lang:a,themes:ld,tokenizeMaxLineLength:cd}).map(e=>pd(e,o))}catch{return e=null,t.delete(a),null}}}})()),hd=new WeakMap,gd=(e,t,n)=>{let r=hd.get(e)??new Map;hd.set(e,r);let i=`${n}\0${t.id}\0${t.oldStart},${t.newStart},${t.lines.length}`,a=r.get(i);if(a!==void 0)return a;let o=Ku(t.lines),s=ad(o),c=o.some(({line:e})=>e.kind!==`add`),l=o.some(({line:e})=>e.kind!==`del`),u=(t,r)=>r?e.highlight(t,n):Promise.resolve(null),d={promise:Promise.all([u(s.old,c),u(s.new,l)]).then(([e,t])=>{let n=sd(o,e,t);return d.value=n,n}),value:null};return r.set(i,d),d},_d=`1200px 0px`,vd=null,yd=new Map,bd=(e,t)=>(vd??=new IntersectionObserver(e=>{for(let t of e)t.isIntersecting&&(yd.get(t.target)?.(),yd.delete(t.target),vd?.unobserve(t.target))},{rootMargin:_d}),yd.set(e,t),vd.observe(e),()=>{yd.delete(e),vd?.unobserve(e)}),xd=e=>{let[t,n]=(0,H.useState)(()=>typeof IntersectionObserver>`u`);return(0,H.useEffect)(()=>{let r=e.current;if(!(t||r===null))return bd(r,()=>n(!0))},[e,t]),t},Sd=(e,t,n=!0)=>{let r=(0,H.useContext)(md),i=id(t),a=i===null||!n?null:gd(r,e,i),[o,s]=(0,H.useState)();return(0,H.useEffect)(()=>{if(a===null||a.value!==null)return;let e=!0;return a.promise.then(t=>{e&&s({entry:a,tokens:t})}),()=>{e=!1}},[a]),a?.value??(o?.entry===a?o.tokens:null)},Cd={context:` `,add:`+`,del:`-`},wd=20,Td=({status:e})=>(0,G.jsx)(`span`,{className:`file-status status-${e}`,children:e}),Ed=({file:e})=>(0,G.jsx)(`span`,{className:`file-path`,children:e.oldPath!==null&&e.oldPath!==e.path?(0,G.jsxs)(G.Fragment,{children:[e.oldPath,` `,(0,G.jsx)(`span`,{"aria-hidden":`true`,children:`→`}),(0,G.jsx)(`span`,{className:`visually-hidden`,children:`renamed to`}),` `,e.path]}):e.path}),Dd=e=>{let t=e.map(e=>e.split(`/`));return t.map(e=>{for(let n=1;n<e.length;n++){let r=e.slice(-n).join(`/`);if(t.filter(e=>e.slice(-n).join(`/`)===r).length<=1)return r}return e.join(`/`)})},Od=e=>e.flatMap((t,n)=>[n===0?``:n===e.length-1?` and `:`, `,t]),kd=({callers:e,onFollow:t})=>{let[n,r]=(0,H.useState)(!1),i=Dd(e.map(e=>e.path)),a=(e,n)=>(0,G.jsxs)(`button`,{type:`button`,className:`hunk-link`,title:e.path,onClick:()=>t(e.partId),children:[i[n],` ↑`]},e.path),o=e.flatMap((e,t)=>e.test?[]:[a(e,t)]),s=e.flatMap((e,t)=>e.test?[a(e,t)]:[]),c=(0,G.jsx)(`button`,{type:`button`,className:`link-button`,"aria-expanded":!1,onClick:()=>r(!0),children:s.length===1?`1 test`:`${s.length} tests`},`tests`),l=[...o,...s.length===0?[]:n?s:[c]];return(0,G.jsxs)(`p`,{className:`hunk-callers`,children:[(0,G.jsx)(`span`,{className:`hunk-callers-label`,children:`Called from`}),` `,Od(l)]})},Ad=(e,t)=>`${e} ${t}${e===1?``:`s`}`,jd=({callers:e,named:t})=>{let[n,r]=(0,H.useState)(!1),i=(0,H.useId)(),{uses:a,more:o}=e,s=a.filter(e=>kc(e.path)).length,c=a.length-s,l=`${[...c>0?[Ad(c,`place`)]:[],...s>0?[Ad(s,`test`)]:[]].join(` and `)}${o>0?`, and ${o} more`:``}`;return(0,G.jsxs)(`div`,{className:`hunk-unchanged`,children:[(0,G.jsx)(`p`,{className:`hunk-outside`,children:(0,G.jsxs)(`button`,{type:`button`,className:`link-button`,"aria-expanded":n,"aria-controls":i,onClick:()=>r(!n),children:[t&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`code`,{children:e.symbol}),` `]}),t?`used`:`Used`,` unchanged in `,l]})}),n&&(0,G.jsxs)(`ul`,{id:i,className:`unchanged-uses`,children:[a.map(e=>(0,G.jsxs)(`li`,{children:[(0,G.jsxs)(`p`,{className:`unchanged-place`,children:[(0,G.jsx)(`span`,{className:`unchanged-path`,children:e.path}),`:`,e.line,e.use===`type`&&(0,G.jsx)(`span`,{className:`unchanged-kind`,children:` type`})]}),(0,G.jsx)(`pre`,{className:`unchanged-excerpt`,children:e.excerpt.lines.map((t,n)=>{let r=e.excerpt.start+n;return(0,G.jsxs)(`span`,{className:r===e.line?`unchanged-line used`:`unchanged-line`,children:[(0,G.jsx)(`span`,{className:`unchanged-number`,children:r}),t]},r)})})]},`${e.path}:${e.line}`)),o>0&&(0,G.jsxs)(`li`,{className:`muted`,children:[`and `,o,` more`]})]})]})},Md=e=>e.length<=1?e.join(``):`${e.slice(0,-1).join(`, `)} and ${e.at(-1)}`,Nd=({names:e})=>e.length===0?null:(0,G.jsxs)(G.Fragment,{children:[Od(e.map(e=>(0,G.jsx)(`code`,{children:e},e))),` · `]}),Pd=({part:e})=>(0,G.jsxs)(`p`,{className:`hunk-part-of`,children:[`part `,e.n,` of `,e.of,e.elsewhere.length>0&&` · rest of this hunk in ${e.elsewhere.length===1?`step`:`steps`} ${Md(e.elsewhere.map(String))}`]}),Fd=({neighbor:e,of:t,direction:n,onFollow:r})=>(0,G.jsxs)(`button`,{type:`button`,className:`part-fold ${n}`,disabled:r===void 0,onClick:()=>r?.(e.id),children:[(0,G.jsx)(`span`,{"aria-hidden":`true`,children:n===`previous`?`↑`:`↓`}),` `,(0,G.jsx)(Nd,{names:e.definitions}),`part `,e.n,` of `,t,e.step===null?``:` · step ${e.step}`]}),Id=e=>e.kind===`del`?e.oldLine===null?null:{side:`old`,line:e.oldLine}:e.newLine===null?null:{side:`new`,line:e.newLine},Ld=(e,t)=>e.side===t.side&&e.line===t.line,Rd=(0,H.memo)(function({id:e,part:t,hunk:n,file:r,risk:i,proofs:a=[],highlighted:o=!1,focused:s=!1,onFocus:c,lineLimit:l,callers:u=[],unchanged:d=[],onFollow:f,reviewed:p,onReviewed:m,comments:h=[],openComment:g=null,onOpenComment:_,onComment:v,afterHeader:y,belowLine:b,inLine:x,inFile:S=!1}){let ee=e??n.id,te=(0,H.useRef)(null),[C,w]=(0,H.useState)(!1),T=(0,H.useMemo)(()=>Ku(n.lines),[n]),ne=(0,H.useMemo)(()=>Hu(T.map(({line:e,text:t})=>({kind:e.kind,text:t}))),[T]),re=Sd(n,r,xd(te)),ie=l===void 0||C||T.length<=l?T:T.slice(0,l);(0,H.useEffect)(()=>{let e=te.current;s&&e!==null&&!e.contains(document.activeElement)&&(e.focus({preventScroll:!0}),e.scrollIntoView({block:`start`}))},[s]);let ae=qu(n),oe=[`hunk-card`,S&&`in-file`,o&&`highlighted`,i&&`risk-${i.riskClass}`];return(0,G.jsxs)(`section`,{ref:te,className:oe.filter(Boolean).join(` `),"aria-label":`${r.path}, ${Yu(n)}`,tabIndex:0,onFocus:()=>c?.(ee),children:[(0,G.jsxs)(`header`,{className:`hunk-header`,children:[S?(0,G.jsx)(`span`,{className:`hunk-location`,children:Yu(n)}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ed,{file:r}),(0,G.jsx)(Td,{status:r.status})]}),t==null?n.sectionHeading!==null&&(0,G.jsx)(`code`,{className:`hunk-heading`,children:n.sectionHeading}):t.definitions.length>0&&(0,G.jsx)(`span`,{className:`hunk-part`,children:Od(t.definitions.map(e=>(0,G.jsx)(`code`,{children:e},e)))}),(0,G.jsxs)(`span`,{className:`hunk-counts`,children:[(0,G.jsxs)(`span`,{className:`count-added`,children:[`+`,ae.added]}),` `,(0,G.jsxs)(`span`,{className:`count-deleted`,children:[`−`,ae.deleted]})]}),a.map(e=>(0,G.jsxs)(`span`,{className:`hunk-proof`,title:`Mechanical proof`,children:[`✓ `,e.detail]},e.kind)),i?.riskClass===`contract`&&(0,G.jsx)(`span`,{className:`hunk-contract-reason model-text`,children:i.reason}),i!==null&&(0,G.jsx)(Xu,{risk:i}),m!==void 0&&(0,G.jsxs)(`label`,{className:`hunk-reviewed`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:p===!0,onChange:e=>m(ee,e.target.checked)}),`Reviewed`]})]}),u.length>0&&f!==void 0&&(0,G.jsx)(kd,{callers:u,onFollow:f}),d.map(e=>(0,G.jsx)(jd,{callers:e,named:d.length>1},e.symbol)),y,t!=null&&(0,G.jsxs)(`details`,{className:`hunk-related`,children:[(0,G.jsx)(`summary`,{children:`Related parts`}),(0,G.jsx)(Pd,{part:t}),t.previous!=null&&(0,G.jsx)(Fd,{neighbor:t.previous,of:t.of,direction:`previous`,onFollow:f}),t.next!=null&&(0,G.jsx)(Fd,{neighbor:t.next,of:t.of,direction:`next`,onFollow:f})]}),(0,G.jsx)(`div`,{className:`hunk-body`,style:{containIntrinsicSize:`auto ${ie.length*wd}px`},children:(0,G.jsxs)(`table`,{className:`diff-table`,children:[(0,G.jsx)(`thead`,{className:`visually-hidden`,children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{scope:`col`,children:`Old line`}),(0,G.jsx)(`th`,{scope:`col`,children:`New line`}),(0,G.jsx)(`th`,{scope:`col`,children:`Change`}),(0,G.jsx)(`th`,{scope:`col`,children:`Code`})]})}),(0,G.jsx)(`tbody`,{children:ie.map((e,t)=>{let n=Id(e.line),r=n===null?void 0:h.find(e=>Ld(e,n)),i=n!==null&&g!==null&&Ld(g,n),a=e.line.kind===`del`?null:e.line.newLine,o=a===null?void 0:b?.get(a);return(0,G.jsxs)(H.Fragment,{children:[(0,G.jsx)(Bd,{line:e,tokens:re?.[t]??null,changed:ne.get(t)??null,marks:a===null?void 0:x?.get(a),onNumber:n===null||_===void 0||v===void 0?void 0:()=>_(ee,n)}),n!==null&&(r!==void 0||i)&&(0,G.jsx)(zd,{place:n,body:r?.body??``,focus:i,onChange:v===void 0?void 0:e=>v(ee,{...n,body:e}),onDone:()=>_?.(ee,null)}),o!==void 0&&(0,G.jsx)(`tr`,{className:`line-below`,children:(0,G.jsx)(`td`,{colSpan:4,children:o})})]},t)})})]})}),ie.length<T.length&&(0,G.jsxs)(`button`,{type:`button`,className:`button show-all`,onClick:()=>w(!0),children:[`Show all `,T.length,` lines`]})]})}),zd=({place:e,body:t,focus:n,onChange:r,onDone:i})=>{let a=(0,H.useRef)(null);(0,H.useEffect)(()=>{n&&a.current?.focus()},[n]);let o=`Comment on ${e.side===`old`?`old `:``}line ${e.line}`;return(0,G.jsx)(`tr`,{className:`line-comment`,children:(0,G.jsx)(`td`,{colSpan:4,children:r===void 0?(0,G.jsxs)(`p`,{className:`posted-text`,children:[(0,G.jsxs)(`span`,{className:`visually-hidden`,children:[o,`: `]}),t]}):(0,G.jsx)(`textarea`,{ref:a,className:`input`,rows:2,"aria-label":o,placeholder:`What should change here?`,value:t,onChange:e=>r(e.target.value),onBlur:i,onKeyDown:e=>{e.key===`Escape`&&(e.stopPropagation(),a.current?.blur())}})})})},Bd=(0,H.memo)(function({line:{line:e,text:t,carriageReturn:n},tokens:r,changed:i,marks:a=[],onNumber:o}){let s=e.kind===`del`?`del`:`ins`,c=(t,n)=>t!==null&&o!==void 0&&n===`old`==(e.kind===`del`)?(0,G.jsx)(`button`,{type:`button`,className:`line-number-button`,"aria-label":`Comment on ${n===`old`?`old `:``}line ${t}`,onClick:o,children:t}):t;return(0,G.jsxs)(`tr`,{className:`diff-line line-${e.kind}`,children:[(0,G.jsx)(`td`,{className:`line-number`,children:c(e.oldLine,`old`)}),(0,G.jsx)(`td`,{className:`line-number`,children:c(e.newLine,`new`)}),(0,G.jsx)(`td`,{className:`line-marker`,children:Cd[e.kind]}),(0,G.jsxs)(`td`,{className:`line-code`,children:[Vd(Qu(r??Zu(t),i??[],a),a,s),n&&(0,G.jsx)(`span`,{className:`line-note`,title:`This line ends in CRLF`,children:`CRLF`}),e.noNewlineAtEnd&&(0,G.jsx)(`span`,{className:`line-note`,children:`No newline at end of file`})]})]})}),Vd=(e,t,n)=>{let r=[],i=null,a=()=>{i!==null&&r.push((0,G.jsx)(H.Fragment,{children:i.mark.render(i.code)},`mark-${i.mark.start}`)),i=null},o=0;return e.forEach((e,s)=>{let c=o;o+=e.text.length;let l=[`token`,e.italic&&`italic`,e.bold&&`bold`,e.changed&&`changed`].filter(Boolean).join(` `),u=e.light===null&&e.dark===null?void 0:{"--token-light":e.light??void 0,"--token-dark":e.dark??void 0},d=e.changed?n:`span`,f=(0,G.jsx)(d,{className:l,style:u,children:e.text},s),p=t.find(e=>c>=e.start&&c<e.end);p===void 0?(a(),r.push(f)):i?.mark===p?i.code.push(f):(a(),i={mark:p,code:[f]})}),a(),r},Hd=(e,t)=>{let n=new Set,r=e=>{let r=t.filter(t=>!n.has(t)&&e(t));for(let e of r)n.add(e);return r},i=e.flatMap(e=>{let t=r(t=>t.path===e.path&&t.hunkId===null).map(t=>({key:`${e.path}\0${t.kind}`,path:e.path,file:e,hunk:null,proofs:[t],summary:Ud(t,e)})),n=e.hunks.flatMap(t=>{let n=r(e=>e.hunkId===t.id);if(n.length===0)return[];let{added:i,deleted:a}=qu(t),o=n.map(e=>e.detail).join(`; `);return[{key:t.id,path:e.path,file:e,hunk:t,proofs:n,summary:`${e.path} — ${o} (+${i} −${a})`}]});return[...t,...n]}),a=t.filter(e=>!n.has(e)).map((e,t)=>({key:`orphan-${t}`,path:e.path,file:null,hunk:null,proofs:[e],summary:`${e.path} — ${e.detail}`}));return[...i,...a]},Ud=(e,t)=>e.kind===`rename`&&t.oldPath!==null?`${t.oldPath} → ${t.path} — renamed, content unchanged`:`${t.path} — ${e.detail}`,Wd=({files:e,proofs:t,risk:n})=>{let r=(0,H.useId)(),i=(0,H.useMemo)(()=>Hd(e,t),[e,t]),[a,o]=(0,H.useState)(new Set),s=i.filter(e=>e.hunk!==null).map(e=>e.key),c=s.length>0&&s.every(e=>a.has(e));if(i.length===0)return null;let l=e=>o(t=>{let n=new Set(t);return n.delete(e)||n.add(e),n});return(0,G.jsxs)(`section`,{className:`mechanical-group`,"aria-labelledby":r,children:[(0,G.jsxs)(`div`,{className:`mechanical-header`,children:[(0,G.jsxs)(`h2`,{id:r,children:[`Mechanical changes `,(0,G.jsx)(`span`,{className:`mechanical-count`,children:i.length})]}),s.length>0&&(0,G.jsx)(`button`,{type:`button`,className:`button`,onClick:()=>o(new Set(c?[]:s)),children:c?`Collapse all`:`Expand all`})]}),(0,G.jsx)(`ul`,{className:`mechanical-rows`,children:i.map(e=>{let t=a.has(e.key);return(0,G.jsxs)(`li`,{className:`mechanical-row`,children:[e.hunk===null||e.file===null?(0,G.jsx)(`span`,{className:`mechanical-summary`,children:e.summary}):(0,G.jsx)(`button`,{type:`button`,className:`mechanical-summary mechanical-toggle`,"aria-expanded":t,onClick:()=>l(e.key),children:e.summary}),t&&e.hunk!==null&&e.file!==null&&(0,G.jsx)(Rd,{hunk:e.hunk,file:e.file,risk:n.find(t=>t.hunkId===e.hunk?.id)??null,proofs:e.proofs,lineLimit:500})]},e.key)})})]})},Gd=(0,H.memo)(function({hunk:e,file:t,risk:n,proofs:r,focused:i=!1,onFocus:a}){let o=(0,H.useRef)(null),[s,c]=(0,H.useState)(!1),{added:l,deleted:u}=qu(e);return(0,H.useEffect)(()=>{let e=o.current;i&&e!==null&&e!==document.activeElement&&(e.focus({preventScroll:!0}),e.scrollIntoView({block:`start`}))},[i]),(0,G.jsxs)(`div`,{className:`collapsed-hunk`,children:[(0,G.jsxs)(`button`,{ref:o,type:`button`,className:`mechanical-summary mechanical-toggle`,"aria-expanded":s,onClick:()=>c(e=>!e),onFocus:()=>a?.(e.id),children:[t.path,`, `,Yu(e),` — `,r.map(e=>e.detail).join(`; `),` (+`,l,` −`,u,`)`]}),s&&(0,G.jsx)(Rd,{hunk:e,file:t,risk:n,proofs:r,lineLimit:500})]})}),Kd={added:`added`,deleted:`deleted`,modified:`changed`,renamed:`changed`},qd=e=>e.flatMap(e=>{let t=e.oldMode!==null||e.newMode!==null,n=!e.binary&&!t&&e.hunks.length===0&&e.status!==`renamed`;return[...e.binary?[{key:`${e.path}\0binary`,file:e,text:`binary file ${Kd[e.status]}`}]:[],...t?[{key:`${e.path}\0mode`,file:e,text:`mode ${e.oldMode??`unknown`} → ${e.newMode??`unknown`}`}]:[],...n?[{key:`${e.path}\0empty`,file:e,text:e.status===`modified`?`changed, no lines to show`:`empty file ${e.status}`}]:[]]}),Jd=({files:e})=>{let t=(0,H.useId)(),n=qd(e);return n.length===0?null:(0,G.jsxs)(`section`,{className:`file-notices`,"aria-labelledby":t,children:[(0,G.jsx)(`h2`,{id:t,children:`Changes without lines to show`}),(0,G.jsx)(`ul`,{children:n.map(({key:e,file:t,text:n})=>(0,G.jsxs)(`li`,{className:`file-notice`,children:[(0,G.jsx)(Ed,{file:t}),(0,G.jsx)(Td,{status:t.status}),(0,G.jsx)(`span`,{children:n})]},e))})]})},Yd=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),Xd=(e,t)=>{if(t===``)return null;let n=RegExp(`(?<![\\w$])${Yd(t)}(?![\\w$])`).exec(e);return n===null?null:{start:n.index,end:n.index+t.length}},Zd=(e,t,n)=>{let r=new Map;for(let i of e){let e=new Set;for(let a of i){let i=t.get(a);if(i===void 0||r.has(a))continue;let o=new Map;for(let[t,r]of[...i].sort(([e],[t])=>e-t)){let i=new Map;for(let e of r)i.set(e.symbol,[...i.get(e.symbol)??[],e]);let s=[];for(let[r,o]of i){let i=o.some(t=>!e.has(t.toPartId));for(let t of o)e.add(t.toPartId);let c=n(a,t),l=i||c===void 0?null:Xd(c,r);s.push(l===null?{kind:`chip`,symbol:r,calls:o}:{kind:`mention`,symbol:r,calls:o,at:l})}o.set(t,s)}r.set(a,o)}}return r},Qd={api:`API`,data:`Data`,dependency:`Dependency`,security:`Security`,"error-handling":`Error handling`,performance:`Performance`,concurrency:`Concurrency`,configuration:`Configuration`,behavior:`Behavior`,other:`Other`},$d={waiting:``,saving:`Saving…`,saved:`Saved`,failed:`Not saved`},ef=e=>`decision-${e}`,tf=(0,H.memo)(function({decision:e,draft:t,status:n,selected:r,readOnly:i,commentRef:a,onSelect:o,onVerdict:s,onComment:c}){let l=(0,H.useId)(),u=n=>s(e.id,t.verdict===n?`pending`:n);return(0,G.jsxs)(`article`,{id:ef(e.id),className:`decision verdict-${t.verdict}${r?` selected`:``}`,"aria-labelledby":`${l}-title`,tabIndex:-1,onFocus:()=>o(e.id),children:[(0,G.jsxs)(`div`,{className:`decision-head`,children:[(0,G.jsx)(`span`,{className:`badge category`,children:Qd[e.category]}),(0,G.jsx)(`h3`,{id:`${l}-title`,className:`decision-title model-text`,children:e.title})]}),(0,G.jsx)(`p`,{className:`decision-why model-text`,children:e.whyItMatters}),(0,G.jsxs)(`div`,{className:`decision-controls`,children:[(0,G.jsxs)(`div`,{className:`verdict-buttons`,children:[(0,G.jsxs)(`button`,{type:`button`,className:`button verdict approve`,"aria-pressed":t.verdict===`approved`,"aria-label":`Approve: ${e.title}`,disabled:i,onClick:()=>u(`approved`),children:[(0,G.jsx)(`span`,{"aria-hidden":`true`,children:`✓`}),` Approve`]}),(0,G.jsxs)(`button`,{type:`button`,className:`button verdict reject`,"aria-pressed":t.verdict===`rejected`,"aria-label":`Reject: ${e.title}`,disabled:i,onClick:()=>u(`rejected`),children:[(0,G.jsx)(`span`,{"aria-hidden":`true`,children:`✗`}),` Reject`]})]}),(0,G.jsxs)(`label`,{className:`visually-hidden`,htmlFor:`${l}-comment`,children:[`Comment on: `,e.title]}),(0,G.jsx)(`textarea`,{id:`${l}-comment`,ref:r?a:void 0,className:`input comment`,rows:1,placeholder:i?``:`Comment (optional)`,value:t.comment,readOnly:i,onChange:t=>c(e.id,t.target.value)}),n!==null&&$d[n]!==``&&(0,G.jsx)(`span`,{className:`save-status ${n}`,role:`status`,children:$d[n]})]})]})}),nf=({decision:e,onGo:t})=>(0,G.jsxs)(`p`,{className:`decision-mention`,children:[`Decision:`,` `,(0,G.jsx)(`button`,{type:`button`,className:`link-button model-text`,onClick:()=>t(e.id),children:e.title})]}),rf=`a[href], button:not(:disabled), textarea:not(:disabled), input:not(:disabled), [tabindex]:not([tabindex="-1"])`,af=({title:e,onClose:t,children:n,className:r=``})=>{let i=(0,H.useId)(),a=(0,H.useRef)(null);return(0,H.useEffect)(()=>{let e=document.activeElement;return(a.current?.querySelector(`[data-autofocus]`)??a.current?.querySelector(rf))?.focus(),()=>{e instanceof HTMLElement&&e.focus()}},[]),(0,G.jsx)(`div`,{className:`dialog-backdrop`,children:(0,G.jsxs)(`div`,{ref:a,className:`dialog ${r}`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`${i}-title`,onKeyDown:e=>{if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),t();return}if(e.key!==`Tab`)return;let n=[...a.current?.querySelectorAll(rf)??[]],r=n[0],i=n.at(-1);r!==void 0&&i!==void 0&&(e.shiftKey&&document.activeElement===r?(e.preventDefault(),i.focus()):!e.shiftKey&&document.activeElement===i&&(e.preventDefault(),r.focus()))},children:[(0,G.jsxs)(`div`,{className:`dialog-header`,children:[(0,G.jsx)(`h2`,{id:`${i}-title`,children:e}),(0,G.jsx)(`button`,{type:`button`,className:`button quiet`,"aria-label":`Close`,onClick:t,children:`✕`})]}),n]})})},of=e=>`hunk-${e}`,sf=({id:e,deps:t,belowLine:n,inLine:r,focused:i=!1,nested:a=!1,inFile:o=!1})=>{let[s]=t.index.items([e]);if(s===void 0)return null;let{hunk:c,file:l,risk:u,proofs:d=[]}=s;return d.length>0?(0,G.jsx)(Gd,{hunk:c,file:l,risk:u,proofs:d,focused:i,onFocus:a?void 0:t.onFocusHunk}):(0,G.jsx)(Rd,{id:e,part:t.partHeaderOf(e),hunk:c,file:l,risk:u,highlighted:t.highlighted.has(e),focused:i,onFocus:a?void 0:t.onFocusHunk,callers:a?void 0:t.callersOf(e),unchanged:a?void 0:t.unchangedOf(e),onFollow:t.onFollow,reviewed:t.reviewed.has(e),onReviewed:o?void 0:t.onReviewed,inFile:o,comments:t.commentsOf(e),openComment:!a&&t.openComment?.partId===e?t.openComment.place:null,onOpenComment:a?void 0:t.onOpenComment,onComment:a?void 0:t.onComment,afterHeader:a?void 0:t.decisionsOn(e),belowLine:n,inLine:r})},cf=({call:e,index:t})=>{let n=t.items([e.toPartId])[0],r=t.mechanical.has(e.toPartId)?`mechanical`:n?.risk.riskClass??`logic`;return(0,G.jsxs)(G.Fragment,{children:[e.request===!0&&(0,G.jsx)(`span`,{className:`call-kind`,children:`sends`}),e.request===!0&&` `,(0,G.jsx)(`code`,{className:`call-symbol`,children:e.symbol}),` `,(0,G.jsx)(`span`,{className:`call-file`,children:n?.file.path}),` `,(0,G.jsx)(`span`,{className:`call-risk risk-${r}`,children:r})]})},lf=/^#{1,6}\s+/,uf=e=>e.replace(/!?(\[([^\]]+)\])\([^)]*\)/g,`$2`).replace(/(`+)(.*?)\1/g,`$2`).replace(/(\*\*|__|~~)(.*?)\1/g,`$2`).replace(/(^|\s)[*_]([^*_]+)[*_](?=\s|[.,!?]|$)/g,`$1$2`).replace(/^\s*(?:>\s*|[-*+]\s+|\d+[.)]\s+)/,``).replace(/\\([\\`*_{}[\]()#+.!>-])/g,`$1`),df=e=>{let t=e.split(`
66
+ `).map(e=>e.trim()).filter(e=>e!==``);return uf(t.find(e=>!lf.test(e))??t[0]?.replace(lf,``)??``)},ff=({analysis:e,modelOn:t,mismatchAt:n,onMismatch:r,onDetails:i})=>{let{intent:a,pullRequest:o}=e,s=a?.mismatches??[],c=s.length===0?0:n%s.length,l=s[c],u=o===null?``:df(o.description);return(0,G.jsxs)(`div`,{className:`intent-line`,children:[a===null?t&&e.status===`running`?(0,G.jsx)(`p`,{className:`intent-text muted`,"aria-busy":`true`,children:`Working out the intent…`}):o===null?null:(0,G.jsxs)(`p`,{className:`intent-text`,children:[(0,G.jsx)(`span`,{className:`intent-label`,children:`Asked:`}),` `,u===``?(0,G.jsx)(`span`,{className:`muted`,children:`The pull request has no description.`}):(0,G.jsx)(`span`,{className:`pr-description-line`,children:u})]}):(0,G.jsxs)(`p`,{className:`intent-text`,children:[(0,G.jsx)(`span`,{className:`intent-label${s.length===0?` agrees`:``}`,children:s.length>0||a.stated===null?`From the code:`:`✓ Does what was asked:`}),` `,(0,G.jsx)(`span`,{className:`model-text`,children:uf(a.inferred.summary)})]}),l!==void 0&&(0,G.jsxs)(`button`,{type:`button`,className:`mismatch-chip`,title:l.description,onClick:()=>r(c),children:[(0,G.jsx)(`span`,{"aria-hidden":`true`,children:`⚠`}),(0,G.jsx)(`span`,{className:`mismatch-chip-text model-text`,children:l.description}),(0,G.jsxs)(`span`,{className:`mismatch-chip-count`,children:[c+1,` of `,s.length]})]}),(a!==null||o!==null)&&(0,G.jsx)(`button`,{type:`button`,className:`button quiet details-button`,onClick:i,children:`Details`})]})},pf={description:`Description`,commits:`Commits`,branch:`Branch name`},Z={unrequested:`Unrequested`,missing:`Missing`,contradicts:`Contradicts`},mf=({ticketKey:e,ticket:t})=>t===void 0?(0,G.jsxs)(`li`,{className:`chip`,title:`Jira didn't return this ticket, or Jira isn't configured`,children:[e,` · not fetched`]}):(0,G.jsx)(`li`,{className:`chip`,children:(0,G.jsxs)(`a`,{href:t.url,target:`_blank`,rel:`noreferrer`,title:t.summary,children:[t.key,` · `,t.status]})}),hf=({stated:e,ticketOf:t,unfetched:n})=>(0,G.jsxs)(G.Fragment,{children:[e!==null&&(0,G.jsx)(`ul`,{className:`chips`,"aria-label":`Sources`,children:e.sources.map(e=>e.kind===`ticket`&&e.ref!==null?(0,G.jsx)(mf,{ticketKey:e.ref,ticket:t.get(e.ref)},`ticket:${e.ref}`):e.kind===`ticket`?null:(0,G.jsx)(`li`,{className:`chip`,children:pf[e.kind]},e.kind))}),n.length>0&&(0,G.jsx)(`ul`,{className:`chips`,"aria-label":`Tickets mentioned but not fetched`,children:n.map(e=>(0,G.jsx)(mf,{ticketKey:e,ticket:void 0},e))})]}),gf=`No stated intent: the PR has no description or linked tickets.`,_f=({intent:e,tickets:t,missingTicketKeys:n,onSelectMismatch:r})=>{let{stated:i,inferred:a,mismatches:o}=e,s=new Map(t.map(e=>[e.key,e])),c=new Set(i?.sources.flatMap(e=>e.ref??[])??[]),l=n.filter(e=>!c.has(e)),u=(0,G.jsx)(hf,{stated:i,ticketOf:s,unfetched:l}),d=o.length===0?i:null,{behaviorChanges:f}=a;return(0,G.jsxs)(`div`,{className:`intent-panel`,children:[o.length===0?(0,G.jsxs)(`div`,{className:`intent-line`,children:[(0,G.jsxs)(`p`,{children:[i===null?(0,G.jsx)(`span`,{className:`intent-label`,children:`From the code:`}):(0,G.jsx)(`span`,{className:`intent-label agrees`,children:`✓ Does what was asked:`}),` `,(0,G.jsx)(`span`,{className:`model-text`,children:a.summary})]}),i===null&&(0,G.jsx)(`p`,{className:`muted`,children:gf}),u]}):(0,G.jsxs)(`div`,{className:`intent-columns`,children:[(0,G.jsxs)(`div`,{className:`intent-column`,children:[(0,G.jsx)(`h3`,{children:`Stated`}),i===null?(0,G.jsx)(`p`,{className:`muted`,children:gf}):(0,G.jsx)(`p`,{className:`model-text`,children:i.summary}),u]}),(0,G.jsxs)(`div`,{className:`intent-column`,children:[(0,G.jsx)(`h3`,{children:`Inferred from the code`}),(0,G.jsx)(`p`,{className:`model-text`,children:a.summary})]}),(0,G.jsxs)(`div`,{className:`intent-column`,children:[(0,G.jsx)(`h3`,{children:`Mismatches`}),(0,G.jsx)(`ul`,{className:`mismatches`,children:o.map((e,t)=>(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{type:`button`,className:`mismatch`,onClick:()=>r(t),children:[(0,G.jsx)(`span`,{className:`badge mismatch-${e.kind}`,children:Z[e.kind]}),(0,G.jsx)(`span`,{className:`model-text`,children:e.description})]})},t))})]})]}),(d!==null||f.length>0)&&(0,G.jsxs)(`details`,{className:`intent-details`,children:[(0,G.jsxs)(`summary`,{children:[`Details`,f.length>0&&` (${f.length})`]}),d!==null&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`h3`,{children:`Asked`}),(0,G.jsx)(`p`,{className:`model-text`,children:d.summary})]}),f.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`h3`,{children:`Behavior changes`}),(0,G.jsx)(`ul`,{className:`behavior-changes`,children:f.map((e,t)=>(0,G.jsx)(`li`,{className:`model-text`,children:e},t))})]})]})]})},vf=[{group:`decisions`,title:`Decisions`},{group:`mismatches`,title:`Mismatches`},{group:`contract`,title:`Contract changes`},{group:`unchanged`,title:`Used unchanged`},{group:`routes`,title:`Routes`},{group:`symbols`,title:`Symbols`},{group:`steps`,title:`Steps`},{group:`files`,title:`Files`}],yf={"!":[`decisions`,`mismatches`,`contract`],"@":[`symbols`],"/":[`files`]},bf=e=>e.slice(e.lastIndexOf(`/`)+1),xf=8,Sf=(e,t,n)=>{let r=e=>{let t=n.parts.get(e);return t===void 0?``:`${t.file.path}, ${Yu(t.hunk)}`},i=new Map;for(let t of e.callGraph){let e=n.parts.get(t.fromPartId);if(t.use!==`request`||e===void 0||!n.parts.has(t.toPartId))continue;let r=`route:${t.symbol}:${t.toPartId}`,a=i.get(r)??{route:t.toPartId,symbol:t.symbol,files:new Set};a.files.add(e.file.path),i.set(r,a)}let a=[...i].map(([e,{route:t,symbol:r,files:i}])=>({key:e,group:`routes`,label:r,detail:`${bf(n.parts.get(t)?.file.path??``)}, requested in ${[...i].sort((e,t)=>Number(kc(e))-Number(kc(t))).map(bf).join(`, `)}`,target:{kind:`hunk`,partId:t}})),o=new Map;for(let t of e.callGraph){if(t.use===`request`)continue;let e=`symbol:${t.symbol}:${t.toPartId}`;!o.has(e)&&n.parts.has(t.toPartId)&&o.set(e,{key:e,group:`symbols`,label:t.symbol,detail:r(t.toPartId),target:{kind:`hunk`,partId:t.toPartId}})}return[...e.decisions.map(e=>({key:`decision:${e.id}`,group:`decisions`,label:e.title,detail:Qd[e.category],target:{kind:`decision`,decisionId:e.id}})),...(e.intent?.mismatches??[]).map((e,t)=>({key:`mismatch:${t}`,group:`mismatches`,label:e.description,detail:e.kind,target:{kind:`mismatch`,index:t}})),...e.risk.flatMap(e=>{let[t]=e.riskClass===`contract`?n.partsOf(e.hunkId):[];return t===void 0?[]:[{key:`contract:${e.hunkId}`,group:`contract`,label:e.reason,detail:r(t),target:{kind:`hunk`,partId:t}}]}),...e.unchangedCallers.flatMap(({partId:e,symbol:t,uses:r,more:i})=>{let a=n.parts.get(e);if(a===void 0)return[];let o=[...new Set(r.map(e=>e.path))],s=r.length+i;return[{key:`unchanged:${t}:${e}`,group:`unchanged`,label:t,detail:`${bf(a.file.path)}, used unchanged in ${s===1?`1 place`:`${s} places`}: ${o.sort((e,t)=>Number(kc(e))-Number(kc(t))).map(bf).join(`, `)}`,target:{kind:`hunk`,partId:e}}]}),...a,...o.values(),...t.map((e,t)=>({key:`step:${e.id}`,group:`steps`,label:e.title,detail:e.codeTitle===null?`Step ${t+1}`:`Step ${t+1} · ${e.codeTitle}`,target:{kind:`step`,stepId:e.id}})),...[...e.files].sort((e,t)=>e.path<t.path?-1:+(e.path>t.path)).map(e=>{let t=e.hunks.find(e=>!n.mechanical.has(e.id))??e.hunks[0],r=t===void 0?void 0:n.partsOf(t.id)[0];return{key:`file:${e.path}`,group:`files`,label:e.path,detail:e.status,target:r===void 0?{kind:`mechanical`}:{kind:`hunk`,partId:r}}})]},Cf=(e,t)=>{let n=t.trimStart(),r=yf[n.charAt(0)],i=(r===void 0?n:n.slice(1)).toLowerCase().split(/\s+/).filter(Boolean);return vf.filter(({group:e})=>r===void 0||r.includes(e)).map(({group:t,title:n})=>({group:t,title:n,items:e.filter(e=>e.group===t).filter(e=>{let t=`${e.label} ${e.detail}`.toLowerCase();return i.every(e=>t.includes(e))}).slice(0,xf)})).filter(({items:e})=>e.length>0)},wf=({items:e,onPick:t,onClose:n})=>{let[r,i]=(0,H.useState)(``),[a,o]=(0,H.useState)(0),s=(0,H.useMemo)(()=>Cf(e,r),[e,r]),c=s.flatMap(e=>e.items),l=Math.min(a,Math.max(c.length-1,0)),u=c[l];return(0,G.jsxs)(af,{title:`Jump to`,onClose:n,className:`jump-palette`,children:[(0,G.jsx)(`input`,{type:`search`,className:`input`,"aria-label":`Jump to`,placeholder:`A decision, function, step or file · ! findings · @ symbols · / files`,value:r,onChange:e=>{i(e.target.value),o(0)},onKeyDown:e=>{if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault();let t=e.key===`ArrowDown`?1:-1;o(Math.min(Math.max(l+t,0),Math.max(c.length-1,0)))}else e.key===`Enter`&&(e.preventDefault(),u!==void 0&&t(u.target))},"data-autofocus":!0}),c.length===0?(0,G.jsx)(`p`,{className:`muted`,children:`Nothing matches.`}):(0,G.jsx)(`div`,{className:`palette-results`,children:s.map(e=>(0,G.jsxs)(`section`,{"aria-label":e.title,children:[(0,G.jsx)(`h3`,{className:`palette-group`,children:e.title}),(0,G.jsx)(`ul`,{className:`palette-list`,children:e.items.map(e=>(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{type:`button`,className:`palette-item${e===u?` active`:``}`,"aria-current":e===u?`true`:void 0,onClick:()=>t(e.target),children:[(0,G.jsx)(`span`,{className:`palette-label model-text`,children:e.label}),(0,G.jsx)(`span`,{className:`palette-detail`,children:e.detail})]})},e.key))})]},e.group))})]})},Tf=e=>e===`map`?`map`:e===`overview`||e===`tree`?`overview`:void 0,Ef=(e,t)=>e.path<t.path?-1:+(e.path>t.path),Df=`Not classified yet.`,Of=e=>{let t=wc(e.parts),n=new Map,r=new Map,i=new Map;for(let a of e.files){for(let e of a.hunks){let n=t.get(e.id)??[],i=n.map(e=>e.id);r.set(e.id,n.length>0?i:[e.id])}for(let e of Tc(a,t)){let r=t.get(e.hunk.id)??[],o=r.findIndex(t=>t.id===e.id),s=r[o];i.set(e.id,i.size),n.set(e.id,{hunk:e.hunk,file:a,place:s===void 0?null:{n:o+1,of:r.length,definitions:s.definitions,siblings:r.map(e=>e.id)}})}}let a=new Map(e.risk.map(e=>[e.hunkId,e])),o=new Map;for(let t of e.proofs)t.hunkId!==null&&o.set(t.hunkId,[...o.get(t.hunkId)??[],t]);let s=new Set(o.keys()),c=e=>{let t=Sc(e);return a.get(t)??{hunkId:t,riskClass:`logic`,reason:Df,source:`fallback`}},l=e=>e.flatMap(e=>{let t=n.get(e);return t===void 0?[]:[{...t,id:e,hunkId:Sc(e),risk:c(e),proofs:o.get(e)??[]}]}),u=e=>r.get(e)??[];return{parts:n,mechanical:s,items:l,partsOf:u,partsInFile:e=>e.hunks.flatMap(e=>u(e.id)),position:i}},kf=(e,t)=>[...e.files].sort(Ef).flatMap(e=>e.hunks.flatMap(e=>t.partsOf(e.id))).filter(e=>!t.mechanical.has(e)),Af=(e,t)=>{let n=e.tour?.steps??[],r=new Set(n.flatMap(e=>e.partIds)),i=kf(e,t).filter(e=>!r.has(e));return i.length===0?n:[...n,{id:al.parse(`s${n.length+1}`),title:`Changes the tour left out`,explanation:`The tour didn't include these changes, so they're shown here in file order.`,partIds:i,kind:`supporting`,via:[],entries:[],codeTitle:null,merged:[]}]},jf=(e,t,n)=>e.tour===null?[{kind:`files`,partIds:Bf(kf(e,n),n)}]:t.map((e,t)=>({kind:`step`,step:e,number:t+1,partIds:Bf(Mf(e.partIds,n),n)})),Mf=(e,t)=>{let n=new Map;for(let r of e){let e=t.parts.get(r)?.file.path??r;n.set(e,[...n.get(e)??[],r])}let r=e=>t.position.get(e)??2**53-1;return[...n.values()].flatMap(e=>e.sort((e,t)=>r(e)-r(t)))},Nf=(e,t)=>{let n=[];for(let r of e){let e=t.parts.get(r)?.file;if(e===void 0)continue;let i=n.at(-1);i?.file===e?i.partIds.push(r):n.push({file:e,partIds:[r]})}return n},Pf=(e,t,n)=>{let r=n.parts.get(e),i=n.parts.get(t);if(r===void 0||i===void 0||r.file!==i.file)return null;let a=r.file.status===`deleted`?`old`:`new`,o=e=>a===`old`?{start:e.oldStart,count:e.oldLines}:{start:e.newStart,count:e.newLines},s=o(r.hunk),c=o(i.hunk),l=s.count===0?s.start:s.start+s.count-1,u=c.count===0?c.start+1:c.start,d=n.position.get(e)??0,f=n.position.get(t)??0,p=n.partsInFile(r.file).filter(e=>{let t=n.position.get(e)??-1;return t>d&&t<f});return{lines:Math.max(u-l-1,0),parts:p}},Ff=e=>e.kind===`step`?e.step.id:`files`,If=(e,t,n)=>{let r=new Map(t.map((e,t)=>[e,t])),i=new Map,a=new Map,o=new Map,s=[],c=(e,t,n)=>e.set(t,[...e.get(t)??[],n]);for(let t of e){let[e,...l]=[...new Set(t.hunkIds)].flatMap(n.partsOf).filter(e=>r.has(e)&&!n.mechanical.has(e)).sort((e,t)=>(r.get(e)??0)-(r.get(t)??0));if(e===void 0)s.push(t);else{c(i,e,t),o.set(t.id,e);for(let e of l)c(a,e,t)}}return{cards:i,mentions:a,cardHunk:o,unplaced:s}},Lf=(e,t)=>{let n=new Map;for(let{fromPartId:r,toPartId:i,symbol:a,line:o,use:s}of e){if(!t.parts.has(r)||!t.parts.has(i))continue;let e=n.get(r)??new Map,c=s===`request`?{symbol:a,toPartId:i,line:o,request:!0}:{symbol:a,toPartId:i,line:o};e.set(o,[...e.get(o)??[],c]),n.set(r,e)}return n},Rf=e=>Math.min(60,Math.max(12,e.lines.length)),zf=e=>{let t=new Set,n=0;for(let r of e)r.hunkId===null?n+=1:t.add(r.hunkId);return t.size+n},Bf=(e,t)=>{let n=[],r=new Set(e),i=e=>t.parts.get(e)?.file,a=(e,n)=>{let i=n===null?e.hunks.length:e.hunks.findIndex(e=>e.id===Sc(n));return e.hunks.slice(0,i).map(e=>e.id).filter(e=>t.mechanical.has(e)&&!r.has(e))},o=new Map;for(let t of e){let e=i(t);if(e!==void 0){let i=a(e,t);for(let e of i)r.add(e);n.push(...i)}n.push(t),e!==void 0&&o.set(e,n.length)}for(let[e,t]of[...o].sort((e,t)=>t[1]-e[1])){let i=a(e,null);for(let e of i)r.add(e);n.splice(t,0,...i)}return n},Vf=(e,t)=>{let n={contract:0,logic:0,mechanical:0},r=e.files.flatMap(e=>e.hunks.map(e=>e.id));for(let e of t.items(r.flatMap(e=>t.partsOf(e).slice(0,1))))n[t.mechanical.has(e.hunk.id)?`mechanical`:e.risk.riskClass]+=1;return n.mechanical+=e.proofs.filter(e=>e.hunkId===null).length,n},Q=(e,t)=>{let n=new Set([...t.parts].flatMap(([e,{file:n}])=>t.mechanical.has(e)?[]:[n.path]));return e.proofs.filter(e=>e.hunkId===null||!n.has(e.path))},Hf=(e,t,n)=>{let r=new Map(n.map((e,t)=>[e,t])),i=e=>r.get(e)??n.length,a=new Map;for(let{fromPartId:n,toPartId:r}of e){let e=t.parts.get(n);if(e===void 0||!t.parts.has(r)||n===r)continue;let o=a.get(r)??new Map,s=o.get(e.file.path);(s===void 0||i(n)<i(s))&&o.set(e.file.path,n),a.set(r,o)}return new Map([...a].map(([e,t])=>[e,[...t].map(([e,t])=>({path:e,partId:t,test:kc(e)})).sort((e,t)=>Number(e.test)-Number(t.test)||i(e.partId)-i(t.partId))]))},Uf=(e,t)=>e.flatMap(e=>e.partIds).filter(e=>!t.mechanical.has(e)),Wf=(e,t)=>{let n=new Set(e),r=new Set;for(let[e,{place:i}]of t.parts)(n.has(e)||i!==null&&n.has(Sc(e)))&&r.add(e);return r},Gf=(e,t,n,r)=>{let i=Sc(t),a=i!==t&&e.includes(i),o=a?r.partsOf(i).filter(e=>e!==t):[];return[...e.filter(e=>e!==t&&!(a&&e===i)),...o,...n?[t]:[]]},Kf=(e,t)=>{let n=new Map;for(let r of e){let e=Sc(r);n.set(e,(n.get(e)??!0)&&t.has(r))}return{done:[...n.values()].filter(Boolean).length,total:n.size}},qf=(e,t)=>{let n=new Map;for(let t of e)if(t.kind===`step`)for(let e of t.partIds)n.has(e)||n.set(e,t.number);let r=e=>{let r=e===void 0?null:t.parts.get(e)?.place??null;return e===void 0||r===null?null:{id:e,n:r.n,definitions:r.definitions,step:n.get(e)??null}},i=new Map;for(let[e,{place:a}]of t.parts){if(a===null)continue;let t=n.get(e),o=[...new Set(a.siblings.flatMap(e=>{let r=n.get(e);return r===void 0||r===t?[]:[r]}))].sort((e,t)=>e-t);i.set(e,{definitions:a.definitions,n:a.n,of:a.of,elsewhere:o,previous:r(a.siblings[a.n-2]),next:r(a.siblings[a.n])})}return i},Jf=(e,t)=>{let n=new Map;for(let r of e){let e=t.partsOf(r.hunkId).find(e=>t.parts.get(e)?.hunk.lines.some(e=>{let t=Id(e);return t!==null&&t.side===r.side&&t.line===r.line}));e!==void 0&&n.set(e,[...n.get(e)??[],r])}return n},Yf=c(),Xf={context:` `,add:`+`,del:`-`},Zf=(e,t)=>{let n=RegExp(`(?<![\\w$])${t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}(?![\\w$])`),r=RegExp(`\\b(def|class|function|func|fn|const|let|var|type|interface|enum|struct)\\s+${n.source}`),i=e.lines.map((e,t)=>({line:e,at:t})).filter(({line:e})=>e.kind!==`del`);return(i.find(({line:e})=>r.test(e.text))??i.find(({line:e})=>n.test(e.text)))?.at??0},Qf=null,$f=({mark:e,deps:t,children:n})=>{let r=(0,H.useId)(),i=(0,H.useRef)(null),a=(0,H.useRef)(null),[o,s]=(0,H.useState)(null),[c]=e.calls,l=()=>{a.current!==null&&clearTimeout(a.current),a.current=null,s(null)},u=()=>{let e=i.current?.getBoundingClientRect();e!==void 0&&(Qf!==l&&Qf?.(),Qf=l,s({top:e.bottom+4,left:e.left}))};if((0,H.useEffect)(()=>{if(o===null)return;let e=()=>{let e=i.current?.getBoundingClientRect();if(e===void 0||e.bottom<0||e.top>window.innerHeight)return l();s({top:e.bottom+4,left:e.left})};return window.addEventListener(`scroll`,e,!0),()=>window.removeEventListener(`scroll`,e,!0)},[o]),(0,H.useEffect)(()=>()=>{a.current!==null&&clearTimeout(a.current)},[]),c===void 0)return n;let d=(e=>t.index.mechanical.has(e)?`mechanical`:t.index.items([e])[0]?.risk.riskClass??`logic`)(c.toPartId);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`button`,{ref:i,type:`button`,className:`call-mention risk-${d}`,"aria-describedby":o===null?void 0:r,onMouseEnter:()=>{a.current!==null&&clearTimeout(a.current),a.current=setTimeout(u,300)},onMouseLeave:l,onFocus:u,onBlur:l,onKeyDown:e=>{e.key===`Escape`&&o!==null&&(e.stopPropagation(),l())},onClick:()=>{l(),t.onFollow(c.toPartId)},children:n}),o!==null&&(0,Yf.createPortal)((0,G.jsx)(`div`,{id:r,role:`tooltip`,className:`peek`,style:{top:o.top,left:o.left},children:e.calls.map(n=>(0,G.jsx)(ep,{hunkId:n.toPartId,symbol:e.symbol,deps:t},n.toPartId))}),document.body)]})},ep=({hunkId:e,symbol:t,deps:n})=>{let[r]=n.index.items([e]);if(r===void 0)return null;let{hunk:i,file:a}=r,o=n.index.mechanical.has(e)?`mechanical`:r.risk.riskClass,s=Zf(i,t),c=i.lines.slice(s,s+12),l=n.stepOf(e);return(0,G.jsxs)(`div`,{className:`peek-hunk`,children:[(0,G.jsxs)(`p`,{className:`peek-head`,children:[(0,G.jsx)(`code`,{className:`call-symbol`,children:t}),` `,(0,G.jsx)(`span`,{children:a.path}),` `,(0,G.jsx)(`span`,{className:`muted`,children:Yu(i)}),` `,(0,G.jsx)(`span`,{className:`call-risk risk-${o}`,children:o}),l!==null&&(0,G.jsxs)(`span`,{className:`peek-step muted`,children:[` · `,l]})]}),(0,G.jsx)(`pre`,{className:`peek-code`,children:c.map((e,t)=>(0,G.jsxs)(`span`,{className:`peek-line line-${e.kind}`,children:[Xf[e.kind],` `,e.text]},t))})]})},$=e=>`step-${e}`,tp=`mechanical-changes`,np=(e,t)=>`${e.join(`>`)}@${t.line}:${t.symbol}>${t.toPartId}`,rp=(0,H.memo)(function({render:e}){return e()},(e,t)=>e.signature===t.signature),ip=({call:e,chain:t,deps:n,openCalls:r,onToggleCall:i})=>{let a=np(t,e);if(t.includes(e.toPartId))return(0,G.jsx)(`li`,{className:`call`,children:(0,G.jsxs)(`span`,{className:`call-chip above`,children:[(0,G.jsx)(cf,{call:e,index:n.index}),(0,G.jsx)(`span`,{className:`call-note`,children:`open above`})]})});let o=r.has(a);return(0,G.jsxs)(`li`,{className:`call`,children:[(0,G.jsxs)(`button`,{type:`button`,className:`call-chip`,"aria-expanded":o,onClick:()=>i(a),children:[(0,G.jsx)(`span`,{className:`call-arrow`,"aria-hidden":`true`,children:o?`▾`:`▸`}),(0,G.jsx)(cf,{call:e,index:n.index})]}),o&&(0,G.jsx)(`div`,{className:`inline-call`,children:(0,G.jsx)(dp,{id:e.toPartId,chain:[...t,e.toPartId],deps:n,openCalls:r,onToggleCall:i})})]})},ap=({mark:e,chain:t,deps:n,openCalls:r,onToggleCall:i})=>{let[a,o]=(0,H.useState)(!1),s=(0,H.useRef)(null),c=e.calls.filter(e=>!t.includes(e.toPartId)&&r.has(np(t,e))),l=(e,t)=>{let n=[...e.closest(`ul`)?.querySelectorAll(`.call-choice`)??[]];n[(n.indexOf(e)+t+n.length)%n.length]?.focus()};return(0,G.jsxs)(`li`,{className:`call`,children:[(0,G.jsxs)(`button`,{ref:s,type:`button`,className:`call-chip ambiguous`,"aria-expanded":a,onClick:()=>o(e=>!e),children:[(0,G.jsx)(`span`,{className:`call-arrow`,"aria-hidden":`true`,children:a?`▾`:`▸`}),(0,G.jsx)(`code`,{className:`call-symbol`,children:e.symbol}),` `,(0,G.jsxs)(`span`,{className:`call-file`,children:[`→ `,e.calls.length,` places`]})]}),a&&(0,G.jsx)(`ul`,{className:`call-choices`,"aria-label":`Where ${e.symbol} goes`,children:e.calls.map(e=>{let a=t.includes(e.toPartId),c=n.index.parts.get(e.toPartId);return(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{type:`button`,className:`call-choice`,disabled:a,"aria-pressed":r.has(np(t,e)),onClick:()=>{i(np(t,e)),o(!1),s.current?.focus()},onKeyDown:e=>{e.key===`ArrowDown`||e.key===`ArrowUp`?(e.preventDefault(),e.stopPropagation(),l(e.currentTarget,e.key===`ArrowDown`?1:-1)):e.key===`Escape`&&(e.stopPropagation(),o(!1),s.current?.focus())},children:[(0,G.jsx)(cf,{call:e,index:n.index}),c!==void 0&&(0,G.jsxs)(`span`,{className:`call-note`,children:[` `,Yu(c.hunk)]}),a&&(0,G.jsx)(`span`,{className:`call-note`,children:` open above`})]})},e.toPartId)})}),c.map(e=>(0,G.jsx)(`div`,{className:`inline-call`,children:(0,G.jsx)(dp,{id:e.toPartId,chain:[...t,e.toPartId],deps:n,openCalls:r,onToggleCall:i})},e.toPartId))]})},op=({marks:e,chain:t,deps:n,openCalls:r,onToggleCall:i})=>(0,G.jsx)(`ul`,{className:`calls`,children:e.map(e=>{let[a,...o]=e.calls;if(a===void 0)return null;let s={chain:t,deps:n,openCalls:r,onToggleCall:i};return o.length>0?(0,G.jsx)(ap,{mark:e,...s},`${e.symbol}*`):(0,G.jsx)(ip,{call:a,...s},`${e.symbol}>${a.toPartId}`)})}),sp=e=>{let t=new Map;for(let n of e)t.set(n.symbol,[...t.get(n.symbol)??[],n]);return[...t].map(([e,t])=>({kind:`chip`,symbol:e,calls:t}))},cp=(e,t)=>{let n=e.at(-1);if(n===void 0)return;if(e.length===1)return t.plan.get(n);let r=t.calls.get(n);return r===void 0?void 0:new Map([...r].map(([e,t])=>[e,sp(t)]))},lp=(e,t,n,r)=>{let i=cp(e,t);if(i!==void 0)return new Map([...i].flatMap(([i,a])=>{let o=a.filter(e=>e.kind===`chip`);return o.length===0?[]:[[i,(0,G.jsx)(op,{marks:o,chain:e,deps:t,openCalls:n,onToggleCall:r},i)]]}))},up=(e,t)=>new Map([...t.plan.get(e)??[]].flatMap(([e,n])=>{let r=n.flatMap(e=>e.kind===`mention`?[{start:e.at.start,end:e.at.end,render:n=>(0,G.jsx)($f,{mark:e,deps:t,children:n})}]:[]);return r.length===0?[]:[[e,r]]})),dp=({id:e,chain:t,deps:n,openCalls:r,onToggleCall:i})=>(0,G.jsx)(sf,{id:e,deps:n,nested:!0,belowLine:lp(t,n,r,i)}),fp=({via:e,deps:t})=>{let n=e.flatMap(e=>{let n=t.index.parts.get(e);return n===void 0?[]:[{id:e,...n}]});if(n.length===0)return null;let r=new Map;for(let e of n){let n=t.stepOf(e.id)??`Other changes`;r.set(n,[...r.get(n)??[],e])}return(0,G.jsxs)(`div`,{className:`step-via`,children:[(0,G.jsx)(`span`,{className:`step-via-label`,children:`Passes through`}),[...r].map(([e,n])=>(0,G.jsxs)(`details`,{children:[(0,G.jsxs)(`summary`,{children:[e,` · `,n.length,` `,n.length===1?`part`:`parts`]}),(0,G.jsx)(`ul`,{className:`hunk-links`,"aria-label":`Passes through ${e}`,children:n.map(({id:e,file:n,hunk:r})=>(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{type:`button`,className:`hunk-link`,onClick:()=>t.onFollow(e),children:[n.path.slice(n.path.lastIndexOf(`/`)+1),` `,Yu(r),` ↑`]})},e))})]},e))]})},pp=({id:e,deps:t,openCalls:n,onToggleCall:r,signatureOf:i,inFile:a})=>(0,G.jsx)(`div`,{id:of(e),className:`map-hunk`,"data-hunk-id":e,children:(0,G.jsx)(rp,{signature:i(e),render:()=>(0,G.jsx)(sf,{id:e,deps:t,belowLine:lp([e],t,n,r),inLine:up(e,t),inFile:a})})}),mp=({previous:e,next:t,deps:n})=>{let r=Pf(e,t,n.index);if(r===null||r.lines===0&&r.parts.length===0)return null;let i=`${r.lines} ${r.lines===1?`line`:`lines`}`;return(0,G.jsxs)(`div`,{className:`file-gap`,children:[(0,G.jsx)(`span`,{"aria-hidden":`true`,children:`⋯`}),` `,r.parts.length===0?`${i} unchanged`:(0,G.jsxs)(G.Fragment,{children:[i,`, with changes read elsewhere:`,` `,r.parts.map(e=>{let t=n.index.parts.get(e);return(0,G.jsxs)(`button`,{type:`button`,className:`hunk-link`,title:n.stepOf(e)??void 0,onClick:()=>n.onFollow(e),children:[t===void 0?e:Yu(t.hunk),` ↑`]},e)})]})]})},hp=({group:e,deps:t,part:n})=>{let r=t.index.items(e.partIds),i=r.filter(e=>!t.index.mechanical.has(e.id)),a=i.filter(e=>t.reviewed.has(e.id)).length,o=r.reduce((e,t)=>e+qu(t.hunk).added,0),s=r.reduce((e,t)=>e+qu(t.hunk).deleted,0),c=i.some(e=>e.risk.riskClass===`contract`),l=(0,H.useRef)(null);return(0,H.useEffect)(()=>{l.current!==null&&(l.current.indeterminate=a>0&&a<i.length)}),(0,G.jsxs)(`section`,{className:c?`file-card risk-contract`:`file-card`,"aria-label":e.file.path,children:[(0,G.jsxs)(`header`,{className:`file-card-header`,children:[(0,G.jsx)(Ed,{file:e.file}),(0,G.jsx)(Td,{status:e.file.status}),(0,G.jsxs)(`span`,{className:`hunk-counts`,children:[i.length,` `,i.length===1?`part`:`parts`,` ·`,` `,(0,G.jsxs)(`span`,{className:`count-added`,children:[`+`,o]}),` `,(0,G.jsxs)(`span`,{className:`count-deleted`,children:[`−`,s]})]}),i.length>0&&(0,G.jsxs)(`label`,{className:`hunk-reviewed`,children:[(0,G.jsx)(`input`,{ref:l,type:`checkbox`,checked:a===i.length,onChange:e=>{for(let n of i)t.onReviewed(n.id,e.target.checked)}}),`Reviewed`]})]}),e.partIds.map((r,i)=>{let a=e.partIds[i-1];return(0,G.jsxs)(H.Fragment,{children:[a!==void 0&&(0,G.jsx)(mp,{previous:a,next:r,deps:t}),n(r)]},r)})]})},gp=({analysis:e,sections:t,deps:n,contractOnly:r,isContract:i,openCalls:a,onToggleCall:o,before:s,trailingProofs:c,mechanicalCount:l,scrollRequest:u,signatureOf:d})=>{(0,H.useEffect)(()=>{if(u===null)return;let e=document.getElementById(u.id);if(e===null)return;let t=e.querySelector(`:scope > .hunk-card, :scope > div > .mechanical-toggle`)??e,n=e.classList.contains(`decision`);e.scrollIntoView({block:n?`center`:`start`}),t.focus({preventScroll:!0})},[u]);let f=e=>r?e.filter(i):e,p=t.some(e=>f(e.partIds).length>0);return(0,G.jsxs)(`section`,{className:`main-area map`,"aria-label":`Changes`,children:[e.tour?.builtBy===`code`&&e.stages.tour===`done`&&(0,G.jsx)(`p`,{className:`banner`,children:`The model couldn't title the tour, so its steps keep the code's titles.`}),s,r&&!p&&(0,G.jsx)(`p`,{className:`muted`,children:`No contract changes in this pull request. Turn off “Contract changes only” to see the rest.`}),t.map(t=>{let i=f(t.partIds);if(r&&i.length===0)return null;let s=Ff(t);return(0,G.jsxs)(`section`,{id:$(s),className:`map-step`,"aria-labelledby":`${$(s)}-title`,tabIndex:-1,children:[t.kind===`step`?(0,G.jsxs)(`header`,{className:t.step.kind===`supporting`?`step-heading supporting`:`step-heading`,children:[(0,G.jsxs)(`h2`,{id:`${$(s)}-title`,className:`model-text`,children:[(0,G.jsx)(`span`,{className:`step-number`,children:t.number}),` `,t.step.title]}),t.step.codeTitle!==null&&(0,G.jsx)(`p`,{className:`step-code-title`,children:t.step.codeTitle}),(0,G.jsx)(`p`,{className:`model-text`,children:t.step.explanation}),t.step.merged.map(e=>(0,G.jsxs)(`p`,{className:`step-merged`,children:[`Also reads `,e.title,`: `,(0,G.jsx)(`span`,{className:`model-text`,children:e.reason})]},e.title)),(0,G.jsx)(fp,{via:t.step.via,deps:n})]}):(0,G.jsxs)(`header`,{className:`step-heading`,children:[(0,G.jsx)(`h2`,{id:`${$(s)}-title`,children:`Changes by file`}),(0,G.jsx)(`p`,{className:`muted`,children:e.status===`running`?`The guided tour appears when the analysis finishes.`:`There's no guided tour, so the changes are shown by file.`})]}),Nf(i,n.index).map(e=>{let t=(e,t)=>(0,G.jsx)(pp,{id:e,deps:n,openCalls:a,onToggleCall:o,signatureOf:d,inFile:t},e),[r,...i]=e.partIds;return r!==void 0&&i.length===0?t(r,!1):(0,G.jsx)(hp,{group:e,deps:n,part:e=>t(e,!0)},`${e.file.path}@${r}`)})]},s)}),!r&&(0,G.jsxs)(`div`,{id:`mechanical-changes`,className:`map-mechanical`,tabIndex:-1,children:[l===0&&e.stages.prep===`done`&&(0,G.jsx)(`p`,{className:`muted`,children:`No mechanical changes in this pull request.`}),(0,G.jsx)(Wd,{files:e.files,proofs:c,risk:e.risk}),(0,G.jsx)(Jd,{files:e.files})]})]})},_p=64,vp=56,yp=24,bp=16,xp=120,Sp=300,Cp=7.8,wp=6.6,Tp=6.7,Ep=72,Dp=20,Op=380,kp=e=>e.slice(e.lastIndexOf(`/`)+1),Ap=e=>e===1?`1 use`:`${e} uses`,jp=e=>e.kind===`outside`?`${e.paths.length>1?`${e.paths.length} files · `:``}outside the PR · ${Ap(e.uses)}`:`${e.kind===`group`?`${e.paths.length} files · `:``}+${e.added} −${e.deleted}${e.entries.length>0?` · ${e.entries.join(`, `)}`:``}`,Mp=e=>{let t=e.badges.reduce((e,t)=>e+kp(t).length*Tp+14,0),n=Math.min(Math.max(e.label.length*Cp+Ep,jp(e).length*wp+Dp,t+Dp),Op),r=xp+Math.sqrt(e.added+e.deleted)*9;return Math.round(Math.max(n,Math.min(r,Sp)))},Np=72,Pp=(e,t)=>{let n=e.map(e=>e.reduce((e,t,n)=>e+Mp(t)+(n>0?yp:0),0)),r=Math.max(0,...n)+32,i=r+(t?Np:0),a=new Map;return e.forEach((e,t)=>{let i=(r-(n[t]??0))/2;for(let n of e){let e=Mp(n);a.set(n.key,{x:i,y:bp+t*120,width:e}),i+=e+yp}}),{boxes:a,width:i,height:e.length===0?0:32+e.length*_p+(e.length-1)*vp}},Fp=e=>e.outside?`outside`:e.uses.includes(`call`)?`call`:e.uses.includes(`request`)?`request`:e.uses.every(e=>e===`import`)?`import`:`type`,Ip=(e,t)=>{let n=e=>{let n=t.get(e);return n===void 0?0:n.x+n.width/2},r=(e,r,i)=>{let a=t.get(r),o=[...e].sort((e,t)=>n(i(e))-n(i(t)));return new Map(o.map((e,t)=>[e,a===void 0?0:a.x+a.width*(.5+(o.length===1?0:(t/(o.length-1)-.5)*.5))]))},i=e.filter(e=>!e.back&&!e.outside),a=new Map,o=new Map;for(let e of t.keys()){for(let[t,n]of r(i.filter(t=>t.from===e),e,e=>e.to))a.set(t,n);for(let[t,n]of r(i.filter(t=>t.to===e),e,e=>e.from))o.set(t,n)}return{out:a,into:o}},Lp=(e,t,n,r,i=e.x+e.width/2,a=t.x+t.width/2)=>{if(n){let n=e.x+e.width,i=t.x+t.width,a=e.y+_p/2,o=t.y+_p/2,s=r-Np/2;return`M ${n} ${a} C ${s} ${a} ${s} ${o} ${i} ${o}`}if(e.y>t.y){let n=e.y,r=t.y+_p,o=Math.max(vp/2,(n-r)/2);return`M ${i} ${n} C ${i} ${n-o} ${a} ${r+o} ${a} ${r}`}let o=e.y+_p,s=t.y,c=Math.max(vp/2,(s-o)/2);return`M ${i} ${o} C ${i} ${o+c} ${a} ${s-c} ${a} ${s}`},Rp={import:`imports`,call:`calls`,type:`uses types from`,request:`sends requests to`},zp=(e,t)=>{let n=e.uses.map(e=>Rp[e]).join(`, `),r=e.symbols.length>0?`: ${e.symbols.join(`, `)}`:``;return`${t(e.from)} ${n} ${t(e.to)}${r}`},Bp=(e,t)=>{let{done:n,total:r}=Kf(e.partIds,t);return{done:n,total:r,all:n===r}},Vp=({node:e,box:t,reviewed:n,active:r,onOpen:i,onFocus:a})=>{let o=Bp(e,n),s=e.kind===`group`,c=e.kind===`outside`,l=(c?[e.label,jp(e)]:[e.label,s?`${e.paths.length} files`:null,...e.entries,e.risk,e.generated?`generated`:null,o.all?`reviewed`:`${o.done} of ${o.total} hunks reviewed`]).filter(e=>e!==null).join(`, `);return(0,G.jsxs)(`button`,{type:`button`,className:`overview-node ${c?`outside`:`risk-${e.risk}`}${e.generated?` generated`:``}${s?` group`:``}${r?` active`:``}`,"data-key":e.key,"aria-label":l,title:e.paths.length===1?e.paths[0]:void 0,style:t===void 0?{width:Mp(e)}:{left:t.x,top:t.y,width:t.width,height:_p},onClick:()=>i(e),onFocus:()=>a(e),onMouseEnter:()=>a(e),onMouseLeave:()=>a(null),children:[(0,G.jsxs)(`span`,{className:`overview-node-head`,children:[(0,G.jsx)(`span`,{className:`overview-label`,children:e.label}),c?null:o.all?(0,G.jsx)(`span`,{className:`overview-tick`,role:`img`,"aria-label":`reviewed`,children:`✓`}):(0,G.jsxs)(`span`,{className:`overview-count`,children:[o.done,`/`,o.total]})]}),(0,G.jsx)(`span`,{className:`overview-meta`,children:jp(e)}),e.badges.length>0&&(0,G.jsx)(`span`,{className:`overview-badges`,children:e.badges.map(e=>(0,G.jsx)(`span`,{className:`overview-badge`,children:kp(e)},e))})]})},Hp=({overview:e,reviewed:t,focusKey:n,onOpen:r,onCollapse:i,expandedGroups:a,onFocusNode:o})=>{let s=(0,H.useId)(),c=(0,H.useRef)(null),[l,u]=(0,H.useState)(null),{boxes:d,width:f,height:p}=(0,H.useMemo)(()=>Pp(e.rows,e.edges.some(e=>e.back)),[e]),m=(0,H.useMemo)(()=>Ip(e.edges,d),[e.edges,d]),h=(0,H.useMemo)(()=>new Map([...e.rows.flat(),...e.strip].map(e=>[e.key,e.label])),[e]),g=e=>h.get(e)??e,_=(0,H.useMemo)(()=>[...e.rows,e.strip].filter(e=>e.length>0),[e]);(0,H.useEffect)(()=>u(null),[e]);let v=(0,H.useRef)(-1);(0,H.useEffect)(()=>{if(n===null||v.current===n.n)return;let t=e.placeOf.get(n.key)??n.key,r=c.current?.querySelector(`[data-key="${CSS.escape(t)}"]`);r==null||t.startsWith(`group:`)||(v.current=n.n,r.focus(),r.scrollIntoView?.({block:`nearest`,inline:`nearest`}))},[n,e]);let y=e=>c.current?.querySelector(`[data-key="${CSS.escape(e)}"]`)?.focus(),b=e=>{let t=e.target.dataset.key;if(t===void 0)return;let n=_.findIndex(e=>e.some(e=>e.key===t)),r=_[n]?.findIndex(e=>e.key===t)??-1,i=e=>{let t=c.current?.querySelector(`[data-key="${CSS.escape(e.key)}"]`)?.getBoundingClientRect();return t===void 0?0:t.left+t.width/2},a;if(e.key===`ArrowRight`)a=_[n]?.[r+1];else if(e.key===`ArrowLeft`)a=_[n]?.[r-1];else if(e.key===`ArrowDown`||e.key===`ArrowUp`){let t=_[n+(e.key===`ArrowDown`?1:-1)]??[],o=_[n]?.[r],s=o===void 0?0:i(o);a=[...t].sort((e,t)=>Math.abs(i(e)-s)-Math.abs(i(t)-s))[0]}else return;e.preventDefault(),a!==void 0&&y(a.key)},x=l?.kind===`node`?l.node.key:null,S=e=>e.from===x||e.to===x,ee=e=>{e!==null&&o(e.key),u(e===null?null:{kind:`node`,node:e})},te=e=>({node:e,reviewed:t,active:x===e.key,onOpen:r,onFocus:ee});return(0,G.jsxs)(`section`,{className:`overview`,"aria-label":`Overview of the changed files`,ref:c,onKeyDown:b,children:[(0,G.jsxs)(`p`,{className:`overview-legend muted`,children:[`Files that nothing in the pull request calls are on top; each file sits below its callers. Solid lines are calls, dash-dot ones HTTP requests to a route, dashed ones imports, dotted ones types. Tests show on the files they call.`,e.edges.some(e=>e.outside)&&` Faded files are outside the pull request, under the files whose changes they use.`]}),a.length>0&&(0,G.jsx)(`p`,{className:`overview-expanded`,children:a.map(e=>(0,G.jsxs)(`button`,{type:`button`,className:`button quiet`,onClick:()=>i(e),children:[`Collapse `,e.slice(6),`/`]},e))}),e.rows.length>0?(0,G.jsx)(`div`,{className:`overview-scroll`,children:(0,G.jsxs)(`div`,{className:`overview-diagram`,style:{width:f,height:p},children:[(0,G.jsxs)(`svg`,{className:`overview-edges`,width:f,height:p,"aria-hidden":`true`,children:[(0,G.jsx)(`defs`,{children:(0,G.jsx)(`marker`,{id:`${s}-arrow`,viewBox:`0 0 8 8`,refX:`7`,refY:`4`,markerWidth:`7`,markerHeight:`7`,orient:`auto-start-reverse`,children:(0,G.jsx)(`path`,{d:`M 0 0 L 8 4 L 0 8 z`,className:`overview-arrow`})})}),e.edges.map(e=>{let t=d.get(e.from),n=d.get(e.to);if(t===void 0||n===void 0)return null;let r=Lp(t,n,e.back,f,m.out.get(e),m.into.get(e)),i=S(e)||l?.kind===`edge`&&l.edge===e,a=l!==null&&!i;return(0,G.jsxs)(`g`,{className:`overview-edge ${Fp(e)}${i?` lit`:``}${a?` dim`:``}`,onMouseEnter:()=>u({kind:`edge`,edge:e}),onMouseLeave:()=>u(null),children:[(0,G.jsx)(`path`,{d:r,className:`overview-edge-hit`}),(0,G.jsx)(`path`,{d:r,className:`overview-edge-line`,markerEnd:`url(#${s}-arrow)`}),(0,G.jsx)(`title`,{children:zp(e,g)})]},`${e.from}>${e.to}`)})]}),e.rows.flat().map(e=>(0,G.jsx)(Vp,{box:d.get(e.key),...te(e)},e.key))]})}):(0,G.jsx)(`p`,{className:`muted`,children:`No changed file calls or imports another.`}),e.strip.length>0&&(0,G.jsxs)(`section`,{className:`overview-strip`,"aria-label":`Not linked`,children:[(0,G.jsx)(`h3`,{children:`Not linked`}),(0,G.jsx)(`div`,{className:`overview-strip-nodes`,children:e.strip.map(e=>(0,G.jsx)(Vp,{...te(e)},e.key))})]}),(0,G.jsx)(`p`,{className:`overview-detail`,"aria-live":`polite`,children:l===null?`Hover or focus a file to see its flows and tests.`:l.kind===`edge`?zp(l.edge,g):Up(l.node,e.edges,g)})]})},Up=(e,t,n)=>{let r=t.filter(t=>t.from===e.key).map(e=>{let t=e.symbols.length>0?` (${e.symbols.join(`, `)})`:``;return`${n(e.to)}${t}`});return e.kind===`outside`?`${e.paths.length>1?`${e.label}: ${e.paths.length} files`:e.paths[0]} · outside the pull request · uses ${r.join(`, `)}.`:`${[e.kind===`group`?`${e.label}: ${e.paths.length} files, Enter expands`:e.paths[0],e.flows.length>0?`read in ${e.flows.join(`; `)}`:`in no flow`,...r.length>0?[`reaches ${r.join(`, `)}`]:[],...e.badges.length>0?[`tested in ${e.badges.map(kp).join(`, `)}`]:[]].join(` · `)}.`},Wp={mechanical:0,logic:1,contract:2},Gp=[`import`,`call`,`type`,`request`],Kp=e=>e.slice(e.lastIndexOf(`/`)+1),qp=e=>e.slice(0,Math.max(e.lastIndexOf(`/`),0)),Jp=(e,t)=>e<t?-1:+(e>t),Yp=e=>/\.(md|mdx|rst|adoc)$/i.test(e),Xp=/(^|[/_.-])(fakes?|mocks?|stubs?|fixtures?|testing|test[_-]?(utils?|helpers?|support))([/_.-]|$)/i,Zp=e=>qp(e).split(`/`).slice(0,3).join(`/`),Qp=e=>`group:${e}`,$p=e=>{let t=new Map(e.map(e=>[e,e.split(`/`)])),n=(e,n)=>(t.get(e)??[]).slice(-n).join(`/`),r=new Map;for(let i of e){let a=t.get(i)?.length??1,o=1;for(;o<a&&e.some(e=>e!==i&&n(e,o)===n(i,o));)o+=1;r.set(i,n(i,o))}return r},em=`\0routes`,tm=e=>`${e.method} ${e.path}`,nm=e=>{let[t]=e;return e.length===1&&t!==void 0?`${t.method} ${t.path}`:`${e.length} routes`},rm=(e,t)=>{let n=wc(e.parts),r=new Map(e.files.flatMap(e=>Tc(e,n).map(({id:t,hunk:n})=>[t,{file:e,hunk:n}]))),i=new Map,a=(e,t)=>{let n=i.get(e)??[];n.includes(t)||i.set(e,[...n,t])},o=new Map;for(let e of t){let t=new Map;for(let n of e.entries){let e=r.get(n)?.file.path;e!==void 0&&t.set(e,[...t.get(e)??[],n])}for(let[n,i]of t){let t=i.flatMap(e=>{let t=r.get(e),n=t===void 0?null:bl(t.file,t.hunk,[]);return n?.kind===`route`?n.routes:[]});if(t.length>0&&(a(n,em),o.set(n,[...o.get(n)??[],...t])),!(new Set(t.map(tm)).size===i.length&&t.length>0))for(let t of(e.codeTitle??e.title).split(`; `)){t.startsWith(`Page: `)&&a(n,t);let e=/^Command: (\S+) in (.+)$/.exec(t);e!==null&&e[2]===Kp(n)&&a(n,`Command: ${e[1]}`)}}}return new Map([...i].map(([e,t])=>{let n=[...new Map((o.get(e)??[]).map(e=>[tm(e),e])).values()];return[e,t.map(e=>e===em?nm(n):e)]}))},im=(e,t)=>{let n=new Map,r=new Map,i=[],a=new Set,o=[],s=0,c=e=>{n.set(e,s),r.set(e,s),s+=1,i.push(e),a.add(e);for(let i of t(e))n.has(i)?a.has(i)&&r.set(e,Math.min(r.get(e)??0,n.get(i)??0)):(c(i),r.set(e,Math.min(r.get(e)??0,r.get(i)??0)));if(r.get(e)!==n.get(e))return;let l=[];for(let t=i.pop();t!==void 0&&(a.delete(t),l.push(t),t!==e);t=i.pop());l.length>1&&o.push(l)};for(let t of e)n.has(t)||c(t);return o},am=(e,t,n=new Set)=>{let r=new Set(e.proofs.flatMap(e=>e.hunkId??[])),i=new Map(e.risk.map(e=>[e.hunkId,e.riskClass])),a=[...new Set(t.flatMap(e=>e.partIds))],o=new Map(a.map((e,t)=>[e,t])),s=e=>o.get(e)??a.length,c=new Set(e.generated),l=e.files.filter(e=>e.hunks.some(e=>!r.has(e.id))),u=new Map(l.flatMap(e=>e.hunks.map(t=>[t.id,e.path]))),d=new Map(l.map(t=>{let n=t.hunks.flatMap(e=>e.lines),a=Tc(t,wc(e.parts)).map(e=>e.id).filter(e=>!r.has(Sc(e))).sort((e,t)=>s(e)-s(t)),o=t.hunks.map(e=>r.has(e.id)?`mechanical`:i.get(e.id)??`logic`).reduce((e,t)=>Wp[t]>Wp[e]?t:e,`mechanical`);return[t.path,{added:n.filter(e=>e.kind===`add`).length,deleted:n.filter(e=>e.kind===`del`).length,partIds:a,risk:o,rank:a.reduce((e,t)=>Math.min(e,s(t)),1/0)}]})),f=e=>d.get(e)?.rank??1/0,p=(e,t)=>f(e)-f(t)||Jp(e,t),m=l.map(e=>e.path).sort(p),h=new Map,g=(e,t,n,r)=>{if(e===t||!d.has(e)||!d.has(t))return;let i=h.get(e)??new Map,a=i.get(t)??{uses:new Set,symbols:new Set};a.uses.add(n),r!==void 0&&a.symbols.add(r),i.set(t,a),h.set(e,i)};for(let{from:t,to:n}of e.fileLinks)g(t,n,`import`);for(let t of e.callGraph){let e=u.get(Sc(t.fromPartId)),n=u.get(Sc(t.toPartId));e!==void 0&&n!==void 0&&g(e,n,t.use,t.symbol)}let _=e=>[...h.get(e)?.keys()??[]],v=e=>m.filter(t=>h.get(t)?.has(e)===!0),y=new Set(m.filter(kc));for(let e=!0;e;){e=!1;for(let t of m){let n=v(t);!y.has(t)&&Xp.test(t)&&n.length>0&&n.every(e=>y.has(e))&&(y.add(t),e=!0)}}let b=m.filter(e=>!y.has(e)&&Yp(e)),x=m.filter(e=>!y.has(e)&&!Yp(e)),S=new Set(x),ee=new Map;for(let e of[...y].sort(p)){let t=[],n=new Set([e]),r=e=>{for(let i of _(e))n.has(i)||(n.add(i),S.has(i)?t.push(i):r(i))};r(e),ee.set(e,t)}let te=new Map;for(let[e,t]of ee)for(let n of t)te.set(n,[...te.get(n)??[],e]);let C=x.length>40,w=new Map;for(let e of x){let t=Zp(e),r=C&&!n.has(Qp(t))?Qp(t):e;w.set(r,[...w.get(r)??[],e])}for(let[e,t]of[...w]){let[n]=t;e.startsWith(`group:`)&&t.length===1&&n!==void 0&&(w.delete(e),w.set(n,[n]))}let T=new Map;for(let[e,t]of w)for(let n of t)T.set(n,e);let ne=e=>Math.min(...(w.get(e)??[e]).map(f)),re=(e,t)=>ne(e)-ne(t)||Jp(e,t),ie=[...w.keys()].sort(re),ae=new Map;for(let[e,t]of h)for(let[n,r]of t){let t=T.get(e),i=T.get(n);if(t===void 0||i===void 0||t===i)continue;let a=ae.get(t)??new Map,o=a.get(i)??{uses:new Set,symbols:new Set};for(let e of r.uses)o.uses.add(e);for(let e of r.symbols)o.symbols.add(e);a.set(i,o),ae.set(t,a)}let oe=new Map;for(let{partId:t,symbol:n,uses:r}of e.unchangedCallers??[]){let e=u.get(Sc(t)),i=e===void 0?void 0:T.get(e);if(i!==void 0)for(let e of r){let r=oe.get(e.path)??{targets:new Map,uses:0,partIds:new Set},a=r.targets.get(i)??{uses:new Set,symbols:new Set};a.uses.add(e.use),a.symbols.add(n),r.targets.set(i,a),r.uses+=1,r.partIds.add(t),oe.set(e.path,r)}}let se=[...oe.keys()].sort((e,t)=>Number(kc(e))-Number(kc(t))||Jp(e,t)),ce=new Map;for(let e of se){let t=se.length>10?`outside:${Zp(e)}/`:`outside:${e}`;ce.set(t,[...ce.get(t)??[],e])}for(let[e,t]of[...ce]){let[n]=t;e.endsWith(`/`)&&t.length===1&&n!==void 0&&(ce.delete(e),ce.set(`outside:${n}`,[n]))}let le=new Map;for(let[e,t]of ce){let n=new Map;for(let e of t)for(let[t,r]of oe.get(e)?.targets??[]){let e=n.get(t)??{uses:new Set,symbols:new Set};for(let t of r.uses)e.uses.add(t);for(let t of r.symbols)e.symbols.add(t);n.set(t,e)}le.set(e,n)}let ue=new Set([...[...ae].flatMap(([e,t])=>t.size>0?[e,...t.keys()]:[]),...[...le.values()].flatMap(e=>[...e.keys()])]),E=ie.filter(e=>ue.has(e)),de=new Set,fe=(e,t)=>`${e}\u0000${t}`,pe=e=>[...ae.get(e)?.keys()??[]].filter(t=>!de.has(fe(e,t)));for(let e=im(E,pe);e.length>0;e=im(E,pe))for(let t of e){let[e]=[...t].sort(re);for(let n of t)e!==void 0&&pe(n).includes(e)&&de.add(fe(n,e))}let me=new Map(E.map(e=>[e,[]]));for(let e of E)for(let t of pe(e))me.get(t)?.push(e);let he=new Map,ge=e=>{let t=he.get(e);if(t!==void 0)return t;let n=Math.max(-1,...(me.get(e)??[]).map(ge))+1;return he.set(e,n),n},_e=[],ve=(e,t)=>{for(;_e.length<=t;)_e.push([]);_e[t]?.push(e)};for(let e of E)ve(e,ge(e));for(let[e,t]of le){let n=[...t.keys()];me.set(e,n),he.set(e,Math.max(...n.map(ge))+1),ve(e,he.get(e)??0)}let ye=()=>new Map(_e.flatMap(e=>e.map((t,n)=>[t,n-(e.length-1)/2]))),be=e=>pe(e),xe=(e,t)=>{for(let n of e){let e=ye(),r=n=>{let r=t(n).map(t=>e.get(t)??0);return r.length===0?e.get(n)??0:r.reduce((e,t)=>e+t,0)/r.length},i=new Map(n.map(e=>[e,r(e)]));n.sort((e,t)=>(i.get(e)??0)-(i.get(t)??0)||re(e,t))}},Se=e=>me.get(e)??[];xe(_e.slice(1),Se),xe(_e.slice(0,-1).reverse(),be),xe(_e.slice(1),Se);let Ce=$p(m),D=rm(e,t),O=new Map;for(let e of t)if(e.kind===`flow`)for(let t of new Set(e.partIds.flatMap(e=>u.get(Sc(e))??[])))O.set(t,[...O.get(t)??[],e.title]);let we=e=>[...new Set(e)],Te=$p(se),Ee=(e,t)=>{let n=ce.get(e)??[],[r]=n;return{key:e,kind:`outside`,paths:n,label:e.endsWith(`/`)||r===void 0?e.slice(8):Te.get(r)??r,added:0,deleted:0,risk:`logic`,generated:!1,entries:[],flows:[],partIds:[...new Set(n.flatMap(e=>[...oe.get(e)?.partIds??[]]))],uses:n.reduce((e,t)=>e+(oe.get(t)?.uses??0),0),badges:[],row:t}},De=(e,t)=>{if(ce.has(e))return Ee(e,t);let n=w.get(e)??[e],r=n.flatMap(e=>d.get(e)??[]),i=e.startsWith(`group:`);return{key:e,kind:i?`group`:`file`,paths:n,label:i?`${e.slice(6)||`.`}/`:Ce.get(e)??e,added:r.reduce((e,t)=>e+t.added,0),deleted:r.reduce((e,t)=>e+t.deleted,0),risk:r.map(e=>e.risk).reduce((e,t)=>Wp[t]>Wp[e]?t:e,`mechanical`),generated:n.every(e=>c.has(e)),entries:we(n.flatMap(e=>D.get(e)??[])),flows:we(n.flatMap(e=>O.get(e)??[])),partIds:r.flatMap(e=>e.partIds).sort((e,t)=>s(e)-s(t)),badges:we(n.flatMap(e=>te.get(e)??[])).sort(p),uses:0,row:t}},k=_e.map((e,t)=>e.map(e=>De(e,t))),A=[...ie.filter(e=>!ue.has(e)),...b,...[...y].filter(e=>(ee.get(e)??[]).length===0)].sort(re).map(e=>De(e,-1)),Oe=new Map;for(let e of[...k.flat(),...A])if(e.kind!==`outside`)for(let t of e.paths)Oe.set(t,e.key);for(let[e,t]of ee){let[n]=t,r=n===void 0?void 0:T.get(n);r!==void 0&&Oe.set(e,r)}return{rows:k,edges:[...[...ae].map(e=>[e,!1]),...[...le].map(e=>[e,!0])].flatMap(([[e,t],n])=>[...t].map(([t,r])=>({from:e,to:t,uses:Gp.filter(e=>r.uses.has(e)),symbols:[...r.symbols].sort(Jp),back:de.has(fe(e,t)),outside:n}))),strip:A,placeOf:Oe,grouped:C}},om={collect:`Collect`,prep:`Prepare`,intent:`Intent`,risk:`Risk`,decisions:`Decisions`,tour:`Tour`},sm={pending:`waiting`,running:`running`,done:`done`,failed:`failed`,skipped:`skipped`},cm={pending:`○`,running:`◐`,done:`●`,failed:`✗`,skipped:`–`},lm=({stages:e,filesFetched:t})=>(0,G.jsx)(`ol`,{className:`progress-strip`,"aria-label":`Analysis progress`,children:sl.options.map(n=>{let r=e[n];return(0,G.jsxs)(`li`,{className:`stage ${r}`,children:[(0,G.jsx)(`span`,{"aria-hidden":`true`,children:cm[r]}),` `,om[n],(0,G.jsxs)(`span`,{className:`visually-hidden`,children:[`: `,sm[r]]}),n===`collect`&&r===`running`&&t!==null&&(0,G.jsxs)(`span`,{className:`stage-detail`,children:[` `,`· `,t.done,` of `,t.total,` files`]})]},n)})}),um=e=>om[e],dm={approve:`Approve`,request_changes:`Request changes`,comment:`Comment`},fm=(e,t,n)=>`${e} ${e===1?t:n}`,pm=({analysisId:e,isAuthor:t,pendingCount:n,hunkComments:r,chooseVerdict:i,onClose:a,onPublished:o})=>{let{client:s}=cu(),c=(0,H.useId)(),[l,u]=(0,H.useState)(``),[d,f]=(0,H.useState)(`comment`),p=i&&!t?d:null,[m,h]=(0,H.useState)(null),[g,_]=(0,H.useState)(null),[v,y]=(0,H.useState)(!1),[b,x]=(0,H.useState)(!1),S=mu(s.publish),ee=(0,H.useRef)(!1);(0,H.useEffect)(()=>{let t=!0,n=setTimeout(()=>void s.previewPublication(e,{summary:l,hunkComments:r,verdict:p}).then(e=>{t&&(ee.current=!0,h(e.ok?e.value:null),_(e.ok?null:e.error))}),ee.current?400:0);return()=>{t=!1,clearTimeout(n)}},[e,s,l,r,p]);let te=async t=>{x(t),y(!1);let n=await S.run(e,{summary:l,allowStale:t,hunkComments:r,verdict:p});n.ok?o(n.value):n.error.code===`stale-analysis`&&(S.reset(),y(!0))};return(0,G.jsxs)(af,{title:`Publish the review`,onClose:a,className:`publish-dialog`,children:[(0,G.jsx)(`label`,{htmlFor:`${c}-summary`,children:`Summary`}),(0,G.jsx)(`textarea`,{id:`${c}-summary`,className:`input summary-field`,rows:4,"data-autofocus":!0,placeholder:`What you'd like the author to know overall (optional)`,value:l,onChange:e=>u(e.target.value)}),i&&!t&&(0,G.jsxs)(`fieldset`,{className:`verdict-choice`,children:[(0,G.jsx)(`legend`,{children:`Verdict`}),[`approve`,`request_changes`,`comment`].map(e=>(0,G.jsxs)(`label`,{children:[(0,G.jsx)(`input`,{type:`radio`,name:`${c}-verdict`,checked:d===e,onChange:()=>f(e)}),dm[e]]},e))]}),(0,G.jsxs)(`section`,{className:`preview`,"aria-labelledby":`${c}-preview`,"aria-busy":m===null,children:[(0,G.jsx)(`h3`,{id:`${c}-preview`,children:`What will be posted`}),g===null?m===null?(0,G.jsx)(`p`,{className:`muted`,children:`Building the preview…`}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`p`,{children:[`Verdict:`,` `,(0,G.jsx)(`strong`,{className:`publication-verdict ${m.verdict}`,children:dm[m.verdict]})]}),t&&m.verdict===`comment`&&(0,G.jsx)(`p`,{className:`muted`,children:`You opened this pull request, so the review is posted as a comment: hosts don't let authors approve their own pull requests or request changes on them.`}),n>0&&(0,G.jsxs)(`p`,{className:`banner warning`,children:[fm(n,`decision isn't`,`decisions aren't`),` reviewed yet. The summary lists `,n===1?`it`:`them`,` as not reviewed.`]}),(0,G.jsx)(`h4`,{children:fm(m.comments.length,`inline comment`,`inline comments`)}),m.comments.length>0&&(0,G.jsx)(`ul`,{className:`preview-comments`,children:m.comments.map(e=>(0,G.jsxs)(`li`,{children:[(0,G.jsxs)(`code`,{children:[e.path,`:`,e.line,e.side===`old`?` (old side)`:``]}),(0,G.jsx)(`p`,{className:`posted-text`,children:e.body})]},e.key))}),(0,G.jsx)(`h4`,{children:`Summary comment`}),(0,G.jsx)(`p`,{className:`posted-text`,children:m.summary})]}):(0,G.jsxs)(`p`,{className:`banner danger`,role:`alert`,children:[`Couldn't build the preview. `,_u(g)]})]}),v?(0,G.jsxs)(`div`,{className:`banner warning`,role:`alert`,children:[(0,G.jsx)(`p`,{children:`This PR changed since the analysis. Publish anyway?`}),(0,G.jsxs)(`div`,{className:`dialog-actions`,children:[(0,G.jsx)(`button`,{type:`button`,className:`button`,onClick:()=>y(!1),children:`Cancel`}),(0,G.jsx)(`button`,{type:`button`,className:`button primary`,onClick:()=>void te(!0),children:`Publish anyway`})]})]}):(0,G.jsxs)(G.Fragment,{children:[S.error!==null&&(0,G.jsxs)(`div`,{className:`banner danger`,role:`alert`,children:[(0,G.jsxs)(`p`,{children:[`Couldn't publish. `,_u(S.error)]}),(0,G.jsx)(`p`,{className:`muted`,children:`Retrying is safe: comments that were already posted aren't posted again.`})]}),(0,G.jsxs)(`div`,{className:`dialog-actions`,children:[(0,G.jsx)(`button`,{type:`button`,className:`button`,onClick:a,children:`Cancel`}),(0,G.jsx)(`button`,{type:`button`,className:`button primary`,disabled:S.pending||m===null,onClick:()=>void te(b),children:S.pending?`Publishing…`:S.error===null?`Publish`:`Retry`})]})]})]})},mm=2,hm=({view:e,intent:t,tools:n,reanalyzing:r,reanalyzeError:i,onReanalyze:a,onPublish:o})=>{let{analysis:s,publication:c,stale:l}=e,{pullRequest:u,warnings:d}=s,{ref:f}=s.key;return(0,G.jsxs)(`header`,{className:`review-header`,children:[(0,G.jsxs)(`div`,{className:`review-title`,children:[(0,G.jsxs)(`p`,{className:`pr-meta`,children:[(0,G.jsxs)(`a`,{href:u?.url??Nl(f),target:`_blank`,rel:`noreferrer`,children:[f.repo.owner,`/`,f.repo.repo,` #`,f.number]}),u!==null&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`span`,{children:[` · `,u.author.name||u.author.id]}),(0,G.jsxs)(`span`,{children:[` · `,(0,G.jsx)(`code`,{children:u.sourceBranch}),` → `,(0,G.jsx)(`code`,{children:u.targetBranch})]})]})]}),(0,G.jsx)(`h1`,{className:`model-text`,children:u?.title??`Collecting the pull request…`}),t]}),(0,G.jsxs)(`div`,{className:`review-actions`,children:[n,c===null?(0,G.jsx)(`button`,{type:`button`,className:`button primary`,disabled:s.status!==`complete`,onClick:o,children:`Publish…`}):(0,G.jsxs)(`p`,{className:`published`,role:`status`,children:[(0,G.jsx)(`span`,{"aria-hidden":`true`,children:`✓`}),` `,c.url===null?`Published`:(0,G.jsx)(`a`,{href:c.url,target:`_blank`,rel:`noreferrer`,children:`Published`})]})]}),l&&(0,G.jsxs)(`div`,{className:`banner warning stale-banner`,role:`status`,children:[(0,G.jsx)(`span`,{children:`This PR has new commits since the analysis.`}),(0,G.jsx)(`button`,{type:`button`,className:`button`,disabled:r,onClick:a,children:r?`Starting…`:`Re-analyze`}),i!==null&&(0,G.jsx)(`span`,{className:`field-error`,role:`alert`,children:_u(i)})]}),d.length>0&&d.length<=mm&&(0,G.jsx)(`ul`,{className:`warnings`,"aria-label":`Warnings`,children:d.map(e=>(0,G.jsx)(`li`,{className:`banner warning`,children:e},e))}),d.length>mm&&(0,G.jsxs)(`details`,{className:`warnings banner warning`,children:[(0,G.jsxs)(`summary`,{children:[d.length,` warnings`]}),(0,G.jsx)(`ul`,{children:d.map(e=>(0,G.jsx)(`li`,{children:e},e))})]})]})},gm=e=>{let[t,n]=(0,H.useState)(new Set);return(0,H.useEffect)(()=>{if(typeof IntersectionObserver>`u`)return;n(new Set);let t=new Set,r=new Map,i=new IntersectionObserver(e=>{for(let n of e){let e=r.get(n.target);e!==void 0&&(n.isIntersecting?t.add(e):t.delete(e))}n(new Set(t))});for(let t of e){let e=document.getElementById(of(t));e!==null&&(r.set(e,t),i.observe(e))}return()=>i.disconnect()},[e]),t},_m=({sections:e,activePartId:t,index:n,decisionsOn:r,totals:i,reviewed:a,contractOnly:o,onContractOnly:s,mechanicalCount:c,onGo:l,onInView:u})=>{let d=(0,H.useId)(),[f,p]=(0,H.useState)(null),m=(0,H.useRef)(null),[h,g]=(0,H.useState)([]),_=e.flatMap(e=>e.partIds).filter(e=>!o||n.items([e])[0]?.risk.riskClass===`contract`),v=_.join(`,`);(0,H.useEffect)(()=>g(_),[v]);let y=gm(h),b=(0,H.useRef)(u);b.current=u,(0,H.useEffect)(()=>{b.current(h.filter(e=>y.has(e)));let e=m.current,t=e?.querySelector(`.rail-bar.in-view`);if(e==null||t==null)return;let n=t.offsetTop;(n<e.scrollTop||n>e.scrollTop+e.clientHeight-40)&&(e.scrollTop=Math.max(0,n-e.clientHeight/3))},[y,h]);let x=(t!=null&&(y.size===0||y.has(t))?t:h.find(e=>y.has(e)))??e[0]?.partIds[0];return(0,H.useEffect)(()=>p(null),[y]),(0,G.jsxs)(`aside`,{id:`review-map-rail`,ref:m,className:`risk-rail`,"aria-labelledby":`${d}-title`,children:[(0,G.jsxs)(`div`,{className:`rail-header`,children:[(0,G.jsx)(`h2`,{id:`${d}-title`,children:`Map`}),(0,G.jsxs)(`p`,{className:`risk-totals`,children:[(0,G.jsxs)(`span`,{className:i.contract>0?`risk-total-contract`:void 0,children:[i.contract,` contract`]}),` `,`· `,i.logic,` logic · `,i.mechanical,` mechanical`]}),(0,G.jsxs)(`label`,{className:`contract-only`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked)}),`Contract changes only`]})]}),(0,G.jsxs)(`ol`,{className:`rail-steps`,children:[e.map(e=>{let t=Ff(e),i=f===t||x!==void 0&&e.partIds.includes(x),s=e.partIds.filter(e=>!n.mechanical.has(e)),c=s.length>0&&s.every(e=>a.has(e));return(0,G.jsxs)(`li`,{children:[(0,G.jsxs)(`button`,{type:`button`,className:e.kind===`step`&&e.step.kind===`supporting`?`rail-step supporting`:`rail-step`,"aria-expanded":i,onClick:()=>{p(t),l({kind:`section`,key:t})},children:[e.kind===`step`&&(0,G.jsx)(`span`,{className:`rail-step-number`,children:e.number}),` `,(0,G.jsx)(`span`,{className:`rail-step-title model-text`,title:e.kind===`step`?e.step.codeTitle===null?e.step.title:`${e.step.title} · ${e.step.codeTitle}`:void 0,children:e.kind===`step`?e.step.title:`Changes by file`}),c&&(0,G.jsx)(`span`,{className:`rail-tick`,role:`img`,"aria-label":`reviewed`,children:`✓`})]}),(0,G.jsx)(`ul`,{className:`rail-bars`,hidden:!i,children:n.items(e.partIds).map(({id:e,hunk:t,file:i,risk:s})=>{let c=n.mechanical.has(e),u=c?`mechanical`:s.riskClass,d=!c&&a.has(e),f=r(e),p=u===`contract`&&s.source===`rule`,m=[u,f.length>0&&`${f.length} ${f.length===1?`decision`:`decisions`}`],h=[`rail-hunk`,y.has(e)&&`in-view`,o&&u!==`contract`&&`dimmed`];return(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{type:`button`,className:h.filter(Boolean).join(` `),"aria-label":`${i.path}, ${Yu(t)}, ${u}${d?`, reviewed`:``}`,"aria-current":y.has(e)?`location`:void 0,onClick:()=>l({kind:`hunk`,partId:e}),children:[(0,G.jsxs)(`span`,{className:`rail-bar risk-${u}${d?` reviewed`:``}`,style:{height:Rf(t)},children:[p&&(0,G.jsx)(`span`,{className:`rail-mark mark-rule`,title:s.reason,children:(0,G.jsxs)(`span`,{className:`visually-hidden`,children:[`Rule: `,s.reason]})}),f.map(e=>(0,G.jsx)(`span`,{className:`rail-mark mark-decision`,title:e.title,children:(0,G.jsxs)(`span`,{className:`visually-hidden`,children:[`Decision: `,e.title]})},e.id))]}),(0,G.jsxs)(`span`,{className:`rail-hunk-text`,children:[(0,G.jsxs)(`span`,{className:`rail-hunk-file`,children:[i.path.split(`/`).at(-1),` `,Yu(t).replace(/^lines /,``)]}),(0,G.jsx)(`span`,{className:`rail-hunk-meta`,children:m.filter(Boolean).join(` · `)})]}),d&&(0,G.jsx)(`span`,{className:`rail-bar-tick`,"aria-hidden":`true`,children:`✓`})]})},e)})})]},t)}),(0,G.jsx)(`li`,{children:(0,G.jsx)(`button`,{type:`button`,className:`rail-step mechanical`,onClick:()=>l({kind:`mechanical`}),children:(0,G.jsxs)(`span`,{className:`rail-step-title`,children:[`Proved mechanical (`,c,`)`]})})})]}),(0,G.jsxs)(`ul`,{className:`rail-legend`,"aria-label":`Legend`,children:[(0,G.jsxs)(`li`,{children:[(0,G.jsx)(`span`,{className:`legend-swatch risk-contract`}),` Contract`]}),(0,G.jsxs)(`li`,{children:[(0,G.jsx)(`span`,{className:`legend-swatch risk-logic`}),` Logic`]}),(0,G.jsxs)(`li`,{children:[(0,G.jsx)(`span`,{className:`legend-swatch risk-mechanical`}),` Mechanical`]}),(0,G.jsxs)(`li`,{children:[(0,G.jsx)(`span`,{className:`rail-mark mark-decision`}),` Decision`]}),(0,G.jsxs)(`li`,{children:[(0,G.jsx)(`span`,{className:`rail-mark mark-rule`}),` Contract rule`]})]})]})},vm=[`map`,`overview`],ym=new Set([`move-file`,`open-file`]),bm=[{keys:[`j`],action:`next-hunk`,description:`Next hunk`,layouts:[`map`]},{keys:[`k`],action:`previous-hunk`,description:`Previous hunk`,layouts:[`map`]},{keys:[`n`],action:`next-step`,description:`Next tour step`,layouts:[`map`]},{keys:[`p`],action:`previous-step`,description:`Previous tour step`,layouts:[`map`]},{keys:[`o`],action:`open-call`,description:`Open or close the hunk's first call`,layouts:[`map`]},{keys:[`x`],action:`toggle-reviewed`,description:`Mark the hunk reviewed and go to the next`,layouts:[`map`]},{keys:[`]`],action:`next-unreviewed`,description:`Next unreviewed hunk`,layouts:[`map`]},{keys:[`[`],action:`previous-unreviewed`,description:`Previous unreviewed hunk`,layouts:[`map`]},{keys:[`a`],action:`approve`,description:`Approve the selected decision`,layouts:[`map`]},{keys:[`r`],action:`reject`,description:`Reject the selected decision`,layouts:[`map`]},{keys:[`c`],action:`comment`,description:`Comment on the selected decision, or on the focused hunk`,layouts:[`map`]},{keys:[`Escape`],action:`escape`,description:`Clear the selection, go back to where a link was followed from, or back to the overview`,layouts:[`map`]},{keys:[`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`],action:`move-file`,description:`Move between files`,layouts:[`overview`]},{keys:[`Enter`],action:`open-file`,description:`Open the file's code in the map, or a group of files in place`,layouts:[`overview`]},{keys:[`⌘K`,`t`],action:`jump`,description:`Jump to anything`,layouts:vm},{keys:[`v`],action:`toggle-layout`,description:`Map or overview`,layouts:vm},{keys:[`?`],action:`help`,description:`Show these shortcuts`,layouts:vm}],xm=e=>new Map(bm.filter(({layouts:t,action:n})=>t.includes(e)&&!ym.has(n)).flatMap(({keys:e,action:t})=>e.map(e=>[e,t]))),Sm={map:xm(`map`),overview:xm(`overview`)},Cm=e=>e instanceof HTMLElement&&(e.isContentEditable||[`INPUT`,`TEXTAREA`,`SELECT`].includes(e.tagName)),wm=(e,t)=>Cm(e.target)||e.altKey?null:e.metaKey||e.ctrlKey?e.key.toLowerCase()===`k`&&!e.shiftKey?`jump`:null:Sm[t].get(e.key)??null,Tm=(e,t,n)=>{let r=(0,H.useRef)(n);(0,H.useEffect)(()=>{r.current=n}),(0,H.useEffect)(()=>{if(!e)return;let n=e=>{let n=wm(e,t);n!==null&&(e.preventDefault(),r.current(n))};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,t])},Em={Escape:`Esc`,ArrowRight:`→`,ArrowLeft:`←`,ArrowUp:`↑`,ArrowDown:`↓`},Dm=[{title:`Map`,layouts:[`map`]},{title:`Overview`,layouts:[`overview`]},{title:`Both layouts`,layouts:[`map`,`overview`]}],Om=({onClose:e})=>(0,G.jsxs)(af,{title:`Keyboard shortcuts`,onClose:e,className:`shortcuts-dialog`,children:[Dm.map(({title:e,layouts:t})=>(0,G.jsxs)(`section`,{"aria-label":e,children:[(0,G.jsx)(`h3`,{children:e}),(0,G.jsx)(`dl`,{className:`shortcut-list`,children:bm.filter(e=>e.layouts.length===t.length&&t.every(t=>e.layouts.includes(t))).map(({keys:e,description:t})=>(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:e.map(e=>(0,G.jsx)(`kbd`,{children:Em[e]??e},e))}),(0,G.jsx)(`dd`,{children:t})]},t))})]},e)),(0,G.jsx)(`p`,{className:`muted`,children:`Shortcuts don't work while you're typing in a text field.`})]}),km=({pullRequest:e,tickets:t,missingTicketKeys:n})=>{let r=e.description.trim();return(0,G.jsxs)(`div`,{className:`intent-panel stated-intent`,children:[r===``?(0,G.jsx)(`p`,{className:`muted`,children:`The pull request has no description.`}):(0,G.jsx)(`p`,{className:`pr-description`,children:r}),(t.length>0||n.length>0)&&(0,G.jsxs)(`ul`,{className:`chips`,"aria-label":`Tickets`,children:[t.map(e=>(0,G.jsx)(`li`,{className:`chip`,children:(0,G.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,children:[e.key,` · `,e.summary]})},e.key)),n.map(e=>(0,G.jsxs)(`li`,{className:`chip`,title:`Jira didn't return this ticket, or Jira isn't configured`,children:[e,` · not fetched`]},e))]}),e.commits.length>0&&(0,G.jsxs)(`details`,{className:`intent-details`,children:[(0,G.jsxs)(`summary`,{children:[`Commits (`,e.commits.length,`)`]}),(0,G.jsx)(`ol`,{className:`commit-list`,children:e.commits.map(e=>(0,G.jsxs)(`li`,{children:[(0,G.jsx)(`code`,{children:e.sha.slice(0,7)}),` `,e.message.split(`
67
+ `)[0]]},e.sha))})]})]})},Am=`megareviewer:`,jm=e=>{try{let t=window.localStorage.getItem(Am+e);return t===null?void 0:JSON.parse(t)}catch{return}},Mm=(e,t)=>{try{window.localStorage.setItem(Am+e,JSON.stringify(t))}catch{}},Nm=(e,t,n)=>{let[r,i]=(0,H.useState)(()=>({key:e,value:n(jm(e))??t}));return[r.key===e?r.value:n(jm(e))??t,(0,H.useCallback)(r=>i(i=>{let a=r(i.key===e?i.value:n(jm(e))??t);return Mm(e,a),{key:e,value:a}}),[e,t,n])]},Pm=e=>typeof e==`boolean`?e:void 0,Fm=e=>Array.isArray(e)&&e.every(e=>typeof e==`string`)?e:void 0,Im={intent:`Intent`,risk:`Risk`,decisions:`Decisions`,tour:`Tour`},Lm=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${Math.round(e/1e3)}k`:`${e}`,Rm=e=>`$${e.toFixed(2)}`,zm=e=>e.inputTokens+e.cacheWriteTokens,Bm=({usage:e})=>{let t=(0,H.useId)();if(e.length===0)return null;let n=t=>e.reduce((e,n)=>e+t(n),0);return(0,G.jsxs)(`footer`,{className:`usage-footer`,children:[(0,G.jsxs)(`button`,{type:`button`,className:`usage`,"aria-describedby":`${t}-breakdown`,children:[`Usage: `,Lm(n(zm)),` tokens in ·`,` `,Lm(n(e=>e.cacheReadTokens)),` cache read ·`,` `,Lm(n(e=>e.outputTokens)),` out · `,Rm(n(e=>e.costUsd))]}),(0,G.jsxs)(`table`,{id:`${t}-breakdown`,className:`usage-breakdown`,role:`tooltip`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{scope:`col`,children:`Pass`}),(0,G.jsx)(`th`,{scope:`col`,children:`In`}),(0,G.jsx)(`th`,{scope:`col`,children:`Cache read`}),(0,G.jsx)(`th`,{scope:`col`,children:`Out`}),(0,G.jsx)(`th`,{scope:`col`,children:`Cost`})]})}),(0,G.jsx)(`tbody`,{children:e.map(e=>(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{scope:`row`,children:Im[e.pass]}),(0,G.jsx)(`td`,{children:Lm(zm(e))}),(0,G.jsx)(`td`,{children:Lm(e.cacheReadTokens)}),(0,G.jsx)(`td`,{children:Lm(e.outputTokens)}),(0,G.jsx)(`td`,{children:Rm(e.costUsd)})]},e.pass))})]})]})},Vm={verdict:`pending`,comment:``},Hm=(e,t)=>{let{client:n}=cu(),r=(0,H.useRef)(new Map),i=(0,H.useRef)(new Map),a=(0,H.useRef)(new Map),o=(0,H.useRef)(new Map),s=(0,H.useRef)(new Set),[,c]=(0,H.useReducer)(e=>e+1,0),[l,u]=(0,H.useState)(new Map),[d,f]=(0,H.useState)(null),p=(0,H.useRef)(t);(0,H.useEffect)(()=>{p.current=t},[t]);let m=(0,H.useCallback)((e,t)=>{let n=i.current.get(e)??t.find(t=>t.decisionId===e);return n===void 0?Vm:{verdict:n.verdict,comment:n.comment}},[]),h=(0,H.useCallback)(e=>r.current.get(e)??m(e,p.current),[m]),g=e=>r.current.get(e)??m(e,t),_=(0,H.useCallback)((e,t)=>{u(n=>new Map(n).set(e,t))},[]),v=(0,H.useCallback)(async(t,o)=>{let s=h(t),l=(a.current.get(t)??0)+1;a.current.set(t,l),_(t,`saving`);let u=await n.putVerdict(e,t,s);if(a.current.get(t)===l){if(u.ok)i.current.set(t,{verdict:u.value.verdict,comment:u.value.comment}),_(t,`saved`),f(e=>e?.decisionId===t?null:e);else if(_(t,`failed`),f({decisionId:t,what:o,message:_u(u.error)}),o===`verdict`){let e=r.current.get(t)??s;r.current.set(t,{...e,verdict:m(t,p.current).verdict}),c()}}},[e,n,h,m,_]),y=(0,H.useCallback)((e,t)=>{let n=v(e,t);return s.current.add(n),n.finally(()=>s.current.delete(n)),n},[v]),b=(0,H.useCallback)(async()=>{for(let[e,t]of o.current)clearTimeout(t),y(e,`comment`);o.current.clear(),await Promise.all(s.current)},[y]),x=(0,H.useCallback)((e,t)=>{r.current.set(e,{...h(e),verdict:t}),clearTimeout(o.current.get(e)),o.current.delete(e),c(),y(e,`verdict`)},[h,y]),S=(0,H.useCallback)((e,t)=>{r.current.set(e,{...h(e),comment:t}),clearTimeout(o.current.get(e)),o.current.set(e,setTimeout(()=>{o.current.delete(e),y(e,`comment`)},500)),_(e,`waiting`),c()},[h,y,_]);return(0,H.useEffect)(()=>{let e=o.current;return()=>{for(let[t,n]of e)clearTimeout(n),y(t,`comment`);e.clear()}},[y]),{draftOf:g,setVerdict:x,setComment:S,statusOf:e=>l.get(e)??null,flush:b,failure:d,dismissFailure:()=>f(null)}},Um=[],Wm=[],Gm=e=>wl.array().safeParse(e).data,Km=({analysisId:e})=>{let[t,n]=(0,H.useState)(0),r=(0,H.useCallback)(()=>n(e=>e+1),[]);return(0,G.jsx)(qm,{analysisId:e,restart:r},`${e}/${t}`)},qm=({analysisId:e,restart:t})=>{let{view:n,error:r,refetch:i}=pu(e);return n===null?r?.code===`not-found`?(0,G.jsxs)(`div`,{className:`narrow`,children:[(0,G.jsx)(`h1`,{children:`Analysis not found`}),(0,G.jsx)(`p`,{children:_u(r)}),(0,G.jsx)(`p`,{children:(0,G.jsx)(zu,{to:`/`,children:`Pick a pull request to review`})})]}):r===null?(0,G.jsx)(Jm,{}):(0,G.jsxs)(`div`,{className:`narrow`,children:[(0,G.jsxs)(`p`,{className:`banner danger`,role:`alert`,children:[`Couldn't load the analysis. `,_u(r)]}),(0,G.jsx)(`button`,{type:`button`,className:`button`,onClick:()=>void i(),children:`Try again`})]}):(0,G.jsx)(rh,{view:n,refetch:i,restart:t})},Jm=()=>(0,G.jsxs)(`div`,{className:`review-page`,role:`status`,"aria-busy":`true`,"aria-label":`Loading the analysis`,children:[(0,G.jsx)(`div`,{className:`skeleton skeleton-title`}),(0,G.jsxs)(`div`,{className:`review-body map`,children:[(0,G.jsx)(`div`,{className:`skeleton skeleton-main`}),(0,G.jsx)(`div`,{className:`skeleton skeleton-rail`})]})]}),Ym=[],Xm=({analysis:e})=>{let{checkout:t,pullRequest:n}=e;if(t===`read`||n===null)return null;let{ref:r,headSha:i}=n;return(0,G.jsxs)(`p`,{className:`checkout-note muted`,children:[`Code outside the pull request that calls what it changes isn't shown:`,` `,t===`missing-commit`?(0,G.jsxs)(G.Fragment,{children:[`the local checkout doesn't have the head commit `,(0,G.jsx)(`code`,{children:i.slice(0,7)}),`. Run`,` `,(0,G.jsx)(`code`,{children:`git fetch`}),` in it`,r.repo.host===`github`&&(0,G.jsxs)(G.Fragment,{children:[`, or `,(0,G.jsxs)(`code`,{children:[`git fetch origin pull/`,r.number,`/head`]}),` for a pull request from a fork`]}),`, then open the pull request again.`]}):(0,G.jsxs)(G.Fragment,{children:[`megareviewer didn't run in a checkout of `,r.repo.owner,`/`,r.repo.repo,`. Start it in one, or pass `,(0,G.jsx)(`code`,{children:`--checkout <dir>`}),`, then open the pull request again.`]})]})},Zm=[],Qm=[],$m=e=>[...e??[]].map(([e,t])=>`${e}${t.map(e=>e.kind[0]+e.symbol).join()}`).join(`;`),eh=new WeakMap,th=0,nh=e=>{let t=eh.get(e);return t===void 0?(th+=1,eh.set(e,th),th):t},rh=({view:e,refetch:t,restart:n})=>{let{client:r}=cu(),i=du().status?.model.enabled!==!1,{analysis:a,publication:o,isAuthor:s}=e,c=a.id,l=a.status===`complete`,u=o!==null||!l,d=(0,H.useMemo)(()=>Of(a),[a]),f=(0,H.useMemo)(()=>Af(a,d),[a,d]),p=(0,H.useMemo)(()=>jf(a,f,d),[a,f,d]),m=(0,H.useMemo)(()=>p.flatMap(e=>e.partIds),[p]),h=(0,H.useMemo)(()=>Q(a,d),[a,d]),g=zf(h),_=(0,H.useMemo)(()=>Vf(a,d),[a,d]),v=(0,H.useMemo)(()=>new Set(a.risk.flatMap(e=>e.riskClass===`contract`?[e.hunkId]:[])),[a.risk]),y=(0,H.useCallback)(e=>v.has(Sc(e)),[v]),b=(0,H.useMemo)(()=>If(a.decisions,m,d),[a.decisions,m,d]),x=(0,H.useMemo)(()=>{let e=new Map;for(let t of a.decisions)for(let n of new Set(t.hunkIds.flatMap(d.partsOf)))e.set(n,[...e.get(n)??[],t]);return e},[a.decisions,d]),S=(0,H.useMemo)(()=>a.callGraph.filter(e=>e.use!==`type`),[a.callGraph]),ee=(0,H.useMemo)(()=>Lf(S,d),[S,d]),[te,C]=(0,H.useState)([]),w=(0,H.useMemo)(()=>am(a,f,new Set(te)),[a,f,te]),[T,ne]=Nm(`review-layout`,`map`,Tf),[re,ie]=Nm(`contract-only:${c}`,!1,Pm),ae=(0,H.useMemo)(()=>Zd(p.map(e=>e.partIds.filter(e=>!re||y(e))),ee,(e,t)=>d.parts.get(e)?.hunk.lines.find(e=>e.kind!==`del`&&e.newLine===t)?.text),[p,ee,d,re,y]),oe=(0,H.useMemo)(()=>Hf(S,d,m),[S,d,m]),se=(0,H.useCallback)(e=>oe.get(e)??Zm,[oe]),ce=(0,H.useMemo)(()=>{let e=new Map;for(let t of a.unchangedCallers)e.set(t.partId,[...e.get(t.partId)??[],t]);return e},[a.unchangedCallers]),le=(0,H.useCallback)(e=>ce.get(e)??Qm,[ce]),ue=(0,H.useMemo)(()=>{let e=new Map;for(let t of p)if(t.kind===`step`)for(let n of t.partIds)e.has(n)||e.set(n,`step ${t.number}: ${t.step.title}`);return t=>e.get(t)??null},[p]),[E,de]=(0,H.useState)(!1),[fe,pe]=(0,H.useState)(null),[me,he]=(0,H.useState)(null),ge=(0,H.useRef)(null),[_e,ve]=(0,H.useState)(null),[ye,be]=(0,H.useState)([]),[xe,Se]=(0,H.useState)(null),[Ce,D]=(0,H.useState)(new Set),[O,we]=(0,H.useState)(0),[Te,Ee]=(0,H.useState)(new Set),[De,k]=(0,H.useState)(null),[A,Oe]=(0,H.useState)(null),ke=(0,H.useRef)([]),[Ae,je]=(0,H.useState)(!1),[Me,Ne]=(0,H.useState)(!1),[Pe,Fe]=(0,H.useState)(!1),[Ie,Le]=(0,H.useState)(!1),Re=(0,H.useRef)(null),ze=(0,H.useCallback)(e=>{Re.current=e},[]),[Be,j]=Nm(`reviewed-hunks`,Um,Fm),Ve=(0,H.useMemo)(()=>Wf(Be,d),[Be,d]),He=(0,H.useMemo)(()=>Uf(p,d),[p,d]),Ue=Kf(He,Ve),We=(0,H.useCallback)((e,t)=>j(n=>Gf(n,e,t,d).slice(-5e3)),[j,d]),Ge=(0,H.useMemo)(()=>qf(p,d),[p,d]),Ke=(0,H.useCallback)(e=>Ge.get(e)??null,[Ge]),[qe,M]=Nm(`hunk-comments:${c}`,Wm,Gm),[Je,Ye]=(0,H.useState)(null),Xe=(0,H.useMemo)(()=>Jf(qe,d),[qe,d]),Ze=(0,H.useCallback)(e=>Xe.get(e)??Wm,[Xe]),Qe=(0,H.useCallback)((e,t)=>M(n=>{let r=Sc(e),i=e=>e.hunkId===r&&e.side===t.side&&e.line===t.line,a={hunkId:r,...t};return n.some(i)?t.body===``?n.filter(e=>!i(e)):n.map(e=>i(e)?a:e):t.body===``?n:[...n,a]}),[M]),$e=(0,H.useCallback)((e,t)=>Ye(t===null?null:{partId:e,place:t}),[]),et=Hm(c,e.verdicts),tt=e=>k(t=>({id:e,n:(t?.n??0)+1})),nt=e=>!re||y(e),rt=()=>{if(T===`overview`)return null;let e=ke.current;return fe!==null&&(e.length===0||e.includes(fe))?fe:e[0]??fe},it=(0,H.useCallback)(e=>{pe(e);let t=b.cards.get(e)??Ym;Se(e=>t.some(t=>t.id===e)?e:t[0]?.id??null)},[b]),at=e=>{let t=w.placeOf.get(e);t!==void 0&&(t.startsWith(`group:`)&&C(e=>[...e,t]),he(t=>({key:e,n:(t?.n??0)+1})))},ot=(e,t=T)=>{if(t===`overview`){let t=d.parts.get(e)?.file.path;t!==void 0&&at(t)}else nt(e)||ie(()=>!1),tt(m.includes(e)?of(e):tp)},st=e=>{let t=a.decisions.find(t=>t.id===e),n=b.cardHunk.get(e);D(new Set((t?.hunkIds??[]).flatMap(d.partsOf))),T===`overview`?n!==void 0&&ot(n):(n!==void 0&&!nt(n)&&ie(()=>!1),tt(ef(e))),Se(e)},ct=e=>{let t=a.intent?.mismatches[e];if(t===void 0)return;let n=t.hunkIds.flatMap(d.partsOf).sort((e,t)=>m.indexOf(e)-m.indexOf(t));D(new Set(n)),we(e+1);let[r]=n;r!==void 0&&ot(r)},lt=e=>{let t=p.find(t=>Ff(t)===e);if(t!==void 0){if(T===`overview`){let e=t.partIds.find(e=>!d.mechanical.has(e));e!==void 0&&ot(e)}else re&&!t.partIds.some(y)&&ie(()=>!1),pe(null),Oe(t.partIds.find(nt)??null),tt($(e))}},ut=()=>{re&&ie(()=>!1),tt(tp)},dt=e=>{let t=rt();t!==null&&be(e=>[...e,t]),ot(e)},ft=()=>{let e=rt();ne(()=>`overview`),ve(null),e!==null&&ot(e,`overview`)},pt=e=>{if(e.kind===`group`){C(t=>[...t,e.key]);return}let[t]=e.partIds;t!==void 0&&(ne(()=>`map`),ve(e.key),pe(t),ot(t,`map`))},mt=()=>{if(T===`map`)return ft();let e=[...w.rows.flat(),...w.strip].find(e=>e.key===ge.current);if(e!==void 0&&e.kind===`file`)return pt(e);ne(()=>`map`)},ht=m.filter(nt),gt=e=>{if(ht.length===0)return;let t=fe===null?-1:ht.indexOf(fe),n=A??ke.current.find(nt)??null,r=n===null?-1:ht.indexOf(n),i=t===-1?r===-1?e===1?0:ht.length-1:e===1?r:r-1:t+e;Oe(null);let a=ht[Math.min(Math.max(i,0),ht.length-1)];a!==void 0&&tt(of(a))},_t=e=>{let t=p.filter(e=>e.partIds.some(nt)),n=rt()??A,r=t[t.findIndex(e=>n!==null&&e.partIds.includes(n))+e];r!==void 0&&lt(Ff(r))},vt=e=>{let t=He.filter(nt),n=rt(),r=n===null?e===1?-1:t.length:t.indexOf(n);for(let n=r+e;n>=0&&n<t.length;n+=e){let e=t[n];if(e!==void 0&&!Ve.has(e))return ot(e)}},yt=(e,t)=>{if(u)return;let n=et.draftOf(e).verdict;et.setVerdict(e,n===t?`pending`:t)},bt=(0,H.useCallback)(e=>Ee(t=>{let n=new Set(t);return n.delete(e)||n.add(e),n}),[]);Tm(!Ae&&!Me&&!Pe&&!Ie,T,e=>{let t=rt();switch(e){case`next-hunk`:return gt(1);case`previous-hunk`:return gt(-1);case`next-step`:return _t(1);case`previous-step`:return _t(-1);case`open-call`:{let e=[...t===null?[]:ae.get(t)??[]].sort(([e],[t])=>e-t).flatMap(([,e])=>e),n=e.find(e=>e.kind===`chip`)?.calls[0];if(t!==null&&n!==void 0)return bt(np([t],n));let r=e[0]?.calls[0];r!==void 0&&dt(r.toPartId);return}case`approve`:xe!==null&&yt(xe,`approved`);return;case`reject`:xe!==null&&yt(xe,`rejected`);return;case`toggle-reviewed`:t!==null&&!d.mechanical.has(t)&&(We(t,!Ve.has(t)),gt(1));return;case`next-unreviewed`:return vt(1);case`previous-unreviewed`:return vt(-1);case`jump`:Fe(!0);return;case`toggle-layout`:return mt();case`comment`:{if(xe!==null&&Re.current!==null){Re.current.focus();return}let e=t===null?void 0:d.parts.get(t),n=e?.hunk.lines.find(e=>e.kind!==`context`);if(u||e===void 0||n===void 0)return;let r=Id(n);r!==null&&t!==null&&Ye({partId:t,place:r});return}case`escape`:{if(Ce.size>0)return D(new Set);let e=ye.at(-1);if(T!==`map`)return;e===void 0?_e!==null&&(ne(()=>`overview`),he(e=>({key:_e,n:(e?.n??0)+1})),ve(null)):(be(e=>e.slice(0,-1)),ot(e));return}case`help`:Ne(!0);return}});let xt=a.pullRequest?.url??Nl(a.key.ref),St=mu(r.startAnalysis),Ct=mu(r.retryAnalysis),wt=e=>{e===c?n():wu(xu(e))},Tt=async()=>{await et.flush(),je(!0)},Et=a.decisions.filter(e=>et.draftOf(e.id).verdict===`pending`).length,Dt=et.failure===null?``:a.decisions.find(e=>e.id===et.failure?.decisionId)?.title??``,Ot=e=>(0,G.jsx)(tf,{decision:e,draft:et.draftOf(e.id),status:et.statusOf(e.id),selected:xe===e.id,readOnly:u,commentRef:ze,onSelect:Se,onVerdict:et.setVerdict,onComment:et.setComment},e.id),kt=e=>{let t=b.cards.get(e)??Ym,n=b.mentions.get(e)??Ym;return t.length===0&&n.length===0?null:(0,G.jsxs)(`div`,{className:`hunk-decisions`,children:[t.map(Ot),n.map(e=>(0,G.jsx)(nf,{decision:e,onGo:jt.goToDecision},e.id))]})},At=(0,H.useRef)({follow:dt,goToDecision:st});At.current={follow:dt,goToDecision:st};let jt=(0,H.useMemo)(()=>({follow:e=>At.current.follow(e),goToDecision:e=>At.current.goToDecision(e)}),[]),Mt=e=>{let t=[nh(a),u,Ve.has(e),Ce.has(e),$m(ae.get(e)),Je?.partId===e?`${Je.place.side}${Je.place.line}`:``,...Ze(e).map(e=>`${e.side}${e.line}${e.body}`)];for(let n of b.cards.get(e)??Ym){let e=et.draftOf(n.id);t.push(n.id,e.verdict,e.comment,et.statusOf(n.id)),t.push(xe===n.id)}let n=[...Te].filter(t=>t.startsWith(`${e}@`)||t.startsWith(`${e}>`));return n.length>0&&t.push(...n,...Be,...Ce),t.join(`\0`)},Nt={index:d,calls:ee,plan:ae,callersOf:se,unchangedOf:le,stepOf:ue,onFollow:jt.follow,reviewed:Ve,onReviewed:We,partHeaderOf:Ke,highlighted:Ce,commentsOf:Ze,openComment:Je,onOpenComment:$e,onComment:u?void 0:Qe,onFocusHunk:it,decisionsOn:kt},Pt=(0,G.jsxs)(G.Fragment,{children:[i&&a.status===`running`&&a.stages.decisions!==`done`&&(0,G.jsx)(`p`,{className:`muted`,children:`Finding the decisions the code makes…`}),a.stages.decisions===`done`&&!l&&o===null&&a.decisions.length>0&&(0,G.jsx)(`p`,{className:`muted`,children:`You can give verdicts once the analysis is complete.`}),b.unplaced.length>0&&(0,G.jsx)(`section`,{className:`unplaced-decisions`,"aria-label":`Decisions on no change shown here`,children:b.unplaced.map(Ot)})]}),Ft=(0,H.useMemo)(()=>Sf(a,f,d),[a,f,d]),It=e=>{switch(Fe(!1),e.kind){case`decision`:return st(e.decisionId);case`mismatch`:return ct(e.index);case`hunk`:return D(new Set),ot(e.partId);case`step`:return lt(e.stepId);case`mechanical`:T!==`map`&&ne(()=>`map`),ut();return}},Lt=e=>{if(e.kind===`hunk`)return ot(e.partId);if(e.kind===`section`)return lt(e.key);ut()},Rt=(0,H.useCallback)(e=>{ke.current=e},[]);return(0,G.jsxs)(`div`,{className:`review-page layout-${T}`,children:[(0,G.jsx)(hm,{view:e,intent:(0,G.jsx)(ff,{analysis:a,modelOn:i,mismatchAt:O,onMismatch:ct,onDetails:()=>Le(!0)}),tools:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`fieldset`,{className:`layout-toggle`,children:[(0,G.jsx)(`legend`,{className:`visually-hidden`,children:`Layout`}),(0,G.jsx)(`button`,{type:`button`,className:`button`,"aria-pressed":T===`map`,onClick:()=>T!==`map`&&mt(),children:`Map`}),(0,G.jsx)(`button`,{type:`button`,className:`button`,"aria-pressed":T===`overview`,onClick:()=>T!==`overview`&&mt(),children:`Overview`})]}),(0,G.jsxs)(`button`,{type:`button`,className:`button jump-button`,onClick:()=>Fe(!0),children:[`Jump to… `,(0,G.jsx)(`kbd`,{children:`⌘K`})]}),(0,G.jsxs)(`p`,{className:`review-progress`,"aria-live":`polite`,children:[Ue.done,` of `,Ue.total,` `,Ue.total===1?`hunk`:`hunks`,` reviewed`]})]}),reanalyzing:St.pending,reanalyzeError:St.error,onReanalyze:async()=>{let e=await St.run({url:xt});e.ok&&wt(e.value.analysisId)},onPublish:()=>void Tt()}),!l&&(0,G.jsx)(lm,{stages:a.stages,filesFetched:a.filesFetched}),a.error!==null&&(0,G.jsxs)(`div`,{className:`banner danger failed-banner`,role:`alert`,children:[(0,G.jsxs)(`p`,{children:[`The analysis failed at the `,um(a.error.stage).toLowerCase(),` stage:`,` `,a.error.message]}),Ct.error!==null&&(0,G.jsxs)(`p`,{children:[`Couldn't retry. `,_u(Ct.error)]}),(0,G.jsx)(`button`,{type:`button`,className:`button`,disabled:Ct.pending,onClick:async()=>{let e=await Ct.run(c);e.ok&&wt(e.value.analysisId)},children:Ct.pending?`Retrying…`:`Retry`})]}),et.failure!==null&&(0,G.jsxs)(`div`,{className:`banner danger verdict-failure`,role:`alert`,children:[(0,G.jsxs)(`p`,{children:[`Couldn't save your `,et.failure.what,` on “`,Dt,`”.`,` `,et.failure.message]}),(0,G.jsx)(`button`,{type:`button`,className:`button quiet`,onClick:et.dismissFailure,children:`Dismiss`})]}),a.stages.prep===`done`?T===`map`?(0,G.jsxs)(`div`,{className:`review-body map${E?` rail-open`:``}`,children:[(0,G.jsx)(`button`,{type:`button`,className:`button rail-toggle`,"aria-expanded":E,"aria-controls":`review-map-rail`,onClick:()=>de(!E),children:E?`Hide Map`:`Show Map`}),(0,G.jsx)(gp,{analysis:a,sections:p,deps:Nt,contractOnly:re,isContract:y,openCalls:Te,onToggleCall:bt,before:Pt,trailingProofs:h,mechanicalCount:g,scrollRequest:De,signatureOf:Mt}),(0,G.jsx)(_m,{activePartId:fe,sections:p,index:d,decisionsOn:e=>x.get(e)??Ym,totals:_,reviewed:Ve,contractOnly:re,onContractOnly:e=>ie(()=>e),mechanicalCount:g,onGo:Lt,onInView:Rt})]}):(0,G.jsx)(`div`,{className:`review-body overview-body`,children:(0,G.jsx)(Hp,{overview:w,reviewed:Ve,focusKey:me,onOpen:pt,expandedGroups:te,onCollapse:e=>C(t=>t.filter(t=>t!==e)),onFocusNode:e=>{ge.current=e}})}):(0,G.jsx)(`section`,{className:`main-area`,"aria-busy":a.status===`running`,children:(0,G.jsx)(`p`,{className:`muted`,children:a.status===`running`?`Reading the diff…`:`The diff couldn't be read, so there are no changes to show.`})}),(0,G.jsx)(Bm,{usage:a.usage}),Ae&&(0,G.jsx)(pm,{analysisId:c,isAuthor:s,pendingCount:Et,hunkComments:qe,chooseVerdict:a.decisions.length===0,onClose:()=>je(!1),onPublished:()=>{je(!1),t()}}),Me&&(0,G.jsx)(Om,{onClose:()=>Ne(!1)}),Pe&&(0,G.jsx)(wf,{items:Ft,onPick:It,onClose:()=>Fe(!1)}),Ie&&(0,G.jsxs)(af,{title:a.intent===null?`What was asked`:`Intent`,onClose:()=>Le(!1),className:`intent-dialog`,children:[a.intent===null?a.pullRequest!==null&&(0,G.jsx)(km,{pullRequest:a.pullRequest,tickets:a.tickets,missingTicketKeys:a.missingTicketKeys}):(0,G.jsx)(_f,{intent:a.intent,tickets:a.tickets,missingTicketKeys:a.missingTicketKeys,onSelectMismatch:e=>{Le(!1),ct(e)}}),(0,G.jsx)(Xm,{analysis:a})]}),(0,G.jsxs)(`p`,{className:`shortcut-hint muted`,children:[`Press `,(0,G.jsx)(`kbd`,{children:`?`}),` for keyboard shortcuts.`]})]})},ih=(e,t)=>{if(t!==null)return{tone:`danger`,label:`Disconnected`,detail:_u(t)};if(e===null)return{tone:`muted`,label:`Connecting…`,detail:``};let n=`megareviewer ${e.version}`,{github:r,bitbucket:i}=e.hosts;if(!r.configured&&!i.configured)return{tone:`warning`,label:`Setup needed`,detail:n};let a=[{name:`GitHub`,error:r.error},{name:`Bitbucket`,error:i.error}].flatMap(({name:e,error:t})=>t===null?[]:[{name:e,error:t}]);if(a.length>0){let e=a.map(({name:e})=>e).join(` and `);return{tone:`warning`,label:a.length===1?`${e} problem`:`${e} problems`,detail:[...a.map(({name:e,error:t})=>`${e}: ${t}`),n].join(`
68
+ `)}}return{tone:`ok`,label:`Ready`,detail:n}},ah=({status:e,error:t})=>{let n=ih(e,t);return(0,G.jsxs)(`header`,{className:`app-header`,children:[(0,G.jsx)(zu,{to:`/`,className:`brand`,children:`megareviewer`}),(0,G.jsxs)(`span`,{className:`status-indicator`,role:`status`,title:n.detail,children:[(0,G.jsx)(`span`,{className:`status-dot tone-${n.tone}`,"aria-hidden":`true`}),n.label]})]})},oh=()=>(0,G.jsxs)(`div`,{className:`narrow`,children:[(0,G.jsx)(`h1`,{children:`Page not found`}),(0,G.jsxs)(`p`,{children:[`There's nothing at this address. `,(0,G.jsx)(zu,{to:`/`,children:`Go to your pull requests`}),`.`]})]}),sh=(e,t)=>Object.entries(e).find(([e])=>/([^/]+)\/playground\.tsx$/.exec(e)?.[1]===t)?.[1]??null,ch=({modules:e,name:t})=>{let n=sh(e,t),[r,i]=(0,H.useState)();return(0,H.useEffect)(()=>{let e=!0;return n?.().then(n=>{e&&i({name:t,Component:n.default})}),()=>{e=!1}},[n,t]),n===null?(0,G.jsxs)(`p`,{children:[`No playground named “`,t,`”.`]}):r?.name===t?(0,G.jsx)(r.Component,{}):(0,G.jsx)(`p`,{className:`muted`,children:`Loading playground…`})},lh=({reason:e})=>(0,G.jsxs)(`main`,{className:`page narrow`,children:[(0,G.jsx)(`h1`,{children:`Open megareviewer from your terminal`}),e===`missing`?(0,G.jsxs)(`p`,{children:[`This page needs the link megareviewer printed when it started. It looks like`,` `,(0,G.jsx)(`code`,{children:`http://127.0.0.1:4823/?token=…`}),`. Copy it from your terminal and open it.`]}):(0,G.jsx)(`p`,{children:`This page's session has ended, usually because megareviewer was restarted. Open the new link printed in your terminal.`}),(0,G.jsxs)(`p`,{className:`muted`,children:[`Not running? Start it with `,(0,G.jsx)(`code`,{children:`npx megareviewer`}),`.`]})]}),uh=({token:e,fetch:t,openEventStream:n,playgrounds:r})=>{let[i,a]=(0,H.useState)(!1),o=e.value,s=(0,H.useMemo)(()=>o===null?null:{client:au({fetch:t,token:o,onUnauthorized:()=>{e.clear(),a(!0)}}),subscribe:(e,t)=>ou(e,o,t,n)},[t,n,e,o]);return i?(0,G.jsx)(lh,{reason:`ended`}):s===null?(0,G.jsx)(lh,{reason:`missing`}):(0,G.jsx)(su.Provider,{value:s,children:(0,G.jsx)(dh,{playgrounds:r})})},dh=({playgrounds:e})=>{let t=bu(Cu(),{dev:e!==null}),n=du();return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(ah,{status:n.status,error:n.error}),(0,G.jsx)(`main`,{className:`page`,children:t.page===`picker`?(0,G.jsx)(Ru,{status:n.status}):t.page===`review`?(0,G.jsx)(Km,{analysisId:t.analysisId}):t.page===`playground`&&e!==null?(0,G.jsx)(ch,{modules:e,name:t.name}):(0,G.jsx)(oh,{})})]})},fh=class extends H.Component{state={error:null};static getDerivedStateFromError(e){return{error:e instanceof Error?e:Error(String(e))}}render(){let{error:e}=this.state;if(e===null)return this.props.children;let t=this.props.onReload??(()=>window.location.reload());return(0,G.jsxs)(`main`,{className:`page narrow`,role:`alert`,children:[(0,G.jsx)(`h1`,{children:`Something went wrong`}),(0,G.jsx)(`p`,{children:`megareviewer hit a bug while showing this page.`}),(0,G.jsx)(`pre`,{className:`error-detail`,children:String(e)}),(0,G.jsx)(`button`,{type:`button`,className:`button primary`,onClick:t,children:`Reload`})]})}},ph=`token`,mh=`megareviewer.token`,hh=e=>{let t=(()=>{try{return e.sessionStorage}catch{return null}})(),n=e=>{try{return t===null?null:e(t)}catch{return null}},r=new URL(e.location.href),i=r.searchParams.get(ph),a;return i!==null&&i!==``?(a=i,n(e=>e.setItem(mh,i))):a=n(e=>e.getItem(mh)),r.searchParams.has(ph)&&(r.searchParams.delete(ph),e.history.replaceState(e.history.state,``,`${r.pathname}${r.search}${r.hash}`)),{get value(){return a},clear(){a=null,n(e=>e.removeItem(mh))}}},gh=null,_h=document.getElementById(`root`);if(_h===null)throw Error(`index.html has no #root`);(0,sc.createRoot)(_h).render((0,G.jsx)(H.StrictMode,{children:(0,G.jsx)(fh,{children:(0,G.jsx)(uh,{token:hh(window),fetch:window.fetch.bind(window),playgrounds:gh})})}));export{n as t};