@lunora/cli 1.0.0-alpha.21 → 1.0.0-alpha.210

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 (110) hide show
  1. package/LICENSE.md +33 -0
  2. package/README.md +1 -1
  3. package/__assets__/package-og.svg +1 -1
  4. package/dist/bin.mjs +2 -10
  5. package/dist/index.d.mts +731 -341
  6. package/dist/index.d.ts +731 -341
  7. package/dist/index.mjs +1 -19
  8. package/dist/packem_chunks/handler.mjs +1 -150
  9. package/dist/packem_chunks/handler10.mjs +4 -22
  10. package/dist/packem_chunks/handler11.mjs +2 -192
  11. package/dist/packem_chunks/handler12.mjs +1 -131
  12. package/dist/packem_chunks/handler13.mjs +1 -65
  13. package/dist/packem_chunks/handler14.mjs +1 -58
  14. package/dist/packem_chunks/handler15.mjs +1 -79
  15. package/dist/packem_chunks/handler16.mjs +3 -43
  16. package/dist/packem_chunks/handler17.mjs +1 -105
  17. package/dist/packem_chunks/handler18.mjs +1 -170
  18. package/dist/packem_chunks/handler19.mjs +7 -89
  19. package/dist/packem_chunks/handler2.mjs +2 -114
  20. package/dist/packem_chunks/handler20.mjs +1 -94
  21. package/dist/packem_chunks/handler21.mjs +2 -311
  22. package/dist/packem_chunks/handler22.mjs +3 -0
  23. package/dist/packem_chunks/handler23.mjs +3 -0
  24. package/dist/packem_chunks/handler24.mjs +1 -0
  25. package/dist/packem_chunks/handler25.mjs +99 -0
  26. package/dist/packem_chunks/handler26.mjs +10 -0
  27. package/dist/packem_chunks/handler3.mjs +1 -204
  28. package/dist/packem_chunks/handler4.mjs +1 -33
  29. package/dist/packem_chunks/handler5.mjs +1 -49
  30. package/dist/packem_chunks/handler6.mjs +1 -91
  31. package/dist/packem_chunks/handler7.mjs +3 -42
  32. package/dist/packem_chunks/handler8.mjs +1 -174
  33. package/dist/packem_chunks/handler9.mjs +1 -16
  34. package/dist/packem_chunks/planDevCommand.mjs +7 -500
  35. package/dist/packem_chunks/runCodegenCommand.mjs +4 -52
  36. package/dist/packem_chunks/runDeployCommand.mjs +1 -504
  37. package/dist/packem_chunks/runInitCommand.mjs +118 -1383
  38. package/dist/packem_chunks/runMigrateGenerateCommand.mjs +9 -395
  39. package/dist/packem_chunks/runResetCommand.mjs +1 -41
  40. package/dist/packem_chunks/runRpcCommand.mjs +1 -68
  41. package/dist/packem_shared/COMMANDS-BKhYrmpZ.mjs +1 -0
  42. package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Nf7GsE6v.mjs +1 -0
  43. package/dist/packem_shared/admin-token-rxXZbVMZ.mjs +1 -0
  44. package/dist/packem_shared/admin-url-Cil3Or6N.mjs +1 -0
  45. package/dist/packem_shared/advisory-gate-Cl8IEFIj.mjs +1 -0
  46. package/dist/packem_shared/api-spec-lYyq4vL6.mjs +1 -0
  47. package/dist/packem_shared/binding-manifest-file-CQ1eQYy1.mjs +2 -0
  48. package/dist/packem_shared/buildRegistryIndex-Zi3bBqpc.mjs +1 -0
  49. package/dist/packem_shared/cli-CrC0a7dH.mjs +3 -0
  50. package/dist/packem_shared/codegen-error-AmH54ofi.mjs +3 -0
  51. package/dist/packem_shared/command-DwC11Cwe.mjs +1 -0
  52. package/dist/packem_shared/commands-BNKj7r1R.mjs +19 -0
  53. package/dist/packem_shared/createLogger-hGafwf-3.mjs +2 -0
  54. package/dist/packem_shared/createRecordingSpawner-DJlNacZ6.mjs +1 -0
  55. package/dist/packem_shared/deploy-target-D9GPy_tq.mjs +1 -0
  56. package/dist/packem_shared/diffSnapshots-CIOFQN_a.mjs +5 -0
  57. package/dist/packem_shared/docker-DpVxvYpL.mjs +1 -0
  58. package/dist/packem_shared/import-CrVGrOt3.mjs +12 -0
  59. package/dist/packem_shared/insertSchemaExtension-DY4pA8wE.mjs +8 -0
  60. package/dist/packem_shared/lint-ignore-report-DKZagpqk.mjs +2 -0
  61. package/dist/packem_shared/open-url-EnKy--w-.mjs +1 -0
  62. package/dist/packem_shared/output-format-DfogXx0p.mjs +2 -0
  63. package/dist/packem_shared/parseManifest-CwPTKdtS.mjs +1 -0
  64. package/dist/packem_shared/path-containment-CgxYZggb.mjs +1 -0
  65. package/dist/packem_shared/platform-diagnostics-uOXqysk3.mjs +4 -0
  66. package/dist/packem_shared/prompt-cancelled-C8Sj7OqI.mjs +1 -0
  67. package/dist/packem_shared/resolve-DZAGzg67.mjs +1 -0
  68. package/dist/packem_shared/resolve-target-BRvw8Pf7.mjs +1 -0
  69. package/dist/packem_shared/runAddCommand-D1Dj8-pK.mjs +1 -0
  70. package/dist/packem_shared/runExportCommand-DmXKEWSq.mjs +5 -0
  71. package/dist/packem_shared/schema-drift-gate-DARCKocg.mjs +1 -0
  72. package/dist/packem_shared/schemaIrToSnapshot-qpRoV7HY.mjs +1 -0
  73. package/dist/packem_shared/shared-D-zCOmgY.mjs +1 -0
  74. package/dist/packem_shared/storage-wIUel5Az.mjs +1 -0
  75. package/dist/packem_shared/tui-prompts-Dd0pDuNr.mjs +4 -0
  76. package/dist/packem_shared/vectorize-metadata-DbziRKpX.mjs +1 -0
  77. package/dist/packem_shared/wrangler-name-Dsk5K1f-.mjs +1 -0
  78. package/dist/packem_shared/wrangler-secrets-CCdt0mUl.mjs +1 -0
  79. package/package.json +39 -17
  80. package/skills/README.md +35 -17
  81. package/skills/lunora/SKILL.md +65 -9
  82. package/skills/lunora-functions/SKILL.md +38 -3
  83. package/skills/lunora-migration-helper/SKILL.md +70 -17
  84. package/skills/lunora-performance-audit/SKILL.md +36 -6
  85. package/skills/lunora-quickstart/SKILL.md +90 -24
  86. package/skills/lunora-realtime/SKILL.md +58 -30
  87. package/dist/packem_shared/COMMANDS-D3h9Iwvl.mjs +0 -944
  88. package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Ck-2bU08.mjs +0 -244
  89. package/dist/packem_shared/admin-url-4UzT-CI4.mjs +0 -19
  90. package/dist/packem_shared/api-spec-CtA6ilu4.mjs +0 -13
  91. package/dist/packem_shared/buildRegistryIndex-BcYe607_.mjs +0 -38
  92. package/dist/packem_shared/command-BC30oSBW.mjs +0 -14
  93. package/dist/packem_shared/commands-hl0mRqqg.mjs +0 -845
  94. package/dist/packem_shared/createLogger-B40gPzQo.mjs +0 -78
  95. package/dist/packem_shared/createRecordingSpawner-DxI3mebw.mjs +0 -43
  96. package/dist/packem_shared/detect-package-manager-DYp7n3mJ.mjs +0 -61
  97. package/dist/packem_shared/diffSnapshots-BeDvvNiF.mjs +0 -161
  98. package/dist/packem_shared/docker-hMQ97KSQ.mjs +0 -21
  99. package/dist/packem_shared/insertSchemaExtension-DAqbfr9Z.mjs +0 -64
  100. package/dist/packem_shared/open-url-Dfq6fAyT.mjs +0 -41
  101. package/dist/packem_shared/output-format-wUvAN6AL.mjs +0 -17
  102. package/dist/packem_shared/parseArgs-YXFuKdEk.mjs +0 -56
  103. package/dist/packem_shared/parseManifest--vZf2FY1.mjs +0 -94
  104. package/dist/packem_shared/resolve-target-qbsJ_5sF.mjs +0 -16
  105. package/dist/packem_shared/runAddCommand-vJdgiR5t.mjs +0 -4
  106. package/dist/packem_shared/schema-drift-gate-BtBt0as0.mjs +0 -79
  107. package/dist/packem_shared/schemaIrToSnapshot-DdsljJT-.mjs +0 -43
  108. package/dist/packem_shared/storage-B7hHSTZP.mjs +0 -84
  109. package/dist/packem_shared/tui-prompts-M6OWsuyw.mjs +0 -663
  110. package/dist/packem_shared/wrangler-name-cy4yhm9j.mjs +0 -12
