@akanjs/cli 3.2.0-rc.2 → 3.2.0-rc.20

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 (132) hide show
  1. package/.build-stamp +2 -1
  2. package/CodeAgent-faqv7t4g.js +11 -0
  3. package/{CodeTui-zyc7zaq6.js → CodeTui-vqck9tet.js} +822 -666
  4. package/README.ko.md +26 -1
  5. package/README.md +26 -1
  6. package/TunnelShare-bwe3ddv7.js +18 -0
  7. package/agent.command-p75jvgrd.js +56 -0
  8. package/akanCode.js +12 -12
  9. package/appExecutor-020cyesq.js +11 -0
  10. package/{application.command-vb278qnq.js → application.command-ta2knqxm.js} +72 -34
  11. package/{applicationBuildRunner-bqbyeg84.js → applicationBuildRunner-gkh82j2b.js} +18 -13
  12. package/buildBatch.proc.js +26 -11
  13. package/{cloud.command-ca777ee2.js → cloud.command-v3jhfvm5.js} +31 -28
  14. package/cloud.script-be9s1432.js +35 -0
  15. package/{code.command-j08txqcd.js → code.command-mh7dh1st.js} +14 -9
  16. package/{context.command-2fa6egp9.js → context.command-1ycfjkdd.js} +28 -23
  17. package/context.runner-333jkz86.js +34 -0
  18. package/{dependencyScanner-78sq8m4q.js → dependencyScanner-ge10gb52.js} +2 -2
  19. package/{devTui-w38ch13a.js → devTui-rf374y2w.js} +1 -1
  20. package/{fileSys-zpvt5gtf.js → fileSys-q22646yc.js} +1 -1
  21. package/{guideline.command-w6yqpdec.js → guideline.command-w1grfwh7.js} +9 -4
  22. package/guidelines/agentRule/agentRule.instruction.md +17 -5
  23. package/guidelines/akanApi/akanApi.instruction.md +3 -1
  24. package/guidelines/conventions/core.md +23 -5
  25. package/guidelines/conventions/rules/app.md +4 -1
  26. package/guidelines/conventions/rules/page.md +5 -0
  27. package/guidelines/errorCodes/errorCodes.instruction.md +158 -0
  28. package/guidelines/fieldRule/fieldRule.instruction.md +2 -1
  29. package/guidelines/mcpRule/mcpRule.instruction.md +74 -2
  30. package/guidelines/pageRule/pageRule.instruction.md +11 -1
  31. package/guidelines/runtimeRule/runtimeRule.instruction.md +7 -2
  32. package/guidelines/transportRule/transportRule.instruction.md +8 -1
  33. package/incrementalBuilder.proc.js +574 -410
  34. package/{index-c5ymqb05.js → index-013n6z7m.js} +12 -12
  35. package/{index-w15mg3km.js → index-0dm25wvf.js} +1 -1
  36. package/{index-8nbx607g.js → index-0hj82f9w.js} +136 -48
  37. package/{index-ebwkh7bt.js → index-1c0mjc2b.js} +25 -7
  38. package/{index-6h775rv3.js → index-1jk52ffq.js} +53 -12
  39. package/{index-hj6w4ka1.js → index-1p81ecbz.js} +1 -1
  40. package/{index-ygrdw6jw.js → index-1pjwsh2g.js} +65 -8
  41. package/{index-cbcwxp5v.js → index-22g3jq43.js} +9 -7
  42. package/{index-466z5931.js → index-2d9nm03s.js} +580 -364
  43. package/{index-0fj9ra3q.js → index-2k6mve6a.js} +18 -11
  44. package/{index-qd7xn2bk.js → index-2ny1e95c.js} +2 -2
  45. package/{index-j7p0jgaq.js → index-52w4jb87.js} +6 -6
  46. package/{index-e22zedc2.js → index-5h888r6j.js} +3 -3
  47. package/{index-7kmbqp0b.js → index-6pxmcaq8.js} +1 -1
  48. package/{index-xa0289eg.js → index-6zb17wcm.js} +16 -9
  49. package/{index-qgazn58x.js → index-7a07tdap.js} +50 -38
  50. package/{index-m5sg5spm.js → index-7ehdht84.js} +565 -187
  51. package/{index-y725zb1a.js → index-7v7tvgt7.js} +196 -168
  52. package/{index-pq5rjkch.js → index-88s746ns.js} +7 -2
  53. package/{index-r0a604h4.js → index-99kjwyma.js} +1 -1
  54. package/{index-2mrn1mrg.js → index-9f3reh2y.js} +1 -1
  55. package/{index-386canwe.js → index-9rv2zt48.js} +186 -121
  56. package/{index-wr9magsr.js → index-9zswcze5.js} +3 -3
  57. package/{index-xq97me1h.js → index-a41vv4cy.js} +811 -697
  58. package/{index-yf9wc28h.js → index-bejy9zyc.js} +1 -1
  59. package/{index-bdmgqzb5.js → index-bket1068.js} +58 -29
  60. package/{index-bns3wcpc.js → index-by2tvsq6.js} +1 -1
  61. package/{index-1cb9apzn.js → index-czf94w8c.js} +2 -2
  62. package/{index-65b6ms4c.js → index-d3178asw.js} +15 -11
  63. package/index-dss3ds74.js +127 -0
  64. package/{index-annxfpgz.js → index-eyfty8kk.js} +9 -9
  65. package/{index-ny2k80mv.js → index-ffa52fwf.js} +1 -1
  66. package/{index-8jpc5fqv.js → index-g7jgd4xs.js} +2 -2
  67. package/{index-abfbf01s.js → index-gwsesvqc.js} +2 -2
  68. package/{index-kcpk2d20.js → index-h1w4wqgd.js} +1474 -1139
  69. package/{index-j1hjb477.js → index-hp2c7xc2.js} +1 -1
  70. package/index-j4yvgfhr.js +70 -0
  71. package/{index-84c2pgak.js → index-jx2jcw1r.js} +89 -78
  72. package/{index-j6eeh5d7.js → index-knpm8sdm.js} +5 -5
  73. package/{index-2gees180.js → index-mpp4aas6.js} +62 -33
  74. package/index-na8r4a27.js +30 -0
  75. package/{index-0mqga3h9.js → index-nmxszh6x.js} +525 -440
  76. package/{index-35j83zkd.js → index-p5zh7pmc.js} +2 -2
  77. package/{index-20wvskt8.js → index-pt0agdck.js} +1 -1
  78. package/{index-htxck0pn.js → index-q444k260.js} +15 -10
  79. package/{index-wfmpxke3.js → index-qssq2d41.js} +2775 -3677
  80. package/{index-23860fej.js → index-rwgqba9p.js} +24 -9
  81. package/{index-v50xjbbe.js → index-t4d0ckde.js} +1 -1
  82. package/index-va90m8nd.js +25 -0
  83. package/index-vjbne22r.js +80 -0
  84. package/{index-djc5nxpy.js → index-w23tf30e.js} +6 -6
  85. package/{index-mvwvxgtd.js → index-wa01phm9.js} +289 -210
  86. package/{index-h7hehkw6.js → index-xczjdng6.js} +3 -1
  87. package/{index-vbhx60x5.js → index-xwe7y0gf.js} +2140 -2165
  88. package/index-ze48c0vd.js +788 -0
  89. package/{index-dk4g0x0d.js → index-zttyg7tg.js} +27 -16
  90. package/{index-ygdbn9jn.js → index-zyb0ebm4.js} +1 -1
  91. package/index.js +29 -24
  92. package/libExecutor-tq994592.js +10 -0
  93. package/{library.command-8d03a0pq.js → library.command-x219mhcx.js} +9 -4
  94. package/{localRegistry.command-vyv5k6t0.js → localRegistry.command-4p17wa9t.js} +30 -24
  95. package/{module.command-vy3kg965.js → module.command-tjthnvvr.js} +17 -8
  96. package/{package.command-qjh13rs9.js → package.command-c6df2hxx.js} +13 -8
  97. package/package.json +2 -2
  98. package/{page.command-t0nx1jat.js → page.command-gf06paq2.js} +9 -4
  99. package/{pipeline.command-2yjeas7m.js → pipeline.command-y07dgj9b.js} +14 -8
  100. package/pkgExecutor-stde3yc3.js +10 -0
  101. package/{primitive.command-8vm49279.js → primitive.command-0enfygxn.js} +13 -8
  102. package/{projectTypecheck-s9hhe5sa.js → projectTypecheck-mk8wefvd.js} +2 -1
  103. package/{prompter-qrwx1p17.js → prompter-qyggfhqd.js} +2 -2
  104. package/{quality.command-v76fev72.js → quality.command-dkbdztad.js} +23 -16
  105. package/{recipeScanner-4b69ybe0.js → recipeScanner-rrx69awy.js} +1 -1
  106. package/{repair.command-fp4m3w03.js → repair.command-g5vd95ax.js} +13 -8
  107. package/{routeSourceValidator-4h947v7c.js → routeSourceValidator-8n6j1vn7.js} +4 -2
  108. package/{scalar.command-hxe6try8.js → scalar.command-7909pg0d.js} +11 -6
  109. package/skills/akan-debug/SKILL.md +10 -3
  110. package/skills/akan-err/SKILL.md +7 -0
  111. package/skills/akan-mcp/SKILL.md +10 -1
  112. package/skills/akan-scaffold/SKILL.md +2 -2
  113. package/skills/akan-transport/SKILL.md +2 -0
  114. package/skills/akan-validate/SKILL.md +1 -0
  115. package/{subspace.command-q42n1844.js → subspace.command-at4jt1fb.js} +29 -23
  116. package/templates/biomeForm.ts +1 -1
  117. package/templates/env/_env.server.type.ts +1 -1
  118. package/templates/facetIndex/index.ts +2 -37
  119. package/templates/lib/sig.ts +0 -4
  120. package/templates/lib/useClient.ts +1 -1
  121. package/templates/workspaceRoot/AGENTS.md.template +2 -1
  122. package/{tunnel.command-22g11n0x.js → tunnel.command-91h92dwr.js} +17 -12
  123. package/{typeChecker-s640r6c0.js → typeChecker-bfrd1n9n.js} +1 -1
  124. package/typecheck.proc.js +6 -3
  125. package/{verify.command-rx43bha1.js → verify.command-pzky05ts.js} +26 -20
  126. package/{workflow.command-yg0d8mmq.js → workflow.command-mqqe4n12.js} +37 -19
  127. package/{workspace.command-fcfztvn5.js → workspace.command-y4rznvhx.js} +64 -53
  128. package/CodeAgent-6cpjtj25.js +0 -11
  129. package/TunnelShare-zkfkrw8w.js +0 -14
  130. package/agent.command-kf1g3nh4.js +0 -51
  131. package/cloud.script-agpxzq6j.js +0 -30
  132. package/context.runner-ftv8373t.js +0 -29
