@akanjs/devkit 3.3.0-rc.2 → 3.3.0-rc.20

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 (111) hide show
  1. package/CHANGELOG.md +284 -20
  2. package/DEV_RUNTIME_KNOBS.md +1 -1
  3. package/README.ko.md +3 -2
  4. package/README.md +3 -3
  5. package/akanApp/akanApp.host.test.ts +1 -1
  6. package/akanConfig/akanConfig.test.ts +57 -8
  7. package/akanConfig/akanConfig.ts +16 -69
  8. package/akanConfig/dockerImage.ts +17 -0
  9. package/akanConfig/nativeKeys.ts +52 -0
  10. package/app/applicationBuildRunner.test.ts +321 -1
  11. package/app/applicationBuildRunner.ts +90 -3
  12. package/artifact/implicitRootLayoutRender.test.tsx +4 -1
  13. package/codeAgent/agent/CodeAgent.ts +36 -16
  14. package/codeAgent/agent/CodeAgentAllowed.ts +35 -0
  15. package/codeAgent/agent/CodeAgentCommandLine.ts +372 -0
  16. package/codeAgent/agent/CodeAgentGate.ts +23 -4
  17. package/codeAgent/agent/CodeAgentRpcHost.ts +1 -1
  18. package/codeAgent/agent/codeAgent.test.ts +62 -0
  19. package/codeAgent/agent/codeAgentCommandLine.test.ts +212 -0
  20. package/codeAgent/agent/codeAgentContract.test.ts +117 -5
  21. package/codeAgent/skills/akan-agent/SKILL.md +8 -1
  22. package/codeAgent/skills/akan-code/SKILL.md +38 -3
  23. package/codeAgent/skills/akan-err/SKILL.md +11 -2
  24. package/codeAgent/skills/akan-page/SKILL.md +21 -26
  25. package/codeAgent/skills/akan-runtime/SKILL.md +41 -16
  26. package/codeAgent/skills/akan-service/SKILL.md +2 -2
  27. package/docs/apiReference.test.ts +14 -0
  28. package/docs/apiReference.ts +21 -3
  29. package/docs/declarationReader.ts +28 -1
  30. package/executors/appExecutor.ts +16 -7
  31. package/executors/workspaceExecutor.ts +7 -4
  32. package/frontendBuild/buildRouteClient.test.ts +2 -7
  33. package/frontendBuild/clientEntryDiscovery.test.ts +35 -0
  34. package/frontendBuild/clientEntryDiscovery.ts +16 -3
  35. package/frontendBuild/cssCompiler.test.ts +112 -0
  36. package/frontendBuild/cssCompiler.ts +41 -21
  37. package/frontendBuild/devBarrelImports.test.ts +30 -0
  38. package/frontendBuild/devBarrelImports.ts +2 -2
  39. package/frontendBuild/pagesBundleBuilder.ts +3 -1
  40. package/frontendBuild/plainStylesheet.test.ts +155 -0
  41. package/frontendBuild/plainStylesheet.ts +197 -0
  42. package/frontendBuild/rscServerRendererGuard.test.ts +60 -0
  43. package/frontendBuild/rscServerRendererGuard.ts +68 -0
  44. package/guideline/agentAssets.test.ts +10 -0
  45. package/guideline/agentAssets.ts +52 -11
  46. package/incrementalBuilder/buildBatch.proc.ts +9 -9
  47. package/incrementalBuilder/buildBatchProtocol.ts +1 -1
  48. package/incrementalBuilder/builderBoot.ts +5 -5
  49. package/incrementalBuilder/builderGraphPayloads.ts +4 -4
  50. package/incrementalBuilder/builderLanes.ts +2 -2
  51. package/incrementalBuilder/builderWatch.ts +8 -8
  52. package/incrementalBuilder/csrRegistry.ts +4 -4
  53. package/incrementalBuilder/incrementalBuilder.proc.ts +8 -8
  54. package/incrementalBuilder/ssrRegistry.ts +6 -6
  55. package/index.ts +1 -1
  56. package/integration/renderAdmissionSoak.test.ts +99 -0
  57. package/integration/renderAdmissionSoak.ts +609 -0
  58. package/lint/__fixtures__/no-arbitrary-color/every-color-function/bad.tsx +11 -0
  59. package/lint/__fixtures__/no-arbitrary-color/every-color-function/good.tsx +2 -0
  60. package/lint/__fixtures__/no-daisyui-legacy-class/every-class/bad.tsx +34 -0
  61. package/lint/__fixtures__/no-daisyui-legacy-class/every-class/good.tsx +2 -0
  62. package/lint/__fixtures__/no-inline-color/every-color-function/bad.tsx +10 -0
  63. package/lint/__fixtures__/no-inline-color/every-color-function/good.tsx +2 -0
  64. package/lint/__fixtures__/no-raw-palette-class/every-palette/bad.tsx +22 -0
  65. package/lint/__fixtures__/no-raw-palette-class/every-palette/good.tsx +2 -0
  66. package/lint/biomeCheck.test.ts +145 -0
  67. package/lint/biomeCheck.ts +131 -0
  68. package/lint/no-arbitrary-color.grit +5 -0
  69. package/lint/no-conditional-st-hook.grit +5 -1
  70. package/lint/no-daisyui-legacy-class.grit +8 -0
  71. package/lint/no-document-cookie.grit +3 -0
  72. package/lint/no-inline-color.grit +10 -2
  73. package/lint/no-oversized-list-limit.grit +2 -0
  74. package/lint/no-raw-palette-class.grit +7 -0
  75. package/lint/no-unpublished-form-setter.grit +2 -0
  76. package/lint/no-web-only-api-outside-webkit.grit +5 -0
  77. package/lint/no-web-storage.grit +3 -0
  78. package/lint/withheldEnvFile.ts +17 -0
  79. package/mobile/nativeApp.test.ts +7 -5
  80. package/mobile/nativeApp.ts +2 -2
  81. package/mobile/nativeConfig.test.ts +117 -1
  82. package/mobile/nativeConfig.ts +66 -22
  83. package/mobile/serverBundleSecrets.ts +43 -0
  84. package/package.json +14 -169
  85. package/packageExports.test.ts +38 -24
  86. package/test/secretEnvFixture.ts +134 -0
  87. package/transforms/barrelAnalyzer.ts +2 -2
  88. package/transforms/secretEnvDeclaration.test.ts +208 -0
  89. package/transforms/secretEnvDeclaration.ts +213 -0
  90. package/transforms/secretEnvFile.test.ts +117 -0
  91. package/transforms/secretEnvFile.ts +113 -0
  92. package/transforms/secretEnvName.test.ts +54 -0
  93. package/transforms/secretEnvName.ts +29 -0
  94. package/transforms/secretEnvSource.test.ts +148 -0
  95. package/transforms/secretEnvSource.ts +166 -0
  96. package/transforms/serverEnvEvaluationError.ts +11 -0
  97. package/transforms/serverEnvPlugin.test.ts +2 -1
  98. package/transforms/serverEnvPlugin.ts +13 -0
  99. package/transforms/serverEnvProfile.test.ts +115 -2
  100. package/transforms/serverEnvProfile.ts +117 -40
  101. package/transforms/serverEnvSecrets.test.ts +292 -0
  102. package/transforms/transforms.test.ts +3 -3
  103. package/tunnel/createTunnel.test.ts +29 -8
  104. package/tunnel/createTunnel.ts +18 -11
  105. package/typecheck/projectTypecheck.test.ts +29 -0
  106. package/typecheck/typeChecker.test.ts +49 -0
  107. package/typecheck/typeChecker.ts +9 -7
  108. package/typecheck/withheldDiagnostics.ts +41 -0
  109. package/util/fileEditor.ts +1 -0
  110. package/util/selectModel.ts +1 -0
  111. package/workspace/getRelatedCnsts.ts +7 -0
