@akanjs/cli 3.2.0-rc.1 → 3.2.0-rc.11

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 (99) hide show
  1. package/.build-stamp +2 -1
  2. package/{CodeAgent-vmd9k4ak.js → CodeAgent-fk66n37w.js} +3 -3
  3. package/{CodeTui-zka44v52.js → CodeTui-4rf1mqmv.js} +1 -1
  4. package/README.ko.md +26 -1
  5. package/README.md +26 -1
  6. package/TunnelShare-44er4e29.js +15 -0
  7. package/{agent.command-2f657613.js → agent.command-7g9czkkd.js} +20 -19
  8. package/akanCode.js +3 -3
  9. package/{application.command-q6skd3am.js → application.command-00spg55s.js} +31 -24
  10. package/{applicationBuildRunner-sctcmkyx.js → applicationBuildRunner-f4yf0qyc.js} +9 -7
  11. package/buildBatch.proc.js +7 -6
  12. package/{cloud.command-7642pks6.js → cloud.command-ab704p0g.js} +24 -25
  13. package/cloud.script-4p4y0s7e.js +31 -0
  14. package/{code.command-7s4ndq2k.js → code.command-m6c9xk56.js} +7 -6
  15. package/{context.command-569z0rqf.js → context.command-hgcgxtdk.js} +20 -19
  16. package/context.runner-w071gmc3.js +30 -0
  17. package/{devTui-w38ch13a.js → devTui-h77zrjv5.js} +1 -1
  18. package/{guideline.command-gnv3e8p8.js → guideline.command-6yz6d4hf.js} +3 -2
  19. package/guidelines/agentRule/agentRule.instruction.md +4 -3
  20. package/guidelines/akanApi/akanApi.instruction.md +2 -0
  21. package/guidelines/conventions/core.md +1 -1
  22. package/guidelines/conventions/rules/app.md +3 -0
  23. package/guidelines/conventions/rules/page.md +5 -0
  24. package/guidelines/errorCodes/errorCodes.instruction.md +140 -0
  25. package/guidelines/fieldRule/fieldRule.instruction.md +2 -1
  26. package/guidelines/mcpRule/mcpRule.instruction.md +72 -2
  27. package/guidelines/pageRule/pageRule.instruction.md +5 -0
  28. package/guidelines/runtimeRule/runtimeRule.instruction.md +5 -1
  29. package/guidelines/transportRule/transportRule.instruction.md +5 -0
  30. package/incrementalBuilder.proc.js +8 -7
  31. package/{index-vkzfk7qt.js → index-097bjwvm.js} +40 -30
  32. package/{index-93ewzmp6.js → index-23d8gw08.js} +165 -102
  33. package/{index-p6hjwt2d.js → index-41mfhgq0.js} +72 -26
  34. package/{index-ktb3wcqz.js → index-4k9nv4m3.js} +71 -81
  35. package/{index-vr68mxj5.js → index-5jwx4bf2.js} +69 -33
  36. package/{index-5w9my9qe.js → index-6eptmk8z.js} +30 -20
  37. package/{index-d4n1wmrz.js → index-6fnrhpn1.js} +8 -4
  38. package/{index-kpdv34rq.js → index-6qtxs86x.js} +10 -7
  39. package/{index-ed6ea0qp.js → index-6z57w95f.js} +1 -1
  40. package/{index-drz9e84d.js → index-7ky4brfy.js} +2 -2
  41. package/{index-8g7tdsk4.js → index-849qvd7t.js} +58 -29
  42. package/{index-1q1cjn8s.js → index-9xh4zvw3.js} +94 -53
  43. package/{index-48d5qsj3.js → index-adj7qmz9.js} +23 -15
  44. package/{index-fjr4d6yd.js → index-apcr1qgk.js} +458 -304
  45. package/{index-8ts9774g.js → index-aybfcx58.js} +9 -4
  46. package/{index-8kczhnmv.js → index-b3pr4ee6.js} +1 -1
  47. package/{index-23860fej.js → index-b4qq3rq0.js} +23 -8
  48. package/{index-thckcabc.js → index-bper31wr.js} +24 -6
  49. package/{index-a8a9ede9.js → index-bxkx0x03.js} +14 -7
  50. package/{index-0fb3cpbt.js → index-c3r23w24.js} +9 -7
  51. package/{index-8pb9yvp8.js → index-dfsa009c.js} +148 -31
  52. package/{index-zpv14wpy.js → index-dsg50er9.js} +3 -3
  53. package/{index-hqrkqxx2.js → index-e5f6czck.js} +46 -7
  54. package/{index-sy481q2x.js → index-frvjq1rd.js} +1 -1
  55. package/{index-abgh0jve.js → index-grt0e6kk.js} +1 -1
  56. package/{index-e3vmjtph.js → index-hf9nvwam.js} +7 -2
  57. package/{index-v4p1zye8.js → index-hhagjhkh.js} +7 -7
  58. package/index-j4yvgfhr.js +70 -0
  59. package/{index-s2grpzef.js → index-k2r3hmbz.js} +6 -4
  60. package/{index-7y5yghjg.js → index-nd39rssn.js} +1162 -435
  61. package/{index-6wpaq392.js → index-p4htjyvk.js} +44 -5
  62. package/{index-aj3ehkcx.js → index-p54s83sz.js} +1 -1
  63. package/{index-7xdpww43.js → index-rdx8cyv2.js} +342 -134
  64. package/{index-sr5da35e.js → index-sq9d0jhj.js} +21 -18
  65. package/{index-eajbmk10.js → index-t4d0ckde.js} +2 -2
  66. package/{index-mqntfzv5.js → index-t8h09yjs.js} +7 -2
  67. package/index-va90m8nd.js +25 -0
  68. package/{index-rc5fvqj2.js → index-xfv2p7b5.js} +95 -58
  69. package/{index-w639tvkd.js → index-xgqz3kak.js} +29 -8
  70. package/{index-9tbgb4d8.js → index-xy70tcv4.js} +1 -1
  71. package/{index-mmym5xmb.js → index-z43wddce.js} +5 -3
  72. package/index.js +24 -23
  73. package/{library.command-1gp5qe3r.js → library.command-kc1zahcg.js} +5 -4
  74. package/{localRegistry.command-x7jptkd3.js → localRegistry.command-bz2df40m.js} +19 -18
  75. package/{module.command-4xz9he6h.js → module.command-cchwzz9r.js} +12 -7
  76. package/{package.command-s7qpnn1g.js → package.command-qcjajpv8.js} +8 -7
  77. package/package.json +2 -2
  78. package/{page.command-fan34c49.js → page.command-1t86dx8a.js} +4 -3
  79. package/{pipeline.command-ph4fnn9w.js → pipeline.command-2xx9z3d0.js} +3 -2
  80. package/{primitive.command-3fqh8emf.js → primitive.command-mc0x8txr.js} +8 -7
  81. package/{projectTypecheck-vkb40hjc.js → projectTypecheck-tz497yx7.js} +2 -1
  82. package/{quality.command-ecj6exsh.js → quality.command-11rayf5c.js} +7 -6
  83. package/{repair.command-fe9jw719.js → repair.command-8w41vy78.js} +7 -6
  84. package/{scalar.command-cnvfhk0n.js → scalar.command-rvwh98ny.js} +7 -6
  85. package/skills/akan-debug/SKILL.md +7 -3
  86. package/skills/akan-err/SKILL.md +7 -0
  87. package/skills/akan-mcp/SKILL.md +10 -1
  88. package/skills/akan-scaffold/SKILL.md +3 -2
  89. package/skills/akan-transport/SKILL.md +2 -0
  90. package/skills/akan-validate/SKILL.md +1 -0
  91. package/{subspace.command-qw5ddd6y.js → subspace.command-0970n7kd.js} +9 -8
  92. package/{tunnel.command-ggj38mqf.js → tunnel.command-bcy0rtmh.js} +8 -7
  93. package/typecheck.proc.js +5 -2
  94. package/{verify.command-w9ttxkdz.js → verify.command-ynaztxr2.js} +18 -16
  95. package/{workflow.command-ss8devj0.js → workflow.command-yp9ajthb.js} +45 -16
  96. package/{workspace.command-6z2rh8ze.js → workspace.command-e4wfxm86.js} +39 -34
  97. package/TunnelShare-k3ja4w9x.js +0 -14
  98. package/cloud.script-1sfseznn.js +0 -30
  99. package/context.runner-ms8v1rxy.js +0 -29