@@ -0,0 +1,4 @@
1
+ import{jsx as n,jsxs as a}from"react/jsx-runtime";import{isInteractive as m,ACCENT as w,LUNA_ART as ce,LUNA_NAME as le,LUNA_SIGNOFF as se,BADGE_COLUMN_WIDTH as z,badgeWidth as J,badgeLead as ae,padBadge as ue}from"@lunora/config";import{render as H}from"@visulima/tui";import{Box as u}from"@visulima/tui/components/box";import{Text as l}from"@visulima/tui/components/text";import{useApp as I}from"@visulima/tui/hooks/use-app";import{useInput as B}from"@visulima/tui/hooks/use-input";import{useInterval as de}from"@visulima/tui/hooks/use-interval";import{CommandPalette as fe}from"@visulima/tui-kit/command-palette";import{ConfirmInput as he}from"@visulima/tui-kit/confirm-input";import{SelectInput as me}from"@visulima/tui-kit/select-input";import{Spinner as pe}from"@visulima/tui-kit/spinner";import{TextInput as ve}from"@visulima/tui-kit/text-input";import{useState as S,useEffect as A}from"react";import{P as K}from"./prompt-cancelled-C8Sj7OqI.mjs";let j=!1;const V=()=>{j||(j=!0,process.getMaxListeners()<64&&process.setMaxListeners(64))},we=({children:e,onCancel:r})=>{const{exit:t}=I();return B((i,o)=>{o.ctrl&&i==="c"&&(r(),t())}),e},Q=e=>e instanceof Error?e:new Error(typeof e=="string"?e:"task failed"),Z=10,xe=8,ee=({spec:e})=>a(l,{children:[n(l,{children:ae(e.text)}),n(l,{backgroundColor:e.bg,bold:!0,color:e.fg,children:ue(e.text)})]}),$=({badge:e,message:r})=>e===void 0?n(l,{bold:!0,children:r}):a(u,{children:[n(ee,{spec:e}),n(l,{bold:!0,children:` ${r}`})]}),re=2,T=" ".repeat(z-1),te=e=>" ".repeat(J(e)+1),Ce=e=>e===void 0?re:J(e)+1,D=({badge:e,children:r,message:t})=>a(u,{flexDirection:"column",children:[n($,{badge:e,message:t}),n(u,{flexDirection:"column",marginLeft:Ce(e),children:r})]}),g=({answer:e,badge:r,message:t})=>a(u,{flexDirection:"column",children:[n($,{badge:r,message:t}),e===""?null:n(l,{dimColor:!0,children:`${r===void 0?" ".repeat(re):te(r)}${e}`})]}),R=e=>{const{exit:r}=I(),[t,i]=S(void 0);return A(()=>{t!==void 0&&r()},[t,r]),{answer:t,submit:(o,c)=>{e(o),i(c)}}},Se=({children:e})=>{const{exit:r}=I();return A(()=>{r()},[r]),e},N=async e=>{V(),process.stdout.write(`
2
+ `);const r=H(n(Se,{children:e}));try{await r.waitUntilExit()}catch{}finally{r.unmount()}},Ze=async(e,r,t)=>{if(!m())return;const i=t===void 0||t===""?[]:t.split(`
3
+ `);await N(a(u,{flexDirection:"column",children:[n($,{badge:e,message:r}),i.map(o=>n(l,{dimColor:!0,children:`${te(e)}${o}`},o))]}))},G=async e=>{V(),process.stdout.write(`
4
+ `);const r={value:!1},t=H(n(we,{onCancel:()=>{r.value=!0},children:e}),{exitOnCtrlC:!1});try{await t.waitUntilExit()}finally{t.unmount()}if(r.value)throw new K},E=async(e,r)=>{let t=r;return await G(e(i=>{t=i})),t},ne=e=>e.description===void 0?e.label:`${e.label} — ${e.description}`,U=()=>{const{exit:e}=I();B((r,t)=>{t.escape&&e()})},Ie=({badge:e,finish:r,initialIndex:t,message:i,options:o})=>{const{answer:c,submit:d}=R(r);return U(),c!==void 0?n(g,{answer:c,badge:e,message:i}):n(D,{badge:e,message:i,children:n(me,{accentColor:w,initialIndex:t,items:o.map(s=>({key:s.value,label:ne(s),value:s.value})),limit:Z,onSelect:s=>{d(s.value,o.find(f=>f.value===s.value)?.label??s.value)}})})},be=({badge:e,finish:r,message:t,options:i})=>{const{exit:o}=I(),{answer:c,submit:d}=R(r);return c!==void 0?n(g,{answer:c,badge:e,message:t}):n(D,{badge:e,message:t,children:n(fe,{accentColor:w,autoFocus:!0,commands:i.map(s=>({description:s.description,id:s.value,label:s.label})),limit:Z,onCancel:()=>{o()},onSelect:s=>{d(s,i.find(f=>f.value===s)?.label??s)},placeholder:"Type to filter…"})})},er=async(e,r,t)=>{if(!m()||r.length===0)return t?.default;const{badge:i}=t??{};if(r.length>xe)return E(c=>n(be,{badge:i,finish:c,message:e,options:r}),t?.default);const o=t?.default===void 0?-1:r.findIndex(c=>c.value===t.default);return E(c=>n(Ie,{badge:i,finish:c,initialIndex:o>=0?o:void 0,message:e,options:r}),t?.default)},Te=({badge:e,defaultValue:r,finish:t,message:i,placeholder:o})=>{const{answer:c,submit:d}=R(t);return U(),c!==void 0?n(g,{answer:c,badge:e,message:i}):n(D,{badge:e,message:i,children:n(ve,{defaultValue:r,onSubmit:s=>{const f=s.trim()===""?r:s.trim();d(f,f)},placeholder:o})})},rr=async(e,r)=>{const t=r?.default??"";if(!m())return t;const{badge:i}=r??{};return E(o=>n(Te,{badge:i,defaultValue:t,finish:o,message:e,placeholder:r?.placeholder}),t)},Ne=({badge:e,defaults:r,finish:t,message:i,options:o})=>{const{answer:c,submit:d}=R(t),[s,f]=S(0),[p,x]=S(()=>new Set(r));return U(),B((b,v)=>{if(!(c!==void 0||o.length===0)){if(v.upArrow)f(h=>(h-1+o.length)%o.length);else if(v.downArrow)f(h=>(h+1)%o.length);else if(b===" "){const h=o[s];h!==void 0&&x(C=>{const _=new Set(C);return _.has(h.value)?_.delete(h.value):_.add(h.value),_})}else if(v.return){const h=o.filter(C=>p.has(C.value));d(h.map(C=>C.value),h.length>0?h.map(C=>C.label).join(", "):"none")}}}),c!==void 0?n(g,{answer:c,badge:e,message:i}):n(D,{badge:e,message:i,children:a(u,{flexDirection:"column",children:[n(l,{dimColor:!0,children:"space toggles · enter confirms · esc cancels"}),o.map((b,v)=>{const h=v===s;return n(l,{color:h?w:void 0,children:`${h?"▸ ":" "}${p.has(b.value)?"◼":"◻"} ${ne(b)}`},b.value)})]})})},tr=async(e,r,t)=>{const i=t?.defaults??[];if(!m()||r.length===0)return[...i];const{badge:o}=t??{};return E(c=>n(Ne,{badge:o,defaults:i,finish:c,message:e,options:r}),[...i])},ye=({badge:e,defaultYes:r,finish:t,message:i})=>{const{answer:o,submit:c}=R(t);return o!==void 0?n(g,{answer:o,badge:e,message:i}):a(u,{children:[e===void 0?null:n(ee,{spec:e}),n(l,{bold:!0,children:e===void 0?`${i} `:` ${i} `}),n(he,{defaultChoice:r?"confirm":"cancel",onCancel:()=>{c(!1,"No")},onConfirm:()=>{c(!0,"Yes")}})]})},Ee=async(e,r)=>{const t=r?.defaultYes===!0;if(!m())return t;const{badge:i}=r??{};return E(o=>n(ye,{badge:i,defaultYes:t,finish:o,message:e}),!1)},nr=()=>m()?e=>Ee(e,{defaultYes:!0}):()=>Promise.resolve(!1),W="#c8a8ff",L="#d9c8ff",$e="#6b5b9a",P=({moon:e,prefix:r,suffix:t})=>a(u,{children:[n(l,{color:W,dimColor:!0,children:r}),typeof e=="string"?n(l,{color:L,children:e}):e,t===void 0?null:n(l,{color:W,children:t})]}),X=({left:e,right:r})=>a(l,{color:L,children:[e,n(l,{color:$e,children:"●●"}),r]}),ge=()=>a(u,{flexDirection:"column",paddingX:1,children:[n(P,{moon:".-‐-.",prefix:"· ✦ · ",suffix:" ✦"}),n(P,{moon:n(X,{left:"/",right:"\\"}),prefix:" ✦ · ",suffix:" ·"}),n(P,{moon:n(X,{left:"\\",right:"/"}),prefix:" . ✦ · "}),a(u,{children:[n(l,{bold:!0,color:w,children:" lunora init "}),n(l,{dimColor:!0,children:"· moonrise sequence"}),n(l,{color:L})]})]}),or=async e=>{m()&&await N(a(u,{flexDirection:"column",children:[n(ge,{}),n(u,{paddingX:1,children:n(l,{dimColor:!0,children:e})})]}))},Re=({label:e})=>a(u,{children:[n(l,{color:w,children:n(pe,{type:"dots"})}),a(l,{children:[" ",e]})]}),ir=async(e,r)=>{if(!m())return r();V();const t=H(n(Re,{label:e}));try{return await r()}finally{t.unmount()}},cr=async()=>{m()&&await N(a(u,{paddingX:1,children:[n(l,{color:L,children:ce}),a(u,{flexDirection:"column",marginLeft:2,children:[n(l,{bold:!0,color:w,children:le}),n(l,{children:se})]})]}))},_e="#06b6d4",k=" ".repeat(9),lr=async e=>{m()&&await N(n(l,{bold:!0,children:`${k}${e}`}))},sr=async e=>{m()&&await N(a(u,{children:[n(l,{color:_e,children:`${T}◼`}),n(l,{children:` ${e}`})]}))},ar=async(e,r,t,i)=>{m()&&await N(a(u,{flexDirection:"column",children:[n($,{badge:e,message:r}),n(u,{flexDirection:"column",marginTop:1,children:t.map(o=>a(l,{children:[`${k}${o.lead} `,n(l,{color:w,children:o.code}),o.tail??""]},o.lead))}),n(u,{flexDirection:"column",marginTop:1,children:i.map(o=>a(l,{children:[`${k}${o.lead} `,n(l,{color:w,children:o.code}),o.tail??""]},o.lead))})]}))},Y="#a855f7",oe="#06b6d4",y=[Y,"#9b51f6","#8a5cf6","#6f86f6","#4aa6ef","#2bb6dd","#12bcd0",oe],O=y.length-2,F=(e,r)=>Array.from({length:Math.max(0,e)},()=>r),q=[...F(y.length-1,Y),...y,...F(y.length-1,oe),...y.toReversed()],M=q.map((e,r)=>{const t=q.slice(r,r+O);return[...t,...F(O-t.length,Y)]}),Ae=" ".repeat(Math.max(0,z-O)),ie=({label:e})=>{const[r,t]=S(0);de(()=>{t(o=>(o+1)%M.length)},90);const i=M[r%M.length]??[];return a(l,{children:[Ae,i.map((o,c)=>n(l,{color:o,children:"█"},c)),` ${e}`]})},De=({label:e,status:r})=>r==="running"?n(l,{color:w,children:`${T}▶ ${e}`}):r==="failed"?n(l,{color:"red",children:`${T}✖ ${e}`}):r==="done"?n(l,{dimColor:!0,children:`${T}■ ${e}`}):n(l,{dimColor:!0,children:`${T}□ ${e}`}),Le=async(e,r)=>{const t=[];let i;for(const[o,c]of e.entries()){r(o,"running");try{t.push(await c.run()),r(o,"done")}catch(d){r(o,"failed"),i=d;break}}return{failure:i,results:t}},Pe=(e,r,t,i)=>{let o=!0;return Le(e,(d,s)=>{o&&r(f=>f.map((p,x)=>x===d?s:p))}).then(({failure:d,results:s})=>{setTimeout(()=>{o&&(t(s,d),i())},400)}).catch(()=>{}),()=>{o=!1}},Me=({end:e,onSettle:r,start:t,tasks:i})=>{const{exit:o}=I(),[c,d]=S(()=>i.map(()=>"pending"));A(()=>Pe(i,d,r,o),[o,r,i]);const s=c.length>0&&c.every(f=>f==="done");return a(u,{flexDirection:"column",children:[s?a(u,{children:[n(l,{bold:!0,color:"green",children:`${T}✔`}),n(l,{bold:!0,color:"green",children:` ${e}`})]}):n(ie,{label:t}),i.map((f,p)=>n(De,{label:f.label,status:c[p]??"pending"},f.label))]})},ur=async(e,r)=>{if(!m()){const o=[];for(const c of e)o.push(await c.run());return o}let t=[],i;if(await G(n(Me,{end:r.end,onSettle:(o,c)=>{t=o,i=c},start:r.start,tasks:e})),i!==void 0)throw Q(i);return t},ke=async(e,r)=>{const t=[];let i;for(const[o,c]of e.entries()){r(o);try{t.push(await c.task())}catch(d){i=d;break}}return{failure:i,values:t}},Oe=({badge:e,done:r,onSettle:t,steps:i})=>{const{exit:o}=I(),[c,d]=S(0),[s,f]=S(!1);return A(()=>{let p=!0,x;return ke(i,v=>{p&&d(v)}).then(({failure:v,values:h})=>{if(p){if(v!==void 0){t({error:v,ok:!1}),o();return}f(!0),x=setTimeout(()=>{p&&(t({ok:!0,values:h}),o())},400)}}).catch(()=>{}),()=>{p=!1,x!==void 0&&clearTimeout(x)}},[o,t,i]),s?n($,{badge:e,message:r}):n(ie,{label:i[c]?.running??""})},dr=async(e,r,t)=>{if(!m()){const o=[];for(const c of r)o.push(await c.task());return o}let i;if(await G(n(Oe,{badge:e,done:t,onSettle:o=>{i=o},steps:r})),i===void 0)throw new K;if(!i.ok)throw Q(i.error);return i.values};export{rr as a,Ee as b,nr as c,cr as d,Ze as e,or as f,tr as g,lr as h,sr as i,ar as j,ur as k,dr as l,er as t,ir as w};
@@ -0,0 +1 @@
1
+ const p=/(?:key|password|secret|token)$/iu,x=e=>p.test(e),g=e=>{switch(e){case"boolean":return"boolean";case"date":case"number":case"timestamp":return"number";case"id":case"literal":case"string":return"string";default:return}},l=/already (?:exists|indexed)|duplicate/iu,i=e=>["vectorize","create-metadata-index",e.index,`--property-name=${e.property}`,`--type=${e.type}`],m=async(e,n)=>{try{return await e(n)}catch(r){return{code:1,stderr:r instanceof Error?r.message:String(r)}}},y=async e=>{const{cwd:n,entries:r,exec:o,logger:d,spawner:u}=e,s=[];for(const t of r){const a=await m(u,{args:[...o.args,...i(t)],captureStderr:!0,command:o.command,cwd:n,stdoutToStderr:!0});if(a.code===0){s.push({entry:t,status:"created"});continue}const c=`${a.stderr??""}${a.stdout??""}`;if(l.test(c)){s.push({entry:t,status:"exists"});continue}s.push({entry:t,error:c.trim()||`exit code ${String(a.code)}`,status:"failed"}),d.warn(`could not create the Vectorize metadata index for "${t.property}" on "${t.index}" — filters on that property will match nothing until it exists. Run: wrangler ${i(t).join(" ")}`)}return s};export{i as c,y as e,x as i,g as m};
@@ -0,0 +1 @@
1
+ import{findWranglerFile as a,readWranglerJsonc as t}from"@lunora/config/cloudflare";const i=n=>{const e=a(n);if(!e)return;const{parsed:r}=t(e);return typeof r?.name=="string"&&r.name.length>0?r.name:void 0};export{i as r};
@@ -0,0 +1 @@
1
+ import{resolveDeployDriver as c,resolveProjectTarget as d,execArgsFor as l,detectPackageManager as i}from"@lunora/config";import{defaultSpawner as m}from"./createRecordingSpawner-DJlNacZ6.mjs";const u=async(e,t,o)=>{try{const r=await m({args:t,captureStderr:!0,captureStdoutSilently:!0,command:e,cwd:o});return{code:r.code,stderr:r.stderr??"",stdout:r.stdout??""}}catch(r){return{code:1,stderr:r instanceof Error?r.message:String(r),stdout:""}}},f=e=>{let t;try{t=JSON.parse(e)}catch{return}return Array.isArray(t)?[...t.map(r=>r!==null&&typeof r=="object"?r.name:void 0).filter(r=>typeof r=="string"&&r.length>0)].toSorted((r,n)=>r.localeCompare(n)):void 0},y=async e=>{const t=c(d(e.cwd)).toolchain?.secretList({environment:e.env,temporary:e.temporary});if(t===void 0)return{error:"deploy target has no command-line toolchain",names:[],ok:!1};const{args:o,command:r}=l(i(e.cwd),t.tool,t.args),a=await(e.runner??u)(r,o,e.cwd);if(a.code!==0)return{error:a.stderr.trim()||`wrangler secret list exited ${String(a.code)}`,names:[],ok:!1};const s=f(a.stdout);return s===void 0?{error:"could not parse `wrangler secret list --format json` output",names:[],ok:!1}:{names:s,ok:!0}};export{y as l};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lunora/cli",
3
- "version": "1.0.0-alpha.21",
4
- "description": "The Lunora CLI: init, dev, deploy, codegen, run, reset, and migrate commands",
3
+ "version": "1.0.0-alpha.210",
4
+ "description": "The Lunora CLI: init, dev, deploy, codegen, migrate, seed, doctor, insights, logs, registry, and the rest of the project commands",
5
5
  "keywords": [
6
6
  "agent-skills",
7
7
  "cli",
@@ -51,26 +51,48 @@
51
51
  "access": "public"
52
52
  },
