@akanjs/cli 3.2.0-rc.0 → 3.2.0-rc.10

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 (98) hide show
  1. package/.build-stamp +2 -1
  2. package/{CodeAgent-h6g8dg3a.js → CodeAgent-fk66n37w.js} +3 -3
  3. package/{CodeTui-n9gacepn.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 +6 -6
  9. package/{application.command-yb8v177e.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-et06ja22.js → cloud.command-ab704p0g.js} +24 -25
  13. package/cloud.script-4p4y0s7e.js +31 -0
  14. package/{code.command-7m67c7zc.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-evr3b35y.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/conventions/core.md +1 -1
  21. package/guidelines/conventions/rules/app.md +3 -0
  22. package/guidelines/conventions/rules/page.md +5 -0
  23. package/guidelines/errorCodes/errorCodes.instruction.md +140 -0
  24. package/guidelines/fieldRule/fieldRule.instruction.md +2 -1
  25. package/guidelines/mcpRule/mcpRule.instruction.md +28 -0
  26. package/guidelines/pageRule/pageRule.instruction.md +5 -0
  27. package/guidelines/runtimeRule/runtimeRule.instruction.md +5 -1
  28. package/guidelines/transportRule/transportRule.instruction.md +5 -0
  29. package/incrementalBuilder.proc.js +8 -7
  30. package/{index-vkzfk7qt.js → index-097bjwvm.js} +40 -30
  31. package/{index-93ewzmp6.js → index-23d8gw08.js} +165 -102
  32. package/{index-p6hjwt2d.js → index-41mfhgq0.js} +72 -26
  33. package/{index-ktb3wcqz.js → index-4k9nv4m3.js} +71 -81
  34. package/{index-ryrm5z2c.js → index-5jwx4bf2.js} +69 -33
  35. package/{index-5w9my9qe.js → index-6eptmk8z.js} +30 -20
  36. package/{index-d4n1wmrz.js → index-6fnrhpn1.js} +8 -4
  37. package/{index-kpdv34rq.js → index-6qtxs86x.js} +10 -7
  38. package/{index-ed6ea0qp.js → index-6z57w95f.js} +1 -1
  39. package/{index-drz9e84d.js → index-7ky4brfy.js} +2 -2
  40. package/{index-8g7tdsk4.js → index-849qvd7t.js} +58 -29
  41. package/{index-1q1cjn8s.js → index-9xh4zvw3.js} +94 -53
  42. package/{index-48d5qsj3.js → index-adj7qmz9.js} +23 -15
  43. package/{index-fjr4d6yd.js → index-apcr1qgk.js} +458 -304
  44. package/{index-8ts9774g.js → index-aybfcx58.js} +9 -4
  45. package/{index-3wjbhj2n.js → index-b3pr4ee6.js} +1 -1
  46. package/{index-tenw3mah.js → index-b4qq3rq0.js} +32 -7
  47. package/{index-thckcabc.js → index-bper31wr.js} +24 -6
  48. package/{index-jdamtr7e.js → index-bxkx0x03.js} +17 -10
  49. package/{index-0fb3cpbt.js → index-c3r23w24.js} +9 -7
  50. package/{index-8pb9yvp8.js → index-dfsa009c.js} +148 -31
  51. package/{index-zpv14wpy.js → index-dsg50er9.js} +3 -3
  52. package/{index-hqrkqxx2.js → index-e5f6czck.js} +46 -7
  53. package/{index-sy481q2x.js → index-frvjq1rd.js} +1 -1
  54. package/{index-abgh0jve.js → index-grt0e6kk.js} +1 -1
  55. package/{index-e3vmjtph.js → index-hf9nvwam.js} +7 -2
  56. package/{index-zxsygkda.js → index-hhagjhkh.js} +7 -7
  57. package/index-j4yvgfhr.js +70 -0
  58. package/{index-s2grpzef.js → index-k2r3hmbz.js} +6 -4
  59. package/{index-7y5yghjg.js → index-nd39rssn.js} +1162 -435
  60. package/{index-6wpaq392.js → index-p4htjyvk.js} +44 -5
  61. package/{index-aj3ehkcx.js → index-p54s83sz.js} +1 -1
  62. package/{index-7xdpww43.js → index-rdx8cyv2.js} +342 -134
  63. package/{index-sr5da35e.js → index-sq9d0jhj.js} +21 -18
  64. package/{index-eajbmk10.js → index-t4d0ckde.js} +2 -2
  65. package/{index-mqntfzv5.js → index-t8h09yjs.js} +7 -2
  66. package/index-va90m8nd.js +25 -0
  67. package/{index-rc5fvqj2.js → index-xfv2p7b5.js} +95 -58
  68. package/{index-w639tvkd.js → index-xgqz3kak.js} +29 -8
  69. package/{index-9tbgb4d8.js → index-xy70tcv4.js} +1 -1
  70. package/{index-mmym5xmb.js → index-z43wddce.js} +5 -3
  71. package/index.js +24 -23
  72. package/{library.command-1gp5qe3r.js → library.command-kc1zahcg.js} +5 -4
  73. package/{localRegistry.command-v3g21rex.js → localRegistry.command-bz2df40m.js} +19 -18
  74. package/{module.command-4xz9he6h.js → module.command-cchwzz9r.js} +12 -7
  75. package/{package.command-s7qpnn1g.js → package.command-qcjajpv8.js} +8 -7
  76. package/package.json +2 -2
  77. package/{page.command-fan34c49.js → page.command-1t86dx8a.js} +4 -3
  78. package/{pipeline.command-ph4fnn9w.js → pipeline.command-2xx9z3d0.js} +3 -2
  79. package/{primitive.command-3fqh8emf.js → primitive.command-mc0x8txr.js} +8 -7
  80. package/{projectTypecheck-vkb40hjc.js → projectTypecheck-tz497yx7.js} +2 -1
  81. package/{quality.command-ecj6exsh.js → quality.command-11rayf5c.js} +7 -6
  82. package/{repair.command-fe9jw719.js → repair.command-8w41vy78.js} +7 -6
  83. package/{scalar.command-cnvfhk0n.js → scalar.command-rvwh98ny.js} +7 -6
  84. package/skills/akan-debug/SKILL.md +7 -3
  85. package/skills/akan-err/SKILL.md +7 -0
  86. package/skills/akan-mcp/SKILL.md +7 -1
  87. package/skills/akan-scaffold/SKILL.md +3 -2
  88. package/skills/akan-transport/SKILL.md +2 -0
  89. package/skills/akan-validate/SKILL.md +1 -0
  90. package/{subspace.command-yxtt3v3e.js → subspace.command-0970n7kd.js} +9 -8
  91. package/{tunnel.command-ggj38mqf.js → tunnel.command-bcy0rtmh.js} +8 -7
  92. package/typecheck.proc.js +5 -2
  93. package/{verify.command-w9ttxkdz.js → verify.command-ynaztxr2.js} +18 -16
  94. package/{workflow.command-ss8devj0.js → workflow.command-yp9ajthb.js} +45 -16
  95. package/{workspace.command-rw1p0xeq.js → workspace.command-e4wfxm86.js} +39 -34
  96. package/TunnelShare-k3ja4w9x.js +0 -14
  97. package/cloud.script-s6rbrwer.js +0 -30
  98. package/context.runner-ms8v1rxy.js +0 -29
@@ -7,18 +7,21 @@ import {
7
7
  AppExecutor,
8
8
  LibExecutor,
9
9
  PkgExecutor
10
- } from "./index-sr5da35e.js";
10
+ } from "./index-sq9d0jhj.js";
11
11
  import {
12
12
  FileSys2
13
13
  } from "./index-bns3wcpc.js";
14
+ import {
15
+ CliError
16
+ } from "./index-j4yvgfhr.js";
14
17
  import {
15
18
  UNAVAILABLE_REDIS_HOST,
16
19
  redisTunnelPolicy,
20
+ backendRecoveryPolicy,
17
21
  BUILDER_MIN_RSS_RECYCLE_INTERVAL_MS,
18
22
  SOURCE_EXTS,
19
23
  shouldRestartBackendByDevPlan,
20
24
  shouldRestartBuilderByDevPlan,
21
- shouldAbandonBackendRecovery,
22
25
  normalizeBackendReportedGeneration,
23
26
  shouldRestartDevHostByDevPlan,
24
27
  devHostStateOf,
@@ -46,28 +49,27 @@ import {
46
49
  filesChangedSince,
47
50
  HmrWatcher,
48
51
  WatchRootResolver
49
- } from "./index-p6hjwt2d.js";
52
+ } from "./index-41mfhgq0.js";
50
53
  import {
51
54
  runner,
52
- ExitCodeError,
53
55
  assertPromptable
54
- } from "./index-93ewzmp6.js";
56
+ } from "./index-23d8gw08.js";
55
57
  import {
56
58
  UpdatePackFolder,
57
59
  UpdateUploader,
58
60
  NativePublicEnv,
59
61
  NativeApp
60
- } from "./index-zpv14wpy.js";
62
+ } from "./index-dsg50er9.js";
61
63
  import {
62
64
  DesktopServerStage
63
- } from "./index-ed6ea0qp.js";
65
+ } from "./index-6z57w95f.js";
64
66
  import {
65
67
  resolveMobileTargets,
66
68
  resolveAppId
67
69
  } from "./index-m9jj544v.js";
