@lunora/cli 1.0.0-alpha.38 → 1.0.0-alpha.380

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 (130) hide show
  1. package/LICENSE.md +33 -0
  2. package/README.md +1 -1
  3. package/dist/bin.mjs +2 -10
  4. package/dist/index.d.mts +1011 -374
  5. package/dist/index.d.ts +1011 -374
  6. package/dist/index.mjs +1 -19
  7. package/dist/packem_chunks/dispatch.mjs +1 -0
  8. package/dist/packem_chunks/handler.mjs +1 -160
  9. package/dist/packem_chunks/handler10.mjs +1 -16
  10. package/dist/packem_chunks/handler11.mjs +1 -22
  11. package/dist/packem_chunks/handler12.mjs +1 -192
  12. package/dist/packem_chunks/handler13.mjs +3 -131
  13. package/dist/packem_chunks/handler14.mjs +1 -65
  14. package/dist/packem_chunks/handler15.mjs +1 -58
  15. package/dist/packem_chunks/handler16.mjs +1 -80
  16. package/dist/packem_chunks/handler17.mjs +7 -43
  17. package/dist/packem_chunks/handler18.mjs +1 -105
  18. package/dist/packem_chunks/handler19.mjs +3 -170
  19. package/dist/packem_chunks/handler2.mjs +1 -114
  20. package/dist/packem_chunks/handler20.mjs +3 -94
  21. package/dist/packem_chunks/handler21.mjs +1 -94
  22. package/dist/packem_chunks/handler22.mjs +2 -0
  23. package/dist/packem_chunks/handler23.mjs +1 -0
  24. package/dist/packem_chunks/handler24.mjs +99 -0
  25. package/dist/packem_chunks/handler25.mjs +10 -0
  26. package/dist/packem_chunks/handler26.mjs +1 -0
  27. package/dist/packem_chunks/handler3.mjs +1 -204
  28. package/dist/packem_chunks/handler4.mjs +3 -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 +1 -42
  32. package/dist/packem_chunks/handler8.mjs +2 -174
  33. package/dist/packem_chunks/handler9.mjs +1 -315
  34. package/dist/packem_chunks/runCodegenCommand.mjs +4 -52
  35. package/dist/packem_chunks/runDeployCommand.mjs +11 -594
  36. package/dist/packem_chunks/runDevCommand.mjs +2 -0
  37. package/dist/packem_chunks/runInitCommand.mjs +164 -1432
  38. package/dist/packem_chunks/runResetCommand.mjs +1 -41
  39. package/dist/packem_chunks/runRpcCommand.mjs +1 -68
  40. package/dist/packem_shared/COMMANDS-Ba7ybcYb.mjs +1 -0
  41. package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-CyIsI3S1.mjs +1 -0
  42. package/dist/packem_shared/EXIT_CODE-D_XCixv8.mjs +1 -0
  43. package/dist/packem_shared/admin-token-VdUnvnKW.mjs +1 -0
  44. package/dist/packem_shared/admin-url-DJB8P6Jh.mjs +1 -0
  45. package/dist/packem_shared/binding-manifest-file-CQ1eQYy1.mjs +2 -0
  46. package/dist/packem_shared/buildRegistryIndex-Dc8D8AR6.mjs +1 -0
  47. package/dist/packem_shared/catalog-CahzmDLV.mjs +1 -0
  48. package/dist/packem_shared/cli-B5fWPcrA.mjs +2 -0
  49. package/dist/packem_shared/cli-manifest-CRet0egA.mjs +1 -0
  50. package/dist/packem_shared/cloudflare-credentials-BVmZnDZk.mjs +1 -0
  51. package/dist/packem_shared/codegen-error-AmH54ofi.mjs +3 -0
  52. package/dist/packem_shared/command-CAXl2A1S.mjs +1 -0
  53. package/dist/packem_shared/commands-DgUDxkA8.mjs +13 -0
  54. package/dist/packem_shared/createLogger-Cl18I8AX.mjs +2 -0
  55. package/dist/packem_shared/createRecordingSpawner-Ch7zuQQE.mjs +1 -0
  56. package/dist/packem_shared/deploy-target-DCWwiuAe.mjs +1 -0
  57. package/dist/packem_shared/diffSnapshots-WWwx-KvZ.mjs +5 -0
  58. package/dist/packem_shared/docker-AqLAkOyY.mjs +1 -0
  59. package/dist/packem_shared/health-probe-Bw9JFfIy.mjs +1 -0
  60. package/dist/packem_shared/import-BRM1hs7j.mjs +12 -0
  61. package/dist/packem_shared/index-oHZBGBwB.mjs +1 -0
  62. package/dist/packem_shared/insertSchemaExtension-DuiV6cba.mjs +8 -0
  63. package/dist/packem_shared/lint-ignore-report-DKZagpqk.mjs +2 -0
  64. package/dist/packem_shared/open-url-EnKy--w-.mjs +1 -0
  65. package/dist/packem_shared/output-format-B4eQHi5y.mjs +2 -0
  66. package/dist/packem_shared/parseManifest-CwPTKdtS.mjs +1 -0
  67. package/dist/packem_shared/path-containment-CgxYZggb.mjs +1 -0
  68. package/dist/packem_shared/plan-Dl57T11P.mjs +5 -0
  69. package/dist/packem_shared/planDevCommand-D8sm56hO.mjs +1 -0
  70. package/dist/packem_shared/platform-diagnostics-Cn2g6Jh-.mjs +4 -0
  71. package/dist/packem_shared/prompt-cancelled-BvsNxg_Q.mjs +1 -0
  72. package/dist/packem_shared/render-lunora-error-C3OJY5wk.mjs +2 -0
  73. package/dist/packem_shared/resolve-BrsV4Qyc.mjs +5 -0
  74. package/dist/packem_shared/resolve-target-C_ZloTvd.mjs +1 -0
  75. package/dist/packem_shared/runAddCommand-DTvfp4h2.mjs +1 -0
  76. package/dist/packem_shared/runExportCommand-slAq5BCF.mjs +5 -0
  77. package/dist/packem_shared/runMigrateGenerateCommand-Ii_WMZEA.mjs +11 -0
  78. package/dist/packem_shared/schemaIrToSnapshot-BjK-0IRo.mjs +1 -0
  79. package/dist/packem_shared/secret-key-6bCftsxj.mjs +1 -0
  80. package/dist/packem_shared/shared-D-zCOmgY.mjs +1 -0
  81. package/dist/packem_shared/storage-DWhTX8eS.mjs +1 -0
  82. package/dist/packem_shared/tui-prompts-B3YwUhGw.mjs +4 -0
  83. package/dist/packem_shared/variables-CPYyJtsL.mjs +1 -0
  84. package/dist/packem_shared/wrangler-name-Dsk5K1f-.mjs +1 -0
  85. package/dist/packem_shared/wrangler-secrets-3chIVv3H.mjs +1 -0
  86. package/package.json +39 -19
  87. package/skills/README.md +35 -17
  88. package/skills/lunora/SKILL.md +154 -64
  89. package/skills/lunora-create-package/SKILL.md +97 -84
  90. package/skills/lunora-deploy/SKILL.md +175 -105
  91. package/skills/lunora-functions/SKILL.md +362 -56
  92. package/skills/lunora-migration-helper/SKILL.md +162 -137
  93. package/skills/lunora-performance-audit/SKILL.md +137 -95
  94. package/skills/lunora-quickstart/SKILL.md +137 -136
  95. package/skills/lunora-realtime/SKILL.md +140 -99
  96. package/skills/lunora-setup-auth/SKILL.md +162 -102
  97. package/skills/lunora-setup-hyperdrive/SKILL.md +114 -97
  98. package/skills/lunora-setup-hyperdrive-global/SKILL.md +93 -90
  99. package/skills/lunora-setup-mail/SKILL.md +85 -113
  100. package/skills/lunora-setup-scheduler/SKILL.md +132 -96
  101. package/skills/lunora-setup-storage/SKILL.md +189 -95
  102. package/dist/packem_chunks/planDevCommand.mjs +0 -541
  103. package/dist/packem_chunks/runMigrateGenerateCommand.mjs +0 -397
  104. package/dist/packem_shared/COMMANDS-B0ftFD_3.mjs +0 -948
  105. package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Ck-2bU08.mjs +0 -244
  106. package/dist/packem_shared/admin-url-4UzT-CI4.mjs +0 -19
  107. package/dist/packem_shared/api-spec-CtA6ilu4.mjs +0 -13
  108. package/dist/packem_shared/buildRegistryIndex-BcYe607_.mjs +0 -38
  109. package/dist/packem_shared/codegen-error-DJG-ghs_.mjs +0 -31
  110. package/dist/packem_shared/command-D3lB_4Az.mjs +0 -19
  111. package/dist/packem_shared/commands-B-gR09Z_.mjs +0 -845
  112. package/dist/packem_shared/createLogger-B40gPzQo.mjs +0 -78
  113. package/dist/packem_shared/createRecordingSpawner-DxI3mebw.mjs +0 -43
  114. package/dist/packem_shared/detect-package-manager-DYp7n3mJ.mjs +0 -61
  115. package/dist/packem_shared/diffSnapshots-BeDvvNiF.mjs +0 -161
  116. package/dist/packem_shared/docker-hMQ97KSQ.mjs +0 -21
  117. package/dist/packem_shared/insertSchemaExtension-DAqbfr9Z.mjs +0 -64
  118. package/dist/packem_shared/open-url-Dfq6fAyT.mjs +0 -41
  119. package/dist/packem_shared/output-format-wUvAN6AL.mjs +0 -17
  120. package/dist/packem_shared/parseArgs-YXFuKdEk.mjs +0 -56
  121. package/dist/packem_shared/parseManifest--vZf2FY1.mjs +0 -94
  122. package/dist/packem_shared/prompt-cancelled-APzX1Im-.mjs +0 -9
  123. package/dist/packem_shared/resolve-target-qbsJ_5sF.mjs +0 -16
  124. package/dist/packem_shared/runAddCommand-bnY6-HKb.mjs +0 -4
  125. package/dist/packem_shared/schema-drift-gate-BtBt0as0.mjs +0 -79
  126. package/dist/packem_shared/schemaIrToSnapshot-DdsljJT-.mjs +0 -43
  127. package/dist/packem_shared/storage-BIsph-Vk.mjs +0 -84
  128. package/dist/packem_shared/tui-prompts-BjEN8XgP.mjs +0 -658
  129. package/dist/packem_shared/wrangler-name-cy4yhm9j.mjs +0 -12
  130. package/dist/packem_shared/wrangler-secrets-P2_ZUR-k.mjs +0 -47