53
53
  "dependencies": {
54
- "@bomb.sh/tab": "0.0.16",
55
- "@lunora/codegen": "1.0.0-alpha.7",
56
- "@lunora/config": "1.0.0-alpha.11",
57
- "@lunora/container": "1.0.0-alpha.1",
58
- "@lunora/d1": "1.0.0-alpha.4",
59
- "@lunora/seed": "1.0.0-alpha.2",
60
- "@visulima/cerebro": "3.0.0-alpha.32",
61
- "@visulima/fs": "5.0.0-alpha.32",
62
- "@visulima/pail": "4.0.0-alpha.22",
63
- "@visulima/path": "3.0.0-alpha.13",
64
- "@visulima/spinner": "1.0.0-alpha.4",
65
- "@visulima/tui": "1.0.0-alpha.26",
54
+ "@bomb.sh/tab": "0.0.22",
55
+ "@lunora/advisor": "1.0.0-alpha.100",
56
+ "@lunora/bindings": "1.0.0-alpha.42",
57
+ "@lunora/codegen": "1.0.0-alpha.143",
58
+ "@lunora/config": "1.0.0-alpha.177",
59
+ "@lunora/container": "1.0.0-alpha.37",
60
+ "@lunora/d1": "1.0.0-alpha.98",
61
+ "@lunora/errors": "1.0.0-alpha.26",
62
+ "@lunora/mcp": "1.0.0-alpha.100",
63
+ "@lunora/runtime": "1.0.0-alpha.83",
64
+ "@lunora/seed": "1.0.0-alpha.95",
65
+ "@visulima/cerebro": "3.0.6",
66
+ "@visulima/error": "6.1.0",
67
+ "@visulima/fs": "6.0.0",
68
+ "@visulima/pail": "4.1.1",
69
+ "@visulima/path": "4.0.0",
70
+ "@visulima/spinner": "1.0.1",
71
+ "@visulima/tui": "4.0.0",
72
+ "@visulima/tui-kit": "1.0.3",
73
+ "adm-zip": "0.6.0",
66
74
  "cfonts": "^3.3.1",
67
- "giget": "3.3.0",
75
+ "csv-parse": "7.0.2",
76
+ "giget": "3.3.1",
68
77
  "jsonc-parser": "^3.3.1",
69
- "magic-string": "^0.30.21",
70
- "react": "^19.2.7",
78
+ "magic-string": "^1.1.0",
79
+ "react": "^19.2.8",
71
80
  "react-reconciler": "^0.33.0",
81
+ "smol-toml": "1.7.1",
72
82
  "ts-morph": "^28.0.0"
73
83
  },
