@akanjs/cli 3.1.1 → 3.1.2-rc.1

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 (113) hide show
  1. package/.build-stamp +1 -1
  2. package/CodeAgent-dyc45f5w.js +11 -0
  3. package/{CodeAgentRpcHost-9g27hmer.js → CodeAgentRpcHost-6dzfkvsc.js} +1 -1
  4. package/CodeAgentRpcListener-tcwrdvst.js +182 -0
  5. package/{CodeTui-h6yz2kvq.js → CodeTui-q55b2zrn.js} +25 -8
  6. package/TunnelShare-hdq9h1hr.js +14 -0
  7. package/{agent.command-3r4jsck8.js → agent.command-20zaqe60.js} +18 -15
  8. package/akanCode.js +8 -7
  9. package/{application.command-g7xv6ad0.js → application.command-nd0fshsk.js} +11 -11
  10. package/{applicationBuildRunner-qvjnhr9j.js → applicationBuildRunner-s13x3zqb.js} +10 -9
  11. package/buildBatch.proc.js +6 -6
  12. package/{cloud.command-6ebygmhw.js → cloud.command-8kbddsz9.js} +25 -18
  13. package/cloud.script-hgvvajm3.js +27 -0
  14. package/code.command-625bg8s8.js +345 -0
  15. package/{context.command-svdh6b2w.js → context.command-p6haqjay.js} +19 -18
  16. package/context.runner-rsnqnk9j.js +27 -0
  17. package/{dependencyScanner-3afj2vt1.js → dependencyScanner-78sq8m4q.js} +2 -2
  18. package/{fileSys-wzzrntkw.js → fileSys-zpvt5gtf.js} +1 -1
  19. package/{guideline.command-qwp3tnjx.js → guideline.command-195g0h9a.js} +4 -4
  20. package/guidelines/agentRule/agentRule.instruction.md +22 -8
  21. package/guidelines/conventions/rules/auth.md +5 -4
  22. package/guidelines/conventions/rules/config.md +5 -1
  23. package/guidelines/conventions/rules/gates.md +2 -1
  24. package/guidelines/conventions/rules/module.md +1 -1
  25. package/guidelines/conventions/rules/server.md +8 -3
  26. package/guidelines/conventions/rules/ssr.md +2 -2
  27. package/guidelines/conventions/rules/tsx.md +2 -1
  28. package/guidelines/pageRule/pageRule.instruction.md +4 -4
  29. package/guidelines/runtimeRule/runtimeRule.instruction.md +35 -25
  30. package/guidelines/ssrRule/ssrRule.instruction.md +11 -10
  31. package/guidelines/transportRule/transportRule.instruction.md +5 -4
  32. package/guidelines/workspaceRecipes/workspaceRecipes.instruction.md +1 -1
  33. package/incrementalBuilder.proc.js +4 -4
  34. package/{index-w4k2ragk.js → index-00a7j05x.js} +7 -7
  35. package/{index-w7q6h97v.js → index-0j1t1h2b.js} +3 -1
  36. package/{index-payhwt51.js → index-1h2jc0x3.js} +141 -67
  37. package/{index-vxmy1p4f.js → index-1qsd8ft1.js} +63 -123
  38. package/{index-s6da8ta9.js → index-2mwjshz5.js} +158 -51
  39. package/index-2nxk8wgs.js +266 -0
  40. package/{index-k5jbcxyh.js → index-2phm56a1.js} +49 -8
  41. package/{index-jje9qzyq.js → index-35j83zkd.js} +37 -3
  42. package/{index-m5n3ka0p.js → index-4am4dvmf.js} +13 -2
  43. package/index-75y7bcz4.js +28 -0
  44. package/{index-b8c289dx.js → index-7apsdr5g.js} +55 -12
  45. package/{index-8559hsz4.js → index-84h43kg6.js} +6 -5
  46. package/{index-eja64h28.js → index-9zy8479y.js} +5 -3
  47. package/{index-96wzdhfh.js → index-a1vb3x7t.js} +209 -36
  48. package/{index-52w0fvh8.js → index-bns3wcpc.js} +15 -0
  49. package/{index-am36s3jh.js → index-cjmjvg4r.js} +157 -117
  50. package/{index-1p0qbq3m.js → index-defp4gmb.js} +1 -1
  51. package/{index-4pdts00b.js → index-ewbmfarf.js} +10 -8
  52. package/{index-9rvcs76p.js → index-fhw7yq2d.js} +10 -10
  53. package/{index-8scw1pjk.js → index-g500c5j9.js} +178 -82
  54. package/{index-qxzrp5xt.js → index-g841cap9.js} +4 -4
  55. package/{index-qkkdhjm6.js → index-gr9thy79.js} +5 -5
  56. package/{index-4pf8g7ff.js → index-h7hehkw6.js} +3 -0
  57. package/{index-4mj92tsh.js → index-hm0tn7qv.js} +73 -68
  58. package/{index-r2wedvqn.js → index-j6eeh5d7.js} +1 -1
  59. package/{index-tgt2fnd6.js → index-j7hwy56s.js} +3 -3
  60. package/{index-rnphv731.js → index-jc2zbwra.js} +2 -2
  61. package/{index-z4b84y6k.js → index-khk05tsf.js} +1 -1
  62. package/{index-tvehn2sp.js → index-qd7xn2bk.js} +1 -1
  63. package/{index-266dewjs.js → index-qw6814m4.js} +53 -15
  64. package/{index-zcf6k8a5.js → index-raz588b3.js} +47 -12
  65. package/{index-at7bz0xq.js → index-s4nvxpzm.js} +2 -0
  66. package/{index-3yz30c07.js → index-sp0qsr7a.js} +114 -12
  67. package/{index-1shvxzt0.js → index-sveq36gh.js} +39 -42
  68. package/{index-r2w2eh93.js → index-t1t9wq9a.js} +4 -4
  69. package/index-t78230d7.js +191 -0
  70. package/{index-r0k3ham2.js → index-tgqameyb.js} +4 -4
  71. package/{index-dd44g6vz.js → index-tp56652m.js} +5 -5
  72. package/index-w15mg3km.js +389 -0
  73. package/{index-xq543a5y.js → index-y4kcmbt2.js} +2 -2
  74. package/index-yf9wc28h.js +52 -0
  75. package/{index-xqgwjz7a.js → index-zbrwnmf1.js} +9 -7
  76. package/{index-xxfy1jp2.js → index-zttm13c3.js} +4 -4
  77. package/index.js +24 -24
  78. package/{library.command-2853y6mk.js → library.command-63hgt9te.js} +4 -4
  79. package/{localRegistry.command-76ds31p4.js → localRegistry.command-g3f8k25t.js} +43 -23
  80. package/{module.command-yfnb0abs.js → module.command-r4sa2khp.js} +7 -6
  81. package/{package.command-d9s86hp9.js → package.command-96eheyvd.js} +5 -5
  82. package/package.json +2 -2
  83. package/{page.command-6a8a8rd1.js → page.command-gs6d841d.js} +4 -4
  84. package/{pipeline.command-rt3rwd2z.js → pipeline.command-wdfvdbfj.js} +3 -3
  85. package/{primitive.command-emcebgrq.js → primitive.command-dfsv4mpe.js} +8 -7
  86. package/{projectTypecheck-51m7eh1f.js → projectTypecheck-kqj1t6hb.js} +1 -1
  87. package/{prompter-hgcta8pb.js → prompter-qrwx1p17.js} +2 -2
  88. package/{quality.command-xtrk0n3x.js → quality.command-webzxee2.js} +6 -4
  89. package/{repair.command-51szxnxx.js → repair.command-3r3j1xre.js} +7 -6
  90. package/{scalar.command-8qv27t82.js → scalar.command-e8y47j6d.js} +6 -5
  91. package/skills/akan-agent/SKILL.md +8 -1
  92. package/skills/akan-code/SKILL.md +37 -11
  93. package/skills/akan-debug/SKILL.md +2 -1
  94. package/skills/akan-err/SKILL.md +2 -1
  95. package/skills/akan-query/SKILL.md +3 -2
  96. package/skills/akan-runtime/SKILL.md +3 -0
  97. package/{subspace.command-pn56pnh8.js → subspace.command-a1sf9n5a.js} +12 -10
  98. package/templates/appSample/lib/task/task.signal.ts +14 -9
  99. package/templates/appSample/srvkit/guards.ts +11 -0
  100. package/templates/service/__model__.dictionary.ts +3 -5
  101. package/templates/workspaceRoot/.gitignore.template +1 -0
  102. package/{tunnel.command-q2h0j2en.js → tunnel.command-dcb0wg93.js} +25 -13
  103. package/{verify.command-z1dsbmrt.js → verify.command-yyepccbh.js} +13 -11
  104. package/{workflow.command-r3y67jeq.js → workflow.command-z5pg9ay0.js} +12 -11
  105. package/{workspace.command-t2f0xsrw.js → workspace.command-d7x5jttw.js} +74 -47
  106. package/CodeAgent-35wnb7w5.js +0 -9
  107. package/CodeAgentRpcListener-7p7z5dd7.js +0 -97
  108. package/TunnelShare-xyjpa7gx.js +0 -14
  109. package/cloud.script-0s1jybd5.js +0 -26
  110. package/code.command-mpkm2emr.js +0 -167
  111. package/context.runner-ch0z3a8g.js +0 -26
  112. package/index-c6eggbee.js +0 -123
  113. package/index-ksfgqq1x.js +0 -49
