@akanjs/cli 3.1.1-rc.8 → 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-rqxarxsn.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-14xsthcr.js → application.command-g7xv6ad0.js} +46 -13
  8. package/{applicationBuildRunner-t2r84sz6.js → applicationBuildRunner-qvjnhr9j.js} +9 -6
  9. package/buildBatch.proc.js +6 -6
  10. package/{cloud.command-rmw1kcf1.js → cloud.command-6ebygmhw.js} +17 -15
  11. package/cloud.script-0s1jybd5.js +26 -0
  12. package/{code.command-719k3e9q.js → code.command-mpkm2emr.js} +6 -6
  13. package/commandManifest.json +1 -1
  14. package/{context.command-c4t4z1vy.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-8w76g4rm.js → index-266dewjs.js} +11 -11
  43. package/{index-5max10jx.js → index-3yz30c07.js} +72 -53
  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-5phjb48k.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-hmmv2cah.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-0p37cz91.js → index-payhwt51.js} +21 -29
  62. package/{index-myc22sgv.js → index-qkkdhjm6.js} +5 -4
  63. package/{index-74tjjsnc.js → index-qxzrp5xt.js} +33 -37
  64. package/{index-zrte51fn.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-pa3c2mb8.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-8ap5z1n5.js → index-vxmy1p4f.js} +16 -36
  72. package/{index-mdqr41sp.js → index-w4k2ragk.js} +7 -7
  73. package/{index-qd5km521.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-2t3fghje.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-kvxmyxtf.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-kxv0ddmp.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-3sy7kjgj.js +0 -9
  171. package/TunnelShare-2ef94kha.js +0 -14
  172. package/agent.command-ydftceda.js +0 -25
  173. package/cloud.script-v1ysyerg.js +0 -24
  174. package/context.runner-qb15sjf8.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-tsc99yec.js +0 -521
@@ -0,0 +1,653 @@
1
+ // @bun
2
+ import {
3
+ runner,
4
+ script,
5
+ ExitCodeError,
6
+ markCliErrorPrinted
7
+ } from "./index-eja64h28.js";
8
+ import {
9
+ AGENT_BLOCK_START,
10
+ AGENT_BLOCK_END,
11
+ stampBlockVersion,
12
+ readDevkitVersion,
13
+ upsertAgentBlock,
14
+ renderRecipeEntries,
15
+ CLAUDE_COMMENT_RULE,
16
+ AppExecutor,
17
+ LibExecutor
18
+ } from "./index-8scw1pjk.js";
19
+ import {
20
+ ConventionSet,
21
+ Prompter2
22
+ } from "./index-r2wedvqn.js";
23
+ import {
24
+ collectRecipeSources2,
25
+ scanRecipes2
26
+ } from "./index-hj6w4ka1.js";
27
+ import {
28
+ AkanContextAnalyzer
29
+ } from "./index-tgt2fnd6.js";
30
+ import {
31
+ ApplicationRunner,
32
+ VerifyScope
33
+ } from "./index-s6da8ta9.js";
34
+ import {
35
+ WorkspaceRunner
36
+ } from "./index-am36s3jh.js";
37
+ import {
38
+ VerifyComments,
39
+ VerifyPipeline,
40
+ VerifyReport
41
+ } from "./index-b8c289dx.js";
42
+ import {
43
+ akanCodePaths2
44
+ } from "./index-jje9qzyq.js";
45
+
46
+ // pkgs/@akanjs/cli/agent/agent.script.ts
47
+ import { Logger as Logger3 } from "akanjs/common";
48
+
49
+ // pkgs/@akanjs/devkit/agentAssets.ts
50
+ import fsPromise from "fs/promises";
51
+ import path from "path";
52
+ class AgentAssets {
53
+ static marker = "<!-- akan:generated -->";
54
+ static ruleDir = ".claude/rules/akan";
55
+ static skillRoots = [".claude/skills", ".agents/skills"];
56
+ static referenceLimit = 28000;
57
+ static ownedGlobs = [
58
+ ".claude/rules/akan/*.md",
59
+ ".cursor/rules/akan-*.mdc",
60
+ ".claude/skills/akan-*/**",
61
+ ".agents/skills/akan-*/**"
62
+ ];
63
+ static skillReferences = {
64
+ "akan-validate": [],
65
+ "akan-scaffold": ["workspaceRecipes"],
66
+ "akan-module": ["moduleOverview", "modelConstant", "modelDictionary", "fieldRule"],
67
+ "akan-scalar": ["scalarModule", "scalarConstant", "scalarDictionary"],
68
+ "akan-service": ["modelService", "modelSignal", "modelDocument"],
69
+ "akan-store": ["modelStore"],
70
+ "akan-ui": [
71
+ "ssrRule",
72
+ "cssRule",
73
+ "componentRule",
74
+ "recipeRule",
75
+ "modelTemplate",
76
+ "modelUnit",
77
+ "modelView",
78
+ "modelZone",
79
+ "modelUtil",
80
+ "framework"
81
+ ],
82
+ "akan-err": [],
83
+ "akan-deps": [],
84
+ "akan-debug": [],
85
+ "akan-page": ["pageRule"],
86
+ "akan-query": ["queryRule"],
87
+ "akan-transport": ["transportRule"],
88
+ "akan-runtime": ["runtimeRule"],
89
+ "akan-mcp": ["mcpRule"],
90
+ "akan-agent": ["agentRule"]
91
+ };
92
+ static async rules({ appendix = {} } = {}) {
93
+ const conventions = await Prompter2.getConventionSet();
94
+ return conventions.rules.flatMap((rule) => AgentAssets.#ruleFiles(rule, appendix[rule.name]));
95
+ }
96
+ static rulePath(name) {
97
+ return `${AgentAssets.ruleDir}/${name}.md`;
98
+ }
99
+ static #ruleFiles(rule, appendix) {
100
+ const globs = rule.paths.flatMap((glob) => ConventionSet.expand(glob));
101
+ const body = appendix ? `${rule.body}
102
+
103
+ ${appendix.trim()}` : rule.body;
104
+ const claude = `---
105
+ description: ${rule.description}
106
+ paths:
107
+ ${globs.map((glob) => ` - "${glob}"`).join(`
108
+ `)}
109
+ ---
110
+
111
+ ${AgentAssets.marker}
112
+
113
+ ${body}
114
+ `;
115
+ const cursor = `---
116
+ description: ${rule.description}
117
+ globs: ${globs.join(",")}
118
+ alwaysApply: false
119
+ ---
120
+
121
+ ${AgentAssets.marker}
122
+
123
+ @${AgentAssets.rulePath(rule.name)}
124
+ `;
125
+ return [
126
+ { path: AgentAssets.rulePath(rule.name), content: claude },
127
+ { path: `.cursor/rules/akan-${rule.name}.mdc`, content: cursor }
128
+ ];
129
+ }
130
+ static async skills() {
131
+ const dir = akanCodePaths2.builtinSkillsDir();
132
+ if (!dir)
133
+ return [];
134
+ const assets = [];
135
+ for (const [name, guidelines] of Object.entries(AgentAssets.skillReferences)) {
136
+ const source = await fsPromise.readFile(path.join(dir, name, "SKILL.md"), "utf-8");
137
+ const index = [];
138
+ for (const guideline of guidelines) {
139
+ const parts = AgentAssets.split(await Prompter2.getInstruction(guideline));
140
+ parts.forEach((part, idx) => {
141
+ const file = parts.length === 1 ? `${guideline}.md` : `${guideline}-${idx + 1}.md`;
142
+ const referencePath = `.agents/skills/${name}/references/${file}`;
143
+ assets.push({ path: referencePath, content: `${AgentAssets.marker}
144
+
145
+ ${part.text.trim()}
146
+ ` });
147
+ index.push(`- \`${referencePath}\` \u2014 ${AgentAssets.#summarize(part.headings)}`);
148
+ });
149
+ }
150
+ const skill = AgentAssets.#skillFile(source, index);
151
+ for (const root of AgentAssets.skillRoots)
152
+ assets.push({ path: `${root}/${name}/SKILL.md`, content: skill });
153
+ }
154
+ return assets;
155
+ }
156
+ static split(markdown) {
157
+ const sections = [];
158
+ let fenced = false;
159
+ for (const line of markdown.trim().split(`
160
+ `)) {
161
+ if (line.startsWith("```"))
162
+ fenced = !fenced;
163
+ const heading = !fenced && line.startsWith("## ") ? line.slice(3).trim() : null;
164
+ const last = sections.at(-1);
165
+ if (heading !== null || !last)
166
+ sections.push({ text: line, headings: heading === null ? [] : [heading] });
167
+ else
168
+ last.text += `
169
+ ${line}`;
170
+ }
171
+ const parts = [];
172
+ for (const section of sections) {
173
+ const last = parts.at(-1);
174
+ if (last && last.text.length + section.text.length + 1 <= AgentAssets.referenceLimit) {
175
+ last.text += `
176
+ ${section.text}`;
177
+ last.headings.push(...section.headings);
178
+ } else
179
+ parts.push({ text: section.text, headings: [...section.headings] });
180
+ }
181
+ return parts;
182
+ }
183
+ static #summarize(headings) {
184
+ if (headings.length === 0)
185
+ return "the whole guideline";
186
+ const shown = headings.slice(0, 5).join(" \xB7 ");
187
+ return headings.length > 5 ? `${shown} \xB7 \u2026` : shown;
188
+ }
189
+ static #skillFile(source, index) {
190
+ const match = /^---\n[\s\S]*?\n---\n/.exec(source);
191
+ const front = match?.[0] ?? "";
192
+ const body = source.slice(front.length).trim();
193
+ const references = index.length ? `
194
+
195
+ ## References
196
+
197
+ The full guidelines, split where each part fits one read; \`akan guideline show <name>\` prints the same text.
198
+
199
+ ${index.join(`
200
+ `)}` : "";
201
+ return `${front}
202
+ ${AgentAssets.marker}
203
+
204
+ ${body}${references}
205
+ `;
206
+ }
207
+ static async generatedFiles(workspaceRoot) {
208
+ const found = [];
209
+ for (const pattern of AgentAssets.ownedGlobs) {
210
+ for (const file of new Bun.Glob(pattern).scanSync({ cwd: workspaceRoot, dot: true, onlyFiles: true })) {
211
+ const content = await Bun.file(path.join(workspaceRoot, file)).text();
212
+ if (content.includes(AgentAssets.marker))
213
+ found.push(file.split(path.sep).join("/"));
214
+ }
215
+ }
216
+ return found.sort((a, b) => a.localeCompare(b));
217
+ }
218
+ }
219
+
220
+ // pkgs/@akanjs/cli/agent/agent.runner.ts
221
+ import { Logger as Logger2 } from "akanjs/common";
222
+
223
+ // pkgs/@akanjs/cli/agent/agentHook.ts
224
+ import { realpathSync } from "fs";
225
+ import path2 from "path";
226
+ import { Logger } from "akanjs/common";
227
+ class AgentHook {
228
+ static events = ["pre-edit", "post-edit", "stop"];
229
+ static editTools = "Edit|Write";
230
+ static generated = [
231
+ "apps/*/client.ts",
232
+ "apps/*/server.ts",
233
+ "{apps,libs}/*/lib/{cnst,db,dict,sig,srv,st,useClient,useServer}.ts",
234
+ "{apps,libs}/*/lib/**/index.ts",
235
+ "{apps,libs}/*/{ui,webkit,srvkit,common,plugin}/index.ts"
236
+ ];
237
+ #workspace;
238
+ constructor(workspace) {
239
+ this.#workspace = workspace;
240
+ }
241
+ static isEvent(value) {
242
+ return AgentHook.events.some((event) => event === value);
243
+ }
244
+ static respond(event, outcome) {
245
+ if (!outcome.block)
246
+ return null;
247
+ if (event === "pre-edit")
248
+ return JSON.stringify({
249
+ hookSpecificOutput: {
250
+ hookEventName: "PreToolUse",
251
+ permissionDecision: "deny",
252
+ permissionDecisionReason: outcome.message
253
+ }
254
+ });
255
+ return JSON.stringify({ decision: "block", reason: outcome.message });
256
+ }
257
+ static command(event) {
258
+ return `cd "$CLAUDE_PROJECT_DIR" && bun run --silent akan agent hook ${event}`;
259
+ }
260
+ static mergeSettings(existing) {
261
+ const hooks = { ...existing.hooks ?? {} };
262
+ const ours = (entry) => !!entry.hooks?.some((hook) => hook.command?.includes("akan agent hook"));
263
+ const add = (name, entry) => {
264
+ hooks[name] = [...(hooks[name] ?? []).filter((current) => !ours(current)), entry];
265
+ };
266
+ const hook = (event, timeout) => [
267
+ { type: "command", command: AgentHook.command(event), timeout }
268
+ ];
269
+ add("PreToolUse", { matcher: AgentHook.editTools, hooks: hook("pre-edit", 30) });
270
+ add("PostToolUse", { matcher: AgentHook.editTools, hooks: hook("post-edit", 120) });
271
+ add("Stop", { hooks: hook("stop", 600) });
272
+ return { ...existing, hooks };
273
+ }
274
+ async run(event, input) {
275
+ if (event === "stop")
276
+ return await this.#stop(input);
277
+ const file = this.#relative(input.tool_input?.file_path);
278
+ if (!file)
279
+ return { block: false, message: "" };
280
+ if (event === "pre-edit")
281
+ return this.#preEdit(file);
282
+ return await this.#postEdit(file, input.session_id);
283
+ }
284
+ #preEdit(file) {
285
+ const pattern = AgentHook.generated.find((glob) => new Bun.Glob(glob).match(file));
286
+ if (!pattern)
287
+ return { block: false, message: "" };
288
+ return {
289
+ block: true,
290
+ message: `${file} is generated (${pattern}). Edit the source file it is generated from, then run \`akan sync <app-or-lib>\`.`
291
+ };
292
+ }
293
+ async#postEdit(file, session) {
294
+ await this.#record(session, file);
295
+ return await this.#verify([file], { lintOnly: true });
296
+ }
297
+ async#stop(input) {
298
+ const ledger = this.#ledgerPath(input.session_id);
299
+ const files = await this.#workspace.exists(ledger) ? (await this.#workspace.readFile(ledger)).split(`
300
+ `).filter(Boolean) : [];
301
+ if (files.length === 0)
302
+ return { block: false, message: "" };
303
+ const result = await this.#verified(files, { lintOnly: false });
304
+ const comments = result?.diagnostics.filter((diagnostic) => diagnostic.code === VerifyComments.code).length ?? 0;
305
+ const block = !!result && (!result.ok || comments > 0);
306
+ if (!block || input.stop_hook_active)
307
+ await this.#workspace.remove(ledger);
308
+ const message = result ? VerifyReport.text(result) : "";
309
+ if (!block || input.stop_hook_active)
310
+ return { block: false, message };
311
+ const lead = comments ? `${comments} comment${comments === 1 ? "" : "s"} added since the last commit in files you edited; delete each one the code already says, then stop again.` : null;
312
+ return { block: true, message: lead ? `${lead}
313
+ ${message}` : message };
314
+ }
315
+ async#verify(files, { lintOnly }) {
316
+ const result = await this.#verified(files, { lintOnly });
317
+ return result ? { block: !result.ok, message: VerifyReport.text(result) } : { block: false, message: "" };
318
+ }
319
+ async#verified(files, { lintOnly }) {
320
+ const [apps, libs, pkgs] = await this.#workspace.getExecs();
321
+ const scope = VerifyScope.resolve(files.map((file) => ({ code: " M", file })), { apps, libs, pkgs });
322
+ if (scope.targets.length === 0)
323
+ return null;
324
+ const consoleOutput = Logger.consoleOutput;
325
+ Logger.consoleOutput = false;
326
+ return await new VerifyPipeline(this.#workspace, new WorkspaceRunner, new ApplicationRunner).run(scope, { lintOnly }).finally(() => {
327
+ Logger.consoleOutput = consoleOutput;
328
+ });
329
+ }
330
+ async#record(session, file) {
331
+ const ledger = this.#ledgerPath(session);
332
+ const current = await this.#workspace.exists(ledger) ? await this.#workspace.readFile(ledger) : "";
333
+ if (current.split(`
334
+ `).includes(file))
335
+ return;
336
+ await this.#workspace.writeFile(ledger, `${current}${file}
337
+ `, { silent: true });
338
+ }
339
+ #ledgerPath(session) {
340
+ return `.akan/agent/edits-${(session ?? "default").replace(/[^\w-]/g, "_")}.txt`;
341
+ }
342
+ #relative(file) {
343
+ if (!file)
344
+ return null;
345
+ const root = AgentHook.#physical(this.#workspace.workspaceRoot);
346
+ const absolute = path2.isAbsolute(file) ? file : path2.resolve(root, file);
347
+ const relative = path2.relative(root, AgentHook.#physical(absolute));
348
+ if (relative.startsWith("..") || path2.isAbsolute(relative))
349
+ return null;
350
+ return relative.split(path2.sep).join("/");
351
+ }
352
+ static #physical(target) {
353
+ try {
354
+ return realpathSync(target);
355
+ } catch {
356
+ const parent = path2.dirname(target);
357
+ return parent === target ? target : path2.join(AgentHook.#physical(parent), path2.basename(target));
358
+ }
359
+ }
360
+ }
361
+
362
+ // pkgs/@akanjs/cli/agent/agent.runner.ts
363
+ var unstamped = (content) => content.replace(/<!-- akan:agent:version \S+ -->\n\n/, "");
364
+ var targetPaths = {
365
+ cursor: ".cursor/rules/akan.mdc",
366
+ "agents-md": "AGENTS.md",
367
+ claude: "CLAUDE.md"
368
+ };
369
+ var SAMPLE_ARTIFACTS = [
370
+ { probe: "lib/task/task.constant.ts", target: "lib/task", label: "sample database module" },
371
+ { probe: "lib/_noti/noti.service.ts", target: "lib/_noti", label: "sample service module" },
372
+ {
373
+ probe: "lib/__scalar/workHistory/workHistory.dictionary.ts",
374
+ target: "lib/__scalar/workHistory",
375
+ label: "sample scalar module"
376
+ },
377
+ { probe: "page/task/_index.tsx", target: "page/task", label: "sample task pages" }
378
+ ];
379
+ var DEFAULT_INDEX_MARKER = "Akan.js template";
380
+ var renderSampleCleanup = async (workspace, appNames) => {
381
+ const items = [];
382
+ for (const appName of appNames) {
383
+ for (const artifact of SAMPLE_ARTIFACTS) {
384
+ if (await workspace.exists(`apps/${appName}/${artifact.probe}`)) {
385
+ items.push(`- \`apps/${appName}/${artifact.target}\` \u2014 ${artifact.label}; delete it once you no longer need the reference.`);
386
+ }
387
+ }
388
+ const indexPath = `apps/${appName}/page/_index.tsx`;
389
+ if (await workspace.exists(indexPath)) {
390
+ const content = await workspace.readFile(indexPath).catch(() => "");
391
+ if (content.includes(DEFAULT_INDEX_MARKER)) {
392
+ items.push(`- \`${indexPath}\` \u2014 default Akan landing page; replace it with your own home page.`);
393
+ }
394
+ }
395
+ }
396
+ if (items.length === 0)
397
+ return "";
398
+ return `## Start Clean (Remove Scaffolded Samples)
399
+
400
+ This workspace was scaffolded with reference samples so the Akan conventions are visible in real code. They are
401
+ not part of your product. Before building real features, remove the samples below and run \`akan sync <app>\`:
402
+
403
+ ${items.join(`
404
+ `)}
405
+
406
+ Keep a sample only while you are still learning its pattern; delete it once your own modules cover the same ground.
407
+
408
+ `;
409
+ };
410
+ var renderFrameworkRecipes = async (workspace) => {
411
+ const monorepo = `${workspace.workspaceRoot}/pkgs/akanjs/ui`;
412
+ const uiDir = await workspace.exists("pkgs/akanjs/ui") ? monorepo : `${workspace.workspaceRoot}/node_modules/akanjs/ui`;
413
+ const recipes = scanRecipes2(await collectRecipeSources2(uiDir, "akanjs/ui", "recipe"));
414
+ if (recipes.length === 0)
415
+ return "";
416
+ return `The framework recipes (\`*\` marks the default, \`key?\` is a boolean flag) \u2014 the full contract:
417
+
418
+ ${renderRecipeEntries(recipes)}`;
419
+ };
420
+ var renderPathRules = (rules) => `## Path Rules
421
+
422
+ Each area's full contract is a rule file. Claude Code and Cursor load it when a matching file is touched; any other
423
+ agent reads it before editing a match.
424
+
425
+ | Files | Rule |
426
+ |---|---|
427
+ ${rules.map((rule) => `| ${rule.paths.map((glob) => `\`${glob}\``).join(", ")} | \`${AgentAssets.rulePath(rule.name)}\` |`).join(`
428
+ `)}
429
+
430
+ Skills in \`.claude/skills/\` and \`.agents/skills/\` carry procedures and the full guidelines:
431
+ ${Object.keys(AgentAssets.skillReferences).map((name) => `\`${name}\``).join(", ")}. \`akan guideline show <name>\` prints any
432
+ guideline.
433
+
434
+ `;
435
+ var renderManagedBlock = async (workspace) => {
436
+ const context = await AkanContextAnalyzer.analyze(workspace);
437
+ const conventions = await Prompter2.getConventionSet();
438
+ const appNames = context.apps.map((app) => app.name);
439
+ const sampleCleanup = await renderSampleCleanup(workspace, appNames);
440
+ const version = await readDevkitVersion();
441
+ const block = `## Workspace
442
+
443
+ - Repo: ${context.repoName}
444
+ - Apps: ${appNames.join(", ") || "none"}
445
+ - Libraries: ${context.libs.map((lib) => lib.name).join(", ") || "none"}
446
+ - Packages: ${context.pkgs.map((pkg) => pkg.name).join(", ") || "none"}
447
+
448
+ ${conventions.core}
449
+
450
+ ${renderPathRules(conventions.rules)}${sampleCleanup}## Generated Files
451
+
452
+ Never hand-edit ${context.generatedFiles.map((file) => `\`${file}\``).join(", ")}. When one is stale or broken, fix the
453
+ owning source file and run \`akan sync <app-or-lib>\` or \`akan repair generated\`.`;
454
+ return version ? stampBlockVersion(block, version) : block;
455
+ };
456
+ var renderAgentsMd = async (workspace, existing) => {
457
+ const block = await renderManagedBlock(workspace);
458
+ if (existing?.trim())
459
+ return upsertAgentBlock(existing, block);
460
+ const context = await AkanContextAnalyzer.analyze(workspace);
461
+ return `# ${context.repoName} Agent Guide
462
+
463
+ This file is the single source of truth for coding agents in this workspace. Claude Code reads it through
464
+ \`CLAUDE.md\` (\`@AGENTS.md\`) and Cursor through \`.cursor/rules/akan.mdc\`. The section between the
465
+ \`akan:agent\` markers is regenerated by \`akan agent install\`; edit anything outside the markers freely.
466
+
467
+ ${AGENT_BLOCK_START}
468
+ ${block}
469
+ ${AGENT_BLOCK_END}
470
+ `;
471
+ };
472
+ var renderClaudeMd = async (workspace) => {
473
+ const context = await AkanContextAnalyzer.analyze(workspace);
474
+ return `# ${context.repoName} \u2014 Claude Code Guide
475
+
476
+ @AGENTS.md
477
+
478
+ ${CLAUDE_COMMENT_RULE}
479
+ `;
480
+ };
481
+ var renderCursorRule = () => `---
482
+ description: Akan workspace agent guide
483
+ alwaysApply: true
484
+ ---
485
+
486
+ Follow the workspace agent guide, which is the single source of truth for Akan conventions,
487
+ generated-file rules, and the MCP workflow policy.
488
+
489
+ @AGENTS.md
490
+ `;
491
+ var renderTarget = async (workspace, target, existing) => {
492
+ if (target === "agents-md")
493
+ return await renderAgentsMd(workspace, existing);
494
+ if (target === "claude")
495
+ return await renderClaudeMd(workspace);
496
+ return renderCursorRule();
497
+ };
498
+
499
+ class AgentRunner extends runner("agent") {
500
+ async renderBlock(workspace) {
501
+ return await renderManagedBlock(workspace);
502
+ }
503
+ async install(workspace, targets, { force = false } = {}) {
504
+ return await this.#apply(workspace, targets, force, null);
505
+ }
506
+ async check(workspace, targets) {
507
+ const drift = [];
508
+ await this.#apply(workspace, targets, false, drift);
509
+ return drift;
510
+ }
511
+ async#apply(workspace, targets, force, drift) {
512
+ const written = [];
513
+ for (const target of targets) {
514
+ if (target === "rules" || target === "skills" || target === "hooks")
515
+ continue;
516
+ const filePath = targetPaths[target];
517
+ const exists = await workspace.exists(filePath);
518
+ if (exists && !force && target !== "agents-md") {
519
+ if (!drift)
520
+ Logger2.rawLog(`Kept ${filePath}: it already exists, and --force overwrites it.`);
521
+ continue;
522
+ }
523
+ const existing = exists ? await workspace.readFile(filePath) : null;
524
+ await this.#put(workspace, filePath, await renderTarget(workspace, target, existing), drift);
525
+ written.push(filePath);
526
+ }
527
+ if (targets.includes("rules")) {
528
+ const appendix = { style: await renderFrameworkRecipes(workspace) };
529
+ const assets = await AgentAssets.rules({ appendix });
530
+ written.push(await this.#writeAssets(workspace, assets, /^\.(claude|cursor)\/rules\//, force, "rules", drift));
531
+ }
532
+ if (targets.includes("skills")) {
533
+ const assets = await AgentAssets.skills();
534
+ written.push(await this.#writeAssets(workspace, assets, /^\.(claude|agents)\/skills\//, force, "skills", drift));
535
+ }
536
+ if (targets.includes("hooks"))
537
+ written.push(await this.#installHooks(workspace, drift));
538
+ if (targets.includes("agents-md") && !drift)
539
+ written.push(...await this.#installScopeIndexes(workspace));
540
+ return written;
541
+ }
542
+ async#put(workspace, file, content, drift) {
543
+ if (!drift)
544
+ return (await workspace.writeFile(file, content, { overwrite: true, silent: true })).written;
545
+ const current = await workspace.exists(file) ? await workspace.readFile(file) : null;
546
+ if (current === null)
547
+ drift.push({ path: file, change: "missing" });
548
+ else if (unstamped(current) !== unstamped(content))
549
+ drift.push({ path: file, change: "outdated" });
550
+ return false;
551
+ }
552
+ async#installHooks(workspace, drift) {
553
+ const settingsPath = ".claude/settings.json";
554
+ const existing = await workspace.exists(settingsPath) ? JSON.parse(await workspace.readFile(settingsPath)) : {};
555
+ await this.#put(workspace, settingsPath, `${JSON.stringify(AgentHook.mergeSettings(existing), null, 2)}
556
+ `, drift);
557
+ return `hooks: ${settingsPath}`;
558
+ }
559
+ async#writeAssets(workspace, assets, owned, force, label, drift) {
560
+ const fresh = new Set(assets.map((asset) => asset.path));
561
+ const stale = (await AgentAssets.generatedFiles(workspace.workspaceRoot)).filter((file) => owned.test(file) && !fresh.has(file));
562
+ if (drift)
563
+ drift.push(...stale.map((file) => ({ path: file, change: "retired" })));
564
+ else
565
+ for (const file of stale)
566
+ await workspace.remove(file);
567
+ let changed = 0;
568
+ for (const asset of assets) {
569
+ if (!force && await workspace.exists(asset.path)) {
570
+ const current = await workspace.readFile(asset.path);
571
+ if (!current.includes(AgentAssets.marker)) {
572
+ if (!drift)
573
+ Logger2.rawLog(`Kept ${asset.path}: it carries no ${AgentAssets.marker} marker, and --force overwrites it.`);
574
+ continue;
575
+ }
576
+ }
577
+ if (await this.#put(workspace, asset.path, asset.content, drift))
578
+ changed++;
579
+ }
580
+ const removed = stale.length ? `, ${stale.length} stale removed` : "";
581
+ return `${label}: ${assets.length} files, ${changed} changed${removed}`;
582
+ }
583
+ async#installScopeIndexes(workspace) {
584
+ const [appNames, libNames] = await workspace.getExecs();
585
+ const written = [];
586
+ const syncScope = async (exec) => {
587
+ try {
588
+ await exec.syncAgentsIndex();
589
+ written.push(`${exec.type}s/${exec.name}/AGENTS.md`);
590
+ } catch (error) {
591
+ const message = error instanceof Error ? error.message : String(error);
592
+ Logger2.rawLog(`Skipped ${exec.type}s/${exec.name}/AGENTS.md (${message})`, undefined, "error");
593
+ }
594
+ };
595
+ for (const name of libNames)
596
+ await syncScope(LibExecutor.from(workspace, name));
597
+ for (const name of appNames)
598
+ await syncScope(AppExecutor.from(workspace, name));
599
+ return written;
600
+ }
601
+ }
602
+
603
+ // pkgs/@akanjs/cli/agent/agent.script.ts
604
+ var singleTargets = ["cursor", "claude", "rules", "skills", "hooks"];
605
+ var resolveTargets = (target) => {
606
+ if (!target || target === "all")
607
+ return ["cursor", "agents-md", "claude", "rules", "skills"];
608
+ if (target === "agents-md")
609
+ return ["agents-md", "rules", "skills"];
610
+ const single = singleTargets.find((name) => name === target);
611
+ if (single)
612
+ return [single];
613
+ throw new Error(`Unknown agent target: ${target}. Use cursor, agents-md, claude, rules, skills, hooks, or all.`);
614
+ };
615
+
616
+ class AgentScript extends script("agent", [AgentRunner]) {
617
+ async agent(workspace, action, target, { force = false, check = false } = {}) {
618
+ if (action === "hook")
619
+ return await this.#hook(workspace, target);
620
+ if (action !== "install")
621
+ throw new Error(`Unknown agent action: ${action}. Use "install" or "hook".`);
622
+ if (check)
623
+ return await this.#check(workspace, resolveTargets(target));
624
+ const written = await this.agentRunner.install(workspace, resolveTargets(target), { force });
625
+ Logger3.rawLog(`Agent rules written:
626
+ ${written.map((file) => `- ${file}`).join(`
627
+ `)}`);
628
+ }
629
+ async#check(workspace, targets) {
630
+ const drift = await this.agentRunner.check(workspace, targets);
631
+ if (drift.length === 0)
632
+ return Logger3.rawLog("agent files ok");
633
+ const files = drift.length === 1 ? "1 file" : `${drift.length} files`;
634
+ const lines = drift.map(({ path, change }) => `${path} ${change}`);
635
+ Logger3.rawLog([`agent files differ \xB7 ${files} \xB7 run \`akan agent install\``, ...lines].join(`
636
+ `));
637
+ const failure = new ExitCodeError("agent files differ", 1);
638
+ markCliErrorPrinted(failure);
639
+ throw failure;
640
+ }
641
+ async#hook(workspace, event) {
642
+ if (!AgentHook.isEvent(event))
643
+ throw new Error(`Unknown hook: ${event}. Use ${AgentHook.events.join(", ")}.`);
644
+ const raw = (await Bun.stdin.text()).trim();
645
+ const input = raw ? JSON.parse(raw) : {};
646
+ const response = AgentHook.respond(event, await new AgentHook(workspace).run(event, input));
647
+ if (response)
648
+ process.stdout.write(`${response}
649
+ `);
650
+ }
651
+ }
652
+
653
+ export { AgentScript };