@north-light/cli 0.3.633 → 0.3.634

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.
@@ -1,2 +1,2 @@
1
- var U=Object.defineProperty;var a=(n,s)=>U(n,"name",{value:s,configurable:!0});import v from"string-width";import{isResponseBearingSlot as A}from"../../../core/human/page-schema.js";import{answerCommentAnchorLabel as X,describePageAnswer as Z}from"../../../core/human/answer.js";import{renderMarkdownBlockAwareLines as nn}from"../../../core/termrender/termrender.js";import{rewriteMarkdownDocLinks as en}from"../../attach/render/markdown-source.js";import{commentAnchors as tn,describeSlot as j,pageComplete as sn,slotActions as on,slotAnswered as R,tableMarkdown as rn,terminalAnswerable as C}from"./slots.js";import{RESET as r,BOLD as w,DIM as u,GREEN as B,YELLOW as I,CYAN as E,REVERSE as T,sanitize as x,singleLine as b,truncate as H,hline as O,wrap as M,centerHorizontal as D,clipLine as P,panLine as cn,visibleWidth as N}from"./ansi.js";const ln=8,L=a((n,s,t)=>nn(en(n),s,t),"mdLines");function z(n){return Z(n.manifest,Object.fromEntries(n.responses),{completedAt:""})}a(z,"pageAnswer");function fn(n,s){return s.id===void 0?void 0:n.slots.find(t=>t.id===s.id)}a(fn,"answerSlot");function F(n){if(n===void 0||n.state==="unanswered")return"unanswered";if(n.raw!==void 0)return"custom response";const s=n.text!==void 0?[n.text.edited?"edited":"accepted"]:n.groups.map(t=>t.picked.length===0?"none":t.picked.map(e=>e.label).join(", "));return n.freetext!==void 0&&s.push(n.freetext),n.comments.length>0&&s.push(`${n.comments.length} comment${n.comments.length===1?"":"s"}`),s.join("; ")||"answered"}a(F,"answerSummary");function Y(n,s){return X(n,s)}a(Y,"commentLabel");function kn(n,s,t){const e=Math.min(Math.max(20,s-4),120),i=Math.max(20,s-4),c=["",...W(b(n.manifest.title),e,"",0,`${w}${E}`)];if(n.manifest.subtitle)for(const d of M(x(n.manifest.subtitle),e))c.push(` ${u}${d}${r}`);if(n.displayMarkdown!==""){c.push("");for(const d of L(n.displayMarkdown,e,i))c.push(` ${d}`)}else n.manifest.dialect==="html"&&c.push("",` ${u}HTML page \u2014 open in Northlight to read this${r}`);const o=n.slots.length>0;o&&c.push(` ${u}${O(e)}${r}`,"");const f=z(n);let l=-1,$;for(let d=0;d<n.slots.length;d++){const p=n.slots[d];n.manifest.steps>1&&p.step!==l&&(l!==-1&&c.push(""),c.push(` ${w}Step ${p.step+1}/${n.manifest.steps}${r}`),l=p.step);const y=p.id===void 0?void 0:n.responses.get(p.id),g=A(p)?R(n,p)?`${B}\u2713${r}`:`${u}\u25CB${r}`:`${u}\xB7${r}`,k=d===n.currentIndex?`${E}\u25B8${r} `:" ";d===n.currentIndex&&($=c.length),c.push(` ${k}${g} ${H(b(j(p)),Math.max(10,s-16))}`),y!==void 0&&c.push(` ${u}${H(b(F(fn(f,p))),Math.max(10,s-10))}${r}`)}if(n.manifest.slots.some(d=>A(d)&&!C(d))){c.push("");for(const d of M("This page must be answered in Northlight. Leaving it here keeps it in your inbox; x on the list cancels it.",e-2))c.push(` ${I}${d}${r}`)}o&&c.push(""),c.push(` ${u}${O(e)}${r}`);const h=!n.manifest.slots.some(A)?` ${u}u/d${r} scroll ${u}q${r} dismiss`:` ${u}enter${r} review ${u}\u2191\u2193/jk${r} navigate ${u}u/d${r} scroll ${u}q${r} close`;return K(c,h,n,s,t,e+2,n.followSelection?$:void 0)}a(kn,"renderOverview");function un(n,s,t){const e=[...n],i=Math.max(0,Math.min(s,e.length)),c=G(n,t);let o=0;for(let $=0;$<c.length;$++)c[$].start<=i&&(o=$);const f=c.map(($,m)=>{if(m!==o)return e.slice($.start,$.end).join("");const h=e.slice($.start,i).join(""),d=i<$.end?e[i]:" ",p=i<$.end?e.slice(i+1,$.end).join(""):"";return`${h}${T}${d}${r}${p}`}),l=c[o];return i===l.end&&v(e.slice(l.start,l.end).join(""))>=t&&(f[o]=e.slice(l.start,l.end).join(""),f.splice(o+1,0,`${T} ${r}`)),f}a(un,"renderInputBuffer");function bn(n,s){const t=[...n];let e=Math.max(0,Math.min(s,t.length));for(;e>0&&/\s/.test(t[e-1]);)e--;for(;e>0&&!/\s/.test(t[e-1]);)e--;return e}a(bn,"wordLeftIndex");function On(n,s){const t=[...n];let e=Math.max(0,Math.min(s,t.length));for(;e<t.length&&/\s/.test(t[e]);)e++;for(;e<t.length&&!/\s/.test(t[e]);)e++;return e}a(On,"wordRightIndex");function G(n,s){const t=[...n],e=Math.max(1,s),i=[];let c=0,o=0;for(let f=0;f<t.length;f++){const l=t[f];if(l===`
2
- `){i.push({start:c,end:f}),c=f+1,o=0;continue}const $=v(l);o+$>e?(i.push({start:c,end:f}),c=f,o=$):o+=$}return i.push({start:c,end:t.length}),i}a(G,"wrappedRowBounds");function yn(n,s,t,e){const i=G(n,e),c=Math.max(0,Math.min(s,[...n].length));let o=0;for(let l=0;l<i.length;l++)i[l].start<=c&&(o=l);const f=i[o+t];return f===void 0?c:Math.min(f.start+(c-i[o].start),f.end)}a(yn,"verticalCursor");function $n(n,s){return s.id===void 0?[]:n.responses.get(s.id)?.comments??[]}a($n,"responseComments");function W(n,s,t,e,i){return M(n,Math.max(10,s-e)).map((c,o)=>` ${o===0?t:" ".repeat(e)}${i}${c}${r}`)}a(W,"hangingWrap");function hn(n,s,t,e){if(s.id===void 0)return!1;const i=n.responses.get(s.id);return t==="option"?i?.selectedOptionIds?.includes(e)===!0:t==="card"?i?.selectedCardIds?.includes(e)===!0:t==="row"?i?.selectedRowIds?.includes(e)===!0:i?.selectedColumnIds?.includes(e)===!0}a(hn,"selected");function V(n,s){const t=n.slots[n.currentIndex],e=Math.min(Math.max(20,s-4),120),i=Math.max(20,s-4),c=`[${n.currentIndex+1}/${n.slots.length}]`,o=["",...W(b(n.manifest.title),e,`${w}${E}${c}${r} `,v(c)+2,u),` ${u}${O(e)}${r}`,"",...W(b(j(t)),e,"",0,w)],f=t.config.body;if(typeof f=="string"&&f.length>0){o.push("");for(const m of L(f,e,i))o.push(` ${m}`)}if(C(t)){if(t.kind==="chart"){const m=t.config,h=m.title??`${m.x} vs ${(m.y??[]).map(d=>d.label??d.field).join(", ")}`;o.push("",` ${u}chart \u2014 ${x(m.kind)}: ${x(h)}${r}`)}else if(t.kind==="table"){o.push("");for(const h of L(rn(t.config),e,i))o.push(` ${h}`);const m=t.config.label;m&&o.push(` ${u}${x(m)}${r}`)}else if(t.kind==="text"){const h=(t.id===void 0?void 0:n.responses.get(t.id))?.text??t.config.initialText;o.push("");for(const d of L(h,e,i))o.push(` ${d}`)}}else{o.push("");for(const m of M(`${x(t.kind)} \u2014 must be answered in Northlight; the terminal cannot submit this page`,Math.max(10,e-2)))o.push(` ${I}${m}${r}`);o.push(` ${u}q leaves it in your inbox; x on the list cancels it${r}`)}o.push("",` ${u}${O(e)}${r}`);let l;if(n.inputMode!==null){const m=n.inputMode.kind==="comment"?`Comment on ${Y(t,n.inputMode.anchor)}`:n.inputMode.kind==="text"?"Edit text":"Other response";o.push(` ${w}${m}${r}`);for(const h of un(n.inputMode.buffer,n.inputMode.cursor,Math.max(10,e-4)))o.push(` ${h}`);l=` ${u}enter save esc cancel${n.editorAvailable?" ^o editor":""}${r}`}else{on(t).forEach((h,d)=>{const p=d===n.selectedAction?`${E}\u25B8${r}`:" ";if(h.kind==="select"){const y=hn(n,t,h.group,h.id)?`${B}\u2713${r}`:" ",g=h.shortcut?`[${h.shortcut}] `:"",k=v(g);if(M(x(h.label),Math.max(10,e-6-k)).forEach((S,Q)=>o.push(Q===0?` ${p} [${y}] ${g}${S}`:`${" ".repeat(8+k)}${S}`)),h.description)for(const S of M(x(h.description),Math.max(10,e-6)))o.push(` ${u}${S}${r}`)}else{const y=h.kind==="freetext"?"r":h.kind==="edit"?"e":"a";M(x(h.label),Math.max(10,e-6)).forEach((g,k)=>o.push(k===0?` ${p} [${y}] ${g}`:` ${g}`))}});for(const h of $n(n,t))for(const d of M(`attached: ${Y(t,h.anchor)} \u2014 ${x(h.text)}`,Math.max(10,e-2)))o.push(` ${u}${d}${r}`);n.hint&&o.push(` ${I}${x(n.hint)}${r}`),l=` ${u}n/p next/previous \u2191\u2193/jk actions${tn(t).length>0?" c comment":""} u/d scroll \u2190\u2192/hl pan q close${r}`}const $=Math.max(0,...o.map(N));return{lines:o,footer:l,maxW:e,maxH:Math.max(0,$-Math.max(1,s))}}a(V,"itemLines");function In(n,s,t){if(n.slots[n.currentIndex]===void 0){n.scrollOffset=0,n.hscrollOffset=0,n.hscrollMax=0;return}const e=V(n,s);n.hscrollMax=e.maxH,n.hscrollOffset=Math.max(0,Math.min(n.hscrollOffset,n.hscrollMax)),n.scrollOffset=Math.max(0,Math.min(n.scrollOffset,Math.max(0,e.lines.length-q(t))))}a(In,"clampItemReviewScroll");function En(n,s){n.hscrollOffset=Math.max(0,Math.min(n.hscrollMax,n.hscrollOffset+s*ln))}a(En,"panItemReview");function Sn(n,s,t){const e=V(n,s),i=q(t),c=n.scrollOffset,o=e.lines.slice(c,c+i);for(;o.length<i;)o.push("");const f=n.hscrollOffset>0?o.map($=>cn($,n.hscrollOffset,s)):o,l=Math.min(s,e.maxW+2);return i<t&&f.push(J(e.footer,_(c,i,e.lines.length),e.maxW+2)),D(f.map($=>P($,s)),s,l)}a(Sn,"renderItemReview");function vn(n,s,t){const e=Math.min(Math.max(20,s-4),120),i=["",...W(`${b(n.manifest.title)} \u2014 Summary`,e,"",0,`${w}${E}`),` ${u}${O(e)}${r}`,""],c=z(n);for(const l of c.slots){const $=n.manifest.slots.find(d=>d.id===l.id),h=$!==void 0&&R(n,$)?`${B}\u2713${r}`:`${I}\u25CB${r}`;i.push(` ${h} ${w}${x($===void 0?l.kind:j($))}${r} ${u}${x(F(l))}${r}`)}const o=sn(n);if(!o){i.push("",` ${I}Cannot submit yet.${r}`);for(const l of n.slots.filter(A))R(n,l)||(i.push(` ${u}${l.id??l.kind} is unanswered${r}`),C(l)||i.push(` ${u}${l.id} must be answered in Northlight${r}`))}i.push("",` ${u}${O(e)}${r}`);const f=o?` ${u}enter${r} submit ${u}u/d${r} scroll ${u}q${r} back`:` ${u}u/d${r} scroll ${u}q${r} back`;return K(i,f,n,s,t,e+2)}a(vn,"renderFinal");function q(n){return n>=2?n-1:n}a(q,"bodyRows");function _(n,s,t){if(s<=0||t<=s)return{marks:"",full:""};const e=Math.min(t,n+s),i=`${n>0?"\u25B4":" "}${e<t?"\u25BE":" "}`;return{marks:`${u}${i}${r}`,full:`${u}${i} ${n+1}\u2013${e}/${t}${r}`}}a(_,"scrollBadge");function J(n,s,t){if(s.full==="")return n;const e=a(i=>t-N(n)-N(i)-2,"room");for(const i of[s.full,s.marks])if(e(i)>=2)return`${n}${" ".repeat(e(i))}${i}`;return` ${s.marks} ${n.trimStart()}`}a(J,"pinnedFooter");function K(n,s,t,e,i,c,o){const f=q(i),l=Math.max(0,n.length-f);t.scrollOffset=Math.max(0,Math.min(t.scrollOffset,l)),o!==void 0&&f>0&&(o<t.scrollOffset?t.scrollOffset=o:o>=t.scrollOffset+f&&(t.scrollOffset=Math.min(l,o-f+1)));const $=n.slice(t.scrollOffset,t.scrollOffset+f);for(;$.length<f;)$.push("");return f<i&&$.push(J(s,_(t.scrollOffset,f,n.length),c)),D($.map(m=>P(m,e)),e,Math.min(e,c))}a(K,"centeredWindow");export{In as clampItemReviewScroll,En as panItemReview,vn as renderFinal,un as renderInputBuffer,Sn as renderItemReview,kn as renderOverview,yn as verticalCursor,bn as wordLeftIndex,On as wordRightIndex,G as wrappedRowBounds};
1
+ var U=Object.defineProperty;var a=(n,s)=>U(n,"name",{value:s,configurable:!0});import R from"string-width";import{isResponseBearingSlot as v}from"../../../core/human/page-schema.js";import{answerCommentAnchorLabel as X,describePageAnswer as Z}from"../../../core/human/answer.js";import{renderMarkdownBlockAwareLines as nn}from"../../../core/termrender/termrender.js";import{rewriteMarkdownDocLinks as en}from"../../attach/render/markdown-source.js";import{commentAnchors as tn,describeSlot as C,pageComplete as sn,slotActions as on,slotAnswered as B,tableMarkdown as rn,terminalAnswerable as N}from"./slots.js";import{RESET as r,BOLD as w,DIM as $,GREEN as A,YELLOW as S,CYAN as E,REVERSE as T,sanitize as x,singleLine as y,truncate as H,hline as I,wrap as g,centerHorizontal as D,clipLine as P,panLine as ln,visibleWidth as L}from"./ansi.js";const cn=8,W=a((n,s,t)=>nn(en(n),s,t),"mdLines");function z(n){return Z(n.manifest,Object.fromEntries(n.responses),{completedAt:""})}a(z,"pageAnswer");function fn(n,s){return s.id===void 0?void 0:n.slots.find(t=>t.id===s.id)}a(fn,"answerSlot");function F(n){if(n===void 0||n.state==="unanswered")return"unanswered";if(n.raw!==void 0)return"custom response";const s=n.text!==void 0?[n.text.edited?"edited":"accepted"]:n.groups.map(t=>t.picked.length===0?"none":t.picked.map(e=>e.label).join(", "));return n.freetext!==void 0&&s.push(n.freetext),n.comments.length>0&&s.push(`${n.comments.length} comment${n.comments.length===1?"":"s"}`),s.join("; ")||"answered"}a(F,"answerSummary");function Y(n,s){return X(n,s)}a(Y,"commentLabel");function kn(n,s,t){const e=Math.min(Math.max(20,s-4),120),o=Math.max(20,s-4),l=["",...j(y(n.manifest.title),e,"",0,`${w}${E}`)];if(n.manifest.subtitle)for(const h of g(x(n.manifest.subtitle),e))l.push(` ${$}${h}${r}`);if(n.displayMarkdown!==""){l.push("");for(const h of W(n.displayMarkdown,e,o))l.push(` ${h}`)}else n.manifest.dialect==="html"&&l.push("",` ${$}HTML page \u2014 open in Northlight to read this${r}`);const i=n.slots.length>0;i&&l.push(` ${$}${I(e)}${r}`,"");const f=z(n);let c=-1,u;for(let h=0;h<n.slots.length;h++){const p=n.slots[h];n.manifest.steps>1&&p.step!==c&&(c!==-1&&l.push(""),l.push(` ${w}Step ${p.step+1}/${n.manifest.steps}${r}`),c=p.step);const k=p.id===void 0?void 0:n.responses.get(p.id),M=v(p)?B(n,p)?`${A}\u2713${r}`:`${$}\u25CB${r}`:`${$}\xB7${r}`,b=h===n.currentIndex?`${E}\u25B8${r} `:" ";h===n.currentIndex&&(u=l.length),l.push(` ${b}${M} ${H(y(C(p)),Math.max(10,s-16))}`),k!==void 0&&l.push(` ${$}${H(y(F(fn(f,p))),Math.max(10,s-10))}${r}`)}if(n.manifest.slots.some(h=>v(h)&&!N(h))){l.push("");for(const h of g("This page must be answered in Northlight. Leaving it here keeps it in your inbox; x on the list cancels it.",e-2))l.push(` ${S}${h}${r}`)}i&&l.push(""),l.push(` ${$}${I(e)}${r}`);const d=!n.manifest.slots.some(v)?` ${$}u/d${r} scroll ${$}q${r} dismiss`:` ${$}enter${r} review ${$}\u2191\u2193/jk${r} navigate ${$}u/d${r} scroll ${$}q${r} close`;return K(l,d,n,s,t,e+2,n.followSelection?u:void 0)}a(kn,"renderOverview");function $n(n,s,t){const e=[...n],o=Math.max(0,Math.min(s,e.length)),l=G(n,t);let i=0;for(let u=0;u<l.length;u++)l[u].start<=o&&(i=u);const f=l.map((u,m)=>{if(m!==i)return e.slice(u.start,u.end).join("");const d=e.slice(u.start,o).join(""),h=o<u.end?e[o]:" ",p=o<u.end?e.slice(o+1,u.end).join(""):"";return`${d}${T}${h}${r}${p}`}),c=l[i];return o===c.end&&R(e.slice(c.start,c.end).join(""))>=t&&(f[i]=e.slice(c.start,c.end).join(""),f.splice(i+1,0,`${T} ${r}`)),f}a($n,"renderInputBuffer");function bn(n,s){const t=[...n];let e=Math.max(0,Math.min(s,t.length));for(;e>0&&/\s/.test(t[e-1]);)e--;for(;e>0&&!/\s/.test(t[e-1]);)e--;return e}a(bn,"wordLeftIndex");function On(n,s){const t=[...n];let e=Math.max(0,Math.min(s,t.length));for(;e<t.length&&/\s/.test(t[e]);)e++;for(;e<t.length&&!/\s/.test(t[e]);)e++;return e}a(On,"wordRightIndex");function G(n,s){const t=[...n],e=Math.max(1,s),o=[];let l=0,i=0;for(let f=0;f<t.length;f++){const c=t[f];if(c===`
2
+ `){o.push({start:l,end:f}),l=f+1,i=0;continue}const u=R(c);i+u>e?(o.push({start:l,end:f}),l=f,i=u):i+=u}return o.push({start:l,end:t.length}),o}a(G,"wrappedRowBounds");function yn(n,s,t,e){const o=G(n,e),l=Math.max(0,Math.min(s,[...n].length));let i=0;for(let c=0;c<o.length;c++)o[c].start<=l&&(i=c);const f=o[i+t];return f===void 0?l:Math.min(f.start+(l-o[i].start),f.end)}a(yn,"verticalCursor");function un(n,s){return s.id===void 0?[]:n.responses.get(s.id)?.comments??[]}a(un,"responseComments");function j(n,s,t,e,o){return g(n,Math.max(10,s-e)).map((l,i)=>` ${i===0?t:" ".repeat(e)}${o}${l}${r}`)}a(j,"hangingWrap");function dn(n,s,t,e){if(s.id===void 0)return!1;const o=n.responses.get(s.id);return t==="option"?o?.selectedOptionIds?.includes(e)===!0:t==="card"?o?.selectedCardIds?.includes(e)===!0:t==="row"?o?.selectedRowIds?.includes(e)===!0:o?.selectedColumnIds?.includes(e)===!0}a(dn,"selected");function V(n,s){const t=n.slots[n.currentIndex],e=Math.min(Math.max(20,s-4),120),o=Math.max(20,s-4),l=`[${n.currentIndex+1}/${n.slots.length}]`,i=["",...j(y(n.manifest.title),e,`${w}${E}${l}${r} `,R(l)+2,$),` ${$}${I(e)}${r}`,"",...j(y(C(t)),e,"",0,w)],f=t.config.body;if(typeof f=="string"&&f.length>0){i.push("");for(const m of W(f,e,o))i.push(` ${m}`)}if(N(t)){if(t.kind==="chart"){const m=t.config,d=m.title??`${m.x} vs ${(m.y??[]).map(h=>h.label??h.field).join(", ")}`;i.push("",` ${$}chart \u2014 ${x(m.kind)}: ${x(d)}${r}`)}else if(t.kind==="table"){i.push("");for(const d of W(rn(t.config),e,o))i.push(` ${d}`);const m=t.config.label;m&&i.push(` ${$}${x(m)}${r}`)}else if(t.kind==="text"){const d=(t.id===void 0?void 0:n.responses.get(t.id))?.text??t.config.initialText;i.push("");for(const h of W(d,e,o))i.push(` ${h}`)}}else{i.push("");for(const m of g(`${x(t.kind)} \u2014 must be answered in Northlight; the terminal cannot submit this page`,Math.max(10,e-2)))i.push(` ${S}${m}${r}`);i.push(` ${$}q leaves it in your inbox; x on the list cancels it${r}`)}i.push("",` ${$}${I(e)}${r}`);let c;if(n.inputMode!==null){const m=n.inputMode.kind==="comment"?`Comment on ${Y(t,n.inputMode.anchor)}`:n.inputMode.kind==="text"?"Edit text":"Other response";i.push(` ${w}${m}${r}`);for(const d of $n(n.inputMode.buffer,n.inputMode.cursor,Math.max(10,e-4)))i.push(` ${d}`);c=` ${$}enter save esc cancel${n.editorAvailable?" ^o editor":""}${r}`}else{on(t).forEach((d,h)=>{const p=h===n.selectedAction?`${E}\u25B8${r}`:" ";if(d.kind==="select"){const k=dn(n,t,d.group,d.id);let M;d.mode==="multi"?M=`[${k?`${A}\u2713${r}`:" "}] ${d.shortcut?`[${d.shortcut}] `:""}`:M=`[${k?`${A}\u2713${r}`:d.shortcut??" "}] `;const b=L(M);if(g(x(d.label),Math.max(10,e-2-b)).forEach((O,Q)=>i.push(Q===0?` ${p} ${M}${O}`:`${" ".repeat(4+b)}${O}`)),d.description)for(const O of g(x(d.description),Math.max(10,e-6)))i.push(` ${$}${O}${r}`)}else{const k=d.kind==="freetext"?"r":d.kind==="edit"?"e":"a";g(x(d.label),Math.max(10,e-6)).forEach((M,b)=>i.push(b===0?` ${p} [${k}] ${M}`:` ${M}`))}});for(const d of un(n,t))for(const h of g(`attached: ${Y(t,d.anchor)} \u2014 ${x(d.text)}`,Math.max(10,e-2)))i.push(` ${$}${h}${r}`);n.hint&&i.push(` ${S}${x(n.hint)}${r}`),c=` ${$}n/p next/previous \u2191\u2193/jk actions${tn(t).length>0?" c comment":""} u/d scroll \u2190\u2192/hl pan q close${r}`}const u=Math.max(0,...i.map(L));return{lines:i,footer:c,maxW:e,maxH:Math.max(0,u-Math.max(1,s))}}a(V,"itemLines");function In(n,s,t){if(n.slots[n.currentIndex]===void 0){n.scrollOffset=0,n.hscrollOffset=0,n.hscrollMax=0;return}const e=V(n,s);n.hscrollMax=e.maxH,n.hscrollOffset=Math.max(0,Math.min(n.hscrollOffset,n.hscrollMax)),n.scrollOffset=Math.max(0,Math.min(n.scrollOffset,Math.max(0,e.lines.length-q(t))))}a(In,"clampItemReviewScroll");function Sn(n,s){n.hscrollOffset=Math.max(0,Math.min(n.hscrollMax,n.hscrollOffset+s*cn))}a(Sn,"panItemReview");function En(n,s,t){const e=V(n,s),o=q(t),l=n.scrollOffset,i=e.lines.slice(l,l+o);for(;i.length<o;)i.push("");const f=n.hscrollOffset>0?i.map(u=>ln(u,n.hscrollOffset,s)):i,c=Math.min(s,e.maxW+2);return o<t&&f.push(J(e.footer,_(l,o,e.lines.length),e.maxW+2)),D(f.map(u=>P(u,s)),s,c)}a(En,"renderItemReview");function vn(n,s,t){const e=Math.min(Math.max(20,s-4),120),o=["",...j(`${y(n.manifest.title)} \u2014 Summary`,e,"",0,`${w}${E}`),` ${$}${I(e)}${r}`,""],l=z(n);for(const c of l.slots){const u=n.manifest.slots.find(h=>h.id===c.id),d=u!==void 0&&B(n,u)?`${A}\u2713${r}`:`${S}\u25CB${r}`;o.push(` ${d} ${w}${x(u===void 0?c.kind:C(u))}${r} ${$}${x(F(c))}${r}`)}const i=sn(n);if(!i){o.push("",` ${S}Cannot submit yet.${r}`);for(const c of n.slots.filter(v))B(n,c)||(o.push(` ${$}${c.id??c.kind} is unanswered${r}`),N(c)||o.push(` ${$}${c.id} must be answered in Northlight${r}`))}o.push("",` ${$}${I(e)}${r}`);const f=i?` ${$}enter${r} submit ${$}u/d${r} scroll ${$}q${r} back`:` ${$}u/d${r} scroll ${$}q${r} back`;return K(o,f,n,s,t,e+2)}a(vn,"renderFinal");function q(n){return n>=2?n-1:n}a(q,"bodyRows");function _(n,s,t){if(s<=0||t<=s)return{marks:"",full:""};const e=Math.min(t,n+s),o=`${n>0?"\u25B4":" "}${e<t?"\u25BE":" "}`;return{marks:`${$}${o}${r}`,full:`${$}${o} ${n+1}\u2013${e}/${t}${r}`}}a(_,"scrollBadge");function J(n,s,t){if(s.full==="")return n;const e=a(o=>t-L(n)-L(o)-2,"room");for(const o of[s.full,s.marks])if(e(o)>=2)return`${n}${" ".repeat(e(o))}${o}`;return` ${s.marks} ${n.trimStart()}`}a(J,"pinnedFooter");function K(n,s,t,e,o,l,i){const f=q(o),c=Math.max(0,n.length-f);t.scrollOffset=Math.max(0,Math.min(t.scrollOffset,c)),i!==void 0&&f>0&&(i<t.scrollOffset?t.scrollOffset=i:i>=t.scrollOffset+f&&(t.scrollOffset=Math.min(c,i-f+1)));const u=n.slice(t.scrollOffset,t.scrollOffset+f);for(;u.length<f;)u.push("");return f<o&&u.push(J(s,_(t.scrollOffset,f,n.length),l)),D(u.map(m=>P(m,e)),e,Math.min(e,l))}a(K,"centeredWindow");export{In as clampItemReviewScroll,Sn as panItemReview,vn as renderFinal,$n as renderInputBuffer,En as renderItemReview,kn as renderOverview,yn as verticalCursor,bn as wordLeftIndex,On as wordRightIndex,G as wrappedRowBounds};
@@ -1,9 +1,11 @@
1
1
  import type { CanvasDb } from '../../canvas/db.js';