@@ -0,0 +1,345 @@
1
+ // @bun
2
+ import {
3
+ Workspace,
4
+ runner,
5
+ script,
6
+ command
7
+ } from "./index-9zy8479y.js";
8
+ import"./index-bns3wcpc.js";
9
+ import"./index-g500c5j9.js";
10
+ import {
11
+ AkanCodeEnv,
12
+ akanCodePaths2
13
+ } from "./index-35j83zkd.js";
14
+ import {
15
+ akanCodeDefaultModel2,
16
+ CodeAgentStreamPrinter2,
17
+ WorkspaceTrust
18
+ } from "./index-w15mg3km.js";
19
+
20
+ // pkgs/@akanjs/cli/code/code.runner.ts
21
+ import { randomBytes } from "crypto";
22
+ import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "fs";
23
+ import path from "path";
24
+ import { codeAgentPresets, isCodeAgentPresetName } from "akanjs/common";
25
+
26
+ // pkgs/@akanjs/cli/code/CodeTrustPrompt.ts
27
+ var shown = 8;
28
+
29
+ class CodeTrustPrompt {
30
+ static describe(items) {
31
+ const lines = ["This repo asks akan code to run its own code:"];
32
+ for (const item of items) {
33
+ lines.push(item.kind === "mcp" ? " MCP servers in .akan/code/mcp.json, which it would start or connect to:" : " Extensions in .akan/code/extensions/, which it would load and run:");
34
+ lines.push(...item.lines.slice(0, shown).map((line) => ` ${line}`));
35
+ if (item.lines.length > shown)
36
+ lines.push(` \u2026 and ${item.lines.length - shown} more`);
37
+ }
38
+ return lines.join(`
39
+ `);
40
+ }
41
+ static skipped(items) {
42
+ const what = items.map((item) => item.kind === "mcp" ? "MCP servers" : "extensions").join(" and ");
43
+ return `This repo's ${what} were not started: they are not approved. Start akan code in a terminal to approve them, or pass --trust-workspace.`;
44
+ }
45
+ static async ask(items, { input, output }) {
46
+ output.write(`${CodeTrustPrompt.describe(items)}
47
+
48
+ Start them, and remember this until they change? [y/N] `);
49
+ const answer = await CodeTrustPrompt.#line(input);
50
+ return /^\s*y(es)?\s*$/i.test(answer ?? "");
51
+ }
52
+ static #line(input) {
53
+ return new Promise((resolve) => {
54
+ let buffer = "";
55
+ const finish = (value) => {
56
+ input.off("data", onData);
57
+ input.off("end", onEnd);
58
+ input.pause();
59
+ resolve(value);
60
+ };
61
+ const onData = (chunk) => {
62
+ buffer += chunk.toString();
63
+ const newline = buffer.search(/[\r\n]/);
64
+ if (newline >= 0)
65
+ finish(buffer.slice(0, newline));
66
+ };
67
+ const onEnd = () => finish(undefined);
68
+ input.on("data", onData);
69
+ input.on("end", onEnd);
70
+ input.resume();
71
+ });
72
+ }
73
+ }
74
+
75
+ // pkgs/@akanjs/cli/code/code.runner.ts
76
+ class CodeRunner extends runner("code") {
77
+ async serve(options, listen) {
78
+ await import("./consoleToStderr-h5bryj94.js");
79
+ const [{ CodeAgent }, { CodeAgentRpcHost }, { CodeAgentRpcListener }] = await Promise.all([
80
+ import("./CodeAgent-dyc45f5w.js"),
81
+ import("./CodeAgentRpcHost-6dzfkvsc.js"),
82
+ import("./CodeAgentRpcListener-tcwrdvst.js")
83
+ ]);
84
+ const address = listen ? CodeAgentRpcListener.parse(listen, { anyHost: !!options.rpcBindAny }) : null;
85
+ const tcp = !!address && !("unix" in address);
86
+ const tokenFile = tcp && options.rpcToken !== false ? AkanCodeEnv.get("AKAN_CODE_RPC_TOKEN_FILE") : undefined;
87
+ const token = !tcp || options.rpcToken === false ? null : CodeRunner.#rpcTokenFrom(tokenFile);
88
+ const start = await CodeRunner.#start(options, { hostAttached: true, interactive: false, ask: false });
89
+ for (const warning of start.warnings)
90
+ process.stderr.write(`${warning}
91
+ `);
92
+ const agent = await CodeAgent.create({ ...start.agent, mode: "rpc" });
93
+ if (!address)
94
+ return await new CodeAgentRpcHost(agent).serve();
95
+ const listener = new CodeAgentRpcListener(new CodeAgentRpcHost(agent, null), address, { token }).listen();
96
+ const where = "unix" in address ? address.unix : `${address.hostname}:${listener.port}`;
97
+ const written = token && !tokenFile ? CodeRunner.#writeRpcToken(listener.port ?? 0, token) : undefined;
98
+ const tokenAt = tokenFile ?? written;
99
+ process.stderr.write(tokenAt ? `akan code rpc listening on ${where}; open with {"auth":"<token>"}, the token is in ${tokenAt}
100
+ ` : `akan code rpc listening on ${where}
101
+ `);
102
+ if (tcp && !token)
103
+ process.stderr.write(`No token is asked for, so any process on this machine can drive this agent.
104
+ `);
105
+ try {
106
+ await listener.serve();
107
+ } finally {
108
+ if (written)
109
+ rmSync(written, { force: true });
110
+ }
111
+ }
112
+ async tui(options, seed) {
113
+ const [{ CodeAgent }, { CodeTui }] = await Promise.all([
114
+ import("./CodeAgent-dyc45f5w.js"),
115
+ import("./CodeTui-q55b2zrn.js")
116
+ ]);
117
+ const start = await CodeRunner.#start(options, { hostAttached: false, interactive: true, ask: true });
118
+ const agentOptions = start.agent;
119
+ let warnings = start.warnings;
120
+ let resume = options.resume;
121
+ let autoCompactAt = agentOptions.autoCompactAt;
122
+ let prompt = seed;
123
+ let notice;
124
+ for (;; ) {
125
+ const agent = await CodeAgent.create({
126
+ ...agentOptions,
127
+ mode: "tui",
128
+ ...resume ? { resume } : {},
129
+ ...autoCompactAt ? { autoCompactAt } : {}
130
+ });
131
+ let next;
132
+ try {
133
+ next = await new CodeTui(agent, {
134
+ thinking: options.thinking,
135
+ ...notice ? { notice } : {},
136
+ warnings
137
+ }).run(prompt);
138
+ autoCompactAt = agent.info.autoCompactAt;
139
+ } finally {
140
+ agent.dispose();
141
+ }
142
+ if (!next)
143
+ return;
144
+ resume = next.id;
145
+ notice = next.notice;
146
+ warnings = [];
147
+ prompt = "";
148
+ }
149
+ }
150
+ async run(prompt, options) {
151
+ const { CodeAgent } = await import("./CodeAgent-dyc45f5w.js");
152
+ const ask = !!process.stdin.isTTY && !!process.stderr.isTTY;
153
+ const start = await CodeRunner.#start(options, { hostAttached: false, interactive: false, ask });
154
+ for (const warning of start.warnings)
155
+ process.stderr.write(`${warning}
156
+ `);
157
+ const agent = await CodeAgent.create(start.agent);
158
+ const printer = new CodeAgentStreamPrinter2({ json: options.json, thinking: options.thinking });
159
+ agent.on((event) => printer.print(event));
160
+ agent.announce();
161
+ try {
162
+ await agent.prompt(prompt);
163
+ await agent.waitForIdle();
164
+ } finally {
165
+ printer.finish();
166
+ agent.dispose();
167
+ }
168
+ }
169
+ static async#start(options, mode) {
170
+ const profile = CodeRunner.profileOf(options, mode);
171
+ const trust = await CodeRunner.trust(options.workspace.workspaceRoot, profile, {
172
+ trustWorkspace: !!options.trustWorkspace,
173
+ ...mode.ask && process.stdin.isTTY ? { streams: { input: process.stdin, output: process.stderr } } : {}
174
+ });
175
+ const agent = {
176
+ workspace: options.workspace,
177
+ cwd: profile.paths.root,
178
+ profile,
179
+ apps: options.app ? [options.app] : await options.workspace.getApps(),
180
+ model: CodeRunner.modelOf(options.model),
181
+ ...options.compactAt !== undefined ? { autoCompactAt: options.compactAt } : {}
182
+ };
183
+ return { agent, warnings: [...CodeRunner.startWarnings(profile), ...trust] };
184
+ }
185
+ static profileOf(options, { hostAttached, interactive = true }) {
186
+ if (!isCodeAgentPresetName(options.profile))
187
+ throw new Error(`Unknown profile: ${options.profile}. Use local, pod, review, or web.`);
188
+ const root = options.app ? `${options.workspace.workspaceRoot}/apps/${options.app}` : options.workspace.workspaceRoot;
189
+ const profile = codeAgentPresets[options.profile](root);
190
+ const { askOutside: _ask, ...network } = profile.network;
191
+ return {
192
+ ...profile,
193
+ ...options.askNetwork === false ? { network } : {},
194
+ ui: { ...profile.ui, canPrompt: CodeRunner.canPrompt(profile, hostAttached, interactive) }
195
+ };
196
+ }
197
+ static canPrompt(profile, hostAttached, interactive = true) {
198
+ const forced = AkanCodeEnv.get("AKAN_CODE_CAN_PROMPT");
199
+ if (forced === "1")
200
+ return true;
201
+ if (forced === "0")
202
+ return false;
203
+ return hostAttached || interactive && profile.ui.canPrompt;
204
+ }
205
+ static startWarnings(profile) {
206
+ return [
207
+ ...AkanCodeEnv.ignored(),
208
+ ...profile.name === "local" ? [
209
+ "The local profile is not a sandbox: it refuses known secret files and asks before an unlisted host, but a command it runs can read anything you can. Use --profile pod inside a container to isolate it."
210
+ ] : []
211
+ ];
212
+ }
213
+ static async trust(workspaceRoot, profile, { trustWorkspace, streams }) {
214
+ const kinds = profile.tools.mcp === "off" ? ["extensions"] : ["mcp", "extensions"];
215
+ const pending = WorkspaceTrust.pending(workspaceRoot, kinds);
216
+ if (!pending.length)
217
+ return [];
218
+ if (trustWorkspace) {
219
+ WorkspaceTrust.approve(workspaceRoot, pending, false);
220
+ return [];
221
+ }
222
+ if (streams && await CodeTrustPrompt.ask(pending, streams)) {
223
+ WorkspaceTrust.approve(workspaceRoot, pending, true);
224
+ return [];
225
+ }
226
+ return [CodeTrustPrompt.skipped(pending)];
227
+ }
228
+ static #rpcTokenFrom(file) {
229
+ if (!file || !existsSync(file)) {
230
+ const token = randomBytes(32).toString("base64url");
231
+ if (file)
232
+ CodeRunner.#writePrivate(file, token);
233
+ return token;
234
+ }
235
+ const token = readFileSync(file, "utf8").trim();
236
+ if (!token)
237
+ throw new Error(`AKAN_CODE_RPC_TOKEN_FILE names ${file}, which is empty.`);
238
+ return token;
239
+ }
240
+ static #writeRpcToken(port, token) {
241
+ const file = akanCodePaths2.rpcTokenFile(port);
242
+ CodeRunner.#writePrivate(file, token);
243
+ return file;
244
+ }
245
+ static #writePrivate(file, content) {
246
+ akanCodePaths2.ensureGlobalDir();
247
+ mkdirSync(path.dirname(file), { recursive: true, mode: 448 });
248
+ writeFileSync(file, `${content}
249
+ `, { mode: 384 });
250
+ chmodSync(file, 384);
251
+ }
252
+ static modelOf(model) {
253
+ if (!model)
254
+ return;
255
+ const [provider, ...rest] = model.split("/");
256
+ if (!provider || !rest.length)
257
+ throw new Error(`Model must be "<provider>/<id>", e.g. ${akanCodeDefaultModel2.provider}/${akanCodeDefaultModel2.id}`);
258
+ return { provider, id: rest.join("/") };
259
+ }
260
+ }
261
+
262
+ // pkgs/@akanjs/cli/code/code.script.ts
263
+ class CodeScript extends script("code", [CodeRunner]) {
264
+ async run(workspace, prompt, options) {
265
+ const run = {
266
+ workspace,
267
+ ...options.app ? { app: options.app } : {},
268
+ profile: options.profile,
269
+ ...options.model ? { model: options.model } : {},
270
+ ...options.compactAt !== null ? { compactAt: options.compactAt } : {},
271
+ json: options.json,
272
+ thinking: options.thinking,
273
+ ...options.resume ? { resume: options.resume } : {},
274
+ trustWorkspace: options.trustWorkspace,
275
+ askNetwork: options.askNetwork,
276
+ rpcBindAny: options.rpcBindAny,
277
+ rpcToken: options.rpcToken
278
+ };
279
+ if (options.rpcListen)
280
+ return await this.codeRunner.serve(run, options.rpcListen);
281
+ if (options.rpc)
282
+ return await this.codeRunner.serve(run);
283
+ const interactive = options.interactive || !prompt.trim() && !options.json && !!process.stdout.isTTY;
284
+ if (interactive)
285
+ return await this.codeRunner.tui(run, prompt);
286
+ if (!prompt.trim())
287
+ throw new Error('akan code needs a prompt when it has no terminal: akan code "add a comment module"');
288
+ await this.codeRunner.run(prompt, run);
289
+ }
290
+ }
291
+
292
+ // pkgs/@akanjs/cli/code/code.command.ts
293
+ class CodeCommand extends command("code", [CodeScript], ({ public: target }) => ({
294
+ code: target({ desc: "Run the akan coding agent on a prompt" }).arg("prompt", String, { desc: "what the agent should do", nullable: true }).option("app", String, { desc: "narrow the agent to one app instead of the whole repo", nullable: true }).option("profile", String, { desc: "local, pod, review, or web", default: "local" }).option("model", String, { desc: "<provider>/<id>, e.g. deepseek/deepseek-flash", nullable: true }).option("compactAt", Number, {
295
+ desc: "compact once the context window is this full, in percent: 10, 20, \u2026 100",
296
+ flag: "c",
297
+ nullable: true
298
+ }).option("json", Boolean, { desc: "print one event per line as JSON", default: false }).option("thinking", Boolean, { desc: "print the model's reasoning", default: false }).option("rpc", Boolean, { desc: "serve the agent over stdio for another process to drive", default: false }).option("rpcListen", String, {
299
+ desc: "serve the RPC wire on unix:<path> or tcp:[host:]<port> instead of stdio",
300
+ flag: "L",
301
+ nullable: true
302
+ }).option("resume", String, { desc: "continue a stored session by id", flag: "R", nullable: true }).option("interactive", Boolean, {
303
+ desc: "open the full-screen session even when a prompt is given",
304
+ flag: "i",
305
+ default: false
306
+ }).option("trustWorkspace", Boolean, {
307
+ desc: "start this repo's own MCP servers and extensions for this run without asking",
308
+ flag: "T",
309
+ default: false
310
+ }).option("askNetwork", Boolean, {
311
+ desc: "ask before fetching an unlisted host or running a networking command (local profile)",
312
+ flag: "N",
313
+ default: true
314
+ }).option("rpcBindAny", Boolean, {
315
+ desc: "let --rpc-listen bind an address other machines can reach",
316
+ flag: "B",
317
+ default: false
318
+ }).option("rpcToken", Boolean, {
319
+ desc: "make a --rpc-listen tcp: connection open with its token",
320
+ flag: "K",
321
+ default: true
322
+ }).with(Workspace).exec(async function(prompt, app, profile, model, compactAt, json, thinking, rpc, rpcListen, resume, interactive, trustWorkspace, askNetwork, rpcBindAny, rpcToken, workspace) {
323
+ const options = {
324
+ app,
325
+ profile,
326
+ model,
327
+ compactAt,
328
+ json,
329
+ thinking,
330
+ rpc,
331
+ rpcListen,
332
+ interactive,
333
+ resume,
334
+ trustWorkspace,
335
+ askNetwork,
336
+ rpcBindAny,
337
+ rpcToken
338
+ };
339
+ await this.codeScript.run(workspace, prompt ?? "", options);
340
+ })
341
+ })) {
342
+ }
343
+ export {
344
+ CodeCommand
345
+ };
@@ -2,29 +2,30 @@
2
2
  import {
3
3
  Workspace,
4
4
  command
5
- } from "./index-eja64h28.js";
6
- import"./index-52w0fvh8.js";
7
- import"./index-8scw1pjk.js";
5
+ } from "./index-9zy8479y.js";
6
+ import"./index-bns3wcpc.js";
7
+ import"./index-g500c5j9.js";
8
8
  import"./index-hj6w4ka1.js";
