@akanjs/devkit 3.2.0-rc.18 → 3.2.0-rc.19
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/CHANGELOG.md +44 -4
- package/DEV_RUNTIME_KNOBS.md +4 -3
- package/akanApp/akanApp.host.test.ts +18 -2
- package/akanApp/akanApp.host.wiring.test.ts +723 -0
- package/akanApp/devIdleSuspend.test.ts +107 -20
- package/akanApp/devIdleSuspend.ts +31 -14
- package/akanApp/devIdleSuspend.watcher.test.ts +77 -0
- package/apiReport/apiReport.test.ts +29 -0
- package/apiReport/apiReportDiff.ts +35 -1
- package/app/applicationBuildReporter.ts +2 -49
- package/artifact/implicitRootLayoutRender.test.tsx +23 -3
- package/codeAgent/agent/akanSystemPrompt.ts +1 -1
- package/codeAgent/skills/akan-scaffold/SKILL.md +1 -1
- package/commandDecorators/command.ts +2 -1
- package/commandDecorators/commandBuilder.ts +1 -1
- package/commandDecorators/commandDecorators.test.ts +28 -4
- package/context/akanContext.ts +20 -527
- package/context/akanContextInspection.ts +296 -0
- package/context/akanMcpContract.ts +13 -253
- package/context/doctor/agentGuideCheck.ts +81 -0
- package/context/doctor/configLeftoverCheck.ts +35 -0
- package/context/doctor/doctorFindings.ts +70 -0
- package/context/doctor/generatedFreshness.ts +56 -0
- package/context/doctor/moduleShapeCheck.ts +88 -0
- package/context/doctor/recipeDuplicateCheck.ts +39 -0
- package/context/doctor/recipeIndexCheck.ts +87 -0
- package/context/doctor/rootShapeCheck.ts +55 -0
- package/context/doctor/workflowScope.ts +97 -0
- package/context/safeRead.ts +9 -0
- package/devkitUtils.test.ts +34 -0
- package/executors/executors.test.ts +1 -4
- package/executors/workspaceExecutor.ts +1 -2
- package/frontendBuild/hmrWatcher.stop.test.ts +36 -0
- package/frontendBuild/hmrWatcher.ts +2 -0
- package/incrementalBuilder/buildBatch.proc.ts +13 -3
- package/incrementalBuilder/buildBatchProtocol.ts +2 -0
- package/incrementalBuilder/buildBatchRunner.test.ts +61 -0
- package/incrementalBuilder/buildBatchRunner.ts +6 -3
- package/incrementalBuilder/builderBoot.ts +106 -0
- package/incrementalBuilder/builderBuildStatus.ts +23 -0
- package/incrementalBuilder/builderChannel.ts +11 -0
- package/incrementalBuilder/builderLanes.ts +157 -0
- package/incrementalBuilder/builderWatch.ts +213 -0
- package/incrementalBuilder/csrRegistry.ts +234 -0
- package/incrementalBuilder/incrementalBuilder.proc.test.ts +92 -1
- package/incrementalBuilder/incrementalBuilder.proc.ts +80 -822
- package/incrementalBuilder/ssrRegistry.ts +278 -0
- package/integration/devStability.integration.test.ts +62 -56
- package/package.json +3 -3
- package/test/testHelpers.ts +36 -0
- package/util/errorReport.ts +66 -0
- package/workflow/constantSource.ts +187 -0
- package/workflow/dictionarySource.ts +184 -0
- package/workflow/executor.ts +5 -8
- package/workflow/fieldExpression.ts +153 -0
- package/workflow/fieldLabel.ts +61 -0
- package/workflow/fieldOrder.ts +117 -0
- package/workflow/fieldType.ts +2 -1
- package/workflow/keyRename.ts +1 -1
- package/workflow/moduleIndex.ts +1 -1
- package/workflow/modulePaths.ts +27 -0
- package/workflow/mutationScaffold.ts +7 -15
- package/workflow/mutationSource.ts +2 -1
- package/workflow/plan.ts +2 -1
- package/workflow/primitiveReport.ts +78 -0
- package/workflow/serviceSource.ts +33 -0
- package/workflow/signalSource.ts +96 -0
- package/workflow/source.ts +50 -1100
- package/workflow/sourceAst.ts +30 -0
- package/workflow/sourceImports.ts +105 -0
- package/workflow/sourceText.ts +13 -0
- package/workflow/templateSource.ts +30 -0
- package/workflow/testSource.ts +31 -0
- package/workflow/types.ts +1 -1
- package/workflow/uiPolicy.ts +1 -1
|
@@ -440,7 +440,6 @@ describe("enum arg type inference", () => {
|
|
|
440
440
|
|
|
441
441
|
describe("a Sys that defaults to the only app", () => {
|
|
442
442
|
const ownIsTTY = Object.getOwnPropertyDescriptor(process.stdin, "isTTY");
|
|
443
|
-
const ownCwd = process.cwd();
|
|
444
443
|
const asked: unknown[] = [];
|
|
445
444
|
let answer = "";
|
|
446
445
|
const setTTY = (isTTY: boolean | undefined) =>
|
|
@@ -456,7 +455,6 @@ describe("a Sys that defaults to the only app", () => {
|
|
|
456
455
|
});
|
|
457
456
|
afterEach(() => {
|
|
458
457
|
CommandContainer.clear();
|
|
459
|
-
process.chdir(ownCwd);
|
|
460
458
|
if (ownIsTTY) Object.defineProperty(process.stdin, "isTTY", ownIsTTY);
|
|
461
459
|
else Reflect.deleteProperty(process.stdin, "isTTY");
|
|
462
460
|
});
|
|
@@ -479,10 +477,8 @@ describe("a Sys that defaults to the only app", () => {
|
|
|
479
477
|
return meta;
|
|
480
478
|
};
|
|
481
479
|
const track = tempRoots();
|
|
482
|
-
//? From the workspace root, as the CLI runs: getDirInModule stats its entries relative to the process directory.
|
|
483
480
|
const moduleWorkspace = async () => {
|
|
484
481
|
const { root, workspace } = track(await makeCliTempWorkspace());
|
|
485
|
-
process.chdir(root);
|
|
486
482
|
for (const [sys, name] of [
|
|
487
483
|
["apps/web", "card"],
|
|
488
484
|
["libs/util", "photo"],
|
|
@@ -926,6 +922,34 @@ describe("the exit code of a command that failed", () => {
|
|
|
926
922
|
expect(rejected.code).toBe(2);
|
|
927
923
|
}, 60_000);
|
|
928
924
|
|
|
925
|
+
test("ends with each reason an aggregate holds, where a bundler log names its file and line", async () => {
|
|
926
|
+
const graphFailure = [
|
|
927
|
+
"await (async () => {",
|
|
928
|
+
' await Bun.write("graph/server.ts", \'import { env } from "./env.server.debug";\\nexport default env;\\n\');',
|
|
929
|
+
' const result = await Bun.build({ entrypoints: ["graph/server.ts"], target: "bun", throw: false });',
|
|
930
|
+
' return new AggregateError(result.logs, "[licenseNotices] server graph failed");',
|
|
931
|
+
"})()",
|
|
932
|
+
].join("\n");
|
|
933
|
+
const reason = ' Could not resolve: "./env.server.debug" (graph/server.ts:1:21)';
|
|
934
|
+
const json = ' }).option("json", Boolean, { default: false';
|
|
935
|
+
const [text, asJson] = await Promise.all([
|
|
936
|
+
run(graphFailure),
|
|
937
|
+
run(graphFailure, { option: json, args: ["--json"] }),
|
|
938
|
+
]);
|
|
939
|
+
expect(text.code).toBe(1);
|
|
940
|
+
expect(stripAnsi(text.stdout).trimEnd().split("\n").slice(-2)).toEqual([
|
|
941
|
+
"[licenseNotices] server graph failed",
|
|
942
|
+
reason,
|
|
943
|
+
]);
|
|
944
|
+
expect(asJson.code).toBe(1);
|
|
945
|
+
expect(JSON.parse(asJson.stdout)).toEqual({
|
|
946
|
+
ok: false,
|
|
947
|
+
error: "[licenseNotices] server graph failed",
|
|
948
|
+
code: "failed",
|
|
949
|
+
});
|
|
950
|
+
expect(stripAnsi(asJson.stderr).trimEnd().split("\n").at(-1)).toBe(reason);
|
|
951
|
+
}, 30_000);
|
|
952
|
+
|
|
929
953
|
test("prints nothing more for an error the command marked as printed", async () => {
|
|
930
954
|
const marked = await run(
|
|
931
955
|
'(() => { const error = new Error("printed already"); markCliErrorPrinted(error); return error; })()',
|
package/context/akanContext.ts
CHANGED
|
@@ -1,30 +1,18 @@
|
|
|
1
|
-
import { readdir } from "node:fs/promises";
|
|
2
1
|
import path from "node:path";
|
|
3
|
-
import {
|
|
2
|
+
import { parseRouteModuleKey } from "akanjs/common";
|
|
4
3
|
import { AppExecutor, LibExecutor, type SysExecutor, type WorkspaceExecutor } from "../executors";
|
|
5
|
-
import { extractBlockVersion, readDevkitVersion } from "../guideline/agentsIndex";
|
|
6
4
|
import { FileSys } from "../util/fileSys";
|
|
7
|
-
import {
|
|
8
|
-
type GeneratedSyncState,
|
|
9
|
-
type RepairAction,
|
|
10
|
-
type WorkflowApplyReport,
|
|
11
|
-
type WorkflowPlan,
|
|
12
|
-
type WorkflowRunArtifact,
|
|
13
|
-
workflowPathsForPlan,
|
|
14
|
-
workflowRunArtifactPath,
|
|
15
|
-
workflowSyncDir,
|
|
16
|
-
} from "../workflow";
|
|
5
|
+
import type { RepairAction } from "../workflow";
|
|
17
6
|
import type { PackageJson } from "../workspace/types";
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
} from "
|
|
26
|
-
import {
|
|
27
|
-
import { collectRecipeSources, findInlineRecipeDuplicates, scanRecipes } from "./recipeScanner";
|
|
7
|
+
import { AgentGuideCheck } from "./doctor/agentGuideCheck";
|
|
8
|
+
import { ConfigLeftoverCheck } from "./doctor/configLeftoverCheck";
|
|
9
|
+
import { DoctorFindings } from "./doctor/doctorFindings";
|
|
10
|
+
import { ModuleShapeCheck } from "./doctor/moduleShapeCheck";
|
|
11
|
+
import { RecipeDuplicateCheck } from "./doctor/recipeDuplicateCheck";
|
|
12
|
+
import { RecipeIndexCheck } from "./doctor/recipeIndexCheck";
|
|
13
|
+
import { RootShapeCheck } from "./doctor/rootShapeCheck";
|
|
14
|
+
import { loadWorkflowContextPaths } from "./doctor/workflowScope";
|
|
15
|
+
import { safeReadDir, safeReadJson, safeReadText } from "./safeRead";
|
|
28
16
|
|
|
29
17
|
export type AkanContextFormat = "json" | "markdown";
|
|
30
18
|
export type AkanModuleKind = "domain" | "service" | "scalar";
|
|
@@ -305,172 +293,6 @@ const validationCommands = [
|
|
|
305
293
|
"akan quality ssr [--format json]",
|
|
306
294
|
];
|
|
307
295
|
|
|
308
|
-
const unknownGeneratedFilesFreshness: GeneratedFilesFreshness = {
|
|
309
|
-
status: "unknown" as const,
|
|
310
|
-
message: "Run sync before validation so generated Akan files match the current source conventions.",
|
|
311
|
-
refreshCommand: "akan sync <app-or-lib>",
|
|
312
|
-
verifyingCommands: ["akan verify <app-or-lib>"],
|
|
313
|
-
};
|
|
314
|
-
|
|
315
|
-
const repairAction = (
|
|
316
|
-
kind: RepairAction["kind"],
|
|
317
|
-
command: string,
|
|
318
|
-
reason: string,
|
|
319
|
-
safeToRun: boolean,
|
|
320
|
-
): RepairAction => ({
|
|
321
|
-
kind,
|
|
322
|
-
command,
|
|
323
|
-
reason,
|
|
324
|
-
safeToRun,
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
const moduleShapeFiles = (module: AkanModuleContext) => {
|
|
328
|
-
if (module.kind === "service") {
|
|
329
|
-
return [`${module.name}.dictionary.ts`, `${module.name}.service.ts`, `${module.name}.signal.ts`];
|
|
330
|
-
}
|
|
331
|
-
if (module.kind === "scalar") return [`${module.name}.constant.ts`, `${module.name}.dictionary.ts`];
|
|
332
|
-
return [
|
|
333
|
-
`${module.name}.constant.ts`,
|
|
334
|
-
`${module.name}.dictionary.ts`,
|
|
335
|
-
`${module.name}.service.ts`,
|
|
336
|
-
`${module.name}.store.ts`,
|
|
337
|
-
`${module.name}.signal.ts`,
|
|
338
|
-
];
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
const safeReadDir = async (dirPath: string) =>
|
|
342
|
-
(await readdir(dirPath, { withFileTypes: true }).catch(() => [])).sort((a, b) => a.name.localeCompare(b.name));
|
|
343
|
-
|
|
344
|
-
const safeReadText = (filePath: string) => FileSys.readText(filePath).catch(() => null);
|
|
345
|
-
|
|
346
|
-
const safeReadJson = <T>(filePath: string) => FileSys.readJson<T>(filePath).catch(() => null);
|
|
347
|
-
|
|
348
|
-
const isWorkflowPlan = (value: unknown): value is WorkflowPlan =>
|
|
349
|
-
typeof value === "object" &&
|
|
350
|
-
value !== null &&
|
|
351
|
-
"schemaVersion" in value &&
|
|
352
|
-
value.schemaVersion === 1 &&
|
|
353
|
-
"mode" in value &&
|
|
354
|
-
value.mode === "plan" &&
|
|
355
|
-
"inputs" in value &&
|
|
356
|
-
isRecord(value.inputs) &&
|
|
357
|
-
"predictedChanges" in value &&
|
|
358
|
-
Array.isArray(value.predictedChanges) &&
|
|
359
|
-
value.predictedChanges.every((change) => isRecord(change) && typeof change.target === "string");
|
|
360
|
-
|
|
361
|
-
const isPathList = (value: unknown) =>
|
|
362
|
-
Array.isArray(value) && value.every((file) => isRecord(file) && typeof file.path === "string");
|
|
363
|
-
|
|
364
|
-
const isWorkflowApplyReport = (value: unknown): value is WorkflowApplyReport =>
|
|
365
|
-
typeof value === "object" &&
|
|
366
|
-
value !== null &&
|
|
367
|
-
"schemaVersion" in value &&
|
|
368
|
-
value.schemaVersion === 1 &&
|
|
369
|
-
"mode" in value &&
|
|
370
|
-
(value.mode === "apply" || value.mode === "dry-run") &&
|
|
371
|
-
"changedFiles" in value &&
|
|
372
|
-
isPathList(value.changedFiles) &&
|
|
373
|
-
"generatedFiles" in value &&
|
|
374
|
-
isPathList(value.generatedFiles) &&
|
|
375
|
-
"plan" in value &&
|
|
376
|
-
isWorkflowPlan(value.plan);
|
|
377
|
-
|
|
378
|
-
const isWorkflowRunArtifact = (value: unknown): value is WorkflowRunArtifact =>
|
|
379
|
-
typeof value === "object" && value !== null && "schemaVersion" in value && value.schemaVersion === 1;
|
|
380
|
-
|
|
381
|
-
const workflowPathsForArtifact = (artifact: WorkflowRunArtifact) => {
|
|
382
|
-
if (isWorkflowPlan(artifact)) return workflowPathsForPlan(artifact);
|
|
383
|
-
if (isWorkflowApplyReport(artifact)) {
|
|
384
|
-
return [
|
|
385
|
-
...artifact.changedFiles.map((file) => file.path),
|
|
386
|
-
...artifact.generatedFiles.map((file) => file.path),
|
|
387
|
-
...workflowPathsForPlan(artifact.plan),
|
|
388
|
-
];
|
|
389
|
-
}
|
|
390
|
-
if ("mode" in artifact && artifact.mode === "validate" && isWorkflowPlan(artifact.plan))
|
|
391
|
-
return workflowPathsForPlan(artifact.plan);
|
|
392
|
-
return [];
|
|
393
|
-
};
|
|
394
|
-
|
|
395
|
-
const loadWorkflowContextPaths = async (
|
|
396
|
-
workspace: WorkspaceExecutor,
|
|
397
|
-
runIdOrPlan: string | null,
|
|
398
|
-
changedFiles: string[],
|
|
399
|
-
) => {
|
|
400
|
-
const paths = [...changedFiles];
|
|
401
|
-
if (!runIdOrPlan) return paths;
|
|
402
|
-
const inputPath = path.isAbsolute(runIdOrPlan) ? runIdOrPlan : path.join(workspace.workspaceRoot, runIdOrPlan);
|
|
403
|
-
const artifact =
|
|
404
|
-
(await safeReadJson<WorkflowRunArtifact | WorkflowPlan>(inputPath)) ??
|
|
405
|
-
(await safeReadJson<WorkflowRunArtifact>(path.join(workspace.workspaceRoot, workflowRunArtifactPath(runIdOrPlan))));
|
|
406
|
-
if (artifact && isWorkflowRunArtifact(artifact)) paths.push(...workflowPathsForArtifact(artifact));
|
|
407
|
-
return [...new Set(paths.filter(Boolean))];
|
|
408
|
-
};
|
|
409
|
-
|
|
410
|
-
const pathKey = (value: string) =>
|
|
411
|
-
value
|
|
412
|
-
.replaceAll("\\", "/")
|
|
413
|
-
.replaceAll("*", "")
|
|
414
|
-
.replace(/<[^>]+>/g, "")
|
|
415
|
-
.replace(/\/+/g, "/")
|
|
416
|
-
.replace(/^\/|\/$/g, "");
|
|
417
|
-
|
|
418
|
-
const isWorkflowRelatedDiagnostic = (diagnostic: AkanDiagnostic, workflowPaths: string[]) => {
|
|
419
|
-
if (!diagnostic.path) return false;
|
|
420
|
-
const diagnosticPath = pathKey(diagnostic.path);
|
|
421
|
-
return workflowPaths.some((workflowPath) => {
|
|
422
|
-
const candidate = pathKey(workflowPath);
|
|
423
|
-
if (!candidate) return false;
|
|
424
|
-
return (
|
|
425
|
-
diagnosticPath.startsWith(candidate) || candidate.startsWith(diagnosticPath) || diagnosticPath.includes(candidate)
|
|
426
|
-
);
|
|
427
|
-
});
|
|
428
|
-
};
|
|
429
|
-
|
|
430
|
-
const readGeneratedSyncStates = async (workspace: WorkspaceExecutor) => {
|
|
431
|
-
const syncDir = path.join(workspace.workspaceRoot, workflowSyncDir);
|
|
432
|
-
const entries = await safeReadDir(syncDir);
|
|
433
|
-
const states = await Promise.all(
|
|
434
|
-
entries
|
|
435
|
-
.filter((entry) => entry.isFile() && entry.name.endsWith(".json"))
|
|
436
|
-
.map((entry) => safeReadJson<GeneratedSyncState>(path.join(syncDir, entry.name))),
|
|
437
|
-
);
|
|
438
|
-
return states.filter(
|
|
439
|
-
(state): state is GeneratedSyncState =>
|
|
440
|
-
!!state && state.schemaVersion === 1 && typeof state.target === "string" && typeof state.syncedAt === "string",
|
|
441
|
-
);
|
|
442
|
-
};
|
|
443
|
-
|
|
444
|
-
const generatedFreshnessFromStates = async (workspace: WorkspaceExecutor): Promise<GeneratedFilesFreshness> => {
|
|
445
|
-
const states = await readGeneratedSyncStates(workspace);
|
|
446
|
-
if (states.length === 0) return unknownGeneratedFilesFreshness;
|
|
447
|
-
const targets = states
|
|
448
|
-
.sort((a, b) => a.target.localeCompare(b.target))
|
|
449
|
-
.map((state) => ({
|
|
450
|
-
target: state.target,
|
|
451
|
-
status: state.status === "passed" ? ("fresh" as const) : ("stale" as const),
|
|
452
|
-
lastSyncedAt: state.syncedAt,
|
|
453
|
-
runId: state.runId,
|
|
454
|
-
generatedFiles: state.generatedFiles.map((file) => file.path),
|
|
455
|
-
reason:
|
|
456
|
-
state.status === "passed"
|
|
457
|
-
? `Generated files were refreshed by ${state.command}.`
|
|
458
|
-
: `Last generated repair command failed: ${state.command}.`,
|
|
459
|
-
}));
|
|
460
|
-
const lastFresh = targets
|
|
461
|
-
.filter((target) => target.status === "fresh" && target.lastSyncedAt)
|
|
462
|
-
.sort((a, b) => (b.lastSyncedAt ?? "").localeCompare(a.lastSyncedAt ?? ""))[0];
|
|
463
|
-
return {
|
|
464
|
-
status: targets.some((target) => target.status === "fresh") ? "fresh" : "stale",
|
|
465
|
-
message: lastFresh
|
|
466
|
-
? `Generated files were refreshed for ${lastFresh.target} at ${lastFresh.lastSyncedAt}.`
|
|
467
|
-
: "Generated sync state exists, but the last recorded repair did not pass.",
|
|
468
|
-
refreshCommand: "akan sync <app-or-lib>",
|
|
469
|
-
verifyingCommands: ["akan verify <app-or-lib>"],
|
|
470
|
-
targets,
|
|
471
|
-
};
|
|
472
|
-
};
|
|
473
|
-
|
|
474
296
|
const parseAbstractSummary = (
|
|
475
297
|
relativePath: string,
|
|
476
298
|
content: string | null,
|
|
@@ -656,86 +478,6 @@ export class AkanContextAnalyzer {
|
|
|
656
478
|
};
|
|
657
479
|
}
|
|
658
480
|
|
|
659
|
-
// Nothing re-renders the AGENTS.md block on `bun update`, so the version stamp is the only staleness signal.
|
|
660
|
-
static async #agentGuideDrift(workspace: WorkspaceExecutor) {
|
|
661
|
-
const installed = await readDevkitVersion();
|
|
662
|
-
if (!installed) return null;
|
|
663
|
-
const content = await safeReadText(path.join(workspace.workspaceRoot, "AGENTS.md"));
|
|
664
|
-
if (content === null) return null;
|
|
665
|
-
const stamped = extractBlockVersion(content);
|
|
666
|
-
if (stamped === installed) return null;
|
|
667
|
-
const hint = "Re-render the AGENTS.md managed block from the installed framework release.";
|
|
668
|
-
if (!stamped)
|
|
669
|
-
return {
|
|
670
|
-
code: "agent-guide-unstamped",
|
|
671
|
-
message: `AGENTS.md carries no generated-version stamp, so its conventions may predate @akanjs/devkit ${installed}`,
|
|
672
|
-
hint,
|
|
673
|
-
};
|
|
674
|
-
return {
|
|
675
|
-
code: "agent-guide-stale",
|
|
676
|
-
message: `AGENTS.md was generated by @akanjs/devkit ${stamped}, but ${installed} is installed`,
|
|
677
|
-
hint,
|
|
678
|
-
};
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
//? Codex joins every AGENTS.md from the repo root down to its folder and drops what passes 32 KiB (`project_doc_max_bytes`).
|
|
682
|
-
static async #agentGuideOversize(workspace: WorkspaceExecutor, sysPaths: string[]) {
|
|
683
|
-
const sizeOf = async (file: string) => {
|
|
684
|
-
const content = await safeReadText(path.join(workspace.workspaceRoot, file));
|
|
685
|
-
return { file, bytes: content === null ? 0 : Buffer.byteLength(content) };
|
|
686
|
-
};
|
|
687
|
-
const root = await sizeOf("AGENTS.md");
|
|
688
|
-
if (root.bytes === 0) return null;
|
|
689
|
-
const scoped = await Promise.all(sysPaths.map((sysPath) => sizeOf(`${sysPath}/AGENTS.md`)));
|
|
690
|
-
const largest = scoped.reduce((max, entry) => (entry.bytes > max.bytes ? entry : max), { file: "", bytes: 0 });
|
|
691
|
-
const total = root.bytes + largest.bytes;
|
|
692
|
-
if (total <= 32 * 1024 * 0.8) return null;
|
|
693
|
-
const subject = largest.bytes ? `AGENTS.md and ${largest.file} add up to` : "AGENTS.md is";
|
|
694
|
-
return `${subject} ${Math.ceil(total / 1024)} KiB of the 32 KiB Codex reads — run \`akan agent install\`, then shorten the text outside the akan:agent markers or move it into a skill.`;
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
static async #agentGuideLeftovers(workspace: WorkspaceExecutor) {
|
|
698
|
-
const root = workspace.workspaceRoot;
|
|
699
|
-
const guide = (await safeReadText(path.join(root, "AGENTS.md"))) ?? "";
|
|
700
|
-
const leftovers: { path: string; message: string }[] = [];
|
|
701
|
-
for (const doc of ["docs/AI-DEVELOPMENT.md", "docs/GENERATED.md"]) {
|
|
702
|
-
const pointer = guide.includes(doc);
|
|
703
|
-
if ((await safeReadText(path.join(root, doc))) !== null)
|
|
704
|
-
leftovers.push({
|
|
705
|
-
path: doc,
|
|
706
|
-
message: `${doc} is an older template's copy of the agent guide, and nothing reads it now — delete it${pointer ? " and the AGENTS.md sentence that points to it" : ""}.`,
|
|
707
|
-
});
|
|
708
|
-
else if (pointer)
|
|
709
|
-
leftovers.push({
|
|
710
|
-
path: "AGENTS.md",
|
|
711
|
-
message: `AGENTS.md points to ${doc}, which is gone — delete that sentence.`,
|
|
712
|
-
});
|
|
713
|
-
}
|
|
714
|
-
return leftovers;
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
//? Older templates wrote these for Next.js: nothing installs or reads them, and editors warn about the plugin.
|
|
718
|
-
static async #configLeftovers(workspace: WorkspaceExecutor, sysPaths: string[]) {
|
|
719
|
-
const leftovers: { path: string; message: string }[] = [];
|
|
720
|
-
for (const sysPath of sysPaths) {
|
|
721
|
-
const tsconfigPath = `${sysPath}/tsconfig.json`;
|
|
722
|
-
const tsconfig = await safeReadText(path.join(workspace.workspaceRoot, tsconfigPath));
|
|
723
|
-
if (tsconfig && (/"name"\s*:\s*"next"/.test(tsconfig) || tsconfig.includes(".next/types")))
|
|
724
|
-
leftovers.push({
|
|
725
|
-
path: tsconfigPath,
|
|
726
|
-
message: `${tsconfigPath} still names the Next.js TS plugin or .next/types, which Akan never uses — delete the "next" plugin entry and the ".next/types/**/*.ts" include.`,
|
|
727
|
-
});
|
|
728
|
-
}
|
|
729
|
-
const bunfig = await safeReadText(path.join(workspace.workspaceRoot, "bunfig.toml"));
|
|
730
|
-
if (bunfig?.includes("bun-plugin-tailwind"))
|
|
731
|
-
leftovers.push({
|
|
732
|
-
path: "bunfig.toml",
|
|
733
|
-
message:
|
|
734
|
-
"bunfig.toml still loads bun-plugin-tailwind, which is not installed and which Akan never uses (it compiles Tailwind itself) — delete the [serve.static] section, which Akan never reads.",
|
|
735
|
-
});
|
|
736
|
-
return leftovers;
|
|
737
|
-
}
|
|
738
|
-
|
|
739
481
|
static async doctor(
|
|
740
482
|
workspace: WorkspaceExecutor,
|
|
741
483
|
{
|
|
@@ -746,264 +488,15 @@ export class AkanContextAnalyzer {
|
|
|
746
488
|
): Promise<AkanDoctorResult> {
|
|
747
489
|
const context = await AkanContextAnalyzer.analyze(workspace);
|
|
748
490
|
const workflowPaths = await loadWorkflowContextPaths(workspace, runIdOrPlan, changedFiles);
|
|
749
|
-
const
|
|
750
|
-
const
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
];
|
|
759
|
-
const report = (diagnostic: AkanDiagnostic, action: RepairAction) => {
|
|
760
|
-
diagnostics.push({ ...diagnostic, repairActions: [action] });
|
|
761
|
-
repairActions.push(action);
|
|
762
|
-
};
|
|
763
|
-
|
|
764
|
-
for (const sys of [...context.apps, ...context.libs]) {
|
|
765
|
-
const sysPath = path.join(workspace.workspaceRoot, sys.path);
|
|
766
|
-
for (const entry of await safeReadDir(sysPath)) {
|
|
767
|
-
if (!isScannedRootEntry(sys.type, entry.name)) continue;
|
|
768
|
-
const allowed = entry.isDirectory()
|
|
769
|
-
? rootAllowedDirs[sys.type].has(entry.name)
|
|
770
|
-
: rootAllowedFiles[sys.type].has(entry.name);
|
|
771
|
-
const rootEntryHint = rootEntryHintOf(sys.type, entry.name);
|
|
772
|
-
if (!allowed)
|
|
773
|
-
report(
|
|
774
|
-
{
|
|
775
|
-
severity: "error",
|
|
776
|
-
code: `${sys.type}-root-unknown-entry`,
|
|
777
|
-
path: `${sys.path}/${entry.name}`,
|
|
778
|
-
message: `Unexpected ${entry.isDirectory() ? "folder" : "file"} in ${sys.type} root: ${sys.path}/${entry.name}${
|
|
779
|
-
rootEntryHint ? ` (${rootEntryHint})` : ""
|
|
780
|
-
}`,
|
|
781
|
-
},
|
|
782
|
-
repairAction(
|
|
783
|
-
"module-shape",
|
|
784
|
-
`akan repair module-shape --app ${sys.name}`,
|
|
785
|
-
`Review ${sys.type} root shape and remove or move the unknown entry.`,
|
|
786
|
-
false,
|
|
787
|
-
),
|
|
788
|
-
);
|
|
789
|
-
}
|
|
790
|
-
for (const facet of barrelFacetDirs)
|
|
791
|
-
for (const entry of await safeReadDir(path.join(sysPath, facet))) {
|
|
792
|
-
const shadow = entry.isDirectory() ? null : facetIndexShadowOf(`${facet}/${entry.name}`);
|
|
793
|
-
if (!shadow) continue;
|
|
794
|
-
const entryPath = `${sys.path}/${facet}/${entry.name}`;
|
|
795
|
-
report(
|
|
796
|
-
{ severity: "error", code: "facet-index-shadowed", path: entryPath, message: `${entryPath} ${shadow}` },
|
|
797
|
-
repairAction("generated", `akan sync ${sys.name}`, `Delete ${entryPath} by hand, then sync.`, false),
|
|
798
|
-
);
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
const agentDrift = await AkanContextAnalyzer.#agentGuideDrift(workspace);
|
|
803
|
-
if (agentDrift)
|
|
804
|
-
report(
|
|
805
|
-
{ severity: "warning", code: agentDrift.code, path: "AGENTS.md", message: agentDrift.message },
|
|
806
|
-
repairAction("generated", "akan agent install agents-md", agentDrift.hint, true),
|
|
807
|
-
);
|
|
808
|
-
const sysPaths = [...context.apps, ...context.libs].map((sys) => sys.path);
|
|
809
|
-
const oversize = await AkanContextAnalyzer.#agentGuideOversize(workspace, sysPaths);
|
|
810
|
-
if (oversize)
|
|
811
|
-
diagnostics.push({ severity: "warning", code: "agent-guide-oversized", path: "AGENTS.md", message: oversize });
|
|
812
|
-
for (const leftover of await AkanContextAnalyzer.#agentGuideLeftovers(workspace))
|
|
813
|
-
diagnostics.push({ severity: "warning", code: "agent-guide-leftover", ...leftover });
|
|
814
|
-
for (const leftover of await AkanContextAnalyzer.#configLeftovers(workspace, sysPaths))
|
|
815
|
-
diagnostics.push({ severity: "warning", code: "config-leftover", ...leftover });
|
|
816
|
-
|
|
817
|
-
for (const sys of [...context.apps, ...context.libs]) {
|
|
818
|
-
for (const module of sys.modules) {
|
|
819
|
-
const moduleShapeCommand = `akan repair module-shape --app ${sys.name} --module ${module.name}`;
|
|
820
|
-
if (!module.abstract.exists)
|
|
821
|
-
report(
|
|
822
|
-
{
|
|
823
|
-
severity: strict ? "error" : "warning",
|
|
824
|
-
code: "module-abstract-missing",
|
|
825
|
-
path: module.abstract.path,
|
|
826
|
-
message: `${capitalize(module.kind)} module ${sys.name}:${module.name} should include ${module.abstract.path}`,
|
|
827
|
-
},
|
|
828
|
-
repairAction(
|
|
829
|
-
"module-shape",
|
|
830
|
-
moduleShapeCommand,
|
|
831
|
-
"Create the missing module abstract or inspect required source files.",
|
|
832
|
-
false,
|
|
833
|
-
),
|
|
834
|
-
);
|
|
835
|
-
const missingFiles = moduleShapeFiles(module).filter((filename) => !module.files.includes(filename));
|
|
836
|
-
if (missingFiles.length)
|
|
837
|
-
report(
|
|
838
|
-
{
|
|
839
|
-
severity: "error",
|
|
840
|
-
code: "module-shape-invalid",
|
|
841
|
-
path: module.path,
|
|
842
|
-
message: `${capitalize(module.kind)} module ${sys.name}:${module.name} is missing required files: ${missingFiles.join(", ")}`,
|
|
843
|
-
},
|
|
844
|
-
repairAction("module-shape", moduleShapeCommand, "Review missing required module source files.", false),
|
|
845
|
-
);
|
|
846
|
-
if (module.kind !== "service" && module.files.includes(`${module.name}.dictionary.ts`)) {
|
|
847
|
-
const constantPath = path.join(workspace.workspaceRoot, module.path, `${module.name}.constant.ts`);
|
|
848
|
-
const dictionaryPath = path.join(workspace.workspaceRoot, module.path, `${module.name}.dictionary.ts`);
|
|
849
|
-
const [constantContent, dictionaryContent] = await Promise.all([
|
|
850
|
-
safeReadText(constantPath),
|
|
851
|
-
safeReadText(dictionaryPath),
|
|
852
|
-
]);
|
|
853
|
-
if (constantContent && dictionaryContent) {
|
|
854
|
-
for (const fieldName of unlabeledFieldNames(constantContent, dictionaryContent)) {
|
|
855
|
-
report(
|
|
856
|
-
{
|
|
857
|
-
severity: "warning",
|
|
858
|
-
code: "dictionary-label-missing",
|
|
859
|
-
path: `${module.path}/${module.name}.dictionary.ts`,
|
|
860
|
-
message: `Dictionary labels for ${sys.name}:${module.name}.${fieldName} were not found.`,
|
|
861
|
-
},
|
|
862
|
-
repairAction(
|
|
863
|
-
"dictionary",
|
|
864
|
-
`akan repair dictionary --app ${sys.name} --module ${module.name}`,
|
|
865
|
-
"Add missing dictionary labels for source constant fields.",
|
|
866
|
-
false,
|
|
867
|
-
),
|
|
868
|
-
);
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
//* Advisory only (warning): promoted to lint only if inline re-authoring actually recurs.
|
|
876
|
-
for (const sys of [...context.apps, ...context.libs]) {
|
|
877
|
-
const sources = await collectRecipeSources(path.join(workspace.workspaceRoot, sys.path, "ui"), "ui");
|
|
878
|
-
if (sources.length === 0) continue;
|
|
879
|
-
const recipes = scanRecipes(sources);
|
|
880
|
-
const files: { path: string; content: string }[] = [];
|
|
881
|
-
const glob = new Bun.Glob("**/*.tsx");
|
|
882
|
-
for await (const abs of glob.scan({ cwd: path.join(workspace.workspaceRoot, sys.path), absolute: true })) {
|
|
883
|
-
if (/[\\/](node_modules|\.akan|dist)[\\/]|[\\/]v1[\\/]/.test(abs) || /\.(test|spec)\.tsx$/.test(abs)) continue;
|
|
884
|
-
files.push({
|
|
885
|
-
path: abs,
|
|
886
|
-
content: await Bun.file(abs)
|
|
887
|
-
.text()
|
|
888
|
-
.catch(() => ""),
|
|
889
|
-
});
|
|
890
|
-
}
|
|
891
|
-
const duplicates = findInlineRecipeDuplicates(recipes, files);
|
|
892
|
-
if (duplicates.length === 0) continue;
|
|
893
|
-
const preview = duplicates
|
|
894
|
-
.slice(0, 3)
|
|
895
|
-
.map((duplicate) => `${path.relative(workspace.workspaceRoot, duplicate.path)}:${duplicate.line}`)
|
|
896
|
-
.join(", ");
|
|
897
|
-
diagnostics.push({
|
|
898
|
-
severity: "warning",
|
|
899
|
-
code: "recipe-inline-duplicate",
|
|
900
|
-
path: path.join(sys.path, "ui/Recipe"),
|
|
901
|
-
message: `${sys.name}: ${duplicates.length} inline className(s) re-author a recipe fingerprint (${preview}${duplicates.length > 3 ? ", …" : ""}) — consume the recipe instead.`,
|
|
902
|
-
});
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
// Doctor never writes, so this is what catches a committed stale recipe index (lint and sync self-heal the tree).
|
|
906
|
-
const scanNames = async (uiDirPath: string, basename?: string) =>
|
|
907
|
-
new Set(scanRecipes(await collectRecipeSources(uiDirPath, "ui", basename)).map((info) => info.name));
|
|
908
|
-
const declaredByImport = new Map<string, Set<string>>();
|
|
909
|
-
declaredByImport.set("akanjs/ui", await scanNames(path.join(workspace.workspaceRoot, "pkgs/akanjs/ui"), "recipe"));
|
|
910
|
-
for (const sys of [...context.apps, ...context.libs])
|
|
911
|
-
declaredByImport.set(`@${sys.path}/ui`, await scanNames(path.join(workspace.workspaceRoot, sys.path, "ui")));
|
|
912
|
-
// Section slice anchors the heading to a full line — the same string appears back-ticked in prose.
|
|
913
|
-
const sectionOf = (content: string, heading: string) => {
|
|
914
|
-
const match = new RegExp(`^${heading}$`, "m").exec(content);
|
|
915
|
-
if (!match) return "";
|
|
916
|
-
const section = content.slice(match.index);
|
|
917
|
-
const sectionEnd = section.indexOf("\n## ", 1);
|
|
918
|
-
return sectionEnd === -1 ? section : section.slice(0, sectionEnd);
|
|
919
|
-
};
|
|
920
|
-
// `Import from \`<path>\`:` groups with their `- \`name\`` items, so each name checks against its owner.
|
|
921
|
-
const listedByImport = (body: string) => {
|
|
922
|
-
const groups = new Map<string, Set<string>>();
|
|
923
|
-
let current: Set<string> | null = null;
|
|
924
|
-
for (const line of body.split("\n")) {
|
|
925
|
-
const group = /^Import from `([^`]+)`:/.exec(line);
|
|
926
|
-
if (group) {
|
|
927
|
-
current = groups.get(group[1]) ?? new Set();
|
|
928
|
-
groups.set(group[1], current);
|
|
929
|
-
continue;
|
|
930
|
-
}
|
|
931
|
-
const item = /^- `([A-Za-z0-9_$]+)`/.exec(line);
|
|
932
|
-
if (item && current) current.add(item[1]);
|
|
933
|
-
else if (!item) current = null;
|
|
934
|
-
}
|
|
935
|
-
return groups;
|
|
936
|
-
};
|
|
937
|
-
const pushIndexDiagnostic = (indexPath: string, missing: string[], stale: string[], repairCommand: string) => {
|
|
938
|
-
if (missing.length === 0 && stale.length === 0) return;
|
|
939
|
-
const parts = [
|
|
940
|
-
missing.length > 0 ? `${missing.length} declared but unlisted (${missing.slice(0, 5).join(", ")})` : "",
|
|
941
|
-
stale.length > 0 ? `${stale.length} listed but gone (${stale.slice(0, 5).join(", ")})` : "",
|
|
942
|
-
].filter(Boolean);
|
|
943
|
-
report(
|
|
944
|
-
{
|
|
945
|
-
severity: "error",
|
|
946
|
-
code: "recipe-index-stale",
|
|
947
|
-
path: indexPath,
|
|
948
|
-
message: `${indexPath} recipe index is out of date — ${parts.join("; ")}. Agents read this list as authoritative.`,
|
|
949
|
-
},
|
|
950
|
-
repairAction("generated", repairCommand, "Regenerate the recipe index from the scanned recipes.", true),
|
|
951
|
-
);
|
|
952
|
-
};
|
|
953
|
-
const frameworkDeclared = declaredByImport.get("akanjs/ui") ?? new Set<string>();
|
|
954
|
-
if (frameworkDeclared.size > 0) {
|
|
955
|
-
const agentsMd = await Bun.file(path.join(workspace.workspaceRoot, "AGENTS.md"))
|
|
956
|
-
.text()
|
|
957
|
-
.catch(() => "");
|
|
958
|
-
const listed = listedByImport(sectionOf(agentsMd, "## Recipes")).get("akanjs/ui") ?? new Set<string>();
|
|
959
|
-
pushIndexDiagnostic(
|
|
960
|
-
"AGENTS.md",
|
|
961
|
-
[...frameworkDeclared].filter((name) => !listed.has(name)).sort((a, b) => (a < b ? -1 : a > b ? 1 : 0)),
|
|
962
|
-
[...listed].filter((name) => !frameworkDeclared.has(name)).sort((a, b) => (a < b ? -1 : a > b ? 1 : 0)),
|
|
963
|
-
"akan agent install agents-md",
|
|
964
|
-
);
|
|
965
|
-
}
|
|
966
|
-
for (const sys of [...context.apps, ...context.libs]) {
|
|
967
|
-
const own = declaredByImport.get(`@${sys.path}/ui`) ?? new Set<string>();
|
|
968
|
-
const scopeMd = await Bun.file(path.join(workspace.workspaceRoot, sys.path, "AGENTS.md"))
|
|
969
|
-
.text()
|
|
970
|
-
.catch(() => "");
|
|
971
|
-
const groups = listedByImport(sectionOf(scopeMd, "## Recipes In Scope"));
|
|
972
|
-
const ownListed = groups.get(`@${sys.path}/ui`) ?? new Set<string>();
|
|
973
|
-
const missing = [...own].filter((name) => !ownListed.has(name)).sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
974
|
-
// Every listed name — the scope's own and its dependency libs' — must still exist at its owner.
|
|
975
|
-
const stale = [...groups.entries()]
|
|
976
|
-
.flatMap(([importFrom, names]) =>
|
|
977
|
-
[...names].filter((name) => !(declaredByImport.get(importFrom) ?? new Set()).has(name)),
|
|
978
|
-
)
|
|
979
|
-
.sort();
|
|
980
|
-
pushIndexDiagnostic(`${sys.path}/AGENTS.md`, missing, stale, `akan sync ${sys.name}`);
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
const scopedDiagnostics = diagnostics.map((diagnostic) => ({
|
|
984
|
-
...diagnostic,
|
|
985
|
-
scope: workflowPaths.length
|
|
986
|
-
? isWorkflowRelatedDiagnostic(diagnostic, workflowPaths)
|
|
987
|
-
? ("workflow" as const)
|
|
988
|
-
: ("baseline" as const)
|
|
989
|
-
: diagnostic.scope,
|
|
990
|
-
context: workflowPaths.length ? { ...diagnostic.context, paths: workflowPaths } : diagnostic.context,
|
|
991
|
-
}));
|
|
992
|
-
const workflowDiagnostics = scopedDiagnostics.filter((diagnostic) => diagnostic.scope === "workflow");
|
|
993
|
-
const baselineDiagnostics = scopedDiagnostics.filter((diagnostic) => diagnostic.scope === "baseline");
|
|
994
|
-
return {
|
|
995
|
-
schemaVersion: 1,
|
|
996
|
-
repoName: context.repoName,
|
|
997
|
-
root: context.root,
|
|
998
|
-
strict,
|
|
999
|
-
status: scopedDiagnostics.some((diagnostic) => diagnostic.severity === "error") ? "failed" : "passed",
|
|
1000
|
-
diagnostics: scopedDiagnostics,
|
|
1001
|
-
generatedFiles: context.generatedFiles,
|
|
1002
|
-
generatedFilesFreshness: await generatedFreshnessFromStates(workspace),
|
|
1003
|
-
validationCommands: context.validationCommands,
|
|
1004
|
-
repairActions,
|
|
1005
|
-
...(workflowPaths.length ? { baselineDiagnostics, workflowDiagnostics } : {}),
|
|
1006
|
-
};
|
|
491
|
+
const systems = [...context.apps, ...context.libs];
|
|
492
|
+
const findings = new DoctorFindings();
|
|
493
|
+
await RootShapeCheck.run(workspace, systems, findings);
|
|
494
|
+
await AgentGuideCheck.run(workspace, systems, findings);
|
|
495
|
+
await ConfigLeftoverCheck.run(workspace, systems, findings);
|
|
496
|
+
await ModuleShapeCheck.run(workspace, systems, findings, { strict });
|
|
497
|
+
await RecipeDuplicateCheck.run(workspace, systems, findings);
|
|
498
|
+
await RecipeIndexCheck.run(workspace, systems, findings);
|
|
499
|
+
return await findings.result(workspace, context, { strict, workflowPaths });
|
|
1007
500
|
}
|
|
1008
501
|
|
|
1009
502
|
static findModules(
|