@aventurevc/aventure-cli 0.8.233 → 0.8.235

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.
Files changed (54) hide show
  1. package/dist/aventure-cli/index.js +1 -1
  2. package/dist/aventure-cli/unified-operations.json +1 -1
  3. package/dist/chunks/{api-key-bearer-credential-BYlgsMzT.js → api-key-bearer-credential-BDpScO9J.js} +1 -1
  4. package/dist/chunks/{api-key-bearer-credential-BfapI4GF.js → api-key-bearer-credential-CyFG5_Cm.js} +1 -1
  5. package/dist/chunks/{aventure-cli-BR-sQxyd.js → aventure-cli-uxhwf3qk.js} +4 -4
  6. package/dist/chunks/{builtin-auth-tFwMX6wg.js → builtin-auth-DzCjM2rV.js} +2 -2
  7. package/dist/chunks/builtin-research-run-wait-BF06g2eh.js +1 -0
  8. package/dist/chunks/{builtin-update-ByBZxQIt.js → builtin-update-5IL6qRqK.js} +1 -1
  9. package/dist/chunks/builtin-update-Dx_i2YGF.js +1 -0
  10. package/dist/chunks/{cli-help-policy-DdcHm_F7.js → cli-help-policy-CEyg0zEz.js} +1 -1
  11. package/dist/chunks/{completion-v7Uobf8W.js → completion-CoE0a605.js} +1 -1
  12. package/dist/chunks/{contract-BEa-OAos.js → contract-BztWeCTz.js} +1 -1
  13. package/dist/chunks/{generated-option-order-DH8yCg4h.js → generated-option-order-CZUJFgSS.js} +1 -1
  14. package/dist/chunks/{help-intent-Dtkz55rC.js → help-intent-kPjXtxOf.js} +1 -1
  15. package/dist/chunks/{logging-BnHashoK.js → logging-Bk8_GcPH.js} +1 -1
  16. package/dist/chunks/logging-DchmkRaS.js +1 -0
  17. package/dist/chunks/{mcp-generation-contract-XxGTW_nR.js → mcp-generation-contract-D0mlhvEk.js} +1 -1
  18. package/dist/chunks/{mcp-generation-contract-CdNJO_dx.js → mcp-generation-contract-XdtSQ9XZ.js} +1 -1
  19. package/dist/chunks/{oauth-bearer-credential-DdkhuhWl.js → oauth-bearer-credential-CMDf5sF6.js} +2 -2
  20. package/dist/chunks/oauth-bearer-credential-flA02CPH.js +1 -0
  21. package/dist/chunks/{oauth-login-GE10Mmja.js → oauth-login-Cj6xqtM3.js} +1 -1
  22. package/dist/chunks/oauth-login-DHyn5cGQ.js +1 -0
  23. package/dist/chunks/{openapi-call-DYmq9nNq.js → openapi-call-CCpc56ir.js} +1 -1
  24. package/dist/chunks/{openapi-call-CrfewEHX.js → openapi-call-Cu_IqRxU.js} +7 -7
  25. package/dist/chunks/{openapi-commands-BogvSuBR.js → openapi-commands-BlMzQV8z.js} +1 -1
  26. package/dist/chunks/openapi-commands-CKb-tN3f.js +1 -0
  27. package/dist/chunks/{openapi-snapshot-DD4lwuez.js → openapi-snapshot-C2TJ4vNL.js} +1 -1
  28. package/dist/chunks/{operation-invocation-fkSqlOfs.js → operation-invocation-C29yUZSq.js} +1 -1
  29. package/dist/chunks/{operations-catalog-DchG_yZT.js → operations-catalog-BiO8B33R.js} +1 -1
  30. package/dist/chunks/operations-catalog-CtACMf18.js +1 -0
  31. package/dist/chunks/{operations-metadata-BBPoVaXN.js → operations-metadata-r3glpbEg.js} +1 -1
  32. package/dist/chunks/{operations-D7L98CLW.js → operations-uVpQkO2z.js} +2 -2
  33. package/dist/chunks/{output-ewPhzpBl.js → output-BCOtzmsw.js} +1 -1
  34. package/dist/chunks/{output-Bs19gfSd.js → output-CtsN3oh3.js} +1 -1
  35. package/dist/chunks/{output-mode-CMdKmp9N.js → output-mode-DYvJUCAE.js} +1 -1
  36. package/dist/chunks/output-mode-_ENfBi2N.js +1 -0
  37. package/dist/chunks/{output-spill-5SehC7pV.js → output-spill-DBSmywMi.js} +1 -1
  38. package/dist/chunks/{parse-error-hint-B4SJhS4y.js → parse-error-hint-BNJ09L05.js} +1 -1
  39. package/dist/chunks/{reference-recovery-BIxVJJpL.js → reference-recovery-FRzF750i.js} +1 -1
  40. package/dist/chunks/{response-problem-DG4194cZ.js → response-problem-BGEYFwd5.js} +1 -1
  41. package/dist/chunks/{result-envelope-BKQSGfkH.js → result-envelope-5R2VEWAg.js} +1 -1
  42. package/dist/chunks/{startup-auth-Cs5DWeuA.js → startup-auth-CnOyg9R-.js} +1 -1
  43. package/dist/chunks/{startup-auth-DXABdGOL.js → startup-auth-DobaZEW6.js} +1 -1
  44. package/dist/chunks/tool-policy-BPefkvzQ.js +1 -0
  45. package/package.json +3 -3
  46. package/dist/chunks/builtin-research-run-wait-CqKv4AU5.js +0 -1
  47. package/dist/chunks/builtin-update-BHM1NsWc.js +0 -1
  48. package/dist/chunks/logging-DtglvosR.js +0 -1
  49. package/dist/chunks/oauth-bearer-credential-BXwkYSjn.js +0 -1
  50. package/dist/chunks/oauth-login-CtF86hwd.js +0 -1
  51. package/dist/chunks/openapi-commands-v6H75r4H.js +0 -1
  52. package/dist/chunks/operations-catalog-0v18i0og.js +0 -1
  53. package/dist/chunks/output-mode-CJBQJGLK.js +0 -1
  54. package/dist/chunks/tool-policy-TAT9-UP4.js +0 -1
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{enableCompileCache as e}from"node:module";import{fileURLToPath as t}from"node:url";e();var{Command:n,CommanderError:r}=await import(`../chunks/commander-D8IVfzyC.js`),{readRuntimePackage:i}=await import(`../chunks/package-DxrXjUBK.js`),{locateRuntimeManifest:a}=await import(`../chunks/runtime-identity-COBUpkxY.js`),o=process.argv.slice(2);try{if(a(),o.length===1&&(o[0]===`--version`||o[0]===`-V`))await new n().exitOverride().version(i(t(import.meta.url)).version).parseAsync();else{let{logWarn:e,setStderrLogging:t}=await import(`../chunks/logging-DtglvosR.js`),{cliMachineOutputSelected:n}=await import(`../chunks/output-mode-CJBQJGLK.js`),{commandAuthMaterializationMode:r,materializeCommandCredential:a}=await import(`../chunks/startup-auth-DXABdGOL.js`),{GENERATED_OPENAPI_COMMAND_SPECS:s}=await import(`../chunks/openapi-commands-BogvSuBR.js`);if(n(o)&&t(!1),o.includes(`--all-fields`)){let{setTextAllFields:e}=await import(`../chunks/text-field-BDYE-wQt.js`);e(!0)}let c=r(o,s);if(c===`stored`||c===`optional`)try{await a(c)}catch(t){e({component:i().bin[0],event:`optional_auth_materialization_failed`,message:`saved credential unavailable; continuing with credential-optional command`,error:t})}await import(`../chunks/aventure-cli-BR-sQxyd.js`)}}catch(e){if(!(e instanceof r))throw e;e.code!==`commander.version`&&process.stderr.write(`${e.message}\n`),process.exitCode=e.exitCode}export{};
2
+ import{enableCompileCache as e}from"node:module";import{fileURLToPath as t}from"node:url";e();var{Command:n,CommanderError:r}=await import(`../chunks/commander-D8IVfzyC.js`),{readRuntimePackage:i}=await import(`../chunks/package-DxrXjUBK.js`),{locateRuntimeManifest:a}=await import(`../chunks/runtime-identity-COBUpkxY.js`),o=process.argv.slice(2);try{if(a(),o.length===1&&(o[0]===`--version`||o[0]===`-V`))await new n().exitOverride().version(i(t(import.meta.url)).version).parseAsync();else{let{logWarn:e,setStderrLogging:t}=await import(`../chunks/logging-DchmkRaS.js`),{cliMachineOutputSelected:n}=await import(`../chunks/output-mode-_ENfBi2N.js`),{commandAuthMaterializationMode:r,materializeCommandCredential:a}=await import(`../chunks/startup-auth-DobaZEW6.js`),{GENERATED_OPENAPI_COMMAND_SPECS:s}=await import(`../chunks/openapi-commands-BlMzQV8z.js`);if(n(o)&&t(!1),o.includes(`--all-fields`)){let{setTextAllFields:e}=await import(`../chunks/text-field-BDYE-wQt.js`);e(!0)}let c=r(o,s);if(c===`stored`||c===`optional`)try{await a(c)}catch(t){e({component:i().bin[0],event:`optional_auth_materialization_failed`,message:`saved credential unavailable; continuing with credential-optional command`,error:t})}await import(`../chunks/aventure-cli-uxhwf3qk.js`)}}catch(e){if(!(e instanceof r))throw e;e.code!==`commander.version`&&process.stderr.write(`${e.message}\n`),process.exitCode=e.exitCode}export{};
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "generatedFrom": "MCP_GENERATION_CONTRACT",
4
- "generatedAt": "2026-10-23T02:06:17.727Z",
4
+ "generatedAt": "2026-10-23T17:24:08.015Z",
5
5
  "totalOperations": 137,
6
6
  "note": "Projection of MCP_GENERATION_CONTRACT - see mcp/scripts/build-unified-operations.ts header for SSOT rules.",