9
- import"./index-4mj92tsh.js";
10
- import"./index-tgt2fnd6.js";
11
- import"./index-266dewjs.js";
12
- import"./index-3yz30c07.js";
13
- import"./index-w7q6h97v.js";
9
+ import"./index-hm0tn7qv.js";
10
+ import"./index-2nxk8wgs.js";
11
+ import"./index-j7hwy56s.js";
12
+ import"./index-qw6814m4.js";
13
+ import"./index-sp0qsr7a.js";
14
+ import"./index-0j1t1h2b.js";
14
15
  import"./index-m9jj544v.js";
15
- import"./index-1shvxzt0.js";
16
- import"./index-xqgwjz7a.js";
17
- import"./index-r2wedvqn.js";
18
- import"./index-k5jbcxyh.js";
19
- import"./index-z4b84y6k.js";
20
- import"./index-r2w2eh93.js";
21
- import"./index-qxzrp5xt.js";
22
- import"./index-rnphv731.js";
16
+ import"./index-zbrwnmf1.js";
17
+ import"./index-sveq36gh.js";
18
+ import"./index-j6eeh5d7.js";
19
+ import"./index-2phm56a1.js";
20
+ import"./index-khk05tsf.js";
21
+ import"./index-t1t9wq9a.js";
22
+ import"./index-g841cap9.js";
23
+ import"./index-jc2zbwra.js";
23
24
  import"./index-fbewhg4g.js";