@@ -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` ride whole: publish an id or a count there, never
46
+ text a user wrote.
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.
@@ -30,10 +30,19 @@ import path at all**, so keep throwing code out of them entirely rather than rea
30
30
 
31
31
  Best-effort code returns a sentinel (`null`, `undefined`, `{}`) instead of throwing. `try/catch` is rare and
32
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.
33
+ catches, logs (`logger.error`), and returns `null`; a UI `try/finally` resets a spinner. A store action never
34
+ catches — let the framework toast the `Err`, or list it in the store's `static silent` when no screen waits on it
35
+ and its caller handles the rejection.
35
36
  Client-side validation failure is `msg.error("<key>")` plus an early return, never a throw.
36
37
 
38
+ An `srvkit/` adapter belongs to no module: its keys go in the app's or lib's own service dictionary,
39
+ `lib/_<name>/<name>.dictionary.ts`, thrown as `new Err("<name>.error.<key>")` with `Err` from `"../lib/dict"`.
40
+
41
+ **An endpoint names the errors it throws on purpose** — `errors: { 409: ["ticket.error.locked"] }` in its signal
42
+ option, with keys its dictionary defines and never `base.error.*`. That is the status's OpenAPI response and a line
43
+ of the MCP tool's description; outside production a thrown key it leaves out warns once. A caller narrows with
44
+ `Err.is(error, "ticket.error.locked")`.
45
+
37
46
  **A failure another process reported travels as itself.** A server-to-server `fetch.<endpoint>(…, { origin })`
38
47
  restores the remote `Err` with its class, key and data. Rethrow it as-is — wrapping it in a `new Error`
39
48
  discards what the endpoint chose to say, and a bare `Error` is generalized to "Internal Server Error" on the
@@ -26,47 +26,42 @@ export default page()
26
26
  ## Steps
27
27
 
28
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. `page/` holds
30
- route modules only — no helpers, no `.ts` files.
29
+ the root one is `rootLayout()`), `[id]` is a dynamic segment, `(group)` groups without a segment.
31
30
  2. Name every `[x]` segment with `.param("x", Type)` and read a query key only with `.search("k", Type)`. Values
32
- arrive typed; `lang` reaches every stage and is never declared.
33
- 3. Gate with `.guard(() => signedIn())` on the `_layout.tsx` (a real redirect before anything renders), and repeat
34
- a stricter guard on a page that needs more. The endpoint guards are still the real gate. `signedIn` comes from
35
- `@libs/shared/webkit`, and a new workspace has that lib only with `create-workspace --libs true`.
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. A canonical link comes only from the
39
- page's own head.
40
- 6. Re-skin an `akanjs/ui` component for a subtree with `_overrides.tsx`:
41
- `export default override({ Slot: AppComponent })`, no logic.
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.
37
+ 5. Re-skin an `akanjs/ui` component for a subtree with `_overrides.tsx`:
38
+ `export default override({ Slot: AppComponent })`, no logic. Nested ones merge slot by slot, the closest winning;
39
+ `componentRule` lists the slots.
42
40
 
43
41
  ## API at a glance
44
42
 
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`.
48
-
49
43
  - Data-driven title: `.head(async ({ id }) => <title>{((await fetch.book(id)) as Book | null)?.title}</title>)`,
