kuriko 0.3.1 → 0.3.2
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 +2 -2
- package/package.json +1 -1
package/kuriko.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire as __kurikoRequire } from "node:module"; const require = __kurikoRequire(import.meta.url);
|
|
3
|
-
var _u=Object.create;var mo=Object.defineProperty;var Iu=Object.getOwnPropertyDescriptor;var Tu=Object.getOwnPropertyNames;var Ou=Object.getPrototypeOf,Pu=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 ju=(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 Lu=(n,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Tu(e))!Pu.call(n,r)&&r!==t&&mo(n,r,{get:()=>e[r],enumerable:!(s=Iu(e,r))||s.enumerable});return n};var qu=(n,e,t)=>(t=n!=null?_u(Ou(n)):{},Lu(e||!n||!n.__esModule?mo(t,"default",{value:n,enumerable:!0}):t,n));var k,p=ju(()=>{k={version:"0.3.
|
|
3
|
+
var _u=Object.create;var mo=Object.defineProperty;var Iu=Object.getOwnPropertyDescriptor;var Tu=Object.getOwnPropertyNames;var Ou=Object.getPrototypeOf,Pu=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 ju=(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 Lu=(n,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Tu(e))!Pu.call(n,r)&&r!==t&&mo(n,r,{get:()=>e[r],enumerable:!(s=Iu(e,r))||s.enumerable});return n};var qu=(n,e,t)=>(t=n!=null?_u(Ou(n)):{},Lu(e||!n||!n.__esModule?mo(t,"default",{value:n,enumerable:!0}):t,n));var k,p=ju(()=>{k={version:"0.3.2"}});var x=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"),be=Symbol.for("yaml.node.type"),zu=n=>!!n&&typeof n=="object"&&n[be]===cr,Hu=n=>!!n&&typeof n=="object"&&n[be]===No,Qu=n=>!!n&&typeof n=="object"&&n[be]===Cn,Xu=n=>!!n&&typeof n=="object"&&n[be]===Co,_o=n=>!!n&&typeof n=="object"&&n[be]===lr,Zu=n=>!!n&&typeof n=="object"&&n[be]===_n;function Io(n){if(n&&typeof n=="object")switch(n[be]){case Cn:case _n:return!0}return!1}function ef(n){if(n&&typeof n=="object")switch(n[be]){case cr:case Cn:case lr:case _n:return!0}return!1}var tf=n=>(_o(n)||Io(n))&&!!n.anchor;J.ALIAS=cr;J.DOC=No;J.MAP=Cn;J.NODE_TYPE=be;J.PAIR=Co;J.SCALAR=lr;J.SEQ=_n;J.hasAnchor=tf;J.isAlias=zu;J.isCollection=Io;J.isDocument=Hu;J.isMap=Qu;J.isNode=ef;J.isPair=Xu;J.isScalar=_o;J.isSeq=Zu});var jt=S(ur=>{"use strict";p();var V=x(),Z=Symbol("break visit"),To=Symbol("skip children"),fe=Symbol("remove node");function In(n,e){let t=Oo(e);V.isDocument(n)?it(null,n.contents,t,Object.freeze([n]))===fe&&(n.contents=null):it(null,n,t,Object.freeze([]))}In.BREAK=Z;In.SKIP=To;In.REMOVE=fe;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===fe&&(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===fe&&(e.key=null);let o=it("value",e.value,t,s);if(o===Z)return Z;o===fe&&(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]))===fe&&(n.contents=null):await ot(null,n,t,Object.freeze([]))}Tn.BREAK=Z;Tn.SKIP=To;Tn.REMOVE=fe;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===fe&&(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===fe&&(e.key=null);let o=await ot("value",e.value,t,s);if(o===Z)return Z;o===fe&&(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=x(),nf=jt(),sf={"!":"%21",",":"%2C","[":"%5B","]":"%5D","{":"%7B","}":"%7D"},rf=n=>n.replace(/[!,[\]{}]/g,e=>sf[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+rf(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={};nf.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
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=x(),of=jt();function af(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 of.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 cf(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=af;qt.anchorNames=xo;qt.createNodeAnchors=cf;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 _e=S(Bo=>{"use strict";p();var lf=x();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||!lf.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 uf=dr(),Go=x(),ff=_e(),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=ff.toJS(this,"",o);if(typeof r=="function")for(let{count:c,res:l}of o.anchors.values())r(l,c);return typeof i=="function"?uf.applyReviver(i,{"":a},"",a):a}};Uo.NodeBase=pr});var xt=S(Fo=>{"use strict";p();var df=On(),pf=jt(),at=x(),hf=Pn(),mf=_e(),hr=class extends hf.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=[],pf.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||(mf.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(df.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 gf=x(),yf=Pn(),wf=_e(),bf=n=>!n||typeof n!="function"&&typeof n!="object",Ie=class extends yf.NodeBase{constructor(e){super(gf.SCALAR),this.value=e}toJSON(e,t){return t?.keep?this.value:wf.toJS(this.value,e,t)}toString(){return String(this.value)}};Ie.BLOCK_FOLDED="BLOCK_FOLDED";Ie.BLOCK_LITERAL="BLOCK_LITERAL";Ie.PLAIN="PLAIN";Ie.QUOTE_DOUBLE="QUOTE_DOUBLE";Ie.QUOTE_SINGLE="QUOTE_SINGLE";mr.Scalar=Ie;mr.isScalarValue=bf});var Mt=S(Vo=>{"use strict";p();var kf=xt(),Ye=x(),Yo=Y(),$f="tag:yaml.org,2002:";function Sf(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 vf(n,e,t){if(Ye.isDocument(n)&&(n=n.contents),Ye.isNode(n))return n;if(Ye.isPair(n)){let u=t.schema[Ye.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 kf.Alias(c.anchor);c={anchor:null,node:null},a.set(n,c)}e?.startsWith("!!")&&(e=$f+e.slice(2));let l=Sf(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[Ye.MAP]:Symbol.iterator in Object(n)?o[Ye.SEQ]:o[Ye.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=vf});var qn=S(Ln=>{"use strict";p();var Af=Mt(),de=x(),Ef=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 Af.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 Ef.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=>de.isNode(s)||de.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(de.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(de.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&&de.isScalar(i)?i.value:i:de.isCollection(i)?i.getIn(r,t):void 0}hasAllNullValues(e){return this.items.every(t=>{if(!de.isPair(t))return!1;let s=t.value;return s==null||e&&de.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 de.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(de.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 Nf=n=>n.replace(/^(?!$)(?: $)?/gm,"#");function wr(n,e){return/^\n+$/.test(n)?n.substring(1):e?n.replace(/^(?! *$)/gm,e):n}var Cf=(n,e,t)=>n.endsWith(`
|
|
5
5
|
`)?wr(t,e):t.includes(`
|
|
6
6
|
`)?`
|
|
@@ -138,7 +138,7 @@ ${t.comment}`:t.comment}this.doc.range[2]=t.offset;break}default:this.errors.pus
|
|
|
138
138
|
`)+1;for(;t!==0;)this.onNewLine(this.offset+t),t=this.source.indexOf(`
|
|
139
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(Re(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)&&!Re(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(Re(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]}):Re(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&&!Re(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||Re(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
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(),rm=en(),ln=sn(),im=Ar(),om=x(),am=Mi(),cl=Ki();function ll(n){let e=n.prettyErrors!==!1;return{lineCounter:n.lineCounter||e&&new am.LineCounter||null,prettyErrors:e}}function cm(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 lm(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=>im.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 um(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 om.isDocument(n)&&!s?n.toString(t):new rm.Document(n,s,t).toString(t)}un.parse=lm;un.parseAllDocuments=cm;un.parseDocument=ul;un.stringify=um});var pl=S(K=>{"use strict";p();var fm=Ni(),dm=en(),pm=oi(),Bi=sn(),hm=xt(),xe=x(),mm=Pe(),gm=Y(),ym=Le(),wm=qe(),bm=bs(),km=Ri(),$m=Mi(),Sm=Ki(),Ss=fl(),dl=jt();K.Composer=fm.Composer;K.Document=dm.Document;K.Schema=pm.Schema;K.YAMLError=Bi.YAMLError;K.YAMLParseError=Bi.YAMLParseError;K.YAMLWarning=Bi.YAMLWarning;K.Alias=hm.Alias;K.isAlias=xe.isAlias;K.isCollection=xe.isCollection;K.isDocument=xe.isDocument;K.isMap=xe.isMap;K.isNode=xe.isNode;K.isPair=xe.isPair;K.isScalar=xe.isScalar;K.isSeq=xe.isSeq;K.Pair=mm.Pair;K.Scalar=gm.Scalar;K.YAMLMap=ym.YAMLMap;K.YAMLSeq=wm.YAMLSeq;K.CST=bm;K.Lexer=km.Lexer;K.LineCounter=$m.LineCounter;K.Parser=Sm.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 Ig}from"node:util";p();import{existsSync as Hm,readFileSync as Qm}from"node:fs";import{join as Xm}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 ue=[{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:"
|
|
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(),rm=en(),ln=sn(),im=Ar(),om=x(),am=Mi(),cl=Ki();function ll(n){let e=n.prettyErrors!==!1;return{lineCounter:n.lineCounter||e&&new am.LineCounter||null,prettyErrors:e}}function cm(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 lm(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=>im.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 um(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 om.isDocument(n)&&!s?n.toString(t):new rm.Document(n,s,t).toString(t)}un.parse=lm;un.parseAllDocuments=cm;un.parseDocument=ul;un.stringify=um});var pl=S(K=>{"use strict";p();var fm=Ni(),dm=en(),pm=oi(),Bi=sn(),hm=xt(),xe=x(),mm=Pe(),gm=Y(),ym=Le(),wm=qe(),bm=bs(),km=Ri(),$m=Mi(),Sm=Ki(),Ss=fl(),dl=jt();K.Composer=fm.Composer;K.Document=dm.Document;K.Schema=pm.Schema;K.YAMLError=Bi.YAMLError;K.YAMLParseError=Bi.YAMLParseError;K.YAMLWarning=Bi.YAMLWarning;K.Alias=hm.Alias;K.isAlias=xe.isAlias;K.isCollection=xe.isCollection;K.isDocument=xe.isDocument;K.isMap=xe.isMap;K.isNode=xe.isNode;K.isPair=xe.isPair;K.isScalar=xe.isScalar;K.isSeq=xe.isSeq;K.Pair=mm.Pair;K.Scalar=gm.Scalar;K.YAMLMap=ym.YAMLMap;K.YAMLSeq=wm.YAMLSeq;K.CST=bm;K.Lexer=km.Lexer;K.LineCounter=$m.LineCounter;K.Parser=Sm.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 Ig}from"node:util";p();import{existsSync as Hm,readFileSync as Qm}from"node:fs";import{join as Xm}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 ue=[{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:"chatgpt",name:"ChatGPT",where:"chatgpt.com and its apps, including Codex there",documents:["https://chatgpt.com/oauth/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:"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=ue.filter(n=>!n.notYet),Ce=["claude-code","claude"],wo=new Map(ue.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 Mu="*",rt=class extends Error{name="PolicyFileError";problems;constructor(e){super(`policy.yaml has ${e.length===1?"a problem":`${e.length} problems`}:
|
|
142
142
|
${e.map(t=>` - ${t}`).join(`
|
|
143
143
|
`)}`),this.problems=e}},Du=new Set(["Viewer","Builder","Admin"]),ko=new Set(["notion","postgres"]),$o=/^[A-Za-z_][A-Za-z0-9_]{0,62}$/,Ku=/^[a-z][a-z0-9-]{1,30}$/,Bu=/^[a-z][a-z0-9_-]{0,40}$/,Gu=/^(?:projects\/[a-z][a-z0-9-]{4,28}[a-z0-9]\/secrets\/)?[A-Za-z0-9_-]{1,255}$/,Uu=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),Fu=n=>{let e=n.split("/").pop();return e.startsWith("kuriko-")&&!e.startsWith("kuriko-connector-")},Yu=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))Yu.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"||!Du.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(Ku.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"||!Gu.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.`):Uu(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).`):Fu(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))Bu.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!==Mu&&!$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?[...Ce]: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(Vu)),clients:Tt(n.clients??[...Ce])}}var Vu=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 Ue=(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 Ju}from"node:child_process";import{stripVTControlCharacters as Wu}from"node:util";var Q=class extends Error{command;code;stderr;constructor(e,t,s){let r=Wu(s);super(`${e} failed (exit ${t})${r.trim()?`:
|
|
144
144
|
${r.trim().split(`
|