@typescape-ai/cli 1.9.4 → 1.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli.js +3 -3
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -138,7 +138,7 @@ ${t.comment}`:t.comment}this.doc.range[2]=t.offset;break}default:this.errors.pus
138
138
  `)+1;while(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 n="end"in t.value?t.value.end:void 0;if((Array.isArray(n)?n[n.length-1]:void 0)?.type==="comment")n?.push(this.sourceToken);else e.items.push({start:[this.sourceToken]})}else if(t.sep)t.sep.push(this.sourceToken);else 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 a=e.items[e.items.length-2]?.value?.end;if(Array.isArray(a)){Array.prototype.push.apply(a,t.start),a.push(this.sourceToken),e.items.pop();return}}t.start.push(this.sourceToken)}return}if(this.indent>=e.indent){let n=!this.onKeyLine&&this.indent===e.indent,a=n&&(t.sep||t.explicitKey)&&this.type!=="seq-item-ind",r=[];if(a&&t.sep&&!t.value){let i=[];for(let o=0;o<t.sep.length;++o){let s=t.sep[o];switch(s.type){case"newline":i.push(o);break;case"space":break;case"comment":if(s.indent>e.indent)i.length=0;break;default:i.length=0}}if(i.length>=2)r=t.sep.splice(i[1])}switch(this.type){case"anchor":case"tag":if(a||t.value)r.push(this.sourceToken),e.items.push({start:r}),this.onKeyLine=!0;else if(t.sep)t.sep.push(this.sourceToken);else t.start.push(this.sourceToken);return;case"explicit-key-ind":if(!t.sep&&!t.explicitKey)t.start.push(this.sourceToken),t.explicitKey=!0;else if(a||t.value)r.push(this.sourceToken),e.items.push({start:r,explicitKey:!0});else 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($r(t.start,"newline"))Object.assign(t,{key:null,sep:[this.sourceToken]});else{let i=Uo(t.start);this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:i,key:null,sep:[this.sourceToken]}]})}else if(t.value)e.items.push({start:[],key:null,sep:[this.sourceToken]});else if($r(t.sep,"map-value-ind"))this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:r,key:null,sep:[this.sourceToken]}]});else if(c1(t.key)&&!$r(t.sep,"newline")){let i=Uo(t.start),o=t.key,s=t.sep;s.push(this.sourceToken),delete t.key,delete t.sep,this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:i,key:o,sep:s}]})}else if(r.length>0)t.sep=t.sep.concat(r,this.sourceToken);else t.sep.push(this.sourceToken);else if(!t.sep)Object.assign(t,{key:null,sep:[this.sourceToken]});else if(t.value||a)e.items.push({start:r,key:null,sep:[this.sourceToken]});else if($r(t.sep,"map-value-ind"))this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:[],key:null,sep:[this.sourceToken]}]});else t.sep.push(this.sourceToken);this.onKeyLine=!0;return;case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":{let i=this.flowScalar(this.type);if(a||t.value)e.items.push({start:r,key:i,sep:[]}),this.onKeyLine=!0;else if(t.sep)this.stack.push(i);else Object.assign(t,{key:i,sep:[]}),this.onKeyLine=!0;return}default:{let i=this.startBlockValue(e);if(i){if(i.type==="block-seq"){if(!t.explicitKey&&t.sep&&!$r(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 if(n)e.items.push({start:r});this.stack.push(i);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 n="end"in t.value?t.value.end:void 0;if((Array.isArray(n)?n[n.length-1]:void 0)?.type==="comment")n?.push(this.sourceToken);else 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 a=e.items[e.items.length-2]?.value?.end;if(Array.isArray(a)){Array.prototype.push.apply(a,t.start),a.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;if(t.value||$r(t.start,"seq-item-ind"))e.items.push({start:[this.sourceToken]});else t.start.push(this.sourceToken);return}if(this.indent>e.indent){let n=this.startBlockValue(e);if(n){this.stack.push(n);return}}yield*this.pop(),yield*this.step()}*flowCollection(e){let t=e.items[e.items.length-1];if(this.type==="flow-error-end"){let n;do yield*this.pop(),n=this.peek(1);while(n?.type==="flow-collection")}else if(e.end.length===0){switch(this.type){case"comma":case"explicit-key-ind":if(!t||t.sep)e.items.push({start:[this.sourceToken]});else t.start.push(this.sourceToken);return;case"map-value-ind":if(!t||t.value)e.items.push({start:[],key:null,sep:[this.sourceToken]});else if(t.sep)t.sep.push(this.sourceToken);else Object.assign(t,{key:null,sep:[this.sourceToken]});return;case"space":case"comment":case"newline":case"anchor":case"tag":if(!t||t.value)e.items.push({start:[this.sourceToken]});else if(t.sep)t.sep.push(this.sourceToken);else t.start.push(this.sourceToken);return;case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":{let a=this.flowScalar(this.type);if(!t||t.value)e.items.push({start:[],key:a,sep:[]});else if(t.sep)this.stack.push(a);else Object.assign(t,{key:a,sep:[]});return}case"flow-map-end":case"flow-seq-end":e.end.push(this.sourceToken);return}let n=this.startBlockValue(e);if(n)this.stack.push(n);else yield*this.pop(),yield*this.step()}else{let n=this.peek(2);if(n.type==="block-map"&&(this.type==="map-value-ind"&&n.indent===e.indent||this.type==="newline"&&!n.items[n.items.length-1].sep))yield*this.pop(),yield*this.step();else if(this.type==="map-value-ind"&&n.type!=="flow-collection"){let a=iu(n),r=Uo(a);s1(e);let i=e.end.splice(1,e.end.length);i.push(this.sourceToken);let o={type:"block-map",offset:e.offset,indent:e.indent,items:[{start:r,key:e,sep:i}]};this.onKeyLine=!0,this.stack[this.stack.length-1]=o}else yield*this.lineEnd(e)}}flowScalar(e){if(this.onNewLine){let t=this.source.indexOf(`
140
140
  `)+1;while(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=iu(e),n=Uo(t);return n.push(this.sourceToken),{type:"block-map",offset:this.offset,indent:this.indent,items:[{start:n,explicitKey:!0}]}}case"map-value-ind":{this.onKeyLine=!0;let t=iu(e),n=Uo(t);return{type:"block-map",offset:this.offset,indent:this.indent,items:[{start:n,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(e,t){if(this.type!=="comment")return!1;if(this.indent<=t)return!1;return e.every((n)=>n.type==="newline"||n.type==="space")}*documentEnd(e){if(this.type!=="doc-mode"){if(e.end)e.end.push(this.sourceToken);else e.end=[this.sourceToken];if(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;case"space":case"comment":default:if(e.end)e.end.push(this.sourceToken);else e.end=[this.sourceToken];if(this.type==="newline")yield*this.pop()}}}_re.Parser=A1});var m1=j((Sre)=>{var l1=Xf(),vre=Zc(),Xc=Yc(),Qre=Af(),xre=Ge(),Ire=Ah(),d1=lh();function u1(e){let t=e.prettyErrors!==!1;return{lineCounter:e.lineCounter||t&&new Ire.LineCounter||null,prettyErrors:t}}function Dre(e,t={}){let{lineCounter:n,prettyErrors:a}=u1(t),r=new d1.Parser(n?.addNewLine),i=new l1.Composer(t),o=Array.from(i.compose(r.parse(e)));if(a&&n)for(let s of o)s.errors.forEach(Xc.prettifyError(e,n)),s.warnings.forEach(Xc.prettifyError(e,n));if(o.length>0)return o;return Object.assign([],{empty:!0},i.streamInfo())}function p1(e,t={}){let{lineCounter:n,prettyErrors:a}=u1(t),r=new d1.Parser(n?.addNewLine),i=new l1.Composer(t),o=null;for(let s of i.compose(r.parse(e),!0,e.length))if(!o)o=s;else if(o.options.logLevel!=="silent"){o.errors.push(new Xc.YAMLParseError(s.range.slice(0,2),"MULTIPLE_DOCS","Source contains multiple documents; please use YAML.parseAllDocuments()"));break}if(a&&n)o.errors.forEach(Xc.prettifyError(e,n)),o.warnings.forEach(Xc.prettifyError(e,n));return o}function Fre(e,t,n){let a=void 0;if(typeof t==="function")a=t;else if(n===void 0&&t&&typeof t==="object")n=t;let r=p1(e,n);if(!r)return null;if(r.warnings.forEach((i)=>Qre.warn(r.options.logLevel,i)),r.errors.length>0)if(r.options.logLevel!=="silent")throw r.errors[0];else r.errors=[];return r.toJS(Object.assign({reviver:a},n))}function $re(e,t,n){let a=null;if(typeof t==="function"||Array.isArray(t))a=t;else if(n===void 0&&t)n=t;if(typeof n==="string")n=n.length;if(typeof n==="number"){let r=Math.round(n);n=r<1?void 0:r>8?{indent:8}:{indent:r}}if(e===void 0){let{keepUndefined:r}=n??t??{};if(!r)return}if(xre.isDocument(e)&&!a)return e.toString(n);return new vre.Document(e,a,n).toString(n)}Sre.parse=Fre;Sre.parseAllDocuments=Dre;Sre.parseDocument=p1;Sre.stringify=$re});var hh=j((zHe,Xie)=>{Xie.exports={name:"@typescape-ai/cli",version:"1.9.4",description:"Typescape CLI - Create review sessions, export feedback, and integrate with AI workflows",type:"module",bin:{typescape:"./dist/cli.js"},files:["dist","README.md"],exports:{".":"./dist/cli.js"},publishConfig:{access:"public"},scripts:{build:"bun build src/index.ts --outfile=dist/cli.js --target=bun --bundle --minify",dev:"bun run --watch src/index.ts",test:"bun test",typecheck:"tsc -p tsconfig.typecheck.json --noEmit",lint:"eslint src",prepublishOnly:"bun run build"},dependencies:{},devDependencies:{"@types/bun":"1.1.14","@typescape/integrity":"workspace:*","@typescape/schemas":"workspace:*",ajv:"8.17.1","ajv-formats":"3.0.1",yaml:"2.8.2",zod:"4.3.0"},engines:{bun:">=1.0.0"},keywords:["typescape","cli","review","documentation","ai","feedback","bun"],repository:{type:"git",url:"https://github.com/voidserf/typescape-docs.git",directory:"apps/cli"},license:"MIT"}});var eF=j((aYe,X1)=>{var Oo=1000,Zo=Oo*60,Yo=Zo*60,Ni=Yo*24,$se=Ni*7,Sse=Ni*365.25;X1.exports=function(e,t){t=t||{};var n=typeof e;if(n==="string"&&e.length>0)return Lse(e);else if(n==="number"&&isFinite(e))return t.long?qse(e):jse(e);throw Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))};function Lse(e){if(e=String(e),e.length>100)return;var t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(!t)return;var n=parseFloat(t[1]),a=(t[2]||"ms").toLowerCase();switch(a){case"years":case"year":case"yrs":case"yr":case"y":return n*Sse;case"weeks":case"week":case"w":return n*$se;case"days":case"day":case"d":return n*Ni;case"hours":case"hour":case"hrs":case"hr":case"h":return n*Yo;case"minutes":case"minute":case"mins":case"min":case"m":return n*Zo;case"seconds":case"second":case"secs":case"sec":case"s":return n*Oo;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:return}}function jse(e){var t=Math.abs(e);if(t>=Ni)return Math.round(e/Ni)+"d";if(t>=Yo)return Math.round(e/Yo)+"h";if(t>=Zo)return Math.round(e/Zo)+"m";if(t>=Oo)return Math.round(e/Oo)+"s";return e+"ms"}function qse(e){var t=Math.abs(e);if(t>=Ni)return _u(e,t,Ni,"day");if(t>=Yo)return _u(e,t,Yo,"hour");if(t>=Zo)return _u(e,t,Zo,"minute");if(t>=Oo)return _u(e,t,Oo,"second");return e+" ms"}function _u(e,t,n,a){var r=t>=n*1.5;return Math.round(e/n)+" "+a+(r?"s":"")}});var qh=j((rYe,tF)=>{function Nse(e){n.debug=n,n.default=n,n.coerce=c,n.disable=o,n.enable=r,n.enabled=s,n.humanize=eF(),n.destroy=A,Object.keys(e).forEach((l)=>{n[l]=e[l]}),n.names=[],n.skips=[],n.formatters={};function t(l){let d=0;for(let u=0;u<l.length;u++)d=(d<<5)-d+l.charCodeAt(u),d|=0;return n.colors[Math.abs(d)%n.colors.length]}n.selectColor=t;function n(l){let d,u=null,p,m;function g(...y){if(!g.enabled)return;let w=g,_=Number(new Date),C=_-(d||_);if(w.diff=C,w.prev=d,w.curr=_,d=_,y[0]=n.coerce(y[0]),typeof y[0]!=="string")y.unshift("%O");let $=0;y[0]=y[0].replace(/%([a-zA-Z%])/g,(I,U)=>{if(I==="%%")return"%";$++;let P=n.formatters[U];if(typeof P==="function"){let W=y[$];I=P.call(w,W),y.splice($,1),$--}return I}),n.formatArgs.call(w,y),(w.log||n.log).apply(w,y)}if(g.namespace=l,g.useColors=n.useColors(),g.color=n.selectColor(l),g.extend=a,g.destroy=n.destroy,Object.defineProperty(g,"enabled",{enumerable:!0,configurable:!1,get:()=>{if(u!==null)return u;if(p!==n.namespaces)p=n.namespaces,m=n.enabled(l);return m},set:(y)=>{u=y}}),typeof n.init==="function")n.init(g);return g}function a(l,d){let u=n(this.namespace+(typeof d>"u"?":":d)+l);return u.log=this.log,u}function r(l){n.save(l),n.namespaces=l,n.names=[],n.skips=[];let d=(typeof l==="string"?l:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(let u of d)if(u[0]==="-")n.skips.push(u.slice(1));else n.names.push(u)}function i(l,d){let u=0,p=0,m=-1,g=0;while(u<l.length)if(p<d.length&&(d[p]===l[u]||d[p]==="*"))if(d[p]==="*")m=p,g=u,p++;else u++,p++;else if(m!==-1)p=m+1,g++,u=g;else return!1;while(p<d.length&&d[p]==="*")p++;return p===d.length}function o(){let l=[...n.names,...n.skips.map((d)=>"-"+d)].join(",");return n.enable(""),l}function s(l){for(let d of n.skips)if(i(l,d))return!1;for(let d of n.names)if(i(l,d))return!0;return!1}function c(l){if(l instanceof Error)return l.stack||l.message;return l}function A(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return n.enable(n.load()),n}tF.exports=Nse});var aF=j((nF,Eu)=>{nF.formatArgs=Gse;nF.save=Rse;nF.load=Pse;nF.useColors=Mse;nF.storage=zse();nF.destroy=(()=>{let e=!1;return()=>{if(!e)e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}})();nF.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function Mse(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let e;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(e=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(e[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function Gse(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+Eu.exports.humanize(this.diff),!this.useColors)return;let t="color: "+this.color;e.splice(1,0,t,"color: inherit");let n=0,a=0;e[0].replace(/%[a-zA-Z%]/g,(r)=>{if(r==="%%")return;if(n++,r==="%c")a=n}),e.splice(a,0,t)}nF.log=console.debug||console.log||(()=>{});function Rse(e){try{if(e)nF.storage.setItem("debug",e);else nF.storage.removeItem("debug")}catch(t){}}function Pse(){let e;try{e=nF.storage.getItem("debug")||nF.storage.getItem("DEBUG")}catch(t){}if(!e&&typeof process<"u"&&"env"in process)e=process.env.DEBUG;return e}function zse(){try{return localStorage}catch(e){}}Eu.exports=qh()(nF);var{formatters:Use}=Eu.exports;Use.j=function(e){try{return JSON.stringify(e)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}});var iF=j((oYe,rF)=>{rF.exports=(e,t=process.argv)=>{let n=e.startsWith("-")?"":e.length===1?"-":"--",a=t.indexOf(n+e),r=t.indexOf("--");return a!==-1&&(r===-1||a<r)}});var cF=j((sYe,sF)=>{var Jse=jn("os"),oF=jn("tty"),Gn=iF(),{env:jt}=process,Nr;if(Gn("no-color")||Gn("no-colors")||Gn("color=false")||Gn("color=never"))Nr=0;else if(Gn("color")||Gn("colors")||Gn("color=true")||Gn("color=always"))Nr=1;if("FORCE_COLOR"in jt)if(jt.FORCE_COLOR==="true")Nr=1;else if(jt.FORCE_COLOR==="false")Nr=0;else Nr=jt.FORCE_COLOR.length===0?1:Math.min(parseInt(jt.FORCE_COLOR,10),3);function Nh(e){if(e===0)return!1;return{level:e,hasBasic:!0,has256:e>=2,has16m:e>=3}}function Mh(e,t){if(Nr===0)return 0;if(Gn("color=16m")||Gn("color=full")||Gn("color=truecolor"))return 3;if(Gn("color=256"))return 2;if(e&&!t&&Nr===void 0)return 0;let n=Nr||0;if(jt.TERM==="dumb")return n;if(process.platform==="win32"){let a=Jse.release().split(".");if(Number(a[0])>=10&&Number(a[2])>=10586)return Number(a[2])>=14931?3:2;return 1}if("CI"in jt){if(["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","GITHUB_ACTIONS","BUILDKITE"].some((a)=>(a in jt))||jt.CI_NAME==="codeship")return 1;return n}if("TEAMCITY_VERSION"in jt)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(jt.TEAMCITY_VERSION)?1:0;if(jt.COLORTERM==="truecolor")return 3;if("TERM_PROGRAM"in jt){let a=parseInt((jt.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(jt.TERM_PROGRAM){case"iTerm.app":return a>=3?3:2;case"Apple_Terminal":return 2}}if(/-256(color)?$/i.test(jt.TERM))return 2;if(/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(jt.TERM))return 1;if("COLORTERM"in jt)return 1;return n}function Vse(e){let t=Mh(e,e&&e.isTTY);return Nh(t)}sF.exports={supportsColor:Vse,stdout:Nh(Mh(!0,oF.isatty(1))),stderr:Nh(Mh(!0,oF.isatty(2)))}});var uF=j((lF,Qu)=>{var Xse=jn("tty"),vu=jn("util");lF.init=oce;lF.log=ace;lF.formatArgs=tce;lF.save=rce;lF.load=ice;lF.useColors=ece;lF.destroy=vu.deprecate(()=>{},"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");lF.colors=[6,2,3,4,5,1];try{let e=cF();if(e&&(e.stderr||e).level>=2)lF.colors=[20,21,26,27,32,33,38,39,40,41,42,43,44,45,56,57,62,63,68,69,74,75,76,77,78,79,80,81,92,93,98,99,112,113,128,129,134,135,148,149,160,161,162,163,164,165,166,167,168,169,170,171,172,173,178,179,184,185,196,197,198,199,200,201,202,203,204,205,206,207,208,209,214,215,220,221]}catch(e){}lF.inspectOpts=Object.keys(process.env).filter((e)=>{return/^debug_/i.test(e)}).reduce((e,t)=>{let n=t.substring(6).toLowerCase().replace(/_([a-z])/g,(r,i)=>{return i.toUpperCase()}),a=process.env[t];if(/^(yes|on|true|enabled)$/i.test(a))a=!0;else if(/^(no|off|false|disabled)$/i.test(a))a=!1;else if(a==="null")a=null;else a=Number(a);return e[n]=a,e},{});function ece(){return"colors"in lF.inspectOpts?Boolean(lF.inspectOpts.colors):Xse.isatty(process.stderr.fd)}function tce(e){let{namespace:t,useColors:n}=this;if(n){let a=this.color,r="\x1B[3"+(a<8?a:"8;5;"+a),i=` ${r};1m${t} \x1B[0m`;e[0]=i+e[0].split(`
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=iu(e),n=Uo(t);return n.push(this.sourceToken),{type:"block-map",offset:this.offset,indent:this.indent,items:[{start:n,explicitKey:!0}]}}case"map-value-ind":{this.onKeyLine=!0;let t=iu(e),n=Uo(t);return{type:"block-map",offset:this.offset,indent:this.indent,items:[{start:n,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(e,t){if(this.type!=="comment")return!1;if(this.indent<=t)return!1;return e.every((n)=>n.type==="newline"||n.type==="space")}*documentEnd(e){if(this.type!=="doc-mode"){if(e.end)e.end.push(this.sourceToken);else e.end=[this.sourceToken];if(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;case"space":case"comment":default:if(e.end)e.end.push(this.sourceToken);else e.end=[this.sourceToken];if(this.type==="newline")yield*this.pop()}}}_re.Parser=A1});var m1=j((Sre)=>{var l1=Xf(),vre=Zc(),Xc=Yc(),Qre=Af(),xre=Ge(),Ire=Ah(),d1=lh();function u1(e){let t=e.prettyErrors!==!1;return{lineCounter:e.lineCounter||t&&new Ire.LineCounter||null,prettyErrors:t}}function Dre(e,t={}){let{lineCounter:n,prettyErrors:a}=u1(t),r=new d1.Parser(n?.addNewLine),i=new l1.Composer(t),o=Array.from(i.compose(r.parse(e)));if(a&&n)for(let s of o)s.errors.forEach(Xc.prettifyError(e,n)),s.warnings.forEach(Xc.prettifyError(e,n));if(o.length>0)return o;return Object.assign([],{empty:!0},i.streamInfo())}function p1(e,t={}){let{lineCounter:n,prettyErrors:a}=u1(t),r=new d1.Parser(n?.addNewLine),i=new l1.Composer(t),o=null;for(let s of i.compose(r.parse(e),!0,e.length))if(!o)o=s;else if(o.options.logLevel!=="silent"){o.errors.push(new Xc.YAMLParseError(s.range.slice(0,2),"MULTIPLE_DOCS","Source contains multiple documents; please use YAML.parseAllDocuments()"));break}if(a&&n)o.errors.forEach(Xc.prettifyError(e,n)),o.warnings.forEach(Xc.prettifyError(e,n));return o}function Fre(e,t,n){let a=void 0;if(typeof t==="function")a=t;else if(n===void 0&&t&&typeof t==="object")n=t;let r=p1(e,n);if(!r)return null;if(r.warnings.forEach((i)=>Qre.warn(r.options.logLevel,i)),r.errors.length>0)if(r.options.logLevel!=="silent")throw r.errors[0];else r.errors=[];return r.toJS(Object.assign({reviver:a},n))}function $re(e,t,n){let a=null;if(typeof t==="function"||Array.isArray(t))a=t;else if(n===void 0&&t)n=t;if(typeof n==="string")n=n.length;if(typeof n==="number"){let r=Math.round(n);n=r<1?void 0:r>8?{indent:8}:{indent:r}}if(e===void 0){let{keepUndefined:r}=n??t??{};if(!r)return}if(xre.isDocument(e)&&!a)return e.toString(n);return new vre.Document(e,a,n).toString(n)}Sre.parse=Fre;Sre.parseAllDocuments=Dre;Sre.parseDocument=p1;Sre.stringify=$re});var hh=j((zHe,Xie)=>{Xie.exports={name:"@typescape-ai/cli",version:"1.9.5",description:"Typescape CLI - Create review sessions, export feedback, and integrate with AI workflows",type:"module",bin:{typescape:"./dist/cli.js"},files:["dist","README.md"],exports:{".":"./dist/cli.js"},publishConfig:{access:"public"},scripts:{build:"bun build src/index.ts --outfile=dist/cli.js --target=bun --bundle --minify",dev:"bun run --watch src/index.ts",test:"bun test",typecheck:"tsc -p tsconfig.typecheck.json --noEmit",lint:"eslint src",prepublishOnly:"bun run build"},dependencies:{},devDependencies:{"@types/bun":"1.1.14","@typescape/integrity":"workspace:*","@typescape/schemas":"workspace:*",ajv:"8.17.1","ajv-formats":"3.0.1",yaml:"2.8.2",zod:"4.3.0"},engines:{bun:">=1.0.0"},keywords:["typescape","cli","review","documentation","ai","feedback","bun"],repository:{type:"git",url:"https://github.com/voidserf/typescape-docs.git",directory:"apps/cli"},license:"MIT"}});var eF=j((aYe,X1)=>{var Oo=1000,Zo=Oo*60,Yo=Zo*60,Ni=Yo*24,$se=Ni*7,Sse=Ni*365.25;X1.exports=function(e,t){t=t||{};var n=typeof e;if(n==="string"&&e.length>0)return Lse(e);else if(n==="number"&&isFinite(e))return t.long?qse(e):jse(e);throw Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))};function Lse(e){if(e=String(e),e.length>100)return;var t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(!t)return;var n=parseFloat(t[1]),a=(t[2]||"ms").toLowerCase();switch(a){case"years":case"year":case"yrs":case"yr":case"y":return n*Sse;case"weeks":case"week":case"w":return n*$se;case"days":case"day":case"d":return n*Ni;case"hours":case"hour":case"hrs":case"hr":case"h":return n*Yo;case"minutes":case"minute":case"mins":case"min":case"m":return n*Zo;case"seconds":case"second":case"secs":case"sec":case"s":return n*Oo;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:return}}function jse(e){var t=Math.abs(e);if(t>=Ni)return Math.round(e/Ni)+"d";if(t>=Yo)return Math.round(e/Yo)+"h";if(t>=Zo)return Math.round(e/Zo)+"m";if(t>=Oo)return Math.round(e/Oo)+"s";return e+"ms"}function qse(e){var t=Math.abs(e);if(t>=Ni)return _u(e,t,Ni,"day");if(t>=Yo)return _u(e,t,Yo,"hour");if(t>=Zo)return _u(e,t,Zo,"minute");if(t>=Oo)return _u(e,t,Oo,"second");return e+" ms"}function _u(e,t,n,a){var r=t>=n*1.5;return Math.round(e/n)+" "+a+(r?"s":"")}});var qh=j((rYe,tF)=>{function Nse(e){n.debug=n,n.default=n,n.coerce=c,n.disable=o,n.enable=r,n.enabled=s,n.humanize=eF(),n.destroy=A,Object.keys(e).forEach((l)=>{n[l]=e[l]}),n.names=[],n.skips=[],n.formatters={};function t(l){let d=0;for(let u=0;u<l.length;u++)d=(d<<5)-d+l.charCodeAt(u),d|=0;return n.colors[Math.abs(d)%n.colors.length]}n.selectColor=t;function n(l){let d,u=null,p,m;function g(...y){if(!g.enabled)return;let w=g,_=Number(new Date),C=_-(d||_);if(w.diff=C,w.prev=d,w.curr=_,d=_,y[0]=n.coerce(y[0]),typeof y[0]!=="string")y.unshift("%O");let $=0;y[0]=y[0].replace(/%([a-zA-Z%])/g,(I,U)=>{if(I==="%%")return"%";$++;let P=n.formatters[U];if(typeof P==="function"){let W=y[$];I=P.call(w,W),y.splice($,1),$--}return I}),n.formatArgs.call(w,y),(w.log||n.log).apply(w,y)}if(g.namespace=l,g.useColors=n.useColors(),g.color=n.selectColor(l),g.extend=a,g.destroy=n.destroy,Object.defineProperty(g,"enabled",{enumerable:!0,configurable:!1,get:()=>{if(u!==null)return u;if(p!==n.namespaces)p=n.namespaces,m=n.enabled(l);return m},set:(y)=>{u=y}}),typeof n.init==="function")n.init(g);return g}function a(l,d){let u=n(this.namespace+(typeof d>"u"?":":d)+l);return u.log=this.log,u}function r(l){n.save(l),n.namespaces=l,n.names=[],n.skips=[];let d=(typeof l==="string"?l:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(let u of d)if(u[0]==="-")n.skips.push(u.slice(1));else n.names.push(u)}function i(l,d){let u=0,p=0,m=-1,g=0;while(u<l.length)if(p<d.length&&(d[p]===l[u]||d[p]==="*"))if(d[p]==="*")m=p,g=u,p++;else u++,p++;else if(m!==-1)p=m+1,g++,u=g;else return!1;while(p<d.length&&d[p]==="*")p++;return p===d.length}function o(){let l=[...n.names,...n.skips.map((d)=>"-"+d)].join(",");return n.enable(""),l}function s(l){for(let d of n.skips)if(i(l,d))return!1;for(let d of n.names)if(i(l,d))return!0;return!1}function c(l){if(l instanceof Error)return l.stack||l.message;return l}function A(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return n.enable(n.load()),n}tF.exports=Nse});var aF=j((nF,Eu)=>{nF.formatArgs=Gse;nF.save=Rse;nF.load=Pse;nF.useColors=Mse;nF.storage=zse();nF.destroy=(()=>{let e=!1;return()=>{if(!e)e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}})();nF.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function Mse(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let e;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(e=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(e[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function Gse(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+Eu.exports.humanize(this.diff),!this.useColors)return;let t="color: "+this.color;e.splice(1,0,t,"color: inherit");let n=0,a=0;e[0].replace(/%[a-zA-Z%]/g,(r)=>{if(r==="%%")return;if(n++,r==="%c")a=n}),e.splice(a,0,t)}nF.log=console.debug||console.log||(()=>{});function Rse(e){try{if(e)nF.storage.setItem("debug",e);else nF.storage.removeItem("debug")}catch(t){}}function Pse(){let e;try{e=nF.storage.getItem("debug")||nF.storage.getItem("DEBUG")}catch(t){}if(!e&&typeof process<"u"&&"env"in process)e=process.env.DEBUG;return e}function zse(){try{return localStorage}catch(e){}}Eu.exports=qh()(nF);var{formatters:Use}=Eu.exports;Use.j=function(e){try{return JSON.stringify(e)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}});var iF=j((oYe,rF)=>{rF.exports=(e,t=process.argv)=>{let n=e.startsWith("-")?"":e.length===1?"-":"--",a=t.indexOf(n+e),r=t.indexOf("--");return a!==-1&&(r===-1||a<r)}});var cF=j((sYe,sF)=>{var Jse=jn("os"),oF=jn("tty"),Gn=iF(),{env:jt}=process,Nr;if(Gn("no-color")||Gn("no-colors")||Gn("color=false")||Gn("color=never"))Nr=0;else if(Gn("color")||Gn("colors")||Gn("color=true")||Gn("color=always"))Nr=1;if("FORCE_COLOR"in jt)if(jt.FORCE_COLOR==="true")Nr=1;else if(jt.FORCE_COLOR==="false")Nr=0;else Nr=jt.FORCE_COLOR.length===0?1:Math.min(parseInt(jt.FORCE_COLOR,10),3);function Nh(e){if(e===0)return!1;return{level:e,hasBasic:!0,has256:e>=2,has16m:e>=3}}function Mh(e,t){if(Nr===0)return 0;if(Gn("color=16m")||Gn("color=full")||Gn("color=truecolor"))return 3;if(Gn("color=256"))return 2;if(e&&!t&&Nr===void 0)return 0;let n=Nr||0;if(jt.TERM==="dumb")return n;if(process.platform==="win32"){let a=Jse.release().split(".");if(Number(a[0])>=10&&Number(a[2])>=10586)return Number(a[2])>=14931?3:2;return 1}if("CI"in jt){if(["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","GITHUB_ACTIONS","BUILDKITE"].some((a)=>(a in jt))||jt.CI_NAME==="codeship")return 1;return n}if("TEAMCITY_VERSION"in jt)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(jt.TEAMCITY_VERSION)?1:0;if(jt.COLORTERM==="truecolor")return 3;if("TERM_PROGRAM"in jt){let a=parseInt((jt.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(jt.TERM_PROGRAM){case"iTerm.app":return a>=3?3:2;case"Apple_Terminal":return 2}}if(/-256(color)?$/i.test(jt.TERM))return 2;if(/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(jt.TERM))return 1;if("COLORTERM"in jt)return 1;return n}function Vse(e){let t=Mh(e,e&&e.isTTY);return Nh(t)}sF.exports={supportsColor:Vse,stdout:Nh(Mh(!0,oF.isatty(1))),stderr:Nh(Mh(!0,oF.isatty(2)))}});var uF=j((lF,Qu)=>{var Xse=jn("tty"),vu=jn("util");lF.init=oce;lF.log=ace;lF.formatArgs=tce;lF.save=rce;lF.load=ice;lF.useColors=ece;lF.destroy=vu.deprecate(()=>{},"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");lF.colors=[6,2,3,4,5,1];try{let e=cF();if(e&&(e.stderr||e).level>=2)lF.colors=[20,21,26,27,32,33,38,39,40,41,42,43,44,45,56,57,62,63,68,69,74,75,76,77,78,79,80,81,92,93,98,99,112,113,128,129,134,135,148,149,160,161,162,163,164,165,166,167,168,169,170,171,172,173,178,179,184,185,196,197,198,199,200,201,202,203,204,205,206,207,208,209,214,215,220,221]}catch(e){}lF.inspectOpts=Object.keys(process.env).filter((e)=>{return/^debug_/i.test(e)}).reduce((e,t)=>{let n=t.substring(6).toLowerCase().replace(/_([a-z])/g,(r,i)=>{return i.toUpperCase()}),a=process.env[t];if(/^(yes|on|true|enabled)$/i.test(a))a=!0;else if(/^(no|off|false|disabled)$/i.test(a))a=!1;else if(a==="null")a=null;else a=Number(a);return e[n]=a,e},{});function ece(){return"colors"in lF.inspectOpts?Boolean(lF.inspectOpts.colors):Xse.isatty(process.stderr.fd)}function tce(e){let{namespace:t,useColors:n}=this;if(n){let a=this.color,r="\x1B[3"+(a<8?a:"8;5;"+a),i=` ${r};1m${t} \x1B[0m`;e[0]=i+e[0].split(`
142
142
  `).join(`
143
143
  `+i),e.push(r+"m+"+Qu.exports.humanize(this.diff)+"\x1B[0m")}else e[0]=nce()+t+" "+e[0]}function nce(){if(lF.inspectOpts.hideDate)return"";return new Date().toISOString()+" "}function ace(...e){return process.stderr.write(vu.formatWithOptions(lF.inspectOpts,...e)+`
144
144
  `)}function rce(e){if(e)process.env.DEBUG=e;else delete process.env.DEBUG}function ice(){return process.env.DEBUG}function oce(e){e.inspectOpts={};let t=Object.keys(lF.inspectOpts);for(let n=0;n<t.length;n++)e.inspectOpts[t[n]]=lF.inspectOpts[t[n]]}Qu.exports=qh()(lF);var{formatters:AF}=Qu.exports;AF.o=function(e){return this.inspectOpts.colors=this.useColors,vu.inspect(e,this.inspectOpts).split(`
@@ -654,7 +654,7 @@ Result: ${l.length} findings (${d} blocking, ${u} other)`)}if((s.findings||[]).s
654
654
  `)+`
655
655
  `}function gH(e){let t=B$e(e);if(!t.file)D({code:"missing_required_flag",message:"Missing required flag: --file"},S);let n;try{n=SQ(t.file,"utf-8")}catch{D({code:"file_not_found",message:`File not found: ${t.file}`},S)}let a=Lr(n),r=Gr(a.content,a.bytes),i=a.content.split(`
656
656
  `),o=r.blocks.map((A)=>{let l=i[A.startLine-1]||"";return{blockKey:A.blockKey||C$e(A.blockType,A.blockIndex,l),blockType:A.blockType,blockIndex:A.blockIndex,contentPreview:l}}),s=mH(t.file),c=E$e(t.file,o);if(t.format==="json")console.log(JSON.stringify({file:t.file,sidecar_path:s,total_blocks:r.blocks.length,anchors:o.map((A)=>({block_key:A.blockKey,block_type:A.blockType,block_index:A.blockIndex})),applied:t.write},null,2));else console.log(`${r.blocks.length} blocks -> ${s}`);if(!t.write){if(t.format!=="json")console.log("Run with --write to create/update the sidecar file.");process.exit(H)}if(b$e(f$e(s),{recursive:!0}),g$e(s,c,"utf-8"),t.format!=="json")console.log(`Wrote ${s}`);process.exit(H)}function v$e(e){let t={file:"",format:"text"},n=0;while(n<e.length){let a=e[n];if(a==="--file")t.file=e[n+1]||"",n+=2;else if(a.startsWith("--file="))t.file=a.slice(7),n++;else if(a==="--format")t.format=e[n+1]||"text",n+=2;else if(a.startsWith("--format="))t.format=a.slice(9),n++;else n++}return t}function Q$e(e){let t=[],n=null;for(let a of e.split(`
657
- `)){let r=a.trim();if(r.startsWith("- block_key:")){if(n)t.push({block_key:Ab(n.block_key||""),block_type:Ab(n.block_type||""),block_index:parseInt(n.block_index||"0",10)});n={block_key:r.replace("- block_key:","").trim()}}else if(n&&r.startsWith("block_type:"))n.block_type=r.replace("block_type:","").trim();else if(n&&r.startsWith("block_index:"))n.block_index=r.replace("block_index:","").trim()}if(n)t.push({block_key:Ab(n.block_key||""),block_type:Ab(n.block_type||""),block_index:parseInt(n.block_index||"0",10)});return t}function Ab(e){if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return e.slice(1,-1);return e}function bH(e){let t=v$e(e);if(!t.file)D({code:"missing_required_flag",message:"Missing required flag: --file"},S);let n;try{n=SQ(t.file,"utf-8")}catch{D({code:"file_not_found",message:`File not found: ${t.file}`},S)}let a=mH(t.file),r;try{r=SQ(a,"utf-8")}catch{D({code:"sidecar_not_found",message:`Sidecar file not found: ${a}. Run 'typescape anchors apply --file ${t.file} --write' first.`},S)}let i=Lr(n),o=Gr(i.content,i.bytes),s=Q$e(r),c=new Map;for(let m of o.blocks)c.set(m.blockIndex,m);let A=[],l=[],d=[];for(let m of s){let g=c.get(m.block_index);if(!g){A.push(`${m.block_key} (index ${m.block_index}): block no longer exists`);continue}if(g.blockType!==m.block_type)A.push(`${m.block_key} (index ${m.block_index}): type changed from ${m.block_type} to ${g.blockType}`)}let u=new Set(s.map((m)=>m.block_index));for(let m of o.blocks)if(!u.has(m.blockIndex)&&!m.blockKey)d.push(`Block ${m.blockIndex} (${m.blockType}, line ${m.startLine}): not in sidecar and has no marker`);let p=A.length>0||l.length>0||d.length>0;if(t.format==="json")console.log(JSON.stringify({file:t.file,sidecar_path:a,total_blocks:o.blocks.length,sidecar_anchors:s.length,stale:A,ambiguous:l,missing:d,ok:!p},null,2));else{console.log(`${o.blocks.length} blocks, ${s.length} sidecar anchors`);for(let m of A)console.log(` Stale: ${m}`);for(let m of d)console.log(` Missing: ${m}`);if(!p)console.log("All anchors resolve correctly.")}process.exit(p?An:H)}import{existsSync as x$e,readFileSync as I$e}from"fs";import{resolve as D$e}from"path";import{createHash as F$e}from"crypto";var fH=["dev","standard","safe"],hH=new Set(["version","deployment","deployment.profile","server","server.base_url","server.api_key_env","server.max_file_size_bytes","server.max_comment_bytes","repo","repo.id","repo.local_path","review","review.link_policy","review.link_policy.mode","review.link_policy.audience","review.link_policy.url_token_ttl_minutes","review.link_policy.session_access_token_ttl_minutes","review.link_policy.refresh_token_ttl_hours","review.link_policy.allow_read_without_identity","review.link_policy.single_use","review.link_policy.require_identity_for","review.link_policy.require_identity_for.comment","review.link_policy.require_identity_for.approve","review.auto_read_only_on_supersede","slack","slack.enabled","webhooks","webhooks.enabled","uploads","uploads.enabled","public_review","public_review.enabled","offline","offline.enable_pwa","offline.enable_offline_drafts","offline.enable_offline_reading_cache","offline.encrypt_drafts","export","export.include_render_html","parsing","parsing.block_id_scheme","parsing.block_key_scheme","retention","retention.domain_events","retention.domain_events.hot_window_days","retention.domain_events.archive_batch_size","retention.domain_events.archive_retention_days","retention.job_queue","retention.job_queue.completed_retention_days","retention.idempotency_keys","retention.idempotency_keys.ttl_days","retention.artifacts","retention.artifacts.safety_ttl_hours","retention.artifacts.retention_days","oidc","oidc.enabled","oidc.issuer","oidc.client_id","oidc.client_secret_env","oidc.scopes","oidc.authorization_endpoint","oidc.token_endpoint","oidc.userinfo_endpoint","oidc.jwks_uri","oidc.end_session_endpoint","oidc.audience","oidc.clock_skew_tolerance_seconds","oidc.jwks_cache_ttl_seconds","oidc.discovery_cache_ttl_seconds","oidc.operator_redirect_uri","oidc.reviewer_redirect_uri"]),$$e={"server.max_file_size_bytes":1048576,"server.max_comment_bytes":8000,"server.api_key_env":"TYPESCAPE_API_KEY","deployment.profile":"standard","parsing.block_id_scheme":"v1","parsing.block_key_scheme":"v1","review.link_policy.mode":"email_otp","review.link_policy.audience":"explicit_participants","review.link_policy.url_token_ttl_minutes":60,"review.link_policy.session_access_token_ttl_minutes":120,"review.link_policy.refresh_token_ttl_hours":168,"review.link_policy.allow_read_without_identity":!0,"review.link_policy.single_use":!1,"slack.enabled":!1,"webhooks.enabled":!0,"uploads.enabled":!0,"public_review.enabled":!1,"offline.enable_pwa":!1,"offline.enable_offline_drafts":!0,"offline.enable_offline_reading_cache":!1,"offline.encrypt_drafts":!1,"export.include_render_html":!0,"review.link_policy.require_identity_for.comment":!0,"review.link_policy.require_identity_for.approve":!0,"retention.domain_events.hot_window_days":30,"retention.domain_events.archive_batch_size":1000,"retention.domain_events.archive_retention_days":730,"retention.job_queue.completed_retention_days":7,"retention.idempotency_keys.ttl_days":14,"retention.artifacts.safety_ttl_hours":72,"retention.artifacts.retention_days":365,"oidc.enabled":!1,"oidc.client_secret_env":"TYPESCAPE_OIDC_CLIENT_SECRET","oidc.scopes":["openid","email","profile"],"oidc.clock_skew_tolerance_seconds":60,"oidc.jwks_cache_ttl_seconds":3600,"oidc.discovery_cache_ttl_seconds":86400},S$e={standard:{},safe:{"review.link_policy.url_token_ttl_minutes":15,"review.link_policy.session_access_token_ttl_minutes":60,"review.link_policy.refresh_token_ttl_hours":168,"review.link_policy.allow_read_without_identity":!1,"review.link_policy.single_use":!0,"slack.enabled":!1,"webhooks.enabled":!1,"uploads.enabled":!1,"public_review.enabled":!1,"offline.enable_pwa":!1,"offline.enable_offline_drafts":!0,"offline.enable_offline_reading_cache":!1,"offline.encrypt_drafts":!0,"export.include_render_html":!1},dev:{"review.link_policy.url_token_ttl_minutes":1440,"review.link_policy.session_access_token_ttl_minutes":480,"review.link_policy.refresh_token_ttl_hours":720,"review.link_policy.allow_read_without_identity":!0,"review.link_policy.single_use":!1,"slack.enabled":!0,"webhooks.enabled":!0,"uploads.enabled":!0,"public_review.enabled":!0,"offline.enable_pwa":!0,"offline.enable_offline_drafts":!0,"offline.enable_offline_reading_cache":!0,"offline.encrypt_drafts":!1,"export.include_render_html":!0,"retention.domain_events.hot_window_days":7,"retention.domain_events.archive_batch_size":500,"retention.domain_events.archive_retention_days":90,"retention.job_queue.completed_retention_days":3,"retention.idempotency_keys.ttl_days":7,"retention.artifacts.safety_ttl_hours":24,"retention.artifacts.retention_days":30}},L$e={deployment:{profile:"standard"},review:{link_policy:{audience:"explicit_participants",url_token_ttl_minutes:60,session_access_token_ttl_minutes:120,refresh_token_ttl_hours:168,allow_read_without_identity:!0,single_use:!1}},slack:{enabled:!1},webhooks:{enabled:!0},uploads:{enabled:!0},public_review:{enabled:!1},offline:{enable_pwa:!1,enable_offline_drafts:!0,enable_offline_reading_cache:!1,encrypt_drafts:!1},export:{include_render_html:!0},retention:{domain_events:{hot_window_days:30,archive_batch_size:1000,archive_retention_days:730},job_queue:{completed_retention_days:7},idempotency_keys:{ttl_days:14},artifacts:{safety_ttl_hours:72,retention_days:365}}},j$e={deployment:{profile:"safe"},review:{link_policy:{audience:"explicit_participants",url_token_ttl_minutes:15,session_access_token_ttl_minutes:60,refresh_token_ttl_hours:168,allow_read_without_identity:!1,single_use:!0,require_identity_for:{comment:!0,approve:!0}}},slack:{enabled:!1},webhooks:{enabled:!1},uploads:{enabled:!1},public_review:{enabled:!1},offline:{enable_pwa:!1,enable_offline_drafts:!0,enable_offline_reading_cache:!1,encrypt_drafts:!0},export:{include_render_html:!1},retention:{domain_events:{hot_window_days:30,archive_batch_size:1000,archive_retention_days:730},job_queue:{completed_retention_days:7},idempotency_keys:{ttl_days:14},artifacts:{safety_ttl_hours:72,retention_days:365}}},q$e={deployment:{profile:"dev"},review:{link_policy:{url_token_ttl_minutes:1440,session_access_token_ttl_minutes:480,refresh_token_ttl_hours:720,allow_read_without_identity:!0,single_use:!1}},slack:{enabled:!0},webhooks:{enabled:!0},uploads:{enabled:!0},public_review:{enabled:!0},offline:{enable_pwa:!0,enable_offline_drafts:!0,enable_offline_reading_cache:!0,encrypt_drafts:!1},export:{include_render_html:!0},retention:{domain_events:{hot_window_days:7,archive_batch_size:500,archive_retention_days:90},job_queue:{completed_retention_days:3},idempotency_keys:{ttl_days:7},artifacts:{safety_ttl_hours:24,retention_days:30}}};function N$e(e){let t={format:"text"},n=0;while(n<e.length){let a=e[n];if(a==="--config")t.config=e[n+1],n+=2;else if(a.startsWith("--config="))t.config=a.slice(9),n++;else if(a==="--profile")t.profile=e[n+1],n+=2;else if(a.startsWith("--profile="))t.profile=a.slice(10),n++;else if(a==="--format"){let r=e[n+1];if(r==="json"||r==="text")t.format=r;n+=2}else if(a.startsWith("--format=")){let r=a.slice(9);if(r==="json"||r==="text")t.format=r;n++}else n++}return t}function yH(e,t=""){let n=[];for(let[a,r]of Object.entries(e)){let i=t?`${t}.${a}`:a;if(n.push(i),r&&typeof r==="object"&&!Array.isArray(r))n.push(...yH(r,i))}return n}function M$e(e,t){let n=t.split("."),a=e;for(let r of n)if(a&&typeof a==="object"&&!Array.isArray(a))a=a[r];else return;return a}function ic(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function wH(e,t){let n={...e};for(let[a,r]of Object.entries(t)){let i=n[a];if(ic(i)&&ic(r)){n[a]=wH(i,r);continue}if(r!==void 0)n[a]=r}return n}function LQ(e){if(e===null||typeof e==="number"||typeof e==="boolean")return JSON.stringify(e);if(typeof e==="string")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map((t)=>t===void 0?"null":LQ(t)).join(",")}]`;if(ic(e))return`{${Object.keys(e).filter((n)=>e[n]!==void 0).sort().map((n)=>`${JSON.stringify(n)}:${LQ(e[n])}`).join(",")}}`;return JSON.stringify(e)}function G$e(e,t){if(t){if(fH.includes(t))return t;return null}let n=e.deployment;if(ic(n)&&typeof n.profile==="string"){if(fH.includes(n.profile))return n.profile;return null}return"standard"}function R$e(e){switch(e){case"safe":return j$e;case"dev":return q$e;case"standard":default:return L$e}}function kH(e){return{...$$e,"deployment.profile":e,...S$e[e]}}function P$e(e){let t=e.trim(),n=/^https?:\/\//i.test(t)?t:`https://${t}`;return new URL(n).origin}async function z$e(e,t=fetch){let a=`${P$e(e)}/readyz`;try{let r=await t(a,{method:"GET",headers:{Accept:"application/json"},signal:AbortSignal.timeout(3000)});return{reachable:!0,readyz_url:a,status:r.status,message:"Server reachable"}}catch{return{reachable:!1,readyz_url:a,status:null,message:`Server unreachable at ${a} - check base_url`}}}function U$e(e){let t=e.split("."),n=t[t.length-1];for(let a of hH){let r=a.split("."),i=r[r.length-1];if(Math.abs(n.length-i.length)<=2&&n.slice(0,3)===i.slice(0,3))return a}return null}function H$e(e){let t=LQ(e);return`sha256:${F$e("sha256").update(t).digest("hex").slice(0,16)}`}function T$e(e,t){let n=G$e(e,t),a=n??"standard",r=R$e(a),i=wH(r,e),o=kH(a),s=i.review?.link_policy??{},c={valid:!0,profile:a,config_hash:H$e(i),effective_posture:{url_token_ttl_minutes:s.url_token_ttl_minutes??60,session_access_token_ttl_minutes:s.session_access_token_ttl_minutes??120,refresh_token_ttl_hours:s.refresh_token_ttl_hours??168,allow_read_without_identity:s.allow_read_without_identity??!0,single_use:s.single_use??!1},applied_defaults:[],warnings:[],errors:[],retention_policy:[]};if(!n)c.valid=!1,c.errors.push(`deployment.profile: Invalid profile "${t??(ic(e.deployment)?String(e.deployment.profile):"unknown")}". Expected one of: dev, standard, safe.`);if(e.version!==void 0&&e.version!==tA)c.valid=!1,c.errors.push(`version: Unsupported version ${e.version}. Only version ${tA} is supported.`);if(!i.server||!i.server.base_url)c.valid=!1,c.errors.push("server.base_url: Required field missing");let A=[],l=yH(e);for(let y of l)if(!hH.has(y)){let w=U$e(y);if(w)c.errors.push(`${y}: Unknown key (did you mean "${w}"?)`);else A.push(y)}if(A.length>0)if(c.profile==="dev")c.warnings.push(...A.map((y)=>`${y}: Unknown configuration key`));else c.errors.push(...A.map((y)=>`${y}: Unknown configuration key`)),c.valid=!1;for(let[y]of Object.entries(o))if(M$e(e,y)===void 0)c.applied_defaults.push(y);let d=i.retention,u=d?.domain_events,p=d?.job_queue,m=d?.idempotency_keys,g=d?.artifacts;return c.retention_policy=[{table:"domain_events",strategy:"hot + archive (monthly partitions)",retention_days:u?.hot_window_days??30},{table:"domain_events_archive",strategy:"cold storage (monthly partitions)",retention_days:u?.archive_retention_days??730},{table:"job_queue",strategy:"partition or cleanup archive",retention_days:p?.completed_retention_days??7},{table:"idempotency_keys",strategy:"TTL-driven batched delete",retention_days:m?.ttl_days??14},{table:"artifacts",strategy:"mark-and-sweep GC",retention_days:g?.retention_days??365}],c}async function BH(e){let t=N$e(e),n=D$e(t.config||bh);if(!x$e(n))if(t.format==="json")bt({valid:!1,errors:[`Config file not found: ${n}`],warnings:[]},t.format),process.exit(S);else D({code:"config_not_found",message:`Config file not found: ${n}`},S);let a;try{let o=I$e(n,"utf-8");a=Fi(o)}catch(o){let s=o instanceof Error?o.message:String(o);if(t.format==="json")bt({valid:!1,errors:[`Failed to parse config: ${s}`],warnings:[]},t.format),process.exit(S);else D({code:"config_parse_error",message:`Failed to parse config: ${s}`},S);return}let r=T$e(a,t.profile);if(r.errors.length>0)r.valid=!1;let i=ic(a.server)?a.server.base_url:void 0;if(typeof i==="string"&&i.trim())try{if(r.connectivity=await z$e(i),!r.connectivity.reachable)r.warnings.push(r.connectivity.message)}catch{r.connectivity={reachable:!1,readyz_url:i.trim(),status:null,message:`Server unreachable at ${i.trim()} - check base_url`},r.warnings.push(r.connectivity.message)}if(t.format==="json")bt(r,t.format),process.exit(r.valid?H:S);else if(r.valid){console.log(`\u2713 Config valid
657
+ `)){let r=a.trim();if(r.startsWith("- block_key:")){if(n)t.push({block_key:Ab(n.block_key||""),block_type:Ab(n.block_type||""),block_index:parseInt(n.block_index||"0",10)});n={block_key:r.replace("- block_key:","").trim()}}else if(n&&r.startsWith("block_type:"))n.block_type=r.replace("block_type:","").trim();else if(n&&r.startsWith("block_index:"))n.block_index=r.replace("block_index:","").trim()}if(n)t.push({block_key:Ab(n.block_key||""),block_type:Ab(n.block_type||""),block_index:parseInt(n.block_index||"0",10)});return t}function Ab(e){if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return e.slice(1,-1);return e}function bH(e){let t=v$e(e);if(!t.file)D({code:"missing_required_flag",message:"Missing required flag: --file"},S);let n;try{n=SQ(t.file,"utf-8")}catch{D({code:"file_not_found",message:`File not found: ${t.file}`},S)}let a=mH(t.file),r;try{r=SQ(a,"utf-8")}catch{D({code:"sidecar_not_found",message:`Sidecar file not found: ${a}. Run 'typescape anchors apply --file ${t.file} --write' first.`},S)}let i=Lr(n),o=Gr(i.content,i.bytes),s=Q$e(r),c=new Map;for(let m of o.blocks)c.set(m.blockIndex,m);let A=[],l=[],d=[];for(let m of s){let g=c.get(m.block_index);if(!g){A.push(`${m.block_key} (index ${m.block_index}): block no longer exists`);continue}if(g.blockType!==m.block_type)A.push(`${m.block_key} (index ${m.block_index}): type changed from ${m.block_type} to ${g.blockType}`)}let u=new Set(s.map((m)=>m.block_index));for(let m of o.blocks)if(!u.has(m.blockIndex)&&!m.blockKey)d.push(`Block ${m.blockIndex} (${m.blockType}, line ${m.startLine}): not in sidecar and has no marker`);let p=A.length>0||l.length>0||d.length>0;if(t.format==="json")console.log(JSON.stringify({file:t.file,sidecar_path:a,total_blocks:o.blocks.length,sidecar_anchors:s.length,stale:A,ambiguous:l,missing:d,ok:!p},null,2));else{console.log(`${o.blocks.length} blocks, ${s.length} sidecar anchors`);for(let m of A)console.log(` Stale: ${m}`);for(let m of d)console.log(` Missing: ${m}`);if(!p)console.log("All anchors resolve correctly.")}process.exit(p?An:H)}import{existsSync as x$e,readFileSync as I$e}from"fs";import{resolve as D$e}from"path";import{createHash as F$e}from"crypto";var fH=["dev","standard","safe"],hH=new Set(["version","deployment","deployment.profile","server","server.base_url","server.api_key_env","server.max_file_size_bytes","server.max_comment_bytes","repo","repo.id","repo.local_path","review","review.link_policy","review.link_policy.mode","review.link_policy.audience","review.link_policy.url_token_ttl_minutes","review.link_policy.session_access_token_ttl_minutes","review.link_policy.refresh_token_ttl_hours","review.link_policy.allow_read_without_identity","review.link_policy.single_use","review.link_policy.require_identity_for","review.link_policy.require_identity_for.comment","review.link_policy.require_identity_for.approve","review.auto_read_only_on_supersede","slack","slack.enabled","webhooks","webhooks.enabled","uploads","uploads.enabled","public_review","public_review.enabled","offline","offline.enable_pwa","offline.enable_offline_drafts","offline.enable_offline_reading_cache","offline.encrypt_drafts","export","export.include_render_html","parsing","parsing.block_id_scheme","parsing.block_key_scheme","retention","retention.domain_events","retention.domain_events.hot_window_days","retention.domain_events.archive_batch_size","retention.domain_events.archive_retention_days","retention.job_queue","retention.job_queue.completed_retention_days","retention.idempotency_keys","retention.idempotency_keys.ttl_days","retention.artifacts","retention.artifacts.safety_ttl_hours","retention.artifacts.retention_days","oidc","oidc.enabled","oidc.issuer","oidc.client_id","oidc.client_secret_env","oidc.scopes","oidc.authorization_endpoint","oidc.token_endpoint","oidc.userinfo_endpoint","oidc.jwks_uri","oidc.end_session_endpoint","oidc.audience","oidc.clock_skew_tolerance_seconds","oidc.jwks_cache_ttl_seconds","oidc.discovery_cache_ttl_seconds","oidc.operator_redirect_uri","oidc.reviewer_redirect_uri"]),$$e={"server.max_file_size_bytes":5000000,"server.max_comment_bytes":8000,"server.api_key_env":"TYPESCAPE_API_KEY","deployment.profile":"standard","parsing.block_id_scheme":"v1","parsing.block_key_scheme":"v1","review.link_policy.mode":"email_otp","review.link_policy.audience":"explicit_participants","review.link_policy.url_token_ttl_minutes":60,"review.link_policy.session_access_token_ttl_minutes":120,"review.link_policy.refresh_token_ttl_hours":168,"review.link_policy.allow_read_without_identity":!0,"review.link_policy.single_use":!1,"slack.enabled":!1,"webhooks.enabled":!0,"uploads.enabled":!0,"public_review.enabled":!1,"offline.enable_pwa":!1,"offline.enable_offline_drafts":!0,"offline.enable_offline_reading_cache":!1,"offline.encrypt_drafts":!1,"export.include_render_html":!0,"review.link_policy.require_identity_for.comment":!0,"review.link_policy.require_identity_for.approve":!0,"retention.domain_events.hot_window_days":30,"retention.domain_events.archive_batch_size":1000,"retention.domain_events.archive_retention_days":730,"retention.job_queue.completed_retention_days":7,"retention.idempotency_keys.ttl_days":14,"retention.artifacts.safety_ttl_hours":72,"retention.artifacts.retention_days":365,"oidc.enabled":!1,"oidc.client_secret_env":"TYPESCAPE_OIDC_CLIENT_SECRET","oidc.scopes":["openid","email","profile"],"oidc.clock_skew_tolerance_seconds":60,"oidc.jwks_cache_ttl_seconds":3600,"oidc.discovery_cache_ttl_seconds":86400},S$e={standard:{},safe:{"review.link_policy.url_token_ttl_minutes":15,"review.link_policy.session_access_token_ttl_minutes":60,"review.link_policy.refresh_token_ttl_hours":168,"review.link_policy.allow_read_without_identity":!1,"review.link_policy.single_use":!0,"slack.enabled":!1,"webhooks.enabled":!1,"uploads.enabled":!1,"public_review.enabled":!1,"offline.enable_pwa":!1,"offline.enable_offline_drafts":!0,"offline.enable_offline_reading_cache":!1,"offline.encrypt_drafts":!0,"export.include_render_html":!1},dev:{"review.link_policy.url_token_ttl_minutes":1440,"review.link_policy.session_access_token_ttl_minutes":480,"review.link_policy.refresh_token_ttl_hours":720,"review.link_policy.allow_read_without_identity":!0,"review.link_policy.single_use":!1,"slack.enabled":!0,"webhooks.enabled":!0,"uploads.enabled":!0,"public_review.enabled":!0,"offline.enable_pwa":!0,"offline.enable_offline_drafts":!0,"offline.enable_offline_reading_cache":!0,"offline.encrypt_drafts":!1,"export.include_render_html":!0,"retention.domain_events.hot_window_days":7,"retention.domain_events.archive_batch_size":500,"retention.domain_events.archive_retention_days":90,"retention.job_queue.completed_retention_days":3,"retention.idempotency_keys.ttl_days":7,"retention.artifacts.safety_ttl_hours":24,"retention.artifacts.retention_days":30}},L$e={deployment:{profile:"standard"},review:{link_policy:{audience:"explicit_participants",url_token_ttl_minutes:60,session_access_token_ttl_minutes:120,refresh_token_ttl_hours:168,allow_read_without_identity:!0,single_use:!1}},slack:{enabled:!1},webhooks:{enabled:!0},uploads:{enabled:!0},public_review:{enabled:!1},offline:{enable_pwa:!1,enable_offline_drafts:!0,enable_offline_reading_cache:!1,encrypt_drafts:!1},export:{include_render_html:!0},retention:{domain_events:{hot_window_days:30,archive_batch_size:1000,archive_retention_days:730},job_queue:{completed_retention_days:7},idempotency_keys:{ttl_days:14},artifacts:{safety_ttl_hours:72,retention_days:365}}},j$e={deployment:{profile:"safe"},review:{link_policy:{audience:"explicit_participants",url_token_ttl_minutes:15,session_access_token_ttl_minutes:60,refresh_token_ttl_hours:168,allow_read_without_identity:!1,single_use:!0,require_identity_for:{comment:!0,approve:!0}}},slack:{enabled:!1},webhooks:{enabled:!1},uploads:{enabled:!1},public_review:{enabled:!1},offline:{enable_pwa:!1,enable_offline_drafts:!0,enable_offline_reading_cache:!1,encrypt_drafts:!0},export:{include_render_html:!1},retention:{domain_events:{hot_window_days:30,archive_batch_size:1000,archive_retention_days:730},job_queue:{completed_retention_days:7},idempotency_keys:{ttl_days:14},artifacts:{safety_ttl_hours:72,retention_days:365}}},q$e={deployment:{profile:"dev"},review:{link_policy:{url_token_ttl_minutes:1440,session_access_token_ttl_minutes:480,refresh_token_ttl_hours:720,allow_read_without_identity:!0,single_use:!1}},slack:{enabled:!0},webhooks:{enabled:!0},uploads:{enabled:!0},public_review:{enabled:!0},offline:{enable_pwa:!0,enable_offline_drafts:!0,enable_offline_reading_cache:!0,encrypt_drafts:!1},export:{include_render_html:!0},retention:{domain_events:{hot_window_days:7,archive_batch_size:500,archive_retention_days:90},job_queue:{completed_retention_days:3},idempotency_keys:{ttl_days:7},artifacts:{safety_ttl_hours:24,retention_days:30}}};function N$e(e){let t={format:"text"},n=0;while(n<e.length){let a=e[n];if(a==="--config")t.config=e[n+1],n+=2;else if(a.startsWith("--config="))t.config=a.slice(9),n++;else if(a==="--profile")t.profile=e[n+1],n+=2;else if(a.startsWith("--profile="))t.profile=a.slice(10),n++;else if(a==="--format"){let r=e[n+1];if(r==="json"||r==="text")t.format=r;n+=2}else if(a.startsWith("--format=")){let r=a.slice(9);if(r==="json"||r==="text")t.format=r;n++}else n++}return t}function yH(e,t=""){let n=[];for(let[a,r]of Object.entries(e)){let i=t?`${t}.${a}`:a;if(n.push(i),r&&typeof r==="object"&&!Array.isArray(r))n.push(...yH(r,i))}return n}function M$e(e,t){let n=t.split("."),a=e;for(let r of n)if(a&&typeof a==="object"&&!Array.isArray(a))a=a[r];else return;return a}function ic(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function wH(e,t){let n={...e};for(let[a,r]of Object.entries(t)){let i=n[a];if(ic(i)&&ic(r)){n[a]=wH(i,r);continue}if(r!==void 0)n[a]=r}return n}function LQ(e){if(e===null||typeof e==="number"||typeof e==="boolean")return JSON.stringify(e);if(typeof e==="string")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map((t)=>t===void 0?"null":LQ(t)).join(",")}]`;if(ic(e))return`{${Object.keys(e).filter((n)=>e[n]!==void 0).sort().map((n)=>`${JSON.stringify(n)}:${LQ(e[n])}`).join(",")}}`;return JSON.stringify(e)}function G$e(e,t){if(t){if(fH.includes(t))return t;return null}let n=e.deployment;if(ic(n)&&typeof n.profile==="string"){if(fH.includes(n.profile))return n.profile;return null}return"standard"}function R$e(e){switch(e){case"safe":return j$e;case"dev":return q$e;case"standard":default:return L$e}}function kH(e){return{...$$e,"deployment.profile":e,...S$e[e]}}function P$e(e){let t=e.trim(),n=/^https?:\/\//i.test(t)?t:`https://${t}`;return new URL(n).origin}async function z$e(e,t=fetch){let a=`${P$e(e)}/readyz`;try{let r=await t(a,{method:"GET",headers:{Accept:"application/json"},signal:AbortSignal.timeout(3000)});return{reachable:!0,readyz_url:a,status:r.status,message:"Server reachable"}}catch{return{reachable:!1,readyz_url:a,status:null,message:`Server unreachable at ${a} - check base_url`}}}function U$e(e){let t=e.split("."),n=t[t.length-1];for(let a of hH){let r=a.split("."),i=r[r.length-1];if(Math.abs(n.length-i.length)<=2&&n.slice(0,3)===i.slice(0,3))return a}return null}function H$e(e){let t=LQ(e);return`sha256:${F$e("sha256").update(t).digest("hex").slice(0,16)}`}function T$e(e,t){let n=G$e(e,t),a=n??"standard",r=R$e(a),i=wH(r,e),o=kH(a),s=i.review?.link_policy??{},c={valid:!0,profile:a,config_hash:H$e(i),effective_posture:{url_token_ttl_minutes:s.url_token_ttl_minutes??60,session_access_token_ttl_minutes:s.session_access_token_ttl_minutes??120,refresh_token_ttl_hours:s.refresh_token_ttl_hours??168,allow_read_without_identity:s.allow_read_without_identity??!0,single_use:s.single_use??!1},applied_defaults:[],warnings:[],errors:[],retention_policy:[]};if(!n)c.valid=!1,c.errors.push(`deployment.profile: Invalid profile "${t??(ic(e.deployment)?String(e.deployment.profile):"unknown")}". Expected one of: dev, standard, safe.`);if(e.version!==void 0&&e.version!==tA)c.valid=!1,c.errors.push(`version: Unsupported version ${e.version}. Only version ${tA} is supported.`);if(!i.server||!i.server.base_url)c.valid=!1,c.errors.push("server.base_url: Required field missing");let A=[],l=yH(e);for(let y of l)if(!hH.has(y)){let w=U$e(y);if(w)c.errors.push(`${y}: Unknown key (did you mean "${w}"?)`);else A.push(y)}if(A.length>0)if(c.profile==="dev")c.warnings.push(...A.map((y)=>`${y}: Unknown configuration key`));else c.errors.push(...A.map((y)=>`${y}: Unknown configuration key`)),c.valid=!1;for(let[y]of Object.entries(o))if(M$e(e,y)===void 0)c.applied_defaults.push(y);let d=i.retention,u=d?.domain_events,p=d?.job_queue,m=d?.idempotency_keys,g=d?.artifacts;return c.retention_policy=[{table:"domain_events",strategy:"hot + archive (monthly partitions)",retention_days:u?.hot_window_days??30},{table:"domain_events_archive",strategy:"cold storage (monthly partitions)",retention_days:u?.archive_retention_days??730},{table:"job_queue",strategy:"partition or cleanup archive",retention_days:p?.completed_retention_days??7},{table:"idempotency_keys",strategy:"TTL-driven batched delete",retention_days:m?.ttl_days??14},{table:"artifacts",strategy:"mark-and-sweep GC",retention_days:g?.retention_days??365}],c}async function BH(e){let t=N$e(e),n=D$e(t.config||bh);if(!x$e(n))if(t.format==="json")bt({valid:!1,errors:[`Config file not found: ${n}`],warnings:[]},t.format),process.exit(S);else D({code:"config_not_found",message:`Config file not found: ${n}`},S);let a;try{let o=I$e(n,"utf-8");a=Fi(o)}catch(o){let s=o instanceof Error?o.message:String(o);if(t.format==="json")bt({valid:!1,errors:[`Failed to parse config: ${s}`],warnings:[]},t.format),process.exit(S);else D({code:"config_parse_error",message:`Failed to parse config: ${s}`},S);return}let r=T$e(a,t.profile);if(r.errors.length>0)r.valid=!1;let i=ic(a.server)?a.server.base_url:void 0;if(typeof i==="string"&&i.trim())try{if(r.connectivity=await z$e(i),!r.connectivity.reachable)r.warnings.push(r.connectivity.message)}catch{r.connectivity={reachable:!1,readyz_url:i.trim(),status:null,message:`Server unreachable at ${i.trim()} - check base_url`},r.warnings.push(r.connectivity.message)}if(t.format==="json")bt(r,t.format),process.exit(r.valid?H:S);else if(r.valid){console.log(`\u2713 Config valid
658
658
  `),console.log(`Profile: ${r.profile}`),console.log(`Config hash: ${r.config_hash}`),console.log("Effective posture:",JSON.stringify(r.effective_posture,null,2));let o=kH(r.profile);if(r.applied_defaults.length>0){console.log(`
659
659
  Applied defaults:`);for(let s of r.applied_defaults){let c=o[s];console.log(` ${s}: ${JSON.stringify(c)}`)}}if(r.retention_policy.length>0){console.log(`
660
660
  Retention policy:`);for(let s of r.retention_policy)console.log(` ${s.table}: ${s.retention_days}d (${s.strategy})`)}if(r.warnings.length>0){console.log(`
@@ -695,7 +695,7 @@ Setup Instructions:
695
695
  bunx typescape config validate
696
696
  `);process.exit(H)}import{execSync as m3e}from"child_process";function g3e(e){if(e.summary)return e.summary;if(e.coverage)return{total_files:e.coverage.total_files,reviewed_files:e.coverage.reviewed_files,drifted_files:e.coverage.drifted,never_reviewed_files:e.coverage.never_reviewed,coverage_percent:e.coverage.coverage_percent};D({code:"invalid_response_shape",message:"Coverage API response missing both summary and coverage fields."},Oa)}function b3e(e,t){let n={failOnDrift:!1,failOnUncovered:!1,summary:!1,format:t},a=0;while(a<e.length){let r=e[a];if(r==="--repo")n.repo=e[a+1]||"",a+=2;else if(r.startsWith("--repo="))n.repo=r.slice(7),a++;else if(r==="--session")n.session=e[a+1]||"",a+=2;else if(r.startsWith("--session="))n.session=r.slice(10),a++;else if(r==="--branch")n.branch=e[a+1]||"",a+=2;else if(r.startsWith("--branch="))n.branch=r.slice(9),a++;else if(r==="--sha")n.sha=e[a+1]||"",a+=2;else if(r.startsWith("--sha="))n.sha=r.slice(6),a++;else if(r==="--globs")n.globs=e[a+1]||"",a+=2;else if(r.startsWith("--globs="))n.globs=r.slice(8),a++;else if(r==="--fail-on-drift")n.failOnDrift=!0,a++;else if(r==="--fail-on-uncovered")n.failOnUncovered=!0,a++;else if(r==="--min-coverage"){let i=e[a+1];if(i===void 0||i==="")D({code:"invalid_flag_value",message:"--min-coverage requires a numeric value"},S);let o=Number(i);if(Number.isNaN(o)||o<0||o>100)D({code:"invalid_flag_value",message:`--min-coverage must be a number between 0 and 100, got: ${i}`},S);n.minCoverage=o,a+=2}else if(r.startsWith("--min-coverage=")){let i=r.slice(15),o=Number(i);if(Number.isNaN(o)||o<0||o>100)D({code:"invalid_flag_value",message:`--min-coverage must be a number between 0 and 100, got: ${i}`},S);n.minCoverage=o,a++}else if(r==="--summary")n.summary=!0,a++;else if(r==="--format")n.format=e[a+1]||"text",a+=2;else if(r.startsWith("--format="))n.format=r.slice(9),a++;else a++}return n}async function f3e(e,t){let a=(await e.get(`/sessions/${encodeURIComponent(t)}`)).body.session;if(!a)return null;if(typeof a.repo_id==="string"&&a.repo_id.length>0)return a.repo_id;if(a.source_type==="upload")D({code:"unsupported_source_type",message:"Coverage for upload-backed sessions is not supported yet. Use --repo for git-backed coverage checks."},S);return null}function IH(e){try{return m3e(`git rev-parse "${e}"`,{encoding:"utf-8",stdio:["pipe","pipe","pipe"]}).trim()}catch{D({code:"branch_resolution_failed",message:`Could not resolve branch '${e}' to a git SHA. Make sure you are in a git repository and the branch exists.`},S)}}async function DH(e,t,n,a){let r=b3e(e,a),o=(r.repo==="."?t.repoId:r.repo)??t.repoId;if(!o&&r.session){let p=await f3e(n,r.session);if(p)o=p}if(!o)D({code:"missing_required_flag",message:"Missing repository context. Specify --repo, set repo.id in config, or provide --session for auto-resolution."},S);if(r.branch&&r.sha)D({code:"conflicting_flags",message:"--branch and --sha are mutually exclusive. Use one or the other."},S);let s;if(r.sha)s=r.sha;else if(r.branch)s=IH(r.branch);else s=IH("HEAD");let c={git_sha:s};if(r.globs)c.globs=r.globs;let l=(await n.get(`/repos/${encodeURIComponent(o)}/coverage`,{query:c})).body,d=g3e(l),u=[];if(r.failOnDrift&&d.drifted_files>0)u.push(`${d.drifted_files} file${d.drifted_files===1?"":"s"} drifted`);if(r.failOnUncovered&&d.never_reviewed_files>0)u.push(`${d.never_reviewed_files} file${d.never_reviewed_files===1?"":"s"} never reviewed`);if(r.minCoverage!==void 0&&d.coverage_percent<r.minCoverage)u.push(`coverage ${d.coverage_percent}% < threshold ${r.minCoverage}%`);if(r.format==="json"){let p=r.summary?{repo_id:l.repo_id,git_sha:l.git_sha,summary:d,gate_result:u.length>0?"fail":"pass",gate_failures:u,request_id:l.request_id}:{...l,gate_result:u.length>0?"fail":"pass",gate_failures:u};console.log(JSON.stringify(p,null,2))}else{let{reviewed_files:p,total_files:m,coverage_percent:g,drifted_files:y,never_reviewed_files:w}=d;if(console.log(`${p}/${m} files reviewed (${g}%), ${y} drifted, ${w} never reviewed`),u.length>0){console.log(""),console.log("Gate failures:");for(let _ of u)console.log(` - ${_}`)}}if(u.length>0)process.exit(An);process.exit(H)}function h3e(e){let t={format:"json"},n=0;while(n<e.length){let a=e[n];if(a==="--repo")t.repo=e[n+1]||"",n+=2;else if(a.startsWith("--repo="))t.repo=a.slice(7),n++;else if(a==="--state")t.state=e[n+1]||"",n+=2;else if(a.startsWith("--state="))t.state=a.slice(8),n++;else if(a==="--file-paths")t.filePaths=e[n+1]||"",n+=2;else if(a.startsWith("--file-paths="))t.filePaths=a.slice(13),n++;else if(a==="--cursor")t.cursor=e[n+1]||"",n+=2;else if(a.startsWith("--cursor="))t.cursor=a.slice(9),n++;else if(a==="--limit")t.limit=Number.parseInt(e[n+1]||"20",10),n+=2;else if(a.startsWith("--limit="))t.limit=Number.parseInt(a.slice(8),10),n++;else if(a==="--format")t.format=e[n+1]||"json",n+=2;else if(a.startsWith("--format="))t.format=a.slice(9),n++;else n++}return t}async function FH(e,t,n){let a=h3e(e),r={};if(a.repo)r.repo_id=a.repo;if(a.state)r.state=a.state;if(a.filePaths)r.file_paths=a.filePaths;if(a.cursor)r.cursor=a.cursor;if(a.limit!==void 0)r.limit=String(a.limit);let i=await n.get("/sessions",{query:r});if(a.format==="json")console.log(JSON.stringify(i.body,null,2));else{let o=i.body.items??[];console.log(`Sessions (${o.length}):`);for(let s of o)console.log(` ${s.id} ${s.state} ${s.file_path} ${s.title??""}`);if(i.body.cursor)console.log(`
697
697
  Next cursor: ${i.body.cursor}`)}process.exit(H)}function y3e(e){let t={session:"",format:"json"},n=0;while(n<e.length){let a=e[n];if(a==="--session")t.session=e[n+1]||"",n+=2;else if(a.startsWith("--session="))t.session=a.slice(10),n++;else if(a==="--format")t.format=e[n+1]||"json",n+=2;else if(a.startsWith("--format="))t.format=a.slice(9),n++;else n++}return t}async function $H(e,t,n){let a=y3e(e);if(!a.session)D({code:"missing_required_flag",message:"Missing required flag: --session"},S);let r=await n.get(`/sessions/${encodeURIComponent(a.session)}`);if(a.format==="json")console.log(JSON.stringify(r.body,null,2));else{let i=r.body.session;if(console.log(`Session ID: ${i.id}`),console.log(`Title: ${i.title??"\u2014"}`),console.log(`State: ${i.state}`),console.log(`Source Type: ${i.source_type??"unknown"}`),console.log(`File Path: ${i.file_path??"N/A"}`),i.read_only)console.log("Read Only: yes");if(console.log(`Threads: ${i.summary?.total_threads??0} total, ${i.summary?.open_threads??0} open`),console.log(`Comments: ${i.summary?.total_comments??0}`),i.root_session_id)console.log(`Root Session: ${i.root_session_id}`);if(i.supersedes_session_id)console.log(`Supersedes: ${i.supersedes_session_id}`)}process.exit(H)}function w3e(e){let t={session:"",format:"json"},n=0;while(n<e.length){let a=e[n];if(a==="--session")t.session=e[n+1]||"",n+=2;else if(a.startsWith("--session="))t.session=a.slice(10),n++;else if(a==="--block-id")t.blockId=e[n+1]||"",n+=2;else if(a.startsWith("--block-id="))t.blockId=a.slice(11),n++;else if(a==="--status")t.status=e[n+1]||"",n+=2;else if(a.startsWith("--status="))t.status=a.slice(9),n++;else if(a==="--severity")t.severity=e[n+1]||"",n+=2;else if(a.startsWith("--severity="))t.severity=a.slice(11),n++;else if(a==="--cursor")t.cursor=e[n+1]||"",n+=2;else if(a.startsWith("--cursor="))t.cursor=a.slice(9),n++;else if(a==="--limit")t.limit=Number.parseInt(e[n+1]||"50",10),n+=2;else if(a.startsWith("--limit="))t.limit=Number.parseInt(a.slice(8),10),n++;else if(a==="--format")t.format=e[n+1]||"json",n+=2;else if(a.startsWith("--format="))t.format=a.slice(9),n++;else n++}return t}async function SH(e,t,n){let a=w3e(e);if(!a.session)D({code:"missing_required_flag",message:"Missing required flag: --session"},S);let r={};if(a.blockId)r.block_id=a.blockId;if(a.status)r.status=a.status;if(a.severity)r.severity=a.severity;if(a.cursor)r.cursor=a.cursor;if(a.limit!==void 0)r.limit=String(a.limit);let i=await n.get(`/sessions/${encodeURIComponent(a.session)}/threads`,{query:r});if(a.format==="json")console.log(JSON.stringify(i.body,null,2));else{let o=i.body.threads??[],s=i.body.total_count??o.length;console.log(`Threads (${s}):`);for(let c of o){let A=c.severity?` [${c.severity}]`:"",l=c.block_id?` on ${c.block_id}`:" (session-level)";console.log(` ${c.thread_id} ${c.status}${A}${l} (${c.comment_count} comments)`)}if(i.body.next_cursor)console.log(`
698
- Next cursor: ${i.body.next_cursor}`)}process.exit(H)}function k3e(e){let t={session:"",bodyMd:"",format:"json"},n=0;while(n<e.length){let a=e[n];if(a==="--session")t.session=e[n+1]||"",n+=2;else if(a.startsWith("--session="))t.session=a.slice(10),n++;else if(a==="--block-id"||a==="--block")t.blockId=e[n+1]||"",n+=2;else if(a.startsWith("--block-id="))t.blockId=a.slice(11),n++;else if(a.startsWith("--block="))t.blockId=a.slice(8),n++;else if(a==="--body")t.bodyMd=e[n+1]||"",n+=2;else if(a.startsWith("--body="))t.bodyMd=a.slice(7),n++;else if(a==="--severity")t.severity=e[n+1]||"",n+=2;else if(a.startsWith("--severity="))t.severity=a.slice(11),n++;else if(a==="--idempotency-key")t.idempotencyKey=e[n+1]||"",n+=2;else if(a.startsWith("--idempotency-key="))t.idempotencyKey=a.slice(18),n++;else if(a==="--format")t.format=e[n+1]||"json",n+=2;else if(a.startsWith("--format="))t.format=a.slice(9),n++;else n++}return t}var B3e=new Set(["suggestion","needs_changes","blocking"]);async function LH(e,t,n){let a=k3e(e);if(!a.session)D({code:"missing_required_flag",message:"Missing required flag: --session"},S);if(!a.bodyMd)D({code:"missing_required_flag",message:"Missing required flag: --body"},S);if(a.severity&&!B3e.has(a.severity))D({code:"invalid_flag_value",message:`Invalid --severity value: ${a.severity}. Allowed values: suggestion, needs_changes, blocking.`},S);let r={body_md:a.bodyMd,source:"automation"};if(a.blockId)r.block_id=a.blockId;if(a.severity)r.severity=a.severity;let i={};if(a.idempotencyKey)i["Idempotency-Key"]=a.idempotencyKey;let o=await n.post(`/sessions/${encodeURIComponent(a.session)}/threads`,{body:r,headers:i});if(a.format==="json")console.log(JSON.stringify(o.body,null,2));else{let s=o.body;if(console.log(`Thread created: ${s.thread_id}`),console.log(`Status: ${s.status}`),s.severity)console.log(`Severity: ${s.severity}`);if(s.block_id)console.log(`Block: ${s.block_id}`);console.log(`Request ID: ${s.request_id}`)}process.exit(H)}function C3e(e){let t={session:"",thread:"",bodyMd:"",format:"json"},n=0;while(n<e.length){let a=e[n];if(a==="--session")t.session=e[n+1]||"",n+=2;else if(a.startsWith("--session="))t.session=a.slice(10),n++;else if(a==="--thread")t.thread=e[n+1]||"",n+=2;else if(a.startsWith("--thread="))t.thread=a.slice(9),n++;else if(a==="--body")t.bodyMd=e[n+1]||"",n+=2;else if(a.startsWith("--body="))t.bodyMd=a.slice(7),n++;else if(a==="--idempotency-key")t.idempotencyKey=e[n+1]||"",n+=2;else if(a.startsWith("--idempotency-key="))t.idempotencyKey=a.slice(18),n++;else if(a==="--format")t.format=e[n+1]||"json",n+=2;else if(a.startsWith("--format="))t.format=a.slice(9),n++;else n++}return t}async function jH(e,t,n){let a=C3e(e);if(!a.session)D({code:"missing_required_flag",message:"Missing required flag: --session"},S);if(!a.thread)D({code:"missing_required_flag",message:"Missing required flag: --thread"},S);if(!a.bodyMd)D({code:"missing_required_flag",message:"Missing required flag: --body"},S);let r={body_md:a.bodyMd,source:"automation"},i={};if(a.idempotencyKey)i["Idempotency-Key"]=a.idempotencyKey;let o=encodeURIComponent(a.session),s=encodeURIComponent(a.thread),c=await n.post(`/sessions/${o}/threads/${s}/comments`,{body:r,headers:i});if(a.format==="json")console.log(JSON.stringify(c.body,null,2));else{let A=c.body;console.log(`Comment posted: ${A.comment_id}`),console.log(`Thread: ${A.thread_id}`),console.log(`Request ID: ${A.request_id}`)}process.exit(H)}function _3e(e){let t={session:"",thread:"",action:"resolve",format:"json"},n=0;while(n<e.length){let a=e[n];if(a==="--session")t.session=e[n+1]||"",n+=2;else if(a.startsWith("--session="))t.session=a.slice(10),n++;else if(a==="--thread")t.thread=e[n+1]||"",n+=2;else if(a.startsWith("--thread="))t.thread=a.slice(9),n++;else if(a==="--action")t.action=e[n+1]||"resolve",n+=2;else if(a.startsWith("--action="))t.action=a.slice(9),n++;else if(a==="--disposition")t.disposition=e[n+1]||"",n+=2;else if(a.startsWith("--disposition="))t.disposition=a.slice(14),n++;else if(a==="--body")t.body=e[n+1]||"",n+=2;else if(a.startsWith("--body="))t.body=a.slice(7),n++;else if(a==="--if-match")t.ifMatch=e[n+1]||"",n+=2;else if(a.startsWith("--if-match="))t.ifMatch=a.slice(11),n++;else if(a==="--reopen")t.action="reopen",n++;else if(a==="--format")t.format=e[n+1]||"json",n+=2;else if(a.startsWith("--format="))t.format=a.slice(9),n++;else n++}return t}async function qH(e,t,n){let a=_3e(e);if(!a.session)D({code:"missing_required_flag",message:"Missing required flag: --session"},S);if(!a.thread)D({code:"missing_required_flag",message:"Missing required flag: --thread"},S);let r=encodeURIComponent(a.session),i=encodeURIComponent(a.thread),o=a.action==="reopen"?"reopen":"resolve",s={};if(a.disposition||a.body){let l={};if(a.disposition)l.state=a.disposition;if(a.body)l.rationale_md=a.body;s.disposition=l}let c={};if(a.ifMatch)c["If-Match"]=a.ifMatch;let A=await n.post(`/sessions/${r}/threads/${i}/${o}`,{body:s,headers:c});if(a.format==="json")console.log(JSON.stringify(A.body,null,2));else{let l=A.body,d=a.action==="reopen"?"Reopened":"Resolved";console.log(`${d} thread: ${l.thread_id}`),console.log(`Status: ${l.status}`),console.log(`Version: ${l.version}`),console.log(`Request ID: ${l.request_id}`)}process.exit(H)}function E3e(e){let t={session:"",thread:"",state:"",format:"json"},n=0;while(n<e.length){let a=e[n];if(a==="--session")t.session=e[n+1]||"",n+=2;else if(a.startsWith("--session="))t.session=a.slice(10),n++;else if(a==="--thread")t.thread=e[n+1]||"",n+=2;else if(a.startsWith("--thread="))t.thread=a.slice(9),n++;else if(a==="--state")t.state=e[n+1]||"",n+=2;else if(a.startsWith("--state="))t.state=a.slice(8),n++;else if(a==="--rationale")t.rationaleMd=e[n+1]||"",n+=2;else if(a.startsWith("--rationale="))t.rationaleMd=a.slice(12),n++;else if(a==="--format")t.format=e[n+1]||"json",n+=2;else if(a.startsWith("--format="))t.format=a.slice(9),n++;else n++}return t}async function NH(e,t,n){let a=E3e(e);if(!a.session)D({code:"missing_required_flag",message:"Missing required flag: --session"},S);if(!a.thread)D({code:"missing_required_flag",message:"Missing required flag: --thread"},S);if(!a.state)D({code:"missing_required_flag",message:"Missing required flag: --state"},S);let r={state:a.state};if(a.rationaleMd)r.rationale_md=a.rationaleMd;let i=encodeURIComponent(a.session),o=encodeURIComponent(a.thread),s=await n.post(`/sessions/${i}/threads/${o}/dispositions`,{body:r});if(a.format==="json")console.log(JSON.stringify(s.body,null,2));else{let c=s.body;console.log(`Disposition recorded: ${c.disposition_id}`),console.log(`Thread: ${c.thread_id}`),console.log(`State: ${c.state}`),console.log(`Request ID: ${c.request_id}`)}process.exit(H)}function v3e(e){let t={session:"",thread:"",type:"",format:"json"},n=0;while(n<e.length){let a=e[n];if(a==="--session")t.session=e[n+1]||"",n+=2;else if(a.startsWith("--session="))t.session=a.slice(10),n++;else if(a==="--thread")t.thread=e[n+1]||"",n+=2;else if(a.startsWith("--thread="))t.thread=a.slice(9),n++;else if(a==="--type")t.type=e[n+1]||"",n+=2;else if(a.startsWith("--type="))t.type=a.slice(7),n++;else if(a==="--commit-sha")t.commitSha=e[n+1]||"",n+=2;else if(a.startsWith("--commit-sha="))t.commitSha=a.slice(13),n++;else if(a==="--proposed-change-id")t.proposedChangeId=e[n+1]||"",n+=2;else if(a.startsWith("--proposed-change-id="))t.proposedChangeId=a.slice(21),n++;else if(a==="--pr-url")t.prUrl=e[n+1]||"",n+=2;else if(a.startsWith("--pr-url="))t.prUrl=a.slice(9),n++;else if(a==="--attestation")t.attestation=e[n+1]||"",n+=2;else if(a.startsWith("--attestation="))t.attestation=a.slice(14),n++;else if(a==="--format")t.format=e[n+1]||"json",n+=2;else if(a.startsWith("--format="))t.format=a.slice(9),n++;else n++}return t}async function MH(e,t,n){let a=v3e(e);if(!a.session)D({code:"missing_required_flag",message:"Missing required flag: --session"},S);if(!a.thread)D({code:"missing_required_flag",message:"Missing required flag: --thread"},S);if(!a.type)D({code:"missing_required_flag",message:"Missing required flag: --type"},S);let r={};if(a.commitSha)r.commit_sha=a.commitSha;if(a.proposedChangeId)r.proposed_change_id=a.proposedChangeId;if(a.prUrl)r.pr_url=a.prUrl;if(a.attestation)r.attestation=a.attestation;let i={evidence_type:a.type,evidence_json:r},o=encodeURIComponent(a.session),s=encodeURIComponent(a.thread),c=await n.post(`/sessions/${o}/threads/${s}/evidence`,{body:i});if(a.format==="json")console.log(JSON.stringify(c.body,null,2));else{let A=c.body;console.log(`Evidence attached: ${A.evidence_id}`),console.log(`Thread: ${A.thread_id}`),console.log(`Type: ${A.type}`),console.log(`Request ID: ${A.request_id}`)}process.exit(H)}var GH=["file","doc","pr","custom"],Q3e=new Set(GH);function x3e(e){let t={sourceType:"",kind:"",key:"",headSessionId:"",format:"json"},n=0;while(n<e.length){let a=e[n];if(a==="--source-type")t.sourceType=e[n+1]||"",n+=2;else if(a.startsWith("--source-type="))t.sourceType=a.slice(14),n++;else if(a==="--repo-id")t.repoId=e[n+1]||"",n+=2;else if(a.startsWith("--repo-id="))t.repoId=a.slice(10),n++;else if(a==="--project-id"||a==="--project")t.projectId=e[n+1]||"",n+=2;else if(a.startsWith("--project-id="))t.projectId=a.slice(13),n++;else if(a.startsWith("--project="))t.projectId=a.slice(10),n++;else if(a==="--kind")t.kind=e[n+1]||"",n+=2;else if(a.startsWith("--kind="))t.kind=a.slice(7),n++;else if(a==="--key")t.key=e[n+1]||"",n+=2;else if(a.startsWith("--key="))t.key=a.slice(6),n++;else if(a==="--head-session")t.headSessionId=e[n+1]||"",n+=2;else if(a.startsWith("--head-session="))t.headSessionId=a.slice(15),n++;else if(a==="--format")t.format=e[n+1]||"json",n+=2;else if(a.startsWith("--format="))t.format=a.slice(9),n++;else n++}return t}async function RH(e,t,n){let a=x3e(e);if(!a.sourceType)D({code:"missing_required_flag",message:"Missing required flag: --source-type"},S);if(!a.kind)D({code:"missing_required_flag",message:"Missing required flag: --kind"},S);if(!a.key)D({code:"missing_required_flag",message:"Missing required flag: --key"},S);if(!a.headSessionId)D({code:"missing_required_flag",message:"Missing required flag: --head-session"},S);let r=a.kind.trim().toLowerCase();if(!Q3e.has(r))D({code:"invalid_flag_value",message:`Invalid --kind value: ${a.kind}. Must be one of: ${GH.join(", ")}`},S);let i={source_type:a.sourceType,kind:r,key:a.key,head_session_id:a.headSessionId};if(a.repoId)i.repo_id=a.repoId;if(a.projectId)i.project_id=a.projectId;let o=await n.post("/review-refs",{body:i});if(a.format==="json")console.log(JSON.stringify(o.body,null,2));else console.log(`Review ref created: ${o.body.id}`),console.log(`Head session: ${o.body.head_session_id??"none"}`),console.log(`Request ID: ${o.body.request_id}`);process.exit(H)}function I3e(e){let t={reviewRefId:"",format:"json"},n=0;while(n<e.length){let a=e[n];if(a==="--review-ref")t.reviewRefId=e[n+1]||"",n+=2;else if(a.startsWith("--review-ref="))t.reviewRefId=a.slice(13),n++;else if(a==="--format")t.format=e[n+1]||"json",n+=2;else if(a.startsWith("--format="))t.format=a.slice(9),n++;else n++}return t}async function PH(e,t,n){let a=I3e(e);if(!a.reviewRefId)D({code:"missing_required_flag",message:"Missing required flag: --review-ref"},S);let r=await n.get(`/review-refs/${encodeURIComponent(a.reviewRefId)}/resolve`);if(a.format==="json")console.log(JSON.stringify(r.body,null,2));else console.log(`Review ref: ${r.body.review_ref_id}`),console.log(`Head session: ${r.body.head_session_id}`),console.log(`State: ${r.body.state}`),console.log(`Request ID: ${r.body.request_id}`);process.exit(H)}function D3e(e){let t={reviewRefId:"",headSessionId:"",format:"json"},n=0;while(n<e.length){let a=e[n];if(a==="--review-ref")t.reviewRefId=e[n+1]||"",n+=2;else if(a.startsWith("--review-ref="))t.reviewRefId=a.slice(13),n++;else if(a==="--head-session")t.headSessionId=e[n+1]||"",n+=2;else if(a.startsWith("--head-session="))t.headSessionId=a.slice(15),n++;else if(a==="--expected-head")t.expectedHeadSessionId=e[n+1]||"",n+=2;else if(a.startsWith("--expected-head="))t.expectedHeadSessionId=a.slice(16),n++;else if(a==="--format")t.format=e[n+1]||"json",n+=2;else if(a.startsWith("--format="))t.format=a.slice(9),n++;else n++}return t}async function zH(e,t,n){let a=D3e(e);if(!a.reviewRefId)D({code:"missing_required_flag",message:"Missing required flag: --review-ref"},S);if(!a.headSessionId)D({code:"missing_required_flag",message:"Missing required flag: --head-session"},S);let r=a.expectedHeadSessionId?.trim();if(!r)r=(await n.get(`/review-refs/${encodeURIComponent(a.reviewRefId)}/resolve`)).body.head_session_id;let i={head_session_id:a.headSessionId};if(r)i.expected_head_session_id=r;let o=await n.post(`/review-refs/${encodeURIComponent(a.reviewRefId)}/advance`,{body:i});if(a.format==="json")console.log(JSON.stringify(o.body,null,2));else console.log(`Advanced review ref: ${o.body.review_ref.id}`),console.log(`New head session: ${o.body.review_ref.head_session_id}`),console.log(`Request ID: ${o.body.request_id}`);process.exit(H)}var UH=["approved","rejected","conditional"];function F3e(e){let t={session:"",approverEmails:[],format:"json"},n=0;while(n<e.length){let a=e[n];if(a==="--session")t.session=e[n+1]||"",n+=2;else if(a.startsWith("--session="))t.session=a.slice(10),n++;else if(a==="--approver"){if(e[n+1])t.approverEmails.push(e[n+1]);n+=2}else if(a.startsWith("--approver="))t.approverEmails.push(a.slice(11)),n++;else if(a==="--approvers"){if(e[n+1])t.approverEmails.push(...e[n+1].split(","));n+=2}else if(a.startsWith("--approvers="))t.approverEmails.push(...a.slice(12).split(",")),n++;else if(a==="--message")t.message=e[n+1]||"",n+=2;else if(a.startsWith("--message="))t.message=a.slice(10),n++;else if(a==="--idempotency-key")t.idempotencyKey=e[n+1]||"",n+=2;else if(a.startsWith("--idempotency-key="))t.idempotencyKey=a.slice(18),n++;else if(a==="--format")t.format=e[n+1]||"json",n+=2;else if(a.startsWith("--format="))t.format=a.slice(9),n++;else n++}return t}async function HH(e,t,n){let a=F3e(e);if(!a.session)D({code:"missing_required_flag",message:"Missing required flag: --session"},S);if(a.approverEmails.length===0)D({code:"missing_required_flag",message:"Missing required flag: --approver or --approvers"},S);let r={approver_emails:a.approverEmails};if(a.message)r.message=a.message;let i={};if(a.idempotencyKey)i["Idempotency-Key"]=a.idempotencyKey;let o=await n.post(`/sessions/${encodeURIComponent(a.session)}/request-approval`,{body:r,headers:i});if(a.format==="json")console.log(JSON.stringify(o.body,null,2));else{let s=o.body.approval_requests??[];console.log(`Approval requested (${s.length} approvers):`);for(let c of s)console.log(` ${c.id} ${c.approver_email} ${c.state}`);console.log(`Request ID: ${o.body.request_id}`)}process.exit(H)}function $3e(e){let t={session:"",decision:"",format:"json"},n=0;while(n<e.length){let a=e[n];if(a==="--session")t.session=e[n+1]||"",n+=2;else if(a.startsWith("--session="))t.session=a.slice(10),n++;else if(a==="--decision")t.decision=e[n+1]||"",n+=2;else if(a.startsWith("--decision="))t.decision=a.slice(11),n++;else if(a==="--comment"||a==="--comment-md")t.commentMd=e[n+1]||"",n+=2;else if(a.startsWith("--comment="))t.commentMd=a.slice(10),n++;else if(a.startsWith("--comment-md="))t.commentMd=a.slice(13),n++;else if(a==="--idempotency-key")t.idempotencyKey=e[n+1]||"",n+=2;else if(a.startsWith("--idempotency-key="))t.idempotencyKey=a.slice(18),n++;else if(a==="--format")t.format=e[n+1]||"json",n+=2;else if(a.startsWith("--format="))t.format=a.slice(9),n++;else n++}return t}function S3e(e){return UH.includes(e)}async function TH(e,t,n){let a=$3e(e);if(!a.session)D({code:"missing_required_flag",message:"Missing required flag: --session"},S);if(!a.decision)D({code:"missing_required_flag",message:"Missing required flag: --decision"},S);if(!S3e(a.decision))D({code:"invalid_argument",message:`Invalid decision: ${a.decision}. Must be one of: ${UH.join(", ")}`},S);let r={decision:a.decision};if(a.commentMd!==void 0)r.comment_md=a.commentMd;let i={};if(a.idempotencyKey)i["Idempotency-Key"]=a.idempotencyKey;let o=await n.post(`/sessions/${encodeURIComponent(a.session)}/approval`,{body:r,headers:i});if(a.format==="json")console.log(JSON.stringify(o.body,null,2));else{let s=o.body.approval;if(console.log(`Approval recorded: ${s.approval_id}`),console.log(`Decision: ${s.decision}`),console.log(`Participant: ${s.participant_id}`),s.comment_md)console.log(`Comment: ${s.comment_md}`);console.log(`Decided At: ${s.decided_at}`),console.log(`Request ID: ${o.body.request_id}`)}process.exit(H)}var kK=Fo(NY(),1),BK=Fo(iK(),1);import{readFileSync as yK}from"fs";import{resolve as wK}from"path";var b7e=x.string().regex(/^[a-f0-9]{64}$/,{message:"Must be a 64-character lowercase hex SHA-256 digest"}),Vn=x.string().regex(/^sha256:[a-f0-9]{64}$/,{message:'Must be formatted as "sha256:<64 hex chars>"'}),oK=x.string().datetime(),sK=["export","render_receipt","lineage_diff","attestation","verification_instructions"],cK=x.object({path:x.string().min(1),sha256:Vn,type:x.enum(sK),view:x.string().optional()}),Wx=x.object({render_profile:x.string(),renderer_version:x.string(),sanitizer_version:x.string(),config_hash:Vn}),AK=x.object({enable_export_hash:x.boolean(),enable_export_signature:x.boolean(),sealed_render_of_record:x.boolean(),enable_merkle_roots:x.boolean()}),lK=x.object({alg:x.string(),key_id:x.string(),sig:x.string()}),f7e=x.object({session_id:x.string().min(1),render_artifact_sha256:Vn,render_sha256:Vn,sealed_at:oK,provenance:Wx}),h7e=x.object({bundle_version:x.literal("evidence.v1"),session_id:x.string().min(1),source_content_sha256:Vn,created_at:oK,integrity_settings:AK,renderer_provenance:Wx.optional(),contents:x.array(cK),bundle_sha256:Vn,signature:lK.optional()});var y7e=/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/,dK=x.string().datetime();var w7e=x.enum(["git","upload"]),k7e=x.enum(["approved","rejected","conditional"]),B7e=x.record(x.string(),x.unknown()),uK=x.object({approval_id:x.string().min(1),decision:k7e,decided_by_participant_id:x.string().min(1),decided_by_display:x.string().min(1),decided_at:dK,conditions:x.array(B7e)}),C7e=x.object({schema_version:x.literal("attestation.v1"),session_id:x.string().min(1),source_type:w7e,source_content_sha256:Vn,source_blob_oid:x.string().regex(y7e,"source_blob_oid must be 40 or 64 lowercase hex chars").optional(),timestamp:dK,approvals:x.array(uK).min(1),export_sha256:Vn,blocks_merkle_root:Vn.optional(),threads_merkle_root:Vn.optional()}).superRefine((e,t)=>{if(e.source_type==="git"&&!e.source_blob_oid)t.addIssue({code:x.ZodIssueCode.custom,path:["source_blob_oid"],message:"source_blob_oid is required when source_type=git"});if(e.source_type!=="git"&&e.source_blob_oid)t.addIssue({code:x.ZodIssueCode.custom,path:["source_blob_oid"],message:"source_blob_oid is only allowed when source_type=git"});let n=e.blocks_merkle_root!==void 0,a=e.threads_merkle_root!==void 0;if(n!==a)t.addIssue({code:x.ZodIssueCode.custom,path:["blocks_merkle_root"],message:"blocks_merkle_root and threads_merkle_root must either both be set or both be omitted"})});var Ebt=Uint8Array.from([48,46,2,1,0,48,5,6,3,43,101,112,4,34,4,32]),vbt=Uint8Array.from([48,42,48,5,6,3,43,101,112,3,33,0]);import{createHash as _7e}from"crypto";var E7e=new Set(["integrity","exported_at","request_id","view_requested","view_resolved","partial","incomplete_sections"]),v7e=new Set(["statistics"]),Q7e=new Set(["change_status","change_basis","block_key_derived"]),x7e=new Set(["classification"]);function mK(e){return _7e("sha256").update(e,"utf8").digest("hex")}function Nt(e,t){if(e==null&&t==null)return 0;if(e==null)return 1;if(t==null)return-1;return e.localeCompare(t)}function I7e(e,t){if(e==null&&t==null)return 0;if(e==null)return 1;if(t==null)return-1;return e-t}function D7e(e){return[...e].sort((t,n)=>I7e(t.block_index,n.block_index))}function F7e(e){return[...e].sort((t,n)=>Nt(t.thread_id,n.thread_id))}function $7e(e){return[...e].sort((t,n)=>Nt(t.comment_id,n.comment_id))}function S7e(e){return[...e].sort((t,n)=>{let a=Nt(t.provider,n.provider);if(a!==0)return a;if(a=Nt(t.external_id,n.external_id),a!==0)return a;return Nt(t.url,n.url)})}function L7e(e){return[...e].sort()}function j7e(e){return[...e].sort((t,n)=>{let a=Nt(t.ref_id,n.ref_id);if(a!==0)return a;let r=pK(t),i=pK(n);for(let o=0;o<r.length;o++){let s=Nt(r[o],i[o]);if(s!==0)return s}return 0})}function pK(e){let t=e.target??{},n=t.anchor??{};return[e.purpose??null,t.source_type??null,t.file_path??null,t.doc_key??null,n.type??null,n.block_id??null]}function q7e(e){return[...e].sort()}function N7e(e){return[...e].sort((t,n)=>{let a=Nt(t.emoji,n.emoji);if(a!==0)return a;let r=t.reactor??{},i=n.reactor??{};if(a=Nt(r.participant_id,i.participant_id),a!==0)return a;if(a=Nt(r.email,i.email),a!==0)return a;return Nt(t.created_at,n.created_at)})}function M7e(e){return[...e].sort((t,n)=>Nt(t.request_id,n.request_id))}function G7e(e){return[...e].sort((t,n)=>Nt(t.approval_id,n.approval_id))}function R7e(e){return[...e].sort((t,n)=>Nt(t.proposed_change_id,n.proposed_change_id))}function P7e(e){return[...e].sort((t,n)=>{let a=Nt(t.kind,n.kind);if(a!==0)return a;if(a=Nt(t.require_verification_tier,n.require_verification_tier),a!==0)return a;if(a=Nt(t.description,n.description),a!==0)return a;let r=Array.isArray(t.thread_ids)?[...t.thread_ids].sort().join(","):"",i=Array.isArray(n.thread_ids)?[...n.thread_ids].sort().join(","):"";if(a=r.localeCompare(i),a!==0)return a;let o=Array.isArray(t.check_rule_ids)?[...t.check_rule_ids].sort().join(","):"",s=Array.isArray(n.check_rule_ids)?[...n.check_rule_ids].sort().join(","):"";return o.localeCompare(s)})}function z7e(e){let t={...e};if(Array.isArray(t.mentions))t.mentions=q7e(t.mentions);if(Array.isArray(t.reactions))t.reactions=N7e(t.reactions);return t}function U7e(e){let t={...e};if(Array.isArray(t.comments))t.comments=$7e(t.comments).map((n)=>z7e(n));if(Array.isArray(t.links))t.links=S7e(t.links);if(Array.isArray(t.tags))t.tags=L7e(t.tags);if(Array.isArray(t.references))t.references=j7e(t.references);return t}function H7e(e){let t={...e};if(Array.isArray(t.conditions))t.conditions=P7e(t.conditions).map((n)=>{let a={...n};if(Array.isArray(a.thread_ids))a.thread_ids=[...a.thread_ids].sort();if(Array.isArray(a.check_rule_ids))a.check_rule_ids=[...a.check_rule_ids].sort();return a});return t}function Jx(e,t){let n={};for(let[a,r]of Object.entries(e)){if(E7e.has(a))continue;if(!t.includeNonAuthoritative&&v7e.has(a))continue;n[a]=r}if(Array.isArray(n.blocks)){let a=D7e(n.blocks);if(!t.includeNonAuthoritative)a=a.map((r)=>{let i={};for(let[o,s]of Object.entries(r))if(!Q7e.has(o))i[o]=s;return i});n.blocks=a}if(Array.isArray(n.threads)){let a=F7e(n.threads);a=a.map((r)=>{let i=U7e(r);if(!t.includeNonAuthoritative){let o={};for(let[s,c]of Object.entries(i))if(!x7e.has(s))o[s]=c;i=o}return i}),n.threads=a}if(Array.isArray(n.approval_requests))n.approval_requests=M7e(n.approval_requests);if(Array.isArray(n.approvals))n.approvals=G7e(n.approvals).map((a)=>H7e(a));if(Array.isArray(n.proposed_changes))n.proposed_changes=R7e(n.proposed_changes);if(Array.isArray(n.participants)){let a=n.participants;n.participants=[...a].sort((r,i)=>Nt(r.id,i.id))}if(n.extensions&&typeof n.extensions==="object"&&!Array.isArray(n.extensions)){let a=n.extensions,r={};for(let[i,o]of Object.entries(a))if(o&&typeof o==="object"&&!Array.isArray(o)&&(t.includeNonAuthoritative||o.authoritative===!0))r[i]=o;if(Object.keys(r).length>0)n.extensions=r;else delete n.extensions}return n}function Yb(e){let t=Jx(e,{includeNonAuthoritative:!1});return mK(Ys(t))}function Kb(e){let t=Jx(e,{includeNonAuthoritative:!0});return mK(Ys(t))}import{sign as $bt,verify as T7e,createPublicKey as O7e,createPrivateKey as Sbt}from"crypto";function Z7e(e){let t=Uint8Array.from([48,42,48,5,6,3,43,101,112,3,33,0]),n=new Uint8Array(t.length+e.length);return n.set(t,0),n.set(e,t.length),Buffer.from(n)}function Vx(e,t,n){if(t.alg!=="ed25519")return!1;if(n.publicKey.length!==32)return!1;try{let a=Z7e(n.publicKey),r=O7e({key:a,format:"der",type:"spki"}),i=Uint8Array.from(Buffer.from(t.sig,"base64"));return T7e(null,new TextEncoder().encode(e),r,i)}catch{return!1}}var gK={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://typescape.ai/schemas/export.v1.schema.json",title:"Typescape Export v1",$comment:"Non-enforceable invariants: (1) threads[].block_id must reference blocks[].block_id when anchor.type is block/range; (2) blocks must be sorted by block_index ascending; (3) threads must be sorted by thread_id for hash stability; (4) non-authoritative extensions (authoritative=false) are excluded from integrity.export_sha256; (5) breaking changes require new v2 artifacts and MUST NOT semantically drift v1 files in place.",type:"object",additionalProperties:!1,required:["schema_version","exported_at","view_requested","view_resolved","session","blocks","threads","synthesis"],properties:{schema_version:{const:"v1"},exported_at:{type:"string",format:"date-time"},view_requested:{type:["string","null"]},view_resolved:{type:"string",minLength:1},integrity:{type:"object",additionalProperties:!1,properties:{canonicalization:{type:"string"},export_sha256:{$ref:"#/$defs/sha256"},export_full_sha256:{$ref:"#/$defs/sha256"},signature:{type:"object",additionalProperties:!1,required:["alg","key_id","sig"],properties:{alg:{type:"string",minLength:1},key_id:{type:"string",minLength:1},sig:{type:"string",minLength:1}}},blocks_merkle_root:{$ref:"#/$defs/sha256"},threads_merkle_root:{$ref:"#/$defs/sha256"}}},rendering:{type:"object",additionalProperties:!1,properties:{include_render_html:{type:"boolean"},html_csp:{type:"string"}}},session:{type:"object",additionalProperties:!1,required:["id","source_type","file_path","source_content_sha256","state","block_id_scheme","block_key_scheme","created_at"],properties:{id:{type:"string",minLength:1},source_type:{type:"string",enum:["git","upload"]},document_type:{type:["string","null"],enum:["markdown","image_set","pdf",null]},block_count:{type:["integer","null"],minimum:0},repo_id:{type:["string","null"],minLength:1},git_sha:{anyOf:[{$ref:"#/$defs/gitSha"},{type:"null"}]},project_id:{type:["string","null"],minLength:1},upload_batch_id:{type:["string","null"],minLength:1},file_path:{$ref:"#/$defs/filePath"},document_locator:{type:["object","null"],additionalProperties:!0},doc_key:{type:["string","null"],minLength:1},corpus_snapshot_id:{type:["string","null"],minLength:1},source_context:{type:["object","null"],additionalProperties:!0},extra:{},root_session_id:{type:["string","null"],minLength:1},supersedes_session_id:{type:["string","null"],minLength:1},source_blob_oid:{type:["string","null"],minLength:1},source_content_sha256:{$ref:"#/$defs/sha256"},source_size_bytes:{type:"integer",minimum:0},title:{type:["string","null"]},state:{type:"string",enum:["draft","active","closed","archived","superseded"]},block_id_scheme:{type:"string",minLength:1},block_key_scheme:{type:"string",minLength:1},created_at:{type:"string",format:"date-time"},billable_at:{type:["string","null"],format:"date-time"}},allOf:[{if:{properties:{source_type:{const:"git"}},required:["source_type"]},then:{required:["repo_id","git_sha"],properties:{repo_id:{type:"string",minLength:1},git_sha:{$ref:"#/$defs/gitSha"}}}},{if:{properties:{source_type:{const:"upload"}},required:["source_type"]},then:{required:["project_id","upload_batch_id"],properties:{project_id:{type:"string",minLength:1},upload_batch_id:{type:"string",minLength:1}}}}]},blocks:{type:"array",items:{type:"object",additionalProperties:!1,required:["block_id","block_index","block_type","start_line","end_line"],properties:{block_id:{type:"string",minLength:1},block_key:{type:["string","null"],minLength:1},block_key_source:{type:["string","null"],enum:["marker","sidecar",null]},block_key_derived:{type:["object","null"],additionalProperties:!0},block_index:{type:"integer",minimum:0},block_type:{type:"string",enum:["heading","paragraph","code_block","table","thematic_break","html","blockquote","list_item","image"]},start_line:{type:"integer",minimum:1},end_line:{type:"integer",minimum:1},plaintext:{type:"string"},change_status:{type:["string","null"],enum:["unchanged","modified","added","removed","moved",null]},change_basis:{type:["string","null"],enum:["block_key","fingerprint_ui_only","none",null]}}}},participants:{type:"array",items:{type:"object",additionalProperties:!1,required:["id","email","roles","created_at"],properties:{id:{type:"string",minLength:1},email:{type:"string",minLength:1},roles:{type:"array",items:{type:"string",minLength:1}},delegated_from_participant_id:{type:["string","null"],minLength:1},created_at:{type:"string",format:"date-time"}}}},threads:{type:"array",items:{type:"object",additionalProperties:!1,required:["thread_id","anchor","status","thread_type","source","severity","created_at","comments"],properties:{thread_id:{type:"string",minLength:1},block_id:{type:["string","null"],minLength:1},spatial_anchor:{type:["object","null"],additionalProperties:!1,required:["ref_id","spatial_x","spatial_y","spatial_w","spatial_h","version","ref_width","ref_height"],properties:{ref_id:{type:"string",minLength:1},spatial_x:{type:"number"},spatial_y:{type:"number"},spatial_w:{type:["number","null"]},spatial_h:{type:["number","null"]},version:{type:"integer",minimum:1},ref_width:{type:["number","null"]},ref_height:{type:["number","null"]}}},anchor:{type:"object",additionalProperties:!1,required:["type"],properties:{type:{type:"string",enum:["block","range","session"]},start_offset:{type:"integer",minimum:0},end_offset:{type:"integer",minimum:0}}},references:{type:"array",items:{$ref:"#/$defs/anchorRef"}},duplicate_of_thread_id:{type:"string",minLength:1},status:{type:"string",enum:["open","resolved","draft"]},thread_type:{type:"string",enum:["human","system_finding","intake"]},source:{type:"string",enum:["human","system","automation"]},finding_id:{type:["string","null"],minLength:1},rule_id:{type:["string","null"],minLength:1},rule_fingerprint:{type:["string","null"],minLength:1},check_run_id:{type:["string","null"],minLength:1},severity:{type:["string","null"],enum:["suggestion","needs_changes","blocking",null]},tags:{type:"array",items:{type:"string",minLength:1}},classification:{type:"object",required:["non_authoritative"],properties:{non_authoritative:{const:!0}},additionalProperties:!0},assignee:{type:["object","null"],additionalProperties:!1,required:["email","assigned_at"],properties:{email:{type:"string",minLength:1},assigned_at:{type:"string",format:"date-time"}}},block_snapshot:{type:["string","null"]},created_at:{type:"string",format:"date-time"},comments:{type:"array",items:{$ref:"#/$defs/comment"}},links:{type:"array",items:{type:"object",additionalProperties:!1,required:["link_type","provider","url"],properties:{link_type:{type:"string",minLength:1},provider:{type:"string",minLength:1},url:{type:"string",format:"uri"},external_id:{type:"string",minLength:1}}}}},allOf:[{if:{properties:{anchor:{type:"object",properties:{type:{const:"session"}},required:["type"]}},required:["anchor"]},then:{properties:{block_id:{type:"null"}}}},{if:{properties:{anchor:{type:"object",properties:{type:{const:"block"}},required:["type"]}},required:["anchor"]},then:{required:["block_id"],properties:{block_id:{type:"string",minLength:1}}}},{if:{properties:{anchor:{type:"object",properties:{type:{const:"range"}},required:["type"]}},required:["anchor"]},then:{required:["block_id"],properties:{block_id:{type:"string",minLength:1},anchor:{type:"object",additionalProperties:!1,required:["type","start_offset","end_offset"],properties:{type:{const:"range"},start_offset:{type:"integer",minimum:0},end_offset:{type:"integer",minimum:0}}}}}}]}},synthesis:{type:"object",additionalProperties:!1,required:["blocking","needs_changes","suggestions","resolved","summary"],properties:{blocking:{type:"array",items:{$ref:"#/$defs/synthesisItem"}},needs_changes:{type:"array",items:{$ref:"#/$defs/synthesisItem"}},suggestions:{type:"array",items:{$ref:"#/$defs/synthesisItem"}},resolved:{type:"array",items:{$ref:"#/$defs/synthesisItem"}},summary:{$ref:"#/$defs/synthesisSummary"}}},reconciliation_prompt:{type:"string"},round_history:{type:"array",items:{type:"object",additionalProperties:!1,required:["round","session_id","state"],properties:{round:{type:"integer",minimum:1},session_id:{type:"string",minLength:1},created_at:{type:["string","null"],format:"date-time"},title:{type:["string","null"]},state:{type:"string",minLength:1},changes_summary:{type:["string","null"]}}}},issues:{type:"array",items:{type:"object",additionalProperties:!1,required:["issue_id","title","status","source","anchors","created_at"],properties:{issue_id:{type:"string",minLength:1},title:{type:"string",minLength:1},status:{type:"string",enum:["open","in_progress","resolved","archived"]},source:{type:"string",minLength:1},tags:{type:"array",items:{type:"string",minLength:1}},anchors:{type:"array",minItems:1,items:{$ref:"#/$defs/anchorRef"}},created_at:{type:"string",format:"date-time"},updated_at:{type:"string",format:"date-time"}}}},approval_requests:{type:"array",items:{type:"object",additionalProperties:!1,required:["request_id","requested_from","role","status"],properties:{request_id:{type:"string",minLength:1},requested_from:{type:"string",minLength:1},role:{type:"string",minLength:1},status:{type:"string",minLength:1},deadline_at:{type:"string",format:"date-time"},responded_at:{type:"string",format:"date-time"}}}},approvals:{type:"array",items:{type:"object",additionalProperties:!1,required:["approval_id","participant_id","decision","decided_by","decided_at"],properties:{approval_id:{type:"string",minLength:1},participant_id:{type:"string",minLength:1},decision:{type:"string",enum:["approve","reject","conditional"]},decided_by:{type:"string",minLength:1},decided_at:{type:"string",format:"date-time"},comment_md:{type:"string"},conditions:{type:"array",items:{type:"object",additionalProperties:!1,required:["condition_id","kind","description"],properties:{condition_id:{type:"string",minLength:1},kind:{type:"string",minLength:1},description:{type:"string",minLength:1},thread_ids:{type:"array",items:{type:"string",minLength:1}},require_verification_tier:{type:"string",minLength:1}}}}}}},acknowledgements:{type:"array",items:{type:"object",additionalProperties:!1,required:["block_id","participant_id","ack_type","created_at"],properties:{block_id:{type:"string",minLength:1},participant_id:{type:"string",minLength:1},participant_display:{type:"string",minLength:1},ack_type:{type:"string",enum:["read","confirmed"]},created_at:{type:"string",format:"date-time"}}}},policy_status:{type:"object",additionalProperties:!1,required:["verdict","reasons"],properties:{verdict:{type:"string",enum:["pass","fail","warn"]},reasons:{type:"array",items:{type:"object",additionalProperties:!1,required:["code"],properties:{code:{type:"string",minLength:1},details:{type:"object",additionalProperties:!0},thread_ids:{type:"array",items:{type:"string",minLength:1}},approval_ids:{type:"array",items:{type:"string",minLength:1}}}}}}},proposed_changes:{type:"array",items:{type:"object",additionalProperties:!1,required:["proposed_change_id","source_thread_ids","target","expected_source_content_sha256","patch_sha256","state","created_at"],properties:{proposed_change_id:{type:"string",minLength:1},source_thread_ids:{type:"array",minItems:1,items:{type:"string",minLength:1}},target:{$ref:"#/$defs/contentRef"},expected_source_content_sha256:{$ref:"#/$defs/sha256"},patch_sha256:{$ref:"#/$defs/sha256"},state:{type:"string",enum:["proposed","applied","failed","superseded"]},applied_commit_sha:{$ref:"#/$defs/gitSha"},applied_pr_url:{type:"string",format:"uri"},applied_upload_batch_id:{type:"string",minLength:1},applied_file_content_sha256:{$ref:"#/$defs/sha256"},created_at:{type:"string",format:"date-time"}}}},attestation:{type:"object",additionalProperties:!1,required:["attestation_id","schema_version","payload_sha256","signature"],properties:{attestation_id:{type:"string",minLength:1},schema_version:{const:"attestation.v1"},payload_sha256:{$ref:"#/$defs/sha256"},signature:{type:"object",additionalProperties:!1,required:["alg","key_id","sig"],properties:{alg:{type:"string",minLength:1},key_id:{type:"string",minLength:1},sig:{type:"string",minLength:1}}}}},extensions:{type:"object",propertyNames:{type:"string",pattern:"^[a-z][a-z0-9_.-]*$"},additionalProperties:{type:"object",required:["schema_version","authoritative"],properties:{schema_version:{type:"string",pattern:"^[a-z][a-z0-9_.-]*\\.v[0-9]+$"},authoritative:{type:"boolean"}},additionalProperties:!0}},statistics:{type:"object",additionalProperties:!1,properties:{total_threads:{type:"integer",minimum:0},open_threads:{type:"integer",minimum:0},resolved_threads:{type:"integer",minimum:0},total_comments:{type:"integer",minimum:0},unique_commenters:{type:"integer",minimum:0},suggestions_total:{type:"integer",minimum:0},suggestions_accepted:{type:"integer",minimum:0}}},request_id:{type:"string",minLength:1}},$defs:{gitSha:{type:"string",pattern:"^(?:[0-9a-f]{40}|[0-9a-f]{64})$"},sha256:{type:"string",pattern:"^[0-9a-f]{64}$"},filePath:{type:"string",minLength:1,allOf:[{pattern:"^(?!/).+"},{not:{pattern:"(^|/)\\.\\.(?:/|$)"}},{pattern:"^[^\\u0000]+$"}]},anchorRef:{type:"object",additionalProperties:!1,required:["schema_version","source_type","file_path","anchor"],properties:{schema_version:{const:"anchor_ref.v1"},source_type:{type:"string",enum:["git","upload"]},repo_id:{type:"string",minLength:1},git_sha:{$ref:"#/$defs/gitSha"},project_id:{type:"string",minLength:1},upload_batch_id:{type:"string",minLength:1},file_path:{$ref:"#/$defs/filePath"},doc_key:{type:"string",minLength:1},anchor:{type:"object",additionalProperties:!1,required:["type"],properties:{type:{type:"string",enum:["block","range","session"]},block_id:{type:"string",minLength:1},range:{type:"object",additionalProperties:!1,required:["start_offset","end_offset"],properties:{start_offset:{type:"integer",minimum:0},end_offset:{type:"integer",minimum:0}}}},allOf:[{if:{properties:{type:{const:"block"}},required:["type"]},then:{required:["block_id"],properties:{block_id:{type:"string",minLength:1}}}},{if:{properties:{type:{const:"range"}},required:["type"]},then:{required:["block_id","range"],properties:{block_id:{type:"string",minLength:1},range:{type:"object",additionalProperties:!1,required:["start_offset","end_offset"],properties:{start_offset:{type:"integer",minimum:0},end_offset:{type:"integer",minimum:0}}}}}},{if:{properties:{type:{const:"session"}},required:["type"]},then:{not:{anyOf:[{required:["block_id"]},{required:["range"]}]}}}]},non_authoritative:{type:"boolean"}},allOf:[{if:{properties:{source_type:{const:"git"}},required:["source_type"]},then:{required:["repo_id","git_sha"],properties:{repo_id:{type:"string",minLength:1},git_sha:{$ref:"#/$defs/gitSha"}}}},{if:{properties:{source_type:{const:"upload"}},required:["source_type"]},then:{required:["project_id","upload_batch_id"],properties:{project_id:{type:"string",minLength:1},upload_batch_id:{type:"string",minLength:1}}}}]},contentRef:{type:"object",additionalProperties:!1,required:["source_type","file_path"],properties:{source_type:{type:"string",enum:["git","upload"]},repo_id:{type:"string",minLength:1},git_sha:{$ref:"#/$defs/gitSha"},project_id:{type:"string",minLength:1},upload_batch_id:{type:"string",minLength:1},file_path:{$ref:"#/$defs/filePath"}},allOf:[{if:{properties:{source_type:{const:"git"}},required:["source_type"]},then:{required:["repo_id","git_sha"],properties:{repo_id:{type:"string",minLength:1},git_sha:{$ref:"#/$defs/gitSha"}}}},{if:{properties:{source_type:{const:"upload"}},required:["source_type"]},then:{required:["project_id","upload_batch_id"],properties:{project_id:{type:"string",minLength:1},upload_batch_id:{type:"string",minLength:1}}}}]},synthesisItem:{type:"object",additionalProperties:!1,required:["thread_id","block_id","first_comment","status"],properties:{thread_id:{type:"string",minLength:1},block_id:{type:["string","null"],minLength:1},first_comment:{type:"string"},status:{type:"string",enum:["open","resolved","wont_fix"]}}},synthesisSummary:{type:"object",additionalProperties:!1,required:["total_threads","open_blocking","open_needs_changes","open_suggestions","resolved"],properties:{total_threads:{type:"integer",minimum:0},open_blocking:{type:"integer",minimum:0},open_needs_changes:{type:"integer",minimum:0},open_suggestions:{type:"integer",minimum:0},resolved:{type:"integer",minimum:0}}},reaction:{type:"object",additionalProperties:!1,required:["emoji","reactor_participant_id","reactor_email","created_at"],properties:{emoji:{type:"string",minLength:1},reactor_participant_id:{type:["string","null"],minLength:1},reactor_email:{type:["string","null"],format:"email"},created_at:{type:"string",format:"date-time"}}},commentAttachmentAsset:{type:"object",additionalProperties:!1,required:["mime_type","width","height","blurhash"],properties:{mime_type:{type:"string",minLength:1},width:{type:["number","null"]},height:{type:["number","null"]},blurhash:{type:["string","null"]}}},commentAttachment:{type:"object",additionalProperties:!1,required:["asset_id","sort_order","placement","alt_text","caption","anchor_block_id","anchor_position","spatial_x","spatial_y","asset"],properties:{asset_id:{type:"string",minLength:1},sort_order:{type:"integer",minimum:0},placement:{type:"string",minLength:1},alt_text:{type:["string","null"]},caption:{type:["string","null"]},anchor_block_id:{type:["string","null"],minLength:1},anchor_position:{type:["string","null"]},spatial_x:{type:["number","null"]},spatial_y:{type:["number","null"]},asset:{$ref:"#/$defs/commentAttachmentAsset"}}},comment:{type:"object",additionalProperties:!1,required:["comment_id","author","created_at","body_md"],properties:{comment_id:{type:"string",minLength:1},author:{type:"object",additionalProperties:!1,properties:{display:{type:"string"},email:{type:["string","null"],format:"email"},source:{type:"string",minLength:1},verification_level:{type:["string","null"]}}},author_source:{type:"string",minLength:1},created_at:{type:"string",format:"date-time"},edited_at:{type:["string","null"],format:"date-time"},body_md:{type:"string",minLength:1},redacted:{type:"boolean"},redacted_at:{type:["string","null"],format:"date-time"},redaction_reason_code:{type:["string","null"],minLength:1},mentions:{type:"array",items:{type:"string",minLength:1}},reactions:{type:"array",items:{anyOf:[{$ref:"#/$defs/reaction"},{type:"string",minLength:1}]}},attachments:{type:"array",items:{$ref:"#/$defs/commentAttachment"}},suggestion:{type:["object","null"],additionalProperties:!0},suggestion_state:{type:["string","null"],minLength:1},edit_history:{type:"array",items:{type:"object",additionalProperties:!1,required:["edited_at","editor_source","body_md"],properties:{edited_at:{type:"string",format:"date-time"},editor_source:{type:"string",minLength:1},body_md:{type:"string",minLength:1}}}}}}}};var Bc=0,bK=1,K7e=2,W7e=3,fK=4,Xx=5;function J7e(e){let t={file:"",strict:!1,format:"text"},n=0;while(n<e.length){let a=e[n];if(a==="--public-key")t.publicKey=e[n+1],n+=2;else if(a.startsWith("--public-key="))t.publicKey=a.slice(13),n++;else if(a==="--keys-url")t.keysUrl=e[n+1],n+=2;else if(a.startsWith("--keys-url="))t.keysUrl=a.slice(11),n++;else if(a==="--strict")t.strict=!0,n++;else if(a==="--format")t.format=e[n+1]||"text",n+=2;else if(a.startsWith("--format="))t.format=a.slice(9),n++;else if(a==="--json")t.format="json",n++;else if(!a.startsWith("-")&&!t.file)t.file=a,n++;else n++}return t}function V7e(e,t){let n=new kK.default({allErrors:!0,strict:!1});BK.default(n);let a=n.compile(t);if(a(e))return{check:"schema",status:"pass",message:"Export matches export.v1 schema"};let i=(a.errors??[]).map((o)=>({path:o.instancePath||"/",keyword:o.keyword,message:o.message,params:o.params}));return{check:"schema",status:"fail",message:`Schema validation failed: ${i.length} error(s)`,details:i}}function X7e(e){let t=[],n=e.blocks??[],a=e.threads??[],r=e.session??{},i=new Set(n.map((o)=>o.block_id));for(let o=1;o<n.length;o++){let s=n[o-1].block_index,c=n[o].block_index;if(c<s)t.push(`blocks[${o}].block_index (${c}) < blocks[${o-1}].block_index (${s}): not ascending`)}for(let o=0;o<a.length;o++){let s=a[o],c=s.anchor??{},A=c.type,l=s.block_id??c.block_id;if(A==="block"||A==="range"){if(!l)t.push(`threads[${o}] (${s.thread_id}): anchor.type="${A}" but block_id is null/missing`);else if(!i.has(l))t.push(`threads[${o}] (${s.thread_id}): block_id="${l}" not found in blocks[]`)}if(A==="session"&&l)t.push(`threads[${o}] (${s.thread_id}): anchor.type="session" but block_id is non-null`)}if(!r.source_content_sha256)t.push("session.source_content_sha256 is missing or null");if(t.length===0)return{check:"anchors",status:"pass",message:"All anchor invariants satisfied"};return{check:"anchors",status:"fail",message:`${t.length} anchor invariant violation(s)`,details:t}}function ePe(e){let t={...e};if(delete t.integrity,delete t.exported_at,delete t.request_id,delete t.view_requested,delete t.view_resolved,delete t.partial,delete t.incomplete_sections,delete t.statistics,delete t.synthesis,delete t.reconciliation_prompt,Array.isArray(e.blocks))t.blocks=e.blocks.map((n)=>{if(!n||typeof n!=="object"||Array.isArray(n))return n;let a={...n};return delete a.change_status,delete a.change_basis,delete a.block_key_derived,a});if(Array.isArray(e.threads))t.threads=e.threads.map((n)=>{if(!n||typeof n!=="object"||Array.isArray(n))return n;let a={...n};return delete a.classification,a});return t}function tPe(e){let t=e.integrity;if(!t)return{check:"hash",status:"skip",message:"No integrity block present; hash verification skipped"};let{export_sha256:n,export_full_sha256:a}=t;if(!n&&!a)return{check:"hash",status:"skip",message:"No hashes in integrity block; hash verification skipped"};let r=[],i=ePe(e);if(n){let o=Yb(e);if(o!==n){let s=Yb(i);if(s!==n)r.push(`export_sha256 mismatch: expected ${n}, computed_legacy ${o}, computed_server ${s}`)}}if(a){let o=Kb(e);if(o!==a){let s=Kb(i);if(s!==a)r.push(`export_full_sha256 mismatch: expected ${a}, computed_legacy ${o}, computed_server ${s}`)}}if(r.length===0)return{check:"hash",status:"pass",message:"All hashes verified successfully"};return{check:"hash",status:"fail",message:"Hash verification failed",details:r}}function nPe(e){try{let t=yK(wK(e));if(t.length===32)return{publicKeyBytes:new Uint8Array(t)};if(t.length===44||t.length===45){let n=Buffer.from(t.toString("utf8").trim(),"base64");if(n.length!==32)return{error:`Public key file has invalid size after base64 decode: ${n.length} bytes (expected 32)`};return{publicKeyBytes:new Uint8Array(n)}}return{error:`Public key file has invalid size: ${t.length} bytes (expected 32 raw or 44 base64)`}}catch(t){return{error:`Failed to read public key file: ${t instanceof Error?t.message:String(t)}`}}}async function aPe(e,t){let n;try{n=await fetch(e,{method:"GET",headers:{Accept:"application/json"}})}catch(d){return{error:`Failed to fetch keys URL: ${d instanceof Error?d.message:String(d)}`}}if(!n.ok)return{error:`Failed to fetch keys URL: HTTP ${n.status}`};let a;try{a=await n.json()}catch(d){return{error:`Failed to parse keys URL JSON: ${d instanceof Error?d.message:String(d)}`}}let r=a;if(!Array.isArray(r.keys))return{error:"Keys URL payload is invalid: expected { keys: [] }"};let o=r.keys.find((d)=>d.key_id===t);if(!o)return{error:`key_id "${t}" not found at ${e}`};if((typeof o.algorithm==="string"?o.algorithm.toLowerCase():"unknown")!=="ed25519")return{error:`Unsupported key algorithm "${String(o.algorithm)}" for key_id "${t}"`};let c=typeof o.public_key==="string"?o.public_key:typeof o.public_key_base64==="string"?o.public_key_base64:null;if(!c)return{error:`key_id "${t}" is missing public key material`};let A;try{A=Buffer.from(c.trim(),"base64")}catch{return{error:`key_id "${t}" has invalid base64 public key`}}if(A.length!==32)return{error:`key_id "${t}" public key has invalid length: ${A.length} bytes (expected 32)`};let l=typeof o.deprecated_at==="string"&&o.deprecated_at.trim().length>0?o.deprecated_at:null;return{publicKeyBytes:new Uint8Array(A),warning:l?`Key "${t}" is deprecated since ${l}`:void 0}}async function rPe(e,t){let n=e.integrity;if(!n)return{check:"signature",status:"skip",message:"No integrity block present; signature verification skipped"};let a=n.signature;if(!a)return{check:"signature",status:"skip",message:"No signature in integrity block; signature verification skipped"};let r=n.export_sha256;if(!r)return{check:"signature",status:"fail",message:"Signature present but integrity.export_sha256 is missing; cannot verify"};let i,o;if(t.publicKey){let c=nPe(t.publicKey);if(c.error)return{check:"signature",status:"fail",message:c.error};i=c.publicKeyBytes}else if(t.keysUrl){let c=await aPe(t.keysUrl,a.key_id);if(c.error)return{check:"signature",status:"fail",message:c.error};i=c.publicKeyBytes,o=c.warning}else return{check:"signature",status:"skip",message:"Signature present but no --public-key or --keys-url provided; signature verification skipped"};if(!i)return{check:"signature",status:"fail",message:"Public key resolution failed"};let s=Vx(r,{alg:a.alg,key_id:a.key_id,sig:a.sig},{publicKey:i});if(s&&o)return{check:"signature",status:"warn",message:`Signature verified (key_id: ${a.key_id})`,details:[o]};if(s)return{check:"signature",status:"pass",message:`Signature verified (key_id: ${a.key_id})`};return{check:"signature",status:"fail",message:`Signature verification failed for key_id: ${a.key_id}`}}function hK(e){let t=[];t.push(`Verifying: ${e.file}`),t.push("");for(let n of e.checks){let a=n.status==="pass"?"PASS":n.status==="fail"?"FAIL":n.status==="warn"?"WARN":"SKIP";if(t.push(` [${a}] ${n.check}: ${n.message}`),n.details&&n.status!=="pass"){let r=Array.isArray(n.details)?n.details:[n.details];for(let i of r){let o=typeof i==="string"?i:JSON.stringify(i);t.push(` ${o}`)}}}return t.push(""),t.push(e.overall==="pass"?"Overall: PASS \u2014 all checks passed":`Overall: FAIL \u2014 exit code ${e.exit_code}`),t.join(`
698
+ Next cursor: ${i.body.next_cursor}`)}process.exit(H)}function k3e(e){let t={session:"",bodyMd:"",format:"json"},n=0;while(n<e.length){let a=e[n];if(a==="--session")t.session=e[n+1]||"",n+=2;else if(a.startsWith("--session="))t.session=a.slice(10),n++;else if(a==="--block-id"||a==="--block")t.blockId=e[n+1]||"",n+=2;else if(a.startsWith("--block-id="))t.blockId=a.slice(11),n++;else if(a.startsWith("--block="))t.blockId=a.slice(8),n++;else if(a==="--body")t.bodyMd=e[n+1]||"",n+=2;else if(a.startsWith("--body="))t.bodyMd=a.slice(7),n++;else if(a==="--severity")t.severity=e[n+1]||"",n+=2;else if(a.startsWith("--severity="))t.severity=a.slice(11),n++;else if(a==="--idempotency-key")t.idempotencyKey=e[n+1]||"",n+=2;else if(a.startsWith("--idempotency-key="))t.idempotencyKey=a.slice(18),n++;else if(a==="--format")t.format=e[n+1]||"json",n+=2;else if(a.startsWith("--format="))t.format=a.slice(9),n++;else n++}return t}var B3e=new Set(["suggestion","needs_changes","blocking"]);async function LH(e,t,n){let a=k3e(e);if(!a.session)D({code:"missing_required_flag",message:"Missing required flag: --session"},S);if(!a.bodyMd)D({code:"missing_required_flag",message:"Missing required flag: --body"},S);if(a.severity&&!B3e.has(a.severity))D({code:"invalid_flag_value",message:`Invalid --severity value: ${a.severity}. Allowed values: suggestion, needs_changes, blocking.`},S);let r={body_md:a.bodyMd,source:"automation"};if(a.blockId)r.block_id=a.blockId;if(a.severity)r.severity=a.severity;let i={};if(a.idempotencyKey)i["Idempotency-Key"]=a.idempotencyKey;let o=await n.post(`/sessions/${encodeURIComponent(a.session)}/threads`,{body:r,headers:i});if(a.format==="json")console.log(JSON.stringify(o.body,null,2));else{let s=o.body;if(console.log(`Thread created: ${s.thread_id}`),console.log(`Status: ${s.status}`),s.severity)console.log(`Severity: ${s.severity}`);if(s.block_id)console.log(`Block: ${s.block_id}`);console.log(`Request ID: ${s.request_id}`)}process.exit(H)}function C3e(e){let t={session:"",thread:"",bodyMd:"",format:"json"},n=0;while(n<e.length){let a=e[n];if(a==="--session")t.session=e[n+1]||"",n+=2;else if(a.startsWith("--session="))t.session=a.slice(10),n++;else if(a==="--thread")t.thread=e[n+1]||"",n+=2;else if(a.startsWith("--thread="))t.thread=a.slice(9),n++;else if(a==="--body")t.bodyMd=e[n+1]||"",n+=2;else if(a.startsWith("--body="))t.bodyMd=a.slice(7),n++;else if(a==="--idempotency-key")t.idempotencyKey=e[n+1]||"",n+=2;else if(a.startsWith("--idempotency-key="))t.idempotencyKey=a.slice(18),n++;else if(a==="--format")t.format=e[n+1]||"json",n+=2;else if(a.startsWith("--format="))t.format=a.slice(9),n++;else n++}return t}async function jH(e,t,n){let a=C3e(e);if(!a.session)D({code:"missing_required_flag",message:"Missing required flag: --session"},S);if(!a.thread)D({code:"missing_required_flag",message:"Missing required flag: --thread"},S);if(!a.bodyMd)D({code:"missing_required_flag",message:"Missing required flag: --body"},S);let r={body_md:a.bodyMd,source:"automation"},i={};if(a.idempotencyKey)i["Idempotency-Key"]=a.idempotencyKey;let o=encodeURIComponent(a.session),s=encodeURIComponent(a.thread),c=await n.post(`/sessions/${o}/threads/${s}/comments`,{body:r,headers:i});if(a.format==="json")console.log(JSON.stringify(c.body,null,2));else{let A=c.body;console.log(`Comment posted: ${A.comment_id}`),console.log(`Thread: ${A.thread_id}`),console.log(`Request ID: ${A.request_id}`)}process.exit(H)}function _3e(e){let t={session:"",thread:"",action:"resolve",format:"json"},n=0;while(n<e.length){let a=e[n];if(a==="--session")t.session=e[n+1]||"",n+=2;else if(a.startsWith("--session="))t.session=a.slice(10),n++;else if(a==="--thread")t.thread=e[n+1]||"",n+=2;else if(a.startsWith("--thread="))t.thread=a.slice(9),n++;else if(a==="--action")t.action=e[n+1]||"resolve",n+=2;else if(a.startsWith("--action="))t.action=a.slice(9),n++;else if(a==="--disposition")t.disposition=e[n+1]||"",n+=2;else if(a.startsWith("--disposition="))t.disposition=a.slice(14),n++;else if(a==="--body")t.body=e[n+1]||"",n+=2;else if(a.startsWith("--body="))t.body=a.slice(7),n++;else if(a==="--if-match")t.ifMatch=e[n+1]||"",n+=2;else if(a.startsWith("--if-match="))t.ifMatch=a.slice(11),n++;else if(a==="--reopen")t.action="reopen",n++;else if(a==="--format")t.format=e[n+1]||"json",n+=2;else if(a.startsWith("--format="))t.format=a.slice(9),n++;else n++}return t}async function qH(e,t,n){let a=_3e(e);if(!a.session)D({code:"missing_required_flag",message:"Missing required flag: --session"},S);if(!a.thread)D({code:"missing_required_flag",message:"Missing required flag: --thread"},S);let r=encodeURIComponent(a.session),i=encodeURIComponent(a.thread),o=a.action==="reopen"?"reopen":"resolve",s={};if(a.disposition||a.body){let l={};if(a.disposition)l.state=a.disposition;if(a.body)l.rationale_md=a.body;s.disposition=l}let c={};if(a.ifMatch)c["If-Match"]=a.ifMatch;let A=await n.post(`/sessions/${r}/threads/${i}/${o}`,{body:s,headers:c});if(a.format==="json")console.log(JSON.stringify(A.body,null,2));else{let l=A.body,d=a.action==="reopen"?"Reopened":"Resolved";console.log(`${d} thread: ${l.thread_id}`),console.log(`Status: ${l.status}`),console.log(`Version: ${l.version}`),console.log(`Request ID: ${l.request_id}`)}process.exit(H)}function E3e(e){let t={session:"",thread:"",state:"",format:"json"},n=0;while(n<e.length){let a=e[n];if(a==="--session")t.session=e[n+1]||"",n+=2;else if(a.startsWith("--session="))t.session=a.slice(10),n++;else if(a==="--thread")t.thread=e[n+1]||"",n+=2;else if(a.startsWith("--thread="))t.thread=a.slice(9),n++;else if(a==="--state")t.state=e[n+1]||"",n+=2;else if(a.startsWith("--state="))t.state=a.slice(8),n++;else if(a==="--rationale")t.rationaleMd=e[n+1]||"",n+=2;else if(a.startsWith("--rationale="))t.rationaleMd=a.slice(12),n++;else if(a==="--format")t.format=e[n+1]||"json",n+=2;else if(a.startsWith("--format="))t.format=a.slice(9),n++;else n++}return t}async function NH(e,t,n){let a=E3e(e);if(!a.session)D({code:"missing_required_flag",message:"Missing required flag: --session"},S);if(!a.thread)D({code:"missing_required_flag",message:"Missing required flag: --thread"},S);if(!a.state)D({code:"missing_required_flag",message:"Missing required flag: --state"},S);let r={state:a.state};if(a.rationaleMd)r.rationale_md=a.rationaleMd;let i=encodeURIComponent(a.session),o=encodeURIComponent(a.thread),s=await n.post(`/sessions/${i}/threads/${o}/dispositions`,{body:r});if(a.format==="json")console.log(JSON.stringify(s.body,null,2));else{let c=s.body;console.log(`Disposition recorded: ${c.disposition_id}`),console.log(`Thread: ${c.thread_id}`),console.log(`State: ${c.state}`),console.log(`Request ID: ${c.request_id}`)}process.exit(H)}function v3e(e){let t={session:"",thread:"",type:"",format:"json"},n=0;while(n<e.length){let a=e[n];if(a==="--session")t.session=e[n+1]||"",n+=2;else if(a.startsWith("--session="))t.session=a.slice(10),n++;else if(a==="--thread")t.thread=e[n+1]||"",n+=2;else if(a.startsWith("--thread="))t.thread=a.slice(9),n++;else if(a==="--type")t.type=e[n+1]||"",n+=2;else if(a.startsWith("--type="))t.type=a.slice(7),n++;else if(a==="--commit-sha")t.commitSha=e[n+1]||"",n+=2;else if(a.startsWith("--commit-sha="))t.commitSha=a.slice(13),n++;else if(a==="--proposed-change-id")t.proposedChangeId=e[n+1]||"",n+=2;else if(a.startsWith("--proposed-change-id="))t.proposedChangeId=a.slice(21),n++;else if(a==="--pr-url")t.prUrl=e[n+1]||"",n+=2;else if(a.startsWith("--pr-url="))t.prUrl=a.slice(9),n++;else if(a==="--attestation")t.attestation=e[n+1]||"",n+=2;else if(a.startsWith("--attestation="))t.attestation=a.slice(14),n++;else if(a==="--format")t.format=e[n+1]||"json",n+=2;else if(a.startsWith("--format="))t.format=a.slice(9),n++;else n++}return t}async function MH(e,t,n){let a=v3e(e);if(!a.session)D({code:"missing_required_flag",message:"Missing required flag: --session"},S);if(!a.thread)D({code:"missing_required_flag",message:"Missing required flag: --thread"},S);if(!a.type)D({code:"missing_required_flag",message:"Missing required flag: --type"},S);let r={};if(a.commitSha)r.commit_sha=a.commitSha;if(a.proposedChangeId)r.proposed_change_id=a.proposedChangeId;if(a.prUrl)r.pr_url=a.prUrl;if(a.attestation)r.attestation=a.attestation;let i={evidence_type:a.type,evidence_json:r},o=encodeURIComponent(a.session),s=encodeURIComponent(a.thread),c=await n.post(`/sessions/${o}/threads/${s}/evidence`,{body:i});if(a.format==="json")console.log(JSON.stringify(c.body,null,2));else{let A=c.body;console.log(`Evidence attached: ${A.evidence_id}`),console.log(`Thread: ${A.thread_id}`),console.log(`Type: ${A.type}`),console.log(`Request ID: ${A.request_id}`)}process.exit(H)}var GH=["file","doc","pr","custom"],Q3e=new Set(GH);function x3e(e){let t={sourceType:"",kind:"",key:"",headSessionId:"",format:"json"},n=0;while(n<e.length){let a=e[n];if(a==="--source-type")t.sourceType=e[n+1]||"",n+=2;else if(a.startsWith("--source-type="))t.sourceType=a.slice(14),n++;else if(a==="--repo-id")t.repoId=e[n+1]||"",n+=2;else if(a.startsWith("--repo-id="))t.repoId=a.slice(10),n++;else if(a==="--project-id"||a==="--project")t.projectId=e[n+1]||"",n+=2;else if(a.startsWith("--project-id="))t.projectId=a.slice(13),n++;else if(a.startsWith("--project="))t.projectId=a.slice(10),n++;else if(a==="--kind")t.kind=e[n+1]||"",n+=2;else if(a.startsWith("--kind="))t.kind=a.slice(7),n++;else if(a==="--key")t.key=e[n+1]||"",n+=2;else if(a.startsWith("--key="))t.key=a.slice(6),n++;else if(a==="--head-session")t.headSessionId=e[n+1]||"",n+=2;else if(a.startsWith("--head-session="))t.headSessionId=a.slice(15),n++;else if(a==="--format")t.format=e[n+1]||"json",n+=2;else if(a.startsWith("--format="))t.format=a.slice(9),n++;else n++}return t}async function RH(e,t,n){let a=x3e(e);if(!a.sourceType)D({code:"missing_required_flag",message:"Missing required flag: --source-type"},S);if(!a.kind)D({code:"missing_required_flag",message:"Missing required flag: --kind"},S);if(!a.key)D({code:"missing_required_flag",message:"Missing required flag: --key"},S);if(!a.headSessionId)D({code:"missing_required_flag",message:"Missing required flag: --head-session"},S);let r=a.kind.trim().toLowerCase();if(!Q3e.has(r))D({code:"invalid_flag_value",message:`Invalid --kind value: ${a.kind}. Must be one of: ${GH.join(", ")}`},S);let i={source_type:a.sourceType,kind:r,key:a.key,head_session_id:a.headSessionId};if(a.repoId)i.repo_id=a.repoId;if(a.projectId)i.project_id=a.projectId;let o=await n.post("/review-refs",{body:i});if(a.format==="json")console.log(JSON.stringify(o.body,null,2));else console.log(`Review ref created: ${o.body.id}`),console.log(`Head session: ${o.body.head_session_id??"none"}`),console.log(`Request ID: ${o.body.request_id}`);process.exit(H)}function I3e(e){let t={reviewRefId:"",format:"json"},n=0;while(n<e.length){let a=e[n];if(a==="--review-ref")t.reviewRefId=e[n+1]||"",n+=2;else if(a.startsWith("--review-ref="))t.reviewRefId=a.slice(13),n++;else if(a==="--format")t.format=e[n+1]||"json",n+=2;else if(a.startsWith("--format="))t.format=a.slice(9),n++;else n++}return t}async function PH(e,t,n){let a=I3e(e);if(!a.reviewRefId)D({code:"missing_required_flag",message:"Missing required flag: --review-ref"},S);let r=await n.get(`/review-refs/${encodeURIComponent(a.reviewRefId)}/resolve`);if(a.format==="json")console.log(JSON.stringify(r.body,null,2));else console.log(`Review ref: ${r.body.review_ref_id}`),console.log(`Head session: ${r.body.head_session_id}`),console.log(`State: ${r.body.state}`),console.log(`Request ID: ${r.body.request_id}`);process.exit(H)}function D3e(e){let t={reviewRefId:"",headSessionId:"",format:"json"},n=0;while(n<e.length){let a=e[n];if(a==="--review-ref")t.reviewRefId=e[n+1]||"",n+=2;else if(a.startsWith("--review-ref="))t.reviewRefId=a.slice(13),n++;else if(a==="--head-session")t.headSessionId=e[n+1]||"",n+=2;else if(a.startsWith("--head-session="))t.headSessionId=a.slice(15),n++;else if(a==="--expected-head")t.expectedHeadSessionId=e[n+1]||"",n+=2;else if(a.startsWith("--expected-head="))t.expectedHeadSessionId=a.slice(16),n++;else if(a==="--format")t.format=e[n+1]||"json",n+=2;else if(a.startsWith("--format="))t.format=a.slice(9),n++;else n++}return t}async function zH(e,t,n){let a=D3e(e);if(!a.reviewRefId)D({code:"missing_required_flag",message:"Missing required flag: --review-ref"},S);if(!a.headSessionId)D({code:"missing_required_flag",message:"Missing required flag: --head-session"},S);let r=a.expectedHeadSessionId?.trim();if(!r)r=(await n.get(`/review-refs/${encodeURIComponent(a.reviewRefId)}/resolve`)).body.head_session_id;let i={head_session_id:a.headSessionId};if(r)i.expected_head_session_id=r;let o=await n.post(`/review-refs/${encodeURIComponent(a.reviewRefId)}/advance`,{body:i});if(a.format==="json")console.log(JSON.stringify(o.body,null,2));else console.log(`Advanced review ref: ${o.body.review_ref.id}`),console.log(`New head session: ${o.body.review_ref.head_session_id}`),console.log(`Request ID: ${o.body.request_id}`);process.exit(H)}var UH=["approved","rejected","conditional"];function F3e(e){let t={session:"",approverEmails:[],format:"json"},n=0;while(n<e.length){let a=e[n];if(a==="--session")t.session=e[n+1]||"",n+=2;else if(a.startsWith("--session="))t.session=a.slice(10),n++;else if(a==="--approver"){if(e[n+1])t.approverEmails.push(e[n+1]);n+=2}else if(a.startsWith("--approver="))t.approverEmails.push(a.slice(11)),n++;else if(a==="--approvers"){if(e[n+1])t.approverEmails.push(...e[n+1].split(","));n+=2}else if(a.startsWith("--approvers="))t.approverEmails.push(...a.slice(12).split(",")),n++;else if(a==="--message")t.message=e[n+1]||"",n+=2;else if(a.startsWith("--message="))t.message=a.slice(10),n++;else if(a==="--idempotency-key")t.idempotencyKey=e[n+1]||"",n+=2;else if(a.startsWith("--idempotency-key="))t.idempotencyKey=a.slice(18),n++;else if(a==="--format")t.format=e[n+1]||"json",n+=2;else if(a.startsWith("--format="))t.format=a.slice(9),n++;else n++}return t}async function HH(e,t,n){let a=F3e(e);if(!a.session)D({code:"missing_required_flag",message:"Missing required flag: --session"},S);if(a.approverEmails.length===0)D({code:"missing_required_flag",message:"Missing required flag: --approver or --approvers"},S);let r={approver_emails:a.approverEmails};if(a.message)r.message=a.message;let i={};if(a.idempotencyKey)i["Idempotency-Key"]=a.idempotencyKey;let o=await n.post(`/sessions/${encodeURIComponent(a.session)}/request-approval`,{body:r,headers:i});if(a.format==="json")console.log(JSON.stringify(o.body,null,2));else{let s=o.body.approval_requests??[];console.log(`Approval requested (${s.length} approvers):`);for(let c of s)console.log(` ${c.id} ${c.approver_email} ${c.state}`);console.log(`Request ID: ${o.body.request_id}`)}process.exit(H)}function $3e(e){let t={session:"",decision:"",format:"json"},n=0;while(n<e.length){let a=e[n];if(a==="--session")t.session=e[n+1]||"",n+=2;else if(a.startsWith("--session="))t.session=a.slice(10),n++;else if(a==="--decision")t.decision=e[n+1]||"",n+=2;else if(a.startsWith("--decision="))t.decision=a.slice(11),n++;else if(a==="--comment"||a==="--comment-md")t.commentMd=e[n+1]||"",n+=2;else if(a.startsWith("--comment="))t.commentMd=a.slice(10),n++;else if(a.startsWith("--comment-md="))t.commentMd=a.slice(13),n++;else if(a==="--idempotency-key")t.idempotencyKey=e[n+1]||"",n+=2;else if(a.startsWith("--idempotency-key="))t.idempotencyKey=a.slice(18),n++;else if(a==="--format")t.format=e[n+1]||"json",n+=2;else if(a.startsWith("--format="))t.format=a.slice(9),n++;else n++}return t}function S3e(e){return UH.includes(e)}async function TH(e,t,n){let a=$3e(e);if(!a.session)D({code:"missing_required_flag",message:"Missing required flag: --session"},S);if(!a.decision)D({code:"missing_required_flag",message:"Missing required flag: --decision"},S);if(!S3e(a.decision))D({code:"invalid_argument",message:`Invalid decision: ${a.decision}. Must be one of: ${UH.join(", ")}`},S);let r={decision:a.decision};if(a.commentMd!==void 0)r.comment_md=a.commentMd;let i={};if(a.idempotencyKey)i["Idempotency-Key"]=a.idempotencyKey;let o=await n.post(`/sessions/${encodeURIComponent(a.session)}/approval`,{body:r,headers:i});if(a.format==="json")console.log(JSON.stringify(o.body,null,2));else{let s=o.body.approval;if(console.log(`Approval recorded: ${s.approval_id}`),console.log(`Decision: ${s.decision}`),console.log(`Participant: ${s.participant_id}`),s.comment_md)console.log(`Comment: ${s.comment_md}`);console.log(`Decided At: ${s.decided_at}`),console.log(`Request ID: ${o.body.request_id}`)}process.exit(H)}var kK=Fo(NY(),1),BK=Fo(iK(),1);import{readFileSync as yK}from"fs";import{resolve as wK}from"path";var b7e=x.string().regex(/^[a-f0-9]{64}$/,{message:"Must be a 64-character lowercase hex SHA-256 digest"}),Vn=x.string().regex(/^sha256:[a-f0-9]{64}$/,{message:'Must be formatted as "sha256:<64 hex chars>"'}),oK=x.string().datetime(),sK=["export","render_receipt","lineage_diff","attestation","verification_instructions"],cK=x.object({path:x.string().min(1),sha256:Vn,type:x.enum(sK),view:x.string().optional()}),Wx=x.object({render_profile:x.string(),renderer_version:x.string(),sanitizer_version:x.string(),config_hash:Vn}),AK=x.object({enable_export_hash:x.boolean(),enable_export_signature:x.boolean(),sealed_render_of_record:x.boolean(),enable_merkle_roots:x.boolean()}),lK=x.object({alg:x.string(),key_id:x.string(),sig:x.string()}),f7e=x.object({session_id:x.string().min(1),render_artifact_sha256:Vn,render_sha256:Vn,sealed_at:oK,provenance:Wx}),h7e=x.object({bundle_version:x.literal("evidence.v1"),session_id:x.string().min(1),source_content_sha256:Vn,created_at:oK,integrity_settings:AK,renderer_provenance:Wx.optional(),contents:x.array(cK),bundle_sha256:Vn,signature:lK.optional()});var y7e=/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/,dK=x.string().datetime();var w7e=x.enum(["git","upload"]),k7e=x.enum(["approved","rejected","conditional"]),B7e=x.record(x.string(),x.unknown()),uK=x.object({approval_id:x.string().min(1),decision:k7e,decided_by_participant_id:x.string().min(1),decided_by_display:x.string().min(1),decided_at:dK,conditions:x.array(B7e)}),C7e=x.object({schema_version:x.literal("attestation.v1"),session_id:x.string().min(1),source_type:w7e,source_content_sha256:Vn,source_blob_oid:x.string().regex(y7e,"source_blob_oid must be 40 or 64 lowercase hex chars").optional(),timestamp:dK,approvals:x.array(uK).min(1),export_sha256:Vn,blocks_merkle_root:Vn.optional(),threads_merkle_root:Vn.optional()}).superRefine((e,t)=>{if(e.source_type==="git"&&!e.source_blob_oid)t.addIssue({code:x.ZodIssueCode.custom,path:["source_blob_oid"],message:"source_blob_oid is required when source_type=git"});if(e.source_type!=="git"&&e.source_blob_oid)t.addIssue({code:x.ZodIssueCode.custom,path:["source_blob_oid"],message:"source_blob_oid is only allowed when source_type=git"});let n=e.blocks_merkle_root!==void 0,a=e.threads_merkle_root!==void 0;if(n!==a)t.addIssue({code:x.ZodIssueCode.custom,path:["blocks_merkle_root"],message:"blocks_merkle_root and threads_merkle_root must either both be set or both be omitted"})});var Ebt=Uint8Array.from([48,46,2,1,0,48,5,6,3,43,101,112,4,34,4,32]),vbt=Uint8Array.from([48,42,48,5,6,3,43,101,112,3,33,0]);import{createHash as _7e}from"crypto";var E7e=new Set(["integrity","exported_at","request_id","view_requested","view_resolved","partial","incomplete_sections"]),v7e=new Set(["statistics"]),Q7e=new Set(["change_status","change_basis","block_key_derived"]),x7e=new Set(["classification"]);function mK(e){return _7e("sha256").update(e,"utf8").digest("hex")}function Nt(e,t){if(e==null&&t==null)return 0;if(e==null)return 1;if(t==null)return-1;return e.localeCompare(t)}function I7e(e,t){if(e==null&&t==null)return 0;if(e==null)return 1;if(t==null)return-1;return e-t}function D7e(e){return[...e].sort((t,n)=>I7e(t.block_index,n.block_index))}function F7e(e){return[...e].sort((t,n)=>Nt(t.thread_id,n.thread_id))}function $7e(e){return[...e].sort((t,n)=>Nt(t.comment_id,n.comment_id))}function S7e(e){return[...e].sort((t,n)=>{let a=Nt(t.provider,n.provider);if(a!==0)return a;if(a=Nt(t.external_id,n.external_id),a!==0)return a;return Nt(t.url,n.url)})}function L7e(e){return[...e].sort()}function j7e(e){return[...e].sort((t,n)=>{let a=Nt(t.ref_id,n.ref_id);if(a!==0)return a;let r=pK(t),i=pK(n);for(let o=0;o<r.length;o++){let s=Nt(r[o],i[o]);if(s!==0)return s}return 0})}function pK(e){let t=e.target??{},n=t.anchor??{};return[e.purpose??null,t.source_type??null,t.file_path??null,t.doc_key??null,n.type??null,n.block_id??null]}function q7e(e){return[...e].sort()}function N7e(e){return[...e].sort((t,n)=>{let a=Nt(t.emoji,n.emoji);if(a!==0)return a;let r=t.reactor??{},i=n.reactor??{};if(a=Nt(r.participant_id,i.participant_id),a!==0)return a;if(a=Nt(r.email,i.email),a!==0)return a;return Nt(t.created_at,n.created_at)})}function M7e(e){return[...e].sort((t,n)=>Nt(t.request_id,n.request_id))}function G7e(e){return[...e].sort((t,n)=>Nt(t.approval_id,n.approval_id))}function R7e(e){return[...e].sort((t,n)=>Nt(t.proposed_change_id,n.proposed_change_id))}function P7e(e){return[...e].sort((t,n)=>{let a=Nt(t.kind,n.kind);if(a!==0)return a;if(a=Nt(t.require_verification_tier,n.require_verification_tier),a!==0)return a;if(a=Nt(t.description,n.description),a!==0)return a;let r=Array.isArray(t.thread_ids)?[...t.thread_ids].sort().join(","):"",i=Array.isArray(n.thread_ids)?[...n.thread_ids].sort().join(","):"";if(a=r.localeCompare(i),a!==0)return a;let o=Array.isArray(t.check_rule_ids)?[...t.check_rule_ids].sort().join(","):"",s=Array.isArray(n.check_rule_ids)?[...n.check_rule_ids].sort().join(","):"";return o.localeCompare(s)})}function z7e(e){let t={...e};if(Array.isArray(t.mentions))t.mentions=q7e(t.mentions);if(Array.isArray(t.reactions))t.reactions=N7e(t.reactions);return t}function U7e(e){let t={...e};if(Array.isArray(t.comments))t.comments=$7e(t.comments).map((n)=>z7e(n));if(Array.isArray(t.links))t.links=S7e(t.links);if(Array.isArray(t.tags))t.tags=L7e(t.tags);if(Array.isArray(t.references))t.references=j7e(t.references);return t}function H7e(e){let t={...e};if(Array.isArray(t.conditions))t.conditions=P7e(t.conditions).map((n)=>{let a={...n};if(Array.isArray(a.thread_ids))a.thread_ids=[...a.thread_ids].sort();if(Array.isArray(a.check_rule_ids))a.check_rule_ids=[...a.check_rule_ids].sort();return a});return t}function Jx(e,t){let n={};for(let[a,r]of Object.entries(e)){if(E7e.has(a))continue;if(!t.includeNonAuthoritative&&v7e.has(a))continue;n[a]=r}if(Array.isArray(n.blocks)){let a=D7e(n.blocks);if(!t.includeNonAuthoritative)a=a.map((r)=>{let i={};for(let[o,s]of Object.entries(r))if(!Q7e.has(o))i[o]=s;return i});n.blocks=a}if(Array.isArray(n.threads)){let a=F7e(n.threads);a=a.map((r)=>{let i=U7e(r);if(!t.includeNonAuthoritative){let o={};for(let[s,c]of Object.entries(i))if(!x7e.has(s))o[s]=c;i=o}return i}),n.threads=a}if(Array.isArray(n.approval_requests))n.approval_requests=M7e(n.approval_requests);if(Array.isArray(n.approvals))n.approvals=G7e(n.approvals).map((a)=>H7e(a));if(Array.isArray(n.proposed_changes))n.proposed_changes=R7e(n.proposed_changes);if(Array.isArray(n.participants)){let a=n.participants;n.participants=[...a].sort((r,i)=>Nt(r.id,i.id))}if(n.extensions&&typeof n.extensions==="object"&&!Array.isArray(n.extensions)){let a=n.extensions,r={};for(let[i,o]of Object.entries(a))if(o&&typeof o==="object"&&!Array.isArray(o)&&(t.includeNonAuthoritative||o.authoritative===!0))r[i]=o;if(Object.keys(r).length>0)n.extensions=r;else delete n.extensions}return n}function Yb(e){let t=Jx(e,{includeNonAuthoritative:!1});return mK(Ys(t))}function Kb(e){let t=Jx(e,{includeNonAuthoritative:!0});return mK(Ys(t))}import{sign as $bt,verify as T7e,createPublicKey as O7e,createPrivateKey as Sbt}from"crypto";function Z7e(e){let t=Uint8Array.from([48,42,48,5,6,3,43,101,112,3,33,0]),n=new Uint8Array(t.length+e.length);return n.set(t,0),n.set(e,t.length),Buffer.from(n)}function Vx(e,t,n){if(t.alg!=="ed25519")return!1;if(n.publicKey.length!==32)return!1;try{let a=Z7e(n.publicKey),r=O7e({key:a,format:"der",type:"spki"}),i=Uint8Array.from(Buffer.from(t.sig,"base64"));return T7e(null,new TextEncoder().encode(e),r,i)}catch{return!1}}var gK={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://typescape.ai/schemas/export.v1.schema.json",title:"Typescape Export v1",$comment:"Non-enforceable invariants: (1) threads[].block_id must reference blocks[].block_id when anchor.type is block/range; (2) blocks must be sorted by block_index ascending; (3) threads must be sorted by thread_id for hash stability; (4) non-authoritative extensions (authoritative=false) are excluded from integrity.export_sha256; (5) breaking changes require new v2 artifacts and MUST NOT semantically drift v1 files in place.",type:"object",additionalProperties:!1,required:["schema_version","exported_at","view_requested","view_resolved","session","blocks","threads","synthesis"],properties:{schema_version:{const:"v1"},exported_at:{type:"string",format:"date-time"},view_requested:{type:["string","null"]},view_resolved:{type:"string",minLength:1},integrity:{type:"object",additionalProperties:!1,properties:{canonicalization:{type:"string"},export_sha256:{$ref:"#/$defs/sha256"},export_full_sha256:{$ref:"#/$defs/sha256"},signature:{type:"object",additionalProperties:!1,required:["alg","key_id","sig"],properties:{alg:{type:"string",minLength:1},key_id:{type:"string",minLength:1},sig:{type:"string",minLength:1}}},blocks_merkle_root:{$ref:"#/$defs/sha256"},threads_merkle_root:{$ref:"#/$defs/sha256"}}},rendering:{type:"object",additionalProperties:!1,properties:{include_render_html:{type:"boolean"},html_csp:{type:"string"}}},session:{type:"object",additionalProperties:!1,required:["id","source_type","file_path","source_content_sha256","state","block_id_scheme","block_key_scheme","created_at"],properties:{id:{type:"string",minLength:1},source_type:{type:"string",enum:["git","upload"]},document_type:{type:["string","null"],enum:["markdown","image_set","pdf",null]},block_count:{type:["integer","null"],minimum:0},repo_id:{type:["string","null"],minLength:1},git_sha:{anyOf:[{$ref:"#/$defs/gitSha"},{type:"null"}]},project_id:{type:["string","null"],minLength:1},upload_batch_id:{type:["string","null"],minLength:1},file_path:{$ref:"#/$defs/filePath"},document_locator:{type:["object","null"],additionalProperties:!0},doc_key:{type:["string","null"],minLength:1},corpus_snapshot_id:{type:["string","null"],minLength:1},source_context:{type:["object","null"],additionalProperties:!0},extra:{},root_session_id:{type:["string","null"],minLength:1},supersedes_session_id:{type:["string","null"],minLength:1},source_blob_oid:{type:["string","null"],minLength:1},source_content_sha256:{$ref:"#/$defs/sha256"},source_size_bytes:{type:"integer",minimum:0},title:{type:["string","null"]},state:{type:"string",enum:["draft","active","closed","archived","superseded"]},block_id_scheme:{type:"string",minLength:1},block_key_scheme:{type:"string",minLength:1},created_at:{type:"string",format:"date-time"},billable_at:{type:["string","null"],format:"date-time"}},allOf:[{if:{properties:{source_type:{const:"git"}},required:["source_type"]},then:{required:["repo_id","git_sha"],properties:{repo_id:{type:"string",minLength:1},git_sha:{$ref:"#/$defs/gitSha"}}}},{if:{properties:{source_type:{const:"upload"}},required:["source_type"]},then:{required:["project_id","upload_batch_id"],properties:{project_id:{type:"string",minLength:1},upload_batch_id:{type:"string",minLength:1}}}}]},blocks:{type:"array",items:{type:"object",additionalProperties:!1,required:["block_id","block_index","block_type","start_line","end_line"],properties:{block_id:{type:"string",minLength:1},block_key:{type:["string","null"],minLength:1},block_key_source:{type:["string","null"],enum:["marker","sidecar",null]},block_key_derived:{type:["object","null"],additionalProperties:!0},block_index:{type:"integer",minimum:0},block_type:{type:"string",enum:["heading","paragraph","code_block","table","thematic_break","html","blockquote","list_item","image"]},start_line:{type:"integer",minimum:1},end_line:{type:"integer",minimum:1},plaintext:{type:"string"},change_status:{type:["string","null"],enum:["unchanged","modified","added","removed","moved",null]},change_basis:{type:["string","null"],enum:["block_key","fingerprint_ui_only","none",null]}}}},participants:{type:"array",items:{type:"object",additionalProperties:!1,required:["id","email","roles","created_at"],properties:{id:{type:"string",minLength:1},email:{type:"string",minLength:1},roles:{type:"array",items:{type:"string",minLength:1}},delegated_from_participant_id:{type:["string","null"],minLength:1},created_at:{type:"string",format:"date-time"}}}},threads:{type:"array",items:{type:"object",additionalProperties:!1,required:["thread_id","anchor","status","thread_type","source","severity","created_at","comments"],properties:{thread_id:{type:"string",minLength:1},block_id:{type:["string","null"],minLength:1},spatial_anchor:{type:["object","null"],additionalProperties:!1,required:["ref_id","spatial_x","spatial_y","spatial_w","spatial_h","version","ref_width","ref_height"],properties:{ref_id:{type:"string",minLength:1},spatial_x:{type:"number"},spatial_y:{type:"number"},spatial_w:{type:["number","null"]},spatial_h:{type:["number","null"]},version:{type:"integer",minimum:1},ref_width:{type:["number","null"]},ref_height:{type:["number","null"]}}},anchor:{type:"object",additionalProperties:!1,required:["type"],properties:{type:{type:"string",enum:["block","range","session"]},start_offset:{type:"integer",minimum:0},end_offset:{type:"integer",minimum:0}}},references:{type:"array",items:{$ref:"#/$defs/anchorRef"}},duplicate_of_thread_id:{type:"string",minLength:1},status:{type:"string",enum:["open","resolved","draft"]},thread_type:{type:"string",enum:["human","system_finding","intake"]},source:{type:"string",enum:["human","system","automation"]},finding_id:{type:["string","null"],minLength:1},rule_id:{type:["string","null"],minLength:1},rule_fingerprint:{type:["string","null"],minLength:1},check_run_id:{type:["string","null"],minLength:1},severity:{type:["string","null"],enum:["suggestion","needs_changes","blocking",null]},tags:{type:"array",items:{type:"string",minLength:1}},classification:{type:"object",required:["non_authoritative"],properties:{non_authoritative:{const:!0}},additionalProperties:!0},assignee:{type:["object","null"],additionalProperties:!1,required:["email","assigned_at"],properties:{email:{type:"string",minLength:1},assigned_at:{type:"string",format:"date-time"}}},block_snapshot:{type:["string","null"]},created_at:{type:"string",format:"date-time"},opener_comment_id:{type:["string","null"],minLength:1},opener_preview:{type:["string","null"]},opener_author_display:{type:["string","null"]},opener_author_email:{type:["string","null"],format:"email"},comments:{type:"array",items:{$ref:"#/$defs/comment"}},links:{type:"array",items:{type:"object",additionalProperties:!1,required:["link_type","provider","url"],properties:{link_type:{type:"string",minLength:1},provider:{type:"string",minLength:1},url:{type:"string",format:"uri"},external_id:{type:"string",minLength:1}}}}},allOf:[{if:{properties:{anchor:{type:"object",properties:{type:{const:"session"}},required:["type"]}},required:["anchor"]},then:{properties:{block_id:{type:"null"}}}},{if:{properties:{anchor:{type:"object",properties:{type:{const:"block"}},required:["type"]}},required:["anchor"]},then:{required:["block_id"],properties:{block_id:{type:"string",minLength:1}}}},{if:{properties:{anchor:{type:"object",properties:{type:{const:"range"}},required:["type"]}},required:["anchor"]},then:{required:["block_id"],properties:{block_id:{type:"string",minLength:1},anchor:{type:"object",additionalProperties:!1,required:["type","start_offset","end_offset"],properties:{type:{const:"range"},start_offset:{type:"integer",minimum:0},end_offset:{type:"integer",minimum:0}}}}}}]}},synthesis:{type:"object",additionalProperties:!1,required:["blocking","needs_changes","suggestions","resolved","summary"],properties:{blocking:{type:"array",items:{$ref:"#/$defs/synthesisItem"}},needs_changes:{type:"array",items:{$ref:"#/$defs/synthesisItem"}},suggestions:{type:"array",items:{$ref:"#/$defs/synthesisItem"}},resolved:{type:"array",items:{$ref:"#/$defs/synthesisItem"}},summary:{$ref:"#/$defs/synthesisSummary"}}},reconciliation_prompt:{type:"string"},round_history:{type:"array",items:{type:"object",additionalProperties:!1,required:["round","session_id","state"],properties:{round:{type:"integer",minimum:1},session_id:{type:"string",minLength:1},created_at:{type:["string","null"],format:"date-time"},title:{type:["string","null"]},state:{type:"string",minLength:1},changes_summary:{type:["string","null"]}}}},issues:{type:"array",items:{type:"object",additionalProperties:!1,required:["issue_id","title","status","source","anchors","created_at"],properties:{issue_id:{type:"string",minLength:1},title:{type:"string",minLength:1},status:{type:"string",enum:["open","in_progress","resolved","archived"]},source:{type:"string",minLength:1},tags:{type:"array",items:{type:"string",minLength:1}},anchors:{type:"array",minItems:1,items:{$ref:"#/$defs/anchorRef"}},created_at:{type:"string",format:"date-time"},updated_at:{type:"string",format:"date-time"}}}},approval_requests:{type:"array",items:{type:"object",additionalProperties:!1,required:["request_id","requested_from","role","status"],properties:{request_id:{type:"string",minLength:1},requested_from:{type:"string",minLength:1},role:{type:"string",minLength:1},status:{type:"string",minLength:1},deadline_at:{type:"string",format:"date-time"},responded_at:{type:"string",format:"date-time"}}}},approvals:{type:"array",items:{type:"object",additionalProperties:!1,required:["approval_id","participant_id","decision","decided_by","decided_at"],properties:{approval_id:{type:"string",minLength:1},participant_id:{type:"string",minLength:1},decision:{type:"string",enum:["approve","reject","conditional"]},decided_by:{type:"string",minLength:1},decided_at:{type:"string",format:"date-time"},comment_md:{type:"string"},conditions:{type:"array",items:{type:"object",additionalProperties:!1,required:["condition_id","kind","description"],properties:{condition_id:{type:"string",minLength:1},kind:{type:"string",minLength:1},description:{type:"string",minLength:1},thread_ids:{type:"array",items:{type:"string",minLength:1}},require_verification_tier:{type:"string",minLength:1}}}}}}},acknowledgements:{type:"array",items:{type:"object",additionalProperties:!1,required:["block_id","participant_id","ack_type","created_at"],properties:{block_id:{type:"string",minLength:1},participant_id:{type:"string",minLength:1},participant_display:{type:"string",minLength:1},ack_type:{type:"string",enum:["read","confirmed"]},created_at:{type:"string",format:"date-time"}}}},policy_status:{type:"object",additionalProperties:!1,required:["verdict","reasons"],properties:{verdict:{type:"string",enum:["pass","fail","warn"]},reasons:{type:"array",items:{type:"object",additionalProperties:!1,required:["code"],properties:{code:{type:"string",minLength:1},details:{type:"object",additionalProperties:!0},thread_ids:{type:"array",items:{type:"string",minLength:1}},approval_ids:{type:"array",items:{type:"string",minLength:1}}}}}}},proposed_changes:{type:"array",items:{type:"object",additionalProperties:!1,required:["proposed_change_id","source_thread_ids","target","expected_source_content_sha256","patch_sha256","state","created_at"],properties:{proposed_change_id:{type:"string",minLength:1},source_thread_ids:{type:"array",minItems:1,items:{type:"string",minLength:1}},target:{$ref:"#/$defs/contentRef"},expected_source_content_sha256:{$ref:"#/$defs/sha256"},patch_sha256:{$ref:"#/$defs/sha256"},state:{type:"string",enum:["proposed","applied","failed","superseded"]},applied_commit_sha:{$ref:"#/$defs/gitSha"},applied_pr_url:{type:"string",format:"uri"},applied_upload_batch_id:{type:"string",minLength:1},applied_file_content_sha256:{$ref:"#/$defs/sha256"},created_at:{type:"string",format:"date-time"}}}},attestation:{type:"object",additionalProperties:!1,required:["attestation_id","schema_version","payload_sha256","signature"],properties:{attestation_id:{type:"string",minLength:1},schema_version:{const:"attestation.v1"},payload_sha256:{$ref:"#/$defs/sha256"},signature:{type:"object",additionalProperties:!1,required:["alg","key_id","sig"],properties:{alg:{type:"string",minLength:1},key_id:{type:"string",minLength:1},sig:{type:"string",minLength:1}}}}},extensions:{type:"object",propertyNames:{type:"string",pattern:"^[a-z][a-z0-9_.-]*$"},additionalProperties:{type:"object",required:["schema_version","authoritative"],properties:{schema_version:{type:"string",pattern:"^[a-z][a-z0-9_.-]*\\.v[0-9]+$"},authoritative:{type:"boolean"}},additionalProperties:!0}},statistics:{type:"object",additionalProperties:!1,properties:{total_threads:{type:"integer",minimum:0},open_threads:{type:"integer",minimum:0},resolved_threads:{type:"integer",minimum:0},total_comments:{type:"integer",minimum:0},unique_commenters:{type:"integer",minimum:0},suggestions_total:{type:"integer",minimum:0},suggestions_accepted:{type:"integer",minimum:0}}},request_id:{type:"string",minLength:1}},$defs:{gitSha:{type:"string",pattern:"^(?:[0-9a-f]{40}|[0-9a-f]{64})$"},sha256:{type:"string",pattern:"^[0-9a-f]{64}$"},filePath:{type:"string",minLength:1,allOf:[{pattern:"^(?!/).+"},{not:{pattern:"(^|/)\\.\\.(?:/|$)"}},{pattern:"^[^\\u0000]+$"}]},anchorRef:{type:"object",additionalProperties:!1,required:["schema_version","source_type","file_path","anchor"],properties:{schema_version:{const:"anchor_ref.v1"},source_type:{type:"string",enum:["git","upload"]},repo_id:{type:"string",minLength:1},git_sha:{$ref:"#/$defs/gitSha"},project_id:{type:"string",minLength:1},upload_batch_id:{type:"string",minLength:1},file_path:{$ref:"#/$defs/filePath"},doc_key:{type:"string",minLength:1},anchor:{type:"object",additionalProperties:!1,required:["type"],properties:{type:{type:"string",enum:["block","range","session"]},block_id:{type:"string",minLength:1},range:{type:"object",additionalProperties:!1,required:["start_offset","end_offset"],properties:{start_offset:{type:"integer",minimum:0},end_offset:{type:"integer",minimum:0}}}},allOf:[{if:{properties:{type:{const:"block"}},required:["type"]},then:{required:["block_id"],properties:{block_id:{type:"string",minLength:1}}}},{if:{properties:{type:{const:"range"}},required:["type"]},then:{required:["block_id","range"],properties:{block_id:{type:"string",minLength:1},range:{type:"object",additionalProperties:!1,required:["start_offset","end_offset"],properties:{start_offset:{type:"integer",minimum:0},end_offset:{type:"integer",minimum:0}}}}}},{if:{properties:{type:{const:"session"}},required:["type"]},then:{not:{anyOf:[{required:["block_id"]},{required:["range"]}]}}}]},non_authoritative:{type:"boolean"}},allOf:[{if:{properties:{source_type:{const:"git"}},required:["source_type"]},then:{required:["repo_id","git_sha"],properties:{repo_id:{type:"string",minLength:1},git_sha:{$ref:"#/$defs/gitSha"}}}},{if:{properties:{source_type:{const:"upload"}},required:["source_type"]},then:{required:["project_id","upload_batch_id"],properties:{project_id:{type:"string",minLength:1},upload_batch_id:{type:"string",minLength:1}}}}]},contentRef:{type:"object",additionalProperties:!1,required:["source_type","file_path"],properties:{source_type:{type:"string",enum:["git","upload"]},repo_id:{type:"string",minLength:1},git_sha:{$ref:"#/$defs/gitSha"},project_id:{type:"string",minLength:1},upload_batch_id:{type:"string",minLength:1},file_path:{$ref:"#/$defs/filePath"}},allOf:[{if:{properties:{source_type:{const:"git"}},required:["source_type"]},then:{required:["repo_id","git_sha"],properties:{repo_id:{type:"string",minLength:1},git_sha:{$ref:"#/$defs/gitSha"}}}},{if:{properties:{source_type:{const:"upload"}},required:["source_type"]},then:{required:["project_id","upload_batch_id"],properties:{project_id:{type:"string",minLength:1},upload_batch_id:{type:"string",minLength:1}}}}]},synthesisItem:{type:"object",additionalProperties:!1,required:["thread_id","block_id","first_comment","status"],properties:{thread_id:{type:"string",minLength:1},block_id:{type:["string","null"],minLength:1},first_comment:{type:"string"},status:{type:"string",enum:["open","resolved","wont_fix"]}}},synthesisSummary:{type:"object",additionalProperties:!1,required:["total_threads","open_blocking","open_needs_changes","open_suggestions","resolved"],properties:{total_threads:{type:"integer",minimum:0},open_blocking:{type:"integer",minimum:0},open_needs_changes:{type:"integer",minimum:0},open_suggestions:{type:"integer",minimum:0},resolved:{type:"integer",minimum:0}}},reaction:{type:"object",additionalProperties:!1,required:["emoji","reactor_participant_id","reactor_email","created_at"],properties:{emoji:{type:"string",minLength:1},reactor_participant_id:{type:["string","null"],minLength:1},reactor_email:{type:["string","null"],format:"email"},created_at:{type:"string",format:"date-time"}}},commentAttachmentAsset:{type:"object",additionalProperties:!1,required:["mime_type","width","height","blurhash"],properties:{mime_type:{type:"string",minLength:1},width:{type:["number","null"]},height:{type:["number","null"]},blurhash:{type:["string","null"]}}},commentAttachment:{type:"object",additionalProperties:!1,required:["asset_id","sort_order","placement","alt_text","caption","anchor_block_id","anchor_position","spatial_x","spatial_y","asset"],properties:{asset_id:{type:"string",minLength:1},sort_order:{type:"integer",minimum:0},placement:{type:"string",minLength:1},alt_text:{type:["string","null"]},caption:{type:["string","null"]},anchor_block_id:{type:["string","null"],minLength:1},anchor_position:{type:["string","null"]},spatial_x:{type:["number","null"]},spatial_y:{type:["number","null"]},asset:{$ref:"#/$defs/commentAttachmentAsset"}}},comment:{type:"object",additionalProperties:!1,required:["comment_id","author","created_at","body_md"],properties:{comment_id:{type:"string",minLength:1},author:{type:"object",additionalProperties:!1,properties:{display:{type:"string"},email:{type:["string","null"],format:"email"},source:{type:"string",minLength:1},verification_level:{type:["string","null"]}}},author_source:{type:"string",minLength:1},created_at:{type:"string",format:"date-time"},edited_at:{type:["string","null"],format:"date-time"},body_md:{type:"string",minLength:1},redacted:{type:"boolean"},redacted_at:{type:["string","null"],format:"date-time"},redaction_reason_code:{type:["string","null"],minLength:1},mentions:{type:"array",items:{type:"string",minLength:1}},reactions:{type:"array",items:{anyOf:[{$ref:"#/$defs/reaction"},{type:"string",minLength:1}]}},attachments:{type:"array",items:{$ref:"#/$defs/commentAttachment"}},suggestion:{type:["object","null"],additionalProperties:!0},suggestion_state:{type:["string","null"],minLength:1},edit_history:{type:"array",items:{type:"object",additionalProperties:!1,required:["edited_at","editor_source","body_md"],properties:{edited_at:{type:"string",format:"date-time"},editor_source:{type:"string",minLength:1},body_md:{type:"string",minLength:1}}}}}}}};var Bc=0,bK=1,K7e=2,W7e=3,fK=4,Xx=5;function J7e(e){let t={file:"",strict:!1,format:"text"},n=0;while(n<e.length){let a=e[n];if(a==="--public-key")t.publicKey=e[n+1],n+=2;else if(a.startsWith("--public-key="))t.publicKey=a.slice(13),n++;else if(a==="--keys-url")t.keysUrl=e[n+1],n+=2;else if(a.startsWith("--keys-url="))t.keysUrl=a.slice(11),n++;else if(a==="--strict")t.strict=!0,n++;else if(a==="--format")t.format=e[n+1]||"text",n+=2;else if(a.startsWith("--format="))t.format=a.slice(9),n++;else if(a==="--json")t.format="json",n++;else if(!a.startsWith("-")&&!t.file)t.file=a,n++;else n++}return t}function V7e(e,t){let n=new kK.default({allErrors:!0,strict:!1});BK.default(n);let a=n.compile(t);if(a(e))return{check:"schema",status:"pass",message:"Export matches export.v1 schema"};let i=(a.errors??[]).map((o)=>({path:o.instancePath||"/",keyword:o.keyword,message:o.message,params:o.params}));return{check:"schema",status:"fail",message:`Schema validation failed: ${i.length} error(s)`,details:i}}function X7e(e){let t=[],n=e.blocks??[],a=e.threads??[],r=e.session??{},i=new Set(n.map((o)=>o.block_id));for(let o=1;o<n.length;o++){let s=n[o-1].block_index,c=n[o].block_index;if(c<s)t.push(`blocks[${o}].block_index (${c}) < blocks[${o-1}].block_index (${s}): not ascending`)}for(let o=0;o<a.length;o++){let s=a[o],c=s.anchor??{},A=c.type,l=s.block_id??c.block_id;if(A==="block"||A==="range"){if(!l)t.push(`threads[${o}] (${s.thread_id}): anchor.type="${A}" but block_id is null/missing`);else if(!i.has(l))t.push(`threads[${o}] (${s.thread_id}): block_id="${l}" not found in blocks[]`)}if(A==="session"&&l)t.push(`threads[${o}] (${s.thread_id}): anchor.type="session" but block_id is non-null`)}if(!r.source_content_sha256)t.push("session.source_content_sha256 is missing or null");if(t.length===0)return{check:"anchors",status:"pass",message:"All anchor invariants satisfied"};return{check:"anchors",status:"fail",message:`${t.length} anchor invariant violation(s)`,details:t}}function ePe(e){let t={...e};if(delete t.integrity,delete t.exported_at,delete t.request_id,delete t.view_requested,delete t.view_resolved,delete t.partial,delete t.incomplete_sections,delete t.statistics,delete t.synthesis,delete t.reconciliation_prompt,Array.isArray(e.blocks))t.blocks=e.blocks.map((n)=>{if(!n||typeof n!=="object"||Array.isArray(n))return n;let a={...n};return delete a.change_status,delete a.change_basis,delete a.block_key_derived,a});if(Array.isArray(e.threads))t.threads=e.threads.map((n)=>{if(!n||typeof n!=="object"||Array.isArray(n))return n;let a={...n};return delete a.classification,a});return t}function tPe(e){let t=e.integrity;if(!t)return{check:"hash",status:"skip",message:"No integrity block present; hash verification skipped"};let{export_sha256:n,export_full_sha256:a}=t;if(!n&&!a)return{check:"hash",status:"skip",message:"No hashes in integrity block; hash verification skipped"};let r=[],i=ePe(e);if(n){let o=Yb(e);if(o!==n){let s=Yb(i);if(s!==n)r.push(`export_sha256 mismatch: expected ${n}, computed_legacy ${o}, computed_server ${s}`)}}if(a){let o=Kb(e);if(o!==a){let s=Kb(i);if(s!==a)r.push(`export_full_sha256 mismatch: expected ${a}, computed_legacy ${o}, computed_server ${s}`)}}if(r.length===0)return{check:"hash",status:"pass",message:"All hashes verified successfully"};return{check:"hash",status:"fail",message:"Hash verification failed",details:r}}function nPe(e){try{let t=yK(wK(e));if(t.length===32)return{publicKeyBytes:new Uint8Array(t)};if(t.length===44||t.length===45){let n=Buffer.from(t.toString("utf8").trim(),"base64");if(n.length!==32)return{error:`Public key file has invalid size after base64 decode: ${n.length} bytes (expected 32)`};return{publicKeyBytes:new Uint8Array(n)}}return{error:`Public key file has invalid size: ${t.length} bytes (expected 32 raw or 44 base64)`}}catch(t){return{error:`Failed to read public key file: ${t instanceof Error?t.message:String(t)}`}}}async function aPe(e,t){let n;try{n=await fetch(e,{method:"GET",headers:{Accept:"application/json"}})}catch(d){return{error:`Failed to fetch keys URL: ${d instanceof Error?d.message:String(d)}`}}if(!n.ok)return{error:`Failed to fetch keys URL: HTTP ${n.status}`};let a;try{a=await n.json()}catch(d){return{error:`Failed to parse keys URL JSON: ${d instanceof Error?d.message:String(d)}`}}let r=a;if(!Array.isArray(r.keys))return{error:"Keys URL payload is invalid: expected { keys: [] }"};let o=r.keys.find((d)=>d.key_id===t);if(!o)return{error:`key_id "${t}" not found at ${e}`};if((typeof o.algorithm==="string"?o.algorithm.toLowerCase():"unknown")!=="ed25519")return{error:`Unsupported key algorithm "${String(o.algorithm)}" for key_id "${t}"`};let c=typeof o.public_key==="string"?o.public_key:typeof o.public_key_base64==="string"?o.public_key_base64:null;if(!c)return{error:`key_id "${t}" is missing public key material`};let A;try{A=Buffer.from(c.trim(),"base64")}catch{return{error:`key_id "${t}" has invalid base64 public key`}}if(A.length!==32)return{error:`key_id "${t}" public key has invalid length: ${A.length} bytes (expected 32)`};let l=typeof o.deprecated_at==="string"&&o.deprecated_at.trim().length>0?o.deprecated_at:null;return{publicKeyBytes:new Uint8Array(A),warning:l?`Key "${t}" is deprecated since ${l}`:void 0}}async function rPe(e,t){let n=e.integrity;if(!n)return{check:"signature",status:"skip",message:"No integrity block present; signature verification skipped"};let a=n.signature;if(!a)return{check:"signature",status:"skip",message:"No signature in integrity block; signature verification skipped"};let r=n.export_sha256;if(!r)return{check:"signature",status:"fail",message:"Signature present but integrity.export_sha256 is missing; cannot verify"};let i,o;if(t.publicKey){let c=nPe(t.publicKey);if(c.error)return{check:"signature",status:"fail",message:c.error};i=c.publicKeyBytes}else if(t.keysUrl){let c=await aPe(t.keysUrl,a.key_id);if(c.error)return{check:"signature",status:"fail",message:c.error};i=c.publicKeyBytes,o=c.warning}else return{check:"signature",status:"skip",message:"Signature present but no --public-key or --keys-url provided; signature verification skipped"};if(!i)return{check:"signature",status:"fail",message:"Public key resolution failed"};let s=Vx(r,{alg:a.alg,key_id:a.key_id,sig:a.sig},{publicKey:i});if(s&&o)return{check:"signature",status:"warn",message:`Signature verified (key_id: ${a.key_id})`,details:[o]};if(s)return{check:"signature",status:"pass",message:`Signature verified (key_id: ${a.key_id})`};return{check:"signature",status:"fail",message:`Signature verification failed for key_id: ${a.key_id}`}}function hK(e){let t=[];t.push(`Verifying: ${e.file}`),t.push("");for(let n of e.checks){let a=n.status==="pass"?"PASS":n.status==="fail"?"FAIL":n.status==="warn"?"WARN":"SKIP";if(t.push(` [${a}] ${n.check}: ${n.message}`),n.details&&n.status!=="pass"){let r=Array.isArray(n.details)?n.details:[n.details];for(let i of r){let o=typeof i==="string"?i:JSON.stringify(i);t.push(` ${o}`)}}}return t.push(""),t.push(e.overall==="pass"?"Overall: PASS \u2014 all checks passed":`Overall: FAIL \u2014 exit code ${e.exit_code}`),t.join(`
699
699
  `)}async function CK(e){let t=J7e(e);if(!t.file)console.error(JSON.stringify({error:{code:"missing_file",message:"Usage: typescape verify export <file.json> [options]"}})),process.exit(Xx);let n;try{let d=yK(wK(t.file),"utf8");n=JSON.parse(d)}catch(d){let u={file:t.file,checks:[{check:"read",status:"fail",message:`Failed to read/parse file: ${d instanceof Error?d.message:String(d)}`}],overall:"fail",exit_code:Xx};if(t.format==="json")console.log(JSON.stringify(u,null,2));else console.log(hK(u));process.exit(Xx)}let a=gK,r=[],i=Bc,o=V7e(n,a);if(r.push(o),o.status==="fail")i=bK;let s=X7e(n);if(r.push(s),s.status==="fail"&&i===Bc)i=K7e;let c=tPe(n);if(r.push(c),c.status==="fail"&&i===Bc)i=W7e;let A=await rPe(n,t);if(r.push(A),A.status==="fail"&&i===Bc)i=fK;if(t.strict){for(let d of r)if(d.status==="warn"&&i===Bc)i=d.check==="signature"?fK:bK}let l={file:t.file,checks:r,overall:i===Bc?"pass":"fail",exit_code:i};if(t.format==="json")console.log(JSON.stringify(l,null,2));else console.log(hK(l));process.exit(i)}var _K=["wholesale","targeted","incremental"],EK=["anthropic","openai","custom"];function iPe(e){let t={sessionId:"",dryRun:!1,diff:!0,noCommit:!1,noSupersede:!1,yes:!1,quiet:!1,format:"json"},n=0;while(n<e.length){let a=e[n];if(a==="--profile")t.profile=e[n+1]||"",n+=2;else if(a.startsWith("--profile="))t.profile=a.slice(10),n++;else if(a==="--provider")t.provider=e[n+1],n+=2;else if(a.startsWith("--provider="))t.provider=a.slice(11),n++;else if(a==="--model")t.model=e[n+1]||"",n+=2;else if(a.startsWith("--model="))t.model=a.slice(8),n++;else if(a==="--temperature"){let r=e[n+1],i=Number(r);if(!Number.isFinite(i)||i<0||i>2)D({code:"validation_error",message:"Temperature must be between 0.0 and 2.0"},S);t.temperature=i,n+=2}else if(a.startsWith("--temperature=")){let r=a.slice(14),i=Number(r);if(!Number.isFinite(i)||i<0||i>2)D({code:"validation_error",message:"Temperature must be between 0.0 and 2.0"},S);t.temperature=i,n++}else if(a==="--strategy")t.strategy=e[n+1],n+=2;else if(a.startsWith("--strategy="))t.strategy=a.slice(11),n++;else if(a==="--dry-run")t.dryRun=!0,n++;else if(a==="--no-diff")t.diff=!1,n++;else if(a==="--diff")t.diff=!0,n++;else if(a==="--no-commit")t.noCommit=!0,n++;else if(a==="--no-supersede")t.noSupersede=!0,n++;else if(a==="--out")t.out=e[n+1]||"",n+=2;else if(a.startsWith("--out="))t.out=a.slice(6),n++;else if(a==="--threads"){let r=e[n+1]||"";t.threadIds=r.split(",").map((i)=>i.trim()).filter((i)=>i.length>0),n+=2}else if(a.startsWith("--threads=")){let r=a.slice(10);t.threadIds=r.split(",").map((i)=>i.trim()).filter((i)=>i.length>0),n++}else if(a==="--yes"||a==="-y")t.yes=!0,n++;else if(a==="--quiet"||a==="-q")t.quiet=!0,n++;else if(a==="--format")t.format=e[n+1]||"json",n+=2;else if(a.startsWith("--format="))t.format=a.slice(9),n++;else if(a.startsWith("--"))D({code:"validation_error",message:`Unknown option: ${a}`},S);else if(!t.sessionId)t.sessionId=a,n++;else D({code:"validation_error",message:`Unexpected argument: ${a}`},S)}return t}async function oPe(e,t,n){if(!e.sessionId)D({code:"missing_session_id",message:`Missing required argument: session_id
700
700
 
701
701
  Usage: typescape revise <session_id> [options]`},S);if(e.provider&&!EK.includes(e.provider))D({code:"validation_error",message:`Invalid provider: ${e.provider}. Must be one of: ${EK.join(", ")}`},S);if(e.strategy&&!_K.includes(e.strategy))D({code:"validation_error",message:`Invalid strategy: ${e.strategy}. Must be one of: ${_K.join(", ")}`},S);D({code:"not_implemented",message:"The revise execution flow is not yet implemented (bd-3cg5r.81.2)."},S)}async function vK(e,t,n){let a=iPe(e);await oPe(a,t,n)}function sPe(e){let t={format:"json"},n=0;while(n<e.length){let a=e[n];if(a==="--include-archived")t.includeArchived=!0,n++;else if(a==="--limit")t.limit=Number.parseInt(e[n+1]||"50",10),n+=2;else if(a.startsWith("--limit="))t.limit=Number.parseInt(a.slice(8),10),n++;else if(a==="--cursor")t.cursor=e[n+1]||"",n+=2;else if(a.startsWith("--cursor="))t.cursor=a.slice(9),n++;else if(a==="--format")t.format=e[n+1]||"json",n+=2;else if(a.startsWith("--format="))t.format=a.slice(9),n++;else n++}return t}async function QK(e,t,n){let a=sPe(e),r={};if(a.includeArchived)r.include_archived="true";if(a.limit!==void 0)r.limit=String(a.limit);if(a.cursor)r.cursor=a.cursor;let i=await n.get("/repos",{query:r});if(a.format==="json")console.log(JSON.stringify(i.body,null,2));else{let o=i.body.items??[];console.log(`Repositories (${o.length}):`);for(let s of o){let c=s.origin_url??s.local_path??"\u2014",A=s.archived_at?" [archived]":"";console.log(` ${s.id} ${s.display_name} ${c}${A}`)}if(i.body.next_cursor)console.log(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescape-ai/cli",
3
- "version": "1.9.4",
3
+ "version": "1.9.5",
4
4
  "description": "Typescape CLI - Create review sessions, export feedback, and integrate with AI workflows",
5
5
  "type": "module",
6
6
  "bin": {