@akanjs/cli 3.1.1-rc.16 → 3.1.1-rc.18
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/{CodeAgent-23ewzxqa.js → CodeAgent-fbcq8vks.js} +2 -2
- package/{CodeTui-kc99fk78.js → CodeTui-0626gxqd.js} +1 -1
- package/TunnelShare-2p24xxza.js +14 -0
- package/agent.command-hpza0pg9.js +46 -0
- package/akanCode.js +5 -3
- package/{application.command-bvfd1680.js → application.command-3a7q1hs2.js} +11 -10
- package/{applicationBuildRunner-4ajaesk1.js → applicationBuildRunner-s7yt71j4.js} +5 -5
- package/buildBatch.proc.js +6 -6
- package/{cloud.command-f2w40fyy.js → cloud.command-4vg0pcea.js} +15 -14
- package/cloud.script-nkmeyhet.js +25 -0
- package/{code.command-dbhhnahn.js → code.command-fbntb67p.js} +6 -6
- package/commandManifest.json +1 -1
- package/{context.command-yswjwv6y.js → context.command-31rm54v0.js} +18 -18
- package/context.runner-w01a32ph.js +26 -0
- package/{guideline.command-ztx6dkpk.js → guideline.command-cv3by2ng.js} +3 -3
- package/guidelines/conventions/core.md +104 -0
- package/guidelines/conventions/rules/app.md +83 -0
- package/guidelines/conventions/rules/auth.md +45 -0
- package/guidelines/conventions/rules/config.md +56 -0
- package/guidelines/conventions/rules/constant.md +24 -0
- package/guidelines/conventions/rules/gates.md +31 -0
- package/guidelines/conventions/rules/layer.md +25 -0
- package/guidelines/conventions/rules/migration.md +27 -0
- package/guidelines/conventions/rules/module.md +90 -0
- package/guidelines/conventions/rules/page.md +56 -0
- package/guidelines/conventions/rules/sensitive.md +16 -0
- package/guidelines/conventions/rules/server.md +86 -0
- package/guidelines/conventions/rules/ssr.md +47 -0
- package/guidelines/conventions/rules/style.md +43 -0
- package/guidelines/conventions/rules/test.md +34 -0
- package/guidelines/conventions/rules/ts.md +95 -0
- package/guidelines/conventions/rules/tsx.md +75 -0
- package/guidelines/mcpRule/mcpRule.instruction.md +1 -1
- package/guidelines/workspaceRecipes/workspaceRecipes.instruction.md +3 -3
- package/incrementalBuilder.proc.js +6 -6
- package/{index-xjwcp91m.js → index-05nxx4m5.js} +43 -12
- package/{index-k9k18vq9.js → index-0ht91675.js} +37 -59
- package/{index-er16p89s.js → index-0zwznvv1.js} +1 -1
- package/{index-76jwsm3g.js → index-0zyatd10.js} +2 -2
- package/{index-97fsvy66.js → index-12kzwak1.js} +3 -3
- package/{index-005dqc83.js → index-1dhf8ymv.js} +2 -2
- package/{index-00ke4phc.js → index-3gccwenr.js} +1 -1
- package/{index-2epb3wgh.js → index-3txrjt6n.js} +2 -2
- package/{index-7ndgffg4.js → index-57q1ayd2.js} +18 -1240
- package/index-5kh9scvs.js +514 -0
- package/index-5n5hds19.js +1246 -0
- package/{index-9sa6abze.js → index-6269mf2s.js} +10 -9
- package/{index-921cxqrd.js → index-64g9fsjy.js} +41 -12
- package/index-7zeb5r1p.js +653 -0
- package/{index-s4c2y5gs.js → index-8s8b4eba.js} +45 -4
- package/{index-4332q6yj.js → index-922k2zwq.js} +3 -3
- package/{index-m6qgr1rx.js → index-9ndw5d8j.js} +7 -7
- package/{index-xfp4dcnx.js → index-et6ce601.js} +1 -1
- package/{index-saj9cx3a.js → index-f5adsa58.js} +4 -4
- package/{index-vgt25eh1.js → index-fbewhg4g.js} +7 -32
- package/{index-ysyt782g.js → index-hm7x0c11.js} +4 -4
- package/{index-2p1brf5e.js → index-hvv5rnaq.js} +2 -2
- package/index-jje9qzyq.js +27 -0
- package/{index-rxse80x6.js → index-js1gj6f6.js} +12 -10
- package/{index-p2pahmsa.js → index-kjrvwzav.js} +3 -3
- package/index-m6r88hhr.js +3582 -0
- package/{index-mk391h0z.js → index-mt0wa941.js} +4 -4
- package/{index-m93qg20j.js → index-mwj9q2ya.js} +1 -1
- package/{index-5nd1wtkv.js → index-p6x5b7hr.js} +1 -1
- package/index-r2wedvqn.js +138 -0
- package/{index-gxj80jz7.js → index-rvynj5gz.js} +1 -1
- package/{index-m54n0v29.js → index-tdv66eah.js} +4 -4
- package/{index-vq77g679.js → index-w134p86k.js} +1 -1
- package/{index-deeskxjh.js → index-wfczhj1z.js} +14 -36
- package/{index-dy0jx9ay.js → index-wwe9rsrx.js} +14 -0
- package/{index-qx4r4cj2.js → index-x5ecanqh.js} +2 -2
- package/{index-nzfgyw3b.js → index-zre4m2ce.js} +4 -4
- package/index.js +23 -22
- package/{library.command-hmbkcwzw.js → library.command-sh70fyvy.js} +3 -3
- package/{localRegistry.command-sq5p4c9x.js → localRegistry.command-2nbyy84d.js} +14 -13
- package/{module.command-n4z29zcv.js → module.command-n0bmtzwy.js} +5 -5
- package/{package.command-20025dy3.js → package.command-7h9r51bz.js} +3 -3
- package/package.json +2 -2
- package/{page.command-q8fvpjer.js → page.command-vjtpfbb1.js} +3 -3
- package/{pipeline.command-8j97fq88.js → pipeline.command-c93se3ar.js} +2 -2
- package/{primitive.command-e5y6dqp1.js → primitive.command-a3075qp2.js} +6 -6
- package/{projectTypecheck-tbdye9k3.js → projectTypecheck-sf9xwaga.js} +1 -1
- package/{prompter-76k56b37.js → prompter-hgcta8pb.js} +1 -1
- package/quality.command-dw1y9hmy.js +76 -0
- package/{repair.command-dq1gckth.js → repair.command-tg57d8yt.js} +5 -5
- package/{scalar.command-5vwf152w.js → scalar.command-cwzge353.js} +4 -4
- package/skills/akan-agent/SKILL.md +36 -0
- package/skills/akan-debug/SKILL.md +3 -3
- package/skills/akan-deps/SKILL.md +1 -2
- package/skills/akan-mcp/SKILL.md +40 -0
- package/skills/akan-page/SKILL.md +44 -0
- package/skills/akan-query/SKILL.md +38 -0
- package/skills/akan-runtime/SKILL.md +40 -0
- package/skills/akan-scaffold/SKILL.md +16 -6
- package/skills/akan-transport/SKILL.md +40 -0
- package/skills/akan-validate/SKILL.md +13 -11
- package/{subspace.command-182be8vj.js → subspace.command-3h03c7kc.js} +8 -8
- package/templates/workspaceRoot/.gitignore.template +3 -0
- package/templates/workspaceRoot/AGENTS.md.template +4 -10
- package/{tunnel.command-bfzj7xkb.js → tunnel.command-czaz6ys4.js} +7 -7
- package/{typeChecker-px49mezc.js → typeChecker-j2jdnqsr.js} +1 -1
- package/typecheck.proc.js +6 -1
- package/verify.command-nzwhtz71.js +91 -0
- package/{workflow.command-3g53242s.js → workflow.command-srhky88x.js} +23 -13
- package/{workspace.command-h7399jwv.js → workspace.command-9stchcd2.js} +31 -29
- package/TunnelShare-dk2gw78d.js +0 -14
- package/agent.command-knp5j7bq.js +0 -25
- package/cloud.script-2r82sv0f.js +0 -24
- package/context.runner-c3wsh2jw.js +0 -26
- package/guidelines/conventions/conventions.instruction.md +0 -663
- package/guidelines/workspaceOnboarding/workspaceOnboarding.instruction.md +0 -291
- package/index-4t4qb8jg.js +0 -279
- package/index-hvg3esm0.js +0 -1844
- package/index-zzvvc845.js +0 -74
- package/quality.command-168pt5vm.js +0 -1788
- package/templates/workspaceRoot/docs/AI-DEVELOPMENT.md.template +0 -69
- package/templates/workspaceRoot/docs/GENERATED.md.template +0 -55
|
@@ -0,0 +1,653 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
runner,
|
|
4
|
+
script,
|
|
5
|
+
ExitCodeError,
|
|
6
|
+
markCliErrorPrinted
|
|
7
|
+
} from "./index-3gccwenr.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-64g9fsjy.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-8s8b4eba.js";
|
|
30
|
+
import {
|
|
31
|
+
ApplicationRunner
|
|
32
|
+
} from "./index-57q1ayd2.js";
|
|
33
|
+
import {
|
|
34
|
+
WorkspaceRunner
|
|
35
|
+
} from "./index-m6r88hhr.js";
|
|
36
|
+
import {
|
|
37
|
+
VerifyComments,
|
|
38
|
+
VerifyPipeline,
|
|
39
|
+
VerifyReport,
|
|
40
|
+
VerifyScope
|
|
41
|
+
} from "./index-5kh9scvs.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 };
|