@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,14 +1,15 @@
1
1
  // @bun
2
+ import {
3
+ ErrorReport
4
+ } from "./index-vjbne22r.js";
2
5
  import {
3
6
  JsonFormatter
4
- } from "./index-wfmpxke3.js";
7
+ } from "./index-qssq2d41.js";
5
8
 
6
- // pkgs/@akanjs/devkit/applicationBuildReporter.ts
7
- import { realpathSync } from "fs";
8
- import path4 from "path";
9
+ // pkgs/@akanjs/devkit/app/applicationBuildReporter.ts
9
10
  import { Logger } from "akanjs/common";
10
11
 
11
- // pkgs/@akanjs/devkit/routeJsBudget.ts
12
+ // pkgs/@akanjs/devkit/app/routeJsBudget.ts
12
13
  import path3 from "path";
13
14
  import { toError } from "akanjs/common";
14
15
 
@@ -668,7 +669,7 @@ class FontPruner {
668
669
  }
669
670
  }
670
671
 
671
- // pkgs/@akanjs/devkit/routeJsBudget.ts
672
+ // pkgs/@akanjs/devkit/app/routeJsBudget.ts
672
673
  class RouteJsBudget {
673
674
  kbByRoute;
674
675
  env;
@@ -694,47 +695,74 @@ class RouteJsBudget {
694
695
  brotliBytes: urls.reduce((total, url) => total + (sizeByUrl.get(url)?.brotli ?? 0), 0)
695
696
  })).sort((a, b) => b.brotliBytes - a.brotliBytes || RouteJsBudget.#byCodeUnit(a.routeId, b.routeId));
696
697
  }
698
+ static modeOf({ checkBudget = false, updateBudget = false, raiseBudget = false }) {
699
+ if ([checkBudget, updateBudget, raiseBudget].filter(Boolean).length > 1)
700
+ throw new Error("Pass at most one of --check-budget, --update-budget and --raise-budget.");
701
+ return checkBudget ? "enforce" : updateBudget ? "update" : raiseBudget ? "raise" : "report";
702
+ }
697
703
  static async load(filePath, source = filePath) {
698
704
  const file = Bun.file(filePath);
699
705
  if (!await file.exists())
700
706
  return null;
701
707
  return RouteJsBudget.parse(await file.text(), source);
702
708
  }
