@akanjs/cli 3.0.0-alpha.3 → 3.0.0-alpha.4
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.
- package/.build-stamp +1 -1
- package/{abstractCompactor-e5yq60qz.js → abstractCompactor-rk6twzvj.js} +2 -2
- package/{agent.command-yv00p0s0.js → agent.command-jfz8yfwy.js} +7 -7
- package/{application.command-0qsczf4k.js → application.command-mxyqtd6p.js} +5 -5
- package/{applicationBuildRunner-ct2pxyvw.js → applicationBuildRunner-cwk52sb7.js} +2 -2
- package/{applicationReleasePackager-gg8ccbeh.js → applicationReleasePackager-yrrhbkv3.js} +1 -1
- package/buildBatch.proc.js +3 -3
- package/{capacitorApp-4r9sm3qg.js → capacitorApp-j357ak1g.js} +5 -3
- package/{cloud.command-dxfv18sa.js → cloud.command-f87dwe52.js} +9 -9
- package/{context.command-8d9e3k6b.js → context.command-z5bf8bn7.js} +15 -15
- package/{guideline.command-3jbkxzh6.js → guideline.command-1m1ctar3.js} +5 -5
- package/incrementalBuilder.proc.js +2 -2
- package/{index-1pvex4az.js → index-1s71fwrq.js} +11 -11
- package/{index-0cj2zxbm.js → index-3pgtw35d.js} +1 -1
- package/{index-a00jg8x8.js → index-4yp06pn1.js} +2 -2
- package/{index-rzwcpcc3.js → index-4zgs8g1w.js} +1 -1
- package/{index-mxvakhsm.js → index-6pz1j0zj.js} +2 -6
- package/{index-mr5s7mqd.js → index-b978vs2e.js} +3 -3
- package/{index-pyt2b4nw.js → index-cap2k2ch.js} +2 -2
- package/{index-7c6k4yvg.js → index-cn24dcqn.js} +2 -2
- package/{index-2q1f5j9k.js → index-csqk9z5j.js} +3 -3
- package/{index-k95xkh4p.js → index-e3qskyt2.js} +2 -2
- package/{index-ec09pws3.js → index-fmgbwsr5.js} +4 -4
- package/{index-bbkek1bp.js → index-hjzr8ja1.js} +1 -1
- package/{index-8hsbnyes.js → index-jk9q6pse.js} +1 -1
- package/{index-hgna5rjy.js → index-jtm86byd.js} +1 -1
- package/{index-ej426mcr.js → index-n0z3f2xg.js} +4 -4
- package/{index-bekddz9q.js → index-r4w8cry5.js} +4 -4
- package/{index-e16gnn26.js → index-tq1y56tp.js} +12 -35
- package/{index-yzmhasdb.js → index-vhv3xnjz.js} +6 -6
- package/{index-zasydjxd.js → index-xj8bks3p.js} +4 -4
- package/{index-tdbas9r0.js → index-xwgm94zr.js} +1 -1
- package/{index-t3723f99.js → index-y0k42k04.js} +86 -17
- package/{index-nm6wghb6.js → index-ybybkec0.js} +6 -6
- package/index.js +19 -19
- package/{library.command-ebdj1vnm.js → library.command-pwfx8dx2.js} +4 -4
- package/{localRegistry.command-gb178ne8.js → localRegistry.command-r4zjx5py.js} +8 -8
- package/{module.command-9c1bnsx4.js → module.command-0t3ewata.js} +8 -8
- package/{package.command-t93p4jkj.js → package.command-7hmkxvpa.js} +4 -4
- package/package.json +2 -2
- package/{page.command-k3k0meh2.js → page.command-st6r4s0q.js} +4 -4
- package/{primitive.command-de6nktdt.js → primitive.command-1qkxpzsn.js} +9 -9
- package/{quality.command-z5kth2wa.js → quality.command-hy5vt1bh.js} +48 -451
- package/{repair.command-ehf2g112.js → repair.command-nakkq2zp.js} +6 -6
- package/{scalar.command-7a2jtv33.js → scalar.command-fjq272gs.js} +7 -7
- package/templates/lib/db.ts +1 -3
- package/templates/libRoot/base/baseLogic.ts +14 -0
- package/templates/libRoot/base/index.ts +8 -0
- package/templates/workspaceRoot/.cursor/rules/client-server-boundaries.mdc.template +0 -1
- package/templates/workspaceRoot/AGENTS.md.template +25 -157
- package/templates/workspaceRoot/biome.json.template +19 -0
- package/templates/workspaceRoot/docs/AI-DEVELOPMENT.md.template +4 -1
- package/{workflow.command-e0tt0vk2.js → workflow.command-jswbgk90.js} +12 -12
- package/{workspace.command-fpda0evj.js → workspace.command-h9wwcjpt.js} +21 -21
- package/guidelines/ssrRule/ssrRule.generate.json +0 -31
- package/guidelines/ssrRule/ssrRule.instruction.md +0 -108
- package/templates/workspaceRoot/.cursor/rules/ssr-first.mdc.template +0 -59
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
# Akan SSR Rule Guideline
|
|
2
|
-
|
|
3
|
-
## Purpose
|
|
4
|
-
Use this when writing or reviewing any `.tsx` file. Akan is SSR-first: an element rendered on the server ships as
|
|
5
|
-
HTML and costs nothing to hydrate, while an element behind `"use client"` ships twice — as markup and as bundled JS
|
|
6
|
-
that re-runs in the browser. The boundary question is never "may this file be client", it is **how little ends up
|
|
7
|
-
on the client side**.
|
|
8
|
-
|
|
9
|
-
## When A Client Boundary Is Earned
|
|
10
|
-
- A component earns `"use client"` only by using a client-only capability: a React hook, a JSX event handler, the
|
|
11
|
-
store (`st.use.*` / `st.do.*`), a browser global (`window`, `document`, `navigator`, `localStorage`, …), or a
|
|
12
|
-
client-only third-party package.
|
|
13
|
-
- Rendering markup, mapping over data, reading a route param, and calling `l()` are server work. `usePage()` and
|
|
14
|
-
`getSelf()` are legal in server components and never force a boundary.
|
|
15
|
-
- In domain UI the file role fixes the directive: `Template`, `Zone`, and `Util` are client; `Unit` and `View` are
|
|
16
|
-
server. That decides *where* the boundary sits, not how much markup sits behind it — a `Zone` that hoards markup
|
|
17
|
-
is still an SSR regression.
|
|
18
|
-
- Measure with `akan quality ssr` (`--format json` for tooling). It reports the server render share per app and
|
|
19
|
-
lib as server-rendered JSX elements over total. Treat **50% server share as the floor** and a falling share as a
|
|
20
|
-
regression to justify or revert.
|
|
21
|
-
|
|
22
|
-
## Quality Rules
|
|
23
|
-
- `akan.ssr.unnecessary-use-client` — the directive is present but nothing in the file needs it. Delete it. If the
|
|
24
|
-
file exists only to wrap one client child, drop the wrapper and use the child directly.
|
|
25
|
-
- `akan.ssr.client-static-component` — a component inside a client file renders real markup with zero client-only
|
|
26
|
-
capability. Move it to a server file: a `<Model>.Unit.tsx` / `<Model>.View.tsx` for a module, or a `ui/` file with
|
|
27
|
-
no directive.
|
|
28
|
-
- `akan.ssr.client-static-markup` — a large subtree wraps one or two interactive touches. Keep the interactive
|
|
29
|
-
element in the client component and hoist the static subtree into a server component received as `children`.
|
|
30
|
-
- `akan.ssr.client-mount-load` — a `useEffect(…, [])` loads server data. Fetch it in the route and pass the
|
|
31
|
-
init/view object down.
|
|
32
|
-
- `akan.ssr.module-missing-server-view` — a module renders only from `Template`/`Zone`/`Util` and declares no
|
|
33
|
-
`Unit`/`View`. Add them and have the `Zone` delegate.
|
|
34
|
-
- `akan.ssr.template-client-state` — a `Template` holds form state in `useState`. Bind to the store instead:
|
|
35
|
-
`value={xForm.field}` with `onChange={st.do.setFieldOnX}`.
|
|
36
|
-
|
|
37
|
-
A third-party client package and the `ui/<Folder>/index_.tsx` + `lazy()` boundary both justify the directive and are
|
|
38
|
-
not flagged. Interaction-driven `fetch.*` inside an `onClick` is not flagged either — only mount-time loads are,
|
|
39
|
-
because those are the ones the server could have performed.
|
|
40
|
-
|
|
41
|
-
## Implementation Playbook
|
|
42
|
-
|
|
43
|
-
**① Wrap the interaction, not the UI.** The smallest useful client component adds one behaviour and renders
|
|
44
|
-
`children` untouched, so the markup inside never reaches the bundle.
|
|
45
|
-
|
|
46
|
-
```tsx
|
|
47
|
-
"use client";
|
|
48
|
-
export const ClickWrapper = ({ children, onPick }: ClickWrapperProps) => <div onClick={onPick}>{children}</div>;
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
`libs/shared/ui/Only/User.tsx` is the same shape: it reads auth state on the client and returns `{children}`.
|
|
52
|
-
|
|
53
|
-
**② Split compound components so panels stay on the server.** A tab, accordion, or disclosure needs client state
|
|
54
|
-
only for *which* part is visible, never for what the parts contain. `Tab` / `Tab.Menus` / `Tab.Menu` / `Tab.Panel`
|
|
55
|
-
in `akanjs/ui` is the reference: only the provider and menu hold state, and `<Tab.Panel>` renders its children
|
|
56
|
-
as-is, so a server `Unit`/`View` passed in stays server-rendered.
|
|
57
|
-
|
|
58
|
-
```tsx
|
|
59
|
-
<Tab defaultMenu="detail">
|
|
60
|
-
<Tab.Menus>
|
|
61
|
-
<Tab.Menu menu="detail">{l("post.detail")}</Tab.Menu>
|
|
62
|
-
<Tab.Menu menu="history">{l("post.history")}</Tab.Menu>
|
|
63
|
-
</Tab.Menus>
|
|
64
|
-
<Tab.Panel menu="detail">
|
|
65
|
-
<Post.View.General post={post} />
|
|
66
|
-
</Tab.Panel>
|
|
67
|
-
</Tab>
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
Never collapse this into one client file with a mode `useState` and every panel body inlined.
|
|
71
|
-
|
|
72
|
-
**③ Sync state instead of fetching it.** A server component cannot hold state, so render the initial data on the
|
|
73
|
-
server and hand it across as a serializable object. The route calls `fetch.initXInY(...)` / `fetch.viewX(...)` and
|
|
74
|
-
passes the result into a `Zone`; `Load.Units` / `Load.View` hydrate the store from it. A `useEffect(…, [])` that
|
|
75
|
-
fetches on mount renders an empty shell, hydrates, then round-trips for data the server already had.
|
|
76
|
-
|
|
77
|
-
**④ Push the boundary down to the leaf that needs it.** A store-reading `Zone` should hold zero markup and delegate
|
|
78
|
-
to a server `View` — `User.Zone.Self` is one line, `st.use.self()` into `<User.View.General user={self} />`, so the
|
|
79
|
-
whole detail surface renders server-side wherever a route uses the `View` directly.
|
|
80
|
-
|
|
81
|
-
**⑤ Hand the promise across, not the awaited value.** `ClientInit` / `ClientView` are `PromiseOrObject<T>`, so a
|
|
82
|
-
route may pass an unawaited `fetch.initX(...)` and `Load.*` resolves it behind a skeleton. `await` blocks the shell
|
|
83
|
-
for data the page needs immediately; the promise streams the rest. Independent fetches still go through one
|
|
84
|
-
`Promise.all`.
|
|
85
|
-
|
|
86
|
-
**⑥ Use named `ReactNode` slots, not just `children`.** `Layout.Navbar` accepts `title`, `back`, `left`, `right`,
|
|
87
|
-
and `children`, so a client shell composes server-rendered content in five places instead of absorbing it.
|
|
88
|
-
|
|
89
|
-
**⑦ Let the server do the derived work.** Display and predicate logic belongs on `Light<Model>` (`isNew()`,
|
|
90
|
-
`canWrite(user?)`, `formatTimes()`), and enum→class lookups belong in a module-scope `as const` map. Both sides call
|
|
91
|
-
the same method, so a client component that exists only to compute a label is markup in the wrong place.
|
|
92
|
-
|
|
93
|
-
**⑧ Gate auth on the server.** `getSelf({ unauthorize: "/signin" })` in `_layout.tsx` redirects before any HTML is
|
|
94
|
-
sent. A client-side check costs a hydration round-trip and flashes the wrong UI first.
|
|
95
|
-
|
|
96
|
-
**⑨ Prefer CSS over client state for pure visibility.** A `data-*` attribute plus `group-data-[…]` variants (see
|
|
97
|
-
`libs/util/ui/Grid/*`) or `<details>`/`<summary>` keeps both branches server-rendered. Reach for `useState` when the
|
|
98
|
-
state is real, not when a Tailwind variant would do.
|
|
99
|
-
|
|
100
|
-
**⑩ Keep the heavy island out of the first load.** A large client-only widget goes behind the
|
|
101
|
-
`ui/<Folder>/index_.tsx` + `lazy()` pair so the server renders the page around it.
|
|
102
|
-
|
|
103
|
-
## Review Checklist
|
|
104
|
-
- Does every `"use client"` in the diff name a capability that requires it?
|
|
105
|
-
- Does each client component hold only interaction, with markup delegated to `children`, a slot prop, or a
|
|
106
|
-
`Unit`/`View`?
|
|
107
|
-
- Is initial data fetched in the route and passed as `init`/`view`, with no mount-only load effect?
|
|
108
|
-
- Did `akan quality ssr` hold or improve the server share for every touched app and lib?
|
|
@@ -1,59 +0,0 @@
|
|
|
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.
|