@@ -1,16 +1,28 @@
1
1
  // @bun
2
+ import {
3
+ CliError
4
+ } from "./index-j4yvgfhr.js";
5
+ import {
6
+ Executor,
7
+ WorkspaceExecutor
8
+ } from "./index-qssq2d41.js";
2
9
  import {
3
10
  getDirname2,
4
11
  FileSys2
5
- } from "./index-bns3wcpc.js";
12
+ } from "./index-by2tvsq6.js";
6
13
  import {
7
- Executor,
8
- WorkspaceExecutor,
9
- AppExecutor,
10
- LibExecutor,
11
- PkgExecutor,
12
- ModuleExecutor
13
- } from "./index-wfmpxke3.js";
14
+ AppExecutor2
15
+ } from "./index-ze48c0vd.js";
16
+ import {
17
+ LibExecutor2
18
+ } from "./index-na8r4a27.js";
19
+ import {
20
+ PkgExecutor2
21
+ } from "./index-dss3ds74.js";
22
+ import {
23
+ ModuleExecutor,
24
+ ErrorReport
25
+ } from "./index-vjbne22r.js";
14
26
 
15
27
  // pkgs/@akanjs/devkit/commandDecorators/camelToKebabCase.ts
16
28
  var camelToKebabCase = (str) => str.replace(/([A-Z])/g, "-$1").toLowerCase();