2
+ /** `cascade`: the database deletes the row when its parent row goes (`ON DELETE CASCADE`). */
2
3
  export interface ForeignKey {
3
4
  table: string;
4
5
  columns: string[];
5
6
  parent: string;
6
7
  parentColumns: string[];
8
+ cascade: boolean;
7
9
  }
8
10
  export interface UniqueKey {
9
11
  table: string;
@@ -1,9 +1,9 @@
1
- var g=Object.defineProperty;var r=(n,a)=>g(n,"name",{value:a,configurable:!0});const _=r(n=>n.primaryKey.length>0?n.primaryKey:n.columns,"rowKey"),u=r(n=>`"${n.replace(/"/g,'""')}"`,"q"),f=r((n,a,l,c)=>a.map((s,o)=>`${l}.${u(s)} = (${c} ->> ${o})::${u(n.types[s])}`).join(" AND "),"keyMatch");async function N(n,a,l){const c=[...l],s=await n.prepareUncached(`SELECT table_name, column_name, is_identity, udt_name FROM information_schema.columns
2
- WHERE table_schema = ? AND table_name = ANY(?::text[]) ORDER BY table_name, ordinal_position`).all(a,`{${c.map(e=>`"${e}"`).join(",")}}`),o=new Map;for(const e of c)o.set(e,{name:e,columns:[],types:{},primaryKey:[],identity:[]});for(const e of s){const i=o.get(e.table_name);i.columns.push(e.column_name),i.types[e.column_name]=e.udt_name,e.is_identity==="YES"&&i.identity.push(e.column_name)}const d=await n.prepareUncached(`SELECT c.conrelid::regclass::text AS tbl, c.contype, c.conname,
1
+ var g=Object.defineProperty;var c=(a,n)=>g(a,"name",{value:n,configurable:!0});const x=c(a=>a.primaryKey.length>0?a.primaryKey:a.columns,"rowKey"),u=c(a=>`"${a.replace(/"/g,'""')}"`,"q"),_=c((a,n,l,r)=>n.map((s,o)=>`${l}.${u(s)} = (${r} ->> ${o})::${u(a.types[s])}`).join(" AND "),"keyMatch");async function N(a,n,l){const r=[...l],s=await a.prepareUncached(`SELECT table_name, column_name, is_identity, udt_name FROM information_schema.columns
2
+ WHERE table_schema = ? AND table_name = ANY(?::text[]) ORDER BY table_name, ordinal_position`).all(n,`{${r.map(e=>`"${e}"`).join(",")}}`),o=new Map;for(const e of r)o.set(e,{name:e,columns:[],types:{},primaryKey:[],identity:[]});for(const e of s){const i=o.get(e.table_name);i.columns.push(e.column_name),i.types[e.column_name]=e.udt_name,e.is_identity==="YES"&&i.identity.push(e.column_name)}const d=await a.prepareUncached(`SELECT c.conrelid::regclass::text AS tbl, c.contype, c.conname,
3
3
  (SELECT array_agg(a.attname::text ORDER BY k.ord) FROM unnest(c.conkey) WITH ORDINALITY k(attnum, ord) JOIN pg_attribute a ON a.attrelid = c.conrelid AND a.attnum = k.attnum) AS cols,
4
- c.confrelid::regclass::text AS ptbl,
4
+ c.confrelid::regclass::text AS ptbl, c.confdeltype = 'c' AS cascade,
5
5
  (SELECT array_agg(a.attname::text ORDER BY k.ord) FROM unnest(c.confkey) WITH ORDINALITY k(attnum, ord) JOIN pg_attribute a ON a.attrelid = c.confrelid AND a.attnum = k.attnum) AS pcols
6
- FROM pg_constraint c WHERE c.connamespace = ?::regnamespace AND c.contype IN ('p', 'f')`).all(a),p=r(e=>e.replace(/^.*\./,"").replace(/"/g,""),"bare"),t=[];for(const e of d){const i=p(e.tbl);o.has(i)&&(e.contype==="p"?o.get(i).primaryKey=e.cols:o.has(p(e.ptbl))&&t.push({table:i,columns:e.cols,parent:p(e.ptbl),parentColumns:e.pcols}))}const y=(await n.prepareUncached(`SELECT t.relname AS tbl, i.relname AS name, pg_get_expr(x.indpred, x.indrelid) AS predicate, x.indexprs IS NOT NULL AS has_expr,
6
+ FROM pg_constraint c WHERE c.connamespace = ?::regnamespace AND c.contype IN ('p', 'f')`).all(n),p=c(e=>e.replace(/^.*\./,"").replace(/"/g,""),"bare"),t=[];for(const e of d){const i=p(e.tbl);o.has(i)&&(e.contype==="p"?o.get(i).primaryKey=e.cols:o.has(p(e.ptbl))&&t.push({table:i,columns:e.cols,parent:p(e.ptbl),parentColumns:e.pcols,cascade:e.cascade===!0}))}const y=(await a.prepareUncached(`SELECT t.relname AS tbl, i.relname AS name, pg_get_expr(x.indpred, x.indrelid) AS predicate, x.indexprs IS NOT NULL AS has_expr,
7
7
  (SELECT array_agg(a.attname::text ORDER BY k.ord) FROM unnest(x.indkey::int2[]) WITH ORDINALITY k(attnum, ord) JOIN pg_attribute a ON a.attrelid = x.indrelid AND a.attnum = k.attnum) AS cols
8
8
  FROM pg_index x JOIN pg_class t ON t.oid = x.indrelid JOIN pg_class i ON i.oid = x.indexrelid
9
- WHERE t.relnamespace = ?::regnamespace AND x.indisunique AND NOT x.indisprimary`).all(a)).filter(e=>o.has(e.tbl)&&!e.has_expr).map(e=>({table:e.tbl,name:e.name,columns:e.cols,predicate:e.predicate}));return{schema:a,tables:o,foreignKeys:t,uniqueKeys:y}}r(N,"readCatalog");function O(n,a){const l=new Set(a),c=new Map(a.map(t=>[t,new Set]));for(const t of n.foreignKeys)l.has(t.table)&&l.has(t.parent)&&t.table!==t.parent&&c.get(t.table).add(t.parent);const s=[],o=new Set,d=new Set,p=r(t=>{if(!(o.has(t)||d.has(t))){d.add(t);for(const m of[...c.get(t)].sort())p(m);d.delete(t),o.add(t),s.push(t)}},"visit");for(const t of a)p(t);return s}r(O,"topologicalOrder");export{f as keyMatch,u as q,N as readCatalog,_ as rowKey,O as topologicalOrder};
9
+ WHERE t.relnamespace = ?::regnamespace AND x.indisunique AND NOT x.indisprimary`).all(n)).filter(e=>o.has(e.tbl)&&!e.has_expr).map(e=>({table:e.tbl,name:e.name,columns:e.cols,predicate:e.predicate}));return{schema:n,tables:o,foreignKeys:t,uniqueKeys:y}}c(N,"readCatalog");function O(a,n){const l=new Set(n),r=new Map(n.map(t=>[t,new Set]));for(const t of a.foreignKeys)l.has(t.table)&&l.has(t.parent)&&t.table!==t.parent&&r.get(t.table).add(t.parent);const s=[],o=new Set,d=new Set,p=c(t=>{if(!(o.has(t)||d.has(t))){d.add(t);for(const m of[...r.get(t)].sort())p(m);d.delete(t),o.add(t),s.push(t)}},"visit");for(const t of n)p(t);return s}c(O,"topologicalOrder");export{_ as keyMatch,u as q,N as readCatalog,x as rowKey,O as topologicalOrder};
@@ -1,13 +1,13 @@
1
- var w=Object.defineProperty;var m=(n,c)=>w(n,"name",{value:c,configurable:!0});import{KEY_MAPPED_TABLES as k}from"../bundle/layout.js";import{keyMatch as D,q as a,rowKey as W}from"./catalog.js";import{archiveCutoffs as H,BODY_TYPES as J}from"../../events/run-event-chunks.js";import{MEMORY_READS_RETENTION_MS as j}from"../../canvas/memory-reads.js";import{decodeKeys as x}from"./copy.js";const r=m((n,c)=>`${a(n)}.${a(c)}`,"sq"),B={messages:["seq"]},Y=["claimed_by","lease_expires_at"],P={worktrees:["attempts","next_attempt_at","sweep_reason","sweep_detail","sweep_last_at","sweep_observed_json"]},K=10*6e4;function C(n){const c=Date.now()+K;if(n==="run_events"){const{bodyCutoff:t,controlCutoff:O}=H(c);return`(s.ts < '${O}' OR (s.ts < '${t}' AND s.type IN (${J.map(S=>`'${S}'`).join(", ")})))`}return n==="memory_reads"?`s.at < '${new Date(c-j).toISOString()}'`:"false"}m(C,"removedByMaintenance");async function Q(n,c,t,O,S,h){const d={},A={},L=await n.prepare("SELECT table_name, inserted_keys FROM import_manifest WHERE run_id = ?").all(c);await n.exec(`DROP TABLE IF EXISTS ${a(t)}._m; CREATE TABLE ${a(t)}._m (tbl text NOT NULL, k jsonb NOT NULL)`);for(const{table_name:e,inserted_keys:E}of L){const i=S.tables.get(e);if(i===void 0)continue;const p=x(E);if(p.length===0)continue;await n.prepare(`DELETE FROM ${a(t)}._m WHERE tbl = ?`).run(e);for(let o=0;o<p.length;o+=5e3)await n.prepare(`INSERT INTO ${a(t)}._m SELECT ?, e FROM jsonb_array_elements(?::jsonb) e`).run(e,JSON.stringify(p.slice(o,o+5e3)));await n.exec(`ANALYZE ${a(t)}._m`);const $=[...i.identity,...B[e]??[],...Y,...P[e]??[]].map(o=>`'${o.replace(/'/g,"''")}'`).join(", ")||"''",s=m(o=>`to_jsonb(${o}) - ARRAY[${$}]::text[]`,"strip"),N=W(i);let T;if(e in k){const o=k[e];T=`JOIN import_key_map km ON km.source_install_id = '${h.replace(/'/g,"''")}' AND km.table_name = '${e}' AND km.target_key = m.k ->> 0
2
- JOIN ${r(t,e)} s ON s.${a(o)}::text = km.source_key`}else T=`JOIN ${r(t,e)} s ON ${N.map((o,U)=>`s.${a(o)}::text = m.k ->> ${U}`).join(" AND ")}`;const g=e==="revisions"?` AND m.k ->> 0 NOT IN (SELECT rev_id FROM ${r(t,"_arr_revisions")})`:e==="revision_parents"?` AND NOT EXISTS (SELECT 1 FROM ${r(t,"_arr_parents")} a WHERE a.child = m.k ->> 0 AND a.parent = m.k ->> 1)`:"",b=`FROM ${r(t,"_m")} m LEFT JOIN ${r(O,e)} t ON ${D(i,N,"t","m.k")} ${T.replace("JOIN","LEFT JOIN")} WHERE m.tbl = '${e}'${g}`,F=`${b} AND ((t.${a(N[0])} IS NULL AND NOT (s.${a(N[0])} IS NOT NULL AND ${C(e)})) OR s.${a(N[0])} IS NULL OR (${s("t")}) <> (${s("s")}))`,y=await n.prepareUncached(`SELECT count(*) AS n, array_agg(k) FILTER (WHERE rn <= 10) AS keys FROM (SELECT m.k::text AS k, row_number() OVER () AS rn ${F}) d`).get(),v=Number(y.n);if(v>0&&(d[e]={count:v,keys:y.keys??[]}),e==="run_events"||e==="memory_reads"){const o=Number((await n.prepareUncached(`SELECT count(*) AS n ${b} AND t.${a(N[0])} IS NULL AND s.${a(N[0])} IS NOT NULL AND ${C(e)}`).get()).n);o>0&&(A[e]=o)}}for(const[e,E]of[["revisions",`FROM ${r(t,"_m")} m JOIN ${r(t,"_arr_revisions")} a ON a.rev_id = m.k ->> 0 LEFT JOIN revisions t ON t.rev_id = a.rev_id
3
- WHERE m.tbl = 'revisions' AND (t.rev_id IS NULL OR t.document <> a.document OR t.body_hash <> a.body_hash OR t.rationale IS DISTINCT FROM a.rationale OR t.created_at <> a.created_at)`],["revision_parents",`FROM ${r(t,"_m")} m JOIN ${r(t,"_arr_parents")} a ON a.child = m.k ->> 0 AND a.parent = m.k ->> 1 LEFT JOIN revision_parents t ON t.child = a.child AND t.parent = a.parent
4
- WHERE m.tbl = 'revision_parents' AND t.child IS NULL`]]){const i=Number((await n.prepareUncached(`SELECT count(*) AS n ${E}`).get()).n);i>0&&(d[`${e}.arrived`]={count:i,keys:[]})}const _={},l=r(t,"_ids");await n.exec(`DROP TABLE IF EXISTS ${l}; CREATE TABLE ${l} (key text PRIMARY KEY, mapped boolean NOT NULL);
5
- INSERT INTO ${l} SELECT key, bool_or(mapped) FROM (SELECT source AS key, true AS mapped FROM ${r(t,"_idmap")} WHERE kind = 'object'
6
- UNION ALL SELECT key, false FROM ${r(t,"_dropped")} WHERE tbl = 'objects') u GROUP BY key; ANALYZE ${l}`);let R=!1;for(const{table_name:e}of L){const E=S.tables.get(e);if(E===void 0||R||E.primaryKey.length===0)continue;const i=(await n.prepareUncached("SELECT column_name FROM information_schema.columns WHERE table_schema = ? AND table_name = ? AND data_type = 'text'").all(O,e)).map(s=>s.column_name).filter(s=>!(E.primaryKey.includes(s)&&e==="objects"));if(i.length===0)continue;const p=i.map(s=>`('${s.replace(/'/g,"''")}', t.${a(s)})`).join(", "),$=await n.prepareUncached(`SELECT v.col AS col, count(*) AS n FROM ${r(t,"_m")} m JOIN ${r(O,e)} t ON ${D(E,E.primaryKey,"t","m.k")}
7
- CROSS JOIN LATERAL (VALUES ${p}) v(col, val) JOIN ${l} i ON i.key = v.val${e==="messages"?" AND i.mapped":""}
8
- WHERE m.tbl = ? GROUP BY v.col ORDER BY v.col`).all(e);for(const{col:s,n:N}of $)R=!0,d[`${e}.${s}`]={count:Number(N),keys:["holds a dropped object id"]}}_.no_dropped_id=!R;const I=L.find(e=>e.table_name==="revisions");let f=!0,u=0;if(I!==void 0){const e=`FROM ${r(t,"_m")} m JOIN revisions r ON r.rev_id = m.k ->> 0 WHERE m.tbl = 'revisions' AND NOT EXISTS (SELECT 1 FROM bodies b WHERE b.hash = r.body_hash)`;f=await n.prepare(`SELECT 1 AS lost ${e} AND EXISTS (SELECT 1 FROM ${r(t,"bodies")} s WHERE s.hash = r.body_hash) LIMIT 1`).get()===void 0,u=Number((await n.prepare(`SELECT count(*) AS n ${e} AND NOT EXISTS (SELECT 1 FROM ${r(t,"bodies")} s WHERE s.hash = r.body_hash)`).get()).n)}_.revision_bodies_readable=f,_.revision_bodies_canonical=I===void 0||await n.prepare(`SELECT 1 AS wrong FROM ${r(t,"_m")} m JOIN revisions r ON r.rev_id = m.k ->> 0 JOIN bodies b ON b.hash = r.body_hash
9
- WHERE m.tbl = 'revisions' AND encode(sha256(convert_to(b.text, 'UTF8')), 'hex') <> b.hash LIMIT 1`).get()===void 0;const M=await n.prepare(`SELECT 1 AS found FROM (
1
+ var j=Object.defineProperty;var u=(n,N)=>j(n,"name",{value:N,configurable:!0});import{KEY_MAPPED_TABLES as C}from"../bundle/layout.js";import{keyMatch as h,q as r,rowKey as W}from"./catalog.js";import{archiveCutoffs as H,BODY_TYPES as J}from"../../events/run-event-chunks.js";import{MEMORY_READS_RETENTION_MS as x}from"../../canvas/memory-reads.js";import{PURGE_RETENTION_MS as B}from"../../storage/purge.js";import{decodeKeys as Y}from"./copy.js";const o=u((n,N)=>`${r(n)}.${r(N)}`,"sq"),P={messages:["seq"]},K=["claimed_by","lease_expires_at"],q={worktrees:["attempts","next_attempt_at","sweep_reason","sweep_detail","sweep_last_at","sweep_observed_json"]},G=10*6e4;function M(n,N,e,c,s,m=[]){if(e==="objects")return`${c}."id" IN (${s})`;if(m.includes(e))return"false";const a=[];e==="object_kinds"&&a.push(`${c}."owner" IN (${s})`);for(const E of n.foreignKeys){if(E.table!==e||!E.cascade||E.columns.length!==1)continue;const S=`${c}.${r(E.columns[0])}`;if(E.parent==="objects"){a.push(`${S} IN (${s})`);continue}const O=M(n,N,E.parent,"p",s,[...m,e]);O!=="false"&&a.push(`${S} IN (SELECT p.${r(E.parentColumns[0])} FROM ${o(N,E.parent)} p WHERE ${O})`)}return a.length===0?"false":`(${a.join(" OR ")})`}u(M,"removedWithPurgedObject");function I(n,N,e){const c=Date.now()+G,s=[];if(e==="run_events"){const{bodyCutoff:E,controlCutoff:S}=H(c);s.push(`(s.ts < '${S}' OR (s.ts < '${E}' AND s.type IN (${J.map(O=>`'${O}'`).join(", ")})))`)}e==="memory_reads"&&s.push(`s.at < '${new Date(c-x).toISOString()}'`);const m=`SELECT o.id FROM ${o(N,"objects")} o WHERE o.deleted_at IS NOT NULL AND (o.type = 'node' OR o.deleted_at < '${new Date(c-B).toISOString()}')`,a=M(n,N,e,"s",m);return a!=="false"&&s.push(a),s.length===0?"false":`(${s.join(" OR ")})`}u(I,"removedByMaintenance");async function ne(n,N,e,c,s,m){const a={},E={},S=await n.prepare("SELECT table_name, inserted_keys FROM import_manifest WHERE run_id = ?").all(N);await n.exec(`DROP TABLE IF EXISTS ${r(e)}._m; CREATE TABLE ${r(e)}._m (tbl text NOT NULL, k jsonb NOT NULL)`);for(const{table_name:t,inserted_keys:d}of S){const p=s.tables.get(t);if(p===void 0)continue;const R=Y(d);if(R.length===0)continue;await n.prepare(`DELETE FROM ${r(e)}._m WHERE tbl = ?`).run(t);for(let i=0;i<R.length;i+=5e3)await n.prepare(`INSERT INTO ${r(e)}._m SELECT ?, e FROM jsonb_array_elements(?::jsonb) e`).run(t,JSON.stringify(R.slice(i,i+5e3)));await n.exec(`ANALYZE ${r(e)}._m`);const A=[...p.identity,...P[t]??[],...K,...q[t]??[]].map(i=>`'${i.replace(/'/g,"''")}'`).join(", ")||"''",_=u(i=>`to_jsonb(${i}) - ARRAY[${A}]::text[]`,"strip"),l=W(p);let T;if(t in C){const i=C[t];T=`JOIN import_key_map km ON km.source_install_id = '${m.replace(/'/g,"''")}' AND km.table_name = '${t}' AND km.target_key = m.k ->> 0
2
+ JOIN ${o(e,t)} s ON s.${r(i)}::text = km.source_key`}else T=`JOIN ${o(e,t)} s ON ${l.map((i,w)=>`s.${r(i)}::text = m.k ->> ${w}`).join(" AND ")}`;const F=t==="revisions"?` AND m.k ->> 0 NOT IN (SELECT rev_id FROM ${o(e,"_arr_revisions")})`:t==="revision_parents"?` AND NOT EXISTS (SELECT 1 FROM ${o(e,"_arr_parents")} a WHERE a.child = m.k ->> 0 AND a.parent = m.k ->> 1)`:"",k=`FROM ${o(e,"_m")} m LEFT JOIN ${o(c,t)} t ON ${h(p,l,"t","m.k")} ${T.replace("JOIN","LEFT JOIN")} WHERE m.tbl = '${t}'${F}`,U=`${k} AND ((t.${r(l[0])} IS NULL AND NOT (s.${r(l[0])} IS NOT NULL AND ${I(s,e,t)})) OR s.${r(l[0])} IS NULL OR (${_("t")}) <> (${_("s")}))`,D=await n.prepareUncached(`SELECT count(*) AS n, array_agg(k) FILTER (WHERE rn <= 10) AS keys FROM (SELECT m.k::text AS k, row_number() OVER () AS rn ${U}) d`).get(),v=Number(D.n);if(v>0&&(a[t]={count:v,keys:D.keys??[]}),I(s,e,t)!=="false"){const i=Number((await n.prepareUncached(`SELECT count(*) AS n ${k} AND t.${r(l[0])} IS NULL AND s.${r(l[0])} IS NOT NULL AND ${I(s,e,t)}`).get()).n);i>0&&(E[t]=i)}}for(const[t,d]of[["revisions",`FROM ${o(e,"_m")} m JOIN ${o(e,"_arr_revisions")} a ON a.rev_id = m.k ->> 0 LEFT JOIN revisions t ON t.rev_id = a.rev_id
3
+ WHERE m.tbl = 'revisions' AND (t.rev_id IS NULL OR t.document <> a.document OR t.body_hash <> a.body_hash OR t.rationale IS DISTINCT FROM a.rationale OR t.created_at <> a.created_at)`],["revision_parents",`FROM ${o(e,"_m")} m JOIN ${o(e,"_arr_parents")} a ON a.child = m.k ->> 0 AND a.parent = m.k ->> 1 LEFT JOIN revision_parents t ON t.child = a.child AND t.parent = a.parent
4
+ WHERE m.tbl = 'revision_parents' AND t.child IS NULL`]]){const p=Number((await n.prepareUncached(`SELECT count(*) AS n ${d}`).get()).n);p>0&&(a[`${t}.arrived`]={count:p,keys:[]})}const O={},$=o(e,"_ids");await n.exec(`DROP TABLE IF EXISTS ${$}; CREATE TABLE ${$} (key text PRIMARY KEY, mapped boolean NOT NULL);
5
+ INSERT INTO ${$} SELECT key, bool_or(mapped) FROM (SELECT source AS key, true AS mapped FROM ${o(e,"_idmap")} WHERE kind = 'object'
6
+ UNION ALL SELECT key, false FROM ${o(e,"_dropped")} WHERE tbl = 'objects') u GROUP BY key; ANALYZE ${$}`);let L=!1;for(const{table_name:t}of S){const d=s.tables.get(t);if(d===void 0||L||d.primaryKey.length===0)continue;const p=(await n.prepareUncached("SELECT column_name FROM information_schema.columns WHERE table_schema = ? AND table_name = ? AND data_type = 'text'").all(c,t)).map(_=>_.column_name).filter(_=>!(d.primaryKey.includes(_)&&t==="objects"));if(p.length===0)continue;const R=p.map(_=>`('${_.replace(/'/g,"''")}', t.${r(_)})`).join(", "),A=await n.prepareUncached(`SELECT v.col AS col, count(*) AS n FROM ${o(e,"_m")} m JOIN ${o(c,t)} t ON ${h(d,d.primaryKey,"t","m.k")}
7
+ CROSS JOIN LATERAL (VALUES ${R}) v(col, val) JOIN ${$} i ON i.key = v.val${t==="messages"?" AND i.mapped":""}
8
+ WHERE m.tbl = ? GROUP BY v.col ORDER BY v.col`).all(t);for(const{col:_,n:l}of A)L=!0,a[`${t}.${_}`]={count:Number(l),keys:["holds a dropped object id"]}}O.no_dropped_id=!L;const b=S.find(t=>t.table_name==="revisions");let y=!0,f=0;if(b!==void 0){const t=`FROM ${o(e,"_m")} m JOIN revisions r ON r.rev_id = m.k ->> 0 WHERE m.tbl = 'revisions' AND NOT EXISTS (SELECT 1 FROM bodies b WHERE b.hash = r.body_hash)`;y=await n.prepare(`SELECT 1 AS lost ${t} AND EXISTS (SELECT 1 FROM ${o(e,"bodies")} s WHERE s.hash = r.body_hash) LIMIT 1`).get()===void 0,f=Number((await n.prepare(`SELECT count(*) AS n ${t} AND NOT EXISTS (SELECT 1 FROM ${o(e,"bodies")} s WHERE s.hash = r.body_hash)`).get()).n)}O.revision_bodies_readable=y,O.revision_bodies_canonical=b===void 0||await n.prepare(`SELECT 1 AS wrong FROM ${o(e,"_m")} m JOIN revisions r ON r.rev_id = m.k ->> 0 JOIN bodies b ON b.hash = r.body_hash
9
+ WHERE m.tbl = 'revisions' AND encode(sha256(convert_to(b.text, 'UTF8')), 'hex') <> b.hash LIMIT 1`).get()===void 0;const g=await n.prepare(`SELECT 1 AS found FROM (
10
10
  SELECT month, payer, funding, COALESCE(sub, '') AS sub, grantee, COALESCE(provider, '') AS provider, COALESCE(SUM(usd), 0) AS usd, COALESCE(SUM(billed_usd), 0) AS billed
11
- FROM charges WHERE refused IS NULL AND kind <> 'take' AND (month, payer) IN (SELECT DISTINCT month, payer FROM ${r(t,"charges")}) GROUP BY 1, 2, 3, 4, 5, 6) c
11
+ FROM charges WHERE refused IS NULL AND kind <> 'take' AND (month, payer) IN (SELECT DISTINCT month, payer FROM ${o(e,"charges")}) GROUP BY 1, 2, 3, 4, 5, 6) c
12
12
  FULL JOIN charge_totals t ON t.month = c.month AND t.payer = c.payer AND t.funding = c.funding AND t.sub = c.sub AND t.grantee = c.grantee AND t.provider = c.provider
