@akanjs/devkit 3.3.0-rc.6 → 3.3.0-rc.60

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 (278) hide show
  1. package/DEV_RUNTIME_KNOBS.md +1 -1
  2. package/README.ko.md +8 -2
  3. package/README.md +8 -3
  4. package/akanApp/akanApp.host.test.ts +4 -2
  5. package/akanApp/akanApp.host.ts +11 -0
  6. package/akanConfig/akanBin.ts +4 -0
  7. package/akanConfig/akanConfig.test.ts +280 -19
  8. package/akanConfig/akanConfig.ts +96 -270
  9. package/akanConfig/akanWorkers.test.ts +73 -0
  10. package/akanConfig/akanWorkers.ts +61 -0
  11. package/akanConfig/desktopServerConfig.ts +96 -0
  12. package/akanConfig/dockerImage.ts +216 -0
  13. package/akanConfig/index.ts +2 -0
  14. package/akanConfig/nativeFileSettings.ts +33 -0
  15. package/akanConfig/nativeKeys.ts +52 -0
  16. package/akanConfig/types.ts +2 -0
  17. package/app/appBin.test.ts +63 -0
  18. package/app/appBin.ts +50 -0
  19. package/app/applicationBuildReporter.test.ts +51 -1
  20. package/app/applicationBuildReporter.ts +6 -1
  21. package/app/applicationBuildRunner.test.ts +358 -5
  22. package/app/applicationBuildRunner.ts +204 -30
  23. package/app/dictionarySizes.test.ts +40 -0
  24. package/app/dictionarySizes.ts +95 -0
  25. package/app/routeFilesReport.test.ts +59 -0
  26. package/app/routeFilesReport.ts +46 -0
  27. package/app/routeJsBudget.ts +18 -4
  28. package/artifact/implicitRootLayout.test.ts +19 -0
  29. package/artifact/implicitRootLayout.ts +16 -2
  30. package/artifact/implicitRootLayoutRender.test.tsx +4 -1
  31. package/artifact/storeBootstrap.test.ts +28 -0
  32. package/artifact/storeBootstrap.ts +64 -8
  33. package/biome.base.json +7 -5
  34. package/codeAgent/agent/CodeAgent.ts +36 -16
  35. package/codeAgent/agent/CodeAgentAllowed.ts +35 -0
  36. package/codeAgent/agent/CodeAgentCommandLine.ts +372 -0
  37. package/codeAgent/agent/CodeAgentGate.ts +23 -4
  38. package/codeAgent/agent/CodeAgentRpcHost.ts +1 -1
  39. package/codeAgent/agent/codeAgent.test.ts +62 -0
  40. package/codeAgent/agent/codeAgentCommandLine.test.ts +212 -0
  41. package/codeAgent/agent/codeAgentContract.test.ts +117 -5
  42. package/codeAgent/skills/akan-agent/SKILL.md +8 -1
  43. package/codeAgent/skills/akan-code/SKILL.md +38 -3
  44. package/codeAgent/skills/akan-debug/SKILL.md +1 -1
  45. package/codeAgent/skills/akan-deps/SKILL.md +3 -2
  46. package/codeAgent/skills/akan-err/SKILL.md +13 -8
  47. package/codeAgent/skills/akan-mcp/SKILL.md +1 -1
  48. package/codeAgent/skills/akan-module/SKILL.md +2 -2
  49. package/codeAgent/skills/akan-page/SKILL.md +46 -29
  50. package/codeAgent/skills/akan-query/SKILL.md +13 -20
  51. package/codeAgent/skills/akan-runtime/SKILL.md +21 -1
  52. package/codeAgent/skills/akan-service/SKILL.md +10 -11
  53. package/codeAgent/skills/akan-transport/SKILL.md +5 -14
  54. package/codeAgent/skills/akan-ui/SKILL.md +16 -21
  55. package/commandDecorators/command.ts +28 -12
  56. package/commandDecorators/commandBuilder.ts +8 -1
  57. package/commandDecorators/commandDecorators.test.ts +70 -3
  58. package/commandDecorators/helpFormatter.ts +14 -12
  59. package/context/akanContext.ts +2 -0
  60. package/csrE2e/devHmrLatency.e2e.test.ts +1 -1
  61. package/docs/apiReference.test.ts +9 -0
  62. package/docs/apiReference.ts +15 -0
  63. package/executors/appExecutor.ts +26 -12
  64. package/executors/clientRuntimeKeyOrder.fixture.json +682 -0
  65. package/executors/clientRuntimeKeys.fixture.json +393 -0
  66. package/executors/clientRuntimeKeys.test.ts +1690 -0
  67. package/executors/executor.ts +14 -6
  68. package/executors/executors.test.ts +140 -1
  69. package/executors/sysExecutor.ts +112 -8
  70. package/executors/workspaceExecutor.ts +7 -4
  71. package/frontendBuild/allRoutesBuilder.ts +99 -7
  72. package/frontendBuild/autoImportSync.ts +3 -2
  73. package/frontendBuild/buildRouteClient.test.ts +686 -13
  74. package/frontendBuild/clientBuildTypes.ts +26 -0
  75. package/frontendBuild/clientEntriesBundler.ts +49 -1
  76. package/frontendBuild/clientEntryDiscovery.test.ts +308 -1
  77. package/frontendBuild/clientEntryDiscovery.ts +136 -14
  78. package/frontendBuild/clientEntryGroups.test.ts +77 -0
  79. package/frontendBuild/clientEntryGroups.ts +61 -0
  80. package/frontendBuild/csrDevArtifactWriter.ts +2 -2
  81. package/frontendBuild/csrDevModuleCompiler.test.ts +86 -0
  82. package/frontendBuild/csrDevModuleCompiler.ts +44 -8
  83. package/frontendBuild/csrDevPatcher.test.ts +1 -1
  84. package/frontendBuild/csrDevPatcher.ts +33 -7
  85. package/frontendBuild/csrDevTypes.ts +9 -0
  86. package/frontendBuild/devBarrelImports.test.ts +154 -0
  87. package/frontendBuild/devBarrelImports.ts +83 -23
  88. package/frontendBuild/devRegistryBundler.ts +4 -2
  89. package/frontendBuild/devRouteRuntime.test.ts +492 -0
  90. package/frontendBuild/devRouteRuntime.ts +167 -0
  91. package/frontendBuild/dictionaryAssetBuilder.test.ts +408 -0
  92. package/frontendBuild/dictionaryAssetBuilder.ts +185 -17
  93. package/frontendBuild/dictionaryConstants.ts +136 -0
  94. package/frontendBuild/dictionaryOwnParts.ts +88 -0
  95. package/frontendBuild/dictionaryPackState.ts +131 -0
  96. package/frontendBuild/dictionaryPacking.test.ts +207 -0
  97. package/frontendBuild/dictionaryPacking.ts +160 -0
  98. package/frontendBuild/dictionaryRoutes.test.ts +251 -0
  99. package/frontendBuild/dictionaryRoutes.ts +227 -0
  100. package/frontendBuild/pagesBundleBuilder.test.ts +84 -0
  101. package/frontendBuild/pagesBundleBuilder.ts +78 -2
  102. package/frontendBuild/precompressArtifacts.test.ts +22 -0
  103. package/frontendBuild/precompressArtifacts.ts +34 -8
  104. package/frontendBuild/registryMetadataFingerprint.ts +3 -3
  105. package/frontendBuild/renderedEntries.ts +144 -0
  106. package/frontendBuild/routeClientBuilder.ts +407 -43
  107. package/frontendBuild/routeHandoffs.test.ts +155 -0
  108. package/frontendBuild/routeHandoffs.ts +117 -0
  109. package/frontendBuild/routeModulePreloads.test.ts +32 -0
  110. package/frontendBuild/routeModulePreloads.ts +20 -11
  111. package/frontendBuild/routeRuntimeCheck.test.ts +280 -0
  112. package/frontendBuild/routeRuntimeCheck.ts +248 -0
  113. package/frontendBuild/routeRuntimePays.test.ts +143 -0
  114. package/frontendBuild/routeRuntimePays.ts +117 -0
  115. package/frontendBuild/ssrBaseArtifactBuilder.ts +24 -34
  116. package/frontendBuild/ssrDevBundler.test.ts +150 -1
  117. package/frontendBuild/ssrDevBundler.ts +66 -11
  118. package/frontendBuild/vendorFileImports.test.ts +254 -0
  119. package/frontendBuild/vendorFileImports.ts +163 -0
  120. package/frontendBuild/vendorNarrowing.ts +28 -0
  121. package/frontendBuild/vendorSpecifiers.ts +2 -0
  122. package/incrementalBuilder/buildBatch.proc.ts +9 -9
  123. package/incrementalBuilder/buildBatchProtocol.ts +1 -1
  124. package/incrementalBuilder/builderBoot.ts +5 -5
  125. package/incrementalBuilder/builderGraphPayloads.ts +4 -4
  126. package/incrementalBuilder/builderLanes.ts +2 -2
  127. package/incrementalBuilder/builderWatch.ts +8 -8
  128. package/incrementalBuilder/csrRegistry.ts +4 -4
  129. package/incrementalBuilder/incrementalBuilder.proc.test.ts +79 -0
  130. package/incrementalBuilder/incrementalBuilder.proc.ts +27 -8
  131. package/incrementalBuilder/ssrRegistry.ts +6 -6
  132. package/index.ts +1 -1
  133. package/integration/renderAdmissionSoak.test.ts +99 -0
  134. package/integration/renderAdmissionSoak.ts +609 -0
  135. package/lint/__fixtures__/no-arbitrary-color/every-color-function/bad.tsx +11 -0
  136. package/lint/__fixtures__/no-arbitrary-color/every-color-function/good.tsx +2 -0
  137. package/lint/__fixtures__/no-daisyui-legacy-class/every-class/bad.tsx +34 -0
  138. package/lint/__fixtures__/no-daisyui-legacy-class/every-class/good.tsx +2 -0
  139. package/lint/__fixtures__/no-inline-color/every-color-function/bad.tsx +10 -0
  140. package/lint/__fixtures__/no-inline-color/every-color-function/good.tsx +2 -0
  141. package/lint/__fixtures__/no-raw-palette-class/every-palette/bad.tsx +22 -0
  142. package/lint/__fixtures__/no-raw-palette-class/every-palette/good.tsx +2 -0
  143. package/lint/biomeBase.test.ts +50 -3
  144. package/lint/biomeBase.ts +1 -1
  145. package/lint/biomeCheck.test.ts +162 -0
  146. package/lint/biomeCheck.ts +131 -0
  147. package/lint/linter.test.ts +16 -11
  148. package/lint/no-arbitrary-color.grit +5 -0
  149. package/lint/no-conditional-st-hook.grit +5 -1
  150. package/lint/no-daisyui-legacy-class.grit +8 -0
  151. package/lint/no-document-cookie.grit +3 -0
  152. package/lint/no-inline-color.grit +10 -2
  153. package/lint/no-oversized-list-limit.grit +2 -0
  154. package/lint/no-raw-palette-class.grit +7 -0
  155. package/lint/no-unpublished-form-setter.grit +2 -0
  156. package/lint/no-web-only-api-outside-webkit.grit +5 -0
  157. package/lint/no-web-storage.grit +3 -0
  158. package/lint/withheldEnvFile.ts +17 -0
  159. package/mobile/desktopBin.ts +2 -2
  160. package/mobile/desktopServerStage.test.ts +18 -3
  161. package/mobile/desktopServerStage.ts +7 -2
  162. package/mobile/nativeApp.test.ts +7 -5
  163. package/mobile/nativeApp.ts +2 -2
  164. package/mobile/nativeConfig.test.ts +96 -1
  165. package/mobile/nativeConfig.ts +46 -12
  166. package/mobile/nativePublicEnv.ts +1 -1
  167. package/mobile/serverBundleSecrets.ts +43 -0
  168. package/package.json +20 -171
  169. package/packageExports.test.ts +38 -24
  170. package/quality/dictionaryKeys.test.ts +356 -0
  171. package/quality/dictionaryKeys.ts +488 -0
  172. package/quality/objectImportReport.test.ts +36 -0
  173. package/quality/objectImportReport.ts +105 -0
  174. package/quality/qualityScanner.ts +1 -1
  175. package/quality/routeRuntimeReport.test.ts +91 -0
  176. package/quality/routeRuntimeReport.ts +121 -0
  177. package/quality/runtimeConstantFacts.ts +71 -0
  178. package/quality/runtimeConstantGraph.ts +123 -0
  179. package/quality/runtimeConstantReads.ts +116 -0
  180. package/quality/runtimeImports.test.ts +190 -0
  181. package/quality/runtimeImports.ts +233 -0
  182. package/quality/runtimeKeyNames.ts +46 -0
  183. package/quality/runtimeLexicalScope.ts +132 -0
  184. package/quality/runtimeMarkerReach.test.ts +84 -0
  185. package/quality/runtimeMarkerReach.ts +255 -0
  186. package/quality/runtimeModuleFacts.ts +290 -0
  187. package/quality/runtimeNameTable.test.ts +172 -0
  188. package/quality/runtimeNameTable.ts +477 -0
  189. package/quality/runtimeScopeReport.test.ts +123 -0
  190. package/quality/runtimeScopeReport.ts +167 -0
  191. package/quality/runtimeSliceKey.ts +269 -0
  192. package/quality/runtimeSyntax.ts +133 -0
  193. package/quality/runtimeTable.fixture.ts +189 -0
  194. package/quality/runtimeUse.test.ts +737 -0
  195. package/quality/runtimeUse.ts +696 -0
  196. package/quality/runtimeUseReadable.test.ts +393 -0
  197. package/quality/ssrScanner.test.ts +13 -0
  198. package/quality/ssrScanner.ts +1 -1
  199. package/quality/translatorBindings.ts +187 -0
  200. package/test/secretEnvFixture.ts +134 -0
  201. package/test/testHelpers.ts +11 -0
  202. package/transforms/barrelAnalyzer.ts +26 -4
  203. package/transforms/barrelImportsPlugin.ts +121 -32
  204. package/transforms/exportReach.test.ts +162 -0
  205. package/transforms/exportReach.ts +308 -0
  206. package/transforms/frameworkObjects.fixture.tsx +58 -0
  207. package/transforms/frameworkObjects.test.ts +54 -0
  208. package/transforms/modelReference.test.ts +196 -0
  209. package/transforms/modelReference.ts +39 -0
  210. package/transforms/moduleParts.test.ts +225 -0
  211. package/transforms/moduleParts.ts +418 -0
  212. package/transforms/objectImportEdits.ts +150 -0
  213. package/transforms/objectMemberImports.test.ts +633 -0
  214. package/transforms/objectMemberImports.ts +571 -0
  215. package/transforms/objectMemberLookup.ts +150 -0
  216. package/transforms/objectModule.test.ts +307 -0
  217. package/transforms/objectModule.ts +482 -0
  218. package/transforms/objectModuleAnalyzer.ts +104 -0
  219. package/transforms/partImports.test.ts +76 -0
  220. package/transforms/partImports.ts +110 -0
  221. package/transforms/partModules.test.ts +187 -0
  222. package/transforms/partModules.ts +90 -0
  223. package/transforms/partPurity.ts +124 -0
  224. package/transforms/reactIconImports.test.ts +231 -0
  225. package/transforms/reactIconImports.ts +325 -0
  226. package/transforms/routeConstants.ts +122 -0
  227. package/transforms/routeRuntime.test.ts +835 -0
  228. package/transforms/routeRuntime.ts +703 -0
  229. package/transforms/routeRuntimeEdits.ts +92 -0
  230. package/transforms/routeRuntimeGraph.ts +66 -0
  231. package/transforms/routeRuntimePlan.ts +244 -0
  232. package/transforms/secretEnvDeclaration.test.ts +208 -0
  233. package/transforms/secretEnvDeclaration.ts +213 -0
  234. package/transforms/secretEnvFile.test.ts +117 -0
  235. package/transforms/secretEnvFile.ts +113 -0
  236. package/transforms/secretEnvName.test.ts +54 -0
  237. package/transforms/secretEnvName.ts +29 -0
  238. package/transforms/secretEnvSource.test.ts +148 -0
  239. package/transforms/secretEnvSource.ts +166 -0
  240. package/transforms/serverEnvEvaluationError.ts +11 -0
  241. package/transforms/serverEnvPlugin.test.ts +2 -1
  242. package/transforms/serverEnvPlugin.ts +13 -0
  243. package/transforms/serverEnvProfile.test.ts +129 -2
  244. package/transforms/serverEnvProfile.ts +126 -40
  245. package/transforms/serverEnvSecrets.test.ts +292 -0
  246. package/transforms/signalDescriptors.test.ts +280 -0
  247. package/transforms/signalDescriptors.ts +227 -0
  248. package/transforms/thisFreeExports.ts +87 -0
  249. package/transforms/transforms.test.ts +180 -3
  250. package/transforms/tsconfigPackageResolver.test.ts +1 -0
  251. package/tunnel/createTunnel.test.ts +29 -8
  252. package/tunnel/createTunnel.ts +22 -11
  253. package/tunnel/ssh2Module.test.ts +37 -0
  254. package/tunnel/ssh2Module.ts +32 -0
  255. package/tunnel/sshTunnel.ts +4 -2
  256. package/typecheck/projectTypecheck.test.ts +32 -1
  257. package/typecheck/projectTypecheck.ts +3 -3
  258. package/typecheck/typeChecker.test.ts +49 -0
  259. package/typecheck/typeChecker.ts +9 -7
  260. package/typecheck/withheldDiagnostics.ts +41 -0
  261. package/util/fileEditor.ts +1 -0
  262. package/util/selectModel.ts +1 -0
  263. package/workflow/executor.ts +6 -2
  264. package/workflow/index.ts +1 -0
  265. package/workflow/plan.ts +36 -7
  266. package/workflow/types.ts +1 -1
  267. package/workflow/uiTarget.ts +50 -0
  268. package/workspace/envSeed.test.ts +30 -1
  269. package/workspace/envSeed.ts +30 -1
  270. package/workspace/getRelatedCnsts.ts +7 -0
  271. package/workspace/mainCheckout.test.ts +55 -0
  272. package/workspace/mainCheckout.ts +38 -0
  273. package/workspace/scanInfo.test.ts +39 -0
  274. package/workspace/scanInfo.ts +55 -6
  275. package/workspace/slicePlanner.ts +1 -1
  276. package/workspace/workspaceLayout.test.ts +5 -1
  277. package/workspace/workspaceLayout.ts +3 -0
  278. package/CHANGELOG.md +0 -2717