703
- static async check(sizes, { mode, budgetPath, source, environment }) {
709
+ static async check(sizes, check) {
710
+ const { mode, app, budgetPath, source, environment } = check;
704
711
  const { committed, unreadable } = await RouteJsBudget.#loadFor(mode, budgetPath, source);
705
- const budget = mode === "update" ? (committed ?? new RouteJsBudget).tightenedBy(sizes, environment) : committed;
706
- if (mode === "update" && budget)
712
+ if (mode === "enforce" && !committed)
713
+ throw new Error(`--check-budget found no ${source}: record one with \`akan build ${app} --update-budget\`.`);
714
+ const budget = mode === "raise" ? new RouteJsBudget().tightenedBy(sizes, environment) : mode === "update" ? (committed ?? new RouteJsBudget).tightenedBy(sizes, environment) : committed;
715
+ if ((mode === "update" || mode === "raise") && budget)
707
716
  await Bun.write(budgetPath, budget.stringify());
708
717
  const overages = budget?.overages(sizes) ?? [];
718
+ const unbudgeted = budget?.unbudgeted(sizes) ?? [];
709
719
  const envNote = committed?.envNote(environment) ?? "";
710
- if (overages.length && mode !== "report")
711
- throw new Error(RouteJsBudget.formatOverages(overages, source, envNote));
712
- const unbudgeted = budget?.unbudgeted(sizes).length ?? 0;
713
- if (mode === "update")
714
- return { summary: `${source} ${unreadable ? `rewritten (${unreadable})` : "updated"}` };
720
+ const target = { app, source };
721
+ const failures = [
722
+ ...overages.length && mode !== "report" ? [RouteJsBudget.formatOverages(overages, target, envNote)] : [],
723
+ ...unbudgeted.length && mode === "enforce" ? [RouteJsBudget.formatUnbudgeted(unbudgeted, target)] : []
724
+ ];
725
+ if (failures.length)
726
+ throw new Error(failures.join(`
727
+ `));
728
+ if (mode === "update" || mode === "raise")
729
+ return { summary: RouteJsBudget.#writtenSummary(check, unreadable, committed, budget) };
715
730
  if (unreadable)
716
731
  return {
717
732
  summary: `${unreadable}, not checked`,
718
733
  warnings: [
719
734
  {
720
735
  file: source,
721
- message: `${unreadable}; akan build fails on it`,
722
- fix: "correct it, or rewrite it with akan build <app> --update-budget"
736
+ message: `${unreadable}; akan build --check-budget fails on it`,
737
+ fix: `correct it, or rewrite it with akan build ${app} --update-budget`
723
738
  }
724
739
  ]
725
740
  };
726
741
  if (!budget)
727
742
  return { summary: `no ${RouteJsBudget.fileName}` };
728
- if (overages.length)
729
- return {
730
- summary: `${overages.length} route(s) over ${source}${envNote}, reported only: ${overages.map(({ routeId }) => routeId).join(", ")}`,
731
- warnings: overages.map(({ routeId, brotliBytes, limitBytes }) => ({
732
- file: source,
733
- message: `${routeId} loads ${RouteJsBudget.#bytes(brotliBytes)} bytes brotli, over its limit of ${RouteJsBudget.#bytes(limitBytes)}${envNote}; akan build fails on it`,
734
- fix: "shrink what the route loads, or raise its entry by hand in the same change"
735
- }))
736
- };
737
- return { summary: `within ${source}${envNote}${unbudgeted ? `, ${unbudgeted} route(s) without an entry` : ""}` };
743
+ const warnings = [
744
+ ...overages.map(({ routeId, brotliBytes, limitBytes }) => ({
745
+ file: source,
746
+ message: `${routeId} loads ${RouteJsBudget.#bytes(brotliBytes)} bytes brotli, over its limit of ${RouteJsBudget.#bytes(limitBytes)}${envNote}; akan build --check-budget fails on it`,
747
+ fix: `shrink what the route loads, or raise its entry with akan build ${app} --raise-budget`
748
+ })),
749
+ ...unbudgeted.map((routeId) => ({
750
+ file: source,
751
+ message: `${routeId} has no entry; akan build --check-budget fails on it`,
752
+ fix: `record it with akan build ${app} --update-budget`
753
+ }))
754
+ ];
755
+ const verdict = overages.length ? `${overages.length} route(s) over ${source}${envNote}, reported only: ${overages.map(({ routeId }) => routeId).join(", ")}` : `within ${source}${envNote}`;
756
+ const unbudgetedNote = unbudgeted.length ? `; ${unbudgeted.length} route(s) without an entry` : "";
757
+ return { summary: `${verdict}${unbudgetedNote}`, ...warnings.length ? { warnings } : {} };
758
+ }
759
+ static #writtenSummary({ mode, source }, unreadable, committed, written) {
760
+ if (unreadable)
761
+ return `${source} rewritten (${unreadable})`;
762
+ if (mode === "update")
763
+ return `${source} updated`;
764
+ const raised = [...written?.kbByRoute ?? []].filter(([routeId, kb]) => kb > (committed?.kbByRoute.get(routeId) ?? kb));
765
+ return `${source} re-recorded at each route's measured size${raised.length ? `, raised: ${raised.map(([routeId]) => routeId).join(", ")}` : ""}`;
738
766
  }
739
767
  static async#loadFor(mode, budgetPath, source) {
740
768
  try {
@@ -778,15 +806,27 @@ class RouteJsBudget {
778
806
  ...sizes.length > shown.length ? [` \u2026and ${sizes.length - shown.length} more`] : []
779
807
  ];
780
808
  }
781
- static formatOverages(overages, source, envNote = "") {
809
+ static formatOverages(overages, target, envNote = "") {
782
810
  const bytes = RouteJsBudget.#bytes;
811
+ const { source } = target;
783
812
  return [
784
813
  `${overages.length} route${overages.length === 1 ? "" : "s"} over the JS budget in ${source}${envNote}:`,
785
814
  ...overages.map(({ routeId, brotliBytes, budgetKB, limitBytes }) => ` ${routeId}: ${bytes(brotliBytes)} bytes brotli, over its limit of ${bytes(limitBytes)} (${budgetKB}KB + the larger of 1% and 4KB)`),
786
- "Shrink what the route loads. If the growth is intended, raise its entry by hand in the same change."
815
+ RouteJsBudget.#overageFix(target)
787
816
  ].join(`
788
817
  `);
789
818
  }
819
+ static formatUnbudgeted(routeIds, { app, source }) {
820
+ return [
821
+ `${routeIds.length} route${routeIds.length === 1 ? "" : "s"} with no entry in ${source}, which --check-budget checks every route against:`,
822
+ ...routeIds.map((routeId) => ` ${routeId}`),
823
+ `Record ${routeIds.length === 1 ? "it" : "them"} in the same change: \`akan build ${app} --update-budget\` adds each new route at its measured size.`
824
+ ].join(`
825
+ `);
826
+ }
827
+ static #overageFix({ app, source }) {
828
+ return `Shrink what the route loads. If the growth is intended, record it in the same change: \`akan build ${app} --raise-budget\` re-records every route at its measured size, or raise the route's entry under "${RouteJsBudget.section}" in ${source} by hand.`;
829
+ }
790
830
  static #bytes(value) {
791
831
  return value.toLocaleString("en-US");
792
832
  }
