@akanjs/cli 3.1.2-rc.3 → 3.2.0-rc.0

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/.build-stamp +1 -1
  2. package/{CodeAgent-n2tkg59z.js → CodeAgent-h6g8dg3a.js} +2 -2
  3. package/{CodeTui-9wsdx7ap.js → CodeTui-n9gacepn.js} +1 -1
  4. package/README.ko.md +9 -0
  5. package/README.md +9 -0
  6. package/TunnelShare-k3ja4w9x.js +14 -0
  7. package/{agent.command-tffz6wdn.js → agent.command-2f657613.js} +19 -17
  8. package/akanCode.js +2 -2
  9. package/{application.command-7bkxbrsp.js → application.command-yb8v177e.js} +45 -22
  10. package/{applicationBuildRunner-s13x3zqb.js → applicationBuildRunner-sctcmkyx.js} +57 -17
  11. package/buildBatch.proc.js +7 -7
  12. package/{cloud.command-a792bc10.js → cloud.command-et06ja22.js} +35 -18
  13. package/cloud.script-s6rbrwer.js +30 -0
  14. package/{code.command-ma8dtzww.js → code.command-7m67c7zc.js} +6 -6
  15. package/commandManifest.json +1 -1
  16. package/{context.command-80a1qhps.js → context.command-569z0rqf.js} +20 -19
  17. package/context.runner-ms8v1rxy.js +29 -0
  18. package/{guideline.command-195g0h9a.js → guideline.command-gnv3e8p8.js} +2 -2
  19. package/guidelines/akanApi/akanApi.instruction.md +317 -0
  20. package/guidelines/conventions/rules/app.md +5 -5
  21. package/guidelines/conventions/rules/config.md +1 -1
  22. package/guidelines/conventions/rules/gates.md +10 -5
  23. package/guidelines/conventions/rules/page.md +4 -2
  24. package/guidelines/conventions/rules/server.md +2 -0
  25. package/guidelines/conventions/rules/style.md +3 -1
  26. package/guidelines/conventions/rules/ts.md +2 -1
  27. package/guidelines/cssRule/cssRule.instruction.md +3 -1
  28. package/guidelines/pageRule/pageRule.instruction.md +3 -0
  29. package/incrementalBuilder.proc.js +70 -14
  30. package/{index-tns543wd.js → index-0fb3cpbt.js} +3 -3
  31. package/{index-zbrwnmf1.js → index-1q1cjn8s.js} +21 -11
  32. package/{index-wrmq92vk.js → index-3wjbhj2n.js} +1 -1
  33. package/{index-361ex3rb.js → index-48d5qsj3.js} +4 -4
  34. package/{index-aayg4dqf.js → index-5w9my9qe.js} +8 -8
  35. package/{index-1h2jc0x3.js → index-6wpaq392.js} +61 -15
  36. package/{index-tp56652m.js → index-7xdpww43.js} +69 -12
  37. package/index-7y5yghjg.js +2969 -0
  38. package/{index-zttm13c3.js → index-8g7tdsk4.js} +249 -696
  39. package/{index-m02tdq8a.js → index-8pb9yvp8.js} +63 -21
  40. package/{index-gbp1q1b5.js → index-8ts9774g.js} +4 -4
  41. package/{index-9zy8479y.js → index-93ewzmp6.js} +43 -14
  42. package/{index-zdpte1pj.js → index-9tbgb4d8.js} +1 -1
  43. package/index-abgh0jve.js +126 -0
  44. package/{index-khk05tsf.js → index-aj3ehkcx.js} +1 -1
  45. package/{index-84h43kg6.js → index-d4n1wmrz.js} +37 -4
  46. package/{index-gr9thy79.js → index-drz9e84d.js} +22 -8
  47. package/{index-hapx5myy.js → index-e3vmjtph.js} +2 -2
  48. package/{index-k64mhwbw.js → index-eajbmk10.js} +2 -1
  49. package/{index-0j1t1h2b.js → index-ed6ea0qp.js} +1 -1
  50. package/{index-sjabnf7j.js → index-fjr4d6yd.js} +444 -368
  51. package/index-hqrkqxx2.js +176 -0
  52. package/{index-z7kbxdqg.js → index-jdamtr7e.js} +3 -3
  53. package/{index-scck6h6d.js → index-kpdv34rq.js} +4 -4
  54. package/{index-ppvqy5bc.js → index-ktb3wcqz.js} +73 -34
  55. package/{index-sveq36gh.js → index-mmym5xmb.js} +4 -2
  56. package/{index-y4kcmbt2.js → index-mqntfzv5.js} +2 -2
  57. package/{index-4am4dvmf.js → index-ny2k80mv.js} +15 -3
  58. package/index-p6hjwt2d.js +1668 -0
  59. package/{index-wwe9rsrx.js → index-r0a604h4.js} +12 -2
  60. package/{index-jb2sreps.js → index-rc5fvqj2.js} +18 -18
  61. package/{index-db2nqrad.js → index-ryrm5z2c.js} +71 -19
  62. package/{index-eft5c2mp.js → index-s2grpzef.js} +331 -27
  63. package/{index-g500c5j9.js → index-sr5da35e.js} +33 -10
  64. package/{index-defp4gmb.js → index-sy481q2x.js} +1 -1
  65. package/{index-j9d3mjx1.js → index-thckcabc.js} +2 -2
  66. package/{index-9z3egsmg.js → index-vkzfk7qt.js} +25 -23
  67. package/index-w639tvkd.js +166 -0
  68. package/index-ygdbn9jn.js +122 -0
  69. package/{index-sp0qsr7a.js → index-zpv14wpy.js} +3 -3
  70. package/{index-sx91nf4z.js → index-zxsygkda.js} +18 -9
  71. package/index.js +24 -23
  72. package/{library.command-63hgt9te.js → library.command-1gp5qe3r.js} +3 -3
  73. package/{localRegistry.command-343ksmn9.js → localRegistry.command-v3g21rex.js} +25 -16
  74. package/{module.command-2hce9m6k.js → module.command-4xz9he6h.js} +6 -6
  75. package/{package.command-96eheyvd.js → package.command-s7qpnn1g.js} +12 -3
  76. package/package.json +2 -2
  77. package/{page.command-gs6d841d.js → page.command-fan34c49.js} +3 -3
  78. package/{pipeline.command-wdfvdbfj.js → pipeline.command-ph4fnn9w.js} +2 -2
  79. package/{primitive.command-7tdj12wn.js → primitive.command-3fqh8emf.js} +7 -7
  80. package/{projectTypecheck-kqj1t6hb.js → projectTypecheck-vkb40hjc.js} +1 -1
  81. package/{quality.command-29bgarh1.js → quality.command-ecj6exsh.js} +15 -10
  82. package/{repair.command-yng4rf5d.js → repair.command-fe9jw719.js} +6 -6
  83. package/{scalar.command-1nk4329t.js → scalar.command-cnvfhk0n.js} +5 -5
  84. package/skills/akan-debug/SKILL.md +2 -1
  85. package/skills/akan-page/SKILL.md +30 -2
  86. package/skills/akan-service/SKILL.md +77 -1
  87. package/{subspace.command-5cehmcdd.js → subspace.command-yxtt3v3e.js} +8 -8
  88. package/templates/app/lib/___appName__/__appName__.abstract.md.template +6 -0
  89. package/templates/app/page/_index.tsx +4 -284
  90. package/templates/app/page/_layout.tsx +1 -26
  91. package/templates/app/page/styles.css.template +58 -318
  92. package/templates/appSample/page/_index.tsx +281 -0
  93. package/templates/appSample/page/_layout.tsx +55 -0
  94. package/templates/appSample/page/styles.css.template +327 -0
  95. package/templates/libRoot/lib/___libName__/__libName__.abstract.md.template +6 -0
  96. package/templates/workspaceRoot/package.json.template +1 -12
  97. package/{tunnel.command-yrd4atqy.js → tunnel.command-ggj38mqf.js} +7 -7
  98. package/{typeChecker-j2jdnqsr.js → typeChecker-s640r6c0.js} +1 -1
  99. package/typecheck.proc.js +1 -1
  100. package/{verify.command-kbq0fcg8.js → verify.command-w9ttxkdz.js} +16 -14
  101. package/{workflow.command-274qfa8z.js → workflow.command-ss8devj0.js} +12 -12
  102. package/{workspace.command-r6hgmawy.js → workspace.command-rw1p0xeq.js} +50 -38
  103. package/TunnelShare-6d7z36sr.js +0 -14
  104. package/cloud.script-t2n13gv6.js +0 -27
  105. package/context.runner-wxqb3qcy.js +0 -28
  106. package/index-j2dgmzbj.js +0 -1259
  107. package/index-p6x5b7hr.js +0 -839
  108. package/index-vzpnr12w.js +0 -65
  109. package/templates/workspaceRoot/patches/zod@3.25.76.patch.template +0 -22
  110. package/templates/workspaceRoot/patches/zod@4.4.3.patch.template +0 -11
  111. /package/templates/{app → appSample}/page/_overrides.tsx +0 -0
  112. /package/templates/{app → appSample}/public/fonts/Pretendard-Black.woff2 +0 -0
  113. /package/templates/{app → appSample}/public/fonts/Pretendard-Bold.woff2 +0 -0
  114. /package/templates/{app → appSample}/public/fonts/Pretendard-ExtraBold.woff2 +0 -0
  115. /package/templates/{app → appSample}/public/fonts/Pretendard-ExtraLight.woff2 +0 -0
  116. /package/templates/{app → appSample}/public/fonts/Pretendard-Light.woff2 +0 -0
  117. /package/templates/{app → appSample}/public/fonts/Pretendard-Medium.woff2 +0 -0
  118. /package/templates/{app → appSample}/public/fonts/Pretendard-Regular.woff2 +0 -0
  119. /package/templates/{app → appSample}/public/fonts/Pretendard-SemiBold.woff2 +0 -0
  120. /package/templates/{app → appSample}/public/fonts/Pretendard-Thin.woff2 +0 -0
  121. /package/templates/{app → appSample}/public/jelly/cloud.webp +0 -0
  122. /package/templates/{app → appSample}/public/jelly/comet.webp +0 -0
  123. /package/templates/{app → appSample}/public/jelly/moon.webp +0 -0
  124. /package/templates/{app → appSample}/public/jelly/planet.webp +0 -0
  125. /package/templates/{app → appSample}/public/jelly/rocket.webp +0 -0
  126. /package/templates/{app → appSample}/public/jelly/star.webp +0 -0
  127. /package/templates/{app → appSample}/public/jelly/sugar.webp +0 -0
  128. /package/templates/{app → appSample}/public/logo.png +0 -0
  129. /package/templates/{app → appSample}/ui/Recipe/index.ts +0 -0
  130. /package/templates/{app → appSample}/ui/Recipe/jellyButton.ts +0 -0
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  camelToKebabCase,
4
4
  runner
5
- } from "./index-9zy8479y.js";
5
+ } from "./index-93ewzmp6.js";
6
6
  import {
7
7
  FileSys2
8
8
  } from "./index-bns3wcpc.js";
@@ -10,7 +10,6 @@ import {
10
10
  extractAgentBlock,
11
11
  collectScopeRecipeSources,
12
12
  renderScopeAgentBlock,
13
- JsonFormatter,
14
13
  Linter,
15
14
  rootAllowedFiles,
16
15
  rootAllowedDirs,
@@ -20,17 +19,24 @@ import {
20
19
  rootEntryHintOf,
21
20
  WorkspaceExecutor,
22
21
  SysExecutor,
23
- LibExecutor
24
- } from "./index-g500c5j9.js";
22
+ LibExecutor,
23
+ PkgExecutor
24
+ } from "./index-sr5da35e.js";
25
25
  import {
26
26
  countBlocking,
27
27
  formatStyleContract,
28
28
  ThemeValidator
29
29
  } from "./index-62md4dwy.js";
30
30
  import {
31
- createAst,
32
- createFactReader
33
- } from "./index-j2dgmzbj.js";
31
+ GitRevision
32
+ } from "./index-ygdbn9jn.js";
33
+ import {
34
+ MaintainabilityBaseline
35
+ } from "./index-hqrkqxx2.js";
36
+ import {
37
+ createFactReader,
38
+ createAst
39
+ } from "./index-7y5yghjg.js";
34
40
  import {
35
41
  collectRecipeSources2,
36
42
  scanRecipes2
@@ -38,11 +44,11 @@ import {
38
44
  import {
39
45
  getNpmRegistryUrl,
40
46
  getLatestPackageVersion
41
- } from "./index-4am4dvmf.js";
47
+ } from "./index-ny2k80mv.js";
42
48
  import {
43
49
  sysInputs,
44
50
  workflowSpecs
45
- } from "./index-k64mhwbw.js";
51
+ } from "./index-eajbmk10.js";
46
52
 
47
53
  // pkgs/@akanjs/cli/workspace/workspace.runner.ts
48
54
  import { mkdir, writeFile as writeFile2 } from "fs/promises";
@@ -56,7 +62,7 @@ var biomeVersion = "2.5.14";
56
62
  import { existsSync } from "fs";
57
63
  import { readFile, rm, writeFile } from "fs/promises";
58
64
  import path4 from "path";
59
- import ts11 from "typescript";
65
+ import ts12 from "typescript";
60
66
 
61
67
  // pkgs/@akanjs/devkit/componentSizeScanner.ts
62
68
  import ts from "typescript";
@@ -444,170 +450,6 @@ class EndpointReach {
444
450
  }
445
451
  }
446
452
 