@@ -0,0 +1,212 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { CodeAgentCommandLine } from "./CodeAgentCommandLine";
3
+
4
+ const names = (line: string) => CodeAgentCommandLine.allowable(line);
5
+
6
+ describe("CodeAgentCommandLine.allowable", () => {
7
+ test("a command is named by its program, and by its sub-command where that is what matters", () => {
8
+ expect(names("ls -la apps")).toEqual(["ls"]);
9
+ expect(names("git status --short")).toEqual(["git status"]);
10
+ expect(names("bun test --isolate ./a.test.ts")).toEqual(["bun test"]);
11
+ expect(names("bun x cowsay hi")).toEqual(["bun x"]);
12
+ expect(names("kubectl get pods -n web")).toEqual(["kubectl get"]);
13
+ expect(names("akan verify @akanjs/cli")).toEqual(["akan verify"]);
14
+ expect(names("bunx tsc --noEmit")).toEqual(["bunx tsc"]);
15
+ expect(names("./scripts/check.sh --all")).toEqual(["./scripts/check.sh"]);
16
+ expect(names("/usr/bin/git diff")).toEqual(["/usr/bin/git diff"]);
17
+ });
18
+
19
+ test("a harmless variable set in front of a command does not change its name", () => {
20
+ expect(names("CI=1 NODE_ENV=test bun test")).toEqual(["bun test"]);
21
+ expect(
22
+ names("FORCE_COLOR=0 NO_COLOR=1 TZ=UTC LANG=C LC_ALL=C.UTF-8 TERM=dumb DEBUG=app:* PORT=3000 bun test"),
23
+ ).toEqual(["bun test"]);
24
+ expect(names("CI=1; ls")).toEqual(["ls"]);
25
+ });
26
+
27
+ test("any other variable set in front of a command, or one whose value is not a plain word, has no name to remember", () => {
28
+ for (const line of [
29
+ "GIT_SSH_COMMAND='ssh -i key' git status",
30
+ "PATH=/tmp/bin git status",
31
+ "GIT_PAGER=less git log",
32
+ "LD_PRELOAD=./x.so ls",
33
+ "BASH_ENV=./x.sh ls",
34
+ "NODE_OPTIONS=--require=./x.js bun test",
35
+ "CI=1 PATH=/tmp/bin ls",
36
+ "PATH=/tmp/bin; git status",
37
+ 'CI="1" bun test',
38
+ "CI=\\1 bun test",
39
+ "CI=$X bun test",
40
+ "CI=$(date) bun test",
41
+ "CI+=1 bun test",
42
+ "TZ=~/zone ls",
43
+ "'CI=1' ls",
44
+ ])
45
+ expect(names(line)).toBeUndefined();
46
+ });
47
+
48
+ test("every command of a compound line is named once", () => {
49
+ expect(names("cd apps && bun test; git status | head -5 || git status")).toEqual([
50
+ "cd",
51
+ "bun test",
52
+ "git status",
53
+ "head",
54
+ ]);
55
+ expect(names("(cd apps && ls) & wait")).toEqual(["cd", "ls", "wait"]);
56
+ expect(names('echo "at $(git rev-parse HEAD)" $(date +%s)')).toEqual(["git rev-parse", "date", "echo"]);
57
+ expect(names("bun test\ngit diff --stat")).toEqual(["bun test", "git diff"]);
58
+ expect(names("bun test \\\n --bail # stop early")).toEqual(["bun test"]);
59
+ });
60
+
61
+ test("quotes keep a separator inside an argument, and are read through in a program's name", () => {
62
+ expect(names(`git commit -m "fix: a && b; c | d"`)).toEqual(["git commit"]);
63
+ expect(names(`grep -rn 'a|b' src`)).toEqual(["grep"]);
64
+ expect(names(`'git' "status"`)).toEqual(["git status"]);
65
+ expect(names(`echo \\; done`)).toEqual(["echo"]);
66
+ });
67
+
68
+ test("a redirection is read past when it writes no file", () => {
69
+ expect(names("bun test 2>&1 | tail -20")).toEqual(["bun test", "tail"]);
70
+ expect(names("bun test > /dev/null 2>&1")).toEqual(["bun test"]);
71
+ expect(names("bun test &>/dev/null")).toEqual(["bun test"]);
72
+ expect(names("sort < names.txt")).toEqual(["sort"]);
73
+ expect(names("grep -c x <<< hello")).toEqual(["grep"]);
74
+ });
75
+
76
+ test("a line that writes a file through a redirection has no name to remember", () => {
77
+ for (const line of ["echo hi > out.txt", "echo hi >> ~/.zshrc", "bun test 2> err.log", "ls &> all.log", "ls >&out"])
78
+ expect(names(line)).toBeUndefined();
79
+ });
80
+
81
+ test("the always-asked commands have no name to remember, however they are spelled", () => {
82
+ for (const line of [
83
+ "curl https://example.com",
84
+ "ssh deploy@host",
85
+ "git push",
86
+ "git push origin main",
87
+ "/usr/bin/git push",
88
+ `git "push" -f`,
89
+ "g''it pu\\sh",
90
+ "rm -rf build",
91
+ "/bin/rm a.txt",
92
+ "RM a.txt",
93
+ "sudo ls",
94
+ "env FOO=1 ls",
95
+ "timeout 5 bun test",
96
+ "ls | xargs wc -l",
97
+ "sh -c 'ls'",
98
+ "bash scripts/x.sh",
99
+ "eval ls",
100
+ "ls && rm a.txt",
101
+ "echo $(curl https://example.com)",
102
+ 'echo "$(rm a.txt)"',
103
+ "(git push)",
104
+ ])
105
+ expect(names(line)).toBeUndefined();
106
+ });
107
+
108
+ test("a command the shell itself uses to run another, or to set what a later one runs, has no name to remember", () => {
109
+ for (const line of [
110
+ "builtin eval ls",
111
+ "source ./x.sh",
112
+ ". ./x.sh",
113
+ "trap 'ls' EXIT",
114
+ "alias a='ls'",
115
+ "coproc ls",
116
+ "export PATH=/tmp/bin",
117
+ "declare -x A=1",
118
+ "typeset -x A=1",
119
+ "readonly A=1",
120
+ "ls && export CI=1",
121
+ ])
122
+ expect(names(line)).toBeUndefined();
123
+ });
124
+
125
+ test("a redirection that opens a connection has no name to remember", () => {
126
+ for (const line of [
127
+ "bun test </dev/tcp/host/80",
128
+ "bun test < /dev/udp/host/53",
129
+ "cat <//dev/tcp/host/80",
130
+ "ls > /dev/tcp/host/80",
131
+ "ls 3<>/dev/tcp/host/80",
132
+ "sort < $FILE",
133
+ ])
134
+ expect(names(line)).toBeUndefined();
135
+ expect(names('grep -c x <<< "$VALUE"')).toEqual(["grep"]);
136
+ });
137
+
138
+ test("a command that sends something out of the machine has no name to remember", () => {
139
+ for (const line of [
140
+ "npm publish",
141
+ "pnpm publish --no-git-checks",
142
+ "yarn publish",
143
+ "yarn npm publish",
144
+ "bun publish",
145
+ "cargo publish",
146
+ "docker push repo/image",
147
+ "docker image push repo/image",
148
+ "docker compose push",
149
+ "docker build --push -t repo/image .",
150
+ "docker buildx build --push=true .",
151
+ "ls && npm publish",
152
+ ])
153
+ expect(names(line)).toBeUndefined();
154
+ });
155
+
156
+ test("gh is named two words deep, and gh api has no name to remember", () => {
157
+ expect(names("gh pr view 12")).toEqual(["gh pr view"]);
158
+ expect(names("gh issue list --state open")).toEqual(["gh issue list"]);
159
+ expect(names("gh status")).toEqual(["gh status"]);
160
+ expect(names("gh pr view 12 && gh pr merge 12")).toEqual(["gh pr view", "gh pr merge"]);
161
+ for (const line of [
162
+ "gh",
163
+ "gh api repos/o/r",
164
+ "gh api -X POST repos/o/r",
165
+ "gh pr --repo o/r merge 12",
166
+ "gh -R o/r pr view",
167
+ ])
168
+ expect(names(line)).toBeUndefined();
169
+ });
170
+
171
+ test("a line continued after a space joins its words, and one continued inside a word joins the word", () => {
172
+ expect(names("git \\\npush")).toBeUndefined();
173
+ expect(names("git \\\n push origin main")).toBeUndefined();
174
+ expect(names("git \\\nstatus")).toEqual(["git status"]);
175
+ expect(names("git\\\npush")).toEqual(["gitpush"]);
176
+ expect(names("git \\\r\npush")).toBeUndefined();
177
+ });
178
+
179
+ test("a sub-command that is not the word right after its program is not guessed", () => {
180
+ for (const line of ["git -C ../other push", "git --git-dir=x status", "git", "bun --cwd apps test", "git $SUB"])
181
+ expect(names(line)).toBeUndefined();
182
+ });
183
+
184
+ test("a line it cannot read with confidence has no name", () => {
185
+ for (const line of [
186
+ "",
187
+ "FOO=1",
188
+ "# only a comment",
189
+ "echo `date`",
190
+ "$TOOL --version",
191
+ "for f in *.ts; do wc -l $f; done",
192
+ "if true; then ls; fi",
193
+ "! ls",
194
+ "[ -f a ] && ls",
195
+ "{ ls; }",
196
+ "find . -name '*.log' -exec cat {} \\;",
197
+ "cat <<EOF\nhi\nEOF",
198
+ "diff <(ls a) <(ls b)",
199
+ "echo $((1 + 2))",
200
+ "echo $'a\\x62'",
201
+ // biome-ignore lint/suspicious/noTemplateCurlyInString: a shell expansion, not a template
202
+ "echo ${A:-$(date)}",
203
+ "ls 'unterminated",
204
+ 'ls "unterminated',
205
+ "ls )",
206
+ "echo $(ls",
207
+ "ls >",
208
+ "ls > > a",
209
+ ])
210
+ expect(names(line)).toBeUndefined();
211
+ });
212
+ });
@@ -16,6 +16,7 @@ import {
16
16
  } from "akanjs/common";