24
- import"./index-zcf6k8a5.js";
25
+ import"./index-raz588b3.js";
25
26
  import {
26
27
  ContextScript
27
- } from "./index-r0k3ham2.js";
28
+ } from "./index-tgqameyb.js";
28
29
 
29
30
  // pkgs/@akanjs/cli/context/context.command.ts
30
31
  class ContextCommand extends command("context", [ContextScript], ({ public: target }) => ({
@@ -0,0 +1,27 @@
1
+ // @bun
2
+ import {
3
+ ContextRunner2
4
+ } from "./index-qw6814m4.js";
5
+ import"./index-raz588b3.js";
6
+ import"./index-jc2zbwra.js";
7
+ import"./index-g841cap9.js";
8
+ import"./index-2phm56a1.js";
9
+ import"./index-t1t9wq9a.js";
10
+ import"./index-khk05tsf.js";
11
+ import"./index-fbewhg4g.js";
12
+ import"./index-j7hwy56s.js";
13
+ import"./index-hm0tn7qv.js";
14
+ import"./index-2nxk8wgs.js";
15
+ import"./index-0j1t1h2b.js";
16
+ import"./index-j6eeh5d7.js";
17
+ import"./index-sp0qsr7a.js";
18
+ import"./index-m9jj544v.js";
19
+ import"./index-9zy8479y.js";
20
+ import"./index-sveq36gh.js";
21
+ import"./index-zbrwnmf1.js";
22
+ import"./index-g500c5j9.js";
23
+ import"./index-hj6w4ka1.js";
24
+ import"./index-bns3wcpc.js";
25
+ export {
26
+ ContextRunner2 as ContextRunner
27
+ };
@@ -1,8 +1,8 @@
1
1
  // @bun
2
2
  import {
3
3
  TypeScriptDependencyScanner2
4
- } from "./index-tvehn2sp.js";
5
- import"./index-52w0fvh8.js";
4
+ } from "./index-qd7xn2bk.js";
5
+ import"./index-bns3wcpc.js";
6
6
  export {
7
7
  TypeScriptDependencyScanner2 as TypeScriptDependencyScanner
8
8
  };
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  getDirname2,
4
4
  FileSys2
5
- } from "./index-52w0fvh8.js";
5
+ } from "./index-bns3wcpc.js";
6
6
  export {
7
7
  FileSys2 as FileSys,
8
8
  getDirname2 as getDirname
@@ -2,12 +2,12 @@
2
2
  import {
3
3
  script,
4
4
  command
5
- } from "./index-eja64h28.js";
6
- import"./index-52w0fvh8.js";
7
- import"./index-8scw1pjk.js";
5
+ } from "./index-9zy8479y.js";
6
+ import"./index-bns3wcpc.js";
7
+ import"./index-g500c5j9.js";
8
8
  import {
9
9
  Prompter2
10
- } from "./index-r2wedvqn.js";
10
+ } from "./index-j6eeh5d7.js";
11
11
 
