@akanjs/devkit 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/CHANGELOG.md +0 -528
- package/DEV_RUNTIME_KNOBS.md +4 -3
- package/README.ko.md +3 -2
- package/README.md +4 -2
- package/akanApp/BackendImportGraph.test.ts +1 -1
- package/akanApp/akanApp.host.test.ts +132 -3
- package/akanApp/akanApp.host.ts +146 -1216
- package/akanApp/akanApp.host.wiring.test.ts +727 -0
- package/akanApp/builderGap.ts +68 -0
- package/akanApp/builderRequestRelay.test.ts +93 -0
- package/akanApp/builderRequestRelay.ts +100 -0
- package/akanApp/builderRssRecycler.ts +182 -0
- package/akanApp/devBackend.ts +392 -0
- package/akanApp/devBuildStatusBoard.ts +128 -0
- package/akanApp/devBuilder.ts +196 -0
- package/akanApp/devIdleSuspend.test.ts +221 -0
- package/akanApp/devIdleSuspend.ts +192 -0
- package/akanApp/devIdleSuspend.watcher.test.ts +120 -0
- package/akanApp/devRecycler.test.ts +66 -0
- package/akanApp/devRecycler.ts +305 -0
- package/akanApp/processRss.ts +61 -0
- package/akanConfig/akanConfig.test.ts +45 -17
- package/akanConfig/akanConfig.ts +10 -10
- package/akanConfig/akanWorkspaceConfig.ts +1 -1
- package/akanConfig/productionLockfile.ts +1 -1
- package/apiReport/apiReport.test.ts +34 -3
- package/apiReport/apiReportDiff.ts +35 -1
- package/apiReport/apiReportPolicy.ts +3 -2
- package/{applicationBuildReporter.ts → app/applicationBuildReporter.ts} +2 -49
- package/{applicationBuildRunner.test.ts → app/applicationBuildRunner.test.ts} +71 -8
- package/{applicationBuildRunner.ts → app/applicationBuildRunner.ts} +60 -21
- package/{applicationTestPreload.ts → app/applicationTestPreload.ts} +1 -1
- package/{routeJsBudget.test.ts → app/routeJsBudget.test.ts} +17 -1
- package/{routeJsBudget.ts → app/routeJsBudget.ts} +9 -3
- package/{routeSourceValidator.test.ts → app/routeSourceValidator.test.ts} +17 -0
- package/{routeSourceValidator.ts → app/routeSourceValidator.ts} +5 -1
- package/artifact/implicitRootLayout.test.ts +71 -3
- package/artifact/implicitRootLayout.ts +9 -3
- package/artifact/implicitRootLayoutRender.test.tsx +297 -0
- package/biome.base.json +2 -1
- package/cloud/cloudApi.test.ts +1 -1
- package/cloud/configLock.test.ts +1 -1
- package/cloud/globalConfig.test.ts +1 -1
- package/cloud/globalConfig.ts +1 -1
- package/cloud/updatePackUpload.test.ts +1 -1
- package/codeAgent/agent/AkanCodeEnv.ts +1 -1
- package/codeAgent/agent/AkanCodeServices.ts +23 -0
- package/codeAgent/agent/akanCodePaths.ts +1 -1
- package/codeAgent/agent/akanCodeServices.test.ts +54 -0
- package/codeAgent/agent/akanSystemPrompt.ts +1 -1
- package/codeAgent/agent/codeAgent.test.ts +1 -1
- package/codeAgent/skills/akan-debug/SKILL.md +8 -5
- package/codeAgent/skills/akan-err/SKILL.md +7 -0
- package/codeAgent/skills/akan-mcp/SKILL.md +19 -1
- package/codeAgent/skills/akan-scaffold/SKILL.md +1 -1
- package/codeAgent/skills/akan-validate/SKILL.md +3 -3
- package/codeAgent/tools/AkanCli.ts +1 -1
- package/codeAgent/tools/AkanToolPack.ts +2 -2
- package/codeAgent/tools/akanCodePlugins.test.ts +1 -1
- package/commandDecorators/command.ts +35 -6
- package/commandDecorators/commandBuilder.ts +1 -1
- package/commandDecorators/commandDecorators.test.ts +107 -6
- package/commandDecorators/targetMeta.ts +2 -0
- package/commandDecorators/workspaceVersionCheck.test.ts +70 -1
- package/commandDecorators/workspaceVersionCheck.ts +64 -14
- package/context/akanContext.ts +576 -0
- package/context/akanContextInspection.ts +296 -0
- package/{akanMcpContract.test.ts → context/akanMcpContract.test.ts} +1 -1
- package/{akanMcpContract.ts → context/akanMcpContract.ts} +16 -256
- 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 +42 -0
- package/context/doctor/recipeIndexCheck.ts +87 -0
- package/context/doctor/rootShapeCheck.ts +55 -0
- package/context/doctor/workflowScope.ts +97 -0
- package/{recipeScanner.test.ts → context/recipeScanner.test.ts} +1 -1
- package/context/safeRead.ts +9 -0
- package/csrE2e/csrE2eHarness.fixture.ts +1 -1
- package/devkitUtils.test.ts +39 -5
- package/{apiReference.test.ts → docs/apiReference.test.ts} +4 -4
- package/{apiReference.ts → docs/apiReference.ts} +2 -2
- package/docs/errorCodeReference.test.ts +282 -0
- package/docs/errorCodeReference.ts +71 -0
- package/docs/errorCodeScan.ts +551 -0
- package/{frameworkGraph.test.ts → docs/frameworkGraph.test.ts} +1 -1
- package/executors/appExecutor.ts +448 -0
- package/executors/commandExecutionError.ts +53 -0
- package/executors/executor.ts +527 -0
- package/{executors.linkFallback.test.ts → executors/executors.linkFallback.test.ts} +1 -1
- package/{executors.test.ts → executors/executors.test.ts} +76 -15
- package/executors/index.ts +8 -0
- package/executors/libExecutor.ts +23 -0
- package/executors/moduleExecutor.ts +18 -0
- package/executors/pkgExecutor.ts +129 -0
- package/executors/sysExecutor.ts +301 -0
- package/executors/workspaceExecutor.ts +277 -0
- package/frontendBuild/allRoutesBuilder.test.ts +1 -1
- package/frontendBuild/autoImportSync.test.ts +1 -1
- package/frontendBuild/autoImportSync.ts +1 -1
- package/frontendBuild/buildRouteClient.test.ts +1 -1
- package/frontendBuild/clientEntriesBundler.test.ts +1 -1
- package/frontendBuild/csrArtifactBuilder.test.ts +1 -1
- package/frontendBuild/csrDevArtifactWriter.ts +1 -1
- package/frontendBuild/cssCompiler.test.ts +3 -2
- package/frontendBuild/devGeneratedIndexSync.test.ts +1 -1
- package/frontendBuild/devGeneratedIndexSync.ts +7 -38
- package/frontendBuild/dictionaryAssetBuilder.test.ts +1 -1
- package/frontendBuild/fontOptimizer.test.ts +1 -1
- package/frontendBuild/fontPruner.test.ts +1 -1
- package/frontendBuild/frontendBuild.test.ts +3 -3
- package/frontendBuild/hmrWatcher.stop.test.ts +63 -0
- package/frontendBuild/hmrWatcher.test.ts +1 -1
- package/frontendBuild/hmrWatcher.ts +22 -1
- package/frontendBuild/mcpAppViewBuilder.test.ts +1 -1
- package/frontendBuild/mcpAppViewBuilder.ts +1 -1
- package/frontendBuild/nativeCore.test.ts +1 -1
- package/frontendBuild/optionalPeers.test.ts +36 -8
- package/frontendBuild/pagesBundleBuilder.test.ts +2 -3
- package/frontendBuild/pagesBundleBuilder.ts +1 -1
- package/frontendBuild/precompressArtifacts.test.ts +1 -1
- package/frontendBuild/precompressArtifacts.ts +19 -6
- package/frontendBuild/serverGraphFile.ts +1 -1
- package/frontendBuild/sourceMtimeIndex.test.ts +1 -1
- package/frontendBuild/ssrDevBundler.test.ts +1 -1
- package/frontendBuild/vendorImportScanner.test.ts +1 -1
- package/frontendBuild/vendorNarrowing.test.ts +1 -1
- package/frontendBuild/watchRootResolver.test.ts +1 -1
- package/{agentAssets.test.ts → guideline/agentAssets.test.ts} +1 -1
- package/{agentAssets.ts → guideline/agentAssets.ts} +2 -2
- package/{agentsIndex.test.ts → guideline/agentsIndex.test.ts} +2 -2
- package/{agentsIndex.ts → guideline/agentsIndex.ts} +13 -10
- package/{conventionSet.test.ts → guideline/conventionSet.test.ts} +7 -4
- package/{conventionSet.ts → guideline/conventionSet.ts} +1 -1
- package/{prompter.ts → guideline/prompter.ts} +2 -3
- package/incrementalBuilder/buildBatch.proc.ts +14 -4
- package/incrementalBuilder/buildBatchProtocol.ts +2 -0
- package/incrementalBuilder/buildBatchRunner.test.ts +122 -2
- package/incrementalBuilder/buildBatchRunner.ts +17 -4
- package/incrementalBuilder/builderBoot.ts +106 -0
- package/incrementalBuilder/builderBuildStatus.ts +23 -0
- package/incrementalBuilder/builderChannel.test.ts +1 -1
- package/incrementalBuilder/builderChannel.ts +11 -0
- package/incrementalBuilder/builderGraphPayloads.ts +3 -3
- package/incrementalBuilder/builderLanes.ts +157 -0
- package/incrementalBuilder/builderWatch.ts +213 -0
- package/incrementalBuilder/csrRegistry.ts +234 -0
- package/incrementalBuilder/incrementalBuilder.proc.test.ts +101 -7
- package/incrementalBuilder/incrementalBuilder.proc.ts +81 -823
- package/incrementalBuilder/ssrRegistry.ts +282 -0
- package/index.ts +22 -22
- package/integration/devStability.integration.test.ts +62 -56
- package/integration/devStabilityHarness.test.ts +1 -1
- package/lint/__fixtures__/no-import-common-err/bad.tsx +13 -0
- package/lint/__fixtures__/no-import-common-err/good.tsx +12 -0
- package/{biomeBase.test.ts → lint/biomeBase.test.ts} +1 -1
- package/lint/gritRules.test.ts +1 -1
- package/{linter.test.ts → lint/linter.test.ts} +1 -1
- package/lint/no-import-common-err.grit +31 -0
- package/lint/no-init-fetch-in-client.grit +1 -1
- package/mobile/desktopBin.test.ts +1 -1
- package/mobile/desktopRelease.test.ts +1 -1
- package/mobile/desktopServerStage.test.ts +2 -2
- package/mobile/desktopServerStage.ts +1 -1
- package/mobile/nativeApi.test.ts +1 -1
- package/mobile/nativeApp.test.ts +1 -1
- package/mobile/nativeConfig.test.ts +1 -1
- package/mobile/nativePluginFolders.test.ts +1 -1
- package/mobile/nativePublicEnv.test.ts +1 -1
- package/mobile/nativeWebDir.test.ts +1 -1
- package/mobile/serverBundleSecrets.test.ts +1 -1
- package/mobile/tarWriter.test.ts +1 -1
- package/mobile/updatePackFolder.test.ts +1 -1
- package/package.json +173 -9
- package/packageExports.test.ts +20 -2
- package/piDependencyPins.test.ts +1 -1
- package/pipeline/PipelineDefinition.ts +1 -1
- package/platformTest/IdleWatchedProcess.test.ts +1 -1
- package/platformTest/LinuxDockerTarget.ts +1 -1
- package/platformTest/PlatformTestRun.test.ts +1 -1
- package/platformTest/TestSnapshot.test.ts +1 -1
- package/platformTest/WindowsSshTarget.ts +1 -1
- package/preview/previewView.test.ts +23 -1
- package/{abstractDoc.test.ts → quality/abstractDoc.test.ts} +2 -2
- package/{abstractDoc.ts → quality/abstractDoc.ts} +1 -1
- package/quality/bareErrorScanner.ts +126 -0
- package/{maintainabilityBaseline.test.ts → quality/maintainabilityBaseline.test.ts} +73 -0
- package/{maintainabilityBaseline.ts → quality/maintainabilityBaseline.ts} +97 -9
- package/{maintainabilityContract.test.ts → quality/maintainabilityContract.test.ts} +383 -2
- package/{maintainabilityContract.ts → quality/maintainabilityContract.ts} +151 -29
- package/{maintainabilityExceptionScanner.test.ts → quality/maintainabilityExceptionScanner.test.ts} +15 -1
- package/{maintainabilityExceptionScanner.ts → quality/maintainabilityExceptionScanner.ts} +5 -1
- package/{maintainabilityLimits.ts → quality/maintainabilityLimits.ts} +12 -0
- package/{maintainabilityReport.ts → quality/maintainabilityReport.ts} +20 -3
- package/{qualityScanner.test.ts → quality/qualityScanner.test.ts} +41 -1
- package/{qualityScanner.ts → quality/qualityScanner.ts} +25 -91
- package/{storeAccessScanner.ts → quality/storeAccessScanner.ts} +15 -2
- package/quality/workspaceSourceFiles.ts +82 -0
- package/{subspace.test.ts → subspace/subspace.test.ts} +25 -4
- package/{subspace.ts → subspace/subspace.ts} +5 -5
- package/{subspaceClone.ts → subspace/subspaceClone.ts} +8 -8
- package/{subspaceConfig.ts → subspace/subspaceConfig.ts} +5 -1
- package/{testHelpers.ts → test/testHelpers.ts} +37 -1
- package/transforms/barrelAnalyzer.ts +31 -10
- package/transforms/browserDirnamePlugin.test.ts +1 -1
- package/transforms/externalizeFrameworkPlugin.test.ts +1 -1
- package/transforms/mcpAppPageTrimmer.test.ts +1 -1
- package/transforms/pureLazyMarker.test.ts +1 -1
- package/transforms/serverEnvPlugin.test.ts +1 -1
- package/transforms/serverEnvProfile.test.ts +1 -1
- package/transforms/sideEffectImportOrder.test.ts +1 -1
- package/transforms/transforms.test.ts +52 -2
- package/transforms/tsconfigPackageResolver.test.ts +1 -1
- package/{createTunnel.test.ts → tunnel/createTunnel.test.ts} +1 -1
- package/{createTunnel.ts → tunnel/createTunnel.ts} +2 -2
- package/{sshHostKeys.ts → tunnel/sshHostKeys.ts} +2 -2
- package/typecheck/projectTypecheck.test.ts +23 -1
- package/typecheck/projectTypecheck.ts +10 -2
- package/{typeChecker.test.ts → typecheck/typeChecker.test.ts} +1 -1
- package/{typeChecker.ts → typecheck/typeChecker.ts} +5 -4
- package/typecheck/typecheck.proc.ts +6 -2
- package/typecheck/typecheckFailure.ts +1 -1
- package/util/errorReport.ts +66 -0
- package/{jsonFormatter.test.ts → util/jsonFormatter.test.ts} +1 -1
- package/workflow/constantSource.ts +187 -0
- package/workflow/dictionarySource.ts +184 -0
- package/workflow/executor.ts +6 -9
- 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/guardCatalog.test.ts +1 -1
- package/workflow/keyRename.ts +1 -1
- package/workflow/moduleIndex.test.ts +2 -2
- package/workflow/moduleIndex.ts +2 -2
- 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/rolloutGate.test.ts +1 -1
- package/workflow/rolloutGate.ts +1 -1
- 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
- package/{appSelectionMemory.ts → workspace/appSelectionMemory.ts} +1 -1
- package/{codegenLock.test.ts → workspace/codegenLock.test.ts} +1 -1
- package/{dependencyScanner.test.ts → workspace/dependencyScanner.test.ts} +1 -1
- package/{dependencyScanner.ts → workspace/dependencyScanner.ts} +2 -2
- package/{envSeed.test.ts → workspace/envSeed.test.ts} +2 -2
- package/{envSeed.ts → workspace/envSeed.ts} +1 -1
- package/{libSource.test.ts → workspace/libSource.test.ts} +2 -2
- package/{libSource.ts → workspace/libSource.ts} +1 -1
- package/{scanInfo.ts → workspace/scanInfo.ts} +21 -10
- package/{slicePlanner.test.ts → workspace/slicePlanner.test.ts} +2 -2
- package/{slicePlanner.ts → workspace/slicePlanner.ts} +1 -1
- package/{workspaceGraph.test.ts → workspace/workspaceGraph.test.ts} +1 -1
- package/{workspaceGraph.ts → workspace/workspaceGraph.ts} +1 -1
- package/{workspaceLayout.test.ts → workspace/workspaceLayout.test.ts} +1 -1
- package/{workspaceLayout.ts → workspace/workspaceLayout.ts} +3 -1
- package/akanContext.ts +0 -1083
- package/executors.ts +0 -1749
- /package/{applicationBuildReporter.test.ts → app/applicationBuildReporter.test.ts} +0 -0
- /package/{akanMcpToolError.ts → context/akanMcpToolError.ts} +0 -0
- /package/{moduleFieldNames.test.ts → context/moduleFieldNames.test.ts} +0 -0
- /package/{moduleFieldNames.ts → context/moduleFieldNames.ts} +0 -0
- /package/{recipeScanner.ts → context/recipeScanner.ts} +0 -0
- /package/{declarationReader.ts → docs/declarationReader.ts} +0 -0
- /package/{frameworkGraph.ts → docs/frameworkGraph.ts} +0 -0
- /package/{biomeBase.ts → lint/biomeBase.ts} +0 -0
- /package/{linter.ts → lint/linter.ts} +0 -0
- /package/{commentDensityScanner.test.ts → quality/commentDensityScanner.test.ts} +0 -0
- /package/{commentDensityScanner.ts → quality/commentDensityScanner.ts} +0 -0
- /package/{componentSizeScanner.test.ts → quality/componentSizeScanner.test.ts} +0 -0
- /package/{componentSizeScanner.ts → quality/componentSizeScanner.ts} +0 -0
- /package/{componentWriteChainScanner.test.ts → quality/componentWriteChainScanner.test.ts} +0 -0
- /package/{componentWriteChainScanner.ts → quality/componentWriteChainScanner.ts} +0 -0
- /package/{deprecatedCommentScanner.test.ts → quality/deprecatedCommentScanner.test.ts} +0 -0
- /package/{deprecatedCommentScanner.ts → quality/deprecatedCommentScanner.ts} +0 -0
- /package/{endpointReach.test.ts → quality/endpointReach.test.ts} +0 -0
- /package/{endpointReach.ts → quality/endpointReach.ts} +0 -0
- /package/{formSetterScanner.test.ts → quality/formSetterScanner.test.ts} +0 -0
- /package/{formSetterScanner.ts → quality/formSetterScanner.ts} +0 -0
- /package/{kindBranchScanner.test.ts → quality/kindBranchScanner.test.ts} +0 -0
- /package/{kindBranchScanner.ts → quality/kindBranchScanner.ts} +0 -0
- /package/{maintainabilityReport.test.ts → quality/maintainabilityReport.test.ts} +0 -0
- /package/{renderMutationScanner.test.ts → quality/renderMutationScanner.test.ts} +0 -0
- /package/{renderMutationScanner.ts → quality/renderMutationScanner.ts} +0 -0
- /package/{serviceLoopCallScanner.test.ts → quality/serviceLoopCallScanner.test.ts} +0 -0
- /package/{serviceLoopCallScanner.ts → quality/serviceLoopCallScanner.ts} +0 -0
- /package/{signalMutationIndex.test.ts → quality/signalMutationIndex.test.ts} +0 -0
- /package/{signalMutationIndex.ts → quality/signalMutationIndex.ts} +0 -0
- /package/{sourceComments.test.ts → quality/sourceComments.test.ts} +0 -0
- /package/{sourceComments.ts → quality/sourceComments.ts} +0 -0
- /package/{ssrScanner.test.ts → quality/ssrScanner.test.ts} +0 -0
- /package/{ssrScanner.ts → quality/ssrScanner.ts} +0 -0
- /package/{storeAccessScanner.test.ts → quality/storeAccessScanner.test.ts} +0 -0
- /package/{storeSource.ts → quality/storeSource.ts} +0 -0
- /package/{storeWriteScanner.test.ts → quality/storeWriteScanner.test.ts} +0 -0
- /package/{storeWriteScanner.ts → quality/storeWriteScanner.ts} +0 -0
- /package/{structureScanner.test.ts → quality/structureScanner.test.ts} +0 -0
- /package/{structureScanner.ts → quality/structureScanner.ts} +0 -0
- /package/{testOnlyExportScanner.test.ts → quality/testOnlyExportScanner.test.ts} +0 -0
- /package/{testOnlyExportScanner.ts → quality/testOnlyExportScanner.ts} +0 -0
- /package/{writePath.test.ts → quality/writePath.test.ts} +0 -0
- /package/{writePath.ts → quality/writePath.ts} +0 -0
- /package/{writePlacementScanner.test.ts → quality/writePlacementScanner.test.ts} +0 -0
- /package/{writePlacementScanner.ts → quality/writePlacementScanner.ts} +0 -0
- /package/{writingActionIndex.test.ts → quality/writingActionIndex.test.ts} +0 -0
- /package/{writingActionIndex.ts → quality/writingActionIndex.ts} +0 -0
- /package/{subspaceReport.ts → subspace/subspaceReport.ts} +0 -0
- /package/{sshTunnel.ts → tunnel/sshTunnel.ts} +0 -0
- /package/{fileEditor.ts → util/fileEditor.ts} +0 -0
- /package/{fileSys.test.ts → util/fileSys.test.ts} +0 -0
- /package/{fileSys.ts → util/fileSys.ts} +0 -0
- /package/{jsonFormatter.ts → util/jsonFormatter.ts} +0 -0
- /package/{selectModel.ts → util/selectModel.ts} +0 -0
- /package/{semver.test.ts → util/semver.test.ts} +0 -0
- /package/{semver.ts → util/semver.ts} +0 -0
- /package/{shellOnlyEnv.test.ts → util/shellOnlyEnv.test.ts} +0 -0
- /package/{shellOnlyEnv.ts → util/shellOnlyEnv.ts} +0 -0
- /package/{spinner.test.ts → util/spinner.test.ts} +0 -0
- /package/{spinner.ts → util/spinner.ts} +0 -0
- /package/{stripAnsi.ts → util/stripAnsi.ts} +0 -0
- /package/{codegenLock.ts → workspace/codegenLock.ts} +0 -0
- /package/{getRelatedCnsts.ts → workspace/getRelatedCnsts.ts} +0 -0
- /package/{gitRevision.test.ts → workspace/gitRevision.test.ts} +0 -0
- /package/{gitRevision.ts → workspace/gitRevision.ts} +0 -0
- /package/{manifestDependencies.ts → workspace/manifestDependencies.ts} +0 -0
- /package/{packageExportsMap.ts → workspace/packageExportsMap.ts} +0 -0
- /package/{repoIdentity.ts → workspace/repoIdentity.ts} +0 -0
- /package/{types.ts → workspace/types.ts} +0 -0
|
@@ -0,0 +1,576 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { parseRouteModuleKey } from "akanjs/common";
|
|
3
|
+
import { AppExecutor, LibExecutor, type SysExecutor, type WorkspaceExecutor } from "../executors";
|
|
4
|
+
import { FileSys } from "../util/fileSys";
|
|
5
|
+
import type { RepairAction } from "../workflow";
|
|
6
|
+
import type { PackageJson } from "../workspace/types";
|
|
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";
|
|
16
|
+
|
|
17
|
+
export type AkanContextFormat = "json" | "markdown";
|
|
18
|
+
export type AkanModuleKind = "domain" | "service" | "scalar";
|
|
19
|
+
export type AkanDiagnosticSeverity = "warning" | "error";
|
|
20
|
+
|
|
21
|
+
export interface AkanAbstractSummary {
|
|
22
|
+
path: string;
|
|
23
|
+
exists: boolean;
|
|
24
|
+
title?: string;
|
|
25
|
+
headings: string[];
|
|
26
|
+
content?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface AkanModuleContext {
|
|
30
|
+
kind: AkanModuleKind;
|
|
31
|
+
name: string;
|
|
32
|
+
folderName: string;
|
|
33
|
+
sysName: string;
|
|
34
|
+
sysType: "app" | "lib";
|
|
35
|
+
path: string;
|
|
36
|
+
abstract: AkanAbstractSummary;
|
|
37
|
+
files: string[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface AkanRouteContext {
|
|
41
|
+
/** The URL pattern without the `/:lang` segment every route starts with. */
|
|
42
|
+
path: string;
|
|
43
|
+
file: string;
|
|
44
|
+
search: string[];
|
|
45
|
+
/** The page or a layout above it calls `.guard()`. */
|
|
46
|
+
guarded: boolean;
|
|
47
|
+
devOnly: boolean;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface AkanSysContext {
|
|
51
|
+
type: "app" | "lib";
|
|
52
|
+
name: string;
|
|
53
|
+
path: string;
|
|
54
|
+
hasConfig: boolean;
|
|
55
|
+
modules: AkanModuleContext[];
|
|
56
|
+
/** Listed for the app `--app` names only; reading them parses every route file. */
|
|
57
|
+
routes?: AkanRouteContext[];
|
|
58
|
+
routeError?: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface AkanPackageContext {
|
|
62
|
+
name: string;
|
|
63
|
+
path: string;
|
|
64
|
+
version?: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface AkanWorkspaceContext {
|
|
68
|
+
schemaVersion: 1;
|
|
69
|
+
repoName: string;
|
|
70
|
+
root: string;
|
|
71
|
+
packageVersion?: string;
|
|
72
|
+
apps: AkanSysContext[];
|
|
73
|
+
libs: AkanSysContext[];
|
|
74
|
+
pkgs: AkanPackageContext[];
|
|
75
|
+
generatedFiles: string[];
|
|
76
|
+
validationCommands: string[];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface AkanDiagnostic {
|
|
80
|
+
severity: AkanDiagnosticSeverity;
|
|
81
|
+
code: string;
|
|
82
|
+
message: string;
|
|
83
|
+
path?: string;
|
|
84
|
+
repairActions?: RepairAction[];
|
|
85
|
+
scope?: "baseline" | "workflow" | "unknown";
|
|
86
|
+
context?: {
|
|
87
|
+
workflow?: string;
|
|
88
|
+
planPath?: string;
|
|
89
|
+
runId?: string;
|
|
90
|
+
target?: string;
|
|
91
|
+
paths?: string[];
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface GeneratedFilesFreshness {
|
|
96
|
+
status: "fresh" | "stale" | "missing" | "unknown";
|
|
97
|
+
message: string;
|
|
98
|
+
refreshCommand: string;
|
|
99
|
+
verifyingCommands: string[];
|
|
100
|
+
targets?: {
|
|
101
|
+
target: string;
|
|
102
|
+
status: "fresh" | "stale" | "missing" | "unknown";
|
|
103
|
+
lastSyncedAt?: string;
|
|
104
|
+
runId?: string;
|
|
105
|
+
generatedFiles: string[];
|
|
106
|
+
reason: string;
|
|
107
|
+
}[];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface AkanDoctorResult {
|
|
111
|
+
schemaVersion: 1;
|
|
112
|
+
repoName: string;
|
|
113
|
+
root: string;
|
|
114
|
+
strict: boolean;
|
|
115
|
+
status: "passed" | "failed";
|
|
116
|
+
diagnostics: AkanDiagnostic[];
|
|
117
|
+
generatedFiles: string[];
|
|
118
|
+
generatedFilesFreshness: GeneratedFilesFreshness;
|
|
119
|
+
validationCommands: string[];
|
|
120
|
+
repairActions: RepairAction[];
|
|
121
|
+
baselineDiagnostics?: AkanDiagnostic[];
|
|
122
|
+
workflowDiagnostics?: AkanDiagnostic[];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export type JsonRpcRequest = {
|
|
126
|
+
jsonrpc?: "2.0";
|
|
127
|
+
id?: string | number | null;
|
|
128
|
+
method: string;
|
|
129
|
+
params?: Record<string, unknown>;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export type McpFraming = "content-length" | "newline";
|
|
133
|
+
export type AkanMcpMode = "readonly" | "plan" | "apply";
|
|
134
|
+
|
|
135
|
+
// Cursor and Claude Code read a JSON `mcpServers` map; Codex reads a TOML `[mcp_servers.<name>]` table.
|
|
136
|
+
export type AkanMcpInstallTarget = "cursor" | "claude" | "codex";
|
|
137
|
+
|
|
138
|
+
export type CursorMcpConfig = {
|
|
139
|
+
mcpServers?: Record<string, unknown>;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export const guidelineResourceUri = (name: string) => `akan://guidelines/${name}`;
|
|
143
|
+
|
|
144
|
+
const staticResourceList = [
|
|
145
|
+
{ uri: "akan://docs/framework", name: "Akan framework guide", mimeType: "text/markdown" },
|
|
146
|
+
{ uri: "akan://workspace/summary", name: "Workspace summary", mimeType: "application/json" },
|
|
147
|
+
{ uri: "akan://workspace/apps", name: "Workspace apps", mimeType: "application/json" },
|
|
148
|
+
{ uri: "akan://workspace/modules", name: "Workspace modules", mimeType: "application/json" },
|
|
149
|
+
];
|
|
150
|
+
|
|
151
|
+
export const buildResourceList = (guidelineNames: readonly string[]) => [
|
|
152
|
+
...staticResourceList,
|
|
153
|
+
...guidelineNames.map((name) => ({
|
|
154
|
+
uri: guidelineResourceUri(name),
|
|
155
|
+
name: `${name} guideline`,
|
|
156
|
+
mimeType: "text/markdown",
|
|
157
|
+
})),
|
|
158
|
+
];
|
|
159
|
+
|
|
160
|
+
export const cursorMcpConfigPath = ".cursor/mcp.json";
|
|
161
|
+
// Claude Code reads project-scoped MCP servers from `.mcp.json` at the workspace root.
|
|
162
|
+
export const claudeMcpConfigPath = ".mcp.json";
|
|
163
|
+
// Codex reads project-scoped config (trusted projects) from `.codex/config.toml`.
|
|
164
|
+
export const codexMcpConfigPath = ".codex/config.toml";
|
|
165
|
+
|
|
166
|
+
export const akanMcpInstallTargets: AkanMcpInstallTarget[] = ["cursor", "claude", "codex"];
|
|
167
|
+
|
|
168
|
+
export const akanMcpInstallConfigPaths: Record<AkanMcpInstallTarget, string> = {
|
|
169
|
+
cursor: cursorMcpConfigPath,
|
|
170
|
+
claude: claudeMcpConfigPath,
|
|
171
|
+
codex: codexMcpConfigPath,
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// `akan mcp` resolves the workspace from its cwd: Cursor expands ${workspaceFolder}, Claude Code only sets
|
|
175
|
+
// CLAUDE_PROJECT_DIR (its cwd is not guaranteed), and Codex runs from its own launch cwd.
|
|
176
|
+
const cursorWorkspaceFolder = "$" + "{workspaceFolder}";
|
|
177
|
+
const claudeProjectDir = "$CLAUDE_PROJECT_DIR";
|
|
178
|
+
|
|
179
|
+
const akanMcpCommand = (mode: AkanMcpMode, { cd }: { cd?: string } = {}) =>
|
|
180
|
+
cd ? `cd "${cd}" && akan mcp --mode ${mode}` : `akan mcp --mode ${mode}`;
|
|
181
|
+
|
|
182
|
+
const bashMcpServer = (mode: AkanMcpMode, cd: string) => ({
|
|
183
|
+
type: "stdio",
|
|
184
|
+
command: "bash",
|
|
185
|
+
args: ["-lc", akanMcpCommand(mode, { cd })],
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
export const createAkanCursorMcpServer = (mode: AkanMcpMode = "readonly") => bashMcpServer(mode, cursorWorkspaceFolder);
|
|
189
|
+
|
|
190
|
+
export const createAkanClaudeMcpServer = (mode: AkanMcpMode = "readonly") => bashMcpServer(mode, claudeProjectDir);
|
|
191
|
+
|
|
192
|
+
export const createAkanMcpServer = (target: "cursor" | "claude", mode: AkanMcpMode = "readonly") =>
|
|
193
|
+
target === "cursor" ? createAkanCursorMcpServer(mode) : createAkanClaudeMcpServer(mode);
|
|
194
|
+
|
|
195
|
+
export const akanCursorMcpServer = createAkanCursorMcpServer();
|
|
196
|
+
|
|
197
|
+
// No TOML serializer is bundled, so the `[mcp_servers.akan]` table is written as text.
|
|
198
|
+
export const codexMcpServerTableHeader = "[mcp_servers.akan]";
|
|
199
|
+
export const createAkanCodexMcpServerBlock = (mode: AkanMcpMode = "readonly") =>
|
|
200
|
+
`${codexMcpServerTableHeader}\ncommand = "bash"\nargs = ["-lc", "${akanMcpCommand(mode)}"]\n`;
|
|
201
|
+
|
|
202
|
+
// A TOML table runs from its header until the next top-level `[header]` or EOF.
|
|
203
|
+
const codexAkanTablePattern = /^\[mcp_servers\.akan\][^\n]*\n(?:(?!\[)[^\n]*(?:\n|$))*/m;
|
|
204
|
+
|
|
205
|
+
export const upsertCodexMcpServerBlock = (
|
|
206
|
+
existing: string,
|
|
207
|
+
block: string,
|
|
208
|
+
{ force = false }: { force?: boolean } = {},
|
|
209
|
+
) => {
|
|
210
|
+
const nextBlock = block.endsWith("\n") ? block : `${block}\n`;
|
|
211
|
+
const match = existing.match(codexAkanTablePattern);
|
|
212
|
+
if (!match) {
|
|
213
|
+
if (!existing.trim()) return nextBlock;
|
|
214
|
+
return `${existing.trimEnd()}\n\n${nextBlock}`;
|
|
215
|
+
}
|
|
216
|
+
if (match[0].trim() === nextBlock.trim()) return existing;
|
|
217
|
+
if (!force)
|
|
218
|
+
throw new Error(`${codexMcpConfigPath} already has an "akan" MCP server. Re-run with --force to overwrite it.`);
|
|
219
|
+
const start = match.index ?? 0;
|
|
220
|
+
const before = existing.slice(0, start);
|
|
221
|
+
const after = existing.slice(start + match[0].length);
|
|
222
|
+
// The matched table absorbed its trailing blank line, so re-insert one before any following table.
|
|
223
|
+
const separator = after && !after.startsWith("\n") ? "\n" : "";
|
|
224
|
+
return `${before}${nextBlock}${separator}${after}`;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
export const renderDoctorText = (result: AkanDoctorResult) => {
|
|
228
|
+
const lines = [`Akan doctor status: ${result.status}`];
|
|
229
|
+
if (result.diagnostics.length === 0) {
|
|
230
|
+
lines.push("", "No Akan workspace diagnostics found.");
|
|
231
|
+
} else {
|
|
232
|
+
lines.push(
|
|
233
|
+
"",
|
|
234
|
+
...result.diagnostics.map((diagnostic) =>
|
|
235
|
+
[
|
|
236
|
+
`[${diagnostic.severity}] ${diagnostic.code}: ${diagnostic.message}`,
|
|
237
|
+
diagnostic.path ? ` ${diagnostic.path}` : "",
|
|
238
|
+
]
|
|
239
|
+
.filter(Boolean)
|
|
240
|
+
.join("\n"),
|
|
241
|
+
),
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
lines.push(
|
|
245
|
+
"",
|
|
246
|
+
"Generated file freshness:",
|
|
247
|
+
`Status: ${result.generatedFilesFreshness.status}`,
|
|
248
|
+
result.generatedFilesFreshness.message,
|
|
249
|
+
`Refresh: ${result.generatedFilesFreshness.refreshCommand}`,
|
|
250
|
+
"",
|
|
251
|
+
"Repair actions:",
|
|
252
|
+
...(result.repairActions.length ? result.repairActions.map((action) => `- ${action.command}`) : ["- none"]),
|
|
253
|
+
"",
|
|
254
|
+
"Validation commands:",
|
|
255
|
+
...result.validationCommands.map((command) => `- ${command}`),
|
|
256
|
+
);
|
|
257
|
+
return `${lines.join("\n")}\n`;
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
export interface AkanContextOptions {
|
|
261
|
+
app?: string | null;
|
|
262
|
+
module?: string | null;
|
|
263
|
+
includeAbstractContent?: boolean;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const generatedFiles = [
|
|
267
|
+
"apps/*/client.ts",
|
|
268
|
+
"apps/*/server.ts",
|
|
269
|
+
"*/lib/cnst.ts",
|
|
270
|
+
"*/lib/db.ts",
|
|
271
|
+
"*/lib/dict.ts",
|
|
272
|
+
"*/lib/sig.ts",
|
|
273
|
+
"*/lib/srv.ts",
|
|
274
|
+
"*/lib/st.ts",
|
|
275
|
+
"*/lib/useClient.ts",
|
|
276
|
+
"*/lib/useServer.ts",
|
|
277
|
+
"*/lib/**/index.ts",
|
|
278
|
+
"*/ui/index.ts",
|
|
279
|
+
"*/webkit/index.ts",
|
|
280
|
+
"*/srvkit/index.ts",
|
|
281
|
+
"*/common/index.ts",
|
|
282
|
+
];
|
|
283
|
+
|
|
284
|
+
const validationCommands = [
|
|
285
|
+
"akan verify [<app-or-lib-or-pkg>]",
|
|
286
|
+
"akan sync <app-or-lib>",
|
|
287
|
+
"akan lint <app-or-lib-or-pkg>",
|
|
288
|
+
"akan typecheck <app-or-lib>",
|
|
289
|
+
"akan test <app-or-lib-or-pkg>",
|
|
290
|
+
"akan build <app-name>",
|
|
291
|
+
"akan doctor --strict --format json",
|
|
292
|
+
"akan quality scan [--format json]",
|
|
293
|
+
"akan quality ssr [--format json]",
|
|
294
|
+
];
|
|
295
|
+
|
|
296
|
+
const parseAbstractSummary = (
|
|
297
|
+
relativePath: string,
|
|
298
|
+
content: string | null,
|
|
299
|
+
includeContent: boolean,
|
|
300
|
+
): AkanAbstractSummary => {
|
|
301
|
+
if (content === null) return { path: relativePath, exists: false, headings: [] };
|
|
302
|
+
const headings = content
|
|
303
|
+
.split(/\r?\n/)
|
|
304
|
+
.map((line) => line.trim())
|
|
305
|
+
.filter((line) => line.startsWith("#"))
|
|
306
|
+
.map((line) => line.replace(/^#+\s*/, "").trim())
|
|
307
|
+
.filter(Boolean);
|
|
308
|
+
return {
|
|
309
|
+
path: relativePath,
|
|
310
|
+
exists: true,
|
|
311
|
+
title: headings[0],
|
|
312
|
+
headings: headings.slice(0, 8),
|
|
313
|
+
...(includeContent ? { content } : {}),
|
|
314
|
+
};
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
const readFiles = async (dirPath: string) =>
|
|
318
|
+
(await safeReadDir(dirPath))
|
|
319
|
+
.filter((entry) => entry.isFile())
|
|
320
|
+
.map((entry) => entry.name)
|
|
321
|
+
.sort();
|
|
322
|
+
|
|
323
|
+
const getRelative = (workspace: WorkspaceExecutor, absolutePath: string) =>
|
|
324
|
+
path.relative(workspace.workspaceRoot, absolutePath).replaceAll(path.sep, "/");
|
|
325
|
+
|
|
326
|
+
const createModuleContext = async (
|
|
327
|
+
workspace: WorkspaceExecutor,
|
|
328
|
+
sys: SysExecutor,
|
|
329
|
+
kind: AkanModuleKind,
|
|
330
|
+
folderName: string,
|
|
331
|
+
moduleName: string,
|
|
332
|
+
includeAbstractContent: boolean,
|
|
333
|
+
): Promise<AkanModuleContext> => {
|
|
334
|
+
const modulePath =
|
|
335
|
+
kind === "scalar"
|
|
336
|
+
? path.join(sys.cwdPath, "lib", "__scalar", moduleName)
|
|
337
|
+
: path.join(sys.cwdPath, "lib", folderName);
|
|
338
|
+
const relativePath = getRelative(workspace, modulePath);
|
|
339
|
+
const abstractPath = `${relativePath}/${moduleName}.abstract.md`;
|
|
340
|
+
const abstractContent = await safeReadText(path.join(workspace.workspaceRoot, abstractPath));
|
|
341
|
+
return {
|
|
342
|
+
kind,
|
|
343
|
+
name: moduleName,
|
|
344
|
+
folderName,
|
|
345
|
+
sysName: sys.name,
|
|
346
|
+
sysType: sys.type,
|
|
347
|
+
path: relativePath,
|
|
348
|
+
abstract: parseAbstractSummary(abstractPath, abstractContent, includeAbstractContent),
|
|
349
|
+
files: await readFiles(modulePath),
|
|
350
|
+
};
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
const getSysModules = async (
|
|
354
|
+
workspace: WorkspaceExecutor,
|
|
355
|
+
sys: SysExecutor,
|
|
356
|
+
{
|
|
357
|
+
includeAbstractContent = false,
|
|
358
|
+
module: moduleFilter,
|
|
359
|
+
}: { includeAbstractContent?: boolean; module?: string | null } = {},
|
|
360
|
+
) => {
|
|
361
|
+
const libPath = path.join(sys.cwdPath, "lib");
|
|
362
|
+
const entries = await safeReadDir(libPath);
|
|
363
|
+
const modules: AkanModuleContext[] = [];
|
|
364
|
+
for (const entry of entries) {
|
|
365
|
+
if (!entry.isDirectory()) continue;
|
|
366
|
+
if (entry.name === "__scalar") continue;
|
|
367
|
+
if (entry.name.startsWith("__")) continue;
|
|
368
|
+
if (entry.name.startsWith("_")) {
|
|
369
|
+
const serviceName = entry.name.replace(/^_+/, "");
|
|
370
|
+
if (moduleFilter && moduleFilter !== serviceName && moduleFilter !== entry.name) continue;
|
|
371
|
+
if (!(await FileSys.fileExists(path.join(libPath, entry.name, `${serviceName}.service.ts`)))) continue;
|
|
372
|
+
modules.push(
|
|
373
|
+
await createModuleContext(workspace, sys, "service", entry.name, serviceName, includeAbstractContent),
|
|
374
|
+
);
|
|
375
|
+
} else {
|
|
376
|
+
if (moduleFilter && moduleFilter !== entry.name) continue;
|
|
377
|
+
if (!(await FileSys.fileExists(path.join(libPath, entry.name, `${entry.name}.constant.ts`)))) continue;
|
|
378
|
+
modules.push(await createModuleContext(workspace, sys, "domain", entry.name, entry.name, includeAbstractContent));
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const scalarRoot = path.join(libPath, "__scalar");
|
|
383
|
+
for (const entry of await safeReadDir(scalarRoot)) {
|
|
384
|
+
if (!entry.isDirectory() || entry.name.startsWith("_")) continue;
|
|
385
|
+
if (moduleFilter && moduleFilter !== entry.name) continue;
|
|
386
|
+
if (!(await FileSys.fileExists(path.join(scalarRoot, entry.name, `${entry.name}.constant.ts`)))) continue;
|
|
387
|
+
modules.push(await createModuleContext(workspace, sys, "scalar", entry.name, entry.name, includeAbstractContent));
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
return modules.sort((a, b) => `${a.sysName}:${a.path}`.localeCompare(`${b.sysName}:${b.path}`));
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
const getAppRoutes = async (app: AppExecutor, workspaceRoot: string): Promise<AkanRouteContext[]> => {
|
|
394
|
+
const sources = await app.getRouteSources();
|
|
395
|
+
const guardedLayouts = new Set<string>();
|
|
396
|
+
const pages: { source: (typeof sources)[number]; parsed: ReturnType<typeof parseRouteModuleKey> }[] = [];
|
|
397
|
+
for (const source of sources) {
|
|
398
|
+
const parsed = parseRouteModuleKey(source.key);
|
|
399
|
+
if (parsed.kind === "layout" && source.info.chain?.guarded) guardedLayouts.add(parsed.routeSegments.join("/"));
|
|
400
|
+
else if (parsed.kind === "page") pages.push({ source, parsed });
|
|
401
|
+
}
|
|
402
|
+
return pages
|
|
403
|
+
.map(({ source, parsed }) => {
|
|
404
|
+
const segments = parsed.routeSegments;
|
|
405
|
+
//? The layouts that wrap a page, as the route seed index walks them: an `_index` sits inside its own folder.
|
|
406
|
+
const reach = parsed.leaf === "_index" ? segments.length : segments.length - 1;
|
|
407
|
+
const underGuard = Array.from({ length: reach + 1 }, (_, idx) => segments.slice(0, idx).join("/")).some(
|
|
408
|
+
(prefix) => guardedLayouts.has(prefix),
|
|
409
|
+
);
|
|
410
|
+
return {
|
|
411
|
+
path: parsed.pattern.replace(/^\/:lang/, "") || "/",
|
|
412
|
+
file: path.relative(workspaceRoot, source.absPath).replaceAll(path.sep, "/"),
|
|
413
|
+
search: source.info.chain?.search ?? [],
|
|
414
|
+
guarded: !!source.info.chain?.guarded || underGuard,
|
|
415
|
+
devOnly: source.info.devOnly,
|
|
416
|
+
};
|
|
417
|
+
})
|
|
418
|
+
.sort((a, b) => a.path.localeCompare(b.path));
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
const getSysContext = async (
|
|
422
|
+
workspace: WorkspaceExecutor,
|
|
423
|
+
type: "app" | "lib",
|
|
424
|
+
name: string,
|
|
425
|
+
options: AkanContextOptions,
|
|
426
|
+
): Promise<AkanSysContext> => {
|
|
427
|
+
const sys = type === "app" ? AppExecutor.from(workspace, name) : LibExecutor.from(workspace, name);
|
|
428
|
+
const context: AkanSysContext = {
|
|
429
|
+
type,
|
|
430
|
+
name,
|
|
431
|
+
path: `${type}s/${name}`,
|
|
432
|
+
hasConfig: await FileSys.fileExists(path.join(sys.cwdPath, "akan.config.ts")),
|
|
433
|
+
modules: await getSysModules(workspace, sys, {
|
|
434
|
+
includeAbstractContent: options.includeAbstractContent,
|
|
435
|
+
module: options.module,
|
|
436
|
+
}),
|
|
437
|
+
};
|
|
438
|
+
if (sys instanceof AppExecutor && options.app === name)
|
|
439
|
+
await getAppRoutes(sys, workspace.workspaceRoot).then(
|
|
440
|
+
(routes) => (context.routes = routes),
|
|
441
|
+
(error: unknown) => (context.routeError = error instanceof Error ? error.message : String(error)),
|
|
442
|
+
);
|
|
443
|
+
return context;
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
export class AkanContextAnalyzer {
|
|
447
|
+
static async analyze(workspace: WorkspaceExecutor, options: AkanContextOptions = {}): Promise<AkanWorkspaceContext> {
|
|
448
|
+
const [appNames, libNames, pkgNames] = await workspace.getExecs();
|
|
449
|
+
const rootPackageJson = await safeReadJson<PackageJson>(path.join(workspace.workspaceRoot, "package.json"));
|
|
450
|
+
const filteredApps = options.app ? appNames.filter((name) => name === options.app) : appNames;
|
|
451
|
+
const [apps, libs, pkgs] = await Promise.all([
|
|
452
|
+
Promise.all(filteredApps.map((name) => getSysContext(workspace, "app", name, options))),
|
|
453
|
+
Promise.all(libNames.map((name) => getSysContext(workspace, "lib", name, options))),
|
|
454
|
+
Promise.all(
|
|
455
|
+
pkgNames.map(async (name) => {
|
|
456
|
+
const packageJson = await safeReadJson<PackageJson>(
|
|
457
|
+
path.join(workspace.workspaceRoot, "pkgs", name, "package.json"),
|
|
458
|
+
);
|
|
459
|
+
return {
|
|
460
|
+
name,
|
|
461
|
+
path: `pkgs/${name}`,
|
|
462
|
+
...(packageJson?.version ? { version: packageJson.version } : {}),
|
|
463
|
+
};
|
|
464
|
+
}),
|
|
465
|
+
),
|
|
466
|
+
]);
|
|
467
|
+
|
|
468
|
+
return {
|
|
469
|
+
schemaVersion: 1,
|
|
470
|
+
repoName: workspace.repoName,
|
|
471
|
+
root: workspace.workspaceRoot,
|
|
472
|
+
packageVersion: rootPackageJson?.dependencies?.akanjs ?? rootPackageJson?.devDependencies?.["@akanjs/devkit"],
|
|
473
|
+
apps,
|
|
474
|
+
libs,
|
|
475
|
+
pkgs,
|
|
476
|
+
generatedFiles,
|
|
477
|
+
validationCommands,
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
static async doctor(
|
|
482
|
+
workspace: WorkspaceExecutor,
|
|
483
|
+
{
|
|
484
|
+
strict = false,
|
|
485
|
+
runIdOrPlan = null,
|
|
486
|
+
changedFiles = [],
|
|
487
|
+
}: { strict?: boolean; runIdOrPlan?: string | null; changedFiles?: string[] } = {},
|
|
488
|
+
): Promise<AkanDoctorResult> {
|
|
489
|
+
const context = await AkanContextAnalyzer.analyze(workspace);
|
|
490
|
+
const workflowPaths = await loadWorkflowContextPaths(workspace, runIdOrPlan, changedFiles);
|
|
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 });
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
static findModules(
|
|
503
|
+
context: AkanWorkspaceContext,
|
|
504
|
+
moduleName?: string | null,
|
|
505
|
+
{ app = null }: { app?: string | null } = {},
|
|
506
|
+
) {
|
|
507
|
+
const modules = [...context.apps, ...context.libs]
|
|
508
|
+
.filter((sys) => !app || sys.name === app)
|
|
509
|
+
.flatMap((sys) => sys.modules);
|
|
510
|
+
return moduleName
|
|
511
|
+
? modules.filter((module) => module.name === moduleName || module.folderName === moduleName)
|
|
512
|
+
: modules;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
static renderMarkdown(context: AkanWorkspaceContext, { module: moduleName }: { module?: string | null } = {}) {
|
|
516
|
+
const lines = [`# Akan Workspace Context`, "", `- Repo: ${context.repoName}`, `- Root: ${context.root}`];
|
|
517
|
+
if (context.packageVersion) lines.push(`- Akan version: ${context.packageVersion}`);
|
|
518
|
+
lines.push("", "## Apps", ...context.apps.map((app) => `- ${app.name}: ${app.modules.length} module(s)`));
|
|
519
|
+
lines.push("", "## Libraries", ...context.libs.map((lib) => `- ${lib.name}: ${lib.modules.length} module(s)`));
|
|
520
|
+
lines.push(
|
|
521
|
+
"",
|
|
522
|
+
"## Packages",
|
|
523
|
+
...context.pkgs.map((pkg) => `- ${pkg.name}${pkg.version ? ` (${pkg.version})` : ""}`),
|
|
524
|
+
);
|
|
525
|
+
|
|
526
|
+
for (const app of context.apps) {
|
|
527
|
+
if (app.routeError) lines.push("", `## Routes: ${app.name}`, `- Not read: ${app.routeError}`);
|
|
528
|
+
else if (app.routes)
|
|
529
|
+
lines.push("", `## Routes: ${app.name}`, ...AkanContextAnalyzer.#routeLines(app.name, app.routes));
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
const modules = AkanContextAnalyzer.findModules(context, moduleName);
|
|
533
|
+
lines.push("", "## Modules");
|
|
534
|
+
for (const module of modules) {
|
|
535
|
+
lines.push("", `### ${module.sysName}:${module.name} (${module.kind})`, `- Path: ${module.path}`);
|
|
536
|
+
lines.push(`- Abstract: ${module.abstract.exists ? module.abstract.path : "missing"}`);
|
|
537
|
+
if (module.abstract.exists && module.abstract.content) lines.push("", module.abstract.content.trim(), "");
|
|
538
|
+
else if (module.abstract.headings.length)
|
|
539
|
+
lines.push(`- Abstract headings: ${module.abstract.headings.join(", ")}`);
|
|
540
|
+
lines.push(`- Files: ${module.files.join(", ") || "none"}`);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
lines.push("", "## Validation", ...context.validationCommands.map((command) => `- \`${command}\``));
|
|
544
|
+
return `${lines.join("\n")}\n`;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
static readonly routeListLimit = 60;
|
|
548
|
+
|
|
549
|
+
//? Past the limit the biggest top folders fold into one line each: a docs section alone would fill the context.
|
|
550
|
+
static #routeLines(appName: string, routes: AkanRouteContext[]) {
|
|
551
|
+
const folderOf = (route: AkanRouteContext) => route.file.split("/").slice(0, 4).join("/");
|
|
552
|
+
const groups = Map.groupBy(routes, folderOf);
|
|
553
|
+
const folded = new Set<string>();
|
|
554
|
+
let listed = routes.length;
|
|
555
|
+
for (const [folder, members] of [...groups].sort((a, b) => b[1].length - a[1].length)) {
|
|
556
|
+
if (listed <= AkanContextAnalyzer.routeListLimit) break;
|
|
557
|
+
folded.add(folder);
|
|
558
|
+
listed -= members.length;
|
|
559
|
+
}
|
|
560
|
+
const lines = [`Paths omit the \`/:lang\` prefix; \`akan preview ${appName} <path>\` opens one.`];
|
|
561
|
+
for (const route of routes) {
|
|
562
|
+
if (folded.has(folderOf(route))) continue;
|
|
563
|
+
const search = route.search.length ? ` ?${route.search.join("&")}` : "";
|
|
564
|
+
const marks = `${route.guarded ? " (guarded)" : ""}${route.devOnly ? " (dev only)" : ""}`;
|
|
565
|
+
lines.push(`- ${route.path}${search}${marks} — ${route.file}`);
|
|
566
|
+
}
|
|
567
|
+
for (const folder of folded) {
|
|
568
|
+
const members = groups.get(folder) ?? [];
|
|
569
|
+
const examples = members.slice(0, 3).map((route) => route.path);
|
|
570
|
+
lines.push(
|
|
571
|
+
`- ${folder}/: ${members.length} routes folded (${examples.join(", ")}, …); \`--format json\` lists every route`,
|
|
572
|
+
);
|
|
573
|
+
}
|
|
574
|
+
return lines;
|
|
575
|
+
}
|
|
576
|
+
}
|