@akanjs/devkit 3.2.0-rc.17 → 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 +74 -5
- 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/app/routeSourceValidator.test.ts +17 -0
- package/app/routeSourceValidator.ts +5 -1
- package/artifact/implicitRootLayout.test.ts +67 -3
- package/artifact/implicitRootLayout.ts +9 -4
- package/artifact/implicitRootLayoutRender.test.tsx +297 -0
- 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 +28 -4
- package/executors/workspaceExecutor.ts +1 -2
- package/frontendBuild/devGeneratedIndexSync.ts +5 -36
- package/frontendBuild/hmrWatcher.stop.test.ts +36 -0
- package/frontendBuild/hmrWatcher.ts +2 -0
- package/frontendBuild/optionalPeers.test.ts +35 -7
- 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
- package/workspace/workspaceLayout.ts +3 -1
package/workflow/sourceAst.ts
CHANGED
|
@@ -10,3 +10,33 @@ export const {
|
|
|
10
10
|
firstObjectReturnedByArrow,
|
|
11
11
|
heritageCall,
|
|
12
12
|
} = createAst(ts);
|
|
13
|
+
|
|
14
|
+
export const hasParseDiagnostics = (source: ts.SourceFile) =>
|
|
15
|
+
((source as ts.SourceFile & { parseDiagnostics?: readonly ts.Diagnostic[] }).parseDiagnostics ?? []).length > 0;
|
|
16
|
+
|
|
17
|
+
export const hasSourceParseErrors = (content: string, fileName = "source.ts") =>
|
|
18
|
+
hasParseDiagnostics(sourceFileFor(fileName, content));
|
|
19
|
+
|
|
20
|
+
export const findClassDeclaration = (source: ts.SourceFile, className: string): ts.ClassDeclaration | null => {
|
|
21
|
+
let found: ts.ClassDeclaration | null = null;
|
|
22
|
+
const visit = (node: ts.Node) => {
|
|
23
|
+
if (found) return;
|
|
24
|
+
if (ts.isClassDeclaration(node) && node.name?.text === className) {
|
|
25
|
+
found = node;
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
ts.forEachChild(node, visit);
|
|
29
|
+
};
|
|
30
|
+
ts.forEachChild(source, visit);
|
|
31
|
+
return found;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const firstHeritageCall = (node: ts.ClassDeclaration): ts.CallExpression | null => {
|
|
35
|
+
const expression = (node.heritageClauses?.flatMap((clause) => [...clause.types]) ?? [])[0]?.expression;
|
|
36
|
+
return expression && ts.isCallExpression(expression) ? expression : null;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const factoryArrowOf = (call: ts.CallExpression): ts.ArrowFunction | ts.FunctionExpression | null => {
|
|
40
|
+
const arg = call.arguments.find((argument) => ts.isArrowFunction(argument) || ts.isFunctionExpression(argument));
|
|
41
|
+
return arg && (ts.isArrowFunction(arg) || ts.isFunctionExpression(arg)) ? arg : null;
|
|
42
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { sourceFileFor } from "./sourceAst";
|
|
3
|
+
import { lineEndAt, lineStartAt, spliceText } from "./sourceText";
|
|
4
|
+
|
|
5
|
+
//? Biome's organizeImports order: case-insensitive, an uppercase name before its lowercase twin.
|
|
6
|
+
const importOrder = (a: string, b: string) => {
|
|
7
|
+
const [lowerA, lowerB] = [a.toLowerCase(), b.toLowerCase()];
|
|
8
|
+
if (lowerA !== lowerB) return lowerA < lowerB ? -1 : 1;
|
|
9
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const ensureNamedImport = (content: string, moduleSpecifier: string, name: string) => {
|
|
13
|
+
const source = sourceFileFor("source.ts", content);
|
|
14
|
+
const namedImport = findNamedImport(source, moduleSpecifier, { valueOnly: true });
|
|
15
|
+
if (!namedImport) return ensureImportDeclaration(content, moduleSpecifier, `{ ${name} }`);
|
|
16
|
+
if (namedImport.names.includes(name)) return content;
|
|
17
|
+
const nextElements = [...namedImport.elements, { name, text: name }].sort((a, b) => importOrder(a.name, b.name));
|
|
18
|
+
return spliceText(
|
|
19
|
+
content,
|
|
20
|
+
namedImport.namedBindingsStart,
|
|
21
|
+
namedImport.namedBindingsEnd,
|
|
22
|
+
`{ ${nextElements.map((element) => element.text).join(", ")} }`,
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const ensureImportDeclaration = (content: string, moduleSpecifier: string, clause: string) => {
|
|
27
|
+
const line = `import ${clause} from "${moduleSpecifier}";`;
|
|
28
|
+
if (content.includes(line)) return content;
|
|
29
|
+
const source = sourceFileFor("source.ts", content);
|
|
30
|
+
const imports = source.statements
|
|
31
|
+
.filter((statement): statement is ts.ImportDeclaration => ts.isImportDeclaration(statement))
|
|
32
|
+
.flatMap((statement) =>
|
|
33
|
+
ts.isStringLiteral(statement.moduleSpecifier)
|
|
34
|
+
? [{ specifier: statement.moduleSpecifier.text, start: statement.getStart(source), end: statement.getEnd() }]
|
|
35
|
+
: [],
|
|
36
|
+
);
|
|
37
|
+
const isRelative = (specifier: string) => specifier.startsWith(".");
|
|
38
|
+
const peers = imports.filter((entry) => isRelative(entry.specifier) === isRelative(moduleSpecifier));
|
|
39
|
+
const before = peers.find((entry) => importOrder(entry.specifier, moduleSpecifier) > 0);
|
|
40
|
+
if (before) {
|
|
41
|
+
const insertAt = lineStartAt(content, before.start);
|
|
42
|
+
return spliceText(content, insertAt, insertAt, `${line}\n`);
|
|
43
|
+
}
|
|
44
|
+
const after = peers.at(-1) ?? (isRelative(moduleSpecifier) ? imports.at(-1) : undefined);
|
|
45
|
+
if (after) {
|
|
46
|
+
const insertAt = lineEndAt(content, after.end);
|
|
47
|
+
return spliceText(content, insertAt, insertAt, peers.length ? `${line}\n` : `\n${line}\n`);
|
|
48
|
+
}
|
|
49
|
+
const insertAt = imports[0] ? lineStartAt(content, imports[0].start) : 0;
|
|
50
|
+
return spliceText(content, insertAt, insertAt, `${line}\n\n`);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const ensureBaseImport = (content: string, name: string) => ensureNamedImport(content, "akanjs/base", name);
|
|
54
|
+
|
|
55
|
+
interface NamedImportLocator {
|
|
56
|
+
names: string[];
|
|
57
|
+
elements: { name: string; text: string }[];
|
|
58
|
+
namedBindingsStart: number;
|
|
59
|
+
namedBindingsEnd: number;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const findNamedImport = (
|
|
63
|
+
source: ts.SourceFile,
|
|
64
|
+
moduleSpecifier: string,
|
|
65
|
+
{ valueOnly = false }: { valueOnly?: boolean } = {},
|
|
66
|
+
): NamedImportLocator | null => {
|
|
67
|
+
for (const statement of source.statements) {
|
|
68
|
+
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) continue;
|
|
69
|
+
if (statement.moduleSpecifier.text !== moduleSpecifier) continue;
|
|
70
|
+
if (valueOnly && statement.importClause?.isTypeOnly) continue;
|
|
71
|
+
const namedBindings = statement.importClause?.namedBindings;
|
|
72
|
+
if (!namedBindings || !ts.isNamedImports(namedBindings)) continue;
|
|
73
|
+
return {
|
|
74
|
+
names: namedBindings.elements.map((element) => element.name.text),
|
|
75
|
+
elements: namedBindings.elements.map((element) => ({ name: element.name.text, text: element.getText(source) })),
|
|
76
|
+
namedBindingsStart: namedBindings.getStart(source),
|
|
77
|
+
namedBindingsEnd: namedBindings.getEnd(),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export const ensureEnumImport = (content: string) => {
|
|
84
|
+
if (content.includes("enumOf")) return content;
|
|
85
|
+
const baseImport = /import \{ ([^{}]+) \} from "akanjs\/base";/.exec(content);
|
|
86
|
+
if (baseImport) {
|
|
87
|
+
const names = baseImport[1]?.split(",").map((name) => name.trim()) ?? [];
|
|
88
|
+
return content.replace(baseImport[0], `import { ${[...names, "enumOf"].sort().join(", ")} } from "akanjs/base";`);
|
|
89
|
+
}
|
|
90
|
+
return `import { enumOf } from "akanjs/base";\n${content}`;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export const ensureConstantTypeImport = (content: string, constantPath: string, typeName: string) => {
|
|
94
|
+
if (new RegExp(`import type \\{[^}]*\\b${typeName}\\b[^}]*\\} from "${constantPath}";`).test(content)) return content;
|
|
95
|
+
const importPattern = new RegExp(`import type \\{ ([^}]+) \\} from "${constantPath}";`);
|
|
96
|
+
const existingImport = content.match(importPattern);
|
|
97
|
+
if (existingImport !== null) {
|
|
98
|
+
const names = existingImport[1]?.split(",").map((name) => name.trim()) ?? [];
|
|
99
|
+
return content.replace(
|
|
100
|
+
existingImport[0],
|
|
101
|
+
`import type { ${[...names, typeName].sort().join(", ")} } from "${constantPath}";`,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
return `import type { ${typeName} } from "${constantPath}";\n${content}`;
|
|
105
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const spliceText = (content: string, start: number, end: number, replacement: string) =>
|
|
2
|
+
`${content.slice(0, start)}${replacement}${content.slice(end)}`;
|
|
3
|
+
|
|
4
|
+
export const lineStartAt = (content: string, position: number) =>
|
|
5
|
+
content.lastIndexOf("\n", Math.max(0, position - 1)) + 1;
|
|
6
|
+
|
|
7
|
+
export const lineEndAt = (content: string, position: number) => {
|
|
8
|
+
const end = content.indexOf("\n", position);
|
|
9
|
+
return end < 0 ? content.length : end + 1;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const lineIndentAt = (content: string, position: number) =>
|
|
13
|
+
/^[ \t]*/.exec(content.slice(lineStartAt(content, position)))?.[0] ?? "";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { moduleComponentName } from "./modulePaths";
|
|
2
|
+
|
|
3
|
+
export const insertTemplateField = ({
|
|
4
|
+
content,
|
|
5
|
+
moduleName,
|
|
6
|
+
moduleClassName,
|
|
7
|
+
fieldName,
|
|
8
|
+
component,
|
|
9
|
+
}: {
|
|
10
|
+
content: string;
|
|
11
|
+
moduleName: string;
|
|
12
|
+
moduleClassName: string;
|
|
13
|
+
fieldName: string;
|
|
14
|
+
component: "Field.Text" | "Field.Number" | "Field.Date";
|
|
15
|
+
}) => {
|
|
16
|
+
if (content.includes(`l("${moduleName}.${fieldName}")`) || content.includes(`.${fieldName}`)) return content;
|
|
17
|
+
const layoutEndIndex = content.indexOf(" </Layout.Template>");
|
|
18
|
+
if (layoutEndIndex < 0) return null;
|
|
19
|
+
const formName = `${moduleName}Form`;
|
|
20
|
+
if (!content.includes(`const ${formName} = st.use.${moduleName}Form();`)) return null;
|
|
21
|
+
const fieldSetter = `st.do.set${moduleComponentName(fieldName)}On${moduleClassName}`;
|
|
22
|
+
const fieldBlock = ` <${component}
|
|
23
|
+
label={l("${moduleName}.${fieldName}")}
|
|
24
|
+
desc={l("${moduleName}.${fieldName}.desc")}
|
|
25
|
+
value={${formName}.${fieldName}}
|
|
26
|
+
onChange={${fieldSetter}}
|
|
27
|
+
/>
|
|
28
|
+
`;
|
|
29
|
+
return `${content.slice(0, layoutEndIndex)}${fieldBlock}${content.slice(layoutEndIndex)}`;
|
|
30
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { expressionName, factoryArrowOf, sourceFileFor } from "./sourceAst";
|
|
3
|
+
import { ensureNamedImport, findNamedImport } from "./sourceImports";
|
|
4
|
+
import { lineIndentAt, lineStartAt, spliceText } from "./sourceText";
|
|
5
|
+
|
|
6
|
+
export const appendTopLevelTestCases = (
|
|
7
|
+
content: string,
|
|
8
|
+
describeTitle: string,
|
|
9
|
+
render: (itName: string, indent: string) => string[],
|
|
10
|
+
) => {
|
|
11
|
+
const bunImport = findNamedImport(sourceFileFor("test.ts", content), "bun:test", { valueOnly: true });
|
|
12
|
+
const itName = !bunImport?.names.includes("it") && bunImport?.names.includes("test") ? "test" : "it";
|
|
13
|
+
const imported = ensureNamedImport(content, "bun:test", itName);
|
|
14
|
+
const source = sourceFileFor("test.ts", imported);
|
|
15
|
+
const body = source.statements.flatMap((statement) => {
|
|
16
|
+
if (!ts.isExpressionStatement(statement) || !ts.isCallExpression(statement.expression)) return [];
|
|
17
|
+
if (expressionName(statement.expression.expression) !== "describe") return [];
|
|
18
|
+
const callback = factoryArrowOf(statement.expression);
|
|
19
|
+
return callback && ts.isBlock(callback.body) ? [callback.body] : [];
|
|
20
|
+
})[0];
|
|
21
|
+
if (!body) {
|
|
22
|
+
const block = [`describe(${JSON.stringify(describeTitle)}, () => {`, ...render(itName, " "), "});", ""];
|
|
23
|
+
return `${ensureNamedImport(imported, "bun:test", "describe").trimEnd()}\n\n${block.join("\n")}`;
|
|
24
|
+
}
|
|
25
|
+
const firstStatement = body.statements[0];
|
|
26
|
+
const indent = firstStatement
|
|
27
|
+
? lineIndentAt(imported, firstStatement.getStart(source))
|
|
28
|
+
: `${lineIndentAt(imported, body.getStart(source))} `;
|
|
29
|
+
const insertAt = lineStartAt(imported, body.getEnd() - 1);
|
|
30
|
+
return spliceText(imported, insertAt, insertAt, `${render(itName, indent).join("\n")}\n`);
|
|
31
|
+
};
|
package/workflow/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Sys, Workspace } from "../commandDecorators";
|
|
2
|
-
import type { FieldDefaultValue } from "./
|
|
2
|
+
import type { FieldDefaultValue } from "./fieldExpression";
|
|
3
3
|
|
|
4
4
|
export type WorkflowInputType = "string" | "string-list" | "surface-mode" | "boolean";
|
|
5
5
|
export type WorkflowSurfaceMode = "infer" | "include" | "skip";
|
package/workflow/uiPolicy.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// The one source of the app/lib root allowlists (sync, doctor and quality scan read it); mirror a change into the
|
|
2
2
|
// root AGENTS.md list.
|
|
3
3
|
|
|
4
|
+
import { barrelFacetDirs } from "akanjs/common";
|
|
5
|
+
|
|
4
6
|
export type SysType = "app" | "lib";
|
|
5
7
|
|
|
6
8
|
export const appRootAllowedFiles = new Set([
|
|
@@ -98,7 +100,7 @@ export const moduleTestHint =
|
|
|
98
100
|
"a module test is named after the one module file it covers (<model>.<role>.test.ts); add a describe block to " +
|
|
99
101
|
"that file's suite instead, or move a suite that drives several modules into srvkit/";
|
|
100
102
|
|
|
101
|
-
export
|
|
103
|
+
export { barrelFacetDirs };
|
|
102
104
|
|
|
103
105
|
//* Bun resolves a folder import to `index.tsx`, `index.jsx` or `index.mts` ahead of `index.ts`, and TypeScript to
|
|
104
106
|
//* `index.ts` first, so one of these beside the generated barrel typechecks every name the barrel adds and serves none.
|