12
12
  // pkgs/@akanjs/cli/guideline/guideline.script.ts
13
13
  import { Logger } from "akanjs/common";
@@ -34,7 +34,12 @@ pages declaring one name never clash, and a registry kept outside the surface re
34
34
  cannot spend the LLM key. **The guard decides who, not what** — the browser writes the instructions, tools and
35
35
  transcript — so `option.setAgentRequestPolicy((request, { account, ip }) => request)` sees each turn after the
36
36
  guard, before the quota and the model (tool names as the page published them), and returns what is sent, or
37
- throws an `Err` (`agent.error.requestRefused`) to refuse it.
37
+ throws an `Err` (`agent.error.requestRefused`) to refuse it. With no policy set, a turn past
38
+ `AgentRelayPolicy.defaultLimits` (5,000 messages, 512 tools, 256 context entries, 8M characters, 64 MiB of
39
+ attachments) is refused with 413; a policy of the app's own keeps them by returning
40
+ `AgentRelayPolicy.capped(request, limits)`, and `(request) => request` lifts them. An error that is not an `Err`
41
+ reaches the chat as a generic failure and the server log in full, unless `AKAN_ERROR_DETAIL=1` or a development
42
+ runtime (`akan start`, `NODE_ENV` `development` or `test`) shows its message.
38
43
  `persist` keeps the transcript across reloads (sessionStorage; `{ storage: "local" }` to outlive the tab),