7
7
  "operations": [
@@ -1 +1 @@
1
- export{t as materializeCliApiKeyBearerCredential}from"./api-key-bearer-credential-BfapI4GF.js";
1
+ export{t as materializeCliApiKeyBearerCredential}from"./api-key-bearer-credential-CyFG5_Cm.js";
@@ -1,4 +1,4 @@
1
- import{f as e,g as t,o as n,r,x as i}from"./logging-BnHashoK.js";import{i as a,l as o,o as s,w as c,y as l}from"./person-owner-C0YuWKvY.js";import{a as u}from"./package-CZBWjlYb.js";import{i as d}from"./response-problem-DG4194cZ.js";import{execFile as f}from"node:child_process";import{dirname as p,join as m}from"node:path";import{homedir as h,platform as g}from"node:os";import{setTimeout as _}from"node:timers/promises";import{randomUUID as v}from"node:crypto";import{AsyncLocalStorage as ee}from"node:async_hooks";import{chmod as te,mkdir as y,readFile as b,rename as x,rm as S,stat as ne,writeFile as C}from"node:fs/promises";function w(e){let t=e.trim();if(t.length===0)throw Error(`API host must not be blank`);let n=new URL(ae(t)?t:`${oe(t)}://${t}`),r=E(n.hostname);if(n.protocol!==`https:`&&n.protocol!==`http:`||n.username.length>0||n.password.length>0||n.pathname!==`/`&&n.pathname!==``||n.search.length>0||n.hash.length>0)throw Error(`API host must contain only an HTTP(S) host and optional port`);if(n.protocol===`http:`&&!r)throw Error(`stored credentials require HTTPS except for loopback API hosts`);return{host:n.host.toLowerCase(),origin:n.origin,isLoopback:r}}function T(e){let n=w(e);return n.isLoopback?w(t()).host:n.host}function re(e){return{...e,host:w(e.host).origin}}function ie(e){let t=w(e);if(t.isLoopback)return`http://localhost:3000`;if(t.host===`api.aventure.vc`)return`https://aventure.vc`;throw Error(`no first-party browser origin is configured for API host ${t.host}`)}function ae(e){return/^[a-z][a-z\d+.-]*:\/\//iu.test(e)}function oe(e){let t=e.split(`/`,1)[0]?.toLowerCase()??``;try{return E(new URL(`http://${t}`).hostname)?`http`:`https`}catch{return`https`}}function E(e){let t=e.toLowerCase();return t===`localhost`||t===`127.0.0.1`||t===`0.0.0.0`||t===`[::1]`}var D=l({createdAt:a({offset:!0}),description:c().nullish(),expiresAt:a({offset:!0}).nullish(),id:c().regex(/^ak_[0-9A-Fa-f]{32}$/),lastUsedAt:a({offset:!0}).nullish(),name:c(),revocationReason:c().nullish(),scopes:o(c()),status:s([`ACTIVE`,`REVOKED`,`EXPIRED`]),subject:c(),updatedAt:a({offset:!0})});function O(e,t=[]){let n=e instanceof Error?e.message:String(e);return d(n,t)}function se(e,t=[]){let n=d(e.title,t),r=d(e.detail?.trim()??``,t);return`${e.status} ${n}${r?` — ${r}`:``}`}function ce(){if(g()===`win32`){let e=process.env.APPDATA??m(h(),`AppData`,`Roaming`);return m(e,`aventure`,`config.json`)}let e=process.env.XDG_CONFIG_HOME??m(h(),`.config`);return m(e,`aventure`,`config.json`)}function le(){let t=process.env[e.authToken];return typeof t==`string`&&t.length>0?{present:!0,source:`env`}:{present:!1,source:null}}function k(e,t){return typeof e==`object`&&!!e&&`code`in e&&e.code===t}var ue=2;function de(e,t){return j(e,t).redactedUrl}async function fe(e,t,n){let r=j(e,t);return await A(new URL(r.openerUrl),n)}async function A(e,t){let n=t.environment??process.env,r=t.operatingSystem??g(),i=M(t.noBrowser,n,r);if(i!==null)return{state:`skipped`,reason:i};let a=pe(r,e.toString());if(a===null)return{state:`failed`,reason:`unsupported browser-opening platform: ${r}`};try{return await me(a.command,a.arguments),{state:`opened`,reason:null}}catch{return{state:`failed`,reason:`browser opener failed`}}}function j(e,t){let{id:n,verificationUrl:r,pollSecret:i}=e,a,o;try{a=new URL(r),o=new URL(t)}catch{throw Error(`broker returned an invalid browser verification URL`)}if(o.username.length>0||o.password.length>0||o.pathname!==`/`||o.search.length>0||o.hash.length>0)throw Error(`configured browser origin must contain only an origin`);let s=E(o.hostname);if(o.protocol!==`https:`&&!(o.protocol===`http:`&&s))throw Error(`configured browser origin must use HTTPS except for loopback development`);let c=new URLSearchParams(a.hash.slice(1)),l=[...c.keys()],u=c.getAll(`cliAuthorizationId`),d=c.getAll(`browserSecret`),f=d[0]??``;if(a.origin!==o.origin||a.protocol!==o.protocol||a.username.length>0||a.password.length>0||a.pathname!==`/settings/developer`||a.search.length>0||l.length!==ue||u.length!==1||u[0]!==n||d.length!==1||f.length===0||i.length===0||f===i)throw Error(`broker returned a browser verification URL outside the configured first-party approval flow`);let p;try{p=decodeURIComponent(r)}catch{throw Error(`broker returned a browser verification URL outside the configured first-party approval flow`)}if(r.includes(i)||p.includes(i))throw Error(`broker returned a browser verification URL outside the configured first-party approval flow`);let m=new URL(a);return m.hash=new URLSearchParams({cliAuthorizationId:n,browserSecret:`<redacted>`}).toString(),{openerUrl:r,redactedUrl:m.toString()}}function M(e,t,n){return e?`--no-browser was set`:n===`darwin`&&t.CODEX_SESSION_ID?`macOS Codex browser process boundary`:t.SSH_CONNECTION||t.SSH_CLIENT||t.SSH_TTY?`SSH/headless session detected`:(n===`linux`||n===`freebsd`)&&!t.DISPLAY&&!t.WAYLAND_DISPLAY?`no graphical display detected`:null}function pe(e,t){return e===`darwin`?{command:`open`,arguments:[t]}:e===`win32`?{command:`rundll32.exe`,arguments:[`url.dll,FileProtocolHandler`,t]}:e===`linux`||e===`freebsd`?{command:`xdg-open`,arguments:[t]}:null}function me(e,t){return new Promise((n,r)=>{f(e,[...t],{timeout:5e3,windowsHide:!0},e=>e?r(e):n())})}var he=100,N=3e4,ge=6e4,P=new ee;function F(){return m(p(ce()),`credentials.json`)}function I(e){return`OS keyring is unusable (${e}); the credential will be stored in ${F()} (mode 0600).\n`}async function L(e,t){let n=(await W())[e]?.[t];if(n!==void 0)return{record:{provider:`file`,value:n}};try{let n=await(await U(e,t)).getPassword()??void 0;return n===void 0?{}:{record:{provider:`keyring`,value:n}}}catch(e){return{keyringFailure:H(e)}}}async function R(e,t,n){if((await W())[e]?.[t]!==void 0)return await z(e,t,n,`file store holds this account`);let r;try{let i=await U(e,t);if(await i.setPassword(n),await i.getPassword()===n)return await q(e,t,void 0),`keyring`;r=`Error: keyring readback did not match`}catch(e){r=H(e,[n])}return await z(e,t,n,r)}async function z(e,t,n,r){if(await q(e,t,n),(await W())[e]?.[t]!==n)throw Error(`credential storage did not confirm a durable write (keyring: ${r}; file: readback did not match)`);return`file`}async function B(e,t){try{let n=await U(e,t),r;try{await n.deleteCredential()}catch(e){r=e}let i;try{i=await n.getPassword()??void 0}catch(e){throw Error(`OS keyring removal outcome is unknown (${H(r??e)})`,{cause:e})}if(i!==void 0)throw Error(`OS keyring did not confirm removal (${H(r)})`,r===void 0?void 0:{cause:r})}finally{await q(e,t,void 0)}}async function V(e,t){let n=`${t}:probe:${v()}`,r=`aventure-cli-credential-probe:${v()}`,i;try{let t=await U(e,n);await t.setPassword(r);let a=await(await U(e,n)).getPassword(),o=await t.deleteCredential(),s=await(await U(e,n)).getPassword()??void 0;if(a!==r)i=`Error: probe readback did not match`;else if(!o||s!==void 0)i=`Error: probe cleanup was not confirmed`;else return{provider:`keyring`}}catch(e){i=H(e,[r])}try{await K(async()=>{await q(e,n,r);let t=(await W())[e]?.[n];if(await q(e,n,void 0),t!==r)throw Error(`probe readback did not match`)})}catch(e){throw Error(`credential storage is unavailable (keyring: ${i}; file ${F()}: ${H(e,[r])})`,{cause:e})}return{provider:`file`,keyringFailure:i}}function H(e,t=[]){if(!(e instanceof Error))return`Error`;let n=e.name||`Error`,[r=``]=O(e,t).trim().split(`
1
+ import{f as e,g as t,o as n,r,x as i}from"./logging-Bk8_GcPH.js";import{i as a,l as o,o as s,w as c,y as l}from"./person-owner-C0YuWKvY.js";import{a as u}from"./package-CZBWjlYb.js";import{i as d}from"./response-problem-BGEYFwd5.js";import{execFile as f}from"node:child_process";import{dirname as p,join as m}from"node:path";import{homedir as h,platform as g}from"node:os";import{setTimeout as _}from"node:timers/promises";import{randomUUID as v}from"node:crypto";import{AsyncLocalStorage as ee}from"node:async_hooks";import{chmod as te,mkdir as y,readFile as b,rename as x,rm as S,stat as ne,writeFile as C}from"node:fs/promises";function w(e){let t=e.trim();if(t.length===0)throw Error(`API host must not be blank`);let n=new URL(ae(t)?t:`${oe(t)}://${t}`),r=E(n.hostname);if(n.protocol!==`https:`&&n.protocol!==`http:`||n.username.length>0||n.password.length>0||n.pathname!==`/`&&n.pathname!==``||n.search.length>0||n.hash.length>0)throw Error(`API host must contain only an HTTP(S) host and optional port`);if(n.protocol===`http:`&&!r)throw Error(`stored credentials require HTTPS except for loopback API hosts`);return{host:n.host.toLowerCase(),origin:n.origin,isLoopback:r}}function T(e){let n=w(e);return n.isLoopback?w(t()).host:n.host}function re(e){return{...e,host:w(e.host).origin}}function ie(e){let t=w(e);if(t.isLoopback)return`http://localhost:3000`;if(t.host===`api.aventure.vc`)return`https://aventure.vc`;throw Error(`no first-party browser origin is configured for API host ${t.host}`)}function ae(e){return/^[a-z][a-z\d+.-]*:\/\//iu.test(e)}function oe(e){let t=e.split(`/`,1)[0]?.toLowerCase()??``;try{return E(new URL(`http://${t}`).hostname)?`http`:`https`}catch{return`https`}}function E(e){let t=e.toLowerCase();return t===`localhost`||t===`127.0.0.1`||t===`0.0.0.0`||t===`[::1]`}var D=l({createdAt:a({offset:!0}),description:c().nullish(),expiresAt:a({offset:!0}).nullish(),id:c().regex(/^ak_[0-9A-Fa-f]{32}$/),lastUsedAt:a({offset:!0}).nullish(),name:c(),revocationReason:c().nullish(),scopes:o(c()),status:s([`ACTIVE`,`REVOKED`,`EXPIRED`]),subject:c(),updatedAt:a({offset:!0})});function O(e,t=[]){let n=e instanceof Error?e.message:String(e);return d(n,t)}function se(e,t=[]){let n=d(e.title,t),r=d(e.detail?.trim()??``,t);return`${e.status} ${n}${r?` — ${r}`:``}`}function ce(){if(g()===`win32`){let e=process.env.APPDATA??m(h(),`AppData`,`Roaming`);return m(e,`aventure`,`config.json`)}let e=process.env.XDG_CONFIG_HOME??m(h(),`.config`);return m(e,`aventure`,`config.json`)}function le(){let t=process.env[e.authToken];return typeof t==`string`&&t.length>0?{present:!0,source:`env`}:{present:!1,source:null}}function k(e,t){return typeof e==`object`&&!!e&&`code`in e&&e.code===t}var ue=2;function de(e,t){return j(e,t).redactedUrl}async function fe(e,t,n){let r=j(e,t);return await A(new URL(r.openerUrl),n)}async function A(e,t){let n=t.environment??process.env,r=t.operatingSystem??g(),i=M(t.noBrowser,n,r);if(i!==null)return{state:`skipped`,reason:i};let a=pe(r,e.toString());if(a===null)return{state:`failed`,reason:`unsupported browser-opening platform: ${r}`};try{return await me(a.command,a.arguments),{state:`opened`,reason:null}}catch{return{state:`failed`,reason:`browser opener failed`}}}function j(e,t){let{id:n,verificationUrl:r,pollSecret:i}=e,a,o;try{a=new URL(r),o=new URL(t)}catch{throw Error(`broker returned an invalid browser verification URL`)}if(o.username.length>0||o.password.length>0||o.pathname!==`/`||o.search.length>0||o.hash.length>0)throw Error(`configured browser origin must contain only an origin`);let s=E(o.hostname);if(o.protocol!==`https:`&&!(o.protocol===`http:`&&s))throw Error(`configured browser origin must use HTTPS except for loopback development`);let c=new URLSearchParams(a.hash.slice(1)),l=[...c.keys()],u=c.getAll(`cliAuthorizationId`),d=c.getAll(`browserSecret`),f=d[0]??``;if(a.origin!==o.origin||a.protocol!==o.protocol||a.username.length>0||a.password.length>0||a.pathname!==`/settings/developer`||a.search.length>0||l.length!==ue||u.length!==1||u[0]!==n||d.length!==1||f.length===0||i.length===0||f===i)throw Error(`broker returned a browser verification URL outside the configured first-party approval flow`);let p;try{p=decodeURIComponent(r)}catch{throw Error(`broker returned a browser verification URL outside the configured first-party approval flow`)}if(r.includes(i)||p.includes(i))throw Error(`broker returned a browser verification URL outside the configured first-party approval flow`);let m=new URL(a);return m.hash=new URLSearchParams({cliAuthorizationId:n,browserSecret:`<redacted>`}).toString(),{openerUrl:r,redactedUrl:m.toString()}}function M(e,t,n){return e?`--no-browser was set`:n===`darwin`&&t.CODEX_SESSION_ID?`macOS Codex browser process boundary`:t.SSH_CONNECTION||t.SSH_CLIENT||t.SSH_TTY?`SSH/headless session detected`:(n===`linux`||n===`freebsd`)&&!t.DISPLAY&&!t.WAYLAND_DISPLAY?`no graphical display detected`:null}function pe(e,t){return e===`darwin`?{command:`open`,arguments:[t]}:e===`win32`?{command:`rundll32.exe`,arguments:[`url.dll,FileProtocolHandler`,t]}:e===`linux`||e===`freebsd`?{command:`xdg-open`,arguments:[t]}:null}function me(e,t){return new Promise((n,r)=>{f(e,[...t],{timeout:5e3,windowsHide:!0},e=>e?r(e):n())})}var he=100,N=3e4,ge=6e4,P=new ee;function F(){return m(p(ce()),`credentials.json`)}function I(e){return`OS keyring is unusable (${e}); the credential will be stored in ${F()} (mode 0600).\n`}async function L(e,t){let n=(await W())[e]?.[t];if(n!==void 0)return{record:{provider:`file`,value:n}};try{let n=await(await U(e,t)).getPassword()??void 0;return n===void 0?{}:{record:{provider:`keyring`,value:n}}}catch(e){return{keyringFailure:H(e)}}}async function R(e,t,n){if((await W())[e]?.[t]!==void 0)return await z(e,t,n,`file store holds this account`);let r;try{let i=await U(e,t);if(await i.setPassword(n),await i.getPassword()===n)return await q(e,t,void 0),`keyring`;r=`Error: keyring readback did not match`}catch(e){r=H(e,[n])}return await z(e,t,n,r)}async function z(e,t,n,r){if(await q(e,t,n),(await W())[e]?.[t]!==n)throw Error(`credential storage did not confirm a durable write (keyring: ${r}; file: readback did not match)`);return`file`}async function B(e,t){try{let n=await U(e,t),r;try{await n.deleteCredential()}catch(e){r=e}let i;try{i=await n.getPassword()??void 0}catch(e){throw Error(`OS keyring removal outcome is unknown (${H(r??e)})`,{cause:e})}if(i!==void 0)throw Error(`OS keyring did not confirm removal (${H(r)})`,r===void 0?void 0:{cause:r})}finally{await q(e,t,void 0)}}async function V(e,t){let n=`${t}:probe:${v()}`,r=`aventure-cli-credential-probe:${v()}`,i;try{let t=await U(e,n);await t.setPassword(r);let a=await(await U(e,n)).getPassword(),o=await t.deleteCredential(),s=await(await U(e,n)).getPassword()??void 0;if(a!==r)i=`Error: probe readback did not match`;else if(!o||s!==void 0)i=`Error: probe cleanup was not confirmed`;else return{provider:`keyring`}}catch(e){i=H(e,[r])}try{await K(async()=>{await q(e,n,r);let t=(await W())[e]?.[n];if(await q(e,n,void 0),t!==r)throw Error(`probe readback did not match`)})}catch(e){throw Error(`credential storage is unavailable (keyring: ${i}; file ${F()}: ${H(e,[r])})`,{cause:e})}return{provider:`file`,keyringFailure:i}}function H(e,t=[]){if(!(e instanceof Error))return`Error`;let n=e.name||`Error`,[r=``]=O(e,t).trim().split(`
2
2
  `,1);return r&&r!==n?`${n}: ${r}`:n}async function U(e,t){let n=g(),r=n===`linux`||n===`freebsd`?M(!1,process.env,n):null;if(r!==null)throw Error(`OS keyring unlock prompt is unreachable (${r})`);let{AsyncEntry:i}=await import(`@napi-rs/keyring`);return new i(e,t)}async function W(){let e=F(),t;try{t=await b(e,`utf8`)}catch(e){if(k(e,`ENOENT`))return{};throw e}let n;try{n=JSON.parse(t)}catch(t){return await G(e,t)}return ve(n)?n:await G(e,void 0)}async function G(e,t){let r=`${e}.corrupt-${new Date().toISOString().replace(/[:.]/gu,`-`)}`;try{await x(e,r)}catch(t){if(k(t,`ENOENT`))return{};throw Error(`${e} is not a valid credential file and could not be moved aside`,{cause:t})}return n({component:u().bin[0],event:`credential_file_quarantined`,message:`${e} is not a valid credential file; moved it to ${r} and continuing with an empty file store`,...t===void 0?{}:{error:t}}),{}}async function K(e){if(P.getStore()===!0)return await e();let t=`${F()}.lock`;await y(p(t),{recursive:!0,mode:448});let n=Date.now()+N,r=v();for(;;){try{await C(t,r,{flag:`wx`,mode:384});break}catch(e){if(!k(e,`EEXIST`))throw e}if(await ne(t).then(e=>Date.now()-e.mtimeMs,()=>0)>ge)await S(t,{force:!0});else if(Date.now()>n)throw Error(`credential store is locked by another CLI process (${t})`);else await _(he)}try{return await P.run(!0,e)}finally{await b(t,`utf8`).catch(()=>``)===r&&await S(t,{force:!0})}}async function q(e,t,n){await K(async()=>await _e(e,t,n))}async function _e(e,t,n){let r=F(),i=await W(),a={...i[e]};if(n===void 0?delete a[t]:a[t]=n,Object.keys(a).length===0?delete i[e]:i[e]=a,Object.keys(i).length===0){await S(r,{force:!0});return}await y(p(r),{recursive:!0,mode:448});let o=`${r}.${v()}.tmp`;await C(o,`${JSON.stringify(i,null,2)}\n`,{mode:384}),await te(o,384),await x(o,r)}function ve(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.values(e).every(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.values(e).every(e=>typeof e==`string`))}var J=`vc.aventure.aventure-cli`,Y=`aventure-cli-personal-v1`;async function ye(e,t,n){let r=T(e),i=Se(t,n),a;try{a=await R(J,r,i)}catch(e){throw Error(`${O(e,[i,t.secret])}; broker acknowledgment was withheld. Re-run auth status before retrying.`,{cause:e})}return{host:r,provider:a,activation:n,credential:t}}async function X(e){let t=T(e),n;try{n=await L(J,t)}catch(e){return Z(O(e))}let{record:r,keyringFailure:i}=n;return r===void 0?i===void 0?{state:`missing`}:{state:`missing`,keyringFailure:i}:{state:`found`,stored:{host:t,provider:r.provider,...Ce(r.value)}}}async function be(e){let t=await X(e);if(t.state!==`missing`)return t;try{let{keyringFailure:t}=await V(J,T(e));return t===void 0?{state:`missing`}:{state:`missing`,keyringFailure:t}}catch(e){return Z(O(e))}}async function xe(e){await B(J,T(e))}function Z(e){return{state:`unavailable`,summary:e,cause:`storage`}}function Se(e,t){return`${Y}:${t}\n${JSON.stringify(e.apiKey)}\n${e.secret}`}function Ce(e){let t=e.indexOf(`
3
3
  `),n=t<0?-1:e.indexOf(`
4
4
  `,t+1),r=t<0?e:e.slice(0,t),i=r===`${Y}:active`?`active`:`pending`;if(t<0||n<0||r!==`${Y}:pending`&&r!==`${Y}:active`)throw Error(`OS credential entry has an unsupported format`);let a=e.slice(n+1);if(a.length===0)throw Error(`OS credential entry has an empty secret`);let o;try{o=JSON.parse(e.slice(t+1,n))}catch(e){throw Error(`OS credential entry failed canonical schema validation`,{cause:e})}let s=D.safeParse(o);if(!s.success)throw Error(`OS credential entry failed canonical schema validation`,{cause:s.error});return{activation:i,credential:{apiKey:s.data,secret:a}}}async function we(t){if(Q())return;let a=T(i().host);try{let n=await X(a);if(n.state===`unavailable`){r($(`keyring`,Error(n.summary)));return}n.state===`found`&&n.stored.activation===`active`&&!Q()&&(process.env[e.authToken]=n.stored.credential.secret,t?.(`api-key`))}catch(e){n($(`parse`,e))}}function Q(){return(process.env[e.authToken]?.trim().length??0)>0}function $(e,t){return{component:u().bin[0],event:`api_key_materialization_unavailable`,message:`saved API key could not be loaded; continuing with environment auth`,fields:{source:e},error:t}}export{re as S,se as _,ye as a,w as b,V as c,R as d,A as f,O as g,le as h,X as i,L as l,de as m,xe as n,B as o,fe as p,be as r,I as s,we as t,K as u,D as v,T as x,ie as y};
@@ -1,10 +1,10 @@
1
- import{a as e,n as t,o as n,r,t as i}from"./commander-DEj7N1b9.js";import{_ as a,h as o,i as s,m as c,v as l}from"./logging-BnHashoK.js";import{a as u,b as d,c as f,t as p,x as m,y as h}from"./tool-policy-TAT9-UP4.js";import{c as g,p as _,r as v}from"./result-envelope-BKQSGfkH.js";import{a as y}from"./package-CZBWjlYb.js";import{r as ee,t as te}from"./operation-invocation-fkSqlOfs.js";import{i as ne,n as re,t as ie}from"./cli-help-policy-DdcHm_F7.js";import{a as ae,c as oe,d as se,f as ce,l as le,n as ue,o as b,r as de,s as x,t as fe,u as pe}from"./startup-auth-Cs5DWeuA.js";import{t as S}from"./openapi-commands-v6H75r4H.js";import{i as C,r as w,t as T}from"./output-mode-CMdKmp9N.js";import{t as me}from"./operations-metadata-BBPoVaXN.js";import{S as he,_ as E,a as ge,b as D,c as _e,d as ve,f as ye,g as O,h as be,i as xe,l as Se,m as Ce,n as we,o as Te,p as Ee,r as De,s as Oe,t as ke,u as Ae,v as k,x as je,y as Me}from"./generated-option-order-DH8yCg4h.js";import{a as Ne,i as Pe,n as Fe,r as Ie}from"./payload-operand-guard-BVp_alVX.js";import{fileURLToPath as Le}from"node:url";import{readFile as Re}from"node:fs/promises";async function ze(e){let t;try{t=e===`-`?await Be():await Re(e,`utf8`)}catch(t){return v(`Could not read input: ${t.message}`,[`path=${e}`])}try{if(t.trim().length===0)return g(`No input provided`,null);let e=JSON.parse(t);return g(`Input parsed`,e)}catch(e){return v(`Input is not valid JSON: ${e.message}`)}}async function Be(){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 A=`--content-type`;function Ve(e,n,r){let i=e=>!r?.has(e)&&(r?.add(e),!0),a=n.requestBody??[];if(a.length>1&&i(A)){let n=a.map(({contentType:e})=>e);e.addOption(new t(`${A} <media-type>`,`Select the request body encoding, never an uploaded file's media type; omit for ${n[0]}.`).choices(n).argParser(Ue(a)))}if(I(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>`,ge(r,r.requiredPath)).argParser(j(`--from-file`)))}let o=Te(a).filter(e=>i(N(e.variant[0].parameter)));for(let n of o.toSorted((e,t)=>we(e.variant[0].parameter,t.variant[0].parameter))){let{descriptor:r,parameter:i}=n.variant[0],o=new t(xe(n),a.length>1?De(n):_e(r,i));a.length===1&&i.envName!==void 0&&o.env(i.envName);let s=a.length===1?Oe(r,i.optionKey):[];s.length>0&&o.conflicts(s),a.length>1?o.argParser(He):E(i.name)||i.schemaType===`array`?o.argParser(We):o.argParser(j(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`)})}nt(e,n,o)}function He(e,t){return t===void 0?e:typeof t==`string`?[t,e]:[...t,e]}function Ue(e){return(t,r)=>{if(r!==void 0)throw new n(`${A} was already given; pass it once.`);let i=h(e,t);if(!i.ok)throw new n(i.summary);return t}}function We(e,t){return[...t??[],e]}function j(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 M(e,t){let n=x(e,t),r=h(e.requestBody??[],n);if(!r.ok||r.data===null)return v(r.summary,r.warnings);let i=r.data;if(i===void 0)return g(`No body`,void 0);let a=Ge(e,i,t);if(a!==null)return v(a);let o=ye(e.operationId,i,t);if(!o.ok)return v(o.summary,o.warnings);t=o.data;let s=Ke(i,t);if(s!==null)return v(s);let c=await Xe(t);if(!c.ok)return v(c.summary,c.warnings);let l=Ce(e.requestBody??[],i,c.data);if(l!==null)return v(l);let u=Ye(e.operationId,i,c.data);if(!u.ok)return u;let d=be(e.operationId,i,c.data);if(d!==null)return v(d);let f=Ze(e.operationId,i,t);if(!f.ok)return f;if(c.data===void 0&&f.data===void 0)return i.required?v(tt(e.operationId,i)):g(`No body`,void 0);let p=$e(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 v(`${e.operationId} requires a JSON array body.`);if(i.parameter.length>0&&!k(p.data)){let t=i.kind===`multipart`?` keyed by multipart part name`:` body`;return v(`${e.operationId} requires a JSON object${t}.`)}let m=Je(i,p.data);if(m.length>0)return v(`${e.operationId} requires body option(s): ${m.join(`, `)}`);let _=p.data,y=k(_)?D(i).filter(e=>!O(_,e)):[];return y.length>0?v(qe(e.operationId,i,y)):p}function Ge(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`${N(t)} requires ${A} ${i.join(` or `)}.`}return null}function Ke(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 qe(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 Je(e,t){return k(t)?e.parameter.filter(e=>e.required&&!O(t,e.name)).map(N):[]}function Ye(e,t,n){let r=he(t,n);if(r===null)return g(`Body file paths validated`,null);let i=r.suggestion===void 0?``:` Use ${r.suggestion}.`;return v(`${e} --from-file contains unknown JSON path ${r.path}.${i}`)}async function Xe(e){let t=typeof e.fromFile==`string`?e.fromFile:void 0;if(t===void 0)return g(`No body file`,void 0);let n=await ze(t);if(!n.ok)return v(n.summary,n.warnings);let r=_.safeParse(n.data);return r.success?g(`Input parsed`,r.data):v(`Input is not valid JSON value: ${r.error.message}`)}function Ze(e,t,n){let r={},i=!1;for(let e of t.parameter){let a=je(e,n[e.optionKey]);if(!a.ok||a.data===null)return v(a.summary,a.warnings);let o=a.data;if(o===void 0)continue;let s=Qe(t,n,r,e,o);if(!s.ok)return v(s.summary,s.warnings);i=!0}if(!i)return g(`No direct body options`,void 0);let a=Se(e,t,n,r);return a===null?g(`Direct body options parsed`,r):a}function Qe(e,t,n,r,i){let a=Me(r,i);if(a===null){let e=et(r,i);return e.ok?Ae(n,r.name,e.data,r.schemaType===`array`):v(e.summary,e.warnings)}if(a.plain.length>0)return v(`${N(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=Ee(e,t,a.container);for(let e of a.rows.keys())if(!(e<o))return v(`${N(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=F(r.name,r.itemSchemaType,e);if(!t.ok)return v(t.summary,t.warnings);i.push(t.data)}let a=ve(n,r.name,e,i);if(!a.ok)return a}return g(`Body value assigned`,null)}var N=e=>e.flag.split(` `)[0]??e.name;function $e(e,t,n,r){if(n===void 0)return g(`Direct body parsed`,r);if(r===void 0)return g(`Input parsed`,n);if(k(n)&&k(r))try{return g(`Input parsed`,P(t,n,r))}catch(t){return v(`${e} ${t instanceof Error?t.message:String(t)}`)}return v(`${e} cannot combine --from-file with direct body options unless the file body is an object.`)}function P(e,t,n,r=``){let i={...t};for(let[t,a]of Object.entries(n)){let n=i[t],o=`${r}${t}`;if(k(n)&&k(a))i[t]=P(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`:te.test(o)?`; keep multi-line text in the --from-file body`:``}.`)}return i}function et(e,t){if(typeof t==`boolean`)return g(`Body value parsed`,t);if(t===void 0||typeof t==`string`)return F(e.name,e.schemaType,t??``);let n=[],r=E(e.name)&&e.schemaType!==`array`?e.schemaType:e.itemSchemaType;for(let i of t){let t=F(e.name,r,i);if(!t.ok)return t;n.push(t.data)}return g(`Body value parsed`,n)}function F(e,t,n){if(t===`boolean`)return n===`true`?g(`Body value parsed`,!0):n===`false`?g(`Body value parsed`,!1):v(`${e} must be true or false.`);if(t===`number`||t===`integer`){let r=n.trim(),i=Number(r);return r===``||!Number.isFinite(i)?v(`${e} must be a finite ${t}.`):t===`integer`&&!Number.isInteger(i)?v(`${e} must be an integer.`):g(`Body value parsed`,i)}return g(`Body value parsed`,n)}function tt(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(N).join(`, `)}`;let r=D(t);if(r.length>0)return`${e} requires --from-file with JSON body path(s): ${r.join(`, `)}`;let i=t.parameter.map(N).join(`, `);return i.length===0?`${e} requires --from-file`:`${e} requires --from-file or body option(s): ${i}`}function nt(e,t,n){let r=[...t.parameters,...n.map(({variant:e})=>e[0].parameter)];(t.requestBody?.length??0)>1&&r.push({optionKey:`contentType`,flag:A,location:`body`}),I(t)&&r.push({optionKey:`fromFile`,flag:`--from-file`,location:`body`}),ke(e.options,r)}function I(e){return(e.requestBody??[]).some(e=>e.kind!==`multipart`||e.parameter.some(e=>e.schemaFormat!==`binary`))}function rt(e,t,n=y().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 it(r)),r.hook(`preSubcommand`,e=>{e.opts().help&&e.help()});let i=st(t);i!==void 0&&r.option(`--ask <question>`,i.summary),T(r),r.action(async function(r){let{emit:a}=await import(`./output-Bs19gfSd.js`),o=this.optsWithGlobals();if(o.help&&r.length===0){this.outputHelp();return}if(!o.help&&i!==void 0&&o.ask!==void 0){let e=C(o);if(r.length>0){a({mode:e},v(`Use either a command path or --ask, not both.`));return}a({mode:e},await lt(i,o.ask,o.environment,e));return}let s=V(e,r),c=t.find(t=>s!==void 0&&V(e,t.cliPath)===s);if(o.help||s!==void 0&&c===void 0){s===void 0&&this.error(`unknown command '${r.join(` `)}' (run \`${n} --help\` for the command tree)`),s.outputHelp();return}let l=c===void 0?await ct(r,t):g(`Resolved by command path`,{operationId:c.operationId});if(l.ok&&l.data?.command!==void 0&&this.error(`unknown command '${r.join(` `)}' (run \`${n} --help\` for the command tree)`),!l.ok||l.data===null){a({mode:C(o)},l);return}let{writeShowResult:u}=await import(`./operations-catalog-0v18i0og.js`);u({...o,...l.data},t,C(o,`text`),n)}),ot(e,t,n)}var it=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))}},L=2,R=6,at={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=>!re.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(L)}${e}\n${z(n,a,i)}`}};function z(e,t,n){return n.boxWrap(e,t-R).replace(/^/gmu,` `.repeat(R))}function ot(e,t,n){for(let r of t){let i=V(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=ee(r.operationId,t,n),[c,...l]=me(r.errorResponse),u=l.map(t=>z(t.trimStart(),o,e).replace(/^ +/u,` `.repeat(L))),d=c===void 0?[]:[``,c,...u];return`\n${[...s,...d].join(`
2
- `)}\n`})}}function st(e){let[t,...n]=e.filter(e=>{let[t,n,...r]=e.cliPath;return t===`help`&&n!==void 0&&r.length===0&&H(e)!==void 0});return n.length===0?t:void 0}var B='Accepted selectors: `<METHOD> <route template or concrete path>`, an operationId, or a CLI command path such as "entities get".';async function ct(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?g(`Resolved by route`,{operationId:i.operationId}):v(`${n} is served by ${[i,...a].map(({method:e})=>e).join(`, `)}; name the method, as in \`help ${i.method} ${n}\`.`,[B]);let o=d.find(e=>e===n.toLowerCase());if(o===void 0||r.length===0){let n=e.join(` `).trim();return g(`Resolved by name`,t.some(e=>e.operationId===n)?{operationId:n}:{command:n})}let s=m(o),c=r.join(``),l=t.find(e=>e.method===s&&e.path===c);if(l!==void 0)return g(`Resolved by route template`,{operationId:l.operationId});let{resolveOpenApiOperationSelector:u}=await import(`./openapi-call-DYmq9nNq.js`),f=u({method:s,path:c});return!f.ok||f.data===null?v(f.summary,[...f.warnings,B]):g(`Resolved by method and path`,{operationId:f.data.operation.operationId})}function V(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 lt(e,t,n,r){let{buildOpenApiPath:i,runOpenApiCall:a}=await import(`./openapi-call-DYmq9nNq.js`),o=H(e);if(o===void 0)return v(`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 s=await M(e,{[o.optionKey]:t});return s.ok?await a({method:e.method,path:i(e.operationId,{}),searchParams:{},body:s.data,auth:e.auth,responseFormat:w(r)?`json`:`auto`}):s}function H(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 ut(e,t,n){if(e.cliPath[0]!==`lookup`||!dt(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?v(i):v(i,[],{httpStatus:n.httpStatus,problem:n.problem})}function dt(e){return e.ok?Array.isArray(e.data)&&e.data.length===0:e.httpStatus===404}function ft(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]}}function pt(t,n,r,i){let a=mt(t),o=a instanceof e?[]:a,s=o[0],c=i.bin[0],l=[{selected:s===`auth`,register:async()=>{let{registerBuiltinAuthCommands:e}=await import(`./builtin-auth-tFwMX6wg.js`);e(n,c)}},{selected:s===`agents`,register:async()=>{let{registerBuiltinAgentSetupCommand:e}=await import(`./builtin-agent-setup-B2Xvqera.js`);e(n,c)}},{selected:s===`update`,register:async()=>{let{registerBuiltinUpdateCommand:e}=await import(`./builtin-update-BHM1NsWc.js`);e(n,i)}},{selected:s===`batch`,register:async()=>{let{registerBuiltinBatchCommand:e}=await import(`./builtin-batch-DdGyCjlR.js`);e(n,r,c)}},{selected:s===`research-runs`,register:async()=>{let{registerBuiltinResearchRunWaitCommand:e}=await import(`./builtin-research-run-wait-CqKv4AU5.js`);e(n)}},{selected:s===`completion`,register:async()=>{let{registerCompletionCommand:e}=await import(`./completion-v7Uobf8W.js`);e(n,r,c)}},{selected:s===`command-catalog`,register:async()=>{let{registerOperationsCommand:e}=await import(`./operations-D7L98CLW.js`);e(n,r,c)}}],u=s===void 0||s===`help`||s===`completion`||s===`command-catalog`||!l.some(e=>e.selected)&&!r.some(e=>e.cliPath[0]===s),d=1;for(;d<o.length&&r.some(e=>o.slice(0,d+1).every((t,n)=>e.cliPath[n]===t));)d++;let f=o.slice(0,d),p=u?r:r.filter(e=>f.slice(0,e.cliPath.length).every((t,n)=>e.cliPath[n]===t)),m=new Set,h=async(e=!1)=>{for(let t of l)(e||u||t.selected)&&!m.has(t)&&(await t.register(),m.add(t))};return{generated:p,fullTree:u,registerBuiltin:h,async completeTree(e){e(n,r.filter(e=>!p.includes(e))),await h(!0)}}}function mt(n){try{return new i().exitOverride().configureOutput({writeErr:()=>void 0}).addOption(new t(`--environment <environment>`)).parseOptions([...n]).operands}catch(t){if(!(t instanceof e))throw t;return t}}var ht=new Set(S.map(e=>e.cliPath.join(` `)));function U(e,t){e.showHelpAfterError(!1).exitOverride(t(e)),e.commands.length===0?e.hook(`preAction`,Fe):e.registeredArguments.length===0&&!ht.has(Ne(e).join(` `))&&e.addHelpOption(new Pe(e));for(let n of e.commands)U(n,t)}var W=y(Le(import.meta.url)),G=W.bin[0];async function K(e,t){let{BearerVerificationUnavailableError:n}=await import(`./openapi-call-DYmq9nNq.js`),{emitJson:r}=await import(`./output-Bs19gfSd.js`),i=e instanceof Error?e:Error(String(e));s({component:G,event:`fatal`,message:i.message,error:i}),process.stderr.write(`${G} fatal (${t}): ${i.stack??i.message}\n`);let a=i instanceof n?{httpStatus:i.problem.status,problem:i.problem}:{};r({...v(`${G} ${t}: ${i.message}`,[i.name||`Error`],a),counts:{exitCode:1}}),process.exit(1)}function q(e){return ie[ne(e,b)??`cli`]}function J(e,t){let n=t.map(e=>{let t=e.cliPath[0]??``;return{spec:e,top:t,rank:q(t).rank}}).toSorted((e,t)=>e.rank-t.rank||e.top.localeCompare(t.top)).map(e=>e.spec),r=new Set(n.filter(e=>fe(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)gt(e,t,r,a,i.has(t.cliPath.join(` `)))}function gt(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=_t(o,e,s,t)}let l=a.at(-1)??t.operationId,d=o.commands.find(e=>e.name()===l)??o.command(l,t.deprecated===!0?{hidden:!0}:{}),m=t.requestBody?.flatMap(({parameter:e})=>e)??[];d.summary(t.summary||t.operationId).description([`${t.method} ${t.path}.`,t.summary||t.description,`Full documentation: ${G} help ${t.cliPath.join(` `)}`,t.requestBody?.[0]?.kind===`json`||[...t.parameters,...m].some(e=>u(e.schemaType,e.itemSchemaType))?p:``].filter(Boolean).join(`
3
- `));let h=se(t);for(let e of t.parameters)vt(d,e,i||e===h);Ve(d,t),f(t.intent)&&d.option(`--execute`,`Deprecated; accepted and ignored. This command executes by its verb.`,!1),T(d),d.hook(`preAction`,e=>pe(e,t)),t.explain===!0&&d.option(`--explain`,`Print the search strategy and parsed constraints before the results`),h!==void 0&&d.argument(`[text...]`,h.description||`Same as ${oe(h.flag)}.`),d.action(async function(){let{emit:e,emitSearchExplanation:n}=await import(`./output-Bs19gfSd.js`),r=this.optsWithGlobals(),i=C(r),a=r;if(h!==void 0){let t=ce(h,this.args,r);if(!t.ok||t.data===null)return e({mode:i},t);a=t.data}let o=le(t,a);if(o.length>0)return e({mode:i},v(`missing required options: ${o.join(`, `)}`));let s=await yt(t,a,i),c=ut(t,a,s);if(c!==null)return e({mode:i},c);r.explain===!0&&s.ok&&n(i,s.data),s.ok&&s.data instanceof Uint8Array?process.stdout.write(s.data):e({mode:i},s)})}function _t(e,t,n,r){let i=e.commands.find(e=>e.name()===t);if(i!==void 0)return i;let a=b[n],o=e.command(t,r?{hidden:!0}:{}).helpCommand(!1);return a!==void 0&&o.summary(a.summary).description(a.summary),o}function vt(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 yt(e,t,n){let{buildOpenApiPath:r,runOpenApiCall:i}=await import(`./openapi-call-DYmq9nNq.js`),{pendingResult:o}=await import(`./output-Bs19gfSd.js`);if(t.environment!==void 0){let e=l(t.environment);if(e===null)return v(`Unknown aVenture environment '${t.environment}'`,[`Use one of: ${a().join(`, `)}`]);process.env.API_ENV=e}let s=await M(e,t);if(!s.ok)return s;let c=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)]})),u=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]]})),d=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 ft(e,await i({method:e.method,path:r(e.operationId,c),searchParams:u,headers:d,body:s.data,contentType:x(e,t),auth:e.auth,responseFormat:w(n)?`json`:`auto`,responseBytes:e.binaryResponse===!0,pendingResult:o}))}process.on(`uncaughtException`,e=>K(e,`uncaughtException`)),process.on(`unhandledRejection`,e=>K(e,`unhandledRejection`));var Y=ue(process.argv.slice(2),S),X=Y===`required`?S:ae(S),Z=new Ie;Z.name(G).usage(`<command> [subcommand] [options]`).configureHelp(at).version(W.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,
1
+ import{a as e,n as t,o as n,r,t as i}from"./commander-DEj7N1b9.js";import{_ as a,h as o,i as s,m as c,v as l}from"./logging-Bk8_GcPH.js";import{a as u,b as d,c as f,t as p,x as m,y as h}from"./tool-policy-BPefkvzQ.js";import{c as g,p as _,r as v}from"./result-envelope-5R2VEWAg.js";import{a as y}from"./package-CZBWjlYb.js";import{r as ee,t as te}from"./operation-invocation-C29yUZSq.js";import{i as ne,n as re,t as ie}from"./cli-help-policy-CEyg0zEz.js";import{a as ae,c as oe,d as se,f as ce,l as le,n as ue,o as b,r as de,s as x,t as fe,u as pe}from"./startup-auth-CnOyg9R-.js";import{t as S}from"./openapi-commands-CKb-tN3f.js";import{i as C,r as w,t as T}from"./output-mode-DYvJUCAE.js";import{t as me}from"./operations-metadata-r3glpbEg.js";import{S as he,_ as E,a as ge,b as D,c as _e,d as ve,f as ye,g as O,h as be,i as xe,l as Se,m as Ce,n as we,o as Te,p as Ee,r as De,s as Oe,t as ke,u as Ae,v as k,x as je,y as Me}from"./generated-option-order-CZUJFgSS.js";import{a as Ne,i as Pe,n as Fe,r as Ie}from"./payload-operand-guard-BVp_alVX.js";import{fileURLToPath as Le}from"node:url";import{readFile as Re}from"node:fs/promises";async function ze(e){let t;try{t=e===`-`?await Be():await Re(e,`utf8`)}catch(t){return v(`Could not read input: ${t.message}`,[`path=${e}`])}try{if(t.trim().length===0)return g(`No input provided`,null);let e=JSON.parse(t);return g(`Input parsed`,e)}catch(e){return v(`Input is not valid JSON: ${e.message}`)}}async function Be(){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 A=`--content-type`;function Ve(e,n,r){let i=e=>!r?.has(e)&&(r?.add(e),!0),a=n.requestBody??[];if(a.length>1&&i(A)){let n=a.map(({contentType:e})=>e);e.addOption(new t(`${A} <media-type>`,`Select the request body encoding, never an uploaded file's media type; omit for ${n[0]}.`).choices(n).argParser(Ue(a)))}if(I(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>`,ge(r,r.requiredPath)).argParser(j(`--from-file`)))}let o=Te(a).filter(e=>i(N(e.variant[0].parameter)));for(let n of o.toSorted((e,t)=>we(e.variant[0].parameter,t.variant[0].parameter))){let{descriptor:r,parameter:i}=n.variant[0],o=new t(xe(n),a.length>1?De(n):_e(r,i));a.length===1&&i.envName!==void 0&&o.env(i.envName);let s=a.length===1?Oe(r,i.optionKey):[];s.length>0&&o.conflicts(s),a.length>1?o.argParser(He):E(i.name)||i.schemaType===`array`?o.argParser(We):o.argParser(j(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`)})}nt(e,n,o)}function He(e,t){return t===void 0?e:typeof t==`string`?[t,e]:[...t,e]}function Ue(e){return(t,r)=>{if(r!==void 0)throw new n(`${A} was already given; pass it once.`);let i=h(e,t);if(!i.ok)throw new n(i.summary);return t}}function We(e,t){return[...t??[],e]}function j(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 M(e,t){let n=x(e,t),r=h(e.requestBody??[],n);if(!r.ok||r.data===null)return v(r.summary,r.warnings);let i=r.data;if(i===void 0)return g(`No body`,void 0);let a=Ge(e,i,t);if(a!==null)return v(a);let o=ye(e.operationId,i,t);if(!o.ok)return v(o.summary,o.warnings);t=o.data;let s=Ke(i,t);if(s!==null)return v(s);let c=await Xe(t);if(!c.ok)return v(c.summary,c.warnings);let l=Ce(e.requestBody??[],i,c.data);if(l!==null)return v(l);let u=Ye(e.operationId,i,c.data);if(!u.ok)return u;let d=be(e.operationId,i,c.data);if(d!==null)return v(d);let f=Ze(e.operationId,i,t);if(!f.ok)return f;if(c.data===void 0&&f.data===void 0)return i.required?v(tt(e.operationId,i)):g(`No body`,void 0);let p=$e(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 v(`${e.operationId} requires a JSON array body.`);if(i.parameter.length>0&&!k(p.data)){let t=i.kind===`multipart`?` keyed by multipart part name`:` body`;return v(`${e.operationId} requires a JSON object${t}.`)}let m=Je(i,p.data);if(m.length>0)return v(`${e.operationId} requires body option(s): ${m.join(`, `)}`);let _=p.data,y=k(_)?D(i).filter(e=>!O(_,e)):[];return y.length>0?v(qe(e.operationId,i,y)):p}function Ge(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`${N(t)} requires ${A} ${i.join(` or `)}.`}return null}function Ke(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 qe(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 Je(e,t){return k(t)?e.parameter.filter(e=>e.required&&!O(t,e.name)).map(N):[]}function Ye(e,t,n){let r=he(t,n);if(r===null)return g(`Body file paths validated`,null);let i=r.suggestion===void 0?``:` Use ${r.suggestion}.`;return v(`${e} --from-file contains unknown JSON path ${r.path}.${i}`)}async function Xe(e){let t=typeof e.fromFile==`string`?e.fromFile:void 0;if(t===void 0)return g(`No body file`,void 0);let n=await ze(t);if(!n.ok)return v(n.summary,n.warnings);let r=_.safeParse(n.data);return r.success?g(`Input parsed`,r.data):v(`Input is not valid JSON value: ${r.error.message}`)}function Ze(e,t,n){let r={},i=!1;for(let e of t.parameter){let a=je(e,n[e.optionKey]);if(!a.ok||a.data===null)return v(a.summary,a.warnings);let o=a.data;if(o===void 0)continue;let s=Qe(t,n,r,e,o);if(!s.ok)return v(s.summary,s.warnings);i=!0}if(!i)return g(`No direct body options`,void 0);let a=Se(e,t,n,r);return a===null?g(`Direct body options parsed`,r):a}function Qe(e,t,n,r,i){let a=Me(r,i);if(a===null){let e=et(r,i);return e.ok?Ae(n,r.name,e.data,r.schemaType===`array`):v(e.summary,e.warnings)}if(a.plain.length>0)return v(`${N(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=Ee(e,t,a.container);for(let e of a.rows.keys())if(!(e<o))return v(`${N(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=F(r.name,r.itemSchemaType,e);if(!t.ok)return v(t.summary,t.warnings);i.push(t.data)}let a=ve(n,r.name,e,i);if(!a.ok)return a}return g(`Body value assigned`,null)}var N=e=>e.flag.split(` `)[0]??e.name;function $e(e,t,n,r){if(n===void 0)return g(`Direct body parsed`,r);if(r===void 0)return g(`Input parsed`,n);if(k(n)&&k(r))try{return g(`Input parsed`,P(t,n,r))}catch(t){return v(`${e} ${t instanceof Error?t.message:String(t)}`)}return v(`${e} cannot combine --from-file with direct body options unless the file body is an object.`)}function P(e,t,n,r=``){let i={...t};for(let[t,a]of Object.entries(n)){let n=i[t],o=`${r}${t}`;if(k(n)&&k(a))i[t]=P(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`:te.test(o)?`; keep multi-line text in the --from-file body`:``}.`)}return i}function et(e,t){if(typeof t==`boolean`)return g(`Body value parsed`,t);if(t===void 0||typeof t==`string`)return F(e.name,e.schemaType,t??``);let n=[],r=E(e.name)&&e.schemaType!==`array`?e.schemaType:e.itemSchemaType;for(let i of t){let t=F(e.name,r,i);if(!t.ok)return t;n.push(t.data)}return g(`Body value parsed`,n)}function F(e,t,n){if(t===`boolean`)return n===`true`?g(`Body value parsed`,!0):n===`false`?g(`Body value parsed`,!1):v(`${e} must be true or false.`);if(t===`number`||t===`integer`){let r=n.trim(),i=Number(r);return r===``||!Number.isFinite(i)?v(`${e} must be a finite ${t}.`):t===`integer`&&!Number.isInteger(i)?v(`${e} must be an integer.`):g(`Body value parsed`,i)}return g(`Body value parsed`,n)}function tt(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(N).join(`, `)}`;let r=D(t);if(r.length>0)return`${e} requires --from-file with JSON body path(s): ${r.join(`, `)}`;let i=t.parameter.map(N).join(`, `);return i.length===0?`${e} requires --from-file`:`${e} requires --from-file or body option(s): ${i}`}function nt(e,t,n){let r=[...t.parameters,...n.map(({variant:e})=>e[0].parameter)];(t.requestBody?.length??0)>1&&r.push({optionKey:`contentType`,flag:A,location:`body`}),I(t)&&r.push({optionKey:`fromFile`,flag:`--from-file`,location:`body`}),ke(e.options,r)}function I(e){return(e.requestBody??[]).some(e=>e.kind!==`multipart`||e.parameter.some(e=>e.schemaFormat!==`binary`))}function rt(e,t,n=y().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 it(r)),r.hook(`preSubcommand`,e=>{e.opts().help&&e.help()});let i=st(t);i!==void 0&&r.option(`--ask <question>`,i.summary),T(r),r.action(async function(r){let{emit:a}=await import(`./output-CtsN3oh3.js`),o=this.optsWithGlobals();if(o.help&&r.length===0){this.outputHelp();return}if(!o.help&&i!==void 0&&o.ask!==void 0){let e=C(o);if(r.length>0){a({mode:e},v(`Use either a command path or --ask, not both.`));return}a({mode:e},await lt(i,o.ask,o.environment,e));return}let s=V(e,r),c=t.find(t=>s!==void 0&&V(e,t.cliPath)===s);if(o.help||s!==void 0&&c===void 0){s===void 0&&this.error(`unknown command '${r.join(` `)}' (run \`${n} --help\` for the command tree)`),s.outputHelp();return}let l=c===void 0?await ct(r,t):g(`Resolved by command path`,{operationId:c.operationId});if(l.ok&&l.data?.command!==void 0&&this.error(`unknown command '${r.join(` `)}' (run \`${n} --help\` for the command tree)`),!l.ok||l.data===null){a({mode:C(o)},l);return}let{writeShowResult:u}=await import(`./operations-catalog-CtACMf18.js`);u({...o,...l.data},t,C(o,`text`),n)}),ot(e,t,n)}var it=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))}},L=2,R=6,at={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=>!re.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(L)}${e}\n${z(n,a,i)}`}};function z(e,t,n){return n.boxWrap(e,t-R).replace(/^/gmu,` `.repeat(R))}function ot(e,t,n){for(let r of t){let i=V(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=ee(r.operationId,t,n),[c,...l]=me(r.errorResponse),u=l.map(t=>z(t.trimStart(),o,e).replace(/^ +/u,` `.repeat(L))),d=c===void 0?[]:[``,c,...u];return`\n${[...s,...d].join(`
2
+ `)}\n`})}}function st(e){let[t,...n]=e.filter(e=>{let[t,n,...r]=e.cliPath;return t===`help`&&n!==void 0&&r.length===0&&H(e)!==void 0});return n.length===0?t:void 0}var B='Accepted selectors: `<METHOD> <route template or concrete path>`, an operationId, or a CLI command path such as "entities get".';async function ct(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?g(`Resolved by route`,{operationId:i.operationId}):v(`${n} is served by ${[i,...a].map(({method:e})=>e).join(`, `)}; name the method, as in \`help ${i.method} ${n}\`.`,[B]);let o=d.find(e=>e===n.toLowerCase());if(o===void 0||r.length===0){let n=e.join(` `).trim();return g(`Resolved by name`,t.some(e=>e.operationId===n)?{operationId:n}:{command:n})}let s=m(o),c=r.join(``),l=t.find(e=>e.method===s&&e.path===c);if(l!==void 0)return g(`Resolved by route template`,{operationId:l.operationId});let{resolveOpenApiOperationSelector:u}=await import(`./openapi-call-CCpc56ir.js`),f=u({method:s,path:c});return!f.ok||f.data===null?v(f.summary,[...f.warnings,B]):g(`Resolved by method and path`,{operationId:f.data.operation.operationId})}function V(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 lt(e,t,n,r){let{buildOpenApiPath:i,runOpenApiCall:a}=await import(`./openapi-call-CCpc56ir.js`),o=H(e);if(o===void 0)return v(`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 s=await M(e,{[o.optionKey]:t});return s.ok?await a({method:e.method,path:i(e.operationId,{}),searchParams:{},body:s.data,auth:e.auth,responseFormat:w(r)?`json`:`auto`}):s}function H(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 ut(e,t,n){if(e.cliPath[0]!==`lookup`||!dt(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?v(i):v(i,[],{httpStatus:n.httpStatus,problem:n.problem})}function dt(e){return e.ok?Array.isArray(e.data)&&e.data.length===0:e.httpStatus===404}function ft(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]}}function pt(t,n,r,i){let a=mt(t),o=a instanceof e?[]:a,s=o[0],c=i.bin[0],l=[{selected:s===`auth`,register:async()=>{let{registerBuiltinAuthCommands:e}=await import(`./builtin-auth-DzCjM2rV.js`);e(n,c)}},{selected:s===`agents`,register:async()=>{let{registerBuiltinAgentSetupCommand:e}=await import(`./builtin-agent-setup-B2Xvqera.js`);e(n,c)}},{selected:s===`update`,register:async()=>{let{registerBuiltinUpdateCommand:e}=await import(`./builtin-update-Dx_i2YGF.js`);e(n,i)}},{selected:s===`batch`,register:async()=>{let{registerBuiltinBatchCommand:e}=await import(`./builtin-batch-DdGyCjlR.js`);e(n,r,c)}},{selected:s===`research-runs`,register:async()=>{let{registerBuiltinResearchRunWaitCommand:e}=await import(`./builtin-research-run-wait-BF06g2eh.js`);e(n)}},{selected:s===`completion`,register:async()=>{let{registerCompletionCommand:e}=await import(`./completion-CoE0a605.js`);e(n,r,c)}},{selected:s===`command-catalog`,register:async()=>{let{registerOperationsCommand:e}=await import(`./operations-uVpQkO2z.js`);e(n,r,c)}}],u=s===void 0||s===`help`||s===`completion`||s===`command-catalog`||!l.some(e=>e.selected)&&!r.some(e=>e.cliPath[0]===s),d=1;for(;d<o.length&&r.some(e=>o.slice(0,d+1).every((t,n)=>e.cliPath[n]===t));)d++;let f=o.slice(0,d),p=u?r:r.filter(e=>f.slice(0,e.cliPath.length).every((t,n)=>e.cliPath[n]===t)),m=new Set,h=async(e=!1)=>{for(let t of l)(e||u||t.selected)&&!m.has(t)&&(await t.register(),m.add(t))};return{generated:p,fullTree:u,registerBuiltin:h,async completeTree(e){e(n,r.filter(e=>!p.includes(e))),await h(!0)}}}function mt(n){try{return new i().exitOverride().configureOutput({writeErr:()=>void 0}).addOption(new t(`--environment <environment>`)).parseOptions([...n]).operands}catch(t){if(!(t instanceof e))throw t;return t}}var ht=new Set(S.map(e=>e.cliPath.join(` `)));function U(e,t){e.showHelpAfterError(!1).exitOverride(t(e)),e.commands.length===0?e.hook(`preAction`,Fe):e.registeredArguments.length===0&&!ht.has(Ne(e).join(` `))&&e.addHelpOption(new Pe(e));for(let n of e.commands)U(n,t)}var W=y(Le(import.meta.url)),G=W.bin[0];async function K(e,t){let{BearerVerificationUnavailableError:n}=await import(`./openapi-call-CCpc56ir.js`),{emitJson:r}=await import(`./output-CtsN3oh3.js`),i=e instanceof Error?e:Error(String(e));s({component:G,event:`fatal`,message:i.message,error:i}),process.stderr.write(`${G} fatal (${t}): ${i.stack??i.message}\n`);let a=i instanceof n?{httpStatus:i.problem.status,problem:i.problem}:{};r({...v(`${G} ${t}: ${i.message}`,[i.name||`Error`],a),counts:{exitCode:1}}),process.exit(1)}function q(e){return ie[ne(e,b)??`cli`]}function J(e,t){let n=t.map(e=>{let t=e.cliPath[0]??``;return{spec:e,top:t,rank:q(t).rank}}).toSorted((e,t)=>e.rank-t.rank||e.top.localeCompare(t.top)).map(e=>e.spec),r=new Set(n.filter(e=>fe(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)gt(e,t,r,a,i.has(t.cliPath.join(` `)))}function gt(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=_t(o,e,s,t)}let l=a.at(-1)??t.operationId,d=o.commands.find(e=>e.name()===l)??o.command(l,t.deprecated===!0?{hidden:!0}:{}),m=t.requestBody?.flatMap(({parameter:e})=>e)??[];d.summary(t.summary||t.operationId).description([`${t.method} ${t.path}.`,t.summary||t.description,`Full documentation: ${G} help ${t.cliPath.join(` `)}`,t.requestBody?.[0]?.kind===`json`||[...t.parameters,...m].some(e=>u(e.schemaType,e.itemSchemaType))?p:``].filter(Boolean).join(`
3
+ `));let h=se(t);for(let e of t.parameters)vt(d,e,i||e===h);Ve(d,t),f(t.intent)&&d.option(`--execute`,`Deprecated; accepted and ignored. This command executes by its verb.`,!1),T(d),d.hook(`preAction`,e=>pe(e,t)),t.explain===!0&&d.option(`--explain`,`Print the search strategy and parsed constraints before the results`),h!==void 0&&d.argument(`[text...]`,h.description||`Same as ${oe(h.flag)}.`),d.action(async function(){let{emit:e,emitSearchExplanation:n}=await import(`./output-CtsN3oh3.js`),r=this.optsWithGlobals(),i=C(r),a=r;if(h!==void 0){let t=ce(h,this.args,r);if(!t.ok||t.data===null)return e({mode:i},t);a=t.data}let o=le(t,a);if(o.length>0)return e({mode:i},v(`missing required options: ${o.join(`, `)}`));let s=await yt(t,a,i),c=ut(t,a,s);if(c!==null)return e({mode:i},c);r.explain===!0&&s.ok&&n(i,s.data),s.ok&&s.data instanceof Uint8Array?process.stdout.write(s.data):e({mode:i},s)})}function _t(e,t,n,r){let i=e.commands.find(e=>e.name()===t);if(i!==void 0)return i;let a=b[n],o=e.command(t,r?{hidden:!0}:{}).helpCommand(!1);return a!==void 0&&o.summary(a.summary).description(a.summary),o}function vt(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 yt(e,t,n){let{buildOpenApiPath:r,runOpenApiCall:i}=await import(`./openapi-call-CCpc56ir.js`),{pendingResult:o}=await import(`./output-CtsN3oh3.js`);if(t.environment!==void 0){let e=l(t.environment);if(e===null)return v(`Unknown aVenture environment '${t.environment}'`,[`Use one of: ${a().join(`, `)}`]);process.env.API_ENV=e}let s=await M(e,t);if(!s.ok)return s;let c=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)]})),u=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]]})),d=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 ft(e,await i({method:e.method,path:r(e.operationId,c),searchParams:u,headers:d,body:s.data,contentType:x(e,t),auth:e.auth,responseFormat:w(n)?`json`:`auto`,responseBytes:e.binaryResponse===!0,pendingResult:o}))}process.on(`uncaughtException`,e=>K(e,`uncaughtException`)),process.on(`unhandledRejection`,e=>K(e,`unhandledRejection`));var Y=ue(process.argv.slice(2),S),X=Y===`required`?S:ae(S),Z=new Ie;Z.name(G).usage(`<command> [subcommand] [options]`).configureHelp(at).version(W.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,
4
4
  people, and news — carry everything else: funding, publications, and tags.
5
5
 
6
6
  Mutations execute directly; --execute is a deprecated no-op.
7
- 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 ${c})`).choices([...a()])).showHelpAfterError(`(run \`${G} --help\` for usage)`);var Q=pt(process.argv.slice(2),Z,X,W);J(Z,Q.generated),await Q.registerBuiltin(),rt(Z,X,G);for(let e of Z.commands)e.helpGroup()||e.helpGroup(q(e.name()).heading);var $;if(U(Z,e=>t=>{throw $=(async()=>{!Q.fullTree&&![`commander.helpDisplayed`,`commander.version`].includes(t.code)&&await Q.completeTree(J);let{commandExitHandler:n}=await import(`./parse-error-hint-B4SJhS4y.js`);try{n(e)(t)}catch(e){if(e!==t)throw e}})(),t}),Y===`required`){let e=[Z];for(;e.length>0;){let t=e.pop();t!==void 0&&(e.push(...t.commands),t.hook(`preAction`,async(e,t)=>{e===t&&await de(`required`)}))}}var bt=new Set(Z.commands.filter(e=>[`entities`,`people`,`news`].includes(e.name())).flatMap(e=>e.commands.map(e=>e.name())));Z.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])=>bt.has(e)?[t]:[]),``,`Authentication (every command that calls aVenture needs a credential):`,` Create one at ${o}/sign-up, then run: ${G} auth login`,` AUTH_TOKEN aVenture API key, for CI and other non-interactive shells`,` Check what this shell holds with: ${G} 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
7
+ 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 ${c})`).choices([...a()])).showHelpAfterError(`(run \`${G} --help\` for usage)`);var Q=pt(process.argv.slice(2),Z,X,W);J(Z,Q.generated),await Q.registerBuiltin(),rt(Z,X,G);for(let e of Z.commands)e.helpGroup()||e.helpGroup(q(e.name()).heading);var $;if(U(Z,e=>t=>{throw $=(async()=>{!Q.fullTree&&![`commander.helpDisplayed`,`commander.version`].includes(t.code)&&await Q.completeTree(J);let{commandExitHandler:n}=await import(`./parse-error-hint-BNJ09L05.js`);try{n(e)(t)}catch(e){if(e!==t)throw e}})(),t}),Y===`required`){let e=[Z];for(;e.length>0;){let t=e.pop();t!==void 0&&(e.push(...t.commands),t.hook(`preAction`,async(e,t)=>{e===t&&await de(`required`)}))}}var bt=new Set(Z.commands.filter(e=>[`entities`,`people`,`news`].includes(e.name())).flatMap(e=>e.commands.map(e=>e.name())));Z.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])=>bt.has(e)?[t]:[]),``,`Authentication (every command that calls aVenture needs a credential):`,` Create one at ${o}/sign-up, then run: ${G} auth login`,` AUTH_TOKEN aVenture API key, for CI and other non-interactive shells`,` Check what this shell holds with: ${G} 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
8
8
  `,`Exit codes:`,` 0 envelope.ok === true
9
9
  1 envelope.ok === false
10
10
  `,`Examples:`,` $ ${G} auth login`,` $ ${G} lookup --name Stripe --url https://stripe.com`,` $ ${G} search "fintech companies in Austin"\n`,`Run \`${G} <command> --help\` for its subcommands and options,`,`or \`${G} help <command>\` for its full documentation.`].join(`
@@ -1,4 +1,4 @@
1
- import{n as e}from"./commander-DEj7N1b9.js";import{f as t,h as n,x as r}from"./logging-BnHashoK.js";import{S as i}from"./tool-policy-TAT9-UP4.js";import{M as a,O as o,i as s,o as c,v as l,w as u,y as d}from"./person-owner-C0YuWKvY.js";import{c as f,r as p}from"./result-envelope-BKQSGfkH.js";import{a as m}from"./package-CZBWjlYb.js";import{a as h,i as g}from"./response-problem-DG4194cZ.js";import{a as _,d as v,f as y,r as ee,u as te}from"./openapi-call-CrfewEHX.js";import{n as b}from"./contract-BEa-OAos.js";import{S as x,_ as S,a as C,g as w,h as ne,i as re,m as ie,n as ae,p as oe,r as se,s as ce,t as le,v as ue,x as T,y as de}from"./api-key-bearer-credential-BfapI4GF.js";import{a as fe,c as E,d as pe,g as me,l as he,m as ge,o as _e,s as ve,t as ye,u as be}from"./oauth-bearer-credential-DdkhuhWl.js";import{n as xe,r as Se,t as Ce}from"./oauth-login-GE10Mmja.js";import{n as we,t as Te}from"./openapi-commands-v6H75r4H.js";import{t as D}from"./output-ewPhzpBl.js";import{i as O,t as k}from"./output-mode-CMdKmp9N.js";import{n as Ee}from"./builtin-update-ByBZxQIt.js";import{stderr as A,stdin as De}from"node:process";import{TextDecoder as Oe,inspect as ke}from"node:util";import{hostname as Ae,platform as je}from"node:os";import{setTimeout as Me}from"node:timers/promises";import{webcrypto as j}from"node:crypto";var Ne=d({artifact:u().nullish(),group:u().nullish(),name:u().nullish(),revision:u().nullish(),time:s({offset:!0}).nullish(),version:u().nullish()}),Pe=d({build:Ne}),Fe=c([`MACOS`,`LINUX`,`WINDOWS`,`OTHER`]),Ie=c([`RSA_OAEP_256_A256_GCM_V1`]),Le=d({clientLabel:u().regex(/.*\S.*/).min(1).max(120).nullish(),clientPlatform:Fe.nullish(),encryptionAlgorithm:Ie.nullish(),encryptionPublicKey:u().min(344).max(12e3).nullish()}),Re=32;async function ze(){let e=await j.subtle.generateKey({name:`RSA-OAEP`,modulusLength:2048,publicExponent:new Uint8Array([1,0,1]),hash:`SHA-256`},!0,[`encrypt`,`decrypt`]),t=await j.subtle.exportKey(`spki`,e.publicKey);return{publicKey:Buffer.from(t).toString(`base64`),privateKey:e.privateKey}}async function Be(e,t){let{wrappedKey:n,nonce:r,ciphertext:i,authenticationTag:a}=t,o=M(n,`wrapped key`,128,1024),s=M(r,`nonce`,12,12),c=M(i,`ciphertext`,1,65536),l=M(a,`authentication tag`,16,16),u;try{u=await j.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!==Re)throw Error(`broker credential used an invalid AES-256 key`);let e=await j.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 j.subtle.decrypt({name:`AES-GCM`,iv:s,tagLength:128},e,t)}catch{throw Error(`broker credential payload failed authentication`)}let r=new Oe(`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 M(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 Ve=c([`PENDING`,`ISSUING`,`KEY_READY`,`REVOKING`,`CONSUMED`,`REVOKED`,`DENIED`,`EXPIRED`,`FAILED`]),He=c([`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`]),Ue=d({approvedAt:s({offset:!0}).nullish(),clientLabel:u(),clientPlatform:Fe,comparisonCode:u(),consumedAt:s({offset:!0}).nullish(),createdAt:s({offset:!0}),expiresAt:s({offset:!0}),id:o(),intervalSeconds:l().int().min(1),keyReadyAt:s({offset:!0}).nullish(),status:Ve,terminalAt:s({offset:!0}).nullish(),terminalReason:He.nullish(),updatedAt:s({offset:!0})}),We=d({algorithm:Ie,authenticationTag:u(),ciphertext:u(),nonce:u(),wrappedKey:u()}),Ge=d({delivery:We.nullish(),expiresAt:s({offset:!0}),status:Ve,terminalReason:He.nullish()}),Ke=d({comparisonCode:u(),expiresAt:s({offset:!0}),id:o(),intervalSeconds:l().int().min(1),pollSecret:u(),verificationUrl:u()}),N=[{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.`}]}],P=b(N,`start`),F=b(N,`poll`),I=b(N,`acknowledge`),L=class extends Error{httpStatus;retryAfterSeconds;retryable;constructor(e,t,n=[]){super(`CLI authorization ${e} failed: ${S(t,n)}`),this.name=`CliAuthorizationRequestError`,this.httpStatus=t.status,this.retryAfterSeconds=Qe(t.retryAfterSeconds),this.retryable=t.status>=500||t.status===429}},qe=class extends Error{constructor(e,t,n=[]){super(`CLI authorization ${e} transport failed: ${w(t,n)}`,{cause:t}),this.name=`CliAuthorizationTransportError`}};async function Je(e){let t=await y(x(r()),{method:P.method,path:i(P.path,{},P.operationId),headers:{},contentType:`application/json`,body:e},Ke);if(t.ok&&t.redirect)throw new L(`start`,R(t.status));if(!t.ok)throw new L(`start`,t.problem);return $e(t.data)}async function Ye(e,t){let n=v(F.operationId),a=await y(x(r()),{method:F.method,path:i(F.path,{cliAuthorizationId:e},F.operationId),headers:{[n]:t}},Ge);if(a.ok&&a.redirect)throw new L(`poll`,R(a.status),[t]);if(!a.ok)throw new L(`poll`,a.problem,[t]);return{authorization:a.data,retryAfterSeconds:Ze(a.headers[`retry-after`])}}async function Xe(e,t){let n=v(I.operationId),a;try{a=await y(x(r()),{method:I.method,path:i(I.path,{cliAuthorizationId:e},I.operationId),headers:{[n]:t}},Ue)}catch(e){throw new qe(`acknowledge`,e,[t])}if(a.ok&&a.redirect)throw new L(`acknowledge`,R(a.status),[t]);if(!a.ok)throw new L(`acknowledge`,a.problem,[t]);return a.data}function Ze(e){if(e===void 0)return null;let t=Number(e);return Number.isInteger(t)&&t>0?t:null}function Qe(e){return typeof e==`number`&&Number.isInteger(e)&&e>0?e:null}function R(e){return{status:e,title:`Unexpected redirect`,type:`about:blank`,code:void 0,detail:`CLI authorization endpoint returned an unexpected redirect`}}function $e(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())})`},[ke.custom]:{enumerable:!1,value:a}})}async function et(e){let t=await z(e.credential.secret);if(t.state!==`verified`||e.activation!==`active`)return{stored:e,verification:t};try{return{stored:await C(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 — ${w(n,[e.credential.secret])}`}}}}async function z(e){let t=x(r()),n;try{n=await y(t,{method:`GET`,path:ee(`getCurrentApiKey`,{}),headers:{Authorization:`Bearer ${e}`}},ue)}catch(t){return{state:`unavailable`,summary:`identity verification failed before an HTTP response — ${w(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: ${S(n.problem,[e])}`}}var B=b(N,`revoke`);async function tt(e){let t;try{t=T(r().host)}catch(e){return p(`auth logout: invalid API host — ${w(e)}`)}let n=await nt(t),i=await at(t,e),a=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`}`]:[],o={host:t,revoked:!1,forgotten:!1,oauth:n};return i===null?n.state===`missing`?f(`No CLI credential is stored for this API host.`,o):n.state===`failed`?{...p(`auth logout: ${a[0]}`),data:o}:f(n.revoked?`OAuth credential revoked remotely and removed locally.`:`OAuth credential removed locally.`,o,{warnings:a}):{...i,data:{...i.data??o,oauth:n},warnings:[...i.warnings,...a]}}async function nt(e){let t=await _e(e);if(t.state===`missing`)return{state:`missing`};let n=t.state===`found`?await it(t.stored):{revoked:!1};try{await fe(e)}catch(e){return{state:`failed`,summary:w(e)}}return{state:`forgotten`,...n}}async function rt(e){let t=Reflect.get(await Ce(e),`revocation_endpoint`);return typeof t==`string`?me(t,`revocation endpoint`,!0):void 0}async function it(e){let{client:t,tokens:n}=e.credential,r=n.refresh_token??n.access_token;try{let e=await rt(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:be(t)})});return n.ok?{revoked:!0}:{revoked:!1,summary:`revocation endpoint answered ${n.status}`}}catch(e){return{revoked:!1,summary:w(e,ge(n))}}}async function at(e,t){let n;try{n=await re(e)}catch(e){return p(`auth logout: stored credential could not be read — ${w(e)}`)}if(n.state===`unavailable`)return{...p(`auth logout: ${n.summary}`),data:{host:e,revoked:!1,forgotten:!1}};if(n.state===`missing`)return null;let r=n.stored,i=await ot(r),a=i.outcome===`revoked`,o=r.activation===`pending`&&i.outcome===`rejected`;if(!a&&!o&&!t.forgetLocal)return{...p(`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:V(r,!1,!1)};try{await ae(r.host)}catch(e){return{...p(`auth logout: local credential removal failed — ${w(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:V(r,a,!1)}}return f(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.`,V(r,a,!0),{ids:[r.credential.apiKey.id],warnings:a||o?[]:[`Remote revocation was not confirmed; the API key may remain active.`]})}async function ot(e){let t=x(r());try{let n=await y(t,{method:B.method,path:i(B.path,{},B.operationId),headers:{Authorization:`Bearer ${e.credential.secret}`}},ue);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:S(n.problem,[e.credential.secret])}}catch(t){return{outcome:`unconfirmed`,summary:w(t,[e.credential.secret])}}}function V(e,t,n){return{host:e.host,apiKeyId:e.credential.apiKey.id,activation:e.activation,revoked:t,forgotten:n}}var st=`RSA_OAEP_256_A256_GCM_V1`,ct=1,lt=30,H=m().bin[0],U=`The local record remains pending and unavailable to ordinary commands. Re-run \`${H} auth login --key\`; it recovers the credential when the broker acknowledged it, and otherwise clears the stale record.`;async function ut(e){if(!De.isTTY)return p(`${H} 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=r().host;t=T(e),n=de(e)}catch(e){return p(`auth login --key: invalid environment configuration — ${w(e)}`)}for(;;){let e;try{e=await se(t)}catch(e){return p(`auth login --key: credential storage could not be inspected — ${w(e)}`)}if(e.state===`unavailable`)return p(`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&&A.write(ce(e.keyringFailure));break}let n=await dt(e.stored);if(n!==null)return n}let i;try{i=await ze()}catch(e){return p(`auth login --key: ephemeral encryption key could not be created — ${w(e)}`)}let o=Le.safeParse({clientLabel:e.clientLabel?.trim()||(Ae().trim()||H).slice(0,120),clientPlatform:ht(),encryptionAlgorithm:st,encryptionPublicKey:i.publicKey});if(!o.success)return p(`auth login --key: ${a(o.error)}`);let s;try{s=await Je(o.data)}catch(e){return p(`auth login --key: could not start browser authorization — ${w(e)}`)}let c;try{c=ie(s,n)}catch(e){return p(`auth login --key: unsafe browser authorization URL rejected — ${w(e)}`)}if(!mt(await oe(s,n,{noBrowser:e.noBrowser}),s,c))return p(`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:[c]});let l;try{l=await pt(s)}catch(e){return p(`auth login --key: authorization did not complete — ${w(e)}`,[],{references:[c]})}if(l.algorithm!==st)return p(`auth login --key: broker selected an unsupported encryption algorithm`);let u;try{u=await Be(i.privateKey,l)}catch(e){return p(`auth login --key: encrypted credential could not be opened — ${w(e)}`)}let d=await z(u);if(d.state!==`verified`)return p(`auth login --key: decrypted credential was neither stored nor acknowledged — ${d.summary}`);let m;try{m=await C(t,{apiKey:d.apiKey,secret:u},`pending`)}catch(e){return p(`auth login --key: credential could not be durably stored — ${w(e)}`)}let h;try{h=await ft(s)}catch(e){return K(m,!0,`auth login --key: credential was stored and verified, but broker acknowledgment was not confirmed — ${w(e,[s.pollSecret])}`,U)}if(h.status!==`CONSUMED`)return K(m,!0,`auth login --key: broker returned ${h.status} after acknowledgment`,U);let g=await z(u);if(g.state!==`verified`||!_t(g.apiKey,m.credential.apiKey))return K(m,!0,`auth login --key: broker acknowledgment succeeded, but refreshed credential metadata could not prove the granted lifetime — ${g.summary}`,U);try{let e=await C(t,{apiKey:g.apiKey,secret:u},`active`);return f(`API key stored; authenticated identity and broker acknowledgment verified.`,G(e,!0),{ids:[e.credential.apiKey.id]})}catch(e){return K(m,!0,`auth login --key: remote acknowledgment succeeded, but local activation could not be confirmed — ${w(e)}`,U)}}async function dt(e){let t=await z(e.credential.secret);if(e.activation!==`pending`)return t.state===`verified`?f(`API key is already stored and its authenticated identity was verified.`,G(e,!0),{ids:[e.credential.apiKey.id]}):K(e,!1,`auth login --key: stored credential ${t.state} — ${t.summary}`,`Run \`${H} auth logout\` to revoke/remove it before authorizing a replacement.`);if(t.state===`verified`&&_t(t.apiKey,e.credential.apiKey))try{let n=await C(e.host,{apiKey:t.apiKey,secret:e.credential.secret},`active`);return f(`Recovered pending CLI credential: broker acknowledgment had succeeded.`,G(n,!0),{ids:[n.credential.apiKey.id]})}catch(t){return K(e,!0,`auth login --key: credential is valid but could not be promoted locally — ${w(t,[e.credential.secret])}`,`The remote key remains valid. Re-run \`${H} 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 K(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 \`${H} auth login --key\` when the API is reachable; it recovers an acknowledged credential and clears an unacknowledged one.`);let n=await ot(e);if(n.outcome===`unconfirmed`)return K(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 ae(e.host)}catch(t){return K(e,!1,`auth login --key: stale pending credential could not be removed — ${w(t,[e.credential.secret])}`)}return A.write(n.outcome===`revoked`?`Revoked and cleared a stale pending CLI credential; starting a fresh browser authorization.
1
+ import{n as e}from"./commander-DEj7N1b9.js";import{f as t,h as n,x as r}from"./logging-Bk8_GcPH.js";import{S as i}from"./tool-policy-BPefkvzQ.js";import{M as a,O as o,i as s,o as c,v as l,w as u,y as d}from"./person-owner-C0YuWKvY.js";import{c as f,r as p}from"./result-envelope-5R2VEWAg.js";import{a as m}from"./package-CZBWjlYb.js";import{a as h,i as g}from"./response-problem-BGEYFwd5.js";import{a as _,d as v,f as y,r as ee,u as te}from"./openapi-call-Cu_IqRxU.js";import{n as b}from"./contract-BztWeCTz.js";import{S as x,_ as S,a as C,g as w,h as ne,i as re,m as ie,n as ae,p as oe,r as se,s as ce,t as le,v as ue,x as T,y as de}from"./api-key-bearer-credential-CyFG5_Cm.js";import{a as fe,c as E,d as pe,g as me,l as he,m as ge,o as _e,s as ve,t as ye,u as be}from"./oauth-bearer-credential-CMDf5sF6.js";import{n as xe,r as Se,t as Ce}from"./oauth-login-Cj6xqtM3.js";import{n as we,t as Te}from"./openapi-commands-CKb-tN3f.js";import{t as D}from"./output-BCOtzmsw.js";import{i as O,t as k}from"./output-mode-DYvJUCAE.js";import{n as Ee}from"./builtin-update-5IL6qRqK.js";import{stderr as A,stdin as De}from"node:process";import{TextDecoder as Oe,inspect as ke}from"node:util";import{hostname as Ae,platform as je}from"node:os";import{setTimeout as Me}from"node:timers/promises";import{webcrypto as j}from"node:crypto";var Ne=d({artifact:u().nullish(),group:u().nullish(),name:u().nullish(),revision:u().nullish(),time:s({offset:!0}).nullish(),version:u().nullish()}),Pe=d({build:Ne}),Fe=c([`MACOS`,`LINUX`,`WINDOWS`,`OTHER`]),Ie=c([`RSA_OAEP_256_A256_GCM_V1`]),Le=d({clientLabel:u().regex(/.*\S.*/).min(1).max(120).nullish(),clientPlatform:Fe.nullish(),encryptionAlgorithm:Ie.nullish(),encryptionPublicKey:u().min(344).max(12e3).nullish()}),Re=32;async function ze(){let e=await j.subtle.generateKey({name:`RSA-OAEP`,modulusLength:2048,publicExponent:new Uint8Array([1,0,1]),hash:`SHA-256`},!0,[`encrypt`,`decrypt`]),t=await j.subtle.exportKey(`spki`,e.publicKey);return{publicKey:Buffer.from(t).toString(`base64`),privateKey:e.privateKey}}async function Be(e,t){let{wrappedKey:n,nonce:r,ciphertext:i,authenticationTag:a}=t,o=M(n,`wrapped key`,128,1024),s=M(r,`nonce`,12,12),c=M(i,`ciphertext`,1,65536),l=M(a,`authentication tag`,16,16),u;try{u=await j.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!==Re)throw Error(`broker credential used an invalid AES-256 key`);let e=await j.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 j.subtle.decrypt({name:`AES-GCM`,iv:s,tagLength:128},e,t)}catch{throw Error(`broker credential payload failed authentication`)}let r=new Oe(`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 M(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 Ve=c([`PENDING`,`ISSUING`,`KEY_READY`,`REVOKING`,`CONSUMED`,`REVOKED`,`DENIED`,`EXPIRED`,`FAILED`]),He=c([`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`]),Ue=d({approvedAt:s({offset:!0}).nullish(),clientLabel:u(),clientPlatform:Fe,comparisonCode:u(),consumedAt:s({offset:!0}).nullish(),createdAt:s({offset:!0}),expiresAt:s({offset:!0}),id:o(),intervalSeconds:l().int().min(1),keyReadyAt:s({offset:!0}).nullish(),status:Ve,terminalAt:s({offset:!0}).nullish(),terminalReason:He.nullish(),updatedAt:s({offset:!0})}),We=d({algorithm:Ie,authenticationTag:u(),ciphertext:u(),nonce:u(),wrappedKey:u()}),Ge=d({delivery:We.nullish(),expiresAt:s({offset:!0}),status:Ve,terminalReason:He.nullish()}),Ke=d({comparisonCode:u(),expiresAt:s({offset:!0}),id:o(),intervalSeconds:l().int().min(1),pollSecret:u(),verificationUrl:u()}),N=[{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.`}]}],P=b(N,`start`),F=b(N,`poll`),I=b(N,`acknowledge`),L=class extends Error{httpStatus;retryAfterSeconds;retryable;constructor(e,t,n=[]){super(`CLI authorization ${e} failed: ${S(t,n)}`),this.name=`CliAuthorizationRequestError`,this.httpStatus=t.status,this.retryAfterSeconds=Qe(t.retryAfterSeconds),this.retryable=t.status>=500||t.status===429}},qe=class extends Error{constructor(e,t,n=[]){super(`CLI authorization ${e} transport failed: ${w(t,n)}`,{cause:t}),this.name=`CliAuthorizationTransportError`}};async function Je(e){let t=await y(x(r()),{method:P.method,path:i(P.path,{},P.operationId),headers:{},contentType:`application/json`,body:e},Ke);if(t.ok&&t.redirect)throw new L(`start`,R(t.status));if(!t.ok)throw new L(`start`,t.problem);return $e(t.data)}async function Ye(e,t){let n=v(F.operationId),a=await y(x(r()),{method:F.method,path:i(F.path,{cliAuthorizationId:e},F.operationId),headers:{[n]:t}},Ge);if(a.ok&&a.redirect)throw new L(`poll`,R(a.status),[t]);if(!a.ok)throw new L(`poll`,a.problem,[t]);return{authorization:a.data,retryAfterSeconds:Ze(a.headers[`retry-after`])}}async function Xe(e,t){let n=v(I.operationId),a;try{a=await y(x(r()),{method:I.method,path:i(I.path,{cliAuthorizationId:e},I.operationId),headers:{[n]:t}},Ue)}catch(e){throw new qe(`acknowledge`,e,[t])}if(a.ok&&a.redirect)throw new L(`acknowledge`,R(a.status),[t]);if(!a.ok)throw new L(`acknowledge`,a.problem,[t]);return a.data}function Ze(e){if(e===void 0)return null;let t=Number(e);return Number.isInteger(t)&&t>0?t:null}function Qe(e){return typeof e==`number`&&Number.isInteger(e)&&e>0?e:null}function R(e){return{status:e,title:`Unexpected redirect`,type:`about:blank`,code:void 0,detail:`CLI authorization endpoint returned an unexpected redirect`}}function $e(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())})`},[ke.custom]:{enumerable:!1,value:a}})}async function et(e){let t=await z(e.credential.secret);if(t.state!==`verified`||e.activation!==`active`)return{stored:e,verification:t};try{return{stored:await C(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 — ${w(n,[e.credential.secret])}`}}}}async function z(e){let t=x(r()),n;try{n=await y(t,{method:`GET`,path:ee(`getCurrentApiKey`,{}),headers:{Authorization:`Bearer ${e}`}},ue)}catch(t){return{state:`unavailable`,summary:`identity verification failed before an HTTP response — ${w(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: ${S(n.problem,[e])}`}}var B=b(N,`revoke`);async function tt(e){let t;try{t=T(r().host)}catch(e){return p(`auth logout: invalid API host — ${w(e)}`)}let n=await nt(t),i=await at(t,e),a=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`}`]:[],o={host:t,revoked:!1,forgotten:!1,oauth:n};return i===null?n.state===`missing`?f(`No CLI credential is stored for this API host.`,o):n.state===`failed`?{...p(`auth logout: ${a[0]}`),data:o}:f(n.revoked?`OAuth credential revoked remotely and removed locally.`:`OAuth credential removed locally.`,o,{warnings:a}):{...i,data:{...i.data??o,oauth:n},warnings:[...i.warnings,...a]}}async function nt(e){let t=await _e(e);if(t.state===`missing`)return{state:`missing`};let n=t.state===`found`?await it(t.stored):{revoked:!1};try{await fe(e)}catch(e){return{state:`failed`,summary:w(e)}}return{state:`forgotten`,...n}}async function rt(e){let t=Reflect.get(await Ce(e),`revocation_endpoint`);return typeof t==`string`?me(t,`revocation endpoint`,!0):void 0}async function it(e){let{client:t,tokens:n}=e.credential,r=n.refresh_token??n.access_token;try{let e=await rt(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:be(t)})});return n.ok?{revoked:!0}:{revoked:!1,summary:`revocation endpoint answered ${n.status}`}}catch(e){return{revoked:!1,summary:w(e,ge(n))}}}async function at(e,t){let n;try{n=await re(e)}catch(e){return p(`auth logout: stored credential could not be read — ${w(e)}`)}if(n.state===`unavailable`)return{...p(`auth logout: ${n.summary}`),data:{host:e,revoked:!1,forgotten:!1}};if(n.state===`missing`)return null;let r=n.stored,i=await ot(r),a=i.outcome===`revoked`,o=r.activation===`pending`&&i.outcome===`rejected`;if(!a&&!o&&!t.forgetLocal)return{...p(`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:V(r,!1,!1)};try{await ae(r.host)}catch(e){return{...p(`auth logout: local credential removal failed — ${w(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:V(r,a,!1)}}return f(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.`,V(r,a,!0),{ids:[r.credential.apiKey.id],warnings:a||o?[]:[`Remote revocation was not confirmed; the API key may remain active.`]})}async function ot(e){let t=x(r());try{let n=await y(t,{method:B.method,path:i(B.path,{},B.operationId),headers:{Authorization:`Bearer ${e.credential.secret}`}},ue);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:S(n.problem,[e.credential.secret])}}catch(t){return{outcome:`unconfirmed`,summary:w(t,[e.credential.secret])}}}function V(e,t,n){return{host:e.host,apiKeyId:e.credential.apiKey.id,activation:e.activation,revoked:t,forgotten:n}}var st=`RSA_OAEP_256_A256_GCM_V1`,ct=1,lt=30,H=m().bin[0],U=`The local record remains pending and unavailable to ordinary commands. Re-run \`${H} auth login --key\`; it recovers the credential when the broker acknowledged it, and otherwise clears the stale record.`;async function ut(e){if(!De.isTTY)return p(`${H} 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=r().host;t=T(e),n=de(e)}catch(e){return p(`auth login --key: invalid environment configuration — ${w(e)}`)}for(;;){let e;try{e=await se(t)}catch(e){return p(`auth login --key: credential storage could not be inspected — ${w(e)}`)}if(e.state===`unavailable`)return p(`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&&A.write(ce(e.keyringFailure));break}let n=await dt(e.stored);if(n!==null)return n}let i;try{i=await ze()}catch(e){return p(`auth login --key: ephemeral encryption key could not be created — ${w(e)}`)}let o=Le.safeParse({clientLabel:e.clientLabel?.trim()||(Ae().trim()||H).slice(0,120),clientPlatform:ht(),encryptionAlgorithm:st,encryptionPublicKey:i.publicKey});if(!o.success)return p(`auth login --key: ${a(o.error)}`);let s;try{s=await Je(o.data)}catch(e){return p(`auth login --key: could not start browser authorization — ${w(e)}`)}let c;try{c=ie(s,n)}catch(e){return p(`auth login --key: unsafe browser authorization URL rejected — ${w(e)}`)}if(!mt(await oe(s,n,{noBrowser:e.noBrowser}),s,c))return p(`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:[c]});let l;try{l=await pt(s)}catch(e){return p(`auth login --key: authorization did not complete — ${w(e)}`,[],{references:[c]})}if(l.algorithm!==st)return p(`auth login --key: broker selected an unsupported encryption algorithm`);let u;try{u=await Be(i.privateKey,l)}catch(e){return p(`auth login --key: encrypted credential could not be opened — ${w(e)}`)}let d=await z(u);if(d.state!==`verified`)return p(`auth login --key: decrypted credential was neither stored nor acknowledged — ${d.summary}`);let m;try{m=await C(t,{apiKey:d.apiKey,secret:u},`pending`)}catch(e){return p(`auth login --key: credential could not be durably stored — ${w(e)}`)}let h;try{h=await ft(s)}catch(e){return K(m,!0,`auth login --key: credential was stored and verified, but broker acknowledgment was not confirmed — ${w(e,[s.pollSecret])}`,U)}if(h.status!==`CONSUMED`)return K(m,!0,`auth login --key: broker returned ${h.status} after acknowledgment`,U);let g=await z(u);if(g.state!==`verified`||!_t(g.apiKey,m.credential.apiKey))return K(m,!0,`auth login --key: broker acknowledgment succeeded, but refreshed credential metadata could not prove the granted lifetime — ${g.summary}`,U);try{let e=await C(t,{apiKey:g.apiKey,secret:u},`active`);return f(`API key stored; authenticated identity and broker acknowledgment verified.`,G(e,!0),{ids:[e.credential.apiKey.id]})}catch(e){return K(m,!0,`auth login --key: remote acknowledgment succeeded, but local activation could not be confirmed — ${w(e)}`,U)}}async function dt(e){let t=await z(e.credential.secret);if(e.activation!==`pending`)return t.state===`verified`?f(`API key is already stored and its authenticated identity was verified.`,G(e,!0),{ids:[e.credential.apiKey.id]}):K(e,!1,`auth login --key: stored credential ${t.state} — ${t.summary}`,`Run \`${H} auth logout\` to revoke/remove it before authorizing a replacement.`);if(t.state===`verified`&&_t(t.apiKey,e.credential.apiKey))try{let n=await C(e.host,{apiKey:t.apiKey,secret:e.credential.secret},`active`);return f(`Recovered pending CLI credential: broker acknowledgment had succeeded.`,G(n,!0),{ids:[n.credential.apiKey.id]})}catch(t){return K(e,!0,`auth login --key: credential is valid but could not be promoted locally — ${w(t,[e.credential.secret])}`,`The remote key remains valid. Re-run \`${H} 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 K(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 \`${H} auth login --key\` when the API is reachable; it recovers an acknowledged credential and clears an unacknowledged one.`);let n=await ot(e);if(n.outcome===`unconfirmed`)return K(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 ae(e.host)}catch(t){return K(e,!1,`auth login --key: stale pending credential could not be removed — ${w(t,[e.credential.secret])}`)}return A.write(n.outcome===`revoked`?`Revoked and cleared a stale pending CLI credential; starting a fresh browser authorization.
2
2
  `:`Cleared a stale pending CLI credential whose remote key can no longer authenticate; starting a fresh browser authorization.
3
3
  `),null}async function ft(e){let t=new Date(e.expiresAt).getTime(),n=W(e.intervalSeconds);for(;;)try{return await Xe(e.id,e.pollSecret)}catch(e){if(e instanceof L){if(!e.retryable)throw e;n=W(e.retryAfterSeconds??n)}else if(!(e instanceof qe))throw e;if(Date.now()>=t)throw e;A.write(`Broker acknowledgment was interrupted; retrying.
4
4
  `),await gt(n,t)}}async function pt(e){let t=new Date(e.expiresAt).getTime(),n=W(e.intervalSeconds),r;for(A.write(`Waiting for browser approval...
@@ -7,7 +7,7 @@ import{n as e}from"./commander-DEj7N1b9.js";import{f as t,h as n,x as r}from"./l
7
7
  `)),!0)}function ht(){switch(je()){case`darwin`:return`MACOS`;case`linux`:return`LINUX`;case`win32`:return`WINDOWS`;default:return`OTHER`}}function W(e){return Math.min(lt,Math.max(ct,e))}async function gt(e,t){let n=t-Date.now();n>0&&await Me(Math.min(e*1e3,n))}function G(e,t){return{host:e.host,provider:e.provider,apiKeyId:e.credential.apiKey.id,name:g(e.credential.apiKey.name,[e.credential.secret]),activation:e.activation,verified:t}}function K(e,t,n,r){return{...p(n,r===void 0?[]:[r]),data:G(e,t)}}function _t(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 vt(){return null}async function yt(e){let t=null,n=e=>{t=e};try{await ye(e,n),await le(n)}catch(e){return{materialized:t,failure:w(e)}}return{materialized:t,failure:null}}async function bt(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=xt(e.credential,r.materialized)};try{let t=await _({method:`POST`,path:`/v1/auth/me/permissions`,body:{operation:[]},auth:e,requesterScope:e,responseFormat:`json`,onAuthPrepared:s});if(!t.ok)throw Error(St(t));if(a===null)throw Error(`Live permission probe did not prepare a credential`);if(i=Et(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 vt(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:w(r,Ct(t,n,o))}}}function xt(e,t){if(e===null)return null;let n=t??ne().source;if(n===null)throw Error(`Prepared credential has no local provenance`);return{credential:e,source:n}}function St(e){return[e.summary,...e.warnings].join(` — `)}function Ct(e,t,n){return[r().userBearerToken,...h(n?.headers??{}),...e.state===`found`?ge(e.stored.credential.tokens):[],t.state===`found`?t.stored.credential.secret:void 0]}function wt(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:g(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:kt(i),storageFailure:t.state===`unavailable`?t.summary:null,keyringFailure:t.state===`missing`?t.keyringFailure??null:null,error:t.state===`invalid`?t.summary:null}}function Tt(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:E(n.credential),renewable:n===void 0?null:n.credential.tokens.refresh_token!==void 0,identity:n===void 0?null:pe(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 Et(e){if(typeof e!=`object`||!e||e instanceof Uint8Array)throw Error(`permission probe returned no JSON response`);let t=te.safeParse(e.response);if(!t.success)throw t.error;return t.data}function Dt(e,t){let{expiresAt:n,expiresInDay:r}=wt(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 Ot=864e5;function kt(e){if(e===null)return null;let t=new Date(e).getTime();return Number.isNaN(t)?null:Math.round((t-Date.now())/Ot)}var At=7;function jt(e){return e===null?`none`:e.length<=11?e:`${e.slice(0,At)}\u2026${e.slice(-4)}`}var Mt=13,Nt=14;function Pt(e){return[``,`${e.cliName} ${e.cliVersion} \u2192 ${e.apiKey.host}`+(e.apiVersion===null?` (api build unavailable)`:` (api ${e.apiVersion})`),``,...It(e.oauth,e.cliName,e.refresh),...Rt(e.apiKey,e.oauth,e.cliName),``,q(`Providers`,Vt(e.providers)),q(`Environment`,Ht(e.resolved)),q(`Selected`,Ut(e.resolved,e.refresh,e.cliName)),...Ft(e.live)].join(`
8
8
  `)}function Ft(e){if(e===null)return[];let t=J(`local credential provenance was captured before verification`);if(e.error!==null)return[``,q(`Live probe`,`${e.scope} permission probe failed`),t,J(e.error)];if(e.authorization===null)return[];let n=e.authorization.permissionGrant,r=e.identity;return[``,q(`Live probe`,`${e.scope} permission probe succeeded`),t,J(`operation access ${e.authorization.operationAccess}; ${n.role.length} role; ${n.permission.length} permission`),...r===null?[J(e.scope===`read`?`identity not requested for a read-scope credential`:`identity unavailable in this build`)]:[q(`Live account`,r.nameFull??r.email??r.clerkUserId??r.id)],J(`no API operation was executed or individually authorized`)]}function q(e,t){return` ${e.padEnd(Mt)}${t}`}function J(e){return` ${``.padEnd(Mt)}${e}`}function It(e,t,n){switch(e.state){case`found`:{let{credential:r,provider:i}=e.stored,a=pe(r);return[q(`OAuth`,`${a.email??a.subject??`unknown identity`} via ${i}`),J(Lt(r,t,n))]}case`missing`:return[q(`OAuth`,`none stored`),...e.keyringFailure===void 0?[]:[J(`OS keyring unusable — login stores to file: ${e.keyringFailure}`)]];case`unavailable`:return[q(`OAuth`,`storage unavailable: ${e.summary}`)];case`invalid`:return[q(`OAuth`,`stored credential invalid: ${e.summary}`)];default:throw Error(`Unsupported OAuth credential state`)}}function Lt(e,t,n){return E(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 Rt(e,t,n){if(!e.present){if(t.state===`found`)return[];let r=e.storageFailure??(t.state===`unavailable`?t.summary:null);return r===null?[q(`Signed in`,`no \u2014 run \`${n} auth login\``),...e.error===null?[]:[J(`stored credential invalid: ${e.error}`)]]:[q(`Signed in`,`credential storage unavailable`),J(r)]}return[q(t.state===`found`?`API key`:`Signed in`,e.subject??`unknown subject`),J(`via ${e.provider??`unknown store`}`),q(`Key`,`${e.name??`unnamed`} ${jt(e.apiKeyId)}`),...zt(e,n),q(`Scopes`,e.scope.length===0?`none`:e.scope.join(`, `))]}function zt(e,t){let n=e.live,r=e.expiresInDay,i=e.expiresAt;if(n?.state===`invalid`)return[q(`Key state`,`rejected by aVenture sign-in \u2014 ${n.summary}`),J(`run \`${t} auth logout\`, then \`${t} auth login --key\``)];let a=n?.state===`verified`;return[q(`Key state`,a?`${e.status??`unknown`}, verified by aVenture sign-in now`:`${e.status??`unknown`} when stored`),...i===null||r===null?[J(`no expiry recorded`)]:[J(Bt(i,r,a?`expires`:`cached expiry`))],...a?[]:[J(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 Bt(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<=Nt?`${n} ${r}, ${t}d away`:`${n} ${r}`}function Vt(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 ${he(t).host} client ${t.clientId}`:`no OAuth CLI client`].join(`; `)}function Ht(e){return`${t.authToken}=${e.present?e.source??`resolved`:`unset`}`}function Ut(e,n,r){return e.present||n.materialized===`env`?`${t.authToken} from the environment`:n.materialized===`oauth`?`saved OAuth access token`:n.materialized===`api-key`?`saved API key`:`none \u2014 sign in with \`${r} auth login\``}var Wt=[{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 Gt(e,t=m().bin[0]){k(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: [...] }`:",...Wt.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(`
9
9
  `))).action(async function(e){let n=this.optsWithGlobals();n.environment!==void 0&&(process.env.API_ENV=n.environment),D({mode:O(e)},await Kt(t))})}async function Kt(e){let t=qt(),n=Jt(e),[r,i]=await Promise.all([Yt(e),Xt(t,e)]),a=[n.check,r,i.check,await Qt(e),on(t,i.servedFingerprint,n.upgradeAvailable,e)],o={pass:Y(a,`pass`),warn:Y(a,`warn`),fail:Y(a,`fail`),skip:Y(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(`
10
- `);return c.ok?f(l,c,{counts:o}):{...p(l,s,{counts:o}),data:c}}function Y(e,t){return e.filter(e=>e.status===t).length}function X(e,t,n){return{name:e,status:t,message:n}}function qt(){return Te.find(e=>e.intent===`status`&&e.resource===`status`)}function Jt(e){let t=m(),n=Ee(t,`check`);if(!n.ok||n.data===null)return{check:X(`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?X(`cli-version`,`fail`,`Upgrade ${r} from ${i} to ${a}: run \`${e} update\`.`):X(`cli-version`,`pass`,`${r} ${i} matches the latest published release.`),upgradeAvailable:o}}async function Yt(e){try{let{EntityDetailSchema:e}=await import(`./detail-D8sJIA5S.js`);if(typeof e.safeParse!=`function`)throw Error(`EntityDetailSchema does not expose a Zod parser`);return X(`api-schemas`,`pass`,`Installed @aventurevc/api-schemas contracts resolve beyond the CLI startup path.`)}catch(t){return X(`api-schemas`,`fail`,`Reinstall the CLI: run \`${e} update\` — ${w(t)}.`)}}async function Xt(e,t){let n=e??{method:`GET`,path:`/info`,auth:`none`},i;try{i=r().host}catch(e){return{check:X(`api-host`,`fail`,`Correct API_ENV or pass \`--environment <name>\` — ${w(e)}.`),servedFingerprint:null}}let a=await _({method:n.method,path:n.path,auth:n.auth,responseFormat:`json`}).catch(e=>p(w(e)));return a.ok?{check:X(`api-host`,`pass`,`${n.method} ${n.path} answered at ${i}.`),servedFingerprint:e===void 0?null:Zt(a.data)}:{check:X(`api-host`,`fail`,a.httpStatus===401?`Replace or unset the credential ${i} rejected, or run \`${t} auth login\`, then rerun \`${t} auth doctor\` — ${n.method} ${n.path} returned ${a.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 ${i} returned ${a.summary}.`),servedFingerprint:null}}function Zt(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 Qt(e){let n=ne(),[r,i]=await Promise.all([en(),tn()]);if(i.state===`unavailable`&&i.cause===`environment`)return X(`auth`,`fail`,`Fix the environment configuration first — ${i.summary}.`);let a=n.present,o=i.state===`found`&&i.stored.activation===`active`;if(!a&&r.state===`invalid`)return X(`auth`,`fail`,`Saved OAuth credential is invalid; run \`${e} auth login\` to sign in again after verification — ${r.summary}.`);if(!a&&r.state===`found`&&E(r.stored.credential)&&r.stored.credential.tokens.refresh_token===void 0)return X(`auth`,`fail`,`Saved OAuth access token is expired without a refresh token; run \`${e} auth login\` to sign in again.`);if(!a&&!o&&r.state===`unavailable`)return X(`auth`,`fail`,`Make the OS keyring or the CLI config directory usable before \`${e} auth login\`, or inject ${t.authToken} through the environment — ${r.summary}.`);if(a||r.state===`found`||o){let t=await $t(e,n);return X(`auth`,t.status,`Credential source available: ${nn(n,r,i)}; ${t.text}.`)}return i.state===`unavailable`?X(`auth`,`fail`,`Make the OS keyring or the CLI config directory usable before \`${e} auth login --key\`, or inject ${t.authToken} through the environment — ${i.summary}.`):X(`auth`,`fail`,`Run \`${e} auth login\` for OAuth or \`${e} auth login --key\` for an API key. For non-interactive use, set ${t.authToken} in the environment.`)}async function $t(e,t){let n=T(r().host),i=await yt(e),a=`credential=${t.present?t.source??`env`:i.materialized??`none`}`;try{if(i.failure!==null)throw Error(i.failure);let e=await vt(`write`);if(e===null)return{status:`pass`,text:`${a} host=${n}`};let t=e.rbacRole.length===0?`none`:e.rbacRole.join(`,`);return{status:`pass`,text:`${a} account=${e.email??e.id} role=${t} host=${n}`}}catch(t){return{status:`warn`,text:`${a} account=unread host=${n} — GET /v1/auth/me returned ${w(t,[r().userBearerToken])}; run \`${e} auth status --verify write\``}}}async function en(){let e;try{e=T(r().host)}catch(e){return{state:`unavailable`,summary:w(e)}}return await ve(e)}async function tn(){let e;try{e=T(r().host)}catch(e){return{state:`unavailable`,summary:w(e),cause:`environment`}}try{return await se(e)}catch(e){return{state:`unavailable`,summary:w(e),cause:`storage`}}}function nn(e,t,n){return[Ht(e),`oauth=${an(t)}`,`api-key=${rn(n)}`].join(` `)}function rn(e){if(e.state!==`found`)return e.state===`missing`?`unset`:`unavailable`;let t=T(r().host);return`${e.stored.activation}${Dt(t,e)}`}function an(e){switch(e.state){case`found`:return E(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 on(e,t,n,r){let i=Te.length;if(e===void 0)return X(`catalog`,`skip`,`The public catalog omits deployment-status metadata and holds ${i} operations.`);if(t===null)return X(`catalog`,`skip`,`Could not read the served operation fingerprint, so drift is unproven; this catalog holds ${i} operations at ${we}.`);if(t===`9ee4baecf2c298a6`)return X(`catalog`,`pass`,`${i} generated operations match the set the API serves (${we}).`);let a=`This catalog describes a different operation set than the API serves (${we} vs ${t})`;return n===!0?X(`catalog`,`fail`,`${a}: run \`${r} update\`.`):X(`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 Z=b(N,`oauth`),sn=[b(N,`start`),b(N,`poll`),b(N,`acknowledge`)],Q=b(N,`revoke`);function cn(n,r=m().bin[0]){let i=fn(n);Gt(i,r);let a=[`${Z.description} Default method: OAuth in your browser.`,`With --key: ${sn.map(({description:e})=>e).join(` `)}`].join(`
10
+ `);return c.ok?f(l,c,{counts:o}):{...p(l,s,{counts:o}),data:c}}function Y(e,t){return e.filter(e=>e.status===t).length}function X(e,t,n){return{name:e,status:t,message:n}}function qt(){return Te.find(e=>e.intent===`status`&&e.resource===`status`)}function Jt(e){let t=m(),n=Ee(t,`check`);if(!n.ok||n.data===null)return{check:X(`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?X(`cli-version`,`fail`,`Upgrade ${r} from ${i} to ${a}: run \`${e} update\`.`):X(`cli-version`,`pass`,`${r} ${i} matches the latest published release.`),upgradeAvailable:o}}async function Yt(e){try{let{EntityDetailSchema:e}=await import(`./detail-D8sJIA5S.js`);if(typeof e.safeParse!=`function`)throw Error(`EntityDetailSchema does not expose a Zod parser`);return X(`api-schemas`,`pass`,`Installed @aventurevc/api-schemas contracts resolve beyond the CLI startup path.`)}catch(t){return X(`api-schemas`,`fail`,`Reinstall the CLI: run \`${e} update\` — ${w(t)}.`)}}async function Xt(e,t){let n=e??{method:`GET`,path:`/info`,auth:`none`},i;try{i=r().host}catch(e){return{check:X(`api-host`,`fail`,`Correct API_ENV or pass \`--environment <name>\` — ${w(e)}.`),servedFingerprint:null}}let a=await _({method:n.method,path:n.path,auth:n.auth,responseFormat:`json`}).catch(e=>p(w(e)));return a.ok?{check:X(`api-host`,`pass`,`${n.method} ${n.path} answered at ${i}.`),servedFingerprint:e===void 0?null:Zt(a.data)}:{check:X(`api-host`,`fail`,a.httpStatus===401?`Replace or unset the credential ${i} rejected, or run \`${t} auth login\`, then rerun \`${t} auth doctor\` — ${n.method} ${n.path} returned ${a.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 ${i} returned ${a.summary}.`),servedFingerprint:null}}function Zt(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 Qt(e){let n=ne(),[r,i]=await Promise.all([en(),tn()]);if(i.state===`unavailable`&&i.cause===`environment`)return X(`auth`,`fail`,`Fix the environment configuration first — ${i.summary}.`);let a=n.present,o=i.state===`found`&&i.stored.activation===`active`;if(!a&&r.state===`invalid`)return X(`auth`,`fail`,`Saved OAuth credential is invalid; run \`${e} auth login\` to sign in again after verification — ${r.summary}.`);if(!a&&r.state===`found`&&E(r.stored.credential)&&r.stored.credential.tokens.refresh_token===void 0)return X(`auth`,`fail`,`Saved OAuth access token is expired without a refresh token; run \`${e} auth login\` to sign in again.`);if(!a&&!o&&r.state===`unavailable`)return X(`auth`,`fail`,`Make the OS keyring or the CLI config directory usable before \`${e} auth login\`, or inject ${t.authToken} through the environment — ${r.summary}.`);if(a||r.state===`found`||o){let t=await $t(e,n);return X(`auth`,t.status,`Credential source available: ${nn(n,r,i)}; ${t.text}.`)}return i.state===`unavailable`?X(`auth`,`fail`,`Make the OS keyring or the CLI config directory usable before \`${e} auth login --key\`, or inject ${t.authToken} through the environment — ${i.summary}.`):X(`auth`,`fail`,`Run \`${e} auth login\` for OAuth or \`${e} auth login --key\` for an API key. For non-interactive use, set ${t.authToken} in the environment.`)}async function $t(e,t){let n=T(r().host),i=await yt(e),a=`credential=${t.present?t.source??`env`:i.materialized??`none`}`;try{if(i.failure!==null)throw Error(i.failure);let e=await vt(`write`);if(e===null)return{status:`pass`,text:`${a} host=${n}`};let t=e.rbacRole.length===0?`none`:e.rbacRole.join(`,`);return{status:`pass`,text:`${a} account=${e.email??e.id} role=${t} host=${n}`}}catch(t){return{status:`warn`,text:`${a} account=unread host=${n} — GET /v1/auth/me returned ${w(t,[r().userBearerToken])}; run \`${e} auth status --verify write\``}}}async function en(){let e;try{e=T(r().host)}catch(e){return{state:`unavailable`,summary:w(e)}}return await ve(e)}async function tn(){let e;try{e=T(r().host)}catch(e){return{state:`unavailable`,summary:w(e),cause:`environment`}}try{return await se(e)}catch(e){return{state:`unavailable`,summary:w(e),cause:`storage`}}}function nn(e,t,n){return[Ht(e),`oauth=${an(t)}`,`api-key=${rn(n)}`].join(` `)}function rn(e){if(e.state!==`found`)return e.state===`missing`?`unset`:`unavailable`;let t=T(r().host);return`${e.stored.activation}${Dt(t,e)}`}function an(e){switch(e.state){case`found`:return E(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 on(e,t,n,r){let i=Te.length;if(e===void 0)return X(`catalog`,`skip`,`The public catalog omits deployment-status metadata and holds ${i} operations.`);if(t===null)return X(`catalog`,`skip`,`Could not read the served operation fingerprint, so drift is unproven; this catalog holds ${i} operations at ${we}.`);if(t===`0a6436a6f0feb034`)return X(`catalog`,`pass`,`${i} generated operations match the set the API serves (${we}).`);let a=`This catalog describes a different operation set than the API serves (${we} vs ${t})`;return n===!0?X(`catalog`,`fail`,`${a}: run \`${r} update\`.`):X(`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 Z=b(N,`oauth`),sn=[b(N,`start`),b(N,`poll`),b(N,`acknowledge`)],Q=b(N,`revoke`);function cn(n,r=m().bin[0]){let i=fn(n);Gt(i,r);let a=[`${Z.description} Default method: OAuth in your browser.`,`With --key: ${sn.map(({description:e})=>e).join(` `)}`].join(`
11
11
  `);k(dn(i,[Z,...sn],a)).action(ln),k(dn(i,[Q],Q.description)).action(un),k(i.command(`status`).summary(`Keep saved credentials current and report them`).description(`Runs the same credential materialization every command runs, then reports:
12
12
  - auth: whether AUTH_TOKEN was already set in this shell's environment
13
13
  - oauth: the saved OAuth identity and access-token expiry for the selected API host;
@@ -0,0 +1 @@
1
+ import{O as e,i as t,l as n,o as r,p as i,u as a,w as o,y as s}from"./person-owner-C0YuWKvY.js";import{c,f as l,r as u}from"./result-envelope-5R2VEWAg.js";import"./package-CZBWjlYb.js";import{l as d}from"./response-problem-BGEYFwd5.js";import{a as f,m as p,p as m,r as h}from"./openapi-call-Cu_IqRxU.js";import{T as g}from"./detail-BTjlqGmV.js";import{t as _}from"./output-BCOtzmsw.js";import{i as v,t as y}from"./output-mode-DYvJUCAE.js";import"./operations-metadata-r3glpbEg.js";import"node:fs";import{setTimeout as b}from"node:timers/promises";import"node:crypto";var x=r([`UNTRACKED`,`PENDING`,`SETTLED`,`REJECTED`]),S=s({admission:x,hasMore:a(),runId:n(e())}),C=s({complete:a(),entitySlug:o().regex(/^[a-z0-9_-]+$/).max(255).nullable(),gateRemaining:n(o()),note:o().nullish(),whatElseRemaining:n(o()),writeThisIteration:n(o())}),w=r([`COMPREHENSIVE`,`INDIVIDUAL`]),T=r([`claude-agent-sdk`,`pi-agent-sdk`]),E=r([`anthropic`,`openai-chat`,`openai-responses`]),D=r([`unassigned`,`development`,`staging`,`production`]),O=r([`interactive`,`background`]),k=r([`queued`,`running`,`completed`,`failed`,`stopped`]),A=r([`ENRICHMENT`,`TASK`]),j=s({attempt:i(),chassis:T,chassisRouted:a(),createdAt:t({offset:!0}),entitySlug:o().nullish(),environment:D,error:o().nullish(),failureClass:o().nullish(),finishedAt:t({offset:!0}).nullish(),followUpAdmission:x.optional(),hasSourceDocument:a(),id:e(),iteration:i(),lane:O,latestStatus:o().nullish(),llmApi:E,maxIteration:i(),maxScoutConcurrent:i(),mode:w,model:o(),nextAttemptAt:t({offset:!0}).nullish(),researchAllowanceType:l.nullish(),resumeSafeUntil:t({offset:!0}).nullish(),startedAt:t({offset:!0}).nullish(),status:k,subagentModel:o(),taskPresetKey:n(o()).nullish(),type:A,updatedAt:t({offset:!0}),url:o(),userPrompt:o().nullish()}),M=s({entity:g.nullish(),followUp:S.optional(),lastEventAt:t({offset:!0}).nullish(),latestStatus:C.nullish(),provider:g.nullish(),publicUrl:o().nullish(),run:j});function N(e,t,n,r){let i=Number(t);return!Number.isInteger(i)||i<n||i>r?u(`${e} must be an integer between ${n} and ${r}, got "${t}"`):c(`${e} parsed`,i)}async function P(){return{costUsd:null}}var F=5e3,I=6e4,L=3e4,R=86400;function z(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`);y(n),n.action(async function(){let e=this.optsWithGlobals();_({mode:v(e)},await B(e))})}async function B(e){let t=N(`--timeout`,e.timeout,1,R);if(!t.ok||t.data===null)return u(t.summary);let n=Date.now()+t.data*1e3,r=h(`getResearchRun`,{runId:e.runId}),i=F,a=`not read yet`;for(;;){let o=0,s=await H(r,n);if(s.kind===`refused`)return s.envelope;if(s.kind===`detail`){let{run:e}=s.detail;if(e.status===`completed`||e.status===`failed`||e.status===`stopped`)return await V(s.detail);a=`${e.status}, last event ${s.detail.lastEventAt??`none`}`}else a=`unread (${s.reason})`,o=(s.retryAfterSeconds??0)*1e3;let c=n-Date.now();if(c<=0||o>=c){let n=c<=0?`after ${t.data}s`:`and the API asks for ${o/1e3}s, past the ${t.data}s --timeout`;return u(`Run ${e.runId} is still ${a} ${n}`,[`Wait longer with --timeout, or read it with \`research-runs get --run-id ${e.runId}\`.`])}let l=Math.max(o,F+Math.random()*(i-F));await b(Math.min(l,c)),i=Math.min(i*2,I)}}async function V(e){let{run:t}=e,n=await P(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 c(`Run ${t.id} completed${a}`,r,i);let o=t.failureClass?` (${t.failureClass})`:``,s=t.error?`: ${t.error}`:``;return{...c(`Run ${t.id} ${t.status}${o}${a}${s}`,r,i),ok:!1}}async function H(e,t){let n;try{n=await f({method:`GET`,path:e,auth:`auto`,responseFormat:`json`,signal:AbortSignal.timeout(Math.max(1e3,Math.min(L,t-Date.now())))})}catch(e){if(p(e))return{kind:`transient`,reason:String(e)};throw e}if(!n.ok){let{problem:t}=n;if(t!==void 0&&m(t.status,t)){let e=d(t.retryAfterSeconds);return{kind:`transient`,reason:n.summary,...e===void 0?{}:{retryAfterSeconds:e}}}return{kind:`refused`,envelope:u(`GET ${e} failed: ${n.summary}`,n.warnings,{problem:t})}}let r=n.data,i=M.safeParse(typeof r==`object`&&r&&`response`in r?r.response:void 0);return i.success?{kind:`detail`,detail:i.data}:{kind:`refused`,envelope:u(`${e} returned an unexpected body: ${i.error.message}`)}}export{z as registerBuiltinResearchRunWaitCommand};
@@ -1,3 +1,3 @@
1
- import{c as e,r as t}from"./result-envelope-BKQSGfkH.js";import{a as n,n as r,r as i,t as a}from"./package-CZBWjlYb.js";import{t as o}from"./output-ewPhzpBl.js";import{i as s,t as c}from"./output-mode-CMdKmp9N.js";import{t as l}from"./completion-setup-CwJt88xW.js";import{spawnSync as u}from"node:child_process";import{basename as d,dirname as f,relative as p,resolve as m,sep as h}from"node:path";import{existsSync as g,lstatSync as _,mkdirSync as v,mkdtempSync as y,readdirSync as b,readlinkSync as x,realpathSync as S,renameSync as C,symlinkSync as w}from"node:fs";import{randomUUID as T}from"node:crypto";var E=new Intl.Collator(void 0,{numeric:!0}),D=2e4,O=[`lib`,`aventurevc-releases`];function k(e,t=n()){let r=t.registry===``?`Requires npm authentication for @aventurevc packages.`:`Installs from npm.`;c(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). ${r}`,`--execute is deprecated, accepted, and ignored; update executes by its verb.`].join(`
1
+ import{c as e,r as t}from"./result-envelope-5R2VEWAg.js";import{a as n,n as r,r as i,t as a}from"./package-CZBWjlYb.js";import{t as o}from"./output-BCOtzmsw.js";import{i as s,t as c}from"./output-mode-DYvJUCAE.js";import{t as l}from"./completion-setup-CwJt88xW.js";import{spawnSync as u}from"node:child_process";import{basename as d,dirname as f,relative as p,resolve as m,sep as h}from"node:path";import{existsSync as g,lstatSync as _,mkdirSync as v,mkdtempSync as y,readdirSync as b,readlinkSync as x,realpathSync as S,renameSync as C,symlinkSync as w}from"node:fs";import{randomUUID as T}from"node:crypto";var E=new Intl.Collator(void 0,{numeric:!0}),D=2e4,O=[`lib`,`aventurevc-releases`];function k(e,t=n()){let r=t.registry===``?`Requires npm authentication for @aventurevc packages.`:`Installs from npm.`;c(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). ${r}`,`--execute is deprecated, accepted, and ignored; update executes by its verb.`].join(`
2
2
  `)).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=>o({mode:s(e)},A(void 0,`apply`,e.release)))}function A(a,o=`apply`,s){let c=a;try{c??=n(process.argv[1])}catch(e){return t(e instanceof Error?e.message:String(e),[`invalid_package_metadata`])}let l=c.name,u=c.version,f=c.registry===``?``:r,p=c.registry===``&&l===`@aventurevc/aventure-cli`,h=s;if(h===void 0){let e=j([`view`,f,`version`,`--silent`,`--global`],c,{timeout:D});if(!e.ok)return{...e,data:null};if(h=(e.data??``).trim(),h===``)return t(`npm view ${f} returned empty version`,[`empty_stdout`])}let _=s!==void 0||p||E.compare(u,h)<0,x={targetPackage:f,runningPackage:l,currentVersion:u,latestVersion:h,upgradeAvailable:_,upgradeInstalled:!1};if(o===`check`)return e(`${l}@${u} → ${f}@${h} (${_?`available`:`up to date`})`,x);if(c.workingTreeRoot!==null)return t(`Refusing to install over the working-tree build at ${c.workingTreeRoot}; rebuild via make instead`,["running CLI is npm-linked from the back-end checkout — `update` is for published bins"]);try{let t=P(c),n=m(t,...O),r=d(f),a=m(n,`${r}-current`),o=f===``?[f,``]:[f,i],l=F(t,c),p=s??[h,l?.version??u].reduce((e,t)=>E.compare(e,t)<0?t:e,u);v(n,{recursive:!0});let _=[N(c),...g(a)?[S(a)]:[],...b(n,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>m(n,e.name))],C,w=null,T=!1;for(let e of new Set(_.filter(e=>e!==t))){let t=M(e,o,p,c.registry);if(t.ok&&t.data!==null){C=e,w=t.data;break}}if(C===void 0){C=y(m(n,`${r}-${encodeURIComponent(p)}-`));let e=j([`install`,`-g`,`--prefix`,C,...o.map(e=>`${e}@${p}`)],c,{stdio:[`ignore`,`inherit`,`inherit`]});if(!e.ok)return{...e,data:null};T=!0;let t=M(C,o,p,c.registry);if(!t.ok)return{...t,data:null};w=t.data}if(w===null)throw Error(`release verification produced no package`);let D=I(C,t,a,w,s),k=R();return e(`${f} active at ${D}`,{...x,upgradeInstalled:T||s!==void 0||l?.version!==D,installPrefix:t,verifiedVersion:D,completionRefreshed:k.refreshed,completionRefreshMessage:k.message})}catch(e){return t(`${f} update failed: ${L(e)}`,[`existing releases were preserved`])}}function j(n,r,i={}){let a={...process.env};r.registry===``?a.NODE_AUTH_TOKEN??=a.GH_PACKAGES_TOKEN:delete a.GH_PACKAGES_TOKEN;let o=[...n,`--@aventurevc:registry=${r.registry}`],s=u(`npm`,o,{env:a,encoding:`utf8`,...i});if(s.error)return s.signal===`SIGTERM`&&i.timeout!==void 0?t(`npm ${n[0]??``} did not answer within ${i.timeout}ms`,[`timeout`]):t(`npm ${n[0]??``} failed to start: ${s.error.message}`,[`spawn_error`]);if(s.status!==0){let e=(s.stderr??``).trim().split(`
3
3
  `).slice(-3).join(` | `);return t(`npm ${n.join(` `)} exited ${s.status}`,[e||`no stderr`])}return e(`npm ok`,s.stdout??``)}function M(r,i,a,o){try{let t=i.map(e=>{let t=n(m(r,`lib`,`node_modules`,...e.split(`/`),`package.json`));if(t.name!==e||t.version!==a||t.registry!==o)throw Error(`${e} does not match ${a} from ${o}`);for(let e of t.bin)if(!S(m(r,`bin`,e)).startsWith(`${t.packageRoot}${h}`))throw Error(`${e} escapes ${t.packageRoot}`);return t});for(let e of t){let t=m(r,`bin`,e.bin[0]),n=u(process.execPath,[t,`--version`],{encoding:`utf8`,timeout:D});if(n.error)throw Error(`${e.name} verification failed: ${n.error.message}`);let i=(n.stdout??``).trim();if(n.status!==0||i!==a)throw Error(`${e.name} expected ${a} but reported ${i||`empty output`}`)}return e(`CLI and MCP release verified`,t)}catch(e){return t(`release verification failed: ${L(e)}`,[`release prefix: ${r}`])}}function N(e){let t=f(e.packageRoot),n=f(t),r=f(n);if(d(t)!==e.name.split(`/`)[0]||d(n)!==`node_modules`||d(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}${h}`))throw Error(`the running entry escapes its package root`);return f(r)}function P(e){let t=N(e),n=`${h}${O.join(h)}${h}`,r=t.lastIndexOf(n);return r<0?t:t.slice(0,r)}function F(e,t){let r=t.registry===``?d(``):a,i=m(e,`bin`,r);if(!g(i))return null;let o=n(i);if(o.registry!==t.registry)throw Error(`${i} belongs to another product`);return o}function I(e,t,r,i,a){let o=i[0];if(o===void 0)throw Error(`release contains no CLI`);let s=m(t,`bin`);v(s,{recursive:!0});let c=i.flatMap(e=>e.bin.filter((e,t)=>{let r=m(s,e);if(!g(r)||n(r).registry===o.registry)return!0;if(o.registry!==``&&t>0)return!1;throw Error(`${r} belongs to another product`)}));if(!g(r)){let t=y(m(f(r),`${d(r)}-seed-`));v(m(t,`bin`));for(let n of c){let r=m(s,n);w(S(g(r)?r:m(e,`bin`,n)),m(t,`bin`,n))}try{w(p(f(r),t),r)}catch(e){if(!(e instanceof Error&&`code`in e&&e.code===`EEXIST`))throw e}}if(!_(r).isSymbolicLink())throw Error(`${r} is not a release symlink`);for(let e of c){let t=p(s,m(r,`bin`,e)),n=m(s,`.${e}-${T()}`);w(t,n),C(n,m(s,e))}for(let e of c){let t=m(s,e);if(!_(t).isSymbolicLink()||m(s,x(t))!==m(r,`bin`,e))throw Error(`${t} does not follow the product current pointer`)}let l=F(t,o);if(a===void 0&&l!==null&&E.compare(l.version,o.version)>0)return l.version;let u=`${r}-${T()}`;return w(p(f(r),e),u),C(u,r),o.version}function L(e){return e instanceof Error?e.message:String(e)}function R(){try{return l()}catch(e){return{refreshed:!1,message:e instanceof Error?e.message:String(e)}}}export{A as n,k as t};
@@ -0,0 +1 @@
1
+ export{t as registerBuiltinUpdateCommand}from"./builtin-update-5IL6qRqK.js";
@@ -1 +1 @@
1
- import{d as e}from"./tool-policy-TAT9-UP4.js";function t(t,n,r,i){let a=t===`array`?n:t,o=t===`array`?`...`:``;return r===`uuid`||r===`date-time`||r===`date`?`${r}${o}`:a===`boolean`?`true|false${o}`:a===`integer`||a===`number`?`${a}${o}`:`${e(i)}${o}`}function n(e,t){let n=s(e);if(t===void 0||t.length===0)return n;let r=`Allowed values: ${t.join(`, `)}`;return n===``?`${r}.`:`${n} ${r}.`}var r={path:{heading:`Path parameters:`,rank:0},header:{heading:`Request headers:`,rank:1},input:{heading:`Input:`,rank:2},body:{heading:`Body fields:`,rank:3},option:{heading:`Options:`,rank:1/0}};function i(e){return o(e).rank}function a(e){return o(e).heading}function o(e){return e.location===`path`?r.path:e.location===`header`?r.header:e.inputType===`file`||e.schemaFormat===`binary`?r.input:e.location===`body`?r.body:r.option}var s=e=>e===``||/[.!?]$/u.test(e)?e:`${e}.`,c={researchData:{heading:`Research data commands:`,rank:0},account:{heading:`Account commands:`,rank:1},administration:{heading:`Administration commands:`,rank:2},cli:{heading:`CLI commands:`,rank:3}};function l(e,t){return e!==void 0&&u(e,t)===`administration`}function u(e,t){return t?.[e]?.section??d[e]}var d={app:`account`,auth:`account`,entities:`researchData`,people:`researchData`,enrichments:`researchData`,news:`researchData`,search:`researchData`,directory:`researchData`,resolve:`researchData`,lookup:`researchData`,"lookup-jobs":`researchData`,"lookup-mentions":`researchData`,"research-runs":`researchData`,provenance:`administration`,billing:`account`,harness:`administration`,jobs:`administration`,operations:`administration`,metrics:`cli`,inference:`administration`,web:`researchData`,contacts:`administration`,"url-types":`researchData`,"unique-ids":`researchData`,research:`administration`,status:`cli`,agents:`cli`,help:`cli`},f=new Set([`metrics`]);export{n as a,a as c,u as i,s as l,f as n,t as o,l as r,i as s,c as t};
1
+ import{d as e}from"./tool-policy-BPefkvzQ.js";function t(t,n,r,i){let a=t===`array`?n:t,o=t===`array`?`...`:``;return r===`uuid`||r===`date-time`||r===`date`?`${r}${o}`:a===`boolean`?`true|false${o}`:a===`integer`||a===`number`?`${a}${o}`:`${e(i)}${o}`}function n(e,t){let n=s(e);if(t===void 0||t.length===0)return n;let r=`Allowed values: ${t.join(`, `)}`;return n===``?`${r}.`:`${n} ${r}.`}var r={path:{heading:`Path parameters:`,rank:0},header:{heading:`Request headers:`,rank:1},input:{heading:`Input:`,rank:2},body:{heading:`Body fields:`,rank:3},option:{heading:`Options:`,rank:1/0}};function i(e){return o(e).rank}function a(e){return o(e).heading}function o(e){return e.location===`path`?r.path:e.location===`header`?r.header:e.inputType===`file`||e.schemaFormat===`binary`?r.input:e.location===`body`?r.body:r.option}var s=e=>e===``||/[.!?]$/u.test(e)?e:`${e}.`,c={researchData:{heading:`Research data commands:`,rank:0},account:{heading:`Account commands:`,rank:1},administration:{heading:`Administration commands:`,rank:2},cli:{heading:`CLI commands:`,rank:3}};function l(e,t){return e!==void 0&&u(e,t)===`administration`}function u(e,t){return t?.[e]?.section??d[e]}var d={app:`account`,auth:`account`,entities:`researchData`,people:`researchData`,enrichments:`researchData`,news:`researchData`,search:`researchData`,directory:`researchData`,resolve:`researchData`,lookup:`researchData`,"lookup-jobs":`researchData`,"lookup-mentions":`researchData`,"research-runs":`researchData`,provenance:`administration`,billing:`account`,harness:`administration`,jobs:`administration`,operations:`administration`,metrics:`cli`,inference:`administration`,web:`researchData`,contacts:`administration`,"url-types":`researchData`,"unique-ids":`researchData`,research:`administration`,status:`cli`,agents:`cli`,help:`cli`},f=new Set([`metrics`]);export{n as a,a as c,u as i,s as l,f as n,t as o,l as r,i as s,c as t};
@@ -1,4 +1,4 @@
1
- import{a as e}from"./package-CZBWjlYb.js";import{t}from"./openapi-commands-v6H75r4H.js";import{n,r}from"./completion-setup-CwJt88xW.js";import{o as i}from"./generated-option-order-DH8yCg4h.js";import a from"node:process";function o(i,o=t,s=e().bin[0]){let l=i.command(`completion`).summary(`Generate shell completion scripts`).description(`Generate shell completion scripts for the aVenture CLI.`);for(let e of[`bash`,`fish`,`zsh`])l.command(e).summary(`Print ${e} shell completions`).description(`Print ${e} completion definitions for ${s}.`).action(()=>{a.stdout.write(c(i,e,o))});n(l,s),r(l,s)}function s(){return e().bin}function c(e,n,r=t,i=s()){let a=_(r);return n===`fish`?[`# fish completions for ${i.join(`, `)}`,...u(e),...i.map(e=>`complete -c ${N(e)} -e`),`${A(i)} -f`,...d(e,i),...f(e,a,i),``].join(`
1
+ import{a as e}from"./package-CZBWjlYb.js";import{t}from"./openapi-commands-CKb-tN3f.js";import{n,r}from"./completion-setup-CwJt88xW.js";import{o as i}from"./generated-option-order-CZUJFgSS.js";import a from"node:process";function o(i,o=t,s=e().bin[0]){let l=i.command(`completion`).summary(`Generate shell completion scripts`).description(`Generate shell completion scripts for the aVenture CLI.`);for(let e of[`bash`,`fish`,`zsh`])l.command(e).summary(`Print ${e} shell completions`).description(`Print ${e} completion definitions for ${s}.`).action(()=>{a.stdout.write(c(i,e,o))});n(l,s),r(l,s)}function s(){return e().bin}function c(e,n,r=t,i=s()){let a=_(r);return n===`fish`?[`# fish completions for ${i.join(`, `)}`,...u(e),...i.map(e=>`complete -c ${N(e)} -e`),`${A(i)} -f`,...d(e,i),...f(e,a,i),``].join(`
2
2
  `):l(e,n,a,i)}function l(e,t,n,r){let i=t===`zsh`?`typeset -ga `:``,a=`complete -F _aventure_cli ${r.map(e=>e.replaceAll(`'`,`'\\''`)).join(` `)}`,[o,s,c]=b(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}`),`)`,``,...C(t),...t===`bash`?[a,``]:[``]].join(`
3
3
  `)}function u(e){return[`function __aventure_cli_command_path\n set -l global_value_options ${p(e).filter(e=>e.required||e.optional).flatMap(e=>E(e)??[]).map(N).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
4
4
  set -l expected $argv
@@ -1 +1 @@
1
- import{n as e}from"./commander-DEj7N1b9.js";import{o as t}from"./tool-policy-TAT9-UP4.js";import{C as n,w as r}from"./operation-invocation-fkSqlOfs.js";import{a as i,o as a}from"./cli-help-policy-DdcHm_F7.js";function o(e){return e.toSorted((e,t)=>e.projection.cliPath.length-t.projection.cliPath.length||e.projection.cliPath.join(` `).localeCompare(t.projection.cliPath.join(` `))||e.operationId.localeCompare(t.operationId)).map(e=>{let t=e.parameter.flatMap(t=>{if(t.in!==`path`&&t.in!==`query`&&t.in!==`header`)return[];let n=t.in;return(t.in===`query`&&t.itemProperty!==void 0?t.itemProperty:[t]).map(t=>{let i=d(t,r(e,t),n);if(t.legacyName===void 0)return i;let a=d(t,r(e,t,t.legacyName),n).flag;return a===i.flag?i:Object.assign(i,{legacyFlag:a})})}),n=e.requestBody?.map(n=>{let r=l(e,t,n),i=c(n.cliConflicts,r),a=i.length===0?{}:{cliConflicts:i};return Object.assign({},n,{parameter:r},a)}),i=e.response.find(({status:e})=>e.startsWith(`2`)),a=i?.schemaName?.replace(/Schema$/,``);return{operationId:e.operationId,method:e.method,path:e.path,resource:e.resource,intent:e.intent,cliPath:e.projection.cliPath,summary:e.summary,description:e.description,binaryResponse:e.binaryResponse?!0:void 0,explain:e.explain?!0:void 0,deprecated:e.deprecated?!0:void 0,requestBody:n,mutationReadback:e.mutationReadback,scope:e.projection.scope,auth:e.projection.auth,visibility:e.projection.visibility,mutates:e.projection.mutates,errorResponse:e.errorResponse,successResponse:a,detailField:i?.detailField,parameters:t}})}function s(e,t){let[n,r]=e.filter(e=>e.role===t);if(n===void 0||r!==void 0)throw Error(`Generated composite CLI role '${t}' is incomplete`);return n}function c(e,t){let n=new Map(t.map(({name:e,optionKey:t})=>[e,t]));return(e??[]).map(e=>e.map(e=>{let t=n.get(e);if(t===void 0)throw Error(`x-aventure-cli-conflicts field '${e}' was removed from the generated CLI projection`);return t}))}function l(e,t,r){let i=new Set(t.map(e=>e.optionKey));(e.requestBody?.length??0)>1&&i.add(`contentType`);let a=new Set(t.filter(e=>e.location===`path`).map(e=>e.name));return r.parameter.toSorted((e,t)=>u(e.name)-u(t.name)).flatMap(t=>{if(!t.required&&(i.has(t.inputName)||a.has(t.name)))return[];let r=n(e,t,i);return i.add(r),[d(t,r,`body`)]})}function u(e){let t=e.split(`.`).at(-1);return t===`min`?0:t===`max`?1:2}function d(n,r,o){let s=n.itemSchemaEnum??n.schemaEnum,c=a(n.schemaType,n.itemSchemaType,n.schemaFormat,r),l=`${t(r)} ${n.schemaType===`boolean`?`[${c}]`:`<${c}>`}`;return{name:n.name,optionKey:new e(l).attributeName(),flag:l,required:n.required&&n.schemaDefault===void 0,description:i(n.description,s),schemaType:n.schemaType,schemaFormat:n.schemaFormat,itemSchemaType:n.itemSchemaType,defaultValue:f(n.schemaDefault),choices:s,...n.envName===void 0?{}:{envName:n.envName},...n.visibility&&{visibility:n.visibility},location:o}}var f=e=>Array.isArray(e)?e.map(String):typeof e==`number`?String(e):e;export{s as n,o as t};
1
+ import{n as e}from"./commander-DEj7N1b9.js";import{o as t}from"./tool-policy-BPefkvzQ.js";import{C as n,w as r}from"./operation-invocation-C29yUZSq.js";import{a as i,o as a}from"./cli-help-policy-CEyg0zEz.js";function o(e){return e.toSorted((e,t)=>e.projection.cliPath.length-t.projection.cliPath.length||e.projection.cliPath.join(` `).localeCompare(t.projection.cliPath.join(` `))||e.operationId.localeCompare(t.operationId)).map(e=>{let t=e.parameter.flatMap(t=>{if(t.in!==`path`&&t.in!==`query`&&t.in!==`header`)return[];let n=t.in;return(t.in===`query`&&t.itemProperty!==void 0?t.itemProperty:[t]).map(t=>{let i=d(t,r(e,t),n);if(t.legacyName===void 0)return i;let a=d(t,r(e,t,t.legacyName),n).flag;return a===i.flag?i:Object.assign(i,{legacyFlag:a})})}),n=e.requestBody?.map(n=>{let r=l(e,t,n),i=c(n.cliConflicts,r),a=i.length===0?{}:{cliConflicts:i};return Object.assign({},n,{parameter:r},a)}),i=e.response.find(({status:e})=>e.startsWith(`2`)),a=i?.schemaName?.replace(/Schema$/,``);return{operationId:e.operationId,method:e.method,path:e.path,resource:e.resource,intent:e.intent,cliPath:e.projection.cliPath,summary:e.summary,description:e.description,binaryResponse:e.binaryResponse?!0:void 0,explain:e.explain?!0:void 0,deprecated:e.deprecated?!0:void 0,requestBody:n,mutationReadback:e.mutationReadback,scope:e.projection.scope,auth:e.projection.auth,visibility:e.projection.visibility,mutates:e.projection.mutates,errorResponse:e.errorResponse,successResponse:a,detailField:i?.detailField,parameters:t}})}function s(e,t){let[n,r]=e.filter(e=>e.role===t);if(n===void 0||r!==void 0)throw Error(`Generated composite CLI role '${t}' is incomplete`);return n}function c(e,t){let n=new Map(t.map(({name:e,optionKey:t})=>[e,t]));return(e??[]).map(e=>e.map(e=>{let t=n.get(e);if(t===void 0)throw Error(`x-aventure-cli-conflicts field '${e}' was removed from the generated CLI projection`);return t}))}function l(e,t,r){let i=new Set(t.map(e=>e.optionKey));(e.requestBody?.length??0)>1&&i.add(`contentType`);let a=new Set(t.filter(e=>e.location===`path`).map(e=>e.name));return r.parameter.toSorted((e,t)=>u(e.name)-u(t.name)).flatMap(t=>{if(!t.required&&(i.has(t.inputName)||a.has(t.name)))return[];let r=n(e,t,i);return i.add(r),[d(t,r,`body`)]})}function u(e){let t=e.split(`.`).at(-1);return t===`min`?0:t===`max`?1:2}function d(n,r,o){let s=n.itemSchemaEnum??n.schemaEnum,c=a(n.schemaType,n.itemSchemaType,n.schemaFormat,r),l=`${t(r)} ${n.schemaType===`boolean`?`[${c}]`:`<${c}>`}`;return{name:n.name,optionKey:new e(l).attributeName(),flag:l,required:n.required&&n.schemaDefault===void 0,description:i(n.description,s),schemaType:n.schemaType,schemaFormat:n.schemaFormat,itemSchemaType:n.itemSchemaType,defaultValue:f(n.schemaDefault),choices:s,...n.envName===void 0?{}:{envName:n.envName},...n.visibility&&{visibility:n.visibility},location:o}}var f=e=>Array.isArray(e)?e.map(String):typeof e==`number`?String(e):e;export{s as n,o as t};
@@ -1 +1 @@
1
- import{c as e,r as t}from"./result-envelope-BKQSGfkH.js";import{t as n}from"./private-readback-DX42Bf2b.js";import{a as r,c as i,l as a,s as o}from"./cli-help-policy-DdcHm_F7.js";function s(n,r,i){let a={...i};for(let e of r.parameter){let r=e.envName;if(r===void 0)continue;let i=process.env[r]?.trim();if(i===void 0||i.length===0)continue;let o=a[e.optionKey];if(o!==void 0&&(typeof o!=`string`||o!==i))return{...t(`${n} ${e.flag.split(` `)[0]??e.name} conflicts with ${r}; omit the flag or use ${i}.`),data:a};o===void 0&&(a[e.optionKey]=i)}return e(`Environment-bound options applied`,a)}function c(e,t,n){if(!D(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||!S(n,r.name))continue;let a=x(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 l(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 u(t,n,r,i=!1){if(i||!T(n)||!Array.isArray(r))return O(t,n,r);for(let[e,i]of r.entries()){let r=O(t,n,i,e);if(!r.ok)return r}return e(`Body value assigned`,null)}function d(e,t,n,r){return O(e,t,r,n)}function f(e){let t=[];for(let n of e.split(`.`)){let e=A(n);if(t.push(e.key),e.isArray)return t.join(`.`)}return null}function p(e,t){let n=f(t);if(n===null)return null;let r=b(e,n.split(`.`));return Array.isArray(r)?{path:n,rowCount:r.length,firstHole:y(r)}:null}function m(n,r){if(T(n.name)||n.schemaType===`array`)return e(`Repeated body option selected`,typeof r==`string`?[r]:r);if(!Array.isArray(r))return e(`Scalar body option selected`,r);let i=n.flag.split(` `)[0]??n.name;return r.length===1?e(`Scalar body option selected`,r[0]):t(`${i} was already given; pass it once.`)}var h=/^(?<row>\d+):(?<item>.*)$/su;function g(e,t){let n=f(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=h.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 _(e,t,n){let r=0;for(let i of e.parameter){let e=t[i.optionKey];e!==void 0&&typeof e!=`boolean`&&f(i.name)===n&&(r=Math.max(r,typeof e==`string`?1:e.length))}return r}function v(e,n,r,i){for(let a of n.parameter){let n=r[a.optionKey];if(n===void 0)continue;let o=p(i,a.name);if(o===null)continue;if(o.firstHole!==null)return t(`${e} has no ${o.path}[] row ${o.firstHole} — number ${o.path}[] rows from 0 with no gaps.`);if(a.schemaType!==`array`||o.rowCount<=1||g(a,n)!==null)continue;let s=a.flag.split(` `)[0]??a.name;return t(`${s} fills one ${o.path}[] row's list, so ${e} cannot also build ${o.rowCount} ${o.path}[] rows from direct options — prefix each value with its 0-based ${o.path}[] row index, as 0:value, or pass the rows with --from-file.`)}return null}function y(e){for(let t=0;t<e.length;t+=1)if(e[t]===void 0)return t;return null}function b(e,t){let n=e;for(let e of t){if(!D(n))return;n=n[e]??null}return n}function x(e,t){if(!T(t))return b(e,t.split(`.`))}function S(e,t){return w(e,t.split(`.`))}function C(e,t,n){if(!D(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)&&S(n,e.name))return`${e.name} in --from-file requires --content-type ${i.contentType}.`}return null}function w(e,t){let[n,...r]=t;if(n===void 0)return!0;let i=A(n);if(!D(e)||!Object.hasOwn(e,i.key))return!1;let a=e[i.key]??null;return i.isArray?Array.isArray(a)&&a.every(e=>w(e,r)):w(a,r)}function T(e){return e.split(`.`).some(e=>A(e).isArray)}function E(e,t){return e.parameter.length===0||!D(t)?null:M(t,[],j(e.parameter))}function D(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function O(n,r,i,a=0){let o=r.split(`.`),s=n;for(let[n,c]of o.entries()){let l=A(c),u=n===o.length-1,d=k(s,l,r,u,i,a);if(!d.ok||d.data===null)return t(d.summary,d.warnings);if(u)return e(`Body value assigned`,null);s=d.data}return t(`${r} is not a valid body option path.`)}function k(n,r,i,a,o,s){let c=()=>t(`${i} cannot be combined with another body option at ${r.key}.`),l=n[r.key];if(r.isArray){if(l!==void 0&&!Array.isArray(l))return c();let t=l??[];if(l===void 0&&(n[r.key]=t),a)return t[s]===void 0?(t[s]=o,e(`Body value assigned`,n)):c();let i=t[s];if(i===void 0){let n={};return t[s]=n,e(`Body path created`,n)}return D(i)?e(`Body path stepped`,i):c()}if(a)return l===void 0?(n[r.key]=o,e(`Body value assigned`,n)):c();if(l===void 0){let t={};return n[r.key]=t,e(`Body path created`,t)}return D(l)?e(`Body path stepped`,l):c()}function A(e){let t=e.endsWith(`[]`);return{key:t?e.slice(0,-2):e,isArray:t}}function j(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 M(e,t,n){if(Array.isArray(e)){if(e.length===0)return null;for(let r of e){let e=M(r,t,n);if(e!==null)return e}return null}if(!D(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&&N(`${a}[]`,n))continue;if(!N(a,n)){if(!P(e))continue;let t=F(e,n);return{path:a,...t===void 0?{}:{suggestion:t}}}let o=M(i,e,n);if(o!==null)return o}return null}function N(e,t){return t.prefix.has(e)||t.leaf.has(e)}function P(e){return e.slice(0,-1).some(e=>e.endsWith(`[]`))}function F(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:I(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 I(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 L=e=>Array.isArray(e)&&!Object.isFrozen(e);function R(e,t){let r=new Map;for(let e of t){let t=e.flag?.split(` `)[0];t!==void 0&&r.set(t,t===`--from-file`?{...e,inputType:`file`}:e)}for(let t of e){let e=t.long===void 0?void 0:r.get(t.long);e!==void 0&&(t.helpGroup(i(e)),t.description=n(t.description,{...e,hasParseDefault:t.defaultValue!==void 0}))}if(!L(e))throw Error(`Commander option list is frozen; generated option help cannot be ordered.`);e.sort((e,t)=>{let n=e.long===void 0?void 0:r.get(e.long),i=t.long===void 0?void 0:r.get(t.long);return n!==void 0&&i!==void 0?K(n,i):n===void 0?i===void 0?0:1:-1})}function z(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 B(e){let{flag:t}=e.variant[0].parameter;return e.variant.every(({parameter:e})=>e.flag===t)?t:`${t.split(` `)[0]??t} <value>`}function V(e){let t=e.variant.map(({descriptor:e,parameter:t})=>({contentType:e.contentType,text:W(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 H(e,t){return[...new Set((e.cliConflicts??[]).filter(e=>e.includes(t)).flatMap(e=>e.filter(e=>e!==t)))]}function U(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?a(n):`${a(n)} Required JSON paths: ${r.join(`, `)}.`}function W(e,t){let n=r(t.description,void 0),i=e.kind!==`multipart`&&T(t.name),a=e.kind!==`multipart`&&t.optionKey!==t.name&&/^\w+$/u.test(t.name);return`${n}${i?` Repeat to add another value.`:``}${a?` --from-file JSON key: ${t.name}.`:``}${G(e,t)}`}function G(e,t){if(e.kind===`multipart`||t.schemaType!==`array`)return``;let n=f(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 K(e,t){return o(e)-o(t)||Number(e.required!==!0)-Number(t.required!==!0)}export{E as S,T as _,U as a,l as b,W as c,d,s as f,S as g,c as h,B as i,v as l,C as m,K as n,z as o,_ as p,V as r,H as s,R as t,u,D as v,m as x,g as y};
1
+ import{c as e,r as t}from"./result-envelope-5R2VEWAg.js";import{t as n}from"./private-readback-DX42Bf2b.js";import{a as r,c as i,l as a,s as o}from"./cli-help-policy-CEyg0zEz.js";function s(n,r,i){let a={...i};for(let e of r.parameter){let r=e.envName;if(r===void 0)continue;let i=process.env[r]?.trim();if(i===void 0||i.length===0)continue;let o=a[e.optionKey];if(o!==void 0&&(typeof o!=`string`||o!==i))return{...t(`${n} ${e.flag.split(` `)[0]??e.name} conflicts with ${r}; omit the flag or use ${i}.`),data:a};o===void 0&&(a[e.optionKey]=i)}return e(`Environment-bound options applied`,a)}function c(e,t,n){if(!D(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||!S(n,r.name))continue;let a=x(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 l(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 u(t,n,r,i=!1){if(i||!T(n)||!Array.isArray(r))return O(t,n,r);for(let[e,i]of r.entries()){let r=O(t,n,i,e);if(!r.ok)return r}return e(`Body value assigned`,null)}function d(e,t,n,r){return O(e,t,r,n)}function f(e){let t=[];for(let n of e.split(`.`)){let e=A(n);if(t.push(e.key),e.isArray)return t.join(`.`)}return null}function p(e,t){let n=f(t);if(n===null)return null;let r=b(e,n.split(`.`));return Array.isArray(r)?{path:n,rowCount:r.length,firstHole:y(r)}:null}function m(n,r){if(T(n.name)||n.schemaType===`array`)return e(`Repeated body option selected`,typeof r==`string`?[r]:r);if(!Array.isArray(r))return e(`Scalar body option selected`,r);let i=n.flag.split(` `)[0]??n.name;return r.length===1?e(`Scalar body option selected`,r[0]):t(`${i} was already given; pass it once.`)}var h=/^(?<row>\d+):(?<item>.*)$/su;function g(e,t){let n=f(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=h.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 _(e,t,n){let r=0;for(let i of e.parameter){let e=t[i.optionKey];e!==void 0&&typeof e!=`boolean`&&f(i.name)===n&&(r=Math.max(r,typeof e==`string`?1:e.length))}return r}function v(e,n,r,i){for(let a of n.parameter){let n=r[a.optionKey];if(n===void 0)continue;let o=p(i,a.name);if(o===null)continue;if(o.firstHole!==null)return t(`${e} has no ${o.path}[] row ${o.firstHole} — number ${o.path}[] rows from 0 with no gaps.`);if(a.schemaType!==`array`||o.rowCount<=1||g(a,n)!==null)continue;let s=a.flag.split(` `)[0]??a.name;return t(`${s} fills one ${o.path}[] row's list, so ${e} cannot also build ${o.rowCount} ${o.path}[] rows from direct options — prefix each value with its 0-based ${o.path}[] row index, as 0:value, or pass the rows with --from-file.`)}return null}function y(e){for(let t=0;t<e.length;t+=1)if(e[t]===void 0)return t;return null}function b(e,t){let n=e;for(let e of t){if(!D(n))return;n=n[e]??null}return n}function x(e,t){if(!T(t))return b(e,t.split(`.`))}function S(e,t){return w(e,t.split(`.`))}function C(e,t,n){if(!D(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)&&S(n,e.name))return`${e.name} in --from-file requires --content-type ${i.contentType}.`}return null}function w(e,t){let[n,...r]=t;if(n===void 0)return!0;let i=A(n);if(!D(e)||!Object.hasOwn(e,i.key))return!1;let a=e[i.key]??null;return i.isArray?Array.isArray(a)&&a.every(e=>w(e,r)):w(a,r)}function T(e){return e.split(`.`).some(e=>A(e).isArray)}function E(e,t){return e.parameter.length===0||!D(t)?null:M(t,[],j(e.parameter))}function D(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function O(n,r,i,a=0){let o=r.split(`.`),s=n;for(let[n,c]of o.entries()){let l=A(c),u=n===o.length-1,d=k(s,l,r,u,i,a);if(!d.ok||d.data===null)return t(d.summary,d.warnings);if(u)return e(`Body value assigned`,null);s=d.data}return t(`${r} is not a valid body option path.`)}function k(n,r,i,a,o,s){let c=()=>t(`${i} cannot be combined with another body option at ${r.key}.`),l=n[r.key];if(r.isArray){if(l!==void 0&&!Array.isArray(l))return c();let t=l??[];if(l===void 0&&(n[r.key]=t),a)return t[s]===void 0?(t[s]=o,e(`Body value assigned`,n)):c();let i=t[s];if(i===void 0){let n={};return t[s]=n,e(`Body path created`,n)}return D(i)?e(`Body path stepped`,i):c()}if(a)return l===void 0?(n[r.key]=o,e(`Body value assigned`,n)):c();if(l===void 0){let t={};return n[r.key]=t,e(`Body path created`,t)}return D(l)?e(`Body path stepped`,l):c()}function A(e){let t=e.endsWith(`[]`);return{key:t?e.slice(0,-2):e,isArray:t}}function j(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 M(e,t,n){if(Array.isArray(e)){if(e.length===0)return null;for(let r of e){let e=M(r,t,n);if(e!==null)return e}return null}if(!D(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&&N(`${a}[]`,n))continue;if(!N(a,n)){if(!P(e))continue;let t=F(e,n);return{path:a,...t===void 0?{}:{suggestion:t}}}let o=M(i,e,n);if(o!==null)return o}return null}function N(e,t){return t.prefix.has(e)||t.leaf.has(e)}function P(e){return e.slice(0,-1).some(e=>e.endsWith(`[]`))}function F(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:I(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 I(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 L=e=>Array.isArray(e)&&!Object.isFrozen(e);function R(e,t){let r=new Map;for(let e of t){let t=e.flag?.split(` `)[0];t!==void 0&&r.set(t,t===`--from-file`?{...e,inputType:`file`}:e)}for(let t of e){let e=t.long===void 0?void 0:r.get(t.long);e!==void 0&&(t.helpGroup(i(e)),t.description=n(t.description,{...e,hasParseDefault:t.defaultValue!==void 0}))}if(!L(e))throw Error(`Commander option list is frozen; generated option help cannot be ordered.`);e.sort((e,t)=>{let n=e.long===void 0?void 0:r.get(e.long),i=t.long===void 0?void 0:r.get(t.long);return n!==void 0&&i!==void 0?K(n,i):n===void 0?i===void 0?0:1:-1})}function z(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 B(e){let{flag:t}=e.variant[0].parameter;return e.variant.every(({parameter:e})=>e.flag===t)?t:`${t.split(` `)[0]??t} <value>`}function V(e){let t=e.variant.map(({descriptor:e,parameter:t})=>({contentType:e.contentType,text:W(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 H(e,t){return[...new Set((e.cliConflicts??[]).filter(e=>e.includes(t)).flatMap(e=>e.filter(e=>e!==t)))]}function U(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?a(n):`${a(n)} Required JSON paths: ${r.join(`, `)}.`}function W(e,t){let n=r(t.description,void 0),i=e.kind!==`multipart`&&T(t.name),a=e.kind!==`multipart`&&t.optionKey!==t.name&&/^\w+$/u.test(t.name);return`${n}${i?` Repeat to add another value.`:``}${a?` --from-file JSON key: ${t.name}.`:``}${G(e,t)}`}function G(e,t){if(e.kind===`multipart`||t.schemaType!==`array`)return``;let n=f(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 K(e,t){return o(e)-o(t)||Number(e.required!==!0)-Number(t.required!==!0)}export{E as S,T as _,U as a,l as b,W as c,d,s as f,S as g,c as h,B as i,v as l,C as m,K as n,z as o,_ as p,V as r,H as s,R as t,u,D as v,m as x,g as y};
@@ -1 +1 @@
1
- import{c as e,m as t,n,w as r}from"./tool-policy-TAT9-UP4.js";import{c as i,i as a,r as o}from"./result-envelope-BKQSGfkH.js";import{t as s}from"./openapi-snapshot-DD4lwuez.js";import{E as c,S as l,_ as u,b as d,c as f,d as p,f as m,g as h,h as g,l as _,m as v,p as y,u as b,x,y as S}from"./operation-invocation-fkSqlOfs.js";var C=/\b(?:https?:\/\/)?(?:[a-z0-9-]+\.)+[a-z]{2,}(?::\d+)?(?:\/\S*)?/giu,ee=/\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/giu,w=/^[a-z0-9]+(?:-[a-z0-9]+)+$/u,T=250,E=40,D=100;function O(e,t){let n=new Set,r=[],i=/\bslugs?\b/iu.test(e);return{text:e.replace(ee,()=>(n.add(`uuid`),` `)).replace(C,e=>{n.add(`url`);let t=e.replace(/^(?:https?:\/\/)?[^/]+/iu,``).replace(/[?#].*$/su,``).split(`/`).filter(e=>e.length>0).map(e=>e.toLowerCase()),i=t.at(-1);return i!==void 0&&w.test(i)&&(n.add(`slug`),t.pop()),r.push(...t.flatMap(e=>e.split(/[^a-z0-9]+/u))),` `}).split(/\s+/u).filter(e=>{let r=e.replace(/^[^a-z0-9]+|[^a-z0-9]+$/giu,``).toLowerCase(),a=w.test(r)&&!t.has(r)&&(i||/\d/u.test(r));return a&&n.add(`slug`),!a}).join(` `).trim(),kind:n,urlPathWord:r.filter(e=>e.length>0)}}function k(e,t,n){return e===`uuid`?/(?:^id|Id)$/u.test(t)&&n.includes(`{${t}}`):t===e}function A(e,t){let n=new Set;for(let r of e){let e=new Set;f(e,r);let i=t.filter(({cliPath:t})=>e.has(t[0]??``)),a=i.length>0?i:t.filter(({cliPath:t})=>t.some(t=>e.has(t)));for(let{resource:e}of a)n.add(e)}return n}function j(e,t,n){if(n.intent!==`read`&&n.intent!==`lookup`)return 0;let r=new Set(p(n.summary)),i=0;for(let t of e.kind)n.directParameterName.some(e=>k(t,e,n.path))&&(i+=T,r.has(t)&&(i+=E));if(i===0)return 0;let a=new Set(p(`${n.summary} ${n.description}`));return(t.size>0?t.has(n.resource):e.urlPathWord.some(e=>{let t=new Set;return f(t,e),[...t].some(e=>a.has(e))}))&&(i+=D),i}var M=40,N=4,P=3,F=1,I=new Map;function L(e){let n=I.get(e);if(n!==void 0)return n;let i=s(),a=r(i.paths,e),o=a===null?new Map:t(i,a.operation.responses,P);return I.set(e,o),o}function R(e,t,n){let r=0,i=new Map;for(let[e,a]of n){if(t.has(e.toLowerCase())&&(r+=M*(4-a)/4),a>F)continue;let n=new Set;for(let t of p(e))f(n,t);for(let e of n)i.set(e,Math.min(i.get(e)??a,a))}for(let t of e){let e=Math.min(...[...t].map(e=>i.get(e)??1/0));e<=F&&(r+=N*(2-e))}return r}var z=5,B=.5,V=15,H=30,U=2,W=100,G=.5;function K(e,t,n){let r=t.map(e=>({item:e,fields:n(e)})),i=O(e,new Set(r.flatMap(({fields:e})=>e.cliPath))),a=A(i.urlPathWord,r.map(({fields:e})=>e)),o=m(i.text);if(o.length===0&&i.kind.size===0)return t.map(e=>({item:e,score:1}));let s=b(o),c=y(o),l=new Set(i.text.toLowerCase().split(/[^a-z0-9]+/u));return r.map(({item:e,fields:t})=>({item:e,fields:t,score:(o.length===0?0:X({normalizedQuery:o,tokens:s,termForm:c,queryWord:l},t))+j(i,a,t)})).filter(({score:e})=>e>0).toSorted((e,t)=>Number(e.fields.deprecated===!0)-Number(t.fields.deprecated===!0)||t.score-e.score||e.fields.cliPath.length-t.fields.cliPath.length||e.fields.cliPath.join(` `).localeCompare(t.fields.cliPath.join(` `))||e.fields.operationId.localeCompare(t.fields.operationId)).map(({item:e,score:t})=>({item:e,score:t}))}function q(e){let t=e.requestBody??[],n=[...e.parameter,...t.flatMap(e=>e.parameter)];return{...e,cliPath:e.projection.cliPath,enumParameter:n.map(e=>({values:e.itemSchemaEnum??e.schemaEnum??[],direct:e.name===e.inputName})),parameterName:n.flatMap(e=>[e.name,e.inputName]),directParameterName:e.parameter.map(e=>e.name),parameterDescription:[...n,...t].map(({description:e})=>e),responseFieldLevel:L(e.operationId)}}function J(e,t){let n=e.q?.trim()??``,r=K(n,t.filter(t=>Y(e,t)&&(n.length>0||t.deprecated!==!0)),q),o=(r[0]?.score??0)*B,s=r.filter(({score:e})=>e>=o),c=e.limit===void 0||!Number.isFinite(e.limit)?z:e.limit,u=Math.min(s.length,Math.max(0,Math.trunc(c))),f=s.slice(0,u).map(({item:e})=>e),p={totalOperations:t.length,matched:s.length,returned:f.length},m=f.length===1,h=f.map(e=>d(e,m)),g=i(v,h,{counts:p}),_=a(g),y=m?f.map(l):f.map(x);return{summary:v,data:_?h:y,counts:p}}function Y(e,t){let{root:n}=e;return!(e.method!==void 0&&t.method!==e.method||e.scope!==void 0&&t.projection.scope!==e.scope||n&&t.resource!==n&&t.projection.cliPath[0]!==n)}function X({normalizedQuery:t,tokens:n,termForm:r,queryWord:i},a){let o=re(a),s=te(a),c=0;o.some(e=>e===t)&&(c+=100),o.some(e=>e.includes(t))&&(c+=40),c+=ne(t,o);let l=new Set(o.flatMap(p)),u=new Set(s.flatMap(p));for(let e of n)o.some(t=>t===e)?c+=20:u.has(e)?c+=8:l.has(e)&&(c+=U);for(let e of a.cliPath){let t=new Set;f(t,e),[...t].some(e=>n.has(e))&&(c+=V)}_(r,s)&&(c+=200),r.length>1&&s.some(e=>e.includes(t))&&(c+=W),a.parameterName.some(e=>m(e)===t)&&(c+=H);let d=new Set(a.parameterDescription.flatMap(p));for(let e of n)d.has(e)&&(c+=U);return c+=ae(n,a.enumParameter),[`list`,`search`,`find`,`browse`].some(e=>n.has(e))&&/^(?:list|search)[A-Z]/u.test(a.operationId)&&(c+=30),c+=R(r,i,a.responseFieldLevel),c-=ie(t,n,a.description),e(a.intent)&&!$(i)?c*G:c}var Z=`edit change set fix rename link unlink mark publish correct`.split(` `),Q=new Set([...Object.entries(n).filter(([,t])=>e(t)).map(([e])=>e),...Z]);function $(e){return[...e].some(e=>Q.has(e))}function te(e){return[e.operationId,e.cliPath.join(` `),e.summary].map(m).filter(e=>e.length>0)}function ne(e,t){let n=p(e),r=0;for(let e=0;e<n.length-1;e+=1){let i=n.slice(e,e+2).join(` `);t.some(e=>e.includes(i))&&(r+=24)}return r}function re(e){return[...new Set([e.operationId,e.method,e.path,e.resource,e.intent,e.cliPath.join(` `),e.summary,(g(e.description).useFor||e.description).slice(0,240)].map(m).filter(e=>e.length>0))]}function ie(e,t,n){let r=m(g(n).notFor);if(r.length===0)return 0;let i=r.includes(e)?40:0,a=new Set(p(r));for(let e of t)r===e?i+=20:a.has(e)&&(i+=8);return i}function ae(e,t){let n=0;for(let{values:r,direct:i}of t)r.some(t=>oe(e,t))&&(n+=i?40:10);return n}function oe(e,t){let n=p(t);return n.length>0&&n.every(t=>e.has(t))}function se(e){return typeof e.data==`object`&&e.data!==null&&`response`in e.data?e.data.response:void 0}async function ce(e,t,n,r){let a=e.q?.trim()??``;if(a.length===0)return o(`Provide q to resolve a request to one operation.`);let s=n.find(({resource:e,intent:t,deprecated:n})=>e===`help`&&t===`search`&&n!==!0);if(s===void 0)return o(`This build ships no help resolve operation.`);let l=await r(s,{body:{question:a,resolve:!0,...e.scope===void 0?{}:{scope:e.scope===`read`?`READ`:`WRITE`}}});if(!l.ok)return{...l,data:null};let d=c.safeParse(se(l));if(!d.success||d.data.resolution==null)return o(`The help resolve operation returned no resolution.`);let{answer:f,resolution:p}=d.data,m=e=>t.find(t=>t.operationId===e),g=m(p.operationId),_=p.taskPlan??void 0,v=(_?.step??[]).map(({step:e})=>({step:e,contract:m(e.operationId)})),y=[...new Set([...p.operationId!=null&&g===void 0?[p.operationId]:[],...v.filter(({contract:e})=>e===void 0).map(({step:e})=>e.operationId)])];return y.some(e=>!n.some(t=>t.operationId===e))?o(`No operation on this connection answers that request.`):i(y.length===0?`Help resolution`:`Help resolution this connection cannot finish: it cannot run ${y.join(`, `)}.`,{outcome:p.outcome,probability:p.probability,answer:f,candidate:p.candidate.filter(({sourceId:e})=>n.some(({operationId:t})=>t===e)).map(({sourceId:e})=>{let t=m(e);return t===void 0?{sourceId:e}:Object.assign({sourceId:e},u(t))}),...g===void 0?{}:{operation:{operationId:g.operationId,apiRoute:`${g.method} ${g.path}`,...h(g),...u(g)}},...(p.taskKey,{}),..._===void 0?{}:{taskPlan:{input:_.input,step:v.map(({contract:e,step:{stepKey:t,instruction:n,operationId:r}})=>e===void 0?{instruction:n,operationId:r}:{instruction:n,mcpCall:S(e)})}}},{warnings:y.map(e=>n.some(t=>t.operationId===e)?`Operation ${e} is in this server's catalog, but your grant does not allow it.`:`Operation ${e} is outside this server's catalog, so no credential runs it here.`)})}export{L as a,ce as i,K as n,J as r,q as t};
1
+ import{c as e,m as t,n,w as r}from"./tool-policy-BPefkvzQ.js";import{c as i,i as a,r as o}from"./result-envelope-5R2VEWAg.js";import{t as s}from"./openapi-snapshot-C2TJ4vNL.js";import{E as c,S as l,_ as u,b as d,c as f,d as p,f as m,g as h,h as g,l as _,m as v,p as y,u as b,x,y as S}from"./operation-invocation-C29yUZSq.js";var C=/\b(?:https?:\/\/)?(?:[a-z0-9-]+\.)+[a-z]{2,}(?::\d+)?(?:\/\S*)?/giu,ee=/\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/giu,w=/^[a-z0-9]+(?:-[a-z0-9]+)+$/u,T=250,E=40,D=100;function O(e,t){let n=new Set,r=[],i=/\bslugs?\b/iu.test(e);return{text:e.replace(ee,()=>(n.add(`uuid`),` `)).replace(C,e=>{n.add(`url`);let t=e.replace(/^(?:https?:\/\/)?[^/]+/iu,``).replace(/[?#].*$/su,``).split(`/`).filter(e=>e.length>0).map(e=>e.toLowerCase()),i=t.at(-1);return i!==void 0&&w.test(i)&&(n.add(`slug`),t.pop()),r.push(...t.flatMap(e=>e.split(/[^a-z0-9]+/u))),` `}).split(/\s+/u).filter(e=>{let r=e.replace(/^[^a-z0-9]+|[^a-z0-9]+$/giu,``).toLowerCase(),a=w.test(r)&&!t.has(r)&&(i||/\d/u.test(r));return a&&n.add(`slug`),!a}).join(` `).trim(),kind:n,urlPathWord:r.filter(e=>e.length>0)}}function k(e,t,n){return e===`uuid`?/(?:^id|Id)$/u.test(t)&&n.includes(`{${t}}`):t===e}function A(e,t){let n=new Set;for(let r of e){let e=new Set;f(e,r);let i=t.filter(({cliPath:t})=>e.has(t[0]??``)),a=i.length>0?i:t.filter(({cliPath:t})=>t.some(t=>e.has(t)));for(let{resource:e}of a)n.add(e)}return n}function j(e,t,n){if(n.intent!==`read`&&n.intent!==`lookup`)return 0;let r=new Set(p(n.summary)),i=0;for(let t of e.kind)n.directParameterName.some(e=>k(t,e,n.path))&&(i+=T,r.has(t)&&(i+=E));if(i===0)return 0;let a=new Set(p(`${n.summary} ${n.description}`));return(t.size>0?t.has(n.resource):e.urlPathWord.some(e=>{let t=new Set;return f(t,e),[...t].some(e=>a.has(e))}))&&(i+=D),i}var M=40,N=4,P=3,F=1,I=new Map;function L(e){let n=I.get(e);if(n!==void 0)return n;let i=s(),a=r(i.paths,e),o=a===null?new Map:t(i,a.operation.responses,P);return I.set(e,o),o}function R(e,t,n){let r=0,i=new Map;for(let[e,a]of n){if(t.has(e.toLowerCase())&&(r+=M*(4-a)/4),a>F)continue;let n=new Set;for(let t of p(e))f(n,t);for(let e of n)i.set(e,Math.min(i.get(e)??a,a))}for(let t of e){let e=Math.min(...[...t].map(e=>i.get(e)??1/0));e<=F&&(r+=N*(2-e))}return r}var z=5,B=.5,V=15,H=30,U=2,W=100,G=.5;function K(e,t,n){let r=t.map(e=>({item:e,fields:n(e)})),i=O(e,new Set(r.flatMap(({fields:e})=>e.cliPath))),a=A(i.urlPathWord,r.map(({fields:e})=>e)),o=m(i.text);if(o.length===0&&i.kind.size===0)return t.map(e=>({item:e,score:1}));let s=b(o),c=y(o),l=new Set(i.text.toLowerCase().split(/[^a-z0-9]+/u));return r.map(({item:e,fields:t})=>({item:e,fields:t,score:(o.length===0?0:X({normalizedQuery:o,tokens:s,termForm:c,queryWord:l},t))+j(i,a,t)})).filter(({score:e})=>e>0).toSorted((e,t)=>Number(e.fields.deprecated===!0)-Number(t.fields.deprecated===!0)||t.score-e.score||e.fields.cliPath.length-t.fields.cliPath.length||e.fields.cliPath.join(` `).localeCompare(t.fields.cliPath.join(` `))||e.fields.operationId.localeCompare(t.fields.operationId)).map(({item:e,score:t})=>({item:e,score:t}))}function q(e){let t=e.requestBody??[],n=[...e.parameter,...t.flatMap(e=>e.parameter)];return{...e,cliPath:e.projection.cliPath,enumParameter:n.map(e=>({values:e.itemSchemaEnum??e.schemaEnum??[],direct:e.name===e.inputName})),parameterName:n.flatMap(e=>[e.name,e.inputName]),directParameterName:e.parameter.map(e=>e.name),parameterDescription:[...n,...t].map(({description:e})=>e),responseFieldLevel:L(e.operationId)}}function J(e,t){let n=e.q?.trim()??``,r=K(n,t.filter(t=>Y(e,t)&&(n.length>0||t.deprecated!==!0)),q),o=(r[0]?.score??0)*B,s=r.filter(({score:e})=>e>=o),c=e.limit===void 0||!Number.isFinite(e.limit)?z:e.limit,u=Math.min(s.length,Math.max(0,Math.trunc(c))),f=s.slice(0,u).map(({item:e})=>e),p={totalOperations:t.length,matched:s.length,returned:f.length},m=f.length===1,h=f.map(e=>d(e,m)),g=i(v,h,{counts:p}),_=a(g),y=m?f.map(l):f.map(x);return{summary:v,data:_?h:y,counts:p}}function Y(e,t){let{root:n}=e;return!(e.method!==void 0&&t.method!==e.method||e.scope!==void 0&&t.projection.scope!==e.scope||n&&t.resource!==n&&t.projection.cliPath[0]!==n)}function X({normalizedQuery:t,tokens:n,termForm:r,queryWord:i},a){let o=re(a),s=te(a),c=0;o.some(e=>e===t)&&(c+=100),o.some(e=>e.includes(t))&&(c+=40),c+=ne(t,o);let l=new Set(o.flatMap(p)),u=new Set(s.flatMap(p));for(let e of n)o.some(t=>t===e)?c+=20:u.has(e)?c+=8:l.has(e)&&(c+=U);for(let e of a.cliPath){let t=new Set;f(t,e),[...t].some(e=>n.has(e))&&(c+=V)}_(r,s)&&(c+=200),r.length>1&&s.some(e=>e.includes(t))&&(c+=W),a.parameterName.some(e=>m(e)===t)&&(c+=H);let d=new Set(a.parameterDescription.flatMap(p));for(let e of n)d.has(e)&&(c+=U);return c+=ae(n,a.enumParameter),[`list`,`search`,`find`,`browse`].some(e=>n.has(e))&&/^(?:list|search)[A-Z]/u.test(a.operationId)&&(c+=30),c+=R(r,i,a.responseFieldLevel),c-=ie(t,n,a.description),e(a.intent)&&!$(i)?c*G:c}var Z=`edit change set fix rename link unlink mark publish correct`.split(` `),Q=new Set([...Object.entries(n).filter(([,t])=>e(t)).map(([e])=>e),...Z]);function $(e){return[...e].some(e=>Q.has(e))}function te(e){return[e.operationId,e.cliPath.join(` `),e.summary].map(m).filter(e=>e.length>0)}function ne(e,t){let n=p(e),r=0;for(let e=0;e<n.length-1;e+=1){let i=n.slice(e,e+2).join(` `);t.some(e=>e.includes(i))&&(r+=24)}return r}function re(e){return[...new Set([e.operationId,e.method,e.path,e.resource,e.intent,e.cliPath.join(` `),e.summary,(g(e.description).useFor||e.description).slice(0,240)].map(m).filter(e=>e.length>0))]}function ie(e,t,n){let r=m(g(n).notFor);if(r.length===0)return 0;let i=r.includes(e)?40:0,a=new Set(p(r));for(let e of t)r===e?i+=20:a.has(e)&&(i+=8);return i}function ae(e,t){let n=0;for(let{values:r,direct:i}of t)r.some(t=>oe(e,t))&&(n+=i?40:10);return n}function oe(e,t){let n=p(t);return n.length>0&&n.every(t=>e.has(t))}function se(e){return typeof e.data==`object`&&e.data!==null&&`response`in e.data?e.data.response:void 0}async function ce(e,t,n,r){let a=e.q?.trim()??``;if(a.length===0)return o(`Provide q to resolve a request to one operation.`);let s=n.find(({resource:e,intent:t,deprecated:n})=>e===`help`&&t===`search`&&n!==!0);if(s===void 0)return o(`This build ships no help resolve operation.`);let l=await r(s,{body:{question:a,resolve:!0,...e.scope===void 0?{}:{scope:e.scope===`read`?`READ`:`WRITE`}}});if(!l.ok)return{...l,data:null};let d=c.safeParse(se(l));if(!d.success||d.data.resolution==null)return o(`The help resolve operation returned no resolution.`);let{answer:f,resolution:p}=d.data,m=e=>t.find(t=>t.operationId===e),g=m(p.operationId),_=p.taskPlan??void 0,v=(_?.step??[]).map(({step:e})=>({step:e,contract:m(e.operationId)})),y=[...new Set([...p.operationId!=null&&g===void 0?[p.operationId]:[],...v.filter(({contract:e})=>e===void 0).map(({step:e})=>e.operationId)])];return y.some(e=>!n.some(t=>t.operationId===e))?o(`No operation on this connection answers that request.`):i(y.length===0?`Help resolution`:`Help resolution this connection cannot finish: it cannot run ${y.join(`, `)}.`,{outcome:p.outcome,probability:p.probability,answer:f,candidate:p.candidate.filter(({sourceId:e})=>n.some(({operationId:t})=>t===e)).map(({sourceId:e})=>{let t=m(e);return t===void 0?{sourceId:e}:Object.assign({sourceId:e},u(t))}),...g===void 0?{}:{operation:{operationId:g.operationId,apiRoute:`${g.method} ${g.path}`,...h(g),...u(g)}},...(p.taskKey,{}),..._===void 0?{}:{taskPlan:{input:_.input,step:v.map(({contract:e,step:{stepKey:t,instruction:n,operationId:r}})=>e===void 0?{instruction:n,operationId:r}:{instruction:n,mcpCall:S(e)})}}},{warnings:y.map(e=>n.some(t=>t.operationId===e)?`Operation ${e} is in this server's catalog, but your grant does not allow it.`:`Operation ${e} is outside this server's catalog, so no credential runs it here.`)})}export{L as a,ce as i,K as n,J as r,q as t};