@@ -1,37 +1,42 @@
1
1
  // @bun
2
2
  import {
3
3
  ApplicationBuildReporter
4
- } from "./index-p6hjwt2d.js";
4
+ } from "./index-41mfhgq0.js";
5
5
  import {
6
6
  script,
7
- ExitCodeError,
8
7
  markCliErrorPrinted,
9
8
  assertPromptable
10
- } from "./index-93ewzmp6.js";
9
+ } from "./index-23d8gw08.js";
10
+ import {
11
+ CliError
12
+ } from "./index-j4yvgfhr.js";
11
13
  import {
12
14
  SysExecutor,
13
15
  AppExecutor,
14
16
  LibExecutor,
15
17
  PkgExecutor
16
- } from "./index-sr5da35e.js";
18
+ } from "./index-sq9d0jhj.js";
17
19
  import {
18
20
  DesktopServerStage
19
- } from "./index-ed6ea0qp.js";
21
+ } from "./index-6z57w95f.js";
20
22
  import {
21
23
  LibraryScript
22
- } from "./index-mqntfzv5.js";
24
+ } from "./index-t8h09yjs.js";
23
25
  import {
24
26
  ApplicationRunner,
25
27
  VerifyScope
26
- } from "./index-ktb3wcqz.js";
28
+ } from "./index-4k9nv4m3.js";
27
29
  import {
28
30
  PreviewChrome2,
29
31
  PreviewView2,
30
32
  stripAnsi
31
- } from "./index-23860fej.js";
33
+ } from "./index-b4qq3rq0.js";
32
34
  import {
33
35
  formatSlicePlan
34
- } from "./index-sy481q2x.js";
36
+ } from "./index-frvjq1rd.js";
37
+ import {
38
+ assertPlainName
39
+ } from "./index-va90m8nd.js";
35
40
  import {
36
41
  openBrowser
37
42
  } from "./index-9dp031by.js";
