@aventurevc/aventure-cli 0.7.287 → 0.7.291

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.
@@ -1,4 +1,4 @@
1
- import{C as e,D as t,_ as n,a as r,k as i,v as a,x as o}from"./person-owner-ChqQWHII.js";import{$ as s,A as c,C as l,E as u,H as d,I as f,J as p,K as m,M as h,N as g,O as _,Q as ee,R as te,S as ne,St as v,T as re,X as ie,Y as ae,Z as oe,_ as se,b as ce,c as le,f as ue,g as de,h as fe,i as pe,j as me,k as y,l as b,m as he,n as ge,nt as x,o as _e,p as ve,q as ye,r as be,rt as S,s as xe,t as Se,tt as Ce,u as we,v as Te,w as Ee}from"./auth-DwEBWElF.js";import{A as De,C as Oe,D as ke,E as Ae,F as C,I as je,M as Me,N as Ne,O as Pe,P as Fe,S as Ie,T as Le,_ as Re,a as ze,b as Be,c as Ve,d as He,f as Ue,g as We,h as Ge,j as Ke,k as qe,l as Je,m as Ye,n as Xe,o as w,p as Ze,r as T,s as Qe,t as E,u as $e,v as et,w as tt,x as nt,y as rt}from"./openapi-commands-BuISX687.js";import{F as it,a as at,f as ot,i as st,l as ct,m as lt,n as ut,ot as dt,p as ft,r as pt,s as mt,st as ht,t as gt}from"./mcp-generation-contract-l6riM4GC.js";import{execFile as _t,spawnSync as vt}from"node:child_process";import{createHash as yt,randomBytes as bt,timingSafeEqual as xt,webcrypto as St}from"node:crypto";import{readFile as Ct}from"node:fs/promises";import{homedir as wt,hostname as Tt,platform as Et}from"node:os";import{basename as Dt,dirname as D,join as O,resolve as k,sep as Ot}from"node:path";import A,{stderr as j,stdin as kt}from"node:process";import{appendFileSync as At,copyFileSync as jt,existsSync as M,lstatSync as Mt,mkdirSync as Nt,mkdtempSync as Pt,readFileSync as N,readlinkSync as Ft,realpathSync as It,renameSync as Lt,rmSync as Rt,rmdirSync as zt,unlinkSync as Bt,writeFileSync as P}from"node:fs";import{fileURLToPath as Vt}from"node:url";import{once as Ht}from"node:events";import{TextDecoder as Ut,inspect as Wt}from"node:util";import{createServer as Gt}from"node:http";import{setTimeout as Kt}from"node:timers/promises";import{createInterface as qt}from"node:readline/promises";function Jt(e,t,n){let r={...n};for(let n of t.parameter){let t=n.envName;if(t===void 0)continue;let i=process.env[t]?.trim();if(i===void 0||i.length===0)continue;let a=r[n.optionKey];if(a!==void 0&&(typeof a!=`string`||a!==i))return{...x(`${e} ${n.flag.split(` `)[0]??n.name} conflicts with ${t}; omit the flag or use ${i}.`),data:r};a===void 0&&(r[n.optionKey]=i)}return S(`Environment-bound options applied`,r)}function Yt(e,t,n){if(!F(n))return null;for(let r of t.parameter){let t=r.envName,i=t===void 0?void 0:process.env[t]?.trim();if(t===void 0||i===void 0||i.length===0||!un(n,r.name))continue;let a=ln(n,r.name);if(typeof a!=`string`||a!==i)return`${e} ${r.name} in --from-file conflicts with ${t}; omit the field or use ${i}.`}return null}function Xt(e){let t=new Set(e.parameter.map(({name:e})=>e));return e.kind===`multipart`?e.requiredPath:e.requiredPath.filter(e=>!t.has(e))}function Zt(e,t,n,r=!1){if(r||!pn(t)||!Array.isArray(n))return hn(e,t,n);for(let[r,i]of n.entries()){let n=hn(e,t,i,r);if(!n.ok)return n}return S(`Body value assigned`,null)}function Qt(e,t,n,r){return hn(e,t,r,n)}function $t(e){let t=[];for(let n of e.split(`.`)){let e=_n(n);if(t.push(e.key),e.isArray)return t.join(`.`)}return null}function en(e,t){let n=$t(t);if(n===null)return null;let r=cn(e,n.split(`.`));return Array.isArray(r)?{path:n,rowCount:r.length,firstHole:sn(r)}:null}function tn(e,t){if(pn(e.name)||e.schemaType===`array`)return S(`Repeated body option selected`,typeof t==`string`?[t]:t);if(!Array.isArray(t))return S(`Scalar body option selected`,t);let n=e.flag.split(` `)[0]??e.name;return t.length===1?S(`Scalar body option selected`,t[0]):x(`${n} was already given; pass it once.`)}var nn=/^(?<row>\d+):(?<item>.*)$/su;function rn(e,t){let n=$t(e.name);if(e.schemaType!==`array`||n===null||t===void 0||typeof t==`boolean`)return null;let r=new Map,i=[];for(let e of typeof t==`string`?[t]:t){let t=nn.exec(e)?.groups,n=t?.row,a=t?.item;if(n===void 0||a===void 0){i.push(e);continue}let o=r.get(Number(n));o===void 0?r.set(Number(n),[a]):o.push(a)}return r.size===0?null:{container:n,rows:r,plain:i}}function an(e,t,n){let r=0;for(let i of e.parameter){let e=t[i.optionKey];e!==void 0&&typeof e!=`boolean`&&$t(i.name)===n&&(r=Math.max(r,typeof e==`string`?1:e.length))}return r}function on(e,t,n,r){for(let i of t.parameter){let t=n[i.optionKey];if(t===void 0)continue;let a=en(r,i.name);if(a===null)continue;if(a.firstHole!==null)return x(`${e} has no ${a.path}[] row ${a.firstHole} — number ${a.path}[] rows from 0 with no gaps.`);if(i.schemaType!==`array`||a.rowCount<=1||rn(i,t)!==null)continue;let o=i.flag.split(` `)[0]??i.name;return x(`${o} fills one ${a.path}[] row's list, so ${e} cannot also build ${a.rowCount} ${a.path}[] rows from direct options — prefix each value with its 0-based ${a.path}[] row index, as 0:value, or pass the rows with --from-file.`)}return null}function sn(e){for(let t=0;t<e.length;t+=1)if(e[t]===void 0)return t;return null}function cn(e,t){let n=e;for(let e of t){if(!F(n))return;n=n[e]??null}return n}function ln(e,t){if(!pn(t))return cn(e,t.split(`.`))}function un(e,t){return fn(e,t.split(`.`))}function dn(e,t,n){if(!F(n))return null;let r=new Set(t.parameter.map(({name:e})=>e));for(let i of e)if(i!==t){for(let e of i.parameter)if(!r.has(e.name)&&un(n,e.name))return`${e.name} in --from-file requires --content-type ${i.contentType}.`}return null}function fn(e,t){let[n,...r]=t;if(n===void 0)return!0;let i=_n(n);if(!F(e)||!Object.hasOwn(e,i.key))return!1;let a=e[i.key]??null;return i.isArray?Array.isArray(a)&&a.every(e=>fn(e,r)):fn(a,r)}function pn(e){return e.split(`.`).some(e=>_n(e).isArray)}function mn(e,t){return e.parameter.length===0||!F(t)?null:yn(t,[],vn(e.parameter))}function F(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function hn(e,t,n,r=0){let i=t.split(`.`),a=e;for(let[e,o]of i.entries()){let s=_n(o),c=e===i.length-1,l=gn(a,s,t,c,n,r);if(!l.ok||l.data===null)return x(l.summary,l.warnings);if(c)return S(`Body value assigned`,null);a=l.data}return x(`${t} is not a valid body option path.`)}function gn(e,t,n,r,i,a){let o=()=>x(`${n} cannot be combined with another body option at ${t.key}.`),s=e[t.key];if(t.isArray){if(s!==void 0&&!Array.isArray(s))return o();let n=s??[];if(s===void 0&&(e[t.key]=n),r)return n[a]===void 0?(n[a]=i,S(`Body value assigned`,e)):o();let c=n[a];if(c===void 0){let e={};return n[a]=e,S(`Body path created`,e)}return F(c)?S(`Body path stepped`,c):o()}if(r)return s===void 0?(e[t.key]=i,S(`Body value assigned`,e)):o();if(s===void 0){let n={};return e[t.key]=n,S(`Body path created`,n)}return F(s)?S(`Body path stepped`,s):o()}function _n(e){let t=e.endsWith(`[]`);return{key:t?e.slice(0,-2):e,isArray:t}}function vn(e){let t=new Set,n=new Set,r=new Map;for(let i of e){let e=`${i.name}${i.schemaType===`array`?`[]`:``}`;t.add(e),r.set(e,i.flag.split(` `)[0]??i.name);let a=e.split(`.`);for(let e=1;e<a.length;e+=1)n.add(a.slice(0,e).join(`.`))}return{leaf:t,prefix:n,flagByLeaf:r}}function yn(e,t,n){if(Array.isArray(e)){if(e.length===0)return null;for(let r of e){let e=yn(r,t,n);if(e!==null)return e}return null}if(!F(e))return null;for(let[r,i]of Object.entries(e)){let e=[...t,Array.isArray(i)?`${r}[]`:r],a=e.join(`.`);if(!bn(a,n)){if(!xn(e))continue;return{path:a,suggestion:Sn(e,n)}}let o=yn(i,e,n);if(o!==null)return o}return null}function bn(e,t){return t.prefix.has(e)||t.leaf.has(e)}function xn(e){return e.slice(0,-1).some(e=>e.endsWith(`[]`))}function Sn(e,t){let n=e.slice(0,-1).join(`.`),r=e.at(-1)?.replace(/\[\]$/u,``).toLowerCase()??``,[i]=[...t.leaf].filter(e=>e.split(`.`).slice(0,-1).join(`.`)===n).map(e=>({path:e,score:Cn(r,e.split(`.`).at(-1)??``)})).filter(({score:e})=>e<1/0).toSorted((e,t)=>e.score-t.score||e.path.localeCompare(t.path));if(i!==void 0)return{path:i.path,flag:t.flagByLeaf.get(i.path)??i.path}}function Cn(e,t){let n=t.replace(/\[\]$/u,``).toLowerCase();return n===e?0:n.endsWith(e)||e.endsWith(n)?1:n.includes(e)||e.includes(n)?2:1/0}function wn(e,t){let n=new Map;for(let e of t){let t=e.flag?.split(` `)[0];t!==void 0&&n.set(t,t===`--from-file`?{...e,inputType:`file`}:e)}for(let t of e){let e=t.long===void 0?void 0:n.get(t.long);e!==void 0&&t.helpGroup(Ze(e))}e.sort((e,t)=>{let r=e.long===void 0?void 0:n.get(e.long),i=t.long===void 0?void 0:n.get(t.long);return r!==void 0&&i!==void 0?Mn(r,i):r===void 0?i===void 0?0:1:-1})}function Tn(e){let t=new Map;for(let n of e)for(let e of n.parameter){let r=e.flag.split(` `)[0]??e.flag,i=t.get(r);i===void 0?t.set(r,{variant:[{descriptor:n,parameter:e}]}):t.set(r,{variant:[...i.variant,{descriptor:n,parameter:e}]})}return[...t.values()]}function En(e){let{flag:t}=e.variant[0].parameter;return e.variant.every(({parameter:e})=>e.flag===t)?t:`${t.split(` `)[0]??t} <value>`}function Dn(e){let t=e.variant.map(({descriptor:e,parameter:t})=>({contentType:e.contentType,text:An(e,t)})),n=t[0];return n===void 0?``:t.every(({text:e})=>e===n.text)?`${n.text===``?``:`${n.text} `}Request content: ${t.map(({contentType:e})=>e).join(`, `)}.`:t.map(({contentType:e,text:t})=>`${e}: ${t}`).join(` `)}function On(e,t){return[...new Set((e.cliConflicts??[]).filter(e=>e.includes(t)).flatMap(e=>e.filter(e=>e!==t)))]}function kn(e,t){let n=e.kind===`multipart`?`Read a JSON object keyed by multipart part name from a file, or use - for stdin`:`Read the JSON request body from a file, or use - for stdin`,r=t.filter(e=>!t.some(t=>t.startsWith(`${e}.`)||t.startsWith(`${e}[].`)));return r.length===0?Ye(n):`${Ye(n)} Required JSON paths: ${r.join(`, `)}.`}function An(e,t){return`${He(t.description,void 0)}${e.kind!==`multipart`&&pn(t.name)?` Repeat to add another value.`:``}${jn(e,t)}`}function jn(e,t){if(e.kind===`multipart`||t.schemaType!==`array`)return``;let n=$t(t.name);return n===null?``:` Prefix each value with its 0-based ${n}[] row index, as 0:value, to fill more than one ${n}[] row. A leading digits-and-colon is always read as that index, so name the row of a value that starts the same way, as 0:0:00 for the value 0:00.`}function Mn(e,t){return Ue(e)-Ue(t)||Number(e.required!==!0)-Number(t.required!==!0)}async function Nn(e){let t;try{t=e===`-`?await Pn():await Ct(e,`utf8`)}catch(t){return x(`Could not read input: ${t.message}`,[`path=${e}`])}try{if(t.trim().length===0)return S(`No input provided`,null);let e=JSON.parse(t);return S(`Input parsed`,e)}catch(e){return x(`Input is not valid JSON: ${e.message}`)}}async function Pn(){if(process.stdin.isTTY)throw Error(`--from-file - requires JSON on stdin, but stdin is a TTY`);process.stdin.setEncoding(`utf8`);let e=``;for await(let t of process.stdin)e+=t;return e}var Fn=`--content-type`;function In(e,t){let n=t.requestBody??[];if(n.length>1){let t=n.map(({contentType:e})=>e);e.addOption(new u(`${Fn} <media-type>`,`Select the request content type; omit for ${t[0]}.`).choices(t).argParser(Rn(n)))}if(rr(t)){let r=n[0];if(r===void 0)throw Error(`${t.operationId} has no request body`);e.addOption(new u(`--from-file <path>`,kn(r,r.requiredPath)).argParser(Bn(`--from-file`)))}let r=Tn(n);for(let t of r.toSorted((e,t)=>Mn(e.variant[0].parameter,t.variant[0].parameter))){let{descriptor:r,parameter:i}=t.variant[0],a=new u(En(t),n.length>1?Dn(t):An(r,i));n.length===1&&i.envName!==void 0&&a.env(i.envName);let o=n.length===1?On(r,i.optionKey):[];o.length>0&&a.conflicts(o),n.length>1?a.argParser(Ln):pn(i.name)||i.schemaType===`array`?a.argParser(zn):a.argParser(Bn(i.flag)),e.addOption(a)}nr(e,t,r)}function Ln(e,t){return t===void 0?e:typeof t==`string`?[t,e]:[...t,e]}function Rn(e){return(t,n)=>{if(n!==void 0)throw new _(`${Fn} was already given; pass it once.`);let r=Ee(e,t);if(!r.ok)throw new _(r.summary);return t}}function zn(e,t){return[...t??[],e]}function Bn(e){let t=e.split(/\s+/u)[0]??e;return(e,n)=>{if(n!==void 0)throw new _(`${t} was already given; pass it once.`);return e}}async function Vn(e,t){let n=typeof t.contentType==`string`?t.contentType:void 0,r=Ee(e.requestBody??[],n);if(!r.ok||r.data===null)return x(r.summary,r.warnings);let i=r.data;if(i===void 0)return S(`No body`,void 0);let a=Hn(e,i,t);if(a!==null)return x(a);let o=Jt(e.operationId,i,t);if(!o.ok)return x(o.summary,o.warnings);t=o.data;let s=Un(i,t);if(s!==null)return x(s);let c=await qn(t);if(!c.ok)return x(c.summary,c.warnings);let l=dn(e.requestBody??[],i,c.data);if(l!==null)return x(l);let u=Kn(e.operationId,i,c.data);if(!u.ok)return u;let d=Yt(e.operationId,i,c.data);if(d!==null)return x(d);let f=Jn(e.operationId,i,t);if(!f.ok)return f;if(c.data===void 0&&f.data===void 0)return i.required?x(tr(e.operationId,i)):S(`No body`,void 0);let p=Xn(e.operationId,c.data,f.data);if(!p.ok||p.data===void 0)return p;if(i.schemaType===`array`&&!Array.isArray(p.data))return x(`${e.operationId} requires a JSON array body.`);if(i.parameter.length>0&&!F(p.data)){let t=i.kind===`multipart`?` keyed by multipart part name`:` body`;return x(`${e.operationId} requires a JSON object${t}.`)}let m=Gn(i,p.data);if(m.length>0)return x(`${e.operationId} requires body option(s): ${m.join(`, `)}`);let h=p.data,g=F(h)?Xt(i).filter(e=>!un(h,e)):[];return g.length>0?x(Wn(e.operationId,i,g)):p}function Hn(e,t,n){let r=new Set(t.parameter.map(({optionKey:e})=>e));for(let i of e.requestBody??[])if(i!==t)for(let t of i.parameter){if(r.has(t.optionKey)||n[t.optionKey]===void 0)continue;let i=(e.requestBody??[]).filter(e=>e.parameter.some(({optionKey:e})=>e===t.optionKey)).map(({contentType:e})=>e);return`${I(t)} requires ${Fn} ${i.join(` or `)}.`}return null}function Un(e,t){for(let n of e.cliConflicts??[]){let e=n.filter(e=>t[e]!==void 0);if(e.length>1)return`Options ${e.join(`, `)} cannot be used together.`}return null}function Wn(e,t,n){let r=`${e} requires JSON body path(s): ${n.join(`, `)}`;return t.kind===`multipart`?`${r}. ${n.includes(`body`)?`For multipart --from-file, wrap the endpoint JSON under top-level "body".`:`For multipart --from-file, put the missing nested path(s) inside top-level "body".`}`:r}function Gn(e,t){return F(t)?e.parameter.filter(e=>e.required&&!un(t,e.name)).map(I):[]}function Kn(e,t,n){let r=mn(t,n);if(r===null)return S(`Body file paths validated`,null);let i=r.suggestion===void 0?``:` Use ${r.suggestion.path} (${r.suggestion.flag}).`;return x(`${e} --from-file contains unknown JSON path ${r.path}.${i}`)}async function qn(e){let t=typeof e.fromFile==`string`?e.fromFile:void 0;if(t===void 0)return S(`No body file`,void 0);let n=await Nn(t);if(!n.ok)return x(n.summary,n.warnings);let r=v.safeParse(n.data);return r.success?S(`Input parsed`,r.data):x(`Input is not valid JSON value: ${r.error.message}`)}function Jn(e,t,n){let r={},i=!1;for(let e of t.parameter){let a=tn(e,n[e.optionKey]);if(!a.ok||a.data===null)return x(a.summary,a.warnings);let o=a.data;if(o===void 0)continue;let s=Yn(t,n,r,e,o);if(!s.ok)return x(s.summary,s.warnings);i=!0}if(!i)return S(`No direct body options`,void 0);let a=on(e,t,n,r);return a===null?S(`Direct body options parsed`,r):a}function Yn(e,t,n,r,i){let a=rn(r,i);if(a===null){let e=$n(r,i);return e.ok?Zt(n,r.name,e.data,r.schemaType===`array`):x(e.summary,e.warnings)}if(a.plain.length>0)return x(`${I(r)} mixes row-form values with plain value(s): ${a.plain.join(`, `)} — prefix every value with its 0-based ${a.container}[] row index, as 0:value.`);let o=an(e,t,a.container);for(let e of a.rows.keys())if(!(e<o))return x(`${I(r)} names ${a.container}[] row ${e}, but these options build at most ${o} ${a.container}[] row(s) — number rows from 0, and name the row of a value that itself starts with digits and a colon, as 0:0:00 for the value 0:00.`);for(let[e,t]of a.rows){let i=[];for(let e of t){let t=er(r.name,r.itemSchemaType,e);if(!t.ok)return x(t.summary,t.warnings);i.push(t.data)}let a=Qt(n,r.name,e,i);if(!a.ok)return a}return S(`Body value assigned`,null)}function I(e){return e.flag.split(` `)[0]??e.name}function Xn(e,t,n){if(t===void 0)return S(`Direct body parsed`,n);if(n===void 0)return S(`Input parsed`,t);if(F(t)&&F(n))try{return S(`Input parsed`,Zn(t,n))}catch(t){return x(`${e} ${t.message}`)}return x(`${e} cannot combine --from-file with direct body options unless the file body is an object.`)}function Zn(e,t){let n={...e};for(let[e,r]of Object.entries(t)){let t=n[e];if(Array.isArray(t)&&Array.isArray(r))throw Error(`cannot combine --from-file array '${e}' with array body options at the same key — move the per-item fields inside the matching '${e}[]' object(s) in the file body.`);if(t!==void 0&&Qn(t)!==Qn(r))throw Error(`cannot combine --from-file ${Qn(t)} '${e}' with ${Qn(r)} body option(s) at the same key — align the file body shape with the schema.`);n[e]=F(t)&&F(r)?Zn(t,r):r}return n}function Qn(e){return Array.isArray(e)?`array`:F(e)?`object`:`scalar`}function $n(e,t){if(typeof t==`boolean`)return S(`Body value parsed`,t);if(t===void 0||typeof t==`string`)return er(e.name,e.schemaType,t??``);let n=[],r=pn(e.name)&&e.schemaType!==`array`?e.schemaType:e.itemSchemaType;for(let i of t){let t=er(e.name,r,i);if(!t.ok)return t;n.push(t.data)}return S(`Body value parsed`,n)}function er(e,t,n){if(t===`boolean`)return n===`true`?S(`Body value parsed`,!0):n===`false`?S(`Body value parsed`,!1):x(`${e} must be true or false.`);if(t===`number`||t===`integer`){let r=n.trim(),i=Number(r);return r===``||!Number.isFinite(i)?x(`${e} must be a finite ${t}.`):t===`integer`&&!Number.isInteger(i)?x(`${e} must be an integer.`):S(`Body value parsed`,i)}return S(`Body value parsed`,n)}function tr(e,t){let n=t.parameter.filter(e=>e.required);if(n.length>0&&t.requiredPath.every(e=>n.some(({name:t})=>t===e||t.startsWith(`${e}.`))))return`${e} requires body option(s): ${n.map(I).join(`, `)}`;let r=Xt(t);if(r.length>0)return`${e} requires --from-file with JSON body path(s): ${r.join(`, `)}`;let i=t.parameter.map(I).join(`, `);return i.length===0?`${e} requires --from-file`:`${e} requires --from-file or body option(s): ${i}`}function nr(e,t,n){let r=[...t.parameters,...n.map(({variant:e})=>e[0].parameter)];(t.requestBody?.length??0)>1&&r.push({optionKey:`contentType`,flag:Fn,location:`body`}),rr(t)&&r.push({optionKey:`fromFile`,flag:`--from-file`,location:`body`}),wn(e.options,r)}function rr(e){return(e.requestBody??[]).some(e=>e.kind!==`multipart`||e.parameter.some(e=>e.schemaFormat!==`binary`))}function ir(e){let t=Ce(e);return dr(t),process.stdout.write(`${JSON.stringify(t)}\n`),t}function ar(e){dr(e);let t=ut(e.data,e.summary);if(e.ok&&t!==null){process.stdout.write(t.endsWith(`
1
+ import{C as e,D as t,_ as n,a as r,k as i,v as a,x as o}from"./person-owner-ChqQWHII.js";import{$ as s,A as c,C as l,E as u,H as d,I as f,J as p,K as m,M as h,N as g,O as _,Q as ee,R as te,S as ne,St as v,T as re,X as ie,Y as ae,Z as oe,_ as se,b as ce,c as le,f as ue,g as de,h as fe,i as pe,j as me,k as y,l as b,m as he,n as ge,nt as x,o as _e,p as ve,q as ye,r as be,rt as S,s as xe,t as Se,tt as Ce,u as we,v as Te,w as Ee}from"./auth-Bk3u31Il.js";import{A as De,C as Oe,D as ke,E as Ae,F as C,I as je,M as Me,N as Ne,O as Pe,P as Fe,S as Ie,T as Le,_ as Re,a as ze,b as Be,c as Ve,d as He,f as Ue,g as We,h as Ge,j as Ke,k as qe,l as Je,m as Ye,n as Xe,o as w,p as Ze,r as T,s as Qe,t as E,u as $e,v as et,w as tt,x as nt,y as rt}from"./openapi-commands-DBmDBPwP.js";import{F as it,a as at,f as ot,i as st,l as ct,m as lt,n as ut,ot as dt,p as ft,r as pt,s as mt,st as ht,t as gt}from"./mcp-generation-contract-BkeXGnQG.js";import{execFile as _t,spawnSync as vt}from"node:child_process";import{createHash as yt,randomBytes as bt,timingSafeEqual as xt,webcrypto as St}from"node:crypto";import{readFile as Ct}from"node:fs/promises";import{homedir as wt,hostname as Tt,platform as Et}from"node:os";import{basename as Dt,dirname as D,join as O,resolve as k,sep as Ot}from"node:path";import A,{stderr as j,stdin as kt}from"node:process";import{appendFileSync as At,copyFileSync as jt,existsSync as M,lstatSync as Mt,mkdirSync as Nt,mkdtempSync as Pt,readFileSync as N,readlinkSync as Ft,realpathSync as It,renameSync as Lt,rmSync as Rt,rmdirSync as zt,unlinkSync as Bt,writeFileSync as P}from"node:fs";import{fileURLToPath as Vt}from"node:url";import{once as Ht}from"node:events";import{TextDecoder as Ut,inspect as Wt}from"node:util";import{createServer as Gt}from"node:http";import{setTimeout as Kt}from"node:timers/promises";import{createInterface as qt}from"node:readline/promises";function Jt(e,t,n){let r={...n};for(let n of t.parameter){let t=n.envName;if(t===void 0)continue;let i=process.env[t]?.trim();if(i===void 0||i.length===0)continue;let a=r[n.optionKey];if(a!==void 0&&(typeof a!=`string`||a!==i))return{...x(`${e} ${n.flag.split(` `)[0]??n.name} conflicts with ${t}; omit the flag or use ${i}.`),data:r};a===void 0&&(r[n.optionKey]=i)}return S(`Environment-bound options applied`,r)}function Yt(e,t,n){if(!F(n))return null;for(let r of t.parameter){let t=r.envName,i=t===void 0?void 0:process.env[t]?.trim();if(t===void 0||i===void 0||i.length===0||!un(n,r.name))continue;let a=ln(n,r.name);if(typeof a!=`string`||a!==i)return`${e} ${r.name} in --from-file conflicts with ${t}; omit the field or use ${i}.`}return null}function Xt(e){let t=new Set(e.parameter.map(({name:e})=>e));return e.kind===`multipart`?e.requiredPath:e.requiredPath.filter(e=>!t.has(e))}function Zt(e,t,n,r=!1){if(r||!pn(t)||!Array.isArray(n))return hn(e,t,n);for(let[r,i]of n.entries()){let n=hn(e,t,i,r);if(!n.ok)return n}return S(`Body value assigned`,null)}function Qt(e,t,n,r){return hn(e,t,r,n)}function $t(e){let t=[];for(let n of e.split(`.`)){let e=_n(n);if(t.push(e.key),e.isArray)return t.join(`.`)}return null}function en(e,t){let n=$t(t);if(n===null)return null;let r=cn(e,n.split(`.`));return Array.isArray(r)?{path:n,rowCount:r.length,firstHole:sn(r)}:null}function tn(e,t){if(pn(e.name)||e.schemaType===`array`)return S(`Repeated body option selected`,typeof t==`string`?[t]:t);if(!Array.isArray(t))return S(`Scalar body option selected`,t);let n=e.flag.split(` `)[0]??e.name;return t.length===1?S(`Scalar body option selected`,t[0]):x(`${n} was already given; pass it once.`)}var nn=/^(?<row>\d+):(?<item>.*)$/su;function rn(e,t){let n=$t(e.name);if(e.schemaType!==`array`||n===null||t===void 0||typeof t==`boolean`)return null;let r=new Map,i=[];for(let e of typeof t==`string`?[t]:t){let t=nn.exec(e)?.groups,n=t?.row,a=t?.item;if(n===void 0||a===void 0){i.push(e);continue}let o=r.get(Number(n));o===void 0?r.set(Number(n),[a]):o.push(a)}return r.size===0?null:{container:n,rows:r,plain:i}}function an(e,t,n){let r=0;for(let i of e.parameter){let e=t[i.optionKey];e!==void 0&&typeof e!=`boolean`&&$t(i.name)===n&&(r=Math.max(r,typeof e==`string`?1:e.length))}return r}function on(e,t,n,r){for(let i of t.parameter){let t=n[i.optionKey];if(t===void 0)continue;let a=en(r,i.name);if(a===null)continue;if(a.firstHole!==null)return x(`${e} has no ${a.path}[] row ${a.firstHole} — number ${a.path}[] rows from 0 with no gaps.`);if(i.schemaType!==`array`||a.rowCount<=1||rn(i,t)!==null)continue;let o=i.flag.split(` `)[0]??i.name;return x(`${o} fills one ${a.path}[] row's list, so ${e} cannot also build ${a.rowCount} ${a.path}[] rows from direct options — prefix each value with its 0-based ${a.path}[] row index, as 0:value, or pass the rows with --from-file.`)}return null}function sn(e){for(let t=0;t<e.length;t+=1)if(e[t]===void 0)return t;return null}function cn(e,t){let n=e;for(let e of t){if(!F(n))return;n=n[e]??null}return n}function ln(e,t){if(!pn(t))return cn(e,t.split(`.`))}function un(e,t){return fn(e,t.split(`.`))}function dn(e,t,n){if(!F(n))return null;let r=new Set(t.parameter.map(({name:e})=>e));for(let i of e)if(i!==t){for(let e of i.parameter)if(!r.has(e.name)&&un(n,e.name))return`${e.name} in --from-file requires --content-type ${i.contentType}.`}return null}function fn(e,t){let[n,...r]=t;if(n===void 0)return!0;let i=_n(n);if(!F(e)||!Object.hasOwn(e,i.key))return!1;let a=e[i.key]??null;return i.isArray?Array.isArray(a)&&a.every(e=>fn(e,r)):fn(a,r)}function pn(e){return e.split(`.`).some(e=>_n(e).isArray)}function mn(e,t){return e.parameter.length===0||!F(t)?null:yn(t,[],vn(e.parameter))}function F(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function hn(e,t,n,r=0){let i=t.split(`.`),a=e;for(let[e,o]of i.entries()){let s=_n(o),c=e===i.length-1,l=gn(a,s,t,c,n,r);if(!l.ok||l.data===null)return x(l.summary,l.warnings);if(c)return S(`Body value assigned`,null);a=l.data}return x(`${t} is not a valid body option path.`)}function gn(e,t,n,r,i,a){let o=()=>x(`${n} cannot be combined with another body option at ${t.key}.`),s=e[t.key];if(t.isArray){if(s!==void 0&&!Array.isArray(s))return o();let n=s??[];if(s===void 0&&(e[t.key]=n),r)return n[a]===void 0?(n[a]=i,S(`Body value assigned`,e)):o();let c=n[a];if(c===void 0){let e={};return n[a]=e,S(`Body path created`,e)}return F(c)?S(`Body path stepped`,c):o()}if(r)return s===void 0?(e[t.key]=i,S(`Body value assigned`,e)):o();if(s===void 0){let n={};return e[t.key]=n,S(`Body path created`,n)}return F(s)?S(`Body path stepped`,s):o()}function _n(e){let t=e.endsWith(`[]`);return{key:t?e.slice(0,-2):e,isArray:t}}function vn(e){let t=new Set,n=new Set,r=new Map;for(let i of e){let e=`${i.name}${i.schemaType===`array`?`[]`:``}`;t.add(e),r.set(e,i.flag.split(` `)[0]??i.name);let a=e.split(`.`);for(let e=1;e<a.length;e+=1)n.add(a.slice(0,e).join(`.`))}return{leaf:t,prefix:n,flagByLeaf:r}}function yn(e,t,n){if(Array.isArray(e)){if(e.length===0)return null;for(let r of e){let e=yn(r,t,n);if(e!==null)return e}return null}if(!F(e))return null;for(let[r,i]of Object.entries(e)){let e=[...t,Array.isArray(i)?`${r}[]`:r],a=e.join(`.`);if(!bn(a,n)){if(!xn(e))continue;return{path:a,suggestion:Sn(e,n)}}let o=yn(i,e,n);if(o!==null)return o}return null}function bn(e,t){return t.prefix.has(e)||t.leaf.has(e)}function xn(e){return e.slice(0,-1).some(e=>e.endsWith(`[]`))}function Sn(e,t){let n=e.slice(0,-1).join(`.`),r=e.at(-1)?.replace(/\[\]$/u,``).toLowerCase()??``,[i]=[...t.leaf].filter(e=>e.split(`.`).slice(0,-1).join(`.`)===n).map(e=>({path:e,score:Cn(r,e.split(`.`).at(-1)??``)})).filter(({score:e})=>e<1/0).toSorted((e,t)=>e.score-t.score||e.path.localeCompare(t.path));if(i!==void 0)return{path:i.path,flag:t.flagByLeaf.get(i.path)??i.path}}function Cn(e,t){let n=t.replace(/\[\]$/u,``).toLowerCase();return n===e?0:n.endsWith(e)||e.endsWith(n)?1:n.includes(e)||e.includes(n)?2:1/0}function wn(e,t){let n=new Map;for(let e of t){let t=e.flag?.split(` `)[0];t!==void 0&&n.set(t,t===`--from-file`?{...e,inputType:`file`}:e)}for(let t of e){let e=t.long===void 0?void 0:n.get(t.long);e!==void 0&&t.helpGroup(Ze(e))}e.sort((e,t)=>{let r=e.long===void 0?void 0:n.get(e.long),i=t.long===void 0?void 0:n.get(t.long);return r!==void 0&&i!==void 0?Mn(r,i):r===void 0?i===void 0?0:1:-1})}function Tn(e){let t=new Map;for(let n of e)for(let e of n.parameter){let r=e.flag.split(` `)[0]??e.flag,i=t.get(r);i===void 0?t.set(r,{variant:[{descriptor:n,parameter:e}]}):t.set(r,{variant:[...i.variant,{descriptor:n,parameter:e}]})}return[...t.values()]}function En(e){let{flag:t}=e.variant[0].parameter;return e.variant.every(({parameter:e})=>e.flag===t)?t:`${t.split(` `)[0]??t} <value>`}function Dn(e){let t=e.variant.map(({descriptor:e,parameter:t})=>({contentType:e.contentType,text:An(e,t)})),n=t[0];return n===void 0?``:t.every(({text:e})=>e===n.text)?`${n.text===``?``:`${n.text} `}Request content: ${t.map(({contentType:e})=>e).join(`, `)}.`:t.map(({contentType:e,text:t})=>`${e}: ${t}`).join(` `)}function On(e,t){return[...new Set((e.cliConflicts??[]).filter(e=>e.includes(t)).flatMap(e=>e.filter(e=>e!==t)))]}function kn(e,t){let n=e.kind===`multipart`?`Read a JSON object keyed by multipart part name from a file, or use - for stdin`:`Read the JSON request body from a file, or use - for stdin`,r=t.filter(e=>!t.some(t=>t.startsWith(`${e}.`)||t.startsWith(`${e}[].`)));return r.length===0?Ye(n):`${Ye(n)} Required JSON paths: ${r.join(`, `)}.`}function An(e,t){return`${He(t.description,void 0)}${e.kind!==`multipart`&&pn(t.name)?` Repeat to add another value.`:``}${jn(e,t)}`}function jn(e,t){if(e.kind===`multipart`||t.schemaType!==`array`)return``;let n=$t(t.name);return n===null?``:` Prefix each value with its 0-based ${n}[] row index, as 0:value, to fill more than one ${n}[] row. A leading digits-and-colon is always read as that index, so name the row of a value that starts the same way, as 0:0:00 for the value 0:00.`}function Mn(e,t){return Ue(e)-Ue(t)||Number(e.required!==!0)-Number(t.required!==!0)}async function Nn(e){let t;try{t=e===`-`?await Pn():await Ct(e,`utf8`)}catch(t){return x(`Could not read input: ${t.message}`,[`path=${e}`])}try{if(t.trim().length===0)return S(`No input provided`,null);let e=JSON.parse(t);return S(`Input parsed`,e)}catch(e){return x(`Input is not valid JSON: ${e.message}`)}}async function Pn(){if(process.stdin.isTTY)throw Error(`--from-file - requires JSON on stdin, but stdin is a TTY`);process.stdin.setEncoding(`utf8`);let e=``;for await(let t of process.stdin)e+=t;return e}var Fn=`--content-type`;function In(e,t){let n=t.requestBody??[];if(n.length>1){let t=n.map(({contentType:e})=>e);e.addOption(new u(`${Fn} <media-type>`,`Select the request content type; omit for ${t[0]}.`).choices(t).argParser(Rn(n)))}if(rr(t)){let r=n[0];if(r===void 0)throw Error(`${t.operationId} has no request body`);e.addOption(new u(`--from-file <path>`,kn(r,r.requiredPath)).argParser(Bn(`--from-file`)))}let r=Tn(n);for(let t of r.toSorted((e,t)=>Mn(e.variant[0].parameter,t.variant[0].parameter))){let{descriptor:r,parameter:i}=t.variant[0],a=new u(En(t),n.length>1?Dn(t):An(r,i));n.length===1&&i.envName!==void 0&&a.env(i.envName);let o=n.length===1?On(r,i.optionKey):[];o.length>0&&a.conflicts(o),n.length>1?a.argParser(Ln):pn(i.name)||i.schemaType===`array`?a.argParser(zn):a.argParser(Bn(i.flag)),e.addOption(a)}nr(e,t,r)}function Ln(e,t){return t===void 0?e:typeof t==`string`?[t,e]:[...t,e]}function Rn(e){return(t,n)=>{if(n!==void 0)throw new _(`${Fn} was already given; pass it once.`);let r=Ee(e,t);if(!r.ok)throw new _(r.summary);return t}}function zn(e,t){return[...t??[],e]}function Bn(e){let t=e.split(/\s+/u)[0]??e;return(e,n)=>{if(n!==void 0)throw new _(`${t} was already given; pass it once.`);return e}}async function Vn(e,t){let n=typeof t.contentType==`string`?t.contentType:void 0,r=Ee(e.requestBody??[],n);if(!r.ok||r.data===null)return x(r.summary,r.warnings);let i=r.data;if(i===void 0)return S(`No body`,void 0);let a=Hn(e,i,t);if(a!==null)return x(a);let o=Jt(e.operationId,i,t);if(!o.ok)return x(o.summary,o.warnings);t=o.data;let s=Un(i,t);if(s!==null)return x(s);let c=await qn(t);if(!c.ok)return x(c.summary,c.warnings);let l=dn(e.requestBody??[],i,c.data);if(l!==null)return x(l);let u=Kn(e.operationId,i,c.data);if(!u.ok)return u;let d=Yt(e.operationId,i,c.data);if(d!==null)return x(d);let f=Jn(e.operationId,i,t);if(!f.ok)return f;if(c.data===void 0&&f.data===void 0)return i.required?x(tr(e.operationId,i)):S(`No body`,void 0);let p=Xn(e.operationId,c.data,f.data);if(!p.ok||p.data===void 0)return p;if(i.schemaType===`array`&&!Array.isArray(p.data))return x(`${e.operationId} requires a JSON array body.`);if(i.parameter.length>0&&!F(p.data)){let t=i.kind===`multipart`?` keyed by multipart part name`:` body`;return x(`${e.operationId} requires a JSON object${t}.`)}let m=Gn(i,p.data);if(m.length>0)return x(`${e.operationId} requires body option(s): ${m.join(`, `)}`);let h=p.data,g=F(h)?Xt(i).filter(e=>!un(h,e)):[];return g.length>0?x(Wn(e.operationId,i,g)):p}function Hn(e,t,n){let r=new Set(t.parameter.map(({optionKey:e})=>e));for(let i of e.requestBody??[])if(i!==t)for(let t of i.parameter){if(r.has(t.optionKey)||n[t.optionKey]===void 0)continue;let i=(e.requestBody??[]).filter(e=>e.parameter.some(({optionKey:e})=>e===t.optionKey)).map(({contentType:e})=>e);return`${I(t)} requires ${Fn} ${i.join(` or `)}.`}return null}function Un(e,t){for(let n of e.cliConflicts??[]){let e=n.filter(e=>t[e]!==void 0);if(e.length>1)return`Options ${e.join(`, `)} cannot be used together.`}return null}function Wn(e,t,n){let r=`${e} requires JSON body path(s): ${n.join(`, `)}`;return t.kind===`multipart`?`${r}. ${n.includes(`body`)?`For multipart --from-file, wrap the endpoint JSON under top-level "body".`:`For multipart --from-file, put the missing nested path(s) inside top-level "body".`}`:r}function Gn(e,t){return F(t)?e.parameter.filter(e=>e.required&&!un(t,e.name)).map(I):[]}function Kn(e,t,n){let r=mn(t,n);if(r===null)return S(`Body file paths validated`,null);let i=r.suggestion===void 0?``:` Use ${r.suggestion.path} (${r.suggestion.flag}).`;return x(`${e} --from-file contains unknown JSON path ${r.path}.${i}`)}async function qn(e){let t=typeof e.fromFile==`string`?e.fromFile:void 0;if(t===void 0)return S(`No body file`,void 0);let n=await Nn(t);if(!n.ok)return x(n.summary,n.warnings);let r=v.safeParse(n.data);return r.success?S(`Input parsed`,r.data):x(`Input is not valid JSON value: ${r.error.message}`)}function Jn(e,t,n){let r={},i=!1;for(let e of t.parameter){let a=tn(e,n[e.optionKey]);if(!a.ok||a.data===null)return x(a.summary,a.warnings);let o=a.data;if(o===void 0)continue;let s=Yn(t,n,r,e,o);if(!s.ok)return x(s.summary,s.warnings);i=!0}if(!i)return S(`No direct body options`,void 0);let a=on(e,t,n,r);return a===null?S(`Direct body options parsed`,r):a}function Yn(e,t,n,r,i){let a=rn(r,i);if(a===null){let e=$n(r,i);return e.ok?Zt(n,r.name,e.data,r.schemaType===`array`):x(e.summary,e.warnings)}if(a.plain.length>0)return x(`${I(r)} mixes row-form values with plain value(s): ${a.plain.join(`, `)} — prefix every value with its 0-based ${a.container}[] row index, as 0:value.`);let o=an(e,t,a.container);for(let e of a.rows.keys())if(!(e<o))return x(`${I(r)} names ${a.container}[] row ${e}, but these options build at most ${o} ${a.container}[] row(s) — number rows from 0, and name the row of a value that itself starts with digits and a colon, as 0:0:00 for the value 0:00.`);for(let[e,t]of a.rows){let i=[];for(let e of t){let t=er(r.name,r.itemSchemaType,e);if(!t.ok)return x(t.summary,t.warnings);i.push(t.data)}let a=Qt(n,r.name,e,i);if(!a.ok)return a}return S(`Body value assigned`,null)}function I(e){return e.flag.split(` `)[0]??e.name}function Xn(e,t,n){if(t===void 0)return S(`Direct body parsed`,n);if(n===void 0)return S(`Input parsed`,t);if(F(t)&&F(n))try{return S(`Input parsed`,Zn(t,n))}catch(t){return x(`${e} ${t.message}`)}return x(`${e} cannot combine --from-file with direct body options unless the file body is an object.`)}function Zn(e,t){let n={...e};for(let[e,r]of Object.entries(t)){let t=n[e];if(Array.isArray(t)&&Array.isArray(r))throw Error(`cannot combine --from-file array '${e}' with array body options at the same key — move the per-item fields inside the matching '${e}[]' object(s) in the file body.`);if(t!==void 0&&Qn(t)!==Qn(r))throw Error(`cannot combine --from-file ${Qn(t)} '${e}' with ${Qn(r)} body option(s) at the same key — align the file body shape with the schema.`);n[e]=F(t)&&F(r)?Zn(t,r):r}return n}function Qn(e){return Array.isArray(e)?`array`:F(e)?`object`:`scalar`}function $n(e,t){if(typeof t==`boolean`)return S(`Body value parsed`,t);if(t===void 0||typeof t==`string`)return er(e.name,e.schemaType,t??``);let n=[],r=pn(e.name)&&e.schemaType!==`array`?e.schemaType:e.itemSchemaType;for(let i of t){let t=er(e.name,r,i);if(!t.ok)return t;n.push(t.data)}return S(`Body value parsed`,n)}function er(e,t,n){if(t===`boolean`)return n===`true`?S(`Body value parsed`,!0):n===`false`?S(`Body value parsed`,!1):x(`${e} must be true or false.`);if(t===`number`||t===`integer`){let r=n.trim(),i=Number(r);return r===``||!Number.isFinite(i)?x(`${e} must be a finite ${t}.`):t===`integer`&&!Number.isInteger(i)?x(`${e} must be an integer.`):S(`Body value parsed`,i)}return S(`Body value parsed`,n)}function tr(e,t){let n=t.parameter.filter(e=>e.required);if(n.length>0&&t.requiredPath.every(e=>n.some(({name:t})=>t===e||t.startsWith(`${e}.`))))return`${e} requires body option(s): ${n.map(I).join(`, `)}`;let r=Xt(t);if(r.length>0)return`${e} requires --from-file with JSON body path(s): ${r.join(`, `)}`;let i=t.parameter.map(I).join(`, `);return i.length===0?`${e} requires --from-file`:`${e} requires --from-file or body option(s): ${i}`}function nr(e,t,n){let r=[...t.parameters,...n.map(({variant:e})=>e[0].parameter)];(t.requestBody?.length??0)>1&&r.push({optionKey:`contentType`,flag:Fn,location:`body`}),rr(t)&&r.push({optionKey:`fromFile`,flag:`--from-file`,location:`body`}),wn(e.options,r)}function rr(e){return(e.requestBody??[]).some(e=>e.kind!==`multipart`||e.parameter.some(e=>e.schemaFormat!==`binary`))}function ir(e){let t=Ce(e);return dr(t),process.stdout.write(`${JSON.stringify(t)}\n`),t}function ar(e){dr(e);let t=ut(e.data,e.summary);if(e.ok&&t!==null){process.stdout.write(t.endsWith(`
2
2
  `)?t:`${t}\n`),or(e);return}let n=e.ok?`OK`:`FAIL`;process.stdout.write(`[${n}] ${e.summary}\n`),!e.ok&&e.problem!==void 0&&cr(e.problem),or(e)}function or(e){e.ids.length>0&&process.stdout.write(` ids: ${e.ids.join(`, `)}\n`);for(let[t,n]of Object.entries(e.counts))process.stdout.write(` ${t}: ${n}\n`);for(let t of e.references)process.stdout.write(` ref: ${t}\n`);if(e.truncation!==void 0){let t=e.truncation.omitted.join(`, `);process.stdout.write(` truncated: byteLength=${e.truncation.byteLength} maxBytes=${e.truncation.maxBytes} omitted=${t}\n`),process.stdout.write(` recovery: ${e.truncation.recovery}\n`)}for(let t of e.warnings)process.stdout.write(` warn: ${t}\n`)}function L(e,t){if(e.mode===`data`||e.mode===`data-full`){let n=e.mode===`data`?Ce(t):t;dr(n),process.stdout.write(`${JSON.stringify(n.ok&&n.truncated!==!0?sr(n.data):n)}\n`),n.ok||(process.exitCode=1);return}let n=e.mode===`json`?ir(t):t;e.mode===`text`&&ar(n),n.ok||(process.exitCode=1)}function sr(e){return typeof e!=`object`||!e||Array.isArray(e)||!Reflect.has(e,`method`)||!Reflect.has(e,`endpoint`)||!(`response`in e)||e.response===void 0?e:e.response}function cr(e){typeof e.code==`string`&&process.stdout.write(` code: ${e.code}\n`),typeof e.detail==`string`&&process.stdout.write(` detail: ${e.detail}\n`),typeof e.hint==`string`&&process.stdout.write(` hint: ${e.hint}\n`),typeof e.suggestion==`string`&&process.stdout.write(` suggestion: ${e.suggestion}\n`);let t=Object.entries(e.suggestions??{});if(t.length>0){let e=t.map(([e,t])=>`${e}=${t}`).join(`; `);process.stdout.write(` suggestions: ${e}\n`)}lr(`unknownParameters`,e.unknownParameters),lr(`validParameters`,e.validParameters),ur(e.resolution)}function lr(e,t){t!=null&&t.length>0&&process.stdout.write(` ${e}: ${t.join(`, `)}\n`)}function ur(e){if(e==null)return;let t=[`action=${e.action}`];typeof e.parameter==`string`&&t.push(`parameter=${e.parameter}`),typeof e.fieldPath==`string`&&t.push(`fieldPath=${e.fieldPath}`),typeof e.endpoint==`string`&&t.push(`endpoint=${e.endpoint}`),e.acceptedValue!==null&&e.acceptedValue!==void 0&&e.acceptedValue.length>0&&t.push(`acceptedValue=${e.acceptedValue.join(`, `)}`),typeof e.retryable==`boolean`&&t.push(`retryable=${e.retryable}`),process.stdout.write(` resolution: ${t.join(` `)}\n`)}function dr(e){e.ok&&e.warnings.length===0||te({component:`aventure-cli`,event:e.ok?`command_warning`:`command_failed`,message:e.warnings.length>0?e.warnings.join(` | `):e.summary,fields:{warningCount:e.warnings.length,summary:e.summary}})}function fr(e,t,n=m().bin[0]){let r=t.length,i=mt(e.q?.trim()??``),a=at(i),o=ct(i),s=hr(t,n).filter(t=>yr(t,e)).map(e=>({operation:e,score:xr(i,a,o,e)})).filter(({score:e})=>i===``||e>0).toSorted((e,t)=>t.score-e.score||e.operation.cli.command.localeCompare(t.operation.cli.command)||e.operation.operationId.localeCompare(t.operation.operationId)).map(({operation:e})=>e),c=Er(e.limit,s.length),l=s.slice(0,c);return S(`Operation catalog matches`,{operation:l,count:{totalOperations:r,matched:s.length,returned:l.length}})}function pr(e,t,n=m().bin[0]){let r=hr(t,n),i=e.operationId===void 0?mr(r,e.command):r.find(t=>t.operationId===e.operationId);return i===void 0?x(`Generated operation not found`,[`List candidates with \`${n} command-catalog search "<text>"\`.`]):S(`Generated operation detail`,{operation:i,usage:Dr(i)})}function mr(e,t){if(t===void 0)return;let n=Ir(t);return e.find(e=>Ir(e.cli.command)===n||e.cli.alias!==null&&Ir(e.cli.alias)===n)}function hr(e,t){return e.map(e=>{let n=e.requestBody??[],r=[...e.parameters.map(e=>gr(e)),...n.flatMap(e=>e.parameter.map(t=>gr(t,n.length>1?e.contentType:void 0))),..._r(n)],i=`${t} ${e.cliPath.join(` `)}`,a=e.cliAliasPath===void 0?null:`${t} ${e.cliAliasPath.join(` `)}`,o=ne(e.intent),s=e.method===`DELETE`||e.intent===`delete`,c=n[0];return{operationId:e.operationId,method:e.method,path:e.path,resource:e.resource,intent:e.intent,scope:e.scope,mutates:o,destructive:s,auth:e.auth,cli:{command:i,path:e.cliPath,alias:a,aliasPath:e.cliAliasPath??null},mcpTool:e.binaryResponse?null:l(e.intent),body:{hasBody:c!==void 0,kind:c?.kind??null,...c!==void 0&&n.length>1?{contentType:c.contentType}:{},required:c?.required??!1,description:c?.description??``,requiredPath:c?.requiredPath??[]},flags:r,errorResponse:e.errorResponse,summary:e.summary,description:e.description}})}function gr(e,t){let n=e.flag.split(/\s+/u);return{name:n[0]??e.flag,optionKey:e.optionKey,wireName:e.name,location:e.location,required:e.required,placeholder:n.length<=1?null:n.slice(1).join(` `),description:e.description,choices:e.choices??[],...t===void 0?{}:{contentType:t}}}function _r(e){if((e?.length??0)<=1)return[];let t=e?.map(({contentType:e})=>e)??[];return[{name:`--content-type`,optionKey:`contentType`,wireName:`Content-Type`,location:`body`,required:!1,placeholder:`<media-type>`,description:`Select the request content type; omit for ${t[0]}.`,choices:t}]}function vr(e){return e.flags.filter(({contentType:t})=>t===void 0||t===e.body.contentType)}function yr(e,t){return!(t.root!==void 0&&!br(e,t.root)||t.scope!==void 0&&t.scope!==`all`&&t.scope!==e.scope||t.mutates!==void 0&&t.mutates!==`any`&&t.mutates===`true`!==e.mutates||t.destructive!==void 0&&t.destructive!==`any`&&t.destructive===`true`!==e.destructive||t.intent!==void 0&&t.intent!==`all`&&t.intent!==e.intent||t.method!==void 0&&t.method!==`all`&&t.method!==e.method)}function br(e,t){let n=mt(t);return n.length===0||mt(e.cli.path.at(0)??``)===n||mt(e.cli.aliasPath?.at(0)??``)===n}function xr(e,t,n,r){if(e.length===0)return 1;let i=Cr(r),a=Sr(e,t,i,{exactQuery:120,partialQuery:60,exactToken:18,partialToken:6})+Sr(e,t,wr(r),{exactQuery:12,partialQuery:6,exactToken:2,partialToken:1});st(n,i)&&(a+=200);for(let e of r.cli.path){let n=new Set;pt(n,e),[...n].some(e=>t.has(e))&&(a+=15)}return mt(r.cli.command).endsWith(e)&&(a+=40),a}function Sr(e,t,n,r){let i=0;n.includes(e)&&(i+=r.exactQuery),n.some(t=>t.includes(e))&&(i+=r.partialQuery);for(let e of t)n.includes(e)?i+=r.exactToken:n.some(t=>t.includes(e))&&(i+=r.partialToken);return i}function Cr(e){return Tr([e.operationId,e.cli.command,e.cli.alias??``,e.summary])}function wr(e){return Tr([e.method,e.path,e.resource,e.intent,e.scope,e.mutates?`mutates mutation write`:`read only no mutation`,e.destructive?`destructive delete`:`non destructive`,e.mcpTool??``,e.body.kind??``,e.body.description,e.body.requiredPath.join(` `),e.description,...e.flags.flatMap(e=>[e.name,e.optionKey,e.wireName,e.description,e.choices.join(` `)])])}function Tr(e){return e.map(mt).filter(e=>e.length>0)}function Er(e,t){if(e===void 0)return t;let n=Number(e);return Number.isFinite(n)?Math.max(0,Math.trunc(n)):t}function Dr(e){let t=vr(e),n=t.filter(e=>e.required),r=t.filter(e=>!e.required);return[`cli: ${e.cli.command}`,e.cli.alias===null?``:`alias: ${e.cli.alias}`,`${e.method} ${e.path}`,`operationId: ${e.operationId}`,`resource: ${e.resource}`,`intent: ${e.intent}`,`scope: ${e.scope}`,`mutates: ${e.mutates}`,`destructive: ${e.destructive}`,`mcpTool: ${e.mcpTool??`unavailable (binary CLI operation)`}`,e.body.hasBody?`body: kind=${e.body.kind??`unknown`} required=${e.body.required} requiredPath=${e.body.requiredPath.join(`,`)}`:`body: none`,R(`required path flags`,n,`path`),R(`required query flags`,n,`query`),R(`required header flags`,n,`header`),R(`required body flags`,n,`body`),R(`optional path flags`,r,`path`),R(`optional query flags`,r,`query`),R(`optional header flags`,r,`header`),R(`optional body flags`,r,`body`),...Mr(e),...Or(e.errorResponse),``,e.summary,e.description].filter(e=>e.length>0).join(`
3
3
  `)}function Or(e){return e.length===0?[]:[`Errors:`,...e.map(({status:e,description:t})=>` ${e} ${t}`)]}var kr=[`-id`,`-slug`,`-url`],Ar=[`--id`,`--slug`,`--url`],jr=`--from-file "<path>"`;function Mr(e){return[`example: ${[e.cli.command,...Nr(e),`--data`].join(` `)}`]}function Nr(e){let t=vr(e).filter(e=>e.required),n=(t.length>0?t:Pr(e)).map(Fr);return(e.body.required||e.body.requiredPath.length>0)&&!t.some(e=>e.location===`body`)?[...n,jr]:n}function Pr(e){let t=new Set;pt(t,e.resource);for(let n of kr)for(let r of t){let t=e.flags.find(e=>e.name===`--${r}${n}`);if(t!==void 0)return[t]}for(let t of Ar){let n=e.flags.find(e=>e.name===t);if(n!==void 0)return[n]}return[]}function Fr(e){return e.placeholder===null?e.name:`${e.name} "${e.placeholder}"`}function R(e,t,n){let r=t.filter(e=>e.location===n);return`${e}: ${r.length===0?`none`:r.map(e=>e.name).join(` `)}`}function Ir(e){return e.trim().replace(/^aventure(?:-cli)?\s+/u,``).replaceAll(/\s+/gu,` `)}function Lr(e,t,n=m().bin[0]){e.helpCommand(!1);let r=e.commands.find(e=>e.name()===`help`)??e.command(`help`);r.summary(`Show command help, or ask the platform a grounded question`).description([`Show local --help output for a command path (deterministic, offline),`,`or answer a natural-language platform question with --ask via the grounded`,"help operation (the same generated operation as `help ask`)."].join(`
4
4
  `)).argument(`[command...]`,"command path to show help for, e.g. `help search entities`"),r.addOption(new Rr(r));let i=Br(t);i!==void 0&&r.option(`--ask <question>`,i.summary),T(r),r.action(async function(t){let r=this.optsWithGlobals();if(r.help&&t.length===0){this.outputHelp();return}if(!r.help&&i!==void 0&&r.ask!==void 0){let e=w(r);if(t.length>0){L({mode:e},x(`Use either a command path or --ask, not both.`));return}L({mode:e},await Hr(i,r.ask,r.environment,e));return}let a=Vr(e,t);a===void 0&&this.error(`unknown command '${t.join(` `)}' (run \`${n} --help\` for the command tree)`),a.outputHelp()}),zr(e,t)}var Rr=class extends u{helpCommand;constructor(e){super(`-h, --help`,`display help for command`),this.helpCommand=e}is(e){if(e!==this.short&&e!==this.long)return!1;let t=this.helpCommand.parent?.args??[],n=t.findIndex(e=>e===this.helpCommand.name()||this.helpCommand.aliases().includes(e)),r=n<0?void 0:t[n+1];return r===void 0||r.startsWith(`-`)?!0:!this.helpCommand.commands.some(e=>e.name()===r||e.aliases().includes(r))}};function zr(e,t){let n=new Set;for(let r of t){let t=Or(r.errorResponse);if(t.length!==0)for(let i of[r.cliPath,r.cliAliasPath]){let r=i===void 0?void 0:Vr(e,i);r===void 0||n.has(r)||(n.add(r),r.addHelpText(`after`,`\n${t.join(`
@@ -26,7 +26,7 @@ import{C as e,D as t,_ as n,a as r,k as i,v as a,x as o}from"./person-owner-ChqQ
26
26
  `).slice(-3).join(` | `);return x(`npm ${e.join(` `)} exited ${a.status}`,[t||`no stderr`])}return S(`npm ok`,a.stdout??``)}function fs(e,t){let n=vt(process.execPath,[e,`--version`],{encoding:`utf8`});if(n.error)return x(`updated ${d} verification failed: ${n.error.message}`,[`spawn_error`]);let r=(n.stdout??``).trim();if(n.status!==0||r!==t){let i=(n.stderr??``).trim().split(`
27
27
  `).slice(-3).join(` | `);return x(`updated ${d} verification expected ${t} but active bin reported ${r||`empty output`}`,[i||`active bin: ${e}`])}return S(`active CLI version verified`,r)}function ps(e){let t=`${Ot}lib${Ot}node_modules${Ot}${e.name.replace(`/`,Ot)}`,n=e.packageRoot.lastIndexOf(t),r=e.bin.includes(`aventure-cli`)?`aventure-cli`:e.bin[0];return n<0?null:{entryPath:k(e.packageRoot.slice(0,n),`bin`,r),installPrefix:e.packageRoot.slice(0,n)}}function ms(e,t){if(e.name!==`@aventurevc/mcp-server`)return{backup:[],backupDirectory:null};if(t===null)throw Error(`the running MCP package is not in a verifiable global npm prefix`);if(!e.entryPath.startsWith(`${e.packageRoot}${Ot}`))throw Error(`the running CLI entry is outside the MCP package root`);let n=e.bin.filter(e=>e===`aventure`||e===`aventure-cli`).flatMap(n=>{let r=k(t.installPrefix,`bin`,n),i=Mt(r,{throwIfNoEntry:!1});if(i===void 0)return[];if(!i.isSymbolicLink())throw Error(`${r} is not a symlink`);let a;try{a=It(r)}catch(e){throw Error(`${r} has a missing target`,{cause:e})}if(a!==e.entryPath)throw Error(`${r} is not owned by the running MCP CLI`);return{binPath:r,linkTarget:Ft(r)}});if(n.length===0)return{backup:[],backupDirectory:null};let r=Pt(k(t.installPrefix,`bin`,`.aventure-cli-update-`)),i=n.map(({binPath:e,linkTarget:t})=>({backupPath:k(r,Dt(e)),binPath:e,linkTarget:t})),a=[];try{for(let e of i)if(Lt(e.binPath,e.backupPath),a.push(e),Ft(e.backupPath)!==e.linkTarget)throw Error(`${e.binPath} changed ownership while preparing the update`)}catch(e){let t=hs({backup:a,backupDirectory:r},null);throw Error(`could not displace verified MCP CLI bins${t===null?``:`; restoration failed: ${t}`}`,{cause:e})}return{backup:a,backupDirectory:r}}function hs(e,t){let n=t===null?null:k(t,`lib`,`node_modules`,...d.split(`/`)),r=[];for(let t of e.backup.toReversed())try{let e=Mt(t.binPath,{throwIfNoEntry:!1});if(e!==void 0){if(!e.isSymbolicLink())throw Error(`${t.binPath} is not a symlink`);let r=k(D(t.binPath),Ft(t.binPath));if(n===null||r!==n&&!r.startsWith(`${n}${Ot}`))throw Error(`${t.binPath} is not owned by the standalone CLI package`);Bt(t.binPath)}Lt(t.backupPath,t.binPath)}catch(e){r.push(_s(e))}if(e.backupDirectory!==null)try{zt(e.backupDirectory)}catch(e){r.push(_s(e))}return r.length===0?null:r.join(`; `)}function gs(e){let t=[];for(let n of e.backup)try{Bt(n.backupPath)}catch(e){t.push(_s(e))}if(e.backupDirectory!==null)try{zt(e.backupDirectory)}catch(e){t.push(_s(e))}return t.length===0?null:t.join(`; `)}function _s(e){return e instanceof Error?e.message:String(e)}function vs(){try{return Go()}catch(e){return{refreshed:!1,message:e instanceof Error?e.message:String(e)}}}var ys=[{name:`cli-version`,purpose:`running CLI against the latest published release`},{name:`api-schemas`,purpose:`the installed @aventurevc/api-schemas contracts resolve`},{name:`api-host`,purpose:`the selected API host answers its generated status operation`},{name:`auth`,purpose:`which credential scope materialized locally, never the secret`},{name:`catalog`,purpose:`this catalog was generated from the operation set the API serves`}],bs=`operationFingerprint`;function xs(e,t=m().bin[0]){T(e.command(`doctor`).summary(`One-call selftest: CLI version, schemas, API host, auth scope, command catalog`).description(["Run every environment check in one call and report `{ ok, check: [...] }`:",...ys.map(e=>` - ${e.name}: ${e.purpose}`),``,`Exit code is 0 only when no check failed; a skipped check (no registry reachable)`,`does not fail the run. Each failing message names the command that fixes it.`,"--json always carries the report at `.data`; --data prints the report directly when",`every check passes and the result envelope when one fails, like every other command.`].join(`
28
28
  `))).action(async function(e){let n=this.optsWithGlobals();n.environment!==void 0&&(process.env.API_ENV=n.environment),L({mode:w(e)},await Ss(t))})}async function Ss(e){let t=ws(),n=Ts(e),[r,i]=await Promise.all([Es(e),Ds(t,e)]),a=[n.check,r,i.check,await ks(e),Is(t,i.servedFingerprint,n.upgradeAvailable,e)],o={pass:Cs(a,`pass`),fail:Cs(a,`fail`),skip:Cs(a,`skip`)},s=a.filter(e=>e.status===`fail`).map(e=>e.message),c={ok:s.length===0,check:a},l=[`doctor: ${o.pass} pass, ${o.fail} fail, ${o.skip} skip`,...a.map(e=>` ${e.name} ${e.status} — ${e.message}`)].join(`
29
- `);return c.ok?S(l,c,{counts:o}):{...x(l,s,{counts:o}),data:c}}function Cs(e,t){return e.filter(e=>e.status===t).length}function q(e,t,n){return{name:e,status:t,message:n}}function ws(){return E.find(e=>e.intent===`status`&&e.resource===`status`)}function Ts(e){let t=m(),n=us(t,`check`);if(!n.ok||n.data===null)return{check:q(`cli-version`,`skip`,`Could not compare ${t.version} against the registry (${n.summary}); rerun \`${e} update\` with registry access.`),upgradeAvailable:null};let{targetPackage:r,currentVersion:i,latestVersion:a,upgradeAvailable:o}=n.data;return{check:o?q(`cli-version`,`fail`,`Upgrade ${r} from ${i} to ${a}: run \`${e} update\`.`):q(`cli-version`,`pass`,`${r} ${i} matches the latest published release.`),upgradeAvailable:o}}async function Es(e){try{let{EntityDetailSchema:e}=await import(`./detail-DeMsv_6C.js`);if(typeof e.safeParse!=`function`)throw Error(`EntityDetailSchema does not expose a Zod parser`);return q(`api-schemas`,`pass`,`Installed @aventurevc/api-schemas contracts resolve beyond the CLI startup path.`)}catch(t){return q(`api-schemas`,`fail`,`Reinstall the CLI: run \`${e} update\` — ${C(t)}.`)}}async function Ds(e,t){if(e===void 0)return{check:q(`api-host`,`skip`,`No status operation resolved from the generated catalog; fix the catalog check first.`),servedFingerprint:null};let n;try{n=s().host}catch(e){return{check:q(`api-host`,`fail`,`Correct API_ENV or pass \`--environment <name>\` — ${C(e)}.`),servedFingerprint:null}}let r=await b({method:e.method,path:e.path,auth:e.auth,responseFormat:`json`}).catch(e=>x(C(e)));return r.ok?{check:q(`api-host`,`pass`,`${e.method} ${e.path} answered at ${n}.`),servedFingerprint:Os(r.data)}:{check:q(`api-host`,`fail`,`Point the CLI at a reachable API host with \`--environment <name>\` or API_URL, then rerun \`${t} auth doctor\` — ${e.method} ${e.path} at ${n} returned ${r.summary}.`),servedFingerprint:null}}function Os(e){if(typeof e!=`object`||!e||e instanceof Uint8Array)return null;let{response:t}=e;if(typeof t!=`object`||!t||Array.isArray(t))return null;let n=t[bs];return typeof n==`string`&&n.length>0?n:null}async function ks(e){await c();let t;try{t=h(await me())}catch(t){return q(`auth`,`fail`,`Repair or remove ${y()} and run \`${e} auth init\` — ${C(t)}.`)}let[n,r]=await Promise.all([As(),js()]);if(r.state===`unavailable`&&r.cause===`environment`)return q(`auth`,`fail`,`Fix the environment configuration first — ${r.summary}.`);let i=t[ye.authToken].present,a=p.some(e=>t[e].present);return!i&&n.state===`invalid`?q(`auth`,`fail`,`Saved OAuth credential is invalid; run \`${e} auth login\` to sign in again after verification — ${n.summary}.`):!i&&n.state===`found`&&Pe(n.stored.credential)?q(`auth`,`fail`,`Saved OAuth access token is expired; run \`${e} auth login\` to renew it or sign in again.`):!a&&r.state!==`found`&&n.state===`unavailable`?q(`auth`,`fail`,`Unlock OS OAuth credential storage before \`${e} auth login\`, or inject ${ye.authToken} through the environment — ${n.summary}.`):a||n.state===`found`||r.state===`found`?q(`auth`,`pass`,`Credential source available: ${Ms(t,n,r)}.`):r.state===`unavailable`?q(`auth`,`fail`,`Unlock OS credential storage before \`${e} auth personal-login\`, or inject ${p.join(`/`)} through the environment — ${r.summary}.`):p.some(e=>t[e].source===`config`)?q(`auth`,`fail`,`The Doppler source in ${y()} resolved no credential: confirm your access to that project and config, or inject ${p.join(`/`)} through the environment.`):q(`auth`,`fail`,`Run \`${e} auth login\` for OAuth, \`${e} auth personal-login\` for a personal credential, or \`${e} auth init\` to select a Doppler source.`)}async function As(){let e;try{e=tt(s().host)}catch(e){return{state:`unavailable`,summary:C(e)}}return await ke(e)}async function js(){let e;try{e=Re(s().host)}catch(e){return{state:`unavailable`,summary:C(e),cause:`environment`}}try{return await rt(e)}catch(e){return{state:`unavailable`,summary:C(e),cause:`keyring`}}}function Ms(e,t,n){return[...p.map(t=>`${t}=${Ns(e,t)}`),`oauth=${Fs(t)}`,`personal=${Ps(n)}`].join(` `)}function Ns(e,t){let n=e[t];return n.present?n.source??`resolved`:n.source===`config`?`config (unresolved)`:`unset`}function Ps(e){return e.state===`found`?e.stored.activation:e.state===`missing`?`unset`:`unavailable`}function Fs(e){switch(e.state){case`found`:return Pe(e.stored.credential)?`expired`:`stored`;case`missing`:return`unset`;case`invalid`:return`invalid`;case`unavailable`:return`unavailable`;default:throw Error(`Unsupported OAuth credential state`)}}function Is(e,t,n,r){let i=E.length;if(e===void 0)return q(`catalog`,`fail`,`Regenerate the command catalog with \`make mcp-generate-contracts\` and reinstall: none of its ${i} operations is the status operation.`);if(t===null)return q(`catalog`,`skip`,`Could not read the served operation fingerprint, so drift is unproven; this catalog holds ${i} operations at ${Xe}.`);if(t===`cd82b96a230a21a8`)return q(`catalog`,`pass`,`${i} generated operations match the set the API serves (${Xe}).`);let a=`This catalog describes a different operation set than the API serves (${Xe} vs ${t})`;return n===!0?q(`catalog`,`fail`,`${a}: run \`${r} update\`.`):q(`catalog`,`skip`,n===!1?`${a}, and this CLI is already the latest published release: either the deployed API is older than this CLI, or a newer CLI has not been published yet.`:`${a}, and the registry did not answer, so it is unknown whether a newer release describes it: rerun \`${r} update\` with registry access.`)}var Ls=z(B,`oauth`),Rs=z(B,`start`),zs=z(B,`poll`),Bs=z(B,`acknowledge`),Vs=z(B,`revoke`);function Hs(e,t=m().bin[0]){let n=Ws(e);xs(n,t),wo(e,t),T(Us(n,Ls,Ls.description)).action(async function(e){Gs(this),L({mode:w(e)},await fa({noBrowser:!e.browser},t))}),T(Us(n,Rs,[Rs,zs,Bs].map(({description:e})=>e).join(`
29
+ `);return c.ok?S(l,c,{counts:o}):{...x(l,s,{counts:o}),data:c}}function Cs(e,t){return e.filter(e=>e.status===t).length}function q(e,t,n){return{name:e,status:t,message:n}}function ws(){return E.find(e=>e.intent===`status`&&e.resource===`status`)}function Ts(e){let t=m(),n=us(t,`check`);if(!n.ok||n.data===null)return{check:q(`cli-version`,`skip`,`Could not compare ${t.version} against the registry (${n.summary}); rerun \`${e} update\` with registry access.`),upgradeAvailable:null};let{targetPackage:r,currentVersion:i,latestVersion:a,upgradeAvailable:o}=n.data;return{check:o?q(`cli-version`,`fail`,`Upgrade ${r} from ${i} to ${a}: run \`${e} update\`.`):q(`cli-version`,`pass`,`${r} ${i} matches the latest published release.`),upgradeAvailable:o}}async function Es(e){try{let{EntityDetailSchema:e}=await import(`./detail-DeMsv_6C.js`);if(typeof e.safeParse!=`function`)throw Error(`EntityDetailSchema does not expose a Zod parser`);return q(`api-schemas`,`pass`,`Installed @aventurevc/api-schemas contracts resolve beyond the CLI startup path.`)}catch(t){return q(`api-schemas`,`fail`,`Reinstall the CLI: run \`${e} update\` — ${C(t)}.`)}}async function Ds(e,t){if(e===void 0)return{check:q(`api-host`,`skip`,`No status operation resolved from the generated catalog; fix the catalog check first.`),servedFingerprint:null};let n;try{n=s().host}catch(e){return{check:q(`api-host`,`fail`,`Correct API_ENV or pass \`--environment <name>\` — ${C(e)}.`),servedFingerprint:null}}let r=await b({method:e.method,path:e.path,auth:e.auth,responseFormat:`json`}).catch(e=>x(C(e)));return r.ok?{check:q(`api-host`,`pass`,`${e.method} ${e.path} answered at ${n}.`),servedFingerprint:Os(r.data)}:{check:q(`api-host`,`fail`,`Point the CLI at a reachable API host with \`--environment <name>\` or API_URL, then rerun \`${t} auth doctor\` — ${e.method} ${e.path} at ${n} returned ${r.summary}.`),servedFingerprint:null}}function Os(e){if(typeof e!=`object`||!e||e instanceof Uint8Array)return null;let{response:t}=e;if(typeof t!=`object`||!t||Array.isArray(t))return null;let n=t[bs];return typeof n==`string`&&n.length>0?n:null}async function ks(e){await c();let t;try{t=h(await me())}catch(t){return q(`auth`,`fail`,`Repair or remove ${y()} and run \`${e} auth init\` — ${C(t)}.`)}let[n,r]=await Promise.all([As(),js()]);if(r.state===`unavailable`&&r.cause===`environment`)return q(`auth`,`fail`,`Fix the environment configuration first — ${r.summary}.`);let i=t[ye.authToken].present,a=p.some(e=>t[e].present);return!i&&n.state===`invalid`?q(`auth`,`fail`,`Saved OAuth credential is invalid; run \`${e} auth login\` to sign in again after verification — ${n.summary}.`):!i&&n.state===`found`&&Pe(n.stored.credential)?q(`auth`,`fail`,`Saved OAuth access token is expired; run \`${e} auth login\` to renew it or sign in again.`):!a&&r.state!==`found`&&n.state===`unavailable`?q(`auth`,`fail`,`Unlock OS OAuth credential storage before \`${e} auth login\`, or inject ${ye.authToken} through the environment — ${n.summary}.`):a||n.state===`found`||r.state===`found`?q(`auth`,`pass`,`Credential source available: ${Ms(t,n,r)}.`):r.state===`unavailable`?q(`auth`,`fail`,`Unlock OS credential storage before \`${e} auth personal-login\`, or inject ${p.join(`/`)} through the environment — ${r.summary}.`):p.some(e=>t[e].source===`config`)?q(`auth`,`fail`,`The Doppler source in ${y()} resolved no credential: confirm your access to that project and config, or inject ${p.join(`/`)} through the environment.`):q(`auth`,`fail`,`Run \`${e} auth login\` for OAuth, \`${e} auth personal-login\` for a personal credential, or \`${e} auth init\` to select a Doppler source.`)}async function As(){let e;try{e=tt(s().host)}catch(e){return{state:`unavailable`,summary:C(e)}}return await ke(e)}async function js(){let e;try{e=Re(s().host)}catch(e){return{state:`unavailable`,summary:C(e),cause:`environment`}}try{return await rt(e)}catch(e){return{state:`unavailable`,summary:C(e),cause:`keyring`}}}function Ms(e,t,n){return[...p.map(t=>`${t}=${Ns(e,t)}`),`oauth=${Fs(t)}`,`personal=${Ps(n)}`].join(` `)}function Ns(e,t){let n=e[t];return n.present?n.source??`resolved`:n.source===`config`?`config (unresolved)`:`unset`}function Ps(e){return e.state===`found`?e.stored.activation:e.state===`missing`?`unset`:`unavailable`}function Fs(e){switch(e.state){case`found`:return Pe(e.stored.credential)?`expired`:`stored`;case`missing`:return`unset`;case`invalid`:return`invalid`;case`unavailable`:return`unavailable`;default:throw Error(`Unsupported OAuth credential state`)}}function Is(e,t,n,r){let i=E.length;if(e===void 0)return q(`catalog`,`fail`,`Regenerate the command catalog with \`make mcp-generate-contracts\` and reinstall: none of its ${i} operations is the status operation.`);if(t===null)return q(`catalog`,`skip`,`Could not read the served operation fingerprint, so drift is unproven; this catalog holds ${i} operations at ${Xe}.`);if(t===`c978c45f5233b6b9`)return q(`catalog`,`pass`,`${i} generated operations match the set the API serves (${Xe}).`);let a=`This catalog describes a different operation set than the API serves (${Xe} vs ${t})`;return n===!0?q(`catalog`,`fail`,`${a}: run \`${r} update\`.`):q(`catalog`,`skip`,n===!1?`${a}, and this CLI is already the latest published release: either the deployed API is older than this CLI, or a newer CLI has not been published yet.`:`${a}, and the registry did not answer, so it is unknown whether a newer release describes it: rerun \`${r} update\` with registry access.`)}var Ls=z(B,`oauth`),Rs=z(B,`start`),zs=z(B,`poll`),Bs=z(B,`acknowledge`),Vs=z(B,`revoke`);function Hs(e,t=m().bin[0]){let n=Ws(e);xs(n,t),wo(e,t),T(Us(n,Ls,Ls.description)).action(async function(e){Gs(this),L({mode:w(e)},await fa({noBrowser:!e.browser},t))}),T(Us(n,Rs,[Rs,zs,Bs].map(({description:e})=>e).join(`
30
30
  `))).action(async function(e){Gs(this),L({mode:w(e)},await Ri({noBrowser:!e.browser,clientLabel:e.clientLabel}))}),T(Us(n,Vs,Vs.description)).action(async function(e){Gs(this),L({mode:w(e)},await Ai({forgetLocal:e.forgetLocal===!0}))}),T(n.command(`init`).summary(`Interactive credential setup`).description([`Interactively record the Doppler project/config used by ${t} + the MCP server.`,`Credentials resolve from the injected environment first, then Doppler; auth init never writes credentials to disk.`,``,`Prompts go to stderr so stdout stays reserved for the result envelope.`].join(`
31
31
  `))).action(async function(e){Gs(this),L({mode:w(e)},await Qs(t))}),T(n.command(`status`).summary(`Local credential provenance, API build, and server uptime`).description([`Reports local credentials plus two independent remote health signals:`,` - auth: per-credential local provenance (env vs ~/.config/aventure/config.json vs unset)`,` - oauth: OS-keyring OAuth access-token metadata for the selected API host, without the token`,` - personal: OS-keyring metadata for the selected API host, without the secret`,` - api: running CLI package version plus GET /info build metadata`,` - system: GET /v1/status response (Better Stack uptime SLA)`,``,`No headers are sent to the server. Credential provenance is computed locally; this`,`answers whether service credentials, OAuth, or a personal CLI credential are wired without exposing them.`,`To prove a credential survives transit, call any real endpoint that requires it.`].join(`
32
32
  `))).action(async function(e){Gs(this),L({mode:w(e)},await Ks(t))})}function Us(e,t,n){let r=e.command(t.command.slice(t.command.indexOf(` `)+1)).summary(t.summary).description(n);for(let e of t.bodyOption)e.required?r.requiredOption(e.flag,e.description):r.option(e.flag,e.description);for(let e of t.localOption)r.option(e.flag,e.description);return r}function Ws(e){return(e.commands.find(e=>e.name()===`auth`)??e.command(`auth`)).summary(`Authentication, credential setup, API build, and uptime`).description([`\`${Ls.command}\`: ${Ls.summary}.`,`\`${Rs.command}\`: ${Rs.summary}.`,`\`${Vs.command}\`: ${Vs.summary}.`,"`auth status` reports local credential provenance plus CLI/API build and uptime.","`auth doctor` runs the one-call selftest and prints `{ ok, check: [...] }`.","`auth init` configures the local Doppler source used by generated API commands."].join(`