@@ -824,7 +864,7 @@ class RouteJsBudget {
824
864
  }
825
865
  }
826
866
 
827
- // pkgs/@akanjs/devkit/applicationBuildReporter.ts
867
+ // pkgs/@akanjs/devkit/app/applicationBuildReporter.ts
828
868
  class ApplicationBuildReporter {
829
869
  static create() {
830
870
  return {
@@ -838,53 +878,23 @@ class ApplicationBuildReporter {
838
878
  Logger.rawLog(line);
839
879
  Logger.rawLog("");
840
880
  }
881
+ if (result.routeJsWarnings?.length) {
882
+ ApplicationBuildReporter.printRouteJsWarnings(result);
883
+ Logger.rawLog("");
884
+ }
841
885
  Logger.rawLog(`Route artifacts: ${result.artifactDir}`);
842
886
  Logger.rawLog(`Server output: ${result.outputDir}`);
843
887
  Logger.rawLog(`Done in ${ApplicationBuildReporter.formatDuration(result.durationMs)}`);
844
888
  if (result.environment === "local")
845
889
  Logger.rawLog(ApplicationBuildReporter.localBuildNotice);
846
890
  }
891
+ static printRouteJsWarnings({ routeJsWarnings = [] }) {
892
+ for (const { file, message, fix } of routeJsWarnings)
893
+ Logger.rawLog(`Warning: ${file}: ${message} (${fix})`);
894
+ }
847
895
  static localBuildNotice = "Built for local: the server runs without endpoint rate limits, and boots on local defaults (Redis on localhost, the first database mode) where a deployment would stop to ask. For a host others can reach, run `akan build <app> --env main` with AKAN_PUBLIC_REPO_NAME and AKAN_PUBLIC_SERVE_DOMAIN set in the shell or the workspace .env.";
848
896
  static formatError(error, workspaceRoot = process.cwd()) {
849
- if (error instanceof AggregateError) {
850
- const nestedMessages = error.errors.map((nestedError, index) => ApplicationBuildReporter.formatError(nestedError, workspaceRoot).trim() || `Unknown error ${index + 1}`).map((message) => message.replace(/^/gm, " ")).join(`
851
- `);
852
- return nestedMessages ? `${error.message}
853
- ${nestedMessages}` : error.message;
854
- }
855
- if (error instanceof Error) {
856
- const causeMessage = error.cause ? `
857
- Caused by: ${ApplicationBuildReporter.formatError(error.cause, workspaceRoot)}` : "";
858
- return `${ApplicationBuildReporter.#withLocation(error.message, error, workspaceRoot)}${causeMessage}`;
859
- }
860
- if (typeof error === "object" && error !== null && "message" in error)
861
- return ApplicationBuildReporter.#withLocation(String(error.message), error, workspaceRoot);
862
- return String(error);
863
- }
864
- static #withLocation(message, error, workspaceRoot) {
865
- const { position } = error;
866
- if (!position?.file)
867
- return message;
868
- const file = ApplicationBuildReporter.#relativeToWorkspace(position.file, workspaceRoot);
869
- const location = position.line > 0 ? `${file}:${position.line}:${position.column}` : file;
870
- return message.includes(location) ? message : message.replace(/^.*/, (headline) => `${headline} (${location})`);
871
- }
872
- static #relativeToWorkspace(file, workspaceRoot) {
873
- if (!path4.isAbsolute(file))
874
- return file;
875
- for (const root of [workspaceRoot, ApplicationBuildReporter.#realpathOf(workspaceRoot)]) {
876
- const relative = path4.relative(root, file);
877
- if (!relative.startsWith(`..${path4.sep}`) && !path4.isAbsolute(relative))
878
- return relative.replaceAll(path4.sep, "/");
879
- }
880
- return file;
881
- }
882
- static #realpathOf(dir) {
883
- try {
884
- return realpathSync(dir);
885
- } catch {
886
- return dir;
887
- }
897
+ return ErrorReport.format(error, workspaceRoot);
888
898
  }