68
70
  import {
69
71
  SlicePlanner
70
- } from "./index-sy481q2x.js";
72
+ } from "./index-frvjq1rd.js";
71
73
  import {
72
74
  openBrowser
73
75
  } from "./index-9dp031by.js";
@@ -84,7 +86,7 @@ import path7 from "path";
84
86
 
85
87
  // pkgs/@akanjs/devkit/akanApp/akanApp.host.ts
86
88
  import path4 from "path";
87
- import { Logger as Logger2 } from "akanjs/common";
89
+ import { Logger as Logger2, RestartSchedule as RestartSchedule2 } from "akanjs/common";
88
90
 
89
91
  // pkgs/@akanjs/devkit/createTunnel.ts
90
92
  import { readFileSync } from "fs";
@@ -325,7 +327,7 @@ var createTunnel = async (service, { app, environment, port = service === "postg
325
327
  // pkgs/@akanjs/devkit/incrementalBuilder/incrementalBuilder.host.ts
326
328
  import fs from "fs";
327
329
  import path2 from "path";
328
- import { Logger } from "akanjs/common";
330
+ import { Logger, RestartSchedule } from "akanjs/common";
329
331
  import { CSR_DEV_DIRNAME, CSR_DEV_PATCHING_MARKER, SSR_DEV_DIRNAME } from "akanjs/server/hmr/csrDevManifest";
330
332
  import { MemoryLimit } from "akanjs/server/memoryLimit";
331
333
  var builderMsgTypeSet = new Set([
@@ -344,8 +346,6 @@ var builderMsgTypeSet = new Set([
344
346
  ]);
345
347
 
346
348
  class IncrementalBuilderHost {
347
- static #restartBaseDelayMs = 1000;
348
- static #restartMaxDelayMs = 30000;
349
349
  static #recycleDrainTimeoutMs = 30000;
350
350
  static #devMaxRssBytes = 2048 * 1024 * 1024;
351
351
  logger = new Logger("IncrementalBuilderHost");
@@ -358,8 +358,7 @@ class IncrementalBuilderHost {
358
358
  #onOutput;
359
359
  #proc = null;
360
360
  #status = "stopped";
361
- #restartAttempts = 0;
362
- #restartTimer = null;
361
+ #restart = new RestartSchedule({ min: 1000, max: 30000 });
363
362
  #recycleTimer = null;
364
363
  #recycleRequested = false;
365
364
  #spawnAfterRecycle = false;
@@ -430,7 +429,7 @@ class IncrementalBuilderHost {
430
429
  if (msg.type === "builder-ready" && !this.ready) {
431
430
  this.ready = true;
432
431
  this.#status = "ready";
433
- this.#restartAttempts = 0;
432
+ this.#restart.reset();
434
433
  if (isRestart)
435
434
  this.#startOptions.onRestartReady?.();
436
435
  else
@@ -495,19 +494,15 @@ class IncrementalBuilderHost {
495
494
  } catch {}
496
495
  }
497
496
  #scheduleRestart() {
498
- if (this.#manualStop || this.#restartTimer)
497
+ if (this.#manualStop || this.#restart.pending)
499
498
  return;
500
499
  this.#status = "restarting";
501
- const attempt = this.#restartAttempts;
502
- const delay = Math.min(IncrementalBuilderHost.#restartBaseDelayMs * 2 ** attempt, IncrementalBuilderHost.#restartMaxDelayMs);
503
- this.#restartAttempts = attempt + 1;
504
- this.logger.warn(`builder exited after ready; restarting in ${delay}ms (attempt ${this.#restartAttempts})`);
505
- this.#restartTimer = setTimeout(() => {
506
- this.#restartTimer = null;
500
+ const delay = this.#restart.schedule(() => {
507
501
  if (this.#manualStop)
508
502
  return;
509
503
  this.#spawn(true);
510
- }, delay);
504
+ });
505
+ this.logger.warn(`builder exited after ready; restarting in ${delay}ms (attempt ${this.#restart.attempts})`);
511
506
  }
512
507
  recycle(reason) {
513
508
  if (!this.#proc || this.#status !== "ready" || this.#recycleRequested)
@@ -569,16 +564,13 @@ class IncrementalBuilderHost {
569
564
  this.#inFlight.clear();
570
565
  this.logger.warn(`failing ${lost.length} unanswered builder request(s): ${reason}`);
571
566
  for (const [id, type] of lost)
572
- this.#onMessage({ type: `${type}-res`, id, ok: false, error: reason });
567
+ this.#onMessage({ type: `${type}-res`, id, ok: false, error: reason, kind: "unavailable" });
573
568
  }
574
569
  stop() {
575
570
  this.#manualStop = true;
576
571
  this.#clearRecycle();
577
572
  this.#failInFlight("builder was stopped before answering");
578
- if (this.#restartTimer) {
579
- clearTimeout(this.#restartTimer);
580
- this.#restartTimer = null;
581
- }
573
+ this.#restart.cancel();
582
574
  if (this.#proc)
583
575
  this.#proc.kill();
584
576
  this.#proc = null;
@@ -818,16 +810,12 @@ var backendMsgTypeSet = new Set(["build-route", "build-csr", "build-graph"]);
818
810
  var asMib = (bytes) => Math.round(bytes / 1024 / 1024);
819
811
  var BACKEND_RESTART_DEBOUNCE_MS = 120;
820
812
  var BACKEND_GRACEFUL_TIMEOUT_MS = 8000;
821
- var BACKEND_RECOVERY_BASE_DELAY_MS = 1000;
822
- var BACKEND_RECOVERY_MAX_DELAY_MS = 30000;
823
813
  var BACKEND_STDERR_TAIL_LIMIT = 40;
824
814
  var BUILDER_READY_TIMEOUT_MS = 150000;
825
815
  var BUILDER_START_MAX_ATTEMPTS = 3;
826
816
  var BUILDER_RSS_RECYCLE_QUIET_MS = 750;
827
817
  var BUILDER_RSS_SETTLE_MS = 20000;
828
818
  var PS_RSS_TIMEOUT_MS = 2000;
829
- var BUILDER_RECOVERY_BASE_DELAY_MS = 2000;
830
- var BUILDER_RECOVERY_MAX_DELAY_MS = 60000;
831
819
 
832
820
  class AkanAppHost {
833
821
  app;
@@ -843,8 +831,7 @@ class AkanAppHost {
843
831
  #backendReady = false;
844
832
  #plannedBackendStops = new WeakSet;
845
833
  #restartTimer = null;
846
- #backendRecoveryTimer = null;
847
- #backendRecoveryAttempts = 0;
834
+ #backendRecovery = new RestartSchedule2(backendRecoveryPolicy);
848
835
  #backendGaveUp = false;
849
836
  #backendLifecycleState = "stopped";
850
837
  #pendingRestartReason = null;
@@ -852,8 +839,8 @@ class AkanAppHost {
852
839
  #pendingRecycle = null;
853
840
  #restartFailedAfterApply = null;
854
841
  #stopping = false;
855
- #builderRecoveryTimer = null;
856
- #builderRecoveryAttempts = 0;
842
+ #builderRecovery = new RestartSchedule2({ min: 2000, max: 60000 });
843
+ #abandonBuilderStart = null;
857
844
  #backendStartStatus = null;
858
845
  #backendBuildStatusGeneration = 0;
859
846
  #backendStderrTail = [];
@@ -920,6 +907,7 @@ class AkanAppHost {
920
907
  this.#cancelIdleSuspend();
921
908
  this.#stopIdleWatcher();
922
909
  this.#clearRestartTimers();
910
+ this.#abandonBuilderStart?.(new Error("dev server stopped before the builder was ready"));
923
911
  this.#pendingRestartReason = null;
924
912
  this.#failPendingBuilderMessages("dev server is shutting down");
925
913
  await this.#backendRestart;
@@ -928,10 +916,11 @@ class AkanAppHost {
928
916
  return this;
929
917
  }
930
918
  #clearRestartTimers() {
931
- for (const timer of [this.#restartTimer, this.#backendRecoveryTimer, this.#builderRecoveryTimer])
932
- if (timer)
933
- clearTimeout(timer);
934
- this.#restartTimer = this.#backendRecoveryTimer = this.#builderRecoveryTimer = null;
919
+ if (this.#restartTimer)
920
+ clearTimeout(this.#restartTimer);
921
+ this.#restartTimer = null;
922
+ this.#backendRecovery.cancel();
923
+ this.#builderRecovery.cancel();
935
924
  }
936
925
  kill() {
937
926
  this.stop();
@@ -973,7 +962,7 @@ class AkanAppHost {
973
962
  return;
974
963
  if (msg.type === "backend-ready") {
975
964
  this.#backendReady = true;
976
- this.#backendRecoveryAttempts = 0;
965
+ this.#backendRecovery.reset();
977
966
  this.#setBackendLifecycleState("ready", `pid=${msg.pid}`);
978
967
  this.#recordBackendReadyStatus();
979
968
  this.logger.verbose(`backend ready pid=${msg.pid}`);
@@ -1131,10 +1120,7 @@ class AkanAppHost {
1131
1120
  this.#pendingRestartReason = mergeBackendRestartReasons(this.#pendingRestartReason, reason);
1132
1121
  const pending = this.#pendingRestartReason;
1133
1122
  this.#setBackendLifecycleState("restart-pending", `generation=${pending.generation ?? "(unknown)"} files=${pending.files.length} roles=${pending.roles.join(",") || "(none)"}`);
1134
- if (this.#backendRecoveryTimer) {
1135
- clearTimeout(this.#backendRecoveryTimer);
1136
- this.#backendRecoveryTimer = null;
1137
- }
1123
+ this.#backendRecovery.cancel();
1138
1124
  if (this.#restartTimer)
1139
1125
  clearTimeout(this.#restartTimer);
1140
1126
  this.#restartTimer = setTimeout(() => {
@@ -1153,17 +1139,17 @@ class AkanAppHost {
1153
1139
  }
1154
1140
  async#restartBackend(reason) {
1155
1141
  this.logger.verbose(`[backend-reload] restarting backend generation=${reason.generation ?? "(unknown)"} files=${reason.files.length} roles=${reason.roles.join(",") || "(none)"}`);
1156
- this.#backendRecoveryAttempts = 0;
1142
+ this.#backendRecovery.reset();
1157
1143
  await Promise.all([this.#stopBackend(), this.#backendGraph.refresh()]);
1158
1144
  this.#startBackend({ generation: reason.generation, files: reason.files });
1159
1145
  }
1160
1146
  #scheduleBackendRecovery(reason) {
1161
- if (this.#backendRecoveryTimer || this.#backend)
1147
+ if (this.#backendRecovery.pending || this.#backend)
1162
1148
  return;
1163
- if (shouldAbandonBackendRecovery(this.#backendRecoveryAttempts)) {
1164
- const message = `Backend exited ${this.#backendRecoveryAttempts} times in a row (${reason}); waiting for an edit or a green build to retry.`;
1149
+ if (this.#backendRecovery.exhausted) {
1150
+ const message = `Backend exited ${this.#backendRecovery.attempts} times in a row (${reason}); waiting for an edit or a green build to retry.`;
1165
1151
  this.#backendGaveUp = true;
1166
- this.#setBackendLifecycleState("stopped", `gave up after ${this.#backendRecoveryAttempts} recovery attempts`);
1152
+ this.#setBackendLifecycleState("stopped", `gave up after ${this.#backendRecovery.attempts} recovery attempts`);
1167
1153
  this.logger.error(`[backend-recovery] ${message}`);
1168
1154
  if (this.#backendStderrTail.length > 0) {
1169
1155
  this.logger.error(`[backend-recovery] recent backend stderr:
@@ -1175,30 +1161,27 @@ ${this.#backendStderrTail.join(`
1175
1161
  return;
1176
1162
  }
1177
1163
  this.#setBackendLifecycleState("recovering", reason);
1178
- const attempt = this.#backendRecoveryAttempts;
1179
- const delay = Math.min(BACKEND_RECOVERY_BASE_DELAY_MS * 2 ** attempt, BACKEND_RECOVERY_MAX_DELAY_MS);
1180
- this.#backendRecoveryAttempts = attempt + 1;
1164
+ const delay = this.#backendRecovery.next();
1181
1165
  const failureStatus = this.#recordBackendBuildStatus({
1182
1166
  ok: false,
1183
1167
  files: [],
1184
1168
  message: `Backend exited unexpectedly (${reason}); restarting in ${delay}ms`
1185
1169
  });
1186
1170
  this.#sendOrQueueBuildStatus(failureStatus);
1187
- this.logger.warn(`[backend-recovery] backend exited unexpectedly (${reason}); restarting in ${delay}ms (attempt ${this.#backendRecoveryAttempts})`);
1171
+ this.logger.warn(`[backend-recovery] backend exited unexpectedly (${reason}); restarting in ${delay}ms (attempt ${this.#backendRecovery.attempts})`);
1188
1172
  if (this.#backendStderrTail.length > 0) {
1189
1173
  this.logger.warn(`[backend-recovery] recent backend stderr:
1190
1174
  ${this.#backendStderrTail.join(`
1191
1175
  `)}`);
1192
1176
  }
1193
- this.#backendRecoveryTimer = setTimeout(() => {
1194
- this.#backendRecoveryTimer = null;
1177
+ this.#backendRecovery.arm(delay, () => {
1195
1178
  if (this.#backend)
1196
1179
  return;
1197
1180
  this.#backendGraph.refresh().finally(() => {
1198
1181
  if (!this.#backend)
1199
1182
  this.#startBackend({ generation: failureStatus.generation, files: failureStatus.files });
1200
1183
  });
1201
- }, delay);
1184
+ });
1202
1185
  }
1203
1186
  #enqueueBuilderMessage(message) {
1204
1187
  this.#builderMessageQueue = this.#builderMessageQueue.then(() => this.#handleBuilderMessage(message)).catch((err) => {
@@ -1463,7 +1446,7 @@ ${this.#backendStderrTail.join(`
1463
1446
  this.logger.info(`[idle-suspend] no build activity for ${Math.round(idleMs / 1000)}s; released the builder \u2014 the next edit or route request brings it back`);
1464
1447
  }
1465
1448
  get #restartPending() {
1466
- return !!(this.#pendingRecycle || this.#restartTimer || this.#backendRestart || this.#backendRecoveryTimer || this.#builderRecoveryTimer || this.#rssRecycleReason);
1449
+ return !!(this.#pendingRecycle || this.#restartTimer || this.#backendRestart || this.#backendRecovery.pending || this.#builderRecovery.pending || this.#rssRecycleReason);
1467
1450
  }
1468
1451
  async#startIdleWatcher() {
1469
1452
  try {
@@ -1608,11 +1591,11 @@ ${this.#backendStderrTail.join(`
1608
1591
  }
1609
1592
  #failBuilderRequest(message, error) {
1610
1593
  if (message.type === "build-route")
1611
- this.#sendToBackend({ type: "build-route-res", id: message.id, ok: false, error });
1594
+ this.#sendToBackend({ type: "build-route-res", id: message.id, ok: false, error, kind: "unavailable" });
1612
1595
  else if (message.type === "build-csr")
1613
- this.#sendToBackend({ type: "build-csr-res", id: message.id, ok: false, error });
1596
+ this.#sendToBackend({ type: "build-csr-res", id: message.id, ok: false, error, kind: "unavailable" });
1614
1597
  else if (message.type === "build-graph")
1615
- this.#sendToBackend({ type: "build-graph-res", id: message.id, ok: false, error });
1598
+ this.#sendToBackend({ type: "build-graph-res", id: message.id, ok: false, error, kind: "unavailable" });
1616
1599
  else
1617
1600
  return false;
1618
1601
  return true;
@@ -1707,28 +1690,26 @@ ${this.#backendStderrTail.join(`
1707
1690
  this.#scheduleBuilderRecovery({ generation, files: message.files });
1708
1691
  }
1709
1692
  #scheduleBuilderRecovery(reason) {
1710
- if (this.#builderRecoveryTimer || this.#builder)
1711
- return;
1712
- const attempt = this.#builderRecoveryAttempts;
1713
- const delay = Math.min(BUILDER_RECOVERY_BASE_DELAY_MS * 2 ** attempt, BUILDER_RECOVERY_MAX_DELAY_MS);
1714
- this.#builderRecoveryAttempts = attempt + 1;
1715
- this.logger.warn(`[builder-recovery] builder is down; retrying start in ${delay}ms (attempt ${this.#builderRecoveryAttempts})`);
1716
- this.#builderRecoveryTimer = setTimeout(() => {
1717
- this.#builderRecoveryTimer = null;
1718
- if (this.#builder)
1693
+ if (this.#stopping || this.#builderRecovery.pending || this.#builder)
1694
+ return;
1695
+ const delay = this.#builderRecovery.schedule(() => {
1696
+ if (this.#stopping || this.#builder)
1719
1697
  return;
1720
1698
  this.#recoverBuilder(reason);
1721
- }, delay);
1699
+ });
1700
+ this.logger.warn(`[builder-recovery] builder is down; retrying start in ${delay}ms (attempt ${this.#builderRecovery.attempts})`);
1722
1701
  }
1723
1702
  async#recoverBuilder(reason) {
1724
1703
  try {
1725
1704
  await this.#startBuilder();
1726
1705
  } catch (err) {
1706
+ if (this.#stopping)
1707
+ return;
1727
1708
  this.logger.warn(`[builder-recovery] builder start failed: ${err instanceof Error ? err.message : String(err)}`);
1728
1709
  this.#scheduleBuilderRecovery(reason);
1729
1710
  return;
1730
1711
  }
1731
- this.#builderRecoveryAttempts = 0;
1712
+ this.#builderRecovery.reset();
1732
1713
  this.logger.info("[builder-recovery] builder recovered");
1733
1714
  this.#restartBackendForGapChanges();
1734
1715
  const failedAfterApply = this.#restartFailedAfterApply;
@@ -1742,15 +1723,15 @@ ${this.#backendStderrTail.join(`
1742
1723
  };
1743
1724
  this.#recordBuildStatus(status);
1744
1725
  this.#sendOrQueueBuildStatus(status);
1745
- if (!this.#backend && !this.#backendRecoveryTimer) {
1726
+ if (!this.#backend && !this.#backendRecovery.pending) {
1746
1727
  this.#startBackend({ generation: reason.generation, files: reason.files });
1747
1728
  }
1748
1729
  }
1749
1730
  #reviveBackendAfterGreenBuild(status) {
1750
- if (!status.ok || !this.#backendGaveUp || this.#backend || this.#backendRecoveryTimer)
1731
+ if (!status.ok || !this.#backendGaveUp || this.#backend || this.#backendRecovery.pending)
1751
1732
  return;
1752
1733
  this.logger.info(`[backend-recovery] build went green (generation=${status.generation}); retrying backend`);
1753
- this.#backendRecoveryAttempts = 0;
1734
+ this.#backendRecovery.reset();
1754
1735
  this.#startBackend({ generation: status.generation, files: status.files });
1755
1736
  }
1756
1737
  async#restartDevChildren(message) {
@@ -1766,7 +1747,7 @@ ${this.#backendStderrTail.join(`
1766
1747
  async#recycleDevChildren(message, { refreshConfig = false, progress } = {}) {
1767
1748
  const generation = message.devPlan?.generation ?? message.generation;
1768
1749
  this.#clearRestartTimers();
1769
- this.#builderRecoveryAttempts = 0;
1750
+ this.#builderRecovery.reset();
1770
1751
  this.#pendingRestartReason = null;
1771
1752
  await this.#backendRestart;
1772
1753
  this.#lastGoodFrontend = {};
@@ -1886,13 +1867,18 @@ ${this.#backendStderrTail.join(`
1886
1867
  this.app.verbose(`[cli] waiting for builder to complete initial base build\u2026`);
1887
1868
  let lastError;
1888
1869
  for (let attempt = 1;attempt <= BUILDER_START_MAX_ATTEMPTS; attempt++) {
1889
- this.#builder = await IncrementalBuilderHost.create(this.app, this.env, (msg) => {
1870
+ const builder = await IncrementalBuilderHost.create(this.app, this.env, (msg) => {
1890
1871
  this.#enqueueBuilderMessage(msg);
1891
1872
  }, {
1892
1873
  stdio: this.stdio,
1893
1874
  onOutput: (kind, text) => void (kind === "stderr" ? process.stderr : process.stdout).write(text),
1894
1875
  patcherOff: this.#patcherOff
1895
1876
  });
1877
+ if (this.#stopping) {
1878
+ builder.stop();
1879
+ throw new Error("dev server stopped before the builder started");
1880
+ }
1881
+ this.#builder = builder;
1896
1882
  try {
1897
1883
  await this.#waitForBuilderReady(attempt, { announceBootState });
1898
1884
  this.app.verbose(`[cli] base build ready in ${Date.now() - startTime}ms \u2014 starting backend`);
@@ -1900,7 +1886,7 @@ ${this.#backendStderrTail.join(`
1900
1886
  } catch (err) {
1901
1887
  lastError = err;
1902
1888
  this.#stopBuilder();
1903
- if (attempt >= BUILDER_START_MAX_ATTEMPTS)
1889
+ if (attempt >= BUILDER_START_MAX_ATTEMPTS || this.#stopping)
1904
1890
  break;
1905
1891
  this.app.verbose(`[cli] builder failed before ready; retrying (${attempt + 1}/${BUILDER_START_MAX_ATTEMPTS})`);
1906
1892
  }
@@ -1918,8 +1904,12 @@ ${this.#backendStderrTail.join(`
1918
1904
  return;
1919
1905
  settled = true;
1920
1906
  clearTimeout(timeout);
1907
+ if (this.#abandonBuilderStart === abandon)
1908
+ this.#abandonBuilderStart = null;
1921
1909
  fn();
1922
1910
  };
1911
+ const abandon = (error) => settle(() => reject(error));
1912
+ this.#abandonBuilderStart = abandon;
1923
1913
  const timeout = setTimeout(() => {
1924
1914
  settle(() => reject(new Error("[cli] builder timed out before emitting builder-ready")));
1925
1915
  }, BUILDER_READY_TIMEOUT_MS);
@@ -2038,7 +2028,7 @@ var reportsNoTestFile = (exec) => {
2038
2028
  };
2039
2029
 
2040
2030
  // pkgs/@akanjs/cli/application/application.runner.ts
2041
- var loadBuildRunner = async () => (await import("./applicationBuildRunner-sctcmkyx.js")).ApplicationBuildRunner;
2031
+ var loadBuildRunner = async () => (await import("./applicationBuildRunner-f4yf0qyc.js")).ApplicationBuildRunner;
2042
2032
  var loadPrompts = async () => await import("@inquirer/prompts");
2043
2033
 
2044
2034
  class ApplicationRunner extends runner("application") {
@@ -2239,7 +2229,7 @@ if (loaded) process.exitCode = await loaded.migrations.command(loaded.server, ar
2239
2229
  await new (await loadBuildRunner())(app).typecheck(options);
2240
2230
  }
2241
2231
  async typecheckLibrary(lib, options = {}) {
2242
- const { ProjectTypecheck } = await import("./projectTypecheck-vkb40hjc.js");
2232
+ const { ProjectTypecheck } = await import("./projectTypecheck-tz497yx7.js");
2243
2233
  const root = lib.workspace.workspaceRoot;
2244
2234
  await new ProjectTypecheck(lib.cwdPath, root, { ...process.env, AKAN_WORKSPACE_ROOT: root }).run([
2245
2235
  "../../server.ts",
@@ -2715,7 +2705,7 @@ class VerifyScope {
2715
2705
  const targets = requested.map((name) => {
2716
2706
  const target = known.find((candidate) => candidate.name === name);
2717
2707
  if (!target)
2718
- throw new ExitCodeError(`${name} is not an app, library or package of this workspace`, 2);
2708
+ throw new CliError("unknownTarget", `${name} is not an app, library or package of this workspace`);
2719
2709
  return { ...target, files: changedFilesOf(target.dir) };
2720
2710
  });
2721
2711
  return new VerifyScope(targets);
@@ -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-tenw3mah.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-evr3b35y.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);