@akanjs/devkit 3.3.0-rc.1 → 3.3.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 (85) hide show
  1. package/CHANGELOG.md +229 -2
  2. package/README.ko.md +3 -2
  3. package/README.md +3 -3
  4. package/akanApp/akanApp.host.test.ts +22 -5
  5. package/akanApp/akanApp.host.ts +46 -9
  6. package/akanApp/akanApp.host.wiring.test.ts +206 -2
  7. package/akanApp/devBackend.ts +3 -1
  8. package/akanApp/devBuilder.ts +5 -1
  9. package/akanApp/devStartTimeline.test.ts +115 -0
  10. package/akanApp/devStartTimeline.ts +69 -0
  11. package/akanConfig/akanConfig.test.ts +57 -8
  12. package/akanConfig/akanConfig.ts +12 -65
  13. package/akanConfig/dockerImage.ts +17 -0
  14. package/akanConfig/nativeKeys.ts +52 -0
  15. package/app/applicationBuildRunner.test.ts +49 -1
  16. package/app/applicationBuildRunner.ts +3 -1
  17. package/codeAgent/agent/CodeAgent.ts +36 -16
  18. package/codeAgent/agent/CodeAgentAllowed.ts +35 -0
  19. package/codeAgent/agent/CodeAgentCommandLine.ts +372 -0
  20. package/codeAgent/agent/CodeAgentGate.ts +23 -4
  21. package/codeAgent/agent/CodeAgentRpcHost.ts +1 -1
  22. package/codeAgent/agent/codeAgent.test.ts +62 -0
  23. package/codeAgent/agent/codeAgentCommandLine.test.ts +212 -0
  24. package/codeAgent/agent/codeAgentContract.test.ts +117 -5
  25. package/codeAgent/skills/akan-agent/SKILL.md +8 -1
  26. package/codeAgent/skills/akan-code/SKILL.md +38 -3
  27. package/codeAgent/skills/akan-page/SKILL.md +18 -13
  28. package/codeAgent/skills/akan-runtime/SKILL.md +21 -16
  29. package/codeAgent/skills/akan-service/SKILL.md +2 -2
  30. package/docs/apiReference.test.ts +5 -0
  31. package/docs/apiReference.ts +7 -3
  32. package/docs/declarationReader.ts +28 -1
  33. package/executors/appExecutor.ts +35 -11
  34. package/executors/executors.test.ts +30 -3
  35. package/frontendBuild/buildCacheStamp.test.ts +42 -0
  36. package/frontendBuild/buildCacheStamp.ts +23 -0
  37. package/frontendBuild/buildRouteClient.test.ts +2 -7
  38. package/frontendBuild/clientEntryDiscovery.ts +2 -2
  39. package/frontendBuild/cssCandidateCache.test.ts +70 -1
  40. package/frontendBuild/cssCandidateCache.ts +17 -10
  41. package/frontendBuild/cssCompiler.test.ts +112 -0
  42. package/frontendBuild/cssCompiler.ts +41 -21
  43. package/frontendBuild/devBarrelImports.test.ts +30 -0
  44. package/frontendBuild/devBarrelImports.ts +2 -2
  45. package/frontendBuild/fontOptimizer.test.ts +144 -3
  46. package/frontendBuild/fontOptimizer.ts +103 -18
  47. package/frontendBuild/pagesBundleBuilder.ts +3 -1
  48. package/frontendBuild/plainStylesheet.test.ts +155 -0
  49. package/frontendBuild/plainStylesheet.ts +197 -0
  50. package/frontendBuild/rscServerRendererGuard.test.ts +60 -0
  51. package/frontendBuild/rscServerRendererGuard.ts +68 -0
  52. package/frontendBuild/ssrBaseArtifactBuilder.test.ts +30 -1
  53. package/frontendBuild/ssrBaseArtifactBuilder.ts +40 -12
  54. package/guideline/agentAssets.test.ts +10 -0
  55. package/guideline/agentAssets.ts +52 -11
  56. package/incrementalBuilder/buildBatch.proc.ts +11 -10
  57. package/incrementalBuilder/buildBatchProtocol.ts +2 -1
  58. package/incrementalBuilder/builderBoot.ts +14 -7
  59. package/incrementalBuilder/builderChannel.ts +8 -2
  60. package/incrementalBuilder/builderGraphPayloads.ts +4 -4
  61. package/incrementalBuilder/builderLanes.ts +2 -2
  62. package/incrementalBuilder/builderWatch.ts +8 -8
  63. package/incrementalBuilder/csrRegistry.ts +4 -4
  64. package/incrementalBuilder/incrementalBuilder.host.test.ts +16 -0
  65. package/incrementalBuilder/incrementalBuilder.host.ts +7 -1
  66. package/incrementalBuilder/incrementalBuilder.proc.test.ts +41 -0
  67. package/incrementalBuilder/incrementalBuilder.proc.ts +9 -8
  68. package/incrementalBuilder/ssrRegistry.ts +6 -6
  69. package/index.ts +1 -1
  70. package/integration/renderAdmissionSoak.test.ts +99 -0
  71. package/integration/renderAdmissionSoak.ts +609 -0
  72. package/mobile/nativeConfig.test.ts +100 -0
  73. package/mobile/nativeConfig.ts +55 -16
  74. package/mobile/nativePublicEnv.ts +2 -1
  75. package/package.json +14 -169
  76. package/packageExports.test.ts +38 -24
  77. package/transforms/barrelAnalyzer.ts +2 -2
  78. package/transforms/transforms.test.ts +3 -3
  79. package/tunnel/createTunnel.test.ts +29 -8
  80. package/tunnel/createTunnel.ts +18 -11
  81. package/util/fileEditor.ts +1 -0
  82. package/util/fileSys.test.ts +13 -0
  83. package/util/fileSys.ts +2 -2
  84. package/util/selectModel.ts +1 -0
  85. package/workspace/getRelatedCnsts.ts +7 -0