84
+ "peerDependencies": {
85
+ "mysql2": "*",
86
+ "pg": "*"
87
+ },
88
+ "peerDependenciesMeta": {
89
+ "mysql2": {
90
+ "optional": true
91
+ },
92
+ "pg": {
93
+ "optional": true
94
+ }
95
+ },
74
96
  "engines": {
75
97
  "node": "^22.15.0 || >=24.11.0"
76
98
  }
package/skills/README.md CHANGED
@@ -9,21 +9,39 @@ framework correctly. They ship inside `@lunora/cli` and are discovered by the
9
9
  Each skill is a `SKILL.md` with YAML frontmatter (`name`, `description`) in its
10
10
  own directory:
11
11
 
12
- | Skill | Use for |
13
- | -------------------------- | --------------------------------------------------------------------------- |
14
- | `lunora` | Router — start here, then switch to the matching skill below. |
15
- | `lunora-quickstart` | `lunora init` / adding Lunora to an app + first round-trip. |
16
- | `lunora-functions` | Core authoring rules — schema, validators, query/mutation/action, `ctx.db`. |
17
- | `lunora-realtime` | Client reactivity — live hooks, optimistic updates, `@lunora/db`. |
18
- | `lunora-setup-auth` | Authentication via `lunora registry add auth` (+ providers). |
19
- | `lunora-setup-mail` | Transactional email via `lunora registry add mail` — `sendEmail` actions. |
20
- | `lunora-setup-storage` | R2 file storage via `lunora registry add storage` — signed upload/download. |
21
- | `lunora-setup-scheduler` | Deferred (`ctx.scheduler`) + cron jobs (`lunora registry add crons`). |
22
- | `lunora-create-package` | Building a reusable registry item or `@lunora/*` package. |
23
- | `lunora-migration-helper` | Schema/data migrations, `.global()` D1 flow, the drift gate. |
24
- | `lunora-deploy` | Deploying to Cloudflare wrangler bindings, secrets, the gate. |
25
- | `lunora-performance-audit` | Scans, indexes, OCC write conflicts, sharding/`.global()`. |
12
+ | Skill | Use for |
13
+ | -------------------------------- | ---------------------------------------------------------------------------- |
14
+ | `lunora` | Router — start here, then switch to the matching skill below. |
15
+ | `lunora-quickstart` | `lunora init` / adding Lunora to an app + first round-trip. |
16
+ | `lunora-functions` | Core authoring rules — schema, validators, query/mutation/action, `ctx.db`. |
17
+ | `lunora-realtime` | Client reactivity — live hooks, optimistic updates, `@lunora/db`. |
18
+ | `lunora-setup-auth` | Authentication via `lunora registry add auth` (+ providers). |
19
+ | `lunora-setup-mail` | Transactional email via `lunora registry add mail` — `sendEmail` actions. |
20
+ | `lunora-setup-storage` | R2 file storage via `lunora registry add storage` — signed upload/download. |
21
+ | `lunora-setup-scheduler` | Deferred (`ctx.scheduler`) + cron jobs (`lunora registry add crons`). |
22
+ | `lunora-setup-hyperdrive` | Existing Postgres/MySQL from an action `ctx.sql`, non-reactive. |
23
+ | `lunora-setup-hyperdrive-global` | Postgres/MySQL as a reactive `.global()` backend; D1 Hyperdrive migration. |
24
+ | `lunora-create-package` | Building a reusable registry item or `@lunora/*` package. |
25
+ | `lunora-migration-helper` | Schema/data migrations, `.global()` DDL flow, the drift gate. |
26
+ | `lunora-deploy` | Deploying to Cloudflare — wrangler bindings, secrets, the gate. |
27
+ | `lunora-performance-audit` | `lunora insights`, scans, indexes, OCC conflicts, sharding/`.global()`. |
26
28
 
