@akanjs/cli 2.4.2-rc.0 → 2.4.2-rc.2
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/{agent.command-ash7wabs.js → agent.command-ej4g9pbb.js} +6 -6
- package/{application.command-zm47j93m.js → application.command-smn51a28.js} +4 -4
- package/buildBatch.proc.js +1 -1
- package/{capacitorApp-wc75rvfm.js → capacitorApp-yg9b4ajz.js} +2 -2
- package/{cloud.command-vwpzten0.js → cloud.command-2v7ga38h.js} +7 -7
- package/{context.command-j0kq87xa.js → context.command-hhjyjtp7.js} +13 -13
- package/{guideline.command-1m4jwhv0.js → guideline.command-vj956kfr.js} +3 -3
- package/incrementalBuilder.proc.js +1 -1
- package/{index-tnngmzgf.js → index-04as43rp.js} +5 -5
- package/{index-79v9jwqe.js → index-40w1kqp1.js} +3 -3
- package/{index-xjkjcbhd.js → index-7ppn9v4n.js} +3 -3
- package/{index-mpj63mbw.js → index-acwxfncv.js} +4 -4
- package/{index-en4zpzdm.js → index-d0h48d2f.js} +1 -1
- package/{index-f1x6fe2e.js → index-dgeaqwmw.js} +1 -1
- package/{index-2nb022xv.js → index-h971erkm.js} +3 -3
- package/{index-t5rn8q9f.js → index-j3j3qc9j.js} +3 -3
- package/{index-0wgpfp7t.js → index-majzj044.js} +5 -5
- package/{index-31183bxt.js → index-panyahn4.js} +4 -4
- package/{index-ckywhpvp.js → index-pfnh87f9.js} +1 -1
- package/{index-n08vr4hh.js → index-s9s0n5fz.js} +2 -2
- package/{index-xdf6rxyt.js → index-v9jqrdd1.js} +2 -2
- package/{index-ehjhzg5y.js → index-xftstr5s.js} +1 -1
- package/{index-s6nk9815.js → index-xwfg9bam.js} +1 -1
- package/{index-8dsjmcbp.js → index-y1e79mz3.js} +11 -11
- package/{index-31e8cwjq.js → index-z36qzgzp.js} +2 -2
- package/{index-cp26p7qd.js → index-z5v766nx.js} +3 -3
- package/{index-smt4re0s.js → index-zfp1gz9f.js} +1 -1
- package/index.js +18 -18
- package/{library.command-39eq3brk.js → library.command-68ah07a3.js} +3 -3
- package/{localRegistry.command-34zvgkys.js → localRegistry.command-nmyc5vwv.js} +6 -6
- package/{module.command-vwahdkzr.js → module.command-t68xhamx.js} +6 -6
- package/{package.command-wkwd5x5p.js → package.command-00ncttab.js} +3 -3
- package/package.json +2 -2
- package/{page.command-9w85hrg0.js → page.command-1096s18n.js} +3 -3
- package/{primitive.command-2hnr8h7f.js → primitive.command-02eqpx6t.js} +7 -7
- package/{quality.command-4kerz7mh.js → quality.command-vap6xegb.js} +2 -2
- package/{repair.command-zmwshmvr.js → repair.command-7dynpnf1.js} +5 -5
- package/{scalar.command-9kanb73t.js → scalar.command-3kxy3fkh.js} +5 -5
- package/templates/workspaceRoot/.cursor/rules/akan-page-routing.mdc.template +27 -1
- package/templates/workspaceRoot/.cursor/rules/akan-sync-conventions.mdc.template +14 -0
- package/templates/workspaceRoot/.cursor/rules/client-server-boundaries.mdc.template +1 -1
- package/templates/workspaceRoot/.cursor/rules/coding-comments.mdc.template +13 -7
- package/templates/workspaceRoot/.cursor/rules/coding-style.mdc.template +23 -3
- package/templates/workspaceRoot/.cursor/rules/lint-enforced-rules.mdc.template +18 -0
- package/templates/workspaceRoot/.cursor/rules/module-file-playbook.mdc.template +61 -0
- package/templates/workspaceRoot/.cursor/rules/naming-conventions.mdc.template +15 -0
- package/templates/workspaceRoot/.cursor/rules/react-component-style.mdc.template +21 -0
- package/templates/workspaceRoot/.cursor/rules/scalar-modeling.mdc.template +47 -3
- package/templates/workspaceRoot/.cursor/rules/service-signal-conventions.mdc.template +69 -0
- package/templates/workspaceRoot/.cursor/rules/srvkit-adapters-and-guards.mdc.template +50 -0
- package/templates/workspaceRoot/.cursor/rules/typescript-imports.mdc.template +3 -0
- package/templates/workspaceRoot/AGENTS.md.template +145 -26
- package/templates/workspaceRoot/docs/AI-DEVELOPMENT.md.template +19 -0
- package/templates/workspaceRoot/docs/GENERATED.md.template +1 -1
- package/{workflow.command-4areq0ex.js → workflow.command-yy0d9gk3.js} +10 -10
- package/{workspace.command-02x93b10.js → workspace.command-hq1x5605.js} +19 -19
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: srvkit adapter (adapt/plug), guard, and error-handling conventions
|
|
3
|
+
globs: apps/**/srvkit/**/*.ts,libs/**/srvkit/**/*.ts
|
|
4
|
+
alwaysApply: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Adapters — `adapt()` And `plug()`
|
|
8
|
+
|
|
9
|
+
An injected singleton is an `adapt()` class in `srvkit/`. Write new adapters this way.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
export class AdminNoti extends adapt("adminNoti" as const, ({ use, env, plug, memory }) => ({
|
|
13
|
+
discordApi: use<DiscordApi>(),
|
|
14
|
+
workspaceRoot: env(() => `~/build/${getEnv().environment}`),
|
|
15
|
+
masterHost: plug(MasterHost),
|
|
16
|
+
tokenMap: memory(Map, { of: String }),
|
|
17
|
+
})) {}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
- Inject it with `plug(TheClass)` from a service or from another adapter. Destructure only the injectors you use, and write the registration key `as const`.
|
|
21
|
+
- **Do not register an `adapt()` class in `lib/option.ts`.** It self-registers, and `plug(Class)` uses the class itself as the token. `option.ts` is now only for legacy constructor-style adapters and for widening the options type.
|
|
22
|
+
- `this.logger` is provided; never construct a `Logger` inside an `adapt()` class. Lifecycle work goes in `override async onInit()`.
|
|
23
|
+
- `#private` is the house style here — the `#private` lint ban covers only `*.constant.ts`, `*.document.ts`, `*.service.ts`, and `*.store.ts`.
|
|
24
|
+
- **`adapt()` is for singletons only.** A per-use value object stays a plain class you `new` at the call site. Ask whether there is exactly one per process that a service needs injected; if not, it is a plain class.
|
|
25
|
+
- **Legacy shape — recognise it, do not copy it.** Plain classes with `constructor(options: XOptions)`, registered in `lib/option.ts` as `options.x ? new XApi(options.x) : null` and injected with `use<T>()`, still work. Migrate one to `adapt()` only when you are already changing it.
|
|
26
|
+
- Preference order inside a service: `service<srv.XService>()` for another module's service · `plug(AdapterClass)` or `plug(StorageAdaptorRole)` for an adapter · `use<T>()` only to reach an `option.ts`-registered legacy singleton · `env(...)` for config.
|
|
27
|
+
|
|
28
|
+
Conventions that hold for both shapes:
|
|
29
|
+
|
|
30
|
+
- Route every remote call through one private `#api<T>(path, init?)` with `signal: AbortSignal.timeout(20_000)`.
|
|
31
|
+
- Paginate with `for (let page = 1; ; page += 1)` broken by `if (pageItems.length < 100) break;`.
|
|
32
|
+
- Resolve secrets as `process.env.X ?? options.x ?? deterministicGenerator(...)` **inside a function**, never at module scope.
|
|
33
|
+
- Extend a function by appending an optional trailing parameter with a default, never by changing arity.
|
|
34
|
+
- Parameters: up to three required primitives positional; optional flags in a trailing `{ … } = {}`; four or more parameters, or any two same-typed strings, in one named destructured object.
|
|
35
|
+
- Release locks in `finally`. Load heavy optional dependencies through a module-level memoized promise (`sharpLoad ??= import("sharp")`).
|
|
36
|
+
|
|
37
|
+
# Guards (`srvkit/guards.ts`)
|
|
38
|
+
|
|
39
|
+
- Resource guards are `Can<Verb><Model>` classes that `implements Guard` with an `async canPass(context)`.
|
|
40
|
+
- They **fail closed**: no resource named ⇒ `false`; a load that throws ⇒ `logger.warn` then `false`. Admin bypass goes first.
|
|
41
|
+
- Keep `static name = "User";` on guard classes. `fetch` serializes guard names and the API explorer filters on them; it looks like dead code, and deleting it breaks the UI. Comment it so the next reader knows.
|
|
42
|
+
- Guards ship with the library that owns the model and are imported by its own signals through the package path, so a mounting app inherits authorization and cannot forget it.
|
|
43
|
+
- Services re-check ownership even when a guard already gated the call — two independent gates.
|
|
44
|
+
- This file earns real comments: explain what would leak without each guard.
|
|
45
|
+
|
|
46
|
+
# Error Placement
|
|
47
|
+
|
|
48
|
+
- State-machine preconditions throw in `document.ts`; cross-document rules throw in `service.ts`; request-level policy belongs in signal guards.
|
|
49
|
+
- Best-effort code returns a sentinel (`null`, `undefined`, `[0, 0]`, `{}`). There are no Result/Either wrappers.
|
|
50
|
+
- `try/catch` is rare and always converts an exception into a decision, never swallows one. Guards catch → `logger.warn` → `return false`; adapters catch → `logger.error` → `return null`; UI uses `try/finally` to reset a spinner. A bodyless `catch {}` is acceptable only with a one-line reason.
|
|
@@ -11,3 +11,6 @@ alwaysApply: false
|
|
|
11
11
|
- Use `akanjs/*` for framework facets, `@apps/*` for apps, `@libs/*` for shared libs, and `@contract/*` for contract code.
|
|
12
12
|
- Respect existing client/server entrypoints such as `@libs/shared/client`, `@libs/shared/server`, `@apps/myapp/client`, and `@apps/myapp/server`.
|
|
13
13
|
- Let Biome organize imports instead of manually reshuffling unrelated imports.
|
|
14
|
+
- Namespace the generated barrels in backend `.ts` files: `import * as cnst from "../cnst"`, `* as db`, `* as srv`. Use `import type * as srv` in services so the runtime graph stays lazy, and a value import in signals.
|
|
15
|
+
- In `.tsx` files use one flat named import from the package client path (`import { cnst, fetch, st, Task, usePage } from "@apps/myapp/client"`) — never a relative `../` import.
|
|
16
|
+
- Never import a third-party package from a page, a barrel, or a module file; re-export it through a one-line shim in `base/`, `webkit/`, or `ui/` first.
|
|
@@ -39,6 +39,10 @@ Common generated files include:
|
|
|
39
39
|
- `*/srvkit/index.ts`
|
|
40
40
|
- `*/common/index.ts`
|
|
41
41
|
|
|
42
|
+
Only **layer-root** barrels are generated. A nested `ui/<Folder>/index.tsx` that builds a namespace is
|
|
43
|
+
hand-written source and must be edited by hand. The distinguishing test: a generated barrel contains nothing
|
|
44
|
+
but `export * from "./X";` lines.
|
|
45
|
+
|
|
42
46
|
## Domain Module Responsibilities
|
|
43
47
|
|
|
44
48
|
Use the local module shape before adding a new abstraction.
|
|
@@ -55,7 +59,7 @@ Use the local module shape before adding a new abstraction.
|
|
|
55
59
|
- `<Model>.Unit.tsx` owns list/item UI. Server components, no 'use client'.
|
|
56
60
|
- `<Model>.View.tsx` owns detail UI. Server components, no 'use client'.
|
|
57
61
|
- `<Model>.Zone.tsx` owns page/container integration and interactive loading or action flows that need client state. Client components, with 'use client'.
|
|
58
|
-
- `<
|
|
62
|
+
- `<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'.
|
|
59
63
|
|
|
60
64
|
## Agent Workflow
|
|
61
65
|
|
|
@@ -247,26 +251,120 @@ final fallback when no CLI command covers the change.
|
|
|
247
251
|
|-------|-----|------------|
|
|
248
252
|
| 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>` |
|
|
249
253
|
| 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 |
|
|
250
|
-
| Use JS `#private`
|
|
251
|
-
| 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 |
|
|
254
|
+
| 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
|
+
| 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 |
|
|
256
|
+
| `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 `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 |
|
|
258
|
+
| `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 |
|
|
252
259
|
| 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 |
|
|
253
260
|
| 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 |
|
|
254
261
|
| 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 |
|
|
255
262
|
| 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>` |
|
|
256
263
|
| 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 |
|
|
257
264
|
|
|
258
|
-
##
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
265
|
+
## Code Style
|
|
266
|
+
|
|
267
|
+
House style for `apps/**` and `libs/**`. `akan lint` enforces the rules in the anti-pattern table above; the rest
|
|
268
|
+
is convention that keeps hand-written code reading like generated code.
|
|
269
|
+
|
|
270
|
+
### Files And Types
|
|
271
|
+
|
|
272
|
+
- Keep files small. Split a component before it reaches ~150 lines instead of adding section comments.
|
|
273
|
+
- Ship every scaffold file even when it is empty — `export class TaskInternal extends internal(srv.task, () => ({})) {}`,
|
|
274
|
+
empty dictionary stages, the `// state` / `// action` markers in an empty store. They mark where things go.
|
|
275
|
+
- Never add a sibling helper file inside `lib/<model>/`. Helpers go to `common/`, `webkit/`, `srvkit/`, or `ui/`.
|
|
276
|
+
- Prefer duplication to premature abstraction at the leaf: copy the near-identical file and change the literals.
|
|
277
|
+
- `interface` for object shapes, `type` only for unions and aliases.
|
|
278
|
+
- Never use a non-null assertion (`!`). Narrow with `?.`, an early return, or a type predicate.
|
|
279
|
+
- Escape with `as unknown as T`, never `as any`.
|
|
280
|
+
- `as const` on every `enumOf(...)` array, every Light field tuple, and every module-scope lookup map. Never the
|
|
281
|
+
TypeScript `enum` keyword.
|
|
282
|
+
- Never annotate a component's return type. Async functions carry no `Async` suffix.
|
|
283
|
+
|
|
284
|
+
### Components
|
|
285
|
+
|
|
286
|
+
- `export const X = ({ … }: XProps) => { return (…); };` — arrow const with a block body. `export default` is only
|
|
287
|
+
for pages, layouts, and `lazy()` targets.
|
|
288
|
+
- Declare `interface <ComponentName>Props` immediately above the component with no blank line, `className?: string`
|
|
289
|
+
first. Name it for the component (`CardProps`), never for the model.
|
|
290
|
+
- Never `React.FC`, never `defaultProps`, never `PropsWithChildren`. Defaults go in the destructuring; children are
|
|
291
|
+
typed `children: ReactNode`.
|
|
292
|
+
- `"use client"` on line 1 is mechanical by file role: every `.Zone.tsx`, `.Template.tsx`, and `.Util.tsx` has it;
|
|
293
|
+
no `.Unit.tsx` or `.View.tsx` ever does.
|
|
294
|
+
- Conditional render is `cond ? <X/> : null`, never `{cond && <X/>}` — in a `className` context the latter renders
|
|
295
|
+
the literal string `"false"`.
|
|
296
|
+
- Never hand-roll loading, empty, or list states. Use `Load.Units` / `Load.View` / `Load.Edit` with `renderItem`,
|
|
297
|
+
`renderList`, and `renderEmpty`, and `Model.New` / `Model.Edit` / `Model.SureToRemove` for CRUD modals.
|
|
298
|
+
- Avoid hooks. `useState` is for modal-open, tab, draft-input, and drag state only — never for server data.
|
|
299
|
+
`.Template.tsx` files contain zero `useState`: forms are store-driven with `Field.*`, `value={taskForm.x}`, and
|
|
300
|
+
`onChange={st.do.setXOnTask}` passed by reference.
|
|
301
|
+
- Read with `st.use.*` and write with `st.do.*`. Client components do not call `fetch.*`.
|
|
302
|
+
- Static class strings stay plain strings. Use `clsx` only for a conditional or to merge an incoming `className`,
|
|
303
|
+
and merge the caller last: `clsx("base", conditional, className)`. `clsx` comes from `akanjs/client`. No
|
|
304
|
+
`twMerge`, no `cn()`.
|
|
305
|
+
- Use daisyUI semantic tokens with opacity modifiers (`text-base-content/60`, `bg-base-100/70`). Never `dark:` —
|
|
306
|
+
theming is the daisyUI theme block in `page/*/styles.css`.
|
|
307
|
+
- Hoist enum→class lookups to a module-scope `as const` map typed `{ [key in cnst.TaskStatus["value"]]: string }`,
|
|
308
|
+
not `Record<...>`.
|
|
309
|
+
|
|
310
|
+
### Naming
|
|
311
|
+
|
|
312
|
+
- Component exports are role names (`Card`, `General`, `Preview`, `Remove`). The model comes from the namespace, so
|
|
313
|
+
write `Card`, not `TaskCard`.
|
|
314
|
+
- Layer the verbs: the document chain method drops the model (`start()`) and the signal, store, and dictionary
|
|
315
|
+
re-add it (`startTask`). This keeps custom endpoints clear of generated CRUD and makes `st.do.X` read the same as
|
|
316
|
+
`fetch.X`.
|
|
317
|
+
- Slice and filter names are prepositional: `inTodo`, `byStatuses`, `ofProject`. Never `getXInY`, never `listX`.
|
|
318
|
+
- Handlers are `onX` props with inline arrows. Do not extract a `handleX`.
|
|
319
|
+
- Booleans are `is*` / `has*` / `can*` / `show*`. Counters are `*Num`, indices are `idx`, collections are `*List`.
|
|
320
|
+
- Identifiers, type names, endpoint names, and log messages are English. Everything a user reads goes through
|
|
321
|
+
`l("task.title")` or `l.trans({ … })` — never a hard-coded string in JSX, never `window.alert`.
|
|
322
|
+
|
|
323
|
+
### Backend
|
|
324
|
+
|
|
325
|
+
- **`constant.ts`** — five classes in order, `TaskInput → TaskObject → LightTask → Task → TaskInsight`, and write
|
|
326
|
+
`TaskInsight` even when empty. Put display and predicate logic on `LightTask` (`isNew()`, `canWrite(user?)`): it is
|
|
327
|
+
the class both server and client hold, so shared logic belongs there rather than in a util module. Collection
|
|
328
|
+
helpers go `static` on the full model.
|
|
329
|
+
- **`document.ts`** — `TaskFilter extends from(...)` → `Task extends by(...)` → `TaskModel extends into(...)`, with
|
|
330
|
+
`sort: {}` always present. Chain methods validate → mutate → `return this` and never `save()`; the caller saves, so
|
|
331
|
+
chains compose. Indexes and derived totals go in `static override _onSchema`.
|
|
332
|
+
- **`service.ts`** — keep methods to a few lines: load → chain → `return await ….save()`. Side effects go in
|
|
333
|
+
`override async _preUpdate` / `_postCreate`, not inline. Fire-and-forget is explicitly `void`-ed. Return `null` or
|
|
334
|
+
`false` for "not allowed" and let the signal decide whether that is an error.
|
|
335
|
+
- **`signal.ts`** — `TaskInternal` → `TaskSlice` → `TaskEndpoint`, all three declared even when empty, and `exec` is a
|
|
336
|
+
one-liner delegating to the service. Every `slice()` takes an explicit `{ guards: { root: Admin, … } }`, and every
|
|
337
|
+
custom mutation, query, and message names its own `guards: [...]`.
|
|
338
|
+
- **`store.ts`** — write a custom action only for a toast, an optimistic update, or a multi-field write; the rest is
|
|
339
|
+
generated. Never `import type { RootStore } from "../st"` — it crashes `akan build` with a Bun SSR segfault.
|
|
340
|
+
- **`dictionary.ts`** — fixed chain with empty stages still written:
|
|
341
|
+
`.of() → .model() → .insight() → .query() → .sort() → .enum() → .slice() → .endpoint() → .error() → .translate()`.
|
|
342
|
+
Every label is `t(["English", "한국어"])`, and nearly every one also carries `.desc([en, ko])`.
|
|
343
|
+
- **`srvkit/` adapters** — an injected singleton is an `adapt("name" as const, ({ use, env, plug, memory }) => ({…}))`
|
|
344
|
+
class, injected with `plug(TheClass)`. It self-registers, so do not add it to `lib/option.ts`. `this.logger` is
|
|
345
|
+
provided; lifecycle work goes in `override async onInit()`. A per-use value object stays a plain class you `new` at
|
|
346
|
+
the call site. Route remote calls through one private `#api<T>(path, init?)` with `AbortSignal.timeout(20_000)`, and
|
|
347
|
+
resolve secrets inside a function, never at module scope.
|
|
348
|
+
- **Errors** — state-machine preconditions throw in `document.ts`, cross-document rules in `service.ts`, and
|
|
349
|
+
request-level policy lives in signal guards. `try/catch` always converts an exception into a decision, never
|
|
350
|
+
swallows one. Store actions do not `try/catch`; let the framework toast the `Err`.
|
|
351
|
+
|
|
352
|
+
### Comments
|
|
353
|
+
|
|
354
|
+
Do not narrate code. Do document the thing the code cannot say. Both halves are the rule.
|
|
355
|
+
|
|
356
|
+
- Never add a comment that restates the identifier, the signature, or the control flow.
|
|
263
357
|
- Do not add JSDoc, section banners, or "why/how" comments for ordinary logic.
|
|
264
|
-
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
-
|
|
358
|
+
- Density tracks the layer: pages carry none, product code stays under 1 %, and `srvkit/` adapters and `guards.ts`
|
|
359
|
+
carry as much as the external constraints require.
|
|
360
|
+
- A comment is warranted for a vendor spec or protocol quirk, an infrastructure constraint, a third-party library
|
|
361
|
+
gotcha, security reasoning, a math derivation, a domain field's business meaning, a state transition above a
|
|
362
|
+
document chain method, or why an obvious alternative was rejected.
|
|
363
|
+
- Markers: `TODO` unfinished work · `FIXME` known broken behavior · `XXX` hazard a reader must not miss · `//!`
|
|
364
|
+
disabled or must-fix code · `//?` an explanatory aside · `//*` a design note · deletion caution, warning why
|
|
365
|
+
removing a line would break something non-obvious.
|
|
366
|
+
- Keep allowed comments to one short line, and give every suppression a reason:
|
|
367
|
+
`// biome-ignore lint/<rule>: <why>`. Never a bare disable block.
|
|
270
368
|
- Match nearby file style: if the surrounding code has few comments, keep it that way.
|
|
271
369
|
|
|
272
370
|
## Generated File Tracker (Quick Reference)
|
|
@@ -286,7 +384,7 @@ These files are regenerated by `akan sync` and overwritten on every sync. **Do n
|
|
|
286
384
|
| `apps/*/client.ts` | App-wide client barrel | The `fetch` and `st` instances |
|
|
287
385
|
| `apps/*/server.ts` | App-wide server barrel | Server-side service resolution |
|
|
288
386
|
| `*/lib/**/index.ts` | Per-module barrel | Module-level re-exports |
|
|
289
|
-
| `*/ui/index.ts` | All UI
|
|
387
|
+
| `*/ui/index.ts` | All 1-depth UI files/folders | UI layer-root barrel (nested `ui/<Folder>/index.tsx` is **not** generated) |
|
|
290
388
|
| `*/webkit/index.ts` | All webkit files | Webkit barrel |
|
|
291
389
|
| `*/srvkit/index.ts` | All srvkit files | Srvkit barrel |
|
|
292
390
|
| `*/common/index.ts` | All common files | Common barrel |
|
|
@@ -318,9 +416,10 @@ export class TaskInput extends via((field) => ({
|
|
|
318
416
|
export class LightTask extends via(TaskObject, ["title", "priority", "status", "due"] as const, () => ({})) {}
|
|
319
417
|
|
|
320
418
|
// 2. apps/<app>/lib/<model>/<model>.dictionary.ts
|
|
321
|
-
// Add i18n labels for the new field (and its enum values if any)
|
|
419
|
+
// Add i18n labels for the new field (and its enum values if any).
|
|
420
|
+
// Labels are [en, ko] pairs, and nearly every one also carries a .desc([en, ko]).
|
|
322
421
|
.model<Task>((t) => ({
|
|
323
|
-
priority: t(["Priority", "우선순위"]),
|
|
422
|
+
priority: t(["Priority", "우선순위"]).desc(["How urgent the task is", "할 일의 긴급도"]),
|
|
324
423
|
}))
|
|
325
424
|
.enum<TaskPriority>("taskPriority", (t) => ({
|
|
326
425
|
low: t(["Low", "낮음"]),
|
|
@@ -358,6 +457,11 @@ Three patterns: injecting an **external adapter** (`use<>()`), another **module'
|
|
|
358
457
|
or a **predefined framework adapter** (`plug()`). A field named `<refName>Service` resolves to the service
|
|
359
458
|
registered under `<refName>` — the `Service`/`Signal` suffix is required and stripped to derive the lookup key.
|
|
360
459
|
|
|
460
|
+
> **For a new adapter you own, prefer the `adapt()` shape in pattern C over the `option.ts` registration in
|
|
461
|
+
> pattern A.** An `adapt()` class self-registers and is injected with `plug(TheClass)`, so it never touches
|
|
462
|
+
> `option.ts`. Pattern A is the legacy constructor-style shape: recognise it, keep it working, and migrate one
|
|
463
|
+
> only when you are already changing it.
|
|
464
|
+
|
|
361
465
|
> `apps/<app>/lib/option.ts` is a **user-owned** file scaffolded once — edit it to register adapters/DI. Unlike the
|
|
362
466
|
> barrels (`cnst.ts`, `db.ts`, `srv.ts`, …) it is **not** overwritten by `akan sync`, so your `.use(...)` registrations
|
|
363
467
|
> are safe.
|
|
@@ -427,7 +531,8 @@ export class TaskService extends serve(db.task, ({ plug }) => ({
|
|
|
427
531
|
For a custom adapter class (not a predefined role), pass the class itself, e.g. `ipfsApi: plug(IpfsApi)`
|
|
428
532
|
(see `libs/shared/lib/file/file.service.ts`). Injecting a file/image field is usually simpler than calling
|
|
429
533
|
storage directly: declare `image: field(File).optional()` (or `images: field([File])`) on the model and let the
|
|
430
|
-
store's generated `upload<Field>On<Model>(fileList)` action handle the upload.
|
|
534
|
+
store's generated `upload<Field>On<Model>(fileList)` action handle the upload. Add `{ cascade: "remove" }` to that
|
|
535
|
+
field when the file belongs to the model alone, and removing the model removes the file and its stored object.
|
|
431
536
|
|
|
432
537
|
---
|
|
433
538
|
|
|
@@ -468,14 +573,11 @@ export class TaskFilter extends from(cnst.Task, (filter) => ({
|
|
|
468
573
|
})),
|
|
469
574
|
}))
|
|
470
575
|
|
|
471
|
-
// 4. In page — Init slice
|
|
472
|
-
|
|
473
|
-
const { taskInitInTodo } = await fetch.initTaskInTodo();
|
|
474
|
-
return {
|
|
475
|
-
}
|
|
476
|
-
render={({ data: { taskInitInTodo } }) => (
|
|
477
|
-
<Task.Zone.Card init={taskInitInTodo} sliceName="taskInTodo" />
|
|
478
|
-
)}
|
|
576
|
+
// 4. In page — Init the slice in an async Page and hand the init to a Zone.
|
|
577
|
+
export default async function Page() {
|
|
578
|
+
const [{ taskInitInTodo }] = await Promise.all([fetch.initTaskInTodo()]);
|
|
579
|
+
return <Task.Zone.Card init={taskInitInTodo} sliceName="taskInTodo" />;
|
|
580
|
+
}
|
|
479
581
|
```
|
|
480
582
|
|
|
481
583
|
The slice name in code uses camelCase (`inTodo`). In dictionary and components it becomes `"taskInTodo"`.
|
|
@@ -642,6 +744,23 @@ A short list of things the type system does not always catch:
|
|
|
642
744
|
- **Reading a secret field needs an explicit select.** `field(...).secret()` values (e.g. `passwordHash`) are stripped
|
|
643
745
|
from query results by default. Fetch them with `{ select: { <field>: true } }`, e.g.
|
|
644
746
|
`this.userModel.pickById(id, { select: { passwordHash: true } })`.
|
|
747
|
+
- **Text search fields use the `text` role.** Opt a field into the full-text index with
|
|
748
|
+
`field(String, { text: "title" })` (or `"desc"` / `"tag"` / `"thumb"` / `"filter"`). Nothing else opts a field in.
|
|
749
|
+
`secret` / `hidden` / `resolve()` fields with `text` throw at class-build time — the mirror is plaintext. Search
|
|
750
|
+
runs on sqlite/libsql only; `q.search()` against Postgres throws. `thumb` is mirrored for rendering and is not
|
|
751
|
+
indexed.
|
|
752
|
+
- **`cascade: "remove"` takes a relation's target down with its owner.** Declare it on the relation itself —
|
|
753
|
+
`image: field(File, { cascade: "remove" })`, arrays included. The removal runs through the **target's service**,
|
|
754
|
+
so the target's own `_postRemove` runs too; that is how removing a model also deletes the file's stored object.
|
|
755
|
+
Only a relation accepts it: a `String`, an `ID`, or a scalar throws while the class is being built. Nothing
|
|
756
|
+
checks for other references to the same target, so declaring it asserts exclusive ownership. Document removal is
|
|
757
|
+
soft but the storage delete is not, and query-level removal fires no hooks and therefore no cascade.
|
|
758
|
+
- **`q.search()` is a filter node, not a slice requirement.** Prefer
|
|
759
|
+
`bySearch: filter().arg("text", String).query((text, q) => q.search(text, { prefix: true }))` — the generated
|
|
760
|
+
`listBySearch` / `countBySearch` / `queryBySearch` / `insightBySearch` come for free. Only add a search slice when
|
|
761
|
+
the model's data is safe to enumerate. It must sit at an AND position (not under `q.any()` / `q.not()`), blank
|
|
762
|
+
input matches nothing, and score order needs the built-in `relevance` sort key — a slice endpoint that leaves
|
|
763
|
+
`sort` off gets `latest`, not relevance.
|
|
645
764
|
|
|
646
765
|
## Current User, Guards & Auth-Gated Pages
|
|
647
766
|
|
|
@@ -45,6 +45,25 @@ See `docs/GENERATED.md` for the generated file list.
|
|
|
45
45
|
- Server-oriented surfaces include pages, `*.Unit.tsx`, `*.View.tsx`, `lib/`, `srvkit/`, and server entrypoints.
|
|
46
46
|
- Treat `AKAN_PUBLIC_*` values as public.
|
|
47
47
|
|
|
48
|
+
## House Style
|
|
49
|
+
|
|
50
|
+
`AGENTS.md` holds the full style guide. The rules agents break most often:
|
|
51
|
+
|
|
52
|
+
- **Never hand-order Tailwind classes** — the linter sorts them, including inside `clsx()`, and its output looks
|
|
53
|
+
unnatural on purpose.
|
|
54
|
+
- **Never `throw new Error`** — throw `new Err("<module>.error.<key>")` with an `[en, ko]` entry in the module
|
|
55
|
+
dictionary. `common/` cannot import `Err`, so keep throwing code out of it.
|
|
56
|
+
- **Never import a third-party package** from a page, a barrel, or a module file. Re-export it through a one-line
|
|
57
|
+
shim in `base/`, `webkit/`, or `ui/` first.
|
|
58
|
+
- `#private` is lint-banned in `*.constant.ts`, `*.document.ts`, `*.service.ts`, and `*.store.ts` only; it stays
|
|
59
|
+
the house style under `srvkit/`.
|
|
60
|
+
- Components are `export const X = ({ … }: XProps) => { … }` with `interface XProps` directly above and
|
|
61
|
+
`className?: string` first. No `React.FC`, no non-null assertions, no `as any`.
|
|
62
|
+
- `cond ? <X/> : null`, never `{cond && <X/>}` — the latter renders the string `"false"` in a className context.
|
|
63
|
+
- Put display and predicate logic on the `Light<Model>` constant class; keep document chain methods
|
|
64
|
+
validate → mutate → `return this` without `save()`; keep services to load → chain → save.
|
|
65
|
+
- Do not narrate code in comments. Do document vendor quirks, infrastructure constraints, and security reasoning.
|
|
66
|
+
|
|
48
67
|
## Abstract Documents
|
|
49
68
|
|
|
50
69
|
Update `*.abstract.md` when business invariants, workflows, user-visible behavior, cross-module relationships, or
|
|
@@ -28,7 +28,7 @@ sync or build can overwrite local changes.
|
|
|
28
28
|
|
|
29
29
|
| File | Purpose |
|
|
30
30
|
| --- | --- |
|
|
31
|
-
| `*/ui/index.ts` | Re-exports UI component files. |
|
|
31
|
+
| `*/ui/index.ts` | Re-exports 1-depth UI component files and folders. Only this layer-root barrel is generated — a nested `ui/<Folder>/index.tsx` that builds a namespace is hand-written source. |
|
|
32
32
|
| `*/webkit/index.ts` | Re-exports webkit/browser helper files. |
|
|
33
33
|
| `*/srvkit/index.ts` | Re-exports server-kit helper files. |
|
|
34
34
|
| `*/common/index.ts` | Re-exports common helper files. |
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
3
|
WorkflowRunner
|
|
4
|
-
} from "./index-
|
|
4
|
+
} from "./index-h971erkm.js";
|
|
5
5
|
import {
|
|
6
6
|
ScalarScript
|
|
7
|
-
} from "./index-
|
|
7
|
+
} from "./index-z5v766nx.js";
|
|
8
8
|
import {
|
|
9
9
|
PrimitiveScript
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-acwxfncv.js";
|
|
11
11
|
import {
|
|
12
12
|
ModuleScript
|
|
13
|
-
} from "./index-
|
|
14
|
-
import"./index-
|
|
13
|
+
} from "./index-04as43rp.js";
|
|
14
|
+
import"./index-dgeaqwmw.js";
|
|
15
15
|
import"./index-ss469dec.js";
|
|
16
|
-
import"./index-
|
|
16
|
+
import"./index-v9jqrdd1.js";
|
|
17
17
|
import {
|
|
18
18
|
createWorkflowStepRegistry
|
|
19
|
-
} from "./index-
|
|
20
|
-
import"./index-
|
|
19
|
+
} from "./index-pfnh87f9.js";
|
|
20
|
+
import"./index-xftstr5s.js";
|
|
21
21
|
import"./index-nsj2ftxj.js";
|
|
22
22
|
import {
|
|
23
23
|
Workspace,
|
|
24
24
|
command,
|
|
25
25
|
script
|
|
26
|
-
} from "./index-
|
|
27
|
-
import"./index-
|
|
26
|
+
} from "./index-d0h48d2f.js";
|
|
27
|
+
import"./index-xwfg9bam.js";
|
|
28
28
|
import"./index-67546d0j.js";
|
|
29
29
|
import"./index-6pz1j0zj.js";
|
|
30
30
|
import"./index-r24hmh0q.js";
|
|
@@ -1,55 +1,55 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
3
|
ContextScript
|
|
4
|
-
} from "./index-
|
|
5
|
-
import"./index-
|
|
6
|
-
import"./index-
|
|
4
|
+
} from "./index-y1e79mz3.js";
|
|
5
|
+
import"./index-7ppn9v4n.js";
|
|
6
|
+
import"./index-h971erkm.js";
|
|
7
7
|
import {
|
|
8
8
|
CloudScript
|
|
9
|
-
} from "./index-
|
|
10
|
-
import"./index-
|
|
11
|
-
import"./index-
|
|
12
|
-
import"./index-
|
|
13
|
-
import"./index-
|
|
9
|
+
} from "./index-majzj044.js";
|
|
10
|
+
import"./index-z5v766nx.js";
|
|
11
|
+
import"./index-acwxfncv.js";
|
|
12
|
+
import"./index-04as43rp.js";
|
|
13
|
+
import"./index-dgeaqwmw.js";
|
|
14
14
|
import"./index-ss469dec.js";
|
|
15
|
-
import"./index-
|
|
15
|
+
import"./index-zfp1gz9f.js";
|
|
16
16
|
import {
|
|
17
17
|
AgentScript
|
|
18
|
-
} from "./index-
|
|
19
|
-
import"./index-
|
|
20
|
-
import"./index-
|
|
21
|
-
import"./index-
|
|
18
|
+
} from "./index-40w1kqp1.js";
|
|
19
|
+
import"./index-v9jqrdd1.js";
|
|
20
|
+
import"./index-pfnh87f9.js";
|
|
21
|
+
import"./index-xftstr5s.js";
|
|
22
22
|
import {
|
|
23
23
|
getLatestPackageVersion,
|
|
24
24
|
getNpmRegistryUrl
|
|
25
|
-
} from "./index-
|
|
25
|
+
} from "./index-j3j3qc9j.js";
|
|
26
26
|
import {
|
|
27
27
|
GlobalConfig
|
|
28
28
|
} from "./index-nsj2ftxj.js";
|
|
29
29
|
import {
|
|
30
30
|
ApplicationScript
|
|
31
|
-
} from "./index-
|
|
31
|
+
} from "./index-panyahn4.js";
|
|
32
32
|
import"./index-76rn3g2c.js";
|
|
33
33
|
import {
|
|
34
34
|
LibraryScript
|
|
35
|
-
} from "./index-
|
|
35
|
+
} from "./index-s9s0n5fz.js";
|
|
36
36
|
import {
|
|
37
37
|
PackageScript
|
|
38
|
-
} from "./index-
|
|
38
|
+
} from "./index-z36qzgzp.js";
|
|
39
39
|
import {
|
|
40
40
|
Exec,
|
|
41
41
|
Workspace,
|
|
42
42
|
command,
|
|
43
43
|
runner,
|
|
44
44
|
script
|
|
45
|
-
} from "./index-
|
|
45
|
+
} from "./index-d0h48d2f.js";
|
|
46
46
|
import"./index-fgc8r6dj.js";
|
|
47
47
|
import {
|
|
48
48
|
AppExecutor,
|
|
49
49
|
LibExecutor,
|
|
50
50
|
PkgExecutor,
|
|
51
51
|
WorkspaceExecutor
|
|
52
|
-
} from "./index-
|
|
52
|
+
} from "./index-xwfg9bam.js";
|
|
53
53
|
import"./index-46tjzh6s.js";
|
|
54
54
|
import {
|
|
55
55
|
FileSys
|