@akanjs/cli 3.2.0-rc.3 → 3.2.0-rc.30
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 +2 -1
- package/CodeAgent-c17abdbf.js +11 -0
- package/{CodeTui-wv9yf7eq.js → CodeTui-jed1nj82.js} +822 -666
- package/README.ko.md +26 -1
- package/README.md +26 -1
- package/TunnelShare-mbfcaqg0.js +18 -0
- package/agent.command-9whnc6vb.js +56 -0
- package/akanCode.js +12 -12
- package/appExecutor-020cyesq.js +11 -0
- package/{application.command-6515t682.js → application.command-4eqvyxkw.js} +77 -36
- package/{applicationBuildRunner-bqbyeg84.js → applicationBuildRunner-frtcrqfd.js} +18 -13
- package/buildBatch.proc.js +26 -11
- package/{cloud.command-32esk0v1.js → cloud.command-hbvmeezn.js} +31 -28
- package/cloud.script-9kmbr3d6.js +35 -0
- package/{code.command-xk7rwq2x.js → code.command-0ayrenk4.js} +14 -9
- package/{context.command-jwenkkf0.js → context.command-php852kf.js} +28 -23
- package/context.runner-nngmn7c0.js +34 -0
- package/{dependencyScanner-78sq8m4q.js → dependencyScanner-ge10gb52.js} +2 -2
- package/{devTui-cd03z4mx.js → devTui-rf374y2w.js} +1 -1
- package/{fileSys-zpvt5gtf.js → fileSys-q22646yc.js} +1 -1
- package/{guideline.command-w6yqpdec.js → guideline.command-w1grfwh7.js} +9 -4
- package/guidelines/agentRule/agentRule.instruction.md +29 -12
- package/guidelines/akanApi/akanApi.instruction.md +5 -3
- package/guidelines/conventions/core.md +23 -5
- package/guidelines/conventions/rules/app.md +4 -1
- package/guidelines/conventions/rules/page.md +5 -0
- package/guidelines/conventions/rules/ts.md +3 -3
- package/guidelines/errorCodes/errorCodes.instruction.md +158 -0
- package/guidelines/fieldRule/fieldRule.instruction.md +2 -1
- package/guidelines/mcpRule/mcpRule.instruction.md +96 -2
- package/guidelines/pageRule/pageRule.instruction.md +15 -1
- package/guidelines/runtimeRule/runtimeRule.instruction.md +12 -6
- package/guidelines/transportRule/transportRule.instruction.md +8 -1
- package/incrementalBuilder.proc.js +574 -410
- package/{index-w15mg3km.js → index-0dm25wvf.js} +1 -1
- package/{index-xrmrvafh.js → index-0gaj78wn.js} +808 -694
- package/{index-j1hjb477.js → index-11d7nh8a.js} +1 -1
- package/{index-hj6w4ka1.js → index-1p81ecbz.js} +1 -1
- package/{index-ygrdw6jw.js → index-1pjwsh2g.js} +65 -8
- package/{index-43acpsc7.js → index-28nk8w3j.js} +12 -12
- package/{index-qd7xn2bk.js → index-2ny1e95c.js} +2 -2
- package/{index-8gm4yag8.js → index-42jhx2ya.js} +6 -6
- package/{index-2rqyrvcy.js → index-4st0hq72.js} +62 -33
- package/{index-bak9f2br.js → index-5d57kx0s.js} +15 -11
- package/{index-bdmgqzb5.js → index-6469101k.js} +58 -29
- package/{index-7kmbqp0b.js → index-6pxmcaq8.js} +1 -1
- package/{index-54s6knqe.js → index-6zb17wcm.js} +12 -10
- package/{index-0ba8nj4d.js → index-7bs463x7.js} +50 -38
- package/{index-y725zb1a.js → index-7v7tvgt7.js} +196 -168
- package/{index-r0a604h4.js → index-99kjwyma.js} +1 -1
- package/{index-2mrn1mrg.js → index-9f3reh2y.js} +1 -1
- package/{index-386canwe.js → index-9rv2zt48.js} +186 -121
- package/{index-20wvskt8.js → index-9wab2ngg.js} +1 -1
- package/{index-2eym1yjb.js → index-9wjrwjgz.js} +288 -209
- package/{index-kcpk2d20.js → index-at6haq2x.js} +1474 -1139
- package/{index-6h775rv3.js → index-ba2xd32s.js} +53 -12
- package/{index-yf9wc28h.js → index-bejy9zyc.js} +1 -1
- package/{index-ngpt3zz3.js → index-bj8s07s7.js} +525 -440
- package/{index-bns3wcpc.js → index-by2tvsq6.js} +1 -1
- package/{index-vbhx60x5.js → index-cb91b6d8.js} +2140 -2165
- package/index-dss3ds74.js +127 -0
- package/{index-e22zedc2.js → index-f16kr6vj.js} +3 -3
- package/{index-ny2k80mv.js → index-ffa52fwf.js} +1 -1
- package/{index-djc5nxpy.js → index-fp5xf6ef.js} +6 -6
- package/{index-qrk06tfp.js → index-g45y5f3e.js} +2 -2
- package/{index-8jpc5fqv.js → index-g7jgd4xs.js} +2 -2
- package/index-j4yvgfhr.js +70 -0
- package/{index-ytpmk3pb.js → index-jgj31xvw.js} +18 -11
- package/{index-j6eeh5d7.js → index-knpm8sdm.js} +5 -5
- package/{index-s34v3y28.js → index-m3t28rt3.js} +11 -11
- package/{index-dpgywgeq.js → index-m5gg0wzv.js} +27 -16
- package/index-na8r4a27.js +30 -0
- package/{index-h0p6n4k1.js → index-nm7nt9vm.js} +3 -3
- package/{index-j4hkbzj6.js → index-p06kfhdf.js} +6 -6
- package/{index-35j83zkd.js → index-p5zh7pmc.js} +2 -2
- package/{index-cmg5ngqa.js → index-p7beqww9.js} +2 -2
- package/{index-zhkcab5a.js → index-prgvqqxe.js} +580 -364
- package/{index-wfmpxke3.js → index-qssq2d41.js} +2775 -3677
- package/{index-sc0g6zbm.js → index-rwgqba9p.js} +24 -11
- package/{index-zcdmnfrf.js → index-s3m89wt2.js} +9 -9
- package/{index-v50xjbbe.js → index-t4d0ckde.js} +1 -1
- package/{index-9p260r4e.js → index-trffs83s.js} +538 -250
- package/{index-ddk49ypz.js → index-v929w7j7.js} +133 -49
- package/index-va90m8nd.js +25 -0
- package/index-vjbne22r.js +80 -0
- package/{index-h7hehkw6.js → index-xczjdng6.js} +3 -1
- package/{index-39jz41jb.js → index-xs9a3ddt.js} +3 -3
- package/{index-84c2pgak.js → index-yvzm8mby.js} +94 -82
- package/{index-wr9magsr.js → index-yxkjsyx8.js} +3 -3
- package/index-ze48c0vd.js +788 -0
- package/{index-ygdbn9jn.js → index-zyb0ebm4.js} +1 -1
- package/index.js +29 -24
- package/libExecutor-tq994592.js +10 -0
- package/{library.command-qs8beggh.js → library.command-x219mhcx.js} +9 -4
- package/{localRegistry.command-hz4ged9n.js → localRegistry.command-zvdcejhn.js} +30 -24
- package/{module.command-z9js77m2.js → module.command-k6cwcm7g.js} +17 -8
- package/{package.command-zqenq8c0.js → package.command-vw7x09f8.js} +13 -8
- package/package.json +2 -2
- package/{page.command-t0nx1jat.js → page.command-gf06paq2.js} +9 -4
- package/{pipeline.command-2yjeas7m.js → pipeline.command-y07dgj9b.js} +14 -8
- package/pkgExecutor-stde3yc3.js +10 -0
- package/{primitive.command-v5kypwy4.js → primitive.command-edydvh07.js} +13 -8
- package/{projectTypecheck-s9hhe5sa.js → projectTypecheck-mk8wefvd.js} +2 -1
- package/{prompter-qrwx1p17.js → prompter-qyggfhqd.js} +2 -2
- package/{quality.command-q55j2htd.js → quality.command-mdb45vyr.js} +23 -16
- package/{recipeScanner-4b69ybe0.js → recipeScanner-rrx69awy.js} +1 -1
- package/{repair.command-7ssbbdq2.js → repair.command-kvtaeecy.js} +13 -8
- package/{routeSourceValidator-4h947v7c.js → routeSourceValidator-8n6j1vn7.js} +4 -2
- package/{scalar.command-p5jb7z57.js → scalar.command-sjt9p5e1.js} +11 -6
- package/skills/akan-debug/SKILL.md +10 -3
- package/skills/akan-err/SKILL.md +7 -0
- package/skills/akan-mcp/SKILL.md +14 -2
- package/skills/akan-scaffold/SKILL.md +2 -2
- package/skills/akan-transport/SKILL.md +2 -0
- package/skills/akan-validate/SKILL.md +1 -0
- package/{subspace.command-7wxy6ptj.js → subspace.command-mkkqync4.js} +29 -23
- package/templates/app/page/_layout.tsx +13 -0
- package/templates/app/page/styles.css.template +40 -0
- package/templates/appSample/page/_index.tsx +9 -9
- package/templates/appSample/page/_layout.tsx +1 -0
- package/templates/appSample/page/styles.css.template +40 -5
- package/templates/appSample/ui/Recipe/jellyButton.ts +1 -1
- package/templates/biomeForm.ts +1 -1
- package/templates/env/_env.server.type.ts +1 -1
- package/templates/facetIndex/index.ts +2 -37
- package/templates/lib/sig.ts +0 -4
- package/templates/lib/useClient.ts +1 -1
- package/templates/workspaceRoot/AGENTS.md.template +2 -1
- package/{tunnel.command-22g11n0x.js → tunnel.command-tr5b3030.js} +17 -12
- package/{typeChecker-s640r6c0.js → typeChecker-bfrd1n9n.js} +1 -1
- package/typecheck.proc.js +6 -3
- package/{verify.command-m0wnndd7.js → verify.command-0p9h8tpp.js} +26 -20
- package/{workflow.command-jx8dqs9n.js → workflow.command-9mfcwqzj.js} +37 -19
- package/{workspace.command-ca9kfyt3.js → workspace.command-5hjtmcfs.js} +61 -54
- package/CodeAgent-e9c712an.js +0 -11
- package/TunnelShare-zkfkrw8w.js +0 -14
- package/agent.command-9erafkcb.js +0 -51
- package/cloud.script-arsagnq6.js +0 -30
- package/context.runner-mqpp67br.js +0 -29
- package/index-x3x31df8.js +0 -14
- /package/templates/{appSample → app}/public/fonts/Pretendard-Bold.woff2 +0 -0
- /package/templates/{appSample → app}/public/fonts/Pretendard-Medium.woff2 +0 -0
- /package/templates/{appSample → app}/public/fonts/Pretendard-Regular.woff2 +0 -0
- /package/templates/{appSample → app}/public/fonts/Pretendard-SemiBold.woff2 +0 -0
|
@@ -1,50 +1,491 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
readDevkitVersion,
|
|
3
|
+
barrelFacetDirs,
|
|
5
4
|
rootAllowedFiles,
|
|
6
5
|
rootAllowedDirs,
|
|
7
|
-
barrelFacetDirs,
|
|
8
6
|
facetIndexShadowOf,
|
|
9
7
|
rootEntryHintOf,
|
|
10
8
|
isScannedRootEntry,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} from "./index-
|
|
9
|
+
extractBlockVersion,
|
|
10
|
+
readDevkitVersion
|
|
11
|
+
} from "./index-qssq2d41.js";
|
|
14
12
|
import {
|
|
15
13
|
FileSys2
|
|
16
|
-
} from "./index-
|
|
14
|
+
} from "./index-by2tvsq6.js";
|
|
17
15
|
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
AppExecutor2
|
|
17
|
+
} from "./index-ze48c0vd.js";
|
|
18
|
+
import {
|
|
19
|
+
LibExecutor2
|
|
20
|
+
} from "./index-na8r4a27.js";
|
|
22
21
|
import {
|
|
23
22
|
workflowPathsForPlan,
|
|
24
23
|
workflowRunArtifactPath,
|
|
25
24
|
workflowSyncDir
|
|
26
|
-
} from "./index-
|
|
25
|
+
} from "./index-0gaj78wn.js";
|
|
26
|
+
import {
|
|
27
|
+
collectRecipeSources2,
|
|
28
|
+
scanRecipes2,
|
|
29
|
+
findInlineRecipeDuplicates2
|
|
30
|
+
} from "./index-1p81ecbz.js";
|
|
27
31
|
|
|
28
|
-
// pkgs/@akanjs/devkit/akanContext.ts
|
|
32
|
+
// pkgs/@akanjs/devkit/context/akanContext.ts
|
|
33
|
+
import path9 from "path";
|
|
34
|
+
import { parseRouteModuleKey } from "akanjs/common";
|
|
35
|
+
|
|
36
|
+
// pkgs/@akanjs/devkit/context/doctor/agentGuideCheck.ts
|
|
37
|
+
import path3 from "path";
|
|
38
|
+
|
|
39
|
+
// pkgs/@akanjs/devkit/context/safeRead.ts
|
|
29
40
|
import { readdir } from "fs/promises";
|
|
41
|
+
var safeReadDir = async (dirPath) => (await readdir(dirPath, { withFileTypes: true }).catch(() => [])).sort((a, b) => a.name.localeCompare(b.name));
|
|
42
|
+
var safeReadText = (filePath) => FileSys2.readText(filePath).catch(() => null);
|
|
43
|
+
var safeReadJson = (filePath) => FileSys2.readJson(filePath).catch(() => null);
|
|
44
|
+
|
|
45
|
+
// pkgs/@akanjs/devkit/context/doctor/generatedFreshness.ts
|
|
30
46
|
import path from "path";
|
|
31
|
-
|
|
47
|
+
var unknownGeneratedFilesFreshness = {
|
|
48
|
+
status: "unknown",
|
|
49
|
+
message: "Run sync before validation so generated Akan files match the current source conventions.",
|
|
50
|
+
refreshCommand: "akan sync <app-or-lib>",
|
|
51
|
+
verifyingCommands: ["akan verify <app-or-lib>"]
|
|
52
|
+
};
|
|
53
|
+
var readGeneratedSyncStates = async (workspace) => {
|
|
54
|
+
const syncDir = path.join(workspace.workspaceRoot, workflowSyncDir);
|
|
55
|
+
const entries = await safeReadDir(syncDir);
|
|
56
|
+
const states = await Promise.all(entries.filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => safeReadJson(path.join(syncDir, entry.name))));
|
|
57
|
+
return states.filter((state) => !!state && state.schemaVersion === 1 && typeof state.target === "string" && typeof state.syncedAt === "string");
|
|
58
|
+
};
|
|
59
|
+
var generatedFreshnessFromStates = async (workspace) => {
|
|
60
|
+
const states = await readGeneratedSyncStates(workspace);
|
|
61
|
+
if (states.length === 0)
|
|
62
|
+
return unknownGeneratedFilesFreshness;
|
|
63
|
+
const targets = states.sort((a, b) => a.target.localeCompare(b.target)).map((state) => ({
|
|
64
|
+
target: state.target,
|
|
65
|
+
status: state.status === "passed" ? "fresh" : "stale",
|
|
66
|
+
lastSyncedAt: state.syncedAt,
|
|
67
|
+
runId: state.runId,
|
|
68
|
+
generatedFiles: state.generatedFiles.map((file) => file.path),
|
|
69
|
+
reason: state.status === "passed" ? `Generated files were refreshed by ${state.command}.` : `Last generated repair command failed: ${state.command}.`
|
|
70
|
+
}));
|
|
71
|
+
const lastFresh = targets.filter((target) => target.status === "fresh" && target.lastSyncedAt).sort((a, b) => (b.lastSyncedAt ?? "").localeCompare(a.lastSyncedAt ?? ""))[0];
|
|
72
|
+
return {
|
|
73
|
+
status: targets.some((target) => target.status === "fresh") ? "fresh" : "stale",
|
|
74
|
+
message: lastFresh ? `Generated files were refreshed for ${lastFresh.target} at ${lastFresh.lastSyncedAt}.` : "Generated sync state exists, but the last recorded repair did not pass.",
|
|
75
|
+
refreshCommand: "akan sync <app-or-lib>",
|
|
76
|
+
verifyingCommands: ["akan verify <app-or-lib>"],
|
|
77
|
+
targets
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// pkgs/@akanjs/devkit/context/doctor/workflowScope.ts
|
|
82
|
+
import path2 from "path";
|
|
83
|
+
import { isRecord } from "akanjs/common";
|
|
84
|
+
var isWorkflowPlan = (value) => typeof value === "object" && value !== null && ("schemaVersion" in value) && value.schemaVersion === 1 && ("mode" in value) && value.mode === "plan" && ("inputs" in value) && isRecord(value.inputs) && ("predictedChanges" in value) && Array.isArray(value.predictedChanges) && value.predictedChanges.every((change) => isRecord(change) && typeof change.target === "string");
|
|
85
|
+
var isPathList = (value) => Array.isArray(value) && value.every((file) => isRecord(file) && typeof file.path === "string");
|
|
86
|
+
var isWorkflowApplyReport = (value) => typeof value === "object" && value !== null && ("schemaVersion" in value) && value.schemaVersion === 1 && ("mode" in value) && (value.mode === "apply" || value.mode === "dry-run") && ("changedFiles" in value) && isPathList(value.changedFiles) && ("generatedFiles" in value) && isPathList(value.generatedFiles) && ("plan" in value) && isWorkflowPlan(value.plan);
|
|
87
|
+
var isWorkflowRunArtifact = (value) => typeof value === "object" && value !== null && ("schemaVersion" in value) && value.schemaVersion === 1;
|
|
88
|
+
var workflowPathsForArtifact = (artifact) => {
|
|
89
|
+
if (isWorkflowPlan(artifact))
|
|
90
|
+
return workflowPathsForPlan(artifact);
|
|
91
|
+
if (isWorkflowApplyReport(artifact)) {
|
|
92
|
+
return [
|
|
93
|
+
...artifact.changedFiles.map((file) => file.path),
|
|
94
|
+
...artifact.generatedFiles.map((file) => file.path),
|
|
95
|
+
...workflowPathsForPlan(artifact.plan)
|
|
96
|
+
];
|
|
97
|
+
}
|
|
98
|
+
if ("mode" in artifact && artifact.mode === "validate" && isWorkflowPlan(artifact.plan))
|
|
99
|
+
return workflowPathsForPlan(artifact.plan);
|
|
100
|
+
return [];
|
|
101
|
+
};
|
|
102
|
+
var loadWorkflowContextPaths = async (workspace, runIdOrPlan, changedFiles) => {
|
|
103
|
+
const paths = [...changedFiles];
|
|
104
|
+
if (!runIdOrPlan)
|
|
105
|
+
return paths;
|
|
106
|
+
const inputPath = path2.isAbsolute(runIdOrPlan) ? runIdOrPlan : path2.join(workspace.workspaceRoot, runIdOrPlan);
|
|
107
|
+
const artifact = await safeReadJson(inputPath) ?? await safeReadJson(path2.join(workspace.workspaceRoot, workflowRunArtifactPath(runIdOrPlan)));
|
|
108
|
+
if (artifact && isWorkflowRunArtifact(artifact))
|
|
109
|
+
paths.push(...workflowPathsForArtifact(artifact));
|
|
110
|
+
return [...new Set(paths.filter(Boolean))];
|
|
111
|
+
};
|
|
112
|
+
var withoutPlaceholders = (value) => value.split("<").map((part, index) => index === 0 ? part : part.slice(part.indexOf(">") + 1)).join("");
|
|
113
|
+
var pathKey = (value) => withoutPlaceholders(value.replaceAll("\\", "/").replaceAll("*", "")).replace(/\/+/g, "/").replace(/^\/|\/$/g, "");
|
|
114
|
+
var isWorkflowRelatedDiagnostic = (diagnostic, workflowPaths) => {
|
|
115
|
+
if (!diagnostic.path)
|
|
116
|
+
return false;
|
|
117
|
+
const diagnosticPath = pathKey(diagnostic.path);
|
|
118
|
+
return workflowPaths.some((workflowPath) => {
|
|
119
|
+
const candidate = pathKey(workflowPath);
|
|
120
|
+
if (!candidate)
|
|
121
|
+
return false;
|
|
122
|
+
return diagnosticPath.startsWith(candidate) || candidate.startsWith(diagnosticPath) || diagnosticPath.includes(candidate);
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
// pkgs/@akanjs/devkit/context/doctor/doctorFindings.ts
|
|
127
|
+
var repairAction = (kind, command, reason, safeToRun) => ({
|
|
128
|
+
kind,
|
|
129
|
+
command,
|
|
130
|
+
reason,
|
|
131
|
+
safeToRun
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
class DoctorFindings {
|
|
135
|
+
#diagnostics = [];
|
|
136
|
+
#repairActions = [
|
|
137
|
+
repairAction("generated", "akan repair generated --app <app-or-lib>", "Refresh generated Akan files.", true),
|
|
138
|
+
repairAction("format", "akan repair format --target <app-or-lib-or-pkg>", "Run the formatter/linter repair path.", true)
|
|
139
|
+
];
|
|
140
|
+
report(diagnostic, action) {
|
|
141
|
+
this.#diagnostics.push({ ...diagnostic, repairActions: [action] });
|
|
142
|
+
this.#repairActions.push(action);
|
|
143
|
+
}
|
|
144
|
+
push(diagnostic) {
|
|
145
|
+
this.#diagnostics.push(diagnostic);
|
|
146
|
+
}
|
|
147
|
+
async result(workspace, context, { strict, workflowPaths }) {
|
|
148
|
+
const scopedDiagnostics = this.#diagnostics.map((diagnostic) => ({
|
|
149
|
+
...diagnostic,
|
|
150
|
+
scope: workflowPaths.length ? isWorkflowRelatedDiagnostic(diagnostic, workflowPaths) ? "workflow" : "baseline" : diagnostic.scope,
|
|
151
|
+
context: workflowPaths.length ? { ...diagnostic.context, paths: workflowPaths } : diagnostic.context
|
|
152
|
+
}));
|
|
153
|
+
const workflowDiagnostics = scopedDiagnostics.filter((diagnostic) => diagnostic.scope === "workflow");
|
|
154
|
+
const baselineDiagnostics = scopedDiagnostics.filter((diagnostic) => diagnostic.scope === "baseline");
|
|
155
|
+
return {
|
|
156
|
+
schemaVersion: 1,
|
|
157
|
+
repoName: context.repoName,
|
|
158
|
+
root: context.root,
|
|
159
|
+
strict,
|
|
160
|
+
status: scopedDiagnostics.some((diagnostic) => diagnostic.severity === "error") ? "failed" : "passed",
|
|
161
|
+
diagnostics: scopedDiagnostics,
|
|
162
|
+
generatedFiles: context.generatedFiles,
|
|
163
|
+
generatedFilesFreshness: await generatedFreshnessFromStates(workspace),
|
|
164
|
+
validationCommands: context.validationCommands,
|
|
165
|
+
repairActions: this.#repairActions,
|
|
166
|
+
...workflowPaths.length ? { baselineDiagnostics, workflowDiagnostics } : {}
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// pkgs/@akanjs/devkit/context/doctor/agentGuideCheck.ts
|
|
172
|
+
class AgentGuideCheck {
|
|
173
|
+
static async run(workspace, systems, findings) {
|
|
174
|
+
const agentDrift = await AgentGuideCheck.#drift(workspace);
|
|
175
|
+
if (agentDrift)
|
|
176
|
+
findings.report({ severity: "warning", code: agentDrift.code, path: "AGENTS.md", message: agentDrift.message }, repairAction("generated", "akan agent install agents-md", agentDrift.hint, true));
|
|
177
|
+
const sysPaths = systems.map((sys) => sys.path);
|
|
178
|
+
const oversize = await AgentGuideCheck.#oversize(workspace, sysPaths);
|
|
179
|
+
if (oversize)
|
|
180
|
+
findings.push({ severity: "warning", code: "agent-guide-oversized", path: "AGENTS.md", message: oversize });
|
|
181
|
+
for (const leftover of await AgentGuideCheck.#leftovers(workspace))
|
|
182
|
+
findings.push({ severity: "warning", code: "agent-guide-leftover", ...leftover });
|
|
183
|
+
}
|
|
184
|
+
static async#drift(workspace) {
|
|
185
|
+
const installed = await readDevkitVersion();
|
|
186
|
+
if (!installed)
|
|
187
|
+
return null;
|
|
188
|
+
const content = await safeReadText(path3.join(workspace.workspaceRoot, "AGENTS.md"));
|
|
189
|
+
if (content === null)
|
|
190
|
+
return null;
|
|
191
|
+
const stamped = extractBlockVersion(content);
|
|
192
|
+
if (stamped === installed)
|
|
193
|
+
return null;
|
|
194
|
+
const hint = "Re-render the AGENTS.md managed block from the installed framework release.";
|
|
195
|
+
if (!stamped)
|
|
196
|
+
return {
|
|
197
|
+
code: "agent-guide-unstamped",
|
|
198
|
+
message: `AGENTS.md carries no generated-version stamp, so its conventions may predate @akanjs/devkit ${installed}`,
|
|
199
|
+
hint
|
|
200
|
+
};
|
|
201
|
+
return {
|
|
202
|
+
code: "agent-guide-stale",
|
|
203
|
+
message: `AGENTS.md was generated by @akanjs/devkit ${stamped}, but ${installed} is installed`,
|
|
204
|
+
hint
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
static async#oversize(workspace, sysPaths) {
|
|
208
|
+
const sizeOf = async (file) => {
|
|
209
|
+
const content = await safeReadText(path3.join(workspace.workspaceRoot, file));
|
|
210
|
+
return { file, bytes: content === null ? 0 : Buffer.byteLength(content) };
|
|
211
|
+
};
|
|
212
|
+
const root = await sizeOf("AGENTS.md");
|
|
213
|
+
if (root.bytes === 0)
|
|
214
|
+
return null;
|
|
215
|
+
const scoped = await Promise.all(sysPaths.map((sysPath) => sizeOf(`${sysPath}/AGENTS.md`)));
|
|
216
|
+
const largest = scoped.reduce((max, entry) => entry.bytes > max.bytes ? entry : max, { file: "", bytes: 0 });
|
|
217
|
+
const total = root.bytes + largest.bytes;
|
|
218
|
+
if (total <= 32 * 1024 * 0.8)
|
|
219
|
+
return null;
|
|
220
|
+
const subject = largest.bytes ? `AGENTS.md and ${largest.file} add up to` : "AGENTS.md is";
|
|
221
|
+
return `${subject} ${Math.ceil(total / 1024)} KiB of the 32 KiB Codex reads \u2014 run \`akan agent install\`, then shorten the text outside the akan:agent markers or move it into a skill.`;
|
|
222
|
+
}
|
|
223
|
+
static async#leftovers(workspace) {
|
|
224
|
+
const root = workspace.workspaceRoot;
|
|
225
|
+
const guide = await safeReadText(path3.join(root, "AGENTS.md")) ?? "";
|
|
226
|
+
const leftovers = [];
|
|
227
|
+
for (const doc of ["docs/AI-DEVELOPMENT.md", "docs/GENERATED.md"]) {
|
|
228
|
+
const pointer = guide.includes(doc);
|
|
229
|
+
if (await safeReadText(path3.join(root, doc)) !== null)
|
|
230
|
+
leftovers.push({
|
|
231
|
+
path: doc,
|
|
232
|
+
message: `${doc} is an older template's copy of the agent guide, and nothing reads it now \u2014 delete it${pointer ? " and the AGENTS.md sentence that points to it" : ""}.`
|
|
233
|
+
});
|
|
234
|
+
else if (pointer)
|
|
235
|
+
leftovers.push({
|
|
236
|
+
path: "AGENTS.md",
|
|
237
|
+
message: `AGENTS.md points to ${doc}, which is gone \u2014 delete that sentence.`
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
return leftovers;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
32
243
|
|
|
33
|
-
// pkgs/@akanjs/devkit/
|
|
244
|
+
// pkgs/@akanjs/devkit/context/doctor/configLeftoverCheck.ts
|
|
245
|
+
import path4 from "path";
|
|
246
|
+
class ConfigLeftoverCheck {
|
|
247
|
+
static async run(workspace, systems, findings) {
|
|
248
|
+
const sysPaths = systems.map((sys) => sys.path);
|
|
249
|
+
for (const leftover of await ConfigLeftoverCheck.#leftovers(workspace, sysPaths))
|
|
250
|
+
findings.push({ severity: "warning", code: "config-leftover", ...leftover });
|
|
251
|
+
}
|
|
252
|
+
static async#leftovers(workspace, sysPaths) {
|
|
253
|
+
const leftovers = [];
|
|
254
|
+
for (const sysPath of sysPaths) {
|
|
255
|
+
const tsconfigPath = `${sysPath}/tsconfig.json`;
|
|
256
|
+
const tsconfig = await safeReadText(path4.join(workspace.workspaceRoot, tsconfigPath));
|
|
257
|
+
if (tsconfig && (/"name"\s*:\s*"next"/.test(tsconfig) || tsconfig.includes(".next/types")))
|
|
258
|
+
leftovers.push({
|
|
259
|
+
path: tsconfigPath,
|
|
260
|
+
message: `${tsconfigPath} still names the Next.js TS plugin or .next/types, which Akan never uses \u2014 delete the "next" plugin entry and the ".next/types/**/*.ts" include.`
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
const bunfig = await safeReadText(path4.join(workspace.workspaceRoot, "bunfig.toml"));
|
|
264
|
+
if (bunfig?.includes("bun-plugin-tailwind"))
|
|
265
|
+
leftovers.push({
|
|
266
|
+
path: "bunfig.toml",
|
|
267
|
+
message: "bunfig.toml still loads bun-plugin-tailwind, which is not installed and which Akan never uses (it compiles Tailwind itself) \u2014 delete the [serve.static] section, which Akan never reads."
|
|
268
|
+
});
|
|
269
|
+
return leftovers;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// pkgs/@akanjs/devkit/context/doctor/moduleShapeCheck.ts
|
|
274
|
+
import path5 from "path";
|
|
275
|
+
import { capitalize } from "akanjs/common";
|
|
276
|
+
|
|
277
|
+
// pkgs/@akanjs/devkit/context/moduleFieldNames.ts
|
|
34
278
|
import ts from "typescript";
|
|
35
279
|
var isFieldCall = (node) => ts.isCallExpression(node) && (ts.isIdentifier(node.expression) ? node.expression.text === "field" : ts.isPropertyAccessExpression(node.expression) && isFieldCall(node.expression.expression));
|
|
36
|
-
var
|
|
280
|
+
var propertyNames = (content, declares) => {
|
|
37
281
|
const names = [];
|
|
38
282
|
const visit = (node) => {
|
|
39
|
-
if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name) &&
|
|
283
|
+
if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name) && declares(node.initializer))
|
|
40
284
|
names.push(node.name.text);
|
|
41
285
|
ts.forEachChild(node, visit);
|
|
42
286
|
};
|
|
43
|
-
visit(ts.createSourceFile("
|
|
287
|
+
visit(ts.createSourceFile("module.ts", content, ts.ScriptTarget.Latest));
|
|
44
288
|
return names;
|
|
45
289
|
};
|
|
290
|
+
var constantFieldNames = (content) => propertyNames(content, isFieldCall);
|
|
291
|
+
var unlabeledFieldNames = (constantContent, dictionaryContent) => {
|
|
292
|
+
const labels = new Set(propertyNames(dictionaryContent, () => true));
|
|
293
|
+
return constantFieldNames(constantContent).filter((name) => !labels.has(name));
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
// pkgs/@akanjs/devkit/context/doctor/moduleShapeCheck.ts
|
|
297
|
+
var moduleShapeFiles = (module) => {
|
|
298
|
+
if (module.kind === "service") {
|
|
299
|
+
return [`${module.name}.dictionary.ts`, `${module.name}.service.ts`, `${module.name}.signal.ts`];
|
|
300
|
+
}
|
|
301
|
+
if (module.kind === "scalar")
|
|
302
|
+
return [`${module.name}.constant.ts`, `${module.name}.dictionary.ts`];
|
|
303
|
+
return [
|
|
304
|
+
`${module.name}.constant.ts`,
|
|
305
|
+
`${module.name}.dictionary.ts`,
|
|
306
|
+
`${module.name}.service.ts`,
|
|
307
|
+
`${module.name}.store.ts`,
|
|
308
|
+
`${module.name}.signal.ts`
|
|
309
|
+
];
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
class ModuleShapeCheck {
|
|
313
|
+
static async run(workspace, systems, findings, { strict }) {
|
|
314
|
+
for (const sys of systems) {
|
|
315
|
+
for (const module of sys.modules) {
|
|
316
|
+
const moduleShapeCommand = `akan repair module-shape --app ${sys.name} --module ${module.name}`;
|
|
317
|
+
if (!module.abstract.exists)
|
|
318
|
+
findings.report({
|
|
319
|
+
severity: strict ? "error" : "warning",
|
|
320
|
+
code: "module-abstract-missing",
|
|
321
|
+
path: module.abstract.path,
|
|
322
|
+
message: `${capitalize(module.kind)} module ${sys.name}:${module.name} should include ${module.abstract.path}`
|
|
323
|
+
}, repairAction("module-shape", moduleShapeCommand, "Create the missing module abstract or inspect required source files.", false));
|
|
324
|
+
const missingFiles = moduleShapeFiles(module).filter((filename) => !module.files.includes(filename));
|
|
325
|
+
if (missingFiles.length)
|
|
326
|
+
findings.report({
|
|
327
|
+
severity: "error",
|
|
328
|
+
code: "module-shape-invalid",
|
|
329
|
+
path: module.path,
|
|
330
|
+
message: `${capitalize(module.kind)} module ${sys.name}:${module.name} is missing required files: ${missingFiles.join(", ")}`
|
|
331
|
+
}, repairAction("module-shape", moduleShapeCommand, "Review missing required module source files.", false));
|
|
332
|
+
if (module.kind !== "service" && module.files.includes(`${module.name}.dictionary.ts`)) {
|
|
333
|
+
const constantPath = path5.join(workspace.workspaceRoot, module.path, `${module.name}.constant.ts`);
|
|
334
|
+
const dictionaryPath = path5.join(workspace.workspaceRoot, module.path, `${module.name}.dictionary.ts`);
|
|
335
|
+
const [constantContent, dictionaryContent] = await Promise.all([
|
|
336
|
+
safeReadText(constantPath),
|
|
337
|
+
safeReadText(dictionaryPath)
|
|
338
|
+
]);
|
|
339
|
+
if (constantContent && dictionaryContent) {
|
|
340
|
+
for (const fieldName of unlabeledFieldNames(constantContent, dictionaryContent)) {
|
|
341
|
+
findings.report({
|
|
342
|
+
severity: "warning",
|
|
343
|
+
code: "dictionary-label-missing",
|
|
344
|
+
path: `${module.path}/${module.name}.dictionary.ts`,
|
|
345
|
+
message: `Dictionary labels for ${sys.name}:${module.name}.${fieldName} were not found.`
|
|
346
|
+
}, repairAction("dictionary", `akan repair dictionary --app ${sys.name} --module ${module.name}`, "Add missing dictionary labels for source constant fields.", false));
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
46
354
|
|
|
47
|
-
// pkgs/@akanjs/devkit/
|
|
355
|
+
// pkgs/@akanjs/devkit/context/doctor/recipeDuplicateCheck.ts
|
|
356
|
+
import path6 from "path";
|
|
357
|
+
class RecipeDuplicateCheck {
|
|
358
|
+
static async run(workspace, systems, findings) {
|
|
359
|
+
for (const sys of systems) {
|
|
360
|
+
const sources = await collectRecipeSources2(path6.join(workspace.workspaceRoot, sys.path, "ui"), "ui");
|
|
361
|
+
if (sources.length === 0)
|
|
362
|
+
continue;
|
|
363
|
+
const recipes = scanRecipes2(sources);
|
|
364
|
+
const files = [];
|
|
365
|
+
const glob = new Bun.Glob("**/*.tsx");
|
|
366
|
+
for await (const abs of glob.scan({ cwd: path6.join(workspace.workspaceRoot, sys.path), absolute: true })) {
|
|
367
|
+
if (/[\\/](node_modules|\.akan|dist)[\\/]|[\\/]v1[\\/]/.test(abs) || /\.(test|spec)\.tsx$/.test(abs))
|
|
368
|
+
continue;
|
|
369
|
+
files.push({
|
|
370
|
+
path: abs,
|
|
371
|
+
content: await Bun.file(abs).text().catch(() => "")
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
const duplicates = findInlineRecipeDuplicates2(recipes, files);
|
|
375
|
+
if (duplicates.length === 0)
|
|
376
|
+
continue;
|
|
377
|
+
const preview = duplicates.slice(0, 3).map((duplicate) => `${path6.relative(workspace.workspaceRoot, duplicate.path)}:${duplicate.line}`).join(", ");
|
|
378
|
+
findings.push({
|
|
379
|
+
severity: "warning",
|
|
380
|
+
code: "recipe-inline-duplicate",
|
|
381
|
+
path: path6.join(sys.path, "ui/Recipe"),
|
|
382
|
+
message: `${sys.name}: ${duplicates.length} inline className(s) re-author a recipe fingerprint (${preview}${duplicates.length > 3 ? ", \u2026" : ""}) \u2014 consume the recipe instead.`
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// pkgs/@akanjs/devkit/context/doctor/recipeIndexCheck.ts
|
|
389
|
+
import path7 from "path";
|
|
390
|
+
class RecipeIndexCheck {
|
|
391
|
+
static async run(workspace, systems, findings) {
|
|
392
|
+
const scanNames = async (uiDirPath, basename) => new Set(scanRecipes2(await collectRecipeSources2(uiDirPath, "ui", basename)).map((info) => info.name));
|
|
393
|
+
const declaredByImport = new Map;
|
|
394
|
+
declaredByImport.set("akanjs/ui", await scanNames(path7.join(workspace.workspaceRoot, "pkgs/akanjs/ui"), "recipe"));
|
|
395
|
+
for (const sys of systems)
|
|
396
|
+
declaredByImport.set(`@${sys.path}/ui`, await scanNames(path7.join(workspace.workspaceRoot, sys.path, "ui")));
|
|
397
|
+
const sectionOf = (content, heading) => {
|
|
398
|
+
const match = new RegExp(`^${heading}$`, "m").exec(content);
|
|
399
|
+
if (!match)
|
|
400
|
+
return "";
|
|
401
|
+
const section = content.slice(match.index);
|
|
402
|
+
const sectionEnd = section.indexOf(`
|
|
403
|
+
## `, 1);
|
|
404
|
+
return sectionEnd === -1 ? section : section.slice(0, sectionEnd);
|
|
405
|
+
};
|
|
406
|
+
const listedByImport = (body) => {
|
|
407
|
+
const groups = new Map;
|
|
408
|
+
let current = null;
|
|
409
|
+
for (const line of body.split(`
|
|
410
|
+
`)) {
|
|
411
|
+
const group = /^Import from `([^`]+)`:/.exec(line);
|
|
412
|
+
if (group) {
|
|
413
|
+
current = groups.get(group[1]) ?? new Set;
|
|
414
|
+
groups.set(group[1], current);
|
|
415
|
+
continue;
|
|
416
|
+
}
|
|
417
|
+
const item = /^- `([A-Za-z0-9_$]+)`/.exec(line);
|
|
418
|
+
if (item && current)
|
|
419
|
+
current.add(item[1]);
|
|
420
|
+
else if (!item)
|
|
421
|
+
current = null;
|
|
422
|
+
}
|
|
423
|
+
return groups;
|
|
424
|
+
};
|
|
425
|
+
const pushIndexDiagnostic = (indexPath, missing, stale, repairCommand) => {
|
|
426
|
+
if (missing.length === 0 && stale.length === 0)
|
|
427
|
+
return;
|
|
428
|
+
const parts = [
|
|
429
|
+
missing.length > 0 ? `${missing.length} declared but unlisted (${missing.slice(0, 5).join(", ")})` : "",
|
|
430
|
+
stale.length > 0 ? `${stale.length} listed but gone (${stale.slice(0, 5).join(", ")})` : ""
|
|
431
|
+
].filter(Boolean);
|
|
432
|
+
findings.report({
|
|
433
|
+
severity: "error",
|
|
434
|
+
code: "recipe-index-stale",
|
|
435
|
+
path: indexPath,
|
|
436
|
+
message: `${indexPath} recipe index is out of date \u2014 ${parts.join("; ")}. Agents read this list as authoritative.`
|
|
437
|
+
}, repairAction("generated", repairCommand, "Regenerate the recipe index from the scanned recipes.", true));
|
|
438
|
+
};
|
|
439
|
+
const frameworkDeclared = declaredByImport.get("akanjs/ui") ?? new Set;
|
|
440
|
+
if (frameworkDeclared.size > 0) {
|
|
441
|
+
const agentsMd = await Bun.file(path7.join(workspace.workspaceRoot, "AGENTS.md")).text().catch(() => "");
|
|
442
|
+
const listed = listedByImport(sectionOf(agentsMd, "## Recipes")).get("akanjs/ui") ?? new Set;
|
|
443
|
+
pushIndexDiagnostic("AGENTS.md", [...frameworkDeclared].filter((name) => !listed.has(name)).sort((a, b) => a < b ? -1 : a > b ? 1 : 0), [...listed].filter((name) => !frameworkDeclared.has(name)).sort((a, b) => a < b ? -1 : a > b ? 1 : 0), "akan agent install agents-md");
|
|
444
|
+
}
|
|
445
|
+
for (const sys of systems) {
|
|
446
|
+
const own = declaredByImport.get(`@${sys.path}/ui`) ?? new Set;
|
|
447
|
+
const scopeMd = await Bun.file(path7.join(workspace.workspaceRoot, sys.path, "AGENTS.md")).text().catch(() => "");
|
|
448
|
+
const groups = listedByImport(sectionOf(scopeMd, "## Recipes In Scope"));
|
|
449
|
+
const ownListed = groups.get(`@${sys.path}/ui`) ?? new Set;
|
|
450
|
+
const missing = [...own].filter((name) => !ownListed.has(name)).sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
451
|
+
const stale = [...groups.entries()].flatMap(([importFrom, names]) => [...names].filter((name) => !(declaredByImport.get(importFrom) ?? new Set).has(name))).sort();
|
|
452
|
+
pushIndexDiagnostic(`${sys.path}/AGENTS.md`, missing, stale, `akan sync ${sys.name}`);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// pkgs/@akanjs/devkit/context/doctor/rootShapeCheck.ts
|
|
458
|
+
import path8 from "path";
|
|
459
|
+
class RootShapeCheck {
|
|
460
|
+
static async run(workspace, systems, findings) {
|
|
461
|
+
for (const sys of systems) {
|
|
462
|
+
const sysPath = path8.join(workspace.workspaceRoot, sys.path);
|
|
463
|
+
for (const entry of await safeReadDir(sysPath)) {
|
|
464
|
+
if (!isScannedRootEntry(sys.type, entry.name))
|
|
465
|
+
continue;
|
|
466
|
+
const allowed = entry.isDirectory() ? rootAllowedDirs[sys.type].has(entry.name) : rootAllowedFiles[sys.type].has(entry.name);
|
|
467
|
+
const rootEntryHint = rootEntryHintOf(sys.type, entry.name);
|
|
468
|
+
if (!allowed)
|
|
469
|
+
findings.report({
|
|
470
|
+
severity: "error",
|
|
471
|
+
code: `${sys.type}-root-unknown-entry`,
|
|
472
|
+
path: `${sys.path}/${entry.name}`,
|
|
473
|
+
message: `Unexpected ${entry.isDirectory() ? "folder" : "file"} in ${sys.type} root: ${sys.path}/${entry.name}${rootEntryHint ? ` (${rootEntryHint})` : ""}`
|
|
474
|
+
}, repairAction("module-shape", `akan repair module-shape --app ${sys.name}`, `Review ${sys.type} root shape and remove or move the unknown entry.`, false));
|
|
475
|
+
}
|
|
476
|
+
for (const facet of barrelFacetDirs)
|
|
477
|
+
for (const entry of await safeReadDir(path8.join(sysPath, facet))) {
|
|
478
|
+
const shadow = entry.isDirectory() ? null : facetIndexShadowOf(`${facet}/${entry.name}`);
|
|
479
|
+
if (!shadow)
|
|
480
|
+
continue;
|
|
481
|
+
const entryPath = `${sys.path}/${facet}/${entry.name}`;
|
|
482
|
+
findings.report({ severity: "error", code: "facet-index-shadowed", path: entryPath, message: `${entryPath} ${shadow}` }, repairAction("generated", `akan sync ${sys.name}`, `Delete ${entryPath} by hand, then sync.`, false));
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// pkgs/@akanjs/devkit/context/akanContext.ts
|
|
48
489
|
var guidelineResourceUri = (name) => `akan://guidelines/${name}`;
|
|
49
490
|
var staticResourceList = [
|
|
50
491
|
{ uri: "akan://docs/framework", name: "Akan framework guide", mimeType: "text/markdown" },
|
|
@@ -112,145 +553,49 @@ ${nextBlock}`;
|
|
|
112
553
|
return `${before}${nextBlock}${separator}${after}`;
|
|
113
554
|
};
|
|
114
555
|
var renderDoctorText = (result) => {
|
|
115
|
-
const lines = [`Akan doctor status: ${result.status}`];
|
|
116
|
-
if (result.diagnostics.length === 0) {
|
|
117
|
-
lines.push("", "No Akan workspace diagnostics found.");
|
|
118
|
-
} else {
|
|
119
|
-
lines.push("", ...result.diagnostics.map((diagnostic) => [
|
|
120
|
-
`[${diagnostic.severity}] ${diagnostic.code}: ${diagnostic.message}`,
|
|
121
|
-
diagnostic.path ? ` ${diagnostic.path}` : ""
|
|
122
|
-
].filter(Boolean).join(`
|
|
123
|
-
`)));
|
|
124
|
-
}
|
|
125
|
-
lines.push("", "Generated file freshness:", `Status: ${result.generatedFilesFreshness.status}`, result.generatedFilesFreshness.message, `Refresh: ${result.generatedFilesFreshness.refreshCommand}`, "", "Repair actions:", ...result.repairActions.length ? result.repairActions.map((action) => `- ${action.command}`) : ["- none"], "", "Validation commands:", ...result.validationCommands.map((command) => `- ${command}`));
|
|
126
|
-
return `${lines.join(`
|
|
127
|
-
`)}
|
|
128
|
-
`;
|
|
129
|
-
};
|
|
130
|
-
var generatedFiles = [
|
|
131
|
-
"apps/*/client.ts",
|
|
132
|
-
"apps/*/server.ts",
|
|
133
|
-
"*/lib/cnst.ts",
|
|
134
|
-
"*/lib/db.ts",
|
|
135
|
-
"*/lib/dict.ts",
|
|
136
|
-
"*/lib/sig.ts",
|
|
137
|
-
"*/lib/srv.ts",
|
|
138
|
-
"*/lib/st.ts",
|
|
139
|
-
"*/lib/useClient.ts",
|
|
140
|
-
"*/lib/useServer.ts",
|
|
141
|
-
"*/lib/**/index.ts",
|
|
142
|
-
"*/ui/index.ts",
|
|
143
|
-
"*/webkit/index.ts",
|
|
144
|
-
"*/srvkit/index.ts",
|
|
145
|
-
"*/common/index.ts"
|
|
146
|
-
];
|
|
147
|
-
var validationCommands = [
|
|
148
|
-
"akan verify [<app-or-lib-or-pkg>]",
|
|
149
|
-
"akan sync <app-or-lib>",
|
|
150
|
-
"akan lint <app-or-lib-or-pkg>",
|
|
151
|
-
"akan typecheck <app-or-lib>",
|
|
152
|
-
"akan test <app-or-lib-or-pkg>",
|
|
153
|
-
"akan build <app-name>",
|
|
154
|
-
"akan doctor --strict --format json",
|
|
155
|
-
"akan quality scan [--format json]",
|
|
156
|
-
"akan quality ssr [--format json]"
|
|
157
|
-
];
|
|
158
|
-
var unknownGeneratedFilesFreshness = {
|
|
159
|
-
status: "unknown",
|
|
160
|
-
message: "Run sync before validation so generated Akan files match the current source conventions.",
|
|
161
|
-
refreshCommand: "akan sync <app-or-lib>",
|
|
162
|
-
verifyingCommands: ["akan verify <app-or-lib>"]
|
|
163
|
-
};
|
|
164
|
-
var repairAction = (kind, command, reason, safeToRun) => ({
|
|
165
|
-
kind,
|
|
166
|
-
command,
|
|
167
|
-
reason,
|
|
168
|
-
safeToRun
|
|
169
|
-
});
|
|
170
|
-
var moduleShapeFiles = (module) => {
|
|
171
|
-
if (module.kind === "service") {
|
|
172
|
-
return [`${module.name}.dictionary.ts`, `${module.name}.service.ts`, `${module.name}.signal.ts`];
|
|
173
|
-
}
|
|
174
|
-
if (module.kind === "scalar")
|
|
175
|
-
return [`${module.name}.constant.ts`, `${module.name}.dictionary.ts`];
|
|
176
|
-
return [
|
|
177
|
-
`${module.name}.constant.ts`,
|
|
178
|
-
`${module.name}.dictionary.ts`,
|
|
179
|
-
`${module.name}.service.ts`,
|
|
180
|
-
`${module.name}.store.ts`,
|
|
181
|
-
`${module.name}.signal.ts`
|
|
182
|
-
];
|
|
183
|
-
};
|
|
184
|
-
var safeReadDir = async (dirPath) => (await readdir(dirPath, { withFileTypes: true }).catch(() => [])).sort((a, b) => a.name.localeCompare(b.name));
|
|
185
|
-
var safeReadText = (filePath) => FileSys2.readText(filePath).catch(() => null);
|
|
186
|
-
var safeReadJson = (filePath) => FileSys2.readJson(filePath).catch(() => null);
|
|
187
|
-
var isWorkflowPlan = (value) => typeof value === "object" && value !== null && ("schemaVersion" in value) && value.schemaVersion === 1 && ("mode" in value) && value.mode === "plan" && ("inputs" in value) && isRecord(value.inputs) && ("predictedChanges" in value) && Array.isArray(value.predictedChanges) && value.predictedChanges.every((change) => isRecord(change) && typeof change.target === "string");
|
|
188
|
-
var isPathList = (value) => Array.isArray(value) && value.every((file) => isRecord(file) && typeof file.path === "string");
|
|
189
|
-
var isWorkflowApplyReport = (value) => typeof value === "object" && value !== null && ("schemaVersion" in value) && value.schemaVersion === 1 && ("mode" in value) && (value.mode === "apply" || value.mode === "dry-run") && ("changedFiles" in value) && isPathList(value.changedFiles) && ("generatedFiles" in value) && isPathList(value.generatedFiles) && ("plan" in value) && isWorkflowPlan(value.plan);
|
|
190
|
-
var isWorkflowRunArtifact = (value) => typeof value === "object" && value !== null && ("schemaVersion" in value) && value.schemaVersion === 1;
|
|
191
|
-
var workflowPathsForArtifact = (artifact) => {
|
|
192
|
-
if (isWorkflowPlan(artifact))
|
|
193
|
-
return workflowPathsForPlan(artifact);
|
|
194
|
-
if (isWorkflowApplyReport(artifact)) {
|
|
195
|
-
return [
|
|
196
|
-
...artifact.changedFiles.map((file) => file.path),
|
|
197
|
-
...artifact.generatedFiles.map((file) => file.path),
|
|
198
|
-
...workflowPathsForPlan(artifact.plan)
|
|
199
|
-
];
|
|
200
|
-
}
|
|
201
|
-
if ("mode" in artifact && artifact.mode === "validate" && isWorkflowPlan(artifact.plan))
|
|
202
|
-
return workflowPathsForPlan(artifact.plan);
|
|
203
|
-
return [];
|
|
204
|
-
};
|
|
205
|
-
var loadWorkflowContextPaths = async (workspace, runIdOrPlan, changedFiles) => {
|
|
206
|
-
const paths = [...changedFiles];
|
|
207
|
-
if (!runIdOrPlan)
|
|
208
|
-
return paths;
|
|
209
|
-
const inputPath = path.isAbsolute(runIdOrPlan) ? runIdOrPlan : path.join(workspace.workspaceRoot, runIdOrPlan);
|
|
210
|
-
const artifact = await safeReadJson(inputPath) ?? await safeReadJson(path.join(workspace.workspaceRoot, workflowRunArtifactPath(runIdOrPlan)));
|
|
211
|
-
if (artifact && isWorkflowRunArtifact(artifact))
|
|
212
|
-
paths.push(...workflowPathsForArtifact(artifact));
|
|
213
|
-
return [...new Set(paths.filter(Boolean))];
|
|
214
|
-
};
|
|
215
|
-
var pathKey = (value) => value.replaceAll("\\", "/").replaceAll("*", "").replace(/<[^>]+>/g, "").replace(/\/+/g, "/").replace(/^\/|\/$/g, "");
|
|
216
|
-
var isWorkflowRelatedDiagnostic = (diagnostic, workflowPaths) => {
|
|
217
|
-
if (!diagnostic.path)
|
|
218
|
-
return false;
|
|
219
|
-
const diagnosticPath = pathKey(diagnostic.path);
|
|
220
|
-
return workflowPaths.some((workflowPath) => {
|
|
221
|
-
const candidate = pathKey(workflowPath);
|
|
222
|
-
if (!candidate)
|
|
223
|
-
return false;
|
|
224
|
-
return diagnosticPath.startsWith(candidate) || candidate.startsWith(diagnosticPath) || diagnosticPath.includes(candidate);
|
|
225
|
-
});
|
|
226
|
-
};
|
|
227
|
-
var readGeneratedSyncStates = async (workspace) => {
|
|
228
|
-
const syncDir = path.join(workspace.workspaceRoot, workflowSyncDir);
|
|
229
|
-
const entries = await safeReadDir(syncDir);
|
|
230
|
-
const states = await Promise.all(entries.filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => safeReadJson(path.join(syncDir, entry.name))));
|
|
231
|
-
return states.filter((state) => !!state && state.schemaVersion === 1 && typeof state.target === "string" && typeof state.syncedAt === "string");
|
|
232
|
-
};
|
|
233
|
-
var generatedFreshnessFromStates = async (workspace) => {
|
|
234
|
-
const states = await readGeneratedSyncStates(workspace);
|
|
235
|
-
if (states.length === 0)
|
|
236
|
-
return unknownGeneratedFilesFreshness;
|
|
237
|
-
const targets = states.sort((a, b) => a.target.localeCompare(b.target)).map((state) => ({
|
|
238
|
-
target: state.target,
|
|
239
|
-
status: state.status === "passed" ? "fresh" : "stale",
|
|
240
|
-
lastSyncedAt: state.syncedAt,
|
|
241
|
-
runId: state.runId,
|
|
242
|
-
generatedFiles: state.generatedFiles.map((file) => file.path),
|
|
243
|
-
reason: state.status === "passed" ? `Generated files were refreshed by ${state.command}.` : `Last generated repair command failed: ${state.command}.`
|
|
244
|
-
}));
|
|
245
|
-
const lastFresh = targets.filter((target) => target.status === "fresh" && target.lastSyncedAt).sort((a, b) => (b.lastSyncedAt ?? "").localeCompare(a.lastSyncedAt ?? ""))[0];
|
|
246
|
-
return {
|
|
247
|
-
status: targets.some((target) => target.status === "fresh") ? "fresh" : "stale",
|
|
248
|
-
message: lastFresh ? `Generated files were refreshed for ${lastFresh.target} at ${lastFresh.lastSyncedAt}.` : "Generated sync state exists, but the last recorded repair did not pass.",
|
|
249
|
-
refreshCommand: "akan sync <app-or-lib>",
|
|
250
|
-
verifyingCommands: ["akan verify <app-or-lib>"],
|
|
251
|
-
targets
|
|
252
|
-
};
|
|
556
|
+
const lines = [`Akan doctor status: ${result.status}`];
|
|
557
|
+
if (result.diagnostics.length === 0) {
|
|
558
|
+
lines.push("", "No Akan workspace diagnostics found.");
|
|
559
|
+
} else {
|
|
560
|
+
lines.push("", ...result.diagnostics.map((diagnostic) => [
|
|
561
|
+
`[${diagnostic.severity}] ${diagnostic.code}: ${diagnostic.message}`,
|
|
562
|
+
diagnostic.path ? ` ${diagnostic.path}` : ""
|
|
563
|
+
].filter(Boolean).join(`
|
|
564
|
+
`)));
|
|
565
|
+
}
|
|
566
|
+
lines.push("", "Generated file freshness:", `Status: ${result.generatedFilesFreshness.status}`, result.generatedFilesFreshness.message, `Refresh: ${result.generatedFilesFreshness.refreshCommand}`, "", "Repair actions:", ...result.repairActions.length ? result.repairActions.map((action) => `- ${action.command}`) : ["- none"], "", "Validation commands:", ...result.validationCommands.map((command) => `- ${command}`));
|
|
567
|
+
return `${lines.join(`
|
|
568
|
+
`)}
|
|
569
|
+
`;
|
|
253
570
|
};
|
|
571
|
+
var generatedFiles = [
|
|
572
|
+
"apps/*/client.ts",
|
|
573
|
+
"apps/*/server.ts",
|
|
574
|
+
"*/lib/cnst.ts",
|
|
575
|
+
"*/lib/db.ts",
|
|
576
|
+
"*/lib/dict.ts",
|
|
577
|
+
"*/lib/sig.ts",
|
|
578
|
+
"*/lib/srv.ts",
|
|
579
|
+
"*/lib/st.ts",
|
|
580
|
+
"*/lib/useClient.ts",
|
|
581
|
+
"*/lib/useServer.ts",
|
|
582
|
+
"*/lib/**/index.ts",
|
|
583
|
+
"*/ui/index.ts",
|
|
584
|
+
"*/webkit/index.ts",
|
|
585
|
+
"*/srvkit/index.ts",
|
|
586
|
+
"*/common/index.ts"
|
|
587
|
+
];
|
|
588
|
+
var validationCommands = [
|
|
589
|
+
"akan verify [<app-or-lib-or-pkg>]",
|
|
590
|
+
"akan sync <app-or-lib>",
|
|
591
|
+
"akan lint <app-or-lib-or-pkg>",
|
|
592
|
+
"akan typecheck <app-or-lib>",
|
|
593
|
+
"akan test <app-or-lib-or-pkg>",
|
|
594
|
+
"akan build <app-name>",
|
|
595
|
+
"akan doctor --strict --format json",
|
|
596
|
+
"akan quality scan [--format json]",
|
|
597
|
+
"akan quality ssr [--format json]"
|
|
598
|
+
];
|
|
254
599
|
var parseAbstractSummary = (relativePath, content, includeContent) => {
|
|
255
600
|
if (content === null)
|
|
256
601
|
return { path: relativePath, exists: false, headings: [] };
|
|
@@ -264,12 +609,12 @@ var parseAbstractSummary = (relativePath, content, includeContent) => {
|
|
|
264
609
|
};
|
|
265
610
|
};
|
|
266
611
|
var readFiles = async (dirPath) => (await safeReadDir(dirPath)).filter((entry) => entry.isFile()).map((entry) => entry.name).sort();
|
|
267
|
-
var getRelative = (workspace, absolutePath) =>
|
|
612
|
+
var getRelative = (workspace, absolutePath) => path9.relative(workspace.workspaceRoot, absolutePath).replaceAll(path9.sep, "/");
|
|
268
613
|
var createModuleContext = async (workspace, sys, kind, folderName, moduleName, includeAbstractContent) => {
|
|
269
|
-
const modulePath = kind === "scalar" ?
|
|
614
|
+
const modulePath = kind === "scalar" ? path9.join(sys.cwdPath, "lib", "__scalar", moduleName) : path9.join(sys.cwdPath, "lib", folderName);
|
|
270
615
|
const relativePath = getRelative(workspace, modulePath);
|
|
271
616
|
const abstractPath = `${relativePath}/${moduleName}.abstract.md`;
|
|
272
|
-
const abstractContent = await safeReadText(
|
|
617
|
+
const abstractContent = await safeReadText(path9.join(workspace.workspaceRoot, abstractPath));
|
|
273
618
|
return {
|
|
274
619
|
kind,
|
|
275
620
|
name: moduleName,
|
|
@@ -285,7 +630,7 @@ var getSysModules = async (workspace, sys, {
|
|
|
285
630
|
includeAbstractContent = false,
|
|
286
631
|
module: moduleFilter
|
|
287
632
|
} = {}) => {
|
|
288
|
-
const libPath =
|
|
633
|
+
const libPath = path9.join(sys.cwdPath, "lib");
|
|
289
634
|
const entries = await safeReadDir(libPath);
|
|
290
635
|
const modules = [];
|
|
291
636
|
for (const entry of entries) {
|
|
@@ -299,24 +644,24 @@ var getSysModules = async (workspace, sys, {
|
|
|
299
644
|
const serviceName = entry.name.replace(/^_+/, "");
|
|
300
645
|
if (moduleFilter && moduleFilter !== serviceName && moduleFilter !== entry.name)
|
|
301
646
|
continue;
|
|
302
|
-
if (!await FileSys2.fileExists(
|
|
647
|
+
if (!await FileSys2.fileExists(path9.join(libPath, entry.name, `${serviceName}.service.ts`)))
|
|
303
648
|
continue;
|
|
304
649
|
modules.push(await createModuleContext(workspace, sys, "service", entry.name, serviceName, includeAbstractContent));
|
|
305
650
|
} else {
|
|
306
651
|
if (moduleFilter && moduleFilter !== entry.name)
|
|
307
652
|
continue;
|
|
308
|
-
if (!await FileSys2.fileExists(
|
|
653
|
+
if (!await FileSys2.fileExists(path9.join(libPath, entry.name, `${entry.name}.constant.ts`)))
|
|
309
654
|
continue;
|
|
310
655
|
modules.push(await createModuleContext(workspace, sys, "domain", entry.name, entry.name, includeAbstractContent));
|
|
311
656
|
}
|
|
312
657
|
}
|
|
313
|
-
const scalarRoot =
|
|
658
|
+
const scalarRoot = path9.join(libPath, "__scalar");
|
|
314
659
|
for (const entry of await safeReadDir(scalarRoot)) {
|
|
315
660
|
if (!entry.isDirectory() || entry.name.startsWith("_"))
|
|
316
661
|
continue;
|
|
317
662
|
if (moduleFilter && moduleFilter !== entry.name)
|
|
318
663
|
continue;
|
|
319
|
-
if (!await FileSys2.fileExists(
|
|
664
|
+
if (!await FileSys2.fileExists(path9.join(scalarRoot, entry.name, `${entry.name}.constant.ts`)))
|
|
320
665
|
continue;
|
|
321
666
|
modules.push(await createModuleContext(workspace, sys, "scalar", entry.name, entry.name, includeAbstractContent));
|
|
322
667
|
}
|
|
@@ -339,7 +684,7 @@ var getAppRoutes = async (app, workspaceRoot) => {
|
|
|
339
684
|
const underGuard = Array.from({ length: reach + 1 }, (_, idx) => segments.slice(0, idx).join("/")).some((prefix) => guardedLayouts.has(prefix));
|
|
340
685
|
return {
|
|
341
686
|
path: parsed.pattern.replace(/^\/:lang/, "") || "/",
|
|
342
|
-
file:
|
|
687
|
+
file: path9.relative(workspaceRoot, source.absPath).replaceAll(path9.sep, "/"),
|
|
343
688
|
search: source.info.chain?.search ?? [],
|
|
344
689
|
guarded: !!source.info.chain?.guarded || underGuard,
|
|
345
690
|
devOnly: source.info.devOnly
|
|
@@ -347,18 +692,18 @@ var getAppRoutes = async (app, workspaceRoot) => {
|
|
|
347
692
|
}).sort((a, b) => a.path.localeCompare(b.path));
|
|
348
693
|
};
|
|
349
694
|
var getSysContext = async (workspace, type, name, options) => {
|
|
350
|
-
const sys = type === "app" ?
|
|
695
|
+
const sys = type === "app" ? AppExecutor2.from(workspace, name) : LibExecutor2.from(workspace, name);
|
|
351
696
|
const context = {
|
|
352
697
|
type,
|
|
353
698
|
name,
|
|
354
699
|
path: `${type}s/${name}`,
|
|
355
|
-
hasConfig: await FileSys2.fileExists(
|
|
700
|
+
hasConfig: await FileSys2.fileExists(path9.join(sys.cwdPath, "akan.config.ts")),
|
|
356
701
|
modules: await getSysModules(workspace, sys, {
|
|
357
702
|
includeAbstractContent: options.includeAbstractContent,
|
|
358
703
|
module: options.module
|
|
359
704
|
})
|
|
360
705
|
};
|
|
361
|
-
if (sys instanceof
|
|
706
|
+
if (sys instanceof AppExecutor2 && options.app === name)
|
|
362
707
|
await getAppRoutes(sys, workspace.workspaceRoot).then((routes) => context.routes = routes, (error) => context.routeError = error instanceof Error ? error.message : String(error));
|
|
363
708
|
return context;
|
|
364
709
|
};
|
|
@@ -366,13 +711,13 @@ var getSysContext = async (workspace, type, name, options) => {
|
|
|
366
711
|
class AkanContextAnalyzer {
|
|
367
712
|
static async analyze(workspace, options = {}) {
|
|
368
713
|
const [appNames, libNames, pkgNames] = await workspace.getExecs();
|
|
369
|
-
const rootPackageJson = await safeReadJson(
|
|
714
|
+
const rootPackageJson = await safeReadJson(path9.join(workspace.workspaceRoot, "package.json"));
|
|
370
715
|
const filteredApps = options.app ? appNames.filter((name) => name === options.app) : appNames;
|
|
371
716
|
const [apps, libs, pkgs] = await Promise.all([
|
|
372
717
|
Promise.all(filteredApps.map((name) => getSysContext(workspace, "app", name, options))),
|
|
373
718
|
Promise.all(libNames.map((name) => getSysContext(workspace, "lib", name, options))),
|
|
374
719
|
Promise.all(pkgNames.map(async (name) => {
|
|
375
|
-
const packageJson = await safeReadJson(
|
|
720
|
+
const packageJson = await safeReadJson(path9.join(workspace.workspaceRoot, "pkgs", name, "package.json"));
|
|
376
721
|
return {
|
|
377
722
|
name,
|
|
378
723
|
path: `pkgs/${name}`,
|
|
@@ -392,83 +737,6 @@ class AkanContextAnalyzer {
|
|
|
392
737
|
validationCommands
|
|
393
738
|
};
|
|
394
739
|
}
|
|
395
|
-
static async#agentGuideDrift(workspace) {
|
|
396
|
-
const installed = await readDevkitVersion();
|
|
397
|
-
if (!installed)
|
|
398
|
-
return null;
|
|
399
|
-
const content = await safeReadText(path.join(workspace.workspaceRoot, "AGENTS.md"));
|
|
400
|
-
if (content === null)
|
|
401
|
-
return null;
|
|
402
|
-
const stamped = extractBlockVersion(content);
|
|
403
|
-
if (stamped === installed)
|
|
404
|
-
return null;
|
|
405
|
-
const hint = "Re-render the AGENTS.md managed block from the installed framework release.";
|
|
406
|
-
if (!stamped)
|
|
407
|
-
return {
|
|
408
|
-
code: "agent-guide-unstamped",
|
|
409
|
-
message: `AGENTS.md carries no generated-version stamp, so its conventions may predate @akanjs/devkit ${installed}`,
|
|
410
|
-
hint
|
|
411
|
-
};
|
|
412
|
-
return {
|
|
413
|
-
code: "agent-guide-stale",
|
|
414
|
-
message: `AGENTS.md was generated by @akanjs/devkit ${stamped}, but ${installed} is installed`,
|
|
415
|
-
hint
|
|
416
|
-
};
|
|
417
|
-
}
|
|
418
|
-
static async#agentGuideOversize(workspace, sysPaths) {
|
|
419
|
-
const sizeOf = async (file) => {
|
|
420
|
-
const content = await safeReadText(path.join(workspace.workspaceRoot, file));
|
|
421
|
-
return { file, bytes: content === null ? 0 : Buffer.byteLength(content) };
|
|
422
|
-
};
|
|
423
|
-
const root = await sizeOf("AGENTS.md");
|
|
424
|
-
if (root.bytes === 0)
|
|
425
|
-
return null;
|
|
426
|
-
const scoped = await Promise.all(sysPaths.map((sysPath) => sizeOf(`${sysPath}/AGENTS.md`)));
|
|
427
|
-
const largest = scoped.reduce((max, entry) => entry.bytes > max.bytes ? entry : max, { file: "", bytes: 0 });
|
|
428
|
-
const total = root.bytes + largest.bytes;
|
|
429
|
-
if (total <= 32 * 1024 * 0.8)
|
|
430
|
-
return null;
|
|
431
|
-
const subject = largest.bytes ? `AGENTS.md and ${largest.file} add up to` : "AGENTS.md is";
|
|
432
|
-
return `${subject} ${Math.ceil(total / 1024)} KiB of the 32 KiB Codex reads \u2014 run \`akan agent install\`, then shorten the text outside the akan:agent markers or move it into a skill.`;
|
|
433
|
-
}
|
|
434
|
-
static async#agentGuideLeftovers(workspace) {
|
|
435
|
-
const root = workspace.workspaceRoot;
|
|
436
|
-
const guide = await safeReadText(path.join(root, "AGENTS.md")) ?? "";
|
|
437
|
-
const leftovers = [];
|
|
438
|
-
for (const doc of ["docs/AI-DEVELOPMENT.md", "docs/GENERATED.md"]) {
|
|
439
|
-
const pointer = guide.includes(doc);
|
|
440
|
-
if (await safeReadText(path.join(root, doc)) !== null)
|
|
441
|
-
leftovers.push({
|
|
442
|
-
path: doc,
|
|
443
|
-
message: `${doc} is an older template's copy of the agent guide, and nothing reads it now \u2014 delete it${pointer ? " and the AGENTS.md sentence that points to it" : ""}.`
|
|
444
|
-
});
|
|
445
|
-
else if (pointer)
|
|
446
|
-
leftovers.push({
|
|
447
|
-
path: "AGENTS.md",
|
|
448
|
-
message: `AGENTS.md points to ${doc}, which is gone \u2014 delete that sentence.`
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
return leftovers;
|
|
452
|
-
}
|
|
453
|
-
static async#configLeftovers(workspace, sysPaths) {
|
|
454
|
-
const leftovers = [];
|
|
455
|
-
for (const sysPath of sysPaths) {
|
|
456
|
-
const tsconfigPath = `${sysPath}/tsconfig.json`;
|
|
457
|
-
const tsconfig = await safeReadText(path.join(workspace.workspaceRoot, tsconfigPath));
|
|
458
|
-
if (tsconfig && (/"name"\s*:\s*"next"/.test(tsconfig) || tsconfig.includes(".next/types")))
|
|
459
|
-
leftovers.push({
|
|
460
|
-
path: tsconfigPath,
|
|
461
|
-
message: `${tsconfigPath} still names the Next.js TS plugin or .next/types, which Akan never uses \u2014 delete the "next" plugin entry and the ".next/types/**/*.ts" include.`
|
|
462
|
-
});
|
|
463
|
-
}
|
|
464
|
-
const bunfig = await safeReadText(path.join(workspace.workspaceRoot, "bunfig.toml"));
|
|
465
|
-
if (bunfig?.includes("bun-plugin-tailwind"))
|
|
466
|
-
leftovers.push({
|
|
467
|
-
path: "bunfig.toml",
|
|
468
|
-
message: "bunfig.toml still loads bun-plugin-tailwind, which is not installed and which Akan never uses (it compiles Tailwind itself) \u2014 delete the [serve.static] section, which Akan never reads."
|
|
469
|
-
});
|
|
470
|
-
return leftovers;
|
|
471
|
-
}
|
|
472
740
|
static async doctor(workspace, {
|
|
473
741
|
strict = false,
|
|
474
742
|
runIdOrPlan = null,
|
|
@@ -476,198 +744,15 @@ class AkanContextAnalyzer {
|
|
|
476
744
|
} = {}) {
|
|
477
745
|
const context = await AkanContextAnalyzer.analyze(workspace);
|
|
478
746
|
const workflowPaths = await loadWorkflowContextPaths(workspace, runIdOrPlan, changedFiles);
|
|
479
|
-
const
|
|
480
|
-
const
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
};
|
|
488
|
-
for (const sys of [...context.apps, ...context.libs]) {
|
|
489
|
-
const sysPath = path.join(workspace.workspaceRoot, sys.path);
|
|
490
|
-
for (const entry of await safeReadDir(sysPath)) {
|
|
491
|
-
if (!isScannedRootEntry(sys.type, entry.name))
|
|
492
|
-
continue;
|
|
493
|
-
const allowed = entry.isDirectory() ? rootAllowedDirs[sys.type].has(entry.name) : rootAllowedFiles[sys.type].has(entry.name);
|
|
494
|
-
const rootEntryHint = rootEntryHintOf(sys.type, entry.name);
|
|
495
|
-
if (!allowed)
|
|
496
|
-
report({
|
|
497
|
-
severity: "error",
|
|
498
|
-
code: `${sys.type}-root-unknown-entry`,
|
|
499
|
-
path: `${sys.path}/${entry.name}`,
|
|
500
|
-
message: `Unexpected ${entry.isDirectory() ? "folder" : "file"} in ${sys.type} root: ${sys.path}/${entry.name}${rootEntryHint ? ` (${rootEntryHint})` : ""}`
|
|
501
|
-
}, repairAction("module-shape", `akan repair module-shape --app ${sys.name}`, `Review ${sys.type} root shape and remove or move the unknown entry.`, false));
|
|
502
|
-
}
|
|
503
|
-
for (const facet of barrelFacetDirs)
|
|
504
|
-
for (const entry of await safeReadDir(path.join(sysPath, facet))) {
|
|
505
|
-
const shadow = entry.isDirectory() ? null : facetIndexShadowOf(`${facet}/${entry.name}`);
|
|
506
|
-
if (!shadow)
|
|
507
|
-
continue;
|
|
508
|
-
const entryPath = `${sys.path}/${facet}/${entry.name}`;
|
|
509
|
-
report({ severity: "error", code: "facet-index-shadowed", path: entryPath, message: `${entryPath} ${shadow}` }, repairAction("generated", `akan sync ${sys.name}`, `Delete ${entryPath} by hand, then sync.`, false));
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
const agentDrift = await AkanContextAnalyzer.#agentGuideDrift(workspace);
|
|
513
|
-
if (agentDrift)
|
|
514
|
-
report({ severity: "warning", code: agentDrift.code, path: "AGENTS.md", message: agentDrift.message }, repairAction("generated", "akan agent install agents-md", agentDrift.hint, true));
|
|
515
|
-
const sysPaths = [...context.apps, ...context.libs].map((sys) => sys.path);
|
|
516
|
-
const oversize = await AkanContextAnalyzer.#agentGuideOversize(workspace, sysPaths);
|
|
517
|
-
if (oversize)
|
|
518
|
-
diagnostics.push({ severity: "warning", code: "agent-guide-oversized", path: "AGENTS.md", message: oversize });
|
|
519
|
-
for (const leftover of await AkanContextAnalyzer.#agentGuideLeftovers(workspace))
|
|
520
|
-
diagnostics.push({ severity: "warning", code: "agent-guide-leftover", ...leftover });
|
|
521
|
-
for (const leftover of await AkanContextAnalyzer.#configLeftovers(workspace, sysPaths))
|
|
522
|
-
diagnostics.push({ severity: "warning", code: "config-leftover", ...leftover });
|
|
523
|
-
for (const sys of [...context.apps, ...context.libs]) {
|
|
524
|
-
for (const module of sys.modules) {
|
|
525
|
-
const moduleShapeCommand = `akan repair module-shape --app ${sys.name} --module ${module.name}`;
|
|
526
|
-
if (!module.abstract.exists)
|
|
527
|
-
report({
|
|
528
|
-
severity: strict ? "error" : "warning",
|
|
529
|
-
code: "module-abstract-missing",
|
|
530
|
-
path: module.abstract.path,
|
|
531
|
-
message: `${capitalize(module.kind)} module ${sys.name}:${module.name} should include ${module.abstract.path}`
|
|
532
|
-
}, repairAction("module-shape", moduleShapeCommand, "Create the missing module abstract or inspect required source files.", false));
|
|
533
|
-
const missingFiles = moduleShapeFiles(module).filter((filename) => !module.files.includes(filename));
|
|
534
|
-
if (missingFiles.length)
|
|
535
|
-
report({
|
|
536
|
-
severity: "error",
|
|
537
|
-
code: "module-shape-invalid",
|
|
538
|
-
path: module.path,
|
|
539
|
-
message: `${capitalize(module.kind)} module ${sys.name}:${module.name} is missing required files: ${missingFiles.join(", ")}`
|
|
540
|
-
}, repairAction("module-shape", moduleShapeCommand, "Review missing required module source files.", false));
|
|
541
|
-
if (module.kind !== "service" && module.files.includes(`${module.name}.dictionary.ts`)) {
|
|
542
|
-
const constantPath = path.join(workspace.workspaceRoot, module.path, `${module.name}.constant.ts`);
|
|
543
|
-
const dictionaryPath = path.join(workspace.workspaceRoot, module.path, `${module.name}.dictionary.ts`);
|
|
544
|
-
const [constantContent, dictionaryContent] = await Promise.all([
|
|
545
|
-
safeReadText(constantPath),
|
|
546
|
-
safeReadText(dictionaryPath)
|
|
547
|
-
]);
|
|
548
|
-
if (constantContent && dictionaryContent) {
|
|
549
|
-
for (const fieldName of constantFieldNames(constantContent)) {
|
|
550
|
-
if (new RegExp(`\\b${fieldName}\\s*:`).test(dictionaryContent))
|
|
551
|
-
continue;
|
|
552
|
-
report({
|
|
553
|
-
severity: "warning",
|
|
554
|
-
code: "dictionary-label-missing",
|
|
555
|
-
path: `${module.path}/${module.name}.dictionary.ts`,
|
|
556
|
-
message: `Dictionary labels for ${sys.name}:${module.name}.${fieldName} were not found.`
|
|
557
|
-
}, repairAction("dictionary", `akan repair dictionary --app ${sys.name} --module ${module.name}`, "Add missing dictionary labels for source constant fields.", false));
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
for (const sys of [...context.apps, ...context.libs]) {
|
|
564
|
-
const sources = await collectRecipeSources2(path.join(workspace.workspaceRoot, sys.path, "ui"), "ui");
|
|
565
|
-
if (sources.length === 0)
|
|
566
|
-
continue;
|
|
567
|
-
const recipes = scanRecipes2(sources);
|
|
568
|
-
const files = [];
|
|
569
|
-
const glob = new Bun.Glob("**/*.tsx");
|
|
570
|
-
for await (const abs of glob.scan({ cwd: path.join(workspace.workspaceRoot, sys.path), absolute: true })) {
|
|
571
|
-
if (/[\\/](node_modules|\.akan|dist)[\\/]|[\\/]v1[\\/]/.test(abs) || /\.(test|spec)\.tsx$/.test(abs))
|
|
572
|
-
continue;
|
|
573
|
-
files.push({
|
|
574
|
-
path: abs,
|
|
575
|
-
content: await Bun.file(abs).text().catch(() => "")
|
|
576
|
-
});
|
|
577
|
-
}
|
|
578
|
-
const duplicates = findInlineRecipeDuplicates2(recipes, files);
|
|
579
|
-
if (duplicates.length === 0)
|
|
580
|
-
continue;
|
|
581
|
-
const preview = duplicates.slice(0, 3).map((duplicate) => `${path.relative(workspace.workspaceRoot, duplicate.path)}:${duplicate.line}`).join(", ");
|
|
582
|
-
diagnostics.push({
|
|
583
|
-
severity: "warning",
|
|
584
|
-
code: "recipe-inline-duplicate",
|
|
585
|
-
path: path.join(sys.path, "ui/Recipe"),
|
|
586
|
-
message: `${sys.name}: ${duplicates.length} inline className(s) re-author a recipe fingerprint (${preview}${duplicates.length > 3 ? ", \u2026" : ""}) \u2014 consume the recipe instead.`
|
|
587
|
-
});
|
|
588
|
-
}
|
|
589
|
-
const scanNames = async (uiDirPath, basename) => new Set(scanRecipes2(await collectRecipeSources2(uiDirPath, "ui", basename)).map((info) => info.name));
|
|
590
|
-
const declaredByImport = new Map;
|
|
591
|
-
declaredByImport.set("akanjs/ui", await scanNames(path.join(workspace.workspaceRoot, "pkgs/akanjs/ui"), "recipe"));
|
|
592
|
-
for (const sys of [...context.apps, ...context.libs])
|
|
593
|
-
declaredByImport.set(`@${sys.path}/ui`, await scanNames(path.join(workspace.workspaceRoot, sys.path, "ui")));
|
|
594
|
-
const sectionOf = (content, heading) => {
|
|
595
|
-
const match = new RegExp(`^${heading}$`, "m").exec(content);
|
|
596
|
-
if (!match)
|
|
597
|
-
return "";
|
|
598
|
-
const section = content.slice(match.index);
|
|
599
|
-
const sectionEnd = section.indexOf(`
|
|
600
|
-
## `, 1);
|
|
601
|
-
return sectionEnd === -1 ? section : section.slice(0, sectionEnd);
|
|
602
|
-
};
|
|
603
|
-
const listedByImport = (body) => {
|
|
604
|
-
const groups = new Map;
|
|
605
|
-
let current = null;
|
|
606
|
-
for (const line of body.split(`
|
|
607
|
-
`)) {
|
|
608
|
-
const group = /^Import from `([^`]+)`:/.exec(line);
|
|
609
|
-
if (group) {
|
|
610
|
-
current = groups.get(group[1]) ?? new Set;
|
|
611
|
-
groups.set(group[1], current);
|
|
612
|
-
continue;
|
|
613
|
-
}
|
|
614
|
-
const item = /^- `([A-Za-z0-9_$]+)`/.exec(line);
|
|
615
|
-
if (item && current)
|
|
616
|
-
current.add(item[1]);
|
|
617
|
-
else if (!item)
|
|
618
|
-
current = null;
|
|
619
|
-
}
|
|
620
|
-
return groups;
|
|
621
|
-
};
|
|
622
|
-
const pushIndexDiagnostic = (indexPath, missing, stale, repairCommand) => {
|
|
623
|
-
if (missing.length === 0 && stale.length === 0)
|
|
624
|
-
return;
|
|
625
|
-
const parts = [
|
|
626
|
-
missing.length > 0 ? `${missing.length} declared but unlisted (${missing.slice(0, 5).join(", ")})` : "",
|
|
627
|
-
stale.length > 0 ? `${stale.length} listed but gone (${stale.slice(0, 5).join(", ")})` : ""
|
|
628
|
-
].filter(Boolean);
|
|
629
|
-
report({
|
|
630
|
-
severity: "error",
|
|
631
|
-
code: "recipe-index-stale",
|
|
632
|
-
path: indexPath,
|
|
633
|
-
message: `${indexPath} recipe index is out of date \u2014 ${parts.join("; ")}. Agents read this list as authoritative.`
|
|
634
|
-
}, repairAction("generated", repairCommand, "Regenerate the recipe index from the scanned recipes.", true));
|
|
635
|
-
};
|
|
636
|
-
const frameworkDeclared = declaredByImport.get("akanjs/ui") ?? new Set;
|
|
637
|
-
if (frameworkDeclared.size > 0) {
|
|
638
|
-
const agentsMd = await Bun.file(path.join(workspace.workspaceRoot, "AGENTS.md")).text().catch(() => "");
|
|
639
|
-
const listed = listedByImport(sectionOf(agentsMd, "## Recipes")).get("akanjs/ui") ?? new Set;
|
|
640
|
-
pushIndexDiagnostic("AGENTS.md", [...frameworkDeclared].filter((name) => !listed.has(name)).sort((a, b) => a < b ? -1 : a > b ? 1 : 0), [...listed].filter((name) => !frameworkDeclared.has(name)).sort((a, b) => a < b ? -1 : a > b ? 1 : 0), "akan agent install agents-md");
|
|
641
|
-
}
|
|
642
|
-
for (const sys of [...context.apps, ...context.libs]) {
|
|
643
|
-
const own = declaredByImport.get(`@${sys.path}/ui`) ?? new Set;
|
|
644
|
-
const scopeMd = await Bun.file(path.join(workspace.workspaceRoot, sys.path, "AGENTS.md")).text().catch(() => "");
|
|
645
|
-
const groups = listedByImport(sectionOf(scopeMd, "## Recipes In Scope"));
|
|
646
|
-
const ownListed = groups.get(`@${sys.path}/ui`) ?? new Set;
|
|
647
|
-
const missing = [...own].filter((name) => !ownListed.has(name)).sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
648
|
-
const stale = [...groups.entries()].flatMap(([importFrom, names]) => [...names].filter((name) => !(declaredByImport.get(importFrom) ?? new Set).has(name))).sort();
|
|
649
|
-
pushIndexDiagnostic(`${sys.path}/AGENTS.md`, missing, stale, `akan sync ${sys.name}`);
|
|
650
|
-
}
|
|
651
|
-
const scopedDiagnostics = diagnostics.map((diagnostic) => ({
|
|
652
|
-
...diagnostic,
|
|
653
|
-
scope: workflowPaths.length ? isWorkflowRelatedDiagnostic(diagnostic, workflowPaths) ? "workflow" : "baseline" : diagnostic.scope,
|
|
654
|
-
context: workflowPaths.length ? { ...diagnostic.context, paths: workflowPaths } : diagnostic.context
|
|
655
|
-
}));
|
|
656
|
-
const workflowDiagnostics = scopedDiagnostics.filter((diagnostic) => diagnostic.scope === "workflow");
|
|
657
|
-
const baselineDiagnostics = scopedDiagnostics.filter((diagnostic) => diagnostic.scope === "baseline");
|
|
658
|
-
return {
|
|
659
|
-
schemaVersion: 1,
|
|
660
|
-
repoName: context.repoName,
|
|
661
|
-
root: context.root,
|
|
662
|
-
strict,
|
|
663
|
-
status: scopedDiagnostics.some((diagnostic) => diagnostic.severity === "error") ? "failed" : "passed",
|
|
664
|
-
diagnostics: scopedDiagnostics,
|
|
665
|
-
generatedFiles: context.generatedFiles,
|
|
666
|
-
generatedFilesFreshness: await generatedFreshnessFromStates(workspace),
|
|
667
|
-
validationCommands: context.validationCommands,
|
|
668
|
-
repairActions,
|
|
669
|
-
...workflowPaths.length ? { baselineDiagnostics, workflowDiagnostics } : {}
|
|
670
|
-
};
|
|
747
|
+
const systems = [...context.apps, ...context.libs];
|
|
748
|
+
const findings = new DoctorFindings;
|
|
749
|
+
await RootShapeCheck.run(workspace, systems, findings);
|
|
750
|
+
await AgentGuideCheck.run(workspace, systems, findings);
|
|
751
|
+
await ConfigLeftoverCheck.run(workspace, systems, findings);
|
|
752
|
+
await ModuleShapeCheck.run(workspace, systems, findings, { strict });
|
|
753
|
+
await RecipeDuplicateCheck.run(workspace, systems, findings);
|
|
754
|
+
await RecipeIndexCheck.run(workspace, systems, findings);
|
|
755
|
+
return await findings.result(workspace, context, { strict, workflowPaths });
|
|
671
756
|
}
|
|
672
757
|
static findModules(context, moduleName, { app = null } = {}) {
|
|
673
758
|
const modules = [...context.apps, ...context.libs].filter((sys) => !app || sys.name === app).flatMap((sys) => sys.modules);
|