@akanjs/cli 3.1.1-rc.9 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. package/.build-stamp +1 -1
  2. package/CodeAgent-35wnb7w5.js +9 -0
  3. package/{CodeTui-z5vkm9ea.js → CodeTui-h6yz2kvq.js} +1 -1
  4. package/TunnelShare-xyjpa7gx.js +14 -0
  5. package/agent.command-3r4jsck8.js +46 -0
  6. package/akanCode.js +10 -6
  7. package/{application.command-wthg8nn9.js → application.command-g7xv6ad0.js} +44 -11
  8. package/{applicationBuildRunner-t2r84sz6.js → applicationBuildRunner-qvjnhr9j.js} +9 -6
  9. package/buildBatch.proc.js +6 -6
  10. package/{cloud.command-sz11hpre.js → cloud.command-6ebygmhw.js} +17 -15
  11. package/cloud.script-0s1jybd5.js +26 -0
  12. package/{code.command-9h3yrzhe.js → code.command-mpkm2emr.js} +6 -6
  13. package/commandManifest.json +1 -1
  14. package/{context.command-15j9b7c0.js → context.command-svdh6b2w.js} +18 -17
  15. package/context.runner-ch0z3a8g.js +26 -0
  16. package/{devTui-q7k7bakd.js → devTui-evr3b35y.js} +1 -1
  17. package/{guideline.command-snh85ctf.js → guideline.command-qwp3tnjx.js} +3 -3
  18. package/guidelines/conventions/core.md +106 -0
  19. package/guidelines/conventions/rules/app.md +83 -0
  20. package/guidelines/conventions/rules/auth.md +45 -0
  21. package/guidelines/conventions/rules/config.md +56 -0
  22. package/guidelines/conventions/rules/constant.md +24 -0
  23. package/guidelines/conventions/rules/gates.md +31 -0
  24. package/guidelines/conventions/rules/layer.md +25 -0
  25. package/guidelines/conventions/rules/migration.md +27 -0
  26. package/guidelines/conventions/rules/module.md +90 -0
  27. package/guidelines/conventions/rules/page.md +56 -0
  28. package/guidelines/conventions/rules/sensitive.md +16 -0
  29. package/guidelines/conventions/rules/server.md +86 -0
  30. package/guidelines/conventions/rules/ssr.md +47 -0
  31. package/guidelines/conventions/rules/style.md +43 -0
  32. package/guidelines/conventions/rules/test.md +34 -0
  33. package/guidelines/conventions/rules/ts.md +95 -0
  34. package/guidelines/conventions/rules/tsx.md +75 -0
  35. package/guidelines/mcpRule/mcpRule.instruction.md +1 -1
  36. package/guidelines/pageRule/pageRule.instruction.md +4 -3
  37. package/guidelines/queryRule/queryRule.instruction.md +4 -0
  38. package/guidelines/workspaceRecipes/workspaceRecipes.instruction.md +3 -3
  39. package/incrementalBuilder.proc.js +6 -6
  40. package/{index-pcwzkdqb.js → index-1p0qbq3m.js} +1 -1
  41. package/{index-xb8809yb.js → index-1shvxzt0.js} +3 -3
  42. package/{index-a58emady.js → index-266dewjs.js} +11 -11
  43. package/{index-bt438yxm.js → index-3yz30c07.js} +5 -4
  44. package/{index-xjf5j657.js → index-4mj92tsh.js} +952 -47
  45. package/index-4pdts00b.js +1604 -0
  46. package/{index-42j4a8zq.js → index-8559hsz4.js} +4 -3
  47. package/{index-wcej7g4z.js → index-8scw1pjk.js} +93 -23
  48. package/{index-a5dhqkdr.js → index-96wzdhfh.js} +74 -233
  49. package/index-9bv479q5.js +1 -0
  50. package/index-9rvcs76p.js +653 -0
  51. package/index-am36s3jh.js +3582 -0
  52. package/index-b8c289dx.js +444 -0
  53. package/{index-espk51ah.js → index-dd44g6vz.js} +3 -3
  54. package/{index-3wypz6xj.js → index-eja64h28.js} +7 -3
  55. package/index-fbewhg4g.js +590 -0
  56. package/index-jje9qzyq.js +27 -0
  57. package/{index-j9vyj3dj.js → index-k5jbcxyh.js} +3 -3
  58. package/{index-2mwc0g0d.js → index-ksfgqq1x.js} +1 -1
  59. package/index-m5n3ka0p.js +18 -0
  60. package/{index-5nd1wtkv.js → index-p6x5b7hr.js} +1 -1
  61. package/{index-6txx6a9p.js → index-payhwt51.js} +21 -29
  62. package/{index-2azahjaw.js → index-qkkdhjm6.js} +2 -2
  63. package/{index-74tjjsnc.js → index-qxzrp5xt.js} +33 -37
  64. package/{index-qfp55x1y.js → index-r0k3ham2.js} +4 -4
  65. package/{index-hmt54t45.js → index-r2w2eh93.js} +4 -4
  66. package/index-r2wedvqn.js +138 -0
  67. package/{index-skk9zc1x.js → index-rnphv731.js} +2 -2
  68. package/{index-9th4gszy.js → index-s6da8ta9.js} +82 -1227
  69. package/index-tenw3mah.js +225 -0
  70. package/{index-31es1yev.js → index-tgt2fnd6.js} +107 -6
  71. package/{index-55j120r8.js → index-vxmy1p4f.js} +16 -36
  72. package/{index-301pdbzz.js → index-w4k2ragk.js} +7 -7
  73. package/{index-js6geqjn.js → index-w7q6h97v.js} +1 -1
  74. package/{index-dy0jx9ay.js → index-wwe9rsrx.js} +14 -0
  75. package/{index-2xcc2ax5.js → index-xq543a5y.js} +2 -2
  76. package/{index-0fz95kxe.js → index-xqgwjz7a.js} +1 -1
  77. package/{index-40brg4px.js → index-xxfy1jp2.js} +4 -4
  78. package/{index-905qdgqp.js → index-z4b84y6k.js} +1 -1
  79. package/index-zcf6k8a5.js +410 -0
  80. package/index.js +23 -22
  81. package/{library.command-gycrwhf1.js → library.command-2853y6mk.js} +3 -3
  82. package/{localRegistry.command-jtd8gaes.js → localRegistry.command-76ds31p4.js} +19 -15
  83. package/{module.command-v6hgs1bc.js → module.command-yfnb0abs.js} +5 -5
  84. package/{package.command-shzpcfph.js → package.command-d9s86hp9.js} +3 -3
  85. package/package.json +2 -2
  86. package/{page.command-ptxn5kqk.js → page.command-6a8a8rd1.js} +3 -3
  87. package/{pipeline.command-zz31pgax.js → pipeline.command-rt3rwd2z.js} +2 -2
  88. package/{primitive.command-a1vse91z.js → primitive.command-emcebgrq.js} +6 -6
  89. package/{projectTypecheck-2ztky9cf.js → projectTypecheck-51m7eh1f.js} +1 -1
  90. package/{prompter-76k56b37.js → prompter-hgcta8pb.js} +1 -1
  91. package/quality.command-xtrk0n3x.js +76 -0
  92. package/{repair.command-cvazbz99.js → repair.command-51szxnxx.js} +5 -5
  93. package/{routeSourceValidator-6jd0q6r6.js → routeSourceValidator-4h947v7c.js} +13 -3
  94. package/{scalar.command-0acvyp26.js → scalar.command-8qv27t82.js} +4 -4
  95. package/skills/akan-agent/SKILL.md +36 -0
  96. package/skills/akan-code/SKILL.md +1 -0
  97. package/skills/akan-debug/SKILL.md +40 -6
  98. package/skills/akan-deps/SKILL.md +1 -2
  99. package/skills/akan-mcp/SKILL.md +40 -0
  100. package/skills/akan-page/SKILL.md +44 -0
  101. package/skills/akan-query/SKILL.md +38 -0
  102. package/skills/akan-runtime/SKILL.md +40 -0
  103. package/skills/akan-scaffold/SKILL.md +16 -6
  104. package/skills/akan-transport/SKILL.md +40 -0
  105. package/skills/akan-validate/SKILL.md +13 -11
  106. package/{subspace.command-822qx2bx.js → subspace.command-pn56pnh8.js} +8 -8
  107. package/templates/__scalar/__model__/__model__.constant.ts +3 -5
  108. package/templates/__scalar/__model__/__model__.dictionary.ts +6 -5
  109. package/templates/__scalar/__model__/__model__.document.ts +3 -3
  110. package/templates/app/akan.config.ts +2 -3
  111. package/templates/app/env/env.client.ts +2 -4
  112. package/templates/app/env/env.client.type.ts +2 -3
  113. package/templates/app/env/env.server.ts +2 -3
  114. package/templates/app/lib/___appName__/__appName__.dictionary.ts +1 -2
  115. package/templates/app/lib/___appName__/__appName__.service.ts +3 -3
  116. package/templates/app/lib/___appName__/__appName__.signal.ts +5 -5
  117. package/templates/app/lib/___appName__/__appName__.store.ts +4 -6
  118. package/templates/app/lib/option.ts +2 -3
  119. package/templates/app/main.ts +2 -4
  120. package/templates/app/page/_index.tsx +3 -3
  121. package/templates/app/page/_layout.tsx +13 -10
  122. package/templates/appSample/lib/__scalar/workHistory/workHistory.constant.ts +1 -5
  123. package/templates/appSample/lib/__scalar/workHistory/workHistory.dictionary.ts +1 -1
  124. package/templates/appSample/lib/_noti/noti.signal.ts +1 -1
  125. package/templates/appSample/lib/task/Task.Template.tsx +2 -1
  126. package/templates/appSample/lib/task/Task.Unit.tsx +3 -2
  127. package/templates/appSample/lib/task/Task.Util.tsx +16 -4
  128. package/templates/appSample/lib/task/task.constant.ts +1 -5
  129. package/templates/appSample/lib/task/task.dictionary.ts +2 -8
  130. package/templates/appSample/lib/task/task.document.ts +1 -1
  131. package/templates/appSample/page/task/_index.tsx +2 -1
  132. package/templates/appSample/page/task/new.tsx +2 -1
  133. package/templates/appSample/ui/QuantityControl.tsx +5 -9
  134. package/templates/biomeForm.ts +144 -0
  135. package/templates/crudPages/[__model__Id]/edit/page.tsx +3 -3
  136. package/templates/crudPages/[__model__Id]/page.tsx +5 -5
  137. package/templates/crudPages/new/page.tsx +4 -3
  138. package/templates/crudPages/page.tsx +3 -3
  139. package/templates/crudSinglePage/page.tsx +9 -5
  140. package/templates/libRoot/akan.config.ts +2 -3
  141. package/templates/libRoot/lib/___libName__/__libName__.dictionary.ts +1 -2
  142. package/templates/libRoot/lib/___libName__/__libName__.service.ts +5 -4
  143. package/templates/libRoot/lib/___libName__/__libName__.signal.ts +6 -5
  144. package/templates/libRoot/lib/___libName__/__libName__.store.ts +5 -6
  145. package/templates/libRoot/lib/option.ts +1 -2
  146. package/templates/module/__Model__.Template.tsx +11 -10
  147. package/templates/module/__Model__.Unit.tsx +18 -5
  148. package/templates/module/__Model__.Util.tsx +9 -7
  149. package/templates/module/__Model__.View.tsx +9 -6
  150. package/templates/module/__Model__.Zone.tsx +25 -17
  151. package/templates/module/__model__.constant.ts +8 -9
  152. package/templates/module/__model__.dictionary.ts +16 -17
  153. package/templates/module/__model__.document.ts +6 -8
  154. package/templates/module/__model__.service.ts +3 -3
  155. package/templates/module/__model__.signal.ts +11 -10
  156. package/templates/module/__model__.store.ts +3 -5
  157. package/templates/service/__model__.dictionary.ts +6 -5
  158. package/templates/service/__model__.service.ts +3 -3
  159. package/templates/service/__model__.signal.ts +5 -4
  160. package/templates/service/__model__.store.ts +3 -5
  161. package/templates/workspaceRoot/.gitignore.template +3 -0
  162. package/templates/workspaceRoot/.vscode/settings.json.template +21 -21
  163. package/templates/workspaceRoot/AGENTS.md.template +4 -10
  164. package/{tunnel.command-ycmja19q.js → tunnel.command-q2h0j2en.js} +7 -7
  165. package/{typeChecker-px49mezc.js → typeChecker-j2jdnqsr.js} +1 -1
  166. package/typecheck.proc.js +6 -1
  167. package/verify.command-z1dsbmrt.js +91 -0
  168. package/{workflow.command-abb1d5xy.js → workflow.command-r3y67jeq.js} +47 -13
  169. package/workspace.command-t2f0xsrw.js +263 -0
  170. package/CodeAgent-8d5qs787.js +0 -9
  171. package/TunnelShare-qkm8zp03.js +0 -14
  172. package/agent.command-ydftceda.js +0 -25
  173. package/cloud.script-nqevg5qw.js +0 -24
  174. package/context.runner-8gg030b0.js +0 -25
  175. package/guidelines/conventions/conventions.instruction.md +0 -617
  176. package/guidelines/workspaceOnboarding/workspaceOnboarding.instruction.md +0 -291
  177. package/index-4vgbysa0.js +0 -279
  178. package/index-7md2g9vw.js +0 -6
  179. package/index-b70zct19.js +0 -856
  180. package/index-zzvvc845.js +0 -74
  181. package/quality.command-ah8qcakd.js +0 -1478
  182. package/templates/workspaceRoot/docs/AI-DEVELOPMENT.md.template +0 -69
  183. package/templates/workspaceRoot/docs/GENERATED.md.template +0 -55
  184. package/workspace.command-qm7cw29v.js +0 -521
