kuriko 0.0.0-stage → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/kuriko.mjs ADDED
@@ -0,0 +1,408 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as __kurikoRequire } from "node:module"; const require = __kurikoRequire(import.meta.url);
3
+ var Cu=Object.create;var mo=Object.defineProperty;var _u=Object.getOwnPropertyDescriptor;var Iu=Object.getOwnPropertyNames;var Tu=Object.getPrototypeOf,Ou=Object.prototype.hasOwnProperty;var vn=(n=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(n,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):n)(function(n){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+n+'" is not supported')});var Pu=(n,e,t)=>()=>{if(t)throw t[0];try{return n&&(e=n(n=0)),e}catch(s){throw t=[s],s}};var S=(n,e)=>()=>{try{return e||n((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}};var ju=(n,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Iu(e))!Ou.call(n,r)&&r!==t&&mo(n,r,{get:()=>e[r],enumerable:!(s=_u(e,r))||s.enumerable});return n};var Lu=(n,e,t)=>(t=n!=null?Cu(Tu(n)):{},ju(e||!n||!n.__esModule?mo(t,"default",{value:n,enumerable:!0}):t,n));var k,p=Pu(()=>{k={version:"0.2.1"}});var R=S(J=>{"use strict";p();var cr=Symbol.for("yaml.alias"),No=Symbol.for("yaml.document"),Cn=Symbol.for("yaml.map"),Co=Symbol.for("yaml.pair"),lr=Symbol.for("yaml.scalar"),_n=Symbol.for("yaml.seq"),ye=Symbol.for("yaml.node.type"),Wu=n=>!!n&&typeof n=="object"&&n[ye]===cr,zu=n=>!!n&&typeof n=="object"&&n[ye]===No,Hu=n=>!!n&&typeof n=="object"&&n[ye]===Cn,Qu=n=>!!n&&typeof n=="object"&&n[ye]===Co,_o=n=>!!n&&typeof n=="object"&&n[ye]===lr,Xu=n=>!!n&&typeof n=="object"&&n[ye]===_n;function Io(n){if(n&&typeof n=="object")switch(n[ye]){case Cn:case _n:return!0}return!1}function Zu(n){if(n&&typeof n=="object")switch(n[ye]){case cr:case Cn:case lr:case _n:return!0}return!1}var ef=n=>(_o(n)||Io(n))&&!!n.anchor;J.ALIAS=cr;J.DOC=No;J.MAP=Cn;J.NODE_TYPE=ye;J.PAIR=Co;J.SCALAR=lr;J.SEQ=_n;J.hasAnchor=ef;J.isAlias=Wu;J.isCollection=Io;J.isDocument=zu;J.isMap=Hu;J.isNode=Zu;J.isPair=Qu;J.isScalar=_o;J.isSeq=Xu});var jt=S(ur=>{"use strict";p();var V=R(),Z=Symbol("break visit"),To=Symbol("skip children"),ue=Symbol("remove node");function In(n,e){let t=Oo(e);V.isDocument(n)?it(null,n.contents,t,Object.freeze([n]))===ue&&(n.contents=null):it(null,n,t,Object.freeze([]))}In.BREAK=Z;In.SKIP=To;In.REMOVE=ue;function it(n,e,t,s){let r=Po(n,e,t,s);if(V.isNode(r)||V.isPair(r))return jo(n,s,r),it(n,r,t,s);if(typeof r!="symbol"){if(V.isCollection(e)){s=Object.freeze(s.concat(e));for(let i=0;i<e.items.length;++i){let o=it(i,e.items[i],t,s);if(typeof o=="number")i=o-1;else{if(o===Z)return Z;o===ue&&(e.items.splice(i,1),i-=1)}}}else if(V.isPair(e)){s=Object.freeze(s.concat(e));let i=it("key",e.key,t,s);if(i===Z)return Z;i===ue&&(e.key=null);let o=it("value",e.value,t,s);if(o===Z)return Z;o===ue&&(e.value=null)}}return r}async function Tn(n,e){let t=Oo(e);V.isDocument(n)?await ot(null,n.contents,t,Object.freeze([n]))===ue&&(n.contents=null):await ot(null,n,t,Object.freeze([]))}Tn.BREAK=Z;Tn.SKIP=To;Tn.REMOVE=ue;async function ot(n,e,t,s){let r=await Po(n,e,t,s);if(V.isNode(r)||V.isPair(r))return jo(n,s,r),ot(n,r,t,s);if(typeof r!="symbol"){if(V.isCollection(e)){s=Object.freeze(s.concat(e));for(let i=0;i<e.items.length;++i){let o=await ot(i,e.items[i],t,s);if(typeof o=="number")i=o-1;else{if(o===Z)return Z;o===ue&&(e.items.splice(i,1),i-=1)}}}else if(V.isPair(e)){s=Object.freeze(s.concat(e));let i=await ot("key",e.key,t,s);if(i===Z)return Z;i===ue&&(e.key=null);let o=await ot("value",e.value,t,s);if(o===Z)return Z;o===ue&&(e.value=null)}}return r}function Oo(n){return typeof n=="object"&&(n.Collection||n.Node||n.Value)?Object.assign({Alias:n.Node,Map:n.Node,Scalar:n.Node,Seq:n.Node},n.Value&&{Map:n.Value,Scalar:n.Value,Seq:n.Value},n.Collection&&{Map:n.Collection,Seq:n.Collection},n):n}function Po(n,e,t,s){if(typeof t=="function")return t(n,e,s);if(V.isMap(e))return t.Map?.(n,e,s);if(V.isSeq(e))return t.Seq?.(n,e,s);if(V.isPair(e))return t.Pair?.(n,e,s);if(V.isScalar(e))return t.Scalar?.(n,e,s);if(V.isAlias(e))return t.Alias?.(n,e,s)}function jo(n,e,t){let s=e[e.length-1];if(V.isCollection(s))s.items[n]=t;else if(V.isPair(s))n==="key"?s.key=t:s.value=t;else if(V.isDocument(s))s.contents=t;else{let r=V.isAlias(s)?"alias":"scalar";throw new Error(`Cannot replace node with ${r} parent`)}}ur.visit=In;ur.visitAsync=Tn});var fr=S(qo=>{"use strict";p();var Lo=R(),tf=jt(),nf={"!":"%21",",":"%2C","[":"%5B","]":"%5D","{":"%7B","}":"%7D"},sf=n=>n.replace(/[!,[\]{}]/g,e=>nf[e]),Lt=class n{constructor(e,t){this.docStart=null,this.docEnd=!1,this.yaml=Object.assign({},n.defaultYaml,e),this.tags=Object.assign({},n.defaultTags,t)}clone(){let e=new n(this.yaml,this.tags);return e.docStart=this.docStart,e}atDocument(){let e=new n(this.yaml,this.tags);switch(this.yaml.version){case"1.1":this.atNextDocument=!0;break;case"1.2":this.atNextDocument=!1,this.yaml={explicit:n.defaultYaml.explicit,version:"1.2"},this.tags=Object.assign({},n.defaultTags);break}return e}add(e,t){this.atNextDocument&&(this.yaml={explicit:n.defaultYaml.explicit,version:"1.1"},this.tags=Object.assign({},n.defaultTags),this.atNextDocument=!1);let s=e.trim().split(/[ \t]+/),r=s.shift();switch(r){case"%TAG":{if(s.length!==2&&(t(0,"%TAG directive should contain exactly two parts"),s.length<2))return!1;let[i,o]=s;return this.tags[i]=o,!0}case"%YAML":{if(this.yaml.explicit=!0,s.length!==1)return t(0,"%YAML directive should contain exactly one part"),!1;let[i]=s;if(i==="1.1"||i==="1.2")return this.yaml.version=i,!0;{let o=/^\d+\.\d+$/.test(i);return t(6,`Unsupported YAML version ${i}`,o),!1}}default:return t(0,`Unknown directive ${r}`,!0),!1}}tagName(e,t){if(e==="!")return"!";if(e[0]!=="!")return t(`Not a valid tag: ${e}`),null;if(e[1]==="<"){let o=e.slice(2,-1);return o==="!"||o==="!!"?(t(`Verbatim tags aren't resolved, so ${e} is invalid.`),null):(e[e.length-1]!==">"&&t("Verbatim tags must end with a >"),o)}let[,s,r]=e.match(/^(.*!)([^!]*)$/s);r||t(`The ${e} tag has no suffix`);let i=this.tags[s];if(i)try{return i+decodeURIComponent(r)}catch(o){return t(String(o)),null}return s==="!"?e:(t(`Could not resolve tag: ${e}`),null)}tagString(e){for(let[t,s]of Object.entries(this.tags))if(e.startsWith(s))return t+sf(e.substring(s.length));return e[0]==="!"?e:`!<${e}>`}toString(e){let t=this.yaml.explicit?[`%YAML ${this.yaml.version||"1.2"}`]:[],s=Object.entries(this.tags),r;if(e&&s.length>0&&Lo.isNode(e.contents)){let i={};tf.visit(e.contents,(o,a)=>{Lo.isNode(a)&&a.tag&&(i[a.tag]=!0)}),r=Object.keys(i)}else r=[];for(let[i,o]of s)i==="!!"&&o==="tag:yaml.org,2002:"||(!e||r.some(a=>a.startsWith(o)))&&t.push(`%TAG ${i} ${o}`);return t.join(`
4
+ `)}};Lt.defaultYaml={explicit:!1,version:"1.2"};Lt.defaultTags={"!!":"tag:yaml.org,2002:"};qo.Directives=Lt});var On=S(qt=>{"use strict";p();var Ro=R(),rf=jt();function of(n){if(/[\x00-\x19\s,[\]{}]/.test(n)){let t=`Anchor must not contain whitespace or control characters: ${JSON.stringify(n)}`;throw new Error(t)}return!0}function xo(n){let e=new Set;return rf.visit(n,{Value(t,s){s.anchor&&e.add(s.anchor)}}),e}function Mo(n,e){for(let t=1;;++t){let s=`${n}${t}`;if(!e.has(s))return s}}function af(n,e){let t=[],s=new Map,r=null;return{onAnchor:i=>{t.push(i),r??(r=xo(n));let o=Mo(e,r);return r.add(o),o},setAnchors:()=>{for(let i of t){let o=s.get(i);if(typeof o=="object"&&o.anchor&&(Ro.isScalar(o.node)||Ro.isCollection(o.node)))o.node.anchor=o.anchor;else{let a=new Error("Failed to resolve repeated object (this should not happen)");throw a.source=i,a}}},sourceObjects:s}}qt.anchorIsValid=of;qt.anchorNames=xo;qt.createNodeAnchors=af;qt.findNewAnchor=Mo});var dr=S(Do=>{"use strict";p();function Rt(n,e,t,s){if(s&&typeof s=="object")if(Array.isArray(s))for(let r=0,i=s.length;r<i;++r){let o=s[r],a=Rt(n,s,String(r),o);a===void 0?delete s[r]:a!==o&&(s[r]=a)}else if(s instanceof Map)for(let r of Array.from(s.keys())){let i=s.get(r),o=Rt(n,s,r,i);o===void 0?s.delete(r):o!==i&&s.set(r,o)}else if(s instanceof Set)for(let r of Array.from(s)){let i=Rt(n,s,r,r);i===void 0?s.delete(r):i!==r&&(s.delete(r),s.add(i))}else for(let[r,i]of Object.entries(s)){let o=Rt(n,s,r,i);o===void 0?delete s[r]:o!==i&&(s[r]=o)}return n.call(e,t,s)}Do.applyReviver=Rt});var Ce=S(Bo=>{"use strict";p();var cf=R();function Ko(n,e,t){if(Array.isArray(n))return n.map((s,r)=>Ko(s,String(r),t));if(n&&typeof n.toJSON=="function"){if(!t||!cf.hasAnchor(n))return n.toJSON(e,t);let s={aliasCount:0,count:1,res:void 0};t.anchors.set(n,s),t.onCreate=i=>{s.res=i,delete t.onCreate};let r=n.toJSON(e,t);return t.onCreate&&t.onCreate(r),r}return typeof n=="bigint"&&!t?.keep?Number(n):n}Bo.toJS=Ko});var Pn=S(Uo=>{"use strict";p();var lf=dr(),Go=R(),uf=Ce(),pr=class{constructor(e){Object.defineProperty(this,Go.NODE_TYPE,{value:e})}clone(){let e=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return this.range&&(e.range=this.range.slice()),e}toJS(e,{mapAsMap:t,maxAliasCount:s,onAnchor:r,reviver:i}={}){if(!Go.isDocument(e))throw new TypeError("A document argument is required");let o={anchors:new Map,doc:e,keep:!0,mapAsMap:t===!0,mapKeyWarned:!1,maxAliasCount:typeof s=="number"?s:100},a=uf.toJS(this,"",o);if(typeof r=="function")for(let{count:c,res:l}of o.anchors.values())r(l,c);return typeof i=="function"?lf.applyReviver(i,{"":a},"",a):a}};Uo.NodeBase=pr});var xt=S(Fo=>{"use strict";p();var ff=On(),df=jt(),at=R(),pf=Pn(),hf=Ce(),hr=class extends pf.NodeBase{constructor(e){super(at.ALIAS),this.source=e,Object.defineProperty(this,"tag",{set(){throw new Error("Alias nodes cannot have tags")}})}resolve(e,t){let s;t?.aliasResolveCache?s=t.aliasResolveCache:(s=[],df.visit(e,{Node:(i,o)=>{(at.isAlias(o)||at.hasAnchor(o))&&s.push(o)}}),t&&(t.aliasResolveCache=s));let r;for(let i of s){if(i===this)break;i.anchor===this.source&&(r=i)}return r}toJSON(e,t){if(!t)return{source:this.source};let{anchors:s,doc:r,maxAliasCount:i}=t,o=this.resolve(r,t);if(!o){let c=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw new ReferenceError(c)}let a=s.get(o);if(a||(hf.toJS(o,null,t),a=s.get(o)),!a||a.res===void 0){let c="This should not happen: Alias anchor was not resolved?";throw new ReferenceError(c)}if(i>=0&&(a.count+=1,a.aliasCount===0&&(a.aliasCount=jn(r,o,s)),a.count*a.aliasCount>i)){let c="Excessive alias count indicates a resource exhaustion attack";throw new ReferenceError(c)}return a.res}toString(e,t,s){let r=`*${this.source}`;if(e){if(ff.anchorIsValid(this.source),e.options.verifyAliasOrder&&!e.anchors.has(this.source)){let i=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw new Error(i)}if(e.implicitKey)return`${r} `}return r}};function jn(n,e,t){if(at.isAlias(e)){let s=e.resolve(n),r=t&&s&&t.get(s);return r?r.count*r.aliasCount:0}else if(at.isCollection(e)){let s=0;for(let r of e.items){let i=jn(n,r,t);i>s&&(s=i)}return s}else if(at.isPair(e)){let s=jn(n,e.key,t),r=jn(n,e.value,t);return Math.max(s,r)}return 1}Fo.Alias=hr});var Y=S(mr=>{"use strict";p();var mf=R(),gf=Pn(),yf=Ce(),wf=n=>!n||typeof n!="function"&&typeof n!="object",_e=class extends gf.NodeBase{constructor(e){super(mf.SCALAR),this.value=e}toJSON(e,t){return t?.keep?this.value:yf.toJS(this.value,e,t)}toString(){return String(this.value)}};_e.BLOCK_FOLDED="BLOCK_FOLDED";_e.BLOCK_LITERAL="BLOCK_LITERAL";_e.PLAIN="PLAIN";_e.QUOTE_DOUBLE="QUOTE_DOUBLE";_e.QUOTE_SINGLE="QUOTE_SINGLE";mr.Scalar=_e;mr.isScalarValue=wf});var Mt=S(Vo=>{"use strict";p();var bf=xt(),Fe=R(),Yo=Y(),kf="tag:yaml.org,2002:";function $f(n,e,t){if(e){let s=t.filter(i=>i.tag===e),r=s.find(i=>!i.format)??s[0];if(!r)throw new Error(`Tag ${e} not found`);return r}return t.find(s=>s.identify?.(n)&&!s.format)}function Sf(n,e,t){if(Fe.isDocument(n)&&(n=n.contents),Fe.isNode(n))return n;if(Fe.isPair(n)){let u=t.schema[Fe.MAP].createNode?.(t.schema,null,t);return u.items.push(n),u}(n instanceof String||n instanceof Number||n instanceof Boolean||typeof BigInt<"u"&&n instanceof BigInt)&&(n=n.valueOf());let{aliasDuplicateObjects:s,onAnchor:r,onTagObj:i,schema:o,sourceObjects:a}=t,c;if(s&&n&&typeof n=="object"){if(c=a.get(n),c)return c.anchor??(c.anchor=r(n)),new bf.Alias(c.anchor);c={anchor:null,node:null},a.set(n,c)}e?.startsWith("!!")&&(e=kf+e.slice(2));let l=$f(n,e,o.tags);if(!l){if(n&&typeof n.toJSON=="function"&&(n=n.toJSON()),!n||typeof n!="object"){let u=new Yo.Scalar(n);return c&&(c.node=u),u}l=n instanceof Map?o[Fe.MAP]:Symbol.iterator in Object(n)?o[Fe.SEQ]:o[Fe.MAP]}i&&(i(l),delete t.onTagObj);let d=l?.createNode?l.createNode(t.schema,n,t):typeof l?.nodeClass?.from=="function"?l.nodeClass.from(t.schema,n,t):new Yo.Scalar(n);return e?d.tag=e:l.default||(d.tag=l.tag),c&&(c.node=d),d}Vo.createNode=Sf});var qn=S(Ln=>{"use strict";p();var vf=Mt(),fe=R(),Af=Pn();function gr(n,e,t){let s=t;for(let r=e.length-1;r>=0;--r){let i=e[r];if(typeof i=="number"&&Number.isInteger(i)&&i>=0){let o=[];o[i]=s,s=o}else s=new Map([[i,s]])}return vf.createNode(s,void 0,{aliasDuplicateObjects:!1,keepUndefined:!1,onAnchor:()=>{throw new Error("This should not happen, please report a bug.")},schema:n,sourceObjects:new Map})}var Jo=n=>n==null||typeof n=="object"&&!!n[Symbol.iterator]().next().done,yr=class extends Af.NodeBase{constructor(e,t){super(e),Object.defineProperty(this,"schema",{value:t,configurable:!0,enumerable:!1,writable:!0})}clone(e){let t=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return e&&(t.schema=e),t.items=t.items.map(s=>fe.isNode(s)||fe.isPair(s)?s.clone(e):s),this.range&&(t.range=this.range.slice()),t}addIn(e,t){if(Jo(e))this.add(t);else{let[s,...r]=e,i=this.get(s,!0);if(fe.isCollection(i))i.addIn(r,t);else if(i===void 0&&this.schema)this.set(s,gr(this.schema,r,t));else throw new Error(`Expected YAML collection at ${s}. Remaining path: ${r}`)}}deleteIn(e){let[t,...s]=e;if(s.length===0)return this.delete(t);let r=this.get(t,!0);if(fe.isCollection(r))return r.deleteIn(s);throw new Error(`Expected YAML collection at ${t}. Remaining path: ${s}`)}getIn(e,t){let[s,...r]=e,i=this.get(s,!0);return r.length===0?!t&&fe.isScalar(i)?i.value:i:fe.isCollection(i)?i.getIn(r,t):void 0}hasAllNullValues(e){return this.items.every(t=>{if(!fe.isPair(t))return!1;let s=t.value;return s==null||e&&fe.isScalar(s)&&s.value==null&&!s.commentBefore&&!s.comment&&!s.tag})}hasIn(e){let[t,...s]=e;if(s.length===0)return this.has(t);let r=this.get(t,!0);return fe.isCollection(r)?r.hasIn(s):!1}setIn(e,t){let[s,...r]=e;if(r.length===0)this.set(s,t);else{let i=this.get(s,!0);if(fe.isCollection(i))i.setIn(r,t);else if(i===void 0&&this.schema)this.set(s,gr(this.schema,r,t));else throw new Error(`Expected YAML collection at ${s}. Remaining path: ${r}`)}}};Ln.Collection=yr;Ln.collectionFromPath=gr;Ln.isEmptyPath=Jo});var Dt=S(Rn=>{"use strict";p();var Ef=n=>n.replace(/^(?!$)(?: $)?/gm,"#");function wr(n,e){return/^\n+$/.test(n)?n.substring(1):e?n.replace(/^(?! *$)/gm,e):n}var Nf=(n,e,t)=>n.endsWith(`
5
+ `)?wr(t,e):t.includes(`
6
+ `)?`
7
+ `+wr(t,e):(n.endsWith(" ")?"":" ")+t;Rn.indentComment=wr;Rn.lineComment=Nf;Rn.stringifyComment=Ef});var zo=S(Kt=>{"use strict";p();var Cf="flow",br="block",xn="quoted";function _f(n,e,t="flow",{indentAtStart:s,lineWidth:r=80,minContentWidth:i=20,onFold:o,onOverflow:a}={}){if(!r||r<0)return n;r<i&&(i=0);let c=Math.max(1+i,1+r-e.length);if(n.length<=c)return n;let l=[],d={},u=r-e.length;typeof s=="number"&&(s>r-Math.max(2,i)?l.push(0):u=r-s);let f,h,y=!1,m=-1,w=-1,A=-1;t===br&&(m=Wo(n,m,e.length),m!==-1&&(u=m+c));for(let E;E=n[m+=1];){if(t===xn&&E==="\\"){switch(w=m,n[m+1]){case"x":m+=3;break;case"u":m+=5;break;case"U":m+=9;break;default:m+=1}A=m}if(E===`
8
+ `)t===br&&(m=Wo(n,m,e.length)),u=m+e.length+c,f=void 0;else{if(E===" "&&h&&h!==" "&&h!==`
9
+ `&&h!==" "){let N=n[m+1];N&&N!==" "&&N!==`
10
+ `&&N!==" "&&(f=m)}if(m>=u)if(f)l.push(f),u=f+c,f=void 0;else if(t===xn){for(;h===" "||h===" ";)h=E,E=n[m+=1],y=!0;let N=m>A+1?m-2:w-1;if(d[N])return n;l.push(N),d[N]=!0,u=N+c,f=void 0}else y=!0}h=E}if(y&&a&&a(),l.length===0)return n;o&&o();let $=n.slice(0,l[0]);for(let E=0;E<l.length;++E){let N=l[E],g=l[E+1]||n.length;N===0?$=`
11
+ ${e}${n.slice(0,g)}`:(t===xn&&d[N]&&($+=`${n[N]}\\`),$+=`
12
+ ${e}${n.slice(N+1,g)}`)}return $}function Wo(n,e,t){let s=e,r=e+1,i=n[r];for(;i===" "||i===" ";)if(e<r+t)i=n[++e];else{do i=n[++e];while(i&&i!==`
13
+ `);s=e,r=e+1,i=n[r]}return s}Kt.FOLD_BLOCK=br;Kt.FOLD_FLOW=Cf;Kt.FOLD_QUOTED=xn;Kt.foldFlowLines=_f});var Gt=S(Ho=>{"use strict";p();var oe=Y(),Ie=zo(),Dn=(n,e)=>({indentAtStart:e?n.indent.length:n.indentAtStart,lineWidth:n.options.lineWidth,minContentWidth:n.options.minContentWidth}),Kn=n=>/^(%|---|\.\.\.)/m.test(n);function If(n,e,t){if(!e||e<0)return!1;let s=e-t,r=n.length;if(r<=s)return!1;for(let i=0,o=0;i<r;++i)if(n[i]===`
14
+ `){if(i-o>s)return!0;if(o=i+1,r-o<=s)return!1}return!0}function Bt(n,e){let t=JSON.stringify(n);if(e.options.doubleQuotedAsJSON)return t;let{implicitKey:s}=e,r=e.options.doubleQuotedMinMultiLineLength,i=e.indent||(Kn(n)?" ":""),o="",a=0;for(let c=0,l=t[c];l;l=t[++c])if(l===" "&&t[c+1]==="\\"&&t[c+2]==="n"&&(o+=t.slice(a,c)+"\\ ",c+=1,a=c,l="\\"),l==="\\")switch(t[c+1]){case"u":{o+=t.slice(a,c);let d=t.substr(c+2,4);switch(d){case"0000":o+="\\0";break;case"0007":o+="\\a";break;case"000b":o+="\\v";break;case"001b":o+="\\e";break;case"0085":o+="\\N";break;case"00a0":o+="\\_";break;case"2028":o+="\\L";break;case"2029":o+="\\P";break;default:d.substr(0,2)==="00"?o+="\\x"+d.substr(2):o+=t.substr(c,6)}c+=5,a=c+1}break;case"n":if(s||t[c+2]==='"'||t.length<r)c+=1;else{for(o+=t.slice(a,c)+`
15
+
16
+ `;t[c+2]==="\\"&&t[c+3]==="n"&&t[c+4]!=='"';)o+=`
17
+ `,c+=2;o+=i,t[c+2]===" "&&(o+="\\"),c+=1,a=c+1}break;default:c+=1}return o=a?o+t.slice(a):t,s?o:Ie.foldFlowLines(o,i,Ie.FOLD_QUOTED,Dn(e,!1))}function kr(n,e){if(e.options.singleQuote===!1||e.implicitKey&&n.includes(`
18
+ `)||/[ \t]\n|\n[ \t]/.test(n))return Bt(n,e);let t=e.indent||(Kn(n)?" ":""),s="'"+n.replace(/'/g,"''").replace(/\n+/g,`$&
19
+ ${t}`)+"'";return e.implicitKey?s:Ie.foldFlowLines(s,t,Ie.FOLD_FLOW,Dn(e,!1))}function ct(n,e){let{singleQuote:t}=e.options,s;if(t===!1)s=Bt;else{let r=n.includes('"'),i=n.includes("'");r&&!i?s=kr:i&&!r?s=Bt:s=t?kr:Bt}return s(n,e)}var $r;try{$r=new RegExp(`(^|(?<!
20
+ ))
21
+ +(?!
22
+ |$)`,"g")}catch{$r=/\n+(?!\n|$)/g}function Mn({comment:n,type:e,value:t},s,r,i){let{blockQuote:o,commentString:a,lineWidth:c}=s.options;if(!o||/\n[\t ]+$/.test(t))return ct(t,s);let l=s.indent||(s.forceBlockIndent||Kn(t)?" ":""),d=o==="literal"?!0:o==="folded"||e===oe.Scalar.BLOCK_FOLDED?!1:e===oe.Scalar.BLOCK_LITERAL?!0:!If(t,c,l.length);if(!t)return d?`|
23
+ `:`>
24
+ `;let u,f;for(f=t.length;f>0;--f){let g=t[f-1];if(g!==`
25
+ `&&g!==" "&&g!==" ")break}let h=t.substring(f),y=h.indexOf(`
26
+ `);y===-1?u="-":t===h||y!==h.length-1?(u="+",i&&i()):u="",h&&(t=t.slice(0,-h.length),h[h.length-1]===`
27
+ `&&(h=h.slice(0,-1)),h=h.replace($r,`$&${l}`));let m=!1,w,A=-1;for(w=0;w<t.length;++w){let g=t[w];if(g===" ")m=!0;else if(g===`
28
+ `)A=w;else break}let $=t.substring(0,A<w?A+1:w);$&&(t=t.substring($.length),$=$.replace(/\n+/g,`$&${l}`));let N=(m?l?"2":"1":"")+u;if(n&&(N+=" "+a(n.replace(/ ?[\r\n]+/g," ")),r&&r()),!d){let g=t.replace(/\n+/g,`
29
+ $&`).replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,"$1$2").replace(/\n+/g,`$&${l}`),O=!1,L=Dn(s,!0);o!=="folded"&&e!==oe.Scalar.BLOCK_FOLDED&&(L.onOverflow=()=>{O=!0});let b=Ie.foldFlowLines(`${$}${g}${h}`,l,Ie.FOLD_BLOCK,L);if(!O)return`>${N}
30
+ ${l}${b}`}return t=t.replace(/\n+/g,`$&${l}`),`|${N}
31
+ ${l}${$}${t}${h}`}function Tf(n,e,t,s){let{type:r,value:i}=n,{actualString:o,implicitKey:a,indent:c,indentStep:l,inFlow:d}=e;if(a&&i.includes(`
32
+ `)||d&&/[[\]{},]/.test(i))return ct(i,e);if(/^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(i))return a||d||!i.includes(`
33
+ `)?ct(i,e):Mn(n,e,t,s);if(!a&&!d&&r!==oe.Scalar.PLAIN&&i.includes(`
34
+ `))return Mn(n,e,t,s);if(Kn(i)){if(c==="")return e.forceBlockIndent=!0,Mn(n,e,t,s);if(a&&c===l)return ct(i,e)}let u=i.replace(/\n+/g,`$&
35
+ ${c}`);if(o){let f=m=>m.default&&m.tag!=="tag:yaml.org,2002:str"&&m.test?.test(u),{compat:h,tags:y}=e.doc.schema;if(y.some(f)||h?.some(f))return ct(i,e)}return a?u:Ie.foldFlowLines(u,c,Ie.FOLD_FLOW,Dn(e,!1))}function Of(n,e,t,s){let{implicitKey:r,inFlow:i}=e,o=typeof n.value=="string"?n:Object.assign({},n,{value:String(n.value)}),{type:a}=n;a!==oe.Scalar.QUOTE_DOUBLE&&/[\x00-\x08\x0b-\x1f\x7f-\x9f\u{D800}-\u{DFFF}]/u.test(o.value)&&(a=oe.Scalar.QUOTE_DOUBLE);let c=d=>{switch(d){case oe.Scalar.BLOCK_FOLDED:case oe.Scalar.BLOCK_LITERAL:return r||i?ct(o.value,e):Mn(o,e,t,s);case oe.Scalar.QUOTE_DOUBLE:return Bt(o.value,e);case oe.Scalar.QUOTE_SINGLE:return kr(o.value,e);case oe.Scalar.PLAIN:return Tf(o,e,t,s);default:return null}},l=c(a);if(l===null){let{defaultKeyType:d,defaultStringType:u}=e.options,f=r&&d||u;if(l=c(f),l===null)throw new Error(`Unsupported default string type ${f}`)}return l}Ho.stringifyString=Of});var Ut=S(Sr=>{"use strict";p();var Pf=On(),Te=R(),jf=Dt(),Lf=Gt();function qf(n,e){let t=Object.assign({blockQuote:!0,commentString:jf.stringifyComment,defaultKeyType:null,defaultStringType:"PLAIN",directives:null,doubleQuotedAsJSON:!1,doubleQuotedMinMultiLineLength:40,falseStr:"false",flowCollectionPadding:!0,indentSeq:!0,lineWidth:80,minContentWidth:20,nullStr:"null",simpleKeys:!1,singleQuote:null,trueStr:"true",verifyAliasOrder:!0},n.schema.toStringOptions,e),s;switch(t.collectionStyle){case"block":s=!1;break;case"flow":s=!0;break;default:s=null}return{anchors:new Set,doc:n,flowCollectionPadding:t.flowCollectionPadding?" ":"",indent:"",indentStep:typeof t.indent=="number"?" ".repeat(t.indent):" ",inFlow:s,options:t}}function Rf(n,e){if(e.tag){let r=n.filter(i=>i.tag===e.tag);if(r.length>0)return r.find(i=>i.format===e.format)??r[0]}let t,s;if(Te.isScalar(e)){s=e.value;let r=n.filter(i=>i.identify?.(s));if(r.length>1){let i=r.filter(o=>o.test);i.length>0&&(r=i)}t=r.find(i=>i.format===e.format)??r.find(i=>!i.format)}else s=e,t=n.find(r=>r.nodeClass&&s instanceof r.nodeClass);if(!t){let r=s?.constructor?.name??(s===null?"null":typeof s);throw new Error(`Tag not resolved for ${r} value`)}return t}function xf(n,e,{anchors:t,doc:s}){if(!s.directives)return"";let r=[],i=(Te.isScalar(n)||Te.isCollection(n))&&n.anchor;i&&Pf.anchorIsValid(i)&&(t.add(i),r.push(`&${i}`));let o=n.tag??(e.default?null:e.tag);return o&&r.push(s.directives.tagString(o)),r.join(" ")}function Mf(n,e,t,s){if(Te.isPair(n))return n.toString(e,t,s);if(Te.isAlias(n)){if(e.doc.directives)return n.toString(e);if(e.resolvedAliases?.has(n))throw new TypeError("Cannot stringify circular structure without alias nodes");e.resolvedAliases?e.resolvedAliases.add(n):e.resolvedAliases=new Set([n]),n=n.resolve(e.doc)}let r,i=Te.isNode(n)?n:e.doc.createNode(n,{onTagObj:c=>r=c});r??(r=Rf(e.doc.schema.tags,i));let o=xf(i,r,e);o.length>0&&(e.indentAtStart=(e.indentAtStart??0)+o.length+1);let a=typeof r.stringify=="function"?r.stringify(i,e,t,s):Te.isScalar(i)?Lf.stringifyString(i,e,t,s):i.toString(e,t,s);return o?Te.isScalar(i)||a[0]==="{"||a[0]==="["?`${o} ${a}`:`${o}
36
+ ${e.indent}${a}`:a}Sr.createStringifyContext=qf;Sr.stringify=Mf});var ea=S(Zo=>{"use strict";p();var we=R(),Qo=Y(),Xo=Ut(),Ft=Dt();function Df({key:n,value:e},t,s,r){let{allNullValues:i,doc:o,indent:a,indentStep:c,options:{commentString:l,indentSeq:d,simpleKeys:u}}=t,f=we.isNode(n)&&n.comment||null;if(u){if(f)throw new Error("With simple keys, key nodes cannot have comments");if(we.isCollection(n)||!we.isNode(n)&&typeof n=="object"){let L="With simple keys, collection cannot be used as a key value";throw new Error(L)}}let h=!u&&(!n||f&&e==null&&!t.inFlow||we.isCollection(n)||(we.isScalar(n)?n.type===Qo.Scalar.BLOCK_FOLDED||n.type===Qo.Scalar.BLOCK_LITERAL:typeof n=="object"));t=Object.assign({},t,{allNullValues:!1,implicitKey:!h&&(u||!i),indent:a+c});let y=!1,m=!1,w=Xo.stringify(n,t,()=>y=!0,()=>m=!0);if(!h&&!t.inFlow&&w.length>1024){if(u)throw new Error("With simple keys, single line scalar must not span more than 1024 characters");h=!0}if(t.inFlow){if(i||e==null)return y&&s&&s(),w===""?"?":h?`? ${w}`:w}else if(i&&!u||e==null&&h)return w=`? ${w}`,f&&!y?w+=Ft.lineComment(w,t.indent,l(f)):m&&r&&r(),w;y&&(f=null),h?(f&&(w+=Ft.lineComment(w,t.indent,l(f))),w=`? ${w}
37
+ ${a}:`):(w=`${w}:`,f&&(w+=Ft.lineComment(w,t.indent,l(f))));let A,$,E;we.isNode(e)?(A=!!e.spaceBefore,$=e.commentBefore,E=e.comment):(A=!1,$=null,E=null,e&&typeof e=="object"&&(e=o.createNode(e))),t.implicitKey=!1,!h&&!f&&we.isScalar(e)&&(t.indentAtStart=w.length+1),m=!1,!d&&c.length>=2&&!t.inFlow&&!h&&we.isSeq(e)&&!e.flow&&!e.tag&&!e.anchor&&(t.indent=t.indent.substring(2));let N=!1,g=Xo.stringify(e,t,()=>N=!0,()=>m=!0),O=" ";if(f||A||$){if(O=A?`
38
+ `:"",$){let L=l($);O+=`
39
+ ${Ft.indentComment(L,t.indent)}`}g===""&&!t.inFlow?O===`
40
+ `&&(O=`
41
+
42
+ `):O+=`
43
+ ${t.indent}`}else if(!h&&we.isCollection(e)){let L=g[0],b=g.indexOf(`
44
+ `),_=b!==-1,x=t.inFlow??e.flow??e.items.length===0;if(_||!x){let G=!1;if(_&&(L==="&"||L==="!")){let D=g.indexOf(" ");L==="&"&&D!==-1&&D<b&&g[D+1]==="!"&&(D=g.indexOf(" ",D+1)),(D===-1||b<D)&&(G=!0)}G||(O=`
45
+ ${t.indent}`)}}else(g===""||g[0]===`
46
+ `)&&(O="");return w+=O+g,t.inFlow?N&&s&&s():E&&!N?w+=Ft.lineComment(w,t.indent,l(E)):m&&r&&r(),w}Zo.stringifyPair=Df});var Ar=S(vr=>{"use strict";p();var ta=vn("process");function Kf(n,...e){n==="debug"&&console.log(...e)}function Bf(n,e){(n==="debug"||n==="warn")&&(typeof ta.emitWarning=="function"?ta.emitWarning(e):console.warn(e))}vr.debug=Kf;vr.warn=Bf});var Fn=S(Un=>{"use strict";p();var Yt=R(),na=Y(),Bn="<<",Gn={identify:n=>n===Bn||typeof n=="symbol"&&n.description===Bn,default:"key",tag:"tag:yaml.org,2002:merge",test:/^<<$/,resolve:()=>Object.assign(new na.Scalar(Symbol(Bn)),{addToJSMap:sa}),stringify:()=>Bn},Gf=(n,e)=>(Gn.identify(e)||Yt.isScalar(e)&&(!e.type||e.type===na.Scalar.PLAIN)&&Gn.identify(e.value))&&n?.doc.schema.tags.some(t=>t.tag===Gn.tag&&t.default);function sa(n,e,t){if(t=n&&Yt.isAlias(t)?t.resolve(n.doc):t,Yt.isSeq(t))for(let s of t.items)Er(n,e,s);else if(Array.isArray(t))for(let s of t)Er(n,e,s);else Er(n,e,t)}function Er(n,e,t){let s=n&&Yt.isAlias(t)?t.resolve(n.doc):t;if(!Yt.isMap(s))throw new Error("Merge sources must be maps or map aliases");let r=s.toJSON(null,n,Map);for(let[i,o]of r)e instanceof Map?e.has(i)||e.set(i,o):e instanceof Set?e.add(i):Object.prototype.hasOwnProperty.call(e,i)||Object.defineProperty(e,i,{value:o,writable:!0,enumerable:!0,configurable:!0});return e}Un.addMergeToJSMap=sa;Un.isMergeKey=Gf;Un.merge=Gn});var Cr=S(oa=>{"use strict";p();var Uf=Ar(),ra=Fn(),Ff=Ut(),ia=R(),Nr=Ce();function Yf(n,e,{key:t,value:s}){if(ia.isNode(t)&&t.addToJSMap)t.addToJSMap(n,e,s);else if(ra.isMergeKey(n,t))ra.addMergeToJSMap(n,e,s);else{let r=Nr.toJS(t,"",n);if(e instanceof Map)e.set(r,Nr.toJS(s,r,n));else if(e instanceof Set)e.add(r);else{let i=Vf(t,r,n),o=Nr.toJS(s,i,n);i in e?Object.defineProperty(e,i,{value:o,writable:!0,enumerable:!0,configurable:!0}):e[i]=o}}return e}function Vf(n,e,t){if(e===null)return"";if(typeof e!="object")return String(e);if(ia.isNode(n)&&t?.doc){let s=Ff.createStringifyContext(t.doc,{});s.anchors=new Set;for(let i of t.anchors.keys())s.anchors.add(i.anchor);s.inFlow=!0,s.inStringifyKey=!0;let r=n.toString(s);if(!t.mapKeyWarned){let i=JSON.stringify(r);i.length>40&&(i=i.substring(0,36)+'..."'),Uf.warn(t.doc.options.logLevel,`Keys with collection values will be stringified due to JS Object restrictions: ${i}. Set mapAsMap: true to use object keys.`),t.mapKeyWarned=!0}return r}return JSON.stringify(e)}oa.addPairToJSMap=Yf});var Oe=S(_r=>{"use strict";p();var aa=Mt(),Jf=ea(),Wf=Cr(),Yn=R();function zf(n,e,t){let s=aa.createNode(n,void 0,t),r=aa.createNode(e,void 0,t);return new Vn(s,r)}var Vn=class n{constructor(e,t=null){Object.defineProperty(this,Yn.NODE_TYPE,{value:Yn.PAIR}),this.key=e,this.value=t}clone(e){let{key:t,value:s}=this;return Yn.isNode(t)&&(t=t.clone(e)),Yn.isNode(s)&&(s=s.clone(e)),new n(t,s)}toJSON(e,t){let s=t?.mapAsMap?new Map:{};return Wf.addPairToJSMap(t,s,this)}toString(e,t,s){return e?.doc?Jf.stringifyPair(this,e,t,s):JSON.stringify(this)}};_r.Pair=Vn;_r.createPair=zf});var Ir=S(la=>{"use strict";p();var Ye=R(),ca=Ut(),Jn=Dt();function Hf(n,e,t){return(e.inFlow??n.flow?Xf:Qf)(n,e,t)}function Qf({comment:n,items:e},t,{blockItemPrefix:s,flowChars:r,itemIndent:i,onChompKeep:o,onComment:a}){let{indent:c,options:{commentString:l}}=t,d=Object.assign({},t,{indent:i,type:null}),u=!1,f=[];for(let y=0;y<e.length;++y){let m=e[y],w=null;if(Ye.isNode(m))!u&&m.spaceBefore&&f.push(""),Wn(t,f,m.commentBefore,u),m.comment&&(w=m.comment);else if(Ye.isPair(m)){let $=Ye.isNode(m.key)?m.key:null;$&&(!u&&$.spaceBefore&&f.push(""),Wn(t,f,$.commentBefore,u))}u=!1;let A=ca.stringify(m,d,()=>w=null,()=>u=!0);w&&(A+=Jn.lineComment(A,i,l(w))),u&&w&&(u=!1),f.push(s+A)}let h;if(f.length===0)h=r.start+r.end;else{h=f[0];for(let y=1;y<f.length;++y){let m=f[y];h+=m?`
47
+ ${c}${m}`:`
48
+ `}}return n?(h+=`
49
+ `+Jn.indentComment(l(n),c),a&&a()):u&&o&&o(),h}function Xf({items:n},e,{flowChars:t,itemIndent:s}){let{indent:r,indentStep:i,flowCollectionPadding:o,options:{commentString:a}}=e;s+=i;let c=Object.assign({},e,{indent:s,inFlow:!0,type:null}),l=!1,d=0,u=[];for(let y=0;y<n.length;++y){let m=n[y],w=null;if(Ye.isNode(m))m.spaceBefore&&u.push(""),Wn(e,u,m.commentBefore,!1),m.comment&&(w=m.comment);else if(Ye.isPair(m)){let $=Ye.isNode(m.key)?m.key:null;$&&($.spaceBefore&&u.push(""),Wn(e,u,$.commentBefore,!1),$.comment&&(l=!0));let E=Ye.isNode(m.value)?m.value:null;E?(E.comment&&(w=E.comment),E.commentBefore&&(l=!0)):m.value==null&&$?.comment&&(w=$.comment)}w&&(l=!0);let A=ca.stringify(m,c,()=>w=null);y<n.length-1&&(A+=","),w&&(A+=Jn.lineComment(A,s,a(w))),!l&&(u.length>d||A.includes(`
50
+ `))&&(l=!0),u.push(A),d=u.length}let{start:f,end:h}=t;if(u.length===0)return f+h;if(!l){let y=u.reduce((m,w)=>m+w.length+2,2);l=e.options.lineWidth>0&&y>e.options.lineWidth}if(l){let y=f;for(let m of u)y+=m?`
51
+ ${i}${r}${m}`:`
52
+ `;return`${y}
53
+ ${r}${h}`}else return`${f}${o}${u.join(" ")}${o}${h}`}function Wn({indent:n,options:{commentString:e}},t,s,r){if(s&&r&&(s=s.replace(/^\n+/,"")),s){let i=Jn.indentComment(e(s),n);t.push(i.trimStart())}}la.stringifyCollection=Hf});var je=S(Or=>{"use strict";p();var Zf=Ir(),ed=Cr(),td=qn(),Pe=R(),zn=Oe(),nd=Y();function Vt(n,e){let t=Pe.isScalar(e)?e.value:e;for(let s of n)if(Pe.isPair(s)&&(s.key===e||s.key===t||Pe.isScalar(s.key)&&s.key.value===t))return s}var Tr=class extends td.Collection{static get tagName(){return"tag:yaml.org,2002:map"}constructor(e){super(Pe.MAP,e),this.items=[]}static from(e,t,s){let{keepUndefined:r,replacer:i}=s,o=new this(e),a=(c,l)=>{if(typeof i=="function")l=i.call(t,c,l);else if(Array.isArray(i)&&!i.includes(c))return;(l!==void 0||r)&&o.items.push(zn.createPair(c,l,s))};if(t instanceof Map)for(let[c,l]of t)a(c,l);else if(t&&typeof t=="object")for(let c of Object.keys(t))a(c,t[c]);return typeof e.sortMapEntries=="function"&&o.items.sort(e.sortMapEntries),o}add(e,t){let s;Pe.isPair(e)?s=e:!e||typeof e!="object"||!("key"in e)?s=new zn.Pair(e,e?.value):s=new zn.Pair(e.key,e.value);let r=Vt(this.items,s.key),i=this.schema?.sortMapEntries;if(r){if(!t)throw new Error(`Key ${s.key} already set`);Pe.isScalar(r.value)&&nd.isScalarValue(s.value)?r.value.value=s.value:r.value=s.value}else if(i){let o=this.items.findIndex(a=>i(s,a)<0);o===-1?this.items.push(s):this.items.splice(o,0,s)}else this.items.push(s)}delete(e){let t=Vt(this.items,e);return t?this.items.splice(this.items.indexOf(t),1).length>0:!1}get(e,t){let r=Vt(this.items,e)?.value;return(!t&&Pe.isScalar(r)?r.value:r)??void 0}has(e){return!!Vt(this.items,e)}set(e,t){this.add(new zn.Pair(e,t),!0)}toJSON(e,t,s){let r=s?new s:t?.mapAsMap?new Map:{};t?.onCreate&&t.onCreate(r);for(let i of this.items)ed.addPairToJSMap(t,r,i);return r}toString(e,t,s){if(!e)return JSON.stringify(this);for(let r of this.items)if(!Pe.isPair(r))throw new Error(`Map items must all be pairs; found ${JSON.stringify(r)} instead`);return!e.allNullValues&&this.hasAllNullValues(!1)&&(e=Object.assign({},e,{allNullValues:!0})),Zf.stringifyCollection(this,e,{blockItemPrefix:"",flowChars:{start:"{",end:"}"},itemIndent:e.indent||"",onChompKeep:s,onComment:t})}};Or.YAMLMap=Tr;Or.findPair=Vt});var lt=S(fa=>{"use strict";p();var sd=R(),ua=je(),rd={collection:"map",default:!0,nodeClass:ua.YAMLMap,tag:"tag:yaml.org,2002:map",resolve(n,e){return sd.isMap(n)||e("Expected a mapping for this tag"),n},createNode:(n,e,t)=>ua.YAMLMap.from(n,e,t)};fa.map=rd});var Le=S(da=>{"use strict";p();var id=Mt(),od=Ir(),ad=qn(),Qn=R(),cd=Y(),ld=Ce(),Pr=class extends ad.Collection{static get tagName(){return"tag:yaml.org,2002:seq"}constructor(e){super(Qn.SEQ,e),this.items=[]}add(e){this.items.push(e)}delete(e){let t=Hn(e);return typeof t!="number"?!1:this.items.splice(t,1).length>0}get(e,t){let s=Hn(e);if(typeof s!="number")return;let r=this.items[s];return!t&&Qn.isScalar(r)?r.value:r}has(e){let t=Hn(e);return typeof t=="number"&&t<this.items.length}set(e,t){let s=Hn(e);if(typeof s!="number")throw new Error(`Expected a valid index, not ${e}.`);let r=this.items[s];Qn.isScalar(r)&&cd.isScalarValue(t)?r.value=t:this.items[s]=t}toJSON(e,t){let s=[];t?.onCreate&&t.onCreate(s);let r=0;for(let i of this.items)s.push(ld.toJS(i,String(r++),t));return s}toString(e,t,s){return e?od.stringifyCollection(this,e,{blockItemPrefix:"- ",flowChars:{start:"[",end:"]"},itemIndent:(e.indent||"")+" ",onChompKeep:s,onComment:t}):JSON.stringify(this)}static from(e,t,s){let{replacer:r}=s,i=new this(e);if(t&&Symbol.iterator in Object(t)){let o=0;for(let a of t){if(typeof r=="function"){let c=t instanceof Set?a:String(o++);a=r.call(t,c,a)}i.items.push(id.createNode(a,void 0,s))}}return i}};function Hn(n){let e=Qn.isScalar(n)?n.value:n;return e&&typeof e=="string"&&(e=Number(e)),typeof e=="number"&&Number.isInteger(e)&&e>=0?e:null}da.YAMLSeq=Pr});var ut=S(ha=>{"use strict";p();var ud=R(),pa=Le(),fd={collection:"seq",default:!0,nodeClass:pa.YAMLSeq,tag:"tag:yaml.org,2002:seq",resolve(n,e){return ud.isSeq(n)||e("Expected a sequence for this tag"),n},createNode:(n,e,t)=>pa.YAMLSeq.from(n,e,t)};ha.seq=fd});var Jt=S(ma=>{"use strict";p();var dd=Gt(),pd={identify:n=>typeof n=="string",default:!0,tag:"tag:yaml.org,2002:str",resolve:n=>n,stringify(n,e,t,s){return e=Object.assign({actualString:!0},e),dd.stringifyString(n,e,t,s)}};ma.string=pd});var Xn=S(wa=>{"use strict";p();var ga=Y(),ya={identify:n=>n==null,createNode:()=>new ga.Scalar(null),default:!0,tag:"tag:yaml.org,2002:null",test:/^(?:~|[Nn]ull|NULL)?$/,resolve:()=>new ga.Scalar(null),stringify:({source:n},e)=>typeof n=="string"&&ya.test.test(n)?n:e.options.nullStr};wa.nullTag=ya});var jr=S(ka=>{"use strict";p();var hd=Y(),ba={identify:n=>typeof n=="boolean",default:!0,tag:"tag:yaml.org,2002:bool",test:/^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,resolve:n=>new hd.Scalar(n[0]==="t"||n[0]==="T"),stringify({source:n,value:e},t){if(n&&ba.test.test(n)){let s=n[0]==="t"||n[0]==="T";if(e===s)return n}return e?t.options.trueStr:t.options.falseStr}};ka.boolTag=ba});var ft=S($a=>{"use strict";p();function md({format:n,minFractionDigits:e,tag:t,value:s}){if(typeof s=="bigint")return String(s);let r=typeof s=="number"?s:Number(s);if(!isFinite(r))return isNaN(r)?".nan":r<0?"-.inf":".inf";let i=JSON.stringify(s);if(!n&&e&&(!t||t==="tag:yaml.org,2002:float")&&/^\d/.test(i)){let o=i.indexOf(".");o<0&&(o=i.length,i+=".");let a=e-(i.length-o-1);for(;a-- >0;)i+="0"}return i}$a.stringifyNumber=md});var qr=S(Zn=>{"use strict";p();var gd=Y(),Lr=ft(),yd={identify:n=>typeof n=="number",default:!0,tag:"tag:yaml.org,2002:float",test:/^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,resolve:n=>n.slice(-3).toLowerCase()==="nan"?NaN:n[0]==="-"?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,stringify:Lr.stringifyNumber},wd={identify:n=>typeof n=="number",default:!0,tag:"tag:yaml.org,2002:float",format:"EXP",test:/^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,resolve:n=>parseFloat(n),stringify(n){let e=Number(n.value);return isFinite(e)?e.toExponential():Lr.stringifyNumber(n)}},bd={identify:n=>typeof n=="number",default:!0,tag:"tag:yaml.org,2002:float",test:/^[-+]?(?:\.[0-9]+|[0-9]+\.[0-9]*)$/,resolve(n){let e=new gd.Scalar(parseFloat(n)),t=n.indexOf(".");return t!==-1&&n[n.length-1]==="0"&&(e.minFractionDigits=n.length-t-1),e},stringify:Lr.stringifyNumber};Zn.float=bd;Zn.floatExp=wd;Zn.floatNaN=yd});var xr=S(ts=>{"use strict";p();var Sa=ft(),es=n=>typeof n=="bigint"||Number.isInteger(n),Rr=(n,e,t,{intAsBigInt:s})=>s?BigInt(n):parseInt(n.substring(e),t);function va(n,e,t){let{value:s}=n;return es(s)&&s>=0?t+s.toString(e):Sa.stringifyNumber(n)}var kd={identify:n=>es(n)&&n>=0,default:!0,tag:"tag:yaml.org,2002:int",format:"OCT",test:/^0o[0-7]+$/,resolve:(n,e,t)=>Rr(n,2,8,t),stringify:n=>va(n,8,"0o")},$d={identify:es,default:!0,tag:"tag:yaml.org,2002:int",test:/^[-+]?[0-9]+$/,resolve:(n,e,t)=>Rr(n,0,10,t),stringify:Sa.stringifyNumber},Sd={identify:n=>es(n)&&n>=0,default:!0,tag:"tag:yaml.org,2002:int",format:"HEX",test:/^0x[0-9a-fA-F]+$/,resolve:(n,e,t)=>Rr(n,2,16,t),stringify:n=>va(n,16,"0x")};ts.int=$d;ts.intHex=Sd;ts.intOct=kd});var Ea=S(Aa=>{"use strict";p();var vd=lt(),Ad=Xn(),Ed=ut(),Nd=Jt(),Cd=jr(),Mr=qr(),Dr=xr(),_d=[vd.map,Ed.seq,Nd.string,Ad.nullTag,Cd.boolTag,Dr.intOct,Dr.int,Dr.intHex,Mr.floatNaN,Mr.floatExp,Mr.float];Aa.schema=_d});var _a=S(Ca=>{"use strict";p();var Id=Y(),Td=lt(),Od=ut();function Na(n){return typeof n=="bigint"||Number.isInteger(n)}var ns=({value:n})=>JSON.stringify(n),Pd=[{identify:n=>typeof n=="string",default:!0,tag:"tag:yaml.org,2002:str",resolve:n=>n,stringify:ns},{identify:n=>n==null,createNode:()=>new Id.Scalar(null),default:!0,tag:"tag:yaml.org,2002:null",test:/^null$/,resolve:()=>null,stringify:ns},{identify:n=>typeof n=="boolean",default:!0,tag:"tag:yaml.org,2002:bool",test:/^true$|^false$/,resolve:n=>n==="true",stringify:ns},{identify:Na,default:!0,tag:"tag:yaml.org,2002:int",test:/^-?(?:0|[1-9][0-9]*)$/,resolve:(n,e,{intAsBigInt:t})=>t?BigInt(n):parseInt(n,10),stringify:({value:n})=>Na(n)?n.toString():JSON.stringify(n)},{identify:n=>typeof n=="number",default:!0,tag:"tag:yaml.org,2002:float",test:/^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,resolve:n=>parseFloat(n),stringify:ns}],jd={default:!0,tag:"",test:/^/,resolve(n,e){return e(`Unresolved plain scalar ${JSON.stringify(n)}`),n}},Ld=[Td.map,Od.seq].concat(Pd,jd);Ca.schema=Ld});var Br=S(Ia=>{"use strict";p();var Wt=vn("buffer"),Kr=Y(),qd=Gt(),Rd={identify:n=>n instanceof Uint8Array,default:!1,tag:"tag:yaml.org,2002:binary",resolve(n,e){if(typeof Wt.Buffer=="function")return Wt.Buffer.from(n,"base64");if(typeof atob=="function"){let t=atob(n.replace(/[\n\r]/g,"")),s=new Uint8Array(t.length);for(let r=0;r<t.length;++r)s[r]=t.charCodeAt(r);return s}else return e("This environment does not support reading binary tags; either Buffer or atob is required"),n},stringify({comment:n,type:e,value:t},s,r,i){if(!t)return"";let o=t,a;if(typeof Wt.Buffer=="function")a=o instanceof Wt.Buffer?o.toString("base64"):Wt.Buffer.from(o.buffer).toString("base64");else if(typeof btoa=="function"){let c="";for(let l=0;l<o.length;++l)c+=String.fromCharCode(o[l]);a=btoa(c)}else throw new Error("This environment does not support writing binary tags; either Buffer or btoa is required");if(e??(e=Kr.Scalar.BLOCK_LITERAL),e!==Kr.Scalar.QUOTE_DOUBLE){let c=Math.max(s.options.lineWidth-s.indent.length,s.options.minContentWidth),l=Math.ceil(a.length/c),d=new Array(l);for(let u=0,f=0;u<l;++u,f+=c)d[u]=a.substr(f,c);a=d.join(e===Kr.Scalar.BLOCK_LITERAL?`
54
+ `:" ")}return qd.stringifyString({comment:n,type:e,value:a},s,r,i)}};Ia.binary=Rd});var is=S(rs=>{"use strict";p();var ss=R(),Gr=Oe(),xd=Y(),Md=Le();function Ta(n,e){if(ss.isSeq(n))for(let t=0;t<n.items.length;++t){let s=n.items[t];if(!ss.isPair(s)){if(ss.isMap(s)){s.items.length>1&&e("Each pair must have its own sequence indicator");let r=s.items[0]||new Gr.Pair(new xd.Scalar(null));if(s.commentBefore&&(r.key.commentBefore=r.key.commentBefore?`${s.commentBefore}
55
+ ${r.key.commentBefore}`:s.commentBefore),s.comment){let i=r.value??r.key;i.comment=i.comment?`${s.comment}
56
+ ${i.comment}`:s.comment}s=r}n.items[t]=ss.isPair(s)?s:new Gr.Pair(s)}}else e("Expected a sequence for this tag");return n}function Oa(n,e,t){let{replacer:s}=t,r=new Md.YAMLSeq(n);r.tag="tag:yaml.org,2002:pairs";let i=0;if(e&&Symbol.iterator in Object(e))for(let o of e){typeof s=="function"&&(o=s.call(e,String(i++),o));let a,c;if(Array.isArray(o))if(o.length===2)a=o[0],c=o[1];else throw new TypeError(`Expected [key, value] tuple: ${o}`);else if(o&&o instanceof Object){let l=Object.keys(o);if(l.length===1)a=l[0],c=o[a];else throw new TypeError(`Expected tuple with one key, not ${l.length} keys`)}else a=o;r.items.push(Gr.createPair(a,c,t))}return r}var Dd={collection:"seq",default:!1,tag:"tag:yaml.org,2002:pairs",resolve:Ta,createNode:Oa};rs.createPairs=Oa;rs.pairs=Dd;rs.resolvePairs=Ta});var Yr=S(Fr=>{"use strict";p();var Pa=R(),Ur=Ce(),zt=je(),Kd=Le(),ja=is(),Ve=class n extends Kd.YAMLSeq{constructor(){super(),this.add=zt.YAMLMap.prototype.add.bind(this),this.delete=zt.YAMLMap.prototype.delete.bind(this),this.get=zt.YAMLMap.prototype.get.bind(this),this.has=zt.YAMLMap.prototype.has.bind(this),this.set=zt.YAMLMap.prototype.set.bind(this),this.tag=n.tag}toJSON(e,t){if(!t)return super.toJSON(e);let s=new Map;t?.onCreate&&t.onCreate(s);for(let r of this.items){let i,o;if(Pa.isPair(r)?(i=Ur.toJS(r.key,"",t),o=Ur.toJS(r.value,i,t)):i=Ur.toJS(r,"",t),s.has(i))throw new Error("Ordered maps must not include duplicate keys");s.set(i,o)}return s}static from(e,t,s){let r=ja.createPairs(e,t,s),i=new this;return i.items=r.items,i}};Ve.tag="tag:yaml.org,2002:omap";var Bd={collection:"seq",identify:n=>n instanceof Map,nodeClass:Ve,default:!1,tag:"tag:yaml.org,2002:omap",resolve(n,e){let t=ja.resolvePairs(n,e),s=[];for(let{key:r}of t.items)Pa.isScalar(r)&&(s.includes(r.value)?e(`Ordered maps must not include duplicate keys: ${r.value}`):s.push(r.value));return Object.assign(new Ve,t)},createNode:(n,e,t)=>Ve.from(n,e,t)};Fr.YAMLOMap=Ve;Fr.omap=Bd});var Ma=S(Vr=>{"use strict";p();var La=Y();function qa({value:n,source:e},t){return e&&(n?Ra:xa).test.test(e)?e:n?t.options.trueStr:t.options.falseStr}var Ra={identify:n=>n===!0,default:!0,tag:"tag:yaml.org,2002:bool",test:/^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,resolve:()=>new La.Scalar(!0),stringify:qa},xa={identify:n=>n===!1,default:!0,tag:"tag:yaml.org,2002:bool",test:/^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/,resolve:()=>new La.Scalar(!1),stringify:qa};Vr.falseTag=xa;Vr.trueTag=Ra});var Da=S(os=>{"use strict";p();var Gd=Y(),Jr=ft(),Ud={identify:n=>typeof n=="number",default:!0,tag:"tag:yaml.org,2002:float",test:/^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,resolve:n=>n.slice(-3).toLowerCase()==="nan"?NaN:n[0]==="-"?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,stringify:Jr.stringifyNumber},Fd={identify:n=>typeof n=="number",default:!0,tag:"tag:yaml.org,2002:float",format:"EXP",test:/^[-+]?(?:[0-9][0-9_]*)?(?:\.[0-9_]*)?[eE][-+]?[0-9]+$/,resolve:n=>parseFloat(n.replace(/_/g,"")),stringify(n){let e=Number(n.value);return isFinite(e)?e.toExponential():Jr.stringifyNumber(n)}},Yd={identify:n=>typeof n=="number",default:!0,tag:"tag:yaml.org,2002:float",test:/^[-+]?(?:[0-9][0-9_]*)?\.[0-9_]*$/,resolve(n){let e=new Gd.Scalar(parseFloat(n.replace(/_/g,""))),t=n.indexOf(".");if(t!==-1){let s=n.substring(t+1).replace(/_/g,"");s[s.length-1]==="0"&&(e.minFractionDigits=s.length)}return e},stringify:Jr.stringifyNumber};os.float=Yd;os.floatExp=Fd;os.floatNaN=Ud});var Ba=S(Qt=>{"use strict";p();var Ka=ft(),Ht=n=>typeof n=="bigint"||Number.isInteger(n);function as(n,e,t,{intAsBigInt:s}){let r=n[0];if((r==="-"||r==="+")&&(e+=1),n=n.substring(e).replace(/_/g,""),s){switch(t){case 2:n=`0b${n}`;break;case 8:n=`0o${n}`;break;case 16:n=`0x${n}`;break}let o=BigInt(n);return r==="-"?BigInt(-1)*o:o}let i=parseInt(n,t);return r==="-"?-1*i:i}function Wr(n,e,t){let{value:s}=n;if(Ht(s)){let r=s.toString(e);return s<0?"-"+t+r.substr(1):t+r}return Ka.stringifyNumber(n)}var Vd={identify:Ht,default:!0,tag:"tag:yaml.org,2002:int",format:"BIN",test:/^[-+]?0b[0-1_]+$/,resolve:(n,e,t)=>as(n,2,2,t),stringify:n=>Wr(n,2,"0b")},Jd={identify:Ht,default:!0,tag:"tag:yaml.org,2002:int",format:"OCT",test:/^[-+]?0[0-7_]+$/,resolve:(n,e,t)=>as(n,1,8,t),stringify:n=>Wr(n,8,"0")},Wd={identify:Ht,default:!0,tag:"tag:yaml.org,2002:int",test:/^[-+]?[0-9][0-9_]*$/,resolve:(n,e,t)=>as(n,0,10,t),stringify:Ka.stringifyNumber},zd={identify:Ht,default:!0,tag:"tag:yaml.org,2002:int",format:"HEX",test:/^[-+]?0x[0-9a-fA-F_]+$/,resolve:(n,e,t)=>as(n,2,16,t),stringify:n=>Wr(n,16,"0x")};Qt.int=Wd;Qt.intBin=Vd;Qt.intHex=zd;Qt.intOct=Jd});var Hr=S(zr=>{"use strict";p();var us=R(),cs=Oe(),ls=je(),Je=class n extends ls.YAMLMap{constructor(e){super(e),this.tag=n.tag}add(e){let t;us.isPair(e)?t=e:e&&typeof e=="object"&&"key"in e&&"value"in e&&e.value===null?t=new cs.Pair(e.key,null):t=new cs.Pair(e,null),ls.findPair(this.items,t.key)||this.items.push(t)}get(e,t){let s=ls.findPair(this.items,e);return!t&&us.isPair(s)?us.isScalar(s.key)?s.key.value:s.key:s}set(e,t){if(typeof t!="boolean")throw new Error(`Expected boolean value for set(key, value) in a YAML set, not ${typeof t}`);let s=ls.findPair(this.items,e);s&&!t?this.items.splice(this.items.indexOf(s),1):!s&&t&&this.items.push(new cs.Pair(e))}toJSON(e,t){return super.toJSON(e,t,Set)}toString(e,t,s){if(!e)return JSON.stringify(this);if(this.hasAllNullValues(!0))return super.toString(Object.assign({},e,{allNullValues:!0}),t,s);throw new Error("Set items must all have null values")}static from(e,t,s){let{replacer:r}=s,i=new this(e);if(t&&Symbol.iterator in Object(t))for(let o of t)typeof r=="function"&&(o=r.call(t,o,o)),i.items.push(cs.createPair(o,null,s));return i}};Je.tag="tag:yaml.org,2002:set";var Hd={collection:"map",identify:n=>n instanceof Set,nodeClass:Je,default:!1,tag:"tag:yaml.org,2002:set",createNode:(n,e,t)=>Je.from(n,e,t),resolve(n,e){if(us.isMap(n)){if(n.hasAllNullValues(!0))return Object.assign(new Je,n);e("Set items must all have null values")}else e("Expected a mapping for this tag");return n}};zr.YAMLSet=Je;zr.set=Hd});var Xr=S(fs=>{"use strict";p();var Qd=ft();function Qr(n,e){let t=n[0],s=t==="-"||t==="+"?n.substring(1):n,r=o=>e?BigInt(o):Number(o),i=s.replace(/_/g,"").split(":").reduce((o,a)=>o*r(60)+r(a),r(0));return t==="-"?r(-1)*i:i}function Ga(n){let{value:e}=n,t=o=>o;if(typeof e=="bigint")t=o=>BigInt(o);else if(isNaN(e)||!isFinite(e))return Qd.stringifyNumber(n);let s="";e<0&&(s="-",e*=t(-1));let r=t(60),i=[e%r];return e<60?i.unshift(0):(e=(e-i[0])/r,i.unshift(e%r),e>=60&&(e=(e-i[0])/r,i.unshift(e))),s+i.map(o=>String(o).padStart(2,"0")).join(":").replace(/000000\d*$/,"")}var Xd={identify:n=>typeof n=="bigint"||Number.isInteger(n),default:!0,tag:"tag:yaml.org,2002:int",format:"TIME",test:/^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+$/,resolve:(n,e,{intAsBigInt:t})=>Qr(n,t),stringify:Ga},Zd={identify:n=>typeof n=="number",default:!0,tag:"tag:yaml.org,2002:float",format:"TIME",test:/^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*$/,resolve:n=>Qr(n,!1),stringify:Ga},Ua={identify:n=>n instanceof Date,default:!0,tag:"tag:yaml.org,2002:timestamp",test:RegExp("^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})(?:(?:t|T|[ \\t]+)([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?)?$"),resolve(n){let e=n.match(Ua.test);if(!e)throw new Error("!!timestamp expects a date, starting with yyyy-mm-dd");let[,t,s,r,i,o,a]=e.map(Number),c=e[7]?Number((e[7]+"00").substr(1,3)):0,l=Date.UTC(t,s-1,r,i||0,o||0,a||0,c),d=e[8];if(d&&d!=="Z"){let u=Qr(d,!1);Math.abs(u)<30&&(u*=60),l-=6e4*u}return new Date(l)},stringify:({value:n})=>n?.toISOString().replace(/(T00:00:00)?\.000Z$/,"")??""};fs.floatTime=Zd;fs.intTime=Xd;fs.timestamp=Ua});var Va=S(Ya=>{"use strict";p();var ep=lt(),tp=Xn(),np=ut(),sp=Jt(),rp=Br(),Fa=Ma(),Zr=Da(),ds=Ba(),ip=Fn(),op=Yr(),ap=is(),cp=Hr(),ei=Xr(),lp=[ep.map,np.seq,sp.string,tp.nullTag,Fa.trueTag,Fa.falseTag,ds.intBin,ds.intOct,ds.int,ds.intHex,Zr.floatNaN,Zr.floatExp,Zr.float,rp.binary,ip.merge,op.omap,ap.pairs,cp.set,ei.intTime,ei.floatTime,ei.timestamp];Ya.schema=lp});var nc=S(si=>{"use strict";p();var Ha=lt(),up=Xn(),Qa=ut(),fp=Jt(),dp=jr(),ti=qr(),ni=xr(),pp=Ea(),hp=_a(),Xa=Br(),Xt=Fn(),Za=Yr(),ec=is(),Ja=Va(),tc=Hr(),ps=Xr(),Wa=new Map([["core",pp.schema],["failsafe",[Ha.map,Qa.seq,fp.string]],["json",hp.schema],["yaml11",Ja.schema],["yaml-1.1",Ja.schema]]),za={binary:Xa.binary,bool:dp.boolTag,float:ti.float,floatExp:ti.floatExp,floatNaN:ti.floatNaN,floatTime:ps.floatTime,int:ni.int,intHex:ni.intHex,intOct:ni.intOct,intTime:ps.intTime,map:Ha.map,merge:Xt.merge,null:up.nullTag,omap:Za.omap,pairs:ec.pairs,seq:Qa.seq,set:tc.set,timestamp:ps.timestamp},mp={"tag:yaml.org,2002:binary":Xa.binary,"tag:yaml.org,2002:merge":Xt.merge,"tag:yaml.org,2002:omap":Za.omap,"tag:yaml.org,2002:pairs":ec.pairs,"tag:yaml.org,2002:set":tc.set,"tag:yaml.org,2002:timestamp":ps.timestamp};function gp(n,e,t){let s=Wa.get(e);if(s&&!n)return t&&!s.includes(Xt.merge)?s.concat(Xt.merge):s.slice();let r=s;if(!r)if(Array.isArray(n))r=[];else{let i=Array.from(Wa.keys()).filter(o=>o!=="yaml11").map(o=>JSON.stringify(o)).join(", ");throw new Error(`Unknown schema "${e}"; use one of ${i} or define customTags array`)}if(Array.isArray(n))for(let i of n)r=r.concat(i);else typeof n=="function"&&(r=n(r.slice()));return t&&(r=r.concat(Xt.merge)),r.reduce((i,o)=>{let a=typeof o=="string"?za[o]:o;if(!a){let c=JSON.stringify(o),l=Object.keys(za).map(d=>JSON.stringify(d)).join(", ");throw new Error(`Unknown custom tag ${c}; use one of ${l}`)}return i.includes(a)||i.push(a),i},[])}si.coreKnownTags=mp;si.getTags=gp});var oi=S(sc=>{"use strict";p();var ri=R(),yp=lt(),wp=ut(),bp=Jt(),hs=nc(),kp=(n,e)=>n.key<e.key?-1:n.key>e.key?1:0,ii=class n{constructor({compat:e,customTags:t,merge:s,resolveKnownTags:r,schema:i,sortMapEntries:o,toStringDefaults:a}){this.compat=Array.isArray(e)?hs.getTags(e,"compat"):e?hs.getTags(null,e):null,this.name=typeof i=="string"&&i||"core",this.knownTags=r?hs.coreKnownTags:{},this.tags=hs.getTags(t,this.name,s),this.toStringOptions=a??null,Object.defineProperty(this,ri.MAP,{value:yp.map}),Object.defineProperty(this,ri.SCALAR,{value:bp.string}),Object.defineProperty(this,ri.SEQ,{value:wp.seq}),this.sortMapEntries=typeof o=="function"?o:o===!0?kp:null}clone(){let e=Object.create(n.prototype,Object.getOwnPropertyDescriptors(this));return e.tags=this.tags.slice(),e}};sc.Schema=ii});var ic=S(rc=>{"use strict";p();var $p=R(),ai=Ut(),Zt=Dt();function Sp(n,e){let t=[],s=e.directives===!0;if(e.directives!==!1&&n.directives){let c=n.directives.toString(n);c?(t.push(c),s=!0):n.directives.docStart&&(s=!0)}s&&t.push("---");let r=ai.createStringifyContext(n,e),{commentString:i}=r.options;if(n.commentBefore){t.length!==1&&t.unshift("");let c=i(n.commentBefore);t.unshift(Zt.indentComment(c,""))}let o=!1,a=null;if(n.contents){if($p.isNode(n.contents)){if(n.contents.spaceBefore&&s&&t.push(""),n.contents.commentBefore){let d=i(n.contents.commentBefore);t.push(Zt.indentComment(d,""))}r.forceBlockIndent=!!n.comment,a=n.contents.comment}let c=a?void 0:()=>o=!0,l=ai.stringify(n.contents,r,()=>a=null,c);a&&(l+=Zt.lineComment(l,"",i(a))),(l[0]==="|"||l[0]===">")&&t[t.length-1]==="---"?t[t.length-1]=`--- ${l}`:t.push(l)}else t.push(ai.stringify(n.contents,r));if(n.directives?.docEnd)if(n.comment){let c=i(n.comment);c.includes(`
57
+ `)?(t.push("..."),t.push(Zt.indentComment(c,""))):t.push(`... ${c}`)}else t.push("...");else{let c=n.comment;c&&o&&(c=c.replace(/^\n+/,"")),c&&((!o||a)&&t[t.length-1]!==""&&t.push(""),t.push(Zt.indentComment(i(c),"")))}return t.join(`
58
+ `)+`
59
+ `}rc.stringifyDocument=Sp});var en=S(oc=>{"use strict";p();var vp=xt(),dt=qn(),re=R(),Ap=Oe(),Ep=Ce(),Np=oi(),Cp=ic(),ci=On(),_p=dr(),Ip=Mt(),li=fr(),ui=class n{constructor(e,t,s){this.commentBefore=null,this.comment=null,this.errors=[],this.warnings=[],Object.defineProperty(this,re.NODE_TYPE,{value:re.DOC});let r=null;typeof t=="function"||Array.isArray(t)?r=t:s===void 0&&t&&(s=t,t=void 0);let i=Object.assign({intAsBigInt:!1,keepSourceTokens:!1,logLevel:"warn",prettyErrors:!0,strict:!0,stringKeys:!1,uniqueKeys:!0,version:"1.2"},s);this.options=i;let{version:o}=i;s?._directives?(this.directives=s._directives.atDocument(),this.directives.yaml.explicit&&(o=this.directives.yaml.version)):this.directives=new li.Directives({version:o}),this.setSchema(o,s),this.contents=e===void 0?null:this.createNode(e,r,s)}clone(){let e=Object.create(n.prototype,{[re.NODE_TYPE]:{value:re.DOC}});return e.commentBefore=this.commentBefore,e.comment=this.comment,e.errors=this.errors.slice(),e.warnings=this.warnings.slice(),e.options=Object.assign({},this.options),this.directives&&(e.directives=this.directives.clone()),e.schema=this.schema.clone(),e.contents=re.isNode(this.contents)?this.contents.clone(e.schema):this.contents,this.range&&(e.range=this.range.slice()),e}add(e){pt(this.contents)&&this.contents.add(e)}addIn(e,t){pt(this.contents)&&this.contents.addIn(e,t)}createAlias(e,t){if(!e.anchor){let s=ci.anchorNames(this);e.anchor=!t||s.has(t)?ci.findNewAnchor(t||"a",s):t}return new vp.Alias(e.anchor)}createNode(e,t,s){let r;if(typeof t=="function")e=t.call({"":e},"",e),r=t;else if(Array.isArray(t)){let w=$=>typeof $=="number"||$ instanceof String||$ instanceof Number,A=t.filter(w).map(String);A.length>0&&(t=t.concat(A)),r=t}else s===void 0&&t&&(s=t,t=void 0);let{aliasDuplicateObjects:i,anchorPrefix:o,flow:a,keepUndefined:c,onTagObj:l,tag:d}=s??{},{onAnchor:u,setAnchors:f,sourceObjects:h}=ci.createNodeAnchors(this,o||"a"),y={aliasDuplicateObjects:i??!0,keepUndefined:c??!1,onAnchor:u,onTagObj:l,replacer:r,schema:this.schema,sourceObjects:h},m=Ip.createNode(e,d,y);return a&&re.isCollection(m)&&(m.flow=!0),f(),m}createPair(e,t,s={}){let r=this.createNode(e,null,s),i=this.createNode(t,null,s);return new Ap.Pair(r,i)}delete(e){return pt(this.contents)?this.contents.delete(e):!1}deleteIn(e){return dt.isEmptyPath(e)?this.contents==null?!1:(this.contents=null,!0):pt(this.contents)?this.contents.deleteIn(e):!1}get(e,t){return re.isCollection(this.contents)?this.contents.get(e,t):void 0}getIn(e,t){return dt.isEmptyPath(e)?!t&&re.isScalar(this.contents)?this.contents.value:this.contents:re.isCollection(this.contents)?this.contents.getIn(e,t):void 0}has(e){return re.isCollection(this.contents)?this.contents.has(e):!1}hasIn(e){return dt.isEmptyPath(e)?this.contents!==void 0:re.isCollection(this.contents)?this.contents.hasIn(e):!1}set(e,t){this.contents==null?this.contents=dt.collectionFromPath(this.schema,[e],t):pt(this.contents)&&this.contents.set(e,t)}setIn(e,t){dt.isEmptyPath(e)?this.contents=t:this.contents==null?this.contents=dt.collectionFromPath(this.schema,Array.from(e),t):pt(this.contents)&&this.contents.setIn(e,t)}setSchema(e,t={}){typeof e=="number"&&(e=String(e));let s;switch(e){case"1.1":this.directives?this.directives.yaml.version="1.1":this.directives=new li.Directives({version:"1.1"}),s={resolveKnownTags:!1,schema:"yaml-1.1"};break;case"1.2":case"next":this.directives?this.directives.yaml.version=e:this.directives=new li.Directives({version:e}),s={resolveKnownTags:!0,schema:"core"};break;case null:this.directives&&delete this.directives,s=null;break;default:{let r=JSON.stringify(e);throw new Error(`Expected '1.1', '1.2' or null as first argument, but found: ${r}`)}}if(t.schema instanceof Object)this.schema=t.schema;else if(s)this.schema=new Np.Schema(Object.assign(s,t));else throw new Error("With a null YAML version, the { schema: Schema } option is required")}toJS({json:e,jsonArg:t,mapAsMap:s,maxAliasCount:r,onAnchor:i,reviver:o}={}){let a={anchors:new Map,doc:this,keep:!e,mapAsMap:s===!0,mapKeyWarned:!1,maxAliasCount:typeof r=="number"?r:100},c=Ep.toJS(this.contents,t??"",a);if(typeof i=="function")for(let{count:l,res:d}of a.anchors.values())i(d,l);return typeof o=="function"?_p.applyReviver(o,{"":c},"",c):c}toJSON(e,t){return this.toJS({json:!0,jsonArg:e,mapAsMap:!1,onAnchor:t})}toString(e={}){if(this.errors.length>0)throw new Error("Document with errors cannot be stringified");if("indent"in e&&(!Number.isInteger(e.indent)||Number(e.indent)<=0)){let t=JSON.stringify(e.indent);throw new Error(`"indent" option must be a positive integer, not ${t}`)}return Cp.stringifyDocument(this,e)}};function pt(n){if(re.isCollection(n))return!0;throw new Error("Expected a YAML collection as document contents")}oc.Document=ui});var sn=S(nn=>{"use strict";p();var tn=class extends Error{constructor(e,t,s,r){super(),this.name=e,this.code=s,this.message=r,this.pos=t}},fi=class extends tn{constructor(e,t,s){super("YAMLParseError",e,t,s)}},di=class extends tn{constructor(e,t,s){super("YAMLWarning",e,t,s)}},Tp=(n,e)=>t=>{if(t.pos[0]===-1)return;t.linePos=t.pos.map(a=>e.linePos(a));let{line:s,col:r}=t.linePos[0];t.message+=` at line ${s}, column ${r}`;let i=r-1,o=n.substring(e.lineStarts[s-1],e.lineStarts[s]).replace(/[\n\r]+$/,"");if(i>=60&&o.length>80){let a=Math.min(i-39,o.length-79);o="\u2026"+o.substring(a),i-=a-1}if(o.length>80&&(o=o.substring(0,79)+"\u2026"),s>1&&/^ *$/.test(o.substring(0,i))){let a=n.substring(e.lineStarts[s-2],e.lineStarts[s-1]);a.length>80&&(a=a.substring(0,79)+`\u2026
60
+ `),o=a+o}if(/[^ ]/.test(o)){let a=1,c=t.linePos[1];c&&c.line===s&&c.col>r&&(a=Math.max(1,Math.min(c.col-r,80-i)));let l=" ".repeat(i)+"^".repeat(a);t.message+=`:
61
+
62
+ ${o}
63
+ ${l}
64
+ `}};nn.YAMLError=tn;nn.YAMLParseError=fi;nn.YAMLWarning=di;nn.prettifyError=Tp});var rn=S(ac=>{"use strict";p();function Op(n,{flow:e,indicator:t,next:s,offset:r,onError:i,parentIndent:o,startOnNewline:a}){let c=!1,l=a,d=a,u="",f="",h=!1,y=!1,m=null,w=null,A=null,$=null,E=null,N=null,g=null;for(let b of n)switch(y&&(b.type!=="space"&&b.type!=="newline"&&b.type!=="comma"&&i(b.offset,"MISSING_CHAR","Tags and anchors must be separated from the next token by white space"),y=!1),m&&(l&&b.type!=="comment"&&b.type!=="newline"&&i(m,"TAB_AS_INDENT","Tabs are not allowed as indentation"),m=null),b.type){case"space":!e&&(t!=="doc-start"||s?.type!=="flow-collection")&&b.source.includes(" ")&&(m=b),d=!0;break;case"comment":{d||i(b,"MISSING_CHAR","Comments must be separated from other tokens by white space characters");let _=b.source.substring(1)||" ";u?u+=f+_:u=_,f="",l=!1;break}case"newline":l?u?u+=b.source:(!N||t!=="seq-item-ind")&&(c=!0):f+=b.source,l=!0,h=!0,(w||A)&&($=b),d=!0;break;case"anchor":w&&i(b,"MULTIPLE_ANCHORS","A node can have at most one anchor"),b.source.endsWith(":")&&i(b.offset+b.source.length-1,"BAD_ALIAS","Anchor ending in : is ambiguous",!0),w=b,g??(g=b.offset),l=!1,d=!1,y=!0;break;case"tag":{A&&i(b,"MULTIPLE_TAGS","A node can have at most one tag"),A=b,g??(g=b.offset),l=!1,d=!1,y=!0;break}case t:(w||A)&&i(b,"BAD_PROP_ORDER",`Anchors and tags must be after the ${b.source} indicator`),N&&i(b,"UNEXPECTED_TOKEN",`Unexpected ${b.source} in ${e??"collection"}`),N=b,l=t==="seq-item-ind"||t==="explicit-key-ind",d=!1;break;case"comma":if(e){E&&i(b,"UNEXPECTED_TOKEN",`Unexpected , in ${e}`),E=b,l=!1,d=!1;break}default:i(b,"UNEXPECTED_TOKEN",`Unexpected ${b.type} token`),l=!1,d=!1}let O=n[n.length-1],L=O?O.offset+O.source.length:r;return y&&s&&s.type!=="space"&&s.type!=="newline"&&s.type!=="comma"&&(s.type!=="scalar"||s.source!=="")&&i(s.offset,"MISSING_CHAR","Tags and anchors must be separated from the next token by white space"),m&&(l&&m.indent<=o||s?.type==="block-map"||s?.type==="block-seq")&&i(m,"TAB_AS_INDENT","Tabs are not allowed as indentation"),{comma:E,found:N,spaceBefore:c,comment:u,hasNewline:h,anchor:w,tag:A,newlineAfterProp:$,end:L,start:g??L}}ac.resolveProps=Op});var ms=S(cc=>{"use strict";p();function pi(n){if(!n)return null;switch(n.type){case"alias":case"scalar":case"double-quoted-scalar":case"single-quoted-scalar":if(n.source.includes(`
65
+ `))return!0;if(n.end){for(let e of n.end)if(e.type==="newline")return!0}return!1;case"flow-collection":for(let e of n.items){for(let t of e.start)if(t.type==="newline")return!0;if(e.sep){for(let t of e.sep)if(t.type==="newline")return!0}if(pi(e.key)||pi(e.value))return!0}return!1;default:return!0}}cc.containsNewline=pi});var hi=S(lc=>{"use strict";p();var Pp=ms();function jp(n,e,t){if(e?.type==="flow-collection"){let s=e.end[0];s.indent===n&&(s.source==="]"||s.source==="}")&&Pp.containsNewline(e)&&t(s,"BAD_INDENT","Flow end indicator should be more indented than parent",!0)}}lc.flowIndentCheck=jp});var mi=S(fc=>{"use strict";p();var uc=R();function Lp(n,e,t){let{uniqueKeys:s}=n.options;if(s===!1)return!1;let r=typeof s=="function"?s:(i,o)=>i===o||uc.isScalar(i)&&uc.isScalar(o)&&i.value===o.value;return e.some(i=>r(i.key,t))}fc.mapIncludes=Lp});var yc=S(gc=>{"use strict";p();var dc=Oe(),qp=je(),pc=rn(),Rp=ms(),hc=hi(),xp=mi(),mc="All mapping items must start at the same column";function Mp({composeNode:n,composeEmptyNode:e},t,s,r,i){let o=i?.nodeClass??qp.YAMLMap,a=new o(t.schema);t.atRoot&&(t.atRoot=!1);let c=s.offset,l=null;for(let d of s.items){let{start:u,key:f,sep:h,value:y}=d,m=pc.resolveProps(u,{indicator:"explicit-key-ind",next:f??h?.[0],offset:c,onError:r,parentIndent:s.indent,startOnNewline:!0}),w=!m.found;if(w){if(f&&(f.type==="block-seq"?r(c,"BLOCK_AS_IMPLICIT_KEY","A block sequence may not be used as an implicit map key"):"indent"in f&&f.indent!==s.indent&&r(c,"BAD_INDENT",mc)),!m.anchor&&!m.tag&&!h){l=m.end,m.comment&&(a.comment?a.comment+=`
66
+ `+m.comment:a.comment=m.comment);continue}(m.newlineAfterProp||Rp.containsNewline(f))&&r(f??u[u.length-1],"MULTILINE_IMPLICIT_KEY","Implicit keys need to be on a single line")}else m.found?.indent!==s.indent&&r(c,"BAD_INDENT",mc);t.atKey=!0;let A=m.end,$=f?n(t,f,m,r):e(t,A,u,null,m,r);t.schema.compat&&hc.flowIndentCheck(s.indent,f,r),t.atKey=!1,xp.mapIncludes(t,a.items,$)&&r(A,"DUPLICATE_KEY","Map keys must be unique");let E=pc.resolveProps(h??[],{indicator:"map-value-ind",next:y,offset:$.range[2],onError:r,parentIndent:s.indent,startOnNewline:!f||f.type==="block-scalar"});if(c=E.end,E.found){w&&(y?.type==="block-map"&&!E.hasNewline&&r(c,"BLOCK_AS_IMPLICIT_KEY","Nested mappings are not allowed in compact mappings"),t.options.strict&&m.start<E.found.offset-1024&&r($.range,"KEY_OVER_1024_CHARS","The : indicator must be at most 1024 chars after the start of an implicit block mapping key"));let N=y?n(t,y,E,r):e(t,c,h,null,E,r);t.schema.compat&&hc.flowIndentCheck(s.indent,y,r),c=N.range[2];let g=new dc.Pair($,N);t.options.keepSourceTokens&&(g.srcToken=d),a.items.push(g)}else{w&&r($.range,"MISSING_CHAR","Implicit map keys need to be followed by map values"),E.comment&&($.comment?$.comment+=`
67
+ `+E.comment:$.comment=E.comment);let N=new dc.Pair($);t.options.keepSourceTokens&&(N.srcToken=d),a.items.push(N)}}return l&&l<c&&r(l,"IMPOSSIBLE","Map comment with trailing content"),a.range=[s.offset,c,l??c],a}gc.resolveBlockMap=Mp});var bc=S(wc=>{"use strict";p();var Dp=Le(),Kp=rn(),Bp=hi();function Gp({composeNode:n,composeEmptyNode:e},t,s,r,i){let o=i?.nodeClass??Dp.YAMLSeq,a=new o(t.schema);t.atRoot&&(t.atRoot=!1),t.atKey&&(t.atKey=!1);let c=s.offset,l=null;for(let{start:d,value:u}of s.items){let f=Kp.resolveProps(d,{indicator:"seq-item-ind",next:u,offset:c,onError:r,parentIndent:s.indent,startOnNewline:!0});if(!f.found)if(f.anchor||f.tag||u)u&&u.type==="block-seq"?r(f.end,"BAD_INDENT","All sequence items must start at the same column"):r(c,"MISSING_CHAR","Sequence item without - indicator");else{l=f.end,f.comment&&(a.comment=f.comment);continue}let h=u?n(t,u,f,r):e(t,f.end,d,null,f,r);t.schema.compat&&Bp.flowIndentCheck(s.indent,u,r),c=h.range[2],a.items.push(h)}return a.range=[s.offset,c,l??c],a}wc.resolveBlockSeq=Gp});var ht=S(kc=>{"use strict";p();function Up(n,e,t,s){let r="";if(n){let i=!1,o="";for(let a of n){let{source:c,type:l}=a;switch(l){case"space":i=!0;break;case"comment":{t&&!i&&s(a,"MISSING_CHAR","Comments must be separated from other tokens by white space characters");let d=c.substring(1)||" ";r?r+=o+d:r=d,o="";break}case"newline":r&&(o+=c),i=!0;break;default:s(a,"UNEXPECTED_TOKEN",`Unexpected ${l} at node end`)}e+=c.length}}return{comment:r,offset:e}}kc.resolveEnd=Up});var Ac=S(vc=>{"use strict";p();var Fp=R(),Yp=Oe(),$c=je(),Vp=Le(),Jp=ht(),Sc=rn(),Wp=ms(),zp=mi(),gi="Block collections are not allowed within flow collections",yi=n=>n&&(n.type==="block-map"||n.type==="block-seq");function Hp({composeNode:n,composeEmptyNode:e},t,s,r,i){let o=s.start.source==="{",a=o?"flow map":"flow sequence",c=i?.nodeClass??(o?$c.YAMLMap:Vp.YAMLSeq),l=new c(t.schema);l.flow=!0;let d=t.atRoot;d&&(t.atRoot=!1),t.atKey&&(t.atKey=!1);let u=s.offset+s.start.source.length;for(let w=0;w<s.items.length;++w){let A=s.items[w],{start:$,key:E,sep:N,value:g}=A,O=Sc.resolveProps($,{flow:a,indicator:"explicit-key-ind",next:E??N?.[0],offset:u,onError:r,parentIndent:s.indent,startOnNewline:!1});if(!O.found){if(!O.anchor&&!O.tag&&!N&&!g){w===0&&O.comma?r(O.comma,"UNEXPECTED_TOKEN",`Unexpected , in ${a}`):w<s.items.length-1&&r(O.start,"UNEXPECTED_TOKEN",`Unexpected empty item in ${a}`),O.comment&&(l.comment?l.comment+=`
68
+ `+O.comment:l.comment=O.comment),u=O.end;continue}!o&&t.options.strict&&Wp.containsNewline(E)&&r(E,"MULTILINE_IMPLICIT_KEY","Implicit keys of flow sequence pairs need to be on a single line")}if(w===0)O.comma&&r(O.comma,"UNEXPECTED_TOKEN",`Unexpected , in ${a}`);else if(O.comma||r(O.start,"MISSING_CHAR",`Missing , between ${a} items`),O.comment){let L="";e:for(let b of $)switch(b.type){case"comma":case"space":break;case"comment":L=b.source.substring(1);break e;default:break e}if(L){let b=l.items[l.items.length-1];Fp.isPair(b)&&(b=b.value??b.key),b.comment?b.comment+=`
69
+ `+L:b.comment=L,O.comment=O.comment.substring(L.length+1)}}if(!o&&!N&&!O.found){let L=g?n(t,g,O,r):e(t,O.end,N,null,O,r);l.items.push(L),u=L.range[2],yi(g)&&r(L.range,"BLOCK_IN_FLOW",gi)}else{t.atKey=!0;let L=O.end,b=E?n(t,E,O,r):e(t,L,$,null,O,r);yi(E)&&r(b.range,"BLOCK_IN_FLOW",gi),t.atKey=!1;let _=Sc.resolveProps(N??[],{flow:a,indicator:"map-value-ind",next:g,offset:b.range[2],onError:r,parentIndent:s.indent,startOnNewline:!1});if(_.found){if(!o&&!O.found&&t.options.strict){if(N)for(let D of N){if(D===_.found)break;if(D.type==="newline"){r(D,"MULTILINE_IMPLICIT_KEY","Implicit keys of flow sequence pairs need to be on a single line");break}}O.start<_.found.offset-1024&&r(_.found,"KEY_OVER_1024_CHARS","The : indicator must be at most 1024 chars after the start of an implicit flow sequence key")}}else g&&("source"in g&&g.source&&g.source[0]===":"?r(g,"MISSING_CHAR",`Missing space after : in ${a}`):r(_.start,"MISSING_CHAR",`Missing , or : between ${a} items`));let x=g?n(t,g,_,r):_.found?e(t,_.end,N,null,_,r):null;x?yi(g)&&r(x.range,"BLOCK_IN_FLOW",gi):_.comment&&(b.comment?b.comment+=`
70
+ `+_.comment:b.comment=_.comment);let G=new Yp.Pair(b,x);if(t.options.keepSourceTokens&&(G.srcToken=A),o){let D=l;zp.mapIncludes(t,D.items,b)&&r(L,"DUPLICATE_KEY","Map keys must be unique"),D.items.push(G)}else{let D=new $c.YAMLMap(t.schema);D.flow=!0,D.items.push(G);let se=(x??b).range;D.range=[b.range[0],se[1],se[2]],l.items.push(D)}u=x?x.range[2]:_.end}}let f=o?"}":"]",[h,...y]=s.end,m=u;if(h&&h.source===f)m=h.offset+h.source.length;else{let w=a[0].toUpperCase()+a.substring(1),A=d?`${w} must end with a ${f}`:`${w} in block collection must be sufficiently indented and end with a ${f}`;r(u,d?"MISSING_CHAR":"BAD_INDENT",A),h&&h.source.length!==1&&y.unshift(h)}if(y.length>0){let w=Jp.resolveEnd(y,m,t.options.strict,r);w.comment&&(l.comment?l.comment+=`
71
+ `+w.comment:l.comment=w.comment),l.range=[s.offset,m,w.offset]}else l.range=[s.offset,m,m];return l}vc.resolveFlowCollection=Hp});var Nc=S(Ec=>{"use strict";p();var Qp=R(),Xp=Y(),Zp=je(),eh=Le(),th=yc(),nh=bc(),sh=Ac();function wi(n,e,t,s,r,i){let o=t.type==="block-map"?th.resolveBlockMap(n,e,t,s,i):t.type==="block-seq"?nh.resolveBlockSeq(n,e,t,s,i):sh.resolveFlowCollection(n,e,t,s,i),a=o.constructor;return r==="!"||r===a.tagName?(o.tag=a.tagName,o):(r&&(o.tag=r),o)}function rh(n,e,t,s,r){let i=s.tag,o=i?e.directives.tagName(i.source,f=>r(i,"TAG_RESOLVE_FAILED",f)):null;if(t.type==="block-seq"){let{anchor:f,newlineAfterProp:h}=s,y=f&&i?f.offset>i.offset?f:i:f??i;y&&(!h||h.offset<y.offset)&&r(y,"MISSING_CHAR","Missing newline after block sequence props")}let a=t.type==="block-map"?"map":t.type==="block-seq"?"seq":t.start.source==="{"?"map":"seq";if(!i||!o||o==="!"||o===Zp.YAMLMap.tagName&&a==="map"||o===eh.YAMLSeq.tagName&&a==="seq")return wi(n,e,t,r,o);let c=e.schema.tags.find(f=>f.tag===o&&f.collection===a);if(!c){let f=e.schema.knownTags[o];if(f&&f.collection===a)e.schema.tags.push(Object.assign({},f,{default:!1})),c=f;else return f?r(i,"BAD_COLLECTION_TYPE",`${f.tag} used for ${a} collection, but expects ${f.collection??"scalar"}`,!0):r(i,"TAG_RESOLVE_FAILED",`Unresolved tag: ${o}`,!0),wi(n,e,t,r,o)}let l=wi(n,e,t,r,o,c),d=c.resolve?.(l,f=>r(i,"TAG_RESOLVE_FAILED",f),e.options)??l,u=Qp.isNode(d)?d:new Xp.Scalar(d);return u.range=l.range,u.tag=o,c?.format&&(u.format=c.format),u}Ec.composeCollection=rh});var ki=S(Cc=>{"use strict";p();var bi=Y();function ih(n,e,t){let s=e.offset,r=oh(e,n.options.strict,t);if(!r)return{value:"",type:null,comment:"",range:[s,s,s]};let i=r.mode===">"?bi.Scalar.BLOCK_FOLDED:bi.Scalar.BLOCK_LITERAL,o=e.source?ah(e.source):[],a=o.length;for(let m=o.length-1;m>=0;--m){let w=o[m][1];if(w===""||w==="\r")a=m;else break}if(a===0){let m=r.chomp==="+"&&o.length>0?`
72
+ `.repeat(Math.max(1,o.length-1)):"",w=s+r.length;return e.source&&(w+=e.source.length),{value:m,type:i,comment:r.comment,range:[s,w,w]}}let c=e.indent+r.indent,l=e.offset+r.length,d=0;for(let m=0;m<a;++m){let[w,A]=o[m];if(A===""||A==="\r")r.indent===0&&w.length>c&&(c=w.length);else{w.length<c&&t(l+w.length,"MISSING_CHAR","Block scalars with more-indented leading empty lines must use an explicit indentation indicator"),r.indent===0&&(c=w.length),d=m,c===0&&!n.atRoot&&t(l,"BAD_INDENT","Block scalar values in collections must be indented");break}l+=w.length+A.length+1}for(let m=o.length-1;m>=a;--m)o[m][0].length>c&&(a=m+1);let u="",f="",h=!1;for(let m=0;m<d;++m)u+=o[m][0].slice(c)+`
73
+ `;for(let m=d;m<a;++m){let[w,A]=o[m];l+=w.length+A.length+1;let $=A[A.length-1]==="\r";if($&&(A=A.slice(0,-1)),A&&w.length<c){let N=`Block scalar lines must not be less indented than their ${r.indent?"explicit indentation indicator":"first line"}`;t(l-A.length-($?2:1),"BAD_INDENT",N),w=""}i===bi.Scalar.BLOCK_LITERAL?(u+=f+w.slice(c)+A,f=`
74
+ `):w.length>c||A[0]===" "?(f===" "?f=`
75
+ `:!h&&f===`
76
+ `&&(f=`
77
+
78
+ `),u+=f+w.slice(c)+A,f=`
79
+ `,h=!0):A===""?f===`
80
+ `?u+=`
81
+ `:f=`
82
+ `:(u+=f+A,f=" ",h=!1)}switch(r.chomp){case"-":break;case"+":for(let m=a;m<o.length;++m)u+=`
83
+ `+o[m][0].slice(c);u[u.length-1]!==`
84
+ `&&(u+=`
85
+ `);break;default:u+=`
86
+ `}let y=s+r.length+e.source.length;return{value:u,type:i,comment:r.comment,range:[s,y,y]}}function oh({offset:n,props:e},t,s){if(e[0].type!=="block-scalar-header")return s(e[0],"IMPOSSIBLE","Block scalar header not found"),null;let{source:r}=e[0],i=r[0],o=0,a="",c=-1;for(let f=1;f<r.length;++f){let h=r[f];if(!a&&(h==="-"||h==="+"))a=h;else{let y=Number(h);!o&&y?o=y:c===-1&&(c=n+f)}}c!==-1&&s(c,"UNEXPECTED_TOKEN",`Block scalar header includes extra characters: ${r}`);let l=!1,d="",u=r.length;for(let f=1;f<e.length;++f){let h=e[f];switch(h.type){case"space":l=!0;case"newline":u+=h.source.length;break;case"comment":t&&!l&&s(h,"MISSING_CHAR","Comments must be separated from other tokens by white space characters"),u+=h.source.length,d=h.source.substring(1);break;case"error":s(h,"UNEXPECTED_TOKEN",h.message),u+=h.source.length;break;default:{let y=`Unexpected token in block scalar header: ${h.type}`;s(h,"UNEXPECTED_TOKEN",y);let m=h.source;m&&typeof m=="string"&&(u+=m.length)}}}return{mode:i,indent:o,chomp:a,comment:d,length:u}}function ah(n){let e=n.split(/\n( *)/),t=e[0],s=t.match(/^( *)/),i=[s?.[1]?[s[1],t.slice(s[1].length)]:["",t]];for(let o=1;o<e.length;o+=2)i.push([e[o],e[o+1]]);return i}Cc.resolveBlockScalar=ih});var Si=S(Ic=>{"use strict";p();var $i=Y(),ch=ht();function lh(n,e,t){let{offset:s,type:r,source:i,end:o}=n,a,c,l=(f,h,y)=>t(s+f,h,y);switch(r){case"scalar":a=$i.Scalar.PLAIN,c=uh(i,l);break;case"single-quoted-scalar":a=$i.Scalar.QUOTE_SINGLE,c=fh(i,l);break;case"double-quoted-scalar":a=$i.Scalar.QUOTE_DOUBLE,c=dh(i,l);break;default:return t(n,"UNEXPECTED_TOKEN",`Expected a flow scalar value, but found: ${r}`),{value:"",type:null,comment:"",range:[s,s+i.length,s+i.length]}}let d=s+i.length,u=ch.resolveEnd(o,d,e,t);return{value:c,type:a,comment:u.comment,range:[s,d,u.offset]}}function uh(n,e){let t="";switch(n[0]){case" ":t="a tab character";break;case",":t="flow indicator character ,";break;case"%":t="directive indicator character %";break;case"|":case">":{t=`block scalar indicator ${n[0]}`;break}case"@":case"`":{t=`reserved character ${n[0]}`;break}}return t&&e(0,"BAD_SCALAR_START",`Plain value cannot start with ${t}`),_c(n)}function fh(n,e){return(n[n.length-1]!=="'"||n.length===1)&&e(n.length,"MISSING_CHAR","Missing closing 'quote"),_c(n.slice(1,-1)).replace(/''/g,"'")}function _c(n){let e,t;try{e=new RegExp(`(.*?)(?<![ ])[ ]*\r?
87
+ `,"sy"),t=new RegExp(`[ ]*(.*?)(?:(?<![ ])[ ]*)?\r?
88
+ `,"sy")}catch{e=/(.*?)[ \t]*\r?\n/sy,t=/[ \t]*(.*?)[ \t]*\r?\n/sy}let s=e.exec(n);if(!s)return n;let r=s[1],i=" ",o=e.lastIndex;for(t.lastIndex=o;s=t.exec(n);)s[1]===""?i===`
89
+ `?r+=i:i=`
90
+ `:(r+=i+s[1],i=" "),o=t.lastIndex;let a=/[ \t]*(.*)/sy;return a.lastIndex=o,s=a.exec(n),r+i+(s?.[1]??"")}function dh(n,e){let t="";for(let s=1;s<n.length-1;++s){let r=n[s];if(!(r==="\r"&&n[s+1]===`
91
+ `))if(r===`
92
+ `){let{fold:i,offset:o}=ph(n,s);t+=i,s=o}else if(r==="\\"){let i=n[++s],o=hh[i];if(o)t+=o;else if(i===`
93
+ `)for(i=n[s+1];i===" "||i===" ";)i=n[++s+1];else if(i==="\r"&&n[s+1]===`
94
+ `)for(i=n[++s+1];i===" "||i===" ";)i=n[++s+1];else if(i==="x"||i==="u"||i==="U"){let a={x:2,u:4,U:8}[i];t+=mh(n,s+1,a,e),s+=a}else{let a=n.substr(s-1,2);e(s-1,"BAD_DQ_ESCAPE",`Invalid escape sequence ${a}`),t+=a}}else if(r===" "||r===" "){let i=s,o=n[s+1];for(;o===" "||o===" ";)o=n[++s+1];o!==`
95
+ `&&!(o==="\r"&&n[s+2]===`
96
+ `)&&(t+=s>i?n.slice(i,s+1):r)}else t+=r}return(n[n.length-1]!=='"'||n.length===1)&&e(n.length,"MISSING_CHAR",'Missing closing "quote'),t}function ph(n,e){let t="",s=n[e+1];for(;(s===" "||s===" "||s===`
97
+ `||s==="\r")&&!(s==="\r"&&n[e+2]!==`
98
+ `);)s===`
99
+ `&&(t+=`
100
+ `),e+=1,s=n[e+1];return t||(t=" "),{fold:t,offset:e}}var hh={0:"\0",a:"\x07",b:"\b",e:"\x1B",f:"\f",n:`
101
+ `,r:"\r",t:" ",v:"\v",N:"\x85",_:"\xA0",L:"\u2028",P:"\u2029"," ":" ",'"':'"',"/":"/","\\":"\\"," ":" "};function mh(n,e,t,s){let r=n.substr(e,t),o=r.length===t&&/^[0-9a-fA-F]+$/.test(r)?parseInt(r,16):NaN;if(isNaN(o)){let a=n.substr(e-2,t+2);return s(e-2,"BAD_DQ_ESCAPE",`Invalid escape sequence ${a}`),a}return String.fromCodePoint(o)}Ic.resolveFlowScalar=lh});var Pc=S(Oc=>{"use strict";p();var We=R(),Tc=Y(),gh=ki(),yh=Si();function wh(n,e,t,s){let{value:r,type:i,comment:o,range:a}=e.type==="block-scalar"?gh.resolveBlockScalar(n,e,s):yh.resolveFlowScalar(e,n.options.strict,s),c=t?n.directives.tagName(t.source,u=>s(t,"TAG_RESOLVE_FAILED",u)):null,l;n.options.stringKeys&&n.atKey?l=n.schema[We.SCALAR]:c?l=bh(n.schema,r,c,t,s):e.type==="scalar"?l=kh(n,r,e,s):l=n.schema[We.SCALAR];let d;try{let u=l.resolve(r,f=>s(t??e,"TAG_RESOLVE_FAILED",f),n.options);d=We.isScalar(u)?u:new Tc.Scalar(u)}catch(u){let f=u instanceof Error?u.message:String(u);s(t??e,"TAG_RESOLVE_FAILED",f),d=new Tc.Scalar(r)}return d.range=a,d.source=r,i&&(d.type=i),c&&(d.tag=c),l.format&&(d.format=l.format),o&&(d.comment=o),d}function bh(n,e,t,s,r){if(t==="!")return n[We.SCALAR];let i=[];for(let a of n.tags)if(!a.collection&&a.tag===t)if(a.default&&a.test)i.push(a);else return a;for(let a of i)if(a.test?.test(e))return a;let o=n.knownTags[t];return o&&!o.collection?(n.tags.push(Object.assign({},o,{default:!1,test:void 0})),o):(r(s,"TAG_RESOLVE_FAILED",`Unresolved tag: ${t}`,t!=="tag:yaml.org,2002:str"),n[We.SCALAR])}function kh({atKey:n,directives:e,schema:t},s,r,i){let o=t.tags.find(a=>(a.default===!0||n&&a.default==="key")&&a.test?.test(s))||t[We.SCALAR];if(t.compat){let a=t.compat.find(c=>c.default&&c.test?.test(s))??t[We.SCALAR];if(o.tag!==a.tag){let c=e.tagString(o.tag),l=e.tagString(a.tag),d=`Value may be parsed as either ${c} or ${l}`;i(r,"TAG_RESOLVE_FAILED",d,!0)}}return o}Oc.composeScalar=wh});var Lc=S(jc=>{"use strict";p();function $h(n,e,t){if(e){t??(t=e.length);for(let s=t-1;s>=0;--s){let r=e[s];switch(r.type){case"space":case"comment":case"newline":n-=r.source.length;continue}for(r=e[++s];r?.type==="space";)n+=r.source.length,r=e[++s];break}}return n}jc.emptyScalarPosition=$h});var xc=S(Ai=>{"use strict";p();var Sh=xt(),vh=R(),Ah=Nc(),qc=Pc(),Eh=ht(),Nh=Lc(),Ch={composeNode:Rc,composeEmptyNode:vi};function Rc(n,e,t,s){let r=n.atKey,{spaceBefore:i,comment:o,anchor:a,tag:c}=t,l,d=!0;switch(e.type){case"alias":l=_h(n,e,s),(a||c)&&s(e,"ALIAS_PROPS","An alias node must not specify any properties");break;case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":case"block-scalar":l=qc.composeScalar(n,e,c,s),a&&(l.anchor=a.source.substring(1));break;case"block-map":case"block-seq":case"flow-collection":l=Ah.composeCollection(Ch,n,e,t,s),a&&(l.anchor=a.source.substring(1));break;default:{let u=e.type==="error"?e.message:`Unsupported token (type: ${e.type})`;s(e,"UNEXPECTED_TOKEN",u),l=vi(n,e.offset,void 0,null,t,s),d=!1}}return a&&l.anchor===""&&s(a,"BAD_ALIAS","Anchor cannot be an empty string"),r&&n.options.stringKeys&&(!vh.isScalar(l)||typeof l.value!="string"||l.tag&&l.tag!=="tag:yaml.org,2002:str")&&s(c??e,"NON_STRING_KEY","With stringKeys, all keys must be strings"),i&&(l.spaceBefore=!0),o&&(e.type==="scalar"&&e.source===""?l.comment=o:l.commentBefore=o),n.options.keepSourceTokens&&d&&(l.srcToken=e),l}function vi(n,e,t,s,{spaceBefore:r,comment:i,anchor:o,tag:a,end:c},l){let d={type:"scalar",offset:Nh.emptyScalarPosition(e,t,s),indent:-1,source:""},u=qc.composeScalar(n,d,a,l);return o&&(u.anchor=o.source.substring(1),u.anchor===""&&l(o,"BAD_ALIAS","Anchor cannot be an empty string")),r&&(u.spaceBefore=!0),i&&(u.comment=i,u.range[2]=c),u}function _h({options:n},{offset:e,source:t,end:s},r){let i=new Sh.Alias(t.substring(1));i.source===""&&r(e,"BAD_ALIAS","Alias cannot be an empty string"),i.source.endsWith(":")&&r(e+t.length-1,"BAD_ALIAS","Alias ending in : is ambiguous",!0);let o=e+t.length,a=Eh.resolveEnd(s,o,n.strict,r);return i.range=[e,o,a.offset],a.comment&&(i.comment=a.comment),i}Ai.composeEmptyNode=vi;Ai.composeNode=Rc});var Kc=S(Dc=>{"use strict";p();var Ih=en(),Mc=xc(),Th=ht(),Oh=rn();function Ph(n,e,{offset:t,start:s,value:r,end:i},o){let a=Object.assign({_directives:e},n),c=new Ih.Document(void 0,a),l={atKey:!1,atRoot:!0,directives:c.directives,options:c.options,schema:c.schema},d=Oh.resolveProps(s,{indicator:"doc-start",next:r??i?.[0],offset:t,onError:o,parentIndent:0,startOnNewline:!0});d.found&&(c.directives.docStart=!0,r&&(r.type==="block-map"||r.type==="block-seq")&&!d.hasNewline&&o(d.end,"MISSING_CHAR","Block collection cannot start on same line with directives-end marker")),c.contents=r?Mc.composeNode(l,r,d,o):Mc.composeEmptyNode(l,d.end,s,null,d,o);let u=c.contents.range[2],f=Th.resolveEnd(i,u,!1,o);return f.comment&&(c.comment=f.comment),c.range=[t,u,f.offset],c}Dc.composeDoc=Ph});var Ni=S(Uc=>{"use strict";p();var jh=vn("process"),Lh=fr(),qh=en(),on=sn(),Bc=R(),Rh=Kc(),xh=ht();function an(n){if(typeof n=="number")return[n,n+1];if(Array.isArray(n))return n.length===2?n:[n[0],n[1]];let{offset:e,source:t}=n;return[e,e+(typeof t=="string"?t.length:1)]}function Gc(n){let e="",t=!1,s=!1;for(let r=0;r<n.length;++r){let i=n[r];switch(i[0]){case"#":e+=(e===""?"":s?`
102
+
103
+ `:`
104
+ `)+(i.substring(1)||" "),t=!0,s=!1;break;case"%":n[r+1]?.[0]!=="#"&&(r+=1),t=!1;break;default:t||(s=!0),t=!1}}return{comment:e,afterEmptyLine:s}}var Ei=class{constructor(e={}){this.doc=null,this.atDirectives=!1,this.prelude=[],this.errors=[],this.warnings=[],this.onError=(t,s,r,i)=>{let o=an(t);i?this.warnings.push(new on.YAMLWarning(o,s,r)):this.errors.push(new on.YAMLParseError(o,s,r))},this.directives=new Lh.Directives({version:e.version||"1.2"}),this.options=e}decorate(e,t){let{comment:s,afterEmptyLine:r}=Gc(this.prelude);if(s){let i=e.contents;if(t)e.comment=e.comment?`${e.comment}
105
+ ${s}`:s;else if(r||e.directives.docStart||!i)e.commentBefore=s;else if(Bc.isCollection(i)&&!i.flow&&i.items.length>0){let o=i.items[0];Bc.isPair(o)&&(o=o.key);let a=o.commentBefore;o.commentBefore=a?`${s}
106
+ ${a}`:s}else{let o=i.commentBefore;i.commentBefore=o?`${s}
107
+ ${o}`:s}}t?(Array.prototype.push.apply(e.errors,this.errors),Array.prototype.push.apply(e.warnings,this.warnings)):(e.errors=this.errors,e.warnings=this.warnings),this.prelude=[],this.errors=[],this.warnings=[]}streamInfo(){return{comment:Gc(this.prelude).comment,directives:this.directives,errors:this.errors,warnings:this.warnings}}*compose(e,t=!1,s=-1){for(let r of e)yield*this.next(r);yield*this.end(t,s)}*next(e){switch(jh.env.LOG_STREAM&&console.dir(e,{depth:null}),e.type){case"directive":this.directives.add(e.source,(t,s,r)=>{let i=an(e);i[0]+=t,this.onError(i,"BAD_DIRECTIVE",s,r)}),this.prelude.push(e.source),this.atDirectives=!0;break;case"document":{let t=Rh.composeDoc(this.options,this.directives,e,this.onError);this.atDirectives&&!t.directives.docStart&&this.onError(e,"MISSING_CHAR","Missing directives-end/doc-start indicator line"),this.decorate(t,!1),this.doc&&(yield this.doc),this.doc=t,this.atDirectives=!1;break}case"byte-order-mark":case"space":break;case"comment":case"newline":this.prelude.push(e.source);break;case"error":{let t=e.source?`${e.message}: ${JSON.stringify(e.source)}`:e.message,s=new on.YAMLParseError(an(e),"UNEXPECTED_TOKEN",t);this.atDirectives||!this.doc?this.errors.push(s):this.doc.errors.push(s);break}case"doc-end":{if(!this.doc){let s="Unexpected doc-end without preceding document";this.errors.push(new on.YAMLParseError(an(e),"UNEXPECTED_TOKEN",s));break}this.doc.directives.docEnd=!0;let t=xh.resolveEnd(e.end,e.offset+e.source.length,this.doc.options.strict,this.onError);if(this.decorate(this.doc,!0),t.comment){let s=this.doc.comment;this.doc.comment=s?`${s}
108
+ ${t.comment}`:t.comment}this.doc.range[2]=t.offset;break}default:this.errors.push(new on.YAMLParseError(an(e),"UNEXPECTED_TOKEN",`Unsupported token ${e.type}`))}}*end(e=!1,t=-1){if(this.doc)this.decorate(this.doc,!0),yield this.doc,this.doc=null;else if(e){let s=Object.assign({_directives:this.directives},this.options),r=new qh.Document(void 0,s);this.atDirectives&&this.onError(t,"MISSING_CHAR","Missing directives-end indicator line"),r.range=[0,t,t],this.decorate(r,!1),yield r}}};Uc.Composer=Ei});var Vc=S(gs=>{"use strict";p();var Mh=ki(),Dh=Si(),Kh=sn(),Fc=Gt();function Bh(n,e=!0,t){if(n){let s=(r,i,o)=>{let a=typeof r=="number"?r:Array.isArray(r)?r[0]:r.offset;if(t)t(a,i,o);else throw new Kh.YAMLParseError([a,a+1],i,o)};switch(n.type){case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":return Dh.resolveFlowScalar(n,e,s);case"block-scalar":return Mh.resolveBlockScalar({options:{strict:e}},n,s)}}return null}function Gh(n,e){let{implicitKey:t=!1,indent:s,inFlow:r=!1,offset:i=-1,type:o="PLAIN"}=e,a=Fc.stringifyString({type:o,value:n},{implicitKey:t,indent:s>0?" ".repeat(s):"",inFlow:r,options:{blockQuote:!0,lineWidth:-1}}),c=e.end??[{type:"newline",offset:-1,indent:s,source:`
109
+ `}];switch(a[0]){case"|":case">":{let l=a.indexOf(`
110
+ `),d=a.substring(0,l),u=a.substring(l+1)+`
111
+ `,f=[{type:"block-scalar-header",offset:i,indent:s,source:d}];return Yc(f,c)||f.push({type:"newline",offset:-1,indent:s,source:`
112
+ `}),{type:"block-scalar",offset:i,indent:s,props:f,source:u}}case'"':return{type:"double-quoted-scalar",offset:i,indent:s,source:a,end:c};case"'":return{type:"single-quoted-scalar",offset:i,indent:s,source:a,end:c};default:return{type:"scalar",offset:i,indent:s,source:a,end:c}}}function Uh(n,e,t={}){let{afterKey:s=!1,implicitKey:r=!1,inFlow:i=!1,type:o}=t,a="indent"in n?n.indent:null;if(s&&typeof a=="number"&&(a+=2),!o)switch(n.type){case"single-quoted-scalar":o="QUOTE_SINGLE";break;case"double-quoted-scalar":o="QUOTE_DOUBLE";break;case"block-scalar":{let l=n.props[0];if(l.type!=="block-scalar-header")throw new Error("Invalid block scalar header");o=l.source[0]===">"?"BLOCK_FOLDED":"BLOCK_LITERAL";break}default:o="PLAIN"}let c=Fc.stringifyString({type:o,value:e},{implicitKey:r||a===null,indent:a!==null&&a>0?" ".repeat(a):"",inFlow:i,options:{blockQuote:!0,lineWidth:-1}});switch(c[0]){case"|":case">":Fh(n,c);break;case'"':Ci(n,c,"double-quoted-scalar");break;case"'":Ci(n,c,"single-quoted-scalar");break;default:Ci(n,c,"scalar")}}function Fh(n,e){let t=e.indexOf(`
113
+ `),s=e.substring(0,t),r=e.substring(t+1)+`
114
+ `;if(n.type==="block-scalar"){let i=n.props[0];if(i.type!=="block-scalar-header")throw new Error("Invalid block scalar header");i.source=s,n.source=r}else{let{offset:i}=n,o="indent"in n?n.indent:-1,a=[{type:"block-scalar-header",offset:i,indent:o,source:s}];Yc(a,"end"in n?n.end:void 0)||a.push({type:"newline",offset:-1,indent:o,source:`
115
+ `});for(let c of Object.keys(n))c!=="type"&&c!=="offset"&&delete n[c];Object.assign(n,{type:"block-scalar",indent:o,props:a,source:r})}}function Yc(n,e){if(e)for(let t of e)switch(t.type){case"space":case"comment":n.push(t);break;case"newline":return n.push(t),!0}return!1}function Ci(n,e,t){switch(n.type){case"scalar":case"double-quoted-scalar":case"single-quoted-scalar":n.type=t,n.source=e;break;case"block-scalar":{let s=n.props.slice(1),r=e.length;n.props[0].type==="block-scalar-header"&&(r-=n.props[0].source.length);for(let i of s)i.offset+=r;delete n.props,Object.assign(n,{type:t,source:e,end:s});break}case"block-map":case"block-seq":{let r={type:"newline",offset:n.offset+e.length,indent:n.indent,source:`
116
+ `};delete n.items,Object.assign(n,{type:t,source:e,end:[r]});break}default:{let s="indent"in n?n.indent:-1,r="end"in n&&Array.isArray(n.end)?n.end.filter(i=>i.type==="space"||i.type==="comment"||i.type==="newline"):[];for(let i of Object.keys(n))i!=="type"&&i!=="offset"&&delete n[i];Object.assign(n,{type:t,indent:s,source:e,end:r})}}}gs.createScalarToken=Gh;gs.resolveAsScalar=Bh;gs.setScalarValue=Uh});var Wc=S(Jc=>{"use strict";p();var Yh=n=>"type"in n?ws(n):ys(n);function ws(n){switch(n.type){case"block-scalar":{let e="";for(let t of n.props)e+=ws(t);return e+n.source}case"block-map":case"block-seq":{let e="";for(let t of n.items)e+=ys(t);return e}case"flow-collection":{let e=n.start.source;for(let t of n.items)e+=ys(t);for(let t of n.end)e+=t.source;return e}case"document":{let e=ys(n);if(n.end)for(let t of n.end)e+=t.source;return e}default:{let e=n.source;if("end"in n&&n.end)for(let t of n.end)e+=t.source;return e}}}function ys({start:n,key:e,sep:t,value:s}){let r="";for(let i of n)r+=i.source;if(e&&(r+=ws(e)),t)for(let i of t)r+=i.source;return s&&(r+=ws(s)),r}Jc.stringify=Yh});var Xc=S(Qc=>{"use strict";p();var _i=Symbol("break visit"),Vh=Symbol("skip children"),zc=Symbol("remove item");function ze(n,e){"type"in n&&n.type==="document"&&(n={start:n.start,value:n.value}),Hc(Object.freeze([]),n,e)}ze.BREAK=_i;ze.SKIP=Vh;ze.REMOVE=zc;ze.itemAtPath=(n,e)=>{let t=n;for(let[s,r]of e){let i=t?.[s];if(i&&"items"in i)t=i.items[r];else return}return t};ze.parentCollection=(n,e)=>{let t=ze.itemAtPath(n,e.slice(0,-1)),s=e[e.length-1][0],r=t?.[s];if(r&&"items"in r)return r;throw new Error("Parent collection not found")};function Hc(n,e,t){let s=t(e,n);if(typeof s=="symbol")return s;for(let r of["key","value"]){let i=e[r];if(i&&"items"in i){for(let o=0;o<i.items.length;++o){let a=Hc(Object.freeze(n.concat([[r,o]])),i.items[o],t);if(typeof a=="number")o=a-1;else{if(a===_i)return _i;a===zc&&(i.items.splice(o,1),o-=1)}}typeof s=="function"&&r==="key"&&(s=s(e,n))}}return typeof s=="function"?s(e,n):s}Qc.visit=ze});var bs=S(ee=>{"use strict";p();var Ii=Vc(),Jh=Wc(),Wh=Xc(),Ti="\uFEFF",Oi="",Pi="",ji="",zh=n=>!!n&&"items"in n,Hh=n=>!!n&&(n.type==="scalar"||n.type==="single-quoted-scalar"||n.type==="double-quoted-scalar"||n.type==="block-scalar");function Qh(n){switch(n){case Ti:return"<BOM>";case Oi:return"<DOC>";case Pi:return"<FLOW_END>";case ji:return"<SCALAR>";default:return JSON.stringify(n)}}function Xh(n){switch(n){case Ti:return"byte-order-mark";case Oi:return"doc-mode";case Pi:return"flow-error-end";case ji:return"scalar";case"---":return"doc-start";case"...":return"doc-end";case"":case`
117
+ `:case`\r
118
+ `:return"newline";case"-":return"seq-item-ind";case"?":return"explicit-key-ind";case":":return"map-value-ind";case"{":return"flow-map-start";case"}":return"flow-map-end";case"[":return"flow-seq-start";case"]":return"flow-seq-end";case",":return"comma"}switch(n[0]){case" ":case" ":return"space";case"#":return"comment";case"%":return"directive-line";case"*":return"alias";case"&":return"anchor";case"!":return"tag";case"'":return"single-quoted-scalar";case'"':return"double-quoted-scalar";case"|":case">":return"block-scalar-header"}return null}ee.createScalarToken=Ii.createScalarToken;ee.resolveAsScalar=Ii.resolveAsScalar;ee.setScalarValue=Ii.setScalarValue;ee.stringify=Jh.stringify;ee.visit=Wh.visit;ee.BOM=Ti;ee.DOCUMENT=Oi;ee.FLOW_END=Pi;ee.SCALAR=ji;ee.isCollection=zh;ee.isScalar=Hh;ee.prettyToken=Qh;ee.tokenType=Xh});var Ri=S(el=>{"use strict";p();var cn=bs();function ae(n){switch(n){case void 0:case" ":case`
119
+ `:case"\r":case" ":return!0;default:return!1}}var Zc=new Set("0123456789ABCDEFabcdef"),Zh=new Set("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()"),ks=new Set(",[]{}"),em=new Set(` ,[]{}
120
+ \r `),Li=n=>!n||em.has(n),qi=class{constructor(){this.atEnd=!1,this.blockScalarIndent=-1,this.blockScalarKeep=!1,this.buffer="",this.flowKey=!1,this.flowLevel=0,this.indentNext=0,this.indentValue=0,this.lineEndPos=null,this.next=null,this.pos=0}*lex(e,t=!1){if(e){if(typeof e!="string")throw TypeError("source is not a string");this.buffer=this.buffer?this.buffer+e:e,this.lineEndPos=null}this.atEnd=!t;let s=this.next??"stream";for(;s&&(t||this.hasChars(1));)s=yield*this.parseNext(s)}atLineEnd(){let e=this.pos,t=this.buffer[e];for(;t===" "||t===" ";)t=this.buffer[++e];return!t||t==="#"||t===`
121
+ `?!0:t==="\r"?this.buffer[e+1]===`
122
+ `:!1}charAt(e){return this.buffer[this.pos+e]}continueScalar(e){let t=this.buffer[e];if(this.indentNext>0){let s=0;for(;t===" ";)t=this.buffer[++s+e];if(t==="\r"){let r=this.buffer[s+e+1];if(r===`
123
+ `||!r&&!this.atEnd)return e+s+1}return t===`
124
+ `||s>=this.indentNext||!t&&!this.atEnd?e+s:-1}if(t==="-"||t==="."){let s=this.buffer.substr(e,3);if((s==="---"||s==="...")&&ae(this.buffer[e+3]))return-1}return e}getLine(){let e=this.lineEndPos;return(typeof e!="number"||e!==-1&&e<this.pos)&&(e=this.buffer.indexOf(`
125
+ `,this.pos),this.lineEndPos=e),e===-1?this.atEnd?this.buffer.substring(this.pos):null:(this.buffer[e-1]==="\r"&&(e-=1),this.buffer.substring(this.pos,e))}hasChars(e){return this.pos+e<=this.buffer.length}setNext(e){return this.buffer=this.buffer.substring(this.pos),this.pos=0,this.lineEndPos=null,this.next=e,null}peek(e){return this.buffer.substr(this.pos,e)}*parseNext(e){switch(e){case"stream":return yield*this.parseStream();case"line-start":return yield*this.parseLineStart();case"block-start":return yield*this.parseBlockStart();case"doc":return yield*this.parseDocument();case"flow":return yield*this.parseFlowCollection();case"quoted-scalar":return yield*this.parseQuotedScalar();case"block-scalar":return yield*this.parseBlockScalar();case"plain-scalar":return yield*this.parsePlainScalar()}}*parseStream(){let e=this.getLine();if(e===null)return this.setNext("stream");if(e[0]===cn.BOM&&(yield*this.pushCount(1),e=e.substring(1)),e[0]==="%"){let t=e.length,s=e.indexOf("#");for(;s!==-1;){let i=e[s-1];if(i===" "||i===" "){t=s-1;break}else s=e.indexOf("#",s+1)}for(;;){let i=e[t-1];if(i===" "||i===" ")t-=1;else break}let r=(yield*this.pushCount(t))+(yield*this.pushSpaces(!0));return yield*this.pushCount(e.length-r),this.pushNewline(),"stream"}if(this.atLineEnd()){let t=yield*this.pushSpaces(!0);return yield*this.pushCount(e.length-t),yield*this.pushNewline(),"stream"}return yield cn.DOCUMENT,yield*this.parseLineStart()}*parseLineStart(){let e=this.charAt(0);if(!e&&!this.atEnd)return this.setNext("line-start");if(e==="-"||e==="."){if(!this.atEnd&&!this.hasChars(4))return this.setNext("line-start");let t=this.peek(3);if((t==="---"||t==="...")&&ae(this.charAt(3)))return yield*this.pushCount(3),this.indentValue=0,this.indentNext=0,t==="---"?"doc":"stream"}return this.indentValue=yield*this.pushSpaces(!1),this.indentNext>this.indentValue&&!ae(this.charAt(1))&&(this.indentNext=this.indentValue),yield*this.parseBlockStart()}*parseBlockStart(){let[e,t]=this.peek(2);if(!t&&!this.atEnd)return this.setNext("block-start");if((e==="-"||e==="?"||e===":")&&ae(t)){let s=(yield*this.pushCount(1))+(yield*this.pushSpaces(!0));return this.indentNext=this.indentValue+1,this.indentValue+=s,yield*this.parseBlockStart()}return"doc"}*parseDocument(){yield*this.pushSpaces(!0);let e=this.getLine();if(e===null)return this.setNext("doc");let t=yield*this.pushIndicators();switch(e[t]){case"#":yield*this.pushCount(e.length-t);case void 0:return yield*this.pushNewline(),yield*this.parseLineStart();case"{":case"[":return yield*this.pushCount(1),this.flowKey=!1,this.flowLevel=1,"flow";case"}":case"]":return yield*this.pushCount(1),"doc";case"*":return yield*this.pushUntil(Li),"doc";case'"':case"'":return yield*this.parseQuotedScalar();case"|":case">":return t+=yield*this.parseBlockScalarHeader(),t+=yield*this.pushSpaces(!0),yield*this.pushCount(e.length-t),yield*this.pushNewline(),yield*this.parseBlockScalar();default:return yield*this.parsePlainScalar()}}*parseFlowCollection(){let e,t,s=-1;do e=yield*this.pushNewline(),e>0?(t=yield*this.pushSpaces(!1),this.indentValue=s=t):t=0,t+=yield*this.pushSpaces(!0);while(e+t>0);let r=this.getLine();if(r===null)return this.setNext("flow");if((s!==-1&&s<this.indentNext&&r[0]!=="#"||s===0&&(r.startsWith("---")||r.startsWith("..."))&&ae(r[3]))&&!(s===this.indentNext-1&&this.flowLevel===1&&(r[0]==="]"||r[0]==="}")))return this.flowLevel=0,yield cn.FLOW_END,yield*this.parseLineStart();let i=0;for(;r[i]===",";)i+=yield*this.pushCount(1),i+=yield*this.pushSpaces(!0),this.flowKey=!1;switch(i+=yield*this.pushIndicators(),r[i]){case void 0:return"flow";case"#":return yield*this.pushCount(r.length-i),"flow";case"{":case"[":return yield*this.pushCount(1),this.flowKey=!1,this.flowLevel+=1,"flow";case"}":case"]":return yield*this.pushCount(1),this.flowKey=!0,this.flowLevel-=1,this.flowLevel?"flow":"doc";case"*":return yield*this.pushUntil(Li),"flow";case'"':case"'":return this.flowKey=!0,yield*this.parseQuotedScalar();case":":{let o=this.charAt(1);if(this.flowKey||ae(o)||o===",")return this.flowKey=!1,yield*this.pushCount(1),yield*this.pushSpaces(!0),"flow"}default:return this.flowKey=!1,yield*this.parsePlainScalar()}}*parseQuotedScalar(){let e=this.charAt(0),t=this.buffer.indexOf(e,this.pos+1);if(e==="'")for(;t!==-1&&this.buffer[t+1]==="'";)t=this.buffer.indexOf("'",t+2);else for(;t!==-1;){let i=0;for(;this.buffer[t-1-i]==="\\";)i+=1;if(i%2===0)break;t=this.buffer.indexOf('"',t+1)}let s=this.buffer.substring(0,t),r=s.indexOf(`
126
+ `,this.pos);if(r!==-1){for(;r!==-1;){let i=this.continueScalar(r+1);if(i===-1)break;r=s.indexOf(`
127
+ `,i)}r!==-1&&(t=r-(s[r-1]==="\r"?2:1))}if(t===-1){if(!this.atEnd)return this.setNext("quoted-scalar");t=this.buffer.length}return yield*this.pushToIndex(t+1,!1),this.flowLevel?"flow":"doc"}*parseBlockScalarHeader(){this.blockScalarIndent=-1,this.blockScalarKeep=!1;let e=this.pos;for(;;){let t=this.buffer[++e];if(t==="+")this.blockScalarKeep=!0;else if(t>"0"&&t<="9")this.blockScalarIndent=Number(t)-1;else if(t!=="-")break}return yield*this.pushUntil(t=>ae(t)||t==="#")}*parseBlockScalar(){let e=this.pos-1,t=0,s;e:for(let i=this.pos;s=this.buffer[i];++i)switch(s){case" ":t+=1;break;case`
128
+ `:e=i,t=0;break;case"\r":{let o=this.buffer[i+1];if(!o&&!this.atEnd)return this.setNext("block-scalar");if(o===`
129
+ `)break}default:break e}if(!s&&!this.atEnd)return this.setNext("block-scalar");if(t>=this.indentNext){this.blockScalarIndent===-1?this.indentNext=t:this.indentNext=this.blockScalarIndent+(this.indentNext===0?1:this.indentNext);do{let i=this.continueScalar(e+1);if(i===-1)break;e=this.buffer.indexOf(`
130
+ `,i)}while(e!==-1);if(e===-1){if(!this.atEnd)return this.setNext("block-scalar");e=this.buffer.length}}let r=e+1;for(s=this.buffer[r];s===" ";)s=this.buffer[++r];if(s===" "){for(;s===" "||s===" "||s==="\r"||s===`
131
+ `;)s=this.buffer[++r];e=r-1}else if(!this.blockScalarKeep)do{let i=e-1,o=this.buffer[i];o==="\r"&&(o=this.buffer[--i]);let a=i;for(;o===" ";)o=this.buffer[--i];if(o===`
132
+ `&&i>=this.pos&&i+1+t>a)e=i;else break}while(!0);return yield cn.SCALAR,yield*this.pushToIndex(e+1,!0),yield*this.parseLineStart()}*parsePlainScalar(){let e=this.flowLevel>0,t=this.pos-1,s=this.pos-1,r;for(;r=this.buffer[++s];)if(r===":"){let i=this.buffer[s+1];if(ae(i)||e&&ks.has(i))break;t=s}else if(ae(r)){let i=this.buffer[s+1];if(r==="\r"&&(i===`
133
+ `?(s+=1,r=`
134
+ `,i=this.buffer[s+1]):t=s),i==="#"||e&&ks.has(i))break;if(r===`
135
+ `){let o=this.continueScalar(s+1);if(o===-1)break;s=Math.max(s,o-2)}}else{if(e&&ks.has(r))break;t=s}return!r&&!this.atEnd?this.setNext("plain-scalar"):(yield cn.SCALAR,yield*this.pushToIndex(t+1,!0),e?"flow":"doc")}*pushCount(e){return e>0?(yield this.buffer.substr(this.pos,e),this.pos+=e,e):0}*pushToIndex(e,t){let s=this.buffer.slice(this.pos,e);return s?(yield s,this.pos+=s.length,s.length):(t&&(yield""),0)}*pushIndicators(){switch(this.charAt(0)){case"!":return(yield*this.pushTag())+(yield*this.pushSpaces(!0))+(yield*this.pushIndicators());case"&":return(yield*this.pushUntil(Li))+(yield*this.pushSpaces(!0))+(yield*this.pushIndicators());case"-":case"?":case":":{let e=this.flowLevel>0,t=this.charAt(1);if(ae(t)||e&&ks.has(t))return e?this.flowKey&&(this.flowKey=!1):this.indentNext=this.indentValue+1,(yield*this.pushCount(1))+(yield*this.pushSpaces(!0))+(yield*this.pushIndicators())}}return 0}*pushTag(){if(this.charAt(1)==="<"){let e=this.pos+2,t=this.buffer[e];for(;!ae(t)&&t!==">";)t=this.buffer[++e];return yield*this.pushToIndex(t===">"?e+1:e,!1)}else{let e=this.pos+1,t=this.buffer[e];for(;t;)if(Zh.has(t))t=this.buffer[++e];else if(t==="%"&&Zc.has(this.buffer[e+1])&&Zc.has(this.buffer[e+2]))t=this.buffer[e+=3];else break;return yield*this.pushToIndex(e,!1)}}*pushNewline(){let e=this.buffer[this.pos];return e===`
136
+ `?yield*this.pushCount(1):e==="\r"&&this.charAt(1)===`
137
+ `?yield*this.pushCount(2):0}*pushSpaces(e){let t=this.pos-1,s;do s=this.buffer[++t];while(s===" "||e&&s===" ");let r=t-this.pos;return r>0&&(yield this.buffer.substr(this.pos,r),this.pos=t),r}*pushUntil(e){let t=this.pos,s=this.buffer[t];for(;!e(s);)s=this.buffer[++t];return yield*this.pushToIndex(t,!1)}};el.Lexer=qi});var Mi=S(tl=>{"use strict";p();var xi=class{constructor(){this.lineStarts=[],this.addNewLine=e=>this.lineStarts.push(e),this.linePos=e=>{let t=0,s=this.lineStarts.length;for(;t<s;){let i=t+s>>1;this.lineStarts[i]<e?t=i+1:s=i}if(this.lineStarts[t]===e)return{line:t+1,col:1};if(t===0)return{line:0,col:e};let r=this.lineStarts[t-1];return{line:t,col:e-r+1}}}};tl.LineCounter=xi});var Ki=S(ol=>{"use strict";p();var tm=vn("process"),nl=bs(),nm=Ri();function qe(n,e){for(let t=0;t<n.length;++t)if(n[t].type===e)return!0;return!1}function sl(n){for(let e=0;e<n.length;++e)switch(n[e].type){case"space":case"comment":case"newline":break;default:return e}return-1}function il(n){switch(n?.type){case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":case"flow-collection":return!0;default:return!1}}function $s(n){switch(n.type){case"document":return n.start;case"block-map":{let e=n.items[n.items.length-1];return e.sep??e.start}case"block-seq":return n.items[n.items.length-1].start;default:return[]}}function mt(n){if(n.length===0)return[];let e=n.length;e:for(;--e>=0;)switch(n[e].type){case"doc-start":case"explicit-key-ind":case"map-value-ind":case"seq-item-ind":case"newline":break e}for(;n[++e]?.type==="space";);return n.splice(e,n.length)}function rl(n){if(n.start.type==="flow-seq-start")for(let e of n.items)e.sep&&!e.value&&!qe(e.start,"explicit-key-ind")&&!qe(e.sep,"map-value-ind")&&(e.key&&(e.value=e.key),delete e.key,il(e.value)?e.value.end?Array.prototype.push.apply(e.value.end,e.sep):e.value.end=e.sep:Array.prototype.push.apply(e.start,e.sep),delete e.sep)}var Di=class{constructor(e){this.atNewLine=!0,this.atScalar=!1,this.indent=0,this.offset=0,this.onKeyLine=!1,this.stack=[],this.source="",this.type="",this.lexer=new nm.Lexer,this.onNewLine=e}*parse(e,t=!1){this.onNewLine&&this.offset===0&&this.onNewLine(0);for(let s of this.lexer.lex(e,t))yield*this.next(s);t||(yield*this.end())}*next(e){if(this.source=e,tm.env.LOG_TOKENS&&console.log("|",nl.prettyToken(e)),this.atScalar){this.atScalar=!1,yield*this.step(),this.offset+=e.length;return}let t=nl.tokenType(e);if(t)if(t==="scalar")this.atNewLine=!1,this.atScalar=!0,this.type="scalar";else{switch(this.type=t,yield*this.step(),t){case"newline":this.atNewLine=!0,this.indent=0,this.onNewLine&&this.onNewLine(this.offset+e.length);break;case"space":this.atNewLine&&e[0]===" "&&(this.indent+=e.length);break;case"explicit-key-ind":case"map-value-ind":case"seq-item-ind":this.atNewLine&&(this.indent+=e.length);break;case"doc-mode":case"flow-error-end":return;default:this.atNewLine=!1}this.offset+=e.length}else{let s=`Not a YAML token: ${e}`;yield*this.pop({type:"error",offset:this.offset,message:s,source:e}),this.offset+=e.length}}*end(){for(;this.stack.length>0;)yield*this.pop()}get sourceToken(){return{type:this.type,offset:this.offset,indent:this.indent,source:this.source}}*step(){let e=this.peek(1);if(this.type==="doc-end"&&(!e||e.type!=="doc-end")){for(;this.stack.length>0;)yield*this.pop();this.stack.push({type:"doc-end",offset:this.offset,source:this.source});return}if(!e)return yield*this.stream();switch(e.type){case"document":return yield*this.document(e);case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":return yield*this.scalar(e);case"block-scalar":return yield*this.blockScalar(e);case"block-map":return yield*this.blockMap(e);case"block-seq":return yield*this.blockSequence(e);case"flow-collection":return yield*this.flowCollection(e);case"doc-end":return yield*this.documentEnd(e)}yield*this.pop()}peek(e){return this.stack[this.stack.length-e]}*pop(e){let t=e??this.stack.pop();if(!t)yield{type:"error",offset:this.offset,source:"",message:"Tried to pop an empty stack"};else if(this.stack.length===0)yield t;else{let s=this.peek(1);switch(t.type==="block-scalar"?t.indent="indent"in s?s.indent:0:t.type==="flow-collection"&&s.type==="document"&&(t.indent=0),t.type==="flow-collection"&&rl(t),s.type){case"document":s.value=t;break;case"block-scalar":s.props.push(t);break;case"block-map":{let r=s.items[s.items.length-1];if(r.value){s.items.push({start:[],key:t,sep:[]}),this.onKeyLine=!0;return}else if(r.sep)r.value=t;else{Object.assign(r,{key:t,sep:[]}),this.onKeyLine=!r.explicitKey;return}break}case"block-seq":{let r=s.items[s.items.length-1];r.value?s.items.push({start:[],value:t}):r.value=t;break}case"flow-collection":{let r=s.items[s.items.length-1];!r||r.value?s.items.push({start:[],key:t,sep:[]}):r.sep?r.value=t:Object.assign(r,{key:t,sep:[]});return}default:yield*this.pop(),yield*this.pop(t)}if((s.type==="document"||s.type==="block-map"||s.type==="block-seq")&&(t.type==="block-map"||t.type==="block-seq")){let r=t.items[t.items.length-1];r&&!r.sep&&!r.value&&r.start.length>0&&sl(r.start)===-1&&(t.indent===0||r.start.every(i=>i.type!=="comment"||i.indent<t.indent))&&(s.type==="document"?s.end=r.start:s.items.push({start:r.start}),t.items.splice(-1,1))}}}*stream(){switch(this.type){case"directive-line":yield{type:"directive",offset:this.offset,source:this.source};return;case"byte-order-mark":case"space":case"comment":case"newline":yield this.sourceToken;return;case"doc-mode":case"doc-start":{let e={type:"document",offset:this.offset,start:[]};this.type==="doc-start"&&e.start.push(this.sourceToken),this.stack.push(e);return}}yield{type:"error",offset:this.offset,message:`Unexpected ${this.type} token in YAML stream`,source:this.source}}*document(e){if(e.value)return yield*this.lineEnd(e);switch(this.type){case"doc-start":{sl(e.start)!==-1?(yield*this.pop(),yield*this.step()):e.start.push(this.sourceToken);return}case"anchor":case"tag":case"space":case"comment":case"newline":e.start.push(this.sourceToken);return}let t=this.startBlockValue(e);t?this.stack.push(t):yield{type:"error",offset:this.offset,message:`Unexpected ${this.type} token in YAML document`,source:this.source}}*scalar(e){if(this.type==="map-value-ind"){let t=$s(this.peek(2)),s=mt(t),r;e.end?(r=e.end,r.push(this.sourceToken),delete e.end):r=[this.sourceToken];let i={type:"block-map",offset:e.offset,indent:e.indent,items:[{start:s,key:e,sep:r}]};this.onKeyLine=!0,this.stack[this.stack.length-1]=i}else yield*this.lineEnd(e)}*blockScalar(e){switch(this.type){case"space":case"comment":case"newline":e.props.push(this.sourceToken);return;case"scalar":if(e.source=this.source,this.atNewLine=!0,this.indent=0,this.onNewLine){let t=this.source.indexOf(`
138
+ `)+1;for(;t!==0;)this.onNewLine(this.offset+t),t=this.source.indexOf(`
139
+ `,t)+1}yield*this.pop();break;default:yield*this.pop(),yield*this.step()}}*blockMap(e){let t=e.items[e.items.length-1];switch(this.type){case"newline":if(this.onKeyLine=!1,t.value){let s="end"in t.value?t.value.end:void 0;(Array.isArray(s)?s[s.length-1]:void 0)?.type==="comment"?s?.push(this.sourceToken):e.items.push({start:[this.sourceToken]})}else t.sep?t.sep.push(this.sourceToken):t.start.push(this.sourceToken);return;case"space":case"comment":if(t.value)e.items.push({start:[this.sourceToken]});else if(t.sep)t.sep.push(this.sourceToken);else{if(this.atIndentedComment(t.start,e.indent)){let r=e.items[e.items.length-2]?.value?.end;if(Array.isArray(r)){Array.prototype.push.apply(r,t.start),r.push(this.sourceToken),e.items.pop();return}}t.start.push(this.sourceToken)}return}if(this.indent>=e.indent){let s=!this.onKeyLine&&this.indent===e.indent,r=s&&(t.sep||t.explicitKey)&&this.type!=="seq-item-ind",i=[];if(r&&t.sep&&!t.value){let o=[];for(let a=0;a<t.sep.length;++a){let c=t.sep[a];switch(c.type){case"newline":o.push(a);break;case"space":break;case"comment":c.indent>e.indent&&(o.length=0);break;default:o.length=0}}o.length>=2&&(i=t.sep.splice(o[1]))}switch(this.type){case"anchor":case"tag":r||t.value?(i.push(this.sourceToken),e.items.push({start:i}),this.onKeyLine=!0):t.sep?t.sep.push(this.sourceToken):t.start.push(this.sourceToken);return;case"explicit-key-ind":!t.sep&&!t.explicitKey?(t.start.push(this.sourceToken),t.explicitKey=!0):r||t.value?(i.push(this.sourceToken),e.items.push({start:i,explicitKey:!0})):this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken],explicitKey:!0}]}),this.onKeyLine=!0;return;case"map-value-ind":if(t.explicitKey)if(t.sep)if(t.value)e.items.push({start:[],key:null,sep:[this.sourceToken]});else if(qe(t.sep,"map-value-ind"))this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:i,key:null,sep:[this.sourceToken]}]});else if(il(t.key)&&!qe(t.sep,"newline")){let o=mt(t.start),a=t.key,c=t.sep;c.push(this.sourceToken),delete t.key,delete t.sep,this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:o,key:a,sep:c}]})}else i.length>0?t.sep=t.sep.concat(i,this.sourceToken):t.sep.push(this.sourceToken);else if(qe(t.start,"newline"))Object.assign(t,{key:null,sep:[this.sourceToken]});else{let o=mt(t.start);this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:o,key:null,sep:[this.sourceToken]}]})}else t.sep?t.value||r?e.items.push({start:i,key:null,sep:[this.sourceToken]}):qe(t.sep,"map-value-ind")?this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:[],key:null,sep:[this.sourceToken]}]}):t.sep.push(this.sourceToken):Object.assign(t,{key:null,sep:[this.sourceToken]});this.onKeyLine=!0;return;case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":{let o=this.flowScalar(this.type);r||t.value?(e.items.push({start:i,key:o,sep:[]}),this.onKeyLine=!0):t.sep?this.stack.push(o):(Object.assign(t,{key:o,sep:[]}),this.onKeyLine=!0);return}default:{let o=this.startBlockValue(e);if(o){if(o.type==="block-seq"){if(!t.explicitKey&&t.sep&&!qe(t.sep,"newline")){yield*this.pop({type:"error",offset:this.offset,message:"Unexpected block-seq-ind on same line with key",source:this.source});return}}else s&&e.items.push({start:i});this.stack.push(o);return}}}}yield*this.pop(),yield*this.step()}*blockSequence(e){let t=e.items[e.items.length-1];switch(this.type){case"newline":if(t.value){let s="end"in t.value?t.value.end:void 0;(Array.isArray(s)?s[s.length-1]:void 0)?.type==="comment"?s?.push(this.sourceToken):e.items.push({start:[this.sourceToken]})}else t.start.push(this.sourceToken);return;case"space":case"comment":if(t.value)e.items.push({start:[this.sourceToken]});else{if(this.atIndentedComment(t.start,e.indent)){let r=e.items[e.items.length-2]?.value?.end;if(Array.isArray(r)){Array.prototype.push.apply(r,t.start),r.push(this.sourceToken),e.items.pop();return}}t.start.push(this.sourceToken)}return;case"anchor":case"tag":if(t.value||this.indent<=e.indent)break;t.start.push(this.sourceToken);return;case"seq-item-ind":if(this.indent!==e.indent)break;t.value||qe(t.start,"seq-item-ind")?e.items.push({start:[this.sourceToken]}):t.start.push(this.sourceToken);return}if(this.indent>e.indent){let s=this.startBlockValue(e);if(s){this.stack.push(s);return}}yield*this.pop(),yield*this.step()}*flowCollection(e){let t=e.items[e.items.length-1];if(this.type==="flow-error-end"){let s;do yield*this.pop(),s=this.peek(1);while(s&&s.type==="flow-collection")}else if(e.end.length===0){switch(this.type){case"comma":case"explicit-key-ind":!t||t.sep?e.items.push({start:[this.sourceToken]}):t.start.push(this.sourceToken);return;case"map-value-ind":!t||t.value?e.items.push({start:[],key:null,sep:[this.sourceToken]}):t.sep?t.sep.push(this.sourceToken):Object.assign(t,{key:null,sep:[this.sourceToken]});return;case"space":case"comment":case"newline":case"anchor":case"tag":!t||t.value?e.items.push({start:[this.sourceToken]}):t.sep?t.sep.push(this.sourceToken):t.start.push(this.sourceToken);return;case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":{let r=this.flowScalar(this.type);!t||t.value?e.items.push({start:[],key:r,sep:[]}):t.sep?this.stack.push(r):Object.assign(t,{key:r,sep:[]});return}case"flow-map-end":case"flow-seq-end":e.end.push(this.sourceToken);return}let s=this.startBlockValue(e);s?this.stack.push(s):(yield*this.pop(),yield*this.step())}else{let s=this.peek(2);if(s.type==="block-map"&&(this.type==="map-value-ind"&&s.indent===e.indent||this.type==="newline"&&!s.items[s.items.length-1].sep))yield*this.pop(),yield*this.step();else if(this.type==="map-value-ind"&&s.type!=="flow-collection"){let r=$s(s),i=mt(r);rl(e);let o=e.end.splice(1,e.end.length);o.push(this.sourceToken);let a={type:"block-map",offset:e.offset,indent:e.indent,items:[{start:i,key:e,sep:o}]};this.onKeyLine=!0,this.stack[this.stack.length-1]=a}else yield*this.lineEnd(e)}}flowScalar(e){if(this.onNewLine){let t=this.source.indexOf(`
140
+ `)+1;for(;t!==0;)this.onNewLine(this.offset+t),t=this.source.indexOf(`
141
+ `,t)+1}return{type:e,offset:this.offset,indent:this.indent,source:this.source}}startBlockValue(e){switch(this.type){case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":return this.flowScalar(this.type);case"block-scalar-header":return{type:"block-scalar",offset:this.offset,indent:this.indent,props:[this.sourceToken],source:""};case"flow-map-start":case"flow-seq-start":return{type:"flow-collection",offset:this.offset,indent:this.indent,start:this.sourceToken,items:[],end:[]};case"seq-item-ind":return{type:"block-seq",offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken]}]};case"explicit-key-ind":{this.onKeyLine=!0;let t=$s(e),s=mt(t);return s.push(this.sourceToken),{type:"block-map",offset:this.offset,indent:this.indent,items:[{start:s,explicitKey:!0}]}}case"map-value-ind":{this.onKeyLine=!0;let t=$s(e),s=mt(t);return{type:"block-map",offset:this.offset,indent:this.indent,items:[{start:s,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(e,t){return this.type!=="comment"||this.indent<=t?!1:e.every(s=>s.type==="newline"||s.type==="space")}*documentEnd(e){this.type!=="doc-mode"&&(e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type==="newline"&&(yield*this.pop()))}*lineEnd(e){switch(this.type){case"comma":case"doc-start":case"doc-end":case"flow-seq-end":case"flow-map-end":case"map-value-ind":yield*this.pop(),yield*this.step();break;case"newline":this.onKeyLine=!1;default:e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type==="newline"&&(yield*this.pop())}}};ol.Parser=Di});var fl=S(un=>{"use strict";p();var al=Ni(),sm=en(),ln=sn(),rm=Ar(),im=R(),om=Mi(),cl=Ki();function ll(n){let e=n.prettyErrors!==!1;return{lineCounter:n.lineCounter||e&&new om.LineCounter||null,prettyErrors:e}}function am(n,e={}){let{lineCounter:t,prettyErrors:s}=ll(e),r=new cl.Parser(t?.addNewLine),i=new al.Composer(e),o=Array.from(i.compose(r.parse(n)));if(s&&t)for(let a of o)a.errors.forEach(ln.prettifyError(n,t)),a.warnings.forEach(ln.prettifyError(n,t));return o.length>0?o:Object.assign([],{empty:!0},i.streamInfo())}function ul(n,e={}){let{lineCounter:t,prettyErrors:s}=ll(e),r=new cl.Parser(t?.addNewLine),i=new al.Composer(e),o=null;for(let a of i.compose(r.parse(n),!0,n.length))if(!o)o=a;else if(o.options.logLevel!=="silent"){o.errors.push(new ln.YAMLParseError(a.range.slice(0,2),"MULTIPLE_DOCS","Source contains multiple documents; please use YAML.parseAllDocuments()"));break}return s&&t&&(o.errors.forEach(ln.prettifyError(n,t)),o.warnings.forEach(ln.prettifyError(n,t))),o}function cm(n,e,t){let s;typeof e=="function"?s=e:t===void 0&&e&&typeof e=="object"&&(t=e);let r=ul(n,t);if(!r)return null;if(r.warnings.forEach(i=>rm.warn(r.options.logLevel,i)),r.errors.length>0){if(r.options.logLevel!=="silent")throw r.errors[0];r.errors=[]}return r.toJS(Object.assign({reviver:s},t))}function lm(n,e,t){let s=null;if(typeof e=="function"||Array.isArray(e)?s=e:t===void 0&&e&&(t=e),typeof t=="string"&&(t=t.length),typeof t=="number"){let r=Math.round(t);t=r<1?void 0:r>8?{indent:8}:{indent:r}}if(n===void 0){let{keepUndefined:r}=t??e??{};if(!r)return}return im.isDocument(n)&&!s?n.toString(t):new sm.Document(n,s,t).toString(t)}un.parse=cm;un.parseAllDocuments=am;un.parseDocument=ul;un.stringify=lm});var pl=S(K=>{"use strict";p();var um=Ni(),fm=en(),dm=oi(),Bi=sn(),pm=xt(),Re=R(),hm=Oe(),mm=Y(),gm=je(),ym=Le(),wm=bs(),bm=Ri(),km=Mi(),$m=Ki(),Ss=fl(),dl=jt();K.Composer=um.Composer;K.Document=fm.Document;K.Schema=dm.Schema;K.YAMLError=Bi.YAMLError;K.YAMLParseError=Bi.YAMLParseError;K.YAMLWarning=Bi.YAMLWarning;K.Alias=pm.Alias;K.isAlias=Re.isAlias;K.isCollection=Re.isCollection;K.isDocument=Re.isDocument;K.isMap=Re.isMap;K.isNode=Re.isNode;K.isPair=Re.isPair;K.isScalar=Re.isScalar;K.isSeq=Re.isSeq;K.Pair=hm.Pair;K.Scalar=mm.Scalar;K.YAMLMap=gm.YAMLMap;K.YAMLSeq=ym.YAMLSeq;K.CST=wm;K.Lexer=bm.Lexer;K.LineCounter=km.LineCounter;K.Parser=$m.Parser;K.parse=Ss.parse;K.parseAllDocuments=Ss.parseAllDocuments;K.parseDocument=Ss.parseDocument;K.stringify=Ss.stringify;K.visit=dl.visit;K.visitAsync=dl.visitAsync});p();import{parseArgs as _g}from"node:util";p();import{existsSync as zm,readFileSync as Hm}from"node:fs";import{join as Qm}from"node:path";p();p();p();function go(n,e,t=s=>s.length>0&&s.length<=100){let s=[];if(typeof n!="object"||n===null||Array.isArray(n))return{rule:null,problems:[`${e}: rows should map a field to a value, e.g. rows: { rep_email: $me }.`]};let r=Object.entries(n);r.length||s.push(`${e}: rows is empty. Leave it out to grant every row.`);let i={},o=a=>typeof a=="string"||typeof a=="number"||typeof a=="boolean";for(let[a,c]of r)t(a)||s.push(`${e}: "${a}" isn't a field name rows can use.`),Array.isArray(c)?!c.length||!c.every(o)?s.push(`${e}.${a}: give one value, or a list of values, e.g. [won, lost].`):i[a]=[...new Set(c.map(l=>typeof l=="string"?l.trim():l))].sort((l,d)=>String(l).localeCompare(String(d))):o(c)?i[a]=typeof c=="string"?c.trim():c:s.push(`${e}.${a}: give a value (text, a number, true/false or $me), or a list of them.`);return{rule:s.length?null:i,problems:s}}var An="*";p();p();var le=[{id:"claude-code",name:"Claude Code",where:"terminal and IDEs",documents:["https://claude.ai/oauth/claude-code-client-metadata"]},{id:"claude",name:"Claude",where:"claude.ai, desktop and mobile apps",documents:["https://claude.ai/oauth/mcp-oauth-client-metadata"]},{id:"codex",name:"Codex",where:"OpenAI's CLI and IDE extension",documents:["https://chatgpt.com/oauth/codex/client.json","https://chatgpt.com/oauth/codex/*/client.json"]},{id:"vscode",name:"VS Code",where:"GitHub Copilot's agent mode",documents:["https://vscode.dev/oauth/client-metadata.json"]},{id:"cursor",name:"Cursor",where:"Cursor's editor and cloud agents",documents:["https://cursor.com/oauth/mcp-client.json"]},{id:"lovable",name:"Lovable",where:"Lovable's workspace connectors",documents:["https://api.lovable.dev/.well-known/oauth-client"]},{id:"chatgpt",name:"ChatGPT",where:"chatgpt.com connectors",documents:[],notYet:"signs in without a metadata document"},{id:"replit",name:"Replit",where:"Replit Agent's MCP servers",documents:[],notYet:"signs in without a metadata document"},{id:"bolt",name:"Bolt",where:"Bolt's connectors",documents:[],notYet:"signs in without a metadata document"},{id:"v0",name:"v0",where:"Vercel's v0",documents:[],notYet:"custom MCP sign-in unconfirmed"}],yo=le.filter(n=>!n.notYet),Ne=["claude-code","claude"],wo=new Map(le.map(n=>[n.id,n])),En=n=>wo.get(n);function bo(n){let e;try{e=new URL(n)}catch{return!1}return e.protocol==="https:"&&e.pathname.length>1&&!e.hash&&!e.username&&!e.password&&e.href===n}var It=n=>wo.get(n)?.name??n;var xu="*",rt=class extends Error{name="PolicyFileError";problems;constructor(e){super(`policy.yaml has ${e.length===1?"a problem":`${e.length} problems`}:
142
+ ${e.map(t=>` - ${t}`).join(`
143
+ `)}`),this.problems=e}},Mu=new Set(["Viewer","Builder","Admin"]),ko=new Set(["notion","postgres"]),$o=/^[A-Za-z_][A-Za-z0-9_]{0,62}$/,Du=/^[a-z][a-z0-9-]{1,30}$/,Ku=/^[a-z][a-z0-9_-]{0,40}$/,Bu=/^(?:projects\/[a-z][a-z0-9-]{4,28}[a-z0-9]\/secrets\/)?[A-Za-z0-9_-]{1,255}$/,Gu=n=>/^(ntn_|secret_|sk-|sk_live_|sk_test_|rk_live_|ghp_|gho_|github_pat_|xox[abpr]-|AKIA|ASIA|AIza|ya29\.)/.test(n)||n.length>=32&&/[A-Z]/.test(n)&&/[a-z]/.test(n)&&/[0-9]/.test(n)&&!/[-_].*[-_]/.test(n),Uu=n=>{let e=n.split("/").pop();return e.startsWith("kuriko-")&&!e.startsWith("kuriko-connector-")},Fu=new Set(["roles","connectors","access","clients"]);function So(n){let e=n.trim();return e.toLowerCase()==="everyone"?An:e.includes("@")?e.toLowerCase():e}var Ot=n=>n===An?"everyone":n,st=n=>typeof n=="object"&&n!==null&&!Array.isArray(n),Tt=n=>[...new Set(n)].sort();function vo(n,e){let t=[],s={roles:[],connectors:[],grants:[],clients:[]};if(n==null&&(n={}),!st(n))throw new rt(["The file should be a map with roles, connectors, access and clients."]);for(let d of Object.keys(n))Fu.has(d)||t.push(`Unknown section "${d}" (expected roles, connectors, access, clients).`);let r=n.roles??{};if(!st(r))t.push("roles should map a group to Admin, Builder or Viewer.");else for(let[d,u]of Object.entries(r)){let f=So(d);f===An?t.push("roles: everyone can't be given a role (roles need a real group)."):typeof u!="string"||!Mu.has(u)?t.push(`roles: ${d} should be Admin, Builder or Viewer, not ${JSON.stringify(u)}.`):s.roles.some(h=>h.group===f)?t.push(`roles: ${d} is listed twice.`):s.roles.push({group:f,role:u})}let i=n.connectors??{},o=new Map,a=new Set;if(!st(i))t.push("connectors should map an id (e.g. notion) to its settings.");else for(let[d,u]of Object.entries(i)){let f=`connectors.${d}`;if(Du.test(d)||t.push(`${f}: the id should be lowercase letters, digits and dashes.`),!st(u)){t.push(`${f} should have a name and a kind.`);continue}let h=typeof u.kind=="string"&&ko.has(u.kind)?u.kind:null;h||t.push(`${f}: kind should be one of ${[...ko].join(", ")}.`);let y=u.credentials==="per-person";u.credentials!==void 0&&u.credentials!=="shared"&&!y&&t.push(`${f}: credentials should be shared or per-person.`),y&&h!=="notion"&&t.push(`${f}: only notion can be per-person so far.`);let m=new Set(h==="notion"?["name","kind","secret","resources","credentials",...y?["oauth_client_id"]:[]]:h==="postgres"?["name","kind","secret","schema","credentials"]:["name","kind"]);for(let E of Object.keys(u))m.has(E)||t.push(`${f}: unknown setting "${E}".`);let w=typeof u.name=="string"&&u.name.trim()?u.name.trim():null;w||t.push(`${f}: needs a name.`);let A=null;if(h==="notion"||h==="postgres"){let E=y?"the OAuth client secret":h==="postgres"?"the connection URL":"the integration token";typeof u.secret!="string"||!Bu.test(u.secret)?t.push(`${f}: secret should name the secret in Secret Manager holding ${E} (e.g. warehouse-readonly, or projects/<project>/secrets/<name>), never the secret itself.`):Gu(u.secret.split("/").pop())?t.push(`${f}: secret looks like a credential itself. Put it in Secret Manager and name the secret here instead (then rotate it: it's been in this file).`):Uu(u.secret)?t.push(`${f}: ${u.secret} is one of Kuriko's own secrets; a data source needs its own credential.`):A=u.secret}let $={};if(h==="notion"){let E=u.resources??{};if(!st(E))t.push(`${f}.resources should map a name tools use to a Notion data source ID.`);else{for(let[N,g]of Object.entries(E))Ku.test(N)||t.push(`${f}.resources: "${N}" should be lowercase letters, digits, - and _.`),(typeof g!="string"||g.trim().length<8)&&t.push(`${f}.resources.${N} should be a Notion data source ID.`);$={resources:Object.fromEntries(Object.entries(E).map(([N,g])=>[N,String(g).trim()]).sort(([N],[g])=>N.localeCompare(g)))},o.set(d,new Set(Object.keys(E)))}y&&(typeof u.oauth_client_id!="string"||!/^[A-Za-z0-9-]{8,100}$/.test(u.oauth_client_id)?t.push(`${f}: oauth_client_id should be the OAuth client ID of your Notion public integration.`):$.oauthClientId=u.oauth_client_id)}else h==="postgres"&&(u.schema!==void 0&&(typeof u.schema!="string"||!u.schema)&&t.push(`${f}.schema should be a schema name.`),$={schema:typeof u.schema=="string"&&u.schema?u.schema:"public"},o.set(d,null),a.add(d));w&&h&&A&&s.connectors.push({id:d,name:w,kind:h,config:$,mode:y?"delegated":"service",secretRef:e(A)})}let c=n.access??[];Array.isArray(c)?c.forEach((d,u)=>{let f=`access[${u+1}]`;if(!st(d))return void t.push(`${f} should have group, connector, resources and access.`);for(let g of Object.keys(d))["group","connector","resources","access","mask","rows"].includes(g)||t.push(`${f}: unknown setting "${g}".`);let h=typeof d.group=="string"&&d.group.trim()?So(d.group):null;h||t.push(`${f}: needs a group (a group email, or everyone).`);let y=typeof d.connector=="string"?d.connector:"";o.has(y)||t.push(`${f}: there's no connector "${y}" in connectors.`);let m=Array.isArray(d.resources)?d.resources.filter(g=>typeof g=="string"):typeof d.resources=="string"?[d.resources]:[];(!m.length||Array.isArray(d.resources)&&m.length!==d.resources.length)&&t.push(`${f}: resources should list what's granted, e.g. [interviews].`);let w=o.get(y);if(w)for(let g of m)w.has(g)||t.push(`${f}: ${y} has no resource "${g}" (it has: ${[...w].join(", ")||"none"}).`);if(w===null)for(let g of m)g!==xu&&!$o.test(g)&&t.push(`${f}: "${g}" isn't a table name (or "*" for every table).`);a.has(y)&&d.access==="write"&&t.push(`${f}: ${y} is read-only in Kuriko; use access: read.`),d.access!=="read"&&d.access!=="write"&&t.push(`${f}: access should be read or write (write includes read).`);let A=d.mask===void 0?[]:Array.isArray(d.mask)&&d.mask.every(g=>typeof g=="string")?d.mask:null;A||t.push(`${f}: mask should be a list of field names.`);let $=d.rows===void 0||d.rows===null?{rule:void 0,problems:[]}:go(d.rows,`${f}.rows`,w===null?g=>$o.test(g):void 0);if(t.push(...$.problems),!h||!y||!m.length||!A||$.rule===null||d.access!=="read"&&d.access!=="write")return;let E=s.grants.filter(g=>g.group===h&&g.connector===y&&g.access===d.access),N=m.filter(g=>E.some(O=>O.resources.includes(g)));if(N.length)return void t.push(`${f}: ${Ot(h)} already has ${d.access} on ${y}: ${N.join(", ")}. A table can be in one ${d.access} grant per group.`);if(E.some(g=>JSON.stringify(g.rows??null)===JSON.stringify($.rule??null)))return void t.push(`${f}: ${Ot(h)} already has ${d.access} on ${y}${$.rule?" with the same rows":""}; put the resources in one grant.`);s.grants.push({group:h,connector:y,resources:Tt(m),access:d.access,mask:Tt(A),...$.rule?{rows:$.rule}:{}})}):t.push("access should be a list of grants.");let l=n.clients===void 0||n.clients===null?[...Ne]:n.clients;if(Array.isArray(l)?l.forEach((d,u)=>{let f=`clients[${u+1}]`;if(typeof d!="string"||!d.trim())return void t.push(`${f} should be a client's name or its metadata document URL.`);let h=d.trim(),y=En(h);if(y?.notYet)return void t.push(`${f}: ${y.name} can't connect to Kuriko yet (${y.notYet}). Leave it commented out for now.`);if(!y&&!bo(h))return void t.push(/^https?:/.test(h)?`${f}: ${h} isn't a client metadata document URL (https, with a path).`:`${f}: Kuriko doesn't know a client called "${h}". Use one of ${yo.map(m=>m.id).join(", ")}, or the client's metadata document URL.`);if(s.clients.includes(h))return void t.push(`${f}: ${h} is listed twice.`);s.clients.push(h)}):t.push("clients should be a list, e.g. [claude-code, codex]."),t.length)throw new rt(t);return ar(s)}var Pt=n=>Array.isArray(n)?n.map(Pt):n&&typeof n=="object"?Object.fromEntries(Object.keys(n).sort().map(e=>[e,Pt(n[e])])):n;function ar(n){let e=t=>(s,r)=>t(s).localeCompare(t(r));return{roles:n.roles.map(({group:t,role:s})=>({group:t,role:s})).sort(e(t=>t.group)),connectors:n.connectors.map(({id:t,name:s,kind:r,mode:i,secretRef:o,config:a})=>({id:t,name:s,kind:r,mode:i,secretRef:o,config:Pt(a)})).sort(e(t=>t.id)),grants:n.grants.map(({group:t,connector:s,resources:r,access:i,mask:o,rows:a})=>({group:t,connector:s,resources:Tt(r),access:i,mask:Tt(o),...a?{rows:Pt(a)}:{}})).sort(e(Yu)),clients:Tt(n.clients??[...Ne])}}var Yu=n=>`${n.connector}\0${n.group}\0${n.access}\0${JSON.stringify(n.rows?Pt(n.rows):null)}`;function Ao(n,e){let t=[],s=a=>typeof a=="string"?a:JSON.stringify(a);for(let a of["name","kind","mode","secretRef"])n[a]!==e[a]&&t.push(`${a} ${s(n[a])} \u2192 ${s(e[a])}`);let r=(a,c="")=>Object.entries(a).flatMap(([l,d])=>d&&typeof d=="object"&&!Array.isArray(d)?r(d,`${c}${l}.`):[[`${c}${l}`,d]]),i=new Map(r(n.config)),o=new Map(r(e.config));for(let a of new Set([...i.keys(),...o.keys()]))JSON.stringify(i.get(a))!==JSON.stringify(o.get(a))&&t.push(`${a} ${i.has(a)?s(i.get(a)):"(none)"} \u2192 ${o.has(a)?s(o.get(a)):"(none)"}`);return t.length?t:["(settings differ only in form)"]}var Ge=(n,e)=>{let t=/^projects\/([^/]+)\/secrets\/(.+)$/.exec(n);return t&&(!e||t[1]===e)?t[2]:n};function Nn(n){switch(n.kind){case"role":return n.op==="add"?`${n.group} becomes ${n.to}`:n.op==="change"?`${n.group}: ${n.from} \u2192 ${n.to}`:`${n.group} is no longer ${n.from}`;case"connector":return`data source ${n.id}: ${n.summary}`;case"grant":return`${Ot(n.group)}: ${n.summary}`;case"client":return n.op==="add"?`people can connect with ${It(n.client)}`:`people can no longer connect with ${It(n.client)}`}}p();import{spawn as Vu}from"node:child_process";import{stripVTControlCharacters as Ju}from"node:util";var Q=class extends Error{command;code;stderr;constructor(e,t,s){let r=Ju(s);super(`${e} failed (exit ${t})${r.trim()?`:
144
+ ${r.trim().split(`
145
+ `).slice(-15).join(`
146
+ `)}`:""}`),this.command=e,this.code=t,this.stderr=r}get reason(){let e=this.stderr.split(`
147
+ `).map(t=>t.replace(/^[│╷╵\s]+/,"").trim()).filter(Boolean);return e.find(t=>/^error\b/i.test(t))?.replace(/^error:?\s*/i,"")??e[0]??`exit ${this.code}`}},Eo=n=>/invalid_rapt|reauth related error|invalid_grant|Reauthentication (is )?(required|failed)/i.test(n);function j(n,e,t={}){return new Promise((s,r)=>{let i=n==="gcloud"&&!t.inherit?{CLOUDSDK_CORE_DISABLE_PROMPTS:"1"}:{},o=Vu(n,e,{cwd:t.cwd,env:{...process.env,...i,...t.env},stdio:t.inherit?"inherit":[t.input===void 0?"ignore":"pipe","pipe","pipe"]});t.input!==void 0&&o.stdin?.end(t.input);let a="",c="";o.stdout?.on("data",l=>(a+=l,t.tee&&process.stdout.write(l))),o.stderr?.on("data",l=>(c+=l,t.tee&&process.stderr.write(l))),o.on("error",l=>r(new Q(n,null,l.message))),o.on("close",l=>l===0?s(a):r(new Q(`${n} ${e[0]??""}`.trim(),l,c)))})}async function W(n,e,t={}){return JSON.parse(await j(n,e,t))}async function Ue(n,e="--version"){try{return await j(n,[e]),!0}catch{return!1}}p();var nr=Lu(pl(),1);import{existsSync as lo,readFileSync as uo,writeFileSync as pu}from"node:fs";import{join as fo}from"node:path";p();var dn="kuriko-idp-client-secret",fn={ring:"kuriko",key:"user-tokens"};var hl=["serviceusage.googleapis.com","cloudresourcemanager.googleapis.com","run.googleapis.com","sqladmin.googleapis.com","secretmanager.googleapis.com","cloudkms.googleapis.com","artifactregistry.googleapis.com","iam.googleapis.com","cloudidentity.googleapis.com","storage.googleapis.com","cloudbuild.googleapis.com","pubsub.googleapis.com"],ml=["module.kuriko.google_project_service.apis","module.kuriko.google_artifact_registry_repository.kuriko","module.kuriko.google_service_account.gateway","module.kuriko.google_service_account.web","module.kuriko.google_service_account.tools"],Sm=/^[a-z][a-z0-9-]{4,28}[a-z0-9]$/,Gi=n=>Sm.test(n),gl=n=>/^[a-z]+-[a-z]+\d+$/.test(n),yl=n=>/^\d+-[a-z0-9]+\.apps\.googleusercontent\.com$/.test(n),vs=n=>/^[^\s@'"\\]+@[^\s@'"\\]+\.[^\s@'"\\]+$/.test(n);function wl(n){let e=new Set(n);for(let t=0;;t++){let s=t===0?"kuriko":`kuriko-${t}`;if(!e.has(s))return s}}function bl(n){let e=/^(.*?)-(\d+)$/.exec(n);return e?`${e[1]}-${Number(e[2])+1}`:`${n}-1`}function kl(n){return/(failed to create instance|google_sql_database_instance)[\s\S]{0,400}(instanceAlreadyExists|already exists|reuse the name)/i.test(n)}function $l(n){return/IAM_PERMISSION_DENIED|SERVICE_DISABLED|has not been used in project|it is disabled|API .* not enabled|Permission '.*' denied/i.test(n)}var He=(n,e)=>{let t=`https://kuriko-web-${e}.${n.region}.run.app`;return{web:t,mcp:`https://kuriko-gateway-${e}.${n.region}.run.app/mcp`,redirect:`${t}/api/auth/sso/callback/idp`,newClient:`https://console.cloud.google.com/auth/clients/create?project=${n.project}`,registry:`${n.region}-docker.pkg.dev/${n.project}/kuriko`,webServiceAccount:`kuriko-web@${n.project}.iam.gserviceaccount.com`}},z=n=>JSON.stringify(n);function Sl(n,e,t,s=null,r=!!s){let i=s&&r?`${n.region}-docker.pkg.dev/${n.project}/kuriko-releases/${s.owner}`:`${n.region}-docker.pkg.dev/${n.project}/kuriko`;return`# Kuriko install for ${n.domain}, written by \`kuriko install\`. Holds no secrets.
148
+ terraform {
149
+ backend "gcs" {
150
+ bucket = ${z(t)}
151
+ prefix = "kuriko"
152
+ }
153
+ }
154
+
155
+ variable "version_tag" { type = string }
156
+ variable "idp_client_id" { type = string }
157
+ variable "db_instance_name" { type = string }${s?`
158
+ variable "release_token_version" { type = string }`:""}
159
+ # Only \`kuriko destroy\` turns this off, for the one apply just before it deletes everything.
160
+ variable "deletion_protection" {
161
+ type = bool
162
+ default = true
163
+ }
164
+
165
+ locals {
166
+ repo = ${z(i)}
167
+ }
168
+
169
+ module "kuriko" {
170
+ source = ${z(e)}
171
+ project_id = ${z(n.project)}
172
+ region = ${z(n.region)}
173
+ db_instance_name = var.db_instance_name
174
+ deletion_protection = var.deletion_protection
175
+ images = {
176
+ gateway = "\${local.repo}/gateway:\${var.version_tag}"
177
+ web = "\${local.repo}/web:\${var.version_tag}"
178
+ migrate = "\${local.repo}/web-migrate:\${var.version_tag}"
179
+ }
180
+ idp = {
181
+ issuer = "https://accounts.google.com"
182
+ client_id = var.idp_client_id
183
+ domain = ${z(n.domain)}
184
+ groups_source = "google-workspace"
185
+ }${s?`
186
+ release_registry = {
187
+ upstream = ${z(s.upstream)}
188
+ username = ${z(s.username)}
189
+ token_secret_name = ${z(s.tokenSecret)}
190
+ token_version = var.release_token_version
191
+ }`:""}
192
+ }
193
+
194
+ output "web_url" { value = module.kuriko.web_url }
195
+ output "mcp_url" { value = module.kuriko.mcp_url }
196
+ output "idp_redirect_uri" { value = module.kuriko.idp_redirect_uri }
197
+ output "web_service_account" { value = module.kuriko.web_service_account }
198
+ output "migrate_job" { value = module.kuriko.migrate_job }
199
+ `}function vl(n,e,t=null){return[`version_tag = ${z(e)}`,`idp_client_id = ${z(n.idpClientId??"")}`,`db_instance_name = ${z(n.dbInstanceName)}`,...t?[`release_token_version = ${z(t.tokenVersion)}`]:[],""].join(`
200
+ `)}var As="module.kuriko.google_sql_database_instance.kuriko";function Al(n,e){let t=`projects/${n.project}/locations/${n.region}/keyRings/${fn.ring}`;return["# Written by `kuriko install`: things already in the project that this install takes over.",...e.ring?[`import {
201
+ to = module.kuriko.google_kms_key_ring.kuriko
202
+ id = ${z(t)}
203
+ }`]:[],...e.key?[`import {
204
+ to = module.kuriko.google_kms_crypto_key.user_tokens
205
+ id = ${z(`${t}/cryptoKeys/${fn.key}`)}
206
+ }`]:[],...e.sqlInstance?[`import {
207
+ to = ${As}
208
+ id = ${z(`projects/${n.project}/instances/${e.sqlInstance}`)}
209
+ }`]:[]].join(`
210
+
211
+ `)+`
212
+ `}function Es(n){let e=[];for(let t of n.resource_changes??[]){let s=t.change.actions,r=s.includes("delete")&&s.includes("create")?"replace":s[0]==="create"||s[0]==="update"||s[0]==="delete"?s[0]:null;r&&e.push({address:t.address.replace(/^module\.kuriko\./,""),action:r})}return e}var Ns=new Set(["module.kuriko.google_project_iam_member.gateway_connector_secrets"]);function El(n){return(n.resource_changes??[]).filter(e=>e.change.actions.includes("delete")&&!(Ns.has(e.address)&&e.change.actions.length===1)).map(e=>e.address)}var vm={admins:["platform","infra","sre","devops","it","ops","security","secops","admin","admins","cloud","engineering-leads"],builders:["eng","engineering","engineers","dev","developers","product","builders","ops","operations","data","analytics","tech"]};function Nl(n,e,t=6){let s=vm[e],r=i=>{let o=`${i.email.split("@")[0]} ${i.name}`.toLowerCase().split(/[^a-z0-9]+/),a=s.findIndex(c=>o.includes(c));return a<0?1/0:a};return n.map(i=>({g:i,s:r(i)})).filter(i=>i.s!==1/0).sort((i,o)=>i.s-o.s||i.g.email.localeCompare(o.g.email)).slice(0,t).map(i=>i.g)}var Cl=(n,e)=>{let t=e.trim().toLowerCase();return n.filter(s=>s.email.includes(t)||s.name.toLowerCase().includes(t))};p();p();import{emitKeypressEvents as Il}from"node:readline";import{createInterface as Tl}from"node:readline/promises";import{Writable as Am}from"node:stream";import{stripVTControlCharacters as _l,styleText as bt}from"node:util";var C=n=>bt("bold",n),I=n=>bt("dim",n),de=n=>bt("red",n),xe=n=>bt("green",n),Qe=n=>bt("yellow",n),yt=n=>bt("cyan",n),Ol="\u280B\u2819\u2839\u2838\u283C\u2834\u2826\u2827\u2807\u280F",gt=null,Fi=null,Ui=null,Yi=0,Vi=!1,Ji=!1,Wi=()=>process.stdout.isTTY===!0;function Cs(n){let e=Math.floor((Date.now()-n)/1e3);return e<60?`${e}s`:`${Math.floor(e/60)}m ${String(e%60).padStart(2,"0")}s`}function Em(){let n=[gt&&`${gt.text} ${I(Cs(gt.start))}`,Fi?.()&&I(Fi())].filter(s=>!!s);if(!n.length)return null;let e=(process.stdout.columns||80)-1,t=`${yt(Ol[Yi])} ${n.join(I(" \xB7 "))}`;return _l(t).length<=e?t:_l(t).slice(0,e)}function _s(){Wi()&&Ji&&process.stdout.write("\r\x1B[2K"),Ji=!1}function wt(){if(!Wi()||Vi)return;_s();let n=Em();n&&(process.stdout.write(n),Ji=!0)}function Pl(){Ui||!Wi()||(Ui=setInterval(()=>{Yi=(Yi+1)%Ol.length,wt()},100),Ui.unref())}function pn(n){_s(),console.log(n),wt()}async function P(n,e){let t=gt;gt={text:n,start:Date.now()},Pl(),wt();try{return await e()}finally{gt=t,_s(),wt()}}function zi(n){Fi=n,Pl(),wt()}async function kt(n){Vi=!0,_s();try{return await n()}finally{Vi=!1,wt()}}var v=(n="")=>pn(n),q=n=>pn(`
213
+ ${C("\u2192")} ${n}`),T=n=>pn(` ${xe("\u2713")} ${n}`),M=n=>pn(` ${Qe("!")} ${n}`);function Is(){if(!process.stdin.isTTY)throw new Error("This needs answers typed at a terminal; run it in your own terminal, not through a pipe.")}async function te(n,e){return Is(),kt(async()=>{let t=Tl({input:process.stdin,output:process.stdout});try{return(await t.question(e?`${n} ${I(`[${e}]`)} `:`${n} `)).trim()||e||""}finally{t.close()}})}async function H(n,e=!1){let t=(await te(`${n} ${I(e?"[Y/n]":"[y/N]")}`)).toLowerCase();return t?t==="y"||t==="yes":e}async function Ts(n){return Is(),kt(()=>Nm(n))}async function Nm(n){let e=!1,t=new Am({write(r,i,o){e||process.stdout.write(r),o()}}),s=Tl({input:process.stdin,output:t,terminal:!0});try{let r=s.question(`${n} `);e=!0;let i=await r;return process.stdout.write(`
214
+ `),i.trim()}finally{s.close()}}async function ce(n,e){Is();let t=e.map((s,r)=>s.disabled?-1:r).filter(s=>s>=0);if(!t.length)throw new Error(`Nothing to choose for: ${n}`);return kt(()=>new Promise(s=>{let r=process.stdin,i=r.isRaw,o=t[0],a=(f,h)=>{let y=f.disabled?I(f.label):h===o?C(f.label):f.label;return`${h===o?yt(" \u203A"):" "} ${y}${f.hint?` ${I(f.hint)}`:""}`},c=f=>{f||process.stdout.write(`\x1B[${e.length}A`);for(let[h,y]of e.entries())process.stdout.write(`\r\x1B[2K${a(y,h)}
215
+ `)},l=f=>{let h=t.indexOf(o);o=t[(h+f+t.length)%t.length],c(!1)},d=()=>{r.off("keypress",u),r.setRawMode(i),r.pause(),process.stdout.write(`\x1B[${e.length+1}A\r\x1B[J${n} ${yt(e[o].label)}
216
+ `),s(e[o].value)},u=(f,h={})=>{if(h.ctrl&&h.name==="c"){r.setRawMode(i),process.stdout.write(`
217
+ `),process.kill(process.pid,"SIGINT");return}h.name==="up"||h.name==="k"?l(-1):h.name==="down"||h.name==="j"||h.name==="tab"?l(1):h.name==="return"||h.name==="enter"?d():f&&/^[1-9]$/.test(f)&&t.includes(Number(f)-1)&&(o=Number(f)-1,c(!1))};process.stdout.write(`${n} ${I("(\u2191/\u2193, Enter)")}
218
+ `),c(!0),Il(r),r.setRawMode(!0),r.resume(),r.on("keypress",u)}))}async function jl(n,e,t){Is();let s=e.map((r,i)=>r.disabled?-1:i).filter(r=>r>=0);if(!s.length)throw new Error(`Nothing to choose for: ${n}`);return kt(()=>new Promise(r=>{let i=process.stdin,o=i.isRaw,a=e.map(y=>!y.disabled&&t(y.value)),c=s[0],l=(y,m)=>y.disabled?` ${I(`\u25CB ${y.label}${y.hint?` ${y.hint}`:""}`)}`:`${m===c?yt(" \u203A"):" "} ${a[m]?xe("\u25C9"):I("\u25CB")} ${m===c?C(y.label):y.label}${y.hint?` ${I(y.hint)}`:""}`,d=y=>c=s[(s.indexOf(c)+y+s.length)%s.length],u=y=>{y||process.stdout.write(`\x1B[${e.length}A`);for(let[m,w]of e.entries())process.stdout.write(`\r\x1B[2K${l(w,m)}
219
+ `)},f=()=>{i.off("keypress",h),i.setRawMode(o),i.pause();let y=e.filter((m,w)=>a[w]);process.stdout.write(`\x1B[${e.length+1}A\r\x1B[J${n} ${yt(y.map(m=>m.label).join(", ")||"none")}
220
+ `),r(y.map(m=>m.value))},h=(y,m={})=>{if(m.ctrl&&m.name==="c"){i.setRawMode(o),process.stdout.write(`
221
+ `),process.kill(process.pid,"SIGINT");return}if(m.name==="up"||m.name==="k")d(-1);else if(m.name==="down"||m.name==="j"||m.name==="tab")d(1);else if(m.name==="space")a[c]=!a[c];else return m.name==="return"||m.name==="enter"?f():void 0;u(!1)};process.stdout.write(`${n} ${I("(\u2191/\u2193, Space to tick, Enter)")}
222
+ `),u(!0),Il(i),i.setRawMode(!0),i.resume(),i.on("keypress",h)}))}async function Hi(n,e){let t=e.filter(s=>!s.disabled);return t.length===1&&e.length===1?(v(`${n} ${yt(t[0].label)}`),t[0].value):ce(n,e)}function Xe(n,e){pn(`
223
+ ${C("\u270B")} ${C(n)}
224
+ ${e.map(t=>t?` ${t}`:"").join(`
225
+ `)}`)}var hn=async n=>{try{return await j("gcloud",n),!0}catch(e){if(e instanceof Q&&/NOT_FOUND|not found|does not exist|404/i.test(e.stderr))return!1;throw e}},$t=async()=>(await j("gcloud",["config","get","account"])).trim();async function X(n={}){let e=async t=>{try{return await j("gcloud",t),null}catch(s){return s instanceof Q&&Eo(s.stderr)?"expired":"missing"}};for(let t=!1;;t=!0){let[s,r]=await Promise.all([n.terraformOnly?null:e(["auth","print-access-token"]),e(["auth","application-default","print-access-token"])]);if(!s&&!r)return;let i=await $t().catch(()=>""),c=`${[s&&"gcloud",r&&"Terraform"].filter(Boolean).join(" and ")}${s==="expired"||r==="expired"?`'s Google sign-in${s&&r?"s have":" has"} expired`:` ${s&&r?"aren't":"isn't"} signed in to Google`}`,l=s?["auth","login",...i?[i]:[],"--force",...r?["--update-adc"]:[]]:["auth","application-default","login"];if(!t&&process.stdin.isTTY&&(M(`${c}.`),await H(` Sign in${i?` as ${i}`:""} now? (opens your browser)`,!0))){await kt(()=>j("gcloud",l,{inherit:!0}));continue}throw new Error(`${c}. Run:
226
+ gcloud ${l.join(" ")}`)}}async function St(){return(await W("gcloud",["organizations","list","--format=json"])).map(n=>({id:n.name.split("/")[1],name:n.displayName,customerId:n.owner?.directoryCustomerId??null}))}async function Ll(){return(await W("gcloud",["billing","accounts","list","--format=json"])).filter(n=>n.open).map(n=>({id:n.name.split("/")[1],name:n.displayName}))}async function Me(n){try{let e=await W("gcloud",["projects","describe",n,"--format=json"]);return{number:e.projectNumber,state:e.lifecycleState}}catch(e){if(e instanceof Q&&/not found|does not exist|permission/i.test(e.stderr))return null;throw e}}var ql=(n,e)=>j("gcloud",["projects","create",n,`--organization=${e}`,"--name=Kuriko"]);async function Rl(n){return(await W("gcloud",["billing","projects","describe",n,"--format=json"])).billingEnabled===!0}var xl=(n,e)=>j("gcloud",["billing","projects","link",n,`--billing-account=${e}`]),Ps=(n,e)=>j("gcloud",["services","enable",...e,`--project=${n}`]);async function Ml(n,e,t){return await hn(["storage","buckets","describe",`gs://${n}`,"--format=json"])?"exists":(await j("gcloud",["storage","buckets","create",`gs://${n}`,`--project=${e}`,`--location=${t}`,"--uniform-bucket-level-access","--public-access-prevention"]),await j("gcloud",["storage","buckets","update",`gs://${n}`,"--versioning"]),"created")}async function Dl(n){return(await W("gcloud",["sql","instances","list",`--project=${n}`,"--format=json"])).map(e=>({name:e.name,kuriko:e.settings?.userLabels?.["managed-by"]==="kuriko"}))}async function Kl(n,e,t,s){let r=[`--location=${e}`,`--project=${n}`,"--format=json"],i=await hn(["kms","keyrings","describe",t,...r]);return{ring:i,key:i&&await hn(["kms","keys","describe",s,`--keyring=${t}`,...r])}}async function Bl(n){return hn(["artifacts","docker","images","describe",n,"--format=json"])}async function mn(n,e){return await hn(["secrets","describe",e,`--project=${n}`,"--format=json"])?(await W("gcloud",["secrets","versions","list",e,`--project=${n}`,"--filter=state:ENABLED","--format=json"])).length>0:null}async function js(n,e,t){await mn(n,e)===null?await j("gcloud",["secrets","create",e,`--project=${n}`,"--replication-policy=automatic","--labels=managed-by=kuriko-security-team","--data-file=-"],{input:t}):await j("gcloud",["secrets","versions","add",e,`--project=${n}`,"--data-file=-"],{input:t})}async function Gl(n,e,t){try{let r=await(await fetch("https://oauth2.googleapis.com/token",{method:"POST",headers:{"content-type":"application/x-www-form-urlencoded"},body:new URLSearchParams({client_id:n,client_secret:e,code:"kuriko-install-check",redirect_uri:t,grant_type:"authorization_code"})})).json().catch(()=>({}));return r.error==="invalid_client"||r.error==="unauthorized_client"?!1:r.error==="invalid_grant"?!0:null}catch{return null}}async function Os(n,e,t){let s=(await j("gcloud",["auth","print-access-token"])).trim(),r=new URL(`https://cloudidentity.googleapis.com/v1/${e}`);for(let[o,a]of Object.entries(t))r.searchParams.set(o,a);let i=await fetch(r,{headers:{authorization:`Bearer ${s}`,"x-goog-user-project":n}});if(i.status===404||i.status===403)return null;if(!i.ok)throw new Error(`Cloud Identity ${i.status}: ${(await i.text()).slice(0,300)}`);return await i.json()}async function Ul(n,e,t,s){let r=(await j("gcloud",["auth","print-access-token"])).trim(),i=new URL(`https://cloudidentity.googleapis.com/v1/${e}`);for(let[a,c]of Object.entries(t))i.searchParams.set(a,c);let o=await fetch(i,{method:"POST",headers:{authorization:`Bearer ${r}`,"x-goog-user-project":n,"content-type":"application/json"},body:JSON.stringify(s)});return{status:o.status,text:await o.text()}}async function Fl(n,e){let t=await Ul(n,"groups",{initialGroupConfig:e.owner?"WITH_INITIAL_OWNER":"EMPTY"},{parent:`customers/${e.customerId}`,groupKey:{id:e.email},displayName:e.name,description:e.description,labels:{"cloudidentity.googleapis.com/groups.discussion_forum":""}});if(t.status===409)return"exists";if(t.status>=300)throw new Error(`Couldn't create ${e.email} (${t.status}): ${t.text.slice(0,300)}`);return"created"}async function Ls(n,e){let t=[],s="";do{let r=await Os(n,"groups",{parent:`customers/${e}`,view:"BASIC",pageSize:"500",...s?{pageToken:s}:{}});if(!r)return t.length?t:null;for(let i of r.groups??[])i.groupKey?.id&&t.push({email:i.groupKey.id.toLowerCase(),name:i.displayName??"",description:i.description??""});s=r.nextPageToken??""}while(s&&t.length<2e4);return t.sort((r,i)=>r.email.localeCompare(i.email))}async function Qi(n,e,t){let s=await Os(n,"groups:lookup",{"groupKey.id":e});if(!s?.name)throw new Error(`Group ${e} not found`);let r=await Ul(n,`${s.name}/memberships`,{},{preferredMemberKey:{id:t},roles:[{name:"MEMBER"}]});if(r.status===409)return"exists";if(r.status>=300)throw new Error(`Couldn't add ${t} to ${e} (${r.status}): ${r.text.slice(0,300)}`);return"added"}async function qs(n,e,t){let s=await Os(n,"groups:lookup",{"groupKey.id":e});if(!s?.name)return{exists:!1,isMember:!1};let r="";do{let i=await Os(n,`${s.name}/memberships:searchTransitiveMemberships`,{pageSize:"500",...r?{pageToken:r}:{}});if(i?.memberships?.some(o=>o.preferredMemberKey?.some(a=>a.id?.toLowerCase()===t.toLowerCase())))return{exists:!0,isMember:!0};r=i?.nextPageToken??""}while(r);return{exists:!0,isMember:!1}}async function vt(n,e,t,s){let r=[`--project=${n}`,`--region=${e}`],o=(await W("gcloud",["run","jobs","execute",t,...r,"--async","--format=json",...s?[`--args=^;;^${s.join(";;")}`]:[]])).metadata.name;for(;!(await W("gcloud",["run","jobs","executions","describe",o,...r,"--format=json"])).status?.completionTime;)await new Promise(c=>setTimeout(c,3e3));for(let a=0;a<12;a++){let l=(await W("gcloud",["logging","read",`resource.type="cloud_run_job" AND labels."run.googleapis.com/execution_name"="${o}"`,`--project=${n}`,"--freshness=1h","--order=asc","--format=json"])).map(u=>u.textPayload??"").filter(Boolean),d=l.map(u=>/Container called exit\((\d+)\)/.exec(u)).find(Boolean);if(d)return{code:Number(d[1]),logs:l.filter(u=>!/Container called exit/.test(u))};await new Promise(u=>setTimeout(u,5e3))}return{code:null,logs:[]}}async function Yl(n,e){return(await j("gcloud",["secrets","versions","list",e,`--project=${n}`,"--filter=state:ENABLED","--sort-by=~createTime","--limit=1","--format=value(name)"])).trim().split("/").pop()||null}async function Vl(n,e){return(await j("gcloud",["secrets","versions","access","latest",`--secret=${e}`,`--project=${n}`])).trim()}async function Xi(n,e){let t=(await j("gcloud",["auth","print-access-token"])).trim(),s=await fetch(`https://serviceusage.googleapis.com/v1beta1/projects/${n}/services/${e}:generateServiceIdentity`,{method:"POST",headers:{authorization:`Bearer ${t}`,"x-goog-user-project":n}});if(!s.ok)throw new Error(`Couldn't set up ${e}'s service account (${s.status}): ${(await s.text()).slice(0,200)}`)}async function Jl(n,e,t,s,r){try{let i=`${n.owner}/${s}`,o=Buffer.from(`${e}:${t}`).toString("base64"),a=await fetch(`https://${n.host}/token?service=${n.host}&scope=repository:${i}:pull`,{headers:{authorization:`Basic ${o}`}});if(a.status===401||a.status===403)return"denied";if(!a.ok)return"unreachable";let{token:c}=await a.json(),l=await fetch(`https://${n.host}/v2/${i}/manifests/${r}`,{method:"HEAD",headers:{authorization:`Bearer ${c}`,accept:"application/vnd.oci.image.index.v1+json, application/vnd.oci.image.manifest.v1+json, application/vnd.docker.distribution.manifest.v2+json, application/vnd.docker.distribution.manifest.list.v2+json"}});return l.ok?"ok":l.status===401||l.status===403?"denied":l.status===404?"missing":"unreachable"}catch{return"unreachable"}}var Zi="roles/secretmanager.secretAccessor",Rs=n=>{let e=/^projects\/([^/]+)\/secrets\/([^/]+)$/.exec(n);if(!e)throw new Error(`Not a secret reference: ${n}`);return[e[1],e[2]]};async function gn(n){let[e,t]=Rs(n);return j("gcloud",["secrets","describe",t,`--project=${e}`,"--format=value(name)"]).then(()=>!0,()=>!1)}async function yn(n,e){let[t,s]=Rs(n);return!!(await W("gcloud",["secrets","get-iam-policy",s,`--project=${t}`,"--format=json"])).bindings?.some(i=>i.role===Zi&&!i.condition&&i.members?.includes(e))}async function eo(n,e){let[t,s]=Rs(n);await j("gcloud",["secrets","add-iam-policy-binding",s,`--project=${t}`,`--member=${e}`,`--role=${Zi}`,"--condition=None","--format=none"])}async function Wl(n,e){let[t,s]=Rs(n);await gn(n)&&await yn(n,e)&&await j("gcloud",["secrets","remove-iam-policy-binding",s,`--project=${t}`,`--member=${e}`,`--role=${Zi}`,"--condition=None","--format=none"])}p();import{relative as Om}from"node:path";p();import{existsSync as xs,readdirSync as Cm,readFileSync as Ks}from"node:fs";import{homedir as _m}from"node:os";import{dirname as to,join as be,relative as Im,resolve as Ms}from"node:path";import{fileURLToPath as Tm}from"node:url";var ne=Ms(Tm(new URL("../../..",import.meta.url))),Ds="kuriko-installs.json";function ke(n=process.cwd(),e=process.env){for(let t=Ms(n);;t=to(t)){if(xs(be(t,Ds)))return t;if(to(t)===t)break}for(let t of[e.KURIKO_INSTALLS,be(to(ne),"kuriko-installs")])if(t&&xs(be(t,Ds)))return Ms(t);return null}var Bs=`No installs repo found. Installs live in a git repo you share with whoever runs Kuriko:
227
+ clone yours next to the Kuriko checkout (or cd into it), or start one with: kuriko init <folder>`;function pe(n=process.cwd()){let e=ke(n);if(!e)throw new Error(Bs);return e}function bn(n,e=process.cwd(),t=ke(e)){if(n){let r=[Ms(e,n),t&&be(t,n)].find(i=>!!i&&no(i));if(!r)throw new Error(`No Kuriko install at ${n}. Run kuriko list to see them.`);return r}let s=Ze(e,t);if(s.length===1)return s[0];throw s.length>1?new Error(`Several installs; choose one with --dir:
228
+ ${s.map(r=>` ${r}`).join(`
229
+ `)}`):new Error(t?"No Kuriko installs yet. Start one with: kuriko install":Bs)}function Ze(n=process.cwd(),e=ke(n)){return no(n)?[n]:!e||!xs(e)?[]:Cm(e).sort().map(t=>be(e,t)).filter(no)}function U(n,e=process.cwd()){let t=Im(e,n);if(t&&!t.startsWith(".."))return t;let s=_m();return n.startsWith(s)?`~${n.slice(s.length)}`:n}function zl(n){let e=Ks(be(n,"main.tf"),"utf8"),t=s=>new RegExp(`^\\s*${s}\\s*=\\s*"([^"]+)"`,"m").exec(e)?.[1]??null;return{project:t("project_id"),region:t("region")}}var Hl=n=>/requested project was not found|project .* (was )?not found|has been deleted|DELETE_REQUESTED/i.test(n);function Ql(n){let e=n.filter(t=>t&&!/(^|\.)data\./.test(t));return e.includes("module.kuriko.google_cloud_run_v2_service.web")&&e.includes("module.kuriko.google_cloud_run_v2_service.gateway")?"installed":e.length?"partial":"empty"}function no(n){let e=be(n,"main.tf");return xs(e)&&/module\s+"kuriko"/.test(Ks(e,"utf8"))}function Xl(n){let e=Ks(be(n,"main.tf"),"utf8");return/variable\s+"deletion_protection"/.test(e)&&/deletion_protection\s*=\s*var\.deletion_protection/.test(e)}function Zl(n){try{let e=JSON.parse(Ks(be(n,".terraform","terraform.tfstate"),"utf8"));return e?.backend?.type==="gcs"?`gs://${e.backend.config.bucket}/${e.backend.config.prefix??""}`:null}catch{return null}}function eu(n){let e=n.values?.root_module;return[...e?.resources??[],...(e?.child_modules??[]).flatMap(t=>t.resources??[])]}var $e=(n,e)=>j("git",["-C",n,...e]);async function tu(n){try{return(await $e(n,["rev-parse","--show-toplevel"])).trim()}catch{return null}}async function nu(n){try{return(await $e(n,["rev-parse","--abbrev-ref","--symbolic-full-name","@{u}"])).trim()}catch{return null}}async function he(n){let e=await tu(n);if(!e)return;let t=await nu(e);if(!t)return;await P("Checking the installs repo is up to date",()=>$e(e,["fetch","--quiet"]));let s=Number((await $e(e,["rev-list","--count","HEAD..@{u}"])).trim());if(s>0)throw new Error(`The installs repo is ${s} commit${s===1?"":"s"} behind ${t}. Pull first:
230
+ git -C ${U(e)} pull`)}async function De(n,e,t={}){let s=await tu(n[0]);if(!s)return;let r=n.map(a=>Om(s,a)||".");if(await $e(s,t.remove?["rm","-r","-q","--ignore-unmatch","--",...r]:["add","-A","--",...r]),!(await $e(s,["diff","--cached","--name-only","--",...r])).trim())return;let o=await nu(s);if(!await H(`
231
+ Commit this to the installs repo${o?` and push to ${o}`:""}?`,!0)){M(`Left uncommitted in ${U(s)}. Commit it so others running Kuriko see the change.`);return}await $e(s,["commit","-q","-m",e,"--",...r]),o?(await P("Pushing",()=>$e(s,["push","-q"])),T(`Committed and pushed: ${e}`)):(T(`Committed: ${e}`),v(" (no remote to push to; add one so others can pull it)"))}async function su(n,e,t){let s=i=>i.replace(/-dirty-.*$/,"");if(s(e)===s(t))return"same";let r=async(i,o)=>{try{return await $e(n,["merge-base","--is-ancestor",s(i),s(o)]),!0}catch{return!1}};return await r(e,t)?"forward":await r(t,e)?"backward":"unknown"}p();import{existsSync as Pm}from"node:fs";import{basename as jm,join as Lm}from"node:path";var Gs={installed:{mark:"\u25CF",text:"installed"},partial:{mark:"\u25D0",text:"partly installed"},empty:{mark:"\u25CB",text:"not installed"},gone:{mark:"\u25CB",text:"project deleted"},unknown:{mark:"?",text:"status unknown"}};async function qm(n){let{project:e,region:t}=zl(n),s={dir:n,project:e??jm(n),region:t??"?",status:"unknown"};if(!Pm(Lm(n,".terraform")))return{...s,detail:"Terraform isn't set up here yet (run install to continue)"};try{let[r,i]=await Promise.all([j("terraform",["state","list","-no-color"],{cwd:n}),j("terraform",["output","-json"],{cwd:n}).then(o=>JSON.parse(o))]);s.status=Ql(r.split(`
232
+ `)),s.status==="installed"&&(s.web=String(i.web_url?.value??""),s.mcp=String(i.mcp_url?.value??""))}catch(r){let i=r instanceof Q?r.reason:String(r);if(Hl(i))return{...s,status:"gone",detail:`Delete the leftover config when you're done with it: rm -r ${U(n)}`};s.detail=`Couldn't read its state: ${i}`}return s}var kn=n=>P(`Reading ${n.length} install${n.length===1?"":"s"}`,()=>Promise.all(n.map(qm)));async function Ke(n,e,t,s={}){if(n)return bn(n);let r=Ze();if(!r.length)return bn(void 0);await X({terraformOnly:!0});let i=await kn(r);if(!i.filter(a=>t.includes(a.status)).length)throw new Error(`None of your installs can be used for this:
233
+ ${i.map(a=>` ${a.project}: ${Gs[a.status].text}`).join(`
234
+ `)}`);return i.length===1?i[0].dir:ce(e,i.map(a=>{let c=Gs[a.status],l=t.includes(a.status);return{label:a.project,value:a.dir,disabled:!l,hint:`${a.region} ${c.mark} ${c.text}${!l&&s[a.status]?`: ${s[a.status]}`:""}`}}))}p();import{cpSync as ou,existsSync as au,mkdtempSync as Gm,readFileSync as Fs,rmSync as cu,writeFileSync as Ys}from"node:fs";import{tmpdir as Um}from"node:os";import{join as ve}from"node:path";p();import{cpSync as Rm,existsSync as xm,mkdirSync as Mm,rmSync as Dm}from"node:fs";import{join as ro,relative as Km}from"node:path";import{fileURLToPath as Bm}from"node:url";var F=typeof k>"u"?null:k,et={upstream:"https://ghcr.io",host:"ghcr.io",owner:"usekuriko"},Se="kuriko-release-token",so=F?Bm(new URL("./module",import.meta.url)):ro(ne,"infra/terraform/gcp"),Us=".kuriko/module";function ru(n){if(!F)return Km(n,so);let e=ro(n,Us);if(Dm(e,{recursive:!0,force:!0}),Mm(e,{recursive:!0}),Rm(so,e,{recursive:!0,filter:t=>!/[/\\]\.terraform([/\\]|$)/.test(t)}),!xm(ro(e,"main.tf")))throw new Error(`The Terraform module wasn't found in this package (${so}).`);return`./${Us}`}var At=n=>/^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/.test(n);function iu(n,e){let t=i=>{let[o,a]=i.split("-",2);return{nums:o.split(".").map(Number),pre:a??null}},s=t(n),r=t(e);for(let i=0;i<3;i++)if(s.nums[i]!==r.nums[i])return s.nums[i]-r.nums[i];return s.pre===r.pre?0:s.pre===null?1:r.pre===null||s.pre<r.pre?-1:1}var Be="kuriko.json";function me(n,e){Ys(ve(n,Be),JSON.stringify(e,null,2)+`
235
+ `)}function Et(n){try{return JSON.parse(Fs(ve(n,Be),"utf8"))}catch{throw new Error(`${n} has no ${Be}, so it wasn't made by kuriko install. Upgrade it by hand (terraform apply).`)}}var io=null,$n=n=>io=n;function lu(n,e){if(!e.releaseUsername)return null;let t=/^release_token_version\s*=\s*"([^"]+)"/m.exec(Fs(ve(n,"terraform.tfvars"),"utf8"))?.[1];return t?{upstream:et.upstream,owner:et.owner,username:e.releaseUsername,tokenSecret:Se,tokenVersion:t}:null}async function Vs(n){await P("Setting up deploy events",async()=>{await Ps(n.project,["pubsub.googleapis.com"]),await Xi(n.project,"pubsub.googleapis.com")})}function Nt(n,e,t){Ys(ve(n,"terraform.tfvars"),vl(e,t,io))}function Js(n,e){Ys(ve(n,"main.tf"),Sl(e,ru(n),`${e.project}-tfstate`,io,!!F))}function uu(n){try{return/^version_tag\s*=\s*"([^"]+)"/m.exec(Fs(ve(n,"terraform.tfvars"),"utf8"))?.[1]??null}catch{return null}}async function tt(n,e){try{return(await j("terraform",["state","list"],{cwd:n})).split(`
236
+ `).includes(e)}catch{return!1}}async function Ws(n){if(F)return F.version;let e=(await j("git",["rev-parse","--short","HEAD"],{cwd:ne})).trim();if(!(await j("git",["status","--porcelain"],{cwd:ne})).trim())return e;if(!n)throw new Error("The Kuriko checkout has uncommitted changes, so its version isn't a commit. Commit them, or pass --allow-dirty.");return`${e}-dirty-${Date.now().toString(36)}`}async function fu(n,e){let t=s=>s.replace(/-dirty-.*$/,"");try{return(await j("git",["log","--oneline","--no-decorate",`${t(n)}..${t(e)}`],{cwd:ne})).split(`
237
+ `).filter(Boolean)}catch{return[]}}async function oo(n,e,t){let s=`.kuriko-${e}.plan`;await j("terraform",["plan","-input=false",...(t??[]).map(o=>`-target=${o}`),`-out=${s}`],{cwd:n});let r=await W("terraform",["show","-json",s],{cwd:n}),i=El(r);if(i.length)throw new Error(`This would delete or replace existing resources, which Kuriko never does on its own:
238
+ ${i.map(o=>` ${o}`).join(`
239
+ `)}
240
+ Nothing was changed.`);return{file:s,plan:r}}async function zs(n,e,t){let{file:s,plan:r}=await oo(n,e,t);Es(r).length&&await j("terraform",["apply","-input=false",s],{cwd:n})}async function Hs(n,e,t){for(let s=1;;s++)try{return await zs(n,e,t)}catch(r){if(!(r instanceof Q&&$l(r.stderr))||s>=8)throw r;await new Promise(i=>setTimeout(i,2e4))}}async function Qs(n,e,t,s){let r=await P(`${s}, in the cloud`,()=>vt(n.project,n.region,e,t));if(r.code!==0)throw new Error(`${s} failed in the cloud:
241
+ ${r.logs.slice(-10).map(i=>` ${i}`).join(`
242
+ `)}`);T(s)}var Fm=[["gateway","apps/gateway/Dockerfile",null],["web","apps/web/Dockerfile",null],["web-migrate","apps/web/Dockerfile","migrate"]];async function Xs(n,e,t){await j("gcloud",["auth","configure-docker",`${n}-docker.pkg.dev`,"--quiet"]);for(let[s,r,i]of Fm){let o=`${e}/${s}:${t}`;if(await Bl(o)){T(`${s} (already pushed)`);continue}await P(`Building and pushing ${s}`,()=>j("docker",["buildx","build","--platform","linux/amd64","-f",r,...i?["--target",i]:[],"-t",o,"--push","."],{cwd:ne})),T(s)}}async function Zs(n,e){let t=(o,a)=>P("Checking access to Kuriko's images",()=>Jl(et,o,a,"gateway",e)),s=await mn(n.project,Se),r=!1;if(s&&n.releaseUsername){let o=await t(n.releaseUsername,await Vl(n.project,Se));o==="ok"?r=!0:M(o==="missing"?`Kuriko ${e} isn't available with the stored token.`:"The stored registry token no longer works (expired or revoked).")}if(r)T(`Kuriko's images ${e}: access checked`);else for(Xe("Access to Kuriko's images",["Kuriko's images are private. With your agreement, Kuriko gave you a registry username and token for",`${C(n.domain)}. They only let this install pull Kuriko's images. The token goes straight into this`,`project's Secret Manager (${Se}), readable only by Artifact Registry.`]);;){let o=await te(`
243
+ Registry username:`,n.releaseUsername),a=await Ts(" Registry token (hidden as you type or paste):");if(!o||!a)continue;let c=await t(o,a);if(c==="denied"){M("That username and token can't pull Kuriko's images. Check both, or ask Kuriko for new ones.");continue}if(c==="missing")throw new Error(`Kuriko ${e} isn't published (or your token can't see it). Ask Kuriko, or use an earlier CLI version.`);c==="unreachable"&&M(`Couldn't reach ${et.host} to check; storing the token anyway.`),await P("Storing the token",()=>js(n.project,Se,a)),n.releaseUsername=o,T("Registry token stored in Secret Manager");break}await P("Setting up Artifact Registry's service account",()=>Xi(n.project,"artifactregistry.googleapis.com"));let i=await Yl(n.project,Se);if(!i)throw new Error(`${Se} has no enabled version.`);return{upstream:et.upstream,owner:et.owner,username:n.releaseUsername,tokenSecret:Se,tokenVersion:i}}function du(n){let e=["main.tf","terraform.tfvars",Be].map(i=>ve(n,i)),t=e.map(i=>au(i)?Fs(i):null),s=ve(n,Us),r=au(s)?Gm(ve(Um(),"kuriko-module-")):null;return r&&ou(s,r,{recursive:!0}),()=>{e.forEach((i,o)=>t[o]?Ys(i,t[o]):cu(i,{force:!0})),cu(s,{recursive:!0,force:!0}),r&&ou(r,s,{recursive:!0})}}var B="policy.yaml",ao="KURIKO_RESULT ";function Ym(n){let e=Math.max(...le.map(o=>o.id.length)),t=o=>`# ${o.name}: ${o.where}${o.notYet?` (not yet: ${o.notYet})`:""}`,s=o=>n.includes(o.id)&&!o.notYet?` - ${o.id.padEnd(e+2)} ${t(o)}`:` # - ${o.id.padEnd(e)} ${t(o)}`,r=n.filter(o=>!le.some(a=>a.id===o)),i=[...le.map(s),...r.map(o=>` - ${o}`)];return`# AI apps people may connect to Kuriko with, to build and use tools. Which data someone sees never
244
+ # depends on the app: their own access above applies either way. This only decides which apps may
245
+ # act on their behalf. Remove the # to allow one; take an app out and it stops working within an hour.
246
+ # Any other app that signs in with a client metadata document can be listed by that document's URL:
247
+ # - https://example.com/oauth/client-metadata.json
248
+ ${n.some(o=>!En(o)?.notYet)?"clients:":"clients: [] # nobody can connect from an AI app yet"}
249
+ ${i.join(`
250
+ `)}
251
+ `}function hu(n,e=""){return`# Who can do what in Kuriko (${n.project}). This file is the source of truth: change it here,
252
+ # then run kuriko policy apply --dir ${n.project} (it shows the changes and asks first).
253
+ # Credentials never go in this file. They live in Secret Manager; a connector only names its secret.
254
+
255
+ # Google groups -> Kuriko role. Admins manage access and see the audit log; builders make tools.
256
+ # Everyone else who can sign in is a Viewer: they use the tools shared with them.
257
+ roles:
258
+ ${n.adminsGroup}: Admin
259
+ ${n.buildersGroup}: Builder
260
+
261
+ ${e}# Data sources tools can use. Credentials stay in Secret Manager under any name (an existing secret
262
+ # is fine); Kuriko's gateway can read only the ones named here.
263
+ #
264
+ # warehouse: # Postgres: a read-only user's connection URL, in Secret Manager
265
+ # name: Warehouse
266
+ # kind: postgres
267
+ # secret: warehouse-readonly
268
+ # schema: public
269
+ #
270
+ # notion: # Notion, one shared integration (share each database with it in Notion)
271
+ # name: Notion
272
+ # kind: notion
273
+ # secret: notion-integration-token
274
+ # resources:
275
+ # interviews: 6643d20a-7cdb-4154-a1eb-7994499dd58b # name tools use: the database's data source ID
276
+ #
277
+ # notion-personal: # Notion, each person connects their own account once: tools see
278
+ # name: Notion (yours) # exactly what that person can see in Notion
279
+ # kind: notion
280
+ # credentials: per-person
281
+ # oauth_client_id: 1a2b3c4d-... # your Notion public integration
282
+ # secret: notion-oauth-client-secret # its OAuth client secret
283
+ # resources:
284
+ # interviews: 6643d20a-7cdb-4154-a1eb-7994499dd58b
285
+ connectors: {}
286
+
287
+ # Who may use which data. group is a Google group email, or everyone. write includes read.
288
+ # A tool only ever gets what its viewer is granted here AND what the tool declared it needs.
289
+ # For a per-person source, this says who may use it at all; the source decides what each person sees.
290
+ #
291
+ # - group: everyone
292
+ # connector: notion
293
+ # resources: [interviews] # for a database: table names, or ["*"] for every table
294
+ # access: write
295
+ # mask: [] # fields that come back hidden
296
+ #
297
+ # rows limits a grant to some rows: every field must match, a list means any of these, and $me is
298
+ # the email of whoever is using the tool. The same tool then shows each person their own rows.
299
+ #
300
+ # - group: sales@example.com
301
+ # connector: warehouse
302
+ # resources: [deals]
303
+ # access: read
304
+ # rows:
305
+ # rep_email: $me # each rep sees only their own deals
306
+ # - group: finance@example.com
307
+ # connector: warehouse
308
+ # resources: [deals]
309
+ # access: read
310
+ # rows:
311
+ # stage: [won, lost] # finance sees closed deals,
312
+ # mask: [rep_email] # without who closed them
313
+ access: []
314
+
315
+ ${Ym(n.clients??Ne)}`}function Ae(n,e){let t;try{t=(0,nr.parse)(n,{prettyErrors:!0,uniqueKeys:!0})}catch(s){throw s instanceof nr.YAMLParseError?new rt([`It isn't valid YAML: ${s.message.split(`
316
+ `)[0]}`]):s}return vo(t,s=>s.startsWith("projects/")?s:`projects/${e}/secrets/${s}`)}var co={add:xe("+"),change:Qe("~"),remove:de("-")};function Vm(n){for(let e of n)v(` ${co[e.op]} ${e.op==="remove"?de(Nn(e)):Nn(e)}`)}async function er(n,e,t){let s=await P(e,()=>vt(n.project,n.region,"kuriko-migrate",["scripts/admin.ts",...t])),r=s.logs.find(o=>o.startsWith(ao));if(s.code===0&&r)return JSON.parse(r.slice(ao.length));if(s.logs.some(o=>o.includes("Unknown task")))throw new Error(`${n.project} is on a Kuriko version without policy files. Upgrade it first: kuriko upgrade --dir ${n.project}`);let i=s.logs.filter(o=>!o.startsWith(ao)).slice(-8);throw new Error(`${e} failed in the cloud${i.length?`:
317
+ ${i.map(o=>` ${o}`).join(`
318
+ `)}`:" (no logs yet; try again)"}`)}async function mu(n,e){q("Checking this machine"),await he(pe()),await X();let t=await Ke(e.dir,"Which install's policy?",["installed"],{partial:"finish it with kuriko install"}),s=Et(t);if(!await tt(t,"module.kuriko.google_cloud_run_v2_job.migrate"))throw new Error(`${s.project} isn't fully installed yet. Run kuriko install --dir ${s.project}`);T(`Install ${C(s.project)} ${I(`(${U(t)})`)}`);let r=fo(t,B);if(!lo(r))throw pu(r,hu(s)),new Error(`${s.project} had no ${B}, so one was started at ${U(r)} with just the two roles.
319
+ Add any data sources and access this install already has (the plan would remove them otherwise), then run this again.`);q(`Reading ${B}`);let i=Ae(uo(r,"utf8"),s.project),o=(g,O)=>`${g} ${O}${g===1?"":"s"}`;T(`${o(i.roles.length,"role rule")}, ${o(i.connectors.length,"data source")}, ${o(i.grants.length,"grant")}, ${o(i.clients.length,"AI app")}`),i.clients.length||M("clients is empty: nobody can connect to Kuriko from an AI app (Claude Code, Codex, \u2026).");let a=tr(i),c=[];if(await P("Checking the secrets it names exist",async()=>{for(let g of a)await gn(g)||c.push(g)}),c.length){let[g,O]=c[0].split("/").filter((L,b)=>b%2===1);throw new Error(`Secret Manager has no ${c.map(L=>Ge(L,s.project)).join(", ")} (or your account can't see ${c.length>1?"them":"it"}). Whoever manages credentials creates it, e.g.:
320
+ read -s TOKEN && printf '%s' "$TOKEN" | gcloud secrets create ${O} --project ${g} --data-file=- && unset TOKEN`)}a.length&&T(`Secrets exist: ${a.map(g=>Ge(g,s.project)).join(", ")}`),q("What changes");let l=Buffer.from(JSON.stringify(i)).toString("base64"),d=await er(s,"Comparing with the install, in the cloud",["policy-plan",l]);d.changes=d.changes.filter(g=>{if(g.kind!=="connector"||g.op!=="change")return!0;let O=d.connectors.find(x=>x.id===g.id),L=i.connectors.find(x=>x.id===g.id);if(!O||!L)return!0;let b=x=>ar({roles:[],grants:[],clients:[],connectors:[x]}).connectors[0],_=Ao(b(O),b(L));return _[0]==="(settings differ only in form)"?!1:(g.summary=`${L.name}: ${_.join("; ")}`,!0)});let u=await P("Checking which secrets the gateway can read",()=>Wm(s,{roles:[],grants:[],clients:[],connectors:d.connectors},i));d.lastApply?v(I(` Last applied ${new Date(d.lastApply.at).toLocaleString()} by ${d.lastApply.appliedBy}`)):v(I(" This would be the first apply. After it, access changes go through this file; admin tools in Claude point here."));let f=!d.changes.length&&!u.allow.length&&!u.disallow.length;if(f&&(T(`${s.project} already matches ${B}.`),n==="plan"||d.lastApply))return;Vm(d.changes);for(let g of u.allow)v(` ${co.add} the gateway can read secret ${Ge(g,s.project)}`);for(let g of u.disallow)v(` ${co.remove} ${de(`the gateway can no longer read secret ${Ge(g,s.project)}`)}`);let h=i.connectors.filter(g=>g.mode==="delegated");if(h.length){let g=(await Me(s.project))?.number;if(g){let O=He(s,g).mcp.replace(/\/mcp$/,"");for(let L of h)v(I(` ${L.id}: set the OAuth redirect URI to ${O}/connect/callback; people connect at ${He(s,g).web}/connect/${L.id}`))}}let y=d.changes.filter(g=>g.op==="remove").length+u.disallow.length,m=d.changes.filter(g=>g.op==="remove"&&(g.kind==="role"||g.kind==="grant")).length,w=d.changes.filter(g=>g.op==="remove"&&g.kind==="connector").length;m&&M(`${m} role${m===1?" or grant is":"s or grants are"} removed: people lose that access on their next request.`),w&&M(`${w} data source${w===1?" is":"s are"} removed: tools using ${w===1?"it":"them"} stop getting its data, and everyone's own connections to ${w===1?"it":"them"} are deleted.`);let A=d.changes.filter(g=>g.kind==="client"&&g.op==="remove");if(A.length&&M(`${A.map(g=>It(g.client)).join(", ")} can't sign anyone in any more, and ${A.length===1?"its":"their"} current sessions stop within an hour. People's access is unchanged in the apps that remain.`),u.disallow.length&&M(`Kuriko gives up ${u.disallow.length===1?"a secret":"secrets"} the file no longer names. Nobody loses access; the secret${u.disallow.length===1?" itself is":"s themselves are"} kept.`),n==="plan"){v(`
321
+ ${I(`Plan only: nothing was changed. Apply with: kuriko policy apply --dir ${s.project}`)}`);return}if(!e.yes&&!await H(`
322
+ Apply ${f?`${B} (no changes; records it as the source of truth)`:"these changes"}?`,!y)){v("Nothing was changed.");return}u.allow.length&&await P("Letting the gateway read the new secrets",async()=>{for(let g of u.allow)await eo(g,Ct(s))});let $=await $t(),E=await er(s,"Applying, in the cloud",["policy-apply",l,$,d.hash]);u.disallow.length&&await P("Taking away the gateway's access to secrets no longer used",async()=>{for(let g of u.disallow)await Wl(g,Ct(s))});let N=E.changes.length+u.allow.length+u.disallow.length;T(`${s.project} matches ${B} (${N} change${N===1?"":"s"}, recorded in the audit log as ${$})`),u.allow.length&&v(I(" New secret access can take a minute or two to reach Google's servers.")),await De([r],`Policy for ${s.project}: ${E.changes.length?E.changes.map(Nn).slice(0,3).join("; ")+(E.changes.length>3?"; \u2026":""):"first apply"}`)}var tr=n=>[...new Set(n.connectors.map(e=>e.secretRef))].sort(),Jm=n=>`kuriko-gateway@${n.project}.iam.gserviceaccount.com`,Ct=n=>`serviceAccount:${Jm(n)}`;async function Wm(n,e,t){let s=tr(t),r=[];for(let o of s)await yn(o,Ct(n))||r.push(o);let i=[];for(let o of tr(e))o.startsWith("projects/")&&!s.includes(o)&&await gn(o)&&await yn(o,Ct(n))&&i.push(o);return{allow:r,disallow:i}}async function gu(n,e){let t=fo(e,B);if(!lo(t))return[];let s=tr(Ae(uo(t,"utf8"),n.project)),r=[];for(let i of s)await gn(i)&&!await yn(i,Ct(n))&&(await eo(i,Ct(n)),r.push(i));return r}async function yu(n,e,t=""){let s=fo(e,B);lo(s)||pu(s,hu(n,t));let r=Ae(uo(s,"utf8"),n.project),i=Buffer.from(JSON.stringify(r)).toString("base64"),o=await er(n,"Reading the install's access, in the cloud",["policy-plan",i]);if(o.lastApply)return T(`Access comes from ${B} (change it with kuriko policy apply)`);await er(n,`Applying ${B}, in the cloud`,["policy-apply",i,await $t(),o.hash]),T(`Roles for your two groups, from ${B}`)}var Ee="module.kuriko",Xm=[`${Ee}.google_sql_database_instance.kuriko`,`${Ee}.google_sql_database.kuriko`,`${Ee}.google_sql_user.kuriko`,`${Ee}.google_cloud_run_v2_service.web`,`${Ee}.google_cloud_run_v2_service.gateway`,`${Ee}.google_cloud_run_v2_job.migrate`],Zm=[`${Ee}.google_kms_crypto_key.user_tokens`,`${Ee}.google_kms_key_ring.kuriko`],eg=new Set(["deletion_protection","deletion_policy"]);function tg(n){let e=eu(n).filter(u=>u.address.startsWith(`${Ee}.`)),t=e.find(u=>u.type==="google_project"&&u.mode==="data")?.values.project_id;if(typeof t!="string")throw new Error("This install has no Kuriko resources in its state (already destroyed, or never installed).");let s=e.filter(u=>u.mode==="managed"),r=u=>s.filter(f=>f.type===u),i=(u,f)=>String(u.values[f]??""),o=i(r("google_cloud_run_v2_service")[0]??r("google_artifact_registry_repository")[0]??{values:{}},"location"),a=[];for(let u of r("google_sql_database_instance"))a.push(`Cloud SQL instance ${C(i(u,"name"))} with all its data and backups: every user, tool, grant and audit record`);for(let u of r("google_cloud_run_v2_service"))a.push(`Cloud Run service ${i(u,"name")}`);for(let u of r("google_cloud_run_v2_job"))a.push(`Cloud Run job ${i(u,"name")}`);for(let u of r("google_secret_manager_secret"))a.push(`Secret ${i(u,"secret_id")} (generated by Kuriko)`);for(let u of r("google_service_account"))a.push(`Service account ${i(u,"email")}`);for(let u of r("google_artifact_registry_repository"))a.push(`Image repository ${i(u,"name")} and every image in it`);s.some(u=>u.type.endsWith("_iam_member"))&&a.push("Every IAM grant Kuriko made");let c=s.filter(u=>Zm.includes(u.address)).map(u=>u.address),l=r("google_kms_crypto_key").map(u=>`${i(u,"key_ring").split("/").pop()}/${i(u,"name")}`),d=e.find(u=>u.type==="google_secret_manager_secret"&&u.mode==="data");return{project:t,region:o,deletes:a,release:c,keys:l,idpSecret:d?i(d,"secret_id"):null}}function ng(n){let e=[];for(let t of n.resource_changes??[]){let s=t.change.actions;if(s.length===1&&(s[0]==="no-op"||s[0]==="read"))continue;if(s.length!==1||s[0]!=="update"){e.push(`${t.address} would be ${s.join("/")}`);continue}let r=t.change.before??{},i=t.change.after??{},c=[...new Set([...Object.keys(r),...Object.keys(i),...Object.keys(t.change.after_unknown??{})])].filter(l=>t.change.after_unknown?.[l]===!0||JSON.stringify(r[l]??null)!==JSON.stringify(i[l]??null)).filter(l=>!eg.has(l));c.length&&e.push(`${t.address} would also change ${c.join(", ")}`)}return e}async function wu(n){q("Checking this machine");for(let[h,y]of[["terraform","runs the install's Terraform"],["gcloud","finds what Kuriko created outside Terraform"]])if(!await Ue(h))throw new Error(`${h} isn't installed (${y}).`);await X(),await he(pe());let e=await Ke(n.dir,"Which install should be destroyed?",["installed","partial"],{empty:"nothing left to destroy",unknown:"can't read its state"}),t=(h,y=!1)=>j("terraform",h,{cwd:e,inherit:y});if(!Xl(e))throw new Error(`${e}/main.tf must pass deletion protection through to the module, so destroy can turn it off:
323
+ variable "deletion_protection" { type = bool, default = true }
324
+ and in module "kuriko": deletion_protection = var.deletion_protection`);T(`Install at ${U(e)}`),q("Reading the install");let s=tg(await W("terraform",["show","-json"],{cwd:e})),r=["--project",s.project,"--format=json"],i=(await W("gcloud",["run","services","list","--region",s.region,...r])).filter(h=>h.metadata.labels?.["kuriko-tool"]).map(h=>h.metadata.name),o=Qm(e,B),a=zm(o)?[...new Set(Ae(Hm(o,"utf8"),s.project).connectors.map(h=>Ge(h.secretRef,s.project)))]:[],c=Zl(e);v(`
325
+ ${C(`Destroying Kuriko in ${s.project} (${s.region}) deletes, permanently:`)}`);for(let h of i)v(` ${de("\u2717")} Tool ${h} (Cloud Run service)`);for(let h of s.deletes)v(` ${de("\u2717")} ${h}`);v(`
326
+ ${C("It keeps:")}`);let l=[...s.keys.map(h=>`KMS key ${h}. GCP never deletes keys; it costs cents a month and a reinstall here reuses it.`),...s.idpSecret?[`Your IdP client secret ${s.idpSecret}`]:[],...a.map(h=>`Your connector credential ${h}`),...c?[`Terraform state in ${c}`]:[],"The project itself and its enabled APIs"];for(let h of l)v(` ${I("\u2022")} ${h}`);if(n.dryRun){v(`
327
+ ${I("Dry run: nothing was changed.")}`);return}if((n.confirm??await te(`
328
+ Type the project id (${s.project}) to destroy this install: `))!==s.project){v("That doesn't match. Nothing was changed.");return}q("Turning off deletion protection");let u=".kuriko-unlock.plan";await t(["plan","-input=false","-var","deletion_protection=false",...Xm.map(h=>`-target=${h}`),`-out=${u}`]);let f=ng(JSON.parse(await t(["show","-json",u])));if(f.length)throw new Error(`The install's config doesn't match what's deployed, so turning off protection would change more than that:
329
+ ${f.map(h=>` ${h}`).join(`
330
+ `)}
331
+ Apply the config first (or fix it), then run destroy again.`);if(await t(["apply","-input=false",u],!0),T("Deletion protection is off"),i.length){q(`Deleting ${i.length} tool${i.length===1?"":"s"}`);for(let h of i)await j("gcloud",["run","services","delete",h,"--region",s.region,"--project",s.project,"--quiet"]),T(h)}s.release.length&&(q("Keeping the KMS key out of the destroy"),await t(["state","rm",...s.release]),T("Terraform no longer manages the key; it stays in the project")),q("Destroying everything else (Cloud SQL takes a few minutes)"),await t(["destroy","-input=false","-auto-approve","-var","deletion_protection=false"],!0),v(`
332
+ ${C(`Kuriko is gone from ${s.project}.`)} Still there, by design:`);for(let h of l)v(` ${I("\u2022")} ${h}`);v(`
333
+ ${C("Outside Google Cloud")} (yours to remove if you're done with Kuriko):`),v(` ${I("\u2022")} The OAuth client for Kuriko's sign-in, and the Groups Reader role assignment for the deleted kuriko-web account`),v(` ${I("\u2022")} Your kuriko-admins / kuriko-builders groups`),v(`
334
+ To remove everything at once: ${C(`gcloud projects delete ${s.project}`)}`),await De([e],`Destroy ${s.project}`,{remove:!0})}p();import{existsSync as rr,mkdirSync as lg,readFileSync as Su,writeFileSync as ug}from"node:fs";import{basename as fg,join as nt}from"node:path";p();import{existsSync as sg,readFileSync as rg}from"node:fs";import{join as ig}from"node:path";var og=40,ag=n=>n.endsWith(".guest.google")||/^(abuse|postmaster)@/.test(n);async function po(n){let e=await St().catch(()=>[]),t=(e.find(r=>r.name===n.domain)??e[0])?.customerId;if(!t)return null;let s=await Ls(n.project,t).catch(()=>null);return s&&s.filter(r=>!ag(r.email))}function bu(n,e){let t=n.filter(a=>a.email!==e.adminsGroup&&a.email!==e.buildersGroup),s=`# Groups in ${e.domain} when this file was made (kuriko groups --dir ${e.project} lists them now).
335
+ # Name one in roles or access to give its members something; groups not named here get nothing.`;if(!t.length)return`${s}
336
+ # (none besides the two above)
337
+ `;let r=t.slice(0,og),i=Math.max(...r.map(a=>a.email.length)),o=r.map(a=>`# ${a.name&&a.name.toLowerCase()!==a.email.split("@")[0]?`${a.email.padEnd(i)} ${a.name}`:a.email}`);return t.length>r.length&&o.push(`# \u2026 and ${t.length-r.length} more`),`${s}
338
+ ${o.join(`
339
+ `)}
340
+ `}function cg(n,e){let t=new Map,s=ig(n,B);if(!sg(s))return t;let r=Ae(rg(s,"utf8"),e),i=(o,a)=>t.set(o,[...t.get(o)??[],a]);for(let o of r.roles)i(o.group,o.role);for(let o of r.grants)i(o.group,`${o.access} ${o.connector}`);return t}async function ku(n){q("Checking this machine"),await he(pe()),await X();let e=await Ke(n.dir,"Which install's groups?",["installed","partial"]),t=Et(e);T(`Install ${C(t.project)} ${I(`(${U(e)})`)}`),q(`Google Groups in ${t.domain}`);let s=await P("Reading your Workspace's groups",()=>po(t));if(!s){M("Couldn't list your Workspace's groups: your account may not be allowed to. A Workspace admin can, or find them at admin.google.com \u2192 Directory \u2192 Groups.");return}let r=n.search?.toLowerCase(),i=r?s.filter(l=>`${l.email} ${l.name} ${l.description}`.toLowerCase().includes(r)):s,o=cg(e,t.project),a=Math.max(10,...i.map(l=>l.email.length));for(let l of i){let d=o.get(l.email);v(` ${l.email.padEnd(a)} ${l.name&&l.name.toLowerCase()!==l.email.split("@")[0]?l.name:""}${d?` ${xe(`in ${B}: ${d.join(", ")}`)}`:""}`)}T(r?`${i.length} of ${s.length} groups match "${n.search}"`:`${s.length} group${s.length===1?"":"s"}`);let c=[...o.keys()].filter(l=>l!=="*"&&l.includes("@")&&!s.some(d=>d.email===l));for(let l of c)M(`${B} names ${Ot(l)}, which isn't a group in ${t.domain} (a typo, or deleted?). Its rules apply to nobody.`);v(I(`
341
+ Copy an email into ${B} (roles or access), then: kuriko policy apply --dir ${t.project}`))}async function vu(n){v(`${C("Kuriko install")}
342
+
343
+ This puts Kuriko in your own cloud. Everything runs there, under your control: your people sign
344
+ in with the accounts they already have, and credentials stay in your own secret manager.
345
+
346
+ First a few questions; nothing is created until you've seen the plan and said yes. Then it takes
347
+ about 30 minutes, mostly waiting for the database. A few steps happen in your providers' admin
348
+ pages; this explains each one and checks it before moving on. If anything fails, run it again:
349
+ it picks up where it stopped.`);let e=pe();await he(e);let t=n.dir?bn(n.dir):await yg(),s=t&&rr(nt(t,Be))?JSON.parse(Su(nt(t,Be),"utf8")):null;s||(v(""),await ce("Where should Kuriko run?",[{label:"Google Cloud",value:"gcp",hint:"in a project of yours"},{label:"AWS",value:"aws",hint:"coming soon",disabled:!0},{label:"Azure",value:"azure",hint:"coming soon",disabled:!0},{label:"Managed by Kuriko",value:"managed",hint:"coming soon: we run it for you",disabled:!0}]),await ce("Where do your people sign in?",[{label:"Google Workspace",value:"google-workspace"},{label:"Okta",value:"okta",hint:"coming soon",disabled:!0},{label:"Microsoft Entra ID",value:"entra",hint:"coming soon",disabled:!0},{label:"Another OIDC or SAML provider",value:"other",hint:"coming soon",disabled:!0}])),q("Checking this machine");for(let[b,_,x]of[["gcloud","Google Cloud's CLI: https://cloud.google.com/sdk/docs/install","--version"],["terraform","creates the cloud resources: https://developer.hashicorp.com/terraform/install","-version"]])if(!await Ue(b,x))throw new Error(`${b} isn't installed (${_}).`);if(!F){if(!await Ue("git","--version"))throw new Error("git isn't installed (it identifies the Kuriko version).");try{await j("docker",["info","--format","{{.ServerVersion}}"])}catch{throw new Error("Docker isn't running. Start Docker Desktop (it builds Kuriko's images), then run this again.")}}let r=await $t();if(!r)throw new Error("gcloud isn't signed in. Run: gcloud auth login");let i=r.split("@")[1]??"";if(/^(gmail|googlemail)\.com$/.test(i))throw new Error(`gcloud is signed in as ${r}. Sign in with your Google Workspace admin account instead: gcloud auth login`);await X(),T(`Signed in to Google Cloud as ${r}`);let o;if(s){q(`Continuing the install in ${s.project}`);let b=await Me(s.project);if(!b||b.state!=="ACTIVE")throw new Error(`Project ${s.project} isn't available (deleted, or your account can't see it).`);o=b.number,T(`Project ${s.project} ${I(`(${t})`)}`)}else{q("Your Google Cloud project"),v(" Kuriko should have a project to itself, so its permissions don't mix with anything else.");let b=await ce("New project or existing?",[{label:"Create a new project",value:!0,hint:"recommended"},{label:"Use an existing, empty project",value:!1}]),_="",x=null;if(b){let ie=await P("Finding your organization",()=>St());if(!ie.length)throw new Error(`${r} can't see any Google Cloud organization. Projects for Kuriko should live in your Workspace's organization.`);x=await Hi("Organization:",ie.map(ge=>({label:ge.name,value:ge,hint:ge.id}))),_=await sr("Project ID (can't be changed later):",`kuriko-${Math.floor(1e3+Math.random()*9e3)}`,Gi,"6\u201330 characters, starting with a letter: lowercase letters, digits and hyphens.")}else for(;_=await te("Project ID:"),!await P("Looking it up",()=>Me(_));)v(` Can't find ${_}, or ${r} can't see it.`);let G=null;if(b||!await P("Checking billing",()=>Rl(_))){let ie=await P("Finding billing accounts",()=>Ll());if(!ie.length)throw new Error("No open billing account. Create one at https://console.cloud.google.com/billing, then run this again.");G=await Hi("Billing account:",ie.map(ge=>({label:ge.name,value:ge,hint:ge.id})))}let D=await gg();q("The plan");let se=(ie,ge)=>v(` ${I(ie.padEnd(10))}${ge}`);if(se("Runs in",`Google Cloud \xB7 ${b?`new project ${C(_)}${x?` in ${x.name}`:""}`:`existing project ${C(_)}`} \xB7 ${D}`),G&&se("Billing",`${G.name} ${I(G.id)}`),se("Sign-in",`Google Workspace \xB7 people at ${C(i)}`),se("Admins",`kuriko-admins@${i}`),se("Builders",`kuriko-builders@${i}`),se("Cost","about $10\u201315 a month, almost all of it the database; the rest scales to zero when idle"),v(""),!await H("Start?",!0)){v("Nothing was created.");return}if(b){for(;;)try{await P(`Creating project ${_}`,()=>ql(_,x.id));break}catch(ie){if(!(ie instanceof Q&&/already (in use|exists)/i.test(ie.stderr)))throw ie;v(` ${_} is taken (project IDs are unique across all of Google Cloud).`),_=await sr("Another project ID:",void 0,Gi,"6\u201330 characters, starting with a letter: lowercase letters, digits and hyphens.")}T(`Created project ${_}`)}G&&(await P("Linking billing",()=>xl(_,G.id)),T("Billing linked")),o=(await Me(_)).number,s={host:"gcp",sso:"google-workspace",project:_,region:D,domain:i,adminEmail:r,adminsGroup:`kuriko-admins@${i}`,buildersGroup:`kuriko-builders@${i}`,dbInstanceName:""},t=nt(e,_),lg(t,{recursive:!0}),me(t,s)}let a=t,c=He(s,o);q("Turning on the Google Cloud services Kuriko uses"),await P("Enabling APIs",()=>Ps(s.project,hl)),await Vs(s),T("Cloud Run, Cloud SQL, Secret Manager, KMS, Artifact Registry, Cloud Build, Pub/Sub, IAM, Cloud Identity"),q("Somewhere to keep Kuriko's Terraform state");let l=`${s.project}-tfstate`,d=await P("Creating the state bucket",()=>Ml(l,s.project,s.region));T(`gs://${l} ${I(`(${d}; versioned, private)`)}`);let u=await Dl(s.project);s.dbInstanceName||(s.dbInstanceName=wl(u.map(b=>b.name)),me(a,s));let f=await Ws(n.allowDirty);F&&(q(`Kuriko ${f}`),$n(await Zs(s,f)),me(a,s)),Js(a,s),await P("Preparing Terraform",()=>j("terraform",["init","-input=false"],{cwd:a}));let h={},y=()=>ug(nt(a,"imports.tf"),Al(s,h));await tt(a,"module.kuriko.google_kms_key_ring.kuriko")||(Object.assign(h,await Kl(s.project,s.region,fn.ring,fn.key)),h.ring&&T("Found a KMS key from an earlier install; this one will reuse it")),y(),T(`Install config in ${a}`),q("Kuriko's service accounts and image registry"),Nt(a,s,f),await P("Creating service accounts and the image registry",()=>Hs(a,"bootstrap",ml)),T("kuriko-web, kuriko-gateway and kuriko-tools service accounts; image registry"),q("Kuriko's database");let m={started:Date.now(),state:"creating",note:""},w=Promise.resolve();if(await tt(a,As))m.state="ready",T(`Database ${s.dbInstanceName} ${I("(already created)")}`);else{let b=u.find(_=>_.name===s.dbInstanceName&&_.kuriko);if(b)h.sqlInstance=b.name,y(),T(`Found database ${b.name} from an earlier run; picking it up`);else if(v(" Cloud SQL takes 10\u201315 minutes to create, so it starts now and carries on while you do the next steps."),v(" It's most of Kuriko's cost: about $10\u201315 a month. The rest scales to zero when nobody's using it."),!await H(" Start creating it?",!0))throw new Error("Stopped before creating the database. Run install again to continue.");w=hg(a,s,f,m).then(()=>m.state="ready",_=>(m.state="failed",_)),zi(()=>m.state==="creating"?`database: ${m.note||"creating"} (${Cs(m.started)})`:m.state==="ready"?"database: ready":"database: failed"),T("Started; it'll be ready in about 10\u201315 minutes")}for(F||(q(`Kuriko's images (version ${f})`),v(I(" Built from this checkout (development). Released versions pull Kuriko's published images instead.")),await Xs(s.region,c.registry,f)),Xe("Let people sign in with Google (an OAuth app, in Google Cloud)",["Kuriko signs people in with their Google accounts. Google needs an OAuth app in this project for that.","",`1. Open ${C(c.newClient)}`,` If Google first asks you to set up the app (${C("Get started")}): App name ${C("Kuriko")}, support email: you,`,` Audience: ${C("Internal")} (only people in ${s.domain} can sign in), contact email: you. Agree, ${C("Create")},`," then open the link again. If it goes straight to a form for a new client, skip this.","",`2. Application type: ${C("Web application")}. Name: ${C("Kuriko")}.`,` Under Authorized redirect URIs, ${C("Add URI")} and paste exactly:`,` ${C(c.redirect)}`,` Then ${C("Create")}. A dialog shows the Client ID and Client secret: keep it open.`]);;){let b=await sr(`
350
+ Client ID:`,s.idpClientId,yl,"It looks like 1234567890-abc123.apps.googleusercontent.com."),_=b!==s.idpClientId;if(s.idpClientId=b,me(a,s),await mn(s.project,dn)&&!_&&!await H(` A client secret is already in Secret Manager (${dn}). Replace it?`)){T("Keeping the stored client secret");break}v(I(` The secret goes straight into Secret Manager as ${dn}. It isn't shown or saved anywhere else.`));let G=await Ts(" Client secret (hidden as you type or paste):");if(!G)continue;let D=await P("Checking them with Google",()=>Gl(b,G,c.redirect));if(D===!1){M("Google doesn't accept that client ID and secret together. Copy both again from the same client.");continue}await P("Storing the secret",()=>js(s.project,dn,G)),T(`Client secret stored in Secret Manager${D?", and Google accepts it":""}`);break}s.groupsChosen||((await Promise.all([s.adminsGroup,s.buildersGroup].map(_=>qs(s.project,_,s.adminEmail).catch(()=>null)))).every(_=>_?.exists)||await wg(s),s.groupsChosen=!0,me(a,s)),s.clients||(s.clients=await dg(a),me(a,s)),Xe("Decide who runs Kuriko (Google Groups)",["Kuriko gives roles by Google Group, so access is managed where you already manage people:",` ${C(s.adminsGroup)} Admin: manages who can use which data, sees the audit log.`,` ${C(s.buildersGroup)} Builder: builds tools.`,` Everyone else in ${s.domain} can sign in and use tools shared with them. Groups inside these groups count too.`]);let A=()=>P("Looking for the groups",()=>Promise.all([qs(s.project,s.adminsGroup,s.adminEmail),qs(s.project,s.buildersGroup,s.adminEmail)])),[$,E]=await A(),N=[!$.exists&&s.adminsGroup,!E.exists&&s.buildersGroup].filter(b=>!!b),g=!1;if(N.length&&await H(`
351
+ Create ${N.join(" and ")} now${$.exists?"":`, with you in ${s.adminsGroup}`}?`,!0)){let b=await St(),_=(b.find(x=>x.name===s.domain)??b[0])?.customerId;if(!_)throw new Error("Couldn't find your Workspace's customer ID to create the groups. Create them in the Admin console instead.");for(let[x,G,D,se]of[[s.adminsGroup,"Kuriko admins","Kuriko Admin role: manages who can use which data, sees the audit log.",!0],[s.buildersGroup,"Kuriko builders","Kuriko Builder role: builds tools on Kuriko.",!1]])N.includes(x)&&(await P(`Creating ${x}`,()=>Fl(s.project,{customerId:_,email:x,name:G,description:D,owner:se})),T(`Created ${x}${se?" (you're its owner)":""}`));if(g=!0,!E.exists){let x=(await te(` Who should build? Their ${s.domain} emails, comma-separated (Enter to add people later):`)).split(/[\s,]+/).filter(Boolean);for(let G of x){if(!vs(G)){M(`Skipped ${G}: not an email address.`);continue}try{await P(`Adding ${G}`,()=>Qi(s.project,s.buildersGroup,G)),T(`Added ${G} to ${s.buildersGroup}`)}catch(D){M(`Couldn't add ${G}: ${D instanceof Error?D.message:String(D)}`)}}}}else N.length&&Xe("Create the groups in the Google Admin console",[`${C("https://admin.google.com/ac/groups")} \u2192 ${C("Create group")}, once for each group email above.`,`Under access settings choose ${C("Restricted")} (only members see the member list) and no external members.`,`Add yourself to ${s.adminsGroup}, and the people who'll build to ${s.buildersGroup}.`]);for(let b=0;;b++){if(b&&([$,E]=await A()),$.exists&&E.exists&&$.isMember){T(`${s.adminsGroup} (you're in it) and ${s.buildersGroup} are ready`);break}if(g&&b<6){await new Promise(x=>setTimeout(x,3e3));continue}if($.exists&&!$.isMember&&await H(` You're not in ${s.adminsGroup}, so you wouldn't be a Kuriko admin. Add you?`,!0)){await P("Adding you",()=>Qi(s.project,s.adminsGroup,s.adminEmail)),g=!0,b=0;continue}let _=[!$.exists&&s.adminsGroup,!E.exists&&s.buildersGroup].filter(Boolean);_.length?M(`Not found yet: ${_.join(", ")} (or ${s.adminEmail} can't see ${_.length>1?"them":"it"}).`):M(`${s.adminEmail} isn't in ${s.adminsGroup}. Add yourself, or you won't be an admin.`),await te(" Press Enter to check again.")}Xe("Let Kuriko see group membership (Groups Reader role, in the Google Admin console)",["Google doesn't tell apps which groups someone is in when they sign in, so Kuriko asks Google","directly. It needs the Groups Reader admin role for that: it can read group membership and nothing else.","",`1. Open ${C("https://admin.google.com/ac/roles")} and click ${C("Groups Reader")}.`,`2. Open ${C("Admins")} (or "Assign role"), then ${C("Assign service accounts")}.`,`3. Paste ${C(c.webServiceAccount)}, click ${C("Add")}, then ${C("Assign role")}.`,"","It can take a few minutes to take effect. Kuriko checks it at the end."]),await te(" Press Enter when you've assigned it."),q("Creating Kuriko");let O=await P("Waiting for the database",()=>w);if(zi(null),m.state==="failed")throw O;T(`Database ${s.dbInstanceName} ${I(`(${Cs(m.started)} in all)`)}`),Nt(a,s,f),await P("Creating Kuriko's secrets, key and services",()=>Hs(a,"install",null));for(let b of Object.keys(h))delete h[b];y(),T("Kuriko's secrets, key and services"),q("Setting up Kuriko's database"),await Qs(s,"kuriko-migrate",void 0,"Database schema");let L="";if(!rr(nt(a,B))){let b=await P("Reading your Workspace's groups for policy.yaml",()=>po(s));b&&(L=bu(b,s))}for(await yu(s,a,L),q("Checking Kuriko can see group membership");;){let b=await P("Checking as kuriko-web, in the cloud",()=>vt(s.project,s.region,"kuriko-migrate",["scripts/admin.ts","check-groups",s.adminEmail,s.adminsGroup]));if(b.code===0){T(`Kuriko sees you in ${s.adminsGroup}`);break}for(let _ of b.logs.slice(-3))v(I(` ${_.trim()}`));b.code===3?M(`Kuriko can read groups, but doesn't see ${s.adminEmail} in ${s.adminsGroup}.`):M(`Kuriko can't read group membership yet. Check ${c.webServiceAccount} has Groups Reader (above); it can take a few minutes.`),await te(" Press Enter to check again.")}v(`
352
+ ${C("Kuriko is installed.")}
353
+
354
+ Sign in: ${C(c.web)}
355
+ MCP server: ${C(c.mcp)}
356
+ ${pg(s.clients??Ne,c.mcp)}
357
+
358
+ To let someone build: add them to ${s.buildersGroup} and send them the MCP server address.
359
+ Data sources, who may use them, and which AI apps can connect go in ${s.project}/${B};
360
+ apply with kuriko policy apply.
361
+ Their first sign-in is their setup; they never need Google Cloud access.
362
+
363
+ Install config: ${U(a)} ${I("(no secrets in it; state is in gs://"+l+")")}`),await De([a],`Install ${s.project} (Kuriko ${f})`)}async function dg(n){q("Choosing which AI apps can connect");let e=nt(n,B);if(rr(e)){let{clients:s}=Ae(Su(e,"utf8"),fg(n));return T(`From ${B}: ${s.length?s.join(", "):"none"}`),s}v(I(" People connect Kuriko to the AI app they build in. Data access is the same whichever app they use;")),v(I(` this only decides which apps may act for them. Change it any time in ${B}.`));let t=await jl(`
364
+ Which AI apps can people connect with?`,le.map(s=>({label:s.name,value:s.id,hint:s.notYet?"not yet":s.where,disabled:!!s.notYet})),s=>Ne.includes(s));return t.length?T(`AI apps: ${t.map(s=>le.find(r=>r.id===s).name).join(", ")}`):M(`Nobody will be able to connect from an AI app until you allow one in ${B}.`),t}function pg(n,e){let t={"claude-code":`claude mcp add --transport http kuriko ${e} (then /mcp to sign in)`,claude:"Settings \u2192 Connectors \u2192 Add custom connector, with the MCP server address",codex:`codex mcp add kuriko --url ${e} (then codex mcp login kuriko)`,vscode:"Command Palette \u2192 MCP: Add Server \u2192 HTTP, with the MCP server address",cursor:"Settings \u2192 MCP \u2192 Add new MCP server, with the MCP server address",lovable:"Connectors \u2192 Add custom, with the MCP server address"},s=n.map(r=>` ${`${le.find(o=>o.id===r)?.name??r}:`.padEnd(14)}${t[r]??"add the MCP server address as a remote MCP server"}`);return s.length?s.join(`
365
+ `):` ${I(`No AI apps can connect yet: allow one in ${B}.`)}`}async function hg(n,e,t,s){for(;;)try{await Hs(n,"database",[As]);return}catch(r){if(!(r instanceof Q&&kl(r.stderr)))throw r;let i=bl(e.dbInstanceName);s.note=`${e.dbInstanceName} was taken, creating ${i}`,e.dbInstanceName=i,me(n,e),Nt(n,e,t)}}var mg=[["europe-west2","London"],["europe-west1","Belgium"],["europe-west3","Frankfurt"],["us-central1","Iowa"],["us-east1","South Carolina"],["us-west1","Oregon"],["asia-southeast1","Singapore"],["australia-southeast1","Sydney"]];async function gg(){return await ce("Region (where Kuriko and its data live):",[...mg.map(([e,t])=>({label:e,value:e,hint:t})),{label:"Another region\u2026",value:""}])||sr("Region:",void 0,gl,"Like europe-west2 or us-central1: https://cloud.google.com/run/docs/locations")}async function yg(){let n=Ze().filter(t=>rr(nt(t,Be)));if(!n.length)return null;await X({terraformOnly:!0});let e=await kn(n);return ce("Continue an install, or start a new one?",[{label:"Start a new install",value:null},...e.map(t=>{let s=Gs[t.status],r=t.status==="gone";return{label:`Continue ${t.project}`,value:t.dir,disabled:r,hint:`${t.region} ${s.mark} ${s.text}`}})])}async function sr(n,e,t,s){for(;;){let r=await te(n,e);if(t(r))return r;v(` ${s}`)}}async function wg(n){q("Choosing who runs Kuriko");let e=await St().catch(()=>[]),t=(e.find(r=>r.name===n.domain)??e[0])?.customerId,s=t?await P("Reading your Workspace's groups",()=>Ls(n.project,t)).catch(()=>null):null;s?T(`${s.length} group${s.length===1?"":"s"} in ${n.domain}`):M("Couldn't list your Workspace's groups (your account may not be allowed to). Type the group emails instead."),v(I(" Admins manage who can use which data and see the audit log. Builders make tools and deploy them into this project.")),v(I(" Everyone else who can sign in uses the tools shared with them. More groups can be given roles later, in policy.yaml.")),n.adminsGroup=await $u("admins",s,`kuriko-admins@${n.domain}`),n.buildersGroup=await $u("builders",s?.filter(r=>r.email!==n.adminsGroup)??null,`kuriko-builders@${n.domain}`),n.groupsChosen=!0,T(`Admins: ${C(n.adminsGroup)} Builders: ${C(n.buildersGroup)}`)}async function $u(n,e,t){let s=n==="admins"?`
366
+ Which group are Kuriko's admins?`:`
367
+ Which group can build tools?`,r=async()=>{for(;;){let l=(await te(e?" Group email, or part of its name:":" Group email:",e?void 0:t)).toLowerCase();if(!e){if(vs(l))return l;M(`${l} isn't an email address.`);continue}let d=e.find(f=>f.email===l);if(d)return d.email;let u=Cl(e,l);if(u.length===1&&await H(` ${u[0].email}${u[0].name?` (${u[0].name})`:""}?`,!0))return u[0].email;if(u.length>1&&u.length<=9){let f=await ce(" Which one?",[...u.map(h=>({label:h.email,value:h.email,hint:h.name})),{label:"None of these",value:""}]);if(f)return f}else if(u.length>9)M(`${u.length} groups match "${l}"; type more of it.`);else if(!u.length){if(vs(l)&&await H(` No group ${l} yet. Create it?`,!1))return l;M(`No group matches "${l}".`)}}};if(!e?.length)return r();let i=Nl(e,n),o={label:`Create ${t}`,value:t,hint:"(a new, empty group)"},a=[...i.length?[]:[o],...i.map(l=>({label:l.email,value:l.email,hint:l.name&&l.name.toLowerCase()!==l.email.split("@")[0]?l.name:void 0})),{label:"Another existing group\u2026",value:"?",hint:`(search all ${e.length})`},...i.length?[o]:[]],c=await ce(s,a);return c==="?"?r():c}p();async function Au(){if(!ke()){v(Bs);return}let n=Ze();if(!n.length){v(`No Kuriko installs yet. Start one with: ${C("kuriko install")}`);return}await X({terraformOnly:!0});let e=await kn(n),t={installed:xe("\u25CF installed"),partial:Qe("\u25D0 partly installed: run install to continue, or destroy"),empty:I("\u25CB not installed (or destroyed)"),gone:I("\u25CB project deleted"),unknown:Qe("? unknown")};for(let s of e)v(`
368
+ ${C(s.project)} ${I(s.region)} ${t[s.status]}`),s.web&&v(` web ${s.web}`),s.mcp&&v(` mcp ${s.mcp}`),s.detail&&v(s.status==="gone"?I(` ${s.detail}`):` ${Qe("!")} ${s.detail}`),v(I(` dir ${U(s.dir)}`))}p();import{existsSync as bg}from"node:fs";import{join as kg}from"node:path";var $g="module.kuriko.google_cloud_run_v2_job.migrate",Sg={create:"+",update:"~",replace:"\xB1",delete:"-"};async function vg(n,e){if(n==="unknown")return"forward";if(At(n)&&At(e)){let t=iu(n,e);return t===0?"same":t<0?"forward":"backward"}return!At(n)&&!At(e)?su(ne,n,e):"switch"}async function Eu(n){q("Checking this machine"),await he(pe());for(let f of["gcloud","terraform",...F?[]:["git"]])if(!await Ue(f,f==="terraform"?"-version":"--version"))throw new Error(`${f} isn't installed.`);if(await X(),!F&&!n.dryRun)try{await j("docker",["info","--format","{{.ServerVersion}}"])}catch{throw new Error("Docker isn't running. Start Docker Desktop (it builds Kuriko's images), then run this again.")}let e=await Ke(n.dir,"Which install should be upgraded?",["installed"],{partial:"finish it with kuriko install",empty:"nothing to upgrade",unknown:"can't read its state"}),t=Et(e),s=await Me(t.project);if(!s||s.state!=="ACTIVE")throw new Error(`Project ${t.project} isn't available (deleted, or your account can't see it).`);if(!await tt(e,"module.kuriko.google_cloud_run_v2_service.web"))throw new Error(`${t.project} isn't fully installed yet. Run install to finish it: kuriko install --dir ${t.project}`);let r=He(t,s.number);T(`Install ${C(t.project)} ${I(`(${U(e)})`)}`),q("What changes");let i=uu(e)??"unknown",o=await Ws(n.allowDirty),a=await vg(i,o);if(a==="backward")throw new Error(F?`${t.project} is on ${i}, newer than this CLI (${o}). Update the CLI first: npm i -g kuriko`:`${t.project} is on ${i}, which is newer than this Kuriko checkout (${o}). Pull the Kuriko repo first: git -C ${U(ne)} pull`);if(a==="unknown")throw new Error(`${t.project} is on ${i}, which this Kuriko checkout doesn't have. Pull the Kuriko repo first: git -C ${U(ne)} pull`);let c=du(e);F?($n(await Zs(t,o)),me(e,t)):$n(lu(e,t)),Js(e,t),Nt(e,t,o),await P("Preparing Terraform",()=>j("terraform",["init","-input=false"],{cwd:e}));let{plan:l}=await P("Working out the changes",()=>oo(e,"upgrade",null)),d=Es(l);if(i===o&&!d.length){c(),T(`Already on ${o}. Nothing to do.`);return}v(` Version ${i===o?o:`${I(i)} \u2192 ${C(o)}`}`),a==="switch"&&M(At(o)?`Moves from a development build to release ${o}.`:`Moves from release ${i} to a development build. Use this only for testing.`);let u=a==="forward"&&!F?await fu(i,o):[];if(u.length){v(` ${u.length} commit${u.length===1?"":"s"}:`);for(let f of u.slice(0,12))v(I(` ${f}`));u.length>12&&v(I(` \u2026 and ${u.length-12} more`))}v(d.length?" Cloud":" Cloud no resource changes");for(let f of d)v(I(` ${Sg[f.action]} ${f.address}${Ns.has(`module.kuriko.${f.address}`)?" (old project-wide secret access; policy.yaml grants each secret instead)":""}`));if(v(I(" No data or service is deleted. The database is migrated first; the web app and gateway switch over after.")),n.dryRun){c(),v(`
369
+ ${I("Dry run: nothing was changed.")}`);return}if(!await H(`
370
+ Upgrade?`,!0)){c(),v("Nothing was changed.");return}if(F||(q(`Kuriko's images (version ${o})`),await Xs(t.region,r.registry,o)),await Vs(t),q("Migrating the database"),await P("Updating the migrate job",()=>zs(e,"upgrade-migrate",[$g,...F?["module.kuriko.google_artifact_registry_repository.releases"]:[]])),await Qs(t,"kuriko-migrate",void 0,"Database schema"),d.some(f=>Ns.has(`module.kuriko.${f.address}`))){bg(kg(e,B))||M(`No ${B}: the gateway won't be able to read data source secrets until one names them (kuriko policy apply).`);let f=await P("Giving the gateway the secrets policy.yaml names, one by one",()=>gu(t,e));T(f.length?`The gateway can read ${f.map(h=>h.split("/").pop()).join(", ")}`:"The gateway already reads the secrets policy.yaml names")}q("Switching to the new version"),await P("Updating the web app and gateway",()=>zs(e,"upgrade",null)),T(`${t.project} is on ${C(o)}`),v(`
371
+ ${r.web}`),await De([e],`Upgrade ${t.project} to Kuriko ${o}${i!=="unknown"&&i!==o?` (from ${i})`:""}`)}p();import{existsSync as Ag,mkdirSync as Eg,writeFileSync as ho}from"node:fs";import{join as ir,resolve as Ng}from"node:path";var Cg=`# Kuriko installs
372
+
373
+ One folder per Kuriko install, named after its cloud project, made and changed by the \`kuriko\` CLI.
374
+ Each holds the install's answers (\`kuriko.json\`) and the Terraform config generated from them. No
375
+ secrets: those stay in the cloud's secret manager, and Terraform state stays in each install's own
376
+ state bucket.
377
+
378
+ Who can clone this repo can see the installs. Changing one also needs permissions on its cloud
379
+ project, which are granted separately.
380
+
381
+ \`\`\`bash
382
+ kuriko list # every install here, with its live status
383
+ kuriko upgrade # move one to the Kuriko version you have checked out
384
+ \`\`\`
385
+
386
+ Clone it next to your Kuriko checkout, or run \`kuriko\` from inside it.
387
+ `;async function Nu(n="."){let e=Ng(n);if(ke(e)===e){T(`${U(e)} is already an installs repo`);return}Eg(e,{recursive:!0}),ho(ir(e,Ds),JSON.stringify({kuriko:"installs",version:1},null,2)+`
388
+ `),ho(ir(e,".gitignore"),`.terraform/
389
+ .kuriko-*.plan
390
+ `),Ag(ir(e,"README.md"))||ho(ir(e,"README.md"),Cg);let s=!0;try{await j("git",["-C",e,"rev-parse","--git-dir"])}catch{s=!1}T(`${U(e)} is now an installs repo`),v(`
391
+ Share it through git: whoever can clone it can see your installs (changing one also needs
392
+ permissions on its cloud project). ${s?"Commit these files and push.":`Make it a git repo: ${C(`git -C ${U(e)} init`)}, then add a private remote.`}`)}var Sn={install:{usage:"install [--dir <install>] [--allow-dirty]",summary:"Put Kuriko in a Google Cloud project, for a company on Google Workspace",details:["Walks through every step, including the three done in Google's admin pages (an OAuth app,","two Google Groups, and the Groups Reader role), explaining each and checking it before moving on.","Takes about 30 minutes, mostly waiting for the database. Safe to re-run: it continues where it stopped.",""," --dir <install> Continue a specific install, by project ID (default: asks, if there are any)"," --allow-dirty Install from a checkout with uncommitted changes (images get a -dirty tag)"],run:n=>vu({dir:n.dir,allowDirty:n["allow-dirty"]})},list:{usage:"list",summary:"Show your installs, how far each got, and their URLs",details:["Reads each install's Terraform state, so it shows what's actually in the cloud."],run:()=>Au()},upgrade:{usage:"upgrade [--dir <install>] [--dry-run] [--allow-dirty]",summary:"Move an install to the version in this checkout",details:["Shows the version change, the commits in it and what changes in the cloud, then asks.","Builds and pushes the new images, migrates the database with the new version, and only then","switches the web app and gateway over. Never deletes anything; a plan that would is refused.",""," --dir <install> Which install, by project ID (default: asks, if there's more than one)"," --dry-run Show what would change, change nothing (no images built)"," --allow-dirty Upgrade to a checkout with uncommitted changes (images get a -dirty tag)"],run:n=>Eu({dir:n.dir,allowDirty:n["allow-dirty"],dryRun:n["dry-run"]})},policy:{usage:"policy plan|apply [--dir <install>] [--yes]",summary:"Change who can do what: roles, data sources and access, from the install's policy.yaml",details:["Each install's access lives in policy.yaml next to its Terraform: which Google groups are admins and","builders, which data sources exist (naming their secrets, never holding them), and who may use what.","plan shows what applying the file would change; apply shows the same, asks, and makes the install match.","Runs inside the cloud; every change is in the audit log. Commit the file so the repo is the record.",""," --dir <install> Which install, by project ID (default: asks, if there's more than one)"," --yes Apply without asking (for CI)"],run:(n,e)=>{if(e[0]!=="plan"&&e[0]!=="apply")throw new _t('Say "kuriko policy plan" or "kuriko policy apply".');return mu(e[0],{dir:n.dir,yes:n.yes})}},groups:{usage:"groups [search] [--dir <install>]",summary:"List your Google Groups, to name in policy.yaml, and which ones it already uses",details:["Shows every group in the install's Google Workspace with its name, marks the ones policy.yaml gives a","role or access to, and warns about groups policy.yaml names that don't exist. Membership is never","copied into Kuriko: people's groups are read from Workspace each time they sign in.",""," search Only groups whose email, name or description contains this"," --dir <install> Which install, by project ID (default: asks, if there's more than one)"],run:(n,e)=>ku({dir:n.dir,search:e.join(" ")||void 0})},destroy:{usage:"destroy [--dir <install>] [--dry-run] [--confirm <project-id>]",summary:"Remove an install from its cloud project",details:["Shows what will be deleted (the database and everything in it, services, accounts) and what stays","(the KMS key, your own secrets, the state bucket, the project), then asks for the project ID.",""," --dir <install> Which install, by project ID (default: asks, if there's more than one)"," --dry-run Show what would happen, change nothing"," --confirm <project-id> Give the project ID up front instead of typing it"],run:n=>wu({dir:n.dir,dryRun:n["dry-run"],confirm:n.confirm})},init:{usage:"init [folder]",summary:"Make a folder the installs repo you share with whoever runs Kuriko",details:["Installs (answers and Terraform config, no secrets) live in a git repo. Whoever can clone it sees","the installs; changing one also needs permissions on its cloud project. Commands find the repo","from inside it, from $KURIKO_INSTALLS, or as a kuriko-installs checkout next to the Kuriko one."],run:(n,e)=>Nu(e[0])},help:{usage:"help [command]",summary:"Show this, or the details of one command",details:[],run:async(n,e)=>or(e[0])}};function or(n){if(n){let t=Sn[n];if(!t)throw new _t(`No command "${n}".`);console.log(`${C(`kuriko ${t.usage}`)}
393
+
394
+ ${t.summary}.${t.details.length?`
395
+
396
+ ${t.details.join(`
397
+ `)}`:""}`);return}let e=Math.max(...Object.keys(Sn).map(t=>t.length));console.log(`${C("kuriko")} ${I("\xB7 runs Kuriko in your own cloud")}
398
+
399
+ Usage: kuriko <command> [options] ${I(F?`version ${F.version}`:"development build, from a Kuriko checkout")}
400
+
401
+ Commands:
402
+ ${Object.entries(Sn).map(([t,s])=>` ${t.padEnd(e)} ${s.summary}`).join(`
403
+ `)}
404
+
405
+ Run ${C("kuriko help <command>")} for a command's options.
406
+ ${Ig()}`)}function Ig(){let n=ke();return n?`Installs repo: ${U(n)}`:"No installs repo yet: clone yours next to the Kuriko checkout, or run kuriko init <folder>."}var _t=class extends Error{};try{let{positionals:n,values:e}=_g({allowPositionals:!0,options:{dir:{type:"string"},"allow-dirty":{type:"boolean"},confirm:{type:"string"},"dry-run":{type:"boolean"},yes:{type:"boolean"},help:{type:"boolean",short:"h"},version:{type:"boolean",short:"v"}}}),[t,...s]=n;if(e.version)console.log(F?F.version:"development build");else if(!t)or();else if(Sn[t])e.help?or(t):await Sn[t].run(e,s);else throw new _t(`No command "${t}".`)}catch(n){let e=n instanceof Error?n.message:String(n),t=/Unknown option '([^']+)'/.exec(e)?.[1],s=t?`No option ${t}.`:e,r=n.code;n instanceof _t||typeof r=="string"&&r.startsWith("ERR_PARSE_ARGS")?(console.error(`${de("\u2717")} ${s}
407
+ `),or(),process.exitCode=2):(console.error(`
408
+ ${de("\u2717")} ${s}`),process.exitCode=1)}