27
- These are mirrored into `.agents/skills/` and `.claude/skills/` (via symlinks)
28
- so agents working inside this repo pick them up directly. The source of truth
29
- lives here so the published `@lunora/cli` tarball carries them.
29
+ These are mirrored (via symlinks) into `.agents/skills/` and `.claude/skills/`,
30
+ so agents working inside this repo pick them up directly, and into
31
+ `plugins/lunora/skills/`, the payload of the Claude Code / Codex plugin. The
32
+ source of truth lives here so the published `@lunora/cli` tarball carries them —
33
+ `lunora rules install` copies this directory into a consumer project.
34
+
35
+ **Adding a skill?** Create it here, then mirror it through all three hops:
36
+
37
+ ```bash
38
+ ln -s ../../packages/cli/skills/<name> .agents/skills/<name>
39
+ ln -s ../../.agents/skills/<name> .claude/skills/<name>
40
+ ln -s ../../../packages/cli/skills/<name> plugins/lunora/skills/<name>
41
+ ```
42
+
43
+ `scripts/check-skill-mirrors.js` (run on every `pnpm install`) fails if a mirror
44
+ is missing, dangling, or has become a real directory — a copied directory keeps
45
+ resolving while it silently drifts from the source, so it is treated as an
46
+ error rather than a warning. Forget a hop and it prints the exact `ln -s` for
47
+ the one you missed, so `pnpm install` is the shortest path to the right command.
@@ -14,8 +14,9 @@ Lunora exposes a Convex-style functional API (`defineSchema`, `query`,
14
14
  `mutation`, `action`) on top of Cloudflare Workers and Durable Objects. State
15
15
  lives in a per-app `ShardDO` (SQLite, OCC, hibernated WebSocket subscriptions)
16
16
  by default; `.shardBy(key)` partitions it across many DOs and `.global()`
17
- replicates a table to D1 for low-latency cross-region reads. A Vite plugin
18
- drives codegen and end-to-end type sync.
17
+ replicates a table to D1 or to Postgres/MySQL over Hyperdrive — for
18
+ low-latency cross-region reads. A Vite plugin drives codegen and end-to-end
19
+ type sync.
19
20
 
20
21
  If a more specific Lunora skill clearly matches the request, use that instead.
21
22
 
@@ -47,12 +48,13 @@ After codegen is green, use the most specific Lunora skill for the task:
47
48
  - Wiring live data into a client (hooks, optimistic updates): `lunora-realtime`
