@kernlang/core 3.1.5 → 3.1.6
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/LICENSE +17 -0
- package/README.md +5 -2
- package/dist/codegen/data-layer.d.ts +12 -0
- package/dist/codegen/data-layer.js +292 -0
- package/dist/codegen/data-layer.js.map +1 -0
- package/dist/codegen/events.d.ts +9 -0
- package/dist/codegen/events.js +158 -0
- package/dist/codegen/events.js.map +1 -0
- package/dist/codegen/functions.d.ts +8 -0
- package/dist/codegen/functions.js +147 -0
- package/dist/codegen/functions.js.map +1 -0
- package/dist/codegen/ground-layer.d.ts +22 -0
- package/dist/codegen/ground-layer.js +317 -0
- package/dist/codegen/ground-layer.js.map +1 -0
- package/dist/codegen/machines.d.ts +9 -0
- package/dist/codegen/machines.js +127 -0
- package/dist/codegen/machines.js.map +1 -0
- package/dist/codegen/modules.d.ts +10 -0
- package/dist/codegen/modules.js +40 -0
- package/dist/codegen/modules.js.map +1 -0
- package/dist/codegen/semantic-types.d.ts +14 -0
- package/dist/codegen/semantic-types.js +31 -0
- package/dist/codegen/semantic-types.js.map +1 -0
- package/dist/codegen/test-gen.d.ts +7 -0
- package/dist/codegen/test-gen.js +56 -0
- package/dist/codegen/test-gen.js.map +1 -0
- package/dist/codegen/type-system.d.ts +11 -0
- package/dist/codegen/type-system.js +162 -0
- package/dist/codegen/type-system.js.map +1 -0
- package/dist/codegen-core.d.ts +26 -33
- package/dist/codegen-core.js +58 -1367
- package/dist/codegen-core.js.map +1 -1
- package/dist/config.d.ts +20 -1
- package/dist/config.js +23 -3
- package/dist/config.js.map +1 -1
- package/dist/coverage-gap.js +6 -2
- package/dist/coverage-gap.js.map +1 -1
- package/dist/decompiler.d.ts +9 -0
- package/dist/decompiler.js +17 -2
- package/dist/decompiler.js.map +1 -1
- package/dist/errors.d.ts +5 -0
- package/dist/errors.js +10 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +11 -4
- package/dist/index.js +9 -3
- package/dist/index.js.map +1 -1
- package/dist/node-props.d.ts +253 -0
- package/dist/node-props.js +35 -0
- package/dist/node-props.js.map +1 -0
- package/dist/parser-core.d.ts +5 -0
- package/dist/parser-core.js +363 -0
- package/dist/parser-core.js.map +1 -0
- package/dist/parser-diagnostics.d.ts +14 -0
- package/dist/parser-diagnostics.js +31 -0
- package/dist/parser-diagnostics.js.map +1 -0
- package/dist/parser-keywords.d.ts +5 -0
- package/dist/parser-keywords.js +135 -0
- package/dist/parser-keywords.js.map +1 -0
- package/dist/parser-style.d.ts +3 -0
- package/dist/parser-style.js +73 -0
- package/dist/parser-style.js.map +1 -0
- package/dist/parser-token-stream.d.ts +27 -0
- package/dist/parser-token-stream.js +69 -0
- package/dist/parser-token-stream.js.map +1 -0
- package/dist/parser-tokenizer.d.ts +11 -0
- package/dist/parser-tokenizer.js +188 -0
- package/dist/parser-tokenizer.js.map +1 -0
- package/dist/parser.d.ts +59 -12
- package/dist/parser.js +51 -862
- package/dist/parser.js.map +1 -1
- package/dist/schema.d.ts +7 -2
- package/dist/schema.js +7 -2
- package/dist/schema.js.map +1 -1
- package/dist/source-map.d.ts +27 -0
- package/dist/source-map.js +82 -0
- package/dist/source-map.js.map +1 -0
- package/dist/spec.d.ts +1 -1
- package/dist/spec.js +2 -0
- package/dist/spec.js.map +1 -1
- package/dist/styles-tailwind.d.ts +10 -0
- package/dist/styles-tailwind.js +10 -0
- package/dist/styles-tailwind.js.map +1 -1
- package/dist/template-engine.d.ts +10 -5
- package/dist/template-engine.js +10 -5
- package/dist/template-engine.js.map +1 -1
- package/dist/types.d.ts +8 -3
- package/dist/utils.d.ts +20 -0
- package/dist/utils.js +20 -0
- package/dist/utils.js.map +1 -1
- package/dist/walk.d.ts +40 -0
- package/dist/walk.js +107 -0
- package/dist/walk.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function & Error Generators — fn, error.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from codegen-core.ts for modular codegen architecture.
|
|
5
|
+
*/
|
|
6
|
+
import { propsOf } from '../node-props.js';
|
|
7
|
+
import { emitIdentifier, emitTypeAnnotation } from './emitters.js';
|
|
8
|
+
import { getProps, getChildren, getFirstChild, dedent, handlerCode, exportPrefix, parseParamList } from './helpers.js';
|
|
9
|
+
const p = getProps;
|
|
10
|
+
const kids = getChildren;
|
|
11
|
+
const firstChild = getFirstChild;
|
|
12
|
+
// ── Function ─────────────────────────────────────────────────────────────
|
|
13
|
+
export function generateFunction(node) {
|
|
14
|
+
const props = propsOf(node);
|
|
15
|
+
const name = emitIdentifier(props.name, 'unknownFn', node);
|
|
16
|
+
const params = props.params || '';
|
|
17
|
+
const returns = props.returns;
|
|
18
|
+
const isAsync = props.async === 'true' || props.async === true;
|
|
19
|
+
const isStream = props.stream === 'true' || props.stream === true;
|
|
20
|
+
const exp = exportPrefix(node);
|
|
21
|
+
const lines = [];
|
|
22
|
+
// Parse params: "action:PlanAction,ws:WorkspaceSnapshot,spread:number=8"
|
|
23
|
+
// → "action: PlanAction, ws: WorkspaceSnapshot, spread: number = 8"
|
|
24
|
+
const paramList = params ? parseParamList(params) : '';
|
|
25
|
+
// stream=true → async generator function
|
|
26
|
+
if (isStream) {
|
|
27
|
+
const yieldType = emitTypeAnnotation(returns, 'unknown', node);
|
|
28
|
+
const retClause = `: AsyncGenerator<${yieldType}>`;
|
|
29
|
+
const code = handlerCode(node);
|
|
30
|
+
lines.push(`${exp}async function* ${name}(${paramList})${retClause} {`);
|
|
31
|
+
if (code) {
|
|
32
|
+
for (const line of code.split('\n')) {
|
|
33
|
+
lines.push(` ${line}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
lines.push('}');
|
|
37
|
+
return lines;
|
|
38
|
+
}
|
|
39
|
+
const retClause = returns ? `: ${emitTypeAnnotation(returns, 'unknown', node)}` : '';
|
|
40
|
+
const asyncKw = isAsync ? 'async ' : '';
|
|
41
|
+
const code = handlerCode(node);
|
|
42
|
+
// Gap 3: signal + cleanup support for async functions
|
|
43
|
+
const signalNode = firstChild(node, 'signal');
|
|
44
|
+
const cleanupNode = firstChild(node, 'cleanup');
|
|
45
|
+
const hasSignal = !!signalNode;
|
|
46
|
+
const hasCleanup = !!cleanupNode;
|
|
47
|
+
lines.push(`${exp}${asyncKw}function ${name}(${paramList})${retClause} {`);
|
|
48
|
+
// Signal → AbortController setup
|
|
49
|
+
if (hasSignal) {
|
|
50
|
+
const signalName = emitIdentifier(p(signalNode).name, 'abort', signalNode);
|
|
51
|
+
lines.push(` const ${signalName} = new AbortController();`);
|
|
52
|
+
}
|
|
53
|
+
// Wrap body in try/finally if cleanup exists
|
|
54
|
+
if (hasCleanup) {
|
|
55
|
+
lines.push(' try {');
|
|
56
|
+
if (code) {
|
|
57
|
+
for (const line of code.split('\n')) {
|
|
58
|
+
lines.push(` ${line}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
lines.push(' } finally {');
|
|
62
|
+
const cleanupCode = p(cleanupNode).code || '';
|
|
63
|
+
if (cleanupCode) {
|
|
64
|
+
const dedented = dedent(cleanupCode);
|
|
65
|
+
for (const line of dedented.split('\n')) {
|
|
66
|
+
lines.push(` ${line}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
lines.push(' }');
|
|
70
|
+
}
|
|
71
|
+
else if (code) {
|
|
72
|
+
for (const line of code.split('\n')) {
|
|
73
|
+
lines.push(` ${line}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
lines.push('}');
|
|
77
|
+
return lines;
|
|
78
|
+
}
|
|
79
|
+
// ── Error Class ──────────────────────────────────────────────────────────
|
|
80
|
+
export function generateError(node) {
|
|
81
|
+
const props = propsOf(node);
|
|
82
|
+
const name = emitIdentifier(props.name, 'UnknownError', node);
|
|
83
|
+
const ext = emitIdentifier(props.extends, 'Error', node);
|
|
84
|
+
const message = props.message;
|
|
85
|
+
const exp = exportPrefix(node);
|
|
86
|
+
const fields = kids(node, 'field');
|
|
87
|
+
const lines = [];
|
|
88
|
+
lines.push(`${exp}class ${name} extends ${ext} {`);
|
|
89
|
+
const code = handlerCode(node);
|
|
90
|
+
if (fields.length > 0) {
|
|
91
|
+
lines.push(` constructor(`);
|
|
92
|
+
// Check if first field is 'message' — special case: pass to super
|
|
93
|
+
const hasMessageParam = propsOf(fields[0]).name === 'message';
|
|
94
|
+
for (const field of fields) {
|
|
95
|
+
const fp = propsOf(field);
|
|
96
|
+
const opt = fp.optional === 'true' || fp.optional === true ? '?' : '';
|
|
97
|
+
const isMessage = fp.name === 'message';
|
|
98
|
+
// 'message' param is not readonly — it's passed to super
|
|
99
|
+
const fName = emitIdentifier(fp.name, 'field', field);
|
|
100
|
+
const fType = emitTypeAnnotation(fp.type, 'unknown', field);
|
|
101
|
+
if (isMessage) {
|
|
102
|
+
lines.push(` ${fName}${opt}: ${fType},`);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
lines.push(` public readonly ${fName}${opt}: ${fType},`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
lines.push(` ) {`);
|
|
109
|
+
if (code) {
|
|
110
|
+
// Custom handler body — replaces auto-generated constructor logic
|
|
111
|
+
for (const line of code.split('\n')) {
|
|
112
|
+
lines.push(` ${line}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else if (message) {
|
|
116
|
+
// Check if message references array fields that need formatting
|
|
117
|
+
const arrayFields = fields.filter(f => {
|
|
118
|
+
const ft = propsOf(f).type || '';
|
|
119
|
+
return ft.includes('[]') || ft.includes('string |') || ft.includes('| string');
|
|
120
|
+
});
|
|
121
|
+
for (const f of arrayFields) {
|
|
122
|
+
const fn = propsOf(f).name || 'field';
|
|
123
|
+
lines.push(` const ${fn}Str = Array.isArray(${fn}) ? ${fn}.join(' | ') : ${fn};`);
|
|
124
|
+
}
|
|
125
|
+
lines.push(` super(\`${message}\`);`);
|
|
126
|
+
lines.push(` this.name = '${name}';`);
|
|
127
|
+
}
|
|
128
|
+
else if (hasMessageParam) {
|
|
129
|
+
lines.push(` super(message);`);
|
|
130
|
+
lines.push(` this.name = '${name}';`);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
lines.push(` super();`);
|
|
134
|
+
lines.push(` this.name = '${name}';`);
|
|
135
|
+
}
|
|
136
|
+
lines.push(` }`);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
lines.push(` constructor(message: string) {`);
|
|
140
|
+
lines.push(` super(message);`);
|
|
141
|
+
lines.push(` this.name = '${name}';`);
|
|
142
|
+
lines.push(` }`);
|
|
143
|
+
}
|
|
144
|
+
lines.push('}');
|
|
145
|
+
return lines;
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=functions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/codegen/functions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEvH,MAAM,CAAC,GAAG,QAAQ,CAAC;AACnB,MAAM,IAAI,GAAG,WAAW,CAAC;AACzB,MAAM,UAAU,GAAG,aAAa,CAAC;AAEjC,4EAA4E;AAE5E,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,MAAM,KAAK,GAAG,OAAO,CAAO,IAAI,CAAC,CAAC;IAClC,MAAM,IAAI,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;IAC3D,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,IAAI,EAAE,CAAC;IAClC,MAAM,OAAO,GAA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,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ground Layer Generators — derive, transform, action, guard, assume, invariant,
|
|
3
|
+
* collect, resolve, expect, recover, pattern, apply.
|
|
4
|
+
*
|
|
5
|
+
* NOTE: generateEach and generateBranch remain in codegen-core.ts because they
|
|
6
|
+
* call generateCoreNode recursively (avoiding circular imports).
|
|
7
|
+
*
|
|
8
|
+
* Extracted from codegen-core.ts for modular codegen architecture.
|
|
9
|
+
*/
|
|
10
|
+
import type { IRNode } from '../types.js';
|
|
11
|
+
export declare function generateDerive(node: IRNode): string[];
|
|
12
|
+
export declare function generateTransform(node: IRNode): string[];
|
|
13
|
+
export declare function generateAction(node: IRNode): string[];
|
|
14
|
+
export declare function generateGuard(node: IRNode): string[];
|
|
15
|
+
export declare function generateAssume(node: IRNode): string[];
|
|
16
|
+
export declare function generateInvariant(node: IRNode): string[];
|
|
17
|
+
export declare function generateCollect(node: IRNode): string[];
|
|
18
|
+
export declare function generateResolve(node: IRNode): string[];
|
|
19
|
+
export declare function generateExpect(node: IRNode): string[];
|
|
20
|
+
export declare function generateRecover(node: IRNode): string[];
|
|
21
|
+
export declare function generatePattern(_node: IRNode): string[];
|
|
22
|
+
export declare function generateApply(node: IRNode, _depth?: number): string[];
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ground Layer Generators — derive, transform, action, guard, assume, invariant,
|
|
3
|
+
* collect, resolve, expect, recover, pattern, apply.
|
|
4
|
+
*
|
|
5
|
+
* NOTE: generateEach and generateBranch remain in codegen-core.ts because they
|
|
6
|
+
* call generateCoreNode recursively (avoiding circular imports).
|
|
7
|
+
*
|
|
8
|
+
* Extracted from codegen-core.ts for modular codegen architecture.
|
|
9
|
+
*/
|
|
10
|
+
import { propsOf } from '../node-props.js';
|
|
11
|
+
import { isTemplateNode, expandTemplateNode } from '../template-engine.js';
|
|
12
|
+
import { KernCodegenError } from '../errors.js';
|
|
13
|
+
import { emitIdentifier, emitTypeAnnotation } from './emitters.js';
|
|
14
|
+
import { getProps, getChildren, getFirstChild, handlerCode, exportPrefix, capitalize, parseParamList, emitReasonAnnotations, emitLowConfidenceTodo } from './helpers.js';
|
|
15
|
+
const p = getProps;
|
|
16
|
+
const kids = getChildren;
|
|
17
|
+
const firstChild = getFirstChild;
|
|
18
|
+
// ── Ground Layer: derive ─────────────────────────────────────────────────
|
|
19
|
+
export function generateDerive(node) {
|
|
20
|
+
const annotations = emitReasonAnnotations(node);
|
|
21
|
+
const props = propsOf(node);
|
|
22
|
+
const conf = props.confidence;
|
|
23
|
+
const todo = emitLowConfidenceTodo(node, conf);
|
|
24
|
+
const name = emitIdentifier(props.name, 'derived', node);
|
|
25
|
+
// expr is by-design raw code (escape hatch)
|
|
26
|
+
const expr = props.expr;
|
|
27
|
+
const constType = props.type;
|
|
28
|
+
const exp = exportPrefix(node);
|
|
29
|
+
const typeAnnotation = constType ? `: ${emitTypeAnnotation(constType, 'unknown', node)}` : '';
|
|
30
|
+
return [...todo, ...annotations, `${exp}const ${name}${typeAnnotation} = ${expr};`];
|
|
31
|
+
}
|
|
32
|
+
// ── Ground Layer: transform ──────────────────────────────────────────────
|
|
33
|
+
export function generateTransform(node) {
|
|
34
|
+
const annotations = emitReasonAnnotations(node);
|
|
35
|
+
const props = propsOf(node);
|
|
36
|
+
const conf = props.confidence;
|
|
37
|
+
const todo = emitLowConfidenceTodo(node, conf);
|
|
38
|
+
const name = emitIdentifier(props.name, 'transform', node);
|
|
39
|
+
// target and via are by-design raw code (escape hatches)
|
|
40
|
+
const target = props.target;
|
|
41
|
+
const via = props.via;
|
|
42
|
+
const constType = props.type;
|
|
43
|
+
const exp = exportPrefix(node);
|
|
44
|
+
const code = handlerCode(node);
|
|
45
|
+
const typeAnnotation = constType ? `: ${emitTypeAnnotation(constType, 'unknown', node)}` : '';
|
|
46
|
+
if (code) {
|
|
47
|
+
// Handler block form — generate a function
|
|
48
|
+
const lines = [...todo, ...annotations];
|
|
49
|
+
lines.push(`${exp}function ${name}(state: unknown)${typeAnnotation} {`);
|
|
50
|
+
for (const line of code.split('\n')) {
|
|
51
|
+
lines.push(` ${line}`);
|
|
52
|
+
}
|
|
53
|
+
lines.push('}');
|
|
54
|
+
return lines;
|
|
55
|
+
}
|
|
56
|
+
if (target && via) {
|
|
57
|
+
return [...todo, ...annotations, `${exp}const ${name}${typeAnnotation} = ${via.replace(/\(/, `(${target}, `).replace(/, \)/, ')')};`];
|
|
58
|
+
}
|
|
59
|
+
if (via) {
|
|
60
|
+
return [...todo, ...annotations, `${exp}const ${name}${typeAnnotation} = ${via};`];
|
|
61
|
+
}
|
|
62
|
+
return [...todo, ...annotations, `${exp}const ${name}${typeAnnotation};`];
|
|
63
|
+
}
|
|
64
|
+
// ── Ground Layer: action ─────────────────────────────────────────────────
|
|
65
|
+
export function generateAction(node) {
|
|
66
|
+
const annotations = emitReasonAnnotations(node);
|
|
67
|
+
const props = propsOf(node);
|
|
68
|
+
const conf = props.confidence;
|
|
69
|
+
const todo = emitLowConfidenceTodo(node, conf);
|
|
70
|
+
const name = emitIdentifier(props.name, 'action', node);
|
|
71
|
+
const idempotent = props.idempotent === 'true' || props.idempotent === true;
|
|
72
|
+
const reversible = props.reversible === 'true' || props.reversible === true;
|
|
73
|
+
const params = props.params || '';
|
|
74
|
+
const returns = props.returns;
|
|
75
|
+
const exp = exportPrefix(node);
|
|
76
|
+
const code = handlerCode(node);
|
|
77
|
+
const lines = [...todo, ...annotations];
|
|
78
|
+
// JSDoc for action metadata
|
|
79
|
+
const metaParts = [];
|
|
80
|
+
if (idempotent)
|
|
81
|
+
metaParts.push('idempotent=true');
|
|
82
|
+
if (reversible)
|
|
83
|
+
metaParts.push('reversible=true');
|
|
84
|
+
if (metaParts.length > 0) {
|
|
85
|
+
lines.push(`/** @action ${metaParts.join(' ')} */`);
|
|
86
|
+
}
|
|
87
|
+
const paramList = params ? parseParamList(params) : '';
|
|
88
|
+
const retClause = returns ? `: Promise<${emitTypeAnnotation(returns, 'void', node)}>` : ': Promise<void>';
|
|
89
|
+
lines.push(`${exp}async function ${name}(${paramList})${retClause} {`);
|
|
90
|
+
if (code) {
|
|
91
|
+
for (const line of code.split('\n')) {
|
|
92
|
+
lines.push(` ${line}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
lines.push('}');
|
|
96
|
+
return lines;
|
|
97
|
+
}
|
|
98
|
+
// ── Ground Layer: guard ──────────────────────────────────────────────────
|
|
99
|
+
export function generateGuard(node) {
|
|
100
|
+
const annotations = emitReasonAnnotations(node);
|
|
101
|
+
const props = propsOf(node);
|
|
102
|
+
const conf = props.confidence;
|
|
103
|
+
const todo = emitLowConfidenceTodo(node, conf);
|
|
104
|
+
const name = props.name || 'guard';
|
|
105
|
+
const expr = props.expr;
|
|
106
|
+
const elseCode = props.else;
|
|
107
|
+
const lines = [...todo, ...annotations];
|
|
108
|
+
if (elseCode && /^\d+$/.test(elseCode)) {
|
|
109
|
+
lines.push(`if (!(${expr})) { throw new HttpError(${elseCode}, 'Guard: ${name}'); }`);
|
|
110
|
+
}
|
|
111
|
+
else if (elseCode) {
|
|
112
|
+
lines.push(`if (!(${expr})) { ${elseCode}; }`);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
lines.push(`if (!(${expr})) { throw new Error('Guard failed: ${name}'); }`);
|
|
116
|
+
}
|
|
117
|
+
return lines;
|
|
118
|
+
}
|
|
119
|
+
// ── Ground Layer: assume ─────────────────────────────────────────────────
|
|
120
|
+
export function generateAssume(node) {
|
|
121
|
+
const annotations = emitReasonAnnotations(node);
|
|
122
|
+
const props = propsOf(node);
|
|
123
|
+
const conf = props.confidence;
|
|
124
|
+
const todo = emitLowConfidenceTodo(node, conf);
|
|
125
|
+
const expr = props.expr;
|
|
126
|
+
const scope = props.scope || 'request';
|
|
127
|
+
const evidence = props.evidence;
|
|
128
|
+
const fallback = props.fallback;
|
|
129
|
+
if (!evidence)
|
|
130
|
+
throw new KernCodegenError('assume requires evidence prop', node);
|
|
131
|
+
if (!fallback)
|
|
132
|
+
throw new KernCodegenError('assume requires fallback prop', node);
|
|
133
|
+
const lines = [...todo, ...annotations];
|
|
134
|
+
lines.push(`/** @assume ${expr} @scope ${scope} @evidence ${evidence} */`);
|
|
135
|
+
lines.push(`if (process.env.NODE_ENV !== 'production') {`);
|
|
136
|
+
lines.push(` if (!(${expr})) { ${fallback}; }`);
|
|
137
|
+
lines.push(`}`);
|
|
138
|
+
return lines;
|
|
139
|
+
}
|
|
140
|
+
// ── Ground Layer: invariant ──────────────────────────────────────────────
|
|
141
|
+
export function generateInvariant(node) {
|
|
142
|
+
const annotations = emitReasonAnnotations(node);
|
|
143
|
+
const props = propsOf(node);
|
|
144
|
+
const conf = props.confidence;
|
|
145
|
+
const todo = emitLowConfidenceTodo(node, conf);
|
|
146
|
+
const name = props.name || 'invariant';
|
|
147
|
+
const expr = props.expr;
|
|
148
|
+
const lines = [...todo, ...annotations];
|
|
149
|
+
lines.push(`console.assert(${expr}, 'Invariant: ${name}');`);
|
|
150
|
+
return lines;
|
|
151
|
+
}
|
|
152
|
+
// ── Ground Layer: collect ────────────────────────────────────────────────
|
|
153
|
+
export function generateCollect(node) {
|
|
154
|
+
const annotations = emitReasonAnnotations(node);
|
|
155
|
+
const props = propsOf(node);
|
|
156
|
+
const conf = props.confidence;
|
|
157
|
+
const todo = emitLowConfidenceTodo(node, conf);
|
|
158
|
+
const name = emitIdentifier(props.name, 'collected', node);
|
|
159
|
+
const from = props.from;
|
|
160
|
+
const where = props.where;
|
|
161
|
+
const limit = props.limit;
|
|
162
|
+
const order = props.order;
|
|
163
|
+
const exp = exportPrefix(node);
|
|
164
|
+
let chain = from;
|
|
165
|
+
if (where)
|
|
166
|
+
chain += `.filter(item => ${where})`;
|
|
167
|
+
if (order)
|
|
168
|
+
chain += `.sort((a, b) => ${order})`;
|
|
169
|
+
if (limit)
|
|
170
|
+
chain += `.slice(0, ${limit})`;
|
|
171
|
+
return [...todo, ...annotations, `${exp}const ${name} = ${chain};`];
|
|
172
|
+
}
|
|
173
|
+
// ── Ground Layer: resolve / candidate / discriminator ────────────────────
|
|
174
|
+
export function generateResolve(node) {
|
|
175
|
+
const annotations = emitReasonAnnotations(node);
|
|
176
|
+
const props = propsOf(node);
|
|
177
|
+
const conf = props.confidence;
|
|
178
|
+
const todo = emitLowConfidenceTodo(node, conf);
|
|
179
|
+
const name = emitIdentifier(props.name, 'resolver', node);
|
|
180
|
+
const candidates = kids(node, 'candidate');
|
|
181
|
+
const discriminator = firstChild(node, 'discriminator');
|
|
182
|
+
if (!discriminator)
|
|
183
|
+
throw new KernCodegenError('resolve requires discriminator', node);
|
|
184
|
+
const lines = [...todo, ...annotations];
|
|
185
|
+
const dp = p(discriminator);
|
|
186
|
+
const method = dp.method || 'select';
|
|
187
|
+
const metric = dp.metric || '';
|
|
188
|
+
// Candidate array
|
|
189
|
+
lines.push(`/** resolve: ${name} */`);
|
|
190
|
+
lines.push(`const _${name}_candidates = [`);
|
|
191
|
+
for (const c of candidates) {
|
|
192
|
+
const cp = p(c);
|
|
193
|
+
const cname = emitIdentifier(cp.name, 'candidate', c);
|
|
194
|
+
const code = handlerCode(c);
|
|
195
|
+
lines.push(` { name: '${cname}', fn: (signal: unknown) => { ${code.trim()} } },`);
|
|
196
|
+
}
|
|
197
|
+
lines.push(`];`);
|
|
198
|
+
lines.push('');
|
|
199
|
+
// Resolver function
|
|
200
|
+
const discCode = handlerCode(discriminator);
|
|
201
|
+
lines.push(`async function resolve${capitalize(name)}(signal: unknown): Promise<unknown> {`);
|
|
202
|
+
lines.push(` const candidates = _${name}_candidates;`);
|
|
203
|
+
lines.push(` // discriminator: ${method}(${metric})`);
|
|
204
|
+
if (discCode) {
|
|
205
|
+
for (const line of discCode.split('\n')) {
|
|
206
|
+
lines.push(` ${line}`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
lines.push(` return candidates[winnerIdx].fn(signal);`);
|
|
210
|
+
lines.push('}');
|
|
211
|
+
return lines;
|
|
212
|
+
}
|
|
213
|
+
// ── Ground Layer: expect ─────────────────────────────────────────────────
|
|
214
|
+
export function generateExpect(node) {
|
|
215
|
+
const annotations = emitReasonAnnotations(node);
|
|
216
|
+
const props = propsOf(node);
|
|
217
|
+
const conf = props.confidence;
|
|
218
|
+
const todo = emitLowConfidenceTodo(node, conf);
|
|
219
|
+
const name = props.name || 'expected';
|
|
220
|
+
const expr = props.expr;
|
|
221
|
+
const within = props.within;
|
|
222
|
+
const max = props.max;
|
|
223
|
+
const min = props.min;
|
|
224
|
+
const lines = [...todo, ...annotations];
|
|
225
|
+
lines.push(`if (process.env.NODE_ENV !== 'production') {`);
|
|
226
|
+
lines.push(` const _${name} = ${expr};`);
|
|
227
|
+
if (within) {
|
|
228
|
+
const [lo, hi] = within.split('..');
|
|
229
|
+
lines.push(` console.assert(_${name} >= ${lo} && _${name} <= ${hi}, 'Expected ${name} in [${lo}, ${hi}], got ' + _${name});`);
|
|
230
|
+
}
|
|
231
|
+
else if (min && max) {
|
|
232
|
+
lines.push(` console.assert(_${name} >= ${min} && _${name} <= ${max}, 'Expected ${name} in [${min}, ${max}], got ' + _${name});`);
|
|
233
|
+
}
|
|
234
|
+
else if (max) {
|
|
235
|
+
lines.push(` console.assert(_${name} <= ${max}, 'Expected ${name} <= ${max}, got ' + _${name});`);
|
|
236
|
+
}
|
|
237
|
+
else if (min) {
|
|
238
|
+
lines.push(` console.assert(_${name} >= ${min}, 'Expected ${name} >= ${min}, got ' + _${name});`);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
lines.push(` console.assert(_${name} != null, 'Expected ${name} to be defined');`);
|
|
242
|
+
}
|
|
243
|
+
lines.push('}');
|
|
244
|
+
return lines;
|
|
245
|
+
}
|
|
246
|
+
// ── Ground Layer: recover / strategy ─────────────────────────────────────
|
|
247
|
+
export function generateRecover(node) {
|
|
248
|
+
const annotations = emitReasonAnnotations(node);
|
|
249
|
+
const props = propsOf(node);
|
|
250
|
+
const conf = props.confidence;
|
|
251
|
+
const todo = emitLowConfidenceTodo(node, conf);
|
|
252
|
+
const name = emitIdentifier(props.name, 'recovery', node);
|
|
253
|
+
const strategies = kids(node, 'strategy');
|
|
254
|
+
const hasFallback = strategies.some(s => p(s).name === 'fallback');
|
|
255
|
+
if (!hasFallback)
|
|
256
|
+
throw new KernCodegenError('recover requires a fallback strategy', node);
|
|
257
|
+
const lines = [...todo, ...annotations];
|
|
258
|
+
lines.push(`/** recover: ${name} */`);
|
|
259
|
+
lines.push(`async function ${name}WithRecovery<T>(fn: () => Promise<T>): Promise<T> {`);
|
|
260
|
+
for (const strategy of strategies) {
|
|
261
|
+
const sp = p(strategy);
|
|
262
|
+
const sname = emitIdentifier(sp.name, 'strategy', strategy);
|
|
263
|
+
const code = handlerCode(strategy);
|
|
264
|
+
if (sname === 'retry') {
|
|
265
|
+
const max = Number(sp.max) || 3;
|
|
266
|
+
const delay = Number(sp.delay) || 1000;
|
|
267
|
+
lines.push(` // strategy: retry (max=${max}, delay=${delay}ms)`);
|
|
268
|
+
lines.push(` for (let _attempt = 0; _attempt < ${max}; _attempt++) {`);
|
|
269
|
+
lines.push(` try { return await fn(); }`);
|
|
270
|
+
lines.push(` catch { if (_attempt < ${max - 1}) await new Promise(r => setTimeout(r, ${delay})); }`);
|
|
271
|
+
lines.push(` }`);
|
|
272
|
+
}
|
|
273
|
+
else if (sname === 'fallback') {
|
|
274
|
+
lines.push(` // strategy: fallback (terminal)`);
|
|
275
|
+
if (code) {
|
|
276
|
+
for (const line of code.split('\n')) {
|
|
277
|
+
lines.push(` ${line}`);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
lines.push(` throw new Error('All recovery strategies exhausted for ${name}');`);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
// compensate, degrade, or custom
|
|
286
|
+
lines.push(` // strategy: ${sname}`);
|
|
287
|
+
lines.push(` try {`);
|
|
288
|
+
if (code) {
|
|
289
|
+
for (const line of code.split('\n')) {
|
|
290
|
+
lines.push(` ${line}`);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
lines.push(` } catch {}`);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
lines.push('}');
|
|
297
|
+
return lines;
|
|
298
|
+
}
|
|
299
|
+
// ── Ground Layer: pattern / apply ────────────────────────────────────────
|
|
300
|
+
export function generatePattern(_node) {
|
|
301
|
+
// pattern nodes are registered as templates — no direct output
|
|
302
|
+
return [];
|
|
303
|
+
}
|
|
304
|
+
export function generateApply(node, _depth = 0) {
|
|
305
|
+
// apply nodes expand the referenced pattern
|
|
306
|
+
const props = propsOf(node);
|
|
307
|
+
const patternName = props.pattern;
|
|
308
|
+
if (!patternName)
|
|
309
|
+
return [];
|
|
310
|
+
// Delegate to template expansion — propagate depth to prevent infinite recursion
|
|
311
|
+
const syntheticNode = { ...node, type: patternName };
|
|
312
|
+
if (isTemplateNode(patternName)) {
|
|
313
|
+
return expandTemplateNode(syntheticNode, _depth + 1);
|
|
314
|
+
}
|
|
315
|
+
return [`// apply: pattern '${patternName}' not found`];
|
|
316
|
+
}
|
|
317
|
+
//# sourceMappingURL=ground-layer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ground-layer.js","sourceRoot":"","sources":["../../src/codegen/ground-layer.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc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,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;IAC7D,IAAI,cAAc,CAAC,WAAW,CAAC,EAAE,CAAC;QAChC,OAAO,kBAAkB,CAAC,aAAa,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,CAAC,sBAAsB,WAAW,aAAa,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State Machine Generators — machine, machineReducer.
|
|
3
|
+
*
|
|
4
|
+
* KERN's killer feature: 12 lines of KERN → 140+ lines of TypeScript.
|
|
5
|
+
* Extracted from codegen-core.ts for modular codegen architecture.
|
|
6
|
+
*/
|
|
7
|
+
import type { IRNode } from '../types.js';
|
|
8
|
+
export declare function generateMachine(node: IRNode): string[];
|
|
9
|
+
export declare function generateMachineReducer(node: IRNode): string[];
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State Machine Generators — machine, machineReducer.
|
|
3
|
+
*
|
|
4
|
+
* KERN's killer feature: 12 lines of KERN → 140+ lines of TypeScript.
|
|
5
|
+
* Extracted from codegen-core.ts for modular codegen architecture.
|
|
6
|
+
*/
|
|
7
|
+
import { propsOf } from '../node-props.js';
|
|
8
|
+
import { emitIdentifier, emitTemplateSafe } from './emitters.js';
|
|
9
|
+
import { getProps, getChildren, handlerCode, exportPrefix } from './helpers.js';
|
|
10
|
+
const p = getProps;
|
|
11
|
+
const kids = getChildren;
|
|
12
|
+
// ── State Machine ────────────────────────────────────────────────────────
|
|
13
|
+
export function generateMachine(node) {
|
|
14
|
+
const props = propsOf(node);
|
|
15
|
+
const name = emitIdentifier(props.name, 'UnknownMachine', node);
|
|
16
|
+
const exp = exportPrefix(node);
|
|
17
|
+
const lines = [];
|
|
18
|
+
// Collect states
|
|
19
|
+
const states = kids(node, 'state');
|
|
20
|
+
const stateNames = states.map(s => {
|
|
21
|
+
const sp = propsOf(s);
|
|
22
|
+
return emitIdentifier(sp.name || sp.value, 'state', s);
|
|
23
|
+
});
|
|
24
|
+
// State type
|
|
25
|
+
const stateType = `${name}State`;
|
|
26
|
+
lines.push(`${exp}type ${stateType} = ${stateNames.map(s => `'${emitTemplateSafe(s)}'`).join(' | ')};`);
|
|
27
|
+
lines.push('');
|
|
28
|
+
// Error class
|
|
29
|
+
const errorName = `${name}StateError`;
|
|
30
|
+
lines.push(`${exp}class ${errorName} extends Error {`);
|
|
31
|
+
lines.push(` constructor(`);
|
|
32
|
+
lines.push(` public readonly expected: string | string[],`);
|
|
33
|
+
lines.push(` public readonly actual: string,`);
|
|
34
|
+
lines.push(` ) {`);
|
|
35
|
+
lines.push(` const expectedStr = Array.isArray(expected) ? expected.join(' | ') : expected;`);
|
|
36
|
+
lines.push(` super(\`Invalid ${name.toLowerCase()} state: expected \${expectedStr}, got \${actual}\`);`);
|
|
37
|
+
lines.push(` this.name = '${errorName}';`);
|
|
38
|
+
lines.push(` }`);
|
|
39
|
+
lines.push('}');
|
|
40
|
+
lines.push('');
|
|
41
|
+
// Transition functions
|
|
42
|
+
const transitions = kids(node, 'transition');
|
|
43
|
+
for (const t of transitions) {
|
|
44
|
+
const tp = propsOf(t);
|
|
45
|
+
const tname = emitIdentifier(tp.name, 'transition', t);
|
|
46
|
+
const from = tp.from || '';
|
|
47
|
+
const to = tp.to || '';
|
|
48
|
+
const fromStates = from.split('|').map(s => s.trim());
|
|
49
|
+
const isMultiFrom = fromStates.length > 1;
|
|
50
|
+
const fnName = `${tname}${name}`;
|
|
51
|
+
const code = handlerCode(t);
|
|
52
|
+
lines.push(`/** ${from} → ${to} */`);
|
|
53
|
+
lines.push(`${exp}function ${fnName}<T extends { state: ${stateType} }>(entity: T): T {`);
|
|
54
|
+
if (isMultiFrom) {
|
|
55
|
+
lines.push(` const validStates: ${stateType}[] = [${fromStates.map(s => `'${s}'`).join(', ')}];`);
|
|
56
|
+
lines.push(` if (!validStates.includes(entity.state)) {`);
|
|
57
|
+
lines.push(` throw new ${errorName}(validStates, entity.state);`);
|
|
58
|
+
lines.push(` }`);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
lines.push(` if (entity.state !== '${fromStates[0]}') {`);
|
|
62
|
+
lines.push(` throw new ${errorName}('${fromStates[0]}', entity.state);`);
|
|
63
|
+
lines.push(` }`);
|
|
64
|
+
}
|
|
65
|
+
if (code) {
|
|
66
|
+
for (const line of code.split('\n')) {
|
|
67
|
+
lines.push(` ${line}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
lines.push(` return { ...entity, state: '${to}' as ${stateType} };`);
|
|
72
|
+
}
|
|
73
|
+
lines.push('}');
|
|
74
|
+
lines.push('');
|
|
75
|
+
}
|
|
76
|
+
return lines;
|
|
77
|
+
}
|
|
78
|
+
// ── Machine → useReducer (Ink target) ────────────────────────────────────
|
|
79
|
+
export function generateMachineReducer(node) {
|
|
80
|
+
const props = propsOf(node);
|
|
81
|
+
const name = emitIdentifier(props.name, 'UnknownMachine', node);
|
|
82
|
+
const exp = exportPrefix(node);
|
|
83
|
+
const lines = [];
|
|
84
|
+
lines.push(`import { useReducer } from 'react';`);
|
|
85
|
+
lines.push('');
|
|
86
|
+
// First emit the standard machine output
|
|
87
|
+
lines.push(...generateMachine(node));
|
|
88
|
+
// Collect states + transitions
|
|
89
|
+
const states = kids(node, 'state');
|
|
90
|
+
const stateNames = states.map(s => {
|
|
91
|
+
const sp = propsOf(s);
|
|
92
|
+
return sp.name || sp.value || '';
|
|
93
|
+
});
|
|
94
|
+
const initialState = states.find(s => {
|
|
95
|
+
const sp = propsOf(s);
|
|
96
|
+
return sp.initial === 'true' || sp.initial === true;
|
|
97
|
+
});
|
|
98
|
+
const initialName = initialState ? (propsOf(initialState).name || propsOf(initialState).value || '') : stateNames[0];
|
|
99
|
+
const transitions = kids(node, 'transition');
|
|
100
|
+
const stateType = `${name}State`;
|
|
101
|
+
// Action type union
|
|
102
|
+
const actionNames = transitions.map(t => emitIdentifier(propsOf(t).name, 'action', t));
|
|
103
|
+
lines.push(`${exp}type ${name}Action = ${actionNames.map(a => `'${a}'`).join(' | ')};`);
|
|
104
|
+
lines.push('');
|
|
105
|
+
// Reducer function
|
|
106
|
+
lines.push(`${exp}function ${name.charAt(0).toLowerCase() + name.slice(1)}Reducer(state: ${stateType}, action: ${name}Action): ${stateType} {`);
|
|
107
|
+
lines.push(` const entity = { state };`);
|
|
108
|
+
lines.push(` switch (action) {`);
|
|
109
|
+
for (const t of transitions) {
|
|
110
|
+
const tp = propsOf(t);
|
|
111
|
+
const tname = emitIdentifier(tp.name, 'action', t);
|
|
112
|
+
const fnName = `${tname}${name}`;
|
|
113
|
+
lines.push(` case '${emitTemplateSafe(tname)}': return ${fnName}(entity).state;`);
|
|
114
|
+
}
|
|
115
|
+
lines.push(` default: return state;`);
|
|
116
|
+
lines.push(` }`);
|
|
117
|
+
lines.push('}');
|
|
118
|
+
lines.push('');
|
|
119
|
+
// useReducer hook
|
|
120
|
+
lines.push(`${exp}function use${name}Reducer() {`);
|
|
121
|
+
lines.push(` const [state, dispatch] = useReducer(${name.charAt(0).toLowerCase() + name.slice(1)}Reducer, '${initialName}' as ${stateType});`);
|
|
122
|
+
lines.push(` return { state, dispatch } as const;`);
|
|
123
|
+
lines.push('}');
|
|
124
|
+
lines.push('');
|
|
125
|
+
return lines;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=machines.js.map
|