50
44
  where `Book` is the `common/` interface for the query's `Any` return (`akan-service`).
51
45
  - Async page: `.render(async ({ id }) => { const book = (await fetch.book(id)) as Book | null; if (!book) return router.notFound(); … })`;
52
46
  the same query in `.head()` and `.render()` is one request.
47
+ - Loading: `.loading(() => <Skeleton />)` on a page or layout is what that level shows until its `.render()` and the
48
+ levels below it resolve; the levels above it stream first.
53
49
  - `router.notFound()` from `.guard()`, `.head()` or `.render()` answers 404 with the nearest layout's `.notFound()`
54
50
  above it (an unmatched URL: the deepest layout covering it), else the built-in 404.
55
51
  - A layout's own 404 and error views: `.notFound(({ pathname }) => …)` and `.error(({ error }) => …)` on `layout()`
56
- or `rootLayout()`.
52
+ or `rootLayout()`. A `<title>` and `<meta>` at the top of what they return replace the page's head:
53
+ `.notFound(() => <><title>Not found</title>…</>)`, except below a `.loading()`, where the head is already out.
57
54
  - `<Link href="/books/OL45804W">`: write the path without the locale; Link adds it, or leaves it off for the default
58
- locale under `i18n.localePrefix: "as-needed"`. `activeClassName` marks the current one.
55
+ locale under `i18n.localePrefix: "as-needed"`. It renders an `<a>` and takes its attributes; `activeClassName`
56
+ marks the current one.
59
57
  - From a handler: `router.push(href)` / `router.replace(href)`; in a server stage, `router.redirect(href)`.
