@akanjs/cli 3.1.0-rc.9 → 3.1.1-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 (91) hide show
  1. package/.build-stamp +1 -1
  2. package/{CodeAgent-rkjyxgec.js → CodeAgent-4pnxwptq.js} +2 -2
  3. package/{CodeAgentRpcHost-p7h6n2hp.js → CodeAgentRpcHost-9g27hmer.js} +1 -1
  4. package/{CodeTui-h7pyj6xa.js → CodeTui-hhndze8h.js} +47 -4
  5. package/README.ko.md +1 -1
  6. package/README.md +1 -1
  7. package/TunnelShare-zmq6bbar.js +14 -0
  8. package/{agent.command-3qxf4xcj.js → agent.command-p02330r6.js} +5 -5
  9. package/akanCode.js +7 -5
  10. package/{application.command-m1kcd7jf.js → application.command-ywks5ywm.js} +35 -9
  11. package/{applicationBuildRunner-dj0xkrep.js → applicationBuildRunner-9cnnsdm5.js} +23 -8
  12. package/buildBatch.proc.js +9 -9
  13. package/{cloud.command-9cp1t0f5.js → cloud.command-1tzkvje1.js} +13 -13
  14. package/cloud.script-8g83xqdg.js +24 -0
  15. package/{code.command-0ad6gw2a.js → code.command-16pm1p2v.js} +25 -12
  16. package/commandManifest.json +1 -1
  17. package/{context.command-0qx447mb.js → context.command-6ys86sqf.js} +16 -16
  18. package/context.runner-3jrypwe3.js +25 -0
  19. package/{guideline.command-cv5bmrx2.js → guideline.command-3zay3d8g.js} +2 -2
  20. package/guidelines/agentRule/agentRule.instruction.md +25 -10
  21. package/guidelines/conventions/conventions.instruction.md +71 -24
  22. package/guidelines/fieldRule/fieldRule.instruction.md +17 -0
  23. package/guidelines/mcpRule/mcpRule.instruction.md +93 -48
  24. package/guidelines/modelDocument/modelDocument.instruction.md +2 -1
  25. package/guidelines/modelStore/modelStore.instruction.md +7 -0
  26. package/guidelines/pageRule/pageRule.instruction.md +55 -8
  27. package/guidelines/queryRule/queryRule.instruction.md +24 -10
  28. package/guidelines/runtimeRule/runtimeRule.instruction.md +12 -4
  29. package/guidelines/ssrRule/ssrRule.instruction.md +9 -6
  30. package/guidelines/transportRule/transportRule.instruction.md +36 -5
  31. package/guidelines/workspaceOnboarding/workspaceOnboarding.instruction.md +5 -3
  32. package/guidelines/workspaceRecipes/workspaceRecipes.instruction.md +28 -8
  33. package/incrementalBuilder.proc.js +3 -3
  34. package/{index-cpb3nvma.js → index-1f33g2z5.js} +2 -2
  35. package/{index-tamvyvj3.js → index-1mfyyxh5.js} +3 -3
  36. package/{index-wa5jbxj1.js → index-2mrn1mrg.js} +1 -0
  37. package/{index-8fp3b47h.js → index-4w3skd33.js} +281 -46
  38. package/{index-bspm21y1.js → index-68c3gzvg.js} +7 -7
  39. package/{index-20bxxyvn.js → index-9hbhm6cs.js} +40 -2
  40. package/{index-d2242ksy.js → index-at7bz0xq.js} +3 -0
  41. package/{index-fmzcs8v6.js → index-b5vptvnt.js} +4 -4
  42. package/{index-d72hfmdm.js → index-bb4hj03s.js} +8 -8
  43. package/{index-9z426msb.js → index-e9e9cebg.js} +78 -27
  44. package/{index-vk0pa0mn.js → index-ekpp5tax.js} +2 -1
  45. package/{index-35hc95h5.js → index-fmder14z.js} +1 -1
  46. package/{index-86jt2a0e.js → index-g2s33373.js} +1 -1
  47. package/{index-4mhy6qme.js → index-jaa81e9r.js} +4 -4
  48. package/{index-192ha4xh.js → index-jgs8z8xb.js} +3 -3
  49. package/{index-qwa5k1j8.js → index-kcbq2qcf.js} +1 -1
  50. package/{index-w44cy4vs.js → index-ngpn9hzy.js} +6 -4
  51. package/{index-jw1zm273.js → index-p4dnj2wc.js} +54 -10
  52. package/index-q8age5az.js +643 -0
  53. package/{index-j4mkhz93.js → index-qfzfaq96.js} +3 -3
  54. package/{index-pydbnfez.js → index-qkcwsg6r.js} +35 -9
  55. package/{index-d47ypebv.js → index-qtkycaqn.js} +75 -19
  56. package/{index-va06nr10.js → index-rr7jk14m.js} +65 -20
  57. package/{index-1xj2t7cb.js → index-sh9mmp5v.js} +7 -7
  58. package/{index-1p98exm2.js → index-sng3vt0p.js} +2 -2
  59. package/{index-j237xtew.js → index-tk3jg2bm.js} +25 -8
  60. package/{index-fyq1z6kt.js → index-vg28jsf9.js} +3 -3
  61. package/{index-trpasv9q.js → index-ynqxpwx6.js} +1 -1
  62. package/{index-5edzv8fn.js → index-z6v7k9sb.js} +2 -2
  63. package/{index-g1mbppa9.js → index-z9xepn8t.js} +5 -5
  64. package/{index-awbdfcf2.js → index-zn6bn1s2.js} +4 -4
  65. package/index.js +40 -22
  66. package/{library.command-erp2f56n.js → library.command-a8n9h8j4.js} +3 -3
  67. package/{localRegistry.command-y176p558.js → localRegistry.command-1e6m7w2f.js} +12 -12
  68. package/{module.command-gs2r615e.js → module.command-b6f1p1xa.js} +5 -5
  69. package/{package.command-j10r76ax.js → package.command-tc27ftmy.js} +3 -3
  70. package/package.json +16 -16
  71. package/{page.command-4h4a8pnh.js → page.command-m5wyqfkd.js} +3 -3
  72. package/{pipeline.command-a2nrk26m.js → pipeline.command-4qxyafpz.js} +2 -2
  73. package/{primitive.command-w6t0asqz.js → primitive.command-9yaatk0d.js} +6 -6
  74. package/{projectTypecheck-f534enqj.js → projectTypecheck-87k6z6ab.js} +1 -1
  75. package/{quality.command-77x7vbbx.js → quality.command-ht1wjhv8.js} +2 -2
  76. package/{repair.command-y6sstev7.js → repair.command-evg9g911.js} +5 -5
  77. package/{routeSourceValidator-7ycnfz0e.js → routeSourceValidator-6jd0q6r6.js} +47 -14
  78. package/{scalar.command-20b8cy0k.js → scalar.command-xsejjeq1.js} +4 -4
  79. package/skills/akan-code/SKILL.md +4 -0
  80. package/skills/akan-store/SKILL.md +4 -2
  81. package/{subspace.command-5c7yasd7.js → subspace.command-ps12q5y7.js} +8 -17
  82. package/templates/migration/__migrationId__.ts +23 -0
  83. package/templates/server.ts +8 -1
  84. package/templates/workspaceRoot/biome.json.template +1 -1
  85. package/{tunnel.command-2kw8vt9g.js → tunnel.command-khzgvrj8.js} +7 -7
  86. package/{workflow.command-2djwmpqf.js → workflow.command-qpyq0ya5.js} +10 -10
  87. package/{workspace.command-ms84ykse.js → workspace.command-3dq7e9g2.js} +30 -28
  88. package/TunnelShare-661cxz5e.js +0 -14
  89. package/cloud.script-dgstqt1m.js +0 -24
  90. package/context.runner-1vsjztjg.js +0 -25
  91. package/index-665zp9rs.js +0 -271