48
49
  - Authentication setup (email/password, OAuth, magic link, OTP):
49
50
  `lunora-setup-auth`
50
- - Wiring a prebuilt capability (mail, file storage, scheduled jobs, rate
51
- limiting, vectors, AI, containers, payments, MCP): install it with
52
- `lunora registry add <item>` (see `lunora registry list`). Capabilities with a
53
- dedicated skill: `lunora-setup-mail` (mail), `lunora-setup-storage` (R2 file
54
- storage), `lunora-setup-scheduler` (deferred `ctx.scheduler` + cron jobs). For
55
- the rest, read the item's README after installing.
51
+ - Transactional email: `lunora-setup-mail`
52
+ - R2 file storage (signed upload/download): `lunora-setup-storage`
53
+ - Deferred work (`ctx.scheduler`) and cron jobs: `lunora-setup-scheduler`
54
+ - Querying an **existing** Postgres/MySQL database from an action (`ctx.sql`,
55
+ non-reactive): `lunora-setup-hyperdrive`
56
+ - Using Postgres/MySQL as a **reactive `.global()` backend**, or migrating a D1
57
+ `.global()` dataset onto it: `lunora-setup-hyperdrive-global`
56
58
  - Building a reusable capability — a registry item or an `@lunora/*` package:
57
59
  `lunora-create-package`
58
60
  - Planning or running a schema/data migration: `lunora-migration-helper`
@@ -61,9 +63,61 @@ After codegen is green, use the most specific Lunora skill for the task:
61
63
  - Investigating performance, scan, or write-conflict issues:
62
64
  `lunora-performance-audit`
63
65
 
66
+ **Reviewing or auditing existing `lunora/` code** has no skill of its own,
67
+ because two commands do the work mechanically — run them before reading
68
+ anything:
69
+
70
+ ```bash
71
+ lunora verify # wrangler config + codegen dry-run + tsc --noEmit
72
+ lunora advisor # the static + runtime lint set, scored per procedure
73
+ ```
74
+
75
+ `lunora advisor` is the security/quality review: RLS coverage, ownership and
76
+ identity checks, fail-open guards, input validators, unindexed reads,
77
+ non-deterministic calls in queries, SQL interpolation, and leaked secrets. It
78
+ prints each finding's own lint id and category, so read its output rather than
79
+ grepping for rule names. Use `--entry <file>#<export>` to inspect one procedure
80
+ and `--min-score` / `--baseline` to gate CI. Only after it is clean is a by-hand
81
+ pass over `lunora-functions` worth the tokens.
82
+
64
83
  If one of those clearly matches the user's goal, switch to it instead of staying
65
84
  in this skill.
66
85
 
86
+ ## Capabilities Without a Dedicated Skill
87
+
88
+ Most other capabilities install as a **registry item** — `lunora registry add
89
+ <item>` scaffolds the `lunora/` glue, wrangler bindings, and env vars, then
90
+ prints post-install steps. Browse with `lunora registry list`; preview with
91
+ `lunora registry view <item>`. Read the installed item's README, and the
92
+ package's `docs/` for the API.
93
+
94
+ | Goal | Install / package |
95
+ | --------------------------------------------- | ------------------------------------------------------------ |
96
+ | Background jobs on Cloudflare Queues | `registry add queue` → `@lunora/queue` (`ctx.queues`) |
97
+ | Durable multi-step workflows | `registry add workflow` → `@lunora/workflow` (`ctx.runStep`) |
98
+ | Durable AI agents (tool loops, HITL, memory) | `@lunora/agent` (`defineAgent`) |
99
+ | Workers AI / RAG | `registry add ai` → `@lunora/ai` (`ctx.ai`, `defineRag`) |
100
+ | Feature flags (OpenFeature) | `registry add flags` → `@lunora/flags` (`ctx.flags`) |
101
+ | Payments (Stripe / Polar) | `registry add payment` → `@lunora/payment` |
102
+ | Rate limiting | `registry add ratelimit` → `@lunora/ratelimit` |
103
+ | Headless browser (action-only) | `registry add browser` → `@lunora/browser` (`ctx.browser`) |
104
+ | Cloudflare Containers | `@lunora/container` (`defineContainer`, `ctx.containers`) |
105
+ | Presence / who's-here | `registry add presence` |
106
+ | Cloudflare Access (Zero Trust) identity | `registry add cloudflare-access` |
107
+ | Backup / restore | `registry add backup` |
108
+ | Testing (in-memory harness, agent doubles) | `@lunora/testing` (`lunoraTest`) |
109
+ | Deterministic seed data | `@lunora/seed` + `lunora seed` |
110
+ | Local-first replica / offline mirror | `@lunora/replica` |
111
+ | Exposing the deployment to AI agents over MCP | `@lunora/mcp` |
112
+
113
+ Scaffolding inside this repo uses `vis generate lunora-<kind>` — `query`,
114
+ `mutation`, `action`, `http-route`, `table`, `cron`, `container`, `workflow`,
115
+ `queue`, `step`, `agent`, `flags`, `collections`, `package` (`vis generate
116
+ --list` for the full set). Most take a name: **always** pass it as
117
+ `--name=value`, since vis parses a space-separated `--name foo` as `--name=true`
118
+ plus a stray positional. `lunora-flags` and `lunora-collections` are singletons
119
+ and take no name.
120
+
67
121
  ## Core Mental Model
68
122
 
69
123
  - **Functions** live in `lunora/*.ts` and are one of `query` (reactive read),
@@ -75,7 +129,9 @@ in this skill.
75
129
  - **Reads go through indexes.** Prefer `ctx.db.query("t").withIndex(...)` over
76
130
  `.filter(...)`; declare the index with `.index("by_x", ["x"])`.
77
131
  - **Clients** subscribe over WebSocket. `useQuery`/`useMutation` (React, Vue,
78
- Solid, Svelte) re-render the moment a mutation changes the queried rows.
132
+ Solid, Svelte, React Native; signals in Angular) re-render the moment a
133
+ mutation changes the queried rows. Subscriptions run under the socket's
134
+ verified identity, so `rls()` / `ctx.auth` apply to live updates too.
79
135
 
80
136
  ## When Not to Use
81
137
 
@@ -150,9 +150,44 @@ Declare the index and constrain with `.withIndex`.
150
150
 
151
151
  ## Other `ctx` capabilities
152
152
 
