@akanjs/cli 3.0.0-alpha.4 → 3.0.0-alpha.5

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 (60) hide show
  1. package/.build-stamp +1 -1
  2. package/{abstractCompactor-rk6twzvj.js → abstractCompactor-e5yq60qz.js} +2 -2
  3. package/{agent.command-jfz8yfwy.js → agent.command-b0fcx3r2.js} +7 -7
  4. package/{application.command-mxyqtd6p.js → application.command-cgmy00gd.js} +5 -5
  5. package/{applicationBuildRunner-cwk52sb7.js → applicationBuildRunner-n1svrwgt.js} +4 -4
  6. package/{applicationReleasePackager-yrrhbkv3.js → applicationReleasePackager-gg8ccbeh.js} +1 -1
  7. package/buildBatch.proc.js +4 -4
  8. package/{capacitorApp-j357ak1g.js → capacitorApp-yyw35vg4.js} +3 -5
  9. package/{cloud.command-f87dwe52.js → cloud.command-1m7hfdpk.js} +9 -9
  10. package/{context.command-z5bf8bn7.js → context.command-b5heat2a.js} +15 -15
  11. package/{guideline.command-1m1ctar3.js → guideline.command-9ew6aqhm.js} +5 -5
  12. package/guidelines/ssrRule/ssrRule.generate.json +31 -0
  13. package/guidelines/ssrRule/ssrRule.instruction.md +108 -0
  14. package/incrementalBuilder.proc.js +3 -3
  15. package/{index-3pgtw35d.js → index-0cj2zxbm.js} +1 -1
  16. package/{index-cap2k2ch.js → index-0fj4yg7k.js} +52 -17
  17. package/{index-jtm86byd.js → index-47qxw1tz.js} +28 -22
  18. package/{index-vhv3xnjz.js → index-60a3jfcz.js} +6 -6
  19. package/{index-b978vs2e.js → index-6npsfpxr.js} +3 -3
  20. package/{index-csqk9z5j.js → index-c94nq3c1.js} +3 -3
  21. package/{index-cn24dcqn.js → index-exhpp31y.js} +2 -2
  22. package/{index-hjzr8ja1.js → index-hrwzz2wf.js} +1 -1
  23. package/{index-rh16j3c7.js → index-j9cxndc0.js} +3 -2
  24. package/{index-jk9q6pse.js → index-jkynkyfk.js} +1 -1
  25. package/{index-4yp06pn1.js → index-jn9vfpwz.js} +9 -31
  26. package/{index-4zgs8g1w.js → index-m4kpmmtj.js} +1 -1
  27. package/{index-e3qskyt2.js → index-meh7mmz9.js} +2 -2
  28. package/{index-ybybkec0.js → index-mn96y1nk.js} +6 -6
  29. package/{index-y0k42k04.js → index-mterpj70.js} +17 -86
  30. package/{index-6pz1j0zj.js → index-mxvakhsm.js} +6 -2
  31. package/{index-n0z3f2xg.js → index-nfxq39kj.js} +4 -4
  32. package/{index-tq1y56tp.js → index-nx1vbtsc.js} +35 -12
  33. package/{index-1s71fwrq.js → index-p69fcwe1.js} +11 -11
  34. package/{index-xj8bks3p.js → index-p6txr1ss.js} +4 -4
  35. package/{index-r4w8cry5.js → index-pfrt7qwh.js} +4 -4
  36. package/{index-xwgm94zr.js → index-qp089jp0.js} +1 -1
  37. package/{index-fmgbwsr5.js → index-wrrb8rxk.js} +4 -4
  38. package/index.js +19 -19
  39. package/{library.command-pwfx8dx2.js → library.command-aa1g8nsa.js} +4 -4
  40. package/{localRegistry.command-r4zjx5py.js → localRegistry.command-kshva1ck.js} +8 -8
  41. package/{module.command-0t3ewata.js → module.command-b1zzgqde.js} +8 -8
  42. package/{package.command-7hmkxvpa.js → package.command-9qv6vr9s.js} +4 -4
  43. package/package.json +2 -2
  44. package/{page.command-st6r4s0q.js → page.command-k16pw244.js} +4 -4
  45. package/{primitive.command-1qkxpzsn.js → primitive.command-s60dn1ae.js} +9 -9
  46. package/{quality.command-hy5vt1bh.js → quality.command-p3vaze52.js} +456 -71
  47. package/{repair.command-nakkq2zp.js → repair.command-mfv749ha.js} +6 -6
  48. package/{scalar.command-fjq272gs.js → scalar.command-hs3nwzv1.js} +7 -7
  49. package/templates/lib/db.ts +3 -1
  50. package/templates/lib/useClient.ts +9 -3
  51. package/templates/workspaceRoot/.cursor/rules/akan-sync-conventions.mdc.template +3 -2
  52. package/templates/workspaceRoot/.cursor/rules/client-server-boundaries.mdc.template +1 -0
  53. package/templates/workspaceRoot/.cursor/rules/ssr-first.mdc.template +59 -0
  54. package/templates/workspaceRoot/AGENTS.md.template +161 -25
  55. package/templates/workspaceRoot/biome.json.template +22 -19
  56. package/templates/workspaceRoot/docs/AI-DEVELOPMENT.md.template +1 -4
  57. package/{workflow.command-jswbgk90.js → workflow.command-z0e0fk0z.js} +12 -12
  58. package/{workspace.command-h9wwcjpt.js → workspace.command-3q1d6kk4.js} +21 -21
  59. package/templates/libRoot/base/baseLogic.ts +0 -14
  60. package/templates/libRoot/base/index.ts +0 -8
@@ -1,16 +1,16 @@
1
1
  // @bun
2
2
  import {
3
3
  RepairRunner
4
- } from "./index-b978vs2e.js";
5
- import"./index-4yp06pn1.js";
6
- import"./index-4zgs8g1w.js";
4
+ } from "./index-6npsfpxr.js";
5
+ import"./index-jn9vfpwz.js";
6
+ import"./index-m4kpmmtj.js";
7
7
  import {
8
8
  Workspace,
9
9
  command,
10
10
  script
11
- } from "./index-jk9q6pse.js";
12
- import"./index-jtm86byd.js";
13
- import"./index-6pz1j0zj.js";
11
+ } from "./index-jkynkyfk.js";
12
+ import"./index-47qxw1tz.js";
13
+ import"./index-mxvakhsm.js";
14
14
  import"./index-xys926f2.js";