@@ -44,6 +44,7 @@ type Boot = "ready" | "exit" | "hold" | "starting";
44
44
  interface BuilderStartOptions {
45
45
  onExit?: () => void;
46
46
  onReady?: () => void;
47
+ onBaseBuilt?: (phaseMs: Record<string, number>) => void;
47
48
  onRestartReady?: () => void;
48
49
  onAway?: () => void;
49
50
  }
@@ -54,12 +55,15 @@ interface FakeBuilder {
54
55
  recycled: string[];
55
56
  stopped: number;
56
57
  toHost: (message: BuilderMessage) => void;
58
+ baseBuilt: (phaseMs?: Record<string, number>) => void;
59
+ exit: () => void;
57
60
  ready: () => void;
58
61
  away: () => void;
59
62
  restartReady: () => void;
60
63
  }
61
64
 
62
65
  interface FakeBackend {
66
+ awaitsArtifact: boolean;
63
67
  sent: BuilderMessage[];
64
68
  signals: string[];
65
69
  lingers: boolean;
@@ -69,6 +73,7 @@ interface FakeBackend {
69
73
  }
70
74
 
71
75
  interface BackendSpawnOptions {
76
+ env?: Record<string, string>;
72
77
  ipc: (message: BuilderMessage) => void;
73
78
  onExit?: (proc: unknown, code: number | null, signal: string | null) => void;
74
79
  }
@@ -100,6 +105,11 @@ const fakeBuilder = (toHost: (message: BuilderMessage) => void, boot: Boot) => {
100
105
  recycled: [],
101
106
  stopped: 0,
102
107
  toHost,
108
+ baseBuilt: (phaseMs = {}) => options.onBaseBuilt?.(phaseMs),
109
+ exit: () => {
110
+ builder.status = "stopped";
111
+ options.onExit?.();
112
+ },
103
113
  ready: () => {
104
114
  builder.status = "ready";
105
115
  options.onReady?.();
@@ -124,8 +134,10 @@ const fakeBuilder = (toHost: (message: BuilderMessage) => void, boot: Boot) => {
124
134
  if (boot === "exit") {
125
135
  builder.status = "stopped";
126
136
  options.onExit?.();
127
- } else if (boot === "ready") builder.ready();
128
- else {
137
+ } else if (boot === "ready") {
138
+ builder.baseBuilt();
139
+ builder.ready();
140
+ } else {
129
141
  builder.status = "starting";
130
142
  if (boot === "starting") options.onReady?.();
131
143
  }
@@ -163,6 +175,7 @@ const fakeBackends = () => {
163
175
  queueMicrotask(() => options.onExit?.(proc, code, signal));
164
176
  };
165
177
  const backend: FakeBackend = {
178
+ awaitsArtifact: options.env?.AKAN_DEV_AWAIT_ARTIFACT === "1",
166
179
  sent: [],
167
180
  signals: [],
168
181
  lingers: false,
@@ -681,6 +694,26 @@ describe("AkanAppHost start and stop", () => {
681
694
  expect(dev.events.slice(seen)).toEqual([]);
682
695
  });
683
696
 
697
+ test("says where a start's time went in one line, once the builder and the backend are both ready", async () => {
698
+ const dev = await devHost(["hold"]);
699
+ const starting = dev.host.start();
700
+ expect(await until(() => dev.builders.length === 1)).toBe(true);
701
+ dev.builder().baseBuilt({ runtime: 1, routes: 2, styles: 3, dictionary: 4, pages: 5, total: 15 });
702
+ dev.builder().ready();
703
+ await starting;
704
+ const timelines = () => dev.logs.filter((line) => line.startsWith("ready in "));
705
+ expect(timelines()).toEqual([]);
706
+
707
+ readyBackend(dev);
708
+
709
+ expect(timelines()).toHaveLength(1);
710
+ expect(timelines()[0]).toContain("base build 15 [runtime 1 · routes 2 · styles 3 · dictionary 4 · pages 5]");
711
+ expect(timelines()[0]).toMatch(/prepare \d+ · builder \d+: spawn \d+ .* · backend \d+ · first artifact at \d+\)$/);
712
+
713
+ dev.backend().say({ type: "backend-ready", pid: 1 });
714
+ expect(timelines()).toHaveLength(1);
715
+ });
716
+
684
717
  test("a second start replaces the backend and the builder the first one started", async () => {
685
718
  const dev = await startedHost();
686
719
 
@@ -691,6 +724,177 @@ describe("AkanAppHost start and stop", () => {
691
724
  });
692
725
  });
693
726
 
727
+ describe("AkanAppHost boots the backend beside the first base build", () => {
728
+ isolateEnv({ AKAN_PUBLIC_REPO_NAME: "repo", AKAN_PUBLIC_SERVE_DOMAIN: "localhost", AKAN_PUBLIC_ENV: "local" });
729
+
730
+ const building = async (boots: Boot[] = ["hold"]) => {
731
+ const dev = await devHost(boots);
732
+ const outcome = { error: null as unknown, settled: false };
733
+ const starting = dev.host.start().then(
734
+ () => void Object.assign(outcome, { settled: true }),
735
+ (error: unknown) => void Object.assign(outcome, { error, settled: true }),
736
+ );
737
+ return { dev, starting, outcome };
738
+ };
739
+ const artifactOf = (dev: DevHost) => path.join(dev.root, "apps/demo/.akan/artifact/base-artifact.json");
740
+ const quiet = () => Bun.sleep(60);
741
+
742
+ test("starts the backend while the builder still builds, told to hold its web surface for the artifact", async () => {
743
+ const { dev, starting, outcome } = await building();
744
+ expect(await until(() => dev.backends.length === 1)).toBe(true);
745
+ expect(dev.backend().awaitsArtifact).toBe(true);
746
+ expect(outcome.settled).toBe(false);
747
+
748
+ dev.builder().baseBuilt();
749
+ dev.builder().ready();
750
+ await starting;
751
+ readyBackend(dev);
752
+
753
+ expect(dev.backends.map((backend) => backend.signals)).toEqual([[]]);
754
+ expect(dev.lastState()).toBe("ready");
755
+ });
756
+
757
+ test("a backend ready before the builder has its requests held, and gets its answers once the builder is ready", async () => {
758
+ const { dev, starting } = await building();
759
+ expect(await until(() => dev.backends.length === 1)).toBe(true);
760
+ dev.builder().baseBuilt();
761
+ readyBackend(dev);
762
+ expect(dev.lastState()).toBe("ready");
763
+ dev.backend().say({ type: "build-graph", id: 7 });
764
+ await quiet();
765
+ expect(dev.builder().sent).toEqual([]);
766
+ expect(dev.backend().sent).toEqual([]);
767
+
768
+ dev.builder().ready();
769
+ await starting;
770
+
771
+ expect(sentOf(dev.builder().sent, "build-graph")).toHaveLength(1);
772
+ expect(dev.backends).toHaveLength(1);
773
+ });
774
+
775
+ test("a builder ready before the backend keeps what it built meanwhile, and the backend gets it at its ready", async () => {
776
+ const { dev, starting } = await building();
777
+ expect(await until(() => dev.backends.length === 1)).toBe(true);
778
+ dev.builder().baseBuilt();
779
+ dev.builder().ready();
780
+ await starting;
781
+ dev.builder().toHost(pages(3));
782
+ dev.builder().toHost({ type: "build-status", data: status(3, false) });
783
+ await quiet();
784
+ expect(dev.backend().sent).toEqual([]);
785
+
786
+ readyBackend(dev);
787
+
788
+ expect(sentOf(dev.backend().sent, "pages-updated")).toEqual([pages(3)]);
789
+ expect(statusesOf(dev.backend().sent)).toContainEqual(status(3, false));
790
+ });
791
+
792
+ test("a save that restarts the backend during start-up replaces it with one that no longer waits", async () => {
793
+ const { dev, starting } = await building();
794
+ expect(await until(() => dev.backends.length === 1)).toBe(true);
795
+ dev.builder().baseBuilt();
796
+ dev.builder().ready();
797
+ await starting;
798
+
799
+ dev.builder().toHost(invalidate(2, ["restart-backend"]));
800
+
801
+ expect(await until(() => dev.backends.length === 2)).toBe(true);
802
+ expect(dev.backends.map((backend) => backend.signals)).toEqual([["SIGTERM"], []]);
803
+ expect(dev.backend().awaitsArtifact).toBe(false);
804
+ });
805
+
806
+ test("a boot build that wrote no artifact gets a backend that serves the API without waiting for one", async () => {
807
+ const { dev, starting } = await building();
808
+ expect(await until(() => dev.backends.length === 1)).toBe(true);
809
+
810
+ dev.builder().ready();
811
+ await starting;
812
+
813
+ expect(dev.backends.map((backend) => backend.signals)).toEqual([["SIGTERM"], []]);
814
+ expect(dev.backends.map((backend) => backend.awaitsArtifact)).toEqual([true, false]);
815
+ });
816
+
817
+ test("a builder that never comes up takes the waiting backend down with the failed start", async () => {
818
+ const { dev, starting, outcome } = await building(["hold", "exit", "exit"]);
819
+ expect(await until(() => dev.backends.length === 1)).toBe(true);
820
+
821
+ dev.builder().exit();
822
+ await starting;
823
+
824
+ expect(outcome.error).toBeInstanceOf(Error);
825
+ expect(dev.backends.map((backend) => backend.signals)).toEqual([["SIGTERM"]]);
826
+ await quiet();
827
+ expect(dev.backends).toHaveLength(1);
828
+ });
829
+
830
+ test("a backend that dies while the builder builds comes back still waiting for the artifact", async () => {
831
+ const { dev, starting } = await building();
832
+ expect(await until(() => dev.backends.length === 1)).toBe(true);
833
+
834
+ dev.backend().crash();
835
+
836
+ expect(await until(() => dev.backends.length === 2, (backendRecoveryPolicy.min ?? 0) + 2_000)).toBe(true);
837
+ expect(dev.backend().awaitsArtifact).toBe(true);
838
+ dev.builder().baseBuilt();
839
+ dev.builder().ready();
840
+ await starting;
841
+ expect(dev.backends).toHaveLength(2);
842
+ expect(dev.backend().signals).toEqual([]);
843
+ });
844
+
845
+ test("a builder retried inside one start restarts a backend that booted on the artifact the first try wrote", async () => {
846
+ const { dev, starting } = await building();
847
+ expect(await until(() => dev.backends.length === 1)).toBe(true);
848
+ dev.builder().baseBuilt();
849
+
850
+ dev.builder().baseBuilt();
851
+
852
+ expect(await until(() => dev.backends.length === 2)).toBe(true);
853
+ expect(dev.backends.map((backend) => backend.awaitsArtifact)).toEqual([true, false]);
854
+ dev.builder().ready();
855
+ await starting;
856
+ });
857
+
858
+ test("a stop during start-up signals the waiting backend once, stops the builder, and starts nothing after", async () => {
859
+ const { dev, starting, outcome } = await building();
860
+ expect(await until(() => dev.backends.length === 1)).toBe(true);
861
+
862
+ await dev.host.stop();
863
+ await starting;
864
+
865
+ expect(outcome.error).toBeInstanceOf(Error);
866
+ expect(dev.backends.map((backend) => backend.signals)).toEqual([["SIGTERM"]]);
867
+ expect(dev.builder().stopped).toBeGreaterThanOrEqual(1);
868
+ await quiet();
869
+ expect(dev.backends).toHaveLength(1);
870
+ });
871
+
872
+ test("a stop before the backend was spawned never spawns it", async () => {
873
+ const { dev, starting } = await building();
874
+
875
+ await dev.host.stop();
876
+ await starting;
877
+ await quiet();
878
+
879
+ expect(dev.backends).toEqual([]);
880
+ });
881
+
882
+ test("an artifact already on disk keeps the backend behind the builder, so it never boots on the old one", async () => {
883
+ const dev = await devHost(["hold"]);
884
+ await writeText(artifactOf(dev), "{}\n");
885
+ const starting = dev.host.start();
886
+ expect(await until(() => dev.builders.length === 1)).toBe(true);
887
+ await quiet();
888
+ expect(dev.backends).toEqual([]);
889
+
890
+ dev.builder().ready();
891
+ await starting;
892
+
893
+ expect(dev.backends).toHaveLength(1);
894
+ expect(dev.backend().awaitsArtifact).toBe(false);
895
+ });
896
+ });
897
+
694
898
  describe("AkanAppHost on a fake clock", () => {
695
899
  isolateEnv({
696
900
  AKAN_PUBLIC_REPO_NAME: "repo",
@@ -30,6 +30,7 @@ interface DevBackendLinks {
30
30
  isStopping: () => boolean;
31
31
  emit: (state: DevHostState, detail?: string) => void;
32
32
  beforeSpawn: () => void;
33
+ awaitsArtifact: () => boolean;
33
34
  toBuilder: (message: BuilderMessage) => void;
34
35
  }
35
36
 
@@ -129,7 +130,8 @@ export class DevBackend {
129
130
  const backend = Bun.spawn(["bun", `apps/${this.#app.name}/main.ts`], {
130
131
  cwd: this.#app.workspace.workspaceRoot,
131
132
  stdio: this.#stdio === "pipe" ? ["ignore", "pipe", "pipe"] : ["inherit", "inherit", "inherit"],
132
- env: this.#env,
133
+ //? The first base build is still running: the backend boots beside it and holds its web surface for the artifact.
134
+ env: this.#links.awaitsArtifact() ? { ...this.#env, AKAN_DEV_AWAIT_ARTIFACT: "1" } : this.#env,
133
135
  ipc: (msg: BuilderMessage) => {
134
136
  if (!msg || typeof msg !== "object") return;
135
137
  if (msg.type === "backend-ready") {
@@ -17,6 +17,7 @@ interface DevBuilderLinks {
17
17
  onMessage: (message: BuilderMessage) => void;
18
18
  onAway: () => void;
19
19
  onReady: () => void;
20
+ onBaseBuilt: (phaseMs: Record<string, number>) => void;
20
21
  onRestartReady: () => void;
21
22
  onStartFailed: () => void;
22
23
  onStop: () => void;
@@ -81,7 +82,7 @@ export class DevBuilder {
81
82
  this.#host = builder;
82
83
  try {
83
84
  await this.#waitForReady(attempt, { announceBootState });
84
- this.#app.verbose(`[cli] base build ready in ${Date.now() - startTime}ms — starting backend`);
85
+ this.#app.verbose(`[cli] base build ready in ${Date.now() - startTime}ms`);
85
86
  return this.#host;
86
87
  } catch (err) {
87
88
  lastError = err;
@@ -187,6 +188,9 @@ export class DevBuilder {
187
188
  settle(resolve);
188
189
  this.#links.onReady();
189
190
  },
191
+ onBaseBuilt: (phaseMs) => {
192
+ this.#links.onBaseBuilt(phaseMs);
193
+ },
190
194
  onRestartReady: () => {
191
195
  this.#links.onRestartReady();
192
196
  },
@@ -0,0 +1,115 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import type { Logger } from "akanjs/common";
3
+ import { DevStartTimeline } from "./devStartTimeline";
4
+
5
+ const timeline = () => {
6
+ const lines: string[] = [];
7
+ const clock = { at: 0 };
8
+ const logger = { info: (line: string) => void lines.push(line) } as unknown as Logger;
9
+ return { lines, clock, timeline: new DevStartTimeline(logger, () => clock.at) };
10
+ };
11
+
12
+ const phases = { runtime: 70, routes: 200, styles: 900, dictionary: 6, pages: 500, total: 1700 };
13
+
14
+ describe("DevStartTimeline", () => {
15
+ test("names every phase of a start in one line, once the builder and the backend are both ready", () => {
16
+ const { lines, clock, timeline: start } = timeline();
17
+ clock.at = 800;
18
+ start.begin();
19
+ clock.at = 2700;
20
+ start.baseBuilt(phases);
21
+ start.mark("backendSpawned");
22
+ clock.at = 2900;
23
+ start.mark("builderReady");
24
+ expect(lines).toEqual([]);
25
+ clock.at = 3200;
26
+ start.mark("backendReady");
27
+
28
+ expect(lines).toEqual([
29
+ "ready in 3200ms (prepare 800 · builder 2100: spawn 200 + base build 1700 [runtime 70 · routes 200 · styles 900 · dictionary 6 · pages 500] + watch 200 · backend 500 · first artifact at 2700)",
30
+ ]);
31
+ });
32
+
33
+ test("says what a backend spawned beside the build took once the artifact was there", () => {
34
+ const { lines, clock, timeline: start } = timeline();
35
+ clock.at = 800;
36
+ start.begin();
37
+ clock.at = 850;
38
+ start.mark("backendSpawned");
39
+ clock.at = 2700;
40
+ start.baseBuilt(phases);
41
+ clock.at = 2730;
42
+ start.mark("builderReady");
43
+ clock.at = 2950;
44
+ start.mark("backendReady");
45
+
46
+ expect(lines).toHaveLength(1);
47
+ expect(lines[0]).toStartWith("ready in 2950ms (prepare 800 · builder 1930: spawn 200 + base build 1700 [");
48
+ expect(lines[0]).toEndWith("+ watch 30 · backend 2100 (250 after the artifact) · first artifact at 2700)");
49
+ });
50
+
51
+ test("reports at the builder's ready when the backend was ready first", () => {
52
+ const { lines, clock, timeline: start } = timeline();
53
+ start.begin();
54
+ clock.at = 100;
55
+ start.mark("backendSpawned");
56
+ clock.at = 400;
57
+ start.mark("backendReady");
58
+ expect(lines).toEqual([]);
59
+ clock.at = 2000;
60
+ start.baseBuilt(phases);
61
+ clock.at = 2100;
62
+ start.mark("builderReady");
63
+
64
+ expect(lines).toHaveLength(1);
65
+ expect(lines[0]).toStartWith("ready in 2100ms (prepare 0 · builder 2100: spawn 300 + base build 1700 [");
66
+ expect(lines[0]).toEndWith("+ watch 100 · backend 300 · first artifact at 2000)");
67
+ });
68
+
69
+ test("leaves the build's parts out when the boot build wrote no artifact", () => {
70
+ const { lines, clock, timeline: start } = timeline();
71
+ start.begin();
72
+ clock.at = 900;
73
+ start.mark("builderReady");
74
+ start.mark("backendSpawned");
75
+ clock.at = 1300;
76
+ start.mark("backendReady");
77
+
78
+ expect(lines).toEqual(["ready in 1300ms (prepare 0 · builder 900 · backend 400)"]);
79
+ });
80
+
81
+ test("times a backend replaced before it was ready from its last spawn", () => {
82
+ const { lines, clock, timeline: start } = timeline();
83
+ start.begin();
84
+ start.mark("builderReady");
85
+ start.mark("backendSpawned");
86
+ clock.at = 700;
87
+ start.mark("backendSpawned");
88
+ clock.at = 1000;
89
+ start.mark("backendReady");
90
+
91
+ expect(lines).toEqual(["ready in 1000ms (prepare 0 · builder 0 · backend 300)"]);
92
+ });
93
+
94
+ test("says nothing after its one line until the next start, and nothing before the first", () => {
95
+ const { lines, clock, timeline: start } = timeline();
96
+ start.mark("builderReady");
97
+ start.mark("backendReady");
98
+ expect(lines).toEqual([]);
99
+
100
+ start.begin();
101
+ start.mark("builderReady");
102
+ start.mark("backendReady");
103
+ clock.at = 50;
104
+ start.mark("backendSpawned");
105
+ start.mark("backendReady");
106
+ expect(lines).toHaveLength(1);
107
+
108
+ start.begin();
109
+ start.mark("builderReady");
110
+ clock.at = 80;
111
+ start.mark("backendReady");
112
+ expect(lines).toHaveLength(2);
113
+ expect(lines[1]).toBe("ready in 80ms (prepare 50 · builder 0)");
114
+ });
115
+ });
@@ -0,0 +1,69 @@
1
+ import type { Logger } from "akanjs/common";
2
+
3
+ type StartMark = "started" | "baseBuilt" | "builderReady" | "backendSpawned" | "backendReady";
4
+
5
+ const BASE_BUILD_PARTS = ["runtime", "routes", "styles", "dictionary", "pages"];
6
+
7
+ export class DevStartTimeline {
8
+ readonly #logger: Logger;
9
+ readonly #now: () => number;
10
+ #marks: Partial<Record<StartMark, number>> = {};
11
+ #basePhaseMs: Partial<Record<string, number>> = {};
12
+ #reported = true;
13
+
14
+ constructor(logger: Logger, now: () => number = () => performance.now()) {
15
+ this.#logger = logger;
16
+ this.#now = now;
17
+ }
18
+
19
+ begin(): void {
20
+ this.#marks = { started: this.#now() };
21
+ this.#basePhaseMs = {};
22
+ this.#reported = false;
23
+ }
24
+
25
+ baseBuilt(phaseMs: Record<string, number>): void {
26
+ if (this.#reported || this.#marks.baseBuilt !== undefined) return;
27
+ this.#basePhaseMs = phaseMs;
28
+ this.#marks.baseBuilt = this.#now();
29
+ }
30
+
31
+ mark(mark: Exclude<StartMark, "started" | "baseBuilt">): void {
32
+ if (this.#reported) return;
33
+ if (mark === "backendSpawned") this.#marks.backendSpawned = this.#now();
34
+ else this.#marks[mark] ??= this.#now();
35
+ this.#report();
36
+ }
37
+
38
+ #report(): void {
39
+ const { started, baseBuilt, builderReady, backendSpawned, backendReady } = this.#marks;
40
+ if (started === undefined || builderReady === undefined || backendReady === undefined) return;
41
+ this.#reported = true;
42
+ const ms = (value: number) => Math.round(value).toString();
43
+ //? The clock counts from the start of the process, so the first mark is what the CLI spent before the host.
44
+ const parts = [`prepare ${ms(started)}`, `builder ${ms(builderReady - started)}${this.#builderParts()}`];
45
+ if (backendSpawned !== undefined) {
46
+ //? Spawned beside the build, most of its time is the wait for the artifact: what it took after that is its own.
47
+ const afterArtifact =
48
+ baseBuilt !== undefined && backendSpawned < baseBuilt && baseBuilt <= backendReady
49
+ ? ` (${ms(backendReady - baseBuilt)} after the artifact)`
50
+ : "";
51
+ parts.push(`backend ${ms(backendReady - backendSpawned)}${afterArtifact}`);
52
+ }
53
+ if (baseBuilt !== undefined) parts.push(`first artifact at ${ms(baseBuilt)}`);
54
+ this.#logger.info(`ready in ${ms(Math.max(builderReady, backendReady))}ms (${parts.join(" · ")})`);
55
+ }
56
+
57
+ #builderParts(): string {
58
+ const { started, baseBuilt, builderReady } = this.#marks;
59
+ if (started === undefined || baseBuilt === undefined || builderReady === undefined) return "";
60
+ const total = this.#basePhaseMs.total ?? 0;
61
+ const base = BASE_BUILD_PARTS.flatMap((part) => {
62
+ const partMs = this.#basePhaseMs[part];
63
+ return partMs === undefined ? [] : [`${part} ${Math.round(partMs)}`];
64
+ });
65
+ const spawn = Math.max(0, Math.round(baseBuilt - started - total));
66
+ const watch = Math.max(0, Math.round(builderReady - baseBuilt));
67
+ return `: spawn ${spawn} + base build ${Math.round(total)} [${base.join(" · ")}] + watch ${watch}`;
68
+ }
69
+ }
@@ -7,6 +7,7 @@ import { AppExecutor, WorkspaceExecutor } from "../executors";
7
7
  import { NativeConfig } from "../mobile/nativeConfig";
8
8
  import type { PackageJson } from "../workspace/types";
9
9
  import { AkanAppConfig, AkanLibConfig, deriveDefaultAppId } from "./akanConfig";
10
+ import { BUN_IMAGE_PIN, DEFAULT_DOCKER_IMAGE } from "./dockerImage";
10
11
  import type { LibConfigInput } from "./types";
11
12
 
12
13
  const akanPackageJson = JSON.parse(
@@ -15,7 +16,14 @@ const akanPackageJson = JSON.parse(
15
16
  const rootPackageJson = JSON.parse(
16
17
  fs.readFileSync(path.join(path.dirname(fileURLToPath(import.meta.url)), "../../../../package.json"), "utf8"),
17
18
  ) as { engines: { bun: string } };
18
- const pinnedBunImage = `oven/bun:${rootPackageJson.engines.bun}-slim`;
19
+ const writeDirsStep =
20
+ "RUN mkdir -p /workspace/sqlite /workspace/local /workspace/runtime /workspace/data /workspace/.akan/artifact/image-cache && chown 1000:1000 /workspace/sqlite /workspace/local /workspace/runtime /workspace/data /workspace/.akan/artifact/image-cache";
21
+ const setupActionBunVersion = /bun-version:\s*(\S+)/.exec(
22
+ fs.readFileSync(
23
+ path.join(path.dirname(fileURLToPath(import.meta.url)), "../../../../.github/actions/setup/action.yml"),
24
+ "utf8",
25
+ ),
26
+ )?.[1];
19
27
 
20
28
  const packageJson: PackageJson = {
21
29
  name: "repo",
@@ -180,7 +188,7 @@ describe("AkanAppConfig", () => {
180
188
  env: { PATH: process.env.PATH ?? "", ...(allow ? { AKAN_ALLOW_LOCAL_IMAGE: allow } : {}) },
181
189
  });
182
190
 
183
- expect(local).toContain(`FROM ${pinnedBunImage}\nARG AKAN_ALLOW_LOCAL_IMAGE\nRUN if`);
191
+ expect(local).toContain(`FROM ${DEFAULT_DOCKER_IMAGE}\nARG AKAN_ALLOW_LOCAL_IMAGE\nRUN if`);
184
192
  expect(config.dockerfileFor("main")).not.toContain("AKAN_ALLOW_LOCAL_IMAGE");
185
193
  expect(run().exitCode).toBe(1);
186
194
  expect(run().stderr.toString()).toContain("--build-arg AKAN_ALLOW_LOCAL_IMAGE=1");
@@ -240,7 +248,9 @@ describe("AkanAppConfig", () => {
240
248
  const envBlock = Object.entries(config.getProductionEnv())
241
249
  .map(([key, value]) => `ENV ${key}=${value}`)
242
250
  .join("\n");
243
- expect(config.dockerfile).toContain(`COPY . .\n${envBlock}\nCMD ["bun","main.js"]`);
251
+ expect(config.dockerfile).toContain(
252
+ `COPY . .\n${writeDirsStep}\n${envBlock}\nUSER 1000:1000\nCMD ["bun","main.js"]`,
253
+ );
244
254
  });
245
255
 
246
256
  test('publishes localePrefix "as-needed" to the bundles and the image, and leaves the default out of the image', () => {
@@ -255,19 +265,19 @@ describe("AkanAppConfig", () => {
255
265
  });
256
266
 
257
267
  test("writes the Dockerfile instructions it wrote before its env came from getProductionEnv", () => {
258
- //? 9adfb95c's output for this config, less the blank lines its empty interpolations left and its floating tag.
268
+ //? 9adfb95c's output for this config, less the blank lines its empty interpolations left, its floating tag and root.
259
269
  const before = [
260
- `FROM ${pinnedBunImage}`,
270
+ `FROM ${DEFAULT_DOCKER_IMAGE}`,
261
271
  "RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends ca-certificates tzdata && rm -rf /var/lib/apt/lists/*",
262
272
  "RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime",
263
273
  "ARG TARGETARCH",
264
274
  "",
265
- "RUN mkdir -p /workspace",
266
275
  "WORKDIR /workspace",
267
276
  "COPY ./package.json ./bun.lock ./",
268
277
  "RUN bun install --production --frozen-lockfile",
269
278
  "",
270
279
  "COPY . .",
280
+ writeDirsStep,
271
281
  "ENV PORT=8282",
272
282
  "ENV NODE_ENV=production",
273
283
  "ENV AKAN_PUBLIC_REPO_NAME=akanjs",
@@ -283,6 +293,7 @@ describe("AkanAppConfig", () => {
283
293
  "ENV AKAN_DATABASE_MODES=single",
284
294
  "ENV AKAN_LOG_TO_FILE=0",
285
295
  "",
296
+ "USER 1000:1000",
286
297
  'CMD ["bun","main.js"]',
287
298
  ];
288
299
  const lines = (text: string) => text.split("\n").filter((line) => line !== "");
@@ -307,6 +318,33 @@ describe("AkanAppConfig", () => {
307
318
  expect(config.dockerfile).not.toContain(dropped);
308
319
  });
309
320
 
321
+ test("pins the default image to the Bun release the repo runs, by the digest kept beside that version", () => {
322
+ expect(rootPackageJson.engines.bun).toBe(BUN_IMAGE_PIN.version);
323
+ expect(setupActionBunVersion).toBe(rootPackageJson.engines.bun);
324
+ expect(BUN_IMAGE_PIN.digest).toMatch(/^sha256:[0-9a-f]{64}$/);
325
+ expect(DEFAULT_DOCKER_IMAGE).toBe(`oven/bun:${BUN_IMAGE_PIN.version}-slim@${BUN_IMAGE_PIN.digest}`);
326
+ });
327
+
328
+ test("runs the generated image as the bun user once every root step is done, owning only what it writes", () => {
329
+ const config = new AkanAppConfig(
330
+ app,
331
+ [],
332
+ packageJson,
333
+ { docker: { preRuns: ["apt-get install -y ffmpeg"], postRuns: ["echo after"] } },
334
+ baseDevEnv,
335
+ );
336
+ const instructions = config.dockerfile.split("\n").filter((line) => line !== "");
337
+ const userAt = instructions.indexOf("USER 1000:1000");
338
+
339
+ expect(instructions.filter((line) => line.startsWith("USER "))).toEqual(["USER 1000:1000"]);
340
+ expect(instructions.slice(userAt + 1)).toEqual(['CMD ["bun","main.js"]']);
341
+ for (const rootStep of ["apt-get update", "apt-get install -y ffmpeg", "bun install", "echo after"])
342
+ expect(instructions.findIndex((line) => line.includes(rootStep))).toBeLessThan(userAt);
343
+ expect(instructions.filter((line) => line.includes("--chown"))).toEqual([]);
344
+ expect(instructions[instructions.indexOf("COPY . .") + 1]).toBe(writeDirsStep);
345
+ expect(instructions.filter((line) => line.includes("chown") && / \/workspace( |$)/.test(line))).toEqual([]);
346
+ });
347
+
310
348
  test("keeps a declared Dockerfile string verbatim", () => {
311
349
  const dockerfile = 'FROM oven/bun:1-slim\nCOPY . .\nCMD ["bun","main.js"]';
312
350
  const config = new AkanAppConfig(app, [], packageJson, { docker: dockerfile }, baseDevEnv);
@@ -319,7 +357,7 @@ describe("AkanAppConfig", () => {
319
357
  const config = new AkanAppConfig(app, [], packageJson, { docker: { preRuns: ["echo hi"] } }, baseDevEnv);
320
358
 
321
359
  expect(config.docker).toEqual({
322
- image: pinnedBunImage,
360
+ image: DEFAULT_DOCKER_IMAGE,
323
361
  preRuns: ["echo hi"],
324
362
  postRuns: [],
325
363
  command: ["bun", "main.js"],
@@ -662,7 +700,7 @@ describe("AkanAppConfig", () => {
662
700
  targets: {
663
701
  default: {
664
702
  plugins: ["share"],
665
- ios: { files: { "extra.caf": "assets/extra.caf" } },
703
+ ios: { files: { "extra.caf": "assets/extra.caf" }, hideFormAccessoryBar: true },
666
704
  android: { manifest: ["<uses-feature/>"] },
667
705
  },
668
706
  },
@@ -677,6 +715,7 @@ describe("AkanAppConfig", () => {
677
715
  ios: {
678
716
  infoPlist: { ITSAppUsesNonExemptEncryption: false },
679
717
  files: { "sound.caf": "assets/sound.caf", "extra.caf": "assets/extra.caf" },
718
+ hideFormAccessoryBar: true,
680
719
  },
681
720
  android: {
682
721
  manifest: ["<uses-feature/>"],
@@ -869,6 +908,16 @@ describe("AkanAppConfig", () => {
869
908
  expect(make({ native: { desktop: { dmg: { backgroundImage: "bg.png" } } } })).toThrow(
870
909
  "native.desktop.dmg.backgroundImage in apps/portal/akan.config.ts is not a native setting",
871
910
  );
911
+ expect(make({ native: { desktop: { externalView: { origins: ["https://board.example"] } } } })).toThrow(
912
+ "native.desktop.externalView.origins in apps/portal/akan.config.ts is not a native setting. Known: allowOrigins, evaluate, sendKey.",
913
+ );
914
+ expect(
915
+ make({
916
+ native: {
917
+ desktop: { externalView: { allowOrigins: ["https://board.example"], evaluate: true, sendKey: true } },
918
+ },
919
+ }),
920
+ ).not.toThrow();
872
921
  });
873
922
 
874
923
  test("derives a repo-scoped default appId and records an explicit native section", () => {