17
17
  import { akanCodeModelWarnings } from "./akanCodeModel";
18
18
  import { CodeAgentAsks } from "./CodeAgentAsks";
19
+ import { CodeAgentCommandLine } from "./CodeAgentCommandLine";
19
20
  import { CodeAgentEventMapper } from "./CodeAgentEventMapper";
20
21
  import { CodeAgentGate } from "./CodeAgentGate";
21
22
  import { CodeAgentStreamPrinter } from "./CodeAgentStreamPrinter";
@@ -107,7 +108,15 @@ describe("codeAgentPresets", () => {
107
108
 
108
109
  test("web asks before writing even though the runner is isolated", () => {
109
110
  expect(codeAgentPresets.web(root).approval).toBe("writes");
110
- expect(codeAgentPresets.local(root).approval).toBe("never");
111
+ });
112
+
113
+ test("local asks before a shell command and nothing else, and a pod asks about neither", () => {
114
+ const local = new CodeAgentGate(codeAgentPresets.local(root));
115
+ expect(local.verdict("bash", { command: "git status" }).approval).toBe("run: git status");
116
+ expect(local.verdict("bash", { command: "curl https://example.com" }).strict).toBe(true);
117
+ expect(local.verdict("write", { path: "a.ts" })).toEqual({});
118
+ expect(local.verdict("read", { path: "a.ts" })).toEqual({});
119
+ expect(new CodeAgentGate(codeAgentPresets.pod(root)).verdict("bash", { command: "git status" })).toEqual({});
111
120
  });
112
121
 
113
122
  test("every preset denies env files and secrets", () => {
@@ -134,6 +143,8 @@ describe("codeAgentPresets", () => {
134
143
  });
135
144
  });
136
145
 
146
+ const localUnasked = () => ({ ...codeAgentPresets.local(root), approval: "never" as const });
147
+
137
148
  describe("CodeAgentGate", () => {
138
149
  test("blocks a path on the deny list", () => {
139
150
  const gate = new CodeAgentGate(codeAgentPresets.local(root));
@@ -174,6 +185,107 @@ describe("CodeAgentGate", () => {
174
185
  });
175
186
  });
176
187
 
188
+ describe("CodeAgentGate allow for this session", () => {
189
+ const gate = () => new CodeAgentGate(codeAgentPresets.local(root));
190
+ const allow = (target: CodeAgentGate, names: string[]) => {
191
+ target.allowed.offer("a0", names);
192
+ target.allowed.settle("a0", true);
193
+ };
194
+
195
+ test("a command asks with the name a session answer would remember", () => {
196
+ expect(gate().verdict("bash", { command: "git status --short" })).toEqual({
197
+ approval: "run: git status --short",
198
+ remember: ["git status"],
199
+ });
200
+ });
201
+
202
+ test("an allowed command runs unasked, and another sub-command of its program still asks", () => {
203
+ const local = gate();
204
+ allow(local, ["git status", "bun test"]);
205
+ expect(local.verdict("bash", { command: "git status" })).toEqual({});
206
+ expect(local.verdict("bash", { command: "bun test --isolate ./a.test.ts" })).toEqual({});
207
+ expect(local.verdict("bash", { command: "git diff" }).remember).toEqual(["git diff"]);
208
+ expect(local.verdict("bash", { command: "bun x cowsay" }).remember).toEqual(["bun x"]);
209
+ });
210
+
211
+ test("a compound line runs unasked only once every command in it is allowed, and offers the ones that are not", () => {
212
+ const local = gate();
213
+ allow(local, ["bun test"]);
214
+ const line = { command: "cd apps && bun test 2>&1 | tail -20" };
215
+ expect(local.verdict("bash", line).remember).toEqual(["cd", "tail"]);
216
+ allow(local, ["cd"]);
217
+ expect(local.verdict("bash", line).remember).toEqual(["tail"]);
218
+ allow(local, ["tail"]);
219
+ expect(local.verdict("bash", line)).toEqual({});
220
+ expect(local.verdict("bash", { command: "bun test && echo $(git log -1)" }).remember).toEqual(["git log", "echo"]);
221
+ });
222
+
223
+ test("a networking command, git push, rm and a command that runs another are asked every time with no session answer", () => {
224
+ const local = gate();
225
+ allow(local, [...CodeAgentCommandLine.alwaysAsked, "git", "ls", "echo"]);
226
+ for (const command of [
227
+ "curl https://example.com",
228
+ "curl http://127.0.0.1:3000/health",
229
+ "ls && ssh deploy@host",
230
+ "git push",
231
+ "git push origin main",
232
+ "ls; rm -rf build",
233
+ "sudo ls",
234
+ "timeout 5 ls",
235
+ "sh -c 'ls'",
236
+ "ls | xargs echo",
237
+ "source ./x.sh",
238
+ "npm publish",
239
+ "gh api user",
240
+ "PATH=/tmp/bin ls",
241
+ "ls </dev/tcp/host/80",
242
+ ]) {
243
+ const verdict = local.verdict("bash", { command });
244
+ expect(verdict.approval).toBeDefined();
245
+ expect(verdict.remember).toBeUndefined();
246
+ }
247
+ });
248
+
249
+ test("a networking command stays asked every time where network requests are not asked about", () => {
250
+ const { askOutside: _ask, ...network } = codeAgentPresets.local(root).network;
251
+ const quiet = new CodeAgentGate({ ...codeAgentPresets.local(root), network });
252
+ expect(quiet.verdict("bash", { command: "curl https://example.com" })).toEqual({
253
+ approval: "run: curl https://example.com",
254
+ });
255
+ });
256
+
257
+ test("a line that cannot be split with confidence, or that writes a file by redirection, asks with no session answer", () => {
258
+ const local = gate();
259
+ allow(local, ["echo", "ls", "wc"]);
260
+ for (const command of ["echo `ls`", "for f in a b; do wc -l $f; done", "echo hi > ~/.zshrc", "ls | wc -l > n.txt"])
261
+ expect(local.verdict("bash", { command })).toEqual({ approval: `run: ${command}` });
262
+ });
263
+
264
+ test("forgetting what was allowed asks again", () => {
265
+ const local = gate();
266
+ allow(local, ["ls"]);
267
+ expect(local.allowed.names).toEqual(["ls"]);
268
+ expect(local.allowed.clear()).toBe(1);
269
+ expect(local.verdict("bash", { command: "ls" }).remember).toEqual(["ls"]);
270
+ });
271
+
272
+ test("a file write that waits for approval has no session answer", () => {
273
+ const web = new CodeAgentGate(codeAgentPresets.web(root));
274
+ expect(web.verdict("write", { path: "a.ts" })).toEqual({ approval: "write a.ts" });
275
+ });
276
+
277
+ test("an approval still waiting is covered once the names it offered are all allowed", () => {
278
+ const local = gate();
279
+ local.allowed.offer("a1", ["bun test"]);
280
+ local.allowed.offer("a2", ["bun test"]);
281
+ local.allowed.offer("a3", ["bun test", "cd"]);
282
+ expect(local.allowed.settle("a1", true)).toEqual(["bun test"]);
283
+ expect(local.allowed.covered()).toEqual(["a2"]);
284
+ expect(local.allowed.settle("a2", false)).toEqual([]);
285
+ expect(local.allowed.covered()).toEqual([]);
286
+ });
287
+ });
288
+
177
289
  describe("CodeAgentAsks", () => {
178
290
  const questionOf = (questionId: string): CodeAgentQuestion => ({
179
291
  questionId,
@@ -409,15 +521,15 @@ describe("CodeAgentGate bash", () => {
409
521
  expect(gate.verdict("bash", { command: "openssl x509 -in server.pem" }).block).toContain(".pem");
410
522
  });
411
523
 
412
- test("leaves an ordinary command alone", () => {
413
- const gate = new CodeAgentGate(codeAgentPresets.local(root));
524
+ test("leaves an ordinary command alone where commands are not asked about", () => {
525
+ const gate = new CodeAgentGate(localUnasked());
414
526
  expect(gate.verdict("bash", { command: "bun test --isolate" })).toEqual({});
415
527
  expect(gate.verdict("bash", { command: "grep -r TODO ." })).toEqual({});
416
528
  });
417
529
  });
418
530
 
419
531
  describe("CodeAgentGate secrets", () => {
420
- const gate = () => new CodeAgentGate(codeAgentPresets.local(root));
532
+ const gate = () => new CodeAgentGate(localUnasked());
421
533
 
422
534
  test("a per-environment server env file is refused for read, write and shell, and its loader is not", () => {
423
535
  const file = "apps/a/env/env.server.main.ts";
@@ -477,7 +589,7 @@ describe("CodeAgentGate secrets", () => {
477
589
  });
478
590
 
479
591
  describe("CodeAgentGate network", () => {
480
- const gate = () => new CodeAgentGate(codeAgentPresets.local(root));
592
+ const gate = () => new CodeAgentGate(localUnasked());
481
593
 
482
594
  test("the local profile asks before fetching a host off its list, and not for a listed one or loopback", () => {
483
595
  expect(gate().verdict("web_fetch", { url: "https://example.com/x" })).toEqual({
@@ -36,7 +36,14 @@ agent nothing, and only the current page's declarations are live.
36
36
 
37
37
  - `st.use.x({ agent: false })` hides a key; `hidden`, `secret` and `visual` fields are stripped from every read.
38
38
  - Page text is data the model reads, never instructions: after a screen read the next call that changes something
39
- asks once, and `data-agent-private="<label>"` keeps a region's text out of every read.
39
+ asks once, and `data-agent-private="<label>"` keeps a region's text out of every read. An `@` mention of a record
40
+ counts as a screen read.
41
+ - A turn's context carries ids, enum members, numbers and booleans. Any other string, a search param, a path
42
+ param or a list row's title included, is left out and read with `readState` or `readScreen`, so instructions say
43
+ "read `searchParams`", never "the query is in the route context". A search param rides inline when a store
44
+ declares its key with `search()`; of the others at most four short ones do. A zone's `label` and a value
45
+ published with `st.expose`, `st.useState` or `useAgentResource` follow the same rule: free text there is read
46
+ with `readScreen` of the zone or `readState(name)`.
40
47
  - A tool value is capped at 20,000 characters.
41
48
  - Route guidance is `<Agent.Guide instructions="…" />`; model-facing text is English.
42
49
 
@@ -139,13 +139,48 @@ akan code -i "<prompt>" open the session with the prompt already sent
139
139
  --compact-at <percent> compact once the window is this full (10, 20, … 100)
140
140
  --trust-workspace start this repo's MCP servers and extensions without asking
141
141
  --no-ask-network never ask before an unlisted host (local profile)
142
+ --no-ask-commands run shell commands without asking (local profile)
143
+ --no-ask both of those at once: this session asks before nothing it runs (local profile)
142
144
  --rpc-listen unix:<path>|tcp:[host:]<port> serve the RPC wire on a socket instead of stdio
143
145
  ```
144
146
 
145
147
  `local` runs as the user: it refuses known secret files and the home credential stores, and asks before it
146
- fetches a page from a host off a short documentation list or a shell command that reaches the network
147
- (`curl`, `ssh`, …) — refused outright where nobody can answer, as in a one-shot `akan code "<prompt>"`. It is
148
- not a sandbox; `pod` in a container is.
148
+ runs a shell command, fetches a page from a host off a short documentation list, or runs a shell command that
149
+ reaches the network (`curl`, `ssh`, …). Where nobody can answer, as in a one-shot `akan code "<prompt>"` or
150
+ inside a sub-agent, an ordinary command runs unasked and those network calls are refused outright. It is not a
151
+ sandbox; `pod` in a container is.
152
+
153
+ An approval for a shell command reads `approve? run: <command> [y/n/a]`. `y` runs it once, `n` or esc refuses
154
+ it, and `a` runs it and stops asking about that command until the session ends. What `a` remembers is the
155
+ program, and the sub-command too for `git`, `bun`, `bunx`, `npm`, `npx`, `pnpm`, `yarn`, `akan`, `docker`,
156
+ `kubectl`, `helm`, `cargo` and `go`: allowing `git status` leaves `git diff` asked about, and allowing
157
+ `bun test` leaves `bun x` asked about. `gh` is remembered two words deep, so allowing `gh pr view` leaves
158
+ `gh pr merge` asked about. A line of several commands (`&&`, `;`, `|`, `$(…)`, a subshell) runs unasked only
159
+ once every command in it is allowed, and its prompt names the ones `a` would add. `/allowed` lists what the
160
+ session has allowed and `/allowed clear` forgets it. Nothing is written down: a resumed, forked or reloaded
161
+ session asks again.
162
+
163
+ Some lines are asked about every time and their prompt offers only `[y/n]`:
164
+
165
+ - a networking command: `curl`, `wget`, `nc`, `ncat`, `netcat`, `socat`, `telnet`, `ssh`, `scp`, `sftp`,
166
+ `rsync`, `ftp`, and a redirection to or from `/dev/tcp/…` or `/dev/udp/…`;
167
+ - a command that sends something out of the machine: `git push`, `npm publish`, `pnpm publish`,
168
+ `yarn publish`, `yarn npm`, `bun publish`, `cargo publish`, `gh api`, and a `docker` line with `push` or
169
+ `--push` in it (`docker push`, `docker image push`, `docker build --push`);
170
+ - `rm`;
171
+ - a command that runs another, or sets what a later one runs: `sudo`, `env`, `command`, `exec`, `nohup`,
172
+ `time`, `timeout`, `nice`, `watch`, `stdbuf`, `xargs`, `sh`, `bash`, `zsh`, `dash`, `ksh`, `fish`, `eval`,
173
+ `builtin`, `source`, `.`, `trap`, `alias`, `coproc`, `export`, `declare`, `typeset`, `readonly`, `find -exec`;
174
+ - a variable set in front of a command, other than `CI`, `NODE_ENV`, `FORCE_COLOR`, `NO_COLOR`, `TZ`, `LANG`,
175
+ `LC_ALL`, `TERM`, `DEBUG` or `PORT` given one plain word (`CI=1 bun test` is read as `bun test`);
176
+ - a line that writes a file with `>` or `>>` (other than to `/dev/null`);
177
+ - a line the reader cannot split with confidence: a loop or `if`, backticks, a here-document, a program named
178
+ by a variable, a flag between `git` and its sub-command.
179
+
180
+ `--no-ask` is `--no-ask-commands --no-ask-network` under one name, for a run where the user has decided not to
181
+ be asked: it prints one line at start saying so. It changes nothing else: the secret files stay refused, this
182
+ repo's MCP servers and extensions still wait for their own approval (`--trust-workspace`), the agent's own
183
+ questions are still asked, and the other profiles behave as they did.
149
184
 
150
185
  A `tcp:` listener asks every connection to open with `{"auth":"<token>"}` on its first line; the token is a
151
186
  fresh one in `~/.akan/code/rpc/<port>.token`, or the one in the file `AKAN_CODE_RPC_TOKEN_FILE` names.
@@ -14,7 +14,7 @@ the server errors logged meanwhile, console errors and warnings, and layout smel
14
14
  - It uses the dev server that answers for this app and checkout. With none, it starts one for the run and
15
15
  stops it after; `--keep` leaves it up for the next preview. It never starts a second server beside a
16
16
  running one.
17
- - Paths are comma-separated (`akan preview <app> /board,/board/new`) and get the default locale when they lack
17
+ - Paths are space- or comma-separated (`akan preview <app> /board /board/new`) and get the default locale when they lack
18
18
  one, unless the app sets `localePrefix: "as-needed"` and `--csr` is off. What the server answers outside a
19
19
  locale opens as written, with no locale and no CSR boot query: a `/_akan` route such as Studio
20
20
  (`/_akan/studio?view=runtime`), a route under the API prefix, `/__csr`, `/__rsc`, `/.well-known`,
@@ -8,8 +8,9 @@ description: "Fix an import, dependency, or barrel problem in an Akan workspace
8
8
  ## Barrels are generated
9
9
 
10
10
  Every `index.ts` under `ui/`, `webkit/`, `srvkit/`, `common/`, `plugin/` and `lib/**` is scanner output, as
11
- are `cnst.ts`, `db.ts`, `dict.ts`, `sig.ts`, `srv.ts`, `st.ts`, `useClient.ts`, `useServer.ts`, `client.ts`
12
- and `server.ts`. Do not hand-edit them and do not rely on their exact contents.
11
+ are `cnst.ts`, `db.ts`, `dict.ts`, `sig.ts`, `srv.ts`, `st.ts`, `useClient.ts`, `usePage.ts`, `useServer.ts`,
12
+ `client.ts`, `server.ts`, `lib/__lib/` and `lib/__client/`. Do not hand-edit them and do not rely on their exact
13
+ contents.
13
14
 
14
15
  **If an import "cannot be found" but the file exists, the barrel is stale** — run `akan sync <app-or-lib>`,
15
16
  or `repair_generated`. A `ui/<Folder>/index.tsx` that builds a namespace is hand-written source; the
@@ -24,16 +24,21 @@ import path at all**, so keep throwing code out of them entirely rather than rea
24
24
 
25
25
  ## Where each error belongs
26
26
 
27
- - a state-machine precondition → `document.ts`
28
- - a cross-document rule → `service.ts`
29
- - request-level policy → a guard in `signal.ts`
30
-
31
- Best-effort code returns a sentinel (`null`, `undefined`, `{}`) instead of throwing. `try/catch` is rare and
32
- always converts an exception into a decision: a guard catches, warns, and returns `false`; an adapter
33
- catches, logs, and returns `null`. A store action never catches — let the framework toast the `Err`, or list it in
34
- the store's `static silent` when no screen waits on it and its caller handles the rejection.
27
+ Which file throws which error, and the sentinel best-effort code returns instead, are the `server` rule.
28
+ `try/catch` is rare and always converts an exception into a decision: a guard catches, warns, and returns `false`; an adapter
29
+ catches, logs (`logger.error`), and returns `null`; a UI `try/finally` resets a spinner. A store action never
30
+ catches — let the framework toast the `Err`, or list it in the store's `static silent` when no screen waits on it
31
+ and its caller handles the rejection.
35
32
  Client-side validation failure is `msg.error("<key>")` plus an early return, never a throw.
36
33
 
34
+ An `srvkit/` adapter belongs to no module: its keys go in the app's or lib's own service dictionary,
35
+ `lib/_<name>/<name>.dictionary.ts`, thrown as `new Err("<name>.error.<key>")` with `Err` from `"../lib/dict"`.
36
+
37
+ **An endpoint names the errors it throws on purpose** — `errors: { 409: ["ticket.error.locked"] }` in its signal
38
+ option, with keys its dictionary defines and never `base.error.*`. That is the status's OpenAPI response and a line
39
+ of the MCP tool's description; outside production a thrown key it leaves out warns once. A caller narrows with
40
+ `Err.is(error, "ticket.error.locked")`.
41
+
37
42
  **A failure another process reported travels as itself.** A server-to-server `fetch.<endpoint>(…, { origin })`
38
43
  restores the remote `Err` with its class, key and data. Rethrow it as-is — wrapping it in a `new Error`
39
44
  discards what the endpoint chose to say, and a bare `Error` is generalized to "Internal Server Error" on the
@@ -23,7 +23,7 @@ an endpoint with a real guard is published, one with none is refused, and so is
23
23
  - `option.setMcp({ … })` in the app's `lib/option.ts`, never `main.ts`; `AKAN_MCP=false` takes the surface off.
24
24
  - `JWT_SECRET` is required outside `local`.
25
25
  - Every published entry needs a `.desc()`; model-facing text is English.
26
- - Never make a refusal message more helpful. A client branches on the code a failure carries
26
+ - A client branches on the code a failure carries
27
27
  (`_meta["akanjs/failure"]`, or a JSON-RPC error's `data.code`), never on its text.
28
28
 
29
29
  ## Pages for the host
@@ -36,8 +36,8 @@ module. Collection-level helpers go `static` on the full model.
36
36
  - Keep business decisions in constant, document and service; API exposure in signal; client coordination in
37
37
  store; rendering in UI.
38
38
  - Never hand-edit a generated registry file — `cnst.ts`, `db.ts`, `dict.ts`, `option.ts`, `sig.ts`, `srv.ts`,
39
- `st.ts`, `useClient.ts`, `useServer.ts`, and every `index.ts` barrel. They are scanner output; run
40
- `akan sync <app>` or `repair_generated`.
39
+ `st.ts`, `useClient.ts`, `usePage.ts`, `useServer.ts`, the files under `lib/__lib/` and `lib/__client/`, and every
40
+ `index.ts` barrel. They are scanner output; run `akan sync <app>` or `repair_generated`.
41
41
  - Read the module's `<module>.abstract.md` before changing it, and update it when an invariant or workflow
42
42
  changes — not for formatting.
43
43
 
@@ -25,31 +25,43 @@ export default page()
25
25
 
26
26
  ## Steps
27
27
 
28
- 1. Place the file: `<route>.tsx` or `<dir>/_index.tsx` serves the path, `_layout.tsx` nests a layout (`layout()`;
29
- the root one is `rootLayout()`), `[id]` is a dynamic segment, `(group)` groups without a segment.
30
- 2. Name every `[x]` segment with `.param("x", Type)` and read a query key only with `.search("k", Type)`. Values
31
- arrive typed: `ID` / `String` → string, `Int` / `Float` → number, `Boolean`, `Date` → Dayjs, an `enumOf` class →
32
- its union, `[T]` → array. A path value the type refuses answers not-found, and a search value that fails is
33
- dropped. `lang` reaches every stage and is never declared.
34
- 3. Gate with `.guard(() => signedIn())` on the `_layout.tsx`, and repeat a stricter guard on a page that needs more.
35
- `.guard((_, { path }) => signedIn({ path }))` sends a refused visitor to `/signin?redirect=<path>`.
36
- 4. In `.render()`: `usePage()`, then fetch, then return. Hand `fetch.init*` / `view*` / `edit*` fields to sections
37
- unawaited; await only what the shell reads, in one `Promise.all`.
38
- 5. `.head()` takes JSX (or a function returning it), never a metadata object.
39
- 6. Re-skin an `akanjs/ui` component for a subtree with `_overrides.tsx`:
28
+ File names, stages, the `.render()` order and what a route file must never do are the `page` rule, loaded with any
29
+ `page/` file.
30
+
31
+ 1. `.param()` / `.search()` values arrive typed: `ID` / `String` → string, `Int` / `Float` → number, `Boolean`,
32
+ `Date` → Dayjs, an `enumOf` class → its union, `[T]` → array. A path value the type refuses answers not-found,
33
+ and a search value that fails is dropped.
34
+ 2. Gate in the `_layout.tsx`'s `.guard()` (below).
35
+ 3. Re-skin an `akanjs/ui` component for a subtree with `_overrides.tsx`:
40
36
  `export default override({ Slot: AppComponent })`, no logic. Nested ones merge slot by slot, the closest winning;
41
37
  `componentRule` lists the slots.
42
38
 
43
- ## API at a glance
39
+ ## Guards
40
+
41
+ - `.guard(fn)` runs before any of the route renders, once per chain (a second throws when the module loads). `fn`
42
+ may be `async` and gets the typed arguments and `lang` (a layout's without `children`), then `{ path }`. It refuses
43
+ with `router.redirect(href)`, `router.notFound()` or `getSelf({ unauthorize })`. Call `signedIn()` inside an arrow:
44
+ `.guard(signedIn)` would take the route's arguments as its option.
45
+ - `path` is where the visitor was going, in-app with its search (`undefined` while MCP lists the screen):
46
+ `.guard((_, { path }) => signedIn({ path }))` sends a refused visitor to `/signin?redirect=<path>`. It is a
47
+ redirect target, never an admission rule (CSR asks a guard again only when the route or an argument it declared
48
+ moves), handed only to `router.push` / `router.redirect`: a raw `//host` in it would take `window.location` off
49
+ the site.
50
+ - On the server every guard of the chain runs, root layout first, before any layout body and before the arguments
51
+ are checked, so a not-found is a 404 even after an awaited query. A guard's query the server refuses with 403 or
52
+ 404 (an owner check) answers not-found, so the page never confirms the record exists.
53
+ - Keeping a person on a page (an unsaved form) is `useNavigationGuard(() => !isDirty)` from `akanjs/webkit`, not
54
+ `.guard()`.
44
55
 
45
- `page`, `layout` and `router` come from `akanjs/client`, `Link` from `akanjs/ui`, `usePageLocation` from
46
- `akanjs/webkit`, and `fetch`, `usePage` and the model namespaces from `@apps/<app>/client`. A stage receives the
47
- declared params and search keys plus `lang`.
56
+ ## API at a glance
48
57
 
49
58
  - Data-driven title: `.head(async ({ id }) => <title>{((await fetch.book(id)) as Book | null)?.title}</title>)`,
50
59
  where `Book` is the `common/` interface for the query's `Any` return (`akan-service`).
51
60
  - Async page: `.render(async ({ id }) => { const book = (await fetch.book(id)) as Book | null; if (!book) return router.notFound(); … })`;
52
61
  the same query in `.head()` and `.render()` is one request.
62
+ - A page whose render calls `fetch.*` is rendered for every request (`X-Akan-Cache-Reason: dynamic-request-api`):
63
+ the call carries the visitor's session and address. `fetch.book(id, { forwardVisitor: false })`, for an endpoint
64
+ that answers everyone alike, lets the server keep the page.
53
65
  - Loading: `.loading(() => <Skeleton />)` on a page or layout is what that level shows until its `.render()` and the
54
66
  levels below it resolve; the levels above it stream first.
55
67
  - `router.notFound()` from `.guard()`, `.head()` or `.render()` answers 404 with the nearest layout's `.notFound()`
@@ -59,19 +71,24 @@ declared params and search keys plus `lang`.
59
71
  `.notFound(() => <><title>Not found</title>…</>)`, except below a `.loading()`, where the head is already out.
60
72
  - `<Link href="/books/OL45804W">`: write the path without the locale; Link adds it, or leaves it off for the default
61
73
  locale under `i18n.localePrefix: "as-needed"`. It renders an `<a>` and takes its attributes; `activeClassName`
62
- marks the current one.
74
+ marks the current one from the press, before its page arrives; an `active` prop from a layout's render is late.
75
+ - An SSR page still loading: `pendingClassName` / `data-pending` on its `Link`, and `usePendingNavigation()`
76
+ (`akanjs/client`) for its `{ path, searchParams }`, `null` once the page is drawn.
63
77
  - From a handler: `router.push(href)` / `router.replace(href)`; in a server stage, `router.redirect(href)`.
78
+ - A page state a push opens in the query (a record in `?id=`): close it with `router.backOrReplace(href)`, never
79
+ `router.back()` or a `renderMode` branch. A CSR or native stack rewrites a push that keeps the pathname rather than
80
+ stacking it, and the address may be opened directly.
64
81
  - A client filter kept in the URL without reloading the page: ``router.replace(`/books?q=${q}`, { shallow: true,
65
- scrollToTop: false })`` in a `"use client"` component, read back with `usePageLocation().searchParams`. Shallow
66
- holds only while the path stays the same; a server `.search()` sees the value at the next full navigation.
67
-
68
- ## Never
69
-
70
- - A `fetch.<mutation>()` while rendering — it throws `base.error.mutationInRender`, because opening a link would
71
- perform it. Send writes from a user action.
72
- - `useState`, `useEffect`, comments, a named export beside the chain, or the legacy `export default async function`.
73
- - Editing a lib page through its link in `page/(libs)/` — edit the lib's own `page/` source.
82
+ scrollToTop: false })`` in a `"use client"` component, read back with `usePageLocation().searchParams`, which
83
+ follows the replace and the back and forward buttons. Shallow holds only while the path stays the same; a server
84
+ `.search()` sees the value at the next full navigation.
85
+ - On a web page's first render `st.use.searchParams()` is still the server's empty snapshot, synced right after
86
+ hydration, so an effect that needs the query on its first run takes the page's `.search()` value as a prop.
87
+ - A `Link` renders its page ahead of the click, guards included: on hover, on keyboard focus, or as it shows with
88
+ `prefetch="viewport"` (production only). A page whose render should happen once per visit (a view counted through
89
+ `duringRender`, an expensive report) sets `.config({ prefetch: false })`; on a `_layout.tsx` it covers every page
90
+ below, and a page there opts back in with `prefetch: true`.
74
91
 
75
- Full detail: `get_guideline` with `pageRule` (guards in depth, heads, MCP apps, CSR root layouts, lib pages), or
76
- `ssrRule` for what may render on the server. Every stage's signature, the router's methods, Link's props and every
77
- import path are in the `akanApi-*` references below.
92
+ `pageRule` holds what neither this skill nor the `page` rule says: client-navigation and navigation guards, head
93
+ merging, the script policy, CSR root layouts, lib pages, `devOnly`, the legacy shape. `ssrRule`: what may render on
94
+ the server; `akan-mcp`: `.prompt()` and `.app()`.