15
15
  import"./index-67546d0j.js";
16
16
  import"./index-r24hmh0q.js";
@@ -1,19 +1,19 @@
1
1
  // @bun
2
2
  import {
3
3
  ScalarScript
4
- } from "./index-fmgbwsr5.js";
4
+ } from "./index-wrrb8rxk.js";
5
5
  import"./index-ss469dec.js";
6
- import"./index-3pgtw35d.js";
6
+ import"./index-0cj2zxbm.js";
7
7
  import {
8
8
  renderPrimitiveReport
9
- } from "./index-4zgs8g1w.js";
10
- import"./index-xwgm94zr.js";
9
+ } from "./index-m4kpmmtj.js";
10
+ import"./index-qp089jp0.js";
11
11
  import {
12
12
  Sys,
13
13
  command
14
- } from "./index-jk9q6pse.js";
15
- import"./index-jtm86byd.js";
16
- import"./index-6pz1j0zj.js";
14
+ } from "./index-jkynkyfk.js";
15
+ import"./index-47qxw1tz.js";
16
+ import"./index-mxvakhsm.js";
17
17
  import"./index-67546d0j.js";
18
18
  import"./index-r24hmh0q.js";
19
19
 
@@ -16,7 +16,9 @@ ${databaseModules.map((module) => `import * as ${module}Db from "./${module}/${m
16
16
  ${libs.map((lib) => `export { db as ${lib} } from "@libs/${lib}/server";`).join("\n")}
17
17
 
18
18
  ${databaseModules.map((module) => `class ${capitalize(module)}Input extends by(cnst.${capitalize(module)}Input) {}`).join("\n")}
19
+ ${databaseModules.map((module) => `class ${capitalize(module)}Insight extends by(cnst.${capitalize(module)}Insight) {}`).join("\n")}
19
20
  ${databaseModules.length ? `export type { ${databaseModules.map((module) => `${capitalize(module)}Input`).join(", ")} };` : ""}
21
+ ${databaseModules.length ? `export type { ${databaseModules.map((module) => `${capitalize(module)}Insight`).join(", ")} };` : ""}
20
22
 
21
23
  ${scalarModules.map((module) => `export type * from "./__scalar/${module}/${module}.document";`).join("\n")}
22
24
  ${databaseModules.map((module) => `export type * from "./${module}/${module}.document";`).join("\n")}
@@ -24,7 +26,7 @@ ${databaseModules.map((module) => `export type * from "./${module}/${module}.doc
24
26
  ${databaseModules
25
27
  .map((module) => {
26
28
  const names = { Module: module.charAt(0).toUpperCase() + module.slice(1) };
27
- return `export const ${module} = DatabaseRegistry.buildModel("${module}" as const, ${names.Module}Input, ${module}Db.${names.Module}, ${module}Db.${names.Module}Model, cnst.${names.Module}, cnst.${names.Module}Insight, ${module}Db.${names.Module}Filter);`;
29
+ return `export const ${module} = DatabaseRegistry.buildModel("${module}" as const, ${names.Module}Input, ${module}Db.${names.Module}, ${module}Db.${names.Module}Model, cnst.${names.Module}, ${names.Module}Insight, ${module}Db.${names.Module}Filter);`;
28
30
  })
29
31
  .join("\n")}
30
32
  ${scalarModules.map((module) => `export const ${module} = DatabaseRegistry.buildScalar("${module}" as const, ${capitalize(module)});`).join("\n")}
@@ -1,16 +1,22 @@
1
1
  import type { AppInfo, LibInfo } from "akanjs";
2
2
 
3
3
  export default function getContent(scanInfo: AppInfo | LibInfo | null, dict: { [key: string]: string } = {}) {
4
+ const isApp = (scanInfo?.type ?? "lib") === "app";
4
5
  return `
5
6
  import { makePageProto, registerClientRuntime } from "akanjs/client";
6
7
  import { FetchClient } from "akanjs/fetch";
7
8
  import * as cnst from "./cnst";
8
- import { getAllDictionary } from "./dict" with { type: "macro" };
9
- import type * as dict from "./dict";
9
+ ${isApp ? `import { getAllDictionary } from "./dict" with { type: "macro" };\n` : ""}import type * as dict from "./dict";
10
10
  import { getSerializedSignal } from "./sig" with { type: "macro" };
11
11
  import type * as signal from "./sig";
12
12
 
13
- const dictionary = process.env.AKAN_PUBLIC_RENDER_ENV === "csr" ? getAllDictionary() : {};
13
+ ${
14
+ isApp
15
+ ? `const dictionary = process.env.AKAN_PUBLIC_RENDER_ENV === "csr" ? getAllDictionary() : {};`
16
+ : `// dict.ts is cumulative, so a lib dictionary is a subset of the mounting app's. Translator state is global,
17
+ // so the app's seed already resolves l() here — seeding again would ship the same payload a second time.
18
+ const dictionary = {};`
19
+ }
14
20
  const pageProto = makePageProto<typeof dict>(dictionary);
15
21
  const fetchProto = FetchClient.build<typeof signal>(cnst, getSerializedSignal(), { Err: pageProto.Err });
16
22
  export const runtime = registerClientRuntime({ ...pageProto, ...fetchProto }, { scope: ${JSON.stringify(scanInfo?.type ?? "lib")} });
@@ -6,8 +6,9 @@ alwaysApply: false
6
6
 
7
7
  # Akan Sync Conventions
8
8
 
9
- - `apps/<appName>` root may only contain these files: `akan.app.json`, `akan.config.ts`, `capacitor.config.ts`, `client.ts`, `main.ts`, `package.json`, `server.ts`, `tsconfig.json`.
10
- - `apps/<appName>` root may only contain these folders: `.akan`, `android`, `common`, `env`, `ios`, `lib`, `page`, `private`, `public`, `script`, `srvkit`, `ui`, `webkit`.
9
+ - `apps/<appName>` root may only contain these files: `AGENTS.md`, `CLAUDE.md`, `akan.app.json`, `akan.config.ts`, `capacitor.config.ts`, `client.ts`, `main.ts`, `package.json`, `server.ts`, `tsconfig.json`.
10
+ - `apps/<appName>` root may only contain these folders: `.akan`, `android`, `common`, `env`, `ios`, `lib`, `mobile`, `page`, `plugin`, `private`, `public`, `script`, `secrets`, `srvkit`, `ui`, `webkit`.
11
+ - `akan sync` maintains a scoped agent guide per app/lib (`apps/<app>/AGENTS.md` / `libs/<lib>/AGENTS.md`); the `akan:agent` block in it is generated, content outside the markers is hand-editable, and `akan lint` fails when the block is stale.
11
12
  - Do not add `apps/*/base`; place shared app utilities under `apps/*/common`.
12
13
  - `apps/*/lib` and `libs/*/lib` root files are limited to generated/support files: `cnst.ts`, `db.ts`, `dict.ts`, `option.ts`, `sig.ts`, `srv.ts`, `st.ts`, `useClient.ts`, `useServer.ts`.
13
14
  - Domain module folders are `lib/<model>` for database modules, `lib/_<service>` for service modules, and `lib/__scalar/<scalar>` for scalar modules.
@@ -15,3 +15,4 @@ alwaysApply: false
15
15
  - In domain UI the boundary is mechanical, not a judgment call: `Template`, `Zone`, and `Util` are always client components with `"use client"` on line 1; `Unit` and `View` are always server components and never carry the directive. `usePage()` is still legal in server files.
16
16
  - Preserve established domain file roles such as `.document.ts`, `.service.ts`, `.store.ts`, `.constant.ts`, and `.client.ts`.
17
17
  - When unsure, inspect nearby files in the same app or package before introducing a new boundary pattern.
18
+ - The boundary is only half the rule: how *little* ends up on the client is the other half. See `ssr-first.mdc`.
@@ -0,0 +1,59 @@
1
+ ---
2
+ description: SSR-first rendering rules — keep JSX on the server and justify every "use client"
3
+ globs: apps/**/*.tsx,libs/**/*.tsx
4
+ alwaysApply: false
5
+ ---
6
+
7
+ # SSR First — Server Rendering Is The Default
8
+
9
+ Akan is SSR-first. A JSX element rendered on the server ships as HTML and costs nothing to hydrate; an element
10
+ behind `"use client"` ships twice — as markup and as bundled JS that re-runs in the browser. The boundary question
11
+ is not which file *may* be client, it is **how little** ends up on the client side.
12
+
13
+ - **The default is server. `"use client"` is a cost you justify per component, not a habit.** A component earns the
14
+ directive only by using a client-only capability: a React hook, a JSX event handler, the store (`st.use.*` /
15
+ `st.do.*`), a browser global, or a client-only third-party package. Rendering markup, mapping over data, reading a
16
+ route param, and calling `l()` are server work — `usePage()` and `l()` never force a boundary.
17
+ - The file role decides *where* the boundary sits (`Template`/`Zone`/`Util` are client, `Unit`/`View` are server);
18
+ it does not decide how much markup sits behind it. A `Zone` that hoards markup is still an SSR regression.
19
+ - Measure with `akan quality ssr` (`--format json` for tooling). It reports the server render share per app and lib.
20
+ Treat **50% server share as the floor** and a falling share as a regression to justify or revert.
21
+
22
+ ## What `akan quality ssr` Flags
23
+
24
+ - `akan.ssr.unnecessary-use-client` — the directive is there but nothing in the file needs it. Delete it.
25
+ - `akan.ssr.client-static-component` — a component in a client file renders real markup with zero client-only
26
+ capability: pure server work sitting in the bundle.
27
+ - `akan.ssr.client-static-markup` — a large subtree wraps one or two interactive touches. Split it.
28
+ - `akan.ssr.client-mount-load` — a `useEffect(…, [])` loads server data the page could fetch first.
29
+ - `akan.ssr.module-missing-server-view` — a module renders only from `Template`/`Zone`/`Util`, with no `Unit`/`View`.
30
+ - `akan.ssr.template-client-state` — a `Template` holds form state in `useState` instead of the store.
31
+
32
+ A third-party client package and the `ui/<Folder>/index_.tsx` + `lazy()` boundary both justify the directive and are
33
+ not flagged. Interaction-driven `fetch.*` inside an `onClick` is not flagged either — only mount-time loads are.
34
+
35
+ ## Server-Side Implementation Playbook
36
+
37
+ 1. **Wrap the interaction, not the UI.** The smallest useful client component adds one behaviour and renders
38
+ `children` untouched, so the markup inside never reaches the bundle:
39
+ `export const ClickWrapper = ({ children, onPick }: ClickWrapperProps) => <div onClick={onPick}>{children}</div>;`
40
+ 2. **Split compound components so panels stay on the server.** A tab or accordion needs client state only for
41
+ *which* part is visible. `Tab` / `Tab.Menus` / `Tab.Menu` / `Tab.Panel` from `akanjs/ui` is the shape: only the
42
+ provider and menu hold state, and `<Tab.Panel>` renders children as-is, so a server `Unit`/`View` passed in stays
43
+ server-rendered. Never one client file with a mode `useState` and every panel body inlined.
44
+ 3. **Sync state instead of fetching it.** The page calls `fetch.initTaskInTodo()` / `fetch.viewTask(id)` and passes
45
+ the serializable result into a `Zone`; `Load.Units` / `Load.View` hydrate the store from it. Never a
46
+ `useEffect(…, [])` that fetches on mount.
47
+ 4. **Push the boundary down to the leaf that needs it.** A store-reading `Zone` holds zero markup and delegates to a
48
+ server `View`: `export const Self = () => <Task.View.General task={st.use.task()} />;`
49
+ 5. **Hand the promise across, not the awaited value.** `ClientInit` / `ClientView` are `PromiseOrObject<T>`, so a
50
+ page may pass an unawaited `fetch.initTaskInTodo()` and `Load.*` resolves it behind a skeleton.
51
+ 6. **Use named `ReactNode` slots, not just `children`.** `Layout.Navbar` takes `title`, `back`, `left`, `right`, and
52
+ `children`, so a client shell composes server content in five places.
53
+ 7. **Let the server do the derived work.** Display and predicate logic lives on `LightTask` (`isNew()`,
54
+ `canWrite(user?)`); enum→class lookups live in a module-scope `as const` map.
55
+ 8. **Gate auth on the server.** Check the session in `_layout.tsx` and redirect there, before any HTML is sent.
56
+ 9. **Prefer CSS over client state for pure visibility.** A `data-*` attribute plus `group-data-[…]` variants, or
57
+ `<details>`/`<summary>`, keeps both branches server-rendered.
58
+ 10. **Keep the heavy island out of the first load.** Put a large client-only widget behind the
59
+ `ui/<Folder>/index_.tsx` + `lazy()` pair.
@@ -74,11 +74,12 @@ Use the local module shape before adding a new abstraction.
74
74
  9. Keep page and layout files server-oriented: route-level `usePage`, headers, static layout, and `akanjs/ui` `Tab` composition belong there.
75
75
  10. Put interactive loading, submit/import actions, local form state, and `router.push` in client `Util`, `Template`, or `Zone` components.
76
76
  11. Prefer `Tab` for static mode selection instead of extra `useState`; render one focused client component inside each `Tab.Panel`.
77
- 12. Keep server-only logic out of client surfaces and client-only code out of server imports.
78
- 13. Treat `AKAN_PUBLIC_*` env vars as public. Never put secrets in them.
79
- 14. Add or update tests when behavior, contracts, or CLI output changes.
80
- 15. Update `*.abstract.md` when business invariants, workflows, or public behavior change.
81
- 16. Run the smallest relevant verification command after changes.
77
+ 12. Default to server rendering. Add `"use client"` only for a real client-only capability, and keep markup out of the component that carries it — see **SSR First** below.
78
+ 13. Keep server-only logic out of client surfaces and client-only code out of server imports.
79
+ 14. Treat `AKAN_PUBLIC_*` env vars as public. Never put secrets in them.
80
+ 15. Add or update tests when behavior, contracts, or CLI output changes.
81
+ 16. Update `*.abstract.md` when business invariants, workflows, or public behavior change.
82
+ 17. Run the smallest relevant verification command after changes. After touching any `.tsx`, that includes `akan quality ssr`.
82
83
 
83
84
  ## Common Commands
84
85
 
@@ -111,7 +112,11 @@ akan typecheck <%= appName %>
111
112
  # 3. Test — Run the test code (lib/*/*.signal.test.ts or others)
112
113
  akan test <%= appName %>
113
114
 
114
- # 4. Full production build bundles the app, runs all type/lint checks combined
115
+ # 4. SSR balanceonly after touching .tsx files. Reports the server render share
116
+ # per app/lib and flags client code that should render on the server.
117
+ akan quality ssr
118
+
119
+ # 5. Full production build — bundles the app, runs all type/lint checks combined
115
120
  akan build <%= appName %>
116
121
  ```
117
122
 
@@ -128,6 +133,8 @@ akan create-scalar <scalar-name> <%= appName %> # Add a scalar module (
128
133
  akan create-service <service-name> <%= appName %> # Add a service module (lib/_<service-name>/)
129
134
  akan test <%= appName %> # Run the test code (lib/*/*.signal.test.ts or others)
130
135
  akan lint <%= appName %> # Lint only (no typecheck)
136
+ akan quality scan # All code-quality warnings + SSR balance
137
+ akan quality ssr # SSR balance and client-boundary warnings only
131
138
  ```
132
139
 
133
140
  **CLI argument conventions.** Two argument styles, and mixing them up is a common mistake:
@@ -240,7 +247,7 @@ final fallback when no CLI command covers the change.
240
247
  | Add a reusable value type (e.g., Address, WorkHistory) | `lib/__scalar/<type>/` → constant, dictionary, abstract | `akan sync <name>` |
241
248
  | Create a new URL-visitable page | `page/` → `_index.tsx`, `_layout.tsx`, `[param]/_index.tsx` | Rebuild (akan start auto-detects) |
242
249
  | Change the app color theme / design tokens | `apps/<app>/page/styles.css` → override the semantic token values under `:root, [data-theme="dark"]` and `[data-theme="light"]` (`--primary`, `--background`, `--foreground`, …) | akan start hot-reloads |
243
- | Add a form or reusable UI component | `ui/` → PascalCase `.tsx` with `"use client"` if needed | `akan sync <name>` |
250
+ | Add a form or reusable UI component | `ui/` → PascalCase `.tsx`, **no** `"use client"` unless it uses a hook, event handler, store, or browser API | `akan sync <name>` |
244
251
  | Add a React hook or browser helper | `webkit/` → camelCase `.ts` with `"use client"` | `akan sync <name>` |
245
252
  | Add a server-only guard, middleware, or adaptor | `srvkit/` → PascalCase `.ts` | `akan sync <name>` |
246
253
  | Add a pure helper (no DOM, no server API) | `common/` → camelCase `.ts` | `akan sync <name>` |
@@ -253,15 +260,129 @@ final fallback when no CLI command covers the change.
253
260
  | Create a file without running sync | New files won't appear in barrel exports. Imports like `import * as cnst from "../cnst"` will fail. | Always run `akan sync <name>` after creating, renaming, or deleting any module file |
254
261
  | Use JS `#private` in `*.constant.ts`, `*.document.ts`, `*.service.ts`, or `*.store.ts` | `no-js-private-class-method.grit` bans `#private` in exactly those four file suffixes. The rule is scoped by file path, not class shape — `#private` stays the house style under `srvkit/`, including `adapt()` classes. | `private _methodName()` in those four files; `#methodName()` in `srvkit/` |
255
262
  | Use `console.log()` | Biome lint forbids `console.log`. Only `console.error`, `console.info`, `console.warn` are allowed. | Use one of the three allowed console methods, or `this.logger.*` / `new Logger("ClassName")` on the server |
263
+ | Write a `//!` marker in `ui/`, `webkit/`, `common/`, `page/**/*.tsx`, `*.constant.ts`, `*.store.ts`, or a module component file | `no-bang-comment-in-client.grit` bans it. Bun classifies `//!` and `/*!` as legal comments and keeps them through minification, so the note ships to every visitor. | `// FIXME:` in browser-reachable code; `//!` stays legal in server, `srvkit/`, and CLI files |
256
264
  | `throw new Error("...")` | `no-throw-raw-error.grit` bans raw errors outside tests, `*.constant.ts`, and `common/`. Raw errors carry no dictionary key, so they cannot be localized or toasted. | `throw new Err("task.error.<key>")` plus an `[en, ko]` entry in the module dictionary's `.error({})` |
257
- | Hand-order Tailwind classes, or reorder them to "fix" a diff | `useSortedClasses` is an error and also sorts the string arguments to `cn()`. Sorter output like `font-bold text-2xl` looks wrong but is correct. | Write classes in any order and let `akan lint` sort them |
258
- | A colour outside the semantic vocabulary — `bg-red-500`, `bg-[#3b82f6]`, `btn-primary`, `text-base-content`, `style={{ color: "#fff" }}` | The theme closes the vocabulary, so these produce **no CSS at all** — the element renders unstyled, and without the lint rules there is no error and no warning either. Raw-palette, arbitrary-colour, daisyUI-legacy and inline-colour rules all catch this. | Semantic tokens: `bg-primary`, `text-foreground/70`, `border-border`. A genuinely fixed colour takes a `// biome-ignore lint/plugin: <reason>` |
265
+ | Hand-order Tailwind classes, or reorder them to "fix" a diff | `useSortedClasses` is an error and also sorts the string arguments to `clsx()` and `cva()`. Sorter output like `font-bold text-2xl` looks wrong but is correct. | Write classes in any order and let `akan lint` sort them |
259
266
  | `import` a third-party package inside a page, a barrel, or a module file | `no-import-external-library.grit` covers `page/**`, all barrels, and every `*.{constant,dictionary,document,service,signal,store}.ts` and `*.{Template,Unit,Util,View,Zone}.tsx`. | Re-export the symbol from a one-line shim in `base/`, `webkit/`, or `ui/` first, then import that |
260
267
  | Import server APIs (`fs`, `Bun`, `process.env`) in `ui/`, `webkit/`, or `common/` | Server-only imports in client code cause build failures. | Keep server dependencies in `lib/`, `srvkit/`, or `private/` only |
261
268
  | Skip running `akan sync` after deleting a file | Deleted files remain referenced in barrel exports, causing import errors everywhere. | Run `akan sync <name>` after every file add, remove, or rename |
262
269
  | Use "use client" or `useState`/`useEffect` in pages/*.tsx, *.Unit.tsx, and *.View.tsx files | Server code cannot use React hooks. Wrap in a separate `"use client"` component. | Move hook logic to `webkit/` or a `"use client"` UI component |
263
270
  | Use `<a>` tag for internal navigation between pages | Akan.js uses `<Link>` from `akanjs/ui` for client-side navigation — avoids full page reloads. | `import { Link } from "akanjs/ui"` and use `<Link href="/task">...</Link>` |
264
271
  | Name a custom `Endpoint`/`Slice` like a generated CRUD op — `create<Model>`, `update<Model>`, `remove<Model>`, `view<Model>`, `edit<Model>`, `merge<Model>` | These names are already auto-generated. A collision can pass sync/typecheck/build and only fail at runtime. | Pick a distinct verb, e.g. `startTask`/`archiveTask`, never `createTask` for a custom endpoint |
272
+ | Add `"use client"` to a file that renders markup but uses no hook, event handler, store, or browser API | The directive is a cost, not a formality: everything behind it ships twice, as HTML and as JS that re-runs in the browser. | Delete the directive. `akan quality ssr` flags this as `akan.ssr.unnecessary-use-client` |
273
+ | Put a large static subtree inside a client component that only needs one `onClick` | The whole subtree lands in the bundle for the sake of one handler. | Keep the handler in a small client shell and pass the static markup in as `children`, or move it to a `Unit`/`View` |
274
+ | Load server data with `useEffect(() => { void st.do.initTaskInTodo(); }, [])` | The page renders an empty shell, hydrates, then round-trips for data the server already had. | `await fetch.initTaskInTodo()` in the page and pass `init` to the `Zone` |
275
+
276
+ ## SSR First — Server Rendering Is The Default
277
+
278
+ Akan is SSR-first. Every JSX element that renders on the server ships as HTML and costs nothing to hydrate; every
279
+ element behind `"use client"` ships twice — as markup and as bundled JS that must re-run in the browser. The
280
+ boundary question is not which file *may* be client, it is **how little** ends up on the client side.
281
+
282
+ **The default is server. `"use client"` is a cost you justify per component, not a habit.** A component earns the
283
+ directive only by using a client-only capability: a React hook, a JSX event handler, the store (`st.use.*` /
284
+ `st.do.*`), a browser global, or a client-only third-party package. Rendering markup, mapping over data, reading a
285
+ route param, and calling `l()` are all server work — `usePage()` and `l()` are legal in server components and never
286
+ force a boundary.
287
+
288
+ The file role decides *where* the boundary sits (`Template`/`Zone`/`Util` are client, `Unit`/`View` are server); it
289
+ does not decide how much markup sits behind it. A `Zone` that hoards markup is still an SSR regression.
290
+
291
+ Measure with `akan quality ssr` (`--format json` for tooling). It reports the server render share per app and lib —
292
+ server-rendered JSX elements over total — plus the warnings below. Treat **50% server share as the floor** and a
293
+ falling share as a regression to justify or revert.
294
+
295
+ | Rule | Means |
296
+ |---|---|
297
+ | `akan.ssr.unnecessary-use-client` | The directive is there but nothing in the file needs it. Delete it. |
298
+ | `akan.ssr.client-static-component` | A component in a client file renders real markup with zero client-only capability — pure server work sitting in the bundle. |
299
+ | `akan.ssr.client-static-markup` | A large subtree wraps one or two interactive touches. Split it: interaction stays client, markup goes server. |
300
+ | `akan.ssr.client-mount-load` | A `useEffect(…, [])` loads server data. The page can fetch it before the first byte. |
301
+ | `akan.ssr.module-missing-server-view` | A module renders only from `Template`/`Zone`/`Util` and has no `Unit`/`View` at all. |
302
+ | `akan.ssr.template-client-state` | A `Template` holds form state in `useState` instead of the store. |
303
+
304
+ A third-party client package and the `ui/<Folder>/index_.tsx` + `lazy()` boundary both justify the directive and are
305
+ not flagged. Interaction-driven `fetch.*` inside an `onClick` is not flagged either — only mount-time loads are,
306
+ because those are the ones the server could have performed.
307
+
308
+ ### Server-Side Implementation Playbook
309
+
310
+ **① Wrap the interaction, not the UI.** The smallest useful client component adds one behaviour and renders
311
+ `children` untouched, so the markup inside never reaches the bundle.
312
+
313
+ ```tsx
314
+ // apps/<%= appName %>/ui/ClickWrapper.tsx
315
+ "use client";
316
+ export const ClickWrapper = ({ children, onPick }: ClickWrapperProps) => <div onClick={onPick}>{children}</div>;
317
+
318
+ // in a server page — Task.Unit.Card stays server-rendered
319
+ <ClickWrapper onPick={…}>
320
+ <Task.Unit.Card task={task} />
321
+ </ClickWrapper>
322
+ ```
323
+
324
+ **② Split compound components so panels stay on the server.** A tab, accordion, or disclosure needs client state
325
+ only for *which* part is visible — never for what the parts contain. `Tab` / `Tab.Menus` / `Tab.Menu` / `Tab.Panel`
326
+ from `akanjs/ui` is the reference shape: only the provider and menu hold state, and `<Tab.Panel>` renders its
327
+ children as-is, so a server `Unit`/`View` passed in stays server-rendered.
328
+
329
+ ```tsx
330
+ <Tab defaultMenu="detail">
331
+ <Tab.Menus>
332
+ <Tab.Menu menu="detail">{l("task.detail")}</Tab.Menu>
333
+ <Tab.Menu menu="history">{l("task.history")}</Tab.Menu>
334
+ </Tab.Menus>
335
+ <Tab.Panel menu="detail">
336
+ <Task.View.General task={task} />
337
+ </Tab.Panel>
338
+ </Tab>
339
+ ```
340
+
341
+ Never collapse this into one `"use client"` file with a mode `useState` and every panel body inlined.
342
+
343
+ **③ Sync state instead of fetching it.** A server component cannot hold state, so render the initial data on the
344
+ server and hand it across the boundary as a serializable object. That is what `init` / `view` props are: the page
345
+ calls `fetch.initTaskInTodo()` / `fetch.viewTask(id)`, passes the result into a `Zone`, and `Load.Units` /
346
+ `Load.View` hydrate the store from it.
347
+
348
+ ```tsx
349
+ export default async function Page() {
350
+ const [{ taskInitInTodo }] = await Promise.all([fetch.initTaskInTodo()]);
351
+ return <Task.Zone.Card init={taskInitInTodo} sliceName="taskInTodo" />;
352
+ }
353
+ ```
354
+
355
+ **④ Push the boundary down to the leaf that needs it.** When a `Zone` reads the store, it should hold *zero* markup
356
+ and delegate to a server `View`, so the whole detail surface renders server-side wherever a page uses the `View`
357
+ directly.
358
+
359
+ ```tsx
360
+ "use client";
361
+ export const Self = () => <Task.View.General task={st.use.task()} />;
362
+ ```
363
+
364
+ **⑤ Hand the promise across, not the awaited value.** `ClientInit` / `ClientView` are `PromiseOrObject<T>`, so a
365
+ page may pass an unawaited `fetch.initTaskInTodo()` and `Load.*` resolves it behind a skeleton. `await` blocks the
366
+ shell for data the page needs immediately; passing the promise streams the rest. Independent fetches still go
367
+ through one `Promise.all`.
368
+
369
+ **⑥ Use named `ReactNode` slots, not just `children`.** A client shell can take several server-rendered subtrees:
370
+ `Layout.Navbar` accepts `title`, `back`, `left`, `right`, and `children`, so it composes server content in five
371
+ places instead of absorbing it.
372
+
373
+ **⑦ Let the server do the derived work.** Display and predicate logic belongs on `LightTask` (`isNew()`,
374
+ `canWrite(user?)`, `formatTimes()`), and enum→class lookups belong in a module-scope `as const` map. Both sides call
375
+ the same method, so a client component that exists only to compute a label is markup in the wrong place.
376
+
377
+ **⑧ Gate auth on the server.** Check the session in `_layout.tsx` and redirect there, before any HTML is sent. A
378
+ client-side auth check costs a hydration round-trip and flashes the wrong UI first.
379
+
380
+ **⑨ Prefer CSS over client state for pure visibility.** A `data-*` attribute plus `group-data-[…]` variants, or
381
+ `<details>`/`<summary>`, keeps both branches server-rendered. Reach for `useState` when the state is real, not when
382
+ a Tailwind variant would do.
383
+
384
+ **⑩ Keep the heavy island out of the first load.** A large client-only widget goes behind the
385
+ `ui/<Folder>/index_.tsx` + `lazy()` pair so the server renders the page around it.
265
386
 
266
387
  ## Code Style
267
388
 
@@ -300,14 +421,11 @@ is convention that keeps hand-written code reading like generated code.
300
421
  `.Template.tsx` files contain zero `useState`: forms are store-driven with `Field.*`, `value={taskForm.x}`, and
301
422
  `onChange={st.do.setXOnTask}` passed by reference.
302
423
  - Read with `st.use.*` and write with `st.do.*`. Client components do not call `fetch.*`.
303
- - Reach for a recipe before writing a look by hand: `buttonRecipe`, `badgeRecipe` and `inputRecipe` from
304
- `akanjs/ui` carry the button, badge and field surfaces. Call them as `buttonRecipe(variants?, className?)` —
305
- the second argument merges internally and takes an array, so never wrap it in `cn()`.
306
- - Static class strings stay plain strings. Reach for `cn` only for a conditional or to merge an incoming
307
- `className`, and merge the caller last: `cn("base", conditional, className)`. `cn` comes from `akanjs/client`
308
- and is the only class-combining function — no `clsx`, no raw `twMerge`.
309
- - Use semantic tokens with opacity modifiers (`text-foreground/60`, `bg-background/70`, `border-border`). Never
310
- `dark:` — theming is the token block in `page/*/styles.css`, where each token has a `-foreground` pair.
424
+ - Static class strings stay plain strings. Use `clsx` only for a conditional or to merge an incoming `className`,
425
+ and merge the caller last: `clsx("base", conditional, className)`. `clsx` comes from `akanjs/client`. No
426
+ `twMerge`, no `cn()`.
427
+ - Use daisyUI semantic tokens with opacity modifiers (`text-base-content/60`, `bg-base-100/70`). Never `dark:`
428
+ theming is the daisyUI theme block in `page/*/styles.css`.
311
429
  - Hoist enum→class lookups to a module-scope `as const` map typed `{ [key in cnst.TaskStatus["value"]]: string }`,
312
430
  not `Record<...>`.
313
431
 
@@ -367,6 +485,9 @@ Do not narrate code. Do document the thing the code cannot say. Both halves are
367
485
  - Markers: `TODO` unfinished work · `FIXME` known broken behavior · `XXX` hazard a reader must not miss · `//!`
368
486
  disabled or must-fix code · `//?` an explanatory aside · `//*` a design note · deletion caution, warning why
369
487
  removing a line would break something non-obvious.
488
+ - `//!` is for server, `srvkit/`, and CLI files only. Bun's bundler treats `//!` and `/*!` as legal comments and
489
+ keeps them through minification, so in browser-reachable code the note ships verbatim to every visitor. Use
490
+ `// FIXME:` there — `no-bang-comment-in-client.grit` enforces it.
370
491
  - Keep allowed comments to one short line, and give every suppression a reason:
371
492
  `// biome-ignore lint/<rule>: <why>`. Never a bare disable block.
372
493
  - Match nearby file style: if the surrounding code has few comments, keep it that way.
@@ -533,7 +654,7 @@ export class TaskService extends serve(db.task, ({ plug }) => ({
533
654
  For a custom adapter class (not a predefined role), pass the class itself, e.g. `ipfsApi: plug(IpfsApi)`
534
655
  (see `libs/shared/lib/file/file.service.ts`). Injecting a file/image field is usually simpler than calling
535
656
  storage directly: declare `image: field(File).optional()` (or `images: field([File])`) on the model and let the
536
- store's generated `upload<Field>On<Model>(fileList)` action handle the upload. Add `{ cascade: "remove" }` to that
657
+ store's generated `upload<Field>On<Model>(fileList)` action handle the upload. Add `{ cascade: "removeRef" }` to that
537
658
  field when the file belongs to the model alone, and removing the model removes the file and its stored object.
538
659
 
539
660
  ---
@@ -751,12 +872,23 @@ A short list of things the type system does not always catch:
751
872
  `secret` / `hidden` / `resolve()` fields with `text` throw at class-build time — the mirror is plaintext. Search
752
873
  runs on sqlite/libsql only; `q.search()` against Postgres throws. `thumb` is mirrored for rendering and is not
753
874
  indexed.
754
- - **`cascade: "remove"` takes a relation's target down with its owner.** Declare it on the relation itself
755
- `image: field(File, { cascade: "remove" })`, arrays included. The removal runs through the **target's service**,
756
- so the target's own `_postRemove` runs too; that is how removing a model also deletes the file's stored object.
757
- Only a relation accepts it: a `String`, an `ID`, or a scalar throws while the class is being built. Nothing
758
- checks for other references to the same target, so declaring it asserts exclusive ownership. Document removal is
759
- soft but the storage delete is not, and query-level removal fires no hooks and therefore no cascade.
875
+ - **`cascade` names a direction, and the wrong one is a data loss.** Both actions can sit on the same field shape,
876
+ so the value has to say which end goes away. `cascade: "removeRef"` on the relation an owner holds
877
+ (`image: field(File, { cascade: "removeRef" })`, arrays included) removes the target when the owner is removed;
878
+ only a relation accepts it. `cascade: "removeWith"` on a child's own reference to its owner
879
+ (`field(ID, { ref: "agentSession", cascade: "removeWith" })`, or a relation, or `refPath` for a polymorphic
880
+ owner whose type field must be an `enumOf`) removes the child when the owner is the owner never learns its
881
+ children exist. The removal runs through the **target's service** so its `_postRemove` runs too, unless the
882
+ target provably has no removal side effect, in which case the boot-time plan collapses it into one query. A
883
+ `removeWith` field gets its index automatically. Nothing checks for other references to the same target, so
884
+ `removeRef` asserts exclusive ownership. Removal is soft but a storage delete is not, and a query-level removal
885
+ fires no hooks and therefore no cascade.
886
+ - **Removal is always soft, and `delete` is reserved.** `remove(id)`, the facade's `removeMany(query)`, and the
887
+ store's `removeManyByQuery` all stamp `removedAt`; the framework has no hard delete for a model table.
888
+ - **The model facade spells out `Many`/`One` on its writes** — `updateOne`, `updateMany`, `removeOne`, `removeMany`
889
+ — because a bare `update`/`remove` would read like the document-path `update(id)` / `doc.remove()` while hitting
890
+ every match. Reads keep the short `find`/`findOne` pair, and counting is `count(query)` (`countDocuments` is
891
+ `@deprecated`).
760
892
  - **`q.search()` is a filter node, not a slice requirement.** Prefer
761
893
  `bySearch: filter().arg("text", String).query((text, q) => q.search(text, { prefix: true }))` — the generated
762
894
  `listBySearch` / `countBySearch` / `queryBySearch` / `insightBySearch` come for free. Only add a search slice when
@@ -834,8 +966,12 @@ akan sync automatically generates APIs across all layers. Only write custom logi
834
966
  | `pick[Query](args)`, `pickId[Query](args)` | Find one (throw if not found) |
835
967
  | `exists[Query](args)`, `count[Query](args)` | Existence check and count |
836
968
  | `insight[Query](args)`, `query[Query](args)` | Insight and raw query |
969
+ | `remove[Query](args)`, `removeOne[Query](args)` | Query-level soft remove — all matches, or the newest one (`createdAt` desc, not caller-chosen) |
970
+ | `update[Query](args).set(patch)`, `updateOne[Query](args).set(patch)` | Query-level update — the patch lands on a terminal `.set()`, because a filter's trailing args may be optional |
971
+
972
+ **Rule**: Define `Filter` with `.query()` conditions in `document.ts`. akan sync auto-generates all 14 query helper methods per filter. Write `Document` chain methods only for state transitions with validation.
837
973
 
838
- **Rule**: Define `Filter` with `.query()` conditions in `document.ts`. akan sync auto-generates all 10 query helper methods per filter. Write `Document` chain methods only for state transitions with validation.
974
+ **The four query-level writes fire no hooks**, so no `_pre`/`_postRemove` and no cascade run — same as `updateManyByQuery`. Reach for them when the model carries no removal side effect; otherwise remove documents one at a time. A filter keyed after its own model (filter `chat` on model `chat`) is rejected at boot, because `removeChat`/`updateChat` would otherwise shadow the generated single-document CRUD.
839
975
 
840
976
  ## Generated Context
841
977
 
@@ -166,6 +166,28 @@
166
166
  "includes": ["**/*.signal.ts"],
167
167
  "plugins": ["./node_modules/@akanjs/devkit/lint/no-redeclare-predefined-endpoint.grit"]
168
168
  },
169
+ {
170
+ "includes": [
171
+ "**/ui/**/*.ts",
172
+ "**/ui/**/*.tsx",
173
+ "**/webkit/**/*.ts",
174
+ "**/webkit/**/*.tsx",
175
+ "**/common/**/*.ts",
176
+ "**/page/**/*.tsx",
177
+ "**/*.constant.ts",
178
+ "**/*.store.ts",
179
+ "**/*.Template.tsx",
180
+ "**/*.Unit.tsx",
181
+ "**/*.Util.tsx",
182
+ "**/*.View.tsx",
183
+ "**/*.Zone.tsx",
184
+ "!**/*.test.ts",
185
+ "!**/*.test.tsx",
186
+ "!**/*.spec.ts",
187
+ "!**/*.spec.tsx"
188
+ ],
189
+ "plugins": ["./node_modules/@akanjs/devkit/lint/no-bang-comment-in-client.grit"]
190
+ },
169
191
  {
170
192
  "includes": [
171
193
  "**/*.constant.ts",
@@ -210,25 +232,6 @@
210
232
  "**/*.Zone.tsx"
211
233
  ],
212
234
  "plugins": ["./node_modules/@akanjs/devkit/lint/no-import-external-library.grit"]
213
- },
214
- {
215
- "includes": [
216
- "apps/**/*.ts",
217
- "apps/**/*.tsx",
218
- "libs/**/*.ts",
219
- "libs/**/*.tsx",
220
- "!**/*.test.ts",
221
- "!**/*.test.tsx",
222
- "!**/*.spec.ts",
223
- "!**/*.spec.tsx"
224
- ],
225
- "plugins": [
226
- "./node_modules/@akanjs/devkit/lint/no-raw-palette-class.grit",
227
- "./node_modules/@akanjs/devkit/lint/no-arbitrary-color.grit",
228
- "./node_modules/@akanjs/devkit/lint/no-daisyui-legacy-class.grit",
229
- "./node_modules/@akanjs/devkit/lint/no-inline-color.grit",
230
- "./node_modules/@akanjs/devkit/lint/no-interpolated-arbitrary-class.grit"
231
- ]
232
235
  }
233
236
  ]
234
237
  }