13
- WHERE (COALESCE(t.month, c.month), COALESCE(t.payer, c.payer)) IN (SELECT DISTINCT month, payer FROM ${r(t,"charges")}) AND (c.month IS NULL OR t.month IS NULL OR c.usd <> t.usd OR c.billed <> t.billed_usd) LIMIT 1`).get();return _.charge_totals_equal_recompute=M===void 0,{ok:Object.keys(d).length===0&&Object.values(_).every(Boolean),differences:d,...Object.keys(A).length>0?{archived:A}:{},...u>0?{source_missing_bodies:u}:{},invariants:_}}m(Q,"verifyRun");export{Q as verifyRun};
13
+ WHERE (COALESCE(t.month, c.month), COALESCE(t.payer, c.payer)) IN (SELECT DISTINCT month, payer FROM ${o(e,"charges")}) AND (c.month IS NULL OR t.month IS NULL OR c.usd <> t.usd OR c.billed <> t.billed_usd) LIMIT 1`).get();return O.charge_totals_equal_recompute=g===void 0,{ok:Object.keys(a).length===0&&Object.values(O).every(Boolean),differences:a,...Object.keys(E).length>0?{archived:E}:{},...f>0?{source_missing_bodies:f}:{},invariants:O}}u(ne,"verifyRun");export{ne as verifyRun};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/cli",
3
- "version": "0.3.633",
3
+ "version": "0.3.634",
4
4
  "description": "crtr — agent runtime with memory, plugins, and marketplaces",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -145,7 +145,7 @@
