@akanjs/cli 3.0.0-alpha.46 → 3.0.0-alpha.48

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.
@@ -2,56 +2,13 @@
2
2
 
3
3
  - `apps/<app>` contains application pages, app UI, app domain modules, env files, and `akan.config.ts`.
4
4
  - `libs/<lib>` contains shared domain and utility code reused by apps.
5
- - `apps/<app>/page` contains server-side file-routed pages. Index pages use `_index.tsx`; nested layouts use `_layout.tsx`. routeName.tsx becomes /routeName and [modelId].tsx becomes /[modelId].
6
- - `apps/<app>/lib/<model>` contains database-backed domain modules.
7
- - `apps/<app>/lib/_<service>` contains service modules that are not database document models.
8
- - `apps/<app>/lib/__scalar/<scalar>` contains reusable scalar/value types.
9
- - Module abstracts live beside module code as `<model>.abstract.md`, `<service>.abstract.md`, or
10
- `<scalar>.abstract.md`.
11
-
12
- ## Generated Files
13
-
14
- Do not hand-edit generated Akan files. Regenerate them through Akan sync, lint, start, build, or the matching
15
- CLI command instead.
16
-
17
- Common generated files include:
18
- - `apps/*/client.ts`
19
- - `apps/*/server.ts`
20
- - `*/lib/cnst.ts`
21
- - `*/lib/db.ts`
22
- - `*/lib/dict.ts`
23
- - `*/lib/sig.ts`
24
- - `*/lib/srv.ts`
25
- - `*/lib/st.ts`
26
- - `*/lib/useClient.ts`
27
- - `*/lib/useServer.ts`
28
- - `*/lib/**/index.ts`
29
- - `*/ui/index.ts`
30
- - `*/webkit/index.ts`
31
- - `*/srvkit/index.ts`
32
- - `*/common/index.ts`
33
-
34
- Only **layer-root** barrels are generated. A nested `ui/<Folder>/index.tsx` that builds a namespace is
35
- hand-written source and must be edited by hand. The distinguishing test: a generated barrel contains nothing
36
- but `export * from "./X";` lines.
37
-
38
- ## Domain Module Responsibilities
39
-
40
- Use the local module shape before adding a new abstraction.
41
-
42
- - `<model>.constant.ts` defines model, enum, scalar, and schema intent.
43
- - `<model>.abstract.md` defines business intent, domain rules, workflows, and agent notes that are not obvious
44
- from code.
45
- - `<model>.dictionary.ts` defines labels, descriptions, messages, and i18n metadata.
46
- - `<model>.signal.ts` defines typed endpoint contracts.
47
- - `<model>.document.ts` owns persistence and document queries.
48
- - `<model>.service.ts` owns business logic.
49
- - `<model>.store.ts` owns reusable workflow state and actions that span loading, selections, messages, or multi-step client actions. Consume stores through generated `st.use.*` state and `st.do.*` actions.
50
- - `<Model>.Template.tsx` owns form-oriented UI, including local form inputs and submit/import interactions. Client components, with 'use client'.
51
- - `<Model>.Unit.tsx` owns list/item UI. Server components, no 'use client'.
52
- - `<Model>.View.tsx` owns detail UI. Server components, no 'use client'.
53
- - `<Model>.Zone.tsx` owns page/container integration and interactive loading or action flows that need client state. Client components, with 'use client'.
54
- - `<Model>.Util.tsx` owns small module UI helpers, including buttons, import actions, and client-side navigation such as `router.push`. Client components, with 'use client'.
5
+ - `apps/<app>/lib/<model>` holds database-backed domain modules, `lib/_<service>` service modules, and
6
+ `lib/__scalar/<scalar>` reusable value types. Module abstracts sit beside the code as `<name>.abstract.md`.
7
+ - `apps/<app>/page` holds server-side file-routed pages: `<routeName>.tsx` serves `/routeName`, a directory's
8
+ `_index.tsx` serves that directory, `_layout.tsx` nests a layout, and `[modelId]` is a dynamic segment.
9
+
10
+ The file roles inside a module — which file owns persistence, business logic, state, and each UI shape — are in
11
+ the convention set above under **Domain Module Conventions**.
55
12
 
56
13
  ## Agent Workflow
57
14
 
@@ -63,15 +20,14 @@ Use the local module shape before adding a new abstraction.
63
20
  6. After `apply_workflow`, run `run_validation` with `validationTarget` when present; otherwise use `applyReportPath`.
64
21
  7. Direct source edits are denied when an allowlisted Akan workflow or repair tool can perform the change.
65
22
  8. If no workflow exists, or apply reports unsupported/no-op/failed diagnostics that require manual action, edit only the owning source files and never patch generated files directly.
66
- 9. Keep page and layout files server-oriented: route-level `usePage`, headers, static layout, and `akanjs/ui` `Tab` composition belong there.
67
- 10. Put interactive loading, submit/import actions, local form state, and `router.push` in client `Util`, `Template`, or `Zone` components.
68
- 11. Prefer `Tab` for static mode selection instead of extra `useState`; render one focused client component inside each `Tab.Panel`.
69
- 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.
70
- 13. Keep server-only logic out of client surfaces and client-only code out of server imports.
71
- 14. Treat `AKAN_PUBLIC_*` env vars as public. Never put secrets in them.
72
- 15. Add or update tests when behavior, contracts, or CLI output changes.
73
- 16. Update `*.abstract.md` when business invariants, workflows, or public behavior change.
74
- 17. Run the smallest relevant verification command after changes. After touching any `.tsx`, that includes `akan quality ssr`.
23
+ 9. Treat `AKAN_PUBLIC_*` env vars as public. Never put secrets in them.
24
+ 10. Add or update tests when behavior, contracts, or CLI output changes.
25
+ 11. Update `*.abstract.md` when business invariants, workflows, or public behavior change.
26
+ 12. Run the smallest relevant verification command after changes. After touching any `.tsx`, that includes
27
+ `akan quality ssr`.
28
+
29
+ The rules for where code goes, the client/server boundary, and SSR discipline are in the convention set above;
30
+ this section covers only the order of operations.
75
31
 
