@aventurevc/aventure-cli 0.8.227 → 0.8.229
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/dist/aventure-cli/command-catalog.compact.txt +1 -1
- package/dist/aventure-cli/index.js +1 -1
- package/dist/aventure-cli/unified-operations.json +1 -1
- package/dist/chunks/api-key-bearer-credential-B0ulZ4jd.js +1 -0
- package/dist/chunks/{api-key-bearer-credential-_J7FcBLo.js → api-key-bearer-credential-BbO1Igh-.js} +1 -1
- package/dist/chunks/{aventure-cli-Dbh5RcM2.js → aventure-cli-BezDdo41.js} +40 -30
- package/dist/chunks/{cli-help-policy-DQmyRbFU.js → cli-help-policy-BfaoryK2.js} +1 -1
- package/dist/chunks/{commander-BB7CDPLs.js → commander-DEj7N1b9.js} +1 -1
- package/dist/chunks/commander-wH7TO4kY.js +1 -0
- package/dist/chunks/{contract-DXaYYWLp.js → contract-BSeJEx3C.js} +3 -3
- package/dist/chunks/{detail-BsTee2g2.js → detail-2DCBfxlE.js} +1 -1
- package/dist/chunks/detail-BvYZMVnx.js +1 -0
- package/dist/chunks/dist-fXe9nMDe.js +111 -0
- package/dist/chunks/esm-BVGNzX-8.js +1 -0
- package/dist/chunks/logging-D2cJNH4n.js +1 -0
- package/dist/chunks/logging-WPLQQZUz.js +1 -0
- package/dist/chunks/mcp-generation-contract-DZjsDosk.js +1 -0
- package/dist/chunks/mcp-generation-contract-v7KJV9zz.js +1 -0
- package/dist/chunks/oauth-bearer-credential-CzBRB0__.js +8 -0
- package/dist/chunks/oauth-bearer-credential-O51okl02.js +1 -0
- package/dist/chunks/{oauth-login-NB8o3TyE.js → oauth-login-Cma_FBmS.js} +2 -2
- package/dist/chunks/oauth-login-x4A1JmtV.js +1 -0
- package/dist/chunks/openapi-commands-DI1iHEnD.js +1 -0
- package/dist/chunks/openapi-commands-Hbk5R8_d.js +1 -0
- package/dist/chunks/{output-mode-BBqgy7Lp.js → output-mode-CBmpDQfL.js} +1 -1
- package/dist/chunks/output-mode-DwSn_bis.js +1 -0
- package/dist/chunks/{output-spill-BMnGOacl.js → output-spill-5SehC7pV.js} +1 -1
- package/dist/chunks/package-zL1GOs0L.js +1 -0
- package/dist/chunks/person-owner-C0YuWKvY.js +56 -0
- package/dist/chunks/provider-catalog-DKPiAtu0.js +1 -0
- package/dist/chunks/{response-problem-VCowzUP1.js → response-problem-DG4194cZ.js} +1 -1
- package/dist/chunks/{result-envelope-P63eZxlW.js → result-envelope-BKQSGfkH.js} +1 -1
- package/dist/chunks/runtime-identity-ChLiOrMh.js +1 -0
- package/dist/chunks/startup-auth-CIGeUrGQ.js +1 -0
- package/dist/chunks/startup-auth-DusJtRGD.js +1 -0
- package/dist/chunks/text-field-BDYE-wQt.js +1 -0
- package/dist/chunks/tool-policy-BjOSkLem.js +1 -0
- package/package.json +3 -3
- package/dist/chunks/api-key-bearer-credential-D27sVflq.js +0 -1
- package/dist/chunks/commander-Cj79cOD4.js +0 -1
- package/dist/chunks/detail-jqEwPPHS.js +0 -1
- package/dist/chunks/dist-Bn_k8-Uf.js +0 -111
- package/dist/chunks/esm-CFkfzPrU.js +0 -1
- package/dist/chunks/logging-BmcqBxWT.js +0 -1
- package/dist/chunks/logging-CgilPI78.js +0 -1
- package/dist/chunks/mcp-generation-contract-BFjyiSxQ.js +0 -1
- package/dist/chunks/mcp-generation-contract-BJtg1egP.js +0 -1
- package/dist/chunks/oauth-bearer-credential-BBDXvwTf.js +0 -1
- package/dist/chunks/oauth-bearer-credential-DUENbgQP.js +0 -8
- package/dist/chunks/oauth-login-CS94Dzqr.js +0 -1
- package/dist/chunks/openapi-commands-BsJqRKV4.js +0 -1
- package/dist/chunks/openapi-commands-DJeVvCZ1.js +0 -1
- package/dist/chunks/output-mode-BGFO8gdE.js +0 -1
- package/dist/chunks/package-N5oYCiVc.js +0 -1
- package/dist/chunks/person-owner-BJgNYLKX.js +0 -56
- package/dist/chunks/provider-catalog-C4Squz9J.js +0 -1
- package/dist/chunks/runtime-identity-Bva_KyCh.js +0 -1
- package/dist/chunks/startup-auth-BPjdSrY0.js +0 -1
- package/dist/chunks/startup-auth-DP84P7aY.js +0 -1
- package/dist/chunks/text-field-BGnJUpd7.js +0 -1
- package/dist/chunks/tool-policy-NZK3f-HT.js +0 -1
|
@@ -1,37 +1,46 @@
|
|
|
1
|
-
import{a as e,n as t,o as n,r,t as i}from"./commander-BB7CDPLs.js";import{_ as a,f as o,h as s,i as c,m as l,o as u,v as d,x as f}from"./logging-BmcqBxWT.js";import{S as p,a as m,b as h,c as g,l as ee,t as te,x as ne,y as re}from"./tool-policy-NZK3f-HT.js";import{M as ie,O as ae,i as _,l as oe,o as v,p as se,u as ce,v as le,w as y,y as b}from"./person-owner-BJgNYLKX.js";import{Ar as ue,Br as de,Jr as fe,Mr as x,Pr as pe,Qr as me,Rr as he,Xr as ge,Zr as _e,jr as ve,kr as ye}from"./dist-Bn_k8-Uf.js";import{c as S,f as be,n as xe,p as Se,r as C}from"./result-envelope-P63eZxlW.js";import{a as w,n as Ce,r as we,t as Te}from"./package-DPDX5zmx.js";import{a as Ee,i as De}from"./response-problem-VCowzUP1.js";import{n as Oe,r as ke}from"./output-spill-BMnGOacl.js";import{_ as Ae,a as je,b as Me,c as Ne,d as Pe,f as Fe,i as Ie,l as Le,m as Re,n as T,o as ze,r as Be,s as Ve,u as He}from"./contract-DXaYYWLp.js";import{T as Ue}from"./detail-BsTee2g2.js";import{a as We,c as Ge,i as Ke,l as qe,n as Je,s as Ye,t as Xe}from"./cli-help-policy-DQmyRbFU.js";import{S as Ze,_ as Qe,a as $e,g as E,h as et,i as tt,m as nt,n as rt,p as it,r as at,s as ot,t as st,v as ct,x as D,y as lt}from"./api-key-bearer-credential-_J7FcBLo.js";import{a as ut,c as dt,d as ft,g as pt,l as mt,m as ht,o as gt,s as _t,t as vt,u as yt}from"./oauth-bearer-credential-DUENbgQP.js";import{n as bt,r as xt,t as St}from"./oauth-login-NB8o3TyE.js";import{a as Ct,c as wt,d as Tt,i as Et,l as Dt,n as Ot,o as kt,s as At,t as jt,u as Mt}from"./startup-auth-DP84P7aY.js";import{n as Nt,t as O}from"./openapi-commands-BsJqRKV4.js";import{i as k,r as Pt,t as A}from"./output-mode-BBqgy7Lp.js";import{spawnSync as Ft}from"node:child_process";import{basename as j,dirname as M,relative as It,resolve as N,sep as Lt}from"node:path";import{copyFileSync as Rt,existsSync as P,lstatSync as zt,mkdirSync as Bt,mkdtempSync as Vt,readFileSync as Ht,readdirSync as Ut,readlinkSync as Wt,realpathSync as Gt,renameSync as Kt,symlinkSync as qt,writeFileSync as Jt}from"node:fs";import F,{stderr as I,stdin as Yt}from"node:process";import{TextDecoder as Xt,inspect as Zt}from"node:util";import{homedir as Qt,hostname as $t,platform as en}from"node:os";import{fileURLToPath as tn}from"node:url";import{setTimeout as nn}from"node:timers/promises";import{randomUUID as rn,webcrypto as an}from"node:crypto";import{readFile as on}from"node:fs/promises";import{createInterface as sn}from"node:readline/promises";function cn(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{...C(`${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 ln(e,t,n){if(!R(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||!Cn(n,r.name))continue;let a=Sn(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 un(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 dn(e,t,n,r=!1){if(r||!L(t)||!Array.isArray(n))return Dn(e,t,n);for(let[r,i]of n.entries()){let n=Dn(e,t,i,r);if(!n.ok)return n}return S(`Body value assigned`,null)}function fn(e,t,n,r){return Dn(e,t,r,n)}function pn(e){let t=[];for(let n of e.split(`.`)){let e=kn(n);if(t.push(e.key),e.isArray)return t.join(`.`)}return null}function mn(e,t){let n=pn(t);if(n===null)return null;let r=xn(e,n.split(`.`));return Array.isArray(r)?{path:n,rowCount:r.length,firstHole:bn(r)}:null}function hn(e,t){if(L(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]):C(`${n} was already given; pass it once.`)}var gn=/^(?<row>\d+):(?<item>.*)$/su;function _n(e,t){let n=pn(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=gn.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 vn(e,t,n){let r=0;for(let i of e.parameter){let e=t[i.optionKey];e!==void 0&&typeof e!=`boolean`&&pn(i.name)===n&&(r=Math.max(r,typeof e==`string`?1:e.length))}return r}function yn(e,t,n,r){for(let i of t.parameter){let t=n[i.optionKey];if(t===void 0)continue;let a=mn(r,i.name);if(a===null)continue;if(a.firstHole!==null)return C(`${e} has no ${a.path}[] row ${a.firstHole} — number ${a.path}[] rows from 0 with no gaps.`);if(i.schemaType!==`array`||a.rowCount<=1||_n(i,t)!==null)continue;let o=i.flag.split(` `)[0]??i.name;return C(`${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 bn(e){for(let t=0;t<e.length;t+=1)if(e[t]===void 0)return t;return null}function xn(e,t){let n=e;for(let e of t){if(!R(n))return;n=n[e]??null}return n}function Sn(e,t){if(!L(t))return xn(e,t.split(`.`))}function Cn(e,t){return Tn(e,t.split(`.`))}function wn(e,t,n){if(!R(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)&&Cn(n,e.name))return`${e.name} in --from-file requires --content-type ${i.contentType}.`}return null}function Tn(e,t){let[n,...r]=t;if(n===void 0)return!0;let i=kn(n);if(!R(e)||!Object.hasOwn(e,i.key))return!1;let a=e[i.key]??null;return i.isArray?Array.isArray(a)&&a.every(e=>Tn(e,r)):Tn(a,r)}function L(e){return e.split(`.`).some(e=>kn(e).isArray)}function En(e,t){return e.parameter.length===0||!R(t)?null:jn(t,[],An(e.parameter))}function R(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Dn(e,t,n,r=0){let i=t.split(`.`),a=e;for(let[e,o]of i.entries()){let s=kn(o),c=e===i.length-1,l=On(a,s,t,c,n,r);if(!l.ok||l.data===null)return C(l.summary,l.warnings);if(c)return S(`Body value assigned`,null);a=l.data}return C(`${t} is not a valid body option path.`)}function On(e,t,n,r,i,a){let o=()=>C(`${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 R(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 R(s)?S(`Body path stepped`,s):o()}function kn(e){let t=e.endsWith(`[]`);return{key:t?e.slice(0,-2):e,isArray:t}}function An(e){let t=new Set,n=new Set;for(let r of e){let e=`${r.name}${r.schemaType===`array`?`[]`:``}`;t.add(e);let i=e.split(`.`);for(let e=1;e<i.length;e+=1)n.add(i.slice(0,e).join(`.`))}return{leaf:t,prefix:n}}function jn(e,t,n){if(Array.isArray(e)){if(e.length===0)return null;for(let r of e){let e=jn(r,t,n);if(e!==null)return e}return null}if(!R(e))return null;for(let[r,i]of Object.entries(e)){let e=[...t,Array.isArray(i)?`${r}[]`:r],a=e.join(`.`);if(!Mn(a,n)){if(!Nn(e))continue;let t=Pn(e,n);return{path:a,...t===void 0?{}:{suggestion:t}}}let o=jn(i,e,n);if(o!==null)return o}return null}function Mn(e,t){return t.prefix.has(e)||t.leaf.has(e)}function Nn(e){return e.slice(0,-1).some(e=>e.endsWith(`[]`))}function Pn(e,t){let n=e.slice(0,-1).join(`.`),r=e.at(-1)?.replace(/\[\]$/u,``).toLowerCase()??``;return[...t.leaf].filter(e=>e.split(`.`).slice(0,-1).join(`.`)===n).map(e=>({path:e,score:Fn(r,e.split(`.`).at(-1)??``)})).filter(({score:e})=>e<1/0).toSorted((e,t)=>e.score-t.score||e.path.localeCompare(t.path))[0]?.path}function Fn(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}var In=e=>Array.isArray(e)&&!Object.isFrozen(e);function Ln(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(Ge(e)),t.description=pe(t.description,{...e,hasParseDefault:t.defaultValue!==void 0}))}if(!In(e))throw Error(`Commander option list is frozen; generated option help cannot be ordered.`);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?Gn(r,i):r===void 0?i===void 0?0:1:-1})}function Rn(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 zn(e){let{flag:t}=e.variant[0].parameter;return e.variant.every(({parameter:e})=>e.flag===t)?t:`${t.split(` `)[0]??t} <value>`}function Bn(e){let t=e.variant.map(({descriptor:e,parameter:t})=>({contentType:e.contentType,text:Un(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 Vn(e,t){return[...new Set((e.cliConflicts??[]).filter(e=>e.includes(t)).flatMap(e=>e.filter(e=>e!==t)))]}function Hn(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?qe(n):`${qe(n)} Required JSON paths: ${r.join(`, `)}.`}function Un(e,t){let n=We(t.description,void 0),r=e.kind!==`multipart`&&L(t.name),i=e.kind!==`multipart`&&t.optionKey!==t.name&&/^\w+$/u.test(t.name);return`${n}${r?` Repeat to add another value.`:``}${i?` --from-file JSON key: ${t.name}.`:``}${Wn(e,t)}`}function Wn(e,t){if(e.kind===`multipart`||t.schemaType!==`array`)return``;let n=pn(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 Gn(e,t){return Ye(e)-Ye(t)||Number(e.required!==!0)-Number(t.required!==!0)}async function Kn(e){let t;try{t=e===`-`?await qn():await on(e,`utf8`)}catch(t){return C(`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 C(`Input is not valid JSON: ${e.message}`)}}async function qn(){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 Jn=`--content-type`;function Yn(e,n,r){let i=e=>!r?.has(e)&&(r?.add(e),!0),a=n.requestBody??[];if(a.length>1&&i(Jn)){let n=a.map(({contentType:e})=>e);e.addOption(new t(`${Jn} <media-type>`,`Select the request body encoding, never an uploaded file's media type; omit for ${n[0]}.`).choices(n).argParser(Zn(a)))}if(hr(n)&&i(`--from-file`)){let r=a[0];if(r===void 0)throw Error(`${n.operationId} has no request body`);e.addOption(new t(`--from-file <path>`,Hn(r,r.requiredPath)).argParser($n(`--from-file`)))}let o=Rn(a).filter(e=>i(z(e.variant[0].parameter)));for(let n of o.toSorted((e,t)=>Gn(e.variant[0].parameter,t.variant[0].parameter))){let{descriptor:r,parameter:i}=n.variant[0],o=new t(zn(n),a.length>1?Bn(n):Un(r,i));a.length===1&&i.envName!==void 0&&o.env(i.envName);let s=a.length===1?Vn(r,i.optionKey):[];s.length>0&&o.conflicts(s),a.length>1?o.argParser(Xn):L(i.name)||i.schemaType===`array`?o.argParser(Qn):o.argParser($n(i.flag)),e.addOption(o),o.envVar!==void 0&&e.on(`optionEnv:${o.name()}`,()=>{let t=e.opts()[i.optionKey];typeof t==`string`&&t.trim()&&e.setOptionValueWithSource(i.optionKey,t.trim(),`env`)})}mr(e,n,o)}function Xn(e,t){return t===void 0?e:typeof t==`string`?[t,e]:[...t,e]}function Zn(e){return(t,r)=>{if(r!==void 0)throw new n(`${Jn} was already given; pass it once.`);let i=re(e,t);if(!i.ok)throw new n(i.summary);return t}}function Qn(e,t){return[...t??[],e]}function $n(e){let t=e.split(/\s+/u)[0]??e;return(e,r)=>{if(r!==void 0)throw new n(`${t} was already given; pass it once.`);return e}}async function er(e,t){let n=kt(e,t),r=re(e.requestBody??[],n);if(!r.ok||r.data===null)return C(r.summary,r.warnings);let i=r.data;if(i===void 0)return S(`No body`,void 0);let a=tr(e,i,t);if(a!==null)return C(a);let o=cn(e.operationId,i,t);if(!o.ok)return C(o.summary,o.warnings);t=o.data;let s=nr(i,t);if(s!==null)return C(s);let c=await or(t);if(!c.ok)return C(c.summary,c.warnings);let l=wn(e.requestBody??[],i,c.data);if(l!==null)return C(l);let u=ar(e.operationId,i,c.data);if(!u.ok)return u;let d=ln(e.operationId,i,c.data);if(d!==null)return C(d);let f=sr(e.operationId,i,t);if(!f.ok)return f;if(c.data===void 0&&f.data===void 0)return i.required?C(pr(e.operationId,i)):S(`No body`,void 0);let p=lr(e.operationId,i,c.data,f.data);if(!p.ok||p.data===void 0)return p;if(i.schemaType===`array`&&!Array.isArray(p.data))return C(`${e.operationId} requires a JSON array body.`);if(i.parameter.length>0&&!R(p.data)){let t=i.kind===`multipart`?` keyed by multipart part name`:` body`;return C(`${e.operationId} requires a JSON object${t}.`)}let m=ir(i,p.data);if(m.length>0)return C(`${e.operationId} requires body option(s): ${m.join(`, `)}`);let h=p.data,g=R(h)?un(i).filter(e=>!Cn(h,e)):[];return g.length>0?C(rr(e.operationId,i,g)):p}function tr(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`${z(t)} requires ${Jn} ${i.join(` or `)}.`}return null}function nr(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 rr(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 ir(e,t){return R(t)?e.parameter.filter(e=>e.required&&!Cn(t,e.name)).map(z):[]}function ar(e,t,n){let r=En(t,n);if(r===null)return S(`Body file paths validated`,null);let i=r.suggestion===void 0?``:` Use ${r.suggestion}.`;return C(`${e} --from-file contains unknown JSON path ${r.path}.${i}`)}async function or(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 Kn(t);if(!n.ok)return C(n.summary,n.warnings);let r=Se.safeParse(n.data);return r.success?S(`Input parsed`,r.data):C(`Input is not valid JSON value: ${r.error.message}`)}function sr(e,t,n){let r={},i=!1;for(let e of t.parameter){let a=hn(e,n[e.optionKey]);if(!a.ok||a.data===null)return C(a.summary,a.warnings);let o=a.data;if(o===void 0)continue;let s=cr(t,n,r,e,o);if(!s.ok)return C(s.summary,s.warnings);i=!0}if(!i)return S(`No direct body options`,void 0);let a=yn(e,t,n,r);return a===null?S(`Direct body options parsed`,r):a}function cr(e,t,n,r,i){let a=_n(r,i);if(a===null){let e=dr(r,i);return e.ok?dn(n,r.name,e.data,r.schemaType===`array`):C(e.summary,e.warnings)}if(a.plain.length>0)return C(`${z(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=vn(e,t,a.container);for(let e of a.rows.keys())if(!(e<o))return C(`${z(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=fr(r.name,r.itemSchemaType,e);if(!t.ok)return C(t.summary,t.warnings);i.push(t.data)}let a=fn(n,r.name,e,i);if(!a.ok)return a}return S(`Body value assigned`,null)}var z=e=>e.flag.split(` `)[0]??e.name;function lr(e,t,n,r){if(n===void 0)return S(`Direct body parsed`,r);if(r===void 0)return S(`Input parsed`,n);if(R(n)&&R(r))try{return S(`Input parsed`,ur(t,n,r))}catch(t){return C(`${e} ${t instanceof Error?t.message:String(t)}`)}return C(`${e} cannot combine --from-file with direct body options unless the file body is an object.`)}function ur(e,t,n,r=``){let i={...t};for(let[t,a]of Object.entries(n)){let n=i[t],o=`${r}${t}`;if(R(n)&&R(a))i[t]=ur(e,n,a,`${o}.`);else if(n===void 0||n===a)i[t]=a;else throw Error(`sets JSON key '${o}' both in --from-file and with ${e.parameter.find(({name:e})=>e===o)?.flag.split(` `)[0]??`body options`} — set it in one place${Array.isArray(n)?`: move the per-item fields inside the matching '${o}[]' object(s) in the file body`:Ve.test(o)?`; keep multi-line text in the --from-file body`:``}.`)}return i}function dr(e,t){if(typeof t==`boolean`)return S(`Body value parsed`,t);if(t===void 0||typeof t==`string`)return fr(e.name,e.schemaType,t??``);let n=[],r=L(e.name)&&e.schemaType!==`array`?e.schemaType:e.itemSchemaType;for(let i of t){let t=fr(e.name,r,i);if(!t.ok)return t;n.push(t.data)}return S(`Body value parsed`,n)}function fr(e,t,n){if(t===`boolean`)return n===`true`?S(`Body value parsed`,!0):n===`false`?S(`Body value parsed`,!1):C(`${e} must be true or false.`);if(t===`number`||t===`integer`){let r=n.trim(),i=Number(r);return r===``||!Number.isFinite(i)?C(`${e} must be a finite ${t}.`):t===`integer`&&!Number.isInteger(i)?C(`${e} must be an integer.`):S(`Body value parsed`,i)}return S(`Body value parsed`,n)}function pr(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(z).join(`, `)}`;let r=un(t);if(r.length>0)return`${e} requires --from-file with JSON body path(s): ${r.join(`, `)}`;let i=t.parameter.map(z).join(`, `);return i.length===0?`${e} requires --from-file`:`${e} requires --from-file or body option(s): ${i}`}function mr(e,t,n){let r=[...t.parameters,...n.map(({variant:e})=>e[0].parameter)];(t.requestBody?.length??0)>1&&r.push({optionKey:`contentType`,flag:Jn,location:`body`}),hr(t)&&r.push({optionKey:`fromFile`,flag:`--from-file`,location:`body`}),Ln(e.options,r)}function hr(e){return(e.requestBody??[]).some(e=>e.kind!==`multipart`||e.parameter.some(e=>e.schemaFormat!==`binary`))}function gr(e,t){let n=t.data,r=`jobId`,i=`statusUrl`,a=t.rolloverJob?.jobId??(typeof n==`object`&&n&&r in n&&typeof n[r]==`string`?n[r]:void 0),o=t.rolloverJob?.statusUrl??t.headers.location??(typeof n==`object`&&n&&i in n&&typeof n[i]==`string`?n[i]:void 0),s=t.headers[`retry-after`],c=`Pending: ${e.operationId??`request`}${a===void 0?``:` job ${a}`} is still running.`+(s===void 0?``:` Retry-After: ${s}.`)+(o===void 0?``:` Poll GET ${o} for the result.`);return{...e,summary:c,warnings:[...e.warnings,c],ids:a===void 0?e.ids:[...new Set([...e.ids,a])],references:o===void 0?e.references:[...new Set([...e.references,o])]}}function _r(e){let t=xe(e,br(e));return Er(t),process.stdout.write(`${JSON.stringify(t)}\n`),t}function vr(e){let t=xe(e,{...br(e),foldRows:!1});Er(t);let n=je(O,t.data,t.summary),r=[];if(t.ok&&n!==null){let e=yr(t);r.push(n.endsWith(`
|
|
1
|
+
import{a as e,n as t,o as n,r,t as i}from"./commander-DEj7N1b9.js";import{_ as a,f as o,h as s,i as c,m as l,o as u,v as d,x as f}from"./logging-D2cJNH4n.js";import{S as p,a as m,b as h,c as g,l as ee,t as te,x as ne,y as re}from"./tool-policy-BjOSkLem.js";import{M as ie,O as ae,i as _,l as oe,o as v,p as se,u as ce,v as le,w as y,y as b}from"./person-owner-C0YuWKvY.js";import{Ar as ue,Br as de,Jr as fe,Mr as x,Pr as pe,Qr as me,Rr as he,Xr as ge,Zr as _e,jr as ve,kr as ye}from"./dist-fXe9nMDe.js";import{c as S,f as be,n as xe,p as Se,r as C}from"./result-envelope-BKQSGfkH.js";import{a as w,n as Ce,r as we,t as Te}from"./package-DPDX5zmx.js";import{a as Ee,i as De}from"./response-problem-DG4194cZ.js";import{n as Oe,r as ke}from"./output-spill-5SehC7pV.js";import{_ as Ae,a as je,b as Me,c as Ne,d as Pe,f as Fe,i as Ie,l as Le,m as Re,n as T,o as ze,r as Be,s as Ve,u as He}from"./contract-BSeJEx3C.js";import{T as Ue}from"./detail-2DCBfxlE.js";import{a as We,c as Ge,i as Ke,l as qe,n as Je,s as Ye,t as Xe}from"./cli-help-policy-BfaoryK2.js";import{S as Ze,_ as Qe,a as $e,g as E,h as et,i as tt,m as nt,n as rt,p as it,r as at,s as ot,t as st,v as ct,x as D,y as lt}from"./api-key-bearer-credential-BbO1Igh-.js";import{a as ut,c as dt,d as ft,g as pt,l as mt,m as ht,o as gt,s as _t,t as vt,u as yt}from"./oauth-bearer-credential-CzBRB0__.js";import{n as bt,r as xt,t as St}from"./oauth-login-Cma_FBmS.js";import{a as Ct,c as wt,d as Tt,i as Et,l as Dt,n as Ot,o as kt,s as At,t as jt,u as Mt}from"./startup-auth-CIGeUrGQ.js";import{n as Nt,t as O}from"./openapi-commands-Hbk5R8_d.js";import{i as k,r as Pt,t as A}from"./output-mode-CBmpDQfL.js";import{spawnSync as Ft}from"node:child_process";import{basename as j,dirname as M,relative as It,resolve as N,sep as Lt}from"node:path";import{copyFileSync as Rt,existsSync as P,lstatSync as zt,mkdirSync as Bt,mkdtempSync as Vt,readFileSync as Ht,readdirSync as Ut,readlinkSync as Wt,realpathSync as Gt,renameSync as Kt,symlinkSync as qt,writeFileSync as Jt}from"node:fs";import F,{stderr as I,stdin as Yt}from"node:process";import{TextDecoder as Xt,inspect as Zt}from"node:util";import{homedir as Qt,hostname as $t,platform as en}from"node:os";import{fileURLToPath as tn}from"node:url";import{setTimeout as nn}from"node:timers/promises";import{randomUUID as rn,webcrypto as an}from"node:crypto";import{readFile as on}from"node:fs/promises";import{createInterface as sn}from"node:readline/promises";function cn(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{...C(`${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 ln(e,t,n){if(!L(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||!Cn(n,r.name))continue;let a=Sn(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 un(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 dn(e,t,n,r=!1){if(r||!En(t)||!Array.isArray(n))return On(e,t,n);for(let[r,i]of n.entries()){let n=On(e,t,i,r);if(!n.ok)return n}return S(`Body value assigned`,null)}function fn(e,t,n,r){return On(e,t,r,n)}function pn(e){let t=[];for(let n of e.split(`.`)){let e=An(n);if(t.push(e.key),e.isArray)return t.join(`.`)}return null}function mn(e,t){let n=pn(t);if(n===null)return null;let r=xn(e,n.split(`.`));return Array.isArray(r)?{path:n,rowCount:r.length,firstHole:bn(r)}:null}function hn(e,t){if(En(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]):C(`${n} was already given; pass it once.`)}var gn=/^(?<row>\d+):(?<item>.*)$/su;function _n(e,t){let n=pn(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=gn.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 vn(e,t,n){let r=0;for(let i of e.parameter){let e=t[i.optionKey];e!==void 0&&typeof e!=`boolean`&&pn(i.name)===n&&(r=Math.max(r,typeof e==`string`?1:e.length))}return r}function yn(e,t,n,r){for(let i of t.parameter){let t=n[i.optionKey];if(t===void 0)continue;let a=mn(r,i.name);if(a===null)continue;if(a.firstHole!==null)return C(`${e} has no ${a.path}[] row ${a.firstHole} — number ${a.path}[] rows from 0 with no gaps.`);if(i.schemaType!==`array`||a.rowCount<=1||_n(i,t)!==null)continue;let o=i.flag.split(` `)[0]??i.name;return C(`${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 bn(e){for(let t=0;t<e.length;t+=1)if(e[t]===void 0)return t;return null}function xn(e,t){let n=e;for(let e of t){if(!L(n))return;n=n[e]??null}return n}function Sn(e,t){if(!En(t))return xn(e,t.split(`.`))}function Cn(e,t){return Tn(e,t.split(`.`))}function wn(e,t,n){if(!L(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)&&Cn(n,e.name))return`${e.name} in --from-file requires --content-type ${i.contentType}.`}return null}function Tn(e,t){let[n,...r]=t;if(n===void 0)return!0;let i=An(n);if(!L(e)||!Object.hasOwn(e,i.key))return!1;let a=e[i.key]??null;return i.isArray?Array.isArray(a)&&a.every(e=>Tn(e,r)):Tn(a,r)}function En(e){return e.split(`.`).some(e=>An(e).isArray)}function Dn(e,t){return e.parameter.length===0||!L(t)?null:Mn(t,[],jn(e.parameter))}function L(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function On(e,t,n,r=0){let i=t.split(`.`),a=e;for(let[e,o]of i.entries()){let s=An(o),c=e===i.length-1,l=kn(a,s,t,c,n,r);if(!l.ok||l.data===null)return C(l.summary,l.warnings);if(c)return S(`Body value assigned`,null);a=l.data}return C(`${t} is not a valid body option path.`)}function kn(e,t,n,r,i,a){let o=()=>C(`${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 L(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 L(s)?S(`Body path stepped`,s):o()}function An(e){let t=e.endsWith(`[]`);return{key:t?e.slice(0,-2):e,isArray:t}}function jn(e){let t=new Set,n=new Set;for(let r of e){let e=`${r.name}${r.schemaType===`array`?`[]`:``}`;t.add(e);let i=e.split(`.`);for(let e=1;e<i.length;e+=1)n.add(i.slice(0,e).join(`.`))}return{leaf:t,prefix:n}}function Mn(e,t,n){if(Array.isArray(e)){if(e.length===0)return null;for(let r of e){let e=Mn(r,t,n);if(e!==null)return e}return null}if(!L(e))return null;for(let[r,i]of Object.entries(e)){let e=[...t,Array.isArray(i)?`${r}[]`:r],a=e.join(`.`);if(i===null&&Nn(`${a}[]`,n))continue;if(!Nn(a,n)){if(!Pn(e))continue;let t=Fn(e,n);return{path:a,...t===void 0?{}:{suggestion:t}}}let o=Mn(i,e,n);if(o!==null)return o}return null}function Nn(e,t){return t.prefix.has(e)||t.leaf.has(e)}function Pn(e){return e.slice(0,-1).some(e=>e.endsWith(`[]`))}function Fn(e,t){let n=e.slice(0,-1).join(`.`),r=e.at(-1)?.replace(/\[\]$/u,``).toLowerCase()??``;return[...t.leaf].filter(e=>e.split(`.`).slice(0,-1).join(`.`)===n).map(e=>({path:e,score:In(r,e.split(`.`).at(-1)??``)})).filter(({score:e})=>e<1/0).toSorted((e,t)=>e.score-t.score||e.path.localeCompare(t.path))[0]?.path}function In(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}var Ln=e=>Array.isArray(e)&&!Object.isFrozen(e);function Rn(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(Ge(e)),t.description=pe(t.description,{...e,hasParseDefault:t.defaultValue!==void 0}))}if(!Ln(e))throw Error(`Commander option list is frozen; generated option help cannot be ordered.`);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?Kn(r,i):r===void 0?i===void 0?0:1:-1})}function zn(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 Bn(e){let{flag:t}=e.variant[0].parameter;return e.variant.every(({parameter:e})=>e.flag===t)?t:`${t.split(` `)[0]??t} <value>`}function Vn(e){let t=e.variant.map(({descriptor:e,parameter:t})=>({contentType:e.contentType,text:Wn(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 Hn(e,t){return[...new Set((e.cliConflicts??[]).filter(e=>e.includes(t)).flatMap(e=>e.filter(e=>e!==t)))]}function Un(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?qe(n):`${qe(n)} Required JSON paths: ${r.join(`, `)}.`}function Wn(e,t){let n=We(t.description,void 0),r=e.kind!==`multipart`&&En(t.name),i=e.kind!==`multipart`&&t.optionKey!==t.name&&/^\w+$/u.test(t.name);return`${n}${r?` Repeat to add another value.`:``}${i?` --from-file JSON key: ${t.name}.`:``}${Gn(e,t)}`}function Gn(e,t){if(e.kind===`multipart`||t.schemaType!==`array`)return``;let n=pn(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 Kn(e,t){return Ye(e)-Ye(t)||Number(e.required!==!0)-Number(t.required!==!0)}async function qn(e){let t;try{t=e===`-`?await Jn():await on(e,`utf8`)}catch(t){return C(`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 C(`Input is not valid JSON: ${e.message}`)}}async function Jn(){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 Yn=`--content-type`;function Xn(e,n,r){let i=e=>!r?.has(e)&&(r?.add(e),!0),a=n.requestBody??[];if(a.length>1&&i(Yn)){let n=a.map(({contentType:e})=>e);e.addOption(new t(`${Yn} <media-type>`,`Select the request body encoding, never an uploaded file's media type; omit for ${n[0]}.`).choices(n).argParser(Qn(a)))}if(gr(n)&&i(`--from-file`)){let r=a[0];if(r===void 0)throw Error(`${n.operationId} has no request body`);e.addOption(new t(`--from-file <path>`,Un(r,r.requiredPath)).argParser(er(`--from-file`)))}let o=zn(a).filter(e=>i(R(e.variant[0].parameter)));for(let n of o.toSorted((e,t)=>Kn(e.variant[0].parameter,t.variant[0].parameter))){let{descriptor:r,parameter:i}=n.variant[0],o=new t(Bn(n),a.length>1?Vn(n):Wn(r,i));a.length===1&&i.envName!==void 0&&o.env(i.envName);let s=a.length===1?Hn(r,i.optionKey):[];s.length>0&&o.conflicts(s),a.length>1?o.argParser(Zn):En(i.name)||i.schemaType===`array`?o.argParser($n):o.argParser(er(i.flag)),e.addOption(o),o.envVar!==void 0&&e.on(`optionEnv:${o.name()}`,()=>{let t=e.opts()[i.optionKey];typeof t==`string`&&t.trim()&&e.setOptionValueWithSource(i.optionKey,t.trim(),`env`)})}hr(e,n,o)}function Zn(e,t){return t===void 0?e:typeof t==`string`?[t,e]:[...t,e]}function Qn(e){return(t,r)=>{if(r!==void 0)throw new n(`${Yn} was already given; pass it once.`);let i=re(e,t);if(!i.ok)throw new n(i.summary);return t}}function $n(e,t){return[...t??[],e]}function er(e){let t=e.split(/\s+/u)[0]??e;return(e,r)=>{if(r!==void 0)throw new n(`${t} was already given; pass it once.`);return e}}async function tr(e,t){let n=kt(e,t),r=re(e.requestBody??[],n);if(!r.ok||r.data===null)return C(r.summary,r.warnings);let i=r.data;if(i===void 0)return S(`No body`,void 0);let a=nr(e,i,t);if(a!==null)return C(a);let o=cn(e.operationId,i,t);if(!o.ok)return C(o.summary,o.warnings);t=o.data;let s=rr(i,t);if(s!==null)return C(s);let c=await sr(t);if(!c.ok)return C(c.summary,c.warnings);let l=wn(e.requestBody??[],i,c.data);if(l!==null)return C(l);let u=or(e.operationId,i,c.data);if(!u.ok)return u;let d=ln(e.operationId,i,c.data);if(d!==null)return C(d);let f=cr(e.operationId,i,t);if(!f.ok)return f;if(c.data===void 0&&f.data===void 0)return i.required?C(mr(e.operationId,i)):S(`No body`,void 0);let p=ur(e.operationId,i,c.data,f.data);if(!p.ok||p.data===void 0)return p;if(i.schemaType===`array`&&!Array.isArray(p.data))return C(`${e.operationId} requires a JSON array body.`);if(i.parameter.length>0&&!L(p.data)){let t=i.kind===`multipart`?` keyed by multipart part name`:` body`;return C(`${e.operationId} requires a JSON object${t}.`)}let m=ar(i,p.data);if(m.length>0)return C(`${e.operationId} requires body option(s): ${m.join(`, `)}`);let h=p.data,g=L(h)?un(i).filter(e=>!Cn(h,e)):[];return g.length>0?C(ir(e.operationId,i,g)):p}function nr(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`${R(t)} requires ${Yn} ${i.join(` or `)}.`}return null}function rr(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 ir(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 ar(e,t){return L(t)?e.parameter.filter(e=>e.required&&!Cn(t,e.name)).map(R):[]}function or(e,t,n){let r=Dn(t,n);if(r===null)return S(`Body file paths validated`,null);let i=r.suggestion===void 0?``:` Use ${r.suggestion}.`;return C(`${e} --from-file contains unknown JSON path ${r.path}.${i}`)}async function sr(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 qn(t);if(!n.ok)return C(n.summary,n.warnings);let r=Se.safeParse(n.data);return r.success?S(`Input parsed`,r.data):C(`Input is not valid JSON value: ${r.error.message}`)}function cr(e,t,n){let r={},i=!1;for(let e of t.parameter){let a=hn(e,n[e.optionKey]);if(!a.ok||a.data===null)return C(a.summary,a.warnings);let o=a.data;if(o===void 0)continue;let s=lr(t,n,r,e,o);if(!s.ok)return C(s.summary,s.warnings);i=!0}if(!i)return S(`No direct body options`,void 0);let a=yn(e,t,n,r);return a===null?S(`Direct body options parsed`,r):a}function lr(e,t,n,r,i){let a=_n(r,i);if(a===null){let e=fr(r,i);return e.ok?dn(n,r.name,e.data,r.schemaType===`array`):C(e.summary,e.warnings)}if(a.plain.length>0)return C(`${R(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=vn(e,t,a.container);for(let e of a.rows.keys())if(!(e<o))return C(`${R(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=pr(r.name,r.itemSchemaType,e);if(!t.ok)return C(t.summary,t.warnings);i.push(t.data)}let a=fn(n,r.name,e,i);if(!a.ok)return a}return S(`Body value assigned`,null)}var R=e=>e.flag.split(` `)[0]??e.name;function ur(e,t,n,r){if(n===void 0)return S(`Direct body parsed`,r);if(r===void 0)return S(`Input parsed`,n);if(L(n)&&L(r))try{return S(`Input parsed`,dr(t,n,r))}catch(t){return C(`${e} ${t instanceof Error?t.message:String(t)}`)}return C(`${e} cannot combine --from-file with direct body options unless the file body is an object.`)}function dr(e,t,n,r=``){let i={...t};for(let[t,a]of Object.entries(n)){let n=i[t],o=`${r}${t}`;if(L(n)&&L(a))i[t]=dr(e,n,a,`${o}.`);else if(n===void 0||n===a)i[t]=a;else throw Error(`sets JSON key '${o}' both in --from-file and with ${e.parameter.find(({name:e})=>e===o)?.flag.split(` `)[0]??`body options`} — set it in one place${Array.isArray(n)?`: move the per-item fields inside the matching '${o}[]' object(s) in the file body`:Ve.test(o)?`; keep multi-line text in the --from-file body`:``}.`)}return i}function fr(e,t){if(typeof t==`boolean`)return S(`Body value parsed`,t);if(t===void 0||typeof t==`string`)return pr(e.name,e.schemaType,t??``);let n=[],r=En(e.name)&&e.schemaType!==`array`?e.schemaType:e.itemSchemaType;for(let i of t){let t=pr(e.name,r,i);if(!t.ok)return t;n.push(t.data)}return S(`Body value parsed`,n)}function pr(e,t,n){if(t===`boolean`)return n===`true`?S(`Body value parsed`,!0):n===`false`?S(`Body value parsed`,!1):C(`${e} must be true or false.`);if(t===`number`||t===`integer`){let r=n.trim(),i=Number(r);return r===``||!Number.isFinite(i)?C(`${e} must be a finite ${t}.`):t===`integer`&&!Number.isInteger(i)?C(`${e} must be an integer.`):S(`Body value parsed`,i)}return S(`Body value parsed`,n)}function mr(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(R).join(`, `)}`;let r=un(t);if(r.length>0)return`${e} requires --from-file with JSON body path(s): ${r.join(`, `)}`;let i=t.parameter.map(R).join(`, `);return i.length===0?`${e} requires --from-file`:`${e} requires --from-file or body option(s): ${i}`}function hr(e,t,n){let r=[...t.parameters,...n.map(({variant:e})=>e[0].parameter)];(t.requestBody?.length??0)>1&&r.push({optionKey:`contentType`,flag:Yn,location:`body`}),gr(t)&&r.push({optionKey:`fromFile`,flag:`--from-file`,location:`body`}),Rn(e.options,r)}function gr(e){return(e.requestBody??[]).some(e=>e.kind!==`multipart`||e.parameter.some(e=>e.schemaFormat!==`binary`))}function _r(e,t){let n=t.data,r=`jobId`,i=`statusUrl`,a=t.rolloverJob?.jobId??(typeof n==`object`&&n&&r in n&&typeof n[r]==`string`?n[r]:void 0),o=t.rolloverJob?.statusUrl??t.headers.location??(typeof n==`object`&&n&&i in n&&typeof n[i]==`string`?n[i]:void 0),s=t.headers[`retry-after`],c=`Pending: ${e.operationId??`request`}${a===void 0?``:` job ${a}`} is still running.`+(s===void 0?``:` Retry-After: ${s}.`)+(o===void 0?``:` Poll GET ${o} for the result.`);return{...e,summary:c,warnings:[...e.warnings,c],ids:a===void 0?e.ids:[...new Set([...e.ids,a])],references:o===void 0?e.references:[...new Set([...e.references,o])]}}function vr(e){let t=xe(e,xr(e));return Dr(t),process.stdout.write(`${JSON.stringify(t)}\n`),t}function yr(e){let t=xe(e,{...xr(e),foldRows:!1});Dr(t);let n=je(O,t.data,t.summary),r=[];if(t.ok&&n!==null){let e=br(t);r.push(n.endsWith(`
|
|
2
2
|
`)?n.slice(0,-1):n),r.push(...e),process.stdout.write(de(r.join(`
|
|
3
|
-
`),{appendNewline:!0,preservedTrailerLines:e.length}));return}let i=t.ok?`OK`:`FAIL`;r.push(`[${i}] ${t.summary}`),!t.ok&&t.problem!==void 0&&r.push(...
|
|
4
|
-
`),{appendNewline:!0}))}function
|
|
5
|
-
`),process.exitCode=1
|
|
6
|
-
`)}function
|
|
7
|
-
`)?i:`${i}\n`;
|
|
8
|
-
`)?n.data:`${n.data}\n`)}function
|
|
9
|
-
`):t===`text
|
|
10
|
-
`):e.operation.map(
|
|
11
|
-
`)}function
|
|
12
|
-
`)}function
|
|
13
|
-
`)).argument(`[command...]`,"command path, operationId, or METHOD and path, e.g. `help entities get`"),r.addOption(new ni(r)),r.hook(`preSubcommand`,e=>{e.opts().help&&e.help()});let i=ci(t);i!==void 0&&r.option(`--ask <question>`,i.summary),A(r),r.action(async function(r){let a=this.optsWithGlobals();if(a.help&&r.length===0){this.outputHelp();return}if(!a.help&&i!==void 0&&a.ask!==void 0){let e=k(a);if(r.length>0){B({mode:e},C(`Use either a command path or --ask, not both.`));return}B({mode:e},await fi(i,a.ask,a.environment,e));return}let o=di(e,r),s=t.find(t=>o!==void 0&&di(e,t.cliPath)===o);if(a.help||o!==void 0&&s===void 0){o===void 0&&this.error(`unknown command '${r.join(` `)}' (run \`${n} --help\` for the command tree)`),o.outputHelp();return}let c=s===void 0?ui(r,t):S(`Resolved by command path`,{operationId:s.operationId});if(c.ok&&c.data?.command!==void 0&&this.error(`unknown command '${r.join(` `)}' (run \`${n} --help\` for the command tree)`),!c.ok||c.data===null){B({mode:k(a)},c);return}Wr({...a,...c.data},t,k(a,`text`),n)}),si(e,t,n)}var ni=class extends t{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))}},ri=2,ii=6,ai={formatHelp(e,t){let n=n=>r.prototype.formatHelp.call(this,e,Object.assign(Object.create(t),n));if(t.visibleCommands(e).length===0)return n({});let i=t.padWidth(e,t),a={padWidth:()=>i,visibleOptions:()=>[],showGlobalOptions:!1},o=n({...a,visibleCommands:()=>[]}),s=n({padWidth:()=>i,visibleCommands:()=>[]}).slice(o.length);return n(a)+s},visibleCommands(e){let t=r.prototype.visibleCommands.call(this,e);return e.parent===null?t.filter(e=>!Je.has(e.name())):t},subcommandTerm(e){let t=r.prototype.subcommandTerm.call(this,e);return e.commands.length>0&&e.registeredArguments.length===0?`${t} <command>`:t},formatItem(e,t,n,i){let a=i.helpWidth??80,o=a-t-4;return n===``||o>=i.minWidthToWrap?r.prototype.formatItem.call(i,e,t,n,i):`${` `.repeat(ri)}${e}\n${oi(n,a,i)}`}};function oi(e,t,n){return n.boxWrap(e,t-ii).replace(/^/gmu,` `.repeat(ii))}function si(e,t,n){for(let r of t){let i=di(e,r.cliPath);i!==void 0&&i.addHelpText(`after`,()=>{let e=i.createHelp(),a=i.configureOutput().getOutHelpWidth?.();e.prepareContext(a===void 0?{}:{helpWidth:a});let o=e.helpWidth??80,s=Le(r.operationId,t,n),[c,...l]=Pr(r.errorResponse),u=l.map(t=>oi(t.trimStart(),o,e).replace(/^ +/u,` `.repeat(ri))),d=c===void 0?[]:[``,c,...u];return`\n${[...s,...d].join(`
|
|
14
|
-
`)}\n`})}}function ci(e){let[t,...n]=e.filter(e=>{let[t,n,...r]=e.cliPath;return t===`help`&&n!==void 0&&r.length===0&&pi(e)!==void 0});return n.length===0?t:void 0}var li='Accepted selectors: `<METHOD> <route template or concrete path>`, an operationId, or a CLI command path such as "entities get".';function ui(e,t){let[n=``,...r]=e.join(` `).trim().split(/\s+/u),[i,...a]=t.filter(e=>e.path===n);if(r.length===0&&i!==void 0)return a.length===0?S(`Resolved by route`,{operationId:i.operationId}):C(`${n} is served by ${[i,...a].map(({method:e})=>e).join(`, `)}; name the method, as in \`help ${i.method} ${n}\`.`,[li]);let o=h.find(e=>e===n.toLowerCase());if(o===void 0||r.length===0){let n=e.join(` `).trim();return S(`Resolved by name`,t.some(e=>e.operationId===n)?{operationId:n}:{command:n})}let s=ne(o),c=r.join(``),l=t.find(e=>e.method===s&&e.path===c);if(l!==void 0)return S(`Resolved by route template`,{operationId:l.operationId});let u=ve({method:s,path:c});return!u.ok||u.data===null?C(u.summary,[...u.warnings,li]):S(`Resolved by method and path`,{operationId:u.data.operation.operationId})}function di(e,t){let n=e;for(let e of t){let t=n.commands.find(t=>t.name()===e||t.aliases().includes(e));if(t===void 0)return;n=t}return n}async function fi(e,t,n,r){let i=pi(e);if(i===void 0)return C(`The \`${e.cliPath.join(` `)}\` operation no longer takes a single required text body; run it directly instead of \`help --ask\`.`);n!==void 0&&(process.env.API_ENV=n);let a=await er(e,{[i.optionKey]:t});return a.ok?await x({method:e.method,path:ue(e.operationId,{}),searchParams:{},body:a.data,auth:e.auth,responseFormat:Pt(r)?`json`:`auto`}):a}function pi(e){if(e.requestBody?.length!==1||e.parameters.some(e=>e.required))return;let t=(e.requestBody[0]?.parameter??[]).filter(e=>e.required);return t.length===1&&t[0]?.schemaType===`string`?t[0]:void 0}function mi(e,t,n){if(e.cliPath[0]!==`lookup`||!hi(n))return null;let r=e.parameters.filter(e=>t[e.optionKey]!==void 0).map(e=>`${e.name}=${String(t[e.optionKey])}`),i=`no record for ${r.length===0?`the given input`:r.join(`, `)}`;return n.ok?C(i):C(i,[],{httpStatus:n.httpStatus,problem:n.problem})}function hi(e){return e.ok?Array.isArray(e.data)&&e.data.length===0:e.httpStatus===404}function gi(e,t){if(e.deprecated!==!0)return t;let n=e.description.match(/^Deprecated:[^.]*\./u)?.[0]??`Deprecated; run \`help ${e.cliPath.join(` `)}\` for its replacement.`;return{...t,warnings:[n,...t.warnings]}}var _i=b({artifact:y().nullish(),group:y().nullish(),name:y().nullish(),revision:y().nullish(),time:_({offset:!0}).nullish(),version:y().nullish()}),vi=b({build:_i}),yi=v([`MACOS`,`LINUX`,`WINDOWS`,`OTHER`]),bi=v([`RSA_OAEP_256_A256_GCM_V1`]),xi=b({clientLabel:y().regex(/.*\S.*/).min(1).max(120).nullish(),clientPlatform:yi.nullish(),encryptionAlgorithm:bi.nullish(),encryptionPublicKey:y().min(344).max(12e3).nullish()}),Si=32;async function Ci(){let e=await an.subtle.generateKey({name:`RSA-OAEP`,modulusLength:2048,publicExponent:new Uint8Array([1,0,1]),hash:`SHA-256`},!0,[`encrypt`,`decrypt`]),t=await an.subtle.exportKey(`spki`,e.publicKey);return{publicKey:Buffer.from(t).toString(`base64`),privateKey:e.privateKey}}async function wi(e,t){let{wrappedKey:n,nonce:r,ciphertext:i,authenticationTag:a}=t,o=Ti(n,`wrapped key`,128,1024),s=Ti(r,`nonce`,12,12),c=Ti(i,`ciphertext`,1,65536),l=Ti(a,`authentication tag`,16,16),u;try{u=await an.subtle.decrypt({name:`RSA-OAEP`},e,o)}catch{throw Error(`broker credential key could not be decrypted`)}let d=new Uint8Array(u);try{if(d.byteLength!==Si)throw Error(`broker credential used an invalid AES-256 key`);let e=await an.subtle.importKey(`raw`,d,{name:`AES-GCM`},!1,[`decrypt`]),t=new Uint8Array(c.byteLength+l.byteLength);t.set(c),t.set(l,c.byteLength);let n;try{n=await an.subtle.decrypt({name:`AES-GCM`,iv:s,tagLength:128},e,t)}catch{throw Error(`broker credential payload failed authentication`)}let r=new Xt(`utf-8`,{fatal:!0}).decode(n);if(r.trim().length===0)throw Error(`broker returned a blank credential`);return r}finally{d.fill(0)}}function Ti(e,t,n,r){let i=e.replace(/=+$/u,``),a=Uint8Array.from(Buffer.from(e,`base64`)),o=Buffer.from(a).toString(`base64`).replace(/=+$/u,``);if(i.length===0||o!==i||a.byteLength<n||a.byteLength>r)throw Error(`broker returned an invalid ${t}`);return a}var Ei=v([`PENDING`,`ISSUING`,`KEY_READY`,`REVOKING`,`CONSUMED`,`REVOKED`,`DENIED`,`EXPIRED`,`FAILED`]),Di=v([`Denied by user`,`Authorization request expired`,`CLI authorization expired before acknowledgement`,`Credential issuance recovery revoked an unrecoverable key`,`Revoked by user`,`Clerk create response validation failed`,`Credential issuance failed`,`Credential issuance could not be recovered`,`API-key quota reached`,`Credential issuance lost its database claim`,`Credential delivery encryption failed`,`Credential issuance finalization was lost`]),Oi=b({approvedAt:_({offset:!0}).nullish(),clientLabel:y(),clientPlatform:yi,comparisonCode:y(),consumedAt:_({offset:!0}).nullish(),createdAt:_({offset:!0}),expiresAt:_({offset:!0}),id:ae(),intervalSeconds:le().int().min(1),keyReadyAt:_({offset:!0}).nullish(),status:Ei,terminalAt:_({offset:!0}).nullish(),terminalReason:Di.nullish(),updatedAt:_({offset:!0})}),ki=b({algorithm:bi,authenticationTag:y(),ciphertext:y(),nonce:y(),wrappedKey:y()}),Ai=b({delivery:ki.nullish(),expiresAt:_({offset:!0}),status:Ei,terminalReason:Di.nullish()}),ji=b({comparisonCode:y(),expiresAt:_({offset:!0}),id:ae(),intervalSeconds:le().int().min(1),pollSecret:y(),verificationUrl:y()}),H=[{command:`auth login`,role:`oauth`,summary:`Sign In Through Your Browser`,description:`Sign in through your browser and save verified CLI access in the credential store. Use --no-browser for OAuth device authorization only when the issuer advertises device-grant support; otherwise use --key --no-browser for API-key approval.`,operationId:`getAuthProviderCatalog`,method:`GET`,path:`/v1/auth/providers`,bodyOption:[],localOption:[{optionKey:`browser`,flag:`--no-browser`,description:`Use OAuth device authorization only when the issuer advertises device-grant support: print a sign-in URL and code, then wait for approval. Otherwise use --key --no-browser for API-key approval.`},{optionKey:`providers`,flag:`--providers`,description:`Print the sign-in providers and CLI OAuth client, then exit without signing in.`}]},{command:`auth login`,role:`start`,summary:`Sign In With a Browser-Approved aVenture API Key`,description:`Creates a short-lived browser approval request and returns its poll credential once.`,operationId:`createCliAuthorization`,method:`POST`,path:`/v1/auth/cli-authorizations`,bodyOption:[{name:`clientLabel`,optionKey:`clientLabel`,flag:`--client-label <client-label>`,required:!1,description:`Label for this CLI installation.`}],localOption:[{optionKey:`key`,flag:`--key`,description:`Sign in with a browser-approved aVenture API key instead of OAuth; the approval URL opens on any device.`},{optionKey:`browser`,flag:`--no-browser`,description:`Print the API-key approval URL and wait for approval without opening a browser.`}]},{command:`auth login`,role:`poll`,summary:`Poll CLI Authorization`,description:`Returns pending state, a terminal state, or an encrypted one-time credential delivery.`,operationId:`pollCliAuthorization`,method:`POST`,path:`/v1/auth/cli-authorizations/{cliAuthorizationId}/poll`,bodyOption:[],localOption:[]},{command:`auth login`,role:`acknowledge`,summary:`Acknowledge CLI Credential Delivery`,description:`Confirms the CLI stored the delivered API key in its credential store and clears transient delivery material.`,operationId:`acknowledgeCliAuthorization`,method:`POST`,path:`/v1/auth/cli-authorizations/{cliAuthorizationId}/acknowledge`,bodyOption:[],localOption:[]},{command:`auth logout`,role:`revoke`,summary:`Sign Out: Revoke the API Key and Forget Stored OAuth`,description:`Revokes the aVenture API key authenticating this request and returns its metadata so the CLI can confirm revocation before deleting its saved copy.`,operationId:`revokeCurrentApiKey`,method:`DELETE`,path:`/v1/auth/api-key`,bodyOption:[],localOption:[{optionKey:`forgetLocal`,flag:`--forget-local`,description:`Delete the saved key even when revocation cannot be confirmed.`}]}],Mi=T(H,`start`),Ni=T(H,`poll`),Pi=T(H,`acknowledge`),U=class extends Error{httpStatus;retryAfterSeconds;retryable;constructor(e,t,n=[]){super(`CLI authorization ${e} failed: ${Qe(t,n)}`),this.name=`CliAuthorizationRequestError`,this.httpStatus=t.status,this.retryAfterSeconds=Bi(t.retryAfterSeconds),this.retryable=t.status>=500||t.status===429}},Fi=class extends Error{constructor(e,t,n=[]){super(`CLI authorization ${e} transport failed: ${E(t,n)}`,{cause:t}),this.name=`CliAuthorizationTransportError`}};async function Ii(e){let t=await ge(Ze(f()),{method:Mi.method,path:p(Mi.path,{},Mi.operationId),headers:{},contentType:`application/json`,body:e},ji);if(t.ok&&t.redirect)throw new U(`start`,Vi(t.status));if(!t.ok)throw new U(`start`,t.problem);return Hi(t.data)}async function Li(e,t){let n=fe(Ni.operationId),r=await ge(Ze(f()),{method:Ni.method,path:p(Ni.path,{cliAuthorizationId:e},Ni.operationId),headers:{[n]:t}},Ai);if(r.ok&&r.redirect)throw new U(`poll`,Vi(r.status),[t]);if(!r.ok)throw new U(`poll`,r.problem,[t]);return{authorization:r.data,retryAfterSeconds:zi(r.headers[`retry-after`])}}async function Ri(e,t){let n=fe(Pi.operationId),r;try{r=await ge(Ze(f()),{method:Pi.method,path:p(Pi.path,{cliAuthorizationId:e},Pi.operationId),headers:{[n]:t}},Oi)}catch(e){throw new Fi(`acknowledge`,e,[t])}if(r.ok&&r.redirect)throw new U(`acknowledge`,Vi(r.status),[t]);if(!r.ok)throw new U(`acknowledge`,r.problem,[t]);return r.data}function zi(e){if(e===void 0)return null;let t=Number(e);return Number.isInteger(t)&&t>0?t:null}function Bi(e){return typeof e==`number`&&Number.isInteger(e)&&e>0?e:null}function Vi(e){return{status:e,title:`Unexpected redirect`,type:`about:blank`,code:void 0,detail:`CLI authorization endpoint returned an unexpected redirect`}}function Hi(e){let{verificationUrl:t,pollSecret:n,...r}=e,i={...e},a=()=>({...r,verificationUrl:`<redacted>`,pollSecret:`<redacted>`});return Object.defineProperties(i,{verificationUrl:{enumerable:!1,get:()=>t},pollSecret:{enumerable:!1,get:()=>n},toJSON:{enumerable:!1,value:a},toString:{enumerable:!1,value:()=>`CliAuthorizationStart(${JSON.stringify(a())})`},[Zt.custom]:{enumerable:!1,value:a}})}async function Ui(e){let t=await Wi(e.credential.secret);if(t.state!==`verified`||e.activation!==`active`)return{stored:e,verification:t};try{return{stored:await $e(e.host,{apiKey:t.apiKey,secret:e.credential.secret},`active`),verification:t}}catch(n){return{stored:e,verification:{state:`unavailable`,summary:`${t.summary}, but the cached metadata could not be updated — ${E(n,[e.credential.secret])}`}}}}async function Wi(e){let t=Ze(f()),n;try{n=await ge(t,{method:`GET`,path:ue(`getCurrentApiKey`,{}),headers:{Authorization:`Bearer ${e}`}},ct)}catch(t){return{state:`unavailable`,summary:`identity verification failed before an HTTP response — ${E(t,[e])}`}}return n.ok&&n.redirect?{state:`unavailable`,summary:`identity verification returned unexpected redirect ${n.status}`}:n.ok?n.data.status===`ACTIVE`?{state:`verified`,summary:`API key verified by aVenture sign-in`,apiKey:n.data}:{state:`invalid`,summary:`API key is not active`}:{state:n.problem.status===401||n.problem.status===403?`invalid`:`unavailable`,summary:`identity verification: ${Qe(n.problem,[e])}`}}var Gi=T(H,`revoke`);async function Ki(e){let t;try{t=D(f().host)}catch(e){return C(`auth logout: invalid API host — ${E(e)}`)}let n=await qi(t),r=await Xi(t,e),i=n.state===`failed`?[`OAuth credential could not be removed — ${n.summary}`]:n.state===`forgotten`&&!n.revoked?[`OAuth refresh token was not revoked remotely — ${n.summary??`no revocation endpoint`}`]:[],a={host:t,revoked:!1,forgotten:!1,oauth:n};return r===null?n.state===`missing`?S(`No CLI credential is stored for this API host.`,a):n.state===`failed`?{...C(`auth logout: ${i[0]}`),data:a}:S(n.revoked?`OAuth credential revoked remotely and removed locally.`:`OAuth credential removed locally.`,a,{warnings:i}):{...r,data:{...r.data??a,oauth:n},warnings:[...r.warnings,...i]}}async function qi(e){let t=await gt(e);if(t.state===`missing`)return{state:`missing`};let n=t.state===`found`?await Yi(t.stored):{revoked:!1};try{await ut(e)}catch(e){return{state:`failed`,summary:E(e)}}return{state:`forgotten`,...n}}async function Ji(e){let t=Reflect.get(await St(e),`revocation_endpoint`);return typeof t==`string`?pt(t,`revocation endpoint`,!0):void 0}async function Yi(e){let{client:t,tokens:n}=e.credential,r=n.refresh_token??n.access_token;try{let e=await Ji(t);if(e===void 0)return{revoked:!1};let n=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/x-www-form-urlencoded`},body:new URLSearchParams({token:r,client_id:yt(t)})});return n.ok?{revoked:!0}:{revoked:!1,summary:`revocation endpoint answered ${n.status}`}}catch(e){return{revoked:!1,summary:E(e,ht(n))}}}async function Xi(e,t){let n;try{n=await tt(e)}catch(e){return C(`auth logout: stored credential could not be read — ${E(e)}`)}if(n.state===`unavailable`)return{...C(`auth logout: ${n.summary}`),data:{host:e,revoked:!1,forgotten:!1}};if(n.state===`missing`)return null;let r=n.stored,i=await Zi(r),a=i.outcome===`revoked`,o=r.activation===`pending`&&i.outcome===`rejected`;if(!a&&!o&&!t.forgetLocal)return{...C(`auth logout: remote revocation was not confirmed; local credential preserved — ${i.summary}`,[`Retry when the API is available. If an earlier response was lost after revocation, the retry can be unauthorized because revoked keys cannot authenticate.`,"Use `--forget-local` only to remove local bytes while accepting that the remote key may remain active."]),data:Qi(r,!1,!1)};try{await rt(r.host)}catch(e){return{...C(`auth logout: local credential removal failed — ${E(e,[r.credential.secret])}`,[a?"The remote key is revoked. Re-run with `--forget-local` to retry local cleanup.":`Remote revocation was not confirmed; inspect auth status before retrying.`]),data:Qi(r,a,!1)}}return S(a?`API key revoked remotely and removed locally.`:o?`Stale pending CLI credential removed; its remote key can no longer authenticate and unacknowledged keys expire at the authorization deadline.`:`API key removed locally without confirmed remote revocation.`,Qi(r,a,!0),{ids:[r.credential.apiKey.id],warnings:a||o?[]:[`Remote revocation was not confirmed; the API key may remain active.`]})}async function Zi(e){let t=Ze(f());try{let n=await ge(t,{method:Gi.method,path:p(Gi.path,{},Gi.operationId),headers:{Authorization:`Bearer ${e.credential.secret}`}},ct);return n.ok&&n.redirect?{outcome:`unconfirmed`,summary:`remote key revocation returned unexpected redirect ${n.status}`}:n.ok?n.data.id!==e.credential.apiKey.id||n.data.subject!==e.credential.apiKey.subject?{outcome:`unconfirmed`,summary:`remote response did not match the stored API key identity`}:n.data.status===`REVOKED`?{outcome:`revoked`,summary:`remote key revocation confirmed`}:{outcome:`unconfirmed`,summary:`remote response did not confirm REVOKED status`}:{outcome:n.problem.status===401&&n.problem.type!==`about:blank`?`rejected`:`unconfirmed`,summary:Qe(n.problem,[e.credential.secret])}}catch(t){return{outcome:`unconfirmed`,summary:E(t,[e.credential.secret])}}}function Qi(e,t,n){return{host:e.host,apiKeyId:e.credential.apiKey.id,activation:e.activation,revoked:t,forgotten:n}}var $i=`RSA_OAEP_256_A256_GCM_V1`,ea=1,ta=30,na=w().bin[0],ra=`The local record remains pending and unavailable to ordinary commands. Re-run \`${na} auth login --key\`; it recovers the credential when the broker acknowledged it, and otherwise clears the stale record.`;async function ia(e){if(!Yt.isTTY)return C(`${na} auth login --key requires an interactive TTY on stdin`,[`For non-interactive automation, inject AUTH_TOKEN through the environment.`]);let t,n;try{let e=f().host;t=D(e),n=lt(e)}catch(e){return C(`auth login --key: invalid environment configuration — ${E(e)}`)}for(;;){let e;try{e=await at(t)}catch(e){return C(`auth login --key: credential storage could not be inspected — ${E(e)}`)}if(e.state===`unavailable`)return C(`auth login --key: ${e.summary}`,[`Make the OS keyring or the CLI config directory writable, or use AUTH_TOKEN from the environment.`]);if(e.state===`missing`){e.keyringFailure!==void 0&&I.write(ot(e.keyringFailure));break}let n=await aa(e.stored);if(n!==null)return n}let r;try{r=await Ci()}catch(e){return C(`auth login --key: ephemeral encryption key could not be created — ${E(e)}`)}let i=xi.safeParse({clientLabel:e.clientLabel?.trim()||($t().trim()||na).slice(0,120),clientPlatform:la(),encryptionAlgorithm:$i,encryptionPublicKey:r.publicKey});if(!i.success)return C(`auth login --key: ${ie(i.error)}`);let a;try{a=await Ii(i.data)}catch(e){return C(`auth login --key: could not start browser authorization — ${E(e)}`)}let o;try{o=nt(a,n)}catch(e){return C(`auth login --key: unsafe browser authorization URL rejected — ${E(e)}`)}if(!ca(await it(a,n,{noBrowser:e.noBrowser}),a,o))return C(`auth login --key: browser authorization requires an interactive terminal for manual handoff`,[`Automatic browser opening did not complete, and the approval URL was withheld because stderr is not an interactive terminal. Retry from an interactive terminal.`],{references:[o]});let s;try{s=await sa(a)}catch(e){return C(`auth login --key: authorization did not complete — ${E(e)}`,[],{references:[o]})}if(s.algorithm!==$i)return C(`auth login --key: broker selected an unsupported encryption algorithm`);let c;try{c=await wi(r.privateKey,s)}catch(e){return C(`auth login --key: encrypted credential could not be opened — ${E(e)}`)}let l=await Wi(c);if(l.state!==`verified`)return C(`auth login --key: decrypted credential was neither stored nor acknowledged — ${l.summary}`);let u;try{u=await $e(t,{apiKey:l.apiKey,secret:c},`pending`)}catch(e){return C(`auth login --key: credential could not be durably stored — ${E(e)}`)}let d;try{d=await oa(a)}catch(e){return W(u,!0,`auth login --key: credential was stored and verified, but broker acknowledgment was not confirmed — ${E(e,[a.pollSecret])}`,ra)}if(d.status!==`CONSUMED`)return W(u,!0,`auth login --key: broker returned ${d.status} after acknowledgment`,ra);let p=await Wi(c);if(p.state!==`verified`||!pa(p.apiKey,u.credential.apiKey))return W(u,!0,`auth login --key: broker acknowledgment succeeded, but refreshed credential metadata could not prove the granted lifetime — ${p.summary}`,ra);try{let e=await $e(t,{apiKey:p.apiKey,secret:c},`active`);return S(`API key stored; authenticated identity and broker acknowledgment verified.`,fa(e,!0),{ids:[e.credential.apiKey.id]})}catch(e){return W(u,!0,`auth login --key: remote acknowledgment succeeded, but local activation could not be confirmed — ${E(e)}`,ra)}}async function aa(e){let t=await Wi(e.credential.secret);if(e.activation!==`pending`)return t.state===`verified`?S(`API key is already stored and its authenticated identity was verified.`,fa(e,!0),{ids:[e.credential.apiKey.id]}):W(e,!1,`auth login --key: stored credential ${t.state} — ${t.summary}`,`Run \`${na} auth logout\` to revoke/remove it before authorizing a replacement.`);if(t.state===`verified`&&pa(t.apiKey,e.credential.apiKey))try{let n=await $e(e.host,{apiKey:t.apiKey,secret:e.credential.secret},`active`);return S(`Recovered pending CLI credential: broker acknowledgment had succeeded.`,fa(n,!0),{ids:[n.credential.apiKey.id]})}catch(t){return W(e,!0,`auth login --key: credential is valid but could not be promoted locally — ${E(t,[e.credential.secret])}`,`The remote key remains valid. Re-run \`${na} auth login --key\` to retry local activation; it will recover the pending credential automatically.`)}if(t.state===`unavailable`||t.state===`verified`&&!e.credential.apiKey.expiresAt)return W(e,t.state===`verified`,`auth login --key: the stored pending credential acknowledgment could not be verified — ${t.summary}`,t.state===`verified`?`The stored expiry is missing. Both records were preserved; inspect the existing key in your account before deciding how to recover it.`:`The stored record and the remote key were both preserved. Re-run \`${na} auth login --key\` when the API is reachable; it recovers an acknowledged credential and clears an unacknowledged one.`);let n=await Zi(e);if(n.outcome===`unconfirmed`)return W(e,!1,`auth login --key: a prior credential is durably stored but broker acknowledgment was not confirmed`,`Remote revocation of the stale pending key was not confirmed — ${n.summary}. Retry when the API is reachable.`);try{await rt(e.host)}catch(t){return W(e,!1,`auth login --key: stale pending credential could not be removed — ${E(t,[e.credential.secret])}`)}return I.write(n.outcome===`revoked`?`Revoked and cleared a stale pending CLI credential; starting a fresh browser authorization.
|
|
3
|
+
`),{appendNewline:!0,preservedTrailerLines:e.length}));return}let i=t.ok?`OK`:`FAIL`;r.push(`[${i}] ${t.summary}`),!t.ok&&t.problem!==void 0&&r.push(...Cr(t.problem)),r.push(...br(t)),process.stdout.write(de(r.join(`
|
|
4
|
+
`),{appendNewline:!0}))}function br(e){let t=[];e.ids.length>0&&t.push(` ids: ${e.ids.join(`, `)}`);for(let[n,r]of Object.entries(e.counts))t.push(` ${n}: ${r}`);for(let n of e.references)t.push(` ref: ${n}`);if(e.truncation!==void 0){let n=e.truncation.omitted.join(`, `);t.push(` truncated: byteLength=${e.truncation.byteLength} maxBytes=${e.truncation.maxBytes} omitted=${n}`,` recovery: ${e.truncation.recovery}`)}for(let n of e.warnings)t.push(` warn: ${n}`);return t}function z(e,t){let n=ke(t);if(e.mode===`data`||e.mode===`data-full`){let t=e.mode===`data`?xe(n,xr(n)):n;Dr(t),process.stdout.write(`${JSON.stringify(t.ok&&t.truncated!==!0?Oe(t.data):t)}\n`),t.ok||(process.exitCode=1);return}let r=e.mode===`json`?vr(n):n;e.mode===`text`&&yr(r),r.ok||(process.exitCode=1)}function xr(e){let t=Ie(e,O);if(t.write===!0||!e.ok)return t;let n=Be(e,O);return n===void 0?t:{...t,exactRecovery:`Inline output is truncated. ${n}`}}function Sr(e,t){if(typeof t==`object`&&t&&`httpStatus`in t&&t.httpStatus===202)return;let n=ze(t);n===null?(process.stderr.write(`explain: the response carried no search interpretation
|
|
5
|
+
`),process.exitCode=1):(e===`text`?process.stdout:process.stderr).write(n)}function Cr(e){let t=[];typeof e.code==`string`&&t.push(` code: ${e.code}`),typeof e.detail==`string`&&t.push(` detail: ${e.detail}`),typeof e.hint==`string`&&t.push(` hint: ${e.hint}`),typeof e.suggestion==`string`&&t.push(` suggestion: ${e.suggestion}`);let n=Object.entries(e.suggestions??{});if(n.length>0){let e=n.map(([e,t])=>`${e}=${t}`).join(`; `);t.push(` suggestions: ${e}`)}return typeof e.requiredRole==`string`&&t.push(` requiredRole: ${e.requiredRole}`),t.push(...wr(e),...Tr(`unknownParameters`,e.unknownParameters),...Tr(`validParameters`,e.validParameters),...Er(e.resolution)),t}function wr(e){let t=[];return typeof e.limitType==`string`&&t.push(`limitType=${e.limitType}`),typeof e.used==`number`&&t.push(`used=${e.used}`),typeof e.limit==`number`&&t.push(`limit=${e.limit}`),typeof e.remaining==`number`&&t.push(`remaining=${e.remaining}`),typeof e.resetAt==`string`&&t.push(`resetAt=${e.resetAt}`),typeof e.windowSeconds==`number`&&t.push(`windowSeconds=${e.windowSeconds}`),typeof e.retryAfterSeconds==`number`&&t.push(`retryAfterSeconds=${e.retryAfterSeconds}`),t.length>0?[` meter: ${t.join(` `)}`]:[]}function Tr(e,t){return t!=null&&t.length>0?[` ${e}: ${t.join(`, `)}`]:[]}function Er(e){if(e==null)return[];let t=[`action=${e.action}`];return 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}`),[` resolution: ${t.join(` `)}`]}function Dr(e){if(e.ok&&e.warnings.length===0)return;let t=e.truncation===void 0?e.warnings:[...e.warnings,`omitted: ${e.truncation.omitted.join(`, `)}`,`recovery: ${e.truncation.recovery}`];u({component:w().bin[0],event:e.ok?`command_warning`:`command_failed`,message:t.length>0?t.join(` | `):e.summary,fields:{warningCount:e.warnings.length,summary:e.summary}})}function Or(e,t,n=w().bin[0]){let r=e.limit===void 0?void 0:Number(e.limit);if(r!==void 0&&(e.limit?.trim()===``||!Number.isInteger(r)||r<0))return C(`Invalid --limit value: ${JSON.stringify(e.limit)} (expected a non-negative integer)`,["Pass a non-negative integer, e.g. `--limit 20`."]);let i=Fe(t,n),a=Me(e.root??``),o=[...new Set(i.map(({cli:e})=>Me(e.path.at(0)??``)))].toSorted();if(a.length>0&&!o.includes(a))return C(`Unknown --root value: ${JSON.stringify(e.root)}`,[`Pass one of: ${o.join(`, `)}.`]);let s=Re(e.q??``,i.filter(t=>Mr(t,e)),e=>({...e,cliPath:e.cli.path,enumParameter:e.flags.map(({choices:e,location:t})=>({values:e,direct:t!==`body`})),parameterName:e.flags.flatMap(({wireName:e,optionKey:t})=>[e,t]),directParameterName:e.flags.filter(({location:e})=>e!==`body`).map(({wireName:e})=>e),parameterDescription:[e.body.description,...e.flags.map(({description:e})=>e)],responseFieldLevel:Ae(e.operationId)})).map(({item:e})=>e),c=s.slice(0,r);return S(`Operation catalog matches`,{operation:c,count:{totalOperations:t.length,matched:s.length,returned:c.length}})}function kr(e,t,n=w().bin[0]){let r=Fe(t,n),i=e.operationId===void 0?Ar(r,e.command):r.find(t=>t.operationId===e.operationId);if(i===void 0){let i=Lr(e.command??``),a=r.map(e=>e.cli.command).filter(e=>e.startsWith(`${n} ${i} `));if(a.length>0)return C(`${i} is a command group; show one of its subcommands.`,[`Run \`${n} command-catalog show --command "<subcommand>"\` with one of:`,...a]);let o=i.split(` `),s=new Set([...[...o.keys()].map(e=>o.slice(e+1).join(` `)),...o.slice(1).map((e,t)=>o.toSpliced(t,2,`${o[t]}-${e}`).join(` `))]),c=Or({q:e.command??e.operationId},t,n),l=[...r.filter(({cli:e})=>e.path.length>1&&s.has(e.path.join(` `))).toSorted((e,t)=>t.cli.path.length-e.cli.path.length),...c.data?.operation??[]];return C(`Generated operation not found`,[...[...new Set(l.map(({cli:e,operationId:t})=>`${e.command} (operationId ${t})`))].slice(0,3).map(e=>`closest: ${e}`),`List candidates with \`${n} command-catalog search "<text>"\`.`])}return S(`Generated operation detail`,{operation:i,usage:Pr(i,r)})}function Ar(e,t){if(t===void 0)return;let{bin:n}=w(),r=Lr(t,n);return e.find(e=>Lr(e.cli.command,n)===r)}var jr=(e,t)=>e===void 0||e===`all`||e===`any`||e===String(t);function Mr(e,t){return(t.root===void 0||Nr(e,t.root))&&jr(t.scope,e.scope)&&jr(t.mutates,e.mutates)&&jr(t.destructive,e.destructive)&&jr(t.intent,e.intent)&&jr(t.method,e.method)}function Nr(e,t){let n=Me(t);return n.length===0||Me(e.cli.path.at(0)??``)===n}function Pr(e,t){let n=Ne(e);return[`cli: ${e.cli.command}`,`${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 (CLI-only operation)`}`,e.body.hasBody?`body: kind=${e.body.kind??`unknown`} required=${e.body.required} requiredPath=${e.body.requiredPath.join(`,`)}`:`body: none`,...e.successResponse===void 0?[]:[`success: ${e.successResponse}`],...[!0,!1].flatMap(t=>[`path`,`query`,`header`,`body`].map(r=>{let i=n.filter(e=>e.required===t&&e.location===r),a=Ir(`${t?`required`:`optional`} ${r} flags`,i);return t&&r===`body`&&e.body.kind===`json`&&i.length>0?`${a} (required unless --from-file sets JSON key(s) ${i.map(({wireName:e})=>e).join(`, `)})`:a})),...Pe(e,t),...Fr(e.errorResponse),``,e.summary,e.description].filter(e=>e.length>0).join(`
|
|
6
|
+
`)}function Fr(e){return e.length===0?[]:[`Errors:`,...e.map(({status:e,description:t})=>` ${e} ${t}`)]}function Ir(e,t){return`${e}: ${t.length===0?`none`:t.map(e=>e.name).join(` `)}`}function Lr(e,t=w().bin){let[n=``,...r]=e.trim().split(/\s+/u);return(t.includes(n)?r:[n,...r]).join(` `)}var Rr=`dist/aventure-cli/command-catalog.compact.txt`,zr=` · `,Br=`-`;function Vr(e=w().bin[0]){return N(Hr(M(tn(import.meta.url)),e),Rr)}function Hr(e,t){let n=e;for(;;){if(P(N(n,`package.json`)))return n;let r=M(n);if(r===n)throw Error(`No package.json above ${e}; ${t} is not in a package layout.`);n=r}}function Ur(e,t){let n=t.join(` `).trim();return n.length===0?e:{...e,q:e.q===void 0?n:`${e.q} ${n}`}}function Wr(e,t,n,r=w().bin[0]){let i=Or(e,t,r);!i.ok||i.data===null?z({mode:n},i):Kr({opts:e,mode:n,data:i.data,defaultFormat:`lines`,rendered:Yr(i.data,Jr(e.format,`lines`)),summary:`Generated operation matches`})}function Gr(e,t,n,r=w().bin[0]){let i=kr(e,t,r);!i.ok||i.data===null?z({mode:n},i):Kr({opts:e,mode:n,data:i.data,defaultFormat:`usage`,rendered:Xr(i.data,Jr(e.format,`usage`)),summary:`Generated operation detail`})}function Kr(e){let t=e.mode,n=Jr(e.opts.format,e.defaultFormat),r=e.opts.text===!0||e.opts.allFields===!0;if(e.opts.output===void 0&&r&&(n===`json`||n===`ndjson`)){z({mode:t},C(`--text or --all-fields cannot be combined with --format json or ndjson`,[`Omit the text flag for machine output, or use --format lines, compact, or text.`]));return}let i=e.opts.output===void 0&&t===`text`&&`count`in e.data&&e.data.count.matched===0&&(r||e.opts.format===void 0||n===`text`)?`No generated operations matched.`:e.rendered,a=i.endsWith(`
|
|
7
|
+
`)?i:`${i}\n`;e.opts.output===void 0?t===`text`?qr(e.summary,a):z({mode:t},S(e.summary,e.data,{counts:ti(e.data)})):(Jt(e.opts.output,a),z({mode:t},S(e.summary,{outputPath:e.opts.output,byteLength:Buffer.byteLength(a,`utf8`),format:n},{counts:ti(e.data)})))}function qr(e,t){let n=ke(S(e,t));!n.ok||n.data===null?z({mode:`text`},n):process.stdout.write(n.data.endsWith(`
|
|
8
|
+
`)?n.data:`${n.data}\n`)}function Jr(e,t){return e??t}function Yr(e,t){return t===`json`?JSON.stringify(e,null,2):t===`ndjson`?e.operation.map(e=>JSON.stringify(e)).join(`
|
|
9
|
+
`):t===`text`?$r(e.operation):t===`compact`?e.operation.map(Zr).join(`
|
|
10
|
+
`):e.operation.map(ei).join(`
|
|
11
|
+
`)}function Xr(e,t){return t===`json`?JSON.stringify(e,null,2):t===`ndjson`?JSON.stringify(e.operation):t===`lines`?ei(e.operation):t===`compact`?Zr(e.operation):e.usage}function Zr(e){let t=Qr(e);return[e.cli.command,e.summary,t.length===0?Br:t.join(` `)].join(zr)}function Qr(e){return e.flags.filter(t=>t.required&&(t.contentType===void 0||t.contentType===e.body.contentType)).map(e=>e.name)}function $r(e){return e.map(e=>`${e.cli.command}\n ${ei(e)}`).join(`
|
|
12
|
+
`)}function ei(e){let t=Qr(e);return[B(`operationId`,e.operationId),B(`scope`,e.scope),B(`mutates`,String(e.mutates)),B(`destructive`,String(e.destructive)),B(`intent`,e.intent),B(`resource`,e.resource),B(`cli`,e.cli.command),e.mcpTool===null?``:B(`mcpTool`,e.mcpTool),B(`method`,e.method),B(`path`,e.path),B(`auth`,e.auth),B(`flags`,[...new Set(e.flags.map(e=>e.name))].join(` `)),B(`requiredFlags`,t.join(` `)),B(`bodyKind`,e.body.kind??``),B(`bodyRequired`,String(e.body.required)),B(`summary`,e.summary)].filter(e=>e.length>0).join(` `)}function B(e,t){return t.length===0?``:`${e}=${JSON.stringify(t)}`}function ti(e){return`count`in e?e.count:{returned:1}}function ni(e,t,n=w().bin[0]){e.helpCommand(!1);let r=e.commands.find(e=>e.name()===`help`)??e.command(`help`);r.summary(`Show full documentation for a command, or ask a question`).description("Show a command's full documentation offline. Select it by command path,\noperationId, or `<METHOD> <path>`; `<command> --help` prints only its usage.\n`help ask <question>` or `help --ask <question>` answers a platform question.").argument(`[command...]`,"command path, operationId, or METHOD and path, e.g. `help entities get`"),r.addOption(new ri(r)),r.hook(`preSubcommand`,e=>{e.opts().help&&e.help()});let i=li(t);i!==void 0&&r.option(`--ask <question>`,i.summary),A(r),r.action(async function(r){let a=this.optsWithGlobals();if(a.help&&r.length===0){this.outputHelp();return}if(!a.help&&i!==void 0&&a.ask!==void 0){let e=k(a);if(r.length>0){z({mode:e},C(`Use either a command path or --ask, not both.`));return}z({mode:e},await pi(i,a.ask,a.environment,e));return}let o=fi(e,r),s=t.find(t=>o!==void 0&&fi(e,t.cliPath)===o);if(a.help||o!==void 0&&s===void 0){o===void 0&&this.error(`unknown command '${r.join(` `)}' (run \`${n} --help\` for the command tree)`),o.outputHelp();return}let c=s===void 0?di(r,t):S(`Resolved by command path`,{operationId:s.operationId});c.ok&&c.data?.command!==void 0&&this.error(`unknown command '${r.join(` `)}' (run \`${n} --help\` for the command tree)`),!c.ok||c.data===null?z({mode:k(a)},c):Gr({...a,...c.data},t,k(a,`text`),n)}),ci(e,t,n)}var ri=class extends t{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))}},ii=2,ai=6,oi={formatHelp(e,t){let n=n=>r.prototype.formatHelp.call(this,e,Object.assign(Object.create(t),n));if(t.visibleCommands(e).length===0)return n({});let i=t.padWidth(e,t),a={padWidth:()=>i,visibleOptions:()=>[],showGlobalOptions:!1},o=n({...a,visibleCommands:()=>[]}),s=n({padWidth:()=>i,visibleCommands:()=>[]}).slice(o.length);return n(a)+s},visibleCommands(e){let t=r.prototype.visibleCommands.call(this,e);return e.parent===null?t.filter(e=>!Je.has(e.name())):t},subcommandTerm(e){let t=r.prototype.subcommandTerm.call(this,e);return e.commands.length>0&&e.registeredArguments.length===0?`${t} <command>`:t},formatItem(e,t,n,i){let a=i.helpWidth??80,o=a-t-4;return n===``||o>=i.minWidthToWrap?r.prototype.formatItem.call(i,e,t,n,i):`${` `.repeat(ii)}${e}\n${si(n,a,i)}`}};function si(e,t,n){return n.boxWrap(e,t-ai).replace(/^/gmu,` `.repeat(ai))}function ci(e,t,n){for(let r of t){let i=fi(e,r.cliPath);i!==void 0&&i.addHelpText(`after`,()=>{let e=i.createHelp(),a=i.configureOutput().getOutHelpWidth?.();e.prepareContext(a===void 0?{}:{helpWidth:a});let o=e.helpWidth??80,s=Le(r.operationId,t,n),[c,...l]=Fr(r.errorResponse),u=l.map(t=>si(t.trimStart(),o,e).replace(/^ +/u,` `.repeat(ii))),d=c===void 0?[]:[``,c,...u];return`\n${[...s,...d].join(`
|
|
13
|
+
`)}\n`})}}function li(e){let[t,...n]=e.filter(e=>{let[t,n,...r]=e.cliPath;return t===`help`&&n!==void 0&&r.length===0&&mi(e)!==void 0});return n.length===0?t:void 0}var ui='Accepted selectors: `<METHOD> <route template or concrete path>`, an operationId, or a CLI command path such as "entities get".';function di(e,t){let[n=``,...r]=e.join(` `).trim().split(/\s+/u),[i,...a]=t.filter(e=>e.path===n);if(r.length===0&&i!==void 0)return a.length===0?S(`Resolved by route`,{operationId:i.operationId}):C(`${n} is served by ${[i,...a].map(({method:e})=>e).join(`, `)}; name the method, as in \`help ${i.method} ${n}\`.`,[ui]);let o=h.find(e=>e===n.toLowerCase());if(o===void 0||r.length===0){let n=e.join(` `).trim();return S(`Resolved by name`,t.some(e=>e.operationId===n)?{operationId:n}:{command:n})}let s=ne(o),c=r.join(``),l=t.find(e=>e.method===s&&e.path===c);if(l!==void 0)return S(`Resolved by route template`,{operationId:l.operationId});let u=ve({method:s,path:c});return!u.ok||u.data===null?C(u.summary,[...u.warnings,ui]):S(`Resolved by method and path`,{operationId:u.data.operation.operationId})}function fi(e,t){let n=e;for(let e of t){let t=n.commands.find(t=>t.name()===e||t.aliases().includes(e));if(t===void 0)return;n=t}return n}async function pi(e,t,n,r){let i=mi(e);if(i===void 0)return C(`The \`${e.cliPath.join(` `)}\` operation no longer takes a single required text body; run it directly instead of \`help --ask\`.`);n!==void 0&&(process.env.API_ENV=n);let a=await tr(e,{[i.optionKey]:t});return a.ok?await x({method:e.method,path:ue(e.operationId,{}),searchParams:{},body:a.data,auth:e.auth,responseFormat:Pt(r)?`json`:`auto`}):a}function mi(e){if(e.requestBody?.length!==1||e.parameters.some(e=>e.required))return;let t=(e.requestBody[0]?.parameter??[]).filter(e=>e.required);return t.length===1&&t[0]?.schemaType===`string`?t[0]:void 0}function hi(e,t,n){if(e.cliPath[0]!==`lookup`||!gi(n))return null;let r=e.parameters.filter(e=>t[e.optionKey]!==void 0).map(e=>`${e.name}=${String(t[e.optionKey])}`),i=`no record for ${r.length===0?`the given input`:r.join(`, `)}`;return n.ok?C(i):C(i,[],{httpStatus:n.httpStatus,problem:n.problem})}function gi(e){return e.ok?Array.isArray(e.data)&&e.data.length===0:e.httpStatus===404}function _i(e,t){if(e.deprecated!==!0)return t;let n=e.description.match(/^Deprecated:[^.]*\./u)?.[0]??`Deprecated; run \`help ${e.cliPath.join(` `)}\` for its replacement.`;return{...t,warnings:[n,...t.warnings]}}var vi=b({artifact:y().nullish(),group:y().nullish(),name:y().nullish(),revision:y().nullish(),time:_({offset:!0}).nullish(),version:y().nullish()}),yi=b({build:vi}),bi=v([`MACOS`,`LINUX`,`WINDOWS`,`OTHER`]),xi=v([`RSA_OAEP_256_A256_GCM_V1`]),Si=b({clientLabel:y().regex(/.*\S.*/).min(1).max(120).nullish(),clientPlatform:bi.nullish(),encryptionAlgorithm:xi.nullish(),encryptionPublicKey:y().min(344).max(12e3).nullish()}),Ci=32;async function wi(){let e=await an.subtle.generateKey({name:`RSA-OAEP`,modulusLength:2048,publicExponent:new Uint8Array([1,0,1]),hash:`SHA-256`},!0,[`encrypt`,`decrypt`]),t=await an.subtle.exportKey(`spki`,e.publicKey);return{publicKey:Buffer.from(t).toString(`base64`),privateKey:e.privateKey}}async function Ti(e,t){let{wrappedKey:n,nonce:r,ciphertext:i,authenticationTag:a}=t,o=Ei(n,`wrapped key`,128,1024),s=Ei(r,`nonce`,12,12),c=Ei(i,`ciphertext`,1,65536),l=Ei(a,`authentication tag`,16,16),u;try{u=await an.subtle.decrypt({name:`RSA-OAEP`},e,o)}catch{throw Error(`broker credential key could not be decrypted`)}let d=new Uint8Array(u);try{if(d.byteLength!==Ci)throw Error(`broker credential used an invalid AES-256 key`);let e=await an.subtle.importKey(`raw`,d,{name:`AES-GCM`},!1,[`decrypt`]),t=new Uint8Array(c.byteLength+l.byteLength);t.set(c),t.set(l,c.byteLength);let n;try{n=await an.subtle.decrypt({name:`AES-GCM`,iv:s,tagLength:128},e,t)}catch{throw Error(`broker credential payload failed authentication`)}let r=new Xt(`utf-8`,{fatal:!0}).decode(n);if(r.trim().length===0)throw Error(`broker returned a blank credential`);return r}finally{d.fill(0)}}function Ei(e,t,n,r){let i=e.replace(/=+$/u,``),a=Uint8Array.from(Buffer.from(e,`base64`)),o=Buffer.from(a).toString(`base64`).replace(/=+$/u,``);if(i.length===0||o!==i||a.byteLength<n||a.byteLength>r)throw Error(`broker returned an invalid ${t}`);return a}var Di=v([`PENDING`,`ISSUING`,`KEY_READY`,`REVOKING`,`CONSUMED`,`REVOKED`,`DENIED`,`EXPIRED`,`FAILED`]),Oi=v([`Denied by user`,`Authorization request expired`,`CLI authorization expired before acknowledgement`,`Credential issuance recovery revoked an unrecoverable key`,`Revoked by user`,`Clerk create response validation failed`,`Credential issuance failed`,`Credential issuance could not be recovered`,`API-key quota reached`,`Credential issuance lost its database claim`,`Credential delivery encryption failed`,`Credential issuance finalization was lost`]),ki=b({approvedAt:_({offset:!0}).nullish(),clientLabel:y(),clientPlatform:bi,comparisonCode:y(),consumedAt:_({offset:!0}).nullish(),createdAt:_({offset:!0}),expiresAt:_({offset:!0}),id:ae(),intervalSeconds:le().int().min(1),keyReadyAt:_({offset:!0}).nullish(),status:Di,terminalAt:_({offset:!0}).nullish(),terminalReason:Oi.nullish(),updatedAt:_({offset:!0})}),Ai=b({algorithm:xi,authenticationTag:y(),ciphertext:y(),nonce:y(),wrappedKey:y()}),ji=b({delivery:Ai.nullish(),expiresAt:_({offset:!0}),status:Di,terminalReason:Oi.nullish()}),Mi=b({comparisonCode:y(),expiresAt:_({offset:!0}),id:ae(),intervalSeconds:le().int().min(1),pollSecret:y(),verificationUrl:y()}),V=[{command:`auth login`,role:`oauth`,summary:`Sign In Through Your Browser`,description:`Sign in through your browser and save verified CLI access in the credential store. Use --no-browser for OAuth device authorization only when the issuer advertises device-grant support; otherwise use --key --no-browser for API-key approval.`,operationId:`getAuthProviderCatalog`,method:`GET`,path:`/v1/auth/providers`,bodyOption:[],localOption:[{optionKey:`browser`,flag:`--no-browser`,description:`Use OAuth device authorization only when the issuer advertises device-grant support: print a sign-in URL and code, then wait for approval. Otherwise use --key --no-browser for API-key approval.`},{optionKey:`providers`,flag:`--providers`,description:`Print the sign-in providers and CLI OAuth client, then exit without signing in.`}]},{command:`auth login`,role:`start`,summary:`Sign In With a Browser-Approved aVenture API Key`,description:`Creates a short-lived browser approval request and returns its poll credential once.`,operationId:`createCliAuthorization`,method:`POST`,path:`/v1/auth/cli-authorizations`,bodyOption:[{name:`clientLabel`,optionKey:`clientLabel`,flag:`--client-label <client-label>`,required:!1,description:`Label for this CLI installation.`}],localOption:[{optionKey:`key`,flag:`--key`,description:`Sign in with a browser-approved aVenture API key instead of OAuth; the approval URL opens on any device.`},{optionKey:`browser`,flag:`--no-browser`,description:`Print the API-key approval URL and wait for approval without opening a browser.`}]},{command:`auth login`,role:`poll`,summary:`Poll CLI Authorization`,description:`Returns pending state, a terminal state, or an encrypted one-time credential delivery.`,operationId:`pollCliAuthorization`,method:`POST`,path:`/v1/auth/cli-authorizations/{cliAuthorizationId}/poll`,bodyOption:[],localOption:[]},{command:`auth login`,role:`acknowledge`,summary:`Acknowledge CLI Credential Delivery`,description:`Confirms the CLI stored the delivered API key in its credential store and clears transient delivery material.`,operationId:`acknowledgeCliAuthorization`,method:`POST`,path:`/v1/auth/cli-authorizations/{cliAuthorizationId}/acknowledge`,bodyOption:[],localOption:[]},{command:`auth logout`,role:`revoke`,summary:`Sign Out: Revoke the API Key and Forget Stored OAuth`,description:`Revokes the aVenture API key authenticating this request and returns its metadata so the CLI can confirm revocation before deleting its saved copy.`,operationId:`revokeCurrentApiKey`,method:`DELETE`,path:`/v1/auth/api-key`,bodyOption:[],localOption:[{optionKey:`forgetLocal`,flag:`--forget-local`,description:`Delete the saved key even when revocation cannot be confirmed.`}]}],Ni=T(V,`start`),Pi=T(V,`poll`),Fi=T(V,`acknowledge`),H=class extends Error{httpStatus;retryAfterSeconds;retryable;constructor(e,t,n=[]){super(`CLI authorization ${e} failed: ${Qe(t,n)}`),this.name=`CliAuthorizationRequestError`,this.httpStatus=t.status,this.retryAfterSeconds=Vi(t.retryAfterSeconds),this.retryable=t.status>=500||t.status===429}},Ii=class extends Error{constructor(e,t,n=[]){super(`CLI authorization ${e} transport failed: ${E(t,n)}`,{cause:t}),this.name=`CliAuthorizationTransportError`}};async function Li(e){let t=await ge(Ze(f()),{method:Ni.method,path:p(Ni.path,{},Ni.operationId),headers:{},contentType:`application/json`,body:e},Mi);if(t.ok&&t.redirect)throw new H(`start`,Hi(t.status));if(!t.ok)throw new H(`start`,t.problem);return Ui(t.data)}async function Ri(e,t){let n=fe(Pi.operationId),r=await ge(Ze(f()),{method:Pi.method,path:p(Pi.path,{cliAuthorizationId:e},Pi.operationId),headers:{[n]:t}},ji);if(r.ok&&r.redirect)throw new H(`poll`,Hi(r.status),[t]);if(!r.ok)throw new H(`poll`,r.problem,[t]);return{authorization:r.data,retryAfterSeconds:Bi(r.headers[`retry-after`])}}async function zi(e,t){let n=fe(Fi.operationId),r;try{r=await ge(Ze(f()),{method:Fi.method,path:p(Fi.path,{cliAuthorizationId:e},Fi.operationId),headers:{[n]:t}},ki)}catch(e){throw new Ii(`acknowledge`,e,[t])}if(r.ok&&r.redirect)throw new H(`acknowledge`,Hi(r.status),[t]);if(!r.ok)throw new H(`acknowledge`,r.problem,[t]);return r.data}function Bi(e){if(e===void 0)return null;let t=Number(e);return Number.isInteger(t)&&t>0?t:null}function Vi(e){return typeof e==`number`&&Number.isInteger(e)&&e>0?e:null}function Hi(e){return{status:e,title:`Unexpected redirect`,type:`about:blank`,code:void 0,detail:`CLI authorization endpoint returned an unexpected redirect`}}function Ui(e){let{verificationUrl:t,pollSecret:n,...r}=e,i={...e},a=()=>({...r,verificationUrl:`<redacted>`,pollSecret:`<redacted>`});return Object.defineProperties(i,{verificationUrl:{enumerable:!1,get:()=>t},pollSecret:{enumerable:!1,get:()=>n},toJSON:{enumerable:!1,value:a},toString:{enumerable:!1,value:()=>`CliAuthorizationStart(${JSON.stringify(a())})`},[Zt.custom]:{enumerable:!1,value:a}})}async function Wi(e){let t=await Gi(e.credential.secret);if(t.state!==`verified`||e.activation!==`active`)return{stored:e,verification:t};try{return{stored:await $e(e.host,{apiKey:t.apiKey,secret:e.credential.secret},`active`),verification:t}}catch(n){return{stored:e,verification:{state:`unavailable`,summary:`${t.summary}, but the cached metadata could not be updated — ${E(n,[e.credential.secret])}`}}}}async function Gi(e){let t=Ze(f()),n;try{n=await ge(t,{method:`GET`,path:ue(`getCurrentApiKey`,{}),headers:{Authorization:`Bearer ${e}`}},ct)}catch(t){return{state:`unavailable`,summary:`identity verification failed before an HTTP response — ${E(t,[e])}`}}return n.ok&&n.redirect?{state:`unavailable`,summary:`identity verification returned unexpected redirect ${n.status}`}:n.ok?n.data.status===`ACTIVE`?{state:`verified`,summary:`API key verified by aVenture sign-in`,apiKey:n.data}:{state:`invalid`,summary:`API key is not active`}:{state:n.problem.status===401||n.problem.status===403?`invalid`:`unavailable`,summary:`identity verification: ${Qe(n.problem,[e])}`}}var Ki=T(V,`revoke`);async function qi(e){let t;try{t=D(f().host)}catch(e){return C(`auth logout: invalid API host — ${E(e)}`)}let n=await Ji(t),r=await Zi(t,e),i=n.state===`failed`?[`OAuth credential could not be removed — ${n.summary}`]:n.state===`forgotten`&&!n.revoked?[`OAuth refresh token was not revoked remotely — ${n.summary??`no revocation endpoint`}`]:[],a={host:t,revoked:!1,forgotten:!1,oauth:n};return r===null?n.state===`missing`?S(`No CLI credential is stored for this API host.`,a):n.state===`failed`?{...C(`auth logout: ${i[0]}`),data:a}:S(n.revoked?`OAuth credential revoked remotely and removed locally.`:`OAuth credential removed locally.`,a,{warnings:i}):{...r,data:{...r.data??a,oauth:n},warnings:[...r.warnings,...i]}}async function Ji(e){let t=await gt(e);if(t.state===`missing`)return{state:`missing`};let n=t.state===`found`?await Xi(t.stored):{revoked:!1};try{await ut(e)}catch(e){return{state:`failed`,summary:E(e)}}return{state:`forgotten`,...n}}async function Yi(e){let t=Reflect.get(await St(e),`revocation_endpoint`);return typeof t==`string`?pt(t,`revocation endpoint`,!0):void 0}async function Xi(e){let{client:t,tokens:n}=e.credential,r=n.refresh_token??n.access_token;try{let e=await Yi(t);if(e===void 0)return{revoked:!1};let n=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/x-www-form-urlencoded`},body:new URLSearchParams({token:r,client_id:yt(t)})});return n.ok?{revoked:!0}:{revoked:!1,summary:`revocation endpoint answered ${n.status}`}}catch(e){return{revoked:!1,summary:E(e,ht(n))}}}async function Zi(e,t){let n;try{n=await tt(e)}catch(e){return C(`auth logout: stored credential could not be read — ${E(e)}`)}if(n.state===`unavailable`)return{...C(`auth logout: ${n.summary}`),data:{host:e,revoked:!1,forgotten:!1}};if(n.state===`missing`)return null;let r=n.stored,i=await Qi(r),a=i.outcome===`revoked`,o=r.activation===`pending`&&i.outcome===`rejected`;if(!a&&!o&&!t.forgetLocal)return{...C(`auth logout: remote revocation was not confirmed; local credential preserved — ${i.summary}`,[`Retry when the API is available. If an earlier response was lost after revocation, the retry can be unauthorized because revoked keys cannot authenticate.`,"Use `--forget-local` only to remove local bytes while accepting that the remote key may remain active."]),data:$i(r,!1,!1)};try{await rt(r.host)}catch(e){return{...C(`auth logout: local credential removal failed — ${E(e,[r.credential.secret])}`,[a?"The remote key is revoked. Re-run with `--forget-local` to retry local cleanup.":`Remote revocation was not confirmed; inspect auth status before retrying.`]),data:$i(r,a,!1)}}return S(a?`API key revoked remotely and removed locally.`:o?`Stale pending CLI credential removed; its remote key can no longer authenticate and unacknowledged keys expire at the authorization deadline.`:`API key removed locally without confirmed remote revocation.`,$i(r,a,!0),{ids:[r.credential.apiKey.id],warnings:a||o?[]:[`Remote revocation was not confirmed; the API key may remain active.`]})}async function Qi(e){let t=Ze(f());try{let n=await ge(t,{method:Ki.method,path:p(Ki.path,{},Ki.operationId),headers:{Authorization:`Bearer ${e.credential.secret}`}},ct);return n.ok&&n.redirect?{outcome:`unconfirmed`,summary:`remote key revocation returned unexpected redirect ${n.status}`}:n.ok?n.data.id!==e.credential.apiKey.id||n.data.subject!==e.credential.apiKey.subject?{outcome:`unconfirmed`,summary:`remote response did not match the stored API key identity`}:n.data.status===`REVOKED`?{outcome:`revoked`,summary:`remote key revocation confirmed`}:{outcome:`unconfirmed`,summary:`remote response did not confirm REVOKED status`}:{outcome:n.problem.status===401&&n.problem.type!==`about:blank`?`rejected`:`unconfirmed`,summary:Qe(n.problem,[e.credential.secret])}}catch(t){return{outcome:`unconfirmed`,summary:E(t,[e.credential.secret])}}}function $i(e,t,n){return{host:e.host,apiKeyId:e.credential.apiKey.id,activation:e.activation,revoked:t,forgotten:n}}var ea=`RSA_OAEP_256_A256_GCM_V1`,ta=1,na=30,U=w().bin[0],ra=`The local record remains pending and unavailable to ordinary commands. Re-run \`${U} auth login --key\`; it recovers the credential when the broker acknowledged it, and otherwise clears the stale record.`;async function ia(e){if(!Yt.isTTY)return C(`${U} auth login --key requires an interactive TTY on stdin`,[`For non-interactive automation, inject AUTH_TOKEN through the environment.`]);let t,n;try{let e=f().host;t=D(e),n=lt(e)}catch(e){return C(`auth login --key: invalid environment configuration — ${E(e)}`)}for(;;){let e;try{e=await at(t)}catch(e){return C(`auth login --key: credential storage could not be inspected — ${E(e)}`)}if(e.state===`unavailable`)return C(`auth login --key: ${e.summary}`,[`Make the OS keyring or the CLI config directory writable, or use AUTH_TOKEN from the environment.`]);if(e.state===`missing`){e.keyringFailure!==void 0&&I.write(ot(e.keyringFailure));break}let n=await aa(e.stored);if(n!==null)return n}let r;try{r=await wi()}catch(e){return C(`auth login --key: ephemeral encryption key could not be created — ${E(e)}`)}let i=Si.safeParse({clientLabel:e.clientLabel?.trim()||($t().trim()||U).slice(0,120),clientPlatform:la(),encryptionAlgorithm:ea,encryptionPublicKey:r.publicKey});if(!i.success)return C(`auth login --key: ${ie(i.error)}`);let a;try{a=await Li(i.data)}catch(e){return C(`auth login --key: could not start browser authorization — ${E(e)}`)}let o;try{o=nt(a,n)}catch(e){return C(`auth login --key: unsafe browser authorization URL rejected — ${E(e)}`)}if(!ca(await it(a,n,{noBrowser:e.noBrowser}),a,o))return C(`auth login --key: browser authorization requires an interactive terminal for manual handoff`,[`Automatic browser opening did not complete, and the approval URL was withheld because stderr is not an interactive terminal. Retry from an interactive terminal.`],{references:[o]});let s;try{s=await sa(a)}catch(e){return C(`auth login --key: authorization did not complete — ${E(e)}`,[],{references:[o]})}if(s.algorithm!==ea)return C(`auth login --key: broker selected an unsupported encryption algorithm`);let c;try{c=await Ti(r.privateKey,s)}catch(e){return C(`auth login --key: encrypted credential could not be opened — ${E(e)}`)}let l=await Gi(c);if(l.state!==`verified`)return C(`auth login --key: decrypted credential was neither stored nor acknowledged — ${l.summary}`);let u;try{u=await $e(t,{apiKey:l.apiKey,secret:c},`pending`)}catch(e){return C(`auth login --key: credential could not be durably stored — ${E(e)}`)}let d;try{d=await oa(a)}catch(e){return W(u,!0,`auth login --key: credential was stored and verified, but broker acknowledgment was not confirmed — ${E(e,[a.pollSecret])}`,ra)}if(d.status!==`CONSUMED`)return W(u,!0,`auth login --key: broker returned ${d.status} after acknowledgment`,ra);let p=await Gi(c);if(p.state!==`verified`||!pa(p.apiKey,u.credential.apiKey))return W(u,!0,`auth login --key: broker acknowledgment succeeded, but refreshed credential metadata could not prove the granted lifetime — ${p.summary}`,ra);try{let e=await $e(t,{apiKey:p.apiKey,secret:c},`active`);return S(`API key stored; authenticated identity and broker acknowledgment verified.`,fa(e,!0),{ids:[e.credential.apiKey.id]})}catch(e){return W(u,!0,`auth login --key: remote acknowledgment succeeded, but local activation could not be confirmed — ${E(e)}`,ra)}}async function aa(e){let t=await Gi(e.credential.secret);if(e.activation!==`pending`)return t.state===`verified`?S(`API key is already stored and its authenticated identity was verified.`,fa(e,!0),{ids:[e.credential.apiKey.id]}):W(e,!1,`auth login --key: stored credential ${t.state} — ${t.summary}`,`Run \`${U} auth logout\` to revoke/remove it before authorizing a replacement.`);if(t.state===`verified`&&pa(t.apiKey,e.credential.apiKey))try{let n=await $e(e.host,{apiKey:t.apiKey,secret:e.credential.secret},`active`);return S(`Recovered pending CLI credential: broker acknowledgment had succeeded.`,fa(n,!0),{ids:[n.credential.apiKey.id]})}catch(t){return W(e,!0,`auth login --key: credential is valid but could not be promoted locally — ${E(t,[e.credential.secret])}`,`The remote key remains valid. Re-run \`${U} auth login --key\` to retry local activation; it will recover the pending credential automatically.`)}if(t.state===`unavailable`||t.state===`verified`&&!e.credential.apiKey.expiresAt)return W(e,t.state===`verified`,`auth login --key: the stored pending credential acknowledgment could not be verified — ${t.summary}`,t.state===`verified`?`The stored expiry is missing. Both records were preserved; inspect the existing key in your account before deciding how to recover it.`:`The stored record and the remote key were both preserved. Re-run \`${U} auth login --key\` when the API is reachable; it recovers an acknowledged credential and clears an unacknowledged one.`);let n=await Qi(e);if(n.outcome===`unconfirmed`)return W(e,!1,`auth login --key: a prior credential is durably stored but broker acknowledgment was not confirmed`,`Remote revocation of the stale pending key was not confirmed — ${n.summary}. Retry when the API is reachable.`);try{await rt(e.host)}catch(t){return W(e,!1,`auth login --key: stale pending credential could not be removed — ${E(t,[e.credential.secret])}`)}return I.write(n.outcome===`revoked`?`Revoked and cleared a stale pending CLI credential; starting a fresh browser authorization.
|
|
15
14
|
`:`Cleared a stale pending CLI credential whose remote key can no longer authenticate; starting a fresh browser authorization.
|
|
16
|
-
`),null}async function oa(e){let t=new Date(e.expiresAt).getTime(),n=ua(e.intervalSeconds);for(;;)try{return await
|
|
15
|
+
`),null}async function oa(e){let t=new Date(e.expiresAt).getTime(),n=ua(e.intervalSeconds);for(;;)try{return await zi(e.id,e.pollSecret)}catch(e){if(e instanceof H){if(!e.retryable)throw e;n=ua(e.retryAfterSeconds??n)}else if(!(e instanceof Ii))throw e;if(Date.now()>=t)throw e;I.write(`Broker acknowledgment was interrupted; retrying.
|
|
17
16
|
`),await da(n,t)}}async function sa(e){let t=new Date(e.expiresAt).getTime(),n=ua(e.intervalSeconds),r;for(I.write(`Waiting for browser approval...
|
|
18
|
-
`);Date.now()<t;){let i;try{i=await
|
|
17
|
+
`);Date.now()<t;){let i;try{i=await Ri(e.id,e.pollSecret)}catch(e){if(e instanceof H){if(!e.retryable)throw e;n=ua(e.retryAfterSeconds??n)}r=e,I.write(`Authorization poll was interrupted; retrying.
|
|
19
18
|
`),await da(n,t);continue}r=void 0;let a=i.authorization;switch(a.status){case`PENDING`:case`ISSUING`:case`REVOKING`:n=ua(i.retryAfterSeconds??n),await da(n,t);break;case`KEY_READY`:if(a.delivery===null||a.delivery===void 0)throw Error(`broker returned KEY_READY without an encrypted delivery`);return a.delivery;case`DENIED`:case`EXPIRED`:case`FAILED`:case`REVOKED`:throw Error(De(a.terminalReason?.trim()??``,[e.pollSecret])||`broker entered terminal state ${a.status}`);case`CONSUMED`:throw Error(`broker credential was already consumed; restart login`)}}throw Error(r===void 0?`browser authorization expired before approval completed`:`browser authorization expired after a retryable broker failure: ${E(r,[e.pollSecret])}`)}function ca(e,t,n){let r=e.state===`opened`;return!r&&!I.isTTY?!1:(I.write([r?`Browser approval opened for this request.`:`Browser not opened automatically (${e.reason}).`,...I.isTTY?[`Open this one-time approval URL in your browser:`,t.verificationUrl]:[`Approval reference: ${n}`],`Comparison code: ${t.comparisonCode}`,`Confirm that the browser shows the same code before approving.`,``].join(`
|
|
20
|
-
`)),!0)}function la(){switch(en()){case`darwin`:return`MACOS`;case`linux`:return`LINUX`;case`win32`:return`WINDOWS`;default:return`OTHER`}}function ua(e){return Math.min(
|
|
19
|
+
`)),!0)}function la(){switch(en()){case`darwin`:return`MACOS`;case`linux`:return`LINUX`;case`win32`:return`WINDOWS`;default:return`OTHER`}}function ua(e){return Math.min(na,Math.max(ta,e))}async function da(e,t){let n=t-Date.now();n>0&&await nn(Math.min(e*1e3,n))}function fa(e,t){return{host:e.host,provider:e.provider,apiKeyId:e.credential.apiKey.id,name:De(e.credential.apiKey.name,[e.credential.secret]),activation:e.activation,verified:t}}function W(e,t,n,r){return{...C(n,r===void 0?[]:[r]),data:fa(e,t)}}function pa(e,t){return e.expiresAt===null||e.expiresAt===void 0||t.expiresAt===null||t.expiresAt===void 0?!1:new Date(e.expiresAt)>new Date(t.expiresAt)}async function ma(){return null}async function ha(e){let t=null,n=e=>{t=e};try{await vt(e,n),await st(n)}catch(e){return{materialized:t,failure:E(e)}}return{materialized:t,failure:null}}async function ga(e,t,n,r){if(r.failure!==null)return{scope:e,selected:null,identity:null,authorization:null,error:r.failure};let i=null,a=null,o,s=e=>{o=e,a=_a(e.credential,r.materialized)};try{let t=await x({method:`POST`,path:`/v1/auth/me/permissions`,body:{operation:[]},auth:e,requesterScope:e,responseFormat:`json`,onAuthPrepared:s});if(!t.ok)throw Error(va(t));if(a===null)throw Error(`Live permission probe did not prepare a credential`);if(i=Sa(t.data),e===`read`)return{scope:e,selected:a,identity:null,authorization:i,error:null};if(o===void 0)throw Error(`Live permission probe did not retain its prepared credential`);let n=await ma(e,o);return{scope:e,selected:a,identity:n,authorization:i,error:null}}catch(r){return{scope:e,selected:a,identity:null,authorization:i,error:E(r,ya(t,n,o))}}}function _a(e,t){if(e===null)return null;let n=t??et().source;if(n===null)throw Error(`Prepared credential has no local provenance`);return{credential:e,source:n}}function va(e){return[e.summary,...e.warnings].join(` — `)}function ya(e,t,n){return[f().userBearerToken,...Ee(n?.headers??{}),...e.state===`found`?ht(e.stored.credential.tokens):[],t.state===`found`?t.stored.credential.secret:void 0]}function ba(e,t,n=null){let r=t.state===`found`?t.stored:void 0,i=r?.credential.apiKey.expiresAt??null;return{host:e,present:r!==void 0,provider:r?.provider??null,activation:r?.activation??null,apiKeyId:r?.credential.apiKey.id??null,subject:r?.credential.apiKey.subject??null,scope:r?.credential.apiKey.scopes??[],name:r===void 0?null:De(r.credential.apiKey.name,[r.credential.secret]),status:r?.credential.apiKey.status??null,expiresAt:i,metadataSource:r===void 0?null:n?.state===`verified`?`clerk`:`store-cache`,live:n===null?null:{state:n.state,summary:n.summary},expiresInDay:Ta(i),storageFailure:t.state===`unavailable`?t.summary:null,keyringFailure:t.state===`missing`?t.keyringFailure??null:null,error:t.state===`invalid`?t.summary:null}}function xa(e,t){let n=t.state===`found`?t.stored:void 0;return{host:e,present:n!==void 0,provider:n?.provider??null,expiresAt:n?.credential.expiresAt??null,expired:n===void 0?null:dt(n.credential),renewable:n===void 0?null:n.credential.tokens.refresh_token!==void 0,identity:n===void 0?null:ft(n.credential),client:n?.credential.client??null,storageFailure:t.state===`unavailable`?t.summary:null,keyringFailure:t.state===`missing`?t.keyringFailure??null:null,error:t.state===`invalid`?t.summary:null}}function Sa(e){if(typeof e!=`object`||!e||e instanceof Uint8Array)throw Error(`permission probe returned no JSON response`);let t=he.safeParse(e.response);if(!t.success)throw t.error;return t.data}function Ca(e,t){let{expiresAt:n,expiresInDay:r}=ba(e,t);return n!==null&&r!==null&&new Date(n).getTime()<=Date.now()?` (cached expiry passed ${Math.abs(r)}d ago; \`auth status\` re-checks it with aVenture sign-in)`:``}var wa=864e5;function Ta(e){if(e===null)return null;let t=new Date(e).getTime();return Number.isNaN(t)?null:Math.round((t-Date.now())/wa)}var Ea=7;function Da(e){return e===null?`none`:e.length<=11?e:`${e.slice(0,Ea)}\u2026${e.slice(-4)}`}var Oa=13,ka=14;function Aa(e){return[``,`${e.cliName} ${e.cliVersion} \u2192 ${e.apiKey.host}`+(e.apiVersion===null?` (api build unavailable)`:` (api ${e.apiVersion})`),``,...Ma(e.oauth,e.cliName,e.refresh),...Pa(e.apiKey,e.oauth,e.cliName),``,G(`Providers`,La(e.providers)),G(`Environment`,Ra(e.resolved)),G(`Selected`,za(e.resolved,e.refresh,e.cliName)),...ja(e.live)].join(`
|
|
21
20
|
`)}function ja(e){if(e===null)return[];let t=K(`local credential provenance was captured before verification`);if(e.error!==null)return[``,G(`Live probe`,`${e.scope} permission probe failed`),t,K(e.error)];if(e.authorization===null)return[];let n=e.authorization.permissionGrant,r=e.identity;return[``,G(`Live probe`,`${e.scope} permission probe succeeded`),t,K(`operation access ${e.authorization.operationAccess}; ${n.role.length} role; ${n.permission.length} permission`),...r===null?[K(e.scope===`read`?`identity not requested for a read-scope credential`:`identity unavailable in this build`)]:[G(`Live account`,r.nameFull??r.email??r.clerkUserId??r.id)],K(`no API operation was executed or individually authorized`)]}function G(e,t){return` ${e.padEnd(Oa)}${t}`}function K(e){return` ${``.padEnd(Oa)}${e}`}function Ma(e,t,n){switch(e.state){case`found`:{let{credential:r,provider:i}=e.stored,a=ft(r);return[G(`OAuth`,`${a.email??a.subject??`unknown identity`} via ${i}`),K(Na(r,t,n))]}case`missing`:return[G(`OAuth`,`none stored`),...e.keyringFailure===void 0?[]:[K(`OS keyring unusable — login stores to file: ${e.keyringFailure}`)]];case`unavailable`:return[G(`OAuth`,`storage unavailable: ${e.summary}`)];case`invalid`:return[G(`OAuth`,`stored credential invalid: ${e.summary}`)];default:throw Error(`Unsupported OAuth credential state`)}}function Na(e,t,n){return dt(e)?e.tokens.refresh_token===void 0?`access token expired — run \`${t} auth login\``:n.failure===null?n.materialized===`api-key`?`access token expired and renewal failed; the API key is in use — \`${t} auth login\` renews OAuth`:`access token expired — not renewed while AUTH_TOKEN is set in the environment`:`access token expired — ${n.failure}`:`access token valid until ${e.expiresAt}`}function Pa(e,t,n){if(!e.present){if(t.state===`found`)return[];let r=e.storageFailure??(t.state===`unavailable`?t.summary:null);return r===null?[G(`Signed in`,`no \u2014 run \`${n} auth login\``),...e.error===null?[]:[K(`stored credential invalid: ${e.error}`)]]:[G(`Signed in`,`credential storage unavailable`),K(r)]}return[G(t.state===`found`?`API key`:`Signed in`,e.subject??`unknown subject`),K(`via ${e.provider??`unknown store`}`),G(`Key`,`${e.name??`unnamed`} ${Da(e.apiKeyId)}`),...Fa(e,n),G(`Scopes`,e.scope.length===0?`none`:e.scope.join(`, `))]}function Fa(e,t){let n=e.live,r=e.expiresInDay,i=e.expiresAt;if(n?.state===`invalid`)return[G(`Key state`,`rejected by aVenture sign-in \u2014 ${n.summary}`),K(`run \`${t} auth logout\`, then \`${t} auth login --key\``)];let a=n?.state===`verified`;return[G(`Key state`,a?`${e.status??`unknown`}, verified by aVenture sign-in now`:`${e.status??`unknown`} when stored`),...i===null||r===null?[K(`no expiry recorded`)]:[K(Ia(i,r,a?`expires`:`cached expiry`))],...a?[]:[K(n===null?"aVenture sign-in owns the live verdict — `auth status` re-checks it":`aVenture sign-in could not be reached \u2014 ${n.summary}`)]]}function Ia(e,t,n){let r=e.slice(0,10);return new Date(e).getTime()<=Date.now()?`${n} ${r} passed ${Math.abs(t)}d ago`:t<=ka?`${n} ${r}, ${t}d away`:`${n} ${r}`}function La(e){if(e.state===`unavailable`)return`unavailable: ${e.summary}`;let t=e.catalog.oauthClient;return[e.catalog.clerkPublishableKey?`browser sign-in`:`no browser sign-in`,t?`oauth ${mt(t).host} client ${t.clientId}`:`no OAuth CLI client`].join(`; `)}function Ra(e){return`${o.authToken}=${e.present?e.source??`resolved`:`unset`}`}function za(e,t,n){return e.present||t.materialized===`env`?`${o.authToken} from the environment`:t.materialized===`oauth`?`saved OAuth access token`:t.materialized===`api-key`?`saved API key`:`none \u2014 sign in with \`${n} auth login\``}var Ba=`# >>> aventure-cli completion setup (managed by aventure-cli) >>>`,Va=`# <<< aventure-cli completion setup (managed by aventure-cli) <<<`,Ha=`.aventure-cli-completion.bak`;function Ua(e,t){e.command(`install`).summary(`install shell completion loaders`).description(`Install managed shell completion loaders for supported shells.`).action(()=>Xa([])),e.command(`uninstall`).summary(`remove shell completion loaders`).description(`Remove managed shell completion loaders installed by ${t}.`).action(()=>Xa([`--uninstall`]))}function Wa(e,t){e.command(`setup`).summary(`configure zsh completion startup`).description(`Configure ~/.zshrc so zsh loads ${t} completion loaders.`).option(`--dry-run`,`print the managed zshrc block without writing`).option(`--yes`,`apply without prompting`).option(`--uninstall`,`remove the managed zshrc block`).action(async e=>{let t=Ja(),n=await qa({rcFile:N(Qt(),`.zshrc`),installerPath:t,mode:e.uninstall?`uninstall`:`install`,dryRun:e.dryRun,prompter:e.yes||e.dryRun?void 0:so});F.stdout.write(`${n.message}\n`),!n.cancelled&&!e.dryRun&&Xa(e.uninstall?[`--uninstall`]:[])})}function Ga(e,t=`fpath-only`){return[Ba,`# installer: ${e}`,'fpath=("${XDG_DATA_HOME:-$HOME/.local/share}/zsh/site-functions" $fpath)',...t===`fpath-and-compinit`?[`autoload -Uz compinit`,`compinit`]:[],Va].join(`
|
|
22
21
|
`)}function Ka(){let e=Xa([`--status`],`pipe`);if(e.status!==0)return{refreshed:!1,message:`completion status exited ${e.status??1}`};if(!Za(e.stdout??``))return{refreshed:!1,message:`no managed shell completions found`};let t=Xa([],`pipe`);return t.status===0?{refreshed:!0,message:(t.stdout??``).trim()||`shell completions refreshed`}:{refreshed:!1,message:`completion refresh exited ${t.status??1}`}}async function qa({rcFile:e,installerPath:t,mode:n,dryRun:r=!1,prompter:i}){let a=Qa(e),o=a.length===0?[]:a.split(`
|
|
23
|
-
`),s=$a(o,e);if(n===`uninstall`&&s===null)return{changed:!1,cancelled:!1,message:`${e}: already up-to-date`,content:a};let c=n===`install`?eo(o,s,t,e):to(o,s);return c===a?{changed:!1,cancelled:!1,message:`${e}: already up-to-date`,content:c}:r?{changed:!0,cancelled:!1,message:c,content:c}:i!==void 0&&!await i(`Update ${e}?`)?{changed:!0,cancelled:!0,message:`${e}: unchanged; pass --yes to apply without a prompt`,content:a}:(io(e,c),{changed:!0,cancelled:!1,message:`${e}: updated`,content:c})}function Ja(e=F.argv[1]){let t=e===void 0?``:Ya(e),n=N(M(t),`..`,`..`,`scripts`,`install-zsh-completion-loader.mjs`);return P(n)?n:N(M(t),`..`,`scripts`,`install-zsh-completion-loader.mjs`)}function Ya(e){try{return Gt(e)}catch{return N(e)}}function Xa(e,t=`inherit`){let n=Ft(F.execPath,[Ja(),...e],{encoding:t===`pipe`?`utf8`:void 0,stdio:t});if(n.error!==void 0)throw n.error;if(t===`inherit`)
|
|
22
|
+
`),s=$a(o,e);if(n===`uninstall`&&s===null)return{changed:!1,cancelled:!1,message:`${e}: already up-to-date`,content:a};let c=n===`install`?eo(o,s,t,e):to(o,s);return c===a?{changed:!1,cancelled:!1,message:`${e}: already up-to-date`,content:c}:r?{changed:!0,cancelled:!1,message:c,content:c}:i!==void 0&&!await i(`Update ${e}?`)?{changed:!0,cancelled:!0,message:`${e}: unchanged; pass --yes to apply without a prompt`,content:a}:(io(e,c),{changed:!0,cancelled:!1,message:`${e}: updated`,content:c})}function Ja(e=F.argv[1]){let t=e===void 0?``:Ya(e),n=N(M(t),`..`,`..`,`scripts`,`install-zsh-completion-loader.mjs`);return P(n)?n:N(M(t),`..`,`scripts`,`install-zsh-completion-loader.mjs`)}function Ya(e){try{return Gt(e)}catch{return N(e)}}function Xa(e,t=`inherit`){let n=Ft(F.execPath,[Ja(),...e],{encoding:t===`pipe`?`utf8`:void 0,stdio:t});if(n.error!==void 0)throw n.error;if(t===`inherit`)n.status!==0&&(F.exitCode=n.status??1);else return{stdout:n.stdout?.toString(),stderr:n.stderr?.toString(),status:n.status}}function Za(e){return e.split(/\r?\n/u).some(e=>e.trim().endsWith(`: managed`))}function Qa(e){return P(e)?(ao(e),Ht(e,`utf8`)):``}function $a(e,t){let n=no(e,Ba),r=no(e,Va);if(n.length===0&&r.length===0)return null;let[i]=n,[a]=r;if(n.length!==1||r.length!==1||i===void 0||a===void 0||i>=a)throw Error(`${t} has malformed managed completion setup markers; fix manually before retrying.`);return[i,a]}function eo(e,t,n,r){let i=t===null?[...e]:[...e.slice(0,t[0]),...e.slice(t[1]+1)],a=ro(i),o=Ga(n,a===-1?`fpath-and-compinit`:`fpath-only`).split(`
|
|
24
23
|
`),s=t===null?a:t[0],c=s===-1?i.length:s;if(t!==null&&a!==-1&&a<c)throw Error(`${r} runs compinit before the managed block; move the block above compinit manually.`);return oo([...i.slice(0,c),...o,...i.slice(c)])}function to(e,t){return oo(t===null?e:[...e.slice(0,t[0]),...e.slice(t[1]+1)])}function no(e,t){return e.flatMap((e,n)=>e===t?[n]:[])}function ro(e){return e.findIndex(e=>/^\s*(autoload\s+.*\bcompinit\b|compinit(?:\s|$))/.test(e))}function io(e,t){Bt(M(e),{recursive:!0}),P(e)&&(ao(e),ao(`${e}${Ha}`),Rt(e,`${e}${Ha}`));let n=N(M(e),`.${j(e)}.${F.pid}.tmp`);ao(n),Jt(n,t,{mode:420}),Kt(n,e)}function ao(e){if(P(e)&&zt(e).isSymbolicLink())throw Error(`refusing to write symlink: ${e}`)}function oo(e){let t=e.join(`
|
|
25
24
|
`);return t.length===0||t.endsWith(`
|
|
26
25
|
`)?t:`${t}\n`}async function so(e){if(!F.stdin.isTTY)return!1;let t=sn({input:F.stdin,output:F.stdout});try{let n=await t.question(`${e} [y/N] `);return/^(y|yes)$/i.test(n.trim())}finally{t.close()}}var co=new Intl.Collator(void 0,{numeric:!0}),lo=2e4,uo=[`lib`,`aventurevc-releases`];function fo(e,t=w()){let n=t.registry===``?`Requires npm authentication for @aventurevc packages.`:`Installs from npm.`;A(e.command(`update`).summary(`Check for or install the latest release`).description([`Compare the running CLI version against the latest published`,`release and install it into the active published bin prefix.`,``,`Refuses to install when the running binary is the working-tree build`,`(rebuild that checkout instead). ${n}`,`--execute is deprecated, accepted, and ignored; update executes by its verb.`].join(`
|
|
27
|
-
`)).option(`--execute`,`Deprecated; accepted and ignored. This command executes by its verb.`,!1).option(`--release <version>`,`Install and activate exactly this version, not the latest.`)).action(e=>
|
|
26
|
+
`)).option(`--execute`,`Deprecated; accepted and ignored. This command executes by its verb.`,!1).option(`--release <version>`,`Install and activate exactly this version, not the latest.`)).action(e=>z({mode:k(e)},po(void 0,`apply`,e.release)))}function po(e,t=`apply`,n){let r=e;try{r??=w(process.argv[1])}catch(e){return C(e instanceof Error?e.message:String(e),[`invalid_package_metadata`])}let i=r.name,a=r.version,o=r.registry===``?``:Ce,s=r.registry===``&&i===`@aventurevc/aventure-cli`,c=n;if(c===void 0){let e=mo([`view`,o,`version`,`--silent`,`--global`],r,{timeout:lo});if(!e.ok)return{...e,data:null};if(c=(e.data??``).trim(),c===``)return C(`npm view ${o} returned empty version`,[`empty_stdout`])}let l=n!==void 0||s||co.compare(a,c)<0,u={targetPackage:o,runningPackage:i,currentVersion:a,latestVersion:c,upgradeAvailable:l,upgradeInstalled:!1};if(t===`check`)return S(`${i}@${a} → ${o}@${c} (${l?`available`:`up to date`})`,u);if(r.workingTreeRoot!==null)return C(`Refusing to install over the working-tree build at ${r.workingTreeRoot}; rebuild via make instead`,["running CLI is npm-linked from the back-end checkout — `update` is for published bins"]);try{let e=_o(r),t=N(e,...uo),i=j(o),s=N(t,`${i}-current`),l=o===``?[o,``]:[o,we],d=vo(e,r),f=n??[c,d?.version??a].reduce((e,t)=>co.compare(e,t)<0?t:e,a);Bt(t,{recursive:!0});let p=[go(r),...P(s)?[Gt(s)]:[],...Ut(t,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>N(t,e.name))],m,h=null,g=!1;for(let t of new Set(p.filter(t=>t!==e))){let e=ho(t,l,f,r.registry);if(e.ok&&e.data!==null){m=t,h=e.data;break}}if(m===void 0){m=Vt(N(t,`${i}-${encodeURIComponent(f)}-`));let e=mo([`install`,`-g`,`--prefix`,m,...l.map(e=>`${e}@${f}`)],r,{stdio:[`ignore`,`inherit`,`inherit`]});if(!e.ok)return{...e,data:null};g=!0;let n=ho(m,l,f,r.registry);if(!n.ok)return{...n,data:null};h=n.data}if(h===null)throw Error(`release verification produced no package`);let ee=yo(m,e,s,h,n),te=xo();return S(`${o} active at ${ee}`,{...u,upgradeInstalled:g||n!==void 0||d?.version!==ee,installPrefix:e,verifiedVersion:ee,completionRefreshed:te.refreshed,completionRefreshMessage:te.message})}catch(e){return C(`${o} update failed: ${bo(e)}`,[`existing releases were preserved`])}}function mo(e,t,n={}){let r={...process.env};t.registry===``?r.NODE_AUTH_TOKEN??=r.GH_PACKAGES_TOKEN:delete r.GH_PACKAGES_TOKEN;let i=[...e,`--@aventurevc:registry=${t.registry}`],a=Ft(`npm`,i,{env:r,encoding:`utf8`,...n});if(a.error)return a.signal===`SIGTERM`&&n.timeout!==void 0?C(`npm ${e[0]??``} did not answer within ${n.timeout}ms`,[`timeout`]):C(`npm ${e[0]??``} failed to start: ${a.error.message}`,[`spawn_error`]);if(a.status!==0){let t=(a.stderr??``).trim().split(`
|
|
28
27
|
`).slice(-3).join(` | `);return C(`npm ${e.join(` `)} exited ${a.status}`,[t||`no stderr`])}return S(`npm ok`,a.stdout??``)}function ho(e,t,n,r){try{let i=t.map(t=>{let i=w(N(e,`lib`,`node_modules`,...t.split(`/`),`package.json`));if(i.name!==t||i.version!==n||i.registry!==r)throw Error(`${t} does not match ${n} from ${r}`);for(let t of i.bin)if(!Gt(N(e,`bin`,t)).startsWith(`${i.packageRoot}${Lt}`))throw Error(`${t} escapes ${i.packageRoot}`);return i});for(let t of i){let r=N(e,`bin`,t.bin[0]),i=Ft(process.execPath,[r,`--version`],{encoding:`utf8`,timeout:lo});if(i.error)throw Error(`${t.name} verification failed: ${i.error.message}`);let a=(i.stdout??``).trim();if(i.status!==0||a!==n)throw Error(`${t.name} expected ${n} but reported ${a||`empty output`}`)}return S(`CLI and MCP release verified`,i)}catch(t){return C(`release verification failed: ${bo(t)}`,[`release prefix: ${e}`])}}function go(e){let t=M(e.packageRoot),n=M(t),r=M(n);if(j(t)!==e.name.split(`/`)[0]||j(n)!==`node_modules`||j(r)!==`lib`)throw Error(`the running package is not in a verifiable global npm prefix; npm install was not run`);if(!e.entryPath.startsWith(`${e.packageRoot}${Lt}`))throw Error(`the running entry escapes its package root`);return M(r)}function _o(e){let t=go(e),n=`${Lt}${uo.join(Lt)}${Lt}`,r=t.lastIndexOf(n);return r<0?t:t.slice(0,r)}function vo(e,t){let n=t.registry===``?j(``):Te,r=N(e,`bin`,n);if(!P(r))return null;let i=w(r);if(i.registry!==t.registry)throw Error(`${r} belongs to another product`);return i}function yo(e,t,n,r,i){let a=r[0];if(a===void 0)throw Error(`release contains no CLI`);let o=N(t,`bin`);Bt(o,{recursive:!0});let s=r.flatMap(e=>e.bin.filter((e,t)=>{let n=N(o,e);if(!P(n)||w(n).registry===a.registry)return!0;if(a.registry!==``&&t>0)return!1;throw Error(`${n} belongs to another product`)}));if(!P(n)){let t=Vt(N(M(n),`${j(n)}-seed-`));Bt(N(t,`bin`));for(let n of s){let r=N(o,n);qt(Gt(P(r)?r:N(e,`bin`,n)),N(t,`bin`,n))}try{qt(It(M(n),t),n)}catch(e){if(!(e instanceof Error&&`code`in e&&e.code===`EEXIST`))throw e}}if(!zt(n).isSymbolicLink())throw Error(`${n} is not a release symlink`);for(let e of s){let t=It(o,N(n,`bin`,e)),r=N(o,`.${e}-${rn()}`);qt(t,r),Kt(r,N(o,e))}for(let e of s){let t=N(o,e);if(!zt(t).isSymbolicLink()||N(o,Wt(t))!==N(n,`bin`,e))throw Error(`${t} does not follow the product current pointer`)}let c=vo(t,a);if(i===void 0&&c!==null&&co.compare(c.version,a.version)>0)return c.version;let l=`${n}-${rn()}`;return qt(It(M(n),e),l),Kt(l,n),a.version}function bo(e){return e instanceof Error?e.message:String(e)}function xo(){try{return Ka()}catch(e){return{refreshed:!1,message:e instanceof Error?e.message:String(e)}}}var So=[{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`},{name:`auth`,purpose:`which credential signs in, as which account and role, never secrets`},{name:`catalog`,purpose:`this CLI knows every operation the API serves`}];function Co(e,t=w().bin[0]){A(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: [...] }`:",...So.map(e=>` - ${e.name}: ${e.purpose}`),``,`Exit code is 0 only when no check failed; a skipped check (no registry reachable) or a`,`warned one (the account read failed) 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(`
|
|
29
|
-
`))).action(async function(e){let n=this.optsWithGlobals();n.environment!==void 0&&(process.env.API_ENV=n.environment),
|
|
30
|
-
`);return c.ok?S(l,c,{counts:o}):{...C(l,s,{counts:o}),data:c}}function To(e,t){return e.filter(e=>e.status===t).length}function q(e,t,n){return{name:e,status:t,message:n}}function Eo(){return O.find(e=>e.intent===`status`&&e.resource===`status`)}function Do(e){let t=w(),n=po(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 Oo(e){try{let{EntityDetailSchema:e}=await import(`./detail-
|
|
31
|
-
`);A(Go(r,[zo,...Bo],i)).action(Uo),A(Go(r,[Vo],Vo.description)).action(Wo),A(r.command(`status`).summary(`Keep saved credentials current and report them`).description(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
`))).action(async function(e){let n=this.optsWithGlobals();n.environment!==void 0&&(process.env.API_ENV=n.environment),z({mode:k(e)},await wo(t))})}async function wo(e){let t=Eo(),n=Do(e),[r,i]=await Promise.all([Oo(e),ko(t,e)]),a=[n.check,r,i.check,await jo(e),Ro(t,i.servedFingerprint,n.upgradeAvailable,e)],o={pass:To(a,`pass`),warn:To(a,`warn`),fail:To(a,`fail`),skip:To(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.warn} warn, ${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}):{...C(l,s,{counts:o}),data:c}}function To(e,t){return e.filter(e=>e.status===t).length}function q(e,t,n){return{name:e,status:t,message:n}}function Eo(){return O.find(e=>e.intent===`status`&&e.resource===`status`)}function Do(e){let t=w(),n=po(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 Oo(e){try{let{EntityDetailSchema:e}=await import(`./detail-BvYZMVnx.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\` — ${E(t)}.`)}}async function ko(e,t){let n=e??{method:`GET`,path:`/info`,auth:`none`},r;try{r=f().host}catch(e){return{check:q(`api-host`,`fail`,`Correct API_ENV or pass \`--environment <name>\` — ${E(e)}.`),servedFingerprint:null}}let i=await x({method:n.method,path:n.path,auth:n.auth,responseFormat:`json`}).catch(e=>C(E(e)));return i.ok?{check:q(`api-host`,`pass`,`${n.method} ${n.path} answered at ${r}.`),servedFingerprint:e===void 0?null:Ao(i.data)}:{check:q(`api-host`,`fail`,i.httpStatus===401?`Replace or unset the credential ${r} rejected, or run \`${t} auth login\`, then rerun \`${t} auth doctor\` — ${n.method} ${n.path} returned ${i.summary}.`:`Point the CLI at a reachable API host with \`--environment <name>\` or API_URL, then rerun \`${t} auth doctor\` — ${n.method} ${n.path} at ${r} returned ${i.summary}.`),servedFingerprint:null}}function Ao(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.operationFingerprint;return typeof n==`string`&&n.length>0?n:null}async function jo(e){let t=et(),[n,r]=await Promise.all([No(),Po()]);if(r.state===`unavailable`&&r.cause===`environment`)return q(`auth`,`fail`,`Fix the environment configuration first — ${r.summary}.`);let i=t.present,a=r.state===`found`&&r.stored.activation===`active`;if(!i&&n.state===`invalid`)return q(`auth`,`fail`,`Saved OAuth credential is invalid; run \`${e} auth login\` to sign in again after verification — ${n.summary}.`);if(!i&&n.state===`found`&&dt(n.stored.credential)&&n.stored.credential.tokens.refresh_token===void 0)return q(`auth`,`fail`,`Saved OAuth access token is expired without a refresh token; run \`${e} auth login\` to sign in again.`);if(!i&&!a&&n.state===`unavailable`)return q(`auth`,`fail`,`Make the OS keyring or the CLI config directory usable before \`${e} auth login\`, or inject ${o.authToken} through the environment — ${n.summary}.`);if(i||n.state===`found`||a){let i=await Mo(e,t);return q(`auth`,i.status,`Credential source available: ${Fo(t,n,r)}; ${i.text}.`)}return r.state===`unavailable`?q(`auth`,`fail`,`Make the OS keyring or the CLI config directory usable before \`${e} auth login --key\`, or inject ${o.authToken} through the environment — ${r.summary}.`):q(`auth`,`fail`,`Run \`${e} auth login\` for OAuth or \`${e} auth login --key\` for an API key. For non-interactive use, set ${o.authToken} in the environment.`)}async function Mo(e,t){let n=D(f().host),r=await ha(e),i=`credential=${t.present?t.source??`env`:r.materialized??`none`}`;try{if(r.failure!==null)throw Error(r.failure);let e=await ma(`write`);if(e===null)return{status:`pass`,text:`${i} host=${n}`};let t=e.rbacRole.length===0?`none`:e.rbacRole.join(`,`);return{status:`pass`,text:`${i} account=${e.email??e.id} role=${t} host=${n}`}}catch(t){return{status:`warn`,text:`${i} account=unread host=${n} — GET /v1/auth/me returned ${E(t,[f().userBearerToken])}; run \`${e} auth status --verify write\``}}}async function No(){let e;try{e=D(f().host)}catch(e){return{state:`unavailable`,summary:E(e)}}return await _t(e)}async function Po(){let e;try{e=D(f().host)}catch(e){return{state:`unavailable`,summary:E(e),cause:`environment`}}try{return await at(e)}catch(e){return{state:`unavailable`,summary:E(e),cause:`storage`}}}function Fo(e,t,n){return[Ra(e),`oauth=${Lo(t)}`,`api-key=${Io(n)}`].join(` `)}function Io(e){if(e.state!==`found`)return e.state===`missing`?`unset`:`unavailable`;let t=D(f().host);return`${e.stored.activation}${Ca(t,e)}`}function Lo(e){switch(e.state){case`found`:return dt(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 Ro(e,t,n,r){let i=O.length;if(e===void 0)return q(`catalog`,`skip`,`The public catalog omits deployment-status metadata and holds ${i} operations.`);if(t===null)return q(`catalog`,`skip`,`Could not read the served operation fingerprint, so drift is unproven; this catalog holds ${i} operations at ${Nt}.`);if(t===`9e90cf1a8bfaaac9`)return q(`catalog`,`pass`,`${i} generated operations match the set the API serves (${Nt}).`);let a=`This catalog describes a different operation set than the API serves (${Nt} 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 zo=T(V,`oauth`),Bo=[T(V,`start`),T(V,`poll`),T(V,`acknowledge`)],Vo=T(V,`revoke`);function Ho(e,n=w().bin[0]){let r=Ko(e);Co(r,n);let i=[`${zo.description} Default method: OAuth in your browser.`,`With --key: ${Bo.map(({description:e})=>e).join(` `)}`].join(`
|
|
30
|
+
`);A(Go(r,[zo,...Bo],i)).action(Uo),A(Go(r,[Vo],Vo.description)).action(Wo),A(r.command(`status`).summary(`Keep saved credentials current and report them`).description(`Runs the same credential materialization every command runs, then reports:
|
|
31
|
+
- auth: whether AUTH_TOKEN was already set in this shell's environment
|
|
32
|
+
- oauth: the saved OAuth identity and access-token expiry for the selected API host;
|
|
33
|
+
an expired token is renewed with its refresh token and a token the sign-in service rejects is retired
|
|
34
|
+
- api-key: the saved aVenture API key, re-verified with aVenture sign-in and its cached metadata updated
|
|
35
|
+
- selected: the credential the next command sends
|
|
36
|
+
- providers: GET /v1/auth/providers (browser sign-in and the CLI OAuth client)
|
|
37
|
+
- api: running CLI package version plus GET /info build metadata
|
|
38
|
+
|
|
39
|
+
Saved credentials are sent only to the selected API host and aVenture sign-in, never printed.
|
|
40
|
+
--verify read|write additionally runs a live permission probe for that scope; it does not
|
|
41
|
+
execute or authorize an arbitrary API operation.`).addOption(new t(`--verify <scope>`,`verify one permission-probe scope`).choices([`read`,`write`]))).action(async function(e){qo(this),z({mode:k(e)},await Jo(n,e.verify))}),r.command(`token`).summary(`Print the bearer token the next command sends`).description([`Runs the same credential materialization every command runs, then prints the selected`,`bearer token alone on stdout: ${o.authToken} when set, otherwise the saved OAuth`,`access token (renewed when expired) or the saved aVenture API key.`,`Use it where another client needs this CLI's sign-in, such as an MCP client's header helper.`].join(`
|
|
42
|
+
`)).action(async function(){qo(this);let e=await ha(n),t=process.env[o.authToken]?.trim();e.failure===null&&t!==void 0&&t.length>0?process.stdout.write(`${t}\n`):z({mode:`text`},e.failure===null?ns(`auth token: no credentials resolved`,null,n,{oauth:!0,apiKey:!0}):C(`auth token: ${e.failure}`))})}async function Uo(e){qo(this);let t=k(e);e.providers===!0?z({mode:t},await Xo()):z({mode:t},e.key===!0?await ia({noBrowser:!e.browser,clientLabel:e.clientLabel}):await xt({noBrowser:!e.browser}))}async function Wo(e){qo(this),z({mode:k(e)},await qi({forgetLocal:e.forgetLocal===!0}))}function Go(e,t,n){let[r]=t,i=e.command(r.command.slice(r.command.indexOf(` `)+1)).summary(r.summary).description(n),a=new Set;for(let e of t)for(let t of[...e.bodyOption,...e.localOption])a.has(t.flag)||(a.add(t.flag),`required`in t&&t.required?i.requiredOption(t.flag,t.description):i.option(t.flag,t.description));return i}function Ko(e){return(e.commands.find(e=>e.name()===`auth`)??e.command(`auth`)).summary(`Sign in, sign out, and check credentials`).description([`\`${zo.command}\`: ${zo.summary}; \`--key\` ${Bo[0].summary.toLowerCase()}.`,`\`${Vo.command}\`: ${Vo.summary}.`,"`auth status` reports local credential provenance, sign-in providers, and CLI/API build metadata.","`auth doctor` runs the one-call selftest and prints `{ ok, check: [...] }`.","`auth token` prints the bearer token the next command sends."].join(`
|
|
43
|
+
`))}function qo(e){let t=e.optsWithGlobals();t.environment!==void 0&&(process.env.API_ENV=t.environment)}async function Jo(e,t){let n;try{n=D(f().host)}catch(e){return C(`auth status: invalid API host — ${E(e)}`)}let r=et(),i=ha(e),[a,s]=await Promise.all([ts(`/info`,`GET /info`),Zo()]),c=await i,[l,u]=await Promise.all([_t(n),Yo(n)]),d=t===void 0?null:await ga(t,l,u.inspection,c),p=w().version,m=ba(n,u.inspection,u.verification),h=Aa({cliName:e,cliVersion:p,apiVersion:a.ok?$o(a.data):null,oauth:l,apiKey:m,providers:s,resolved:r,refresh:c,live:d}),g={cli:{version:p},api:a.ok?a.data??null:null,auth:{[o.authToken]:r},selected:c.materialized,oauth:xa(n,l),apiKey:m,providers:s,live:d,...a.ok?{}:{apiError:a.summary}};return c.failure===null?!a.ok&&a.httpStatus===401?{...C(`auth status: the API rejected the selected credential (401) | ${h}`,[`Replace or unset ${o.authToken}, or run \`${e} auth login\`.`]),data:g}:d!==null&&d.error!==null?{...C(`auth status: ${d.scope} permission probe failed — ${d.error}`,[d.error]),data:g}:d!==null||r.present||l.state===`found`||u.inspection.state===`found`?S(h,g):ns(`auth status: no credentials resolved | ${h}`,g,e,{oauth:l.state===`missing`,apiKey:u.inspection.state===`missing`}):{...C(`auth status: ${c.failure} | ${h}`,[c.failure]),data:g}}async function Yo(e){let t=await Qo(e);if(t.state!==`found`)return{inspection:t,verification:null};let{stored:n,verification:r}=await Wi(t.stored);return{inspection:{state:`found`,stored:n},verification:r}}async function Xo(){let e=await Zo();return e.state===`found`?S(`Sign-in providers for the selected API host`,e.catalog):C(`auth login --providers: ${e.summary}`)}async function Zo(){try{return{state:`found`,catalog:await bt()}}catch(e){return{state:`unavailable`,summary:E(e)}}}async function Qo(e){try{return await at(e)}catch(e){return{state:`invalid`,summary:E(e)}}}function $o(e){if(!es(e))return null;let t=yi.safeParse(Reflect.get(e,`response`));if(!t.success)return null;let n=t.data.build.version?.trim();return n&&n.length>0?n:null}function es(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}async function ts(e,t){return await x({method:`GET`,path:e,auth:`none`,responseFormat:`json`}).catch(e=>C(`${t} failed: ${e instanceof Error?e.message:String(e)}`))}function ns(e,t,n,r){return{...C(e,[...r.apiKey?[`For an API key (works over SSH), run \`${n} auth login --key\`.`]:[],...r.oauth?[`For OAuth, run \`${n} auth login\`; without a browser it prints a device code.`]:[],`For non-interactive use, set ${o.authToken} to an aVenture API key (create one at ${s}/settings/api-keys).`]),data:t}}var rs=v([`UNTRACKED`,`PENDING`,`SETTLED`,`REJECTED`]),is=b({admission:rs,hasMore:ce(),runId:oe(ae())}),as=b({complete:ce(),entitySlug:y().regex(/^[a-z0-9_-]+$/).max(255).nullable(),gateRemaining:oe(y()),note:y().nullish(),whatElseRemaining:oe(y()),writeThisIteration:oe(y())}),os=v([`COMPREHENSIVE`,`INDIVIDUAL`]),ss=v([`claude-agent-sdk`,`pi-agent-sdk`]),cs=v([`anthropic`,`openai-chat`,`openai-responses`]),ls=v([`unassigned`,`development`,`staging`,`production`]),us=v([`interactive`,`background`]),ds=v([`queued`,`running`,`completed`,`failed`,`stopped`]),fs=v([`ENRICHMENT`,`TASK`]),ps=b({attempt:se(),chassis:ss,chassisRouted:ce(),createdAt:_({offset:!0}),entitySlug:y().nullish(),environment:ls,error:y().nullish(),failureClass:y().nullish(),finishedAt:_({offset:!0}).nullish(),followUpAdmission:rs.optional(),hasSourceDocument:ce(),id:ae(),iteration:se(),lane:us,latestStatus:y().nullish(),llmApi:cs,maxIteration:se(),maxScoutConcurrent:se(),mode:os,model:y(),nextAttemptAt:_({offset:!0}).nullish(),researchAllowanceType:be.nullish(),resumeSafeUntil:_({offset:!0}).nullish(),startedAt:_({offset:!0}).nullish(),status:ds,subagentModel:y(),taskPresetKey:oe(y()).nullish(),type:fs,updatedAt:_({offset:!0}),url:y(),userPrompt:y().nullish()}),ms=b({entity:Ue.nullish(),followUp:is.optional(),lastEventAt:_({offset:!0}).nullish(),latestStatus:as.nullish(),provider:Ue.nullish(),publicUrl:y().nullish(),run:ps});function hs(e,t,n,r){let i=Number(t);return!Number.isInteger(i)||i<n||i>r?C(`${e} must be an integer between ${n} and ${r}, got "${t}"`):S(`${e} parsed`,i)}async function gs(){return{costUsd:null}}var _s=5e3,vs=6e4,ys=3e4,bs=86400;function xs(e){let t=e.commands.find(e=>e.name()===`research-runs`);if(t===void 0)return;let n=t.command(`wait`).summary(`Wait for one research run to finish, then report its outcome`).description("Polls `research-runs get` with backoff until the run is completed, failed, or stopped, then prints its status, error, failure class, spend, and last event time; a timeout reports the last event time so a stalled run shows. Exits nonzero when the run failed or stopped, or when --timeout passes first.").requiredOption(`--run-id <uuid>`,`Research run id`).option(`--timeout <seconds>`,`Total seconds to wait`,`1800`);A(n),n.action(async function(){let e=this.optsWithGlobals();z({mode:k(e)},await Ss(e))})}async function Ss(e){let t=hs(`--timeout`,e.timeout,1,bs);if(!t.ok||t.data===null)return C(t.summary);let n=Date.now()+t.data*1e3,r=ue(`getResearchRun`,{runId:e.runId}),i=_s,a=`not read yet`;for(;;){let o=await ws(r,n);if(o.kind===`refused`)return o.envelope;if(o.kind===`detail`){let{run:e}=o.detail;if(e.status===`completed`||e.status===`failed`||e.status===`stopped`)return await Cs(o.detail);a=`${e.status}, last event ${o.detail.lastEventAt??`none`}`}else a=`unread (${o.reason})`;let s=n-Date.now();if(s<=0)return C(`Run ${e.runId} is still ${a} after ${t.data}s`,[`Wait longer with --timeout, or read it with \`research-runs get --run-id ${e.runId}\`.`]);let c=_s+Math.random()*(i-_s);await nn(Math.min(c,s)),i=Math.min(i*2,vs)}}async function Cs(e){let{run:t}=e,n=await gs(t.id),r={runId:t.id,status:t.status,error:t.error??null,failureClass:t.failureClass??null,publicUrl:e.publicUrl??null,finishedAt:t.finishedAt??null,lastEventAt:e.lastEventAt??null,...n.costUsd===null?{}:{costUsd:n.costUsd}},i={warnings:n.warning===void 0?[]:[n.warning]},a=n.costUsd===null?``:`; spend $${n.costUsd.toFixed(4)}`;if(t.status===`completed`)return S(`Run ${t.id} completed${a}`,r,i);let o=t.failureClass?` (${t.failureClass})`:``,s=t.error?`: ${t.error}`:``;return{...S(`Run ${t.id} ${t.status}${o}${a}${s}`,r,i),ok:!1}}async function ws(e,t){let n;try{n=await x({method:`GET`,path:e,auth:`auto`,responseFormat:`json`,signal:AbortSignal.timeout(Math.max(1e3,Math.min(ys,t-Date.now())))})}catch(e){if(me(e))return{kind:`transient`,reason:String(e)};throw e}if(!n.ok){let{problem:t}=n;return t!==void 0&&_e(t.status,t)?{kind:`transient`,reason:n.summary}:{kind:`refused`,envelope:C(`GET ${e} failed: ${n.summary}`,n.warnings,{problem:t})}}let r=n.data,i=ms.safeParse(typeof r==`object`&&r&&`response`in r?r.response:void 0);return i.success?{kind:`detail`,detail:i.data}:{kind:`refused`,envelope:C(`${e} returned an unexpected body: ${i.error.message}`)}}function Ts(e,t=O,n=w().bin[0]){let r=e.command(`completion`).summary(`Generate shell completion scripts`).description(`Generate shell completion scripts for the aVenture CLI.`);for(let i of[`bash`,`fish`,`zsh`])r.command(i).summary(`Print ${i} shell completions`).description(`Print ${i} completion definitions for ${n}.`).action(()=>{F.stdout.write(Ds(e,i,t))});Ua(r,n),Wa(r,n)}function Es(){return w().bin}function Ds(e,t,n=O,r=Es()){let i=Is(n);return t===`fish`?[`# fish completions for ${r.join(`, `)}`,...ks(e),...r.map(e=>`complete -c ${J(e)} -e`),`${Ys(r)} -f`,...As(e,r),...js(e,i,r),``].join(`
|
|
35
44
|
`):Os(e,t,i,r)}function Os(e,t,n,r){let i=t===`zsh`?`typeset -ga `:``,a=`complete -F _aventure_cli ${r.map(e=>e.replaceAll(`'`,`'\\''`)).join(` `)}`,[o,s,c]=zs(e,n);return[...t===`zsh`?[`#compdef ${r.join(` `)}`]:[],`# ${t} completions for ${r.join(`, `)}`,`${i}_aventure_cli_commands=(`,...o.map(e=>` ${e}`),`)`,`${i}_aventure_cli_options=(`,...s.map(e=>` ${e}`),`)`,`${i}_aventure_cli_values=(`,...c.map(e=>` ${e}`),`)`,``,...Hs(t),...t===`bash`?[a,``]:[``]].join(`
|
|
36
45
|
`)}function ks(e){return[`function __aventure_cli_command_path\n set -l global_value_options ${Ms(e).filter(e=>e.required||e.optional).flatMap(e=>Gs(e)??[]).map(J).join(` `)}\n set -l tokens (commandline -xpc)\n if test (count $tokens) -gt 0\n set -e tokens[1]\n end\n set -l path\n set -l skip_next 0\n for token in $tokens\n if test $skip_next -eq 1\n set skip_next 0\n continue\n end\n if string match -q -- '--*=*' $token\n set -l name (string replace -r '^--([^=]+)=.*$' '$1' -- $token)\n contains -- $name $global_value_options; and continue\n end\n if string match -q -- '--*' $token\n set -l name (string replace -r '^--' '' -- $token)\n if contains -- $name $global_value_options\n set skip_next 1\n continue\n end\n break\n end\n if string match -q -- '-*' $token\n break\n end\n set -a path $token\n end\n printf '%s\\n' $path\nend\n`,`function __aventure_cli_path_is
|
|
37
46
|
set -l expected $argv
|
|
@@ -50,17 +59,18 @@ import{a as e,n as t,o as n,r,t as i}from"./commander-BB7CDPLs.js";import{_ as a
|
|
|
50
59
|
return 0
|
|
51
60
|
end
|
|
52
61
|
`].flatMap(e=>e.split(`
|
|
53
|
-
`))}function As(e,t){return Rs(e).map(e=>`${Ys(t)} -f -n ${J(Xs(e.parentPath))} -a ${J(e.name)} -d ${J(e.description)}`).toSorted((e,t)=>e.localeCompare(t))}function js(e,t,n){return Ks(e).flatMap(e=>{let r=Js(e),i=r.length===0?void 0:Xs(r);return Ms(e).flatMap(e=>{let a=t.get(Ls(r,e));return Vs(a)?Ns(e,i,a,n):[]})}).toSorted((e,t)=>e.localeCompare(t))}function Ms(e){return e.parent===null?e.createHelp().visibleOptions(e):e.options}function Ns(e,t,n,r){let i=Gs(e);if(i===void 0)return[];let a=e.argChoices??Bs(n),o=[`-l ${J(i)}`,e.short===void 0?``:`${e.short.startsWith(`--`)?`-l`:`-s`} ${J(e.short.replace(/^-+/,``))}`].filter(Boolean),s=t===void 0?``:` -n ${J(t)}`,c=e.required||e.optional?Ps(a,Fs(i,n)):`-f`,l=`${Ys(r)}${s} ${o.join(` `)} ${c}`;return a===void 0||a.length===0?[`${l} -d ${J(Zs(e.description))}`]:a.map(t=>`${l} -a ${J(t)} -d ${J(Zs(e.description))}`)}function Ps(e,t){return e!==void 0&&e.length>0?`-x`:t?`-r -F`:`-r -f`}function Fs(e,t){return e===`from-file`?!0:t===void 0||t.some(({location:e})=>e!==`body`)?!1:t.every(({schemaFormat:e})=>e===`binary`)?!0:t.length===1&&[`file`,`path`].includes(e.split(`-`).at(-1)??``)}function Is(e){return new Map(e.flatMap(e=>[...e.parameters.map(e=>[e]),...Rn(e.requestBody??[]).map(({variant:e})=>e.map(({parameter:e})=>e))].flatMap(t=>{let n=t[0];if(n===void 0)throw Error(`Generated CLI option has no parameter`);return[[Ls(e.cliPath,n),t]]})))}function Ls(e,t){let n=`flag`in t?t.flag.split(/\s+/)[0]?.replace(/^--/,``):Gs(t);if(`flag`in t&&(n===void 0||n.length===0||n===t.flag))throw Error(`Cannot render completion for option flag: ${t.flag}`);return`${e.join(`\0`)}\u0000${n??``}`}function Rs(e){return Ks(e).flatMap(e=>e.commands.map(t=>({parentPath:Js(e),name:t.name(),description:Zs(t.summary()||t.description()||t.name())})))}function zs(e,t){let n=[],r=[];for(let i of Ks(e)){let e=Js(i);for(let a of Ms(i)){let i=Gs(a);if(i===void 0)continue;let o=t.get(Ls(e,a));if(!Vs(o))continue;let s=a.argChoices??Bs(o),c=`none`;(a.required||a.optional)&&(c=s!==void 0&&s.length>0?`choice`:`scalar`,c===`scalar`&&Fs(i,o)&&(c=`file`)),n.push(Us([e.join(` `),`--${i}`,a.short??``,a.description,c]));for(let t of s??[])r.push(Us([e.join(` `),`--${i}`,t,a.description]))}}return[Rs(e).map(e=>Us([e.parentPath.join(` `),e.name,e.description])).toSorted((e,t)=>e.localeCompare(t)),n.toSorted((e,t)=>e.localeCompare(t)),r.toSorted((e,t)=>e.localeCompare(t))]}function Bs(e){let t=e?.[0]?.choices;if(e!==void 0&&t!==void 0)return e.every(e=>e.choices?.length===t.length&&e.choices.every((e,n)=>e===t[n]))?t:void 0}function Vs(e){return e?.some(({visibility:e})=>e!==`private`)??!0}function Hs(e){let t=e===`bash`,n=t?`COMP_WORDS`:`words`,r=t?`COMP_CWORD`:`CURRENT`,i=t?"${path[*]}":"${(j: :)path}",a=t?'"${_aventure_cli_options[@]}"':`$_aventure_cli_options`,o=t?'"${_aventure_cli_values[@]}"':`$_aventure_cli_values`,s=t?'"${_aventure_cli_commands[@]}"':`$_aventure_cli_commands`;return[`function _aventure_cli {`,` local current="\${${n}[${r}]}" previous="\${${n}[${r}-1]}" row row_path long short description mode name value option token key prefix candidate file_current`,...t?[` COMPREPLY=()`]:[],` local index=${t?1:2} skip_next=0; local -a path names descriptions`,` while (( index < ${r} )); do`,` token="\${${n}[index]}"; (( skip_next )) && { skip_next=0; (( index++ )); continue; }`,` if [[ "$token" == -* && "$token" != "-" && "$token" != "--" ]]; then`,` option="\${token%%=*}"; key="${i}"; mode=''`,` for row in ${a}; do IFS='|' read -r row_path long short description mode <<< "$row"; [[ "$row_path" == "$key" && ( "$long" == "$option" || "$short" == "$option" ) ]] && break; mode=''; done`,` [[ -n "$mode" && "$mode" != none && "$token" != *=* ]] && skip_next=1`,` elif [[ "$token" != -* ]]; then path+=("$token"); fi`,` (( index++ ))`,` done`,` key="${i}"`,` if [[ "$current" == --*=* || ( "$previous" == -* && "$current" != -* ) ]]; then`,` option="$previous"; prefix=''; file_current="$current"; [[ "$current" == --*=* ]] && { option="\${current%%=*}"; prefix="$option="; file_current="\${current#*=}"; }`,` for row in ${a}; do IFS='|' read -r row_path long short description mode <<< "$row"; [[ "$row_path" == "$key" && ( "$long" == "$option" || "$short" == "$option" ) ]] && { option="$long"; break; }; mode=''; done`,t?` [[ "$mode" == file ]] && { while IFS= read -r candidate; do COMPREPLY+=("$prefix$candidate"); done < <(compgen -f -- "$file_current"); return 0; }`:` [[ "$mode" == file ]] && { _files; return 0; }`,t?` [[ "$mode" == choice ]] && for row in ${o}; do IFS='|' read -r row_path long value description <<< "$row"; [[ "$row_path" == "$key" && "$long" == "$option" ]] && { candidate="$prefix$value"; [[ "$candidate" == "$current"* ]] && COMPREPLY+=("$candidate"); }; done`:` [[ "$mode" == choice ]] && for row in ${o}; do IFS='|' read -r row_path long value description <<< "$row"; [[ "$row_path" == "$key" && "$long" == "$option" ]] && { names+=("$prefix$value"); descriptions+=("$description"); }; done`,` elif [[ "$current" == -* ]]; then`,` for row in ${a}; do`,` IFS='|' read -r row_path long short description mode <<< "$row"`,t?` [[ "$row_path" == "$key" ]] && { [[ "$long" == "$current"* ]] && COMPREPLY+=("$long"); [[ -n "$short" && "$short" == "$current"* ]] && COMPREPLY+=("$short"); }`:` [[ "$row_path" == "$key" ]] && { names+=("$long"); descriptions+=("$description"); [[ -n "$short" ]] && { names+=("$short"); descriptions+=("$description"); }; }`,` done`,` elif [[ "$previous" != -* ]]; then`,` for row in ${s}; do`,` IFS='|' read -r row_path name description <<< "$row"`,t?` [[ "$row_path" == "$key" ]] && { [[ "$name" == "$current"* ]] && COMPREPLY+=("$name"); }`:` [[ "$row_path" == "$key" ]] && { names+=("$name"); descriptions+=("$description"); }`,` done`,` fi`,...t?[]:[" (( ${#names} )) && compadd -d descriptions -a names"],` return 0`,`}`,...t?[]:[`_aventure_cli "$@"`]]}function Us(e){return`$'${e.map(Ws).join(`|`)}'`}function Ws(e){return Zs(e).replaceAll(`\\`,`\\\\`).replaceAll(`'`,`\\'`).replaceAll(`|`,` `)}function Gs(e){return e.long?.replace(/^--/,``)}function Ks(e){return[e,...e.commands.filter(qs).flatMap(e=>Ks(e))]}var qs=e=>e.parent?.createHelp().visibleCommands(e.parent).includes(e)??!0;function Js(e){let t=[];for(let n=e;n?.parent!==null;n=n.parent)t.unshift(n.name());return t}function Ys(e){return`complete ${e.map(e=>`-c ${J(e)}`).join(` `)}`}function Xs(e){return[`__aventure_cli_path_is`,...e.map(J)].join(` `)}function Zs(e){return e.replace(/\s+/g,` `).trim()}function J(e){return`'${e.replace(/[\r\n\t]/g,` `).replaceAll(`\\`,`\\\\`).replaceAll(`'`,`\\'`)}'`}var Qs=/^error: unknown option '(.+)'$/mu,$s=/\n\(Did you mean (--[^\s,?]+)\?\)$/u,ec=class e extends i{createCommand(t){return new e(t)}error(e,t){return super.error(this.withoutSwitchSuggestion(e,t),t)}withoutSwitchSuggestion(e,t){if(t?.code!==`commander.unknownOption`)return e;let n=$s.exec(e),r=n?.[1],i=Qs.exec(e)?.[1];return n===null||r===void 0||i===void 0||!this.suppliesValue(i)||!this.suggestsBareSwitch(r)?e:e.slice(0,n.index)}suppliesValue(e){let t=this.args.indexOf(e);if(t===-1)return!1;if(e.includes(`=`))return!0;let n=this.args[t+1];return n!==void 0&&(n===`-`||!n.startsWith(`-`)||Number.isFinite(Number(n)))}suggestsBareSwitch(e,t=this){let n=t.createHelp().visibleOptions(t).find(t=>t.long===e);return n===void 0?t.parent!==null&&this.suggestsBareSwitch(e,t.parent):!n.required&&!n.optional}};function tc(e,t){if(e!==t)return;let n=nc(t);n!==void 0&&t.error(`error: ${ic(t)} takes text input, not a JSON object.\n${n}`,{code:`aventure.payloadOperand`})}function nc(e){if(!process.argv.includes(`--`)&&e.args.some(rc))return`hint: use the command's named options instead of a JSON payload; run --help to list them.`}function rc(e){if(!e.startsWith(`{`))return!1;try{return typeof JSON.parse(e)==`object`}catch{return!1}}function ic(e){let t=[];for(let n=e;n?.parent;n=n.parent)t.unshift(n.name());return t.join(` `)}function ac(e,t){return e.message.match(RegExp(`${t} '([^']+)'`,`iu`))?.[1]?.split(/\s+/u)[0]}function Y(e){return e.flags.split(` `)[0]??e.flags}function oc(e,t){let n=ac(t,`required option`),r=e.options.findIndex(e=>Y(e)===n);if(r<0)return;let i=new Set((wc(X(e))?.parameters??[]).flatMap(e=>e.location===`path`?[e.optionKey]:[])),a=e.options.slice(r+1).find(t=>{let n=e.getOptionValue(t.attributeName());return i.has(t.attributeName())&&typeof n==`string`&&n!==``});if(a!==void 0)return`hint: ${n} is still required for this nested command; supplied child selector ${Y(a)} does not replace the parent selector.`}var sc=[[`--search`,`--query`,`--q`,`--term`,`--keyword`],[`--size`,`--limit`,`--page-size`,`--per-page`],[`--transaction-id`,`--fundraise-round-id`]];function cc(e){let t=new Set(e.options.map(Y)),n=process.argv.indexOf(`--`),r=new Set(n<0?process.argv:process.argv.slice(0,n));return e.args.filter(e=>r.has(e)&&/^--[^-=]/u.test(e)).map(e=>e.split(`=`)[0]??e).filter(e=>!t.has(e))}function lc(e){let t=wc(X(e))?.parameters??[],n=cc(e).flatMap(n=>{let r=sc.find(e=>e.includes(n))?.find(t=>e.options.some(e=>Y(e)===t))??t.filter(({name:e})=>`--${e.replace(/[A-Z]/gu,`-$&`).toLowerCase()}`===n).map(e=>e.flag.split(` `)[0])[0];return r===void 0?[]:[`use ${r}, not ${n}`]});return n.length===0?void 0:`hint: ${n.join(`; `)}`}function X(e){return e.parent===null?[]:[...X(e.parent),e.name()]}function uc(e){return e.commands.length===0?[e]:e.commands.flatMap(uc)}function Z(e){return e.parent===null?e:Z(e.parent)}function dc(e,t){let n=t=>{let n=X(t).slice(X(e).length);return n.length*2+ +![`get`,`list`].includes(n.at(-1)??``)};return t.toSorted((e,t)=>n(e)-n(t))[0]}function fc(e){return/^[A-Za-z0-9_./:=@+-]+$/u.test(e)?e:`'${e.replaceAll(`'`,`'"'"'`)}'`}function pc(e,t){let n=[...e.options,...e.createHelp().visibleOptions(e)];for(let t=e.parent;t!==null;t=t.parent)n.push(...t.options);let r=t,i;for(let e=0;e<t.length;e++){let a=t[e];if(a===void 0||a===`--`)break;if(!a.startsWith(`-`)||a===`-`||i?.variadic&&Number.isFinite(Number(a)))continue;let o=a.indexOf(`=`),s=o<0?a:a.slice(0,o);if(i=n.find(e=>e.short===s||e.long===s),i===void 0||o>=0&&!i.required&&!i.optional){r=[`--help`];break}o<0&&(i.required||i.optional&&!t[e+1]?.startsWith(`-`))&&e++}return[Z(e).name(),...X(e),...r].map(fc).join(` `)}function mc(e,t){let n=ac(t,`unknown option`);if(n===void 0||e.commands.length===0)return;let r=dc(e,uc(e).filter(e=>e.options.some(e=>Y(e)===n)));return r===void 0?void 0:`hint: run: ${pc(r,process.argv.slice(2+X(e).length))}`}function hc(e){return e!==void 0&&Object.hasOwn(Ct,e)}function gc(e,t){return t.reduce((e,t)=>e?.commands.find(e=>e.name()===t),e)}function _c(e,t){let n=X(e),r=[...n.slice(1),t];if(!hc(n.at(0))||!hc(r.at(0)))return;let i=gc(Z(e),r);if(i===void 0)return;let a=i;for(let e of process.argv.slice(2+n.length+1)){if(e.startsWith(`-`))break;let t=a.commands.find(t=>t.name()===e);if(t===void 0)break;r.push(e),a=t}return r}function vc(e,t){let[n]=X(e);if(n===void 0||!hc(n))return;let r=[n,t];return gc(Z(e),r)?.commands.length===0?r:void 0}function yc(e){let[t,...n]=e.args;if(t===void 0)return[];let r=uc(Z(e)).map(X),i=n.findIndex((e,t)=>{let i=[...n.slice(0,t),e];return!r.some(e=>e.some((t,n)=>t===i[0]&&i.every((t,r)=>e[n+r]===t)))});return[t,...i<0?n:n.slice(0,i)]}function bc(e,t,n=[]){let r=X(e),i=Et(O).map(e=>e.cliPath).filter(e=>e[0]!==r[0]&&e.length>=t.length&&t.every((n,r)=>e[e.length-t.length+r]===n)),a=i.find(e=>e.length===t.length&&e.every((e,n)=>e===t[n]))??(i.length===1?i[0]:void 0);if(a===void 0)return;let o=gc(Z(e),a);return o===void 0?void 0:`hint: run: ${pc(o,n)}`}function xc(e,t,n){if(!Cc(t))return;let r=gc(Z(e),t);if(r===void 0)return;let i=e.args.slice(n.length),a=i.findIndex(e=>e.startsWith(`-`));return`hint: Did you mean: ${pc(r,a<0?[]:i.slice(a))}`}function Sc(e){let t=X(e);if(t.at(1)!==void 0&&hc(t.at(0)))return`hint: inspect generated command group: ${[Z(e).name(),...t,`--help`].map(fc).join(` `)}`}function Cc(e,t){let n=wc(e);return n!==void 0&&(t===void 0||g(n.intent)===t)}function wc(e){return O.find(t=>t.cliPath.join(` `)===e.join(` `))}function Tc(e){let t=X(e).join(` `),n=Et(O),r=n.find(e=>e.cliPath.join(` `)===t);return r===void 0?[]:Le(r.operationId,n,Z(e).name()).map(e=>`hint: ${e}`)}function Ec(e){let t=X(e);if(hc(t.at(0))&&Cc(t))return`hint: inspect generated command: ${[Z(e).name(),...t,`--help`].map(fc).join(` `)}`}function Dc(e){let t=new Set,n=[];for(let r of O){let i=gc(e,r.cliPath);if(i===void 0)continue;let a=i.options.map(Y);if(g(r.intent))n.push(a);else for(let e of a)t.add(e)}let[r=[],...i]=n;return new Set(r.filter(e=>!t.has(e)&&i.every(t=>t.includes(e))))}function Oc(e,t){let n=X(e);if(Cc(n,!1)&&Dc(Z(e)).has(t))return`hint: ${n.join(` `)} is a read operation; ${t} is a deprecated compatibility option only on mutation commands`}function kc(e,t,n=!0){let r=Z(e),i=r.commands.find(e=>e.name()===`command-catalog`),a=i?.commands.find(e=>e.name()===`search`);if(i===void 0||a===void 0)return;let o=[r.name(),i.name(),a.name(),t],s=X(e).at(0),c=a.options.find(e=>Y(e)===`--root`),l=n&&c!==void 0&&hc(s)?s:void 0;c!==void 0&&l!==void 0&&o.push(Y(c),l);let u=Et(O),d=Dr({q:t,root:l,limit:`3`},u,r.name()),f=d.ok&&d.data!==null?Jr(d.data,`compact`):``;return[`hint: search generated commands: ${o.map(fc).join(` `)}`,...f===``?[]:[`hint: closest commands (command · summary · required flags):`],...f.split(`
|
|
62
|
+
`))}function As(e,t){return Rs(e).map(e=>`${Ys(t)} -f -n ${J(Xs(e.parentPath))} -a ${J(e.name)} -d ${J(e.description)}`).toSorted((e,t)=>e.localeCompare(t))}function js(e,t,n){return Ks(e).flatMap(e=>{let r=Js(e),i=r.length===0?void 0:Xs(r);return Ms(e).flatMap(e=>{let a=t.get(Ls(r,e));return Vs(a)?Ns(e,i,a,n):[]})}).toSorted((e,t)=>e.localeCompare(t))}function Ms(e){return e.parent===null?e.createHelp().visibleOptions(e):e.options}function Ns(e,t,n,r){let i=Gs(e);if(i===void 0)return[];let a=e.argChoices??Bs(n),o=[`-l ${J(i)}`,e.short===void 0?``:`${e.short.startsWith(`--`)?`-l`:`-s`} ${J(e.short.replace(/^-+/,``))}`].filter(Boolean),s=t===void 0?``:` -n ${J(t)}`,c=e.required||e.optional?Ps(a,Fs(i,n)):`-f`,l=`${Ys(r)}${s} ${o.join(` `)} ${c}`;return a===void 0||a.length===0?[`${l} -d ${J(Zs(e.description))}`]:a.map(t=>`${l} -a ${J(t)} -d ${J(Zs(e.description))}`)}function Ps(e,t){return e!==void 0&&e.length>0?`-x`:t?`-r -F`:`-r -f`}function Fs(e,t){return e===`from-file`?!0:t===void 0||t.some(({location:e})=>e!==`body`)?!1:t.every(({schemaFormat:e})=>e===`binary`)?!0:t.length===1&&[`file`,`path`].includes(e.split(`-`).at(-1)??``)}function Is(e){return new Map(e.flatMap(e=>[...e.parameters.map(e=>[e]),...zn(e.requestBody??[]).map(({variant:e})=>e.map(({parameter:e})=>e))].flatMap(t=>{let n=t[0];if(n===void 0)throw Error(`Generated CLI option has no parameter`);return[[Ls(e.cliPath,n),t]]})))}function Ls(e,t){let n=`flag`in t?t.flag.split(/\s+/)[0]?.replace(/^--/,``):Gs(t);if(`flag`in t&&(n===void 0||n.length===0||n===t.flag))throw Error(`Cannot render completion for option flag: ${t.flag}`);return`${e.join(`\0`)}\u0000${n??``}`}function Rs(e){return Ks(e).flatMap(e=>e.commands.map(t=>({parentPath:Js(e),name:t.name(),description:Zs(t.summary()||t.description()||t.name())})))}function zs(e,t){let n=[],r=[];for(let i of Ks(e)){let e=Js(i);for(let a of Ms(i)){let i=Gs(a);if(i===void 0)continue;let o=t.get(Ls(e,a));if(!Vs(o))continue;let s=a.argChoices??Bs(o),c=`none`;(a.required||a.optional)&&(c=s!==void 0&&s.length>0?`choice`:`scalar`,c===`scalar`&&Fs(i,o)&&(c=`file`)),n.push(Us([e.join(` `),`--${i}`,a.short??``,a.description,c]));for(let t of s??[])r.push(Us([e.join(` `),`--${i}`,t,a.description]))}}return[Rs(e).map(e=>Us([e.parentPath.join(` `),e.name,e.description])).toSorted((e,t)=>e.localeCompare(t)),n.toSorted((e,t)=>e.localeCompare(t)),r.toSorted((e,t)=>e.localeCompare(t))]}function Bs(e){let t=e?.[0]?.choices;if(e!==void 0&&t!==void 0)return e.every(e=>e.choices?.length===t.length&&e.choices.every((e,n)=>e===t[n]))?t:void 0}function Vs(e){return e?.some(({visibility:e})=>e!==`private`)??!0}function Hs(e){let t=e===`bash`,n=t?`COMP_WORDS`:`words`,r=t?`COMP_CWORD`:`CURRENT`,i=t?"${path[*]}":"${(j: :)path}",a=t?'"${_aventure_cli_options[@]}"':`$_aventure_cli_options`,o=t?'"${_aventure_cli_values[@]}"':`$_aventure_cli_values`,s=t?'"${_aventure_cli_commands[@]}"':`$_aventure_cli_commands`;return[`function _aventure_cli {`,` local current="\${${n}[${r}]}" previous="\${${n}[${r}-1]}" row row_path long short description mode name value option token key prefix candidate file_current`,...t?[` COMPREPLY=()`]:[],` local index=${t?1:2} skip_next=0; local -a path names descriptions`,` while (( index < ${r} )); do`,` token="\${${n}[index]}"; (( skip_next )) && { skip_next=0; (( index++ )); continue; }`,` if [[ "$token" == -* && "$token" != "-" && "$token" != "--" ]]; then`,` option="\${token%%=*}"; key="${i}"; mode=''`,` for row in ${a}; do IFS='|' read -r row_path long short description mode <<< "$row"; [[ "$row_path" == "$key" && ( "$long" == "$option" || "$short" == "$option" ) ]] && break; mode=''; done`,` [[ -n "$mode" && "$mode" != none && "$token" != *=* ]] && skip_next=1`,` elif [[ "$token" != -* ]]; then path+=("$token"); fi`,` (( index++ ))`,` done`,` key="${i}"`,` if [[ "$current" == --*=* || ( "$previous" == -* && "$current" != -* ) ]]; then`,` option="$previous"; prefix=''; file_current="$current"; [[ "$current" == --*=* ]] && { option="\${current%%=*}"; prefix="$option="; file_current="\${current#*=}"; }`,` for row in ${a}; do IFS='|' read -r row_path long short description mode <<< "$row"; [[ "$row_path" == "$key" && ( "$long" == "$option" || "$short" == "$option" ) ]] && { option="$long"; break; }; mode=''; done`,t?` [[ "$mode" == file ]] && { while IFS= read -r candidate; do COMPREPLY+=("$prefix$candidate"); done < <(compgen -f -- "$file_current"); return 0; }`:` [[ "$mode" == file ]] && { _files; return 0; }`,t?` [[ "$mode" == choice ]] && for row in ${o}; do IFS='|' read -r row_path long value description <<< "$row"; [[ "$row_path" == "$key" && "$long" == "$option" ]] && { candidate="$prefix$value"; [[ "$candidate" == "$current"* ]] && COMPREPLY+=("$candidate"); }; done`:` [[ "$mode" == choice ]] && for row in ${o}; do IFS='|' read -r row_path long value description <<< "$row"; [[ "$row_path" == "$key" && "$long" == "$option" ]] && { names+=("$prefix$value"); descriptions+=("$description"); }; done`,` elif [[ "$current" == -* ]]; then`,` for row in ${a}; do`,` IFS='|' read -r row_path long short description mode <<< "$row"`,t?` [[ "$row_path" == "$key" ]] && { [[ "$long" == "$current"* ]] && COMPREPLY+=("$long"); [[ -n "$short" && "$short" == "$current"* ]] && COMPREPLY+=("$short"); }`:` [[ "$row_path" == "$key" ]] && { names+=("$long"); descriptions+=("$description"); [[ -n "$short" ]] && { names+=("$short"); descriptions+=("$description"); }; }`,` done`,` elif [[ "$previous" != -* ]]; then`,` for row in ${s}; do`,` IFS='|' read -r row_path name description <<< "$row"`,t?` [[ "$row_path" == "$key" ]] && { [[ "$name" == "$current"* ]] && COMPREPLY+=("$name"); }`:` [[ "$row_path" == "$key" ]] && { names+=("$name"); descriptions+=("$description"); }`,` done`,` fi`,...t?[]:[" (( ${#names} )) && compadd -d descriptions -a names"],` return 0`,`}`,...t?[]:[`_aventure_cli "$@"`]]}function Us(e){return`$'${e.map(Ws).join(`|`)}'`}function Ws(e){return Zs(e).replaceAll(`\\`,`\\\\`).replaceAll(`'`,`\\'`).replaceAll(`|`,` `)}function Gs(e){return e.long?.replace(/^--/,``)}function Ks(e){return[e,...e.commands.filter(qs).flatMap(e=>Ks(e))]}var qs=e=>e.parent?.createHelp().visibleCommands(e.parent).includes(e)??!0;function Js(e){let t=[];for(let n=e;n?.parent!==null;n=n.parent)t.unshift(n.name());return t}function Ys(e){return`complete ${e.map(e=>`-c ${J(e)}`).join(` `)}`}function Xs(e){return[`__aventure_cli_path_is`,...e.map(J)].join(` `)}function Zs(e){return e.replace(/\s+/g,` `).trim()}function J(e){return`'${e.replace(/[\r\n\t]/g,` `).replaceAll(`\\`,`\\\\`).replaceAll(`'`,`\\'`)}'`}var Qs=/^error: unknown option '(.+)'$/mu,$s=/\n\(Did you mean (--[^\s,?]+)\?\)$/u,ec=class e extends i{createCommand(t){return new e(t)}error(e,t){return super.error(this.withoutSwitchSuggestion(e,t),t)}withoutSwitchSuggestion(e,t){if(t?.code!==`commander.unknownOption`)return e;let n=$s.exec(e),r=n?.[1],i=Qs.exec(e)?.[1];return n===null||r===void 0||i===void 0||!this.suppliesValue(i)||!this.suggestsBareSwitch(r)?e:e.slice(0,n.index)}suppliesValue(e){let t=this.args.indexOf(e);if(t===-1)return!1;if(e.includes(`=`))return!0;let n=this.args[t+1];return n!==void 0&&(n===`-`||!n.startsWith(`-`)||Number.isFinite(Number(n)))}suggestsBareSwitch(e,t=this){let n=t.createHelp().visibleOptions(t).find(t=>t.long===e);return n===void 0?t.parent!==null&&this.suggestsBareSwitch(e,t.parent):!n.required&&!n.optional}};function tc(e,t){if(e!==t)return;let n=nc(t);n!==void 0&&t.error(`error: ${ic(t)} takes text input, not a JSON object.\n${n}`,{code:`aventure.payloadOperand`})}function nc(e){if(!process.argv.includes(`--`)&&e.args.some(rc))return`hint: use the command's named options instead of a JSON payload; run --help to list them.`}function rc(e){if(!e.startsWith(`{`))return!1;try{return typeof JSON.parse(e)==`object`}catch{return!1}}function ic(e){let t=[];for(let n=e;n?.parent;n=n.parent)t.unshift(n.name());return t.join(` `)}function ac(e,t){return e.message.match(RegExp(`${t} '([^']+)'`,`iu`))?.[1]?.split(/\s+/u)[0]}function Y(e){return e.flags.split(` `)[0]??e.flags}function oc(e,t){let n=ac(t,`required option`),r=e.options.findIndex(e=>Y(e)===n);if(r<0)return;let i=new Set((wc(X(e))?.parameters??[]).flatMap(e=>e.location===`path`?[e.optionKey]:[])),a=e.options.slice(r+1).find(t=>{let n=e.getOptionValue(t.attributeName());return i.has(t.attributeName())&&typeof n==`string`&&n!==``});if(a!==void 0)return`hint: ${n} is still required for this nested command; supplied child selector ${Y(a)} does not replace the parent selector.`}var sc=[[`--search`,`--query`,`--q`,`--term`,`--keyword`],[`--size`,`--limit`,`--page-size`,`--per-page`],[`--transaction-id`,`--fundraise-round-id`]];function cc(e){let t=new Set(e.options.map(Y)),n=process.argv.indexOf(`--`),r=new Set(n<0?process.argv:process.argv.slice(0,n));return e.args.filter(e=>r.has(e)&&/^--[^-=]/u.test(e)).map(e=>e.split(`=`)[0]??e).filter(e=>!t.has(e))}function lc(e){let t=wc(X(e))?.parameters??[],n=cc(e).flatMap(n=>{let r=sc.find(e=>e.includes(n))?.find(t=>e.options.some(e=>Y(e)===t))??t.filter(({name:e})=>`--${e.replace(/[A-Z]/gu,`-$&`).toLowerCase()}`===n).map(e=>e.flag.split(` `)[0])[0];return r===void 0?[]:[`use ${r}, not ${n}`]});return n.length===0?void 0:`hint: ${n.join(`; `)}`}function X(e){return e.parent===null?[]:[...X(e.parent),e.name()]}function uc(e){return e.commands.length===0?[e]:e.commands.flatMap(uc)}function Z(e){return e.parent===null?e:Z(e.parent)}function dc(e,t){let n=t=>{let n=X(t).slice(X(e).length);return n.length*2+ +![`get`,`list`].includes(n.at(-1)??``)};return t.toSorted((e,t)=>n(e)-n(t))[0]}function fc(e){return/^[A-Za-z0-9_./:=@+-]+$/u.test(e)?e:`'${e.replaceAll(`'`,`'"'"'`)}'`}function pc(e,t){let n=[...e.options,...e.createHelp().visibleOptions(e)];for(let t=e.parent;t!==null;t=t.parent)n.push(...t.options);let r=t,i;for(let e=0;e<t.length;e++){let a=t[e];if(a===void 0||a===`--`)break;if(!a.startsWith(`-`)||a===`-`||i?.variadic&&Number.isFinite(Number(a)))continue;let o=a.indexOf(`=`),s=o<0?a:a.slice(0,o);if(i=n.find(e=>e.short===s||e.long===s),i===void 0||o>=0&&!i.required&&!i.optional){r=[`--help`];break}o<0&&(i.required||i.optional&&!t[e+1]?.startsWith(`-`))&&e++}return[Z(e).name(),...X(e),...r].map(fc).join(` `)}function mc(e,t){let n=ac(t,`unknown option`);if(n===void 0||e.commands.length===0)return;let r=dc(e,uc(e).filter(e=>e.options.some(e=>Y(e)===n)));return r===void 0?void 0:`hint: run: ${pc(r,process.argv.slice(2+X(e).length))}`}function hc(e){return e!==void 0&&Object.hasOwn(Ct,e)}function gc(e,t){return t.reduce((e,t)=>e?.commands.find(e=>e.name()===t),e)}function _c(e,t){let n=X(e),r=[...n.slice(1),t];if(!hc(n.at(0))||!hc(r.at(0)))return;let i=gc(Z(e),r);if(i===void 0)return;let a=i;for(let e of process.argv.slice(2+n.length+1)){if(e.startsWith(`-`))break;let t=a.commands.find(t=>t.name()===e);if(t===void 0)break;r.push(e),a=t}return r}function vc(e,t){let[n]=X(e);if(n===void 0||!hc(n))return;let r=[n,t];return gc(Z(e),r)?.commands.length===0?r:void 0}function yc(e){let[t,...n]=e.args;if(t===void 0)return[];let r=uc(Z(e)).map(X),i=n.findIndex((e,t)=>{let i=[...n.slice(0,t),e];return!r.some(e=>e.some((t,n)=>t===i[0]&&i.every((t,r)=>e[n+r]===t)))});return[t,...i<0?n:n.slice(0,i)]}function bc(e,t,n=[]){let r=X(e),i=Et(O).map(e=>e.cliPath).filter(e=>e[0]!==r[0]&&e.length>=t.length&&t.every((n,r)=>e[e.length-t.length+r]===n)),a=i.find(e=>e.length===t.length&&e.every((e,n)=>e===t[n]))??(i.length===1?i[0]:void 0);if(a===void 0)return;let o=gc(Z(e),a);return o===void 0?void 0:`hint: run: ${pc(o,n)}`}function xc(e,t,n){if(!Cc(t))return;let r=gc(Z(e),t);if(r===void 0)return;let i=e.args.slice(n.length),a=i.findIndex(e=>e.startsWith(`-`));return`hint: Did you mean: ${pc(r,a<0?[]:i.slice(a))}`}function Sc(e){let t=X(e);if(t.at(1)!==void 0&&hc(t.at(0)))return`hint: inspect generated command group: ${[Z(e).name(),...t,`--help`].map(fc).join(` `)}`}function Cc(e,t){let n=wc(e);return n!==void 0&&(t===void 0||g(n.intent)===t)}function wc(e){return O.find(t=>t.cliPath.join(` `)===e.join(` `))}function Tc(e){let t=X(e).join(` `),n=Et(O),r=n.find(e=>e.cliPath.join(` `)===t);return r===void 0?[]:Le(r.operationId,n,Z(e).name()).map(e=>`hint: ${e}`)}function Ec(e){let t=X(e);if(hc(t.at(0))&&Cc(t))return`hint: inspect generated command: ${[Z(e).name(),...t,`--help`].map(fc).join(` `)}`}function Dc(e){let t=new Set,n=[];for(let r of O){let i=gc(e,r.cliPath);if(i===void 0)continue;let a=i.options.map(Y);if(g(r.intent))n.push(a);else for(let e of a)t.add(e)}let[r=[],...i]=n;return new Set(r.filter(e=>!t.has(e)&&i.every(t=>t.includes(e))))}function Oc(e,t){let n=X(e);if(Cc(n,!1)&&Dc(Z(e)).has(t))return`hint: ${n.join(` `)} is a read operation; ${t} is a deprecated compatibility option only on mutation commands`}function kc(e,t,n=!0){let r=Z(e),i=r.commands.find(e=>e.name()===`command-catalog`),a=i?.commands.find(e=>e.name()===`search`);if(i===void 0||a===void 0)return;let o=[r.name(),i.name(),a.name(),t],s=X(e).at(0),c=a.options.find(e=>Y(e)===`--root`),l=n&&c!==void 0&&hc(s)?s:void 0;c!==void 0&&l!==void 0&&o.push(Y(c),l);let u=Et(O),d=Or({q:t,root:l,limit:`3`},u,r.name()),f=d.ok&&d.data!==null?Yr(d.data,`compact`):``;return[`hint: search generated commands: ${o.map(fc).join(` `)}`,...f===``?[]:[`hint: closest commands (command · summary · required flags):`],...f.split(`
|
|
54
63
|
`).filter(Boolean).map(e=>` ${e}`)].join(`
|
|
55
64
|
`)}function Ac(e,t=``){if(e.commands.length>0&&!Cc(X(e)))return;let n=e.options.flatMap(e=>e.hidden?[]:[Y(e)]),r=Et(O),i=He(t,r,X(e),Z(e).name());return`${i===void 0?``:`hint: an id you already hold is read with: ${i}\n`}hint: ${X(e).join(` `)} accepts: ${n.join(` `)}`}function jc(e,t){let n=ac(t,`unknown command`);if(n===void 0||t.message.includes(`
|
|
56
65
|
(Did you mean `))return;let r=yc(e),i=process.argv.slice(2+X(e).length);if(r.length>0&&r.every((e,t)=>i[t]===e)){let t=bc(e,r);if(t!==void 0)return t}let a=X(e),o=[...a.slice(0,-1),`${a.at(-1)}-${n}`,...r.slice(1)],s=(Cc(o)?o:void 0)??_c(e,n)??vc(e,n);if(s!==void 0)return xc(e,s,r)??kc(e,s.join(` `),!1);let c=r.join(` `)||n,l=Sc(e)??kc(e,c),u=[...a,...r.slice(1)];return[l,r.length===a.length+a.length&&a.at(-1)===a.at(0)?xc(e,u,r)?.replace(/^hint: Did you mean: /u,` `)+` · `:u.slice(1,-1).length>0?xc(e,u,r):void 0].filter(e=>e!==void 0).join(`
|
|
57
66
|
`)||void 0}function Mc(e){return t=>{if(t.code===`commander.missingMandatoryOptionValue`){let n=e.options.filter(t=>t.mandatory&&e.getOptionValue(t.attributeName())===void 0);if(n.length>1){let e=n.map(e=>e.flags.split(`, `).at(-1)??e.flags);process.stderr.write(`error: missing required options: ${e.join(`, `)}\n`)}let r=cc(e);for(let e of r)process.stderr.write(`error: unknown option '${e}'\n`);for(let n of[lc(e)??(r.length>0?Ac(e):void 0),nc(e),oc(e,t),...Tc(e)])n!==void 0&&process.stderr.write(`${n}\n`)}else if(t.code===`commander.excessArguments`){let t=nc(e)??Ec(e);t!==void 0&&process.stderr.write(`${t}\n`)}else if(t.code===`commander.unknownOption`){let n=ac(t,`unknown option`),r=lc(e)??mc(e,t)??(n!==void 0&&!t.message.includes(`
|
|
58
67
|
(Did you mean `)?Oc(e,n)??bc(e,[n.replace(/^--/u,``)],process.argv.slice(process.argv.indexOf(n)+1))??Ac(e,n)??kc(e,X(e).slice(1).join(` `)||n.replace(/^--/u,``)):void 0);r!==void 0&&process.stderr.write(`${r}\n`)}else if(t.code===`commander.unknownCommand`){let n=jc(e,t);n!==void 0&&process.stderr.write(`${n}\n`)}else if(t.code===`commander.helpDisplayed`){let[n]=e.args;if(n?.startsWith(`-`)===!1&&e.registeredArguments.length===0){let r=[Z(e).name(),...X(e)].join(` `);t.exitCode=1,process.stderr.write(`hint: ${r} takes no '${n}' subcommand; the help shown is for ${r}\n`)}}throw t}}var Nc=class extends t{group;constructor(e){super(`-h, --help`,`display help for command`),this.group=e}is(e){if(e!==this.short&&e!==this.long)return!1;let t=this.group.args.at(0);return t===void 0||t.startsWith(`-`)?!0:this.group.commands.some(e=>e.name()===t||e.aliases().includes(t))}};function Pc(e){e.showHelpAfterError(!1).exitOverride(Mc(e)),e.commands.length===0?e.hook(`preAction`,tc):e.registeredArguments.length===0&&!wc(X(e))&&e.addHelpOption(new Nc(e));for(let t of e.commands)Pc(t)}function Fc(e,t=new Date){let n=Rc(e);return{schemaVersion:1,generatedFrom:`MCP_GENERATION_CONTRACT`,generatedAt:t.toISOString(),totalOperations:n.length,note:`Projection of MCP_GENERATION_CONTRACT - see mcp/scripts/build-unified-operations.ts header for SSOT rules.`,operations:n}}function Ic(e){return`${JSON.stringify(e,null,2)}\n`}function Lc(e,t){let n=N(e),r=Ic(t);return Bt(M(n),{recursive:!0}),Jt(n,r),{target:n,byteLength:Buffer.byteLength(r,`utf8`),totalOperations:t.totalOperations}}function Rc(e){return e.map(e=>({operationId:e.operationId,method:e.method,path:e.path,resource:e.resource,intent:e.intent,cliCommand:e.projection.cliPath.join(` `),cliPath:e.projection.cliPath,mcpTool:ee(e.intent),bodySchemaName:e.requestBody?.[0]?.schemaName??null,bodySchemaImport:e.requestBody?.[0]?.schemaImport??null,auth:e.projection.auth,scope:e.projection.scope,destructive:e.projection.destructive})).toSorted((e,t)=>e.path.localeCompare(t.path)||e.method.localeCompare(t.method)||e.operationId.localeCompare(t.operationId))}var zc=`Match only the first canonical or CLI-alias command segment`,Bc=[`text`,`lines`,`compact`,`json`,`ndjson`];function Vc(e,t,n=w().bin[0]){let r=e.command(`command-catalog`).summary(`LLM agent only: search generated CLI metadata`).description([`LLM agent only: search and dump generated ${n} command metadata.`,`This is read-only command metadata derived from the generated OpenAPI command specs.`,`Use --format lines for rg/grep/ag/ack and --format ndjson|json for ast-grep/sg/parsers.`,"Use --format compact for one `cli · summary · requiredFlags` row per operation."].join(`
|
|
59
|
-
`));r.addHelpText(`after`,()=>`\nShipped compact catalog of operations callable without an admin grant, greppable without\nrunning this CLI (dump --format compact lists every operation your credential reaches):\n ${
|
|
60
|
-
`));let f=Mt(t);for(let e of t.parameters)Qc(u,e,i||e===f);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
68
|
+
`));r.addHelpText(`after`,()=>`\nShipped compact catalog of operations callable without an admin grant, greppable without\nrunning this CLI (dump --format compact lists every operation your credential reaches):\n ${Vr(n)}\n`),Hc(r,t,n),Uc(r,t,n),Wc(r,t,n),Gc(r)}function Hc(e,n,r){let i=e.command(`search`).summary(`Search generated operations`).description(`Search generated operation metadata without calling the API.`).argument(`[query...]`,`Search query; same as --q.`).option(`--q <query>`,`Search generated command metadata`).option(`--root <root>`,zc).addOption(new t(`--scope <scope>`,`Filter by required auth scope`).choices([`read`,`write`,`all`]).default(`all`)).addOption(new t(`--mutates <mutates>`,`Filter mutating operations`).choices([`true`,`false`,`any`]).default(`any`)).addOption(new t(`--destructive <destructive>`,`Filter destructive operations`).choices([`true`,`false`,`any`]).default(`any`)).addOption(new t(`--intent <intent>`,`Filter by operation intent`).choices([`read`,`lookup`,`search`,`write`,`delete`,`status`,`all`]).default(`all`)).addOption(new t(`--method <method>`,`Filter by HTTP method`).choices([`GET`,`POST`,`PUT`,`PATCH`,`DELETE`,`all`]).default(`all`)).option(`--limit <count>`,`Maximum rows to return`,`20`).addOption(new t(`--format <format>`,`Text/file render format`).choices(Bc)).option(`--output <path>`,`Write rendered output to a file`);A(i),i.action(function(e){let t=this.optsWithGlobals(),i=k(t,`text`),a=Ur(t,e);Wr(a,(a.q?.trim()??``)===``?n.filter(({deprecated:e})=>e!==!0):n,i,r)})}function Uc(e,n,r){let i=e.command(`show`).summary(`Show one generated operation`).description(`Show one generated operation by command path or operationId.`).option(`--command <command>`,`CLI command path, with or without ${r} prefix`).option(`--operation-id <operationId>`,`Generated OpenAPI operationId`).addOption(new t(`--format <format>`,`Text/file render format`).choices([`usage`,`lines`,`compact`,`json`,`ndjson`]).default(`usage`)).option(`--output <path>`,`Write rendered output to a file`);A(i),i.action(function(){let e=this.optsWithGlobals();Gr(e,n,k(e,`text`),r)})}function Wc(e,n,r){let i=e.command(`dump`).summary(`Dump generated operations`).description(`Dump generated operations for rg/grep/ag/ack or JSON/NDJSON tooling.`).option(`--root <root>`,zc).addOption(new t(`--scope <scope>`,`Filter by required auth scope`).choices([`read`,`write`,`all`]).default(`all`)).addOption(new t(`--mutates <mutates>`,`Filter mutating operations`).choices([`true`,`false`,`any`]).default(`any`)).addOption(new t(`--destructive <destructive>`,`Filter destructive operations`).choices([`true`,`false`,`any`]).default(`any`)).addOption(new t(`--intent <intent>`,`Filter by operation intent`).choices([`read`,`lookup`,`search`,`write`,`delete`,`status`,`all`]).default(`all`)).addOption(new t(`--method <method>`,`Filter by HTTP method`).choices([`GET`,`POST`,`PUT`,`PATCH`,`DELETE`,`all`]).default(`all`)).option(`--limit <count>`,`Maximum rows to return`).addOption(new t(`--format <format>`,`Text/file render format`).choices(Bc)).option(`--output <path>`,`Write rendered output to a file`);A(i),i.action(function(){let e=this.optsWithGlobals();Wr(e,n,k(e,`text`),r)})}function Gc(e){let t=e.command(`unified`).summary(`Dump unified CLI/API/MCP operation JSON`).description(`Dump the flat unified operations JSON projected from MCP_GENERATION_CONTRACT.`).option(`--output <path>`,`Write unified operations JSON to a file`);A(t),t.action(async function(){let e=this.optsWithGlobals(),t=k(e,`text`),{MCP_GENERATION_CONTRACT:n}=await import(`./mcp-generation-contract-v7KJV9zz.js`);if(t===`text`&&e.output===void 0&&(e.text===!0||e.allFields===!0)){z({mode:t},S(`Unified operations JSON`,`Use --output <path> to write the unified operations JSON.`,{counts:{totalOperations:n.length}}));return}let r=Fc(n);if(e.output!==void 0){let n=Lc(e.output,r);z({mode:t},S(`Unified operations JSON written`,{outputPath:n.target,byteLength:n.byteLength,schemaVersion:r.schemaVersion},{counts:{totalOperations:n.totalOperations}}))}else t===`text`?qr(`Unified operations JSON`,Ic(r)):z({mode:t},S(`Unified operations JSON`,r,{counts:{totalOperations:r.totalOperations}}))})}var Kc=w(tn(import.meta.url)),Q=Kc.bin[0];function qc(e,t){let n=e instanceof Error?e:Error(String(e));c({component:Q,event:`fatal`,message:n.message,error:n}),process.stderr.write(`${Q} fatal (${t}): ${n.stack??n.message}\n`);let r=n instanceof ye?{httpStatus:n.problem.status,problem:n.problem}:{};vr({...C(`${Q} ${t}: ${n.message}`,[n.name||`Error`],r),counts:{exitCode:1}}),process.exit(1)}function Jc(e){return Xe[Ke(e,Ct)??`cli`]}function Yc(e,t){let n=t.map(e=>{let t=e.cliPath[0]??``;return{spec:e,top:t,rank:Jc(t).rank}}).toSorted((e,t)=>e.rank-t.rank||e.top.localeCompare(t.top)).map(e=>e.spec),r=new Set(n.filter(e=>jt(e.cliPath[0])).map(e=>e.cliPath[0]??``)),i=new Set,a=new Set;for(let{cliPath:e,deprecated:t}of n)for(let n=1;n<e.length;n++){let r=e.slice(0,n).join(` `);i.add(r),t!==!0&&a.add(r)}for(let t of n)Xc(e,t,r,a,i.has(t.cliPath.join(` `)))}function Xc(e,t,n,r,i){let a=t.cliPath,o=e,s=``,c=!n.has(a[0]??``);for(let e of a.slice(0,-1)){s=s===``?e:`${s} ${e}`;let t=c&&s===e||!r.has(s);o=Zc(o,e,s,t)}let l=a.at(-1)??t.operationId,u=o.commands.find(e=>e.name()===l)??o.command(l,t.deprecated===!0?{hidden:!0}:{}),d=t.requestBody?.flatMap(({parameter:e})=>e)??[];u.summary(t.summary||t.operationId).description([`${t.method} ${t.path}.`,t.summary||t.description,`Full documentation: ${Q} help ${t.cliPath.join(` `)}`,t.requestBody?.[0]?.kind===`json`||[...t.parameters,...d].some(e=>m(e.schemaType,e.itemSchemaType))?te:``].filter(Boolean).join(`
|
|
69
|
+
`));let f=Mt(t);for(let e of t.parameters)Qc(u,e,i||e===f);Xn(u,t),g(t.intent)&&u.option(`--execute`,`Deprecated; accepted and ignored. This command executes by its verb.`,!1),A(u),u.hook(`preAction`,e=>Dt(e,t)),t.explain===!0&&u.option(`--explain`,`Print the search strategy and parsed constraints before the results`),f!==void 0&&u.argument(`[text...]`,f.description||`Same as ${At(f.flag)}.`),u.action(async function(){let e=this.optsWithGlobals(),n=k(e),r=e;if(f!==void 0){let t=Tt(f,this.args,e);if(!t.ok||t.data===null)return z({mode:n},t);r=t.data}let i=wt(t,r);if(i.length>0)return z({mode:n},C(`missing required options: ${i.join(`, `)}`));let a=await $c(t,r,n),o=hi(t,r,a);if(o!==null)return z({mode:n},o);e.explain===!0&&a.ok&&Sr(n,a.data),a.ok&&a.data instanceof Uint8Array?process.stdout.write(a.data):z({mode:n},a)})}function Zc(e,t,n,r){let i=e.commands.find(e=>e.name()===t);if(i!==void 0)return i;let a=Ct[n],o=e.command(t,r?{hidden:!0}:{}).helpCommand(!1);return a!==void 0&&o.summary(a.summary).description(a.summary),o}function Qc(e,n,r=!1){let i=n.description||`${n.name} ${n.location} parameter`,a=n.defaultValue===void 0?void 0:typeof n.defaultValue==`string`||typeof n.defaultValue==`boolean`?n.defaultValue:[...n.defaultValue];if(n.legacyFlag!==void 0){let o=new t(n.flag,i);a!==void 0&&o.default(a);let s=new t(n.legacyFlag,i).conflicts(n.optionKey);e.addOption(o).addOption(s),e.hook(`preAction`,e=>{let t=e.opts(),i=t[n.optionKey],a=t[s.attributeName()];a===void 0?!r&&n.required&&i===void 0&&e.error(`error: required option '${o.flags}' not specified`,{code:`commander.missingMandatoryOptionValue`}):(i===void 0||e.getOptionValueSource(n.optionKey)==="default")&&e.setOptionValueWithSource(n.optionKey,a,`cli`)})}else a===void 0?n.required&&!r?e.requiredOption(n.flag,i):e.option(n.flag,i):e.option(n.flag,i,a)}async function $c(e,t,n){if(t.environment!==void 0){let e=d(t.environment);if(e===null)return C(`Unknown aVenture environment '${t.environment}'`,[`Use one of: ${a().join(`, `)}`]);process.env.API_ENV=e}let r=await tr(e,t);if(!r.ok)return r;let i=Object.fromEntries(e.parameters.filter(e=>e.location===`path`).map(e=>{let n=t[e.optionKey];if(Array.isArray(n))return[e.name,n.at(0)??``];if(n===void 0)throw Error(`Missing required option ${e.optionKey}`);return[e.name,String(n)]})),o=Object.fromEntries(e.parameters.filter(e=>e.location===`query`).flatMap(e=>{let n=t[e.optionKey];if(n===void 0||Array.isArray(n)&&n.length===0)return[];let r=Array.isArray(n)||typeof n==`boolean`?n:String(n);return[[e.name,r]]})),s=Object.fromEntries(e.parameters.filter(e=>e.location===`header`).flatMap(e=>{let n=t[e.optionKey];return n===void 0||Array.isArray(n)&&n.length===0?[]:[[e.name,Array.isArray(n)?n.join(`,`):String(n)]]}));return _i(e,await x({method:e.method,path:ue(e.operationId,i),searchParams:o,headers:s,body:r.data,contentType:kt(e,t),auth:e.auth,responseFormat:Pt(n)?`json`:`auto`,responseBytes:e.binaryResponse===!0,pendingResult:_r}))}process.on(`uncaughtException`,e=>qc(e,`uncaughtException`)),process.on(`unhandledRejection`,e=>qc(e,`unhandledRejection`));var el=Ot(process.argv.slice(2),O),tl=el===`required`?O:Et(O),$=new ec;$.name(Q).usage(`<command> [subcommand] [options]`).configureHelp(oi).version(Kc.version).summary(`CLI for the aVenture API: companies, people, and news, with the funding, publications, and classifications attached to them`).description(`The aVenture research API from your terminal. Three records — companies,
|
|
70
|
+
people, and news — carry everything else: funding, publications, and tags.
|
|
71
|
+
|
|
72
|
+
Mutations execute directly; --execute is a deprecated no-op.
|
|
73
|
+
The aVenture MCP server tools execute through this same CLI.`).addOption(new t(`--environment <environment>`,`route all API calls to a mapped API environment (default: API_URL host, else API_ENV, else ${l})`).choices([...a()])).showHelpAfterError(`(run \`${Q} --help\` for usage)`),Yc($,tl),Ho($,Q),fo($,Kc),xs($),Ts($,tl,Q),Vc($,tl,Q),ni($,tl,Q);for(let e of $.commands)e.helpGroup()||e.helpGroup(Jc(e.name()).heading);if(Pc($),el===`required`){let e=[$];for(;e.length>0;){let t=e.pop();t!==void 0&&(e.push(...t.commands),t.hook(`preAction`,async(e,t)=>{e===t&&(await vt(),await st())}))}}var nl=new Set($.commands.filter(e=>[`entities`,`people`,`news`].includes(e.name())).flatMap(e=>e.commands.map(e=>e.name())));$.addHelpText(`after`,[``,`Record subcommands under entities, people, and news:`,...[[`search`,` search Find many of that record from a plain-English query or a filter`],[`lookup`,` lookup Find one news article; companies and people use the root lookup`],[`get`,` get Read one record`],[`list`,` list Read many records`],[`create`,` create, update, delete Write; each needs a credential that permits it`]].flatMap(([e,t])=>nl.has(e)?[t]:[]),``,`Authentication (every command that calls aVenture needs a credential):`,` Create one at ${s}/sign-up, then run: ${Q} auth login`,` AUTH_TOKEN aVenture API key, for CI and other non-interactive shells`,` Check what this shell holds with: ${Q} auth status\n`,`Output modes (per command):`,` --text compact lines, the terminal default; --json the full envelope`,` --data response data as JSON, the default when piped or non-TTY`,` --data-full uncapped, for bounded programs, never LLM agents`,` --all-fields --text plus the detail fields it hides by default
|
|
64
74
|
`,`Exit codes:`,` 0 envelope.ok === true
|
|
65
75
|
1 envelope.ok === false
|
|
66
76
|
`,`Examples:`,` $ ${Q} auth login`,` $ ${Q} lookup --name Stripe --url https://stripe.com`,` $ ${Q} search "fintech companies in Austin"\n`,`Run \`${Q} <command> --help\` for its subcommands and options,`,`or \`${Q} help <command>\` for its full documentation.`].join(`
|