@@ -630,15 +635,10 @@ class AppPreview {
630
635
  const unavailable = PreviewView2.unavailableReason(engine);
631
636
  if (unavailable)
632
637
  throw new Error(unavailable);
633
- const { i18n, api } = await app.getConfig();
634
638
  const changed = options.changed ? await AppPreview.#changedPages(app) : { paths: [], skipped: [] };
635
639
  if (options.changed && !changed.paths.length && !options.paths?.length)
636
640
  throw new Error(`No page to open: ${changed.skipped.join("; ")}. Pass a concrete path, e.g. \`akan preview ${app.name} /memo/1\`.`);
637
- const paths = AppPreview.pagePaths([...options.paths ?? [], ...changed.paths], i18n, {
638
- csr: !!options.csr,
639
- apiPrefix: api.prefix,
640
- publicDir: path2.join(app.cwdPath, "public")
641
- });
641
+ const paths = await AppPreview.pathsOf(app, options.paths ?? [], !!options.csr, changed.paths);
642
642
  const port = await app.getDevPort();
643
643
  const origin = `http://localhost:${port}`;
644
644
  const root = app.workspace.workspaceRoot;
@@ -690,12 +690,23 @@ class AppPreview {
690
690
  started?.proc.unref();
691
691
  }
692
692
  }