39
44
  default off, and `shortcut={false}` gives the browser back the Cmd/Ctrl+L the launcher otherwise captures.
40
45
  **`persist` also takes a `SessionHistory` of the app's own** — `{ load, save, clear }` — which is how a
@@ -111,11 +116,12 @@ pages declaring one name never clash, and a registry kept outside the surface re
111
116
  app's own chat-completions adaptor claims through `OpenaiLlm.acceptsOf(llmOption)` instead of copying the rule —
112
117
  a copy that read "any host is a gateway" kept a vision model text-only for an app that spelled out
113
118
  `https://api.openai.com/v1`.
114
- - **A refusal is `agent.error.llmRequestFailed`, and it names the host** — unless the prompt did not fit. The
115
- provider's own sentence rides in `reason` and the hostname in `provider`. `LlmOverflow.refusal(host, status,
116
- reason)` builds it, and reads the one refusal a chat can undo — a prompt past the window, recognized from each
117
- provider's own sentence — as `agent.error.contextOverflow` with the `limit` it named, which the relay flags so
118
- the chat compacts and asks again. An adaptor an app wrote throws through the same function, so its refusals
119
+ - **A refusal is `agent.error.llmRequestFailed`, and it names the host** — unless the prompt did not fit. It
120
+ carries `{ provider, status }`, the hostname and the HTTP status; the provider's own sentence goes to the server
121
+ log only, because it can quote an account id or part of a key and `Err` data reaches the browser.
122
+ `LlmOverflow.refusal(host, status, reason)` builds it, and reads the one refusal a chat can undo — a prompt past
123
+ the window, recognized from each provider's own sentence — as `agent.error.contextOverflow` with the `limit` it
124
+ named, which the relay flags so the chat compacts and asks again. An adaptor an app wrote throws through the same function, so its refusals
119
125
  translate and recover the way the shipped ones do without a key in the framework's dictionary it cannot add.
120
126
  - **`accepts` is answered per model, through `option.setLlm({ accepts })`.** An adaptor answers for an API and one
121
127
  API serves models that differ, so the override rides beside the `model` it is a fact about. It is not a table
@@ -322,7 +328,12 @@ pages declaring one name never clash, and a registry kept outside the surface re
322
328
  an inline arrow can be clicked by a person and by nobody else. `.desc()` is required and comes first, `.arg()`
323
329
  is an argument the caller must pass and `.opt()` one it may leave out (the `exec` parameter is then `| null`),
324
330
  and `.exec()` is the only hook, so the chain completes in one unconditional statement and the callable carries
325
- `data-akan-action` like a store setter does. A `remove*` name defaults to a confirm gate. `st.tool("x", { label:
331
+ `data-akan-action` like a store setter does. A name starting with a write verb (`remove`, `delete`, `create`,
332
+ `update`, `upsert`, `submit`, `save`, `send`, `export`) asks the user first unless it says `{ confirm: false }`;
333
+ `AgentConfirm.set({ byName })` moves that default app-wide. After a tool marked `taint: "source"` (`readScreen`,
334
+ `readState`, `viewImage`) returns text the user did not write, the next call that changes something asks once,
335
+ whatever its own `confirm` says, until the user approves a call; `taint: "exempt"` marks a tool that only moves the
336
+ view, and `AgentConfirm.set({ afterScreenRead: false })` turns the rule off. `st.tool("x", { label:
326
337
  l("ticket.archive") })` gives the action a name a person reads — `Agent.useScreenActions()` hands it to a command
327
338
  palette, and the model never sees it. Reach a store action
328
339
  from the body — `.exec((id) => st.do.removeX(id))` — which is how an agent gets CRUD; `st.do` on its own
@@ -718,7 +729,10 @@ pages declaring one name never clash, and a registry kept outside the surface re
718
729
  or `<nav>` and the component insists on a label. A region that is hidden anyway leaves no marker claiming it is
719
730
  there. **It hides text, not behaviour**: tools and state keys are declarations rather than markup, so an
720
731
  `st.tool` inside is published exactly as before and `highlight` still reaches a control in there. This is
721
- `field.visual` one layer up — cost, not secrecy.
732
+ `field.visual` one layer up — cost, not secrecy. Secrecy is `data-agent-private="<label>"`: the read prints
733
+ `[private: <label>]` in its place even when asked for by name, and it is no `section` or `highlight` target. A
734
+ password, one-time-code or card input (its standard `autocomplete`) is never read either; any other value on
735
+ screen is.
722
736
  - **Reach for it second.** A read narrows from the other side too: `Agent.Zone` and `readScreen({ section })` scope
723
737
  to one container, which beats blocklisting five regions on a screen that is mostly chrome. And a footer is last
724
738
  in the document, so on a page long enough to truncate it was already past the cut — the regions worth marking are
@@ -11,10 +11,10 @@ paths:
11
11
  `guards: { cru: false }` (or per verb) takes a generated verb off HTTP; `mcp: { cru: false }` only keeps it off the
12
12
  agent shelf.
13
13
  - **Every custom `mutation` / `query` / `message` names its own `guards: [...]`** — the slice map reaches only
14
- generated endpoints, and a `pubsub` / `message` without its own is unguarded. `Public` belongs on a slice `get:`;
14
+ generated endpoints, and a `pubsub` / `message` without its own declares none. `Public` belongs on a slice `get:`;
15
15
  on a mutation only for an act that must work signed out (sign-up/in, token refresh, an OAuth route), which also
16
- declares a `rateLimit`. A guardless endpoint is warned at boot and never published to MCP, which also refuses a
17
- mutation guarded only by `Public`.
16
+ declares a `rateLimit`. A guardless endpoint answers every call with 403 and stops the boot outside local
17
+ operation; MCP also refuses a mutation guarded only by `Public`.
18
18
  - Guards serve HTTP and websocket alike: read `context.get<T>("account")`, never `getHttpContext()` /
19
19
  `getWebSocketContext()`; keep them side-effect free and re-runnable. The acting user comes from `.with(Self)` /
20
20
  `.with(CurrentUserId)` / `.with(Me)` (never a client-supplied id) and the caller's address from `.with(Ip)`.
@@ -28,7 +28,8 @@ paths:
28
28
 
29
29
  - **Every endpoint and named slice names its guards** (`no-unguarded-endpoint`, a warning) — a `query` / `mutation` /
30
30
  `pubsub` / `message`, a named slice's `init()`, or a `slice()` map without `root` that names none (or `guards: []`)
31
- answers every caller. Write `guards: [Public]` when anonymous access is the intent.
31
+ refuses every caller, and outside local operation the server does not boot. Write `guards: [Public]` when
32
+ anonymous access is the intent.
32
33
 
33
34
  - **A `slice()` takes its guard map as a second argument**, `slice(srv.task, { guards: { root: Admin, get: SignedIn,
34
35
  cru: SignedIn } }, (init) => ({...}))`. An `endpoint()` takes no guard argument at all —
@@ -27,11 +27,15 @@ Declared in `akan.config.ts`, narrowed — never widened — by an env at boot;
27
27
  `NativeSecret` (the OS credential store), never in a file.
28
28
  - **`database: { modes: [...] }`** (`single`, `multiple`, `cluster`), chosen by `AKAN_DATABASE_MODE`; an app running
29
29
  in two modes avoids `q.raw`.
30
+ - **`i18n: { localePrefix: "as-needed" }`** serves the default locale at unprefixed paths (`/pokemon/x`, and `<Link>`
31
+ renders them so) while other locales keep `/<locale>/…`. Use it, not a raw `<a>`, for a single-language app or URLs
32
+ fixed from outside (OAuth callbacks, QR codes, mail links, a migrated site).
30
33
 
31
34
  ## Running An App
32
35
 
33
36
  - After changing application code, run `bun run akan start <appName>` (`a,b`, `a b`, or `all` for several); check
34
- the production build with `bun run akan build <appName>`.
37
+ the production build with `bun run akan build <appName>`, and serve it without Docker with
38
+ `cd dist/apps/<appName> && bun main.js` (`PORT` or any variable you set overrides the build's env).
35
39
  - A supervised session writes `local/apps/<app>/runtime/dev.log` (previous: `dev.prev.log`) — hand over that path,
36
40
  not a paste of the repainting full-screen view. Keys, `--plain`, boot waves, `--kill`, watch scope, running a
37
41
  built artifact, booting a server in a test: `runtimeRule`.
@@ -24,7 +24,8 @@ paths:
24
24
  action calls once.
25
25
  - `akan.service.call-in-loop`: a service method an `endpoint` or `slice` reaches calling a service, a model or a
26
26
  generated query once per item (`for … of`, `map`, `forEach`); load the set once (`load<Model>Many`, one
27
- filter query) or write it once. An `internal` job and a counted loop (a retry, paging) are spared.
27
+ filter query) or write it once (`create<Model>Many`). An `internal` job and a counted loop (a retry, paging) are
28
+ spared.
28
29
  - `akan.baseline.json` (`akan.baseline.growth`) records, per rule, the debt adopted with the gate, and is compared
29
30
  with its copy at the fork point of the default branch, so it only ever shrinks: never add or raise an entry. A size,
30
31
  store-reach or per-item entry with a `reasons` line is an exception a person decided on, never an agent; the write
@@ -30,7 +30,7 @@ orchestration in `service`, client state in `store`; `Template` is forms, `Unit`
30
30
  - **`<model>.service.ts`** — a few lines: load → chain → `return await ….save()` (keep the `return await`). Side
31
31
  effects go in `override async _preUpdate` / `_postCreate`; fire-and-forget is `void`-ed. Load every referenced
32
32
  document, then save, then notify; writes that must land together go in `this.transaction(async () => …)` and
33
- their notification in `this.afterCommit(…)` (`queryRule`). Return `null` / `false` for not allowed or not found;
33
+ their notification in `this.afterCommit(…)` (`queryRule`); a list of new rows is one `create<Model>Many(rows)`. Return `null` / `false` for not allowed or not found;
34
34
  the signal decides whether that is an error.
35
35
  - **`<model>.signal.ts`** — `XInternal` → `XSlice` → `XEndpoint`, all three even when empty; `exec` is a one-liner
36
36
  calling the service.
@@ -14,6 +14,10 @@ paths:
14
14
 
15
15
  ## Calls, Queries, Agents
16
16
 
17
+ - **Guards (`transportRule`)**: an endpoint, a named slice's `init()` or a root slice that declares no guards is
18
+ refused with 403 on every transport, and outside local operation the server does not boot with one. Name its
19
+ guards, or `[Public]` to open it on purpose; `AKAN_UNGUARDED_ENDPOINTS=open` is a deployment's stopgap, never the
20
+ fix.
17
21
  - **Wire (`transportRule`)**: a deadline is the endpoint's `{ timeout: <ms> }` (undeclared, the client quits at
18
22
  30 s; the handler is not cancelled); `{ cache }` only on a `query` with no internal argument, capped at one day,
19
23
  dropped early by `invalidate(endpoint, args?)` on a plugged `EndpointCacheControl`; `{ rateLimit }` per endpoint,
@@ -47,7 +51,7 @@ paths:
47
51
  `page().app(name, description, load)` — a read-only tool whose `load` may only query.
48
52
  - **In-page agent (`agentRule`)**: mount `<Agent.Chat />` once in a layout; it never executes tools and refuses
49
53
  every call until `option.setAgentAccess(<guard>)`, which decides who — what a turn may ask is
50
- `option.setAgentRequestPolicy`; the LLM is `option.setLlm({ apiKey, model, host })`, never env.
54
+ `option.setAgentRequestPolicy`, size-capped until one is set; the LLM is `option.setLlm({ apiKey, model, host })`, never env.
51
55
  The surface is what components declare — `st.tool(…).exec(fn)` beside its control, `st.use` / `st.sel` /
52
56
  `st.ref` keys — never a store class. `st.use.x({ agent: false })` hides a key; its model's `hidden` / `secret` /
53
57
  `visual` fields are stripped at read. A tool value is capped at 20,000 characters. Route guidance is
@@ -82,5 +86,6 @@ paths:
82
86
  `Err.is(error, "ticket.error.locked")`.
83
87
  - `try/catch` turns an exception into a decision: guards → `logger.warn` → `false`; adapters → `logger.error` →
84
88
  `null`; UI `try/finally` resets a spinner. A bodyless `catch {}` needs a one-line reason.
85
- - Store actions do not `try/catch` (the framework toasts the `Err`); client validation is `msg.error("<key>")` plus
86
- an early return, never a throw.
89
+ - Store actions do not `try/catch` (the framework toasts the `Err`); one no screen waits on (a token refresh) is
90
+ listed in the store's `static silent`, rejecting untoasted to the caller that handles it. Client validation is
91
+ `msg.error("<key>")` plus an early return, never a throw.
@@ -43,5 +43,5 @@ promise across — `const { xInitInY, xListInY } = fetch.initXInY(id)`, `xInitIn
43
43
  `<Load.Stream>` (model instances, server-only) — and `await` only what the shell must contain; ⑥ named `ReactNode`
44
44
  slots (`Layout.Navbar`); ⑦ derived display logic on `Light<Model>`; ⑧ `.guard(() => signedIn())`
45
45
  (`@libs/shared/webkit`) on `_layout.tsx` (a real 3xx before anything renders; `getSelf({ unauthorize })` in a body
46
- redirects in-page after I/O); ⑨ CSS (`data-*` + `group-data-[…]`, `<details>`) over client state for visibility;
47
- ⑩ heavy islands behind `index_.tsx` + `lazy()`.
46
+ under a `.loading()` redirects in-page after I/O); ⑨ CSS (`data-*` + `group-data-[…]`, `<details>`) over client
47
+ state for visibility; ⑩ heavy islands behind `index_.tsx` + `lazy()`.
@@ -47,7 +47,8 @@ state. Reach for the path, not the nearest file:
47
47
  values never saved; field `cache` / `cacheKey` props are deprecated no-ops — `modelStore`).
48
48
  - `<Link>` from `akanjs/ui` for internal navigation; `<a>` only for `mailto:` and external links. A `<Link>` handed
49
49
  an absolute URL (any scheme, any case) or a `//host` path passes it through untouched and opens it outside the app;
50
- only an app path gets the locale and basePath. `Href.isExternal(href)` from `akanjs/client` is that test.
50
+ only an app path gets the locale (none for the default locale under `i18n.localePrefix: "as-needed"`) and basePath.
51
+ `Href.isExternal(href)` from `akanjs/client` is that test.
51
52
 
52
53
  ## Lint Rules On Components
53
54