@akanjs/cli 3.2.0-rc.8 → 3.2.0
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 -2
- package/CodeAgent-fx6088tv.js +11 -0
- package/{CodeTui-qstk5vpj.js → CodeTui-zee8atsr.js} +822 -666
- package/README.ko.md +7 -0
- package/README.md +7 -0
- package/TunnelShare-9ry4vh0y.js +18 -0
- package/agent.command-x65f2ags.js +61 -0
- package/akanCode.js +12 -12
- package/appExecutor-79azsb2w.js +11 -0
- package/{application.command-m4rq4wc2.js → application.command-azbd1pb2.js} +83 -37
- package/{applicationBuildRunner-df7rx3ra.js → applicationBuildRunner-trfxv3pd.js} +49 -18
- package/buildBatch.proc.js +25 -11
- package/{cloud.command-a0gy0qq2.js → cloud.command-gapp4634.js} +33 -29
- package/cloud.script-3b401efv.js +35 -0
- package/{code.command-5rsdqw8s.js → code.command-5smx61yf.js} +13 -9
- package/context.command-ym5jbkny.js +64 -0
- package/context.runner-kctbfsde.js +34 -0
- package/{dependencyScanner-78sq8m4q.js → dependencyScanner-ge10gb52.js} +2 -2
- package/{devTui-h77zrjv5.js → devTui-rf374y2w.js} +1 -1
- package/{fileSys-zpvt5gtf.js → fileSys-q22646yc.js} +1 -1
- package/{guideline.command-mffxknbr.js → guideline.command-zwypaqsh.js} +9 -5
- package/guidelines/agentRule/agentRule.instruction.md +25 -9
- package/guidelines/akanApi/akanApi.instruction.md +6 -4
- package/guidelines/conventions/core.md +23 -5
- package/guidelines/conventions/rules/app.md +4 -1
- package/guidelines/conventions/rules/page.md +5 -4
- package/guidelines/conventions/rules/ts.md +3 -3
- package/guidelines/errorCodes/errorCodes.instruction.md +165 -0
- package/guidelines/fieldRule/fieldRule.instruction.md +2 -1
- package/guidelines/mcpRule/mcpRule.instruction.md +225 -5
- package/guidelines/pageRule/pageRule.instruction.md +10 -1
- package/guidelines/queryRule/queryRule.instruction.md +3 -1
- package/guidelines/runtimeRule/runtimeRule.instruction.md +14 -8
- package/guidelines/transportRule/transportRule.instruction.md +31 -1
- package/incrementalBuilder.proc.js +577 -411
- package/{index-w15mg3km.js → index-0dm25wvf.js} +1 -1
- package/{index-0gg15zwa.js → index-0s7w2085.js} +6 -6
- package/{index-hj6w4ka1.js → index-1p81ecbz.js} +1 -1
- package/{index-swwjakt0.js → index-275a4r3n.js} +11 -11
- package/{index-j6gc8n14.js → index-2jmvfa62.js} +11 -9
- package/{index-qd7xn2bk.js → index-2ny1e95c.js} +2 -2
- package/{index-exn38bzx.js → index-2yn3r67f.js} +116 -54
- package/{index-34792nh7.js → index-3txdtztz.js} +1 -1
- package/{index-28x1aszt.js → index-41a03gkj.js} +149 -53
- package/{index-2mf1aen9.js → index-4ss4gkv3.js} +2 -2
- package/{index-an76bdrv.js → index-612fdtbk.js} +1 -1
- package/{index-5radqwn2.js → index-67sd09ag.js} +12 -12
- package/{index-0hbtve0a.js → index-6dzjer7p.js} +32 -28
- package/{index-3ghdb7p5.js → index-71y6176j.js} +2777 -3676
- package/{index-xyn02k0w.js → index-78y75t0a.js} +662 -433
- package/index-7wf8snar.js +80 -0
- package/{index-skmtj8rm.js → index-8jtqfye2.js} +27 -10
- package/{index-2mrn1mrg.js → index-9f3reh2y.js} +1 -1
- package/{index-nmvhjn8c.js → index-9wh04mqy.js} +93 -82
- package/{index-xvk2a75m.js → index-a860mx0m.js} +3 -3
- package/{index-5zwr4n6k.js → index-baccvws5.js} +65 -8
- package/{index-yf9wc28h.js → index-bejy9zyc.js} +1 -1
- package/{index-bns3wcpc.js → index-by2tvsq6.js} +1 -1
- package/{index-r0a604h4.js → index-c669pbyb.js} +5 -4
- package/{index-x40bdsca.js → index-dadwp2aw.js} +33 -98
- package/{index-vm0dn0mt.js → index-dmcpetwe.js} +200 -138
- package/{index-43f4h4cm.js → index-ebn9kgea.js} +6 -6
- package/{index-hqv34wzq.js → index-gt8phqpt.js} +10 -10
- package/{index-yckz5t8b.js → index-h901f24n.js} +516 -434
- package/{index-j3v29pq7.js → index-j0wr4e32.js} +219 -175
- package/{index-gcx48get.js → index-j592zfqc.js} +2 -2
- package/{index-grxs6fts.js → index-j6jjmn2r.js} +57 -31
- package/{index-w8yasvpc.js → index-jek2re5k.js} +2136 -2175
- package/{index-ny2k80mv.js → index-jf4vk1s0.js} +9 -2
- package/{index-gxav1bjz.js → index-k6vwww45.js} +9 -9
- package/{index-99qvtff2.js → index-kfvjzk8r.js} +5 -5
- package/{index-j6eeh5d7.js → index-knpm8sdm.js} +5 -5
- package/{index-2r9ff9qm.js → index-nc3br31y.js} +2 -2
- package/{index-35j83zkd.js → index-p5zh7pmc.js} +2 -2
- package/{index-cmg5ngqa.js → index-p7beqww9.js} +2 -2
- package/{index-b4qq3rq0.js → index-rwgqba9p.js} +1 -1
- package/{index-rfzp4pqs.js → index-s885g0jj.js} +3 -3
- package/{index-9p260r4e.js → index-trffs83s.js} +538 -250
- package/{index-k92x3vne.js → index-v7ajmsh3.js} +1 -1
- package/index-w1zexzpx.js +127 -0
- package/{index-h7hehkw6.js → index-xczjdng6.js} +3 -1
- package/{index-39jz41jb.js → index-xs9a3ddt.js} +3 -3
- package/{index-rp4yf32g.js → index-xwwex8rf.js} +36 -29
- package/{index-ra9fvn7s.js → index-ybcb9wc8.js} +74 -38
- package/index-z92zm3wd.js +788 -0
- package/{index-j9790rhk.js → index-z96ks033.js} +1509 -1121
- package/index-zfnz878d.js +30 -0
- package/{index-2vgv7fs7.js → index-zmd9xxgd.js} +727 -693
- package/{index-ygdbn9jn.js → index-zyb0ebm4.js} +1 -1
- package/index.js +28 -24
- package/libExecutor-jc6f8hm6.js +10 -0
- package/{library.command-bmd7zc5m.js → library.command-nxvesvhb.js} +12 -5
- package/{localRegistry.command-y6en1599.js → localRegistry.command-xz62e4ng.js} +29 -24
- package/{module.command-7exfffqw.js → module.command-aaws9byg.js} +11 -7
- package/{package.command-adskw2rj.js → package.command-j7hv26p0.js} +14 -10
- package/package.json +8 -8
- package/{page.command-dw01272p.js → page.command-7yffs7n9.js} +8 -4
- package/{pipeline.command-0b1r3y5r.js → pipeline.command-7yk0zcng.js} +15 -9
- package/pkgExecutor-arxmvx4t.js +10 -0
- package/{primitive.command-byw6vc04.js → primitive.command-7a1pt715.js} +12 -8
- package/{projectTypecheck-kkrpq60a.js → projectTypecheck-f4qhbecd.js} +1 -1
- package/{prompter-qrwx1p17.js → prompter-qyggfhqd.js} +2 -2
- package/{quality.command-6rqnhzct.js → quality.command-c6mvrjh1.js} +25 -16
- package/{recipeScanner-4b69ybe0.js → recipeScanner-rrx69awy.js} +1 -1
- package/{repair.command-rw5zymak.js → repair.command-093adzt9.js} +12 -8
- package/{routeSourceValidator-4h947v7c.js → routeSourceValidator-8n6j1vn7.js} +4 -2
- package/{scalar.command-2dyp9nh9.js → scalar.command-2ex84spb.js} +10 -6
- package/skills/akan-debug/SKILL.md +8 -5
- package/skills/akan-err/SKILL.md +7 -0
- package/skills/akan-mcp/SKILL.md +19 -1
- package/skills/akan-scaffold/SKILL.md +1 -1
- package/skills/akan-validate/SKILL.md +3 -3
- package/{subspace.command-111ynwv1.js → subspace.command-4n4n4jpv.js} +32 -24
- 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/.devcontainer/devcontainer.json.template +1 -1
- package/templates/workspaceRoot/AGENTS.md.template +2 -1
- package/templates/workspaceRoot/README.ts +4 -2
- package/{tunnel.command-2gcpfbdj.js → tunnel.command-f7ep1qfa.js} +17 -13
- package/{typeChecker-s640r6c0.js → typeChecker-7jt6abrs.js} +1 -1
- package/typecheck.proc.js +3 -2
- package/{verify.command-djgs86ma.js → verify.command-zrkxnvct.js} +21 -17
- package/{workflow.command-n0k2mxr5.js → workflow.command-ks16jegk.js} +21 -14
- package/{workspace.command-fh1qwxfx.js → workspace.command-ahhfpaag.js} +60 -54
- package/CodeAgent-x2p3a3e0.js +0 -11
- package/TunnelShare-c4xsfzg5.js +0 -15
- package/agent.command-9et2e27p.js +0 -52
- package/cloud.script-xze4zh7n.js +0 -31
- package/context.command-rk1dwrg4.js +0 -57
- package/context.runner-83ky5m1b.js +0 -30
- /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,36 +1,280 @@
|
|
|
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-71y6176j.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-z92zm3wd.js";
|
|
18
|
+
import {
|
|
19
|
+
LibExecutor2
|
|
20
|
+
} from "./index-zfnz878d.js";
|
|
22
21
|
import {
|
|
23
22
|
workflowPathsForPlan,
|
|
24
23
|
workflowRunArtifactPath,
|
|
25
24
|
workflowSyncDir
|
|
26
|
-
} from "./index-
|
|
25
|
+
} from "./index-zmd9xxgd.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
280
|
var propertyNames = (content, declares) => {
|
|
@@ -49,7 +293,199 @@ var unlabeledFieldNames = (constantContent, dictionaryContent) => {
|
|
|
49
293
|
return constantFieldNames(constantContent).filter((name) => !labels.has(name));
|
|
50
294
|
};
|
|
51
295
|
|
|
52
|
-
// pkgs/@akanjs/devkit/
|
|
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
|
+
}
|
|
354
|
+
|
|
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).replaceAll(path6.sep, "/")}:${duplicate.line}`).join(", ");
|
|
378
|
+
findings.push({
|
|
379
|
+
severity: "warning",
|
|
380
|
+
code: "recipe-inline-duplicate",
|
|
381
|
+
path: path6.posix.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
|
|
53
489
|
var guidelineResourceUri = (name) => `akan://guidelines/${name}`;
|
|
54
490
|
var staticResourceList = [
|
|
55
491
|
{ uri: "akan://docs/framework", name: "Akan framework guide", mimeType: "text/markdown" },
|
|
@@ -118,144 +554,48 @@ ${nextBlock}`;
|
|
|
118
554
|
};
|
|
119
555
|
var renderDoctorText = (result) => {
|
|
120
556
|
const lines = [`Akan doctor status: ${result.status}`];
|
|
121
|
-
if (result.diagnostics.length === 0) {
|
|
122
|
-
lines.push("", "No Akan workspace diagnostics found.");
|
|
123
|
-
} else {
|
|
124
|
-
lines.push("", ...result.diagnostics.map((diagnostic) => [
|
|
125
|
-
`[${diagnostic.severity}] ${diagnostic.code}: ${diagnostic.message}`,
|
|
126
|
-
diagnostic.path ? ` ${diagnostic.path}` : ""
|
|
127
|
-
].filter(Boolean).join(`
|
|
128
|
-
`)));
|
|
129
|
-
}
|
|
130
|
-
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}`));
|
|
131
|
-
return `${lines.join(`
|
|
132
|
-
`)}
|
|
133
|
-
`;
|
|
134
|
-
};
|
|
135
|
-
var generatedFiles = [
|
|
136
|
-
"apps/*/client.ts",
|
|
137
|
-
"apps/*/server.ts",
|
|
138
|
-
"*/lib/cnst.ts",
|
|
139
|
-
"*/lib/db.ts",
|
|
140
|
-
"*/lib/dict.ts",
|
|
141
|
-
"*/lib/sig.ts",
|
|
142
|
-
"*/lib/srv.ts",
|
|
143
|
-
"*/lib/st.ts",
|
|
144
|
-
"*/lib/useClient.ts",
|
|
145
|
-
"*/lib/useServer.ts",
|
|
146
|
-
"*/lib/**/index.ts",
|
|
147
|
-
"*/ui/index.ts",
|
|
148
|
-
"*/webkit/index.ts",
|
|
149
|
-
"*/srvkit/index.ts",
|
|
150
|
-
"*/common/index.ts"
|
|
151
|
-
];
|
|
152
|
-
var validationCommands = [
|
|
153
|
-
"akan verify [<app-or-lib-or-pkg>]",
|
|
154
|
-
"akan sync <app-or-lib>",
|
|
155
|
-
"akan lint <app-or-lib-or-pkg>",
|
|
156
|
-
"akan typecheck <app-or-lib>",
|
|
157
|
-
"akan test <app-or-lib-or-pkg>",
|
|
158
|
-
"akan build <app-name>",
|
|
159
|
-
"akan doctor --strict --format json",
|
|
160
|
-
"akan quality scan [--format json]",
|
|
161
|
-
"akan quality ssr [--format json]"
|
|
162
|
-
];
|
|
163
|
-
var unknownGeneratedFilesFreshness = {
|
|
164
|
-
status: "unknown",
|
|
165
|
-
message: "Run sync before validation so generated Akan files match the current source conventions.",
|
|
166
|
-
refreshCommand: "akan sync <app-or-lib>",
|
|
167
|
-
verifyingCommands: ["akan verify <app-or-lib>"]
|
|
168
|
-
};
|
|
169
|
-
var repairAction = (kind, command, reason, safeToRun) => ({
|
|
170
|
-
kind,
|
|
171
|
-
command,
|
|
172
|
-
reason,
|
|
173
|
-
safeToRun
|
|
174
|
-
});
|
|
175
|
-
var moduleShapeFiles = (module) => {
|
|
176
|
-
if (module.kind === "service") {
|
|
177
|
-
return [`${module.name}.dictionary.ts`, `${module.name}.service.ts`, `${module.name}.signal.ts`];
|
|
178
|
-
}
|
|
179
|
-
if (module.kind === "scalar")
|
|
180
|
-
return [`${module.name}.constant.ts`, `${module.name}.dictionary.ts`];
|
|
181
|
-
return [
|
|
182
|
-
`${module.name}.constant.ts`,
|
|
183
|
-
`${module.name}.dictionary.ts`,
|
|
184
|
-
`${module.name}.service.ts`,
|
|
185
|
-
`${module.name}.store.ts`,
|
|
186
|
-
`${module.name}.signal.ts`
|
|
187
|
-
];
|
|
188
|
-
};
|
|
189
|
-
var safeReadDir = async (dirPath) => (await readdir(dirPath, { withFileTypes: true }).catch(() => [])).sort((a, b) => a.name.localeCompare(b.name));
|
|
190
|
-
var safeReadText = (filePath) => FileSys2.readText(filePath).catch(() => null);
|
|
191
|
-
var safeReadJson = (filePath) => FileSys2.readJson(filePath).catch(() => null);
|
|
192
|
-
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");
|
|
193
|
-
var isPathList = (value) => Array.isArray(value) && value.every((file) => isRecord(file) && typeof file.path === "string");
|
|
194
|
-
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);
|
|
195
|
-
var isWorkflowRunArtifact = (value) => typeof value === "object" && value !== null && ("schemaVersion" in value) && value.schemaVersion === 1;
|
|
196
|
-
var workflowPathsForArtifact = (artifact) => {
|
|
197
|
-
if (isWorkflowPlan(artifact))
|
|
198
|
-
return workflowPathsForPlan(artifact);
|
|
199
|
-
if (isWorkflowApplyReport(artifact)) {
|
|
200
|
-
return [
|
|
201
|
-
...artifact.changedFiles.map((file) => file.path),
|
|
202
|
-
...artifact.generatedFiles.map((file) => file.path),
|
|
203
|
-
...workflowPathsForPlan(artifact.plan)
|
|
204
|
-
];
|
|
205
|
-
}
|
|
206
|
-
if ("mode" in artifact && artifact.mode === "validate" && isWorkflowPlan(artifact.plan))
|
|
207
|
-
return workflowPathsForPlan(artifact.plan);
|
|
208
|
-
return [];
|
|
209
|
-
};
|
|
210
|
-
var loadWorkflowContextPaths = async (workspace, runIdOrPlan, changedFiles) => {
|
|
211
|
-
const paths = [...changedFiles];
|
|
212
|
-
if (!runIdOrPlan)
|
|
213
|
-
return paths;
|
|
214
|
-
const inputPath = path.isAbsolute(runIdOrPlan) ? runIdOrPlan : path.join(workspace.workspaceRoot, runIdOrPlan);
|
|
215
|
-
const artifact = await safeReadJson(inputPath) ?? await safeReadJson(path.join(workspace.workspaceRoot, workflowRunArtifactPath(runIdOrPlan)));
|
|
216
|
-
if (artifact && isWorkflowRunArtifact(artifact))
|
|
217
|
-
paths.push(...workflowPathsForArtifact(artifact));
|
|
218
|
-
return [...new Set(paths.filter(Boolean))];
|
|
219
|
-
};
|
|
220
|
-
var pathKey = (value) => value.replaceAll("\\", "/").replaceAll("*", "").replace(/<[^>]+>/g, "").replace(/\/+/g, "/").replace(/^\/|\/$/g, "");
|
|
221
|
-
var isWorkflowRelatedDiagnostic = (diagnostic, workflowPaths) => {
|
|
222
|
-
if (!diagnostic.path)
|
|
223
|
-
return false;
|
|
224
|
-
const diagnosticPath = pathKey(diagnostic.path);
|
|
225
|
-
return workflowPaths.some((workflowPath) => {
|
|
226
|
-
const candidate = pathKey(workflowPath);
|
|
227
|
-
if (!candidate)
|
|
228
|
-
return false;
|
|
229
|
-
return diagnosticPath.startsWith(candidate) || candidate.startsWith(diagnosticPath) || diagnosticPath.includes(candidate);
|
|
230
|
-
});
|
|
231
|
-
};
|
|
232
|
-
var readGeneratedSyncStates = async (workspace) => {
|
|
233
|
-
const syncDir = path.join(workspace.workspaceRoot, workflowSyncDir);
|
|
234
|
-
const entries = await safeReadDir(syncDir);
|
|
235
|
-
const states = await Promise.all(entries.filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => safeReadJson(path.join(syncDir, entry.name))));
|
|
236
|
-
return states.filter((state) => !!state && state.schemaVersion === 1 && typeof state.target === "string" && typeof state.syncedAt === "string");
|
|
237
|
-
};
|
|
238
|
-
var generatedFreshnessFromStates = async (workspace) => {
|
|
239
|
-
const states = await readGeneratedSyncStates(workspace);
|
|
240
|
-
if (states.length === 0)
|
|
241
|
-
return unknownGeneratedFilesFreshness;
|
|
242
|
-
const targets = states.sort((a, b) => a.target.localeCompare(b.target)).map((state) => ({
|
|
243
|
-
target: state.target,
|
|
244
|
-
status: state.status === "passed" ? "fresh" : "stale",
|
|
245
|
-
lastSyncedAt: state.syncedAt,
|
|
246
|
-
runId: state.runId,
|
|
247
|
-
generatedFiles: state.generatedFiles.map((file) => file.path),
|
|
248
|
-
reason: state.status === "passed" ? `Generated files were refreshed by ${state.command}.` : `Last generated repair command failed: ${state.command}.`
|
|
249
|
-
}));
|
|
250
|
-
const lastFresh = targets.filter((target) => target.status === "fresh" && target.lastSyncedAt).sort((a, b) => (b.lastSyncedAt ?? "").localeCompare(a.lastSyncedAt ?? ""))[0];
|
|
251
|
-
return {
|
|
252
|
-
status: targets.some((target) => target.status === "fresh") ? "fresh" : "stale",
|
|
253
|
-
message: lastFresh ? `Generated files were refreshed for ${lastFresh.target} at ${lastFresh.lastSyncedAt}.` : "Generated sync state exists, but the last recorded repair did not pass.",
|
|
254
|
-
refreshCommand: "akan sync <app-or-lib>",
|
|
255
|
-
verifyingCommands: ["akan verify <app-or-lib>"],
|
|
256
|
-
targets
|
|
257
|
-
};
|
|
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
|
+
`;
|
|
258
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
|
+
];
|
|
259
599
|
var parseAbstractSummary = (relativePath, content, includeContent) => {
|
|
260
600
|
if (content === null)
|
|
261
601
|
return { path: relativePath, exists: false, headings: [] };
|
|
@@ -269,12 +609,12 @@ var parseAbstractSummary = (relativePath, content, includeContent) => {
|
|
|
269
609
|
};
|
|
270
610
|
};
|
|
271
611
|
var readFiles = async (dirPath) => (await safeReadDir(dirPath)).filter((entry) => entry.isFile()).map((entry) => entry.name).sort();
|
|
272
|
-
var getRelative = (workspace, absolutePath) =>
|
|
612
|
+
var getRelative = (workspace, absolutePath) => path9.relative(workspace.workspaceRoot, absolutePath).replaceAll(path9.sep, "/");
|
|
273
613
|
var createModuleContext = async (workspace, sys, kind, folderName, moduleName, includeAbstractContent) => {
|
|
274
|
-
const modulePath = kind === "scalar" ?
|
|
614
|
+
const modulePath = kind === "scalar" ? path9.join(sys.cwdPath, "lib", "__scalar", moduleName) : path9.join(sys.cwdPath, "lib", folderName);
|
|
275
615
|
const relativePath = getRelative(workspace, modulePath);
|
|
276
616
|
const abstractPath = `${relativePath}/${moduleName}.abstract.md`;
|
|
277
|
-
const abstractContent = await safeReadText(
|
|
617
|
+
const abstractContent = await safeReadText(path9.join(workspace.workspaceRoot, abstractPath));
|
|
278
618
|
return {
|
|
279
619
|
kind,
|
|
280
620
|
name: moduleName,
|
|
@@ -290,7 +630,7 @@ var getSysModules = async (workspace, sys, {
|
|
|
290
630
|
includeAbstractContent = false,
|
|
291
631
|
module: moduleFilter
|
|
292
632
|
} = {}) => {
|
|
293
|
-
const libPath =
|
|
633
|
+
const libPath = path9.join(sys.cwdPath, "lib");
|
|
294
634
|
const entries = await safeReadDir(libPath);
|
|
295
635
|
const modules = [];
|
|
296
636
|
for (const entry of entries) {
|
|
@@ -304,24 +644,24 @@ var getSysModules = async (workspace, sys, {
|
|
|
304
644
|
const serviceName = entry.name.replace(/^_+/, "");
|
|
305
645
|
if (moduleFilter && moduleFilter !== serviceName && moduleFilter !== entry.name)
|
|
306
646
|
continue;
|
|
307
|
-
if (!await FileSys2.fileExists(
|
|
647
|
+
if (!await FileSys2.fileExists(path9.join(libPath, entry.name, `${serviceName}.service.ts`)))
|
|
308
648
|
continue;
|
|
309
649
|
modules.push(await createModuleContext(workspace, sys, "service", entry.name, serviceName, includeAbstractContent));
|
|
310
650
|
} else {
|
|
311
651
|
if (moduleFilter && moduleFilter !== entry.name)
|
|
312
652
|
continue;
|
|
313
|
-
if (!await FileSys2.fileExists(
|
|
653
|
+
if (!await FileSys2.fileExists(path9.join(libPath, entry.name, `${entry.name}.constant.ts`)))
|
|
314
654
|
continue;
|
|
315
655
|
modules.push(await createModuleContext(workspace, sys, "domain", entry.name, entry.name, includeAbstractContent));
|
|
316
656
|
}
|
|
317
657
|
}
|
|
318
|
-
const scalarRoot =
|
|
658
|
+
const scalarRoot = path9.join(libPath, "__scalar");
|
|
319
659
|
for (const entry of await safeReadDir(scalarRoot)) {
|
|
320
660
|
if (!entry.isDirectory() || entry.name.startsWith("_"))
|
|
321
661
|
continue;
|
|
322
662
|
if (moduleFilter && moduleFilter !== entry.name)
|
|
323
663
|
continue;
|
|
324
|
-
if (!await FileSys2.fileExists(
|
|
664
|
+
if (!await FileSys2.fileExists(path9.join(scalarRoot, entry.name, `${entry.name}.constant.ts`)))
|
|
325
665
|
continue;
|
|
326
666
|
modules.push(await createModuleContext(workspace, sys, "scalar", entry.name, entry.name, includeAbstractContent));
|
|
327
667
|
}
|
|
@@ -344,7 +684,7 @@ var getAppRoutes = async (app, workspaceRoot) => {
|
|
|
344
684
|
const underGuard = Array.from({ length: reach + 1 }, (_, idx) => segments.slice(0, idx).join("/")).some((prefix) => guardedLayouts.has(prefix));
|
|
345
685
|
return {
|
|
346
686
|
path: parsed.pattern.replace(/^\/:lang/, "") || "/",
|
|
347
|
-
file:
|
|
687
|
+
file: path9.relative(workspaceRoot, source.absPath).replaceAll(path9.sep, "/"),
|
|
348
688
|
search: source.info.chain?.search ?? [],
|
|
349
689
|
guarded: !!source.info.chain?.guarded || underGuard,
|
|
350
690
|
devOnly: source.info.devOnly
|
|
@@ -352,18 +692,18 @@ var getAppRoutes = async (app, workspaceRoot) => {
|
|
|
352
692
|
}).sort((a, b) => a.path.localeCompare(b.path));
|
|
353
693
|
};
|
|
354
694
|
var getSysContext = async (workspace, type, name, options) => {
|
|
355
|
-
const sys = type === "app" ?
|
|
695
|
+
const sys = type === "app" ? AppExecutor2.from(workspace, name) : LibExecutor2.from(workspace, name);
|
|
356
696
|
const context = {
|
|
357
697
|
type,
|
|
358
698
|
name,
|
|
359
699
|
path: `${type}s/${name}`,
|
|
360
|
-
hasConfig: await FileSys2.fileExists(
|
|
700
|
+
hasConfig: await FileSys2.fileExists(path9.join(sys.cwdPath, "akan.config.ts")),
|
|
361
701
|
modules: await getSysModules(workspace, sys, {
|
|
362
702
|
includeAbstractContent: options.includeAbstractContent,
|
|
363
703
|
module: options.module
|
|
364
704
|
})
|
|
365
705
|
};
|
|
366
|
-
if (sys instanceof
|
|
706
|
+
if (sys instanceof AppExecutor2 && options.app === name)
|
|
367
707
|
await getAppRoutes(sys, workspace.workspaceRoot).then((routes) => context.routes = routes, (error) => context.routeError = error instanceof Error ? error.message : String(error));
|
|
368
708
|
return context;
|
|
369
709
|
};
|
|
@@ -371,13 +711,13 @@ var getSysContext = async (workspace, type, name, options) => {
|
|
|
371
711
|
class AkanContextAnalyzer {
|
|
372
712
|
static async analyze(workspace, options = {}) {
|
|
373
713
|
const [appNames, libNames, pkgNames] = await workspace.getExecs();
|
|
374
|
-
const rootPackageJson = await safeReadJson(
|
|
714
|
+
const rootPackageJson = await safeReadJson(path9.join(workspace.workspaceRoot, "package.json"));
|
|
375
715
|
const filteredApps = options.app ? appNames.filter((name) => name === options.app) : appNames;
|
|
376
716
|
const [apps, libs, pkgs] = await Promise.all([
|
|
377
717
|
Promise.all(filteredApps.map((name) => getSysContext(workspace, "app", name, options))),
|
|
378
718
|
Promise.all(libNames.map((name) => getSysContext(workspace, "lib", name, options))),
|
|
379
719
|
Promise.all(pkgNames.map(async (name) => {
|
|
380
|
-
const packageJson = await safeReadJson(
|
|
720
|
+
const packageJson = await safeReadJson(path9.join(workspace.workspaceRoot, "pkgs", name, "package.json"));
|
|
381
721
|
return {
|
|
382
722
|
name,
|
|
383
723
|
path: `pkgs/${name}`,
|
|
@@ -397,83 +737,6 @@ class AkanContextAnalyzer {
|
|
|
397
737
|
validationCommands
|
|
398
738
|
};
|
|
399
739
|
}
|
|
400
|
-
static async#agentGuideDrift(workspace) {
|
|
401
|
-
const installed = await readDevkitVersion();
|
|
402
|
-
if (!installed)
|
|
403
|
-
return null;
|
|
404
|
-
const content = await safeReadText(path.join(workspace.workspaceRoot, "AGENTS.md"));
|
|
405
|
-
if (content === null)
|
|
406
|
-
return null;
|
|
407
|
-
const stamped = extractBlockVersion(content);
|
|
408
|
-
if (stamped === installed)
|
|
409
|
-
return null;
|
|
410
|
-
const hint = "Re-render the AGENTS.md managed block from the installed framework release.";
|
|
411
|
-
if (!stamped)
|
|
412
|
-
return {
|
|
413
|
-
code: "agent-guide-unstamped",
|
|
414
|
-
message: `AGENTS.md carries no generated-version stamp, so its conventions may predate @akanjs/devkit ${installed}`,
|
|
415
|
-
hint
|
|
416
|
-
};
|
|
417
|
-
return {
|
|
418
|
-
code: "agent-guide-stale",
|
|
419
|
-
message: `AGENTS.md was generated by @akanjs/devkit ${stamped}, but ${installed} is installed`,
|
|
420
|
-
hint
|
|
421
|
-
};
|
|
422
|
-
}
|
|
423
|
-
static async#agentGuideOversize(workspace, sysPaths) {
|
|
424
|
-
const sizeOf = async (file) => {
|
|
425
|
-
const content = await safeReadText(path.join(workspace.workspaceRoot, file));
|
|
426
|
-
return { file, bytes: content === null ? 0 : Buffer.byteLength(content) };
|
|
427
|
-
};
|
|
428
|
-
const root = await sizeOf("AGENTS.md");
|
|
429
|
-
if (root.bytes === 0)
|
|
430
|
-
return null;
|
|
431
|
-
const scoped = await Promise.all(sysPaths.map((sysPath) => sizeOf(`${sysPath}/AGENTS.md`)));
|
|
432
|
-
const largest = scoped.reduce((max, entry) => entry.bytes > max.bytes ? entry : max, { file: "", bytes: 0 });
|
|
433
|
-
const total = root.bytes + largest.bytes;
|
|
434
|
-
if (total <= 32 * 1024 * 0.8)
|
|
435
|
-
return null;
|
|
436
|
-
const subject = largest.bytes ? `AGENTS.md and ${largest.file} add up to` : "AGENTS.md is";
|
|
437
|
-
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.`;
|
|
438
|
-
}
|
|
439
|
-
static async#agentGuideLeftovers(workspace) {
|
|
440
|
-
const root = workspace.workspaceRoot;
|
|
441
|
-
const guide = await safeReadText(path.join(root, "AGENTS.md")) ?? "";
|
|
442
|
-
const leftovers = [];
|
|
443
|
-
for (const doc of ["docs/AI-DEVELOPMENT.md", "docs/GENERATED.md"]) {
|
|
444
|
-
const pointer = guide.includes(doc);
|
|
445
|
-
if (await safeReadText(path.join(root, doc)) !== null)
|
|
446
|
-
leftovers.push({
|
|
447
|
-
path: doc,
|
|
448
|
-
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" : ""}.`
|
|
449
|
-
});
|
|
450
|
-
else if (pointer)
|
|
451
|
-
leftovers.push({
|
|
452
|
-
path: "AGENTS.md",
|
|
453
|
-
message: `AGENTS.md points to ${doc}, which is gone \u2014 delete that sentence.`
|
|
454
|
-
});
|
|
455
|
-
}
|
|
456
|
-
return leftovers;
|
|
457
|
-
}
|
|
458
|
-
static async#configLeftovers(workspace, sysPaths) {
|
|
459
|
-
const leftovers = [];
|
|
460
|
-
for (const sysPath of sysPaths) {
|
|
461
|
-
const tsconfigPath = `${sysPath}/tsconfig.json`;
|
|
462
|
-
const tsconfig = await safeReadText(path.join(workspace.workspaceRoot, tsconfigPath));
|
|
463
|
-
if (tsconfig && (/"name"\s*:\s*"next"/.test(tsconfig) || tsconfig.includes(".next/types")))
|
|
464
|
-
leftovers.push({
|
|
465
|
-
path: tsconfigPath,
|
|
466
|
-
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.`
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
const bunfig = await safeReadText(path.join(workspace.workspaceRoot, "bunfig.toml"));
|
|
470
|
-
if (bunfig?.includes("bun-plugin-tailwind"))
|
|
471
|
-
leftovers.push({
|
|
472
|
-
path: "bunfig.toml",
|
|
473
|
-
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."
|
|
474
|
-
});
|
|
475
|
-
return leftovers;
|
|
476
|
-
}
|
|
477
740
|
static async doctor(workspace, {
|
|
478
741
|
strict = false,
|
|
479
742
|
runIdOrPlan = null,
|
|
@@ -481,196 +744,15 @@ class AkanContextAnalyzer {
|
|
|
481
744
|
} = {}) {
|
|
482
745
|
const context = await AkanContextAnalyzer.analyze(workspace);
|
|
483
746
|
const workflowPaths = await loadWorkflowContextPaths(workspace, runIdOrPlan, changedFiles);
|
|
484
|
-
const
|
|
485
|
-
const
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
};
|
|
493
|
-
for (const sys of [...context.apps, ...context.libs]) {
|
|
494
|
-
const sysPath = path.join(workspace.workspaceRoot, sys.path);
|
|
495
|
-
for (const entry of await safeReadDir(sysPath)) {
|
|
496
|
-
if (!isScannedRootEntry(sys.type, entry.name))
|
|
497
|
-
continue;
|
|
498
|
-
const allowed = entry.isDirectory() ? rootAllowedDirs[sys.type].has(entry.name) : rootAllowedFiles[sys.type].has(entry.name);
|
|
499
|
-
const rootEntryHint = rootEntryHintOf(sys.type, entry.name);
|
|
500
|
-
if (!allowed)
|
|
501
|
-
report({
|
|
502
|
-
severity: "error",
|
|
503
|
-
code: `${sys.type}-root-unknown-entry`,
|
|
504
|
-
path: `${sys.path}/${entry.name}`,
|
|
505
|
-
message: `Unexpected ${entry.isDirectory() ? "folder" : "file"} in ${sys.type} root: ${sys.path}/${entry.name}${rootEntryHint ? ` (${rootEntryHint})` : ""}`
|
|
506
|
-
}, repairAction("module-shape", `akan repair module-shape --app ${sys.name}`, `Review ${sys.type} root shape and remove or move the unknown entry.`, false));
|
|
507
|
-
}
|
|
508
|
-
for (const facet of barrelFacetDirs)
|
|
509
|
-
for (const entry of await safeReadDir(path.join(sysPath, facet))) {
|
|
510
|
-
const shadow = entry.isDirectory() ? null : facetIndexShadowOf(`${facet}/${entry.name}`);
|
|
511
|
-
if (!shadow)
|
|
512
|
-
continue;
|
|
513
|
-
const entryPath = `${sys.path}/${facet}/${entry.name}`;
|
|
514
|
-
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));
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
const agentDrift = await AkanContextAnalyzer.#agentGuideDrift(workspace);
|
|
518
|
-
if (agentDrift)
|
|
519
|
-
report({ severity: "warning", code: agentDrift.code, path: "AGENTS.md", message: agentDrift.message }, repairAction("generated", "akan agent install agents-md", agentDrift.hint, true));
|
|
520
|
-
const sysPaths = [...context.apps, ...context.libs].map((sys) => sys.path);
|
|
521
|
-
const oversize = await AkanContextAnalyzer.#agentGuideOversize(workspace, sysPaths);
|
|
522
|
-
if (oversize)
|
|
523
|
-
diagnostics.push({ severity: "warning", code: "agent-guide-oversized", path: "AGENTS.md", message: oversize });
|
|
524
|
-
for (const leftover of await AkanContextAnalyzer.#agentGuideLeftovers(workspace))
|
|
525
|
-
diagnostics.push({ severity: "warning", code: "agent-guide-leftover", ...leftover });
|
|
526
|
-
for (const leftover of await AkanContextAnalyzer.#configLeftovers(workspace, sysPaths))
|
|
527
|
-
diagnostics.push({ severity: "warning", code: "config-leftover", ...leftover });
|
|
528
|
-
for (const sys of [...context.apps, ...context.libs]) {
|
|
529
|
-
for (const module of sys.modules) {
|
|
530
|
-
const moduleShapeCommand = `akan repair module-shape --app ${sys.name} --module ${module.name}`;
|
|
531
|
-
if (!module.abstract.exists)
|
|
532
|
-
report({
|
|
533
|
-
severity: strict ? "error" : "warning",
|
|
534
|
-
code: "module-abstract-missing",
|
|
535
|
-
path: module.abstract.path,
|
|
536
|
-
message: `${capitalize(module.kind)} module ${sys.name}:${module.name} should include ${module.abstract.path}`
|
|
537
|
-
}, repairAction("module-shape", moduleShapeCommand, "Create the missing module abstract or inspect required source files.", false));
|
|
538
|
-
const missingFiles = moduleShapeFiles(module).filter((filename) => !module.files.includes(filename));
|
|
539
|
-
if (missingFiles.length)
|
|
540
|
-
report({
|
|
541
|
-
severity: "error",
|
|
542
|
-
code: "module-shape-invalid",
|
|
543
|
-
path: module.path,
|
|
544
|
-
message: `${capitalize(module.kind)} module ${sys.name}:${module.name} is missing required files: ${missingFiles.join(", ")}`
|
|
545
|
-
}, repairAction("module-shape", moduleShapeCommand, "Review missing required module source files.", false));
|
|
546
|
-
if (module.kind !== "service" && module.files.includes(`${module.name}.dictionary.ts`)) {
|
|
547
|
-
const constantPath = path.join(workspace.workspaceRoot, module.path, `${module.name}.constant.ts`);
|
|
548
|
-
const dictionaryPath = path.join(workspace.workspaceRoot, module.path, `${module.name}.dictionary.ts`);
|
|
549
|
-
const [constantContent, dictionaryContent] = await Promise.all([
|
|
550
|
-
safeReadText(constantPath),
|
|
551
|
-
safeReadText(dictionaryPath)
|
|
552
|
-
]);
|
|
553
|
-
if (constantContent && dictionaryContent) {
|
|
554
|
-
for (const fieldName of unlabeledFieldNames(constantContent, dictionaryContent)) {
|
|
555
|
-
report({
|
|
556
|
-
severity: "warning",
|
|
557
|
-
code: "dictionary-label-missing",
|
|
558
|
-
path: `${module.path}/${module.name}.dictionary.ts`,
|
|
559
|
-
message: `Dictionary labels for ${sys.name}:${module.name}.${fieldName} were not found.`
|
|
560
|
-
}, repairAction("dictionary", `akan repair dictionary --app ${sys.name} --module ${module.name}`, "Add missing dictionary labels for source constant fields.", false));
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
for (const sys of [...context.apps, ...context.libs]) {
|
|
567
|
-
const sources = await collectRecipeSources2(path.join(workspace.workspaceRoot, sys.path, "ui"), "ui");
|
|
568
|
-
if (sources.length === 0)
|
|
569
|
-
continue;
|
|
570
|
-
const recipes = scanRecipes2(sources);
|
|
571
|
-
const files = [];
|
|
572
|
-
const glob = new Bun.Glob("**/*.tsx");
|
|
573
|
-
for await (const abs of glob.scan({ cwd: path.join(workspace.workspaceRoot, sys.path), absolute: true })) {
|
|
574
|
-
if (/[\\/](node_modules|\.akan|dist)[\\/]|[\\/]v1[\\/]/.test(abs) || /\.(test|spec)\.tsx$/.test(abs))
|
|
575
|
-
continue;
|
|
576
|
-
files.push({
|
|
577
|
-
path: abs,
|
|
578
|
-
content: await Bun.file(abs).text().catch(() => "")
|
|
579
|
-
});
|
|
580
|
-
}
|
|
581
|
-
const duplicates = findInlineRecipeDuplicates2(recipes, files);
|
|
582
|
-
if (duplicates.length === 0)
|
|
583
|
-
continue;
|
|
584
|
-
const preview = duplicates.slice(0, 3).map((duplicate) => `${path.relative(workspace.workspaceRoot, duplicate.path)}:${duplicate.line}`).join(", ");
|
|
585
|
-
diagnostics.push({
|
|
586
|
-
severity: "warning",
|
|
587
|
-
code: "recipe-inline-duplicate",
|
|
588
|
-
path: path.join(sys.path, "ui/Recipe"),
|
|
589
|
-
message: `${sys.name}: ${duplicates.length} inline className(s) re-author a recipe fingerprint (${preview}${duplicates.length > 3 ? ", \u2026" : ""}) \u2014 consume the recipe instead.`
|
|
590
|
-
});
|
|
591
|
-
}
|
|
592
|
-
const scanNames = async (uiDirPath, basename) => new Set(scanRecipes2(await collectRecipeSources2(uiDirPath, "ui", basename)).map((info) => info.name));
|
|
593
|
-
const declaredByImport = new Map;
|
|
594
|
-
declaredByImport.set("akanjs/ui", await scanNames(path.join(workspace.workspaceRoot, "pkgs/akanjs/ui"), "recipe"));
|
|
595
|
-
for (const sys of [...context.apps, ...context.libs])
|
|
596
|
-
declaredByImport.set(`@${sys.path}/ui`, await scanNames(path.join(workspace.workspaceRoot, sys.path, "ui")));
|
|
597
|
-
const sectionOf = (content, heading) => {
|
|
598
|
-
const match = new RegExp(`^${heading}$`, "m").exec(content);
|
|
599
|
-
if (!match)
|
|
600
|
-
return "";
|
|
601
|
-
const section = content.slice(match.index);
|
|
602
|
-
const sectionEnd = section.indexOf(`
|
|
603
|
-
## `, 1);
|
|
604
|
-
return sectionEnd === -1 ? section : section.slice(0, sectionEnd);
|
|
605
|
-
};
|
|
606
|
-
const listedByImport = (body) => {
|
|
607
|
-
const groups = new Map;
|
|
608
|
-
let current = null;
|
|
609
|
-
for (const line of body.split(`
|
|
610
|
-
`)) {
|
|
611
|
-
const group = /^Import from `([^`]+)`:/.exec(line);
|
|
612
|
-
if (group) {
|
|
613
|
-
current = groups.get(group[1]) ?? new Set;
|
|
614
|
-
groups.set(group[1], current);
|
|
615
|
-
continue;
|
|
616
|
-
}
|
|
617
|
-
const item = /^- `([A-Za-z0-9_$]+)`/.exec(line);
|
|
618
|
-
if (item && current)
|
|
619
|
-
current.add(item[1]);
|
|
620
|
-
else if (!item)
|
|
621
|
-
current = null;
|
|
622
|
-
}
|
|
623
|
-
return groups;
|
|
624
|
-
};
|
|
625
|
-
const pushIndexDiagnostic = (indexPath, missing, stale, repairCommand) => {
|
|
626
|
-
if (missing.length === 0 && stale.length === 0)
|
|
627
|
-
return;
|
|
628
|
-
const parts = [
|
|
629
|
-
missing.length > 0 ? `${missing.length} declared but unlisted (${missing.slice(0, 5).join(", ")})` : "",
|
|
630
|
-
stale.length > 0 ? `${stale.length} listed but gone (${stale.slice(0, 5).join(", ")})` : ""
|
|
631
|
-
].filter(Boolean);
|
|
632
|
-
report({
|
|
633
|
-
severity: "error",
|
|
634
|
-
code: "recipe-index-stale",
|
|
635
|
-
path: indexPath,
|
|
636
|
-
message: `${indexPath} recipe index is out of date \u2014 ${parts.join("; ")}. Agents read this list as authoritative.`
|
|
637
|
-
}, repairAction("generated", repairCommand, "Regenerate the recipe index from the scanned recipes.", true));
|
|
638
|
-
};
|
|
639
|
-
const frameworkDeclared = declaredByImport.get("akanjs/ui") ?? new Set;
|
|
640
|
-
if (frameworkDeclared.size > 0) {
|
|
641
|
-
const agentsMd = await Bun.file(path.join(workspace.workspaceRoot, "AGENTS.md")).text().catch(() => "");
|
|
642
|
-
const listed = listedByImport(sectionOf(agentsMd, "## Recipes")).get("akanjs/ui") ?? new Set;
|
|
643
|
-
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");
|
|
644
|
-
}
|
|
645
|
-
for (const sys of [...context.apps, ...context.libs]) {
|
|
646
|
-
const own = declaredByImport.get(`@${sys.path}/ui`) ?? new Set;
|
|
647
|
-
const scopeMd = await Bun.file(path.join(workspace.workspaceRoot, sys.path, "AGENTS.md")).text().catch(() => "");
|
|
648
|
-
const groups = listedByImport(sectionOf(scopeMd, "## Recipes In Scope"));
|
|
649
|
-
const ownListed = groups.get(`@${sys.path}/ui`) ?? new Set;
|
|
650
|
-
const missing = [...own].filter((name) => !ownListed.has(name)).sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
651
|
-
const stale = [...groups.entries()].flatMap(([importFrom, names]) => [...names].filter((name) => !(declaredByImport.get(importFrom) ?? new Set).has(name))).sort();
|
|
652
|
-
pushIndexDiagnostic(`${sys.path}/AGENTS.md`, missing, stale, `akan sync ${sys.name}`);
|
|
653
|
-
}
|
|
654
|
-
const scopedDiagnostics = diagnostics.map((diagnostic) => ({
|
|
655
|
-
...diagnostic,
|
|
656
|
-
scope: workflowPaths.length ? isWorkflowRelatedDiagnostic(diagnostic, workflowPaths) ? "workflow" : "baseline" : diagnostic.scope,
|
|
657
|
-
context: workflowPaths.length ? { ...diagnostic.context, paths: workflowPaths } : diagnostic.context
|
|
658
|
-
}));
|
|
659
|
-
const workflowDiagnostics = scopedDiagnostics.filter((diagnostic) => diagnostic.scope === "workflow");
|
|
660
|
-
const baselineDiagnostics = scopedDiagnostics.filter((diagnostic) => diagnostic.scope === "baseline");
|
|
661
|
-
return {
|
|
662
|
-
schemaVersion: 1,
|
|
663
|
-
repoName: context.repoName,
|
|
664
|
-
root: context.root,
|
|
665
|
-
strict,
|
|
666
|
-
status: scopedDiagnostics.some((diagnostic) => diagnostic.severity === "error") ? "failed" : "passed",
|
|
667
|
-
diagnostics: scopedDiagnostics,
|
|
668
|
-
generatedFiles: context.generatedFiles,
|
|
669
|
-
generatedFilesFreshness: await generatedFreshnessFromStates(workspace),
|
|
670
|
-
validationCommands: context.validationCommands,
|
|
671
|
-
repairActions,
|
|
672
|
-
...workflowPaths.length ? { baselineDiagnostics, workflowDiagnostics } : {}
|
|
673
|
-
};
|
|
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 });
|
|
674
756
|
}
|
|
675
757
|
static findModules(context, moduleName, { app = null } = {}) {
|
|
676
758
|
const modules = [...context.apps, ...context.libs].filter((sys) => !app || sys.name === app).flatMap((sys) => sys.modules);
|