@@ -2,12 +2,13 @@
2
2
  import {
3
3
  runner,
4
4
  script
5
- } from "./index-jw1zm273.js";
5
+ } from "./index-p4dnj2wc.js";
6
6
  import {
7
7
  LibSource,
8
8
  formatLibStatuses,
9
+ CommandExecutionError,
9
10
  LibExecutor
10
- } from "./index-va06nr10.js";
11
+ } from "./index-rr7jk14m.js";
11
12
 
12
13
  // pkgs/@akanjs/cli/library/library.script.ts
13
14
  import { Logger } from "akanjs/common";
@@ -37,6 +38,8 @@ var compareSemver = (a, b) => {
37
38
  // pkgs/@akanjs/cli/library/library.runner.ts
38
39
  class LibraryRunner extends runner("library") {
39
40
  static libraryRepository = "https://github.com/akan-team/akanjs.git";
41
+ static #cloneDir = "node_modules/.akan/akanjs";
42
+ #clones = new Map;
40
43
  async createLibrary(libName, workspace) {
41
44
  await workspace.mkdir(`libs/${libName}`);
42
45
  await workspace.applyTemplate({ basePath: `libs/${libName}`, template: "libRoot", dict: { libName } });
@@ -59,14 +62,37 @@ class LibraryRunner extends runner("library") {
59
62
  const { version } = await workspace.readJson(manifestPath);
60
63
  return version ?? "unknown";
61
64
  }
65
+ async#hasTag(workspace, tag) {
66
+ try {
67
+ await workspace.spawn("git", ["ls-remote", "--exit-code", LibraryRunner.libraryRepository, `refs/tags/${tag}`]);
68
+ return true;
69
+ } catch (error) {
70
+ if (error instanceof CommandExecutionError && error.code === 2)
71
+ return false;
72
+ throw error;
73
+ }
74
+ }
75
+ async#cloneRepository(workspace) {
76
+ const repository = LibraryRunner.libraryRepository;
77
+ const version = await this.#installedAkanVersion(workspace);
78
+ const tag = version === "unknown" ? null : `v${version}`;
79
+ const branch = tag && await this.#hasTag(workspace, tag) ? ["--branch", tag] : [];
80
+ if (!branch.length) {
81
+ const reason = tag ? `akanjs ${version} has no ${tag} tag` : "akanjs is not installed in this workspace";
82
+ workspace.logger.warn(`${reason}; installing libraries from the default branch of ${repository}, which may expect a newer akanjs`);
83
+ }
84
+ if (await workspace.exists(LibraryRunner.#cloneDir))
85
+ await workspace.removeDir(LibraryRunner.#cloneDir);
86
+ await workspace.spawn("git", ["clone", "--depth", "1", ...branch, repository, LibraryRunner.#cloneDir]);
87
+ const sha = await workspace.spawn("git", ["-C", LibraryRunner.#cloneDir, "rev-parse", "HEAD"]);
88
+ return { origin: repository, sha: sha.trim().slice(0, 12) };
89
+ }
62
90
  async#copyLibraryFromRepository(workspace, libName) {
63
- await workspace.mkdir("node_modules/.akan");
64
- if (await workspace.exists("node_modules/.akan/akanjs"))
65
- await workspace.removeDir("node_modules/.akan/akanjs");
66
- await workspace.exec(`cd node_modules/.akan && git clone ${LibraryRunner.libraryRepository}`);
67
- await workspace.cp(`node_modules/.akan/akanjs/libs/${libName}`, `libs/${libName}`);
68
- const sha = await workspace.spawn("git", ["-C", "node_modules/.akan/akanjs", "rev-parse", "HEAD"]);
69
- return { origin: LibraryRunner.libraryRepository, sha: sha.trim().slice(0, 12) };
91
+ const cloned = this.#clones.get(workspace.workspaceRoot);
92
+ const source = cloned && await workspace.exists(LibraryRunner.#cloneDir) ? cloned : await this.#cloneRepository(workspace);
93
+ this.#clones.set(workspace.workspaceRoot, source);
94
+ await workspace.cp(`${LibraryRunner.#cloneDir}/libs/${libName}`, `libs/${libName}`);
95
+ return source;
70
96
  }
71
97
  async installLibrary(workspace, libName) {
72
98
  const source = await this.#copyInstalledLibrary(workspace, libName) ?? await this.#copyLibraryFromRepository(workspace, libName);
@@ -39,18 +39,21 @@ import {
39
39
  import {
40
40
  runner,
41
41
  script,
42
+ markCliErrorPrinted,
42
43
  assertPromptable
43
- } from "./index-jw1zm273.js";
44
+ } from "./index-p4dnj2wc.js";
44
45
  import {
46
+ AppInfo,
47
+ CommandExecutionError,
45
48
  WorkspaceExecutor,
46
49
  AppExecutor,
47
50
  LibExecutor,
48
51
  PkgExecutor
49
- } from "./index-va06nr10.js";
52
+ } from "./index-rr7jk14m.js";
50
53
  import {
51
54
  DesktopServerStage,
52
55
  UpdateUploader
53
- } from "./index-vk0pa0mn.js";
56
+ } from "./index-ekpp5tax.js";
54
57
  import {
55
58
  resolveMobileTargets,
56
59
  resolveAppId
@@ -59,17 +62,17 @@ import {
59
62
  NativePublicEnv,
60
63
  UpdatePackFolder,
61
64
  NativeApp
62
- } from "./index-g1mbppa9.js";
65
+ } from "./index-z9xepn8t.js";
63
66
  import {
64
67
  LibraryScript
65
- } from "./index-pydbnfez.js";
68
+ } from "./index-qkcwsg6r.js";
66
69
  import {
67
70
  stripAnsi
68
71
  } from "./index-7md2g9vw.js";
69
72
  import {
70
73
  SlicePlanner,
71
74
  formatSlicePlan
72
- } from "./index-35hc95h5.js";
75
+ } from "./index-fmder14z.js";
73
76
  import {
74
77
  openBrowser
75
78
  } from "./index-9dp031by.js";
@@ -1896,7 +1899,7 @@ ${uniqueCandidates.map((candidate) => ` - ${candidate}`).join(`
1896
1899
 
1897
1900
  // pkgs/@akanjs/cli/application/application.runner.ts
1898
1901
  import { Logger as Logger3, toError } from "akanjs/common";
1899
- var loadBuildRunner = async () => (await import("./applicationBuildRunner-dj0xkrep.js")).ApplicationBuildRunner;
1902
+ var loadBuildRunner = async () => (await import("./applicationBuildRunner-9cnnsdm5.js")).ApplicationBuildRunner;
1900
1903
  var loadPrompts = async () => await import("@inquirer/prompts");
1901
1904
 
1902
1905
  class ApplicationRunner extends runner("application") {
@@ -1938,8 +1941,12 @@ class ApplicationRunner extends runner("application") {
1938
1941
  const scriptPath = `script/${scriptName}.ts`;
1939
1942
  if (!await app.exists(scriptPath))
1940
1943
  throw new Error(`Script file not found: apps/${app.name}/${scriptPath}`);
1941
- await app.spawn("bun", [scriptPath], {
1942
- env: app.getCommandEnv({ AKAN_COMMAND_TYPE: "script", ...await app.getDatabaseModeEnv() }),
1944
+ await this.#spawnFromRoot(app, "script", [`${app.cwdPath}/${scriptPath}`]);
1945
+ }
1946
+ async#spawnFromRoot(app, commandType, args) {
1947
+ await app.spawn("bun", args, {
1948
+ cwd: app.workspace.workspaceRoot,
1949
+ env: app.getCommandEnv({ AKAN_COMMAND_TYPE: commandType, ...await app.getDatabaseModeEnv() }),
1943
1950
  stdio: "inherit"
1944
1951
  });
1945
1952
  }
@@ -2026,10 +2033,7 @@ try {
2026
2033
  await server.stop();
2027
2034
  }
2028
2035
  `;
2029
- await app.spawn("bun", ["-e", code], {
2030
- env: app.getCommandEnv({ AKAN_COMMAND_TYPE: "console", ...await app.getDatabaseModeEnv() }),
2031
- stdio: "inherit"
2032
- });
2036
+ await this.#spawnFromRoot(app, "console", ["-e", code]);
2033
2037
  }
2034
2038
  async transferDatabase(app, direction, dir) {
2035
2039
  const serverPath = `${app.cwdPath}/server.ts`;
@@ -2048,16 +2052,55 @@ try {
2048
2052
  await server.stop();
2049
2053
  }
2050
2054
  `;
2051
- await app.spawn("bun", ["-e", code], {
2052
- env: app.getCommandEnv({ AKAN_COMMAND_TYPE: "script", ...await app.getDatabaseModeEnv() }),
2053
- stdio: "inherit"
2055
+ await this.#spawnFromRoot(app, "script", ["-e", code]);
2056
+ }
2057
+ async migrate(app, argv) {
2058
+ const serverPath = `${app.cwdPath}/server.ts`;
2059
+ if (!await app.exists("server.ts"))
2060
+ throw new Error(`Server file not found: apps/${app.name}/server.ts`);
2061
+ const code = `
2062
+ const argv = ${JSON.stringify(argv)};
2063
+ let loaded;
2064
+ try {
2065
+ loaded = await import(${JSON.stringify(serverPath)});
2066
+ } catch (error) {
2067
+ console.error(error);
2068
+ const { MigrationCommand } = await import("akanjs/server");
2069
+ process.exitCode = await MigrationCommand.print(MigrationCommand.failure(null, error), MigrationCommand.jsonOf(argv));
2070
+ }
2071
+ if (loaded) process.exitCode = await loaded.migrations.command(loaded.server, argv, ${JSON.stringify(`akan migrate ${app.name}`)});
2072
+ `;
2073
+ try {
2074
+ await this.#spawnFromRoot(app, "script", ["-e", code]);
2075
+ } catch (error) {
2076
+ if (!(error instanceof CommandExecutionError) || error.code === null)
2077
+ throw error;
2078
+ process.exitCode = error.code;
2079
+ }
2080
+ }
2081
+ async createMigration(app, migrationName, now = new Date) {
2082
+ const words = migrationName.split(/[^A-Za-z0-9]+/).filter(Boolean);
2083
+ const name = words.map((word, idx) => (idx ? word.charAt(0).toUpperCase() : word.charAt(0).toLowerCase()) + word.slice(1)).join("");
2084
+ if (!/^[A-Za-z][A-Za-z0-9]*$/.test(name))
2085
+ throw new Error(`"${migrationName}" is no migration name; name what it does in camelCase, e.g. bizLicenseOwnership`);
2086
+ const migrationId = `${now.toISOString().replace(/\D/g, "").slice(0, 12)}_${name}`;
2087
+ const filePath = `${AppInfo.migrationDir}/${migrationId}.ts`;
2088
+ if (await app.exists(filePath))
2089
+ throw new Error(`apps/${app.name}/${filePath} already exists`);
2090
+ const title = name.replace(/([a-z0-9])([A-Z])/g, "$1 $2").toLowerCase();
2091
+ await app.applyTemplate({
2092
+ basePath: AppInfo.migrationDir,
2093
+ template: "migration",
2094
+ dict: { migrationId, title: title.charAt(0).toUpperCase() + title.slice(1) },
2095
+ overwrite: false
2054
2096
  });
2097
+ return migrationId;
2055
2098
  }
2056
2099
  async typecheck(app, options = {}) {
2057
2100
  await new (await loadBuildRunner())(app).typecheck(options);
2058
2101
  }
2059
2102
  async typecheckLibrary(lib, options = {}) {
2060
- const { ProjectTypecheck } = await import("./projectTypecheck-f534enqj.js");
2103
+ const { ProjectTypecheck } = await import("./projectTypecheck-87k6z6ab.js");
2061
2104
  const root = lib.workspace.workspaceRoot;
2062
2105
  await new ProjectTypecheck(lib.cwdPath, root, { ...process.env, AKAN_WORKSPACE_ROOT: root }).run([
2063
2106
  "../../server.ts",
@@ -3339,6 +3382,14 @@ class ApplicationScript extends script("application", [ApplicationRunner, Librar
3339
3382
  await app.scanSync();
3340
3383
  await this.applicationRunner.runConsole(app);
3341
3384
  }
3385
+ async migrate(app, argv) {
3386
+ await app.scanSync();
3387
+ await this.applicationRunner.migrate(app, argv);
3388
+ }
3389
+ async createMigration(app, migrationName) {
3390
+ const migrationId = await this.applicationRunner.createMigration(app, migrationName);
3391
+ Logger6.rawLog(`Created apps/${app.name}/script/migration/${migrationId}.ts; plan it with \`akan migrate ${app.name} plan ${migrationId}\``);
3392
+ }
3342
3393
  async logs(app, options) {
3343
3394
  await this.applicationRunner.runLogs(app, options);
3344
3395
  }
@@ -3359,6 +3410,7 @@ class ApplicationScript extends script("application", [ApplicationRunner, Librar
3359
3410
  } catch (error) {
3360
3411
  Logger6.rawLog(`${app.name} build failed in dist/apps/${app.name}`, undefined, "error");
3361
3412
  Logger6.rawLog(ApplicationBuildReporter.formatError(error), undefined, "error");
3413
+ markCliErrorPrinted(error);
3362
3414
  throw error;
3363
3415
  }
3364
3416
  }
@@ -3381,12 +3433,16 @@ class ApplicationScript extends script("application", [ApplicationRunner, Librar
3381
3433
  } catch (error) {
3382
3434
  spinner.fail(`${exec.name} typecheck failed`);
3383
3435
  Logger6.rawLog(ApplicationBuildReporter.formatError(error), undefined, "error");
3436
+ markCliErrorPrinted(error);
3384
3437
  throw error;
3385
3438
  }
3386
3439
  }
3387
3440
  async test(exec, { write = true } = {}) {
3388
3441
  if (exec instanceof LibExecutor) {
3389
- await this.libraryScript.syncLibrary(exec);
3442
+ if (write)
3443
+ await this.libraryScript.syncLibrary(exec);
3444
+ else
3445
+ await exec.scan({ write: false });
3390
3446
  exec.spinning(`Preparing ${exec.name}...`).succeed(`${exec.name} prepared`);
3391
3447
  await this.applicationRunner.test(exec);
3392
3448
  return;
@@ -3635,7 +3691,7 @@ class ApplicationScript extends script("application", [ApplicationRunner, Librar
3635
3691
  await Promise.all(shares.map(async (share) => await share.close()));
3636
3692
  }, "Abandoning the tunnel release; the shares expire on their own.");
3637
3693
  await Promise.all(apps.map(async (app) => {
3638
- const { TunnelShare } = await import("./TunnelShare-661cxz5e.js");
3694
+ const { TunnelShare } = await import("./TunnelShare-zmq6bbar.js");
3639
3695
  const share = await TunnelShare.open(app, { workspace: app.workspace });
3640
3696
  shares.push(share);
3641
3697
  urls.set(app.name, share.url);
@@ -519,7 +519,7 @@ var DEFAULT_OPTIMIZE_IMPORTS = [
519
519
  "@material-ui/icons @tabler/icons-react mui-core react-icons/*"
520
520
  ].flatMap((line) => line.split(" "));
521
521
  var WORKSPACE_BARREL_FACETS = ["ui", "webkit", "common", "client", "server"];
522
- var DEFAULT_DOCKER_IMAGE = "oven/bun:1-slim";
522
+ var DEFAULT_DOCKER_IMAGE = "oven/bun:1.4.4-slim";
523
523
  var SSR_RUNTIME_PACKAGES = ["react", "react-dom", "react-server-dom-webpack"];
524
524
  var DEFAULT_AKAN_IMAGE_CONFIG = {
525
525
  deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
@@ -1344,8 +1344,9 @@ var IMPLICIT_LAYOUT_DIR = path6.join(".akan", "generated", "root-layouts");
1344
1344
  var IMPLICIT_DICT_DIR = path6.join(".akan", "generated", "dict");
1345
1345
  var IMPLICIT_OVERRIDES_DIR = path6.join(".akan", "generated", "overrides");
1346
1346
  var OVERRIDES_KEY_RE = /^\.\/(.+\/)?_overrides\.(tsx|ts|jsx|js)$/;
1347
+ var posixRelative = (fromDir, toAbsPath) => path6.relative(fromDir, toAbsPath).split(path6.sep).join("/");
1347
1348
  var importSpecifier = (fromAbsPath, toAbsPath) => {
1348
- const rel = path6.relative(path6.dirname(fromAbsPath), toAbsPath).split(path6.sep).join("/");
1349
+ const rel = posixRelative(path6.dirname(fromAbsPath), toAbsPath);
1349
1350
  return rel.startsWith(".") ? rel : `./${rel}`;
1350
1351
  };
1351
1352
  async function writeGeneratedOverridesLayoutFile(opts) {
@@ -1449,15 +1450,15 @@ async function writeGeneratedRootLayoutFile(opts) {
1449
1450
  void st;
1450
1451
  ` : `import "@apps/${opts.appName}/client";
1451
1452
  `;
1452
- const inheritedLabel = inheritedSourceAbsPath ? path6.relative(opts.appCwdPath, inheritedSourceAbsPath) : "";
1453
+ const inheritedLabel = inheritedSourceAbsPath ? posixRelative(opts.appCwdPath, inheritedSourceAbsPath) : "";
1453
1454
  const inheritedImport = inheritedSourceSpecifier ? `import * as inheritedModule from ${JSON.stringify(inheritedSourceSpecifier)};
1454
- const inheritedLayout = resolveRouteModule(inheritedModule as never, ${JSON.stringify(inheritedLabel)}).module as LayoutModule;
1455
+ const inheritedLayout = assertGuardOnChain(${JSON.stringify(inheritedLabel)}, resolveRouteModule(inheritedModule as never, ${JSON.stringify(inheritedLabel)})).module as LayoutModule;
1455
1456
  ` : `const inheritedLayout: LayoutModule = {};
1456
1457
  `;
1457
1458
  const prefix = opts.boundary.segments.find((segment) => !/^\(.+\)$/.test(segment)) ?? null;
1458
- const userLabel = opts.boundary.sourceAbsPath ? path6.relative(opts.appCwdPath, opts.boundary.sourceAbsPath) : "";
1459
+ const userLabel = opts.boundary.sourceAbsPath ? posixRelative(opts.appCwdPath, opts.boundary.sourceAbsPath) : "";
1459
1460
  const userImport = sourceSpecifier ? `import * as userModule from ${JSON.stringify(sourceSpecifier)};
1460
- const userLayout = resolveRouteModule(userModule as never, ${JSON.stringify(userLabel)}).module as LayoutModule;
1461
+ const userLayout = assertGuardOnChain(${JSON.stringify(userLabel)}, resolveRouteModule(userModule as never, ${JSON.stringify(userLabel)})).module as LayoutModule;
1461
1462
  const UserLayout = userLayout.default as (props: LayoutProps) => ReactNode | Promise<ReactNode>;
1462
1463
  ` : `const UserLayout = ({ children }: LayoutProps) => children;
1463
1464
  const userLayout: LayoutModule = {};
@@ -1473,6 +1474,7 @@ const userLayout: LayoutModule = {};
1473
1474
  const layoutChild = isAsyncUserLayout ? "{layout}" : userLayoutElement;
1474
1475
  const layoutReturn = isAsyncUserLayout ? "layout" : userLayoutElement;
1475
1476
  const headLayouts = opts.includeSystemProvider ? "[inheritedLayout, userLayout]" : "[userLayout]";
1477
+ const guardExport = opts.includeSystemProvider ? "export const guard = RouteGuards.compose(inheritedLayout.guard, userLayout.guard);" : "export const guard = userLayout.guard;";
1476
1478
  const layoutExports = `export async function generateHead(props: PageProps) {
1477
1479
  const heads = await Promise.all(
1478
1480
  ${headLayouts}.map((layout) => (layout.generateHead ? layout.generateHead(props) : layout.head)),
@@ -1484,13 +1486,15 @@ export const NotFound = userLayout.NotFound ?? inheritedLayout.NotFound;
1484
1486
  export const Error = userLayout.Error ?? inheritedLayout.Error;
1485
1487
  export const pageConfig = userLayout.pageConfig ?? inheritedLayout.pageConfig;
1486
1488
  export const Loading = userLayout.Loading;
1489
+ ${guardExport}
1487
1490
 
1488
1491
  ${layoutSignature}({ children, params, searchParams }: LayoutProps) {
1489
1492
  ${layoutBinding} return `;
1490
1493
  const source = opts.includeSystemProvider ? `import type { LayoutModule, LayoutProps, PageProps } from "akanjs/client";
1491
- import { loadFonts, resolveRouteModule, RouteHead } from "akanjs/client";
1494
+ import { assertGuardOnChain, loadFonts, RouteGuards, resolveRouteModule, RouteHead } from "akanjs/client";
1492
1495
  import type { ReactNode } from "react";
1493
1496
  import { System } from "akanjs/ui";
1497
+ import type { McpAppRootProps } from "akanjs/webkit";
1494
1498
  import { env } from "@apps/${opts.appName}/env/env.client";
1495
1499
  import { allDictionary } from ${JSON.stringify(dictMacroSpecifier)};
1496
1500
  ${clientImport}${inheritedImport}${userImport}
@@ -1517,15 +1521,31 @@ ${layoutExports}(
1517
1521
  className={defaultFontClassName}
1518
1522
  layoutStyle={userLayout.layoutStyle ?? inheritedLayout.layoutStyle}
1519
1523
  reconnect={userLayout.reconnect ?? inheritedLayout.reconnect ?? false}
1520
- wsConnect={userLayout.wsConnect ?? inheritedLayout.wsConnect ?? true}
1524
+ wsConnect={userLayout.wsConnect ?? inheritedLayout.wsConnect}
1521
1525
  allDictionary={process.env.AKAN_PUBLIC_RENDER_ENV === "ssr" ? allDictionary : undefined}
1522
1526
  >
1523
1527
  ${layoutChild}
1524
1528
  </System.Provider>
1525
1529
  );
1526
1530
  }
1531
+
1532
+ export function McpAppRoot({ children, params, path }: McpAppRootProps) {
1533
+ return (
1534
+ <System.App
1535
+ params={params}
1536
+ path={path}
1537
+ env={env}
1538
+ theme={theme}
1539
+ viewport={viewport}
1540
+ fonts={loadFonts(userFonts)}
1541
+ className={defaultFontClassName}
1542
+ >
1543
+ {children}
1544
+ </System.App>
1545
+ );
1546
+ }
1527
1547
  ` : `import type { LayoutModule, LayoutProps, PageProps } from "akanjs/client";
1528
- import { resolveRouteModule, RouteHead } from "akanjs/client";
1548
+ import { assertGuardOnChain, resolveRouteModule, RouteHead } from "akanjs/client";
1529
1549
  import type { ReactNode } from "react";
1530
1550
  ${inheritedImport}${userImport}
1531
1551
  ${layoutExports}${layoutReturn};
@@ -2251,6 +2271,7 @@ var resolveRepoName = (workspaceRoot) => {
2251
2271
  };
2252
2272
 
2253
2273
  // pkgs/@akanjs/devkit/scanInfo.ts
2274
+ import { createHash } from "crypto";
2254
2275
  import path11 from "path";
2255
2276
 
2256
2277
  // pkgs/@akanjs/devkit/workspaceLayout.ts
@@ -2574,10 +2595,13 @@ class ScanInfo {
2574
2595
  var isAkanFrameworkDependency = (dep) => dep === "akanjs" || dep.startsWith("akanjs/");
2575
2596
 
2576
2597
  class AppInfo extends ScanInfo {
2598
+ static migrationDir = "script/migration";
2599
+ static #migrationIdRe = /^\d{12}_[A-Za-z][A-Za-z0-9]*$/;
2577
2600
  type = "app";
2578
2601
  exec;
2579
2602
  akanConfig;
2580
2603
  libDeps;
2604
+ migrations;
2581
2605
  static appInfos = new Map;
2582
2606
  static async fromExecutor(exec, options = {}) {
2583
2607
  const existingAppInfo = AppInfo.appInfos.get(exec.name);
@@ -2589,16 +2613,20 @@ class AppInfo extends ScanInfo {
2589
2613
  const libExecutor = LibExecutor.from(exec, libName);
2590
2614
  LibInfo.libInfos.set(libName, await LibInfo.fromExecutor(libExecutor));
2591
2615
  }));
2592
- const libDeps = await AppInfo.#getAllLibDeps(exec, scanResult.libDeps);
2593
- const appInfo = new AppInfo(exec, scanResult, libDeps);
2616
+ const [libDeps, migrations] = await Promise.all([
2617
+ AppInfo.#getAllLibDeps(exec, scanResult.libDeps),
2618
+ AppInfo.scanMigrations(exec)
2619
+ ]);
2620
+ const appInfo = new AppInfo(exec, scanResult, libDeps, migrations);
2594
2621
  AppInfo.appInfos.set(exec.name, appInfo);
2595
2622
  return appInfo;
2596
2623
  }
2597
- constructor(exec, scanResult, libDeps) {
2624
+ constructor(exec, scanResult, libDeps, migrations = []) {
2598
2625
  super(scanResult);
2599
2626
  this.exec = exec;
2600
2627
  this.akanConfig = scanResult.akanConfig;
2601
2628
  this.libDeps = libDeps;
2629
+ this.migrations = migrations;
2602
2630
  }
2603
2631
  getScanResult() {
2604
2632
  return this.scanResult;
@@ -2606,6 +2634,18 @@ class AppInfo extends ScanInfo {
2606
2634
  setRoutes(routes) {
2607
2635
  this.scanResult.routes = routes;
2608
2636
  }
2637
+ static async scanMigrations(exec) {
2638
+ const files = (await exec.readdir(AppInfo.migrationDir)).filter((file) => file.endsWith(".ts") && !/\.(test|spec|d)\.ts$/.test(file));
2639
+ return await Promise.all(files.map(async (file) => {
2640
+ const id = file.slice(0, -".ts".length);
2641
+ if (!AppInfo.#migrationIdRe.test(id))
2642
+ throw new Error(`${AppInfo.migrationDir}/${file}: a migration is named <yyyyMMddHHmm>_<camelName>.ts; create one with \`akan create-migration\``);
2643
+ const source = (await exec.readFile(`${AppInfo.migrationDir}/${file}`)).replace(/^\uFEFF/, "").replaceAll(`\r
2644
+ `, `
2645
+ `);
2646
+ return { id, checksum: createHash("sha256").update(source).digest("hex") };
2647
+ }));
2648
+ }
2609
2649
  static async#getAllLibDeps(exec, libDeps, libSet = new Set) {
2610
2650
  await Promise.all(libDeps.map(async (libName) => {
2611
2651
  if (libSet.has(libName))
@@ -2922,6 +2962,15 @@ var execEmoji = {
2922
2962
  module: "\u2699\uFE0F",
2923
2963
  default: "\u2708\uFE0F"
2924
2964
  };
2965
+ var parseEnvValue = (value) => {
2966
+ const [, quote, inner] = value.match(/^(["'`])((?:\\.|(?!\1)[^\\])*)\1/) ?? [];
2967
+ if (!quote)
2968
+ return value.replace(/#.*/, "").trim();
2969
+ if (quote !== '"')
2970
+ return inner;
2971
+ return inner.replace(/\\(.)/g, (pair, char) => char === "n" ? `
2972
+ ` : char === "r" ? "\r" : pair);
2973
+ };
2925
2974
  var parseEnvFile = (envPath) => {
2926
2975
  const env = {};
2927
2976
  const content = (() => {
@@ -2940,11 +2989,7 @@ var parseEnvFile = (envPath) => {
2940
2989
  if (separatorIndex <= 0)
2941
2990
  continue;
2942
2991
  const key = normalized.slice(0, separatorIndex).trim();
2943
- let value = normalized.slice(separatorIndex + 1).trim();
2944
- if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
2945
- value = value.slice(1, -1);
2946
- }
2947
- env[key] = value;
2992
+ env[key] = parseEnvValue(normalized.slice(separatorIndex + 1).trim());
2948
2993
  }
2949
2994
  return env;
2950
2995
  };
@@ -3741,7 +3786,7 @@ class SysExecutor extends Executor {
3741
3786
  class AppExecutor extends SysExecutor {
3742
3787
  static #routeSourceValidator = null;
3743
3788
  static async#getRouteSourceValidator() {
3744
- AppExecutor.#routeSourceValidator ??= (await import("./routeSourceValidator-7ycnfz0e.js")).RouteSourceValidator;
3789
+ AppExecutor.#routeSourceValidator ??= (await import("./routeSourceValidator-6jd0q6r6.js")).RouteSourceValidator;
3745
3790
  return AppExecutor.#routeSourceValidator;
3746
3791
  }
3747
3792
  dist;
@@ -4225,7 +4270,7 @@ class PkgExecutor extends Executor {
4225
4270
  default: "./index.ts"
4226
4271
  }
4227
4272
  },
4228
- engines: { bun: ">=1.4.0" },
4273
+ engines: { bun: ">=1.4.4" },
4229
4274
  ...dependencyMaps
4230
4275
  };
4231
4276
  await Promise.all([this.dist.writeJson("package.json", distPkgJson), this.writeJson("package.json", distPkgJson)]);
@@ -4268,4 +4313,4 @@ class ModuleExecutor extends Executor {
4268
4313
  }
4269
4314
  }
4270
4315
 
4271
- export { AGENT_BLOCK_START, AGENT_BLOCK_END, stampBlockVersion, extractBlockVersion, readDevkitVersion, upsertAgentBlock, extractAgentBlock, renderRecipeEntries, collectScopeRecipeSources, renderScopeAgentBlock, CLAUDE_COMMENT_RULE, binPlatforms, ServerEnvProfile, AkanAppConfig, AkanWorkspaceConfig, AsyncDefaultExportDetector, resolveSsrPageEntriesForApp, CodegenLock, Linter, LibSource, formatLibStatuses, rootAllowedFiles, rootAllowedDirs, isAllowedLibFacetRootFile, libFacetRootHintOf, barrelFacetDirs, facetIndexShadowOf, rootEntryHintOf, isScannedRootEntry, AppInfo, Spinner, ProjectTypecheck2, Executor, WorkspaceExecutor, SysExecutor, AppExecutor, LibExecutor, PkgExecutor, ModuleExecutor };
4316
+ export { AGENT_BLOCK_START, AGENT_BLOCK_END, stampBlockVersion, extractBlockVersion, readDevkitVersion, upsertAgentBlock, extractAgentBlock, renderRecipeEntries, collectScopeRecipeSources, renderScopeAgentBlock, CLAUDE_COMMENT_RULE, binPlatforms, ServerEnvProfile, AkanAppConfig, AkanWorkspaceConfig, AsyncDefaultExportDetector, resolveSsrPageEntriesForApp, CodegenLock, Linter, LibSource, formatLibStatuses, rootAllowedFiles, rootAllowedDirs, isAllowedLibFacetRootFile, libFacetRootHintOf, barrelFacetDirs, facetIndexShadowOf, rootEntryHintOf, isScannedRootEntry, AppInfo, Spinner, ProjectTypecheck2, CommandExecutionError, Executor, WorkspaceExecutor, SysExecutor, AppExecutor, LibExecutor, PkgExecutor, ModuleExecutor };
@@ -22,26 +22,26 @@ import {
22
22
  renderWorkflowApply,
23
23
  renderWorkflowValidation,
24
24
  renderWorkflowRunArtifact
25
- } from "./index-trpasv9q.js";
25
+ } from "./index-ynqxpwx6.js";
26
26
  import {
27
27
  AkanContextAnalyzer
28
- } from "./index-5edzv8fn.js";
28
+ } from "./index-z6v7k9sb.js";
29
29
  import {
30
30
  CommandContainer,
31
31
  runner
32
- } from "./index-jw1zm273.js";
32
+ } from "./index-p4dnj2wc.js";
33
33
  import {
34
34
  ModuleScript
35
- } from "./index-fmzcs8v6.js";
35
+ } from "./index-b5vptvnt.js";
36
36
  import {
37
37
  PrimitiveScript
38
- } from "./index-awbdfcf2.js";
38
+ } from "./index-zn6bn1s2.js";
39
39
  import {
40
40
  spawnShell
41
- } from "./index-j4mkhz93.js";
41
+ } from "./index-qfzfaq96.js";
42
42
  import {
43
43
  ScalarScript
44
- } from "./index-1p98exm2.js";
44
+ } from "./index-sng3vt0p.js";
45
45
 
46
46
  // pkgs/@akanjs/cli/workflow/workflow.runner.ts
47
47
  import { mkdir, readFile, writeFile } from "fs/promises";
@@ -2,12 +2,12 @@
2
2
  import {
3
3
  runner,
4
4
  script
5
- } from "./index-jw1zm273.js";
5
+ } from "./index-p4dnj2wc.js";
6
6
  import {
7
7
  generatedFilesForSync,
8
8
  createPassedPrimitiveReport,
9
9
  scalarChangedFiles
10
- } from "./index-trpasv9q.js";
10
+ } from "./index-ynqxpwx6.js";
11
11
  import {
12
12
  pluralizeName
13
13
  } from "./index-nz8prx9g.js";
@@ -2,13 +2,13 @@
2
2
  import {
3
3
  runner,
4
4
  script
5
- } from "./index-jw1zm273.js";
5
+ } from "./index-p4dnj2wc.js";
6
6
  import {
7
7
  FileSys2
8
8
  } from "./index-52w0fvh8.js";
9
9
  import {
10
10
  PkgExecutor
11
- } from "./index-va06nr10.js";
11
+ } from "./index-rr7jk14m.js";
12
12
  import {
13
13
  TypeScriptDependencyScanner2
14
14
  } from "./index-tvehn2sp.js";
@@ -111,6 +111,13 @@ class PackageRunner extends runner("package") {
111
111
  "@akanjs/devkit",
112
112
  "create-akan-workspace"
113
113
  ];
114
+ static #bundledRuntimeDependencies = {
115
+ "@akanjs/cli": ["@akanjs/devkit", "@akanjs/native"],
116
+ akanjs: ["use-agentic", "@akanjs/native"]
117
+ };
118
+ static #unpublishedPackages = [
119
+ ...new Set(Object.values(PackageRunner.#bundledRuntimeDependencies).flat())
120
+ ].filter((name) => !PackageRunner.publishableAkanPackages.includes(name));
114
121
  async version(workspace, { log = true } = {}) {
115
122
  const pkgJson = process.env.USE_AKANJS_PKGS === "true" ? await FileSys2.readJson(`${workspace?.workspaceRoot ?? process.cwd()}/pkgs/akanjs/package.json`) : await this.#getInstalledPackageJson();
116
123
  const version = pkgJson.name === "akanjs" ? pkgJson.version : pkgJson.dependencies?.akanjs ?? pkgJson.version;
@@ -174,12 +181,7 @@ class PackageRunner extends runner("package") {
174
181
  "tailwind-scrollbar"
175
182
  ].filter((dep) => dep !== "akanjs" && dep !== "@akanjs/devkit");
176
183
  }
177
- const packageBundledRuntimeDependencies = {
178
- "@akanjs/cli": ["@akanjs/devkit", "@akanjs/native"],
179
- "@akanjs/devkit": ["@akanjs/native"],
180
- akanjs: ["use-agentic", "@akanjs/native"]
181
- };
182
- const bundledRuntimeDeps = new Set(packageBundledRuntimeDependencies[pkg.name] ?? []);
184
+ const bundledRuntimeDeps = new Set(PackageRunner.#bundledRuntimeDependencies[pkg.name] ?? []);
183
185
  const forcedRuntimeDeps = packageRuntimeDependencies[pkg.name] ?? [];
184
186
  const forcedRuntimeDevDeps = packageRuntimeDevDependencies[pkg.name] ?? [];
185
187
  const [rootPackageJson, pkgJson] = await Promise.all([pkg.workspace.getPackageJson(), pkg.getPackageJson()]);
@@ -276,6 +278,20 @@ class PackageRunner extends runner("package") {
276
278
  ` + `${failures.sort((a, b) => a < b ? -1 : a > b ? 1 : 0).join(`
277
279
  `)}
278
280
  ` + `Add the missing "exports" entries: a bare file facet needs "./*": "./*.ts", a directory facet ` + `needs its own "./name": "./name/index.ts", and "./*.ts": "./*.ts" keeps an already-suffixed ` + `specifier from gaining a second extension.`);
281
+ }
282
+ async#verifyDistImportsPublished(pkg) {
283
+ const imports = await this.#collectDistAkanImports(pkg.dist.cwdPath, PackageRunner.#unpublishedPackages);
284
+ if (!imports.size)
285
+ return;
286
+ const failures = [...imports].map(([specifier, importers]) => {
287
+ const files = [...importers].sort();
288
+ const shown = files.slice(0, 3).join(", ") + (files.length > 3 ? ` (+${files.length - 3} more)` : "");
289
+ return ` ${specifier} \u2014 imported by ${shown}`;
290
+ });
291
+ throw new Error(`[package] ${pkg.name} dist imports ${failures.length} specifier(s) of a package that is never published:
292
+ ` + `${failures.sort((a, b) => a < b ? -1 : a > b ? 1 : 0).join(`
293
+ `)}
294
+ ` + "Reach it through a published package that embeds it (akanjs/native/api for @akanjs/native/api), or embed it " + "in this package's build.");
279
295
  }
280
296
  async verifyDistPackage(pkg, {
281
297
  peerExportsMaps = new Map
@@ -308,6 +324,7 @@ class PackageRunner extends runner("package") {
308
324
  }
309
325
  }
310
326
  await this.#verifyDistExportsReachable(pkg, peerExportsMaps);
327
+ await this.#verifyDistImportsPublished(pkg);
311
328
  const packOutput = await pkg.workspace.spawn("npm", ["pack", "--dry-run", "--json", pkg.dist.cwdPath], {
312
329
  cwd: pkg.workspace.workspaceRoot
313
330
  });
@@ -5,15 +5,15 @@ import {
5
5
  CloudApi,
6
6
  CloudUpdates,
7
7
  PipelineSecrets
8
- } from "./index-cpb3nvma.js";
8
+ } from "./index-1f33g2z5.js";
9
9
  import {
10
10
  WorkspaceExecutor,
11
11
  AppExecutor
12
- } from "./index-va06nr10.js";
12
+ } from "./index-rr7jk14m.js";
13
13
  import {
14
14
  runner,
15
15
  assertPromptable
16
- } from "./index-jw1zm273.js";
16
+ } from "./index-p4dnj2wc.js";
17
17
  import {
18
18
  SubspaceConfig
19
19
  } from "./index-4pf8g7ff.js";
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  AppExecutor,
4
4
  LibExecutor
5
- } from "./index-va06nr10.js";
5
+ } from "./index-rr7jk14m.js";
6
6
 
7
7
  // pkgs/@akanjs/devkit/workflow/artifacts.ts
8
8
  import { capitalize } from "akanjs/common";
@@ -10,7 +10,7 @@ import {
10
10
  isScannedRootEntry,
11
11
  AppExecutor,
12
12
  LibExecutor
13
- } from "./index-va06nr10.js";
13
+ } from "./index-rr7jk14m.js";
14
14
  import {
15
15
  FileSys2
16
16
  } from "./index-52w0fvh8.js";
@@ -23,7 +23,7 @@ import {
23
23
  workflowPathsForPlan,
24
24
  workflowRunArtifactPath,
25
25
  workflowSyncDir
26
- } from "./index-trpasv9q.js";
26
+ } from "./index-ynqxpwx6.js";
27
27
 
28
28
  // pkgs/@akanjs/devkit/akanContext.ts
29
29
  import { readdir } from "fs/promises";