889
899
  static formatDuration(ms) {
890
900
  if (ms < 1000)
@@ -901,13 +911,13 @@ Caused by: ${ApplicationBuildReporter.formatError(error.cause, workspaceRoot)}`
901
911
  }
902
912
 
903
913
  // pkgs/@akanjs/devkit/akanApp/devHostPolicy.ts
904
- import path5 from "path";
914
+ import path4 from "path";
905
915
  var UNAVAILABLE_REDIS_HOST = "redis-tunnel-unavailable.invalid";
906
916
  var redisTunnelPolicy = ({
907
917
  environment,
908
918
  databaseMode
909
919
  }) => environment === "local" ? "none" : databaseMode === "single" ? "optional" : "required";
910
- var BACKEND_RECOVERY_MAX_ATTEMPTS = 5;
920
+ var backendRecoveryPolicy = { min: 1000, max: 30000, maxAttempts: 5 };
911
921
  var HELD_BUILDER_REQUEST_LIMIT = 64;
912
922
  var BUILDER_MIN_RSS_RECYCLE_INTERVAL_MS = 30000;
913
923
  var BUILDER_TIGHT_RSS_REPORT_LIMIT = 2;
@@ -928,7 +938,6 @@ var shouldRestartBackendByDevPlan = (message) => {
928
938
  return message.devPlan.actions.includes("restart-backend");
929
939
  };
930
940
  var shouldRestartBuilderByDevPlan = (message) => message.devPlan?.actions.includes("restart-builder") ?? false;
931
- var shouldAbandonBackendRecovery = (attempts, maxAttempts = BACKEND_RECOVERY_MAX_ATTEMPTS) => attempts >= maxAttempts;
932
941
  var normalizeBackendReportedGeneration = (generation) => generation >= 0 ? generation : undefined;
933
942
  var shouldRestartDevHostByDevPlan = (message) => message.devPlan?.actions.includes("restart-dev-host") ?? message.kinds.includes("config");
934
943
  var devHostStateByBackendState = {
@@ -943,18 +952,18 @@ var devHostStateOf = (state, gaveUp) => state === "stopped" && gaveUp ? "failed"
943
952
  var RESTART_ROLE_ORDER = ["server", "shared", "barrel", "config"];
944
953
  var generationValue = (generation) => generation ?? -1;
945
954
  var isLegacyBackendFallbackFile = (file, workspaceRoot) => {
946
- const abs = path5.resolve(file);
947
- const ext = path5.extname(abs).toLowerCase();
955
+ const abs = path4.resolve(file);
956
+ const ext = path4.extname(abs).toLowerCase();
948
957
  if (!SOURCE_EXTS.has(ext))
949
958
  return false;
950
- const rel = path5.relative(path5.resolve(workspaceRoot), abs);
951
- if (!rel || rel.startsWith("..") || path5.isAbsolute(rel))
959
+ const rel = path4.relative(path4.resolve(workspaceRoot), abs);
960
+ if (!rel || rel.startsWith("..") || path4.isAbsolute(rel))
952
961
  return false;
953
- const parts = rel.split(path5.sep).filter(Boolean);
962
+ const parts = rel.split(path4.sep).filter(Boolean);
954
963
  const [scope] = parts;
955
964
  if (scope !== "apps" && scope !== "libs" && scope !== "pkgs")
956
965
  return false;
957
- const base = path5.basename(abs);
966
+ const base = path4.basename(abs);
958
967
  return parts.includes("srvkit") || parts.includes("common") || SERVER_SUFFIXES.some((suffix) => base.endsWith(suffix)) || SHARED_SUFFIXES.some((suffix) => base.endsWith(suffix)) || RUNTIME_METADATA_BASENAMES.has(base) || base === "main.ts" || base === "server.ts";
959
968
  };
960
969
  var shouldMarkBuildPhaseRecovered = (previousByPhase, status) => {
@@ -1115,83 +1124,12 @@ var mergeInvalidateMessages = (current, next) => {
1115
1124
  var buildStatusReplaySequence = (pendingReplay, latestByPhase) => [...pendingReplay, ...latestByPhase.values()];
1116
1125
  var filesChangedSince = (before, after) => [...before].filter(([file, stamp]) => after.get(file) !== stamp).map(([file]) => file);
1117
1126
 
1118
- // pkgs/@akanjs/devkit/frontendBuild/watchRootResolver.ts
1119
- import fs from "fs";
1120
- import { readFile } from "fs/promises";
1121
- import path6 from "path";
1122
-
1123
- class WatchRootResolver {
1124
- #app;
1125
- constructor(app) {
1126
- this.#app = app;
1127
- }
1128
- async resolve() {
1129
- const tsconfig = await this.#app.getTsConfig();
1130
- const appDir = path6.resolve(this.#app.cwdPath);
1131
- const appsContainer = path6.dirname(appDir);
1132
- const libsContainer = path6.resolve(this.#app.workspace.workspaceRoot, "libs");
1133
- const libRoots = (await this.#resolveLibDeps(libsContainer))?.map((name) => path6.join(libsContainer, name)).filter((dir) => fs.existsSync(dir));
1134
- const set = new Set;
1135
- set.add(path6.resolve(`${this.#app.cwdPath}/page`));
1136
- for (const targets of Object.values(tsconfig.compilerOptions.paths ?? {})) {
1137
- for (const target of targets) {
1138
- if (!target)
1139
- continue;
1140
- if (path6.isAbsolute(target))
1141
- continue;
1142
- const cleaned = target.replace(/\/?\*+.*$/, "").replace(/\/[^/]+\.[^/]+$/, "");
1143
- const resolved = path6.resolve(this.#app.workspace.workspaceRoot, cleaned);
1144
- if (resolved === libsContainer && libRoots) {
1145
- for (const root of libRoots)
1146
- set.add(root);
1147
- continue;
1148
- }
1149
- const root = resolved === appsContainer ? appDir : resolved;
1150
- if (fs.existsSync(root))
1151
- set.add(root);
1152
- }
1153
- }
1154
- return [...set];
1155
- }
1156
- async#resolveLibDeps(libsContainer) {
1157
- const scanInfo = this.#app.getScanInfo({ allowEmpty: true });
1158
- if (scanInfo?.type === "app")
1159
- return scanInfo.libDeps;
1160
- const direct = await WatchRootResolver.#readManifestLibDeps(path6.join(this.#app.cwdPath, "akan.app.json"));
1161
- if (!direct)
1162
- return null;
1163
- const closure = new Set;
1164
- const queue = [...direct];
1165
- while (queue.length > 0) {
1166
- const name = queue.shift();
1167
- if (!name || closure.has(name))
1168
- continue;
1169
- closure.add(name);
1170
- const nested = await WatchRootResolver.#readManifestLibDeps(path6.join(libsContainer, name, "akan.lib.json"));
1171
- if (!nested)
1172
- return null;
1173
- queue.push(...nested);
1174
- }
1175
- return [...closure];
1176
- }
1177
- static async#readManifestLibDeps(manifestPath) {
1178
- try {
1179
- const parsed = JSON.parse(await readFile(manifestPath, "utf8"));
1180
- if (!Array.isArray(parsed.libDeps))
1181
- return null;
1182
- return parsed.libDeps.filter((name) => typeof name === "string" && name.length > 0);
1183
- } catch {
1184
- return null;
1185
- }
1186
- }
1187
- }
1188
-
1189
1127
  // pkgs/@akanjs/devkit/frontendBuild/hmrWatcher.ts