145
145
  },
146
146
  "license": "UNLICENSED",
147
147
  "dependencies": {
148
- "@north-light/identity": "0.3.633",
148
+ "@north-light/identity": "0.3.634",
149
149
  "@earendil-works/chord": "1.1.0",
150
150
  "@earendil-works/pi-agent-core": "1.1.0",
151
151
  "@earendil-works/pi-ai": "1.1.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/identity",
3
- "version": "0.3.633",
3
+ "version": "0.3.634",
4
4
  "description": "Northlight access-token verification and scope rules",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/runtime.lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@north-light/cli",
3
- "version": "0.3.633",
3
+ "version": "0.3.634",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@north-light/cli",
9
- "version": "0.3.633",
9
+ "version": "0.3.634",
10
10
  "hasInstallScript": true,
11
11
  "license": "UNLICENSED",
12
12
  "workspaces": [
@@ -28,7 +28,7 @@
28
28
  "@milkdown/preset-gfm": "^7.22.3",
29
29
  "@milkdown/prose": "^7.22.3",
30
30
  "@milkdown/utils": "^7.22.3",
31
- "@north-light/identity": "0.3.633",
31
+ "@north-light/identity": "0.3.634",
32
32
  "cron-parser": "^5.6.0",
33
33
  "esbuild": "^0.27.7",
34
34
  "jose": "^6.2.12",
@@ -11956,17 +11956,17 @@
11956
11956
  },
11957
11957
  "packages/crouter-api": {
11958
11958
  "name": "@north-light/api",
11959
- "version": "0.3.633",
11959
+ "version": "0.3.634",
11960
11960
  "license": "UNLICENSED"
11961
11961
  },
11962
11962
  "packages/crouter-env-docker": {
11963
11963
  "name": "@north-light/env-docker",
11964
- "version": "0.3.633",
11964
+ "version": "0.3.634",
11965
11965
  "license": "UNLICENSED"
11966
11966
  },
11967
11967
  "packages/crouter-identity": {
11968
11968
  "name": "@north-light/identity",
11969
- "version": "0.3.633",
11969
+ "version": "0.3.634",
11970
11970
  "license": "UNLICENSED",
11971
11971
  "dependencies": {
11972
11972
  "jose": "^6.2.1"
@@ -11974,21 +11974,21 @@
11974
11974
  },
11975
11975
  "packages/crouter-plugin": {
11976
11976
  "name": "@north-light/plugin",
11977
- "version": "0.3.633",
11977
+ "version": "0.3.634",
11978
11978
  "license": "UNLICENSED",
11979
11979
  "dependencies": {
11980
- "@north-light/api": "0.3.633",
11981
- "@north-light/identity": "0.3.633"
11980
+ "@north-light/api": "0.3.634",
11981
+ "@north-light/identity": "0.3.634"
11982
11982
  }
11983
11983
  },
11984
11984
  "packages/crouter-sdk": {
11985
11985
  "name": "@north-light/sdk",
11986
- "version": "0.3.633",
11986
+ "version": "0.3.634",
11987
11987
  "license": "UNLICENSED",
11988
11988
  "dependencies": {
11989
- "@north-light/api": "0.3.633",
11990
- "@north-light/identity": "0.3.633",
11991
- "@north-light/plugin": "0.3.633",
11989
+ "@north-light/api": "0.3.634",
11990
+ "@north-light/identity": "0.3.634",
11991
+ "@north-light/plugin": "0.3.634",
11992
11992
  "jose": "^6.2.1"
11993
11993
  },
11994
11994
  "bin": {