693
- static pagePaths(paths, i18n, { csr, apiPrefix = "/api", publicDir = null }) {
693
+ static async pathsOf(app, paths, csr, pages = []) {
694
+ const { i18n, api } = await app.getConfig();
695
+ return AppPreview.pagePaths(paths, i18n, {
696
+ csr,
697
+ apiPrefix: api.prefix,
698
+ publicDir: path2.join(app.cwdPath, "public"),
699
+ pages
700
+ });
701
+ }
702
+ static pagePaths(paths, i18n, {
703
+ csr,
704
+ apiPrefix = "/api",
705
+ publicDir = null,
706
+ pages = []
707
+ }) {
694
708
  const keepsUnprefixed = i18n.localePrefix === "as-needed" && !csr;
695
- const pages = (paths.length ? paths : ["/"]).map((raw) => {
696
- const url = new URL(/^https?:\/\//.test(raw) ? raw : `http://localhost${raw.startsWith("/") ? "" : "/"}${raw}`);
697
- if (!AppPreview.#isPagePath(url.pathname, i18n, { apiPrefix, publicDir }))
698
- return `${url.pathname}${url.search}`;
709
+ const asPage = (url) => {
699
710
  const [first] = url.pathname.split("/").filter(Boolean);
700
711
  if (!keepsUnprefixed && (!first || !i18n.locales.includes(first)))
701
712
  url.pathname = `/${i18n.defaultLocale}${url.pathname === "/" ? "/" : url.pathname}`;
@@ -704,11 +715,26 @@ class AppPreview {
704
715
  url.searchParams.set("akanMobileTarget", AppPreview.csrTarget);
705
716
  }
706
717
  return `${url.pathname}${url.search}`;
718
+ };
719
+ const urlOf = (raw) => new URL(`http://localhost${raw.startsWith("/") ? "" : "/"}${raw}`);
720
+ const typed = (paths.length || pages.length ? paths : ["/"]).map((raw) => {
721
+ if (/^https?:\/\//.test(raw)) {
722
+ const url = new URL(raw);
723
+ return `${url.pathname}${url.search}`;
724
+ }
725
+ const url = urlOf(raw);
726
+ return AppPreview.#isPagePath(url.pathname, i18n, { apiPrefix, publicDir }) ? asPage(url) : `${url.pathname}${url.search}`;
707
727
  });
708
- return [...new Set(pages)];
709
- }
710
- static #serverFiles = new Set(["/favicon.ico", "/robots.txt", "/sitemap.xml", "/manifest.webmanifest"]);
711
- static #basePathFiles = new Set(["sitemap.xml", "manifest.webmanifest"]);
728
+ return [...new Set([...typed, ...pages.map((page) => asPage(urlOf(page)))])];
729
+ }
730
+ static #serverFiles = new Set([
731
+ "/favicon.ico",
732
+ "/robots.txt",
733
+ "/sitemap.xml",
734
+ "/manifest.webmanifest",
735
+ "/openapi.json",
736
+ "/mcp"
737
+ ]);
712
738
  static #isPagePath(pathname, i18n, { apiPrefix, publicDir }) {
713
739
  const segments = pathname.split("/").filter(Boolean);
714
740
  const [first] = segments;
@@ -719,7 +745,7 @@ class AppPreview {
719
745
  return false;
720
746
  if (AppPreview.#serverFiles.has(pathname))
721
747
  return false;
722
- if (segments.length === 2 && AppPreview.#basePathFiles.has(segments[1] ?? ""))
748
+ if (segments.length === 2 && segments[1] === "manifest.webmanifest")
723
749
  return false;
724
750
  return !(publicDir && AppPreview.#isPublicFile(publicDir, pathname));
725
751
  }
@@ -774,8 +800,14 @@ class AppPreview {
774
800
  }
775
801
  static screenshotName(pagePath) {
776
802
  const url = new URL(pagePath, "http://localhost");
777
- const slug = url.pathname.split("/").filter(Boolean).join("-").replace(/[^\w-]/g, "_") || "index";
778
- return `${slug}${url.searchParams.get("csr") === "true" ? ".csr" : ""}.png`;
803
+ const slugOf = (text) => text.replace(/[^\w-]/g, "_");
804
+ const hashOf = (text) => Bun.hash(text).toString(36).slice(0, 6);
805
+ const pathSlug = slugOf(url.pathname.split("/").filter(Boolean).join("-")) || "index";
806
+ const page = pathSlug.length > 80 ? `${pathSlug.slice(0, 80)}-${hashOf(url.pathname)}` : pathSlug;
807
+ const params = [...url.searchParams].filter(([key]) => key !== "csr" && key !== "akanMobileTarget");
808
+ const readable = slugOf(params.map(([key, value]) => `${key}-${value}`).join("-")).slice(0, 40);
809
+ const query = params.length ? `.${readable}-${hashOf(new URLSearchParams(params).toString())}` : "";
810
+ return `${page}${query}${url.searchParams.get("csr") === "true" ? ".csr" : ""}.png`;
779
811
  }
780
812
  static attribute(page, records) {
781
813
  const pathname = new URL(page.finalUrl).pathname;
@@ -1230,6 +1262,7 @@ class ApplicationScript extends script("application", [ApplicationRunner, Librar
1230
1262
  #interrupt = new InterruptTeardown;
1231
1263
  async confirmDatabaseModeDependencyInstall(databaseMode, installSpecs) {
1232
1264
  assertPromptable(`Database mode '${databaseMode}' requires missing dependencies: ${installSpecs.join(", ")}`, {
1265
+ code: "failed",
1233
1266
  remedy: `install them first with \`bun add ${installSpecs.join(" ")}\``
1234
1267
  });
1235
1268
  return await confirm({
@@ -1258,6 +1291,7 @@ class ApplicationScript extends script("application", [ApplicationRunner, Librar
1258
1291
  }
1259
1292
  }
1260
1293
  async createApplication(appName, workspace, { start = false, libs = [] } = {}) {
1294
+ assertPlainName("app", appName);
1261
1295
  const spinner = workspace.spinning("Creating application...");
1262
1296
  const app = await this.applicationRunner.createApplication(appName, workspace, libs);
1263
1297
  spinner.succeed(`Application created in apps/${app.name}`);
@@ -1307,7 +1341,7 @@ class ApplicationScript extends script("application", [ApplicationRunner, Librar
1307
1341
  Logger3.rawLog(format === "json" ? JSON.stringify(report, null, 2) : AppPreview.render(report));
1308
1342
  if (!report.pages.some((page) => page.failed))
1309
1343
  return;
1310
- const failure = new ExitCodeError("preview found broken pages", 1);
1344
+ const failure = new CliError("checkFailed", "preview found broken pages");
1311
1345
  markCliErrorPrinted(failure);
1312
1346
  throw failure;
1313
1347
  }
@@ -1340,7 +1374,7 @@ class ApplicationScript extends script("application", [ApplicationRunner, Librar
1340
1374
  quiet = false,
1341
1375
  profile,
1342
1376
  env,
1343
- updateBudget = false
1377
+ budget = "report"
1344
1378
  } = {}) {
1345
1379
  await app.scanSync({ write });
1346
1380
  if (!quiet)
@@ -1351,10 +1385,12 @@ class ApplicationScript extends script("application", [ApplicationRunner, Librar
1351
1385
  spinner: !quiet,
1352
1386
  envProfile: profile,
1353
1387
  environment: env,
1354
- budget: updateBudget ? "update" : "enforce"
1388
+ budget
1355
1389
  });
1356
1390
  Logger3.rawLog(`${app.name} built in dist/apps/${app.name}`);
1357
- if (!quiet)
1391
+ if (quiet)
1392
+ ApplicationBuildReporter.printRouteJsWarnings(result);
1393
+ else
1358
1394
  ApplicationBuildReporter.printSummary(result);
1359
1395
  } catch (error) {
1360
1396
  Logger3.rawLog(`${app.name} build failed in dist/apps/${app.name}`, undefined, "error");
@@ -1483,7 +1519,7 @@ class ApplicationScript extends script("application", [ApplicationRunner, Librar
1483
1519
  throw new Error("No app selected to start");
1484
1520
  const startedDatabase = dbup ? await this.#prepareSharedDatabase(apps) : false;
1485
1521
  const supervisor = new DevSupervisor({ apps, mode, concurrency, open, write, shares });
1486
- const view = mode === "tui" ? new (await import("./devTui-w38ch13a.js")).DevTui(supervisor) : new DevStreamView(apps.map((app) => app.name));
1522
+ const view = mode === "tui" ? new (await import("./devTui-h77zrjv5.js")).DevTui(supervisor) : new DevStreamView(apps.map((app) => app.name));
1487
1523
  await supervisor.run(view);
1488
1524
  if (startedDatabase)
1489
1525
  await this.#stopDatabase(workspace);
@@ -1647,7 +1683,7 @@ class ApplicationScript extends script("application", [ApplicationRunner, Librar
1647
1683
  await Promise.all(shares.map(async (share) => await share.close()));
1648
1684
  }, "Abandoning the tunnel release; the shares expire on their own.");
1649
1685
  await Promise.all(apps.map(async (app) => {
1650
- const { TunnelShare } = await import("./TunnelShare-k3ja4w9x.js");
1686
+ const { TunnelShare } = await import("./TunnelShare-44er4e29.js");
1651
1687
  const share = await TunnelShare.open(app, { workspace: app.workspace });
1652
1688
  shares.push(share);
1653
1689
  urls.set(app.name, share.url);
@@ -2,9 +2,11 @@
2
2
  import {
3
3
  runner,
4
4
  script,
5
- ExitCodeError,
6
5
  markCliErrorPrinted
7
- } from "./index-93ewzmp6.js";
6
+ } from "./index-23d8gw08.js";
7
+ import {
8
+ CliError
9
+ } from "./index-j4yvgfhr.js";
8
10
  import {
9
11
  AGENT_BLOCK_START,
10
12
  AGENT_BLOCK_END,
@@ -15,7 +17,7 @@ import {
15
17
  CLAUDE_COMMENT_RULE,
16
18
  AppExecutor,
17
19
  LibExecutor
18
- } from "./index-sr5da35e.js";
20
+ } from "./index-sq9d0jhj.js";
19
21
  import {
20
22
  akanCodePaths2
21
23
  } from "./index-35j83zkd.js";
@@ -23,25 +25,25 @@ import {
23
25
  ConventionSet,
24
26
  Prompter2
25
27
  } from "./index-j6eeh5d7.js";
28
+ import {
29
+ AkanContextAnalyzer
30
+ } from "./index-bper31wr.js";
26
31
  import {
27
32
  collectRecipeSources2,
28
33
  scanRecipes2
29
34
  } from "./index-hj6w4ka1.js";
30
- import {
31
- AkanContextAnalyzer
32
- } from "./index-thckcabc.js";
33
35
  import {
34
36
  ApplicationRunner,
35
37
  VerifyScope
36
- } from "./index-ktb3wcqz.js";
38
+ } from "./index-4k9nv4m3.js";
37
39
  import {
38
40
  WorkspaceRunner
39
- } from "./index-fjr4d6yd.js";
41
+ } from "./index-apcr1qgk.js";
40
42
  import {
41
43
  VerifyComments,
42
44
  VerifyPipeline,
43
45
  VerifyReport
44
- } from "./index-s2grpzef.js";
46
+ } from "./index-k2r3hmbz.js";
45
47
 
46
48
  // pkgs/@akanjs/cli/agent/agent.script.ts
47
49
  import { Logger as Logger3 } from "akanjs/common";
@@ -79,7 +81,7 @@ class AgentAssets {
79
81
  "modelUtil",
80
82
  "framework"
81
83
  ],
82
- "akan-err": [],
84
+ "akan-err": ["errorCodes"],
83
85
  "akan-deps": [],
84
86
  "akan-debug": [],
85
87
  "akan-page": ["pageRule", "akanApi"],
@@ -610,7 +612,7 @@ var resolveTargets = (target) => {
610
612
  const single = singleTargets.find((name) => name === target);
611
613
  if (single)
612
614
  return [single];
613
- throw new Error(`Unknown agent target: ${target}. Use cursor, agents-md, claude, rules, skills, hooks, or all.`);
615
+ throw new CliError("usage", `Unknown agent target: ${target}. Use cursor, agents-md, claude, rules, skills, hooks, or all.`);
614
616
  };
615
617
 
616
618
  class AgentScript extends script("agent", [AgentRunner]) {
@@ -618,7 +620,7 @@ class AgentScript extends script("agent", [AgentRunner]) {
618
620
  if (action === "hook")
619
621
  return await this.#hook(workspace, target);
620
622
  if (action !== "install")
621
- throw new Error(`Unknown agent action: ${action}. Use "install" or "hook".`);
623
+ throw new CliError("usage", `Unknown agent action: ${action}. Use "install" or "hook".`);
622
624
  if (check)
623
625
  return await this.#check(workspace, resolveTargets(target));
624
626
  const written = await this.agentRunner.install(workspace, resolveTargets(target), { force });
@@ -634,19 +636,27 @@ ${written.map((file) => `- ${file}`).join(`
634
636
  const lines = drift.map(({ path, change }) => `${path} ${change}`);
635
637
  Logger3.rawLog([`agent files differ \xB7 ${files} \xB7 run \`akan agent install\``, ...lines].join(`
636
638
  `));
637
- const failure = new ExitCodeError("agent files differ", 1);
639
+ const failure = new CliError("checkFailed", "agent files differ");
638
640
  markCliErrorPrinted(failure);
639
641
  throw failure;
640
642
  }
641
643
  async#hook(workspace, event) {
642
- if (!AgentHook.isEvent(event))
643
- throw new Error(`Unknown hook: ${event}. Use ${AgentHook.events.join(", ")}.`);
644
- const raw = (await Bun.stdin.text()).trim();
645
- const input = raw ? JSON.parse(raw) : {};
646
- const response = AgentHook.respond(event, await new AgentHook(workspace).run(event, input));
647
- if (response)
648
- process.stdout.write(`${response}
644
+ try {
645
+ if (!AgentHook.isEvent(event))
646
+ throw new CliError("usage", `Unknown hook: ${event}. Use ${AgentHook.events.join(", ")}.`);
647
+ const raw = (await Bun.stdin.text()).trim();
648
+ const input = raw ? JSON.parse(raw) : {};
649
+ const response = AgentHook.respond(event, await new AgentHook(workspace).run(event, input));
650
+ if (response)
651
+ process.stdout.write(`${response}
649
652
  `);
653
+ } catch (error) {
654
+ const message = CliError.messageOf(error);
655
+ Logger3.rawLog(message, undefined, "error");
656
+ const failure = new CliError("failed", message, { cause: error });
657
+ markCliErrorPrinted(failure);
658
+ throw failure;
659
+ }
650
660
  }
651
661
  }
652
662
 
@@ -2,22 +2,25 @@
2
2
  import {
3
3
  runner,
4
4
  script
5
- } from "./index-93ewzmp6.js";
5
+ } from "./index-23d8gw08.js";
6
6
  import {
7
7
  FileSys2
8
8
  } from "./index-bns3wcpc.js";
9
9
  import {
10
10
  PkgExecutor
11
- } from "./index-sr5da35e.js";
11
+ } from "./index-sq9d0jhj.js";
12
12
  import {
13
13
  TypeScriptDependencyScanner2
14
14
  } from "./index-qd7xn2bk.js";
15
15
  import {
16
16
  FrameworkGraph
17
- } from "./index-abgh0jve.js";
17
+ } from "./index-grt0e6kk.js";
18
18
  import {
19
19
  MaintainabilityBaseline
20
- } from "./index-hqrkqxx2.js";
20
+ } from "./index-e5f6czck.js";
21
+ import {
22
+ assertPackageName
23
+ } from "./index-va90m8nd.js";
21
24
 
22
25
  // pkgs/@akanjs/cli/package/package.runner.ts
23
26
  import path2 from "path";
@@ -404,6 +407,7 @@ class PackageScript extends script("package", [PackageRunner]) {
404
407
  return await this.packageRunner.version(workspace, { log });
405
408
  }
406
409
  async createPackage(workspace, pkgName) {
410
+ assertPackageName(pkgName);
407
411
  const spinner = workspace.spinning(`Creating package in pkgs/${pkgName}...`);
408
412
  await this.packageRunner.createPackage(workspace, pkgName);
409
413
  spinner.succeed(`Package in pkgs/${pkgName} is created`);
@@ -1,16 +1,16 @@
1
1
  // @bun
2
- import {
3
- jsonText
4
- } from "./index-8pb9yvp8.js";
5
2
  import {
6
3
  akanMcpInstallTargets
7
- } from "./index-thckcabc.js";
4
+ } from "./index-bper31wr.js";
5
+ import {
6
+ jsonText
7
+ } from "./index-dfsa009c.js";
8
8
  import {
9
9
  script
10
- } from "./index-93ewzmp6.js";
10
+ } from "./index-23d8gw08.js";
11
11
  import {
12
12
  ContextRunner2
13
- } from "./index-rc5fvqj2.js";
13
+ } from "./index-xfv2p7b5.js";
14
14
 
15
15
  // pkgs/@akanjs/cli/context/context.script.ts
16
16
  import { Logger } from "akanjs/common";
@@ -32,7 +32,10 @@ class ContextScript extends script("context", [ContextRunner2]) {
32
32
  Logger.rawLog(await this.contextRunner.getContext(workspace, options));
33
33
  }
34
34
  async doctor(workspace, options = {}) {
35
- Logger.rawLog(await this.contextRunner.doctor(workspace, options));
35
+ const { status, output } = await this.contextRunner.doctor(workspace, options);
36
+ Logger.rawLog(output);
37
+ if (status === "failed")
38
+ process.exitCode = 1;
36
39
  }
37
40
  async mcpInstall(workspace, target, { force = false, mode = "apply" } = {}) {
38
41
  const targets = resolveMcpInstallTargets(target);
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  DesktopBin
4
- } from "./index-zpv14wpy.js";
4
+ } from "./index-dsg50er9.js";
5
5
  // pkgs/@akanjs/devkit/mobile/desktopServerStage.ts
6
6
  import { cp, mkdir, readdir, rm, writeFile } from "fs/promises";
7
7
  import path from "path";
@@ -9,10 +9,10 @@ import {
9
9
  UpdatePackFolder,
10
10
  NativePublicEnv,
11
11
  NativeApp
12
- } from "./index-zpv14wpy.js";
12
+ } from "./index-dsg50er9.js";
13
13
  import {
14
14
  ExitCodeError
15
- } from "./index-93ewzmp6.js";
15
+ } from "./index-23d8gw08.js";
16
16
  import {
17
17
  ConfigLock
18
18
  } from "./index-bqbf654f.js";
@@ -1,7 +1,9 @@
1
1
  // @bun
2
2
  import {
3
+ ROOT_LAYOUT_SYSTEM,
4
+ isImplicitRootLayoutKey,
3
5
  resolveSsrPageEntriesForApp
4
- } from "./index-sr5da35e.js";
6
+ } from "./index-sq9d0jhj.js";
5
7
  import {
6
8
  computeRouteSeedIndex,
7
9
  saveRouteSeedIndex,
@@ -9,12 +11,12 @@ import {
9
11
  ClientEntriesBundler,
10
12
  VENDOR_SPECIFIERS,
11
13
  RouteClientBuilder
12
- } from "./index-7xdpww43.js";
14
+ } from "./index-rdx8cyv2.js";
13
15
  import {
14
16
  SOURCE_EXTS,
15
17
  FontOptimizer,
16
18
  FontPruner
17
- } from "./index-p6hjwt2d.js";
19
+ } from "./index-41mfhgq0.js";
18
20
  import {
19
21
  BarrelAnalyzer,
20
22
  createTsconfigPackageResolver,
@@ -22,7 +24,7 @@ import {
22
24
  CsrEntryFiles,
23
25
  toClientReferencePath,
24
26
  PagesBundleBuilder
25
- } from "./index-1q1cjn8s.js";
27
+ } from "./index-9xh4zvw3.js";
26
28
  import {
27
29
  CssBlockParser
28
30
  } from "./index-62md4dwy.js";
@@ -98,7 +100,7 @@ class AllRoutesBuilder {
98
100
  };
99
101
  #knownSet = new Set;
100
102
  #routeIds = [];
101
- #entriesByRoute = new Map;
103
+ #ssrEntriesByRoute = new Map;
102
104
  #externalsByChunkUrl = {};
103
105
  #discovery = null;
104
106
  constructor(app, command = "start") {
@@ -111,14 +113,16 @@ class AllRoutesBuilder {
111
113
  const pageEntries = await resolveSsrPageEntriesForApp(this.#app, pageKeys);
112
114
  const seedIndex = computeRouteSeedIndex(pageEntries);
113
115
  this.#app.verbose(`[build-all] discovered ${seedIndex.entries.length} routes`);
114
- this.#discovery = await GraphClientEntryDiscovery.create(this.#app);
116
+ const discovery = await GraphClientEntryDiscovery.create(this.#app);
117
+ this.#discovery = discovery;
118
+ const importsAs = await this.#ssrImportsAs(discovery, pageEntries);
115
119
  const allEntries = new Set;
116
120
  for (const entry of seedIndex.entries) {
117
121
  const seeds = Array.from(new Set([...seedIndex.globalLayoutFiles, ...entry.seeds]));
118
- const routeEntries = await this.#discovery.discover(seeds);
122
+ const routeEntries = await discovery.discover(seeds);
119
123
  for (const discovered of routeEntries)
120
124
  allEntries.add(discovered);
121
- this.#entriesByRoute.set(entry.routeId, routeEntries);
125
+ this.#ssrEntriesByRoute.set(entry.routeId, await discovery.discover(seeds, { importsAs }));
122
126
  this.#routeIds.push(entry.routeId);
123
127
  }
124
128
  this.#app.verbose(`[build-all] ${allEntries.size} client entries across ${this.#routeIds.length} routes`);
@@ -134,10 +138,22 @@ class AllRoutesBuilder {
134
138
  this.#app.verbose(`[build-all] wrote ${manifestPath} routes=${this.#routeIds.length} entries=${this.#merged.knownEntries.length}`);
135
139
  return { manifest, manifestPath, seedIndex };
136
140
  }
141
+ async#ssrImportsAs(discovery, pageEntries) {
142
+ const { specifier, ssrShell, importsNoSsrPageRenders } = ROOT_LAYOUT_SYSTEM;
143
+ const importsAs = new Map;
144
+ const toShell = new Map([[specifier, ssrShell]]);
145
+ for (const { key, moduleAbsPath } of pageEntries)
146
+ if (isImplicitRootLayoutKey(key))
147
+ importsAs.set(path.resolve(moduleAbsPath), toShell);
148
+ const system = await discovery.resolveImport(specifier, this.#app.cwdPath);
149
+ if (system)
150
+ importsAs.set(system, new Map(importsNoSsrPageRenders.map((spec) => [spec, null])));
151
+ return importsAs;
152
+ }
137
153
  async writeModulePreloads(runtimeChunks) {
138
154
  const preloads = new RouteModulePreloads({
139
155
  runtimeChunks,
140
- entriesByRoute: this.#entriesByRoute,
156
+ entriesByRoute: this.#ssrEntriesByRoute,
141
157
  clientManifest: this.#merged.clientManifest,
142
158
  externalsByChunkUrl: this.#externalsByChunkUrl,
143
159
  workspaceRoot: this.#app.workspace.workspaceRoot
@@ -975,16 +991,7 @@ class SsrBaseArtifactBuilder {
975
991
  const rscClientUrl = clientBundle.entryUrlsByAbsPath.get(rscClientEntry) ?? "";
976
992
  const rscRuntimeSsrManifest = {
977
993
  moduleLoading: null,
978
- moduleMap: Object.fromEntries(Object.entries(clientBundle.manifest).map(([key, row]) => {
979
- const ssrOutput = ssrBundle.entryOutputAbsByAbsPath.get(rscSegmentOutletEntry);
980
- if (!ssrOutput || key !== `${clientBundle.clientReferenceIdByAbsPath.get(rscSegmentOutletEntry)}#${row.name}`) {
981
- return null;
982
- }
983
- return [
984
- row.id,
985
- { [row.name]: { id: ssrOutput, chunks: [ssrOutput, ssrOutput], name: row.name, async: true } }
986
- ];
987
- }).filter((entry) => Boolean(entry)))
994
+ moduleMap: SsrBaseArtifactBuilder.outletModuleMap(clientBundle.manifest, clientBundle.clientReferenceIdByAbsPath.get(rscSegmentOutletEntry), ssrBundle.entryOutputAbsByAbsPath.get(rscSegmentOutletEntry))
988
995
  };
989
996
  const vendorMap = Object.fromEntries(vendorEntries.map(({ specifier, absPath }) => [specifier, clientBundle.entryUrlsByAbsPath.get(absPath) ?? ""]));
990
997
  this.#app.verbose(`[base-artifact] rscClientUrl=${rscClientUrl} vendors=${Object.keys(vendorMap).length}`);
@@ -1000,6 +1007,20 @@ class SsrBaseArtifactBuilder {
1000
1007
  }
1001
1008
  };
1002
1009
  }
1010
+ static outletModuleMap(manifest, outletReferenceId, ssrOutput) {
1011
+ const moduleMap = {};
1012
+ if (!ssrOutput || !outletReferenceId)
1013
+ return moduleMap;
1014
+ for (const [key, row] of Object.entries(manifest)) {
1015
+ if (key !== `${outletReferenceId}#${row.name}`)
1016
+ continue;
1017
+ moduleMap[row.id] = {
1018
+ ...moduleMap[row.id],
1019
+ [row.name]: { id: ssrOutput, chunks: [ssrOutput, ssrOutput], name: row.name, async: true }
1020
+ };
1021
+ }
1022
+ return moduleMap;
1023
+ }
1003
1024
  async#resolveAkanServerPath() {
1004
1025
  const candidates = [];
1005
1026
  try {
@@ -1070,28 +1091,36 @@ class VendorImportScanner {
1070
1091
  for (const specifier of specifiers)
1071
1092
  this.#names.set(specifier, new Set);
1072
1093
  }
1073
- static async exportsUsedIn(dir, specifiers) {
1094
+ static async exportsUsedIn(dir, specifiers, entryUrls) {
1074
1095
  const scanner = new VendorImportScanner(specifiers);
1075
- if (!fs3.existsSync(dir))
1076
- return scanner.usedExports();
1077
- for await (const relative of new Bun.Glob("**/*.js").scan({ cwd: dir }))
1078
- scanner.scan(await Bun.file(path8.join(dir, relative)).text(), relative);
1096
+ const scanned = [];
1097
+ if (fs3.existsSync(dir))
1098
+ for await (const relative of new Bun.Glob("**/*.js").scan({ cwd: dir })) {
1099
+ scanner.scan(await Bun.file(path8.join(dir, relative)).text(), relative);
1100
+ scanned.push(`/${relative.split(path8.sep).join("/")}`);
1101
+ }
1102
+ const unread = [...new Set(entryUrls)].filter((url) => !scanned.some((relative) => url.endsWith(relative)));
1103
+ if (unread.length > 0) {
1104
+ const named = `${unread.slice(0, 3).join(", ")}${unread.length > 3 ? `, and ${unread.length - 3} more` : ""}`;
1105
+ throw new Error(`[VendorImportScanner] no file under ${dir} for the route client entries ${named}; narrowing the vendor entries without them would drop names those pages import`);
1106
+ }
1079
1107
  return scanner.usedExports();
1080
1108
  }
1081
1109
  scan(source, fileName = "chunk.js") {
1082
1110
  if (![...this.#specifiers].some((specifier) => source.includes(specifier)))
1083
1111
  return this;
1084
- const file = ts.createSourceFile(fileName, source, ts.ScriptTarget.Latest, false, ts.ScriptKind.JS);
1085
- const visit = (node) => {
1112
+ const stack = [ts.createSourceFile(fileName, source, ts.ScriptTarget.Latest, false, ts.ScriptKind.JS)];
1113
+ for (let node = stack.pop();node; node = stack.pop()) {
1086
1114
  if (ts.isImportDeclaration(node))
1087
1115
  this.#readImport(node);
1088
1116
  else if (ts.isExportDeclaration(node))
1089
1117
  this.#readExport(node);
1090
1118
  else if (ts.isCallExpression(node))
1091
1119
  this.#readCall(node);
1092
- ts.forEachChild(node, visit);
1093
- };
1094
- visit(file);
1120
+ ts.forEachChild(node, (child) => {
1121
+ stack.push(child);
1122
+ });
1123
+ }
1095
1124
  return this;
1096
1125
  }
1097
1126
  usedExports() {