60
58
  - A client filter kept in the URL without reloading the page: ``router.replace(`/books?q=${q}`, { shallow: true,
61
59
  scrollToTop: false })`` in a `"use client"` component, read back with `usePageLocation().searchParams`. Shallow
62
60
  holds only while the path stays the same; a server `.search()` sees the value at the next full navigation.
63
61
 
64
- ## Never
65
-
66
- - A `fetch.<mutation>()` while rendering — it throws `base.error.mutationInRender`, because opening a link would
67
- perform it. Send writes from a user action.
68
- - `useState`, `useEffect`, comments, a named export beside the chain, or the legacy `export default async function`.
69
- - Editing a lib page through its link in `page/(libs)/` — edit the lib's own `page/` source.
62
+ What a route file must never do — write while rendering, hooks, a second export — is the `page` rule, loaded with
63
+ any `page/` file.
70
64
 
71
- Full detail: `get_guideline` with `pageRule`, or `ssrRule` for what may render on the server; every stage's
72
- signature, the router's methods, Link's props and every import path: `akanApi`.
65
+ Full detail: `get_guideline` with `pageRule` (guards in depth, heads, MCP apps, CSR root layouts, lib pages), or
66
+ `ssrRule` for what may render on the server. Every stage's signature, the router's methods, Link's props and every
67
+ import path are in the `akanApi-*` references below.
@@ -5,8 +5,9 @@ description: "Configure how an app runs: web surfaces, route prefixes, gateway v
5
5
 
6
6
  # Akan runtime
7
7
 
8
- Runtime and build settings are declared in `akan.config.ts` and narrowed — never widened — by an env at boot.
9
- Domain code reaches none of them.
8
+ Runtime and build settings are declared in `akan.config.ts`. What must hold when you edit it, `main.ts` or an env
9
+ file — the prefixes, the `main.ts` import, the image, log sinks, the desktop server's guard — is the `config` rule in
10
+ the agent guide's Path Rules table.
10
11
 
11
12
  ## Where each setting lives
12
13
 
@@ -16,28 +17,52 @@ Domain code reaches none of them.
16
17
  | Move the API or websocket mount | `new AkanApp({ prefix, websocketPrefix })` in `main.ts`, mirrored in `api: { … }`; read with `getApiPrefix()` / `getWsPrefix()` |
17
18
  | The production image | `docker: string \| { image, preRuns, postRuns, command }` |
18
19
  | iOS, Android, desktop | the `native` section; `desktop: { server: true }` carries the server |
19
- | SQLite, several databases, a cluster | `database: { modes: [...] }`, picked by `AKAN_DATABASE_MODE` |
20
+ | SQLite, several databases, a cluster | `database: { modes: [...] }` (`single`, `multiple`, `cluster`), picked by `AKAN_DATABASE_MODE` |
21
+ | A secret of `env/env.server.<env>.ts` in a deployed server | nothing to declare: `akan build` leaves it out and the server reads it from a variable named after its key path; `akan secret-env <app> --env <env>` lists them |
20
22
  | URLs without `/<locale>/`: one language, or paths fixed from outside (OAuth callback, QR code, mail link) | `i18n: { localePrefix: "as-needed" }` — the default locale's pages and `<Link>` hrefs drop the prefix, other locales keep it |
21
23
 
22
- - `main.ts` imports `AkanApp` from `akanjs/server/akanApp`, never the barrel.
23
- - Never write `/api` or `/ws` literally, and never pass a prefix as a prop.
24
- - The generated image installs only `ca-certificates` and `tzdata`; add the rest in `preRuns`.
25
- - An app running in two database modes avoids `q.raw`.
26
-
27
24
  ## Running and logs
28
25
 
29
26
  - `akan start <app>` (`a,b` or `all` for several) runs the dev server; `akan build <app>` checks the production
30
- build. A supervised session writes `local/apps/<app>/runtime/dev.log` — hand over that path, not a paste of the
31
- live view. Tail with `akan logs <app>`.
27
+ build. A supervised session writes `local/apps/<app>/runtime/dev.log` (previous: `dev.prev.log`) — hand over that
28
+ path, not a paste of the live view. Tail with `akan logs <app>`.
32
29
  - Run a build without Docker with `cd dist/apps/<app> && bun main.js`: it boots with the env the Dockerfile sets,