76
32
  ## Common Commands
77
33
 
@@ -244,274 +200,6 @@ final fallback when no CLI command covers the change.
244
200
  | Add a server-only guard, middleware, or adaptor | `srvkit/` → PascalCase `.ts` | `akan sync <name>` |
245
201
  | Add a pure helper (no DOM, no server API) | `common/` → camelCase `.ts` | `akan sync <name>` |
246
202
 
247
- ## Anti-patterns: Never Do These
248
-
249
- | Don't | Why | Do Instead |
250
- |-------|-----|------------|
251
- | Edit `cnst.ts`, `db.ts`, `srv.ts`, `sig.ts`, `st.ts`, `dict.ts`, `useClient.ts`, `useServer.ts`, or any `index.ts` | These are **generated by `akan sync`**. Your changes will be overwritten. | Edit the source files in `lib/<model>/` directories and run `akan sync <name>` |
252
- | 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 |
253
- | 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/` |
254
- | 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 |
255
- | 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
- | `return` a value from a store action | `no-return-in-store-action.grit` bans it. Every method of a `store(...)` class dispatches through `st.do.<action>()`, which is typed `void` / `Promise<void>`, so the value never reaches the caller. | `this.set({ ... })` with the result; a bare `return;` guard, a `return` inside a nested callback, a getter, and a `static` helper all stay legal |
257
- | `throw new Error("...")` | `no-throw-raw-error.grit` bans raw errors outside tests, `*.constant.ts`, `common/`, and `apps/akan/env/`. 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({})` |
258
- | 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 |
259
- | A colour outside the semantic vocabulary — `bg-red-500`, `bg-[#3b82f6]`, `btn-primary`, `text-foreground`, `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>` |
260
- | `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 |
261
- | 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 |
262
- | Import across the client/server boundary — a `*.service.ts` or `../db` from a `.tsx`, `@libs/<lib>/client` or `../st` from a `*.signal.ts` | `no-import-server-in-client.grit` and `no-import-client-in-server.grit` ban it in both directions, and hold `common/` and `*.constant.ts` to both at once. One value import drags the whole other-side graph into the bundle or the server process. | Client code goes through the package client entrypoint and `cnst`; server code goes through `cnst`, `db`, and `srv`. `import type` is erased and stays legal both ways |
263
- | 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 |
264
- | 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 |
265
- | 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>` |
266
- | 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 |
267
- | 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` |
268
- | 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` |
269
- | 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` |
270
-
271
- ## SSR First — Server Rendering Is The Default
272
-
273
- Akan is SSR-first. Every JSX element that renders on the server ships as HTML and costs nothing to hydrate; every
274
- element behind `"use client"` ships twice — as markup and as bundled JS that must re-run in the browser. The
275
- boundary question is not which file *may* be client, it is **how little** ends up on the client side.
276
-
277
- **The default is server. `"use client"` is a cost you justify per component, not a habit.** A component earns the
278
- directive only by using a client-only capability: a React hook, a JSX event handler, the store (`st.use.*` /
279
- `st.do.*`), a browser global, or a client-only third-party package. Rendering markup, mapping over data, reading a
280
- route param, and calling `l()` are all server work — `usePage()` and `l()` are legal in server components and never
281
- force a boundary.
282
-
283
- The file role decides *where* the boundary sits (`Template`/`Zone`/`Util` are client, `Unit`/`View` are server); it
284
- does not decide how much markup sits behind it. A `Zone` that hoards markup is still an SSR regression.
285
-
286
- Measure with `akan quality ssr` (`--format json` for tooling). It reports the server render share per app and lib —
287
- server-rendered JSX elements over total — plus the warnings below. Treat **50% server share as the floor** and a
288
- falling share as a regression to justify or revert.
289
-
290
- | Rule | Means |
291
- |---|---|
292
- | `akan.ssr.unnecessary-use-client` | The directive is there but nothing in the file needs it. Delete it. |
293
- | `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. |
294
- | `akan.ssr.client-static-markup` | A large subtree wraps one or two interactive touches. Split it: interaction stays client, markup goes server. |
295
- | `akan.ssr.client-mount-load` | A `useEffect(…, [])` loads server data. The page can fetch it before the first byte. |
296
- | `akan.ssr.module-missing-server-view` | A module renders only from `Template`/`Zone`/`Util` and has no `Unit`/`View` at all. |
297
- | `akan.ssr.template-client-state` | A `Template` holds form state in `useState` instead of the store. |
298
-
299
- A third-party client package and the `ui/<Folder>/index_.tsx` + `lazy()` boundary both justify the directive and are
300
- not flagged. Interaction-driven `fetch.*` inside an `onClick` is not flagged either — only mount-time loads are,
301
- because those are the ones the server could have performed.
302
-
303
- ### Server-Side Implementation Playbook
304
-
305
- **① Wrap the interaction, not the UI.** The smallest useful client component adds one behaviour and renders
306
- `children` untouched, so the markup inside never reaches the bundle.
307
-
308
- ```tsx
309
- // apps/<%= appName %>/ui/ClickWrapper.tsx
310
- "use client";
311
- export const ClickWrapper = ({ children, onPick }: ClickWrapperProps) => <div onClick={onPick}>{children}</div>;
312
-
313
- // in a server page — Task.Unit.Card stays server-rendered
314
- <ClickWrapper onPick={…}>
315
- <Task.Unit.Card task={task} />
316
- </ClickWrapper>
317
- ```
318
-
319
- **② Split compound components so panels stay on the server.** A tab, accordion, or disclosure needs client state
320
- only for *which* part is visible — never for what the parts contain. `Tab` / `Tab.Menus` / `Tab.Menu` / `Tab.Panel`
321
- from `akanjs/ui` is the reference shape: only the provider and menu hold state, and `<Tab.Panel>` renders its
322
- children as-is, so a server `Unit`/`View` passed in stays server-rendered.
323
-
324
- ```tsx
325
- <Tab defaultMenu="detail">
326
- <Tab.Menus>
327
- <Tab.Menu menu="detail">{l("task.detail")}</Tab.Menu>
328
- <Tab.Menu menu="history">{l("task.history")}</Tab.Menu>
329
- </Tab.Menus>
330
- <Tab.Panel menu="detail">
331
- <Task.View.General task={task} />
332
- </Tab.Panel>
333
- </Tab>
334
- ```
335
-
336
- Never collapse this into one `"use client"` file with a mode `useState` and every panel body inlined.
337
-
338
- **③ Sync state instead of fetching it.** A server component cannot hold state, so render the initial data on the
339
- server and hand it across the boundary as a serializable object. That is what `init` / `view` props are: the page
340
- calls `fetch.initTaskInTodo()` / `fetch.viewTask(id)`, passes the result into a `Zone`, and `Load.Units` /
341
- `Load.View` hydrate the store from it.
342
-
343
- ```tsx
344
- export default async function Page() {
345
- const [{ taskInitInTodo }] = await Promise.all([fetch.initTaskInTodo()]);
346
- return <Task.Zone.Card init={taskInitInTodo} sliceName="taskInTodo" />;
347
- }
348
- ```
349
-
350
- **④ Push the boundary down to the leaf that needs it.** When a `Zone` reads the store, it should hold *zero* markup
351
- and delegate to a server `View`, so the whole detail surface renders server-side wherever a page uses the `View`
352
- directly.
353
-
354
- ```tsx
355
- "use client";
356
- export const Self = () => <Task.View.General task={st.use.task()} />;
357
- ```
358
-
359
- **⑤ Hand the promise across, not the awaited value.** `ClientInit` / `ClientView` are `PromiseOrObject<T>`, so a
360
- page may pass an unawaited `fetch.initTaskInTodo()` and `Load.*` resolves it behind a skeleton. `await` blocks the
361
- shell for data the page needs immediately; passing the promise streams the rest. Independent fetches still go
362
- through one `Promise.all`.
363
-
364
- **⑥ Use named `ReactNode` slots, not just `children`.** A client shell can take several server-rendered subtrees:
365
- `Layout.Navbar` accepts `title`, `back`, `left`, `right`, and `children`, so it composes server content in five
366
- places instead of absorbing it.
367
-
368
- **⑦ Let the server do the derived work.** Display and predicate logic belongs on `LightTask` (`isNew()`,
369
- `canWrite(user?)`, `formatTimes()`), and enum→class lookups belong in a module-scope `as const` map. Both sides call
370
- the same method, so a client component that exists only to compute a label is markup in the wrong place.
371
-
372
- **⑧ Gate auth on the server.** Check the session in `_layout.tsx` and redirect there, before any HTML is sent. A
373
- client-side auth check costs a hydration round-trip and flashes the wrong UI first.
374
-
375
- **⑨ Prefer CSS over client state for pure visibility.** A `data-*` attribute plus `group-data-[…]` variants, or
376
- `<details>`/`<summary>`, keeps both branches server-rendered. Reach for `useState` when the state is real, not when
377
- a Tailwind variant would do.
378
-
379
- **⑩ Keep the heavy island out of the first load.** A large client-only widget goes behind the
380
- `ui/<Folder>/index_.tsx` + `lazy()` pair so the server renders the page around it.
381
-
382
- ## Code Style
383
-
384
- House style for `apps/**` and `libs/**`. `akan lint` enforces the rules in the anti-pattern table above; the rest
385
- is convention that keeps hand-written code reading like generated code.
386
-
387
- ### Files And Types
388
-
389
- - Keep files small. Split a component before it reaches ~150 lines instead of adding section comments.
390
- - Ship every scaffold file even when it is empty — `export class TaskInternal extends internal(srv.task, () => ({})) {}`,
391
- empty dictionary stages, the `// state` / `// action` markers in an empty store. They mark where things go.
392
- - Never add a sibling helper file inside `lib/<model>/`. Helpers go to `common/`, `webkit/`, `srvkit/`, or `ui/`.
393
- - Prefer duplication to premature abstraction at the leaf: copy the near-identical file and change the literals.
394
- - `interface` for object shapes, `type` only for unions and aliases.
395
- - Never use a non-null assertion (`!`). Narrow with `?.`, an early return, or a type predicate.
396
- - Escape with `as unknown as T`, never `as any`.
397
- - `as const` on every `enumOf(...)` array, every Light field tuple, and every module-scope lookup map. Never the
398
- TypeScript `enum` keyword.
399
- - Never annotate a component's return type. Async functions carry no `Async` suffix.
400
-
401
- ### Components
402
-
403
- - `export const X = ({ … }: XProps) => { return (…); };` — arrow const with a block body. `export default` is only
404
- for pages, layouts, and `lazy()` targets.
405
- - Declare `interface <ComponentName>Props` immediately above the component with no blank line, `className?: string`
406
- first. Name it for the component (`CardProps`), never for the model.
407
- - Never `React.FC`, never `defaultProps`, never `PropsWithChildren`. Defaults go in the destructuring; children are
408
- typed `children: ReactNode`.
409
- - `"use client"` on line 1 is mechanical by file role: every `.Zone.tsx`, `.Template.tsx`, and `.Util.tsx` has it;
410
- no `.Unit.tsx` or `.View.tsx` ever does.
411
- - Conditional render is `cond ? <X/> : null`, never `{cond && <X/>}` — in a `className` context the latter renders
412
- the literal string `"false"`.
413
- - Never hand-roll loading, empty, or list states. Use `Load.Units` / `Load.View` / `Load.Edit` with `renderItem`,
414
- `renderList`, and `renderEmpty`, and `Model.New` / `Model.Edit` / `Model.SureToRemove` for CRUD modals.
415
- - Avoid hooks. `useState` is for modal-open, tab, draft-input, and drag state only — never for server data.
416
- `.Template.tsx` files contain zero `useState`: forms are store-driven with `Field.*`, `value={taskForm.x}`, and
417
- `onChange={st.do.setXOnTask}` passed by reference.
418
- - Read with `st.use.*` and write with `st.do.*`. Client components do not call `fetch.*`.
419
- - Reach for a recipe before writing a look by hand: `buttonRecipe`, `badgeRecipe` and `inputRecipe` from
420
- `akanjs/ui` carry the button, badge and field surfaces. Call them as `buttonRecipe(variants?, className?)` —
421
- the second argument merges internally and takes an array, so never wrap it in `cn()`.
422
- - Static class strings stay plain strings. Reach for `cn` only for a conditional or to merge an incoming
423
- `className`, and merge the caller last: `cn("base", conditional, className)`. `cn` comes from `akanjs/client`
424
- and is the only class-combining function — no `clsx`, no raw `twMerge`.
425
- - Use semantic tokens with opacity modifiers (`text-foreground/60`, `bg-background/70`, `border-border`). Never
426
- `dark:` — theming is the token block in `page/*/styles.css`, where each token has a `-foreground` pair.
427
- - Hoist enum→class lookups to a module-scope `as const` map typed `{ [key in cnst.TaskStatus["value"]]: string }`,
428
- not `Record<...>`.
429
-
430
- ### Naming
431
-
432
- - Component exports are role names (`Card`, `General`, `Preview`, `Remove`). The model comes from the namespace, so
433
- write `Card`, not `TaskCard`.
434
- - Layer the verbs: the document chain method drops the model (`start()`) and the signal, store, and dictionary
435
- re-add it (`startTask`). This keeps custom endpoints clear of generated CRUD and makes `st.do.X` read the same as
436
- `fetch.X`.
437
- - Slice and filter names are prepositional: `inTodo`, `byStatuses`, `ofProject`. Never `getXInY`, never `listX`.
438
- - Handlers are `onX` props with inline arrows. Do not extract a `handleX`.
439
- - Booleans are `is*` / `has*` / `can*` / `show*`. Counters are `*Num`, indices are `idx`, collections are `*List`.
440
- - Identifiers, type names, endpoint names, and log messages are English. Everything a user reads goes through
441
- `l("task.title")` or `l.trans({ … })` — never a hard-coded string in JSX, never `window.alert`.
442
-
443
- ### Backend
444
-
445
- - **`constant.ts`** — five classes in order, `TaskInput → TaskObject → LightTask → Task → TaskInsight`, and write
446
- `TaskInsight` even when empty. Put display and predicate logic on `LightTask` (`isNew()`, `canWrite(user?)`): it is
447
- the class both server and client hold, so shared logic belongs there rather than in a util module. Collection
448
- helpers go `static` on the full model.
449
- - **`document.ts`** — `TaskFilter extends from(...)` → `Task extends by(...)` → `TaskModel extends into(...)`, with
450
- `sort: {}` always present. Chain methods validate → mutate → `return this` and never `save()`; the caller saves, so
451
- chains compose. Indexes and derived totals go in `static override _onSchema`.
452
- - **`service.ts`** — keep methods to a few lines: load → chain → `return await ….save()`. Side effects go in
453
- `override async _preUpdate` / `_postCreate`, not inline. Fire-and-forget is explicitly `void`-ed. Return `null` or
454
- `false` for "not allowed" and let the signal decide whether that is an error.
455
- - **`signal.ts`** — `TaskInternal` → `TaskSlice` → `TaskEndpoint`, all three declared even when empty, and `exec` is a
456
- one-liner delegating to the service. Every `slice()` takes an explicit `{ guards: { root: Admin, … } }`, and every
457
- custom mutation, query, and message names its own `guards: [...]`.
458
- - **`store.ts`** — write a custom action only for a toast, an optimistic update, or a multi-field write; the rest is
459
- generated. Never `import type { RootStore } from "../st"` — it crashes `akan build` with a Bun SSR segfault.
460
- - **`dictionary.ts`** — fixed chain with empty stages still written:
461
- `.of() → .model() → .insight() → .query() → .sort() → .enum() → .slice() → .endpoint() → .error() → .translate()`.
462
- Every label is `t(["English", "한국어"])`, and nearly every one also carries `.desc([en, ko])`.
463
- - **`srvkit/` adapters** — an injected singleton is an `adapt("name" as const, ({ use, env, plug, memory }) => ({…}))`
464
- class, injected with `plug(TheClass)`. It self-registers, so do not add it to `lib/option.ts`. `this.logger` is
465
- provided; lifecycle work goes in `override async onInit()`. A per-use value object stays a plain class you `new` at
466
- the call site. Route remote calls through one private `#api<T>(path, init?)` with `AbortSignal.timeout(20_000)`, and
467
- resolve secrets inside a function, never at module scope.
468
- - **Errors** — state-machine preconditions throw in `document.ts`, cross-document rules in `service.ts`, and
469
- request-level policy lives in signal guards. `try/catch` always converts an exception into a decision, never
470
- swallows one. Store actions do not `try/catch`; let the framework toast the `Err`.
471
-
472
- ### Comments
473
-
474
- Do not narrate code. Do document the thing the code cannot say. Both halves are the rule.
475
-
476
- - Never add a comment that restates the identifier, the signature, or the control flow.
477
- - Do not add JSDoc, section banners, or "why/how" comments for ordinary logic.
478
- - Density tracks the layer: pages carry none, product code stays under 1 %, and `srvkit/` adapters and `guards.ts`
479
- carry as much as the external constraints require.
480
- - A comment is warranted for a vendor spec or protocol quirk, an infrastructure constraint, a third-party library
481
- gotcha, security reasoning, a math derivation, a domain field's business meaning, a state transition above a
482
- document chain method, or why an obvious alternative was rejected.
483
- - Markers: `TODO` unfinished work · `FIXME` known broken behavior · `XXX` hazard a reader must not miss · `//!`
484
- disabled or must-fix code · `//?` an explanatory aside · `//*` a design note · deletion caution, warning why
485
- removing a line would break something non-obvious.
486
- - `//!` is for server, `srvkit/`, and CLI files only. Bun's bundler treats `//!` and `/*!` as legal comments and
487
- keeps them through minification, so in browser-reachable code the note ships verbatim to every visitor. Use
488
- `// FIXME:` there — `no-bang-comment-in-client.grit` enforces it.
489
- - Keep allowed comments to one short line, and give every suppression a reason:
490
- `// biome-ignore lint/<rule>: <why>`. Never a bare disable block.
491
- - Match nearby file style: if the surrounding code has few comments, keep it that way.
492
-
493
- ## Generated File Tracker (Quick Reference)
494
-
495
- These files are regenerated by `akan sync` and overwritten on every sync. **Do not hand-edit them.**
496
-
497
- | File | Generated From | Purpose |
498
- |------|---------------|---------|
499
- | `*/lib/cnst.ts` | All `*/lib/*/**.constant.ts` | Barrel for all constants |
500
- | `*/lib/db.ts` | All `*/lib/<model>/*.document.ts` | Barrel for all document models |
501
- | `*/lib/dict.ts` | All `*/lib/*/**.dictionary.ts` | Barrel for all dictionaries |
502
- | `*/lib/sig.ts` | All `*/lib/**/**.signal.ts` | Barrel for all signals |
503
- | `*/lib/srv.ts` | All `*/lib/**/**.service.ts` | Barrel for all services |
504
- | `*/lib/st.ts` | All `*/lib/**/**.store.ts` | Barrel for all stores |
505
- | `*/lib/useClient.ts` | Client-safe module re-exports | Client-side import entry |
506
- | `*/lib/useServer.ts` | Server-only module re-exports | Server-side import entry |
507
- | `apps/*/client.ts` | App-wide client barrel | The `fetch` and `st` instances |
508
- | `apps/*/server.ts` | App-wide server barrel | Server-side service resolution |
509
- | `*/lib/**/index.ts` | Per-module barrel | Module-level re-exports |
510
- | `*/ui/index.ts` | All 1-depth UI files/folders | UI layer-root barrel (nested `ui/<Folder>/index.tsx` is **not** generated) |
511
- | `*/webkit/index.ts` | All webkit files | Webkit barrel |
512
- | `*/srvkit/index.ts` | All srvkit files | Srvkit barrel |
513
- | `*/common/index.ts` | All common files | Common barrel |
514
-
515
203
  ## Workflow Recipes