1190
- import fs2 from "fs";
1191
- import path9 from "path";
1128
+ import fs from "fs";
1129
+ import path7 from "path";
1192
1130
 
1193
1131
  // pkgs/@akanjs/devkit/frontendBuild/hmrChangeClassifier.ts
1194
- import path7 from "path";
1132
+ import path5 from "path";
1195
1133
  var CSS_EXTS = new Set([".css"]);
1196
1134
  var CONFIG_BASENAMES = new Set(["akan.config.ts", "bunfig.toml", "tsconfig.json", "package.json"]);
1197
1135
 
@@ -1199,10 +1137,10 @@ class HmrChangeClassifier {
1199
1137
  classify(abs) {
1200
1138
  if (this.#isUninteresting(abs))
1201
1139
  return "ignore";
1202
- const base = path7.basename(abs);
1140
+ const base = path5.basename(abs);
1203
1141
  if (CONFIG_BASENAMES.has(base))
1204
1142
  return "config";
1205
- const ext = path7.extname(abs).toLowerCase();
1143
+ const ext = path5.extname(abs).toLowerCase();
1206
1144
  if (CSS_EXTS.has(ext))
1207
1145
  return "css";
1208
1146
  if (SOURCE_EXTS.has(ext))
@@ -1210,16 +1148,16 @@ class HmrChangeClassifier {
1210
1148
  return "ignore";
1211
1149
  }
1212
1150
  #isUninteresting(abs) {
1213
- const base = path7.basename(abs);
1151
+ const base = path5.basename(abs);
1214
1152
  if (!base)
1215
1153
  return true;
1216
1154
  if (base.startsWith("."))
1217
1155
  return true;
1218
1156
  if (base.endsWith("~") || base.endsWith(".swp") || base.endsWith(".swx") || base.endsWith(".tmp"))
1219
1157
  return true;
1220
- if (abs.includes(`${path7.sep}node_modules${path7.sep}`))
1158
+ if (abs.includes(`${path5.sep}node_modules${path5.sep}`))
1221
1159
  return true;
1222
- if (abs.includes(`${path7.sep}.akan${path7.sep}`))
1160
+ if (abs.includes(`${path5.sep}.akan${path5.sep}`))
1223
1161
  return true;
1224
1162
  return false;
1225
1163
  }
@@ -1227,7 +1165,7 @@ class HmrChangeClassifier {
1227
1165
 
1228
1166
  // pkgs/@akanjs/devkit/frontendBuild/sourceMtimeIndex.ts
1229
1167
  import { readdir, stat as stat3 } from "fs/promises";
1230
- import path8 from "path";
1168
+ import path6 from "path";
1231
1169
  var UNREADABLE = Number.NaN;
1232
1170
 
1233
1171
  class SourceMtimeIndex {
@@ -1290,7 +1228,7 @@ class SourceMtimeIndex {
1290
1228
  if (!this.#primed)
1291
1229
  return;
1292
1230
  await Promise.all(paths.map(async (file) => {
1293
- const abs = path8.resolve(file);
1231
+ const abs = path6.resolve(file);
1294
1232
  const stats = await stat3(abs).catch(() => null);
1295
1233
  if (!stats?.isFile()) {
1296
1234
  this.#files.delete(abs);
@@ -1376,7 +1314,7 @@ class SourceMtimeIndex {
1376
1314
  for (const entry of entries) {
1377
1315
  if (SourceMtimeIndex.#skipDirent(entry.name))
1378
1316
  continue;
1379
- const abs = path8.join(dir, entry.name);
1317
+ const abs = path6.join(dir, entry.name);
1380
1318
  if (entry.isDirectory()) {
1381
1319
  descend.push(abs);
1382
1320
  continue;
@@ -1403,7 +1341,7 @@ class SourceMtimeIndex {
1403
1341
  }
1404
1342
  if (known) {
1405
1343
  for (const abs of [...this.#files.keys()]) {
1406
- if (present.has(abs) || path8.dirname(abs) !== dir)
1344
+ if (present.has(abs) || path6.dirname(abs) !== dir)
1407
1345
  continue;
1408
1346
  this.#files.delete(abs);
1409
1347
  changed?.add(abs);
@@ -1421,7 +1359,7 @@ class SourceMtimeIndex {
1421
1359
  this.#unsettled.delete(dir);
1422
1360
  }
1423
1361
  #forget(dir) {
1424
- const prefix = `${dir}${path8.sep}`;
1362
+ const prefix = `${dir}${path6.sep}`;
1425
1363
  this.#dirs.delete(dir);
1426
1364
  this.#unreadable.delete(dir);
1427
1365
  this.#unsettled.delete(dir);
@@ -1459,8 +1397,8 @@ class SourceMtimeIndex {
1459
1397
  return !name || name.startsWith(".") || name === "node_modules";
1460
1398
  }
1461
1399
  static #pruneNestedRoots(roots) {
1462
- const resolved = [...new Set(roots.map((root) => path8.resolve(root)))].sort();
1463
- return resolved.filter((root) => !resolved.some((other) => other !== root && root.startsWith(`${other}${path8.sep}`)));
1400
+ const resolved = [...new Set(roots.map((root) => path6.resolve(root)))].sort();
1401
+ return resolved.filter((root) => !resolved.some((other) => other !== root && root.startsWith(`${other}${path6.sep}`)));
1464
1402
  }
1465
1403
  }
1466
1404
 
@@ -1476,6 +1414,7 @@ class HmrWatcher {
1476
1414
  #hinted = new Set;
1477
1415
  #classifier = new HmrChangeClassifier;
1478
1416
  #index;
1417
+ #scans = new Set;
1479
1418
  #timer = null;
1480
1419
  #verifyTimer = null;
1481
1420
  #windowStartedAt = null;
@@ -1485,7 +1424,7 @@ class HmrWatcher {
1485
1424
  #reportedCompensating = false;
1486
1425
  #reportedGaps = "";
1487
1426
  constructor(opts) {
1488
- this.#roots = [...new Set(opts.roots.map((r) => path9.resolve(r)))];
1427
+ this.#roots = [...new Set(opts.roots.map((r) => path7.resolve(r)))];
1489
1428
  this.#debounceMs = opts.debounceMs ?? HmrWatcher.#envDebounceMs() ?? 30;
1490
1429
  this.#verifyDelayMs = opts.verifyDelayMs ?? 250;
1491
1430
  this.#onBatch = opts.onBatch;
@@ -1498,10 +1437,10 @@ class HmrWatcher {
1498
1437
  async start() {
1499
1438
  for (const root of this.#roots) {
1500
1439
  try {
1501
- const w = fs2.watch(root, { recursive: true, persistent: false }, (_event, filename) => {
1440
+ const w = fs.watch(root, { recursive: true, persistent: false }, (_event, filename) => {
1502
1441
  if (!filename)
1503
1442
  return;
1504
- const abs = path9.resolve(root, filename.toString());
1443
+ const abs = path7.resolve(root, filename.toString());
1505
1444
  this.#queue(abs);
1506
1445
  });
1507
1446
  w.on("error", (err) => {
@@ -1536,6 +1475,17 @@ class HmrWatcher {
1536
1475
  } catch {}
1537
1476
  }
1538
1477
  }
1478
+ async close() {
1479
+ this.stop();
1480
+ await Promise.all(this.#scans);
1481
+ await this.#mergeDetectedChanges();
1482
+ if (this.#pending.size === 0)
1483
+ return null;
1484
+ const batch = { files: Array.from(this.#pending.keys()), kinds: new Set(this.#pending.values()) };
1485
+ this.#pending.clear();
1486
+ this.#hinted.clear();
1487
+ return batch;
1488
+ }
1539
1489
  async absorb(paths) {
1540
1490
  if (paths.length === 0)
1541
1491
  return;
@@ -1576,6 +1526,8 @@ class HmrWatcher {
1576
1526
  try {
1577
1527
  while (!this.#stopped) {
1578
1528
  await this.#mergeDetectedChanges();
1529
+ if (this.#stopped)
1530
+ break;
1579
1531
  if (this.#pending.size === 0) {
1580
1532
  this.#windowStartedAt = null;
1581
1533
  break;
@@ -1601,7 +1553,12 @@ class HmrWatcher {
1601
1553
  this.#scheduleVerify();
1602
1554
  }
1603
1555
  }
1604
- async#mergeDetectedChanges() {
1556
+ #mergeDetectedChanges() {
1557
+ const scan = this.#collectDetectedChanges().finally(() => this.#scans.delete(scan));
1558
+ this.#scans.add(scan);
1559
+ return scan;
1560
+ }
1561
+ async#collectDetectedChanges() {
1605
1562
  const detected = await this.#index.collectChanges().catch((err) => {
1606
1563
  this.#logger.error(`[hmr] mtime scan failed: ${err.message}`);
1607
1564
  return [];
@@ -1665,4 +1622,75 @@ class HmrWatcher {
1665
1622
  }
1666
1623
  }
1667
1624
 
1668
- export { UNAVAILABLE_REDIS_HOST, redisTunnelPolicy, BUILDER_MIN_RSS_RECYCLE_INTERVAL_MS, SOURCE_EXTS, shouldRestartBackendByDevPlan, shouldRestartBuilderByDevPlan, shouldAbandonBackendRecovery, normalizeBackendReportedGeneration, shouldRestartDevHostByDevPlan, devHostStateOf, isLegacyBackendFallbackFile, shouldMarkBuildPhaseRecovered, shouldKeepBuildFailure, createBackendBuildStatus, backendRestartReasonFromMessage, mergeBackendRestartReasons, shouldReplaceLastGoodMessage, shouldQueueBuildStatusReplay, hasBuildFailureForGeneration, decideBuilderRssRecycle, decideBuilderRssSettle, decideIdleSuspend, resolveIdleSuspendMs, hasAnyBuildFailure, shouldRefreshConfigOnIdleWake, shouldHoldForReturningBuilder, shouldWarnBuilderRssCeilingTight, isRssCeilingUnreachable, shouldRelayRecycledFrontendState, mergeInvalidateMessages, buildStatusReplaySequence, filesChangedSince, HmrWatcher, WatchRootResolver, FontOptimizer, FontPruner, RouteJsBudget, ApplicationBuildReporter };
1625
+ // pkgs/@akanjs/devkit/frontendBuild/watchRootResolver.ts
1626
+ import fs2 from "fs";
1627
+ import { readFile } from "fs/promises";
1628
+ import path8 from "path";
1629
+
1630
+ class WatchRootResolver {
1631
+ #app;
1632
+ constructor(app) {
1633
+ this.#app = app;
1634
+ }
1635
+ async resolve() {
1636
+ const tsconfig = await this.#app.getTsConfig();
1637
+ const appDir = path8.resolve(this.#app.cwdPath);
1638
+ const appsContainer = path8.dirname(appDir);
1639
+ const libsContainer = path8.resolve(this.#app.workspace.workspaceRoot, "libs");
1640
+ const libRoots = (await this.#resolveLibDeps(libsContainer))?.map((name) => path8.join(libsContainer, name)).filter((dir) => fs2.existsSync(dir));
1641
+ const set = new Set;
1642
+ set.add(path8.resolve(`${this.#app.cwdPath}/page`));
1643
+ for (const targets of Object.values(tsconfig.compilerOptions.paths ?? {})) {
1644
+ for (const target of targets) {
1645
+ if (!target)
1646
+ continue;
1647
+ if (path8.isAbsolute(target))
1648
+ continue;
1649
+ const cleaned = target.replace(/\/?\*+.*$/, "").replace(/\/[^/]+\.[^/]+$/, "");
1650
+ const resolved = path8.resolve(this.#app.workspace.workspaceRoot, cleaned);
1651
+ if (resolved === libsContainer && libRoots) {
1652
+ for (const root of libRoots)
1653
+ set.add(root);
1654
+ continue;
1655
+ }
1656
+ const root = resolved === appsContainer ? appDir : resolved;
1657
+ if (fs2.existsSync(root))
1658
+ set.add(root);
1659
+ }
1660
+ }
1661
+ return [...set];
1662
+ }
1663
+ async#resolveLibDeps(libsContainer) {
1664
+ const scanInfo = this.#app.getScanInfo({ allowEmpty: true });
1665
+ if (scanInfo?.type === "app")
1666
+ return scanInfo.libDeps;
1667
+ const direct = await WatchRootResolver.#readManifestLibDeps(path8.join(this.#app.cwdPath, "akan.app.json"));
1668
+ if (!direct)
1669
+ return null;
1670
+ const closure = new Set;
1671
+ const queue = [...direct];
1672
+ while (queue.length > 0) {
1673
+ const name = queue.shift();
1674
+ if (!name || closure.has(name))
1675
+ continue;
1676
+ closure.add(name);
1677
+ const nested = await WatchRootResolver.#readManifestLibDeps(path8.join(libsContainer, name, "akan.lib.json"));
1678
+ if (!nested)
1679
+ return null;
1680
+ queue.push(...nested);
1681
+ }
1682
+ return [...closure];
1683
+ }
1684
+ static async#readManifestLibDeps(manifestPath) {
1685
+ try {
1686
+ const parsed = JSON.parse(await readFile(manifestPath, "utf8"));
1687
+ if (!Array.isArray(parsed.libDeps))
1688
+ return null;
1689
+ return parsed.libDeps.filter((name) => typeof name === "string" && name.length > 0);
1690
+ } catch {
1691
+ return null;
1692
+ }
1693
+ }
1694
+ }
1695
+
1696
+ export { UNAVAILABLE_REDIS_HOST, redisTunnelPolicy, backendRecoveryPolicy, BUILDER_MIN_RSS_RECYCLE_INTERVAL_MS, SOURCE_EXTS, shouldRestartBackendByDevPlan, shouldRestartBuilderByDevPlan, normalizeBackendReportedGeneration, shouldRestartDevHostByDevPlan, devHostStateOf, isLegacyBackendFallbackFile, shouldMarkBuildPhaseRecovered, shouldKeepBuildFailure, createBackendBuildStatus, backendRestartReasonFromMessage, mergeBackendRestartReasons, shouldReplaceLastGoodMessage, shouldQueueBuildStatusReplay, hasBuildFailureForGeneration, decideBuilderRssRecycle, decideBuilderRssSettle, decideIdleSuspend, resolveIdleSuspendMs, hasAnyBuildFailure, shouldRefreshConfigOnIdleWake, shouldHoldForReturningBuilder, shouldWarnBuilderRssCeilingTight, isRssCeilingUnreachable, shouldRelayRecycledFrontendState, mergeInvalidateMessages, buildStatusReplaySequence, filesChangedSince, HmrWatcher, WatchRootResolver, FontOptimizer, FontPruner, RouteJsBudget, ApplicationBuildReporter };
@@ -2,15 +2,18 @@
2
2
  import {
3
3
  runner,
4
4
  script
5
- } from "./index-386canwe.js";
5
+ } from "./index-9rv2zt48.js";
6
6
  import {
7
7
  generatedFilesForSync,
8
8
  createPassedPrimitiveReport,
9
9
  scalarChangedFiles
10
- } from "./index-xq97me1h.js";
10
+ } from "./index-a41vv4cy.js";
11
11
  import {
12
12
  pluralizeName
13
13
  } from "./index-nz8prx9g.js";
14
+ import {
15
+ assertPlainName
16
+ } from "./index-va90m8nd.js";
14
17
 
15
18
  // pkgs/@akanjs/cli/scalar/scalar.runner.ts
16
19
  class ScalarRunner extends runner("scalar") {
@@ -37,6 +40,7 @@ class ScalarRunner extends runner("scalar") {
37
40
  // pkgs/@akanjs/cli/scalar/scalar.script.ts
38
41
  class ScalarScript extends script("scalar", [ScalarRunner]) {
39
42
  async createScalar(sys, scalarName) {
43
+ assertPlainName("scalar", scalarName);
40
44
  const files = await this.scalarRunner.applyScalarTemplate(sys, scalarName);
41
45
  return createPassedPrimitiveReport({
42
46
  command: "create-scalar",
@@ -46,6 +50,7 @@ class ScalarScript extends script("scalar", [ScalarRunner]) {
46
50
  });
47
51
  }
48
52
  async removeScalar(sys, scalarName) {
53
+ assertPlainName("scalar", scalarName);
49
54
  await sys.removeDir(`lib/__scalar/${scalarName}`);
50
55
  }
51
56
  }
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- // pkgs/@akanjs/devkit/typeChecker.ts
2
+ // pkgs/@akanjs/devkit/typecheck/typeChecker.ts
3
3
  import { readFileSync } from "fs";
4
4
  import * as path from "path";
5
5
  import chalk from "chalk";
@@ -758,4 +758,4 @@ class CodeTuiParts2 {
758
758
  }
759
759
  }
760
760
 
761
- export { CodeTuiLines2, CodeTuiAgents2, CodeTuiClipboard2, CodeTuiCommands2, CodeTuiEditor2, CodeTuiFiles2, CodeTuiMarkdown2, CodeTuiParts2 };
761
+ export { CodeTuiCommands2, CodeTuiLines2, CodeTuiEditor2, CodeTuiAgents2, CodeTuiMarkdown2, CodeTuiParts2, CodeTuiClipboard2, CodeTuiFiles2 };