@kernlang/evolve 3.0.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/LICENSE +661 -0
- package/dist/concept-gap-adapter.d.ts +17 -0
- package/dist/concept-gap-adapter.js +43 -0
- package/dist/concept-gap-adapter.js.map +1 -0
- package/dist/detector-registry.d.ts +31 -0
- package/dist/detector-registry.js +89 -0
- package/dist/detector-registry.js.map +1 -0
- package/dist/detectors/animation.d.ts +5 -0
- package/dist/detectors/animation.js +67 -0
- package/dist/detectors/animation.js.map +1 -0
- package/dist/detectors/data-fetching.d.ts +5 -0
- package/dist/detectors/data-fetching.js +117 -0
- package/dist/detectors/data-fetching.js.map +1 -0
- package/dist/detectors/express-middleware.d.ts +5 -0
- package/dist/detectors/express-middleware.js +52 -0
- package/dist/detectors/express-middleware.js.map +1 -0
- package/dist/detectors/react-forms.d.ts +5 -0
- package/dist/detectors/react-forms.js +89 -0
- package/dist/detectors/react-forms.js.map +1 -0
- package/dist/detectors/schema-validation.d.ts +5 -0
- package/dist/detectors/schema-validation.js +92 -0
- package/dist/detectors/schema-validation.js.map +1 -0
- package/dist/detectors/state-mgmt.d.ts +5 -0
- package/dist/detectors/state-mgmt.js +102 -0
- package/dist/detectors/state-mgmt.js.map +1 -0
- package/dist/detectors/structural.d.ts +10 -0
- package/dist/detectors/structural.js +271 -0
- package/dist/detectors/structural.js.map +1 -0
- package/dist/detectors/testing.d.ts +5 -0
- package/dist/detectors/testing.js +56 -0
- package/dist/detectors/testing.js.map +1 -0
- package/dist/detectors/vue-composables.d.ts +5 -0
- package/dist/detectors/vue-composables.js +57 -0
- package/dist/detectors/vue-composables.js.map +1 -0
- package/dist/evolve-dedup.d.ts +12 -0
- package/dist/evolve-dedup.js +50 -0
- package/dist/evolve-dedup.js.map +1 -0
- package/dist/evolve-rollback.d.ts +58 -0
- package/dist/evolve-rollback.js +242 -0
- package/dist/evolve-rollback.js.map +1 -0
- package/dist/evolve-runner.d.ts +22 -0
- package/dist/evolve-runner.js +183 -0
- package/dist/evolve-runner.js.map +1 -0
- package/dist/evolve-validator-v4.d.ts +11 -0
- package/dist/evolve-validator-v4.js +253 -0
- package/dist/evolve-validator-v4.js.map +1 -0
- package/dist/evolved-node-loader.d.ts +61 -0
- package/dist/evolved-node-loader.js +228 -0
- package/dist/evolved-node-loader.js.map +1 -0
- package/dist/evolved-types.d.ts +110 -0
- package/dist/evolved-types.js +8 -0
- package/dist/evolved-types.js.map +1 -0
- package/dist/expressibility-scorer.d.ts +19 -0
- package/dist/expressibility-scorer.js +78 -0
- package/dist/expressibility-scorer.js.map +1 -0
- package/dist/gap-detector.d.ts +26 -0
- package/dist/gap-detector.js +141 -0
- package/dist/gap-detector.js.map +1 -0
- package/dist/golden-test-runner.d.ts +27 -0
- package/dist/golden-test-runner.js +120 -0
- package/dist/golden-test-runner.js.map +1 -0
- package/dist/graduation.d.ts +36 -0
- package/dist/graduation.js +175 -0
- package/dist/graduation.js.map +1 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +58 -0
- package/dist/index.js.map +1 -0
- package/dist/llm-discovery.d.ts +55 -0
- package/dist/llm-discovery.js +352 -0
- package/dist/llm-discovery.js.map +1 -0
- package/dist/llm-provider.d.ts +35 -0
- package/dist/llm-provider.js +143 -0
- package/dist/llm-provider.js.map +1 -0
- package/dist/node-governance.d.ts +23 -0
- package/dist/node-governance.js +45 -0
- package/dist/node-governance.js.map +1 -0
- package/dist/node-proposer.d.ts +27 -0
- package/dist/node-proposer.js +127 -0
- package/dist/node-proposer.js.map +1 -0
- package/dist/node-validator.d.ts +16 -0
- package/dist/node-validator.js +74 -0
- package/dist/node-validator.js.map +1 -0
- package/dist/pattern-analyzer.d.ts +28 -0
- package/dist/pattern-analyzer.js +181 -0
- package/dist/pattern-analyzer.js.map +1 -0
- package/dist/quality-scorer.d.ts +16 -0
- package/dist/quality-scorer.js +79 -0
- package/dist/quality-scorer.js.map +1 -0
- package/dist/sandboxed-generator.d.ts +26 -0
- package/dist/sandboxed-generator.js +133 -0
- package/dist/sandboxed-generator.js.map +1 -0
- package/dist/staging.d.ts +81 -0
- package/dist/staging.js +414 -0
- package/dist/staging.js.map +1 -0
- package/dist/template-proposer.d.ts +24 -0
- package/dist/template-proposer.js +103 -0
- package/dist/template-proposer.js.map +1 -0
- package/dist/template-validator.d.ts +18 -0
- package/dist/template-validator.js +174 -0
- package/dist/template-validator.js.map +1 -0
- package/dist/types.d.ts +169 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/package.json +27 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template Validator — Phase 4 of the evolve pipeline.
|
|
3
|
+
*
|
|
4
|
+
* 5-step validation:
|
|
5
|
+
* 1. Parse: Is the .kern source valid syntax?
|
|
6
|
+
* 2. Register: Can the template be registered?
|
|
7
|
+
* 3. Expand: Does the template expand with real slot values?
|
|
8
|
+
* 4. Golden diff: Does the expansion match the original TS structure?
|
|
9
|
+
* 5. Typecheck: Does the expanded TypeScript pass type checking? (tsconfig-aware)
|
|
10
|
+
*/
|
|
11
|
+
import { Project } from 'ts-morph';
|
|
12
|
+
import { parse, registerTemplate, expandTemplateNode, clearTemplates } from '@kernlang/core';
|
|
13
|
+
/**
|
|
14
|
+
* Validate a template proposal through the 5-step pipeline.
|
|
15
|
+
*
|
|
16
|
+
* Uses REAL values extracted from source, not synthetic placeholders.
|
|
17
|
+
* Each call operates on an isolated template registry (cleared before and after).
|
|
18
|
+
*/
|
|
19
|
+
export function validateProposal(proposal, tsconfigPath) {
|
|
20
|
+
const result = {
|
|
21
|
+
parseOk: false,
|
|
22
|
+
registerOk: false,
|
|
23
|
+
expansionOk: false,
|
|
24
|
+
typecheckOk: false,
|
|
25
|
+
goldenDiffOk: false,
|
|
26
|
+
errors: [],
|
|
27
|
+
};
|
|
28
|
+
// Step 1: Parse the .kern source
|
|
29
|
+
let ast;
|
|
30
|
+
try {
|
|
31
|
+
ast = parse(proposal.kernSource);
|
|
32
|
+
result.parseOk = true;
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
result.errors.push(`Parse error: ${err.message}`);
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
// Isolate: clear the global template registry before registering
|
|
39
|
+
clearTemplates();
|
|
40
|
+
// Step 2: Register the template
|
|
41
|
+
try {
|
|
42
|
+
const templateNodes = ast.type === 'template'
|
|
43
|
+
? [ast]
|
|
44
|
+
: (ast.children || []).filter(n => n.type === 'template');
|
|
45
|
+
if (templateNodes.length === 0) {
|
|
46
|
+
result.errors.push('No template node found in parsed source');
|
|
47
|
+
clearTemplates();
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
for (const node of templateNodes) {
|
|
51
|
+
registerTemplate(node, `evolve:${proposal.id}`);
|
|
52
|
+
}
|
|
53
|
+
result.registerOk = true;
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
result.errors.push(`Register error: ${err.message}`);
|
|
57
|
+
clearTemplates();
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
// Step 3: Expand the template with real values from golden example
|
|
61
|
+
try {
|
|
62
|
+
const instanceNode = buildInstanceNode(proposal);
|
|
63
|
+
const expandedLines = expandTemplateNode(instanceNode);
|
|
64
|
+
result.expandedTs = expandedLines.join('\n');
|
|
65
|
+
result.expansionOk = true;
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
result.errors.push(`Expansion error: ${err.message}`);
|
|
69
|
+
clearTemplates();
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
// Clean up registry — expansion is done, remaining steps don't need it
|
|
73
|
+
clearTemplates();
|
|
74
|
+
// Step 4: Golden diff — compare expanded output with original TS
|
|
75
|
+
try {
|
|
76
|
+
const diff = computeGoldenDiff(proposal.goldenExample.originalTs, result.expandedTs);
|
|
77
|
+
result.goldenDiff = diff;
|
|
78
|
+
result.goldenDiffOk = assessGoldenDiff(diff);
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
result.errors.push(`Golden diff error: ${err.message}`);
|
|
82
|
+
}
|
|
83
|
+
// Step 5: Typecheck the expanded TypeScript
|
|
84
|
+
try {
|
|
85
|
+
result.typecheckOk = typecheckExpansion(result.expandedTs, tsconfigPath);
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
result.errors.push(`Typecheck error: ${err.message}`);
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Build an IRNode instance that uses the template with golden example values.
|
|
94
|
+
*/
|
|
95
|
+
function buildInstanceNode(proposal) {
|
|
96
|
+
const props = {};
|
|
97
|
+
for (const slot of proposal.slots) {
|
|
98
|
+
const value = proposal.goldenExample.slotValues[slot.name];
|
|
99
|
+
if (value !== undefined) {
|
|
100
|
+
props[slot.name] = value;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
type: proposal.templateName,
|
|
105
|
+
props,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Compute a unified diff between the original TS and the expanded TS.
|
|
110
|
+
*/
|
|
111
|
+
function computeGoldenDiff(original, expanded) {
|
|
112
|
+
const origLines = normalizeForDiff(original).split('\n');
|
|
113
|
+
const expLines = normalizeForDiff(expanded).split('\n');
|
|
114
|
+
const diff = [];
|
|
115
|
+
const maxLen = Math.max(origLines.length, expLines.length);
|
|
116
|
+
for (let i = 0; i < maxLen; i++) {
|
|
117
|
+
const origLine = i < origLines.length ? origLines[i] : undefined;
|
|
118
|
+
const expLine = i < expLines.length ? expLines[i] : undefined;
|
|
119
|
+
if (origLine === expLine) {
|
|
120
|
+
if (origLine !== undefined)
|
|
121
|
+
diff.push(` ${origLine}`);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
if (origLine !== undefined)
|
|
125
|
+
diff.push(`- ${origLine}`);
|
|
126
|
+
if (expLine !== undefined)
|
|
127
|
+
diff.push(`+ ${expLine}`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return diff.join('\n');
|
|
131
|
+
}
|
|
132
|
+
function normalizeForDiff(code) {
|
|
133
|
+
return code
|
|
134
|
+
.split('\n')
|
|
135
|
+
.map(l => l.trim())
|
|
136
|
+
.filter(l => l.length > 0)
|
|
137
|
+
.filter(l => !l.startsWith('import '))
|
|
138
|
+
.join('\n');
|
|
139
|
+
}
|
|
140
|
+
function assessGoldenDiff(diff) {
|
|
141
|
+
const lines = diff.split('\n');
|
|
142
|
+
const totalLines = lines.length;
|
|
143
|
+
const matchedLines = lines.filter(l => l.startsWith(' ')).length;
|
|
144
|
+
if (totalLines === 0)
|
|
145
|
+
return true;
|
|
146
|
+
return matchedLines / totalLines >= 0.4;
|
|
147
|
+
}
|
|
148
|
+
function typecheckExpansion(expandedTs, tsconfigPath) {
|
|
149
|
+
const project = new Project({
|
|
150
|
+
skipAddingFilesFromTsConfig: true,
|
|
151
|
+
compilerOptions: tsconfigPath ? undefined : {
|
|
152
|
+
target: 99, // ESNext
|
|
153
|
+
module: 99, // ESNext
|
|
154
|
+
moduleResolution: 100, // Bundler
|
|
155
|
+
strict: true,
|
|
156
|
+
skipLibCheck: true,
|
|
157
|
+
noEmit: true,
|
|
158
|
+
},
|
|
159
|
+
tsConfigFilePath: tsconfigPath,
|
|
160
|
+
});
|
|
161
|
+
const sourceFile = project.createSourceFile('__evolve_check__.ts', expandedTs);
|
|
162
|
+
const diagnostics = sourceFile.getPreEmitDiagnostics();
|
|
163
|
+
const realErrors = diagnostics.filter(d => {
|
|
164
|
+
const msg = d.getMessageText();
|
|
165
|
+
const msgStr = typeof msg === 'string' ? msg : msg.getMessageText();
|
|
166
|
+
if (msgStr.includes('Cannot find module'))
|
|
167
|
+
return false;
|
|
168
|
+
if (msgStr.includes('Could not find a declaration file'))
|
|
169
|
+
return false;
|
|
170
|
+
return true;
|
|
171
|
+
});
|
|
172
|
+
return realErrors.length === 0;
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=template-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-validator.js","sourceRoot":"","sources":["../src/template-validator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAI7F;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,QAA0B,EAC1B,YAAqB;IAErB,MAAM,MAAM,GAAqB;QAC/B,OAAO,EAAE,KAAK;QACd,UAAU,EAAE,KAAK;QACjB,WAAW,EAAE,KAAK;QAClB,WAAW,EAAE,KAAK;QAClB,YAAY,EAAE,KAAK;QACnB,MAAM,EAAE,EAAE;KACX,CAAC;IAEF,iCAAiC;IACjC,IAAI,GAAW,CAAC;IAChB,IAAI,CAAC;QACH,GAAG,GAAG,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;QACjC,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;IACxB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAiB,GAAa,CAAC,OAAO,EAAE,CAAC,CAAC;QAC7D,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,iEAAiE;IACjE,cAAc,EAAE,CAAC;IAEjB,gCAAgC;IAChC,IAAI,CAAC;QACH,MAAM,aAAa,GAAG,GAAG,CAAC,IAAI,KAAK,UAAU;YAC3C,CAAC,CAAC,CAAC,GAAG,CAAC;YACP,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC;QAE5D,IAAI,aAAa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AC;QACxD,IAAI,MAAM,CAAC,QAAQ,CAAC,mCAAmC,CAAC;YAAE,OAAO,KAAK,CAAC;QACvE,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;IAEH,OAAO,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC;AACjC,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for @kernlang/evolve — self-extending template system.
|
|
3
|
+
*
|
|
4
|
+
* Pipeline: scan → gap-detect → analyze → propose → validate → stage → promote
|
|
5
|
+
*/
|
|
6
|
+
import type { SourceFile } from 'ts-morph';
|
|
7
|
+
import type { TemplateSlotType } from '@kernlang/core';
|
|
8
|
+
export type PatternKind = 'form-hook' | 'state-management' | 'animation' | 'data-fetching' | 'schema-validation' | 'middleware' | 'composable' | 'testing' | 'generic' | 'structural';
|
|
9
|
+
export interface ExtractedParam {
|
|
10
|
+
name: string;
|
|
11
|
+
slotType: TemplateSlotType;
|
|
12
|
+
value: string;
|
|
13
|
+
optional: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface DetectionResult {
|
|
16
|
+
anchorImport: string;
|
|
17
|
+
startLine: number;
|
|
18
|
+
endLine: number;
|
|
19
|
+
snippet: string;
|
|
20
|
+
extractedParams: ExtractedParam[];
|
|
21
|
+
confidencePct: number;
|
|
22
|
+
}
|
|
23
|
+
export interface DetectorPack {
|
|
24
|
+
id: string;
|
|
25
|
+
libraryName: string;
|
|
26
|
+
packageNames: string[];
|
|
27
|
+
semverRange?: string;
|
|
28
|
+
patternKind: PatternKind;
|
|
29
|
+
detect: (sourceFile: SourceFile, fullText: string) => DetectionResult[];
|
|
30
|
+
}
|
|
31
|
+
export interface PatternGap {
|
|
32
|
+
id: string;
|
|
33
|
+
detectorId: string;
|
|
34
|
+
libraryName: string;
|
|
35
|
+
patternKind: PatternKind;
|
|
36
|
+
anchorImport: string;
|
|
37
|
+
startLine: number;
|
|
38
|
+
endLine: number;
|
|
39
|
+
snippet: string;
|
|
40
|
+
extractedParams: ExtractedParam[];
|
|
41
|
+
confidencePct: number;
|
|
42
|
+
filePath: string;
|
|
43
|
+
}
|
|
44
|
+
export interface ImportDecl {
|
|
45
|
+
from: string;
|
|
46
|
+
names: string[];
|
|
47
|
+
}
|
|
48
|
+
export interface GoldenExample {
|
|
49
|
+
originalTs: string;
|
|
50
|
+
expectedExpansion: string;
|
|
51
|
+
slotValues: Record<string, string>;
|
|
52
|
+
}
|
|
53
|
+
export interface QualityScore {
|
|
54
|
+
confidence: number;
|
|
55
|
+
supportCount: number;
|
|
56
|
+
variability: number;
|
|
57
|
+
relevanceScore: number;
|
|
58
|
+
overallScore: number;
|
|
59
|
+
}
|
|
60
|
+
export interface QualityThresholds {
|
|
61
|
+
minConfidence: number;
|
|
62
|
+
minSupport: number;
|
|
63
|
+
maxVariability: number;
|
|
64
|
+
minRelevance: number;
|
|
65
|
+
}
|
|
66
|
+
export interface AnalyzedPattern {
|
|
67
|
+
templateName: string;
|
|
68
|
+
structuralHash: string;
|
|
69
|
+
namespace: string;
|
|
70
|
+
slots: ExtractedParam[];
|
|
71
|
+
instanceCount: number;
|
|
72
|
+
qualityScore: QualityScore;
|
|
73
|
+
representativeSnippet: string;
|
|
74
|
+
goldenExample: GoldenExample;
|
|
75
|
+
imports: ImportDecl[];
|
|
76
|
+
gapIds: string[];
|
|
77
|
+
}
|
|
78
|
+
export interface TemplateProposal {
|
|
79
|
+
id: string;
|
|
80
|
+
templateName: string;
|
|
81
|
+
namespace: string;
|
|
82
|
+
kernSource: string;
|
|
83
|
+
slots: ExtractedParam[];
|
|
84
|
+
imports: ImportDecl[];
|
|
85
|
+
goldenExample: GoldenExample;
|
|
86
|
+
qualityScore: QualityScore;
|
|
87
|
+
structuralHash: string;
|
|
88
|
+
instanceCount: number;
|
|
89
|
+
representativeSnippet: string;
|
|
90
|
+
}
|
|
91
|
+
export interface ValidationResult {
|
|
92
|
+
parseOk: boolean;
|
|
93
|
+
registerOk: boolean;
|
|
94
|
+
expansionOk: boolean;
|
|
95
|
+
typecheckOk: boolean;
|
|
96
|
+
goldenDiffOk: boolean;
|
|
97
|
+
errors: string[];
|
|
98
|
+
expandedTs?: string;
|
|
99
|
+
goldenDiff?: string;
|
|
100
|
+
}
|
|
101
|
+
export type ProposalStatus = 'pending' | 'approved' | 'rejected';
|
|
102
|
+
export interface StagedProposal {
|
|
103
|
+
id: string;
|
|
104
|
+
proposal: TemplateProposal;
|
|
105
|
+
validation: ValidationResult;
|
|
106
|
+
status: ProposalStatus;
|
|
107
|
+
stagedAt: string;
|
|
108
|
+
reviewedAt?: string;
|
|
109
|
+
}
|
|
110
|
+
export interface EvolveConfig {
|
|
111
|
+
thresholds: QualityThresholds;
|
|
112
|
+
stagingDir: string;
|
|
113
|
+
promotedDir: string;
|
|
114
|
+
templatesDir: string;
|
|
115
|
+
}
|
|
116
|
+
export interface ConceptGapSummary {
|
|
117
|
+
total: number;
|
|
118
|
+
byRule: Record<string, number>;
|
|
119
|
+
formatted: string;
|
|
120
|
+
}
|
|
121
|
+
export interface ExpressibilityScore {
|
|
122
|
+
handlerEscapes: number;
|
|
123
|
+
nonStandardAttrs: number;
|
|
124
|
+
semanticLeaks: number;
|
|
125
|
+
overall: number;
|
|
126
|
+
}
|
|
127
|
+
export interface NodeProposal {
|
|
128
|
+
id: string;
|
|
129
|
+
nodeName: string;
|
|
130
|
+
kernSyntax: string;
|
|
131
|
+
codegenStub: string;
|
|
132
|
+
targetStubs: Record<string, string>;
|
|
133
|
+
expressibilityScore: ExpressibilityScore;
|
|
134
|
+
frequency: number;
|
|
135
|
+
qualityScore: number;
|
|
136
|
+
supportingGapIds: string[];
|
|
137
|
+
}
|
|
138
|
+
export interface NodeValidationResult {
|
|
139
|
+
parseOk: boolean;
|
|
140
|
+
codegenOk: boolean;
|
|
141
|
+
targetCoverage: number;
|
|
142
|
+
errors: string[];
|
|
143
|
+
}
|
|
144
|
+
export type NodeProposalStatus = 'pending' | 'approved' | 'rejected';
|
|
145
|
+
export interface StagedNodeProposal {
|
|
146
|
+
id: string;
|
|
147
|
+
proposal: NodeProposal;
|
|
148
|
+
validation: NodeValidationResult;
|
|
149
|
+
status: NodeProposalStatus;
|
|
150
|
+
stagedAt: string;
|
|
151
|
+
reviewedAt?: string;
|
|
152
|
+
}
|
|
153
|
+
export interface EvolveResult {
|
|
154
|
+
gaps: PatternGap[];
|
|
155
|
+
analyzed: AnalyzedPattern[];
|
|
156
|
+
proposals: TemplateProposal[];
|
|
157
|
+
validated: Array<{
|
|
158
|
+
proposal: TemplateProposal;
|
|
159
|
+
validation: ValidationResult;
|
|
160
|
+
}>;
|
|
161
|
+
staged: StagedProposal[];
|
|
162
|
+
conceptSummary?: ConceptGapSummary;
|
|
163
|
+
nodeProposals?: NodeProposal[];
|
|
164
|
+
nodeValidated?: Array<{
|
|
165
|
+
proposal: NodeProposal;
|
|
166
|
+
validation: NodeValidationResult;
|
|
167
|
+
}>;
|
|
168
|
+
stagedNodes?: StagedNodeProposal[];
|
|
169
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kernlang/evolve",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "Kern Evolve — self-extending template system: detect gaps, propose templates, validate, stage",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"license": "AGPL-3.0",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"ts-morph": "^24.0.0",
|
|
20
|
+
"@kernlang/core": "3.0.0",
|
|
21
|
+
"@kernlang/review": "3.0.0"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc -b",
|
|
25
|
+
"test": "node --experimental-vm-modules ../../node_modules/jest/bin/jest.js --forceExit --config jest.config.js"
|
|
26
|
+
}
|
|
27
|
+
}
|