@@ -1,69 +0,0 @@
1
- # AI Development Guide
2
-
3
- This workspace is an Akan.js project. Keep business intent in source files and let `akan sync` regenerate the
4
- repeated surfaces.
5
-
6
- ## Domain Module Shape
7
-
8
- - `apps/<app>/lib/<model>` is for database-backed domain modules.
9
- - `apps/<app>/lib/_<service>` is for service modules without their own database document.
10
- - `apps/<app>/lib/__scalar/<scalar>` is for reusable embedded value shapes.
11
- - Put model behavior in the local module before creating a parallel architecture.
12
-
13
- ## Data Flow
14
-
15
- Follow this order for domain changes:
16
-
17
- 1. `constant` defines fields, enums, and model layers.
18
- 2. `document` defines queries, filters, and document state transitions.
19
- 3. `service` owns business workflows and orchestration.
20
- 4. `signal` exposes typed endpoints, slices, and internal jobs.
21
- 5. `store` owns reusable client workflow state and actions.
22
- 6. UI files render forms, lists, details, and actions.
23
-
24
- ## When To Run Sync
25
-
26
- Run this after adding, deleting, or renaming module, UI, webkit, srvkit, or common files:
27
-
28
- ```bash
29
- akan sync <%= appName %>
30
- ```
31
-
32
- Sync regenerates barrels such as `cnst.ts`, `db.ts`, `srv.ts`, `sig.ts`, `st.ts`, `useClient.ts`, `useServer.ts`,
33
- and module `index.ts` files. Without sync, imports can point at stale generated files.
34
-
35
- ## Generated Files
36
-
37
- Do not hand-edit generated Akan files. Edit source files in the owning module and run sync or build instead.
38
- See `docs/GENERATED.md` for the generated file list.
39
-
40
- ## Server And Client Boundary
41
-
42
- - Keep server-only APIs such as `fs`, `Bun`, secrets, database adaptors, and server env access out of client code.
43
- - Client surfaces include `ui/`, `webkit/`, `*.Template.tsx`, `*.Zone.tsx`, and `*.Util.tsx` files that use
44
- `"use client"`.
45
- - Server-oriented surfaces include pages, `*.Unit.tsx`, `*.View.tsx`, `lib/`, `srvkit/`, and server entrypoints.
46
- - Treat `AKAN_PUBLIC_*` values as public.
47
-
48
- ## House Style
49
-
50
- `AGENTS.md` holds the full style guide, and `akan lint` enforces most of it. The four rules that surprise people,
51
- because the failure is silent rather than an error:
52
-
53
- - **Never hand-order Tailwind classes** — the linter sorts them, including inside `cn()`, and its output looks
54
- unnatural on purpose. Do not reorder it back.
55
- - **Never use a colour outside the semantic vocabulary** — `bg-red-500`, `bg-[#3b82f6]` and `text-base-content`
56
- compile to no CSS at all, so the element renders unstyled with no error. Use `bg-primary`, `text-foreground/70`
57
- and the other tokens defined in `page/*/styles.css`.
58
- - **`cond ? <X/> : null`, never `{cond && <X/>}`** — the latter renders the string `"false"` in a className context.
59
- - **Never wrap a form setter in a pass-through arrow** — `onChange={st.do.setXOnY}` publishes the field to agents
60
- and E2E selectors; `onChange={(v) => st.do.setXOnY(v)}` runs identically and publishes nothing.
61
-
62
- Two more that are hard errors: **never `throw new Error`** (throw `new Err("<module>.error.<key>")` with an
63
- `[en, ko]` dictionary entry), and **never import a third-party package** from a page, a barrel, or a module file —
64
- re-export it through a one-line shim in the lib's `common/`, `webkit/`, or `ui/` first.
65
-
66
- ## Abstract Documents
67
-
68
- Update `*.abstract.md` when business invariants, workflows, user-visible behavior, cross-module relationships, or
69
- agent guidance changes. Do not update it for purely mechanical formatting or regenerated file changes.
@@ -1,55 +0,0 @@
1
- # Generated Akan Files
2
-
3
- These files are generated by `akan sync`, `akan start`, or `akan build`. Do not edit them by hand because the next
4
- sync or build can overwrite local changes.
5
-
6
- ## App Entrypoints
7
-
8
- | File | Purpose |
9
- | --- | --- |
10
- | `apps/*/client.ts` | App-wide client entrypoint for generated fetch, store, and client runtime exports. |
11
- | `apps/*/server.ts` | App-wide server entrypoint for generated server, service, signal, database, and dictionary exports. |
12
- | `libs/*/client.ts`, `libs/*/server.ts`, `libs/*/index.ts` | The same entrypoints for a library. |
13
-
14
- ## Module Barrels (apps and libs alike)
15
-
16
- | File | Purpose |
17
- | --- | --- |
18
- | `{apps,libs}/*/lib/cnst.ts` | Re-exports constants and model shapes from module `*.constant.ts` files. |
19
- | `{apps,libs}/*/lib/db.ts` | Re-exports database models from module `*.document.ts` files. |
20
- | `{apps,libs}/*/lib/dict.ts` | Re-exports dictionaries from module `*.dictionary.ts` files. |
21
- | `{apps,libs}/*/lib/srv.ts` | Re-exports services from module `*.service.ts` files. |
22
- | `{apps,libs}/*/lib/sig.ts` | Re-exports endpoints, slices, and internals from module `*.signal.ts` files. |
23
- | `{apps,libs}/*/lib/st.ts` | Re-exports stores from module `*.store.ts` files. |
24
- | `{apps,libs}/*/lib/useClient.ts` | Client-safe generated imports for fetch, message, signal, and store usage. |
25
- | `{apps,libs}/*/lib/useServer.ts` | Server-safe generated imports for service, database, signal, and dictionary usage. |
26
- | `{apps,libs}/*/lib/**/index.ts` | Per-module generated barrel files. |
27
-
28
- ## Shared Surface Barrels
29
-
30
- | File | Purpose |
31
- | --- | --- |
32
- | `*/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. |
33
- | `*/webkit/index.ts` | Re-exports webkit/browser helper files. |
34
- | `*/srvkit/index.ts` | Re-exports server-kit helper files. |
35
- | `*/common/index.ts` | Re-exports common helper files. |
36
- | `*/plugin/index.ts` | Re-exports `<name>.plugin.ts` declarations. |
37
-
38
- ## How To Change Generated Output
39
-
40
- 1. Prefer `akan mcp --mode plan` to find an allowlisted workflow before editing files directly.
41
- 2. If a workflow or repair tool exists, use `akan mcp --mode apply` for `apply_workflow`, `run_validation`, or
42
- `repair_generated`.
43
- 3. Edit the source file that owns the behavior, such as `task.constant.ts`, `task.document.ts`, `task.service.ts`,
44
- `task.signal.ts`, or `task.store.ts`.
45
- 4. Run:
46
-
47
- ```bash
48
- akan sync <%= appName %>
49
- # or: akan repair generated --app <%= appName %>
50
- ```
51
-
52
- 5. Re-run the smallest relevant check, usually `akan test <%= appName %>`, `akan lint <%= appName %>`,
53
- `akan doctor --strict`, or `akan build <%= appName %>`.
54
-
55
- If a generated file looks wrong, fix the source convention or sync input rather than patching the generated file.
@@ -1,521 +0,0 @@
1
- // @bun
2
- import {
3
- Exec,
4
- Workspace,
5
- runner,
6
- script,
7
- command
8
- } from "./index-3wypz6xj.js";
9
- import {
10
- FileSys2
11
- } from "./index-52w0fvh8.js";
12
- import {
13
- extractAgentBlock,
14
- collectScopeRecipeSources,
15
- renderScopeAgentBlock,
16
- Linter,
17
- WorkspaceExecutor,
18
- SysExecutor,
19
- AppExecutor,
20
- LibExecutor,
21
- PkgExecutor
22
- } from "./index-wcej7g4z.js";
23
- import {
24
- countBlocking,
25
- formatStyleContract,
26
- ThemeValidator
27
- } from "./index-62md4dwy.js";
28
- import {
29
- collectRecipeSources2,
30
- scanRecipes2
31
- } from "./index-hj6w4ka1.js";
32
- import"./index-xjf5j657.js";
33
- import"./index-31es1yev.js";
34
- import"./index-zzvvc845.js";
35
- import {
36
- AgentScript
37
- } from "./index-4vgbysa0.js";
38
- import"./index-5nd1wtkv.js";
39
- import"./index-bt438yxm.js";
40
- import"./index-js6geqjn.js";
41
- import"./index-m9jj544v.js";
42
- import"./index-xb8809yb.js";
43
- import"./index-0fz95kxe.js";
44
- import {
45
- LibraryScript
46
- } from "./index-2xcc2ax5.js";
47
- import {
48
- ApplicationScript
49
- } from "./index-9th4gszy.js";
50
- import"./index-7md2g9vw.js";
51
- import"./index-2azahjaw.js";
52
- import"./index-tvehn2sp.js";
53
- import {
54
- PackageScript
55
- } from "./index-42j4a8zq.js";
56
- import {
57
- getNpmRegistryUrl,
58
- getLatestPackageVersion
59
- } from "./index-6txx6a9p.js";
60
- import {
61
- CloudScript2
62
- } from "./index-301pdbzz.js";
63
- import"./index-a58emady.js";
64
- import"./index-j9vyj3dj.js";
65
- import"./index-905qdgqp.js";
66
- import"./index-hmt54t45.js";
67
- import"./index-74tjjsnc.js";
68
- import"./index-skk9zc1x.js";
69
- import"./index-b70zct19.js";
70
- import {
71
- ContextScript
72
- } from "./index-qfp55x1y.js";
73
- import"./index-pcwzkdqb.js";
74
-
75
- // pkgs/@akanjs/cli/workspace/workspace.runner.ts
76
- import { mkdir, writeFile } from "fs/promises";
77
- import path from "path";
78
-
79
- // pkgs/@akanjs/devkit/biomeBase.ts
80
- var biomeVersion = "2.5.14";
81
-
82
- // pkgs/@akanjs/cli/workspace/workspace.runner.ts
83
- import { Ed25519Key } from "akanjs/server/ed25519Key";
84
- var defaultWorkspacePeerDependencies = new Set([
85
- "@react-spring/web",
86
- "@use-gesture/react",
87
- "chance",
88
- "react",
89
- "react-dom",
90
- "react-icons",
91
- "react-refresh",
92
- "react-server-dom-webpack",
93
- "react-spring",
94
- "scheduler",
95
- "tailwind-scrollbar",
96
- "tailwindcss",
97
- "typescript"
98
- ]);
99
- var defaultWorkspaceTypeDependencies = { "@types/react": "^19.3.0", "@types/react-dom": "^19.3.0" };
100
- var defaultMaxDiagnostics = 200;
101
-
102
- class WorkspaceRunner extends runner("workspace") {
103
- async machineKeygen(workspace, out) {
104
- const file = path.resolve(workspace.workspaceRoot, out);
105
- const { privatePem, publicKey } = Ed25519Key.generate();
106
- await mkdir(path.dirname(file), { recursive: true });
107
- try {
108
- await writeFile(file, privatePem, { mode: 384, flag: "wx" });
109
- } catch (error) {
110
- if (error.code === "EEXIST")
111
- throw new Error(`${file} exists; machine-keygen never overwrites a key. Name another file.`);
112
- throw error;
113
- }
114
- return { file, publicKey };
115
- }
116
- async generateAgentRules(workspace, { overwrite = false, cursorRules = true } = {}) {
117
- const [appNames] = await workspace.getExecs();
118
- const dict = { repoName: workspace.repoName, appName: appNames[0] ?? "app" };
119
- const templates = [
120
- [".", "workspaceRoot/AGENTS.md.template"],
121
- [".", "workspaceRoot/CLAUDE.md.template"],
122
- ...cursorRules ? [[".cursor/rules", "workspaceRoot/.cursor/rules/akan.mdc.template"]] : []
123
- ];
124
- const created = [];
125
- for (const [basePath, template] of templates)
126
- created.push(...await workspace.applyTemplate({ basePath, template, dict, overwrite }));
127
- return created;
128
- }
129
- async createWorkspace(repoName, appName, {
130
- dirname = ".",
131
- init = true,
132
- akanVersion,
133
- registryUrl,
134
- owner = ""
135
- }) {
136
- const cwdPath = process.cwd();
137
- const workspaceRoot = path.resolve(cwdPath, dirname, repoName);
138
- const normalizedRegistryUrl = registryUrl ? getNpmRegistryUrl(registryUrl) : undefined;
139
- const workspace = WorkspaceExecutor.fromRoot({ workspaceRoot, repoName });
140
- const templateSpinner = workspace.spinning(`Creating workspace template files in ${workspaceRoot}...`);
141
- const latestTypesBunVersion = await getLatestPackageVersion("@types/bun", "latest", normalizedRegistryUrl);
142
- await workspace.applyTemplate({
143
- basePath: ".",
144
- template: "workspaceRoot",
145
- dict: { repoName, appName, serveDomain: "localhost", owner }
146
- });
147
- if (normalizedRegistryUrl)
148
- await workspace.writeFile(".npmrc", `registry=${normalizedRegistryUrl}/
149
- `);
150
- templateSpinner.succeed(`Workspace files created in ${workspaceRoot}`);
151
- const [rootPackageJson, peerDependencies] = await Promise.all([
152
- workspace.getPackageJson(),
153
- this.#getAkanPeerDependencies()
154
- ]);
155
- const { typescript, ...dependencies } = peerDependencies;
156
- const packageJson = {
157
- ...rootPackageJson,
158
- dependencies: {
159
- ...rootPackageJson.dependencies,
160
- ...dependencies,
161
- akanjs: akanVersion
162
- },
163
- devDependencies: {
164
- ...rootPackageJson.devDependencies,
165
- "@biomejs/biome": biomeVersion,
166
- "@types/bun": latestTypesBunVersion,
167
- ...defaultWorkspaceTypeDependencies,
168
- "@akanjs/devkit": akanVersion,
169
- "@akanjs/cli": akanVersion,
170
- ...typescript ? { typescript } : {}
171
- }
172
- };
173
- await workspace.setPackageJson(packageJson);
174
- if (init) {
175
- const installSpinner = workspace.spinning("Installing dependencies with bun...");
176
- await workspace.spawn("bun", ["install"]);
177
- installSpinner.succeed("Dependencies installed with bun");
178
- }
179
- return workspace;
180
- }
181
- async#getAkanPeerDependencies() {
182
- const [packageJson, cliPackageJson] = await Promise.all([this.#getAkanPackageJson(), this.#getCliPackageJson()]);
183
- const dependencyVersions = {
184
- ...packageJson.dependencies,
185
- ...packageJson.peerDependencies,
186
- ...cliPackageJson.dependencies
187
- };
188
- return Object.fromEntries(Object.entries(dependencyVersions).filter(([dependency]) => defaultWorkspacePeerDependencies.has(dependency)));
189
- }
190
- async#getCliPackageJson() {
191
- const found = await this.#findPackageJson("@akanjs/cli", [
192
- path.join(import.meta.dir, "../package.json"),
193
- path.join(import.meta.dir, "package.json"),
194
- path.join(path.dirname(Bun.main), "package.json")
195
- ]);
196
- return found ?? { name: "@akanjs/cli", version: "0.0.0", description: "@akanjs/cli" };
197
- }
198
- async#getAkanPackageJson() {
199
- const ancestors = [];
200
- for (let current = import.meta.dir, depth = 0;depth < 6; depth++) {
201
- ancestors.push(path.join(current, "package.json"));
202
- if (path.dirname(current) === current)
203
- break;
204
- current = path.dirname(current);
205
- }
206
- const found = await this.#findPackageJson("akanjs", [
207
- path.join(import.meta.dir, "../../../akanjs/package.json"),
208
- path.join(process.cwd(), "pkgs/akanjs/package.json"),
209
- path.join(path.dirname(Bun.main), "node_modules/akanjs/package.json"),
210
- ...ancestors
211
- ]);
212
- if (!found)
213
- throw new Error(`[workspace] failed to locate akanjs package.json from ${import.meta.dir}`);
214
- return found;
215
- }
216
- async#findPackageJson(name, candidates) {
217
- try {
218
- candidates.unshift(Bun.resolveSync(`${name}/package.json`, import.meta.dir));
219
- } catch {}
220
- for (const packageJsonPath of candidates) {
221
- if (!await Bun.file(packageJsonPath).exists())
222
- continue;
223
- const packageJson = await FileSys2.readJson(packageJsonPath);
224
- if (packageJson.name === name)
225
- return packageJson;
226
- }
227
- return null;
228
- }
229
- async lint(exec, workspace, { fix = true, maxDiagnostics = defaultMaxDiagnostics } = {}) {
230
- const configPath = await WorkspaceRunner.resolveBiomeConfigPath(workspace);
231
- const [biome, ...biomeArgs] = Linter.biomeCommand(workspace.workspaceRoot);
232
- await workspace.spawn(biome, [
233
- ...biomeArgs,
234
- "check",
235
- ...fix ? ["--write"] : [],
236
- "--no-errors-on-unmatched",
237
- `--max-diagnostics=${maxDiagnostics > 0 ? maxDiagnostics : "none"}`,
238
- ...configPath ? ["--config-path", configPath] : [],
239
- exec.cwdPath
240
- ]);
241
- await this.#enforceStyleContract(exec);
242
- await this.#enforceRecipeGate(exec);
243
- await this.#enforceAgentsIndex(exec);
244
- }
245
- static async resolveBiomeConfigPath(workspace) {
246
- for (const fileName of ["biome.json", "biome.jsonc"]) {
247
- const configPath = path.join(workspace.workspaceRoot, fileName);
248
- if (await Bun.file(configPath).exists())
249
- return configPath;
250
- }
251
- return null;
252
- }
253
- async#enforceAgentsIndex(exec) {
254
- if (!(exec instanceof SysExecutor))
255
- return;
256
- const scope = { type: exec.type, name: exec.name };
257
- const scanInfo = await exec.scan({ write: false });
258
- const sources = await collectScopeRecipeSources(exec.workspace.workspaceRoot, scope, scanInfo.getScanResult().libDeps);
259
- const expected = renderScopeAgentBlock(scope, scanRecipes2(sources));
260
- const existing = await exec.exists("AGENTS.md") ? await exec.readFile("AGENTS.md") : null;
261
- const actual = existing ? extractAgentBlock(existing) : null;
262
- if (actual === expected.trim())
263
- return;
264
- throw new Error(`[agentsIndex] The recipe index in ${scope.type}s/${scope.name}/AGENTS.md is stale: it differs from the recipe ` + `sources. Run \`akan sync ${scope.name}\` to regenerate it.`);
265
- }
266
- async#enforceRecipeGate(exec) {
267
- const cwdPath = exec.cwdPath;
268
- if (!cwdPath)
269
- return;
270
- const uiDir = path.join(cwdPath, "ui");
271
- const sources = [
272
- ...await collectRecipeSources2(uiDir, "ui/Recipe"),
273
- ...await collectRecipeSources2(uiDir, "ui/recipe", "recipe")
274
- ];
275
- if (sources.length === 0)
276
- return;
277
- const offenders = scanRecipes2(sources).filter((recipe) => !Object.values(recipe.variants).some((values) => values.length >= 2 || values.length === 1 && values[0] === "true"));
278
- if (offenders.length === 0)
279
- return;
280
- throw new Error(`[recipeGate] variant-less recipe(s): ${[...new Set(offenders.map((recipe) => recipe.name))].join(", ")}
281
- ` + "A look with nothing to pick is not a recipe: promote one that has its own markup to a component, and keep " + "a skin passed into another component's className as a shared class constant.");
282
- }
283
- async#enforceStyleContract(exec) {
284
- const cwdPath = exec.cwdPath;
285
- if (!cwdPath)
286
- return;
287
- const stylesCssPath = path.join(cwdPath, "page", "styles.css");
288
- if (!await Bun.file(stylesCssPath).exists())
289
- return;
290
- const violations = {
291
- theme: new ThemeValidator().validate(await Bun.file(stylesCssPath).text())
292
- };
293
- const blocking = countBlocking(violations);
294
- if (blocking === 0)
295
- return;
296
- throw new Error(`[themeValidator] ${blocking} blocking contrast violation(s):
297
- ${formatStyleContract(violations)}
298
-
299
- ` + "Raise the foreground/background contrast of these theme token values to the WCAG threshold.");
300
- }
301
- async writeTopLevelEnv(workspace, devProjectId) {
302
- await workspace.writeFile(".env", `AKAN_WORKSPACE_ID=${devProjectId}
303
-
304
- # organization configuration, no need to change
305
- AKAN_PUBLIC_REPO_NAME=${workspace.repoName}
306
-
307
- # serve domain, it changes the domain of the server.
308
- AKAN_PUBLIC_SERVE_DOMAIN=try.akanjs.com
309
-
310
- # development branch, debug, develop, main, etc. mainly it changes databases.
311
- AKAN_PUBLIC_ENV=local
312
-
313
- # local, cloud, edge it changes the connection point of the clients.
314
- AKAN_PUBLIC_OPERATION_MODE=local
315
-
316
- # log level, debug, info, warn, error
317
- AKAN_PUBLIC_LOG_LEVEL=debug
318
- `);
319
- }
320
- }
321
-
322
- // pkgs/@akanjs/cli/workspace/workspace.script.ts
323
- import { Logger } from "akanjs/common";
324
- class WorkspaceScript extends script("workspace", [
325
- WorkspaceRunner,
326
- ApplicationScript,
327
- LibraryScript,
328
- PackageScript,
329
- CloudScript2,
330
- ContextScript,
331
- AgentScript
332
- ]) {
333
- async createWorkspace(repoName, appName, {
334
- dirname = ".",
335
- installLibs = false,
336
- init = true,
337
- registryUrl,
338
- owner,
339
- mcpInstall = true,
340
- agentInstall = true
341
- }) {
342
- const akanVersion = await this.packageScript.version(null, { log: false });
343
- const workspace = await this.workspaceRunner.createWorkspace(repoName, appName, {
344
- dirname,
345
- init,
346
- akanVersion,
347
- ...registryUrl ? { registryUrl } : {},
348
- ...owner ? { owner } : {}
349
- });
350
- if (installLibs) {
351
- await this.libraryScript.installLibrary(workspace, "util");
352
- await this.libraryScript.installLibrary(workspace, "shared");
353
- }
354
- await this.applicationScript.createApplication(appName, workspace, {
355
- libs: installLibs ? ["util", "shared"] : [],
356
- sample: true
357
- });
358
- await workspace.applyTemplate({
359
- basePath: `apps/${appName}`,
360
- template: "appSample",
361
- dict: { appName },
362
- options: { libs: installLibs ? ["util", "shared"] : [] }
363
- });
364
- if (agentInstall)
365
- await this.agentScript.agent(workspace, "install", "all", { force: true });
366
- if (mcpInstall)
367
- await this.contextScript.mcpInstall(workspace, "all", { force: true });
368
- const gitSpinner = workspace.spinning("Initializing git repository and commit...");
369
- try {
370
- await workspace.commit("Initial commit", { init: true });
371
- gitSpinner.succeed("Git repository initialized and committed");
372
- } catch (_) {
373
- gitSpinner.fail("Git repository initialization failed. It's not fatal, you can commit manually");
374
- }
375
- Logger.rawLog(`
376
- \uD83C\uDF89 Welcome aboard! Workspace created in ${workspace.workspaceRoot}`);
377
- Logger.rawLog(`\uD83D\uDE80 Run \`cd ${workspace.workspaceRoot} && akan start ${appName}\` to start the development server.`);
378
- Logger.rawLog(`
379
- \uD83D\uDC4B Happy coding!`);
380
- }
381
- async generateAgentRules(workspace, { overwrite = false, cursorRules = true } = {}) {
382
- const spinner = workspace.spinning("Generating agent rules...");
383
- const files = await this.workspaceRunner.generateAgentRules(workspace, { overwrite, cursorRules });
384
- if (files.some((file) => file.filePath.endsWith("AGENTS.md")))
385
- await this.agentScript.agent(workspace, "install", "agents-md", { force: overwrite });
386
- spinner.succeed(`Agent rules ready (${files.length} file${files.length === 1 ? "" : "s"})`);
387
- }
388
- async machineKeygen(workspace, out) {
389
- const { file, publicKey } = await this.workspaceRunner.machineKeygen(workspace, out);
390
- const access = process.platform === "win32" ? "; Windows gives it the permissions of its folder, so keep it in one only you can read" : " (mode 600)";
391
- Logger.rawLog(`Wrote the private key to ${file}${access}. Set it as AKAN_MACHINE_PRIVATE_KEY on the server that issues machine tokens; nothing else needs it.`);
392
- Logger.rawLog(`A server that only verifies them takes the public key:
393
- AKAN_MACHINE_PUBLIC_KEY=${publicKey}`);
394
- }
395
- async lint(exec, workspace, { fix = true, maxDiagnostics } = {}) {
396
- if (exec instanceof AppExecutor)
397
- await this.applicationScript.sync(exec);
398
- else if (exec instanceof LibExecutor)
399
- await this.libraryScript.syncLibrary(exec);
400
- const spinner = workspace.spinning(`Linting${fix ? " with fix" : ""}...`);
401
- try {
402
- await this.workspaceRunner.lint(exec, workspace, { fix, maxDiagnostics });
403
- spinner.succeed("Lint completed with no errors");
404
- } catch (error) {
405
- spinner.fail("Lint failed with errors");
406
- throw error;
407
- }
408
- }
409
- async lintAll(workspace, { fix = true, maxDiagnostics } = {}) {
410
- const [appNames, libNames, pkgNames] = await workspace.getExecs();
411
- const options = { fix, maxDiagnostics };
412
- await Promise.all(appNames.map((appName) => this.applicationScript.sync(AppExecutor.from(workspace, appName))));
413
- await Promise.all(libNames.map((libName) => this.libraryScript.syncLibrary(LibExecutor.from(workspace, libName))));
414
- await Promise.all([
415
- ...appNames.map((appName) => this.workspaceRunner.lint(AppExecutor.from(workspace, appName), workspace, options)),
416
- ...libNames.map((libName) => this.workspaceRunner.lint(LibExecutor.from(workspace, libName), workspace, options)),
417
- ...pkgNames.filter((pkgName) => pkgName !== "contract").map((pkgName) => this.workspaceRunner.lint(PkgExecutor.from(workspace, pkgName), workspace, options))
418
- ]);
419
- }
420
- async syncAll(workspace) {
421
- const [appNames, libNames] = await workspace.getExecs();
422
- for (const libName of libNames)
423
- await this.libraryScript.syncLibrary(LibExecutor.from(workspace, libName));
424
- for (const appName of appNames)
425
- await this.applicationScript.sync(AppExecutor.from(workspace, appName));
426
- }
427
- async init(devProjectId, workspace, { host } = {}) {
428
- const [bunfigExists, packageJsonExists, tsconfigExists] = await Promise.all([
429
- workspace.exists("bunfig.toml"),
430
- workspace.exists("package.json"),
431
- workspace.exists("tsconfig.json")
432
- ]);
433
- const isRoot = bunfigExists && packageJsonExists && tsconfigExists;
434
- if (!isRoot)
435
- throw new Error("Current directory is not a root workspace");
436
- const spinner = workspace.spinning("Initializing workspace...");
437
- try {
438
- await this.workspaceRunner.writeTopLevelEnv(workspace, devProjectId);
439
- await this.cloudScript.downloadEnv(workspace, devProjectId, { host });
440
- spinner.succeed("Workspace initialized");
441
- } catch (error) {
442
- spinner.fail("Workspace initialization failed");
443
- throw error;
444
- }
445
- }
446
- }
447
-
448
- // pkgs/@akanjs/cli/workspace/workspace.command.ts
449
- var maxDiagnosticsOption = {
450
- desc: "How many diagnostics Biome prints before truncating (0 for no limit)",
451
- default: defaultMaxDiagnostics
452
- };
453
-
454
- class WorkspaceCommand extends command("workspace", [WorkspaceScript], ({ public: target }) => ({
455
- createWorkspace: target({ desc: "Create a new Akan.js workspace", runsOnWorkspaceRoot: false }).arg("workspaceName", String, { desc: "what is the name of your organization?" }).option("app", String, { desc: "what is the codename of your first application? (e.g. myapp)" }).option("dir", String, {
456
- desc: "directory of workspace",
457
- default: process.env.USE_AKANJS_PKGS === "true" ? "local" : "."
458
- }).option("libs", Boolean, {
459
- desc: "Do you want to install shared and util libraries? (admin, user file, etc.)",
460
- enum: [
461
- { label: "No, I want to start with empty workspace (Recommended)", value: false },
462
- {
463
- label: "Yes, I want to accelerate development by installing shared and util libraries (for akanjs experts)",
464
- value: true
465
- }
466
- ],
467
- default: false
468
- }).option("init", Boolean, { desc: "Do you want to initialize the workspace? (Recommended)", default: true }).option("registry", String, {
469
- desc: "npm registry URL for installing Akan packages",
470
- default: process.env.AKAN_NPM_REGISTRY ?? "https://registry.npmjs.org"
471
- }).option("owner", String, { desc: "owner of the workspace", default: process.env.GITHUB_OWNER, nullable: true }).option("mcpInstall", Boolean, {
472
- desc: "Install the Akan MCP server config for Cursor, Claude Code, and Codex? (Recommended)",
473
- default: true
474
- }).option("agentInstall", Boolean, {
475
- flag: "A",
476
- desc: "Install Akan agent rules (AGENTS.md, CLAUDE.md, Cursor)? (Recommended)",
477
- default: true
478
- }).exec(async function(workspaceName, app, dir, libs, init, registry, owner, mcpInstall, agentInstall) {
479
- const appName = app || "app";
480
- await this.workspaceScript.createWorkspace(workspaceName.toLowerCase().replace(/ /g, "-"), appName.toLowerCase().replace(/ /g, "-"), {
481
- dirname: dir,
482
- installLibs: libs,
483
- init,
484
- owner,
485
- mcpInstall,
486
- agentInstall,
487
- ...registry ? { registryUrl: registry } : {}
488
- });
489
- }),
490
- generateAgentRules: target({
491
- desc: "Generate AGENTS.md, CLAUDE.md, and optional Cursor rules for Akan coding agents"
492
- }).option("overwrite", Boolean, { desc: "Overwrite existing agent rule files", default: false }).option("cursorRules", Boolean, { desc: "Generate .cursor/rules/akan.mdc", default: true }).with(Workspace).exec(async function(overwrite, cursorRules, workspace) {
493
- await this.workspaceScript.generateAgentRules(workspace, { overwrite, cursorRules });
494
- }),
495
- lint: target({ desc: "Lint and fix code in a specific app/lib/pkg" }).with(Exec).option("fix", Boolean, { default: true }).option("maxDiagnostics", Number, maxDiagnosticsOption).with(Workspace).exec(async function(exec, fix, maxDiagnostics, workspace) {
496
- await this.workspaceScript.lint(exec, workspace, { fix, maxDiagnostics });
497
- }),
498
- lintAll: target({ desc: "Lint and fix code in all apps and libraries" }).option("fix", Boolean, { default: true }).option("maxDiagnostics", Number, maxDiagnosticsOption).with(Workspace).exec(async function(fix, maxDiagnostics, workspace) {
499
- await this.workspaceScript.lintAll(workspace, { fix, maxDiagnostics });
500
- }),
501
- machineKeygen: target({
502
- desc: "Make an Ed25519 key for machine tokens: write the private key to a file, print the public key"
503
- }).arg("out", String, {
504
- desc: "file the private key is written to (mode 600; on Windows, its folder's permissions); an existing one is refused"
505
- }).with(Workspace).exec(async function(out, workspace) {
506
- await this.workspaceScript.machineKeygen(workspace, out);
507
- }),
508
- syncAll: target({ desc: "Sync dependencies and configuration for all apps and libraries" }).with(Workspace).exec(async function(workspace) {
509
- await this.workspaceScript.syncAll(workspace);
510
- }),
511
- init: target({ desc: "Initialize the workspace", runsOnWorkspaceRoot: false }).arg("devProjectId", String, { desc: "the ID of the workspace" }).option("host", String, {
512
- desc: "host of the cloud to target (default: cloud.host of the root akan.config.ts, else Akan Cloud)",
513
- nullable: true
514
- }).with(Workspace).exec(async function(devProjectId, host, workspace) {
515
- await this.workspaceScript.init(devProjectId, workspace, { host });
516
- })
517
- })) {
518
- }
519
- export {
520
- WorkspaceCommand
521
- };