@alecsibilia/luca 14.0.0-alpha.36 → 14.0.0-alpha.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/board/package.json +1 -1
- package/board/server/luca-version.ts +1 -1
- package/engine/index.ts +1 -0
- package/engine/story/story-github.ts +26 -2
- package/package.json +1 -1
- package/skills/luca-pr-address/scripts/pr-findings.ts +17 -1
- package/skills/luca-pr-prep/scripts/pr-story.js +8 -8
package/CHANGELOG.md
CHANGED
package/board/package.json
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** The Luca version of this board, stamped when the package was packed. */
|
|
2
|
-
export const LUCA_VERSION: string = "14.0.0-alpha.
|
|
2
|
+
export const LUCA_VERSION: string = "14.0.0-alpha.37"
|
package/engine/index.ts
CHANGED
|
@@ -235,6 +235,31 @@ export const removeReadyLabel = async ({
|
|
|
235
235
|
})
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
+
/**
|
|
239
|
+
* Whether `repo` is the signed-in user's own: its owner is `login`, in
|
|
240
|
+
* any case. An organization's repo is not, and no repo is when the login
|
|
241
|
+
* is unknown (null or empty). `defaultStoryHome` and Luca Walk both use
|
|
242
|
+
* this one rule.
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* isOwnRepo({ repo: 'octocat/hello-world', login: 'Octocat' }) // true
|
|
246
|
+
* isOwnRepo({ repo: 'acme/site', login: 'octocat' }) // false
|
|
247
|
+
*/
|
|
248
|
+
export const isOwnRepo = ({
|
|
249
|
+
repo,
|
|
250
|
+
login,
|
|
251
|
+
}: {
|
|
252
|
+
repo: string
|
|
253
|
+
login: string | null
|
|
254
|
+
}): boolean => {
|
|
255
|
+
const owner = repo.split('/')[0] ?? ''
|
|
256
|
+
return (
|
|
257
|
+
login !== null &&
|
|
258
|
+
login !== '' &&
|
|
259
|
+
owner.toLowerCase() === login.toLowerCase()
|
|
260
|
+
)
|
|
261
|
+
}
|
|
262
|
+
|
|
238
263
|
/**
|
|
239
264
|
* Which home a story for this repo goes to when no flag says: `shared`
|
|
240
265
|
* when the repo belongs to the signed-in GitHub user's own account,
|
|
@@ -248,13 +273,12 @@ export const defaultStoryHome = async ({
|
|
|
248
273
|
gh: Gh
|
|
249
274
|
repo: string
|
|
250
275
|
}): Promise<{ home: 'shared' | 'private'; why: string }> => {
|
|
251
|
-
const owner = repo.split('/')[0] ?? ''
|
|
252
276
|
const user = await gh({ args: ['api', 'user', '--jq', '.login'] })
|
|
253
277
|
const login = user.stdout.trim()
|
|
254
278
|
if (!user.ok || login === '') {
|
|
255
279
|
return { home: 'private', why: 'gh could not say who is signed in' }
|
|
256
280
|
}
|
|
257
|
-
return
|
|
281
|
+
return isOwnRepo({ repo, login })
|
|
258
282
|
? { home: 'shared', why: `${repo} belongs to ${login}` }
|
|
259
283
|
: { home: 'private', why: `${repo} does not belong to ${login}` }
|
|
260
284
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alecsibilia/luca",
|
|
3
3
|
"description": "Luca: turns a spec on GitHub Issues into a reviewed pull request, run from Paseo with Claude Code",
|
|
4
|
-
"version": "14.0.0-alpha.
|
|
4
|
+
"version": "14.0.0-alpha.37",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Alec Sibilia <sibilia.alec@gmail.com>",
|
|
7
7
|
"homepage": "https://github.com/asibilia/luca-framework#readme",
|
|
@@ -25,6 +25,22 @@ export const SUMMARY_MARKER = '<!-- luca-pr-address summary'
|
|
|
25
25
|
*/
|
|
26
26
|
export const REPLY_MARKER = '<!-- luca-pr-address reply -->'
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* The text Luca Walk's review record line starts with: the hidden line at
|
|
30
|
+
* the end of every review Luca Walk sends. It is not a finding. A copy of
|
|
31
|
+
* `REVIEW_RECORD_MARKER` in `packages/walk/src/review-record.ts`, kept as
|
|
32
|
+
* a literal because skill scripts import nothing; a test there fails when
|
|
33
|
+
* the two differ.
|
|
34
|
+
*/
|
|
35
|
+
export const REVIEW_RECORD_MARKER = '<!-- luca-walk review '
|
|
36
|
+
|
|
37
|
+
/** A review's text without Luca Walk's review record line. */
|
|
38
|
+
const withoutReviewRecord = (body: string): string =>
|
|
39
|
+
body
|
|
40
|
+
.split('\n')
|
|
41
|
+
.filter((line) => !line.trimStart().startsWith(REVIEW_RECORD_MARKER))
|
|
42
|
+
.join('\n')
|
|
43
|
+
|
|
28
44
|
/** The label a reviewer's "changes wanted" verdict is carried by. */
|
|
29
45
|
export const CHANGES_WANTED_LABEL = 'changes-wanted'
|
|
30
46
|
|
|
@@ -234,7 +250,7 @@ export const reviewBodyFindings = ({
|
|
|
234
250
|
}): Finding[] =>
|
|
235
251
|
reviews.flatMap((review) => {
|
|
236
252
|
const review_id = numberOrNull(review.id)
|
|
237
|
-
const body = text(review.body).trim()
|
|
253
|
+
const body = withoutReviewRecord(text(review.body)).trim()
|
|
238
254
|
const state = text(review.state)
|
|
239
255
|
if (review_id === null || body === '' || state === 'PENDING') return []
|
|
240
256
|
const author = loginOf(review.user)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
// source-sha256:
|
|
2
|
+
// source-sha256: ad63e2fcf268ec80cb9d66f6f03399d5672371ed3186afc7e2e412ed90d70f54
|
|
3
3
|
// Generated by packages/engine/scripts/build-pr-story.ts from packages/engine/src/story/. Do not edit.
|
|
4
4
|
// @bun
|
|
5
|
-
var Oc=Object.defineProperty;var Ic=(e)=>e;function Ec(e,t){this[e]=Ic.bind(null,t)}var Ac=(e,t)=>{for(var r in t)Oc(e,r,{get:t[r],enumerable:!0,configurable:!0,set:Ec.bind(t,r)})};var vr={};Ac(vr,{ZodISODate:()=>Ae,ZodISODateTime:()=>Ee,ZodISODuration:()=>Ne,ZodISOTime:()=>Te,date:()=>Ta,datetime:()=>Aa,duration:()=>Ca,time:()=>Na});import{homedir as zl}from"os";import{readFile as yl,writeFile as bl}from"fs/promises";function be(e){let t=Object.values(e).filter((n)=>typeof n==="number");return Object.entries(e).filter(([n,o])=>t.indexOf(+n)===-1).map(([n,o])=>o)}function Zt(e,t="|"){return e.map((r)=>Et(r)).join(t)}function xe(e,t){if(typeof t==="bigint")return t.toString();return t}class Or{constructor(e){this._getter=e,this._value=void 0}get value(){let e=this._getter;if(e!==void 0)this._value=e(),this._getter=void 0;return this._value}}function De(e){return new Or(e)}function Ir(e){return e===null||e===void 0}function je(e){let t=e.startsWith("^")?1:0,r=e.endsWith("$")?e.length-1:e.length;return e.slice(t,r)}function Er(e,t){let r=e/t,n=Math.round(r),o=4*Number.EPSILON*Math.max(Math.abs(r),1);if(Math.abs(r-n)<o)return 0;return r-n}function J(e,t,r){Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!0,configurable:!0})}function Le(e){let t=Object.getOwnPropertyDescriptor(e,"shape");return t?.get?t.get.raw:t?.value}function H(e){return Le(e._zod.def)??e._zod.def.shape}function Ar(e,t,r){Object.defineProperty(e,t,{get(){let n=r();return J(this,t,n),n},enumerable:!0,configurable:!0})}function Tr(e,t,r){if(t in e)J(e,t,r);else e[t]=r}function ne(e,t,r,n){let o=H(t);for(let s of r){let i=Object.getOwnPropertyDescriptor(o,s);if(!i.enumerable)continue;if(i.get)Ar(e,s,()=>{let c=t._zod.def.shape[s];return n?n(c,s):c});else Tr(e,s,n?n(i.value,s):i.value)}}function Tc(e,t){for(let r of Reflect.ownKeys(t)){let n=Object.getOwnPropertyDescriptor(t,r);if(!n.enumerable)continue;if(n.get)Ar(e,r,()=>t[r]);else Tr(e,r,n.value)}}function C(...e){let t={};for(let r of e){let n=Object.getOwnPropertyDescriptors(r);Object.assign(t,n)}return Object.defineProperties({},t)}function Nr(e){return JSON.stringify(e)}function Cr(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}var Ot="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function ye(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var Rr=De(()=>{if(R.jitless)return!1;if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(e){return!1}});function ue(e){if(ye(e)===!1)return!1;let t=e.constructor;if(t===void 0)return!0;if(typeof t!=="function")return!0;let r=t.prototype;if(ye(r)===!1)return!1;if(Object.prototype.hasOwnProperty.call(r,"isPrototypeOf")===!1)return!1;return!0}function It(e){if(ue(e))return{...e};if(Array.isArray(e))return[...e];if(e instanceof Map)return new Map(e);if(e instanceof Set)return new Set(e);return e}var Dr=new Set(["string","number","symbol"]);function Q(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function K(e,t,r){let n=new e._zod.constr(t??e._zod.def);if(!t||r?.parent)n._zod.parent=e;return n}function _(e){let t=e;if(!t)return{};if(typeof t==="string")return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}if(delete t.message,typeof t.error==="string")return{...t,error:()=>t.error};return t}function Et(e){if(typeof e==="bigint")return e.toString()+"n";if(typeof e==="string")return`"${e}"`;return`${e}`}function jr(e){return Object.keys(e).filter((t)=>e[t]._zod.optin!==void 0&&e[t]._zod.optout==="optional")}var Fe=(()=>({safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-340282346638528860000000000000000000000,340282346638528860000000000000000000000],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]}))(),At={int64:[BigInt("-9223372036854775808"),BigInt("9223372036854775807")],uint64:[BigInt(0),BigInt("18446744073709551615")]};function Nc(e,t){let r=e._zod.def,n=r.checks;if(n&&n.length>0)throw Error(".pick() cannot be used on object schemas containing refinements");let s={};return ne(s,e,Me(e,t)),K(e,C(r,{shape:s,checks:[]}))}function Me(e,t){let r=H(e),n=[];for(let o of Reflect.ownKeys(t)){if(!Object.getOwnPropertyDescriptor(r,o)?.enumerable)throw Error(`Unrecognized key: "${String(o)}"`);if(t[o])n.push(o)}return n}function Cc(e,t){let r=e._zod.def,n=r.checks;if(n&&n.length>0)throw Error(".omit() cannot be used on object schemas containing refinements");let s=new Set(Me(e,t)),i={};return ne(i,e,Reflect.ownKeys(H(e)).filter((c)=>!s.has(c))),K(e,C(r,{shape:i,checks:[]}))}function Rc(e,t){if(!ue(t))throw Error("Invalid input to extend: expected a plain object");let r=e._zod.def.checks;if(r&&r.length>0){let o=H(e);for(let s of Reflect.ownKeys(t))if(Object.getOwnPropertyDescriptor(o,s)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return K(e,C(e._zod.def,{shape:Lr(e,t)}))}function Lr(e,t){let r={};return ne(r,e,Reflect.ownKeys(H(e))),Tc(r,t),r}function Dc(e,t){if(!ue(t))throw Error("Invalid input to safeExtend: expected a plain object");return K(e,C(e._zod.def,{shape:Lr(e,t)}))}function jc(e,t){if(!t?._zod?.def)throw Error("Invalid input to merge: expected an object schema. To merge a plain shape, use `.extend()`.");if(e._zod.def.checks?.length)throw Error(".merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.");let r={};ne(r,e,Reflect.ownKeys(H(e))),ne(r,t,Reflect.ownKeys(H(t)));let n=C(e._zod.def,{shape:r,get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]});return K(e,n)}function Fr(e,t,r,n="partial"){let s=t._zod.def.checks;if(s&&s.length>0)throw Error(`.${n}() cannot be used on object schemas containing refinements`);let c=r?new Set(Me(t,r)):void 0,u={};return ne(u,t,Reflect.ownKeys(H(t)),e&&((a,l)=>c&&!c.has(l)?a:new e({type:"optional",innerType:a}))),K(t,C(t._zod.def,{shape:u,checks:[]}))}function Lc(e,t,r){let n=r?new Set(Me(t,r)):void 0,o={};return ne(o,t,Reflect.ownKeys(H(t)),(s,i)=>n&&!n.has(i)?s:new e({type:"nonoptional",innerType:s})),K(t,C(t._zod.def,{shape:o}))}function V(e,t=0){if(e.aborted===!0)return!0;for(let r=t;r<e.issues.length;r++)if(e.issues[r]?.continue!==!0)return!0;return!1}function Mr(e,t=0){if(e.aborted===!0)return!0;for(let r=t;r<e.issues.length;r++)if(e.issues[r]?.continue===!1)return!0;return!1}function Ue(e,t){return t.map((r)=>{var n;return(n=r).path??(n.path=[]),r.path.unshift(e),r})}function _e(e){return typeof e==="string"?e:e?.message}function Tt(e,t,r){var n;for(let o=t;o<e.length;o++)(n=e[o]).schema??(n.schema=r)}function ee(e,t,r){var n;let o=e.inst?._zod?.traits;if(o?.has("$ZodType"))if(o.has("$ZodCheck"))(n=e).schema??(n.schema=e.inst);else e.schema=e.inst;let s=e.schema!==e.inst?e.schema?._zod.def?.error:void 0,i=e.message?e.message:_e(e.inst?._zod.def?.error?.(e))??_e(s?.(e))??_e(t?.error?.(e))??_e(r.customError?.(e))??_e(r.localeError?.(e))??"Invalid input",c={};for(let u of Object.keys(e)){if(u==="inst"||u==="schema"||u==="continue"||u==="input"||u==="__proto__")continue;c[u]=e[u]}if(c.path??(c.path=[]),c.message=i,t?.reportInput)c.input=e.input;return c}var Fc=/[\uD800-\uDBFF]/;function Be(e){let t=e.length;if(!Fc.test(e))return t;let r=t;for(let n=0;n<t-1;n++)if((e.charCodeAt(n)&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320)r--,n++;return r}function Je(e){if(Array.isArray(e))return"array";if(typeof e==="string")return"string";return"unknown"}function Ur(e){let t=typeof e;switch(t){case"number":return Number.isNaN(e)?"nan":"number";case"object":{if(e===null)return"null";if(Array.isArray(e))return"array";let r=e;if(r&&Object.getPrototypeOf(r)!==Object.prototype&&"constructor"in r&&r.constructor)return r.constructor.name}}return t}function oe(...e){let[t,r,n]=e;if(typeof t==="string")return{message:t,code:"custom",input:r,inst:n};return{...t}}function Br(e,t){for(let r in t){let n=Object.getOwnPropertyDescriptor(t,r);if(n.get)Object.defineProperty(e,r,{...n,enumerable:!1});else Mc(e,r,n.value)}}function X(e,t,r,n=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:n,value:r}),r}function Ke(e,t,r){return X(e,t,r,!1)}function Jr(e,t){for(let r in e){let n=e[r];Object.defineProperty(t,r,{configurable:!0,enumerable:!0,get(){return X(this,r,n(this))},set(o){X(this,r,o)}})}return t}function Mc(e,t,r){Object.defineProperty(e,t,{configurable:!0,get(){return this==null?r:X(this,t,r.bind(this))},set(n){X(this,t,n)}})}function Uc(e,t){let r=Object.getPrototypeOf(e);return t in r?void 0:r}var Pt,q=!1,Bc={configurable:!0,get(){q=!0;return}};function b(e,t,r){let n=Object.getPrototypeOf(e._zod);if(t in n&&Pt!==e._zod){Pt=void 0;return}Pt=e._zod,Object.defineProperty(n,t,{configurable:!0,get(){Object.defineProperty(this,t,Bc);let o=q;q=!1;try{let s=r(this);if(q)delete this[t];else Object.defineProperty(this,t,{configurable:!0,writable:!0,value:s});return q=q||o,s}catch(s){throw delete this[t],q=q||o,s}},set(o){Object.defineProperty(this,t,{configurable:!0,writable:!0,value:o})}})}function Jc(e,t,r,n){let o=Uc(e,t);if(!o)return;Object.defineProperty(o,t,{configurable:!0,get(){let s={configurable:!0,writable:!0,enumerable:n,value:void 0};return Object.defineProperty(this,t,s),s.value=r(this),Object.defineProperty(this,t,s),s.value},set(s){Object.defineProperty(this,t,{configurable:!0,writable:!0,enumerable:n,value:s})}})}var Kc="~constantCatch";function Kr(e){let t=()=>e;return t[Kc]=!0,t}var Vr;var Nt={value:void 0,enumerable:!1},Gr="captureStackTrace"in Error?Error:null;function Vc(e){let t=Gr;if(t){let r=t.stackTraceLimit;if(typeof r==="number"){try{t.stackTraceLimit=0}catch{return Gr=null,new e}try{return new e}finally{t.stackTraceLimit=r}}}return new e}function p(e,t,r,n){let o={};function s(d){this.def=d,this.constr=f,this.traits=new Set}s.prototype=o;let i=r,c=i&&new WeakSet;function u(d,h){if(!d._zod){Nt.value=new s(h);try{Object.defineProperty(d,"_zod",Nt)}finally{Nt.value=void 0}}else if(d._zod.traits.has(e))return;if(d._zod.traits.add(e),t(d,h),c){let g=Object.getPrototypeOf(d),y=d._zod.constr.prototype,x=g;while(x&&x!==y)x=Object.getPrototypeOf(x);let U=x??g;if(!c.has(U))c.add(U),Br(U,i)}let m=f.prototype;for(let g in m){if(!Object.prototype.hasOwnProperty.call(m,g))continue;if(!(g in d))d[g]=m[g].bind(d)}}let a=n?.Parent??Object;class l extends a{}Object.defineProperty(l,"name",{value:e});function f(d){let h=n?.Parent?Vc(l):this;u(h,d);let m=h._zod.deferred;if(m){for(let y of m)y();h._zod.deferred=void 0}let g=globalThis.__zod_globalConfig?.postProcessor;if(g)g(h);return h}return Object.defineProperty(f,"init",{value:u}),Object.defineProperty(f,Symbol.hasInstance,{value:(d)=>{if(n?.Parent&&d instanceof n.Parent)return!0;return d?._zod?.traits?.has(e)}}),Object.defineProperty(f,"name",{value:e}),f}class G extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class ve extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`);this.name="ZodEncodeError"}}(Vr=globalThis).__zod_globalConfig??(Vr.__zod_globalConfig={});var R=globalThis.__zod_globalConfig;function F(e){if(e)Object.assign(R,e);return R}function Gc(){let e=this._zod;return e.message??(e.message=JSON.stringify(e.def,xe,2)),e.message}function Wc(e){this._zod.message=e}var Hc={get:Gc,set:Wc,enumerable:!0,configurable:!0},Rt={value:void 0,enumerable:!1},Wr=new WeakSet([Object.prototype,Error.prototype]),Hr=(e,t)=>{e.name="$ZodError",Rt.value=t,Object.defineProperty(e,"issues",Rt),Rt.value=void 0,Object.defineProperty(e,"message",Hc);let r=Object.getPrototypeOf(e);if(!Wr.has(r))Wr.add(r),Object.defineProperty(r,"toString",{configurable:!0,enumerable:!1,get(){let n=()=>this.message;return Object.defineProperty(this,"toString",{value:n,configurable:!0,writable:!0}),n},set(n){Object.defineProperty(this,"toString",{value:n,configurable:!0,writable:!0})}})},Xr=p("$ZodError",Hr),El=p("$ZodError",Hr,void 0,{Parent:Error});function Xc(e,t,r){if(!Object.prototype.hasOwnProperty.call(e,t))if(t==="__proto__")Object.defineProperty(e,t,{value:r(),writable:!0,enumerable:!0,configurable:!0});else e[t]=r();return e[t]}function Yr(e,t=(r)=>r.message){let r={},n=[];for(let o of e.issues)if(o.path.length>0)Xc(r,o.path[0],()=>[]).push(t(o));else n.push(t(o));return{formErrors:n,fieldErrors:r}}function qr(e,t=(r)=>r.message){let r={_errors:[]},n=(o,s=[])=>{for(let i of o.issues)if(i.code==="invalid_union"&&i.errors.length)i.errors.map((c)=>n({issues:c},[...s,...i.path]));else if(i.code==="invalid_key")n({issues:i.issues},[...s,...i.path]);else if(i.code==="invalid_element")n({issues:i.issues},[...s,...i.path]);else{let c=[...s,...i.path];if(c.length===0)r._errors.push(t(i));else{let u=r,a=0;while(a<c.length){let l=c[a],f=a===c.length-1;if(l==="_errors"){if(f)u._errors.push(t(i));a++;continue}if(!Object.prototype.hasOwnProperty.call(u,l))Object.defineProperty(u,l,{value:{_errors:[]},enumerable:!0,writable:!0,configurable:!0});let d=u[l];if(f)d._errors.push(t(i));u=d,a++}}}};return n(e),r}function Ve(e,t){return{callee:t?.callee??e,Err:t?.Err}}var Ge=(e)=>{let t=(r,n,o,s)=>{let i=o?{...o,async:!1}:{async:!1},c=r._zod.run({value:n,issues:[]},i);if(c instanceof Promise)throw new G;if(c.issues.length){let u=new(s?.Err??e)(c.issues.map((a)=>ee(a,i,F())));throw Ot(u,s?.callee??t),u}return c.value};return t};var We=(e)=>{let t=async(r,n,o,s)=>{let i=o?{...o,async:!0}:{async:!0},c=r._zod.run({value:n,issues:[]},i);if(c instanceof Promise)c=await c;if(c.issues.length){let u=new(s?.Err??e)(c.issues.map((a)=>ee(a,i,F())));throw Ot(u,s?.callee??t),u}return c.value};return t};var He=(e)=>(t,r,n)=>{let o=n?{...n,async:!1}:{async:!1},s=t._zod.run({value:r,issues:[]},o);if(s instanceof Promise)throw new G;return s.issues.length?Qr(e,s.issues,o):{success:!0,data:s.value}};function Qr(e,t,r){let n;return{success:!1,get error(){if(!n)n=new e(t.map((o)=>ee(o,r,F()))),t=void 0,r=void 0;return n},set error(o){n=o,t=void 0,r=void 0}}}var Xe=(e)=>async(t,r,n)=>{let o=n?{...n,async:!0}:{async:!0},s=t._zod.run({value:r,issues:[]},o);if(s instanceof Promise)s=await s;return s.issues.length?Qr(e,s.issues,o):{success:!0,data:s.value}};var Yc=Symbol.for("zod.compile.invalid"),qc=Symbol.for("zod.compile.fallback"),Dt=(e,t,r)=>{let n=e._zod.bag.validator;if(n!==void 0){if(n(t)!==Yc)return!0;if(n.definite===!0&&r===void 0)return!1}return Qc(e,t,r)};function Qc(e,t,r){let n=r?{...r,async:!1,abortEarly:!0}:{async:!1,abortEarly:!0},o=e._zod.bag.fallbackRun,s;if(o)n[qc]=!0,s=o({value:t,issues:[]},n);else s=e._zod.run({value:t,issues:[]},n);if(s instanceof Promise)throw new G;return s.issues.length===0}var jt=async(e,t,r)=>{let n=r?{...r,async:!0,abortEarly:!0}:{async:!0,abortEarly:!0},o=e._zod.run({value:t,issues:[]},n);if(o instanceof Promise)o=await o;return o.issues.length===0},en=(e)=>{let t=Ge(e),r=(n,o,s,i)=>{let c=s?{...s,direction:"backward"}:{direction:"backward"};return t(n,o,c,Ve(r,i))};return r};var tn=(e)=>{let t=Ge(e),r=(n,o,s,i)=>t(n,o,s,Ve(r,i));return r};var rn=(e)=>{let t=We(e),r=async(n,o,s,i)=>{let c=s?{...s,direction:"backward"}:{direction:"backward"};return await t(n,o,c,Ve(r,i))};return r};var nn=(e)=>{let t=We(e),r=async(n,o,s,i)=>await t(n,o,s,Ve(r,i));return r};var on=(e)=>(t,r,n)=>{let o=n?{...n,direction:"backward"}:{direction:"backward"};return He(e)(t,r,o)};var sn=(e)=>(t,r,n)=>He(e)(t,r,n);var cn=(e)=>async(t,r,n)=>{let o=n?{...n,direction:"backward"}:{direction:"backward"};return Xe(e)(t,r,o)};var un=(e)=>async(t,r,n)=>Xe(e)(t,r,n);var an=/^[cC][0-9a-z]{6,}$/,ln=/^[0-9a-z]+$/,pn=/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,fn=/^[0-9a-vA-V]{20}$/,dn=/^[A-Za-z0-9]{27}$/,mn=/^[a-zA-Z0-9_-]{21}$/;function hn(e){return new RegExp(`^[a-zA-Z0-9_-]{${e}}$`)}var gn=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;var _n=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,Ft=(e)=>{if(!e)return/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`)};var yn=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;var eu="^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$";function bn(){return new RegExp(eu,"u")}var xn=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,vn=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;var $n=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,wn=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,zn=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Sn=/^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/;var kn=/^https?$/,Pn=/^\+[1-9]\d{6,14}$/;var Zn="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))";function tu(e){return new RegExp(`^${e}$`)}var On=tu(Zn);function Lt(e){return typeof e.precision==="number"?e.precision===-1?"(?:[01]\\d|2[0-3]):[0-5]\\d":e.precision===0?"(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d":`(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d\\.\\d{${e.precision}}`:e.seconds?"(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?":"(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?"}function In(e){return new RegExp(`^${Lt(e)}$`)}function En(e){let t=["Z"];if(e.offset)t.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");let r=`${Lt({precision:e.precision,seconds:!0})}(?:${t.join("|")})`,n=e.local?`${r}|${Lt({precision:e.precision})}`:r;return new RegExp(`^${Zn}T(?:${n})$`)}var An=/^[\s\S]{0,}$/;var Mt=/^-?\d+(?:\.\d+)?$/,Tn=/^(?:true|false)$/i;var Nn=/^[^A-Z]*$/,Cn=/^[^a-z]*$/;var A=p("$ZodCheck",(e,t)=>{var r;e._zod??(e._zod={}),e._zod.def=t,(r=e._zod).onattach??(r.onattach=[])});var Ut=(e)=>{let t=e.value;return!Ir(t)&&t.length!==void 0},Ye={number:"number",bigint:"bigint",object:"date"},Bt=p("$ZodCheckLessThan",(e,t)=>{A.init(e,t);let r=Ye[typeof t.value];e._zod.check=(n)=>{if(t.inclusive?n.value<=t.value:n.value<t.value)return;n.issues.push({origin:Ye[typeof n.value]??r,code:"too_big",maximum:typeof t.value==="object"?t.value.getTime():t.value,input:n.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Jt=p("$ZodCheckGreaterThan",(e,t)=>{A.init(e,t);let r=Ye[typeof t.value];e._zod.check=(n)=>{if(t.inclusive?n.value>=t.value:n.value>t.value)return;n.issues.push({origin:Ye[typeof n.value]??r,code:"too_small",minimum:typeof t.value==="object"?t.value.getTime():t.value,input:n.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Rn=p("$ZodCheckMultipleOf",(e,t)=>{A.init(e,t),e._zod.check=(r)=>{if(typeof r.value!==typeof t.value)throw Error("Cannot mix number and bigint in multiple_of check.");if(typeof r.value==="bigint"?t.value!==BigInt(0)&&r.value%t.value===BigInt(0):Er(r.value,t.value)===0)return;r.issues.push({origin:typeof r.value,code:"not_multiple_of",divisor:t.value,input:r.value,inst:e,continue:!t.abort})}}),Dn=p("$ZodCheckNumberFormat",(e,t)=>{A.init(e,t),t.format=t.format||"float64";let r=t.format?.includes("int"),n=r?"int":"number",[o,s]=Fe[t.format];e._zod.check=(i)=>{let c=i.value;if(r){if(!Number.isInteger(c)){i.issues.push({expected:n,format:t.format,code:"invalid_type",continue:!1,input:c,inst:e});return}if(!Number.isSafeInteger(c)){if(c>0)i.issues.push({input:c,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:n,inclusive:!0,continue:!t.abort});else i.issues.push({input:c,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:n,inclusive:!0,continue:!t.abort});return}}if(c<o)i.issues.push({origin:"number",input:c,code:"too_small",minimum:o,inclusive:!0,inst:e,continue:!t.abort});if(c>s)i.issues.push({origin:"number",input:c,code:"too_big",maximum:s,inclusive:!0,inst:e,continue:!t.abort})}});var jn=p("$ZodCheckMaxLength",(e,t)=>{var r;A.init(e,t),(r=e._zod.def).when??(r.when=Ut),e._zod.check=(n)=>{let o=n.value,s=o.length;if((typeof o==="string"&&s>t.maximum?Be(o):s)<=t.maximum)return;let c=Je(o);n.issues.push({origin:c,code:"too_big",maximum:t.maximum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),Ln=p("$ZodCheckMinLength",(e,t)=>{var r;A.init(e,t),(r=e._zod.def).when??(r.when=Ut),e._zod.check=(n)=>{let o=n.value,s=o.length;if((typeof o==="string"&&s>=t.minimum&&s<t.minimum*2?Be(o):s)>=t.minimum)return;let c=Je(o);n.issues.push({origin:c,code:"too_small",minimum:t.minimum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),Fn=p("$ZodCheckLengthEquals",(e,t)=>{var r;A.init(e,t),(r=e._zod.def).when??(r.when=Ut),e._zod.check=(n)=>{let o=n.value,s=o.length,i=typeof o==="string"&&s>=t.length&&s<=t.length*2?Be(o):s;if(i===t.length)return;let c=Je(o),u=i>t.length;n.issues.push({origin:c,...u?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),we=p("$ZodCheckStringFormat",(e,t)=>{var r,n;if(A.init(e,t),t.pattern)(r=e._zod).check??(r.check=(o)=>{if(t.pattern.lastIndex=0,t.pattern.test(o.value))return;o.issues.push({origin:"string",code:"invalid_format",format:t.format,input:o.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})});else(n=e._zod).check??(n.check=()=>{})}),Mn=p("$ZodCheckRegex",(e,t)=>{we.init(e,t),e._zod.check=(r)=>{if(t.pattern.lastIndex=0,t.pattern.test(r.value))return;r.issues.push({origin:"string",code:"invalid_format",format:"regex",input:r.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),Un=p("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=Nn),we.init(e,t)}),Bn=p("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=Cn),we.init(e,t)}),Jn=p("$ZodCheckIncludes",(e,t)=>{A.init(e,t);let r=Q(t.includes),n=new RegExp(typeof t.position==="number"?`^.{${t.position},}${r}`:r);t.pattern=n,e._zod.check=(o)=>{if(o.value.includes(t.includes,t.position))return;o.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:o.value,inst:e,continue:!t.abort})}}),Kn=p("$ZodCheckStartsWith",(e,t)=>{A.init(e,t);let r=new RegExp(`^${Q(t.prefix)}.*`);t.pattern??(t.pattern=r),e._zod.check=(n)=>{if(n.value.startsWith(t.prefix))return;n.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),Vn=p("$ZodCheckEndsWith",(e,t)=>{A.init(e,t);let r=new RegExp(`.*${Q(t.suffix)}$`);t.pattern??(t.pattern=r),e._zod.check=(n)=>{if(n.value.endsWith(t.suffix))return;n.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}});var Gn=p("$ZodCheckOverwrite",(e,t)=>{A.init(e,t),e._zod.check=(r)=>{r.value=t.tx(r.value)}});class Kt{constructor(e=[],t={}){this.content=[],this.indent=0,this.args=e,this.closed=t}indented(e){this.indent+=1;try{e(this)}finally{this.indent-=1}}write(e){if(typeof e==="function"){e(this,{execution:"sync"}),e(this,{execution:"async"});return}let r=e.split(`
|
|
5
|
+
var Oc=Object.defineProperty;var Ic=(e)=>e;function Ec(e,t){this[e]=Ic.bind(null,t)}var Ac=(e,t)=>{for(var r in t)Oc(e,r,{get:t[r],enumerable:!0,configurable:!0,set:Ec.bind(t,r)})};var vr={};Ac(vr,{ZodISODate:()=>Ae,ZodISODateTime:()=>Ee,ZodISODuration:()=>Ne,ZodISOTime:()=>Te,date:()=>Ta,datetime:()=>Aa,duration:()=>Ca,time:()=>Na});import{homedir as Sl}from"os";import{readFile as bl,writeFile as xl}from"fs/promises";function be(e){let t=Object.values(e).filter((n)=>typeof n==="number");return Object.entries(e).filter(([n,o])=>t.indexOf(+n)===-1).map(([n,o])=>o)}function Zt(e,t="|"){return e.map((r)=>Et(r)).join(t)}function xe(e,t){if(typeof t==="bigint")return t.toString();return t}class Or{constructor(e){this._getter=e,this._value=void 0}get value(){let e=this._getter;if(e!==void 0)this._value=e(),this._getter=void 0;return this._value}}function De(e){return new Or(e)}function Ir(e){return e===null||e===void 0}function je(e){let t=e.startsWith("^")?1:0,r=e.endsWith("$")?e.length-1:e.length;return e.slice(t,r)}function Er(e,t){let r=e/t,n=Math.round(r),o=4*Number.EPSILON*Math.max(Math.abs(r),1);if(Math.abs(r-n)<o)return 0;return r-n}function J(e,t,r){Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!0,configurable:!0})}function Le(e){let t=Object.getOwnPropertyDescriptor(e,"shape");return t?.get?t.get.raw:t?.value}function H(e){return Le(e._zod.def)??e._zod.def.shape}function Ar(e,t,r){Object.defineProperty(e,t,{get(){let n=r();return J(this,t,n),n},enumerable:!0,configurable:!0})}function Tr(e,t,r){if(t in e)J(e,t,r);else e[t]=r}function ne(e,t,r,n){let o=H(t);for(let s of r){let i=Object.getOwnPropertyDescriptor(o,s);if(!i.enumerable)continue;if(i.get)Ar(e,s,()=>{let c=t._zod.def.shape[s];return n?n(c,s):c});else Tr(e,s,n?n(i.value,s):i.value)}}function Tc(e,t){for(let r of Reflect.ownKeys(t)){let n=Object.getOwnPropertyDescriptor(t,r);if(!n.enumerable)continue;if(n.get)Ar(e,r,()=>t[r]);else Tr(e,r,n.value)}}function C(...e){let t={};for(let r of e){let n=Object.getOwnPropertyDescriptors(r);Object.assign(t,n)}return Object.defineProperties({},t)}function Nr(e){return JSON.stringify(e)}function Cr(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}var Ot="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function ye(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var Rr=De(()=>{if(R.jitless)return!1;if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(e){return!1}});function ue(e){if(ye(e)===!1)return!1;let t=e.constructor;if(t===void 0)return!0;if(typeof t!=="function")return!0;let r=t.prototype;if(ye(r)===!1)return!1;if(Object.prototype.hasOwnProperty.call(r,"isPrototypeOf")===!1)return!1;return!0}function It(e){if(ue(e))return{...e};if(Array.isArray(e))return[...e];if(e instanceof Map)return new Map(e);if(e instanceof Set)return new Set(e);return e}var Dr=new Set(["string","number","symbol"]);function Q(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function K(e,t,r){let n=new e._zod.constr(t??e._zod.def);if(!t||r?.parent)n._zod.parent=e;return n}function _(e){let t=e;if(!t)return{};if(typeof t==="string")return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}if(delete t.message,typeof t.error==="string")return{...t,error:()=>t.error};return t}function Et(e){if(typeof e==="bigint")return e.toString()+"n";if(typeof e==="string")return`"${e}"`;return`${e}`}function jr(e){return Object.keys(e).filter((t)=>e[t]._zod.optin!==void 0&&e[t]._zod.optout==="optional")}var Fe=(()=>({safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-340282346638528860000000000000000000000,340282346638528860000000000000000000000],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]}))(),At={int64:[BigInt("-9223372036854775808"),BigInt("9223372036854775807")],uint64:[BigInt(0),BigInt("18446744073709551615")]};function Nc(e,t){let r=e._zod.def,n=r.checks;if(n&&n.length>0)throw Error(".pick() cannot be used on object schemas containing refinements");let s={};return ne(s,e,Me(e,t)),K(e,C(r,{shape:s,checks:[]}))}function Me(e,t){let r=H(e),n=[];for(let o of Reflect.ownKeys(t)){if(!Object.getOwnPropertyDescriptor(r,o)?.enumerable)throw Error(`Unrecognized key: "${String(o)}"`);if(t[o])n.push(o)}return n}function Cc(e,t){let r=e._zod.def,n=r.checks;if(n&&n.length>0)throw Error(".omit() cannot be used on object schemas containing refinements");let s=new Set(Me(e,t)),i={};return ne(i,e,Reflect.ownKeys(H(e)).filter((c)=>!s.has(c))),K(e,C(r,{shape:i,checks:[]}))}function Rc(e,t){if(!ue(t))throw Error("Invalid input to extend: expected a plain object");let r=e._zod.def.checks;if(r&&r.length>0){let o=H(e);for(let s of Reflect.ownKeys(t))if(Object.getOwnPropertyDescriptor(o,s)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return K(e,C(e._zod.def,{shape:Lr(e,t)}))}function Lr(e,t){let r={};return ne(r,e,Reflect.ownKeys(H(e))),Tc(r,t),r}function Dc(e,t){if(!ue(t))throw Error("Invalid input to safeExtend: expected a plain object");return K(e,C(e._zod.def,{shape:Lr(e,t)}))}function jc(e,t){if(!t?._zod?.def)throw Error("Invalid input to merge: expected an object schema. To merge a plain shape, use `.extend()`.");if(e._zod.def.checks?.length)throw Error(".merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.");let r={};ne(r,e,Reflect.ownKeys(H(e))),ne(r,t,Reflect.ownKeys(H(t)));let n=C(e._zod.def,{shape:r,get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]});return K(e,n)}function Fr(e,t,r,n="partial"){let s=t._zod.def.checks;if(s&&s.length>0)throw Error(`.${n}() cannot be used on object schemas containing refinements`);let c=r?new Set(Me(t,r)):void 0,u={};return ne(u,t,Reflect.ownKeys(H(t)),e&&((a,l)=>c&&!c.has(l)?a:new e({type:"optional",innerType:a}))),K(t,C(t._zod.def,{shape:u,checks:[]}))}function Lc(e,t,r){let n=r?new Set(Me(t,r)):void 0,o={};return ne(o,t,Reflect.ownKeys(H(t)),(s,i)=>n&&!n.has(i)?s:new e({type:"nonoptional",innerType:s})),K(t,C(t._zod.def,{shape:o}))}function V(e,t=0){if(e.aborted===!0)return!0;for(let r=t;r<e.issues.length;r++)if(e.issues[r]?.continue!==!0)return!0;return!1}function Mr(e,t=0){if(e.aborted===!0)return!0;for(let r=t;r<e.issues.length;r++)if(e.issues[r]?.continue===!1)return!0;return!1}function Ue(e,t){return t.map((r)=>{var n;return(n=r).path??(n.path=[]),r.path.unshift(e),r})}function _e(e){return typeof e==="string"?e:e?.message}function Tt(e,t,r){var n;for(let o=t;o<e.length;o++)(n=e[o]).schema??(n.schema=r)}function ee(e,t,r){var n;let o=e.inst?._zod?.traits;if(o?.has("$ZodType"))if(o.has("$ZodCheck"))(n=e).schema??(n.schema=e.inst);else e.schema=e.inst;let s=e.schema!==e.inst?e.schema?._zod.def?.error:void 0,i=e.message?e.message:_e(e.inst?._zod.def?.error?.(e))??_e(s?.(e))??_e(t?.error?.(e))??_e(r.customError?.(e))??_e(r.localeError?.(e))??"Invalid input",c={};for(let u of Object.keys(e)){if(u==="inst"||u==="schema"||u==="continue"||u==="input"||u==="__proto__")continue;c[u]=e[u]}if(c.path??(c.path=[]),c.message=i,t?.reportInput)c.input=e.input;return c}var Fc=/[\uD800-\uDBFF]/;function Be(e){let t=e.length;if(!Fc.test(e))return t;let r=t;for(let n=0;n<t-1;n++)if((e.charCodeAt(n)&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320)r--,n++;return r}function Je(e){if(Array.isArray(e))return"array";if(typeof e==="string")return"string";return"unknown"}function Ur(e){let t=typeof e;switch(t){case"number":return Number.isNaN(e)?"nan":"number";case"object":{if(e===null)return"null";if(Array.isArray(e))return"array";let r=e;if(r&&Object.getPrototypeOf(r)!==Object.prototype&&"constructor"in r&&r.constructor)return r.constructor.name}}return t}function oe(...e){let[t,r,n]=e;if(typeof t==="string")return{message:t,code:"custom",input:r,inst:n};return{...t}}function Br(e,t){for(let r in t){let n=Object.getOwnPropertyDescriptor(t,r);if(n.get)Object.defineProperty(e,r,{...n,enumerable:!1});else Mc(e,r,n.value)}}function X(e,t,r,n=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:n,value:r}),r}function Ke(e,t,r){return X(e,t,r,!1)}function Jr(e,t){for(let r in e){let n=e[r];Object.defineProperty(t,r,{configurable:!0,enumerable:!0,get(){return X(this,r,n(this))},set(o){X(this,r,o)}})}return t}function Mc(e,t,r){Object.defineProperty(e,t,{configurable:!0,get(){return this==null?r:X(this,t,r.bind(this))},set(n){X(this,t,n)}})}function Uc(e,t){let r=Object.getPrototypeOf(e);return t in r?void 0:r}var Pt,q=!1,Bc={configurable:!0,get(){q=!0;return}};function b(e,t,r){let n=Object.getPrototypeOf(e._zod);if(t in n&&Pt!==e._zod){Pt=void 0;return}Pt=e._zod,Object.defineProperty(n,t,{configurable:!0,get(){Object.defineProperty(this,t,Bc);let o=q;q=!1;try{let s=r(this);if(q)delete this[t];else Object.defineProperty(this,t,{configurable:!0,writable:!0,value:s});return q=q||o,s}catch(s){throw delete this[t],q=q||o,s}},set(o){Object.defineProperty(this,t,{configurable:!0,writable:!0,value:o})}})}function Jc(e,t,r,n){let o=Uc(e,t);if(!o)return;Object.defineProperty(o,t,{configurable:!0,get(){let s={configurable:!0,writable:!0,enumerable:n,value:void 0};return Object.defineProperty(this,t,s),s.value=r(this),Object.defineProperty(this,t,s),s.value},set(s){Object.defineProperty(this,t,{configurable:!0,writable:!0,enumerable:n,value:s})}})}var Kc="~constantCatch";function Kr(e){let t=()=>e;return t[Kc]=!0,t}var Vr;var Nt={value:void 0,enumerable:!1},Gr="captureStackTrace"in Error?Error:null;function Vc(e){let t=Gr;if(t){let r=t.stackTraceLimit;if(typeof r==="number"){try{t.stackTraceLimit=0}catch{return Gr=null,new e}try{return new e}finally{t.stackTraceLimit=r}}}return new e}function p(e,t,r,n){let o={};function s(d){this.def=d,this.constr=f,this.traits=new Set}s.prototype=o;let i=r,c=i&&new WeakSet;function u(d,h){if(!d._zod){Nt.value=new s(h);try{Object.defineProperty(d,"_zod",Nt)}finally{Nt.value=void 0}}else if(d._zod.traits.has(e))return;if(d._zod.traits.add(e),t(d,h),c){let g=Object.getPrototypeOf(d),y=d._zod.constr.prototype,x=g;while(x&&x!==y)x=Object.getPrototypeOf(x);let U=x??g;if(!c.has(U))c.add(U),Br(U,i)}let m=f.prototype;for(let g in m){if(!Object.prototype.hasOwnProperty.call(m,g))continue;if(!(g in d))d[g]=m[g].bind(d)}}let a=n?.Parent??Object;class l extends a{}Object.defineProperty(l,"name",{value:e});function f(d){let h=n?.Parent?Vc(l):this;u(h,d);let m=h._zod.deferred;if(m){for(let y of m)y();h._zod.deferred=void 0}let g=globalThis.__zod_globalConfig?.postProcessor;if(g)g(h);return h}return Object.defineProperty(f,"init",{value:u}),Object.defineProperty(f,Symbol.hasInstance,{value:(d)=>{if(n?.Parent&&d instanceof n.Parent)return!0;return d?._zod?.traits?.has(e)}}),Object.defineProperty(f,"name",{value:e}),f}class G extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class ve extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`);this.name="ZodEncodeError"}}(Vr=globalThis).__zod_globalConfig??(Vr.__zod_globalConfig={});var R=globalThis.__zod_globalConfig;function F(e){if(e)Object.assign(R,e);return R}function Gc(){let e=this._zod;return e.message??(e.message=JSON.stringify(e.def,xe,2)),e.message}function Wc(e){this._zod.message=e}var Hc={get:Gc,set:Wc,enumerable:!0,configurable:!0},Rt={value:void 0,enumerable:!1},Wr=new WeakSet([Object.prototype,Error.prototype]),Hr=(e,t)=>{e.name="$ZodError",Rt.value=t,Object.defineProperty(e,"issues",Rt),Rt.value=void 0,Object.defineProperty(e,"message",Hc);let r=Object.getPrototypeOf(e);if(!Wr.has(r))Wr.add(r),Object.defineProperty(r,"toString",{configurable:!0,enumerable:!1,get(){let n=()=>this.message;return Object.defineProperty(this,"toString",{value:n,configurable:!0,writable:!0}),n},set(n){Object.defineProperty(this,"toString",{value:n,configurable:!0,writable:!0})}})},Xr=p("$ZodError",Hr),Al=p("$ZodError",Hr,void 0,{Parent:Error});function Xc(e,t,r){if(!Object.prototype.hasOwnProperty.call(e,t))if(t==="__proto__")Object.defineProperty(e,t,{value:r(),writable:!0,enumerable:!0,configurable:!0});else e[t]=r();return e[t]}function Yr(e,t=(r)=>r.message){let r={},n=[];for(let o of e.issues)if(o.path.length>0)Xc(r,o.path[0],()=>[]).push(t(o));else n.push(t(o));return{formErrors:n,fieldErrors:r}}function qr(e,t=(r)=>r.message){let r={_errors:[]},n=(o,s=[])=>{for(let i of o.issues)if(i.code==="invalid_union"&&i.errors.length)i.errors.map((c)=>n({issues:c},[...s,...i.path]));else if(i.code==="invalid_key")n({issues:i.issues},[...s,...i.path]);else if(i.code==="invalid_element")n({issues:i.issues},[...s,...i.path]);else{let c=[...s,...i.path];if(c.length===0)r._errors.push(t(i));else{let u=r,a=0;while(a<c.length){let l=c[a],f=a===c.length-1;if(l==="_errors"){if(f)u._errors.push(t(i));a++;continue}if(!Object.prototype.hasOwnProperty.call(u,l))Object.defineProperty(u,l,{value:{_errors:[]},enumerable:!0,writable:!0,configurable:!0});let d=u[l];if(f)d._errors.push(t(i));u=d,a++}}}};return n(e),r}function Ve(e,t){return{callee:t?.callee??e,Err:t?.Err}}var Ge=(e)=>{let t=(r,n,o,s)=>{let i=o?{...o,async:!1}:{async:!1},c=r._zod.run({value:n,issues:[]},i);if(c instanceof Promise)throw new G;if(c.issues.length){let u=new(s?.Err??e)(c.issues.map((a)=>ee(a,i,F())));throw Ot(u,s?.callee??t),u}return c.value};return t};var We=(e)=>{let t=async(r,n,o,s)=>{let i=o?{...o,async:!0}:{async:!0},c=r._zod.run({value:n,issues:[]},i);if(c instanceof Promise)c=await c;if(c.issues.length){let u=new(s?.Err??e)(c.issues.map((a)=>ee(a,i,F())));throw Ot(u,s?.callee??t),u}return c.value};return t};var He=(e)=>(t,r,n)=>{let o=n?{...n,async:!1}:{async:!1},s=t._zod.run({value:r,issues:[]},o);if(s instanceof Promise)throw new G;return s.issues.length?Qr(e,s.issues,o):{success:!0,data:s.value}};function Qr(e,t,r){let n;return{success:!1,get error(){if(!n)n=new e(t.map((o)=>ee(o,r,F()))),t=void 0,r=void 0;return n},set error(o){n=o,t=void 0,r=void 0}}}var Xe=(e)=>async(t,r,n)=>{let o=n?{...n,async:!0}:{async:!0},s=t._zod.run({value:r,issues:[]},o);if(s instanceof Promise)s=await s;return s.issues.length?Qr(e,s.issues,o):{success:!0,data:s.value}};var Yc=Symbol.for("zod.compile.invalid"),qc=Symbol.for("zod.compile.fallback"),Dt=(e,t,r)=>{let n=e._zod.bag.validator;if(n!==void 0){if(n(t)!==Yc)return!0;if(n.definite===!0&&r===void 0)return!1}return Qc(e,t,r)};function Qc(e,t,r){let n=r?{...r,async:!1,abortEarly:!0}:{async:!1,abortEarly:!0},o=e._zod.bag.fallbackRun,s;if(o)n[qc]=!0,s=o({value:t,issues:[]},n);else s=e._zod.run({value:t,issues:[]},n);if(s instanceof Promise)throw new G;return s.issues.length===0}var jt=async(e,t,r)=>{let n=r?{...r,async:!0,abortEarly:!0}:{async:!0,abortEarly:!0},o=e._zod.run({value:t,issues:[]},n);if(o instanceof Promise)o=await o;return o.issues.length===0},en=(e)=>{let t=Ge(e),r=(n,o,s,i)=>{let c=s?{...s,direction:"backward"}:{direction:"backward"};return t(n,o,c,Ve(r,i))};return r};var tn=(e)=>{let t=Ge(e),r=(n,o,s,i)=>t(n,o,s,Ve(r,i));return r};var rn=(e)=>{let t=We(e),r=async(n,o,s,i)=>{let c=s?{...s,direction:"backward"}:{direction:"backward"};return await t(n,o,c,Ve(r,i))};return r};var nn=(e)=>{let t=We(e),r=async(n,o,s,i)=>await t(n,o,s,Ve(r,i));return r};var on=(e)=>(t,r,n)=>{let o=n?{...n,direction:"backward"}:{direction:"backward"};return He(e)(t,r,o)};var sn=(e)=>(t,r,n)=>He(e)(t,r,n);var cn=(e)=>async(t,r,n)=>{let o=n?{...n,direction:"backward"}:{direction:"backward"};return Xe(e)(t,r,o)};var un=(e)=>async(t,r,n)=>Xe(e)(t,r,n);var an=/^[cC][0-9a-z]{6,}$/,ln=/^[0-9a-z]+$/,pn=/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,fn=/^[0-9a-vA-V]{20}$/,dn=/^[A-Za-z0-9]{27}$/,mn=/^[a-zA-Z0-9_-]{21}$/;function hn(e){return new RegExp(`^[a-zA-Z0-9_-]{${e}}$`)}var gn=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;var _n=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,Ft=(e)=>{if(!e)return/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`)};var yn=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;var eu="^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$";function bn(){return new RegExp(eu,"u")}var xn=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,vn=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;var $n=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,wn=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,zn=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Sn=/^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/;var kn=/^https?$/,Pn=/^\+[1-9]\d{6,14}$/;var Zn="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))";function tu(e){return new RegExp(`^${e}$`)}var On=tu(Zn);function Lt(e){return typeof e.precision==="number"?e.precision===-1?"(?:[01]\\d|2[0-3]):[0-5]\\d":e.precision===0?"(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d":`(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d\\.\\d{${e.precision}}`:e.seconds?"(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?":"(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?"}function In(e){return new RegExp(`^${Lt(e)}$`)}function En(e){let t=["Z"];if(e.offset)t.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");let r=`${Lt({precision:e.precision,seconds:!0})}(?:${t.join("|")})`,n=e.local?`${r}|${Lt({precision:e.precision})}`:r;return new RegExp(`^${Zn}T(?:${n})$`)}var An=/^[\s\S]{0,}$/;var Mt=/^-?\d+(?:\.\d+)?$/,Tn=/^(?:true|false)$/i;var Nn=/^[^A-Z]*$/,Cn=/^[^a-z]*$/;var A=p("$ZodCheck",(e,t)=>{var r;e._zod??(e._zod={}),e._zod.def=t,(r=e._zod).onattach??(r.onattach=[])});var Ut=(e)=>{let t=e.value;return!Ir(t)&&t.length!==void 0},Ye={number:"number",bigint:"bigint",object:"date"},Bt=p("$ZodCheckLessThan",(e,t)=>{A.init(e,t);let r=Ye[typeof t.value];e._zod.check=(n)=>{if(t.inclusive?n.value<=t.value:n.value<t.value)return;n.issues.push({origin:Ye[typeof n.value]??r,code:"too_big",maximum:typeof t.value==="object"?t.value.getTime():t.value,input:n.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Jt=p("$ZodCheckGreaterThan",(e,t)=>{A.init(e,t);let r=Ye[typeof t.value];e._zod.check=(n)=>{if(t.inclusive?n.value>=t.value:n.value>t.value)return;n.issues.push({origin:Ye[typeof n.value]??r,code:"too_small",minimum:typeof t.value==="object"?t.value.getTime():t.value,input:n.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Rn=p("$ZodCheckMultipleOf",(e,t)=>{A.init(e,t),e._zod.check=(r)=>{if(typeof r.value!==typeof t.value)throw Error("Cannot mix number and bigint in multiple_of check.");if(typeof r.value==="bigint"?t.value!==BigInt(0)&&r.value%t.value===BigInt(0):Er(r.value,t.value)===0)return;r.issues.push({origin:typeof r.value,code:"not_multiple_of",divisor:t.value,input:r.value,inst:e,continue:!t.abort})}}),Dn=p("$ZodCheckNumberFormat",(e,t)=>{A.init(e,t),t.format=t.format||"float64";let r=t.format?.includes("int"),n=r?"int":"number",[o,s]=Fe[t.format];e._zod.check=(i)=>{let c=i.value;if(r){if(!Number.isInteger(c)){i.issues.push({expected:n,format:t.format,code:"invalid_type",continue:!1,input:c,inst:e});return}if(!Number.isSafeInteger(c)){if(c>0)i.issues.push({input:c,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:n,inclusive:!0,continue:!t.abort});else i.issues.push({input:c,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:n,inclusive:!0,continue:!t.abort});return}}if(c<o)i.issues.push({origin:"number",input:c,code:"too_small",minimum:o,inclusive:!0,inst:e,continue:!t.abort});if(c>s)i.issues.push({origin:"number",input:c,code:"too_big",maximum:s,inclusive:!0,inst:e,continue:!t.abort})}});var jn=p("$ZodCheckMaxLength",(e,t)=>{var r;A.init(e,t),(r=e._zod.def).when??(r.when=Ut),e._zod.check=(n)=>{let o=n.value,s=o.length;if((typeof o==="string"&&s>t.maximum?Be(o):s)<=t.maximum)return;let c=Je(o);n.issues.push({origin:c,code:"too_big",maximum:t.maximum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),Ln=p("$ZodCheckMinLength",(e,t)=>{var r;A.init(e,t),(r=e._zod.def).when??(r.when=Ut),e._zod.check=(n)=>{let o=n.value,s=o.length;if((typeof o==="string"&&s>=t.minimum&&s<t.minimum*2?Be(o):s)>=t.minimum)return;let c=Je(o);n.issues.push({origin:c,code:"too_small",minimum:t.minimum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),Fn=p("$ZodCheckLengthEquals",(e,t)=>{var r;A.init(e,t),(r=e._zod.def).when??(r.when=Ut),e._zod.check=(n)=>{let o=n.value,s=o.length,i=typeof o==="string"&&s>=t.length&&s<=t.length*2?Be(o):s;if(i===t.length)return;let c=Je(o),u=i>t.length;n.issues.push({origin:c,...u?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),we=p("$ZodCheckStringFormat",(e,t)=>{var r,n;if(A.init(e,t),t.pattern)(r=e._zod).check??(r.check=(o)=>{if(t.pattern.lastIndex=0,t.pattern.test(o.value))return;o.issues.push({origin:"string",code:"invalid_format",format:t.format,input:o.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})});else(n=e._zod).check??(n.check=()=>{})}),Mn=p("$ZodCheckRegex",(e,t)=>{we.init(e,t),e._zod.check=(r)=>{if(t.pattern.lastIndex=0,t.pattern.test(r.value))return;r.issues.push({origin:"string",code:"invalid_format",format:"regex",input:r.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),Un=p("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=Nn),we.init(e,t)}),Bn=p("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=Cn),we.init(e,t)}),Jn=p("$ZodCheckIncludes",(e,t)=>{A.init(e,t);let r=Q(t.includes),n=new RegExp(typeof t.position==="number"?`^.{${t.position},}${r}`:r);t.pattern=n,e._zod.check=(o)=>{if(o.value.includes(t.includes,t.position))return;o.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:o.value,inst:e,continue:!t.abort})}}),Kn=p("$ZodCheckStartsWith",(e,t)=>{A.init(e,t);let r=new RegExp(`^${Q(t.prefix)}.*`);t.pattern??(t.pattern=r),e._zod.check=(n)=>{if(n.value.startsWith(t.prefix))return;n.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),Vn=p("$ZodCheckEndsWith",(e,t)=>{A.init(e,t);let r=new RegExp(`.*${Q(t.suffix)}$`);t.pattern??(t.pattern=r),e._zod.check=(n)=>{if(n.value.endsWith(t.suffix))return;n.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}});var Gn=p("$ZodCheckOverwrite",(e,t)=>{A.init(e,t),e._zod.check=(r)=>{r.value=t.tx(r.value)}});class Kt{constructor(e=[],t={}){this.content=[],this.indent=0,this.args=e,this.closed=t}indented(e){this.indent+=1;try{e(this)}finally{this.indent-=1}}write(e){if(typeof e==="function"){e(this,{execution:"sync"}),e(this,{execution:"async"});return}let r=e.split(`
|
|
6
6
|
`).filter((s)=>s),n=Math.min(...r.map((s)=>s.length-s.trimStart().length)),o=r.map((s)=>s.slice(n)).map((s)=>" ".repeat(this.indent*2)+s);for(let s of o)this.content.push(s)}compile(){let e=Function,t=this?.content??[""];return new e(...Object.keys(this.closed),`return function (${this.args.join(", ")}) {
|
|
7
7
|
${t.join(`
|
|
8
8
|
`)}
|
|
@@ -74,14 +74,14 @@ ${i(g)}
|
|
|
74
74
|
Story data, part ${g} of ${y}. The readable summary is in the first story comment.
|
|
75
75
|
|
|
76
76
|
${i(m)}
|
|
77
|
-
`,a=(m)=>Math.floor((t-m)*Ce/(Ce+1))-Ce,l=a(vt(u("",999,999)));if(l<Ce)throw Error(`max_bytes ${t} is too small for a story comment`);let f=rl({text:ec({story:e}),max_bytes:Math.floor(t/2)}),d=Math.max(a(vt(c(f,"",999))),0),h=[o.slice(0,d)];for(let m=d;m<o.length;m+=l)h.push(o.slice(m,m+l));return h.map((m,g)=>g===0?c(f,m,h.length):u(m,g+1,h.length))},nc=({bodies:e})=>{let t=e.flatMap((n)=>{let o=rc.exec(n);if(!o)return[];let[,s,i,c,u,a]=o;return[{version:Number(s),part:Number(i),total:Number(c),head_sha:u??"",sha256:a??"",data:(el.exec(n)?.[1]??"").replace(/\s/g,"")}]});if(t.length===0)return{status:"none"};let r=[...new Set(t.map(({sha256:n})=>n))].toReversed();for(let n of r){let o=t.filter((u)=>u.sha256===n),s=o[0]?.total??0,i=Array.from({length:s},(u,a)=>o.find(({part:l})=>l===a+1));if(i.some((u)=>u===void 0))continue;let c=zr.from(i.map((u)=>u?.data??"").join(""),"base64").toString("utf8");if(tc("sha256").update(c).digest("hex")!==n)continue;try{return fe({value:JSON.parse(c)})}catch{continue}}return{status:"broken",reason:"the story comments are incomplete or were edited; run /luca-pr-prep again"}},oc=({existing:e,bodies:t})=>{let r=e.filter(({body:s})=>nl({body:s})).toSorted((s,i)=>s.comment_id-i.comment_id),n=t.flatMap((s,i)=>{let c=r[i];if(c===void 0)return[{action:"create",body:s}];if(c.body===s)return[];return[{action:"update",comment_id:c.comment_id,body:s}]}),o=r.slice(t.length).map(({comment_id:s})=>({action:"delete",comment_id:s}));return[...n,...o]};var ie="review-ready",ol="Has an up-to-date review story (/luca-pr-prep)",sl=j(j(P({id:T().int(),body:Z().nullable()}))),il=P({headRefOid:Z(),state:Z(),labels:j(P({name:Z()}))}),wt=({what:e,stderr:t})=>{throw Error(`${e}: ${t.trim()||"gh failed"}`)},de=async({gh:e,repo:t,pr_number:r})=>{let n=await e({args:["pr","view",String(r),"--repo",t,"--json","headRefOid,state,labels"]});if(!n.ok)wt({what:`reading PR #${r}`,stderr:n.stderr});let o=il.parse(JSON.parse(n.stdout));return{head_sha:o.headRefOid,state:o.state,labels:o.labels.map(({name:s})=>s)}},sc=async({gh:e,repo:t,pr_number:r})=>{let n=await e({args:["api",`repos/${t}/issues/${r}/comments?per_page=100`,"--paginate","--slurp"]});if(!n.ok)wt({what:`reading the comments of #${r}`,stderr:n.stderr});return sl.parse(JSON.parse(n.stdout)).flat().map(({id:o,body:s})=>({comment_id:o,body:s??""}))},ic=async({gh:e,repo:t,pr_number:r})=>nc({bodies:(await sc({gh:e,repo:t,pr_number:r})).map(({body:n})=>n)}),cc=async({gh:e,story:t})=>{let{repo:r,pr_number:n}=t,o=oc({existing:await sc({gh:e,repo:r,pr_number:n}),bodies:$t({story:t})});for(let i of o){let c=i.action==="delete"?await e({args:["api","-X","DELETE",`repos/${r}/issues/comments/${i.comment_id}`]}):await e({args:i.action==="update"?["api","-X","PATCH",`repos/${r}/issues/comments/${i.comment_id}`,"--input","-"]:["api","-X","POST",`repos/${r}/issues/${n}/comments`,"--input","-"],input:JSON.stringify({body:i.body})});if(!c.ok)wt({what:`${i.action} of a story comment`,stderr:c.stderr})}let s=(i)=>o.filter((c)=>c.action===i).length;return{updated:s("update"),created:s("create"),deleted:s("delete")}},uc=async({gh:e,repo:t,pr_number:r})=>{let n=()=>e({args:["pr","edit",String(r),"--repo",t,"--add-label",ie]});if((await n()).ok)return;await e({args:["label","create",ie,"--repo",t,"--description",ol,"--color","0E8A16"]});let o=await n();if(!o.ok)wt({what:`adding the ${ie} label`,stderr:o.stderr})},ac=async({gh:e,repo:t,pr_number:r})=>{await e({args:["api","-X","DELETE",`repos/${t}/issues/${r}/labels/${ie}`]})},
|
|
78
|
-
`),await
|
|
79
|
-
`)){if(n>0){if(!o.startsWith("\\"))n-=1;continue}if(o.startsWith("diff --git "))r=null;else if(o.startsWith("--- a/"))r={gone:!1,hunks:[]},t.set(o.slice(6).replace(/\t$/,""),r);else if(o==="+++ /dev/null"&&r!==null)r.gone=!0;else if(r!==null){let s=
|
|
80
|
-
`),u(JSON.stringify({status:"shifted",from:d,to:f,lines_moved:g.lines_moved,notes:g.notes})),a(`Wrote ${i}: ${g.lines_moved} line numbers moved, ${g.notes.length} notes.`),g.notes.length>0)a("Each note is something the new commits edited. Rewrite, find again, or recount every one before you save.");return 0};var
|
|
77
|
+
`,a=(m)=>Math.floor((t-m)*Ce/(Ce+1))-Ce,l=a(vt(u("",999,999)));if(l<Ce)throw Error(`max_bytes ${t} is too small for a story comment`);let f=rl({text:ec({story:e}),max_bytes:Math.floor(t/2)}),d=Math.max(a(vt(c(f,"",999))),0),h=[o.slice(0,d)];for(let m=d;m<o.length;m+=l)h.push(o.slice(m,m+l));return h.map((m,g)=>g===0?c(f,m,h.length):u(m,g+1,h.length))},nc=({bodies:e})=>{let t=e.flatMap((n)=>{let o=rc.exec(n);if(!o)return[];let[,s,i,c,u,a]=o;return[{version:Number(s),part:Number(i),total:Number(c),head_sha:u??"",sha256:a??"",data:(el.exec(n)?.[1]??"").replace(/\s/g,"")}]});if(t.length===0)return{status:"none"};let r=[...new Set(t.map(({sha256:n})=>n))].toReversed();for(let n of r){let o=t.filter((u)=>u.sha256===n),s=o[0]?.total??0,i=Array.from({length:s},(u,a)=>o.find(({part:l})=>l===a+1));if(i.some((u)=>u===void 0))continue;let c=zr.from(i.map((u)=>u?.data??"").join(""),"base64").toString("utf8");if(tc("sha256").update(c).digest("hex")!==n)continue;try{return fe({value:JSON.parse(c)})}catch{continue}}return{status:"broken",reason:"the story comments are incomplete or were edited; run /luca-pr-prep again"}},oc=({existing:e,bodies:t})=>{let r=e.filter(({body:s})=>nl({body:s})).toSorted((s,i)=>s.comment_id-i.comment_id),n=t.flatMap((s,i)=>{let c=r[i];if(c===void 0)return[{action:"create",body:s}];if(c.body===s)return[];return[{action:"update",comment_id:c.comment_id,body:s}]}),o=r.slice(t.length).map(({comment_id:s})=>({action:"delete",comment_id:s}));return[...n,...o]};var ie="review-ready",ol="Has an up-to-date review story (/luca-pr-prep)",sl=j(j(P({id:T().int(),body:Z().nullable()}))),il=P({headRefOid:Z(),state:Z(),labels:j(P({name:Z()}))}),wt=({what:e,stderr:t})=>{throw Error(`${e}: ${t.trim()||"gh failed"}`)},de=async({gh:e,repo:t,pr_number:r})=>{let n=await e({args:["pr","view",String(r),"--repo",t,"--json","headRefOid,state,labels"]});if(!n.ok)wt({what:`reading PR #${r}`,stderr:n.stderr});let o=il.parse(JSON.parse(n.stdout));return{head_sha:o.headRefOid,state:o.state,labels:o.labels.map(({name:s})=>s)}},sc=async({gh:e,repo:t,pr_number:r})=>{let n=await e({args:["api",`repos/${t}/issues/${r}/comments?per_page=100`,"--paginate","--slurp"]});if(!n.ok)wt({what:`reading the comments of #${r}`,stderr:n.stderr});return sl.parse(JSON.parse(n.stdout)).flat().map(({id:o,body:s})=>({comment_id:o,body:s??""}))},ic=async({gh:e,repo:t,pr_number:r})=>nc({bodies:(await sc({gh:e,repo:t,pr_number:r})).map(({body:n})=>n)}),cc=async({gh:e,story:t})=>{let{repo:r,pr_number:n}=t,o=oc({existing:await sc({gh:e,repo:r,pr_number:n}),bodies:$t({story:t})});for(let i of o){let c=i.action==="delete"?await e({args:["api","-X","DELETE",`repos/${r}/issues/comments/${i.comment_id}`]}):await e({args:i.action==="update"?["api","-X","PATCH",`repos/${r}/issues/comments/${i.comment_id}`,"--input","-"]:["api","-X","POST",`repos/${r}/issues/${n}/comments`,"--input","-"],input:JSON.stringify({body:i.body})});if(!c.ok)wt({what:`${i.action} of a story comment`,stderr:c.stderr})}let s=(i)=>o.filter((c)=>c.action===i).length;return{updated:s("update"),created:s("create"),deleted:s("delete")}},uc=async({gh:e,repo:t,pr_number:r})=>{let n=()=>e({args:["pr","edit",String(r),"--repo",t,"--add-label",ie]});if((await n()).ok)return;await e({args:["label","create",ie,"--repo",t,"--description",ol,"--color","0E8A16"]});let o=await n();if(!o.ok)wt({what:`adding the ${ie} label`,stderr:o.stderr})},ac=async({gh:e,repo:t,pr_number:r})=>{await e({args:["api","-X","DELETE",`repos/${t}/issues/${r}/labels/${ie}`]})},cl=({repo:e,login:t})=>{let r=e.split("/")[0]??"";return t!==null&&t!==""&&r.toLowerCase()===t.toLowerCase()},me=async({gh:e,repo:t})=>{let r=await e({args:["api","user","--jq",".login"]}),n=r.stdout.trim();if(!r.ok||n==="")return{home:"private",why:"gh could not say who is signed in"};return cl({repo:t,login:n})?{home:"shared",why:`${t} belongs to ${n}`}:{home:"private",why:`${t} does not belong to ${n}`}};import{mkdir as ul,readFile as lc,rename as al,rm as ll,writeFile as pl}from"fs/promises";import{dirname as fl,join as pc}from"path";var zt=({home:e,env:t})=>t.LUCA_STORIES_DIR||pc(e,".local","state","luca","stories"),dl=/^([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)$/,Re=({stories_dir:e,repo:t,pr_number:r})=>{let[,n,o]=dl.exec(t)??[];if(!n||!o||n.startsWith(".")||o.startsWith("."))throw Error(`"${t}" is not an owner/name repo`);return pc(e,n,o,`pr-${r}.json`)},fc=async({stories_dir:e,story:t})=>{let r=Re({stories_dir:e,repo:t.repo,pr_number:t.pr_number});return await ul(fl(r),{recursive:!0}),await pl(`${r}.tmp`,`${JSON.stringify(t,null,2)}
|
|
78
|
+
`),await al(`${r}.tmp`,r),r},dc=async({stories_dir:e,repo:t,pr_number:r})=>{let n=Re({stories_dir:e,repo:t,pr_number:r}),o;try{o=await lc(n,"utf8")}catch{return{status:"none"}}try{return fe({value:JSON.parse(o)})}catch{return{status:"invalid",problems:[`${n} is not JSON`]}}},mc=async({stories_dir:e,repo:t,pr_number:r})=>{let n=Re({stories_dir:e,repo:t,pr_number:r});try{await lc(n)}catch{return!1}return await ll(n,{force:!0}),!0};var hc=({home:e,found:t})=>({home:e,found:t,head_sha:t.status==="ok"?t.story.head_sha:null}),ml=({copies:e,pr_head_sha:t,default_home:r})=>{let[n,o]=e;if(n===void 0)return{used:null,other:null};if(o===void 0)return{used:n,other:null};let s=(i)=>(i.head_sha===t?4:0)+(i.found.status==="ok"?2:0)+(i.home===r?1:0);return s(n)>=s(o)?{used:n,other:o}:{used:o,other:n}},Sr=async({gh:e,stories_dir:t,repo:r,pr_number:n})=>{let o=await dc({stories_dir:t,repo:r,pr_number:n}),s;try{s=await ic({gh:e,repo:r,pr_number:n})}catch(l){if(o.status==="none")throw l;s={status:"none"}}let i=[hc({home:"private",found:o}),hc({home:"shared",found:s})].filter(({found:l})=>l.status!=="none"),c=i.length===2,{used:u,other:a}=ml({copies:i,pr_head_sha:c?(await de({gh:e,repo:r,pr_number:n})).head_sha:"",default_home:c?(await me({gh:e,repo:r})).home:"private"});if(u===null)return{found:{status:"none"},home:null,other_copy:null};return{found:u.found,home:u.home,other_copy:a===null?null:{home:a.home,status:a.found.status,story_head_sha:a.head_sha}}};var gc=async({gh:e,story:t,stories_dir:r,home:n})=>{let{repo:o,pr_number:s}=t;if((n??(await me({gh:e,repo:o})).home)==="private")return await fc({stories_dir:r,story:t}),{status:"saved",home:"private",comments:0,updated:0,created:0,deleted:0,removed_private:!1};let c=await de({gh:e,repo:o,pr_number:s});if(c.head_sha!==t.head_sha)return{status:"head_moved",story_head_sha:t.head_sha,pr_head_sha:c.head_sha};let u=await cc({gh:e,story:t});await uc({gh:e,repo:o,pr_number:s});let a=await mc({stories_dir:r,repo:o,pr_number:s});return{status:"saved",home:"shared",comments:$t({story:t}).length,...u,removed_private:a}};import{writeFile as yl}from"fs/promises";var hl=/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/,yc=({diff:e})=>{let t=new Map,r=null,n=0;for(let o of e.split(`
|
|
79
|
+
`)){if(n>0){if(!o.startsWith("\\"))n-=1;continue}if(o.startsWith("diff --git "))r=null;else if(o.startsWith("--- a/"))r={gone:!1,hunks:[]},t.set(o.slice(6).replace(/\t$/,""),r);else if(o==="+++ /dev/null"&&r!==null)r.gone=!0;else if(r!==null){let s=hl.exec(o);if(s===null)continue;let i=Number(s[2]??1),c=Number(s[4]??1);r.hunks.push({old_start:Number(s[1]),old_count:i,new_start:Number(s[3]),new_count:c}),n=i+c}}return t},gl=({old_start:e,old_count:t,new_start:r,new_count:n})=>({old_after:t>0?e+t:e+1,new_after:n>0?r+n:r+1}),_c=({line:e,hunks:t})=>{let r=0;for(let n of t){let{old_after:o,new_after:s}=gl(n);if(n.old_count>0&&e>=n.old_start&&e<o)return{line:e,touched:!0};if(e<o)break;r=s-o}return{line:e+r,touched:!1}},_l=({start:e,end:t,hunks:r})=>r.some(({old_start:n,old_count:o})=>o>0?n<=t&&n+o-1>=e:n>=e&&n<t),bc=({story:e,files:t,new_head_sha:r})=>{let n=[],o=0,s=({item:a,change_id:l,where:f})=>{let d=t.get(a.path);if(d===void 0)return a;let h={change_id:l,where:f,path:a.path,line:a.line};if(d.gone)return n.push({kind:"ref_file_gone",...h}),a;if(a.line===null)return a;let m=_c({line:a.line,hunks:d.hunks});if(m.touched)return n.push({kind:"ref_touched",...h}),a;if(m.line!==a.line)o+=1;return{...a,line:m.line}},i=({list:a,change_id:l})=>a.map((f)=>s({item:f,change_id:l,where:l===null?"summary_flag":"flag"})),c=(a)=>{let{start_line:l,end_line:f}=a,d=t.get(a.path);if(d===void 0||a.side==="base")return{start_line:l,end_line:f};let h={change_id:a.id,where:"range",path:a.path,line:l};if(d.gone)return n.push({kind:"change_file_gone",...h}),{start_line:l,end_line:f};if(_l({start:l,end:f,hunks:d.hunks}))return n.push({kind:"change_touched",...h}),{start_line:l,end_line:f};let m=_c({line:l,hunks:d.hunks}).line;if(m!==l)o+=1;return{start_line:m,end_line:f+m-l}},u=(a)=>({...a,...c(a),proof:{...a.proof,tests:a.proof.tests.map((l)=>s({item:l,change_id:a.id,where:"proof"}))},blast_radius:{...a.blast_radius,dependents:a.blast_radius.dependents.map((l)=>s({item:l,change_id:a.id,where:"blast_radius"}))},flags:i({list:a.flags,change_id:a.id})});return{story:{...e,head_sha:r,summary:{...e.summary,flags:i({list:e.summary.flags,change_id:null})},stops:e.stops.map((a)=>({...a,changes:a.changes.map(u)}))},lines_moved:o,notes:n}},xc=({story:e})=>{let t=e.stops.flatMap((r)=>r.changes);return[...new Set([...e.summary.flags.map(({path:r})=>r),...t.flatMap((r)=>[r.path,...r.proof.tests.map(({path:n})=>n),...r.blast_radius.dependents.map(({path:n})=>n),...r.flags.map(({path:n})=>n)])])].toSorted()};var vc=({args:e,flag:t})=>{let r=e.indexOf(t);return r===-1?void 0:e[r+1]},$c=async({cli:e,story:t,path:r,new_head_sha:n,args:o})=>{let s=vc({args:o,flag:"--repo-dir"})??".",i=vc({args:o,flag:"--out"})??r,{git:c,out:u,err:a}=e,l=await c({args:["rev-parse","--verify","--quiet",`${n}^{commit}`],cwd:s});if(!l.ok)return a(`Commit ${n} is not in the repo at ${s}. Fetch it first, or pass --repo-dir.`),2;let f=l.stdout.trim(),d=t.head_sha;if(f===d)return u(JSON.stringify({status:"unchanged",from:d,to:f,lines_moved:0,notes:[]})),0;if(!(await c({args:["merge-base","--is-ancestor",d,f],cwd:s})).ok)return a(`The story's commit ${d.slice(0,9)} is not an ancestor of ${f.slice(0,9)} (a force-push or rebase, or it was never fetched). Write a new story.`),1;let m=await c({args:["-c","core.quotePath=false","diff","--unified=0","--no-color","--no-renames","--no-ext-diff",d,f,"--",...xc({story:t})],cwd:s});if(!m.ok)return a(`git diff failed: ${m.stderr.trim()}`),2;let g=bc({story:t,files:yc({diff:m.stdout}),new_head_sha:f});if(await yl(i,`${JSON.stringify(g.story,null,2)}
|
|
80
|
+
`),u(JSON.stringify({status:"shifted",from:d,to:f,lines_moved:g.lines_moved,notes:g.notes})),a(`Wrote ${i}: ${g.lines_moved} line numbers moved, ${g.notes.length} notes.`),g.notes.length>0)a("Each note is something the new commits edited. Rewrite, find again, or recount every one before you save.");return 0};var vl=`Usage:
|
|
81
81
|
bun pr-story.js check <story.json>
|
|
82
82
|
bun pr-story.js home <owner/repo> [--shared | --private]
|
|
83
83
|
bun pr-story.js save <story.json> [--shared | --private]
|
|
84
84
|
bun pr-story.js load <owner/repo> <pr number> [--out <file>]
|
|
85
85
|
bun pr-story.js status <owner/repo> <pr number>
|
|
86
|
-
bun pr-story.js shift <story.json> <new head sha> [--out <file>] [--repo-dir <dir>]`,wc=({flags:e})=>{if(e.includes("--shared"))return"shared";if(e.includes("--private"))return"private";return null},kr=async({path:e,err:t})=>{let r;try{r=JSON.parse(await
|
|
87
|
-
`,c=t.indexOf("--out"),u=c===-1?void 0:t[c+1];if(u===void 0)e.out(i);else await
|
|
86
|
+
bun pr-story.js shift <story.json> <new head sha> [--out <file>] [--repo-dir <dir>]`,wc=({flags:e})=>{if(e.includes("--shared"))return"shared";if(e.includes("--private"))return"private";return null},kr=async({path:e,err:t})=>{let r;try{r=JSON.parse(await bl(e,"utf8"))}catch(o){return t(`${e} can't be read as JSON: ${String(o)}`),null}let n=fe({value:r});if(n.status==="ok")return n.story;if(n.status==="newer_version")return t(`${e} is schema_version ${n.schema_version}; this helper writes version ${xt}. Run \`luca upgrade\`.`),null;t(`${e} is not a valid story (${n.problems.length} problems):`);for(let o of n.problems)t(`- ${o}`);return null},zc=({other_copy:e})=>`A second copy in the ${e.home} home was not used (${e.story_head_sha===null?e.status:`written for ${e.story_head_sha.slice(0,9)}`}).`,$l=async({cli:e,args:t})=>{let[r,...n]=t;if(r===void 0)return ce({cli:e});let o=await kr({path:r,err:e.err});if(o===null)return 1;let s=zt(e),i=await gc({gh:e.gh,story:o,stories_dir:s,home:wc({flags:n})??void 0});if(i.status==="head_moved")return e.err(`Not posted: the story is for ${i.story_head_sha.slice(0,9)} but the PR's head is now ${i.pr_head_sha.slice(0,9)}. Bring the story up to date first.`),1;if(i.home==="private"){let c=Re({stories_dir:s,repo:o.repo,pr_number:o.pr_number});return e.out(`Saved privately: ${c}. Nothing was posted.`),0}if(e.out(`Posted on ${o.pr_url}: ${i.updated} comments updated, ${i.created} created, ${i.deleted} deleted. Label ${ie} added.`),i.removed_private)e.out("Removed the private copy on this computer, so it cannot hide the posted story.");return 0},Sc=({args:e})=>{let[t,r]=e,n=Number(r);if(t===void 0||!Number.isInteger(n)||n<1)return null;return{repo:t,pr_number:n}},wl=async({cli:e,args:t})=>{let r=Sc({args:t});if(r===null)return ce({cli:e});let{found:n,home:o,other_copy:s}=await Sr({gh:e.gh,stories_dir:zt(e),...r});if(n.status!=="ok")return e.err(`No usable story for ${r.repo}#${r.pr_number}: ${n.status}.`),1;let i=`${JSON.stringify(n.story,null,2)}
|
|
87
|
+
`,c=t.indexOf("--out"),u=c===-1?void 0:t[c+1];if(u===void 0)e.out(i);else await xl(u,i);if(e.err(`Found in the ${o} home, written for ${n.story.head_sha}.`),s!==null)e.err(zc({other_copy:s}));return 0},zl=async({cli:e,args:t})=>{let r=Sc({args:t});if(r===null)return ce({cli:e});let{found:n,home:o,other_copy:s}=await Sr({gh:e.gh,stories_dir:zt(e),...r}),i=await de({gh:e.gh,...r}),c=n.status==="ok"?n.story.head_sha:null,u=n.status==="none"?"none":n.status!=="ok"?"broken":c===i.head_sha?"fresh":"stale";if(u!=="fresh"&&i.labels.includes(ie))await ac({gh:e.gh,...r});if(e.out(JSON.stringify({status:u,home:o,story_head_sha:c,pr_head_sha:i.head_sha,other_copy:s})),s!==null)e.err(zc({other_copy:s}));return 0},ce=({cli:e})=>(e.err(vl),2),kc=async(e)=>{let[t,...r]=e.argv;try{if(t==="check"){let[n]=r;if(n===void 0)return ce({cli:e});let o=await kr({path:n,err:e.err});if(o===null)return 1;return e.out(`Valid story: ${o.stops.length} stops, schema_version ${o.schema_version}.`),0}if(t==="home"){let[n,...o]=r;if(n===void 0)return ce({cli:e});let s=wc({flags:o}),i=s===null?await me({gh:e.gh,repo:n}):{home:s,why:"forced by the flag"};return e.out(`${i.home} (${i.why})`),0}if(t==="save")return await $l({cli:e,args:r});if(t==="load")return await wl({cli:e,args:r});if(t==="status")return await zl({cli:e,args:r});if(t==="shift"){let[n,o]=r;if(n===void 0||o===void 0)return ce({cli:e});let s=await kr({path:n,err:e.err});if(s===null)return 1;return await $c({cli:e,story:s,path:n,new_head_sha:o,args:r})}return ce({cli:e})}catch(n){return e.err(n instanceof Error?n.message:String(n)),2}};var kl=async({args:e,input:t})=>{try{let r=Bun.spawn(["gh",...e],{stdin:t===void 0?"ignore":new Blob([t]),stdout:"pipe",stderr:"pipe"}),[n,o,s]=await Promise.all([new Response(r.stdout).text(),new Response(r.stderr).text(),r.exited]);return{ok:s===0,stdout:n,stderr:o}}catch(r){return{ok:!1,stdout:"",stderr:`gh could not run: ${String(r)}`}}},Pl=async({args:e,cwd:t})=>{try{let r=Bun.spawn(["git",...e],{cwd:t,stdin:"ignore",stdout:"pipe",stderr:"pipe"}),[n,o,s]=await Promise.all([new Response(r.stdout).text(),new Response(r.stderr).text(),r.exited]);return{ok:s===0,stdout:n,stderr:o}}catch(r){return{ok:!1,stdout:"",stderr:`git could not run: ${String(r)}`}}};process.exit(await kc({argv:process.argv.slice(2),gh:kl,git:Pl,home:Sl(),env:process.env,out:(e)=>console.log(e),err:(e)=>console.error(e)}));
|