@@ -49,11 +49,8 @@ See `docs/GENERATED.md` for the generated file list.
49
49
 
50
50
  `AGENTS.md` holds the full style guide. The rules agents break most often:
51
51
 
52
- - **Never hand-order Tailwind classes** — the linter sorts them, including inside `cn()`, and its output looks
52
+ - **Never hand-order Tailwind classes** — the linter sorts them, including inside `clsx()`, and its output looks
53
53
  unnatural on purpose.
54
- - **Never use a colour outside the semantic vocabulary** — `bg-red-500`, `bg-[#3b82f6]` and `text-base-content`
55
- compile to no CSS at all, so the element renders unstyled with no error. Use `bg-primary`, `text-foreground/70`
56
- and the other tokens defined in `page/*/styles.css`.
57
54
  - **Never `throw new Error`** — throw `new Err("<module>.error.<key>")` with an `[en, ko]` entry in the module
58
55
  dictionary. `common/` cannot import `Err`, so keep throwing code out of it.
59
56
  - **Never import a third-party package** from a page, a barrel, or a module file. Re-export it through a one-line
@@ -1,31 +1,31 @@
1
1
  // @bun
2
2
  import {
3
3
  WorkflowRunner
4
- } from "./index-csqk9z5j.js";
4
+ } from "./index-c94nq3c1.js";
5
5
  import {
6
6
  PrimitiveScript
7
- } from "./index-r4w8cry5.js";
7
+ } from "./index-pfrt7qwh.js";
8
8
  import {
9
9
  ModuleScript
10
- } from "./index-vhv3xnjz.js";
11
- import"./index-hjzr8ja1.js";
10
+ } from "./index-60a3jfcz.js";
11
+ import"./index-hrwzz2wf.js";
12
12
  import {
13
13
  ScalarScript
14
- } from "./index-fmgbwsr5.js";
14
+ } from "./index-wrrb8rxk.js";
15
15
  import"./index-ss469dec.js";
16
- import"./index-3pgtw35d.js";
17
- import"./index-4yp06pn1.js";
16
+ import"./index-0cj2zxbm.js";
17
+ import"./index-jn9vfpwz.js";
18
18
  import {
19
19
  createWorkflowStepRegistry
20
- } from "./index-4zgs8g1w.js";
21
- import"./index-xwgm94zr.js";
20
+ } from "./index-m4kpmmtj.js";
21
+ import"./index-qp089jp0.js";
22
22
  import {
23
23
  Workspace,
24
24
  command,
25
25
  script
26
- } from "./index-jk9q6pse.js";
27
- import"./index-jtm86byd.js";
28
- import"./index-6pz1j0zj.js";
26
+ } from "./index-jkynkyfk.js";
27
+ import"./index-47qxw1tz.js";
28
+ import"./index-mxvakhsm.js";
29
29
  import"./index-xys926f2.js";
30
30
  import"./index-67546d0j.js";
31
31
  import"./index-r24hmh0q.js";