153
- `ctx.auth` (the resolved session: `ctx.auth.userId`), `ctx.scheduler`
154
- (`runAfter` / `runAt` for deferred work), `ctx.storage` (R2), `ctx.vectors`
155
- (Vectorize), andwhen their packages are wired — `ctx.ai` and `ctx.containers`.
153
+ Always available:
154
+
155
+ - `ctx.auth`the resolved session (`ctx.auth.userId`).
156
+ - `ctx.scheduler` — `runAfter` / `runAt` for deferred work.
157
+ - `ctx.secrets` — Cloudflare Secrets Store.
158
+ - `ctx.span` / `ctx.trace` — the current span and a scoped tracing helper for
159
+ wide events.
160
+
161
+ Added by their package when wired. **A dependency in `package.json` is not
162
+ enough** — codegen scans the `lunora/` source set and flips a capability on only
163
+ when a file there imports the `@lunora/*` package or reads its `ctx.*` helper.
164
+ So write the call first, then run `lunora codegen` to surface the typed context:
165
+
166
+ | `ctx.*` | Package |
167
+ | ----------------------------------------------------------------------------------------- | ----------------------------- |
168
+ | `ctx.storage` | `@lunora/storage` (R2) |
169
+ | `ctx.ai` | `@lunora/ai` (Workers AI) |
170
+ | `ctx.flags` | `@lunora/flags` (OpenFeature) |
171
+ | `ctx.queues.<name>` | `@lunora/queue` |
172
+ | `ctx.workflows` / `ctx.runStep` | `@lunora/workflow` |
173
+ | `ctx.containers` | `@lunora/container` |
174
+ | `ctx.browser` (action-only) | `@lunora/browser` |
175
+ | `ctx.sql` (action-only) | `@lunora/hyperdrive` |
176
+ | `ctx.kv` / `ctx.images` / `ctx.analytics` / `ctx.pipelines` / `ctx.vectors` / `ctx.r2sql` | `@lunora/bindings` subpaths |
177
+
178
+ Two exceptions to the usage scan, and one extra requirement:
179
+
180
+ - **`ctx.flags` gates on a declaration file**, not on usage — codegen wires it
181
+ only when `lunora/flags.ts` exists (`vis generate lunora-flags` creates it).
182
+ `ctx.notify` / `ctx.push` work the same way via `lunora/notify.ts`.
183
+ - **`ctx.sql` also needs the real resource.** Codegen types the field, but the
184
+ connection needs a `HYPERDRIVE` binding (`wrangler hyperdrive create`) and an
185
+ explicit `createHyperdrive(ctx.env.HYPERDRIVE)` + driver adapter in the
186
+ action — see `lunora-setup-hyperdrive`. Bindings codegen can provision on its
187
+ own (e.g. `BROWSER` for `ctx.browser`) need no manual wrangler step.
188
+
189
+ `ctx.browser` and `ctx.sql` are **action-only** by design — they are
190
+ non-deterministic and would break query reactivity and mutation replay.
156
191
 
157
192
  ## HTTP endpoints
158
193
 
@@ -2,7 +2,8 @@
2
2
  name: lunora-migration-helper
3
3
  description: Plans Lunora schema and data migrations with widen-migrate-narrow. Use for
4
4
  breaking schema changes, backfills, table reshaping, online data migrations
5
- (`defineMigration` + `lunora migrate up`), the `.global()` D1 SQL flow, and the
5
+ (`defineMigration` + `lunora migrate up`), the `.global()` D1 / Hyperdrive
6
+ structural flows, and the
6
7
  pre-deploy schema-drift gate.
7
8
  ---
8
9
 
@@ -15,7 +16,7 @@ Safely change a Lunora schema and migrate data when making breaking changes.
15
16
  - Adding required fields to existing tables.
16
17
  - Changing field types or structure.
17
18
  - Splitting/merging tables, renaming/removing fields.
18
- - Reshaping `.global()` (D1-backed) tables.
19
+ - Reshaping `.global()` tables (D1- or Hyperdrive-backed).
19
20
 
20
21
  ## When Not to Use
21
22
 
@@ -23,21 +24,35 @@ Safely change a Lunora schema and migrate data when making breaking changes.
23
24
  - Adding **optional** fields that need no backfill.
24
25
  - Adding new tables or indexes with no correctness concern.
25
26
 
26
- ## Two Storage Layers — Know Which You Are Migrating
27
+ ## Storage Layers — Know Which You Are Migrating
27
28
 
28
- Lunora tables live in one of two backends, and they migrate differently:
29
+ Lunora tables live in one of three backends, and they migrate differently:
29
30
 
30
31
  - **ShardDO SQLite (default `root`, and `.shardBy(key)` tables).** State lives in
31
32
  the per-app / per-shard Durable Object. Data is reshaped with **online data
32
33
  migrations** — `defineMigration` declarations run by `lunora migrate up`,
33
34
  resumable per shard.
34
- - **`.global()` tables (D1).** Replicated to D1 for cross-region reads. Their
35
- structural DDL gets versioned **SQL migrations** via `lunora migrate generate`,
36
- applied by `@lunora/d1`'s runner at deploy time.
37
-
38
- A breaking change to a `.global()` table needs a generated SQL migration; a data
39
- backfill (either layer) is an online `defineMigration`. Both follow the same
40
- **widen migrate narrow** discipline.
35
+ - **`.global()` on D1 (the default global backend).** Replicated to D1 for
36
+ cross-region reads. Structural DDL gets versioned **SQL migrations** via
37
+ `lunora migrate generate`, applied by `@lunora/d1`'s runner at deploy time.
38
+ - **`.global({ backend: "hyperdrive" })` on Postgres/MySQL.** The same reactive
39
+ `.global()` contract served over Cloudflare Hyperdrive. Structural DDL works
40
+ differently here: tables **auto-provision on first use** the runtime applies
41
+ the DDL through the dialect — so there is no `lunora migrate generate` step
42
+ and no versioned SQL file to commit. See `lunora-setup-hyperdrive-global`.
43
+
44
+ So: a breaking structural change to a **D1-backed** `.global()` table needs a
45
+ generated SQL migration; the Hyperdrive-backed equivalent provisions itself. A
46
+ data backfill (any layer) is always an online `defineMigration`. All three
47
+ follow the same **widen → migrate → narrow** discipline — check the table's
48
+ backend before assuming which structural path applies.
49
+
50
+ > **Moving an existing dataset between global backends.** To move a `.global()`
51
+ > dataset from D1 onto Hyperdrive, use
52
+ > `lunora migrate d1-to-hyperdrive --from-url <d1-worker> --to-url <hd-worker>`
53
+ > (`--tables` scopes it; `--out` keeps the intermediate NDJSON dump). This is a
54
+ > backend move, not a schema change — the widen → migrate → narrow discipline
55
+ > below still governs any reshaping you do on either side of it.
41
56
 
42
57
  ## Key Principle: Widen, Migrate, Narrow
43
58
 