516
204
 
517
205
  Concrete step-by-step recipes for the most frequent Akan.js changes. Each recipe shows which files to edit
@@ -649,8 +337,8 @@ export class TaskService extends serve(db.task, ({ plug }) => ({
649
337
  }
650
338
  ```
651
339
 
652
- For a custom adapter class (not a predefined role), pass the class itself, e.g. `ipfsApi: plug(IpfsApi)`
653
- (see `libs/shared/lib/file/file.service.ts`). Injecting a file/image field is usually simpler than calling
340
+ For a custom adapter class (not a predefined role), pass the class itself, e.g. `ipfsApi: plug(IpfsApi)`.
341
+ Injecting a file/image field is usually simpler than calling
654
342
  storage directly: declare `image: field(File).optional()` (or `images: field([File])`) on the model and let the
655
343
  store's generated `upload<Field>On<Model>(fileList)` action handle the upload. Add `{ cascade: "removeRef" }` to that
656
344
  field when the file belongs to the model alone, and removing the model removes the file and its stored object.
@@ -669,8 +357,8 @@ A Slice is a named, filtered data view. Add file entries and connect from a page
669
357
 
670
358
  ```typescript
671
359
  // 1. apps/<app>/lib/<model>/<model>.signal.ts — Define the slice
672
- export class TaskSlice extends slice(srv.task, (init) => ({
673
- inTodo: init()
360
+ export class TaskSlice extends slice(srv.task, { guards: { root: Admin, get: SignedIn, cru: SignedIn } }, (init) => ({
361
+ inTodo: init({ guards: [SignedIn] })
674
362
  .search("statuses", [cnst.TaskStatus])
675
363
  .exec(function (statuses?) {
676
364
  // ✅ query<Filter> — a query descriptor. ❌ listByStatuses(...) returns an array and fails at runtime.
@@ -727,8 +415,8 @@ async startTask(taskId: string) {
727
415
 
728
416
  // 3. <model>.signal.ts — Mutation endpoint
729
417
  export class TaskEndpoint extends endpoint(srv.task, ({ mutation }) => ({
730
- startTask: mutation(cnst.Task)
731
- .param("taskId", String)
418
+ startTask: mutation(cnst.Task, { guards: [SignedIn] })
419
+ .param("taskId", ID)
732
420
  .exec(async function (taskId) {
733
421
  return await this.taskService.startTask(taskId);
734
422
  }),
@@ -851,61 +539,39 @@ For each business question, follow this chain:
851
539
 
852
540
  ## Modeling & Query Gotchas
853
541
 
854
- A short list of things the type system does not always catch:
542
+ A short list of things the type system does not always catch. The full rules for text search, `cascade`, and the
543
+ query-level writes are in the convention set above; these are the shapes that build green and fail later.
855
544
 
856
545
  - **Slices return a query, not a list.** A slice `exec` must return `this.<model>Service.query<Filter>(...)`, never
857
546
  a `list<Filter>(...)` / `listBy...(...)` array. Returning an array type-checks but fails at runtime with
858
547
  `Unknown document field path: 0`. (See Recipe 3.)
859
548
  - **Custom endpoint names must not collide with generated CRUD.** `create/update/remove/view/edit/merge<Model>`
860
549
  already exist. A collision can build green and fail only at runtime — pick a distinct verb.
861
- - **Numbers are `Int` or `Float`, never `Number`.** `field(Number)` / `.body("x", Number)` fail to typecheck. Use
862
- `Int` for counts, `Float` for decimals.
863
- - **Array fields use `field([T])`.** e.g. `tags: field([String])`, `images: field([File])` — not `field(String)` with
864
- a suffix.
865
- - **Reading a secret field needs an explicit select.** `field(...).secret()` values (e.g. `passwordHash`) are stripped
866
- from query results by default. Fetch them with `{ select: { <field>: true } }`, e.g.
867
- `this.userModel.pickById(id, { select: { passwordHash: true } })`.
868
- - **Text search fields use the `text` role.** Opt a field into the full-text index with
869
- `field(String, { text: "title" })` (or `"desc"` / `"tag"` / `"thumb"` / `"filter"`). Nothing else opts a field in.
870
- `secret` / `hidden` / `resolve()` fields with `text` throw at class-build time — the mirror is plaintext. Search
871
- runs on sqlite/libsql only; `q.search()` against Postgres throws. `thumb` is mirrored for rendering and is not
872
- indexed.
873
- - **`cascade` names a direction, and the wrong one is a data loss.** Both actions can sit on the same field shape,
874
- so the value has to say which end goes away. `cascade: "removeRef"` on the relation an owner holds
875
- (`image: field(File, { cascade: "removeRef" })`, arrays included) removes the target when the owner is removed;
876
- only a relation accepts it. `cascade: "removeWith"` on a child's own reference to its owner
877
- (`field(ID, { ref: "agentSession", cascade: "removeWith" })`, or a relation, or `refPath` for a polymorphic
878
- owner whose type field must be an `enumOf`) removes the child when the owner is — the owner never learns its
879
- children exist. The removal runs through the **target's service** so its `_postRemove` runs too, unless the
880
- target provably has no removal side effect, in which case the boot-time plan collapses it into one query. A
881
- `removeWith` field gets its index automatically. Nothing checks for other references to the same target, so
882
- `removeRef` asserts exclusive ownership. Removal is soft but a storage delete is not, and a query-level removal
883
- fires no hooks and therefore no cascade.
884
- - **Removal is always soft, and `delete` is reserved.** `remove(id)`, the facade's `removeMany(query)`, and the
885
- store's `removeManyByQuery` all stamp `removedAt`; the framework has no hard delete for a model table.
886
- - **The model facade spells out `Many`/`One` on its writes** — `updateOne`, `updateMany`, `removeOne`, `removeMany`
887
- — because a bare `update`/`remove` would read like the document-path `update(id)` / `doc.remove()` while hitting
888
- every match. Reads keep the short `find`/`findOne` pair, and counting is `count(query)` (`countDocuments` is
889
- `@deprecated`).
890
- - **`q.search()` is a filter node, not a slice requirement.** Prefer
891
- `bySearch: filter().arg("text", String).query((text, q) => q.search(text, { prefix: true }))` — the generated
892
- `listBySearch` / `countBySearch` / `queryBySearch` / `insightBySearch` come for free. Only add a search slice when
893
- the model's data is safe to enumerate. It must sit at an AND position (not under `q.any()` / `q.not()`), blank
894
- input matches nothing, and score order needs the built-in `relevance` sort key — a slice endpoint that leaves
895
- `sort` off gets `latest`, not relevance.
550
+ - **Numbers are `Int` or `Float`, never `Number`.** `field(Number)` / `.body("x", Number)` fail to typecheck.
551
+ - **Array fields use `field([T])`** — `tags: field([String])`, `images: field([File])`.
552
+ - **Reading a secret field needs an explicit select.** `field(...).secret()` values are stripped from query results
553
+ by default: `this.userModel.pickById(id, { select: { passwordHash: true } })`.
554
+ - **`cascade` names a direction, and the wrong one is a data loss** — `removeRef` on the relation the owner holds,
555
+ `removeWith` on the child's reference to its owner. A query-level removal fires no hooks and therefore no cascade.
556
+ - **`q.search()` is a filter node, not a slice requirement.** `bySearch: filter().arg("text", String).query((text,
557
+ q) => q.search(text, { prefix: true }))` generates `listBySearch` / `countBySearch` / `queryBySearch` /
558
+ `insightBySearch` for free. Only add a search *slice* when the model's data is safe to enumerate.
896
559
 
897
560
  ## Current User, Guards & Auth-Gated Pages
898
561
 
899
562
  Built-in user authentication (session / JWT / password hashing) ships as a separate Akan auth library, not in the
900
563
  core framework. The core framework gives you the composition points below; wire the auth library through them.
901
564
 
902
- - **Guards** attach at the signal declaration, not per-method:
903
- `endpoint(srv.task, { guards: { root: SignedIn } }, ({ mutation }) => ({...}))` or
904
- `slice(srv.task, { guards: { root: SignedIn, get: Public, cru: Public } }, ...)`. `Public` always allows; other
905
- guards implement the `Guard` interface in `srvkit/` (server-only) and read the request context.
565
+ - **A `slice()` takes its guard map as a second argument**, `slice(srv.task, { guards: { root: Admin, get: SignedIn,
566
+ cru: SignedIn } }, (init) => ({...}))`. An `endpoint()` takes no guard argument at all —
567
+ `endpoint(srv.task, ({ mutation }) => ({...}))` — so **every custom `mutation` / `query` / `message` names its own
568
+ `guards: [...]` array**: `mutation(cnst.Task, { guards: [SignedIn] })`. `Public` always allows; other guards
569
+ implement the `Guard` interface in `srvkit/` (server-only).
570
+ - **Read the caller inside a guard** with `context.get<T>("account")`, which works on HTTP and websocket calls
571
+ alike — never branch on `getHttpContext()` / `getWebSocketContext()`. Every guard class also declares
572
+ `static scope: GuardScope`, `"account"` or `"resource"`, with no default.
906
573
  - **Read the current user inside a custom endpoint** by injecting an `InternalArg` with `.with(...)`:
907
- `mutation(cnst.Task).with(CurrentUserId).exec(async function (currentUserId) { ... })`. The `Guard` /
908
- `InternalArg` helpers live in `srvkit/` and read `context.getHttpContext().req.user`.
574
+ `mutation(cnst.Task, { guards: [SignedIn] }).with(CurrentUserId).exec(async function (currentUserId) { ... })`.
909
575
  - **Auto-generated CRUD and `serve()` service methods / lifecycle hooks do not receive session context.** If an
910
576
  operation needs the acting user, expose a custom endpoint that takes it via `.with(CurrentUserId)` — never trust a
911
577
  client-supplied user id.
@@ -7,7 +7,7 @@ import {
7
7
  } from "./index-sh01r3pm.js";
8
8
  import {
9
9
  openBrowser
10
- } from "./index-yay1fd05.js";
10
+ } from "./index-hnysajy8.js";
11
11
  import {
12
12
  runner
13
13
  } from "./index-8rr621r2.js";
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  CloudRunner
4
- } from "./index-3h0d06v8.js";
4
+ } from "./index-2kjyh1jb.js";
5
5
  import {
6
6
  PackageScript
7
7
  } from "./index-7zd96bng.js";
@@ -12,7 +12,7 @@ import {
12
12
  } from "./index-sh01r3pm.js";
13
13
  import {
14
14
  ApplicationScript
15
- } from "./index-yay1fd05.js";
15
+ } from "./index-hnysajy8.js";
16
16
  import {
17
17
  script
18
18
  } from "./index-8rr621r2.js";
@@ -1898,7 +1898,7 @@ function openBrowser(url) {
1898
1898
  }
1899
1899
 
1900
1900
  // pkgs/@akanjs/cli/application/application.runner.ts
1901
- var loadBuildRunner = async () => (await import("./applicationBuildRunner-7gnfz7ww.js")).ApplicationBuildRunner;
1901
+ var loadBuildRunner = async () => (await import("./applicationBuildRunner-0xjav921.js")).ApplicationBuildRunner;
1902
1902
  var loadReleasePackager = async () => (await import("./applicationReleasePackager-93nzdfsy.js")).ApplicationReleasePackager;
1903
1903
  var loadCapacitorApp = async () => (await import("./capacitorApp-927ahhz2.js")).CapacitorApp;
1904
1904
  var loadAbstractCompactor = async () => (await import("./abstractCompactor-20e0cwbs.js")).AbstractCompactor;
@@ -2340,4 +2340,6 @@ var TAIL = "(?=[\\s\"'`})\\]:/!,]|$)";
2340
2340
  var RAW_PALETTE_RE = new RegExp(`${LEAD}((?:${PREFIX})-)${PALETTE}-\\d{2,3}${TAIL}`, "g");
2341
2341
  var INTERPOLATED_ARBITRARY_RE = new RegExp(`${LEAD}[a-z][a-z0-9-]*-\\[[^\\]\`]*\\$\\{`, "g");
2342
2342
  var DAISYUI_LEGACY_RE = new RegExp(`${LEAD}(?:` + "btn-(?:primary|secondary|accent|neutral|info|success|warning|error|ghost|link|outline|square|circle|wide|block|xs|sm|md|lg)|" + "badge-(?:primary|secondary|accent|neutral|info|success|warning|error|ghost|outline)|" + "alert-(?:info|success|warning|error)|" + "input-(?:bordered|primary|secondary|accent|ghost|error)|" + "select-(?:bordered|primary|ghost)|textarea-(?:bordered|primary|ghost)|" + "checkbox-(?:primary|secondary|accent)|toggle-(?:primary|secondary|accent)|" + "loading-(?:spinner|dots|ring|ball|bars|infinity)|" + "card-(?:body|title|actions)|modal-(?:box|action|backdrop)|" + "collapse-(?:title|content|arrow|plus)|dropdown-(?:content|end|start|hover)|" + "stat-(?:title|value|desc)|tabs-(?:boxed|lifted|bordered)|tab-active|" + "menu-(?:title|dropdown)|steps-(?:horizontal|vertical)|join-item|" + "mockup-(?:code|phone|browser|window)|drawer-(?:side|content|toggle)" + `)${TAIL}`, "g");
2343
+ var DAISYUI_TOKEN = "(?:base-(?:100|200|300|content)|(?:primary|secondary|accent|neutral|info|success|warning|error)-content|error)";
2344
+ var DAISYUI_TOKEN_RE = new RegExp(`${LEAD}(?:${PREFIX})-${DAISYUI_TOKEN}${TAIL}`, "g");
2343
2345
  export { AllRoutesBuilder, CsrArtifactBuilder, CssCompiler, FontOptimizer, PagesBundleBuilder, precompressArtifacts, SsrBaseArtifactBuilder };
package/index.js CHANGED
@@ -18,16 +18,16 @@ import path from "path";
18
18
 
19
19
  // pkgs/@akanjs/cli/commandModules.ts
20
20
  var commandModules = {
21
- workspace: async () => (await import("./workspace.command-f2966kvr.js")).WorkspaceCommand,
21
+ workspace: async () => (await import("./workspace.command-zkhcjsj2.js")).WorkspaceCommand,
22
22
  agent: async () => (await import("./agent.command-nqs3bw0g.js")).AgentCommand,
23
- application: async () => (await import("./application.command-cfx525a9.js")).ApplicationCommand,
23
+ application: async () => (await import("./application.command-5w691e89.js")).ApplicationCommand,
24
24
  library: async () => (await import("./library.command-7h3yezwc.js")).LibraryCommand,
25
- localRegistry: async () => (await import("./localRegistry.command-tet9rxqb.js")).LocalRegistryCommand,
25
+ localRegistry: async () => (await import("./localRegistry.command-mp3yc9gg.js")).LocalRegistryCommand,
26
26
  package: async () => (await import("./package.command-z7dd6vy2.js")).PackageCommand,
27
27
  module: async () => (await import("./module.command-4g11k3xd.js")).ModuleCommand,
28
28
  page: async () => (await import("./page.command-y996708m.js")).PageCommand,
29
29
  context: async () => (await import("./context.command-6kn3tady.js")).ContextCommand,
30
- cloud: async () => (await import("./cloud.command-4mkbvey2.js")).CloudCommand,
30
+ cloud: async () => (await import("./cloud.command-dq0mvj11.js")).CloudCommand,
31
31
  guideline: async () => (await import("./guideline.command-pjdrndqk.js")).GuidelineCommand,
32
32
  scalar: async () => (await import("./scalar.command-3chgxybs.js")).ScalarCommand,
33
33
  primitive: async () => (await import("./primitive.command-4fcn8k83.js")).PrimitiveCommand,
@@ -2,14 +2,14 @@
2
2
  import {
3
3
  CloudRunner,
4
4
  getNpmRegistryUrl
5
- } from "./index-3h0d06v8.js";
5
+ } from "./index-2kjyh1jb.js";
6
6
  import {
7
7
  PackageScript
8
8
  } from "./index-7zd96bng.js";
9
9
  import"./index-sh01r3pm.js";
10
10
  import {
11
11
  ApplicationScript
12
- } from "./index-yay1fd05.js";
12
+ } from "./index-hnysajy8.js";
13
13
  import"./index-6bs24rb4.js";
14
14
  import"./index-76rn3g2c.js";
15
15
  import {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/cli",
3
- "version": "3.0.0-alpha.46",
3
+ "version": "3.0.0-alpha.48",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -34,7 +34,7 @@
34
34
  "@langchain/openai": "^1.4.6",
35
35
  "@tailwindcss/node": "^4.3.0",
36
36
  "@trapezedev/project": "^7.1.4",
37
- "akanjs": "3.0.0-alpha.46",
37
+ "akanjs": "3.0.0-alpha.48",
38
38
  "chalk": "^5.6.2",
39
39
  "commander": "^14.0.3",
40
40
  "dayjs": "^1.11.20",