@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 @@
|
|
|
1
|
+
{"version":3,"file":"graduation.js","sourceRoot":"","sources":["../src/graduation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAc,MAAM,IAAI,CAAC;AACpF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C;;GAEG;AACH,MAAM,UAAU,YAAY,CAC1B,QAA4B,EAC5B,UAAkB,EAClB,cAAsB,MAAM,EAC5B,UAAkB,OAAO,CAAC,GAAG,EAAE;IAE/B,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IACxD,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;IAEnD,8CAA8C;IAC9C,IAAI,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QACxB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,QAAQ,CAAC,OAAO,yCAAyC,EAAE,CAAC;IACvG,CAAC;IAED,IAAI,CAAC;QACH,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IA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B,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;QAErF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC;IAC5E,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAG,GAAa,CAAC,OAAO,EAAE,CAAC;IAC3D,CAAC;AACH,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,UAAkB,EAAE,OAAe;IACpE,MAAM,QAAQ,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC;IAC1C,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC;QAAE,OAAO,KAAK,CAAC;IAC3C,OAAO,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC/B,aAAa,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IACpC,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @kernlang/evolve — Self-extending template system for KERN.
|
|
3
|
+
*
|
|
4
|
+
* Scans TypeScript projects, detects patterns KERN can't yet express,
|
|
5
|
+
* proposes new templates, validates them, and stages for human approval.
|
|
6
|
+
*
|
|
7
|
+
* Public API:
|
|
8
|
+
* evolve(inputPath, options?) — full pipeline: scan → detect → propose → stage
|
|
9
|
+
* evolveSource(source, options?) — single-source analysis
|
|
10
|
+
* registerDetector(pack) — register custom detector
|
|
11
|
+
* loadBuiltinDetectors() — load all built-in detectors
|
|
12
|
+
*/
|
|
13
|
+
export type { PatternKind, DetectorPack, DetectionResult, ExtractedParam, PatternGap, ImportDecl, GoldenExample, QualityScore, QualityThresholds, AnalyzedPattern, TemplateProposal, ValidationResult, ProposalStatus, StagedProposal, EvolveConfig, EvolveResult, ConceptGapSummary, ExpressibilityScore, NodeProposal, NodeValidationResult, NodeProposalStatus, StagedNodeProposal, } from './types.js';
|
|
14
|
+
export { registerDetector, unregisterDetector, getDetector, getAllDetectors, getDetectorsForImport, getUniversalDetectors, clearDetectors, detectorCount, loadBuiltinDetectors, registerDetectors, } from './detector-registry.js';
|
|
15
|
+
export { detectGaps, detectGapsInFiles, detectGapsFromSource, resetGapIds } from './gap-detector.js';
|
|
16
|
+
export { detectConceptualGaps, resetConceptGapIds } from './concept-gap-adapter.js';
|
|
17
|
+
export { scorePattern, passesThresholds, DEFAULT_THRESHOLDS } from './quality-scorer.js';
|
|
18
|
+
export { analyzePatterns, analyzeStructuralPatterns, computeStructuralHash, deriveTemplateName } from './pattern-analyzer.js';
|
|
19
|
+
export { proposeTemplates, generateKernSource } from './template-proposer.js';
|
|
20
|
+
export { validateProposal } from './template-validator.js';
|
|
21
|
+
export { stageProposal, listStaged, getStaged, updateStagedStatus, promoteLocal, cleanRejected, formatSplitView, stageNodeProposal, listStagedNodes, updateStagedNodeStatus, formatNodeSplitView, stageEvolveV4Proposal, listStagedEvolveV4, getStagedEvolveV4, updateStagedEvolveV4Status, cleanRejectedEvolveV4, cleanApprovedEvolveV4, formatEvolveV4SplitView, } from './staging.js';
|
|
22
|
+
export { scoreExpressibility, isNodeCandidate, EXPRESSIBILITY_NODE_THRESHOLD, } from './expressibility-scorer.js';
|
|
23
|
+
export { proposeNodes, deriveNodeName as deriveNodeProposalName, resetNodeProposalIds } from './node-proposer.js';
|
|
24
|
+
export { governanceGate, getGovernanceThresholds } from './node-governance.js';
|
|
25
|
+
export { validateNodeProposal } from './node-validator.js';
|
|
26
|
+
export { evolve, evolveSource } from './evolve-runner.js';
|
|
27
|
+
export type { EvolveOptions } from './evolve-runner.js';
|
|
28
|
+
export type { ParserHints, EvolvedNodeDefinition, EvolvedNodeProp, EvolvedNodeReason, EvolvedManifest, EvolvedManifestEntry, EvolveNodeProposal, EvolveV4ValidationResult, EvolveV4ProposalStatus, StagedEvolveProposal, CodegenHelpers, } from './evolved-types.js';
|
|
29
|
+
export { loadEvolvedNodes, clearEvolvedNodes, getEvolvedGenerator, getParserHints as getEvolvedParserHints, hasEvolvedNodes, evolvedNodeCount, getEvolvedKeywords, readManifest as readEvolvedManifest, readNodeDefinition, rebuildManifest as rebuildEvolvedManifest, } from './evolved-node-loader.js';
|
|
30
|
+
export type { RebuildResult } from './evolved-node-loader.js';
|
|
31
|
+
export { loadSandboxedGenerator, compileSandboxedGenerator, getCodegenHelpers } from './sandboxed-generator.js';
|
|
32
|
+
export { validateEvolveProposal } from './evolve-validator-v4.js';
|
|
33
|
+
export { checkDedup } from './evolve-dedup.js';
|
|
34
|
+
export { compareGoldenOutput, runGoldenTests, formatGoldenTestResults } from './golden-test-runner.js';
|
|
35
|
+
export { graduateNode, compileCodegenToJS, promoteNode } from './graduation.js';
|
|
36
|
+
export { rollbackNode, restoreNode, findUsages, pruneNodes, detectCollisions, renameEvolvedNode } from './evolve-rollback.js';
|
|
37
|
+
export type { PruneResult, CollisionInfo } from './evolve-rollback.js';
|
|
38
|
+
export { buildDiscoveryPrompt, parseDiscoveryResponse, selectRepresentativeFiles, collectTsFiles, estimateTokens, buildBackfillPrompt, buildRetryPrompt } from './llm-discovery.js';
|
|
39
|
+
export { createLLMProvider, TokenBudget } from './llm-provider.js';
|
|
40
|
+
export type { LLMProvider, LLMProviderOptions } from './llm-provider.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @kernlang/evolve — Self-extending template system for KERN.
|
|
3
|
+
*
|
|
4
|
+
* Scans TypeScript projects, detects patterns KERN can't yet express,
|
|
5
|
+
* proposes new templates, validates them, and stages for human approval.
|
|
6
|
+
*
|
|
7
|
+
* Public API:
|
|
8
|
+
* evolve(inputPath, options?) — full pipeline: scan → detect → propose → stage
|
|
9
|
+
* evolveSource(source, options?) — single-source analysis
|
|
10
|
+
* registerDetector(pack) — register custom detector
|
|
11
|
+
* loadBuiltinDetectors() — load all built-in detectors
|
|
12
|
+
*/
|
|
13
|
+
// Detector Registry
|
|
14
|
+
export { registerDetector, unregisterDetector, getDetector, getAllDetectors, getDetectorsForImport, getUniversalDetectors, clearDetectors, detectorCount, loadBuiltinDetectors, registerDetectors, } from './detector-registry.js';
|
|
15
|
+
// Gap Detector
|
|
16
|
+
export { detectGaps, detectGapsInFiles, detectGapsFromSource, resetGapIds } from './gap-detector.js';
|
|
17
|
+
// Concept Gap Adapter
|
|
18
|
+
export { detectConceptualGaps, resetConceptGapIds } from './concept-gap-adapter.js';
|
|
19
|
+
// Quality Scorer
|
|
20
|
+
export { scorePattern, passesThresholds, DEFAULT_THRESHOLDS } from './quality-scorer.js';
|
|
21
|
+
// Pattern Analyzer
|
|
22
|
+
export { analyzePatterns, analyzeStructuralPatterns, computeStructuralHash, deriveTemplateName } from './pattern-analyzer.js';
|
|
23
|
+
// Template Proposer
|
|
24
|
+
export { proposeTemplates, generateKernSource } from './template-proposer.js';
|
|
25
|
+
// Template Validator
|
|
26
|
+
export { validateProposal } from './template-validator.js';
|
|
27
|
+
// Staging
|
|
28
|
+
export { stageProposal, listStaged, getStaged, updateStagedStatus, promoteLocal, cleanRejected, formatSplitView,
|
|
29
|
+
// v3 node staging
|
|
30
|
+
stageNodeProposal, listStagedNodes, updateStagedNodeStatus, formatNodeSplitView,
|
|
31
|
+
// v4 evolve staging
|
|
32
|
+
stageEvolveV4Proposal, listStagedEvolveV4, getStagedEvolveV4, updateStagedEvolveV4Status, cleanRejectedEvolveV4, cleanApprovedEvolveV4, formatEvolveV4SplitView, } from './staging.js';
|
|
33
|
+
// Expressibility Scorer (v3)
|
|
34
|
+
export { scoreExpressibility, isNodeCandidate, EXPRESSIBILITY_NODE_THRESHOLD, } from './expressibility-scorer.js';
|
|
35
|
+
// Node Proposer (v3)
|
|
36
|
+
export { proposeNodes, deriveNodeName as deriveNodeProposalName, resetNodeProposalIds } from './node-proposer.js';
|
|
37
|
+
// Node Governance (v3)
|
|
38
|
+
export { governanceGate, getGovernanceThresholds } from './node-governance.js';
|
|
39
|
+
// Node Validator (v3)
|
|
40
|
+
export { validateNodeProposal } from './node-validator.js';
|
|
41
|
+
// Evolve Runner (main entry points)
|
|
42
|
+
export { evolve, evolveSource } from './evolve-runner.js';
|
|
43
|
+
// Evolved Node Loader
|
|
44
|
+
export { loadEvolvedNodes, clearEvolvedNodes, getEvolvedGenerator, getParserHints as getEvolvedParserHints, hasEvolvedNodes, evolvedNodeCount, getEvolvedKeywords, readManifest as readEvolvedManifest, readNodeDefinition, rebuildManifest as rebuildEvolvedManifest, } from './evolved-node-loader.js';
|
|
45
|
+
// Sandboxed Generator
|
|
46
|
+
export { loadSandboxedGenerator, compileSandboxedGenerator, getCodegenHelpers } from './sandboxed-generator.js';
|
|
47
|
+
// v4 Validation
|
|
48
|
+
export { validateEvolveProposal } from './evolve-validator-v4.js';
|
|
49
|
+
export { checkDedup } from './evolve-dedup.js';
|
|
50
|
+
export { compareGoldenOutput, runGoldenTests, formatGoldenTestResults } from './golden-test-runner.js';
|
|
51
|
+
// Graduation
|
|
52
|
+
export { graduateNode, compileCodegenToJS, promoteNode } from './graduation.js';
|
|
53
|
+
// Rollback + Prune + Migrate
|
|
54
|
+
export { rollbackNode, restoreNode, findUsages, pruneNodes, detectCollisions, renameEvolvedNode } from './evolve-rollback.js';
|
|
55
|
+
// LLM Discovery
|
|
56
|
+
export { buildDiscoveryPrompt, parseDiscoveryResponse, selectRepresentativeFiles, collectTsFiles, estimateTokens, buildBackfillPrompt, buildRetryPrompt } from './llm-discovery.js';
|
|
57
|
+
export { createLLMProvider, TokenBudget } from './llm-provider.js';
|
|
58
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AA6BH,oBAAoB;AACpB,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB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
|
3
|
+
*
|
|
4
|
+
* No hardcoded detectors. The LLM reads TypeScript source files and
|
|
5
|
+
* identifies repeating patterns that KERN can't yet express.
|
|
6
|
+
*
|
|
7
|
+
* Offline-safe: this module only constructs prompts and parses responses.
|
|
8
|
+
* The actual LLM call is handled by llm-provider.ts.
|
|
9
|
+
*/
|
|
10
|
+
import type { EvolveNodeProposal, EvolvedNodeProp } from './evolved-types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Select representative TypeScript files, clustered by directory.
|
|
13
|
+
* Returns batches of 3-5 files suitable for LLM context.
|
|
14
|
+
*
|
|
15
|
+
* @param filePaths — all .ts/.tsx files in the project
|
|
16
|
+
* @param maxPerCluster — max files to sample per directory (default: 3)
|
|
17
|
+
* @param maxBatchSize — max files per LLM batch (default: 5)
|
|
18
|
+
*/
|
|
19
|
+
export declare function selectRepresentativeFiles(filePaths: string[], maxPerCluster?: number, maxBatchSize?: number): string[][];
|
|
20
|
+
/**
|
|
21
|
+
* Collect all TypeScript files from a directory (recursive).
|
|
22
|
+
* Skips node_modules, dist, .files, test files, and .d.ts files.
|
|
23
|
+
*/
|
|
24
|
+
export declare function collectTsFiles(dir: string, recursive?: boolean): string[];
|
|
25
|
+
/**
|
|
26
|
+
* Build the LLM discovery prompt for a batch of files.
|
|
27
|
+
*/
|
|
28
|
+
export declare function buildDiscoveryPrompt(files: Array<{
|
|
29
|
+
path: string;
|
|
30
|
+
content: string;
|
|
31
|
+
}>, nodeTypes: readonly string[], evolvedKeywords?: string[]): string;
|
|
32
|
+
/**
|
|
33
|
+
* Parse the LLM response into EvolveNodeProposal[].
|
|
34
|
+
* Handles common LLM quirks: markdown fences, preamble, trailing text.
|
|
35
|
+
*/
|
|
36
|
+
export declare function parseDiscoveryResponse(response: string, evolveRunId?: string): EvolveNodeProposal[];
|
|
37
|
+
/**
|
|
38
|
+
* Estimate token count for a string (rough: 1 token ≈ 4 chars).
|
|
39
|
+
*/
|
|
40
|
+
export declare function estimateTokens(text: string): number;
|
|
41
|
+
/**
|
|
42
|
+
* Build a prompt asking the LLM to fix a failed proposal.
|
|
43
|
+
* Feeds back the validation errors so the LLM can correct its output.
|
|
44
|
+
*/
|
|
45
|
+
export declare function buildRetryPrompt(proposal: EvolveNodeProposal, errors: string[]): string;
|
|
46
|
+
/**
|
|
47
|
+
* Build a prompt for LLM to generate a target-specific codegen for an evolved node.
|
|
48
|
+
*/
|
|
49
|
+
export declare function buildBackfillPrompt(keyword: string, definition: {
|
|
50
|
+
props: EvolvedNodeProp[];
|
|
51
|
+
childTypes: string[];
|
|
52
|
+
kernExample: string;
|
|
53
|
+
codegenSource: string;
|
|
54
|
+
expectedOutput: string;
|
|
55
|
+
}, target: string): string;
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM Discovery — universal pattern recognition for KERN Evolve v4.
|
|
3
|
+
*
|
|
4
|
+
* No hardcoded detectors. The LLM reads TypeScript source files and
|
|
5
|
+
* identifies repeating patterns that KERN can't yet express.
|
|
6
|
+
*
|
|
7
|
+
* Offline-safe: this module only constructs prompts and parses responses.
|
|
8
|
+
* The actual LLM call is handled by llm-provider.ts.
|
|
9
|
+
*/
|
|
10
|
+
import { readdirSync, statSync } from 'fs';
|
|
11
|
+
import { resolve, join, dirname } from 'path';
|
|
12
|
+
// ── File Selection ───────────────────────────────────────────────────────
|
|
13
|
+
/**
|
|
14
|
+
* Select representative TypeScript files, clustered by directory.
|
|
15
|
+
* Returns batches of 3-5 files suitable for LLM context.
|
|
16
|
+
*
|
|
17
|
+
* @param filePaths — all .ts/.tsx files in the project
|
|
18
|
+
* @param maxPerCluster — max files to sample per directory (default: 3)
|
|
19
|
+
* @param maxBatchSize — max files per LLM batch (default: 5)
|
|
20
|
+
*/
|
|
21
|
+
export function selectRepresentativeFiles(filePaths, maxPerCluster = 3, maxBatchSize = 5) {
|
|
22
|
+
// Cluster by parent directory
|
|
23
|
+
const clusters = new Map();
|
|
24
|
+
for (const fp of filePaths) {
|
|
25
|
+
const dir = dirname(fp);
|
|
26
|
+
const cluster = clusters.get(dir) || [];
|
|
27
|
+
cluster.push(fp);
|
|
28
|
+
clusters.set(dir, cluster);
|
|
29
|
+
}
|
|
30
|
+
// Sample from each cluster: pick diverse files (by size variance)
|
|
31
|
+
const sampled = [];
|
|
32
|
+
for (const [dir, files] of clusters) {
|
|
33
|
+
// Sort by file size (descending) to get diverse samples
|
|
34
|
+
const sorted = [...files].sort((a, b) => {
|
|
35
|
+
try {
|
|
36
|
+
return statSync(b).size - statSync(a).size;
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
// Take up to maxPerCluster, spread across the size range
|
|
43
|
+
const take = Math.min(sorted.length, maxPerCluster);
|
|
44
|
+
if (take <= 2) {
|
|
45
|
+
sampled.push(...sorted.slice(0, take));
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// First, middle, last for diversity
|
|
49
|
+
const step = Math.floor((sorted.length - 1) / (take - 1));
|
|
50
|
+
for (let i = 0; i < take; i++) {
|
|
51
|
+
const idx = Math.min(i * step, sorted.length - 1);
|
|
52
|
+
sampled.push(sorted[idx]);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// Group into batches
|
|
57
|
+
const batches = [];
|
|
58
|
+
for (let i = 0; i < sampled.length; i += maxBatchSize) {
|
|
59
|
+
batches.push(sampled.slice(i, i + maxBatchSize));
|
|
60
|
+
}
|
|
61
|
+
return batches;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Collect all TypeScript files from a directory (recursive).
|
|
65
|
+
* Skips node_modules, dist, .files, test files, and .d.ts files.
|
|
66
|
+
*/
|
|
67
|
+
export function collectTsFiles(dir, recursive = true) {
|
|
68
|
+
const files = [];
|
|
69
|
+
function walk(d) {
|
|
70
|
+
try {
|
|
71
|
+
for (const entry of readdirSync(d, { withFileTypes: true })) {
|
|
72
|
+
if (entry.name.startsWith('.') || entry.name === 'node_modules' || entry.name === 'dist')
|
|
73
|
+
continue;
|
|
74
|
+
const full = join(d, entry.name);
|
|
75
|
+
if (entry.isDirectory() && recursive) {
|
|
76
|
+
walk(full);
|
|
77
|
+
}
|
|
78
|
+
else if ((entry.name.endsWith('.ts') || entry.name.endsWith('.tsx')) &&
|
|
79
|
+
!entry.name.endsWith('.d.ts') &&
|
|
80
|
+
!entry.name.endsWith('.test.ts') &&
|
|
81
|
+
!entry.name.endsWith('.test.tsx') &&
|
|
82
|
+
!entry.name.endsWith('.spec.ts')) {
|
|
83
|
+
files.push(full);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch { // file may not exist
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
walk(resolve(dir));
|
|
91
|
+
return files;
|
|
92
|
+
}
|
|
93
|
+
// ── Prompt Construction ──────────────────────────────────────────────────
|
|
94
|
+
/**
|
|
95
|
+
* Build the LLM discovery prompt for a batch of files.
|
|
96
|
+
*/
|
|
97
|
+
export function buildDiscoveryPrompt(files, nodeTypes, evolvedKeywords = []) {
|
|
98
|
+
const fileBlocks = files.map(f => `### ${f.path}\n\`\`\`typescript\n${truncate(f.content, 3000)}\n\`\`\``).join('\n\n');
|
|
99
|
+
const existingNodes = [...nodeTypes, ...evolvedKeywords].join(', ');
|
|
100
|
+
return `You are analyzing TypeScript source files to find repeating structural patterns that a language called KERN cannot yet express.
|
|
101
|
+
|
|
102
|
+
KERN is an indent-based IR language that compiles to TypeScript. It has these existing node types:
|
|
103
|
+
${existingNodes}
|
|
104
|
+
|
|
105
|
+
## Source Files to Analyze
|
|
106
|
+
|
|
107
|
+
${fileBlocks}
|
|
108
|
+
|
|
109
|
+
## Your Task
|
|
110
|
+
|
|
111
|
+
Identify **repeating structural patterns** in these files that:
|
|
112
|
+
1. Appear 2+ times (across these files or clearly would across a larger codebase)
|
|
113
|
+
2. Cannot be expressed by any existing KERN node type listed above
|
|
114
|
+
3. Have a clear structural template (not just random code)
|
|
115
|
+
4. Would benefit from a first-class language construct (saves boilerplate, enforces consistency)
|
|
116
|
+
|
|
117
|
+
## Response Format
|
|
118
|
+
|
|
119
|
+
Respond with a JSON array. Each element represents one proposed node:
|
|
120
|
+
|
|
121
|
+
\`\`\`json
|
|
122
|
+
[
|
|
123
|
+
{
|
|
124
|
+
"keyword": "lowercase-with-hyphens",
|
|
125
|
+
"displayName": "Human Readable Name",
|
|
126
|
+
"description": "What this node represents",
|
|
127
|
+
"props": [
|
|
128
|
+
{ "name": "propName", "type": "string", "required": true, "description": "What this prop does" }
|
|
129
|
+
],
|
|
130
|
+
"childTypes": ["child-type-if-any"],
|
|
131
|
+
"kernExample": "keyword prop1=value1 prop2=value2\\n child-type prop=value",
|
|
132
|
+
"expectedOutput": "export const example = { /* generated TS */ };",
|
|
133
|
+
"codegenSource": "module.exports = function(node, helpers) {\\n var name = helpers.p(node).name;\\n return ['export const ' + name + ' = {};'];\\n};",
|
|
134
|
+
"reason": {
|
|
135
|
+
"observation": "Found N instances of this pattern in the analyzed files",
|
|
136
|
+
"inefficiency": "Each instance requires M lines of boilerplate",
|
|
137
|
+
"kernBenefit": "Reduces to K lines of KERN, ensures consistency"
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
]
|
|
141
|
+
\`\`\`
|
|
142
|
+
|
|
143
|
+
## Critical Rules
|
|
144
|
+
|
|
145
|
+
1. **codegenSource MUST be valid CommonJS JavaScript** (not TypeScript). Use \`module.exports = function(node, helpers) { ... }\`. The function receives an AST node and helpers object.
|
|
146
|
+
2. **Available helpers:** \`helpers.p(node)\` returns props, \`helpers.kids(node, 'type')\` returns children of type, \`helpers.firstChild(node, 'type')\`, \`helpers.capitalize(str)\`, \`helpers.parseParamList(str)\`, \`helpers.dedent(str)\`, \`helpers.handlerCode(node)\`, \`helpers.exportPrefix(node)\`.
|
|
147
|
+
3. **The function must return string[]** — an array of lines of TypeScript code.
|
|
148
|
+
4. **kernExample must parse** with KERN's indent-based parser (2-space indents, key=value props, no special syntax).
|
|
149
|
+
5. **expectedOutput must be the TypeScript** that codegenSource would produce for kernExample.
|
|
150
|
+
6. **keyword must be lowercase with hyphens**, not colliding with existing node types.
|
|
151
|
+
7. **Return an empty array []** if no valid patterns are found. Do not hallucinate patterns.
|
|
152
|
+
8. **Only return the JSON array.** No markdown, no explanation, no preamble.`;
|
|
153
|
+
}
|
|
154
|
+
// ── Response Parsing ─────────────────────────────────────────────────────
|
|
155
|
+
/**
|
|
156
|
+
* Parse the LLM response into EvolveNodeProposal[].
|
|
157
|
+
* Handles common LLM quirks: markdown fences, preamble, trailing text.
|
|
158
|
+
*/
|
|
159
|
+
export function parseDiscoveryResponse(response, evolveRunId = `run-${Date.now()}`) {
|
|
160
|
+
// Strip markdown fences
|
|
161
|
+
let json = response.trim();
|
|
162
|
+
const fenceMatch = json.match(/```(?:json)?\s*\n?([\s\S]*?)```/);
|
|
163
|
+
if (fenceMatch) {
|
|
164
|
+
json = fenceMatch[1].trim();
|
|
165
|
+
}
|
|
166
|
+
// Try to find JSON array boundaries
|
|
167
|
+
const arrayStart = json.indexOf('[');
|
|
168
|
+
const arrayEnd = json.lastIndexOf(']');
|
|
169
|
+
if (arrayStart === -1 || arrayEnd === -1 || arrayEnd <= arrayStart) {
|
|
170
|
+
return [];
|
|
171
|
+
}
|
|
172
|
+
json = json.slice(arrayStart, arrayEnd + 1);
|
|
173
|
+
let parsed;
|
|
174
|
+
try {
|
|
175
|
+
parsed = JSON.parse(json);
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
return [];
|
|
179
|
+
}
|
|
180
|
+
if (!Array.isArray(parsed))
|
|
181
|
+
return [];
|
|
182
|
+
const proposals = [];
|
|
183
|
+
for (const item of parsed) {
|
|
184
|
+
try {
|
|
185
|
+
const p = normalizeProposal(item, evolveRunId);
|
|
186
|
+
if (p)
|
|
187
|
+
proposals.push(p);
|
|
188
|
+
}
|
|
189
|
+
catch (err) {
|
|
190
|
+
// Malformed LLM response entry — log and continue
|
|
191
|
+
if (process.env.KERN_DEBUG)
|
|
192
|
+
console.warn('Skipping malformed proposal entry:', err.message);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return proposals;
|
|
196
|
+
}
|
|
197
|
+
function normalizeProposal(raw, evolveRunId) {
|
|
198
|
+
const keyword = raw.keyword;
|
|
199
|
+
if (!keyword || typeof keyword !== 'string')
|
|
200
|
+
return null;
|
|
201
|
+
// Normalize keyword to lowercase with hyphens
|
|
202
|
+
const normalizedKeyword = keyword.toLowerCase().replace(/[^a-z0-9-]/g, '-').replace(/-+/g, '-').replace(/^-|-$/g, '');
|
|
203
|
+
if (!normalizedKeyword)
|
|
204
|
+
return null;
|
|
205
|
+
const reason = raw.reason || {};
|
|
206
|
+
return {
|
|
207
|
+
id: `proposal-${normalizedKeyword}-${Date.now()}`,
|
|
208
|
+
keyword: normalizedKeyword,
|
|
209
|
+
displayName: raw.displayName || normalizedKeyword,
|
|
210
|
+
description: raw.description || '',
|
|
211
|
+
props: normalizeProps(raw.props),
|
|
212
|
+
childTypes: Array.isArray(raw.childTypes) ? raw.childTypes.filter((c) => typeof c === 'string') : [],
|
|
213
|
+
kernExample: raw.kernExample || '',
|
|
214
|
+
expectedOutput: raw.expectedOutput || '',
|
|
215
|
+
codegenSource: raw.codegenSource || '',
|
|
216
|
+
parserHints: undefined,
|
|
217
|
+
targetOverrides: undefined,
|
|
218
|
+
reason: {
|
|
219
|
+
observation: reason.observation || '',
|
|
220
|
+
inefficiency: reason.inefficiency || '',
|
|
221
|
+
kernBenefit: reason.kernBenefit || '',
|
|
222
|
+
frequency: reason.frequency || 0,
|
|
223
|
+
avgLines: reason.avgLines || 0,
|
|
224
|
+
instances: Array.isArray(reason.instances) ? reason.instances : [],
|
|
225
|
+
},
|
|
226
|
+
codegenTier: 1,
|
|
227
|
+
proposedAt: new Date().toISOString(),
|
|
228
|
+
evolveRunId,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function normalizeProps(raw) {
|
|
232
|
+
if (!Array.isArray(raw))
|
|
233
|
+
return [];
|
|
234
|
+
return raw
|
|
235
|
+
.filter((p) => p !== null && typeof p === 'object')
|
|
236
|
+
.map(p => ({
|
|
237
|
+
name: p.name || 'unknown',
|
|
238
|
+
type: (['string', 'boolean', 'number', 'expression'].includes(p.type) ? p.type : 'string'),
|
|
239
|
+
required: p.required === true,
|
|
240
|
+
description: p.description || '',
|
|
241
|
+
}));
|
|
242
|
+
}
|
|
243
|
+
// ── Utility ──────────────────────────────────────────────────────────────
|
|
244
|
+
function truncate(content, maxChars) {
|
|
245
|
+
if (content.length <= maxChars)
|
|
246
|
+
return content;
|
|
247
|
+
return content.slice(0, maxChars) + '\n// ... truncated ...';
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Estimate token count for a string (rough: 1 token ≈ 4 chars).
|
|
251
|
+
*/
|
|
252
|
+
export function estimateTokens(text) {
|
|
253
|
+
return Math.ceil(text.length / 4);
|
|
254
|
+
}
|
|
255
|
+
// ── Retry Prompt ──────────────────────────────────────────────────────────
|
|
256
|
+
/**
|
|
257
|
+
* Build a prompt asking the LLM to fix a failed proposal.
|
|
258
|
+
* Feeds back the validation errors so the LLM can correct its output.
|
|
259
|
+
*/
|
|
260
|
+
export function buildRetryPrompt(proposal, errors) {
|
|
261
|
+
return `Your previous KERN node proposal "${proposal.keyword}" failed validation. Fix the issues and return the corrected proposal.
|
|
262
|
+
|
|
263
|
+
## Previous Proposal
|
|
264
|
+
|
|
265
|
+
keyword: ${proposal.keyword}
|
|
266
|
+
kernExample: ${proposal.kernExample}
|
|
267
|
+
expectedOutput: ${proposal.expectedOutput}
|
|
268
|
+
codegenSource:
|
|
269
|
+
${proposal.codegenSource}
|
|
270
|
+
|
|
271
|
+
## Validation Errors
|
|
272
|
+
|
|
273
|
+
${errors.map((e, i) => `${i + 1}. ${e}`).join('\n')}
|
|
274
|
+
|
|
275
|
+
## Rules
|
|
276
|
+
|
|
277
|
+
1. **codegenSource MUST be valid CommonJS JavaScript** (not TypeScript). Use \`module.exports = function(node, helpers) { ... }\`.
|
|
278
|
+
2. **Available helpers:** \`helpers.p(node)\` returns props, \`helpers.kids(node, 'type')\`, \`helpers.firstChild(node, 'type')\`, \`helpers.capitalize(str)\`, \`helpers.parseParamList(str)\`, \`helpers.dedent(str)\`, \`helpers.handlerCode(node)\`, \`helpers.exportPrefix(node)\`.
|
|
279
|
+
3. **The function must return string[]** — an array of lines of TypeScript code.
|
|
280
|
+
4. **kernExample must parse** with KERN's indent-based parser (2-space indents, key=value props).
|
|
281
|
+
5. **expectedOutput must match** what codegenSource produces for kernExample.
|
|
282
|
+
|
|
283
|
+
## Response Format
|
|
284
|
+
|
|
285
|
+
Return ONLY the corrected JSON object (same schema as before):
|
|
286
|
+
|
|
287
|
+
\`\`\`json
|
|
288
|
+
{
|
|
289
|
+
"keyword": "${proposal.keyword}",
|
|
290
|
+
"displayName": "${proposal.displayName}",
|
|
291
|
+
"description": "${proposal.description}",
|
|
292
|
+
"props": ${JSON.stringify(proposal.props)},
|
|
293
|
+
"childTypes": ${JSON.stringify(proposal.childTypes)},
|
|
294
|
+
"kernExample": "...",
|
|
295
|
+
"expectedOutput": "...",
|
|
296
|
+
"codegenSource": "module.exports = function(node, helpers) { ... }",
|
|
297
|
+
"reason": ${JSON.stringify(proposal.reason)}
|
|
298
|
+
}
|
|
299
|
+
\`\`\`
|
|
300
|
+
|
|
301
|
+
No markdown outside the JSON block. No explanation.`;
|
|
302
|
+
}
|
|
303
|
+
// ── Backfill Prompt ───────────────────────────────────────────────────────
|
|
304
|
+
/**
|
|
305
|
+
* Build a prompt for LLM to generate a target-specific codegen for an evolved node.
|
|
306
|
+
*/
|
|
307
|
+
export function buildBackfillPrompt(keyword, definition, target) {
|
|
308
|
+
return `You are generating a target-specific code generator for a KERN evolved node.
|
|
309
|
+
|
|
310
|
+
## Node: ${keyword}
|
|
311
|
+
Target: ${target}
|
|
312
|
+
|
|
313
|
+
## Props
|
|
314
|
+
${definition.props.map(p => `- ${p.name} (${p.type}${p.required ? ', required' : ''}): ${p.description}`).join('\n')}
|
|
315
|
+
|
|
316
|
+
## Child Types
|
|
317
|
+
${definition.childTypes.join(', ') || '(none)'}
|
|
318
|
+
|
|
319
|
+
## KERN Example Input
|
|
320
|
+
\`\`\`kern
|
|
321
|
+
${definition.kernExample}
|
|
322
|
+
\`\`\`
|
|
323
|
+
|
|
324
|
+
## Default Codegen (TypeScript target)
|
|
325
|
+
\`\`\`javascript
|
|
326
|
+
${definition.codegenSource}
|
|
327
|
+
\`\`\`
|
|
328
|
+
|
|
329
|
+
## Default Output (TypeScript)
|
|
330
|
+
\`\`\`typescript
|
|
331
|
+
${definition.expectedOutput}
|
|
332
|
+
\`\`\`
|
|
333
|
+
|
|
334
|
+
## Your Task
|
|
335
|
+
|
|
336
|
+
Write a **CommonJS JavaScript** function that generates **${target}**-specific output for this node. The function receives \`(node, helpers)\` and must return \`string[]\` (lines of code).
|
|
337
|
+
|
|
338
|
+
Available helpers: \`helpers.p(node)\` (props), \`helpers.kids(node, 'type')\` (children), \`helpers.firstChild(node, 'type')\`, \`helpers.capitalize(str)\`, \`helpers.parseParamList(str)\`, \`helpers.dedent(str)\`, \`helpers.handlerCode(node)\`, \`helpers.exportPrefix(node)\`.
|
|
339
|
+
|
|
340
|
+
## Response Format
|
|
341
|
+
|
|
342
|
+
Return ONLY a JSON object:
|
|
343
|
+
\`\`\`json
|
|
344
|
+
{
|
|
345
|
+
"codegenSource": "module.exports = function(node, helpers) { ... }",
|
|
346
|
+
"expectedOutput": "// expected output for the kern example above"
|
|
347
|
+
}
|
|
348
|
+
\`\`\`
|
|
349
|
+
|
|
350
|
+
No markdown, no explanation, just the JSON object.`;
|
|
351
|
+
}
|
|
352
|
+
//# sourceMappingURL=llm-discovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm-discovery.js","sourceRoot":"","sources":["../src/llm-discovery.ts"],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,QAAQ,CAAC,UAAU,CAAC;;;;cAIvC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC;;;;oDAIO,CAAC;AACrD,CAAC;AAED,6EAA6E;AAE7E;;GAEG;AACH,MAAM,UAAU,mBAAmB,CACjC,OAAe,EACf,UAMC,EACD,MAAc;IAEd,OAAO;;WAEE,OAAO;UACR,MAAM;;;EAGd,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;;;EAGlH,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,QAAQ;;;;EAI5C,UAAU,CAAC,WAAW;;;;;EAKtB,UAAU,CAAC,aAAa;;;;;EAKxB,UAAU,CAAC,cAAc;;;;;4DAKiC,MAAM;;;;;;;;;;;;;;mDAcf,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM Provider — abstraction over OpenAI, Anthropic, and local models.
|
|
3
|
+
*
|
|
4
|
+
* Used only by `kern evolve discover` and `kern evolve backfill`.
|
|
5
|
+
* Never called during compilation.
|
|
6
|
+
*/
|
|
7
|
+
export interface LLMProvider {
|
|
8
|
+
name: string;
|
|
9
|
+
complete(prompt: string): Promise<string>;
|
|
10
|
+
}
|
|
11
|
+
export interface LLMProviderOptions {
|
|
12
|
+
provider?: 'openai' | 'anthropic' | 'ollama';
|
|
13
|
+
model?: string;
|
|
14
|
+
maxTokens?: number;
|
|
15
|
+
apiKey?: string;
|
|
16
|
+
baseUrl?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Create an LLM provider based on configuration.
|
|
20
|
+
* Checks environment variables for API keys.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createLLMProvider(options?: LLMProviderOptions): LLMProvider;
|
|
23
|
+
/**
|
|
24
|
+
* Track token usage for cost estimation.
|
|
25
|
+
*/
|
|
26
|
+
export declare class TokenBudget {
|
|
27
|
+
readonly limit: number;
|
|
28
|
+
private used;
|
|
29
|
+
constructor(limit: number);
|
|
30
|
+
add(tokens: number): void;
|
|
31
|
+
get remaining(): number;
|
|
32
|
+
get exhausted(): boolean;
|
|
33
|
+
get totalUsed(): number;
|
|
34
|
+
toString(): string;
|
|
35
|
+
}
|