33
30
  read from `akan.env.json` beside it, and a variable you set yourself (`PORT=3000`) wins.
34
- - Give every log sink a floor (`Logger.addSink(sink, { minLevel })`) and never log once per delivered record.
31
+
32
+ ## Secrets in a deployed server
33
+
34
+ - Write secrets in `env/env.server.<env>.ts` as before. `akan build` replaces each string under a secret-named key,
35
+ and each URL carrying a password, with a read of an environment variable: `security.sso.google.clientSecret` is
36
+ `SECURITY__SSO__GOOGLE__CLIENT_SECRET`, an array holding a secret is one JSON variable, `security.jwtSecret` is
37
+ `JWT_SECRET`. The built files hold the names (`AKAN_ENV_NAMES` in `akan.env.json`), never the values.
38
+ - `akan secret-env <app> --env <env>` prints the variables, never a value. `--out <file> --format k8s --name <name>`
39
+ writes a Kubernetes Secret for `envFrom`, `--format dotenv` a file for `bun --env-file`. Never write it
40
+ under `dist/` or a tracked path, and delete it once applied.
41
+ - At boot a variable left unset is one warning naming it. The framework does not stop for it, though whatever reads the value may; 3.5.0 will refuse to boot.
42
+ - A secret the env file computes or imports stops the build, whatever its length: write the string at the key, or
43
+ `process.env.<NAME>` there, which the build leaves as that read. A secret string a plain key or the app's code
44
+ holds as well stops it too when long and mixed, and is a warning when short. A key the name rule misses
45
+ (`stripeKey`) stays in the image unless read from `process.env`.
46
+ - The build loads the env file to list the secrets, with the shell's variables only when it cannot load without
47
+ them; a file that throws as it loads stops the build by error class and line.
48
+ - `akan start`, `akan test`, `akan build --profile …` and desktop and mobile builds read the env file as written.
49
+ `akan build --inline-secrets` keeps the values in the image for one release, for a deployment not ready yet.
35
50
 
36
51
  ## Native and desktop
37
52
 
38
- - `akan start-desktop <app>`, `akan start-ios <app>`, `akan start-android <app>` load pages from a running
39
- `akan start`; a desktop app carrying its server starts it itself.
40
- - A desktop app's carried server listens on a loopback port any local program can call — guard it like a network
41
- server. Read runtime files from `AKAN_APP_DIR`, and keep a user's secret with `NativeSecret`, never in a file.
53
+ A `start-*` command loads its pages from a running `akan start`; a desktop app carrying its server starts it itself.
54
+
55
+ ```bash
56
+ akan start-desktop <app> # Run the desktop app on this computer
57
+ akan start-ios <app> # Run it in a simulator or on an iPhone (start-android alike)
58
+ akan build-desktop <app> # Build it for this computer into dist/native/<app>/<target>/build
59
+ akan build-desktop <app> --installer true # Windows: add a per-user setup program
60
+ akan update-keygen <app> # Make the update signing key once; print its public key
61
+ akan publish-update <app> # Build a key-signed release for updates.url; --sign true also code-signs it
62
+ ```
63
+
64
+ A device capability the framework lacks is a plugin the app owns in `native/<id>/`: `native-plugin.json`,
65
+ `src/index.ts` (the page API, used from a `webkit/` hook), `src/desktop.ts`, Kotlin and Swift.
42
66
 
43
- Full detail: `get_guideline` with `runtimeRule`.
67
+ Full detail: `get_guideline` with `runtimeRule` (keys, `--plain`, boot waves, `--kill`, watch scope, booting a
68
+ server in a test, native targets and updates).
@@ -106,5 +106,5 @@ The page calls it as `await fetch.book(id)` (`fetch` from `@apps/<app>/client`)
106
106
  `common/`, or return a scalar (`akan create-scalar`) for a typed wire shape. A query that answers `null` without
107
107
  `nullable: true` fails the render, naming the endpoint.
108
108
 
109
- Full detail: `get_guideline` with `modelService`; every import path and the exact signatures of serve, adapt,
110
- endpoint and serviceDictionary: `akanApi`.
109
+ Full detail: `get_guideline` with `modelService`. The exact signatures of serve, adapt, endpoint and
110
+ serviceDictionary, and every import path, are in the `akanApi-*` references below.