@@ -1,65 +1 @@
1
- import { existsSync, rmSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { writeLinkedProject, LINKED_PROJECT_FILE } from '@lunora/config';
4
- import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
5
- import { r as readWranglerName } from '../packem_shared/wrangler-name-cy4yhm9j.mjs';
6
-
7
- const isValidWorkerUrl = (value) => {
8
- try {
9
- const { protocol } = new URL(value);
10
- return protocol === "http:" || protocol === "https:";
11
- } catch {
12
- return false;
13
- }
14
- };
15
- const runLinkRemove = (cwd, logger) => {
16
- const path = join(cwd, LINKED_PROJECT_FILE);
17
- if (!existsSync(path)) {
18
- logger.warn(`link: no ${LINKED_PROJECT_FILE} to remove`);
19
- return { code: 0 };
20
- }
21
- rmSync(path);
22
- logger.success(`link: removed ${LINKED_PROJECT_FILE}`);
23
- return { code: 0 };
24
- };
25
- const runLinkCommand = (options) => {
26
- const cwd = options.cwd ?? process.cwd();
27
- const { logger } = options;
28
- if (options.remove) {
29
- return runLinkRemove(cwd, logger);
30
- }
31
- if (options.url === void 0 || options.url === "") {
32
- logger.error("link requires a deployed Worker URL. Usage: lunora link --url <https://your-worker>");
33
- return { code: 1 };
34
- }
35
- if (!isValidWorkerUrl(options.url)) {
36
- logger.error(`link: invalid --url "${options.url}" — expected an http(s) URL`);
37
- return { code: 1 };
38
- }
39
- const now = options.now ?? (() => (/* @__PURE__ */ new Date()).toISOString());
40
- const link = {
41
- env: options.env,
42
- linkedAt: now(),
43
- workerName: options.name ?? readWranglerName(cwd),
44
- workerUrl: options.url
45
- };
46
- const path = writeLinkedProject(cwd, link);
47
- logger.success(`link: ${link.workerName ?? "(unnamed worker)"} -> ${options.url}`);
48
- logger.info(`link: wrote ${path}`);
49
- if (link.env !== void 0) {
50
- logger.info(`link: environment "${link.env}"`);
51
- }
52
- return { code: 0, link };
53
- };
54
- const execute = defineHandler(
55
- ({ cwd, logger, options }) => runLinkCommand({
56
- cwd,
57
- env: options.env,
58
- logger,
59
- name: options.name,
60
- remove: options.remove === true,
61
- url: options.url
62
- })
63
- );
64
-
65
- export { execute, runLinkCommand };
1
+ import{r as $}from"../packem_shared/admin-token-VdUnvnKW.mjs";import{r as S,a as p}from"../packem_shared/admin-url-DJB8P6Jh.mjs";import{d as k}from"../packem_shared/command-CAXl2A1S.mjs";import{EXIT_CODE as u,exitCodeForStatus as b}from"../packem_shared/EXIT_CODE-D_XCixv8.mjs";import{a as y}from"../packem_shared/resolve-target-C_ZloTvd.mjs";const w="/_lunora/admin/shard-registry/prune",f=["prune"],d=(e,r,a)=>(e.error(r),{code:a,error:r}),g=(e,r,a)=>{for(const{shardKey:t,table:n}of r.released)e.info(`${a?"would release":"released"} ${t} (${n})`);for(const{message:t,shardKey:n,tables:l}of r.failed)e.error(`could not check ${n} (${l.join(", ")}) — kept: ${t}`);const s=`${String(r.released.length)} ${a?"would be released":"released"}, ${String(r.kept.length)} kept (still hold rows), ${String(r.failed.length)} unreachable`;r.failed.length>0?e.warn(`${s} — re-run to retry the unreachable shards`):e.success(s)},A=async e=>{const{logger:r}=e;if(!f.includes(e.subcommand))return d(r,`shards: unknown subcommand "${e.subcommand??""}" — expected ${f.join(" | ")}`,u.USAGE);if(e.prod&&e.url===void 0)return d(r,"--prod requires an explicit --url (refusing to prune the implicit localhost worker)",u.USAGE);const a=S(e.url,r,e.cwd);if(a===void 0)return{code:u.USAGE,error:"could not resolve a usable worker URL"};const{token:s}=$({cwd:e.cwd??process.cwd(),token:e.token,url:a});if(!s)return d(r,"admin token required — pass --token, set LUNORA_ADMIN_TOKEN, or add it to .dev.vars (local targets only)",u.AUTH);const t=`${a}${w}`,n=e.fetchImpl??p,l=e.tables?.split(",").map(h=>h.trim()).filter(h=>h!==""),i=e.dryRun===!0;r.info(`POST ${t} -> shards prune${i?" (dry run)":""}`);const c=await n(t,{body:JSON.stringify({dryRun:i,...l===void 0?{}:{tables:l}}),headers:{authorization:`Bearer ${s}`,"content-type":"application/json"},method:"POST"}),m=await c.text();if(!c.ok)return d(r,`shards prune failed: HTTP ${String(c.status)}: ${m}`,b(c.status));let o;try{o=JSON.parse(m)}catch{return d(r,`shards prune failed: worker returned non-JSON: ${m}`,1)}return e.format!=="json"&&g(r,o,i),o.failed.length>0?{code:1,error:`shards prune: ${String(o.failed.length)} shard(s) could not be checked`,result:o}:{code:0,result:o}},E=k(async({argument:e,cwd:r,format:a,logger:s,options:t})=>{const n=await A({cwd:r,dryRun:t.dryRun===!0,format:a,logger:s,prod:t.prod,subcommand:e[0],tables:t.tables,token:t.token,url:y({cwd:r,prod:t.prod===!0,url:t.url})});return{code:n.code,data:n.result,error:n.error}});export{E as execute,A as runShardsCommand};
@@ -1,58 +1 @@
1
- import { readLinkedProject } from '@lunora/config';
2
- import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
3
- import { defaultSpawner } from '../packem_shared/createRecordingSpawner-DxI3mebw.mjs';
4
-
5
- const LOG_FORMATS = /* @__PURE__ */ new Set(["json", "pretty"]);
6
- const runLogsCommand = async (options) => {
7
- const cwd = options.cwd ?? process.cwd();
8
- if (options.format !== void 0 && !LOG_FORMATS.has(options.format)) {
9
- options.logger.error(`logs: unknown --format "${options.format}" — expected pretty | json`);
10
- return { code: 1, descriptor: void 0, error: "invalid format" };
11
- }
12
- const args = ["exec", "wrangler", "tail"];
13
- if (options.worker !== void 0) {
14
- args.push(options.worker);
15
- }
16
- const env = options.env ?? readLinkedProject(cwd)?.env;
17
- if (env !== void 0) {
18
- args.push("--env", env);
19
- }
20
- if (options.format !== void 0) {
21
- args.push("--format", options.format);
22
- }
23
- if (options.status !== void 0) {
24
- args.push("--status", options.status);
25
- }
26
- if (options.search !== void 0) {
27
- args.push("--search", options.search);
28
- }
29
- if (options.temporary) {
30
- args.push("--temporary");
31
- }
32
- const descriptor = {
33
- args,
34
- command: "pnpm",
35
- cwd
36
- };
37
- options.logger.info(`tailing logs via ${descriptor.command} ${descriptor.args.join(" ")}`);
38
- const spawner = options.spawner ?? defaultSpawner;
39
- const result = await spawner(descriptor);
40
- return {
41
- code: result.code,
42
- descriptor
43
- };
44
- };
45
- const execute = defineHandler(
46
- ({ argument, cwd, logger, options }) => runLogsCommand({
47
- cwd,
48
- env: options.env,
49
- format: options.format,
50
- logger,
51
- search: options.search,
52
- status: options.status,
53
- temporary: options.temporary === true,
54
- worker: argument[0]
55
- })
56
- );
57
-
58
- export { execute, runLogsCommand };
1
+ import{existsSync as p}from"node:fs";import{join as m}from"node:path";import{runCodegen as u}from"@lunora/codegen";import{validateWranglerProject as g,wranglerCodegenInputs as v}from"@lunora/config/cloudflare";import{a as w,e as y,r as S}from"../packem_shared/platform-diagnostics-Cn2g6Jh-.mjs";import{p as k,r as j}from"../packem_shared/deploy-target-DCWwiuAe.mjs";import{r as E}from"../packem_shared/codegen-error-AmH54ofi.mjs";import{d as A}from"../packem_shared/command-CAXl2A1S.mjs";import{EXIT_CODE as D}from"../packem_shared/EXIT_CODE-D_XCixv8.mjs";import{r as R,p as $}from"../packem_shared/health-probe-Bw9JFfIy.mjs";import{defaultSpawner as b}from"../packem_shared/createRecordingSpawner-Ch7zuQQE.mjs";import{execArgsFor as U,detectPackageManager as x}from"@lunora/config";const P=async(r,a,t)=>{if(!p(m(r,"tsconfig.json")))return{warning:"no tsconfig.json found — skipping TypeScript type-check"};const o=U(x(r),"tsc",["--noEmit","-p","tsconfig.json"]),e=await a({args:o.args,command:o.command,cwd:r,stdoutToStderr:t==="json"});return e.code===0?{}:{error:`type errors: tsc --noEmit exited ${String(e.code)}`}},T=async(r,a)=>{if(r.healthUrl===void 0||r.healthUrl==="")return;const t=await $({baseUrl:r.healthUrl,fetchImpl:r.healthFetch});if(t.error===void 0){a.success(`verify: health probe ok (${t.url})`);return}return t.error},C=(r,a)=>{const{errorAdvisories:t,names:o,shouldBlock:e}=y(r,S(a));if(e)return`${t.length.toString()} ERROR-level ${t.length===1?"advisory":"advisories"} (${o.join(", ")}). Pass --no-strict-advisories to downgrade this to a warning and continue.`},H=(r,a,t,o)=>{if(a.length===0&&t.length===0)return r.success("verify: project is valid"),{code:0,errors:[],warnings:[],wranglerPath:o};if(t.length>0){r.warn("verify: warnings:");for(const e of t)r.warn(` - ${e}`)}if(a.length>0){r.error("verify: errors:");for(const e of a){r.error(` - ${e}`);const s=E(e);s!==void 0&&r.error(s)}return{code:1,error:a[0],errors:a,warnings:t,wranglerPath:o}}return r.success("verify: project is valid (with warnings)"),{code:0,errors:[],warnings:t,wranglerPath:o}},I=async r=>{const a=r.cwd??process.cwd(),{logger:t}=r,o=g({environment:r.env,projectRoot:a}),e=[...o.report.errors],s=[...o.report.warnings];try{const n=j(a,r.target);if(n.target===void 0){const c=n.error??"unknown deploy target";return t.error(c),{code:D.USAGE,error:c,errors:[c],warnings:[],wranglerPath:void 0}}const i=u({apiSpec:r.apiSpec,dryRun:!0,projectRoot:a,target:n.target,...v(a)}),f=w(i.platformDiagnostics,t);e.push(...f.errors),s.push(...f.warnings);const l=C(i.advisories,r);l!==void 0&&e.push(l);const h=R({allowDrift:r.allowSchemaDrift===!0,codegen:i,command:"verify",logger:t,readOnly:!0});h.blocked&&e.push(h.reason)}catch(n){const i=n instanceof Error?n.message:String(n);e.push(`codegen failed: ${i}`)}if(r.typecheck!==!1){const n=await P(a,r.spawner??b,r.format??"pretty");n.error!==void 0&&e.push(n.error),n.warning!==void 0&&s.push(n.warning)}const d=await T(r,t);return d!==void 0&&e.push(d),H(t,e,s,o.wranglerPath)},K=A(async({cwd:r,format:a,logger:t,options:o})=>{const e=await I({allowSchemaDrift:o.allowSchemaDrift===!0,apiSpec:k(o.apiSpec),cwd:r,env:o.env,format:a,healthUrl:o.healthUrl,logger:t,strictAdvisories:o.strictAdvisories,target:o.target,typecheck:o.typecheck===!1?!1:void 0});return{code:e.code,data:{errors:e.errors,warnings:e.warnings,wranglerPath:e.wranglerPath},error:e.error}});export{K as execute,I as runVerifyCommand};
@@ -1,80 +1 @@
1
- import { runCodegen } from '@lunora/codegen';
2
- import { validateWranglerProject, inferLunoraBindings, reconcileWranglerBindings } from '@lunora/config';
3
- import { p as parseApiSpec } from '../packem_shared/api-spec-CtA6ilu4.mjs';
4
- import { r as renderCodegenFailure } from '../packem_shared/codegen-error-DJG-ghs_.mjs';
5
- import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
6
- import { r as runSchemaDriftGate } from '../packem_shared/schema-drift-gate-BtBt0as0.mjs';
7
-
8
- const provisionBindings = async (cwd, logger) => {
9
- try {
10
- const inferred = await inferLunoraBindings({ projectRoot: cwd });
11
- const reconciled = reconcileWranglerBindings(cwd, inferred);
12
- if (reconciled.changed) {
13
- logger.success(`provisioned bindings: ${reconciled.added.join(", ")} → ${reconciled.wranglerPath ?? "wrangler.jsonc"}`);
14
- }
15
- for (const warning of reconciled.warnings) {
16
- logger.warn(warning);
17
- }
18
- } catch (error) {
19
- const message = error instanceof Error ? error.message : String(error);
20
- logger.warn(`binding inference skipped: ${message}`);
21
- }
22
- };
23
- const runPrepareCommand = async (options) => {
24
- const cwd = options.cwd ?? process.cwd();
25
- options.logger.info("running codegen");
26
- let codegen;
27
- try {
28
- codegen = runCodegen({ apiSpec: options.apiSpec, projectRoot: cwd });
29
- options.logger.success("codegen complete");
30
- } catch (error) {
31
- const message = error instanceof Error ? error.message : String(error);
32
- options.logger.error(renderCodegenFailure(error));
33
- return {
34
- code: 1,
35
- error: `codegen failed: ${message}`,
36
- validation: { problems: [], wranglerPath: void 0 }
37
- };
38
- }
39
- const gate = runSchemaDriftGate({
40
- allowDrift: options.allowSchemaDrift === true,
41
- codegen,
42
- logger: options.logger,
43
- updateBaseline: options.updateSchemaBaseline === true
44
- });
45
- if (gate.blocked) {
46
- return {
47
- code: 1,
48
- error: "schema drift gate blocked prepare",
49
- schemaDrift: { blocked: true, reason: gate.reason },
50
- validation: { problems: [], wranglerPath: void 0 }
51
- };
52
- }
53
- await provisionBindings(cwd, options.logger);
54
- const validation = validateWranglerProject({ projectRoot: cwd });
55
- if (validation.problems.length > 0) {
56
- options.logger.error("wrangler.jsonc validation failed:");
57
- for (const problem of validation.problems) {
58
- options.logger.error(` - ${problem}`);
59
- }
60
- return {
61
- code: 1,
62
- error: "wrangler validation failed",
63
- validation
64
- };
65
- }
66
- gate.rebless?.();
67
- options.logger.success("project is ready to deploy");
68
- return { code: 0, validation };
69
- };
70
- const execute = defineHandler(
71
- ({ cwd, logger, options }) => runPrepareCommand({
72
- allowSchemaDrift: options.allowSchemaDrift === true,
73
- apiSpec: parseApiSpec(options.apiSpec),
74
- cwd,
75
- logger,
76
- updateSchemaBaseline: options.updateSchemaBaseline === true
77
- })
78
- );
79
-
80
- export { execute, runPrepareCommand };
1
+ import{readLiveDevServerState as c}from"@lunora/config";import{d as i}from"../packem_shared/command-CAXl2A1S.mjs";import{o as a}from"../packem_shared/open-url-EnKy--w-.mjs";const n="http://127.0.0.1:6173",d="/__lunora",u=/\/$/u,l=r=>{const e=c(r);return e===void 0?n:e.studioUrl!==void 0?e.studioUrl:e.mode==="vite"?`${e.url.replace(u,"")}${d}`:n},m=async r=>{const e=l(r.cwd??process.cwd()),{logger:t}=r;t.info(`opening ${e}`);try{await a(e,{opener:r.opener})}catch(o){const s=o instanceof Error?o.message:String(o);return t.error(`view: failed to open URL: ${s}`),{code:1,url:e}}return{code:0,url:e}},v=i(({cwd:r,logger:e})=>m({cwd:r,logger:e}));export{v as execute,m as runViewCommand};
@@ -1,43 +1,7 @@
1
- import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
2
- import { r as runAddCommand, b as runRegistryViewCommand, a as runBuildIndexCommand } from '../packem_shared/commands-B-gR09Z_.mjs';
3
-
4
- const execute = defineHandler(({ argument, cwd, logger, options }) => {
5
- const subcommand = argument[0];
6
- const names = argument.slice(1);
7
- if (subcommand === "add") {
8
- return runAddCommand({
9
- allowUnsafeSource: options.allowUnsafeSource === true,
10
- cwd,
11
- diff: options.diff === true,
12
- dryRun: options.dryRun === true,
13
- from: options.from,
14
- json: options.json === true,
15
- logger,
16
- names,
17
- overwrite: options.overwrite === true,
18
- ref: options.ref,
19
- source: options.source,
20
- yes: options.yes === true
21
- });
22
- }
23
- if (subcommand === "list") {
24
- return runAddCommand({ cwd, from: options.from, json: options.json === true, list: true, logger, names: [], ref: options.ref, source: options.source });
25
- }
26
- if (subcommand === "view") {
27
- return runRegistryViewCommand({
28
- allowUnsafeSource: options.allowUnsafeSource === true,
29
- from: options.from,
30
- logger,
31
- names,
32
- ref: options.ref,
33
- source: options.source
34
- });
35
- }
36
- if (subcommand === "build") {
37
- return runBuildIndexCommand({ check: options.check === true, from: options.from, logger, out: options.out });
38
- }
39
- logger.error("registry: unknown subcommand. Usage: lunora registry <add|list|view|build> [names…]");
40
- return { code: 1 };
41
- });
42
-
43
- export { execute };
1
+ import{writeFileSync as h,existsSync as S,readFileSync as p}from"node:fs";import{isAbsolute as w,join as v}from"node:path";import{byCodepoint as b,scoreAdvisor as y,parseAdvisorMap as x,compareToBaseline as j}from"@lunora/advisor";import{runCodegen as A}from"@lunora/codegen";import{wranglerCodegenInputs as M}from"@lunora/config/cloudflare";import{d as D}from"../packem_shared/command-CAXl2A1S.mjs";import{EXIT_CODE as E}from"../packem_shared/EXIT_CODE-D_XCixv8.mjs";import{D as u}from"../packem_shared/cli-B5fWPcrA.mjs";const l={clean:"·",exempt:"–",failing:"✗",warned:"!"},d=(e,r)=>e.length>=r?e:e+" ".repeat(r-e.length),R=e=>`${e.id} (${e.visibility} ${e.kind})`,f=e=>{let r=0;for(const n of e)r=Math.max(r,n.id.length);return r},g=(e,r)=>` ${d(String(e.score),3)} ${l[e.coverage]} ${d(e.id,r)} ${e.visibility} ${e.kind}`,F=e=>{if(!e.comparable)return[` baseline not comparable (${e.reason}) — regenerate it; this run cannot verify anything`];if(!e.regressed)return[` no regression against baseline (score ${e.scoreDelta>=0?"+":""}${String(e.scoreDelta)})`];const r=[` REGRESSED against baseline (score ${e.scoreDelta>=0?"+":""}${String(e.scoreDelta)})`];for(const n of e.dropped)r.push(` ${n.id}: ${String(n.before)} → ${String(n.after)}`);for(const n of e.newFailing)r.push(` ${n}: now failing`);for(const n of e.worsened)r.push(` ${n}: more findings than the baseline`);return e.projectRegressed&&r.push(" project: new schema/config rules fired"),r},k=(e,r)=>{const n=e.procedures.filter(i=>i.coverage!=="clean"&&i.coverage!=="exempt"),t=f(n),o=[`advisor health ${String(e.score)}/100 — ${e.grade}`,` ${String(e.summary.clean)} clean · ${String(e.summary.warned)} warned · ${String(e.summary.failing)} failing · ${String(e.summary.exempt)} exempt (${String(e.summary.procedures)} procedures, ${String(e.summary.rulesFired)} rules fired)`];return e.project.checks.length>0&&o.push("",` project ${String(e.project.score)}/100 — ${e.project.checks.map(i=>i.name).join(", ")}`),n.length>0&&o.push("",...n.map(i=>g(i,t)),""," run with --all for every procedure, or --entry <file#export> for one"),r!==void 0&&o.push("",...F(r)),o.join(`
2
+ `)},C=e=>e.coverage==="exempt"?[` exempt: ${e.exemptReason===void 0||e.exemptReason===""?"no reason given":e.exemptReason}`]:e.checks.map(r=>{const n=r.occurrences>1?`, ×${String(r.occurrences)}`:"";return` ${r.name} (−${String(r.weight)}${n})`}),T=e=>{const r=new Map;for(const n of e){const t=r.get(n.file);t===void 0?r.set(n.file,[n]):t.push(n)}return[...r].toSorted(([n],[t])=>b(n,t))},B=e=>{const r=f(e.procedures),n=[`advisor health ${String(e.score)}/100 — ${e.grade}`,"",` legend: ${l.clean} clean ${l.warned} warned ${l.failing} failing ${l.exempt} exempt`];for(const[t,o]of T(e.procedures)){n.push("",` ${t}`);for(const i of o)n.push(g(i,r),...C(i))}return n.join(`
3
+ `)},I=(e,r)=>{const n=e.procedures.find(o=>o.id===r);if(n===void 0){const o=e.procedures.slice(0,10).map(i=>` ${i.id}`);return[`no procedure ${r} in the map. Known ids:`,...o,e.procedures.length>10?" …":""].filter(Boolean).join(`
4
+ `)}const t=[`${R(n)} — ${String(n.score)}/100, ${n.coverage}`,` weight in the global mean: ${String(n.weight)}`];if(n.checks.length===0)return t.push(""," no rule fired"),t.join(`
5
+ `);t.push(""," rules fired:");for(const o of n.checks)t.push(` [${o.level}] ${o.name} −${String(o.weight)}${o.occurrences>1?` (×${String(o.occurrences)})`:""}`);return t.join(`
6
+ `)},L=new Date(0).toISOString(),m=(e,r)=>w(r)?r:v(e,r),N=e=>{if(e===void 0)return{value:void 0};if(e===null||e==="")return{error:"--min-score needs a value between 0 and 100"};const r=Number(e);return Number.isFinite(r)&&r>=0&&r<=100?{value:r}:{error:"--min-score must be a number between 0 and 100"}},P=(e,r,n)=>{const t=m(r,n===null||n===""?u:n);if(!S(t))return{error:`baseline not found at ${t} — generate one with \`lunora advisor\` and commit it`};const o=x(JSON.parse(p(t,"utf8")));return o===void 0?{error:`baseline at ${t} is malformed — regenerate it with \`lunora advisor\``}:{comparison:j(e,o)}},_=e=>`baseline is not comparable (${e}) — regenerate it; this run verified nothing`,G=(e,r,n)=>r.entry!==void 0?I(e,r.entry):r.all===!0?B(e):k(e,n),H=e=>{const r=e.cwd??process.cwd(),n=e.format==="json",{logger:t}=e,o=N(e.minScore);if("error"in o)return e.logger.error(o.error),{code:E.USAGE,error:o.error};const{advisorContext:i,advisories:$}=A({dryRun:!0,projectRoot:r,...M(r)}),a=y(i?.procedureProtections??[],$,{generatedAt:e.generatedAt??L}),s={map:a};if(e.baseline!==void 0){const c=P(a,r,e.baseline);if("error"in c)return e.logger.error(c.error),{...s,error:c.error};s.comparison=c.comparison,c.comparison.comparable||e.logger.error(_(c.comparison.reason))}if(e.write!==!1){const c=m(r,e.out??u);h(c,`${JSON.stringify(a,void 0,4)}
7
+ `,"utf8"),s.written=c}return s.belowMinScore=o.value!==void 0&&a.score<o.value,s.belowMinScore&&t.error(`advisor score ${String(a.score)} is below the required ${String(o.value)}`),n||(t.info(G(a,e,s.comparison)),s.written!==void 0&&t.success(`wrote ${s.written}`)),s},J=e=>e.error!==void 0||e.belowMinScore===!0?!0:e.comparison!==void 0&&(!e.comparison.comparable||e.comparison.regressed),V=D(({cwd:e,format:r,logger:n,options:t})=>{const o=H({all:t.all,baseline:t.baseline,cwd:e,entry:t.entry,format:r,logger:n,minScore:t.minScore,out:t.out,write:t.write});return{code:o.code??(J(o)?1:0),data:{belowMinScore:o.belowMinScore,comparison:o.comparison,map:o.map,written:o.written},error:o.error}});export{V as execute,H as runAdvisorCommand};
@@ -1,105 +1 @@
1
- import { existsSync, readFileSync, readdirSync, statSync, mkdirSync, writeFileSync } from 'node:fs';
2
- import { fileURLToPath } from 'node:url';
3
- import { AGENT_RULES_DIR, detectAgentRules, LUNORA_SKILL_NAMES } from '@lunora/config';
4
- import { join, relative, dirname } from '@visulima/path';
5
- import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
6
-
7
- const resolveBundledSkillsDirectory = (startDirectory = dirname(fileURLToPath(import.meta.url))) => {
8
- let directory = startDirectory;
9
- for (let index = 0; index < 6; index += 1) {
10
- const packageJson = join(directory, "package.json");
11
- if (existsSync(packageJson)) {
12
- try {
13
- const parsed = JSON.parse(readFileSync(packageJson, "utf8"));
14
- if (parsed.name === "@lunora/cli") {
15
- const skills = join(directory, "skills");
16
- return existsSync(skills) ? skills : void 0;
17
- }
18
- } catch {
19
- }
20
- }
21
- const parent = dirname(directory);
22
- if (parent === directory) {
23
- break;
24
- }
25
- directory = parent;
26
- }
27
- return void 0;
28
- };
29
- const listBundledSkills = (skillsDirectory) => readdirSync(skillsDirectory).filter((name) => {
30
- const directory = join(skillsDirectory, name);
31
- return statSync(directory).isDirectory() && existsSync(join(directory, "SKILL.md"));
32
- });
33
- const copySkill = (source, destination, overwrite) => {
34
- mkdirSync(destination, { recursive: true });
35
- let wrote = false;
36
- for (const entry of readdirSync(source)) {
37
- const from = join(source, entry);
38
- const to = join(destination, entry);
39
- if (statSync(from).isDirectory()) {
40
- wrote = copySkill(from, to, overwrite) || wrote;
41
- continue;
42
- }
43
- if (existsSync(to) && !overwrite) {
44
- continue;
45
- }
46
- writeFileSync(to, readFileSync(from));
47
- wrote = true;
48
- }
49
- return wrote;
50
- };
51
- const runRulesInstall = (options) => {
52
- const cwd = options.cwd ?? process.cwd();
53
- const overwrite = options.overwrite === true;
54
- const skillsDirectory = resolveBundledSkillsDirectory();
55
- if (skillsDirectory === void 0) {
56
- options.logger.error("rules: could not locate the bundled skills (is @lunora/cli installed correctly?).");
57
- return { code: 1, installed: [], skipped: [] };
58
- }
59
- const installed = [];
60
- const skipped = [];
61
- for (const name of listBundledSkills(skillsDirectory)) {
62
- const destination = join(cwd, AGENT_RULES_DIR, name);
63
- const wrote = copySkill(join(skillsDirectory, name), destination, overwrite);
64
- if (wrote) {
65
- installed.push(name);
66
- } else {
67
- skipped.push(name);
68
- }
69
- }
70
- const target = relative(cwd, join(cwd, AGENT_RULES_DIR)) || AGENT_RULES_DIR;
71
- if (installed.length > 0) {
72
- options.logger.success(`Installed ${String(installed.length)} Lunora skill(s) into ${target}/: ${installed.join(", ")}.`);
73
- }
74
- if (skipped.length > 0) {
75
- options.logger.info(`Skipped ${String(skipped.length)} existing skill(s) (re-run with --overwrite to replace): ${skipped.join(", ")}.`);
76
- }
77
- options.logger.info("Your AI coding agent will pick these up automatically. Start with the `lunora` skill.");
78
- return { code: 0, installed, skipped };
79
- };
80
- const runRulesCheck = (options) => {
81
- const cwd = options.cwd ?? process.cwd();
82
- const status = detectAgentRules(cwd);
83
- if (status.installed) {
84
- options.logger.success(`Lunora agent rules are installed (${String(status.present.length)}/${String(LUNORA_SKILL_NAMES.length)} skills).`);
85
- if (status.missing.length > 0) {
86
- options.logger.info(`Missing: ${status.missing.join(", ")}. Run \`lunora rules install\` to add them.`);
87
- }
88
- return { code: 0, installed: status.present, skipped: [] };
89
- }
90
- options.logger.warn("Lunora agent rules are not installed. Run `lunora rules install` so your AI agent knows how to use Lunora.");
91
- return { code: options.strict === true ? 1 : 0, installed: status.present, skipped: [] };
92
- };
93
- const execute = defineHandler(({ argument, cwd, logger, options }) => {
94
- const subcommand = argument[0] ?? "check";
95
- if (subcommand === "install") {
96
- return runRulesInstall({ cwd, logger, overwrite: options.overwrite === true });
97
- }
98
- if (subcommand === "check") {
99
- return runRulesCheck({ cwd, logger, strict: options.strict === true });
100
- }
101
- logger.error("rules: unknown subcommand. Usage: lunora rules <install|check>");
102
- return { code: 1 };
103
- });
104
-
105
- export { execute, resolveBundledSkillsDirectory, runRulesCheck, runRulesInstall };
1
+ import{join as u,resolve as m}from"node:path";import{p as f}from"../packem_shared/deploy-target-DCWwiuAe.mjs";import{d as p}from"../packem_shared/command-CAXl2A1S.mjs";import{defaultSpawner as w}from"../packem_shared/createRecordingSpawner-Ch7zuQQE.mjs";import{runDeployCommand as y}from"./runDeployCommand.mjs";import{readdirSync as g,readFileSync as S}from"node:fs";import{gzipSync as b}from"node:zlib";const d=64*1024*1024,h=e=>!e.endsWith(".map")&&e!=="bundle-meta.json"&&e!=="README.md",v=e=>{let n;try{n=g(e,{recursive:!0,withFileTypes:!0})}catch{return}let o=0,r=0,t=0;for(const i of n){if(!i.isFile()||!h(i.name))continue;const a=S(u(i.parentPath,i.name));o+=1,t+=a.byteLength,r+=b(a).byteLength}return o===0?void 0:{files:o,gzipBytes:r,rawBytes:t}},l=".lunora/build",B=async e=>w({...e,stdoutToStderr:!0}),c=e=>`${(e/1024).toFixed(1)} KiB`,D=async e=>{const n=e.outDir??l,o=e.format==="json",{logger:r}=e,t=await y({allowSchemaDrift:e.allowSchemaDrift,apiSpec:e.apiSpec,commandName:"build",cwd:e.cwd,dryRun:!0,emitBindings:e.emitBindings,format:void 0,interactive:o?!1:void 0,logger:r,outDir:n,spawner:e.spawner??(o?B:void 0),strictAdvisories:e.strictAdvisories,target:e.target});if(t.code!==0)return t;r.success(`build complete — bundle written to ${n}`);const i=v(m(e.cwd??process.cwd(),n));if(i===void 0)r.warn(`could not weigh the bundle — nothing uploadable was found in ${n}`);else{const a=(i.rawBytes/d*100).toFixed(1),s=`bundle: ${c(i.rawBytes)} raw across ${String(i.files)} file(s) — ${a}% of Cloudflare's 64 MiB uncompressed Worker size limit (${c(i.gzipBytes)} gzipped, for reference; there is no compressed limit)`;i.rawBytes>d?r.warn(`${s} — Cloudflare will reject this upload`):r.info(s)}return{...t,bundle:i}},R=p(async({cwd:e,format:n,logger:o,options:r})=>{const t=await D({allowSchemaDrift:r.allowSchemaDrift===!0,apiSpec:f(r.apiSpec),cwd:e,emitBindings:r.emitBindings,format:n,logger:o,outDir:r.outDir,strictAdvisories:r.strictAdvisories,target:r.target});return{code:t.code,data:{bundle:t.bundle,deployment:t.deployment,outDir:r.outDir??l,validation:t.validation},error:t.error}});export{R as execute,D as runBuildCommand};
@@ -1,170 +1,3 @@
1
- import { existsSync } from 'node:fs';
2
- import { mkdtemp, writeFile, rm } from 'node:fs/promises';
3
- import { tmpdir } from 'node:os';
4
- import { discoverSchema, schemaFromIr } from '@lunora/codegen';
5
- import { seedPlan } from '@lunora/seed';
6
- import { join } from '@visulima/path';
7
- import { Project } from 'ts-morph';
8
- import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
9
- import { a as resolveProductionWorkerUrl } from '../packem_shared/resolve-target-qbsJ_5sF.mjs';
10
- import { b as tuiConfirm } from '../packem_shared/tui-prompts-BjEN8XgP.mjs';
11
- import { runImportCommand } from '../packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Ck-2bU08.mjs';
12
- import { runResetCommand } from './runResetCommand.mjs';
13
-
14
- const isLocalUrl = (url) => {
15
- if (url === void 0) {
16
- return true;
17
- }
18
- try {
19
- const { hostname } = new URL(url);
20
- return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]" || hostname === "::1";
21
- } catch {
22
- return false;
23
- }
24
- };
25
- const ndjsonReplacer = (_key, value) => {
26
- if (typeof value === "bigint") {
27
- return Number(value);
28
- }
29
- if (value instanceof ArrayBuffer) {
30
- return [...new Uint8Array(value)];
31
- }
32
- return value;
33
- };
34
- const seedFailure = (code) => {
35
- return { code, conflicts: 0, generated: 0, inserted: 0, ndjson: "" };
36
- };
37
- const guardSeedTargets = (options, schemaPath) => {
38
- if (!existsSync(schemaPath)) {
39
- options.logger.error(`schema not found: ${schemaPath} — run \`vis generate lunora-table --name=<name>\` to create one`);
40
- return seedFailure(1);
41
- }
42
- if (options.reset === true && (options.prod === true || !isLocalUrl(options.url))) {
43
- options.logger.error("--reset only clears local .wrangler/state and cannot be combined with --prod or a remote --url");
44
- return seedFailure(1);
45
- }
46
- return void 0;
47
- };
48
- const insertSeedRows = async (ndjson, generated, cwd, options) => {
49
- const scratchDirectory = await mkdtemp(join(tmpdir(), "lunora-seed-"));
50
- const temporaryFile = join(scratchDirectory, "rows.ndjson");
51
- await writeFile(temporaryFile, ndjson, "utf8");
52
- try {
53
- const result = await runImportCommand({
54
- batchSize: options.batchSize,
55
- fetchImpl: options.fetchImpl,
56
- file: temporaryFile,
57
- logger: options.logger,
58
- prod: options.prod,
59
- token: options.token,
60
- url: options.url
61
- });
62
- const conflicts = result.body?.conflicts ?? 0;
63
- if (conflicts > 0) {
64
- options.logger.warn(
65
- `${String(conflicts)} row(s) skipped — their _id already exists. Seeding is deterministic; re-run with --reset to wipe local state first, or a different --seed for fresh ids.`
66
- );
67
- }
68
- return { code: result.code, conflicts, generated, inserted: result.inserted, ndjson };
69
- } finally {
70
- await rm(scratchDirectory, { force: true, recursive: true }).catch(() => {
71
- });
72
- }
73
- };
74
- const validateSeedTable = (options, ir) => {
75
- if (options.table === void 0 || ir.tables.some((table) => table.name === options.table)) {
76
- return void 0;
77
- }
78
- const available = ir.tables.map((table) => table.name).join(", ");
79
- options.logger.error(`unknown table "${options.table}" — schema defines: ${available || "(no tables)"}`);
80
- return seedFailure(1);
81
- };
82
- const confirmRemoteSeedTarget = async (options, generated) => {
83
- const targetsRemote = options.prod === true || !isLocalUrl(options.url);
84
- if (!targetsRemote || options.yes === true) {
85
- return void 0;
86
- }
87
- if (!process.stdin.isTTY && options.confirm === void 0) {
88
- options.logger.error("seed: refusing to insert into a non-local target without confirmation — re-run with --yes");
89
- return seedFailure(1);
90
- }
91
- const confirmer = options.confirm ?? tuiConfirm;
92
- const confirmed = await confirmer(`This will insert ${String(generated)} generated row(s) into ${options.url ?? "the production worker"}. Continue?`);
93
- if (!confirmed) {
94
- options.logger.info("seed: aborted");
95
- return seedFailure(1);
96
- }
97
- return void 0;
98
- };
99
- const runSeedCommand = async (options) => {
100
- const cwd = options.cwd ?? process.cwd();
101
- const schemaPath = join(cwd, "lunora", "schema.ts");
102
- const guard = guardSeedTargets(options, schemaPath);
103
- if (guard !== void 0) {
104
- return guard;
105
- }
106
- const project = new Project({ skipAddingFilesFromTsConfig: true });
107
- const ir = discoverSchema(project, schemaPath);
108
- const unknownTable = validateSeedTable(options, ir);
109
- if (unknownTable !== void 0) {
110
- return unknownTable;
111
- }
112
- const schema = schemaFromIr(ir);
113
- const plan = seedPlan(schema, {
114
- defaultCount: options.count ?? 10,
115
- only: options.table === void 0 ? void 0 : [options.table],
116
- seed: options.seed ?? 0
117
- });
118
- const lines = [];
119
- for (const { rows, table } of plan) {
120
- for (const row of rows) {
121
- lines.push(JSON.stringify({ doc: row, table }, ndjsonReplacer));
122
- }
123
- }
124
- const ndjson = lines.length > 0 ? `${lines.join("\n")}
125
- ` : "";
126
- const generated = lines.length;
127
- if (options.dryRun === true) {
128
- if (ndjson.length > 0) {
129
- process.stdout.write(ndjson);
130
- }
131
- options.logger.info(`generated ${String(generated)} row(s) across ${String(plan.length)} table(s) — dry run, nothing inserted`);
132
- return { code: 0, conflicts: 0, generated, inserted: 0, ndjson };
133
- }
134
- if (options.reset === true) {
135
- const reset = await runResetCommand({ cwd, logger: options.logger, yes: true });
136
- if (reset.code !== 0) {
137
- return { code: reset.code, conflicts: 0, generated, inserted: 0, ndjson };
138
- }
139
- }
140
- if (generated === 0) {
141
- options.logger.warn("no rows generated — nothing to insert");
142
- return { code: 0, conflicts: 0, generated: 0, inserted: 0, ndjson };
143
- }
144
- const aborted = await confirmRemoteSeedTarget(options, generated);
145
- if (aborted !== void 0) {
146
- return aborted;
147
- }
148
- return insertSeedRows(ndjson, generated, cwd, options);
149
- };
150
- const execute = defineHandler(async ({ cwd, logger, options }) => {
151
- const result = await runSeedCommand({
152
- batchSize: options.batchSize,
153
- count: options.count,
154
- cwd,
155
- dryRun: options.dryRun === true,
156
- logger,
157
- prod: options.prod === true,
158
- reset: options.reset === true,
159
- seed: options.seed,
160
- table: options.table,
161
- token: options.token,
162
- // Resolve the link here (only under --prod) so seed's own remote/confirm
163
- // logic and the downstream import both see the same effective target.
164
- url: resolveProductionWorkerUrl({ cwd, prod: options.prod === true, url: options.url }),
165
- yes: options.yes === true
166
- });
167
- return { code: result.code };
168
- });
169
-
170
- export { execute, runSeedCommand };
1
+ import{writeFileSync as E,existsSync as w,cpSync as j,statSync as b,lstatSync as I,readdirSync as N,mkdirSync as D,readFileSync as M}from"node:fs";import{join as u,sep as x,relative as B,resolve as O,dirname as K}from"node:path";import{SDK_TARGETS as V,SDK_LANGUAGES as G,generateSdk as P,isTypedSchema as Q}from"@lunora/codegen";import{LunoraError as d}from"@lunora/errors";import{d as J}from"../packem_shared/command-CAXl2A1S.mjs";import{r as _,a as q,b as H,s as W}from"../packem_shared/resolve-BrsV4Qyc.mjs";import{r as U}from"../packem_shared/cli-manifest-CRet0egA.mjs";const $="gh:anolilab/lunora/sdks",v="lunora-transport.json",X=/_test\.|Tests?\./u,k=t=>t.startsWith("test_")||X.test(t),A=(t,o="")=>N(t).toSorted((e,r)=>e.localeCompare(r)).flatMap(e=>{const r=u(t,e),a=o.length>0?`${o}/${e}`:e;return b(r).isDirectory()?A(r,a):[a]}),C=(t,o)=>{const e=I(o);if(e.isSymbolicLink())throw new d("INTERNAL",`refusing to vendor "${B(t,o)}" — it is a symlink, not a regular file`);if(e.isDirectory())for(const r of N(o))k(r)||C(t,u(o,r))},F=(t,o,e,r)=>{const a=u(t,e);if(!w(a))throw new d("NOT_FOUND",`transport is missing ${e}`);C(t,a);const s=u(o,r);return j(a,s,{filter:n=>!k(n.slice(n.lastIndexOf(x)+1)),force:!0,recursive:!0}),b(s).isDirectory()?A(s).map(n=>`${r}/${n}`):[r]},R=(t,o)=>o.vendor.every(e=>w(u(t,e.from))),z=async(t,o)=>{const{language:e,logger:r,outputDirectory:a,registryOptions:s,target:n}=o,{cleanup:f,directory:h}=await H(e,{...s,ref:t},$);try{if(!R(h,n)){r.warn(`${$}/${e} does not exist at ${t}.`);return}return{files:n.vendor.flatMap(c=>F(h,a,c.from,c.to)).toSorted((c,l)=>c.localeCompare(l)),ref:t,source:`${$}/${e}`,versionMatched:t===_()}}finally{f()}},Y=(t,o)=>{const{language:e,outputDirectory:r,target:a}=o,s=u(t,e);if(!w(s))throw new d("NOT_FOUND",`no transport at ${s} — --from must point at a directory of per-language transports (the repo's \`sdks/\`)`);if(!R(s,a)){const n=a.vendor.map(f=>f.from).join(", ");throw new d("NOT_FOUND",`${s} is not a ${e} transport — expected it to contain ${n}`)}return{files:a.vendor.flatMap(n=>F(s,r,n.from,n.to)).toSorted((n,f)=>n.localeCompare(f)),ref:"local",source:s,versionMatched:!1}},Z=async t=>{const{allowUnsafeSource:o,from:e,language:r,logger:a,outputDirectory:s,ref:n,source:f,target:h}=t;if(e!==void 0)return Y(e,{language:r,outputDirectory:s,target:h});const c={allowUnsafeSource:o,logger:a,names:[],source:f},l=async i=>z(await q(i,a),{language:r,logger:a,outputDirectory:s,registryOptions:c,target:h});if(n!==void 0&&n.length>0){const i=await l(n);if(i===void 0)throw new d("NOT_FOUND",`--ref ${n} carries no ${r} transport — pick a ref that does, or pass --from <dir> to copy a local one`);return i}const p=_(),g=await l(p).catch(i=>{const y=i instanceof Error?i.message.split(`
2
+ `)[0]??i.message:String(i);a.warn(`could not fetch the transport at ${p} (${y}).`)});if(g!==void 0)return g;const m=await l(void 0);if(m===void 0)throw new d("NOT_FOUND",`no ${r} transport at ${p} or on the release branch. This language may not be released yet — pass --from <dir> to copy one from a checkout, or --ref <tag> to name a ref that has it.`);return a.warn(`FALLBACK: the transport is NOT version-matched to this CLI (${U()}). Wanted ${p}, used ${m.ref}. The vendored wire protocol may not be the one this surface was generated against; ${v} records what was actually copied.`),m},ee=(t,o,e)=>{const r={cliVersion:U(),files:e.files,language:o,note:e.versionMatched?"Vendored by `lunora sdk generate` at the ref matching the CLI that generated the surface beside it. Regenerate with a newer CLI to upgrade.":"Vendored by `lunora sdk generate` from a ref that is NOT this CLI's release tag, so the transport and the generated surface may be different protocol vintages.",ref:e.ref,source:e.source,versionMatched:e.versionMatched};E(u(t,v),`${JSON.stringify(r,void 0,4)}
3
+ `,"utf8")},te=u("lunora","_generated","openrpc.json"),re=t=>{if(!w(t))throw new d("NOT_FOUND",`no OpenRPC document at ${t} — run \`lunora codegen --api-spec openrpc\` (or \`--api-spec both\`) first, or pass --spec`);let o;try{o=JSON.parse(M(t,"utf8"))}catch(e){throw new d("BAD_REQUEST",`${t} is not valid JSON: ${e instanceof Error?e.message:String(e)}`)}if(o===null||typeof o!="object"||!Array.isArray(o.methods))throw new d("BAD_REQUEST",`${t} is not an OpenRPC document (no \`methods\` array)`);return o},le=J(async({argument:t,cwd:o,logger:e,options:r})=>{const a=t[0]??"generate";if(a!=="generate")throw new d("BAD_REQUEST",`unknown subcommand "${a}" — the only one is \`lunora sdk generate\``);const s=r.lang??"python",n=V[s];if(n===void 0)throw new d("BAD_REQUEST",`unsupported --lang "${s}" — expected one of: ${G.join(" | ")}`);const f=W("sdk generate",{allowUnsafeSource:r.allowUnsafeSource,logger:e,names:[],source:r.source});if(f!==void 0)throw new d("BAD_REQUEST",f);const h=O(o,r.spec??te),c=O(o,r.out??u("sdk",s)),l=re(h);l.methods.length===0&&e.warn(`${h} declares no methods — writing an empty SDK.`);const{files:p,undeclared:g,unrepresentable:m}=await P(l,n);D(c,{recursive:!0});const i=await Z({allowUnsafeSource:r.allowUnsafeSource,from:r.from,language:s,logger:e,outputDirectory:c,ref:r.ref,source:r.source,target:n});ee(c,s,i);for(const[S,L]of Object.entries(p)){const T=u(c,S);D(K(T),{recursive:!0}),E(T,L,"utf8")}const y=l.methods.filter(S=>!Q(S.result?.schema)).length;return e.success(`Generated ${s} SDK for ${String(l.methods.length)} function(s) → ${c}`),e.info(`Vendored the ${s} transport (${String(i.files.length)} file(s)) from ${i.source} @ ${i.ref}${i.versionMatched?" — version-matched to this CLI":""}; see ${v}.`),e.info(n.requires.length>0?`Install in the consuming project: ${n.requires.join(", ")}.`:"Nothing to install — the transport is vendored and needs only the standard library."),g.length>0&&e.warn(`${String(g.length)} schema(s) are not expressible as a named ${s} model, so those arguments or returns stay untyped: ${g.join(", ")}`),m.length>0&&e.warn(`${String(m.length)} function(s) take or return a \`v.bigint()\`/\`v.bytes()\`, which no generated model can carry — their parameters stay untyped, so pass wire values directly: ${m.join(", ")}`),y>0&&e.warn(`${String(y)} of ${String(l.methods.length)} function(s) return an untyped result — declare \`.output()\` on them for typed returns.`),{code:0}});export{le as execute};