@@ -115,6 +130,40 @@ export default defineMigration({
115
130
  The transform must preserve row identity — the runner always keeps the original
116
131
  `_id` / `_creationTime`, so do not change them.
117
132
 
133
+ ### Reading another table
134
+
135
+ The transform's second argument is a **shard-scoped reader** (`ctx.db` with
136
+ `get` / `findFirst` / `findMany` / `count`), so the common backfill — read the
137
+ parent, copy a field down onto its children — is expressible. It may be `async`.
138
+
139
+ ```ts
140
+ up: async (doc, ctx) => {
141
+ const thread = await ctx.db.get(String(doc.threadId), "threads");
142
+
143
+ return thread ? { ...doc, userId: thread.userId } : undefined;
144
+ },
145
+ ```
146
+
147
+ It is a reader, not a writer: the runner accounts for exactly one rewrite per
148
+ row read, and a transform writing directly would make that count describe
149
+ something other than what happened. To touch a second table, run a second
150
+ migration over that table.
151
+
152
+ ### A shard key cannot be backfilled by a migration
153
+
154
+ If the field you are backfilling **is** the table's `.shardBy()` key, this is the
155
+ wrong tool, and no amount of reader access fixes it:
156
+
157
+ - a row whose shard key is unset does not belong to any shard, so a shard-scoped
158
+ query will never enumerate it; and
159
+ - writing the key would have to **move the row to a different Durable Object**,
160
+ which a per-shard runner has no way to do.
161
+
162
+ Re-keying is an export → transform → import (`lunora export`, rewrite the NDJSON,
163
+ `lunora import` — ids are preserved, so foreign keys survive), not a migration.
164
+ So the rule elsewhere in this skill that a data backfill is always an online
165
+ `defineMigration` has this one exception.
166
+
118
167
  ### Run it
119
168
 
120
169
  ```bash
@@ -129,7 +178,10 @@ lunora migrate down backfill-display-name # revert (if `down` defined)
129
178
  Useful flags: `--batch-size <n>`, `--steps <n>` (cap batches this run), and
130
179
  `--prod --url <worker> --yes` to target production (with `LUNORA_ADMIN_TOKEN`).
131
180
 
132
- ## `.global()` (D1) Structural Migration Flow
181
+ ## `.global()` on D1 Structural Migration Flow
182
+
183
+ This flow is **D1-specific**. Hyperdrive-backed globals auto-provision their DDL
184
+ at runtime and skip it entirely.
133
185
 
134
186
  ```bash
135
187
  # 1. Edit lunora/schema.ts (widen: add the optional new field to the .global() table).
@@ -146,8 +198,8 @@ lunora deploy
146
198
  ```
147
199
 
148
200
  `lunora migrate generate` only considers `.global()` tables (root/sharded tables
149
- are not D1-backed). Run it after each schema edit in the widen and narrow steps;
150
- backfill data with an online migration between them.
201
+ live in ShardDO SQLite, not D1). Run it after each schema edit in the widen and
202
+ narrow steps; backfill data with an online migration between them.
151
203
 
152
204
  ## The Schema-Drift Gate
153
205
 
@@ -176,9 +228,10 @@ add the migration — not to bypass it.
176
228
  transform before it touches real rows.
177
229
  5. **Deleting a field prematurely.** Deprecate with `v.optional` + a comment;
178
230
  delete only once nothing references it.
179
- 6. **Migrating the wrong layer.** A `.global()` structural change needs `lunora
180
- migrate generate` (SQL); a data backfill needs a `defineMigration`. Check the
181
- table's `.global()` / `.shardBy()` modifier first.
231
+ 6. **Migrating the wrong layer.** A D1-backed `.global()` structural change needs
232
+ `lunora migrate generate` (SQL); a Hyperdrive-backed one auto-provisions; a
233
+ data backfill needs a `defineMigration`. Check the table's `.global()` /
234
+ `.shardBy()` modifier — and, for `.global()`, its `backend` — first.
182
235
 
183
236
  ## Checklist
184
237
 
@@ -2,8 +2,8 @@
2
2
  name: lunora-performance-audit
3
3
  description: Diagnoses and fixes Lunora performance problems — full-table scans, missing
4
4
  indexes, OCC write conflicts, oversized subscriptions, and sharding/`.global()`
5
- scaling. Use when queries are slow, mutations conflict, or `@lunora/advisor`
6
- flags a table.
5
+ scaling. Use when queries are slow, mutations conflict, `lunora insights`
6
+ reports a hot-spot, or `@lunora/advisor` flags a table.
7
7
  ---
8
8
 
9
9
  # Lunora Performance Audit
@@ -34,12 +34,35 @@ apply it across sibling functions consistently.
34
34
 
35
35
  ## Signal Gathering
36
36
 
37
- Start with the static advisors — they need no traffic:
37
+ ### Runtime signal: `lunora insights`
38
+
39
+ When the worker is running and has served traffic, start here — it reports the
40
+ measured problem, not a suspected one:
41
+
42
+ ```bash
43
+ lunora insights # against the local dev worker
44
+ lunora insights --shard channel:demo # scope to one shard
45
+ lunora insights --limit 25 --json # machine-readable, more rows
46
+ lunora insights --prod --url https://app.example.com --token $LUNORA_ADMIN_TOKEN
47
+ ```
48
+
49
+ It ranks per-function **write-conflict hot-spots** (OCC contention — the
50
+ sharding signal), **error rates**, and **latency outliers**. A function at the
51
+ top of the write-conflict list is the direct input to the OCC section below; a
52
+ latency outlier usually resolves to the read-amplification section.
53
+
54
+ The Studio **Issues** panel and `lunora logs` cover the error side in more
55
+ detail once `insights` tells you where to look.
56
+
57
+ ### Static signal: the advisors
58
+
59
+ These need no traffic, so they also work on a cold codebase:
38
60
 
39
61
  - **Lunora Studio → Advisors tab** surfaces `@lunora/advisor` findings live in
40
62
  dev.
41
- - `@lunora/advisor` runs static lints over `defineSchema` + discovered query
42
- reads / insert writes. Relevant performance/schema rules:
63
+ - `@lunora/advisor` runs ~90 static lints over `defineSchema` + discovered query
64
+ reads / insert writes (plus a few runtime lints). The performance/schema rules
65
+ most relevant here:
43
66
  - `filter-without-index` — a query filters a table with no covering index.
44
67
  - `unindexed-foreign-key` — a relation/FK column has no index.
45
68
  - `duplicate-index` / `empty-index` — wasted or malformed indexes.
@@ -75,7 +98,8 @@ column. Fix every sibling query on the table the same way.
75
98
 
76
99
  ## Problem Class: Write Conflicts (OCC)
77
100
 
78
- **Symptom:** mutations on hot rows retry or fail under concurrency. ShardDO uses
101
+ **Symptom:** mutations on hot rows retry or fail under concurrency, or the
102
+ function tops the write-conflict section of `lunora insights`. ShardDO uses
79
103
  optimistic concurrency control — concurrent writes to the same DO that touch
80
104
  overlapping state conflict and retry.
81
105
 
@@ -115,6 +139,11 @@ cross-region reads (with read-your-writes via the Sessions API). Reserve it for
115
139
  read-mostly tables — `.global()` adds the D1 migration flow (see the
116
140
  `lunora-migration-helper` skill) and write-path cost.
117
141
 
142
+ If the dataset outgrows D1, `.global({ backend: "hyperdrive" })` serves the same
143
+ reactive `.global()` contract from Postgres/MySQL over Cloudflare Hyperdrive —
144
+ see the `lunora-setup-hyperdrive-global` skill (and `lunora migrate
145
+ d1-to-hyperdrive` to move an existing dataset).
146
+
118
147
  ### `.shardBy(key)` vs `.global()` — choose one per table
119
148
 
120
149
  - `.shardBy(key)`: partitions a table across Durable Objects by key — scales
@@ -135,6 +164,7 @@ read-mostly tables — `.global()` adds the D1 migration flow (see the
135
164
  ## Checklist
136
165
 
137
166
  - [ ] Scoped one concrete flow; traced every `ctx.db` read/write.
167
+ - [ ] Ran `lunora insights` (if the worker has traffic) for the measured signal.
138
168
  - [ ] Checked the Studio Advisors tab / `@lunora/advisor` findings.
139
169
  - [ ] Read amplification: replaced `.filter()` with an indexed `.withIndex()`.
140
170
  - [ ] Write conflicts: narrowed writes and/or partitioned with `.shardBy(key)`.