@akanjs/devkit 3.3.0-rc.1 → 3.3.0-rc.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/CHANGELOG.md +230 -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
@@ -90,7 +90,7 @@ describe("createTunnel", () => {
90
90
  const listener = Bun.listen({ hostname: "127.0.0.1", port: 0, socket: { data() {} } });
91
91
  const port = listener.port;
92
92
  listener.stop(true);
93
- process.env.SSH_TUNNEL_PORT = String(port);
93
+ Object.assign(process.env, { SSH_TUNNEL_PORT: String(port), SSH_TUNNEL_PASSWORD: "test-password" });
94
94
 
95
95
  let originalError: Error | undefined;
96
96
  const connect = Client.prototype.connect;
@@ -193,7 +193,7 @@ describe("createTunnel", () => {
193
193
  expect(ssh.methods.filter((method) => method !== "none")).toEqual(["password"]);
194
194
  });
195
195
 
196
- test("warns when it signs in with the default shared credential", async () => {
196
+ test("a tunnel needs a configured credential and names the settings that provide one", async () => {
197
197
  const { root, app } = track(await createTempApp("demo"));
198
198
  const ssh = await startSshServer();
199
199
  Object.assign(process.env, {
@@ -203,13 +203,34 @@ describe("createTunnel", () => {
203
203
  //? `akan test` runs from the workspace root, whose dotenv may name a password; this case is the one with none.
204
204
  delete process.env.SSH_TUNNEL_PASSWORD;
205
205
  delete process.env.SSH_TUNNEL_PRIVATE_KEY_PATH;
206
- const warn = spyOn(app.logger, "warn");
207
-
208
- await createTunnel("redis", { app, environment: "testing", port: freePort() });
206
+ const connect = spyOn(Client.prototype, "connect");
207
+ try {
208
+ await expect(createTunnel("redis", { app, environment: "testing", port: freePort() })).rejects.toThrow(
209
+ "The redis tunnel for demo-testing needs an SSH credential: export SSH_TUNNEL_PRIVATE_KEY_PATH",
210
+ );
211
+ await expect(createTunnel("postgres", { app, environment: "testing", port: freePort() })).rejects.toThrow(
212
+ "or set SSH_TUNNEL_PASSWORD",
213
+ );
214
+ expect(connect).not.toHaveBeenCalled();
215
+ } finally {
216
+ connect.mockRestore();
217
+ }
218
+ expect(ssh.methods).toEqual([]);
219
+ });
209
220
 
210
- expect(warn.mock.calls.map(([message]) => String(message)).join("\n")).toContain(
211
- "uses the default shared credential",
212
- );
221
+ test("a key file the tunnel cannot read fails naming the tunnel, the setting and the path", async () => {
222
+ const { root, app } = track(await createTempApp("demo"));
223
+ const keyPath = path.join(root, "missing_key");
224
+ process.env.SSH_TUNNEL_PRIVATE_KEY_PATH = keyPath;
225
+ const connect = spyOn(Client.prototype, "connect");
226
+ try {
227
+ await expect(createTunnel("redis", { app, environment: "testing", port: freePort() })).rejects.toThrow(
228
+ `The redis tunnel for demo-testing could not read the key SSH_TUNNEL_PRIVATE_KEY_PATH names, ${keyPath} (ENOENT)`,
229
+ );
230
+ expect(connect).not.toHaveBeenCalled();
231
+ } finally {
232
+ connect.mockRestore();
233
+ }
213
234
  });
214
235
 
215
236
  test("listens where SSH_TUNNEL_BIND_HOST says and warns when that is not loopback", async () => {
@@ -20,19 +20,25 @@ interface TunnelOption {
20
20
  port?: number;
21
21
  }
22
22
 
23
- const tunnelAuth = (
24
- app: AppExecutor,
25
- repoName: string,
26
- ): Pick<ConnectConfig, "privateKey" | "passphrase" | "password"> => {
23
+ const readTunnelKey = (purpose: string, keyPath: string) => {
24
+ try {
25
+ return readFileSync(keyPath);
26
+ } catch (error) {
27
+ const reason = (error as NodeJS.ErrnoException).code ?? (error instanceof Error ? error.message : String(error));
28
+ throw new Error(`${purpose} could not read the key SSH_TUNNEL_PRIVATE_KEY_PATH names, ${keyPath} (${reason}).`, {
29
+ cause: error,
30
+ });
31
+ }
32
+ };
33
+
34
+ const tunnelAuth = (purpose: string): Pick<ConnectConfig, "privateKey" | "passphrase" | "password"> => {
27
35
  const keyPath = tunnelEnv.get("SSH_TUNNEL_PRIVATE_KEY_PATH");
28
36
  const passphrase = tunnelEnv.get("SSH_TUNNEL_PASSPHRASE");
29
- if (keyPath) return { privateKey: readFileSync(keyPath), ...(passphrase ? { passphrase } : {}) };
37
+ if (keyPath) return { privateKey: readTunnelKey(purpose, keyPath), ...(passphrase ? { passphrase } : {}) };
30
38
  if (process.env.SSH_TUNNEL_PASSWORD) return { password: process.env.SSH_TUNNEL_PASSWORD };
31
- app.logger.warn(
32
- "The SSH tunnel uses the default shared credential. " +
33
- "Set SSH_TUNNEL_PRIVATE_KEY_PATH to a key (or SSH_TUNNEL_PASSWORD) once the cluster's tunnel endpoint accepts it.",
39
+ throw new Error(
40
+ `${purpose} needs an SSH credential: export SSH_TUNNEL_PRIVATE_KEY_PATH (with SSH_TUNNEL_PASSPHRASE if the key has one) in the shell, or set SSH_TUNNEL_PASSWORD.`,
34
41
  );
35
- return { password: repoName };
36
42
  };
37
43
 
38
44
  const tunnelHostVerifier = (app: AppExecutor, hostId: string, onRefusal: (reason: string) => void) => {
@@ -75,7 +81,8 @@ export const createTunnel = async (
75
81
  const baseDevEnv = WorkspaceExecutor.getBaseDevEnv();
76
82
  WorkspaceExecutor.assertDeployableEnv(baseDevEnv, environment, `The ${service} tunnel`);
77
83
  for (const line of tunnelEnv.ignored()) app.logger.warn(line);
78
- const { serveDomain, repoName } = baseDevEnv;
84
+ const auth = tunnelAuth(`The ${service} tunnel for ${app.name}-${environment}`);
85
+ const { serveDomain } = baseDevEnv;
79
86
  const host = `${app.name}-${environment}.${serveDomain}`;
80
87
  //? RFC 6761 makes *.localhost loopback, but only macOS resolves it; glibc without systemd-resolved and Windows answer ENOTFOUND
81
88
  const sshHost = host.endsWith(".localhost") ? "localhost" : host;
@@ -101,7 +108,7 @@ export const createTunnel = async (
101
108
  host: sshHost,
102
109
  port: sshPort,
103
110
  username: process.env.SSH_TUNNEL_USERNAME ?? "root",
104
- ...tunnelAuth(app, repoName),
111
+ ...auth,
105
112
  hostVerifier: tunnelHostVerifier(app, `${sshHost}:${sshPort}`, (reason) => {
106
113
  refusal = reason;
107
114
  }),
@@ -1,3 +1,4 @@
1
+ /** @deprecated Nothing in akanjs uses it; removed in a later minor. */
1
2
  export class FileEditor {
2
3
  #filePath: string;
3
4
  #content: string;
@@ -47,3 +47,16 @@ describe("FileSys.ensurePrivateDir", () => {
47
47
  },
48
48
  );
49
49
  });
50
+
51
+ describe("FileSys.writeTextAtomic", () => {
52
+ test("lands one whole write when two writes of one file start together", async () => {
53
+ const dir = mkdtempSync(path.join(tmpdir(), "akan-atomic-"));
54
+ try {
55
+ const file = path.join(dir, "cache.json");
56
+ await Promise.all([FileSys.writeTextAtomic(file, "first"), FileSys.writeTextAtomic(file, "second")]);
57
+ expect(["first", "second"]).toContain(await Bun.file(file).text());
58
+ } finally {
59
+ rmSync(dir, { recursive: true, force: true });
60
+ }
61
+ });
62
+ });
package/util/fileSys.ts CHANGED
@@ -46,8 +46,8 @@ export class FileSys {
46
46
  }
47
47
  // One `rename`, so a watcher never reads a half-written barrel as a user edit. The temp is a sibling (rename is atomic
48
48
  // only within a filesystem), and its `.tmp` suffix is what `HmrChangeClassifier` ignores it by.
49
- static async writeTextAtomic(filePath: string, content: string) {
50
- const temp = `${filePath}.${process.pid}.${Date.now().toString(36)}.tmp`;
49
+ static async writeTextAtomic(filePath: string, content: string | Uint8Array) {
50
+ const temp = `${filePath}.${process.pid}.${crypto.randomUUID()}.tmp`;
51
51
  try {
52
52
  await Bun.write(temp, content);
53
53
  await FileSys.replace(temp, filePath);
@@ -1,6 +1,7 @@
1
1
  import { readdirSync } from "node:fs";
2
2
  import { select } from "@inquirer/prompts";
3
3
 
4
+ /** @deprecated Nothing in akanjs uses it; removed in a later minor. */
4
5
  export const selectModel = async (modulePath: string) => {
5
6
  const modelNames = readdirSync(`${modulePath}/lib`).filter((dir) => !dir.includes(".") && !dir.startsWith("_"));
6
7
  return await select({
@@ -41,6 +41,7 @@ const scanModuleSpecifiers = (source: string, filePath: string, includeExports:
41
41
  return importSpecifiers;
42
42
  };
43
43
 
44
+ /** @deprecated Nothing in akanjs uses it; removed in a later minor. */
44
45
  export const parseTsConfig = (tsConfigPath: string = "./tsconfig.json") => {
45
46
  const configFile = ts.readConfigFile(tsConfigPath, (path) => {
46
47
  return ts.sys.readFile(path);
@@ -73,12 +74,15 @@ const collectFiles = (constantFilePath: string, parsedConfig: ts.ParsedCommandLi
73
74
  return { allFilesToAnalyze, analyzedFiles };
74
75
  };
75
76
 
77
+ /** @deprecated Nothing in akanjs uses it; removed in a later minor. */
76
78
  export const collectImportedFiles = (constantFilePath: string, parsedConfig: ts.ParsedCommandLine) =>
77
79
  collectFiles(constantFilePath, parsedConfig, false);
78
80
 
81
+ /** @deprecated Nothing in akanjs uses it; removed in a later minor. */
79
82
  export const collectExportedFiles = (constantFilePath: string, parsedConfig: ts.ParsedCommandLine) =>
80
83
  collectFiles(constantFilePath, parsedConfig, true);
81
84
 
85
+ /** @deprecated Nothing in akanjs uses it; removed in a later minor. */
82
86
  export const createTsProgram = (filePaths: Set<string>, options: ts.CompilerOptions) => {
83
87
  const spinner = ora("Creating TypeScript program for all files...");
84
88
  spinner.start();
@@ -94,6 +98,7 @@ export const createTsProgram = (filePaths: Set<string>, options: ts.CompilerOpti
94
98
  };
95
99
  };
96
100
 
101
+ /** @deprecated Nothing in akanjs uses it; removed in a later minor. */
97
102
  export const createSymbolCache = (checker: ts.TypeChecker) => {
98
103
  const symbolCache = new Map<string, ts.Symbol | undefined>();
99
104
 
@@ -108,6 +113,7 @@ export const createSymbolCache = (checker: ts.TypeChecker) => {
108
113
  };
109
114
  };
110
115
 
116
+ /** @deprecated Nothing in akanjs uses it; removed in a later minor. */
111
117
  export const analyzeProperties = (filesToAnalyze: Set<string>, program: ts.Program, checker: ts.TypeChecker) => {
112
118
  const propertyMap = new Map<
113
119
  string,
@@ -226,6 +232,7 @@ export const analyzeProperties = (filesToAnalyze: Set<string>, program: ts.Progr
226
232
  return propertyMap;
227
233
  };
228
234
 
235
+ /** @deprecated Nothing in akanjs uses it; removed in a later minor. */
229
236
  export const getRelatedCnsts = (constantFilePath: string) => {
230
237
  const parsedConfig = parseTsConfig();
231
238
  const { allFilesToAnalyze } = collectImportedFiles(constantFilePath, parsedConfig);