@@ -58,6 +70,7 @@ var SysOrOnlyApp = createInternalArgToken("Sys", { onlyApp: true });
58
70
  var Exec = createInternalArgToken("Exec");
59
71
  var Pkg = createInternalArgToken("Pkg");
60
72
  var Module = createInternalArgToken("Module");
73
+ var ModuleOrService = createInternalArgToken("Module", { services: true });
61
74
  var Workspace = createInternalArgToken("Workspace");
62
75
  // pkgs/@akanjs/devkit/commandDecorators/command.ts
63
76
  import path3 from "path";
@@ -65,7 +78,7 @@ import { Logger } from "akanjs/common";
65
78
  import chalk2 from "chalk";
66
79
  import { program } from "commander";
67
80
 
68
- // pkgs/@akanjs/devkit/appSelectionMemory.ts
81
+ // pkgs/@akanjs/devkit/workspace/appSelectionMemory.ts
69
82
  import path from "path";
70
83
  class AppSelectionMemory {
71
84
  static pathIn(workspaceRoot) {
@@ -160,19 +173,6 @@ var script = (refName, deps = []) => {
160
173
  return ScriptBase;
161
174
  };
162
175
 
163
- // pkgs/@akanjs/devkit/commandDecorators/exitCodeError.ts
164
- class ExitCodeError extends Error {
165
- exitCode;
166
- name = "ExitCodeError";
167
- constructor(message, exitCode) {
168
- super(message);
169
- this.exitCode = exitCode;
170
- }
171
- static codeOf(error) {
172
- return error instanceof ExitCodeError ? error.exitCode : null;
173
- }
174
- }
175
-
176
176
  // pkgs/@akanjs/devkit/commandDecorators/helpFormatter.ts
177
177
  import chalk from "chalk";
178
178
  var formatChoice = (choice) => typeof choice === "object" ? choice.label : choice.toString();
@@ -358,39 +358,54 @@ class WorkspaceVersionCheck {
358
358
 
359
359
  // pkgs/@akanjs/devkit/commandDecorators/command.ts
360
360
  var loggedCliErrorObjects = new WeakSet;
361
+ var answeredCliErrors = new WeakSet;
361
362
  var loggedCliErrorMessages = new Set;
362
363
  var markCliErrorPrinted = (error) => {
363
- if (typeof error === "object" && error !== null)
364
- loggedCliErrorObjects.add(error);
364
+ if (typeof error !== "object" || error === null)
365
+ return;
366
+ loggedCliErrorObjects.add(error);
367
+ answeredCliErrors.add(error);
365
368
  };
366
- var formatCliError = (error) => {
367
- if (error instanceof Error)
368
- return error.message || error.name;
369
- if (typeof error === "string")
370
- return error.trim() || "Unknown error";
371
- if (error === null || error === undefined)
372
- return "Unknown error";
373
- try {
374
- const json = JSON.stringify(error);
375
- if (json)
376
- return json;
377
- } catch {
378
- return String(error);
379
- }
380
- return String(error) || "Unknown error";
381
- };
382
- var printCliError = (error) => {
369
+ var printCliError = (error, stream = "log") => {
383
370
  if (typeof error === "object" && error !== null) {
384
371
  if (loggedCliErrorObjects.has(error))
385
372
  return;
386
373
  loggedCliErrorObjects.add(error);
387
374
  }
388
- const message = formatCliError(error);
375
+ const message = error instanceof Error ? ErrorReport.format(error) || error.name : CliError.messageOf(error);
389
376
  if (loggedCliErrorMessages.has(message))
390
377
  return;
391
378
  loggedCliErrorMessages.add(message);
392
379
  Logger.rawLog(`
393
- ${chalk2.red(message)}`);
380
+ ${chalk2.red(message)}`, undefined, stream);
381
+ };
382
+ var asksJson = (argMetas, opt) => argMetas.some((argMeta) => {
383
+ if (argMeta.type !== "Option")
384
+ return false;
385
+ const value = opt[argMeta.name] ?? argMeta.argsOption.default;
386
+ if (argMeta.name === "json")
387
+ return value === true || value === "true";
388
+ return argMeta.name === "format" && value === "json";
389
+ });
390
+ var writeJsonFailure = async (error) => {
391
+ if (typeof error === "object" && error !== null && answeredCliErrors.has(error))
392
+ return;
393
+ const line = `${JSON.stringify(CliError.failureOf(error))}
394
+ `;
395
+ await new Promise((resolve) => process.stdout.write(line, () => resolve()));
396
+ };
397
+ var failureReporterOf = (json, onFailure, failure) => async (error) => {
398
+ if (onFailure)
399
+ await onFailure(error, failure);
400
+ else if (json)
401
+ await writeJsonFailure(error);
402
+ };
403
+ var usageRefusalOf = (error) => {
404
+ if (error.exitCode === 0)
405
+ process.exit(0);
406
+ const refused = new CliError("usage", error.message.replace(/^error: /, ""));
407
+ loggedCliErrorObjects.add(refused);
408
+ return refused;
394
409
  };
395
410
  var handleOption = (programCommand, argMeta) => {
396
411
  const {
@@ -451,14 +466,14 @@ var assertEnumChoice = (argMeta, value) => {
451
466
  const choices = normalizeEnumChoices(enumChoices);
452
467
  if (choices.some((choice) => String(choice.value) === String(value)))
453
468
  return;
454
- throw new Error(`${argLabelOf(argMeta)} argument '${String(value)}' is invalid. Allowed choices are ${choices.map((choice) => choice.name).join(", ")}.`);
469
+ throw new CliError("usage", `${argLabelOf(argMeta)} argument '${String(value)}' is invalid. Allowed choices are ${choices.map((choice) => choice.name).join(", ")}.`);
455
470
  };
456
471
  var assertPromptable = (problem, refusal = {}) => {
457
472
  if (process.stdin.isTTY)
458
473
  return;
459
474
  throw refusalOf(problem, "stdin is not a terminal to prompt on", refusal);
460
475
  };
461
- var refusalOf = (problem, reason, { choices = [], remedy = "pass it on the command line" }) => new Error(`${problem}: ${reason}, so ${remedy}${choices.length ? ` (choices: ${choices.join(", ")})` : ""}.`);
476
+ var refusalOf = (problem, reason, { choices = [], remedy = "pass it on the command line", code = "usage" }) => new CliError(code, `${problem}: ${reason}, so ${remedy}${choices.length ? ` (choices: ${choices.join(", ")})` : ""}.`);
462
477
  var inputMessageOf = ({ name, argsOption: { desc, example, ask } }) => ask ? `${ask}: ` : desc ? `${desc}: ` : `Enter the ${name} value${example ? ` (example: ${example})` : ""}: `;
463
478
  var getOptionValue = async (argMeta, opt, context) => {
464
479
  const {
@@ -508,11 +523,11 @@ var getArgumentValue = async (argMeta, value) => {
508
523
  return convertArgValue(await input({ message: inputMessageOf(argMeta) }), type ?? "string");
509
524
  };
510
525
  var assignCommandContext = (context, argMeta, value) => {
511
- if (value instanceof AppExecutor)
526
+ if (value instanceof AppExecutor2)
512
527
  context.app = value;
513
- else if (value instanceof LibExecutor)
528
+ else if (value instanceof LibExecutor2)
514
529
  context.lib = value;
515
- else if (value instanceof PkgExecutor)
530
+ else if (value instanceof PkgExecutor2)
516
531
  context.pkg = value;
517
532
  else if (value instanceof ModuleExecutor)
518
533
  context.module = value;
@@ -532,7 +547,7 @@ var assertCurrentDirectoryIsWorkspaceRoot = async () => {
532
547
  ]);
533
548
  if (hasPackageJson && hasTsConfig && hasMemberDirs.some(Boolean))
534
549
  return;
535
- throw new Error([
550
+ throw new CliError("usage", [
536
551
  "Akan CLI commands must be run from the workspace root.",
537
552
  `Current directory: ${cwd}`,
538
553
  "Move to the directory that contains package.json, tsconfig.json, and an apps/, libs/ or pkgs/ folder, then run the command again."
@@ -563,15 +578,15 @@ var getAppsArgumentValue = async (value, workspace, rerun) => {
563
578
  throw new Error("No apps found in this workspace (apps/<appName>/akan.config.ts)");
564
579
  const requested = parseAppNameList(value);
565
580
  if (requested.includes("all"))
566
- return appNames.map((name) => AppExecutor.from(workspace, name));
581
+ return appNames.map((name) => AppExecutor2.from(workspace, name));
567
582
  if (requested.length) {
568
583
  const unknown = requested.filter((name) => !appNames.includes(name));
569
584
  if (unknown.length)
570
- throw new Error(`Unknown app${unknown.length > 1 ? "s" : ""}: ${unknown.join(", ")}. Available: ${appNames.join(", ")}, all`);
571
- return [...new Set(requested)].map((name) => AppExecutor.from(workspace, name));
585
+ throw new CliError("unknownTarget", `Unknown app${unknown.length > 1 ? "s" : ""}: ${unknown.join(", ")}. Available: ${appNames.join(", ")}, all`);
586
+ return [...new Set(requested)].map((name) => AppExecutor2.from(workspace, name));
572
587
  }
573
588
  if (appNames.length === 1 && appNames[0])
574
- return [AppExecutor.from(workspace, appNames[0])];
589
+ return [AppExecutor2.from(workspace, appNames[0])];
575
590
  assertPromptable("Missing apps", { choices: [...appNames, "all"], ...rerunRemedyOf(rerun, "<apps...>") });
576
591
  const remembered = new Set(await AppSelectionMemory.read(workspace.workspaceRoot));
577
592
  const picked = await checkbox({
@@ -580,7 +595,7 @@ var getAppsArgumentValue = async (value, workspace, rerun) => {
580
595
  required: true
581
596
  });
582
597
  await AppSelectionMemory.write(workspace.workspaceRoot, picked);
583
- return picked.map((name) => AppExecutor.from(workspace, name));
598
+ return picked.map((name) => AppExecutor2.from(workspace, name));
584
599
  };
585
600
  var getInternalArgumentValue = async (argMeta, value, workspace, rerun, { destructive = false } = {}) => {
586
601
  if (argMeta.type === "Workspace")
@@ -589,35 +604,40 @@ var getInternalArgumentValue = async (argMeta, value, workspace, rerun, { destru
589
604
  const [appNames, libNames, pkgNames] = await workspace.getExecs();
590
605
  const problemOf = (kind) => value ? `Unknown ${kind} '${value}'` : `Missing ${kind}`;
591
606
  const assertAskable = (kind, choices, placeholder) => {
592
- const refusal = { choices, ...rerunRemedyOf(rerun, placeholder) };
607
+ const refusal = { choices, code: value ? "unknownTarget" : "usage", ...rerunRemedyOf(rerun, placeholder) };
593
608
  if (destructive)
594
609
  throw refusalOf(problemOf(kind), "this command deletes files and never picks its target", refusal);
595
610
  assertPromptable(problemOf(kind), refusal);
596
611
  };
612
+ const takeOnly = (kind, names, take) => {
613
+ const [only] = names;
614
+ if (value || destructive || process.stdin.isTTY || names.length !== 1 || !only)
615
+ return null;
616
+ const how = rerun ? `: ${rerun(only)}` : "";
617
+ Logger.rawLog(`No ${kind} named, so this runs on '${only}', the only one in this workspace${how}`, undefined, "error");
618
+ return take(only);
619
+ };
597
620
  if (sysType === "sys" || sysType === "exec") {
598
621
  const pkgChoices = sysType === "exec" ? pkgNames : [];
599
622
  const execOf = (name) => {
600
623
  if (appNames.includes(name))
601
- return AppExecutor.from(workspace, name);
624
+ return AppExecutor2.from(workspace, name);
602
625
  if (libNames.includes(name))
603
- return LibExecutor.from(workspace, name);
626
+ return LibExecutor2.from(workspace, name);
604
627
  if (pkgChoices.includes(name))
605
- return PkgExecutor.from(workspace, name);
628
+ return PkgExecutor2.from(workspace, name);
606
629
  return null;
607
630
  };
608
631
  const found = value ? execOf(value) : null;
609
632
  if (found)
610
633
  return found;
611
634
  if (!value && !destructive && argMeta.option?.onlyApp && appNames.length === 1 && appNames[0])
612
- return AppExecutor.from(workspace, appNames[0]);
635
+ return AppExecutor2.from(workspace, appNames[0]);
613
636
  const [kind, placeholder] = sysType === "exec" ? ["app, lib or pkg", "<app-lib-or-pkg>"] : ["app or lib", "<app-or-lib>"];
614
637
  const choices = [...appNames, ...libNames, ...pkgChoices];
615
- const only = choices.length === 1 ? execOf(choices[0] ?? "") : null;
616
- if (!value && !destructive && only && !process.stdin.isTTY) {
617
- const how = rerun ? `: ${rerun(only.name)}` : "";
618
- Logger.rawLog(`No ${kind} named, so this runs on '${only.name}', the only one in this workspace${how}`, undefined, "error");
638
+ const only = takeOnly(kind, choices, execOf);
639
+ if (only)
619
640
  return only;
620
- }
621
641
  assertAskable(kind, choices, placeholder);
622
642
  const name = await select({
623
643
  message: sysType === "exec" ? `Select the App or Lib or Pkg name` : `Select the App or Lib name`,
@@ -625,54 +645,68 @@ var getInternalArgumentValue = async (argMeta, value, workspace, rerun, { destru
625
645
  });
626
646
  const picked = execOf(name);
627
647
  if (!picked)
628
- throw new Error(`Invalid system name: ${name}`);
648
+ throw new CliError("unknownTarget", `Invalid system name: ${name}`);
629
649
  return picked;
630
650
  } else if (sysType === "app") {
631
651
  if (value && appNames.includes(value))
632
- return AppExecutor.from(workspace, value);
652
+ return AppExecutor2.from(workspace, value);
633
653
  if (!value && !destructive && appNames.length === 1 && appNames[0])
634
- return AppExecutor.from(workspace, appNames[0]);
654
+ return AppExecutor2.from(workspace, appNames[0]);
635
655
  assertAskable("app", appNames, "<app>");
636
656
  const appName = await select({ message: `Select the ${sysType} name`, choices: appNames });
637
- return AppExecutor.from(workspace, appName);
657
+ return AppExecutor2.from(workspace, appName);
638
658
  } else if (sysType === "lib") {
639
659
  if (value && libNames.includes(value))
640
- return LibExecutor.from(workspace, value);
660
+ return LibExecutor2.from(workspace, value);
661
+ const only = takeOnly("lib", libNames, (name) => LibExecutor2.from(workspace, name));
662
+ if (only)
663
+ return only;
641
664
  assertAskable("lib", libNames, "<lib>");
642
665
  const libName = await select({ message: `Select the ${sysType} name`, choices: libNames });
643
- return LibExecutor.from(workspace, libName);
666
+ return LibExecutor2.from(workspace, libName);
644
667
  } else if (sysType === "pkg") {
645
668
  const pkgs = await workspace.getPkgs();
646
669
  if (value && pkgs.includes(value))
647
- return PkgExecutor.from(workspace, value);
670
+ return PkgExecutor2.from(workspace, value);
671
+ const only = takeOnly("pkg", pkgs, (name) => PkgExecutor2.from(workspace, name));
672
+ if (only)
673
+ return only;
648
674
  assertAskable("pkg", pkgs, "<pkg>");
649
675
  const pkgName = await select({ message: `Select the ${sysType} name`, choices: pkgs });
650
- return PkgExecutor.from(workspace, pkgName);
676
+ return PkgExecutor2.from(workspace, pkgName);
651
677
  } else if (sysType === "module") {
678
+ const systems = [
679
+ ...appNames.map((name) => AppExecutor2.from(workspace, name)),
680
+ ...libNames.map((name) => LibExecutor2.from(workspace, name))
681
+ ];
682
+ const modulesOf = async (sys) => [
683
+ ...await sys.getModules(),
684
+ ...argMeta.option?.services ? await sys.getServiceModules() : []
685
+ ];
686
+ const listModules = async () => (await Promise.all(systems.map(async (sys) => (await modulesOf(sys)).map((m) => `${sys.name}:${m}`)))).flat();
652
687
  if (value) {
653
688
  const [sysName, moduleName] = value.split(":");
654
689
  if (!sysName || !moduleName)
655
- throw new Error(`Invalid module name: ${value}`);
656
- if (appNames.includes(sysName)) {
657
- const app = AppExecutor.from(workspace, sysName);
658
- const modules = await app.getModules();
659
- if (modules.includes(moduleName))
660
- return ModuleExecutor.from(app, moduleName);
661
- else
662
- throw new Error(`Invalid module name: ${moduleName}`);
663
- } else if (libNames.includes(sysName)) {
664
- const lib = LibExecutor.from(workspace, sysName);
665
- const modules = await lib.getModules();
666
- if (modules.includes(moduleName))
667
- return ModuleExecutor.from(lib, moduleName);
668
- } else
669
- throw new Error(`Invalid system name: ${sysName}`);
690
+ throw new CliError("usage", `Invalid module name: ${value}`);
691
+ const sys = systems.find((each) => each.name === sysName);
692
+ if (!sys)
693
+ throw new CliError("unknownTarget", `Invalid system name: ${sysName}`);
694
+ if ((await modulesOf(sys)).includes(moduleName))
695
+ return ModuleExecutor.from(sys, moduleName);
696
+ throw refusalOf(problemOf("module"), `${sysName} has no such module`, {
697
+ code: "unknownTarget",
698
+ choices: await listModules(),
699
+ ...rerunRemedyOf(rerun, "<sys:module>")
700
+ });
670
701
  }
671
- const systems = [
672
- ...appNames.map((name) => AppExecutor.from(workspace, name)),
673
- ...libNames.map((name) => LibExecutor.from(workspace, name))
674
- ];
675
- const choices = process.stdin.isTTY && !destructive ? [] : (await Promise.all(systems.map(async (sys) => (await sys.getModules()).map((m) => `${sys.name}:${m}`)))).flat();
702
+ const choices = process.stdin.isTTY && !destructive ? [] : await listModules();
703
+ const only = takeOnly("module", choices, (label) => {
704
+ const [sysName, moduleName = ""] = label.split(":");
705
+ const sys = systems.find((each) => each.name === sysName);
706
+ return sys ? ModuleExecutor.from(sys, moduleName) : null;
707
+ });
708
+ if (only)
709
+ return only;
676
710
  assertAskable("module", choices, "<sys:module>");
677
711
  const { type, name } = await select({
678
712
  message: `select the App or Lib name`,
@@ -681,8 +715,8 @@ var getInternalArgumentValue = async (argMeta, value, workspace, rerun, { destru
681
715
  ...libNames.map((name) => ({ name, value: { type: "lib", name } }))
682
716
  ]
683
717
  });
684
- const executor = type === "app" ? AppExecutor.from(workspace, name) : LibExecutor.from(workspace, name);
685
- const modules = await executor.getModules();
718
+ const executor = type === "app" ? AppExecutor2.from(workspace, name) : LibExecutor2.from(workspace, name);
719
+ const modules = await modulesOf(executor);
686
720
  const moduleName = await select({
687
721
  message: `Select the module name`,
688
722
  choices: modules.map((name) => ({ name: `${executor.name}:${name}`, value: name }))
@@ -691,13 +725,33 @@ var getInternalArgumentValue = async (argMeta, value, workspace, rerun, { destru
691
725
  } else
692
726
  throw new Error(`Invalid system type: ${argMeta.type}`);
693
727
  };
728
+ var cliFailureOf = () => {
729
+ let failing = false;
730
+ const failure = {
731
+ exitCode: 1,
732
+ usageExitCode: undefined,
733
+ stream: "log",
734
+ report: async (_error) => {},
735
+ exitCodeOf: (error) => {
736
+ const { usageExitCode } = failure;
737
+ if (usageExitCode !== undefined && error instanceof CliError && CliError.usageCodes.includes(error.code))
738
+ return usageExitCode;
739
+ return CliError.exitCodeOf(error) ?? failure.exitCode;
740
+ },
741
+ fail: async (error) => {
742
+ if (failing)
743
+ return;
744
+ failing = true;
745
+ printCliError(error, failure.stream);
746
+ await failure.report(error).catch((reportError) => printCliError(reportError, "error"));
747
+ process.exit(failure.exitCodeOf(error));
748
+ }
749
+ };
750
+ return failure;
751
+ };
694
752
  var runCommands = async (...commands) => {
695
- let failureExitCode = 1;
696
- let reportFailure = async (_error) => {};
697
- process.on("unhandledRejection", (error) => {
698
- printCliError(error);
699
- process.exit(ExitCodeError.codeOf(error) ?? failureExitCode);
700
- });
753
+ const failure = cliFailureOf();
754
+ process.on("unhandledRejection", (error) => void failure.fail(error));
701
755
  const __dirname2 = getDirname2(import.meta.url);
702
756
  const packageJsonCandidates = [`${path3.dirname(Bun.main)}/package.json`, `${__dirname2}/../package.json`];
703
757
  let cliPackageJson = null;
@@ -731,20 +785,16 @@ ${versionWarning}`), undefined, "error");
731
785
  let programCommand = program.command(commandName, {
732
786
  hidden: targetMeta.targetOption.devOnly
733
787
  });
734
- const targetFailureExitCode = targetMeta.targetOption.failureExitCode;
735
- const usageExitCode = targetMeta.targetOption.usageExitCode ?? targetFailureExitCode;
788
+ const { failureExitCode: targetFailureExitCode, usageExitCode: targetUsageExitCode } = targetMeta.targetOption;
736
789
  const { onFailure } = targetMeta.targetOption;
737
790
  const [allArgMetas] = getArgMetas(command, targetMeta.key);
738
- if (usageExitCode !== undefined || onFailure)
739
- programCommand.exitOverride((error) => {
740
- if (error.exitCode === 0)
741
- process.exit(0);
742
- const refused = new ExitCodeError(error.message.replace(/^error: /, ""), usageExitCode ?? error.exitCode);
743
- markCliErrorPrinted(refused);
744
- const given = givenOptionsOf(allArgMetas, programCommand.opts());
745
- reportFailure = async (failure) => await onFailure?.(failure, { usage: true, given });
746
- throw refused;
747
- });
791
+ programCommand.exitOverride((error) => {
792
+ const refused = usageRefusalOf(error);
793
+ failure.usageExitCode = targetUsageExitCode;
794
+ const given = givenOptionsOf(allArgMetas, programCommand.opts());
795
+ failure.report = failureReporterOf(asksJson(allArgMetas, given), onFailure, { usage: true, given });
796
+ throw refused;
797
+ });
748
798
  for (const argMeta of allArgMetas) {
749
799
  if (argMeta.type === "Option")
750
800
  programCommand = handleOption(programCommand, argMeta);
@@ -766,12 +816,18 @@ ${versionWarning}`), undefined, "error");
766
816
  return formatCommandHelp(command, targetMeta.key);
767
817
  };
768
818
  programCommand.action(async (...args) => {
769
- failureExitCode = targetFailureExitCode ?? 1;
819
+ failure.exitCode = targetFailureExitCode ?? 1;
820
+ failure.usageExitCode = targetUsageExitCode;
770
821
  if (!targetMeta.targetOption.stdio)
771
822
  Logger.rawLog();
772
823
  const cmdArgs = args.slice(0, args.length - 2);
773
824
  const opt = args[args.length - 2];
774
- reportFailure = async (failure) => await onFailure?.(failure, { usage: false, given: givenOptionsOf(allArgMetas, opt) });
825
+ const json = asksJson(allArgMetas, opt);
826
+ failure.stream = json ? "error" : "log";
827
+ failure.report = failureReporterOf(json, onFailure, {
828
+ usage: false,
829
+ given: givenOptionsOf(allArgMetas, opt)
830
+ });
775
831
  const commandArgs = [];
776
832
  if (targetMeta.targetOption.runsOnWorkspaceRoot) {
777
833
  await assertCurrentDirectoryIsWorkspaceRoot();
@@ -789,7 +845,7 @@ ${versionWarning}`), undefined, "error");
789
845
  commandArgs[argMeta.idx] = await getAppsArgumentValue(cmdArgs[argMeta.idx], workspace, rerun);
790
846
  else
791
847
  commandArgs[argMeta.idx] = await getInternalArgumentValue(argMeta, cmdArgs[argMeta.idx], workspace, rerun, { destructive: targetMeta.targetOption.destructive });
792
- if (commandArgs[argMeta.idx] instanceof AppExecutor)
848
+ if (commandArgs[argMeta.idx] instanceof AppExecutor2)
793
849
  process.env.AKAN_PUBLIC_APP_NAME = commandArgs[argMeta.idx].name;
794
850
  else if (Array.isArray(commandArgs[argMeta.idx])) {
795
851
  const apps = commandArgs[argMeta.idx];
@@ -806,18 +862,17 @@ ${versionWarning}`), undefined, "error");
806
862
  if (!targetMeta.targetOption.stdio)
807
863
  Logger.rawLog();
808
864
  } catch (e) {
809
- printCliError(e);
865
+ printCliError(e, failure.stream);
810
866
  throw e;
811
867
  }
812
868
  });
813
869
  }
814
870
  }
815
871
  }
816
- await program.parseAsync(process.argv).catch(async (error) => {
817
- printCliError(error);
818
- await reportFailure(error).catch(printCliError);
819
- process.exit(ExitCodeError.codeOf(error) ?? failureExitCode);
872
+ program.exitOverride((error) => {
873
+ throw usageRefusalOf(error);
820
874
  });
875
+ await program.parseAsync(process.argv).catch(failure.fail);
821
876
  };
822
877
  // pkgs/@akanjs/devkit/commandDecorators/commandBuilder.ts
823
878
  var argMetaOf = (type, name, primitive, argsOption, idx) => {
@@ -895,4 +950,14 @@ function command(refName, depsOrBuilder, builder) {
895
950
  }
896
951
  return CommandBase;
897
952
  }
898
- export { camelToKebabCase, getTargetMetas, getTargetCommandNames, App, Apps, Lib, Sys, SysOrOnlyApp, Exec, Pkg, Module, Workspace, CommandContainer, runner, script, ExitCodeError, markCliErrorPrinted, assertPromptable, runCommands, command };
953
+ // pkgs/@akanjs/devkit/commandDecorators/exitCodeError.ts
954
+ class ExitCodeError extends CliError {
955
+ name = "ExitCodeError";
956
+ constructor(message, exitCode) {
957
+ super(exitCode === 2 ? "refused" : exitCode === 3 ? "checkFailed" : "failed", message, { exitCode });
958
+ }
959
+ static codeOf(error) {
960
+ return CliError.exitCodeOf(error);
961
+ }
962
+ }
963
+ export { camelToKebabCase, getTargetMetas, getTargetCommandNames, App, Apps, Lib, Sys, SysOrOnlyApp, Exec, Pkg, Module, ModuleOrService, Workspace, CommandContainer, runner, script, markCliErrorPrinted, assertPromptable, runCommands, command, ExitCodeError };
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  resolveSsrPageEntriesForApp
4
- } from "./index-wfmpxke3.js";
4
+ } from "./index-ze48c0vd.js";
5
5
  import {
6
6
  createBarrelImportsPlugin,
7
7
  workspaceBarrels,
@@ -10,7 +10,7 @@ import {
10
10
  CsrEntryFiles,
11
11
  PagesEntrySourceGenerator,
12
12
  PagesBundleBuilder
13
- } from "./index-84c2pgak.js";
13
+ } from "./index-jx2jcw1r.js";
14
14
 
15
15
  // pkgs/@akanjs/devkit/frontendBuild/csrArtifactBuilder.ts
16
16
  import { mkdir as mkdir2, rm as rm2, unlink as unlink2 } from "fs/promises";
@@ -269,7 +269,7 @@ ${logs}` : ""}`);
269
269
  await rm(stagingDir, { recursive: true, force: true });
270
270
  }
271
271
  static async discover(pageEntries, basePaths) {
272
- const { RouteSourceValidator } = await import("./routeSourceValidator-4h947v7c.js");
272
+ const { RouteSourceValidator } = await import("./routeSourceValidator-8n6j1vn7.js");
273
273
  const roots = pageEntries.filter((entry) => parseRouteModuleKey(entry.key).isInternalRootLayout);
274
274
  const overrides = pageEntries.filter((entry) => parseRouteModuleKey(entry.key).kind === "overrides");
275
275
  const layoutNodes = new Set(pageEntries.flatMap((entry) => {