447
- // pkgs/@akanjs/devkit/maintainabilityBaseline.ts
448
- class MaintainabilityBaseline {
449
- sections;
450
- reasons;
451
- static fileName = "akan.baseline.json";
452
- static reasonMinChars = 10;
453
- static debtRules = [
454
- "akan.size.file",
455
- "akan.size.component",
456
- "akan.component.store-access",
457
- "akan.store.multi-write",
458
- "akan.store.root-write-chain",
459
- "akan.component.write-chain",
460
- "akan.write.placement",
461
- "akan.service.call-in-loop"
462
- ];
463
- static reasonedRules = new Set([
464
- "akan.size.file",
465
- "akan.size.component",
466
- "akan.component.store-access",
467
- "akan.service.call-in-loop"
468
- ]);
469
- static countOf(violation) {
470
- if (violation.kind === "size")
471
- return violation.lineCount;
472
- if (violation.kind === "storeAccess")
473
- return violation.accessCount;
474
- if (violation.kind === "multiWrite")
475
- return violation.writeCount;
476
- if (violation.kind === "writePlacement")
477
- return violation.writes.length;
478
- return violation.calls.length;
479
- }
480
- static isDebtRule(name) {
481
- return MaintainabilityBaseline.debtRules.includes(name);
482
- }
483
- static parse(text, source = MaintainabilityBaseline.fileName, { lenient = false } = {}) {
484
- let json;
485
- try {
486
- json = JSON.parse(text);
487
- } catch {
488
- throw new Error(`${source} is not valid JSON.`);
489
- }
490
- if (typeof json !== "object" || json === null || Array.isArray(json))
491
- throw new Error(`${source} holds an object keyed by rule id.`);
492
- const sections = new Map;
493
- let reasons = new Map;
494
- for (const [name, value] of Object.entries(json)) {
495
- if (name === "reasons") {
496
- const entries = MaintainabilityBaseline.#reasonsOf(value);
497
- if (!entries)
498
- throw new Error(`${source}: "reasons" maps an entry's key to a sentence.`);
499
- reasons = new Map(entries);
500
- continue;
501
- }
502
- if (!MaintainabilityBaseline.isDebtRule(name)) {
503
- if (lenient)
504
- continue;
505
- throw new Error(`${source}: "${name}" is not a rule id. Its sections are ${MaintainabilityBaseline.debtRules.join(", ")} and "reasons"; rewrite it with \`akan quality baseline --force\`.`);
506
- }
507
- const counts = MaintainabilityBaseline.#countsOf(value);
508
- if (!counts)
509
- throw new Error(`${source}: "${name}" maps each key to a whole-number count.`);
510
- sections.set(name, new Map(counts));
511
- }
512
- return new MaintainabilityBaseline(sections, reasons);
513
- }
514
- static of(violations, reasons = new Map) {
515
- const sections = new Map;
516
- for (const violation of violations) {
517
- const counts = sections.get(violation.rule) ?? new Map;
518
- const count = MaintainabilityBaseline.countOf(violation);
519
- counts.set(violation.key, Math.max(counts.get(violation.key) ?? 0, count));
520
- sections.set(violation.rule, counts);
521
- }
522
- return new MaintainabilityBaseline(sections).#withReasonsOf(reasons);
523
- }
524
- constructor(sections = new Map, reasons = new Map) {
525
- this.sections = sections;
526
- this.reasons = reasons;
527
- }
528
- get isEmpty() {
529
- return [...this.sections.values()].every((counts) => !counts.size);
530
- }
531
- allows(violation) {
532
- const recorded = this.recordedOf(violation);
533
- return recorded !== undefined && MaintainabilityBaseline.countOf(violation) <= recorded;
534
- }
535
- recordedOf(violation) {
536
- return this.sections.get(violation.rule)?.get(violation.key);
537
- }
538
- reasonOf(key) {
539
- const reason = this.#holdsReasoned(key) ? this.reasons.get(key) : undefined;
540
- return reason && reason.replace(/\s/g, "").length >= MaintainabilityBaseline.reasonMinChars ? reason : undefined;
541
- }
542
- entriesByRule() {
543
- return new Map([...this.sections].filter(([, counts]) => counts.size).map(([rule, counts]) => [
544
- rule,
545
- [...counts].map(([key, count]) => ({
546
- key,
547
- count,
548
- reason: MaintainabilityBaseline.reasonedRules.has(rule) ? this.reasonOf(key) : undefined
549
- }))
550
- ]));
551
- }
552
- tightenedBy(violations) {
553
- const current = MaintainabilityBaseline.of(violations);
554
- const sections = new Map([...this.sections].map(([rule, counts]) => [
555
- rule,
556
- MaintainabilityBaseline.#lowered(counts, current.sections.get(rule) ?? new Map)
557
- ]));
558
- return new MaintainabilityBaseline(sections).#withReasonsOf(this.reasons);
559
- }
560
- #withReasonsOf(reasons) {
561
- return new MaintainabilityBaseline(this.sections, new Map([...reasons].filter(([key]) => this.#holdsReasoned(key))));
562
- }
563
- grownFrom(committed) {
564
- return [...this.sections].flatMap(([rule, counts]) => MaintainabilityBaseline.#raised(counts, committed.sections.get(rule) ?? new Map).filter(([key]) => !(MaintainabilityBaseline.reasonedRules.has(rule) && this.reasonOf(key))).map(([key, count, recorded]) => ({ rule, key, count, committed: recorded })));
565
- }
566
- stringify() {
567
- const sections = MaintainabilityBaseline.debtRules.flatMap((rule) => {
568
- const counts = this.sections.get(rule);
569
- return counts?.size ? [[rule, MaintainabilityBaseline.#sortedObjectOf(counts)]] : [];
570
- });
571
- return JsonFormatter.stringify({
572
- ...Object.fromEntries(sections),
573
- ...this.reasons.size ? { reasons: MaintainabilityBaseline.#sortedObjectOf(this.reasons) } : {}
574
- }, MaintainabilityBaseline.fileName);
575
- }
576
- #holdsReasoned(key) {
577
- return [...this.sections].some(([rule, counts]) => MaintainabilityBaseline.reasonedRules.has(rule) && counts.has(key));
578
- }
579
- static #countsOf(value) {
580
- if (typeof value !== "object" || value === null || Array.isArray(value))
581
- return null;
582
- const entries = Object.entries(value);
583
- return entries.every(([, count]) => Number.isInteger(count)) ? entries : null;
584
- }
585
- static #reasonsOf(value) {
586
- if (typeof value !== "object" || value === null || Array.isArray(value))
587
- return null;
588
- const entries = Object.entries(value);
589
- return entries.every(([, reason]) => typeof reason === "string") ? entries : null;
590
- }
591
- static #lowered(recorded, current) {
592
- return new Map([...recorded].flatMap(([key, count]) => {
593
- const measured = current.get(key);
594
- return measured === undefined ? [] : [[key, Math.min(count, measured)]];
595
- }));
596
- }
597
- static #raised(working, committed) {
598
- return [...working].flatMap(([key, count]) => {
599
- const recorded = committed.get(key);
600
- return recorded !== undefined && count <= recorded ? [] : [[key, count, recorded]];
601
- });
602
- }
603
- static #sortedObjectOf(values) {
604
- return Object.fromEntries([...values].sort(([a], [b]) => MaintainabilityBaseline.#byKey(a, b)));
605
- }
606
- static #byKey(a, b) {
607
- return a < b ? -1 : a > b ? 1 : 0;
608
- }
609
- }
610
-
611
453
  // pkgs/@akanjs/devkit/maintainabilityLimits.ts
612
454
  import path3 from "path";
613
455
  import ts6 from "typescript";
@@ -626,7 +468,8 @@ class AbstractDoc {
626
468
  return filePath.endsWith(AbstractDoc.suffix);
627
469
  }
628
470
  static lineCountOf(content) {
629
- return content.split(/\r?\n/).length;
471
+ return content.split(/\r?\n/).length - (content.endsWith(`
472
+ `) ? 1 : 0);
630
473
  }
631
474
  static kindOf(filePath) {
632
475
  const [root, folder, ...rest] = filePath.split("/");
@@ -693,6 +536,9 @@ class MaintainabilityLimits {
693
536
  static #maxLinesByKind = { ...MaintainabilityLimits.fileMaxLines, ...MaintainabilityLimits.folderMaxLines };
694
537
  static componentMaxLines = 250;
695
538
  static componentMaxStoreAccesses = 16;
539
+ static packageFileMaxLines = 800;
540
+ static functionMaxLines = 150;
541
+ static classMaxMembers = 60;
696
542
  static fileKindOf(sysRelativePath) {
697
543
  const kinds = Object.keys(MaintainabilityLimits.#maxLinesByKind);
698
544
  const suffix = kinds.find((kind) => sysRelativePath.endsWith(kind));
@@ -721,6 +567,9 @@ class MaintainabilityLimits {
721
567
  return sysRelativePath.endsWith(".tsx");
722
568
  return /^(ui|webkit)\/.+\.tsx?$/.test(sysRelativePath) && !sysRelativePath.endsWith(".d.ts");
723
569
  }
570
+ static isPackageSource(pkgRelativePath) {
571
+ return /\.tsx?$/.test(pkgRelativePath) && !pkgRelativePath.endsWith(".d.ts") && !/(^|\/)(examples|test|tests|__tests__|__fixtures__|__mocks__)\//.test(pkgRelativePath) && !/\.(test|spec|fixture|instance|bench)\.tsx?$/.test(pkgRelativePath);
572
+ }
724
573
  static #isTest(sysRelativePath) {
725
574
  return /\.(test|spec)\.tsx?$/.test(sysRelativePath);
726
575
  }
@@ -742,8 +591,11 @@ class MaintainabilityReport {
742
591
  ".store.ts": "Move business logic into the service behind an endpoint and derived values onto Light<Model>; an action is fetch, set, toast.",
743
592
  ".document.ts": "Move display and predicate logic onto Light<Model>, and split an unrelated concept into its own module.",
744
593
  ".service.ts": "Move state transitions into document chain methods, and split an unrelated responsibility into its own module.",
594
+ package: "Split it by responsibility: one class per file, and each family of helpers in a file of its own behind the package's existing exports.",
745
595
  [AbstractDoc.suffix]: "Trim the abstract to a title, one sentence naming what the module owns, and a `## Rules` list of the invariants the code cannot show.",
746
596
  "akan.size.component": MaintainabilityReport.#clientSplitFix,
597
+ "akan.size.function": "Split it by family into named functions or a collaborator class, each under the limit, keeping its signature for callers.",
598
+ "akan.size.class": "Move each family of members into a collaborator the class holds, and keep the public members on the class as its facade.",
747
599
  "akan.store.multi-write": MaintainabilityReport.#oneEndpointFix,
748
600
  "akan.store.root-write-chain": `A store may call another through \`RootStore\`, but that does not make the writes one. ${MaintainabilityReport.#oneEndpointFix}`,
749
601
  "akan.component.write-chain": "Move the writes into one service method behind one endpoint, called by one store action the handler calls once; a component chaining `st.do` writes, or writing once per item, leaves an agent or another screen half-done.",
@@ -755,7 +607,10 @@ class MaintainabilityReport {
755
607
  static #labels = {
756
608
  "ui/": "ui/**",
757
609
  "webkit/": "webkit/**",
610
+ package: "package file",
758
611
  "akan.size.component": "component or hook",
612
+ "akan.size.function": "function",
613
+ "akan.size.class": "class",
759
614
  "akan.store.multi-write": "store action with several writes",
760
615
  "akan.store.root-write-chain": "store method chaining other stores' writes",
761
616
  "akan.component.write-chain": "handler with several writes",
@@ -767,6 +622,8 @@ class MaintainabilityReport {
767
622
  static #units = {
768
623
  "akan.size.file": "lines",
769
624
  "akan.size.component": "lines",
625
+ "akan.size.function": "lines",
626
+ "akan.size.class": "members",
770
627
  "akan.component.store-access": "store accesses",
771
628
  "akan.store.multi-write": "writes",
772
629
  "akan.store.root-write-chain": "writes",
@@ -777,7 +634,7 @@ class MaintainabilityReport {
777
634
  static describe(sysPath, failures, commands = {}) {
778
635
  const groups = new Map;
779
636
  for (const failure of failures) {
780
- const fixKey = MaintainabilityReport.#fixKeyOf(failure);
637
+ const fixKey = MaintainabilityReport.#fixKeyOf(sysPath, failure);
781
638
  const fix = MaintainabilityReport.#fixes[fixKey];
782
639
  const group = groups.get(fix) ?? { labels: [], rules: new Set };
783
640
  const label = MaintainabilityReport.#labelOf(fixKey);
@@ -803,14 +660,17 @@ class MaintainabilityReport {
803
660
  line: failure.line,
804
661
  rule: failure.rule,
805
662
  problem: MaintainabilityReport.#problemOf(failure),
806
- fix: MaintainabilityReport.#fixes[MaintainabilityReport.#fixKeyOf(failure)],
663
+ fix: MaintainabilityReport.#fixes[MaintainabilityReport.#fixKeyOf(sysPath, failure)],
807
664
  path: commands[failure.rule]?.[0] ?? null
808
665
  }));
809
666
  }
810
667
  static #problemOf(failure) {
811
668
  if (failure.kind === "baselineGrowth") {
812
669
  const entry = `entry "${failure.key}" under ${failure.debtRule}`;
813
- return failure.committed === undefined ? `${entry} is not in the baseline at ${failure.reference}, which may only shrink` : `${entry} allows ${failure.count} ${MaintainabilityReport.#units[failure.debtRule]}, above the ${failure.committed} at ${failure.reference}; the baseline may only shrink`;
670
+ const units = MaintainabilityReport.#units[failure.debtRule];
671
+ if (failure.measured)
672
+ return failure.committed === undefined ? `${entry} is debt the code at ${failure.reference} does not hold, and with no baseline there the baseline may only shrink from that code` : `${entry} allows ${failure.count} ${units}, above the ${failure.committed} the code at ${failure.reference} holds with no baseline there; the baseline may only shrink`;
673
+ return failure.committed === undefined ? `${entry} is not in the baseline at ${failure.reference}, which may only shrink` : `${entry} allows ${failure.count} ${units}, above the ${failure.committed} at ${failure.reference}; the baseline may only shrink`;
814
674
  }
815
675
  const grown = failure.recorded === undefined ? "" : `, more than the ${failure.recorded} recorded`;
816
676
  if (failure.kind === "multiWrite") {
@@ -826,18 +686,22 @@ class MaintainabilityReport {
826
686
  return `sends ${failure.writes.length} server write(s) from outside a store action or a module component: ${failure.writes.join(", ")}${grown}`;
827
687
  if (failure.kind === "loopCall")
828
688
  return `service method ${failure.owner} calls once per item: ${failure.calls.join(", ")}${grown}`;
689
+ if (failure.kind === "classSize")
690
+ return `class ${failure.owner} has ${failure.memberCount} members, over the ${failure.maxMembers}-member limit${failure.recorded === undefined ? "" : `, up from ${failure.recorded}`}`;
829
691
  if (failure.kind === "storeAccess")
830
692
  return `${MaintainabilityReport.#unitOf(failure.component)} ${failure.component} reaches the store ${failure.accessCount} times, over the ${failure.maxAccesses}-access limit${failure.recorded === undefined ? "" : `, up from ${failure.recorded}`}`;
831
- const subject = failure.component ? `${MaintainabilityReport.#unitOf(failure.component)} ${failure.component} has` : "file has";
693
+ const subject = failure.function ? `function ${failure.function} has` : failure.component ? `${MaintainabilityReport.#unitOf(failure.component)} ${failure.component} has` : "file has";
832
694
  const up = failure.recorded === undefined ? "" : `, up from ${failure.recorded}`;
833
695
  return `${subject} ${failure.lineCount} lines, over the ${failure.maxLines}-line limit${up}`;
834
696
  }
835
697
  static #unitOf(name) {
836
698
  return /^use[A-Z]/.test(name) ? "hook" : "component";
837
699
  }
838
- static #fixKeyOf(failure) {
700
+ static #fixKeyOf(sysPath, failure) {
839
701
  if (failure.rule !== "akan.size.file")
840
702
  return failure.rule;
703
+ if (sysPath.startsWith("pkgs/"))
704
+ return "package";
841
705
  return MaintainabilityLimits.fileKindOf(failure.file) ?? "akan.size.component";
842
706
  }
843
707
  static #labelOf(fixKey) {
@@ -1171,8 +1035,120 @@ class StoreWriteScanner {
1171
1035
  }
1172
1036
  }
1173
1037
 
1174
- // pkgs/@akanjs/devkit/writePlacementScanner.ts
1038
+ // pkgs/@akanjs/devkit/structureScanner.ts
1175
1039
  import ts10 from "typescript";
1040
+
1041
+ class StructureScanner {
1042
+ measure(sourceFile) {
1043
+ const functions = [];
1044
+ const classes = [];
1045
+ const lineOf = (pos) => sourceFile.getLineAndCharacterOfPosition(pos).line + 1;
1046
+ const visit = (node, owners) => {
1047
+ if (ts10.isClassDeclaration(node) || ts10.isClassExpression(node)) {
1048
+ const name = StructureScanner.#classNameOf(node);
1049
+ classes.push({
1050
+ name: [...owners, name].join("."),
1051
+ line: lineOf(node.getStart(sourceFile)),
1052
+ memberCount: StructureScanner.#memberCountOf(node)
1053
+ });
1054
+ ts10.forEachChild(node, (child) => visit(child, [...owners, name]));
1055
+ return;
1056
+ }
1057
+ if (StructureScanner.#isFunction(node)) {
1058
+ const name = StructureScanner.#functionNameOf(node);
1059
+ const line = lineOf(node.getStart(sourceFile));
1060
+ functions.push({
1061
+ name: [...owners, name].join("."),
1062
+ line,
1063
+ lineCount: lineOf(node.getEnd()) - line + 1
1064
+ });
1065
+ ts10.forEachChild(node, (child) => visit(child, [...owners, name]));
1066
+ return;
1067
+ }
1068
+ if (ts10.isObjectLiteralExpression(node)) {
1069
+ const name = StructureScanner.#boundNameOf(node);
1070
+ ts10.forEachChild(node, (child) => visit(child, name === "<anonymous>" ? owners : [...owners, name]));
1071
+ return;
1072
+ }
1073
+ ts10.forEachChild(node, (child) => visit(child, owners));
1074
+ };
1075
+ ts10.forEachChild(sourceFile, (child) => visit(child, []));
1076
+ return { functions, classes };
1077
+ }
1078
+ static #memberCountOf(node) {
1079
+ const methods = new Set;
1080
+ return node.members.filter((member) => {
1081
+ if (ts10.isSemicolonClassElement(member) || ts10.isIndexSignatureDeclaration(member) || ts10.isClassStaticBlockDeclaration(member))
1082
+ return false;
1083
+ if (!ts10.isMethodDeclaration(member) && !ts10.isConstructorDeclaration(member))
1084
+ return true;
1085
+ const isStatic = ts10.getModifiers(member)?.some((modifier) => modifier.kind === ts10.SyntaxKind.StaticKeyword);
1086
+ const key = `${isStatic ? "static " : ""}${ts10.isConstructorDeclaration(member) ? "constructor" : StructureScanner.#textOf(member.name)}`;
1087
+ if (methods.has(key))
1088
+ return false;
1089
+ methods.add(key);
1090
+ return true;
1091
+ }).length;
1092
+ }
1093
+ static #isFunction(node) {
1094
+ return (ts10.isFunctionDeclaration(node) || ts10.isMethodDeclaration(node) || ts10.isConstructorDeclaration(node) || ts10.isGetAccessorDeclaration(node) || ts10.isSetAccessorDeclaration(node) || ts10.isFunctionExpression(node) || ts10.isArrowFunction(node)) && node.body !== undefined;
1095
+ }
1096
+ static #functionNameOf(node) {
1097
+ if (ts10.isConstructorDeclaration(node))
1098
+ return "constructor";
1099
+ if (ts10.isGetAccessorDeclaration(node))
1100
+ return `get ${StructureScanner.#textOf(node.name)}`;
1101
+ if (ts10.isSetAccessorDeclaration(node))
1102
+ return `set ${StructureScanner.#textOf(node.name)}`;
1103
+ if (node.name)
1104
+ return StructureScanner.#textOf(node.name);
1105
+ return ts10.isFunctionDeclaration(node) ? "default" : StructureScanner.#boundNameOf(node);
1106
+ }
1107
+ static #classNameOf(node) {
1108
+ if (node.name)
1109
+ return node.name.text;
1110
+ return ts10.isClassDeclaration(node) ? "default" : StructureScanner.#boundNameOf(node);
1111
+ }
1112
+ static #boundNameOf(node) {
1113
+ let current = StructureScanner.#outerOf(node);
1114
+ let call = null;
1115
+ while (ts10.isCallExpression(current.parent) || ts10.isNewExpression(current.parent)) {
1116
+ const callee = current.parent.expression;
1117
+ if (current === callee)
1118
+ break;
1119
+ call ??= `${ts10.isPropertyAccessExpression(callee) ? callee.name.text : ts10.isIdentifier(callee) ? callee.text : "call"}()`;
1120
+ current = StructureScanner.#outerOf(current.parent);
1121
+ }
1122
+ const { parent } = current;
1123
+ if ((ts10.isVariableDeclaration(parent) || ts10.isPropertyAssignment(parent) || ts10.isPropertyDeclaration(parent) || ts10.isParameter(parent) || ts10.isBindingElement(parent)) && parent.name && !ts10.isObjectBindingPattern(parent.name) && !ts10.isArrayBindingPattern(parent.name))
1124
+ return StructureScanner.#textOf(parent.name);
1125
+ if (ts10.isBinaryExpression(parent) && parent.operatorToken.kind === ts10.SyntaxKind.EqualsToken)
1126
+ return ts10.isPropertyAccessExpression(parent.left) ? parent.left.name.text : ts10.isIdentifier(parent.left) ? parent.left.text : "assigned";
1127
+ if (ts10.isExportAssignment(parent))
1128
+ return "default";
1129
+ if (ts10.isJsxExpression(parent))
1130
+ return ts10.isJsxAttribute(parent.parent) ? ts10.isIdentifier(parent.parent.name) ? parent.parent.name.text : parent.parent.name.getText() : "children";
1131
+ return call ?? "<anonymous>";
1132
+ }
1133
+ static #outerOf(node) {
1134
+ let current = node;
1135
+ while (ts10.isParenthesizedExpression(current.parent) || ts10.isAsExpression(current.parent) || ts10.isSatisfiesExpression(current.parent) || ts10.isNonNullExpression(current.parent) || ts10.isTypeAssertionExpression(current.parent) || ts10.isPropertyAccessExpression(current.parent) && current.parent.expression === current || ts10.isCallExpression(current.parent) && current.parent.expression === current)
1136
+ current = current.parent;
1137
+ return current;
1138
+ }
1139
+ static #textOf(name) {
1140
+ if (ts10.isIdentifier(name) || ts10.isPrivateIdentifier(name) || ts10.isStringLiteral(name))
1141
+ return name.text;
1142
+ if (ts10.isNumericLiteral(name) || ts10.isNoSubstitutionTemplateLiteral(name))
1143
+ return name.text;
1144
+ if (ts10.isComputedPropertyName(name))
1145
+ return `[${name.expression.getText()}]`;
1146
+ return "<pattern>";
1147
+ }
1148
+ }
1149
+
1150
+ // pkgs/@akanjs/devkit/writePlacementScanner.ts
1151
+ import ts11 from "typescript";
1176
1152
  class WritePlacementScanner {
1177
1153
  #index;
1178
1154
  constructor(index) {
@@ -1185,9 +1161,9 @@ class WritePlacementScanner {
1185
1161
  return null;
1186
1162
  const sites = [];
1187
1163
  const visit = (node) => {
1188
- if (ts10.isPropertyAccessExpression(node) && this.#isWrite(node, workspaceFile, fetchNames, stNames))
1164
+ if (ts11.isPropertyAccessExpression(node) && this.#isWrite(node, workspaceFile, fetchNames, stNames))
1189
1165
  sites.push(node);
1190
- ts10.forEachChild(node, visit);
1166
+ ts11.forEachChild(node, visit);
1191
1167
  };
1192
1168
  visit(sourceFile);
1193
1169
  const first = sites[0];
@@ -1200,9 +1176,9 @@ class WritePlacementScanner {
1200
1176
  }
1201
1177
  #isWrite(access, workspaceFile, fetchNames, stNames) {
1202
1178
  const owner = access.expression;
1203
- if (ts10.isIdentifier(owner) && fetchNames.has(owner.text))
1179
+ if (ts11.isIdentifier(owner) && fetchNames.has(owner.text))
1204
1180
  return this.#index.isMutation(workspaceFile, access.name.text);
1205
- return ts10.isPropertyAccessExpression(owner) && owner.name.text === "do" && ts10.isIdentifier(owner.expression) && stNames.has(owner.expression.text) && this.#index.isWritingAction(access.name.text);
1181
+ return ts11.isPropertyAccessExpression(owner) && owner.name.text === "do" && ts11.isIdentifier(owner.expression) && stNames.has(owner.expression.text) && this.#index.isWritingAction(access.name.text);
1206
1182
  }
1207
1183
  }
1208
1184
 
@@ -1266,6 +1242,8 @@ class MaintainabilityContract {
1266
1242
  static ruleIds = [
1267
1243
  "akan.size.file",
1268
1244
  "akan.size.component",
1245
+ "akan.size.function",
1246
+ "akan.size.class",
1269
1247
  "akan.store.multi-write",
1270
1248
  "akan.store.root-write-chain",
1271
1249
  "akan.component.write-chain",
@@ -1279,6 +1257,7 @@ class MaintainabilityContract {
1279
1257
  #workspaceRoot;
1280
1258
  #scope;
1281
1259
  #libNames;
1260
+ #tree = null;
1282
1261
  constructor(workspaceRoot, scope, libNames = []) {
1283
1262
  this.#workspaceRoot = workspaceRoot;
1284
1263
  this.#scope = scope;
@@ -1291,6 +1270,8 @@ class MaintainabilityContract {
1291
1270
  return path4.join(this.#workspaceRoot, this.sysPath, MaintainabilityBaseline.fileName);
1292
1271
  }
1293
1272
  async measure() {
1273
+ if (this.#scope.type === "pkg")
1274
+ return await this.#measurePackage();
1294
1275
  const [signalFiles, storeFiles, serviceFiles] = await Promise.all([
1295
1276
  this.#reachedSources("lib/**/*.signal.ts"),
1296
1277
  this.#reachedSources("lib/**/*.store.ts"),
@@ -1298,7 +1279,7 @@ class MaintainabilityContract {
1298
1279
  ]);
1299
1280
  const index = new WritingActionIndex(new SignalMutationIndex(signalFiles), storeFiles);
1300
1281
  const reach = new EndpointReach(signalFiles, serviceFiles);
1301
- const files = await MaintainabilityContract.#filesUnder(path4.join(this.#workspaceRoot, this.sysPath), MaintainabilityContract.#measuredFiles);
1282
+ const files = await this.#filesIn(this.sysPath, MaintainabilityContract.#measuredFiles);
1302
1283
  const violations = await Promise.all(files.map((file) => this.#measureFile(file, index, reach)));
1303
1284
  return violations.flat().sort((a, b) => a.file < b.file ? -1 : a.file > b.file ? 1 : a.line - b.line);
1304
1285
  }
@@ -1316,17 +1297,20 @@ class MaintainabilityContract {
1316
1297
  const recorded = baseline.recordedOf(violation);
1317
1298
  return recorded === undefined ? violation : { ...violation, recorded };
1318
1299
  });
1319
- if (reference === null)
1300
+ const working = fix ? tightened : baseline;
1301
+ const source = `${reference.label}:${this.sysPath}/${MaintainabilityBaseline.fileName}`;
1302
+ const committed = reference.text !== null ? MaintainabilityBaseline.parse(reference.text, source, { lenient: true }) : working.isEmpty ? null : await this.#measuredAt(reference.ref);
1303
+ if (committed === null)
1320
1304
  return failures;
1321
1305
  const lines = (await this.#readBaseline() ?? "").split(/\r?\n/);
1322
- const label = `${reference.ref}:${this.sysPath}/${MaintainabilityBaseline.fileName}`;
1323
- const growths = (fix ? tightened : baseline).grownFrom(MaintainabilityBaseline.parse(reference.text, label, { lenient: true })).map(({ rule, ...growth }) => ({
1306
+ const growths = working.grownFrom(committed).map(({ rule, ...growth }) => ({
1324
1307
  kind: "baselineGrowth",
1325
1308
  rule: "akan.baseline.growth",
1326
1309
  file: MaintainabilityBaseline.fileName,
1327
1310
  line: MaintainabilityContract.#lineOf(lines, rule, growth.key),
1328
1311
  debtRule: rule,
1329
- reference: reference.ref,
1312
+ reference: reference.label,
1313
+ ...reference.text === null ? { measured: true } : {},
1330
1314
  ...growth
1331
1315
  })).sort((a, b) => a.line - b.line);
1332
1316
  return [...growths, ...failures];
@@ -1346,6 +1330,63 @@ class MaintainabilityContract {
1346
1330
  describe(failures, commands) {
1347
1331
  return MaintainabilityReport.describe(this.sysPath, failures, commands);
1348
1332
  }
1333
+ async#measurePackage() {
1334
+ const files = (await this.#packageFiles()).filter(MaintainabilityLimits.isPackageSource);
1335
+ const violations = await Promise.all(files.map(async (file) => {
1336
+ const workspaceFile = `${this.sysPath}/${file}`;
1337
+ const content = await this.#read(workspaceFile);
1338
+ return MaintainabilityContract.#measurePackageFile(file, this.#sourceOf(workspaceFile, content).sourceFile);
1339
+ }));
1340
+ return violations.flat();
1341
+ }
1342
+ static #measurePackageFile(file, sourceFile) {
1343
+ const violations = [];
1344
+ const maxLines = MaintainabilityLimits.packageFileMaxLines;
1345
+ const lineCount = MaintainabilityLimits.lineCountOf(sourceFile.text);
1346
+ if (lineCount > maxLines && !MaintainabilityLimits.isReexportBarrel(file, sourceFile.text))
1347
+ violations.push({ kind: "size", rule: "akan.size.file", key: file, file, line: 1, lineCount, maxLines });
1348
+ const { functions, classes } = new StructureScanner().measure(sourceFile);
1349
+ const longFunctions = functions.filter(({ lineCount }) => lineCount > MaintainabilityLimits.functionMaxLines);
1350
+ for (const { name, line, lineCount } of MaintainabilityContract.#numbered(longFunctions))
1351
+ violations.push({
1352
+ kind: "size",
1353
+ rule: "akan.size.function",
1354
+ key: `${file}#${name}`,
1355
+ file,
1356
+ line,
1357
+ lineCount,
1358
+ maxLines: MaintainabilityLimits.functionMaxLines,
1359
+ function: name
1360
+ });
1361
+ const largeClasses = classes.filter(({ memberCount }) => memberCount > MaintainabilityLimits.classMaxMembers);
1362
+ for (const { name, line, memberCount } of MaintainabilityContract.#numbered(largeClasses))
1363
+ violations.push({
1364
+ kind: "classSize",
1365
+ rule: "akan.size.class",
1366
+ key: `${file}#${name}`,
1367
+ file,
1368
+ line,
1369
+ owner: name,
1370
+ memberCount,
1371
+ maxMembers: MaintainabilityLimits.classMaxMembers
1372
+ });
1373
+ return violations;
1374
+ }
1375
+ static #numbered(items) {
1376
+ const seen = new Map;
1377
+ return items.map((item) => {
1378
+ const count = (seen.get(item.name) ?? 0) + 1;
1379
+ seen.set(item.name, count);
1380
+ return count === 1 ? item : { ...item, name: `${item.name}[${count}]` };
1381
+ });
1382
+ }
1383
+ async#packageFiles() {
1384
+ const listed = this.#tree ? null : await this.#git(["ls-files", "-z", "-co", "--exclude-standard", "--", `./${this.sysPath}`]);
1385
+ if (listed === null)
1386
+ return await this.#filesIn(this.sysPath, "**/*.{ts,tsx}");
1387
+ const prefix = `${this.sysPath}/`;
1388
+ return listed.split("\x00").filter((file) => file.startsWith(prefix) && existsSync(path4.join(this.#workspaceRoot, file))).map((file) => file.slice(prefix.length)).filter((file) => !file.includes("node_modules/")).sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
1389
+ }
1349
1390
  async#measureFile(file, index, reach) {
1350
1391
  const maxLines = MaintainabilityLimits.fileMaxLinesOf(file);
1351
1392
  const isStore = file.endsWith(".store.ts");
@@ -1354,7 +1395,7 @@ class MaintainabilityContract {
1354
1395
  if (!maxLines && !isStore && !isClientCode)
1355
1396
  return [];
1356
1397
  const workspaceFile = `${this.sysPath}/${file}`;
1357
- const content = await readFile(path4.join(this.#workspaceRoot, workspaceFile), "utf8");
1398
+ const content = await this.#read(workspaceFile);
1358
1399
  const violations = [];
1359
1400
  const lineCount = MaintainabilityLimits.lineCountOf(content);
1360
1401
  if (maxLines && lineCount > maxLines && !MaintainabilityLimits.isReexportBarrel(file, content))
@@ -1433,16 +1474,16 @@ class MaintainabilityContract {
1433
1474
  }
1434
1475
  async#reachedSources(pattern) {
1435
1476
  const roots = [this.sysPath, ...this.#libNames.map((libName) => `libs/${libName}`)];
1436
- const files = await Promise.all(roots.map(async (root) => (await MaintainabilityContract.#filesUnder(path4.join(this.#workspaceRoot, root), pattern)).map((file) => `${root}/${file}`)));
1437
- return await Promise.all(files.flat().map(async (file) => this.#sourceOf(file, await readFile(path4.join(this.#workspaceRoot, file), "utf8"))));
1477
+ const files = await Promise.all(roots.map(async (root) => (await this.#filesIn(root, pattern)).map((file) => `${root}/${file}`)));
1478
+ return await Promise.all(files.flat().map(async (file) => this.#sourceOf(file, await this.#read(file))));
1438
1479
  }
1439
1480
  #sourceOf(file, content) {
1440
- const scriptKind = file.endsWith(".tsx") ? ts11.ScriptKind.TSX : ts11.ScriptKind.TS;
1481
+ const scriptKind = file.endsWith(".tsx") ? ts12.ScriptKind.TSX : ts12.ScriptKind.TS;
1441
1482
  return {
1442
1483
  file,
1443
1484
  absolutePath: path4.join(this.#workspaceRoot, file),
1444
1485
  content,
1445
- sourceFile: ts11.createSourceFile(file, content, ts11.ScriptTarget.Latest, true, scriptKind)
1486
+ sourceFile: ts12.createSourceFile(file, content, ts12.ScriptTarget.Latest, true, scriptKind)
1446
1487
  };
1447
1488
  }
1448
1489
  async#readBaseline() {
@@ -1451,7 +1492,15 @@ class MaintainabilityContract {
1451
1492
  async#readReferenceBaseline() {
1452
1493
  const ref = await this.#referenceRef();
1453
1494
  const text = await this.#git(["show", `${ref}:./${this.sysPath}/${MaintainabilityBaseline.fileName}`]);
1454
- return text === null ? null : { ref: ref === "HEAD" ? ref : ref.slice(0, 12), text };
1495
+ return { ref, label: ref === "HEAD" ? ref : ref.slice(0, 12), text };
1496
+ }
1497
+ async#measuredAt(ref) {
1498
+ if (await this.#git(["rev-parse", "--verify", "--quiet", `${ref}^{commit}`]) === null)
1499
+ return null;
1500
+ const roots = [this.sysPath, ...this.#libNames.map((libName) => `libs/${libName}`)];
1501
+ const contract = new MaintainabilityContract(this.#workspaceRoot, this.#scope, this.#libNames);
1502
+ contract.#tree = await new GitRevision(this.#workspaceRoot).filesAt(ref, (file) => /\.(tsx?|md)$/.test(file), roots);
1503
+ return MaintainabilityBaseline.of(await contract.measure());
1455
1504
  }
1456
1505
  async#referenceRef() {
1457
1506
  for (const branch of MaintainabilityContract.#defaultBranches) {
@@ -1498,11 +1547,19 @@ class MaintainabilityContract {
1498
1547
  const idx = lines.findIndex((line, lineIdx) => lineIdx >= from && line.includes(`${JSON.stringify(key)}:`));
1499
1548
  return Math.max(idx + 1, 1);
1500
1549
  }
1501
- static async#filesUnder(root, pattern) {
1550
+ async#filesIn(root, pattern) {
1551
+ const glob = new Bun.Glob(pattern);
1552
+ const files = this.#tree ? [...this.#tree.keys()].filter((file) => file.startsWith(`${root}/`)).map((file) => file.slice(root.length + 1)).filter((file) => glob.match(file)) : await MaintainabilityContract.#filesOnDisk(path4.join(this.#workspaceRoot, root), glob);
1553
+ return files.filter((file) => !file.includes("node_modules/")).sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
1554
+ }
1555
+ static async#filesOnDisk(root, glob) {
1502
1556
  if (!existsSync(root))
1503
1557
  return [];
1504
- const files = await Array.fromAsync(new Bun.Glob(pattern).scan({ cwd: root, onlyFiles: true }));
1505
- return files.map((file) => file.split(path4.sep).join("/")).filter((file) => !file.includes("node_modules/")).sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
1558
+ const files = await Array.fromAsync(glob.scan({ cwd: root, onlyFiles: true }));
1559
+ return files.map((file) => file.split(path4.sep).join("/"));
1560
+ }
1561
+ async#read(file) {
1562
+ return this.#tree ? this.#tree.get(file) ?? "" : await readFile(path4.join(this.#workspaceRoot, file), "utf8");
1506
1563
  }
1507
1564
  }
1508
1565
 
@@ -1514,6 +1571,8 @@ class MaintainabilityPaths {
1514
1571
  static pathless = new Set([
1515
1572
  "akan.size.file",
1516
1573
  "akan.size.component",
1574
+ "akan.size.function",
1575
+ "akan.size.class",
1517
1576
  "akan.service.call-in-loop",
1518
1577
  "akan.baseline.growth"
1519
1578
  ]);
@@ -1588,7 +1647,8 @@ class WorkspaceRunner extends runner("workspace") {
1588
1647
  akanVersion,
1589
1648
  registryUrl,
1590
1649
  owner = "",
1591
- libs = []
1650
+ libs = [],
1651
+ bunDependency
1592
1652
  }) {
1593
1653
  const cwdPath = process.cwd();
1594
1654
  const workspaceRoot = inPlace ? path5.resolve(cwdPath, dirname) : path5.resolve(cwdPath, dirname, repoName);
@@ -1627,10 +1687,18 @@ class WorkspaceRunner extends runner("workspace") {
1627
1687
  const { typescript, ...dependencies } = peerDependencies;
1628
1688
  const packageJson = {
1629
1689
  ...rootPackageJson,
1690
+ ...bunDependency ? {
1691
+ scripts: {
1692
+ ...rootPackageJson.scripts,
1693
+ build: `akan build ${appName}`,
1694
+ start: `cd dist/apps/${appName} && bun main.js`
1695
+ }
1696
+ } : {},
1630
1697
  dependencies: {
1631
1698
  ...rootPackageJson.dependencies,
1632
1699
  ...dependencies,
1633
- akanjs: akanVersion
1700
+ akanjs: akanVersion,
1701
+ ...bunDependency ? { bun: bunDependency } : {}
1634
1702
  },
1635
1703
  devDependencies: {
1636
1704
  ...rootPackageJson.devDependencies,
@@ -1765,14 +1833,16 @@ class WorkspaceRunner extends runner("workspace") {
1765
1833
  () => this.#enforceAgentsIndex(exec)
1766
1834
  ])
1767
1835
  await gate().catch((error) => messages.push(error instanceof Error ? error.message : String(error)));
1768
- if (!(exec instanceof SysExecutor))
1836
+ if (!(exec instanceof SysExecutor) && !(exec instanceof PkgExecutor))
1769
1837
  return { messages, maintainability: [] };
1770
1838
  const contract = await this.maintainabilityContractOf(exec);
1771
1839
  const failures = await contract.enforce({ fix });
1772
- const maintainability = MaintainabilityReport.entriesOf(contract.sysPath, failures, new MaintainabilityPaths().commandsOf(exec.name));
1840
+ const maintainability = MaintainabilityReport.entriesOf(contract.sysPath, failures, WorkspaceRunner.#maintainabilityCommandsOf(exec));
1773
1841
  return { messages, maintainability };
1774
1842
  }
1775
1843
  async maintainabilityContractOf(exec) {
1844
+ if (exec instanceof PkgExecutor)
1845
+ return new MaintainabilityContract(exec.workspace.workspaceRoot, { type: "pkg", name: exec.name });
1776
1846
  const libNames = new Set;
1777
1847
  const visit = async (sys) => {
1778
1848
  for (const libName of (await sys.scan({ write: false })).getScanResult().libDeps) {
@@ -1809,12 +1879,15 @@ class WorkspaceRunner extends runner("workspace") {
1809
1879
  throw new Error(`[agentsIndex] The recipe index in ${scope.type}s/${scope.name}/AGENTS.md is stale: it differs from the recipe ` + `sources. Run \`akan sync ${scope.name}\` to regenerate it.`);
1810
1880
  }
1811
1881
  async#enforceMaintainability(exec, fix) {
1812
- if (!(exec instanceof SysExecutor))
1882
+ if (!(exec instanceof SysExecutor) && !(exec instanceof PkgExecutor))
1813
1883
  return;
1814
1884
  const contract = await this.maintainabilityContractOf(exec);
1815
1885
  const failures = await contract.enforce({ fix });
1816
1886
  if (failures.length)
1817
- throw new Error(contract.describe(failures, new MaintainabilityPaths().commandsOf(exec.name)));
1887
+ throw new Error(contract.describe(failures, WorkspaceRunner.#maintainabilityCommandsOf(exec)));
1888
+ }
1889
+ static #maintainabilityCommandsOf(exec) {
1890
+ return exec instanceof PkgExecutor ? {} : new MaintainabilityPaths().commandsOf(exec.name);
1818
1891
  }
1819
1892
  async#enforceRecipeGate(exec) {
1820
1893
  const cwdPath = exec.cwdPath;
@@ -1878,17 +1951,17 @@ import { readdir as readdir2, readFile as readFile3, stat } from "fs/promises";
1878
1951
  import path9 from "path";
1879
1952
  import { RESERVED_ROUTE_CONFIG_EXPORTS } from "akanjs/common";
1880
1953
  import ignore from "ignore";
1881
- import ts19 from "typescript";
1954
+ import ts20 from "typescript";
1882
1955
 
1883
1956
  // pkgs/@akanjs/devkit/commentDensityScanner.ts
1884
1957
  import path6 from "path";
1885
- import ts13 from "typescript";
1958
+ import ts14 from "typescript";
1886
1959
 
1887
1960
  // pkgs/@akanjs/devkit/sourceComments.ts
1888
- import ts12 from "typescript";
1961
+ import ts13 from "typescript";
1889
1962
 
1890
1963
  class SourceComments {
1891
- static #scanner = ts12.createScanner(ts12.ScriptTarget.Latest, false);
1964
+ static #scanner = ts13.createScanner(ts13.ScriptTarget.Latest, false);
1892
1965
  static of(sourceFile) {
1893
1966
  const comments = [];
1894
1967
  const scanGap = (start, end) => {
@@ -1896,22 +1969,22 @@ class SourceComments {
1896
1969
  return;
1897
1970
  const scanner = SourceComments.#scanner;
1898
1971
  scanner.setText(sourceFile.text, start, end - start);
1899
- for (let kind = scanner.scan();kind !== ts12.SyntaxKind.EndOfFileToken; kind = scanner.scan()) {
1900
- if (kind !== ts12.SyntaxKind.SingleLineCommentTrivia && kind !== ts12.SyntaxKind.MultiLineCommentTrivia)
1972
+ for (let kind = scanner.scan();kind !== ts13.SyntaxKind.EndOfFileToken; kind = scanner.scan()) {
1973
+ if (kind !== ts13.SyntaxKind.SingleLineCommentTrivia && kind !== ts13.SyntaxKind.MultiLineCommentTrivia)
1901
1974
  continue;
1902
1975
  comments.push(SourceComments.#commentOf(sourceFile, scanner.getTokenStart(), scanner.getTokenText()));
1903
1976
  }
1904
1977
  scanner.setText(undefined);
1905
1978
  };
1906
1979
  const visit = (node) => {
1907
- if (node.kind === ts12.SyntaxKind.JsxText)
1980
+ if (node.kind === ts13.SyntaxKind.JsxText)
1908
1981
  return;
1909
- if (ts12.isToken(node)) {
1982
+ if (ts13.isToken(node)) {
1910
1983
  scanGap(node.pos, node.getStart(sourceFile));
1911
1984
  return;
1912
1985
  }
1913
1986
  const children = [];
1914
- ts12.forEachChild(node, (child) => {
1987
+ ts13.forEachChild(node, (child) => {
1915
1988
  children.push(child);
1916
1989
  }, (nodes) => {
1917
1990
  children.push(...nodes);
@@ -2014,7 +2087,7 @@ class CommentDensityScanner {
2014
2087
  static #isMeasured({ file, sourceFile }) {
2015
2088
  if (/\.(test|spec)\.tsx?$/.test(file) || path6.basename(file) === "guards.ts")
2016
2089
  return false;
2017
- return !sourceFile.statements.every((statement) => ts13.isExportDeclaration(statement) || ts13.isExpressionStatement(statement) && ts13.isStringLiteral(statement.expression));
2090
+ return !sourceFile.statements.every((statement) => ts14.isExportDeclaration(statement) || ts14.isExpressionStatement(statement) && ts14.isStringLiteral(statement.expression));
2018
2091
  }
2019
2092
  }
2020
2093
 
@@ -2042,7 +2115,7 @@ class DeprecatedCommentScanner {
2042
2115
 
2043
2116
  // pkgs/@akanjs/devkit/formSetterScanner.ts
2044
2117
  import { capitalize, formSetterNames } from "akanjs/common";
2045
- import ts14 from "typescript";
2118
+ import ts15 from "typescript";
2046
2119
 
2047
2120
  class FormSetterScanner {
2048
2121
  static #constantPath = /(?:^|\/)lib\/([^_/][^/]*)\/\1\.constant\.ts$/;
@@ -2061,7 +2134,7 @@ class FormSetterScanner {
2061
2134
  const fullModelClasses = new Set([`${className}Input`, `${className}Object`, `Light${className}`, className]);
2062
2135
  const keys = new Set(FormSetterScanner.#baseFields);
2063
2136
  for (const statement of sourceFile.statements)
2064
- if (ts14.isClassDeclaration(statement) && statement.name && fullModelClasses.has(statement.name.text))
2137
+ if (ts15.isClassDeclaration(statement) && statement.name && fullModelClasses.has(statement.name.text))
2065
2138
  for (const key of FormSetterScanner.#viaFieldKeysOf(statement))
2066
2139
  keys.add(key);
2067
2140
  for (const key of keys)
@@ -2070,33 +2143,33 @@ class FormSetterScanner {
2070
2143
  return setters;
2071
2144
  }
2072
2145
  static #viaFieldKeysOf(declaration) {
2073
- const via = declaration.heritageClauses?.find((clause) => clause.token === ts14.SyntaxKind.ExtendsKeyword)?.types[0]?.expression;
2074
- if (!via || !ts14.isCallExpression(via))
2146
+ const via = declaration.heritageClauses?.find((clause) => clause.token === ts15.SyntaxKind.ExtendsKeyword)?.types[0]?.expression;
2147
+ if (!via || !ts15.isCallExpression(via))
2075
2148
  return [];
2076
2149
  return via.arguments.flatMap((argument) => {
2077
- if (!ts14.isArrowFunction(argument) && !ts14.isFunctionExpression(argument))
2150
+ if (!ts15.isArrowFunction(argument) && !ts15.isFunctionExpression(argument))
2078
2151
  return [];
2079
2152
  const fields = FormSetterScanner.#returnedObjectOf(argument.body);
2080
- return (fields?.properties ?? []).flatMap((property) => property.name && (ts14.isIdentifier(property.name) || ts14.isStringLiteral(property.name)) ? [property.name.text] : []);
2153
+ return (fields?.properties ?? []).flatMap((property) => property.name && (ts15.isIdentifier(property.name) || ts15.isStringLiteral(property.name)) ? [property.name.text] : []);
2081
2154
  });
2082
2155
  }
2083
2156
  static #returnedObjectOf(body) {
2084
2157
  let expression = body;
2085
- if (ts14.isBlock(body))
2086
- expression = body.statements.find(ts14.isReturnStatement)?.expression;
2087
- while (expression && (ts14.isParenthesizedExpression(expression) || ts14.isAsExpression(expression)))
2158
+ if (ts15.isBlock(body))
2159
+ expression = body.statements.find(ts15.isReturnStatement)?.expression;
2160
+ while (expression && (ts15.isParenthesizedExpression(expression) || ts15.isAsExpression(expression)))
2088
2161
  expression = expression.expression;
2089
- return expression && ts14.isObjectLiteralExpression(expression) ? expression : null;
2162
+ return expression && ts15.isObjectLiteralExpression(expression) ? expression : null;
2090
2163
  }
2091
2164
  #scanFile({ file, sourceFile }, fieldSetters) {
2092
2165
  const wrapped = [];
2093
2166
  const visit = (node) => {
2094
- if (ts14.isJsxAttribute(node)) {
2167
+ if (ts15.isJsxAttribute(node)) {
2095
2168
  const setter = FormSetterScanner.#wrappedSetterOf(node, fieldSetters);
2096
2169
  if (setter)
2097
2170
  wrapped.push({ setter, line: FormSetterScanner.#lineOf(sourceFile, node) });
2098
2171
  }
2099
- ts14.forEachChild(node, visit);
2172
+ ts15.forEachChild(node, visit);
2100
2173
  };
2101
2174
  visit(sourceFile);
2102
2175
  if (!wrapped.length)
@@ -2115,13 +2188,13 @@ class FormSetterScanner {
2115
2188
  ];
2116
2189
  }
2117
2190
  static #wrappedSetterOf(attribute, fieldSetters) {
2118
- if (!ts14.isIdentifier(attribute.name) || !/^on[A-Z]/.test(attribute.name.text))
2191
+ if (!ts15.isIdentifier(attribute.name) || !/^on[A-Z]/.test(attribute.name.text))
2119
2192
  return null;
2120
2193
  const initializer = attribute.initializer;
2121
- if (!initializer || !ts14.isJsxExpression(initializer) || !initializer.expression)
2194
+ if (!initializer || !ts15.isJsxExpression(initializer) || !initializer.expression)
2122
2195
  return null;
2123
2196
  const handler = initializer.expression;
2124
- if (!ts14.isArrowFunction(handler) && !ts14.isFunctionExpression(handler))
2197
+ if (!ts15.isArrowFunction(handler) && !ts15.isFunctionExpression(handler))
2125
2198
  return null;
2126
2199
  if (!handler.parameters.length)
2127
2200
  return null;
@@ -2132,14 +2205,14 @@ class FormSetterScanner {
2132
2205
  const visit = (current) => {
2133
2206
  if (found)
2134
2207
  return;
2135
- if (ts14.isCallExpression(current) && ts14.isPropertyAccessExpression(current.expression)) {
2208
+ if (ts15.isCallExpression(current) && ts15.isPropertyAccessExpression(current.expression)) {
2136
2209
  const { expression, name } = current.expression;
2137
- if (ts14.isPropertyAccessExpression(expression) && ts14.isIdentifier(expression.expression) && expression.expression.text === "st" && expression.name.text === "do" && fieldSetters.has(name.text)) {
2210
+ if (ts15.isPropertyAccessExpression(expression) && ts15.isIdentifier(expression.expression) && expression.expression.text === "st" && expression.name.text === "do" && fieldSetters.has(name.text)) {
2138
2211
  found = name.text;
2139
2212
  return;
2140
2213
  }
2141
2214
  }
2142
- ts14.forEachChild(current, visit);
2215
+ ts15.forEachChild(current, visit);
2143
2216
  };
2144
2217
  visit(node);
2145
2218
  return found;
@@ -2151,7 +2224,7 @@ class FormSetterScanner {
2151
2224
 
2152
2225
  // pkgs/@akanjs/devkit/kindBranchScanner.ts
2153
2226
  import path7 from "path";
2154
- import ts15 from "typescript";
2227
+ import ts16 from "typescript";
2155
2228
 
2156
2229
  class KindBranchScanner {
2157
2230
  static rule = "akan.global.kind-branch";
@@ -2159,10 +2232,10 @@ class KindBranchScanner {
2159
2232
  static #kindName = /(Kind|Type|Mode)$/;
2160
2233
  static #kindSubject = /^(kind|type|mode)$|[a-z](Kind|Type|Mode)$/;
2161
2234
  static #equalities = new Set([
2162
- ts15.SyntaxKind.EqualsEqualsEqualsToken,
2163
- ts15.SyntaxKind.ExclamationEqualsEqualsToken,
2164
- ts15.SyntaxKind.EqualsEqualsToken,
2165
- ts15.SyntaxKind.ExclamationEqualsToken
2235
+ ts16.SyntaxKind.EqualsEqualsEqualsToken,
2236
+ ts16.SyntaxKind.ExclamationEqualsEqualsToken,
2237
+ ts16.SyntaxKind.EqualsEqualsToken,
2238
+ ts16.SyntaxKind.ExclamationEqualsToken
2166
2239
  ]);
2167
2240
  scan(sourceFiles) {
2168
2241
  const enums = sourceFiles.flatMap((sourceFile) => KindBranchScanner.#enumsOf(sourceFile));
@@ -2214,7 +2287,7 @@ class KindBranchScanner {
2214
2287
  static #sitesIn({ file, sourceFile }, ownersByValue) {
2215
2288
  const sites = [];
2216
2289
  const record = (literal, subject) => {
2217
- if (!ts15.isStringLiteralLike(literal) || !ownersByValue.has(literal.text))
2290
+ if (!ts16.isStringLiteralLike(literal) || !ownersByValue.has(literal.text))
2218
2291
  return;
2219
2292
  if (!KindBranchScanner.#isKindSubject(subject))
2220
2293
  return;
@@ -2225,28 +2298,28 @@ class KindBranchScanner {
2225
2298
  });
2226
2299
  };
2227
2300
  const visit = (node) => {
2228
- if (ts15.isBinaryExpression(node) && KindBranchScanner.#equalities.has(node.operatorToken.kind)) {
2301
+ if (ts16.isBinaryExpression(node) && KindBranchScanner.#equalities.has(node.operatorToken.kind)) {
2229
2302
  record(node.left, node.right);
2230
2303
  record(node.right, node.left);
2231
- } else if (ts15.isCaseClause(node) && ts15.isSwitchStatement(node.parent.parent))
2304
+ } else if (ts16.isCaseClause(node) && ts16.isSwitchStatement(node.parent.parent))
2232
2305
  record(node.expression, node.parent.parent.expression);
2233
- ts15.forEachChild(node, visit);
2306
+ ts16.forEachChild(node, visit);
2234
2307
  };
2235
2308
  visit(sourceFile);
2236
2309
  return sites;
2237
2310
  }
2238
2311
  static #isKindSubject(subject) {
2239
2312
  let current = subject;
2240
- while (ts15.isParenthesizedExpression(current) || ts15.isAsExpression(current) || ts15.isNonNullExpression(current))
2313
+ while (ts16.isParenthesizedExpression(current) || ts16.isAsExpression(current) || ts16.isNonNullExpression(current))
2241
2314
  current = current.expression;
2242
- const name = ts15.isIdentifier(current) ? current.text : ts15.isPropertyAccessExpression(current) ? current.name.text : ts15.isElementAccessExpression(current) && ts15.isStringLiteralLike(current.argumentExpression) ? current.argumentExpression.text : "";
2315
+ const name = ts16.isIdentifier(current) ? current.text : ts16.isPropertyAccessExpression(current) ? current.name.text : ts16.isElementAccessExpression(current) && ts16.isStringLiteralLike(current.argumentExpression) ? current.argumentExpression.text : "";
2243
2316
  return KindBranchScanner.#kindSubject.test(name);
2244
2317
  }
2245
2318
  static #enumsOf({ file, sourceFile }) {
2246
2319
  if (!/^(apps|libs)\/[^/]+\/lib\/.+\.constant\.ts$/.test(file))
2247
2320
  return [];
2248
2321
  return sourceFile.statements.flatMap((statement) => {
2249
- if (!ts15.isClassDeclaration(statement) || !statement.name)
2322
+ if (!ts16.isClassDeclaration(statement) || !statement.name)
2250
2323
  return [];
2251
2324
  if (!KindBranchScanner.#kindName.test(statement.name.text))
2252
2325
  return [];
@@ -2271,16 +2344,16 @@ class KindBranchScanner {
2271
2344
  static #enumValuesOf(statement) {
2272
2345
  for (const clause of statement.heritageClauses ?? [])
2273
2346
  for (const { expression } of clause.types) {
2274
- if (!ts15.isCallExpression(expression) || !ts15.isIdentifier(expression.expression))
2347
+ if (!ts16.isCallExpression(expression) || !ts16.isIdentifier(expression.expression))
2275
2348
  continue;
2276
2349
  if (expression.expression.text !== "enumOf")
2277
2350
  continue;
2278
2351
  let list = expression.arguments[1];
2279
- while (list && (ts15.isAsExpression(list) || ts15.isParenthesizedExpression(list)))
2352
+ while (list && (ts16.isAsExpression(list) || ts16.isParenthesizedExpression(list)))
2280
2353
  list = list.expression;
2281
- if (!list || !ts15.isArrayLiteralExpression(list))
2354
+ if (!list || !ts16.isArrayLiteralExpression(list))
2282
2355
  return null;
2283
- return list.elements.filter(ts15.isStringLiteralLike).map(({ text }) => text);
2356
+ return list.elements.filter(ts16.isStringLiteralLike).map(({ text }) => text);
2284
2357
  }
2285
2358
  return null;
2286
2359
  }
@@ -2295,16 +2368,19 @@ class MaintainabilityExceptionScanner {
2295
2368
  static #shapeFix = "Many reasoned exceptions under one rule mean its threshold is wrong: fix the limit in MaintainabilityLimits rather than record another. Otherwise shrink the code, and `akan lint` lowers each entry and drops it once it passes.";
2296
2369
  static #correctnessFix = "A write rule takes no exception: send the writes through one store action and one endpoint (`akan workflow plan add-mutation`), and `akan lint` drops the entry.";
2297
2370
  async scan(workspaceRoot) {
2298
- const sysPaths = await Promise.all(["apps", "libs"].map(async (sysRoot) => {
2299
- const absoluteRoot = path8.join(workspaceRoot, sysRoot);
2300
- if (!existsSync2(absoluteRoot))
2301
- return [];
2302
- const entries = await readdir(absoluteRoot, { withFileTypes: true });
2303
- return entries.filter((entry) => entry.isDirectory()).map((entry) => `${sysRoot}/${entry.name}`);
2304
- }));
2371
+ const sysPaths = await Promise.all(["apps", "libs", "pkgs"].map((sysRoot) => MaintainabilityExceptionScanner.#dirsIn(workspaceRoot, sysRoot)));
2305
2372
  const warnings = await Promise.all(sysPaths.flat().map((sysPath) => MaintainabilityExceptionScanner.#scanSys(workspaceRoot, sysPath)));
2306
2373
  return warnings.flat();
2307
2374
  }
2375
+ static async#dirsIn(workspaceRoot, root) {
2376
+ const absoluteRoot = path8.join(workspaceRoot, root);
2377
+ if (!existsSync2(absoluteRoot))
2378
+ return [];
2379
+ const entries = await readdir(absoluteRoot, { withFileTypes: true });
2380
+ const dirs = entries.filter((entry) => entry.isDirectory()).map((entry) => `${root}/${entry.name}`);
2381
+ const nested = await Promise.all(dirs.map(async (dir) => root === "pkgs" && path8.posix.basename(dir).startsWith("@") ? await MaintainabilityExceptionScanner.#dirsIn(workspaceRoot, dir) : [dir]));
2382
+ return nested.flat();
2383
+ }
2308
2384
  static async#scanSys(workspaceRoot, sysPath) {
2309
2385
  const file = `${sysPath}/${MaintainabilityBaseline.fileName}`;
2310
2386
  const absolutePath = path8.join(workspaceRoot, file);
@@ -2346,10 +2422,10 @@ class MaintainabilityExceptionScanner {
2346
2422
  }
2347
2423
 
2348
2424
  // pkgs/@akanjs/devkit/ssrScanner.ts
2349
- import ts17 from "typescript";
2425
+ import ts18 from "typescript";
2350
2426
 
2351
2427
  // pkgs/@akanjs/devkit/renderMutationScanner.ts
2352
- import ts16 from "typescript";
2428
+ import ts17 from "typescript";
2353
2429
 
2354
2430
  class RenderMutationScanner {
2355
2431
  static rule = "akan.ssr.render-mutation";
@@ -2378,7 +2454,7 @@ class RenderMutationScanner {
2378
2454
  const helper = follow ? RenderMutationScanner.#helperOf(node, functions) : undefined;
2379
2455
  if (helper)
2380
2456
  helpers.add(helper);
2381
- ts16.forEachChild(node, (child) => visit(child, follow));
2457
+ ts17.forEachChild(node, (child) => visit(child, follow));
2382
2458
  };
2383
2459
  for (const body of RenderMutationScanner.#renderBodiesOf(sourceFile, functions))
2384
2460
  visit(body, true);
@@ -2395,7 +2471,7 @@ class RenderMutationScanner {
2395
2471
  }));
2396
2472
  }
2397
2473
  #isRenderMutation(file, node, fetchNames) {
2398
- if (!ts16.isCallExpression(node))
2474
+ if (!ts17.isCallExpression(node))
2399
2475
  return false;
2400
2476
  const name = RenderMutationScanner.#endpointOf(node.expression, fetchNames);
2401
2477
  if (!name || !this.#mutations.isMutation(file, name))
@@ -2403,64 +2479,64 @@ class RenderMutationScanner {
2403
2479
  return !RenderMutationScanner.#optsIn(node, this.#mutations.policyIndexOf(file, name));
2404
2480
  }
2405
2481
  static #isEventHandler(node) {
2406
- return ts16.isJsxAttribute(node) && ts16.isIdentifier(node.name) && /^on[A-Z]/.test(node.name.text);
2482
+ return ts17.isJsxAttribute(node) && ts17.isIdentifier(node.name) && /^on[A-Z]/.test(node.name.text);
2407
2483
  }
2408
2484
  static #endpointOf(callee, fetchNames) {
2409
- if (ts16.isPropertyAccessExpression(callee))
2485
+ if (ts17.isPropertyAccessExpression(callee))
2410
2486
  return RenderMutationScanner.#isFetch(callee.expression, fetchNames) ? callee.name.text : null;
2411
- if (ts16.isElementAccessExpression(callee) && ts16.isStringLiteralLike(callee.argumentExpression))
2487
+ if (ts17.isElementAccessExpression(callee) && ts17.isStringLiteralLike(callee.argumentExpression))
2412
2488
  return RenderMutationScanner.#isFetch(callee.expression, fetchNames) ? callee.argumentExpression.text : null;
2413
2489
  return null;
2414
2490
  }
2415
2491
  static #isFetch(expression, fetchNames) {
2416
- return ts16.isIdentifier(expression) && fetchNames.has(expression.text);
2492
+ return ts17.isIdentifier(expression) && fetchNames.has(expression.text);
2417
2493
  }
2418
2494
  static #optsIn(call, policyIndex) {
2419
2495
  if (policyIndex === null)
2420
2496
  return false;
2421
2497
  const leading = call.arguments.slice(0, policyIndex + 1);
2422
- if (leading.some((argument) => ts16.isSpreadElement(argument)))
2498
+ if (leading.some((argument) => ts17.isSpreadElement(argument)))
2423
2499
  return true;
2424
2500
  const policy = leading[policyIndex];
2425
2501
  return policy ? RenderMutationScanner.#policyOptsIn(policy) : false;
2426
2502
  }
2427
2503
  static #policyOptsIn(argument) {
2428
2504
  const policy = RenderMutationScanner.#unwrap(argument);
2429
- if (!ts16.isObjectLiteralExpression(policy))
2505
+ if (!ts17.isObjectLiteralExpression(policy))
2430
2506
  return !RenderMutationScanner.#cannotBePolicy(policy);
2431
2507
  return policy.properties.some((property) => {
2432
- if (ts16.isSpreadAssignment(property))
2508
+ if (ts17.isSpreadAssignment(property))
2433
2509
  return true;
2434
- if (!ts16.isPropertyAssignment(property) && !ts16.isShorthandPropertyAssignment(property))
2510
+ if (!ts17.isPropertyAssignment(property) && !ts17.isShorthandPropertyAssignment(property))
2435
2511
  return false;
2436
- if (!(ts16.isIdentifier(property.name) || ts16.isStringLiteral(property.name)))
2512
+ if (!(ts17.isIdentifier(property.name) || ts17.isStringLiteral(property.name)))
2437
2513
  return false;
2438
2514
  if (property.name.text !== "duringRender")
2439
2515
  return false;
2440
- if (ts16.isShorthandPropertyAssignment(property))
2516
+ if (ts17.isShorthandPropertyAssignment(property))
2441
2517
  return true;
2442
2518
  const value = RenderMutationScanner.#unwrap(property.initializer);
2443
- return value.kind !== ts16.SyntaxKind.FalseKeyword && !(ts16.isIdentifier(value) && value.text === "undefined");
2519
+ return value.kind !== ts17.SyntaxKind.FalseKeyword && !(ts17.isIdentifier(value) && value.text === "undefined");
2444
2520
  });
2445
2521
  }
2446
2522
  static #unwrap(expression) {
2447
2523
  let current = expression;
2448
- while (ts16.isParenthesizedExpression(current) || ts16.isAsExpression(current) || ts16.isSatisfiesExpression(current) || ts16.isNonNullExpression(current) || ts16.isTypeAssertionExpression(current))
2524
+ while (ts17.isParenthesizedExpression(current) || ts17.isAsExpression(current) || ts17.isSatisfiesExpression(current) || ts17.isNonNullExpression(current) || ts17.isTypeAssertionExpression(current))
2449
2525
  current = current.expression;
2450
2526
  return current;
2451
2527
  }
2452
2528
  static #cannotBePolicy(expression) {
2453
- if (ts16.isIdentifier(expression))
2529
+ if (ts17.isIdentifier(expression))
2454
2530
  return expression.text === "undefined";
2455
- return ts16.isLiteralExpression(expression) || ts16.isNoSubstitutionTemplateLiteral(expression) || ts16.isTemplateExpression(expression) || ts16.isArrayLiteralExpression(expression) || ts16.isArrowFunction(expression) || ts16.isFunctionExpression(expression) || ts16.isVoidExpression(expression) || ts16.isPrefixUnaryExpression(expression) || [ts16.SyntaxKind.NullKeyword, ts16.SyntaxKind.TrueKeyword, ts16.SyntaxKind.FalseKeyword].includes(expression.kind);
2531
+ return ts17.isLiteralExpression(expression) || ts17.isNoSubstitutionTemplateLiteral(expression) || ts17.isTemplateExpression(expression) || ts17.isArrayLiteralExpression(expression) || ts17.isArrowFunction(expression) || ts17.isFunctionExpression(expression) || ts17.isVoidExpression(expression) || ts17.isPrefixUnaryExpression(expression) || [ts17.SyntaxKind.NullKeyword, ts17.SyntaxKind.TrueKeyword, ts17.SyntaxKind.FalseKeyword].includes(expression.kind);
2456
2532
  }
2457
2533
  static #fetchBindingsOf(sourceFile) {
2458
2534
  const names = new Set;
2459
2535
  for (const statement of sourceFile.statements) {
2460
- if (!ts16.isImportDeclaration(statement) || statement.importClause?.isTypeOnly)
2536
+ if (!ts17.isImportDeclaration(statement) || statement.importClause?.isTypeOnly)
2461
2537
  continue;
2462
2538
  const bindings = statement.importClause?.namedBindings;
2463
- if (!bindings || !ts16.isNamedImports(bindings))
2539
+ if (!bindings || !ts17.isNamedImports(bindings))
2464
2540
  continue;
2465
2541
  for (const element of bindings.elements)
2466
2542
  if (!element.isTypeOnly && (element.propertyName ?? element.name).text === "fetch")
@@ -2471,35 +2547,35 @@ class RenderMutationScanner {
2471
2547
  static #functionsOf(sourceFile) {
2472
2548
  const functions = new Map;
2473
2549
  for (const statement of sourceFile.statements) {
2474
- if (ts16.isFunctionDeclaration(statement) && statement.name && statement.body)
2550
+ if (ts17.isFunctionDeclaration(statement) && statement.name && statement.body)
2475
2551
  functions.set(statement.name.text, statement.body);
2476
- if (!ts16.isVariableStatement(statement))
2552
+ if (!ts17.isVariableStatement(statement))
2477
2553
  continue;
2478
2554
  for (const declaration of statement.declarationList.declarations) {
2479
2555
  const initializer = declaration.initializer && RenderMutationScanner.#unwrap(declaration.initializer);
2480
- if (!ts16.isIdentifier(declaration.name) || !initializer)
2556
+ if (!ts17.isIdentifier(declaration.name) || !initializer)
2481
2557
  continue;
2482
- if (ts16.isArrowFunction(initializer) || ts16.isFunctionExpression(initializer))
2558
+ if (ts17.isArrowFunction(initializer) || ts17.isFunctionExpression(initializer))
2483
2559
  functions.set(declaration.name.text, initializer.body);
2484
2560
  }
2485
2561
  }
2486
2562
  return functions;
2487
2563
  }
2488
2564
  static #helperOf(node, functions) {
2489
- const callee = ts16.isCallExpression(node) ? node.expression : ts16.isJsxSelfClosingElement(node) || ts16.isJsxOpeningElement(node) ? node.tagName : undefined;
2490
- return callee && ts16.isIdentifier(callee) ? functions.get(callee.text) : undefined;
2565
+ const callee = ts17.isCallExpression(node) ? node.expression : ts17.isJsxSelfClosingElement(node) || ts17.isJsxOpeningElement(node) ? node.tagName : undefined;
2566
+ return callee && ts17.isIdentifier(callee) ? functions.get(callee.text) : undefined;
2491
2567
  }
2492
2568
  static #renderBodiesOf(sourceFile, functions) {
2493
2569
  const bodies = [];
2494
- const bodyOf = (node) => ts16.isIdentifier(node) ? functions.get(node.text) : node;
2570
+ const bodyOf = (node) => ts17.isIdentifier(node) ? functions.get(node.text) : node;
2495
2571
  const visit = (node) => {
2496
- if (ts16.isCallExpression(node) && ts16.isPropertyAccessExpression(node.expression) && RenderMutationScanner.#stages.has(node.expression.name.text) && RenderMutationScanner.#isRouteChain(node.expression.expression))
2572
+ if (ts17.isCallExpression(node) && ts17.isPropertyAccessExpression(node.expression) && RenderMutationScanner.#stages.has(node.expression.name.text) && RenderMutationScanner.#isRouteChain(node.expression.expression))
2497
2573
  for (const argument of node.arguments) {
2498
2574
  const body = bodyOf(argument);
2499
2575
  if (body)
2500
2576
  bodies.push(body);
2501
2577
  }
2502
- ts16.forEachChild(node, visit);
2578
+ ts17.forEachChild(node, visit);
2503
2579
  };
2504
2580
  visit(sourceFile);
2505
2581
  for (const statement of sourceFile.statements) {
@@ -2511,24 +2587,24 @@ class RenderMutationScanner {
2511
2587
  }
2512
2588
  static #isRouteChain(expression) {
2513
2589
  let current = expression;
2514
- while (ts16.isCallExpression(current)) {
2515
- if (ts16.isIdentifier(current.expression))
2590
+ while (ts17.isCallExpression(current)) {
2591
+ if (ts17.isIdentifier(current.expression))
2516
2592
  return RenderMutationScanner.#builders.has(current.expression.text);
2517
- if (!ts16.isPropertyAccessExpression(current.expression))
2593
+ if (!ts17.isPropertyAccessExpression(current.expression))
2518
2594
  return false;
2519
2595
  current = current.expression.expression;
2520
2596
  }
2521
2597
  return false;
2522
2598
  }
2523
2599
  static #legacyPageOf(statement, functions) {
2524
- if (ts16.isFunctionDeclaration(statement))
2525
- return statement.modifiers?.some((modifier) => modifier.kind === ts16.SyntaxKind.DefaultKeyword) ? statement.body : undefined;
2526
- if (!ts16.isExportAssignment(statement))
2600
+ if (ts17.isFunctionDeclaration(statement))
2601
+ return statement.modifiers?.some((modifier) => modifier.kind === ts17.SyntaxKind.DefaultKeyword) ? statement.body : undefined;
2602
+ if (!ts17.isExportAssignment(statement))
2527
2603
  return;
2528
2604
  const expression = RenderMutationScanner.#unwrap(statement.expression);
2529
- if (ts16.isIdentifier(expression))
2605
+ if (ts17.isIdentifier(expression))
2530
2606
  return functions.get(expression.text);
2531
- return ts16.isArrowFunction(expression) || ts16.isFunctionExpression(expression) ? expression.body : undefined;
2607
+ return ts17.isArrowFunction(expression) || ts17.isFunctionExpression(expression) ? expression.body : undefined;
2532
2608
  }
2533
2609
  }
2534
2610
 
@@ -2613,18 +2689,18 @@ class SsrScanner {
2613
2689
  return warnings;
2614
2690
  }
2615
2691
  #isMountEffect(sourceFile, node) {
2616
- if (!ts17.isCallExpression(node))
2692
+ if (!ts18.isCallExpression(node))
2617
2693
  return false;
2618
2694
  const callee = node.expression.getText(sourceFile);
2619
2695
  if (callee !== "useEffect" && callee !== "useLayoutEffect")
2620
2696
  return false;
2621
2697
  const deps = node.arguments[1];
2622
- return !!deps && ts17.isArrayLiteralExpression(deps) && deps.elements.length === 0;
2698
+ return !!deps && ts18.isArrayLiteralExpression(deps) && deps.elements.length === 0;
2623
2699
  }
2624
2700
  #getLoadCalls(sourceFile, node) {
2625
2701
  const calls = [];
2626
2702
  SsrScanner.#walk(node, (child) => {
2627
- if (!ts17.isCallExpression(child))
2703
+ if (!ts18.isCallExpression(child))
2628
2704
  return;
2629
2705
  const callee = child.expression.getText(sourceFile);
2630
2706
  if (/^fetch\.[a-z]/.test(callee) || /^st\.do\.(init|get|view|load|list|count|insight)[A-Z]/.test(callee))
@@ -2637,7 +2713,7 @@ class SsrScanner {
2637
2713
  return [];
2638
2714
  const warnings = [];
2639
2715
  SsrScanner.#walk(sourceFile.sourceFile, (node) => {
2640
- if (ts17.isCallExpression(node) && node.expression.getText(sourceFile.sourceFile) === "useState")
2716
+ if (ts18.isCallExpression(node) && node.expression.getText(sourceFile.sourceFile) === "useState")
2641
2717
  warnings.push(fileWarning("akan.ssr.template-client-state", "ssr", sourceFile.file, "Template holds form state in useState. Templates are store-driven and carry no local state.", this.#getLine(sourceFile.sourceFile, node)));
2642
2718
  });
2643
2719
  return warnings;
@@ -2680,14 +2756,14 @@ class SsrScanner {
2680
2756
  return components;
2681
2757
  }
2682
2758
  #getComponentNodes(statement) {
2683
- if (ts17.isFunctionDeclaration(statement) && statement.body)
2759
+ if (ts18.isFunctionDeclaration(statement) && statement.body)
2684
2760
  return [{ name: statement.name?.text ?? "default", node: statement.body }];
2685
- if (!ts17.isVariableStatement(statement))
2761
+ if (!ts18.isVariableStatement(statement))
2686
2762
  return [];
2687
2763
  return statement.declarationList.declarations.flatMap((declaration) => {
2688
- if (!ts17.isIdentifier(declaration.name) || !declaration.initializer)
2764
+ if (!ts18.isIdentifier(declaration.name) || !declaration.initializer)
2689
2765
  return [];
2690
- if (!ts17.isArrowFunction(declaration.initializer) && !ts17.isFunctionExpression(declaration.initializer))
2766
+ if (!ts18.isArrowFunction(declaration.initializer) && !ts18.isFunctionExpression(declaration.initializer))
2691
2767
  return [];
2692
2768
  return [{ name: declaration.name.text, node: declaration.initializer }];
2693
2769
  });
@@ -2695,7 +2771,7 @@ class SsrScanner {
2695
2771
  #getTouches(sourceFile, node) {
2696
2772
  const touches = [];
2697
2773
  SsrScanner.#walk(node, (child) => {
2698
- if (ts17.isCallExpression(child)) {
2774
+ if (ts18.isCallExpression(child)) {
2699
2775
  const callee = child.expression.getText(sourceFile);
2700
2776
  const bareName = callee.split(".").pop() ?? callee;
2701
2777
  if (callee === "createContext" || callee === "lazy")
@@ -2703,9 +2779,9 @@ class SsrScanner {
2703
2779
  else if (/^use[A-Z]/.test(bareName) && !SsrScanner.#serverSafeCalls.has(bareName))
2704
2780
  touches.push(bareName);
2705
2781
  }
2706
- if (ts17.isJsxAttribute(child) && /^on[A-Z]/.test(child.name.getText(sourceFile)))
2782
+ if (ts18.isJsxAttribute(child) && /^on[A-Z]/.test(child.name.getText(sourceFile)))
2707
2783
  touches.push(child.name.getText(sourceFile));
2708
- if (ts17.isPropertyAccessExpression(child)) {
2784
+ if (ts18.isPropertyAccessExpression(child)) {
2709
2785
  const root = getAccessRoot(child);
2710
2786
  if (root === "st")
2711
2787
  touches.push("st");
@@ -2718,7 +2794,7 @@ class SsrScanner {
2718
2794
  #getTagNames(sourceFile, node) {
2719
2795
  const tags = new Set;
2720
2796
  SsrScanner.#walk(node, (child) => {
2721
- if (ts17.isJsxOpeningElement(child) || ts17.isJsxSelfClosingElement(child))
2797
+ if (ts18.isJsxOpeningElement(child) || ts18.isJsxSelfClosingElement(child))
2722
2798
  tags.add(child.tagName.getText(sourceFile).split(".")[0]);
2723
2799
  });
2724
2800
  return tags;
@@ -2726,7 +2802,7 @@ class SsrScanner {
2726
2802
  #getMass(node) {
2727
2803
  let mass = 0;
2728
2804
  SsrScanner.#walk(node, (child) => {
2729
- if (ts17.isJsxOpeningElement(child) || ts17.isJsxSelfClosingElement(child))
2805
+ if (ts18.isJsxOpeningElement(child) || ts18.isJsxSelfClosingElement(child))
2730
2806
  mass += 1;
2731
2807
  });
2732
2808
  return mass;
@@ -2734,30 +2810,30 @@ class SsrScanner {
2734
2810
  static #walk(node, visit) {
2735
2811
  const walk = (child) => {
2736
2812
  visit(child);
2737
- ts17.forEachChild(child, walk);
2813
+ ts18.forEachChild(child, walk);
2738
2814
  };
2739
- ts17.forEachChild(node, walk);
2815
+ ts18.forEachChild(node, walk);
2740
2816
  }
2741
2817
  #hasUseClient(sourceFile) {
2742
2818
  const first = sourceFile.statements[0];
2743
- if (!first || !ts17.isExpressionStatement(first) || !ts17.isStringLiteral(first.expression))
2819
+ if (!first || !ts18.isExpressionStatement(first) || !ts18.isStringLiteral(first.expression))
2744
2820
  return false;
2745
2821
  return first.expression.text === "use client";
2746
2822
  }
2747
2823
  #hasVendorImport(sourceFile) {
2748
- return sourceFile.statements.some((statement) => ts17.isImportDeclaration(statement) && isVendorSpecifier(getSpecifier(statement)));
2824
+ return sourceFile.statements.some((statement) => ts18.isImportDeclaration(statement) && isVendorSpecifier(getSpecifier(statement)));
2749
2825
  }
2750
2826
  #getVendorNames(sourceFile) {
2751
2827
  const names = new Set;
2752
2828
  for (const statement of sourceFile.statements) {
2753
- if (!ts17.isImportDeclaration(statement) || !isVendorSpecifier(getSpecifier(statement)))
2829
+ if (!ts18.isImportDeclaration(statement) || !isVendorSpecifier(getSpecifier(statement)))
2754
2830
  continue;
2755
2831
  const clause = statement.importClause;
2756
2832
  if (clause?.name)
2757
2833
  names.add(clause.name.text);
2758
- if (clause?.namedBindings && ts17.isNamespaceImport(clause.namedBindings))
2834
+ if (clause?.namedBindings && ts18.isNamespaceImport(clause.namedBindings))
2759
2835
  names.add(clause.namedBindings.name.text);
2760
- if (clause?.namedBindings && ts17.isNamedImports(clause.namedBindings))
2836
+ if (clause?.namedBindings && ts18.isNamedImports(clause.namedBindings))
2761
2837
  for (const element of clause.namedBindings.elements)
2762
2838
  names.add(element.name.text);
2763
2839
  }
@@ -2765,10 +2841,10 @@ class SsrScanner {
2765
2841
  }
2766
2842
  #importsClientRuntime(sourceFile) {
2767
2843
  for (const statement of sourceFile.statements) {
2768
- if (!ts17.isImportDeclaration(statement))
2844
+ if (!ts18.isImportDeclaration(statement))
2769
2845
  continue;
2770
2846
  const bindings = statement.importClause?.namedBindings;
2771
- if (!bindings || !ts17.isNamedImports(bindings))
2847
+ if (!bindings || !ts18.isNamedImports(bindings))
2772
2848
  continue;
2773
2849
  if (bindings.elements.some((element) => SsrScanner.#clientRuntimeImports.has(element.name.text)))
2774
2850
  return true;
@@ -2819,7 +2895,7 @@ function getShare(serverMass, clientMass) {
2819
2895
  return total === 0 ? 1 : serverMass / total;
2820
2896
  }
2821
2897
  function getSpecifier(statement) {
2822
- return ts17.isStringLiteral(statement.moduleSpecifier) ? statement.moduleSpecifier.text : "";
2898
+ return ts18.isStringLiteral(statement.moduleSpecifier) ? statement.moduleSpecifier.text : "";
2823
2899
  }
2824
2900
  function isVendorSpecifier(specifier) {
2825
2901
  if (specifier === "" || specifier.startsWith(".") || specifier.startsWith("/"))
@@ -2832,13 +2908,13 @@ function isVendorSpecifier(specifier) {
2832
2908
  }
2833
2909
  function getAccessRoot(node) {
2834
2910
  let current = node;
2835
- while (ts17.isPropertyAccessExpression(current))
2911
+ while (ts18.isPropertyAccessExpression(current))
2836
2912
  current = current.expression;
2837
- return ts17.isIdentifier(current) ? current.text : "";
2913
+ return ts18.isIdentifier(current) ? current.text : "";
2838
2914
  }
2839
2915
 
2840
2916
  // pkgs/@akanjs/devkit/testOnlyExportScanner.ts
2841
- import ts18 from "typescript";
2917
+ import ts19 from "typescript";
2842
2918
 
2843
2919
  class TestOnlyExportScanner {
2844
2920
  static rule = "akan.global.test-only-export";
@@ -2889,9 +2965,9 @@ class TestOnlyExportScanner {
2889
2965
  static #identifierLinesOf(sourceFile) {
2890
2966
  const lines = new Map;
2891
2967
  const visit = (node) => {
2892
- if (ts18.isIdentifier(node) && !lines.has(node.text))
2968
+ if (ts19.isIdentifier(node) && !lines.has(node.text))
2893
2969
  lines.set(node.text, sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1);
2894
- ts18.forEachChild(node, visit);
2970
+ ts19.forEachChild(node, visit);
2895
2971
  };
2896
2972
  visit(sourceFile);
2897
2973
  return lines;
@@ -2908,15 +2984,15 @@ class TestOnlyExportScanner {
2908
2984
  });
2909
2985
  }
2910
2986
  static #isNamedExport(statement) {
2911
- if (!ts18.canHaveModifiers(statement))
2987
+ if (!ts19.canHaveModifiers(statement))
2912
2988
  return false;
2913
- const modifiers = ts18.getModifiers(statement) ?? [];
2914
- return modifiers.some((modifier) => modifier.kind === ts18.SyntaxKind.ExportKeyword) && !modifiers.some((modifier) => modifier.kind === ts18.SyntaxKind.DefaultKeyword);
2989
+ const modifiers = ts19.getModifiers(statement) ?? [];
2990
+ return modifiers.some((modifier) => modifier.kind === ts19.SyntaxKind.ExportKeyword) && !modifiers.some((modifier) => modifier.kind === ts19.SyntaxKind.DefaultKeyword);
2915
2991
  }
2916
2992
  static #declaredNamesOf(statement) {
2917
- if (ts18.isVariableStatement(statement))
2918
- return statement.declarationList.declarations.map((declaration) => declaration.name).filter((name) => ts18.isIdentifier(name));
2919
- if (ts18.isFunctionDeclaration(statement) || ts18.isClassDeclaration(statement) || ts18.isInterfaceDeclaration(statement) || ts18.isTypeAliasDeclaration(statement) || ts18.isEnumDeclaration(statement))
2993
+ if (ts19.isVariableStatement(statement))
2994
+ return statement.declarationList.declarations.map((declaration) => declaration.name).filter((name) => ts19.isIdentifier(name));
2995
+ if (ts19.isFunctionDeclaration(statement) || ts19.isClassDeclaration(statement) || ts19.isInterfaceDeclaration(statement) || ts19.isTypeAliasDeclaration(statement) || ts19.isEnumDeclaration(statement))
2920
2996
  return statement.name ? [statement.name] : [];
2921
2997
  return [];
2922
2998
  }
@@ -2926,10 +3002,10 @@ class TestOnlyExportScanner {
2926
3002
  const visit = (node) => {
2927
3003
  if (used || ownStatements.has(node))
2928
3004
  return;
2929
- if (ts18.isIdentifier(node) && node.text === name)
3005
+ if (ts19.isIdentifier(node) && node.text === name)
2930
3006
  used = true;
2931
3007
  else
2932
- ts18.forEachChild(node, visit);
3008
+ ts19.forEachChild(node, visit);
2933
3009
  };
2934
3010
  visit(sourceFile);
2935
3011
  return used;
@@ -3077,7 +3153,7 @@ class AkanQualityScanner {
3077
3153
  file,
3078
3154
  absolutePath,
3079
3155
  content,
3080
- sourceFile: ts19.createSourceFile(file, content, ts19.ScriptTarget.Latest, true, getScriptKind(file))
3156
+ sourceFile: ts20.createSourceFile(file, content, ts20.ScriptTarget.Latest, true, getScriptKind(file))
3081
3157
  };
3082
3158
  }
3083
3159
  async#readTextFile(workspaceRoot, file) {
@@ -3276,13 +3352,13 @@ function getExportedFunctionLikes(sourceFile) {
3276
3352
  duplicateNameExempt: nameExempt || isConventionDuplicateNameExempt(sourceFile.file, isEnumClass)
3277
3353
  });
3278
3354
  for (const statement of sourceFile.sourceFile.statements) {
3279
- if (ts19.isFunctionDeclaration(statement) && statement.name && isExported(statement))
3355
+ if (ts20.isFunctionDeclaration(statement) && statement.name && isExported(statement))
3280
3356
  add(statement.name.text, "function", statement, statement.body);
3281
- if (ts19.isClassDeclaration(statement) && statement.name && isExported(statement))
3357
+ if (ts20.isClassDeclaration(statement) && statement.name && isExported(statement))
3282
3358
  add(statement.name.text, "class", statement, statement, isEnumClassStatement(sourceFile.sourceFile, statement));
3283
- if (ts19.isVariableStatement(statement) && isExported(statement)) {
3359
+ if (ts20.isVariableStatement(statement) && isExported(statement)) {
3284
3360
  for (const declaration of statement.declarationList.declarations) {
3285
- if (!ts19.isIdentifier(declaration.name) || !isFunctionLikeInitializer(declaration.initializer))
3361
+ if (!ts20.isIdentifier(declaration.name) || !isFunctionLikeInitializer(declaration.initializer))
3286
3362
  continue;
3287
3363
  add(declaration.name.text, "function-variable", declaration, declaration.initializer);
3288
3364
  }
@@ -3310,14 +3386,14 @@ function isConventionDuplicateNameExempt(file, isEnumClass) {
3310
3386
  return false;
3311
3387
  }
3312
3388
  function isEnumClassStatement(sourceFile, statement) {
3313
- if (!ts19.isClassDeclaration(statement))
3389
+ if (!ts20.isClassDeclaration(statement))
3314
3390
  return false;
3315
- const heritageClause = statement.heritageClauses?.find((clause) => clause.token === ts19.SyntaxKind.ExtendsKeyword);
3391
+ const heritageClause = statement.heritageClauses?.find((clause) => clause.token === ts20.SyntaxKind.ExtendsKeyword);
3316
3392
  const expression = heritageClause?.types[0]?.expression;
3317
3393
  return !!expression && expression.getText(sourceFile).startsWith("enumOf(");
3318
3394
  }
3319
3395
  function getExportedClassNames(sourceFile) {
3320
- return sourceFile.statements.filter((statement) => ts19.isClassDeclaration(statement)).filter((statement) => isExported(statement)).map((statement) => statement.name?.text).filter((name) => !!name);
3396
+ return sourceFile.statements.filter((statement) => ts20.isClassDeclaration(statement)).filter((statement) => isExported(statement)).map((statement) => statement.name?.text).filter((name) => !!name);
3321
3397
  }
3322
3398
  function isComponentDeclarationFile(file) {
3323
3399
  if (!file.endsWith(".tsx"))
@@ -3333,7 +3409,7 @@ function isComponentDeclarationFile(file) {
3333
3409
  function getComponentFileDeclarations(sourceFile) {
3334
3410
  const reExportedNames = new Set;
3335
3411
  for (const statement of sourceFile.statements) {
3336
- if (ts19.isExportDeclaration(statement) && statement.exportClause && ts19.isNamedExports(statement.exportClause)) {
3412
+ if (ts20.isExportDeclaration(statement) && statement.exportClause && ts20.isNamedExports(statement.exportClause)) {
3337
3413
  for (const element of statement.exportClause.elements)
3338
3414
  reExportedNames.add((element.propertyName ?? element.name).text);
3339
3415
  }
@@ -3343,19 +3419,19 @@ function getComponentFileDeclarations(sourceFile) {
3343
3419
  const isDefaultExport = isDefaultExportStatement(statement);
3344
3420
  const inlineExported = isExported(statement);
3345
3421
  const add = (name, kind, line) => declarations.push({ name, kind, line, exported: inlineExported || reExportedNames.has(name), isDefaultExport });
3346
- if (ts19.isInterfaceDeclaration(statement))
3422
+ if (ts20.isInterfaceDeclaration(statement))
3347
3423
  add(statement.name.text, "interface", getLine(sourceFile, statement));
3348
- else if (ts19.isTypeAliasDeclaration(statement))
3424
+ else if (ts20.isTypeAliasDeclaration(statement))
3349
3425
  add(statement.name.text, "type", getLine(sourceFile, statement));
3350
- else if (ts19.isEnumDeclaration(statement))
3426
+ else if (ts20.isEnumDeclaration(statement))
3351
3427
  add(statement.name.text, "enum", getLine(sourceFile, statement));
3352
- else if (ts19.isFunctionDeclaration(statement) && statement.name)
3428
+ else if (ts20.isFunctionDeclaration(statement) && statement.name)
3353
3429
  add(statement.name.text, "function", getLine(sourceFile, statement));
3354
- else if (ts19.isClassDeclaration(statement) && statement.name)
3430
+ else if (ts20.isClassDeclaration(statement) && statement.name)
3355
3431
  add(statement.name.text, "class", getLine(sourceFile, statement));
3356
- else if (ts19.isVariableStatement(statement)) {
3432
+ else if (ts20.isVariableStatement(statement)) {
3357
3433
  for (const declaration of statement.declarationList.declarations) {
3358
- if (!ts19.isIdentifier(declaration.name))
3434
+ if (!ts20.isIdentifier(declaration.name))
3359
3435
  continue;
3360
3436
  const kind = isFunctionLikeInitializer(declaration.initializer) ? "function" : "variable";
3361
3437
  add(declaration.name.text, kind, getLine(sourceFile, declaration));
@@ -3367,15 +3443,15 @@ function getComponentFileDeclarations(sourceFile) {
3367
3443
  function getCompoundComponentNames(sourceFile) {
3368
3444
  const names = new Set;
3369
3445
  for (const statement of sourceFile.statements) {
3370
- if (!ts19.isExpressionStatement(statement))
3446
+ if (!ts20.isExpressionStatement(statement))
3371
3447
  continue;
3372
3448
  const { expression } = statement;
3373
- if (!ts19.isBinaryExpression(expression) || expression.operatorToken.kind !== ts19.SyntaxKind.EqualsToken)
3449
+ if (!ts20.isBinaryExpression(expression) || expression.operatorToken.kind !== ts20.SyntaxKind.EqualsToken)
3374
3450
  continue;
3375
- if (!ts19.isPropertyAccessExpression(expression.left) || !isPascalCaseName(expression.left.name.text))
3451
+ if (!ts20.isPropertyAccessExpression(expression.left) || !isPascalCaseName(expression.left.name.text))
3376
3452
  continue;
3377
3453
  names.add(expression.left.name.text);
3378
- if (ts19.isIdentifier(expression.right) && isPascalCaseName(expression.right.text))
3454
+ if (ts20.isIdentifier(expression.right) && isPascalCaseName(expression.right.text))
3379
3455
  names.add(expression.right.text);
3380
3456
  }
3381
3457
  return names;
@@ -3395,11 +3471,11 @@ function isPascalCaseName(name) {
3395
3471
  return /^[A-Z]/.test(name) && !/^[A-Z0-9_]+$/.test(name);
3396
3472
  }
3397
3473
  function isDefaultExportStatement(statement) {
3398
- if (ts19.isExportAssignment(statement))
3474
+ if (ts20.isExportAssignment(statement))
3399
3475
  return !statement.isExportEquals;
3400
- if (!ts19.canHaveModifiers(statement))
3476
+ if (!ts20.canHaveModifiers(statement))
3401
3477
  return false;
3402
- return !!ts19.getModifiers(statement)?.some((modifier) => modifier.kind === ts19.SyntaxKind.DefaultKeyword);
3478
+ return !!ts20.getModifiers(statement)?.some((modifier) => modifier.kind === ts20.SyntaxKind.DefaultKeyword);
3403
3479
  }
3404
3480
  function getBangCommentWarnings(sourceFile) {
3405
3481
  if (!isClientReachableFile(sourceFile.file))
@@ -3435,11 +3511,11 @@ function getGlobalMutationWarnings(sourceFile) {
3435
3511
  const warnings = [];
3436
3512
  for (const statement of sourceFile.sourceFile.statements) {
3437
3513
  const warn = (rule, message) => warnings.push(fileWarning(rule, "file", sourceFile.file, message, getLine(sourceFile.sourceFile, statement)));
3438
- if (ts19.isModuleDeclaration(statement) && statement.name.getText(sourceFile.sourceFile) === "global")
3514
+ if (ts20.isModuleDeclaration(statement) && statement.name.getText(sourceFile.sourceFile) === "global")
3439
3515
  warn("akan.file.global-declaration", "Global declarations require an explicit low-level integration allowlist.");
3440
- if (ts19.isInterfaceDeclaration(statement) && statement.name.text === "Window")
3516
+ if (ts20.isInterfaceDeclaration(statement) && statement.name.text === "Window")
3441
3517
  warn("akan.file.window-augmentation", "Window augmentation should be isolated to approved browser integration files.");
3442
- if (ts19.isExpressionStatement(statement) && statement.expression.getText(sourceFile.sourceFile).includes(".prototype."))
3518
+ if (ts20.isExpressionStatement(statement) && statement.expression.getText(sourceFile.sourceFile).includes(".prototype."))
3443
3519
  warn("akan.file.prototype-mutation", "Prototype mutation should be avoided or isolated to approved low-level integration files.");
3444
3520
  }
3445
3521
  return warnings;
@@ -3456,19 +3532,19 @@ function getTopLevelDeclaration(sourceFile, statement) {
3456
3532
  exported: isExported(statement),
3457
3533
  node: statement
3458
3534
  });
3459
- if (ts19.isClassDeclaration(statement) && statement.name)
3535
+ if (ts20.isClassDeclaration(statement) && statement.name)
3460
3536
  return [declared(statement.name.text, "class")];
3461
- if (ts19.isFunctionDeclaration(statement) && statement.name)
3537
+ if (ts20.isFunctionDeclaration(statement) && statement.name)
3462
3538
  return [declared(statement.name.text, "function")];
3463
- if (ts19.isInterfaceDeclaration(statement))
3539
+ if (ts20.isInterfaceDeclaration(statement))
3464
3540
  return [declared(statement.name.text, "interface")];
3465
- if (ts19.isTypeAliasDeclaration(statement))
3541
+ if (ts20.isTypeAliasDeclaration(statement))
3466
3542
  return [declared(statement.name.text, "type")];
3467
- if (ts19.isEnumDeclaration(statement))
3543
+ if (ts20.isEnumDeclaration(statement))
3468
3544
  return [declared(statement.name.text, "enum")];
3469
- if (ts19.isVariableStatement(statement))
3470
- return statement.declarationList.declarations.filter((declaration) => ts19.isIdentifier(declaration.name)).map((declaration) => declared(declaration.name.text, "variable", getLine(sourceFile, declaration)));
3471
- if (ts19.isExportDeclaration(statement))
3545
+ if (ts20.isVariableStatement(statement))
3546
+ return statement.declarationList.declarations.filter((declaration) => ts20.isIdentifier(declaration.name)).map((declaration) => declared(declaration.name.text, "variable", getLine(sourceFile, declaration)));
3547
+ if (ts20.isExportDeclaration(statement))
3472
3548
  return [{ name: "export declaration", kind: "export", line, exported: true, node: statement }];
3473
3549
  return [];
3474
3550
  }
@@ -3556,13 +3632,13 @@ function getModuleInfo(file) {
3556
3632
  return { moduleName, fileName, kind: "database" };
3557
3633
  }
3558
3634
  function isExportedConst(declaration) {
3559
- return declaration.exported && ts19.isVariableStatement(declaration.node) && (declaration.node.declarationList.flags & ts19.NodeFlags.Const) !== 0;
3635
+ return declaration.exported && ts20.isVariableStatement(declaration.node) && (declaration.node.declarationList.flags & ts20.NodeFlags.Const) !== 0;
3560
3636
  }
3561
3637
  function isExported(node) {
3562
- return !!(ts19.getCombinedModifierFlags(node) & ts19.ModifierFlags.Export);
3638
+ return !!(ts20.getCombinedModifierFlags(node) & ts20.ModifierFlags.Export);
3563
3639
  }
3564
3640
  function isFunctionLikeInitializer(node) {
3565
- return !!node && (ts19.isArrowFunction(node) || ts19.isFunctionExpression(node));
3641
+ return !!node && (ts20.isArrowFunction(node) || ts20.isFunctionExpression(node));
3566
3642
  }
3567
3643
  function getBodyFingerprint(sourceFile, node) {
3568
3644
  if (!node)
@@ -3584,7 +3660,7 @@ async function isDirectory(absolutePath) {
3584
3660
  }
3585
3661
  }
3586
3662
  function getScriptKind(file) {
3587
- return file.endsWith(".tsx") ? ts19.ScriptKind.TSX : ts19.ScriptKind.TS;
3663
+ return file.endsWith(".tsx") ? ts20.ScriptKind.TSX : ts20.ScriptKind.TS;
3588
3664
  }
3589
3665
  function getLine(sourceFile, node) {
3590
3666
  return sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1;
@@ -3619,4 +3695,4 @@ function compareWarnings(a, b) {
3619
3695
  return a.scope.localeCompare(b.scope) || (a.file ?? "").localeCompare(b.file ?? "") || (a.line ?? 0) - (b.line ?? 0) || a.rule.localeCompare(b.rule);
3620
3696
  }
3621
3697
 
3622
- export { MaintainabilityBaseline, defaultMaxDiagnostics, WorkspaceRunner, AkanQualityScanner, formatQualityScanResult, formatSsrScanResult };
3698
+ export { defaultMaxDiagnostics, WorkspaceRunner, AkanQualityScanner, formatQualityScanResult, formatSsrScanResult };