kern-lang 1.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/README.md +304 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +244 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +46 -0
- package/dist/config.js +54 -0
- package/dist/config.js.map +1 -0
- package/dist/context-export.d.ts +11 -0
- package/dist/context-export.js +121 -0
- package/dist/context-export.js.map +1 -0
- package/dist/decompiler.d.ts +2 -0
- package/dist/decompiler.js +44 -0
- package/dist/decompiler.js.map +1 -0
- package/dist/draft-protocol.d.ts +27 -0
- package/dist/draft-protocol.js +135 -0
- package/dist/draft-protocol.js.map +1 -0
- package/dist/errors.d.ts +12 -0
- package/dist/errors.js +40 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/metrics.d.ts +30 -0
- package/dist/metrics.js +182 -0
- package/dist/metrics.js.map +1 -0
- package/dist/parser.d.ts +4 -0
- package/dist/parser.js +361 -0
- package/dist/parser.js.map +1 -0
- package/dist/spec.d.ts +17 -0
- package/dist/spec.js +86 -0
- package/dist/spec.js.map +1 -0
- package/dist/styles-react.d.ts +3 -0
- package/dist/styles-react.js +20 -0
- package/dist/styles-react.js.map +1 -0
- package/dist/styles-tailwind.d.ts +8 -0
- package/dist/styles-tailwind.js +197 -0
- package/dist/styles-tailwind.js.map +1 -0
- package/dist/transpiler-cli.d.ts +3 -0
- package/dist/transpiler-cli.js +279 -0
- package/dist/transpiler-cli.js.map +1 -0
- package/dist/transpiler-express.d.ts +3 -0
- package/dist/transpiler-express.js +612 -0
- package/dist/transpiler-express.js.map +1 -0
- package/dist/transpiler-nextjs.d.ts +21 -0
- package/dist/transpiler-nextjs.js +400 -0
- package/dist/transpiler-nextjs.js.map +1 -0
- package/dist/transpiler-tailwind.d.ts +3 -0
- package/dist/transpiler-tailwind.js +594 -0
- package/dist/transpiler-tailwind.js.map +1 -0
- package/dist/transpiler-terminal.d.ts +3 -0
- package/dist/transpiler-terminal.js +522 -0
- package/dist/transpiler-terminal.js.map +1 -0
- package/dist/transpiler-web.d.ts +3 -0
- package/dist/transpiler-web.js +218 -0
- package/dist/transpiler-web.js.map +1 -0
- package/dist/transpiler.d.ts +3 -0
- package/dist/transpiler.js +218 -0
- package/dist/transpiler.js.map +1 -0
- package/dist/types.d.ts +76 -0
- package/dist/types.js +11 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +5 -0
- package/dist/utils.js +36 -0
- package/dist/utils.js.map +1 -0
- package/kern.config.ts +61 -0
- package/package.json +64 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type LanguageMetrics } from './metrics.js';
|
|
2
|
+
import { type ResolvedKernConfig, type KernTarget } from './config.js';
|
|
3
|
+
export interface ProjectSummary {
|
|
4
|
+
cwd: string;
|
|
5
|
+
target: KernTarget;
|
|
6
|
+
kernFiles: string[];
|
|
7
|
+
colorPalette: Record<string, string>;
|
|
8
|
+
metrics: LanguageMetrics | null;
|
|
9
|
+
}
|
|
10
|
+
export declare function scanKernProject(cwd: string, config?: ResolvedKernConfig): ProjectSummary;
|
|
11
|
+
export declare function projectToKern(summary: ProjectSummary): string;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { readFileSync, readdirSync, statSync } from 'fs';
|
|
2
|
+
import { resolve, relative, join } from 'path';
|
|
3
|
+
import { parse } from './parser.js';
|
|
4
|
+
import { collectLanguageMetrics, mergeMetrics } from './metrics.js';
|
|
5
|
+
import { resolveConfig } from './config.js';
|
|
6
|
+
// ── File discovery ───────────────────────────────────────────────────────
|
|
7
|
+
const SKIP_DIRS = new Set(['node_modules', 'dist', '.git', '.next', 'build', 'out']);
|
|
8
|
+
function findKernFiles(cwd, maxDepth = 5) {
|
|
9
|
+
const results = [];
|
|
10
|
+
function walk(dir, depth) {
|
|
11
|
+
if (depth > maxDepth)
|
|
12
|
+
return;
|
|
13
|
+
let entries;
|
|
14
|
+
try {
|
|
15
|
+
entries = readdirSync(dir);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
for (const entry of entries) {
|
|
21
|
+
if (SKIP_DIRS.has(entry))
|
|
22
|
+
continue;
|
|
23
|
+
const full = join(dir, entry);
|
|
24
|
+
let stat;
|
|
25
|
+
try {
|
|
26
|
+
stat = statSync(full);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (stat.isDirectory()) {
|
|
32
|
+
walk(full, depth + 1);
|
|
33
|
+
}
|
|
34
|
+
else if (entry.endsWith('.kern')) {
|
|
35
|
+
results.push(relative(cwd, full));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
walk(cwd, 0);
|
|
40
|
+
return results.sort();
|
|
41
|
+
}
|
|
42
|
+
// ── Project scanning ─────────────────────────────────────────────────────
|
|
43
|
+
export function scanKernProject(cwd, config) {
|
|
44
|
+
const resolved = config ?? resolveConfig();
|
|
45
|
+
const kernFiles = findKernFiles(cwd);
|
|
46
|
+
if (kernFiles.length === 0) {
|
|
47
|
+
return {
|
|
48
|
+
cwd,
|
|
49
|
+
target: resolved.target,
|
|
50
|
+
kernFiles: [],
|
|
51
|
+
colorPalette: resolved.colors,
|
|
52
|
+
metrics: null,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const fileMetrics = [];
|
|
56
|
+
for (const file of kernFiles) {
|
|
57
|
+
try {
|
|
58
|
+
const source = readFileSync(resolve(cwd, file), 'utf-8');
|
|
59
|
+
const ast = parse(source);
|
|
60
|
+
fileMetrics.push(collectLanguageMetrics(ast));
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
// Skip unparseable files
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
cwd,
|
|
68
|
+
target: resolved.target,
|
|
69
|
+
kernFiles,
|
|
70
|
+
colorPalette: resolved.colors,
|
|
71
|
+
metrics: fileMetrics.length > 0 ? mergeMetrics(fileMetrics) : null,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
// ── Kern-format context export (for Agon integration) ────────────────────
|
|
75
|
+
export function projectToKern(summary) {
|
|
76
|
+
const lines = [];
|
|
77
|
+
const name = summary.cwd.split('/').pop() || 'project';
|
|
78
|
+
lines.push(`kern-project ${name} {`);
|
|
79
|
+
lines.push(` target: "${summary.target}"`);
|
|
80
|
+
lines.push(` files: ${summary.kernFiles.length}`);
|
|
81
|
+
for (const file of summary.kernFiles) {
|
|
82
|
+
lines.push(` - ${file}`);
|
|
83
|
+
}
|
|
84
|
+
if (summary.metrics) {
|
|
85
|
+
const m = summary.metrics;
|
|
86
|
+
lines.push('');
|
|
87
|
+
lines.push(' metrics {');
|
|
88
|
+
lines.push(` nodes: ${m.nodeCount}`);
|
|
89
|
+
lines.push(` escapeRatio: ${m.styleMetrics.escapeRatio.toFixed(2)}`);
|
|
90
|
+
if (m.styleMetrics.escapedKeys.length > 0) {
|
|
91
|
+
lines.push(` escapedKeys: ${m.styleMetrics.escapedKeys.join(', ')}`);
|
|
92
|
+
}
|
|
93
|
+
lines.push(` themeRefs: ${m.themeRefCount}`);
|
|
94
|
+
lines.push(` pseudoStyles: ${m.pseudoStyleCount}`);
|
|
95
|
+
lines.push(` shorthandCoverage: ${Math.round(m.shorthandCoverage * 100)}%`);
|
|
96
|
+
if (m.tokenEfficiency) {
|
|
97
|
+
lines.push(` tokenReduction: ${m.tokenEfficiency.tokenReduction}%`);
|
|
98
|
+
}
|
|
99
|
+
lines.push(' }');
|
|
100
|
+
if (m.nodeTypes.length > 0) {
|
|
101
|
+
lines.push('');
|
|
102
|
+
lines.push(' nodeTypes {');
|
|
103
|
+
for (const nt of m.nodeTypes.slice(0, 15)) {
|
|
104
|
+
lines.push(` ${nt.type}: ${nt.count}`);
|
|
105
|
+
}
|
|
106
|
+
lines.push(' }');
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const colorEntries = Object.entries(summary.colorPalette);
|
|
110
|
+
if (colorEntries.length > 0) {
|
|
111
|
+
lines.push('');
|
|
112
|
+
lines.push(' colors {');
|
|
113
|
+
for (const [hex, name] of colorEntries.slice(0, 20)) {
|
|
114
|
+
lines.push(` ${hex}: ${name}`);
|
|
115
|
+
}
|
|
116
|
+
lines.push(' }');
|
|
117
|
+
}
|
|
118
|
+
lines.push('}');
|
|
119
|
+
return lines.join('\n');
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=context-export.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-export.js","sourceRoot":"","sources":["../src/context-export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAc,MAAM,IAAI,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAwB,MAAM,cAAc,CAAC;AAC1F,OAAO,EAAE,aAAa,EAA4C,MAAM,aAAa,CAAC;AAYtF,4EAA4E;AAE5E,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;AAErF,SAAS,aAAa,CAAC,GAAW,EAAE,QAAQ,GAAG,CAAC;IAC9C,MAAM,OAAO,GAAa,EAAE,CAAC;IAE7B,SAAS,IAAI,CAAC,GAAW,EAAE,KAAa;QACtC,IAAI,KAAK,GAAG,QAAQ;YAAE,OAAO;QAC7B,IAAI,OAAiB,CAAC;QACtB,IAAI,CAAC;YACH,OAAO,GAAG,WAAW,CAAC,GAAG,CAAC,C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,CAAC,OAAO,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC;YAC5C,CAAC;YACD,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;IAED,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC1D,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5B,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACf,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACzB,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;YACpD,KAAK,CAAC,IAAI,CAAC,OAAO,GAAG,KAAK,IAAI,EAAE,CAAC,CAAC;QACpC,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { STYLE_SHORTHANDS, VALUE_SHORTHANDS } from './spec.js';
|
|
2
|
+
function expandKey(key) {
|
|
3
|
+
return STYLE_SHORTHANDS[key] || key;
|
|
4
|
+
}
|
|
5
|
+
function expandVal(val) {
|
|
6
|
+
return VALUE_SHORTHANDS[val] || val;
|
|
7
|
+
}
|
|
8
|
+
export function decompile(root) {
|
|
9
|
+
const lines = [];
|
|
10
|
+
function render(node, indent) {
|
|
11
|
+
const props = node.props || {};
|
|
12
|
+
const name = props.name || '';
|
|
13
|
+
const type = node.type.charAt(0).toUpperCase() + node.type.slice(1);
|
|
14
|
+
// Style description
|
|
15
|
+
const styles = props.styles;
|
|
16
|
+
const styleDesc = styles
|
|
17
|
+
? Object.entries(styles).map(([k, v]) => `${expandKey(k)}: ${expandVal(v)}`).join(', ')
|
|
18
|
+
: '';
|
|
19
|
+
// Props (excluding internal keys)
|
|
20
|
+
const propEntries = Object.entries(props)
|
|
21
|
+
.filter(([k]) => k !== 'styles' && k !== 'pseudoStyles' && k !== 'themeRefs')
|
|
22
|
+
.map(([k, v]) => `${k}=${JSON.stringify(v)}`)
|
|
23
|
+
.join(', ');
|
|
24
|
+
let desc = `${indent}${type}`;
|
|
25
|
+
if (name)
|
|
26
|
+
desc += ` "${name}"`;
|
|
27
|
+
if (propEntries)
|
|
28
|
+
desc += ` (${propEntries})`;
|
|
29
|
+
if (styleDesc)
|
|
30
|
+
desc += ` [${styleDesc}]`;
|
|
31
|
+
const themeRefs = props.themeRefs;
|
|
32
|
+
if (themeRefs?.length)
|
|
33
|
+
desc += ` inherits ${themeRefs.map(r => `$${r}`).join(', ')}`;
|
|
34
|
+
lines.push(desc);
|
|
35
|
+
if (node.children) {
|
|
36
|
+
for (const child of node.children) {
|
|
37
|
+
render(child, indent + ' ');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
render(root, '');
|
|
42
|
+
return { code: lines.join('\n') };
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=decompiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decompiler.js","sourceRoot":"","sources":["../src/decompiler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAE/D,SAAS,SAAS,CAAC,GAAW;IAC5B,OAAO,gBAAgB,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC;AACtC,CAAC;AAED,SAAS,SAAS,CAAC,GAAW;IAC5B,OAAO,gBAAgB,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,MAAM,KAAK,GAAa,E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WAAW,GAAG,CAAC;QAC7C,IAAI,SAAS;YAAE,IAAI,IAAI,KAAK,SAAS,GAAG,CAAC;QAEzC,MAAM,SAAS,GAAG,KAAK,CAAC,SAAiC,CAAC;QAC1D,IAAI,SAAS,EAAE,MAAM;YAAE,IAAI,IAAI,aAAa,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAErF,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEjB,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBAClC,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACjB,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kern Draft Protocol
|
|
3
|
+
*
|
|
4
|
+
* Structured communication format for competing AI engines.
|
|
5
|
+
* Engines respond in Kern draft format instead of verbose natural language —
|
|
6
|
+
* 70% fewer tokens, no fluff, structured and rankable.
|
|
7
|
+
*
|
|
8
|
+
* "Engines speak Kern."
|
|
9
|
+
*/
|
|
10
|
+
export interface KernDraft {
|
|
11
|
+
approach: string;
|
|
12
|
+
reasoning: string;
|
|
13
|
+
tradeoffs: string[];
|
|
14
|
+
confidence: number;
|
|
15
|
+
keyFiles: string[];
|
|
16
|
+
steps: string[];
|
|
17
|
+
}
|
|
18
|
+
export declare function buildKernDraftPrompt(opts: {
|
|
19
|
+
question: string;
|
|
20
|
+
context?: string;
|
|
21
|
+
mode: 'brainstorm' | 'forge-plan' | 'tribunal-position';
|
|
22
|
+
}): string;
|
|
23
|
+
export declare function buildKernRankPrompt(drafts: {
|
|
24
|
+
engineId: string;
|
|
25
|
+
draft: KernDraft;
|
|
26
|
+
}[]): string;
|
|
27
|
+
export declare function parseKernDraft(output: string): KernDraft | null;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kern Draft Protocol
|
|
3
|
+
*
|
|
4
|
+
* Structured communication format for competing AI engines.
|
|
5
|
+
* Engines respond in Kern draft format instead of verbose natural language —
|
|
6
|
+
* 70% fewer tokens, no fluff, structured and rankable.
|
|
7
|
+
*
|
|
8
|
+
* "Engines speak Kern."
|
|
9
|
+
*/
|
|
10
|
+
// ── Prompt builders ──────────────────────────────────────────────────────
|
|
11
|
+
export function buildKernDraftPrompt(opts) {
|
|
12
|
+
const modeInstructions = {
|
|
13
|
+
'brainstorm': 'You are proposing an approach to a technical question. Be creative but specific.',
|
|
14
|
+
'forge-plan': 'You are planning an implementation that will be scored against competing implementations. Be precise about files and steps.',
|
|
15
|
+
'tribunal-position': 'You are taking a position in a technical tribunal. State your case clearly with evidence.',
|
|
16
|
+
};
|
|
17
|
+
const lines = [];
|
|
18
|
+
lines.push(modeInstructions[opts.mode]);
|
|
19
|
+
lines.push('');
|
|
20
|
+
if (opts.context) {
|
|
21
|
+
lines.push('## Project Context');
|
|
22
|
+
lines.push(opts.context);
|
|
23
|
+
lines.push('');
|
|
24
|
+
}
|
|
25
|
+
lines.push('## Question');
|
|
26
|
+
lines.push(opts.question);
|
|
27
|
+
lines.push('');
|
|
28
|
+
lines.push('## Response Format');
|
|
29
|
+
lines.push('');
|
|
30
|
+
lines.push('Respond ONLY with a Kern draft block. No markdown, no explanation outside the block.');
|
|
31
|
+
lines.push('');
|
|
32
|
+
lines.push('```');
|
|
33
|
+
lines.push('draft {');
|
|
34
|
+
lines.push(' approach: "your one-line thesis"');
|
|
35
|
+
lines.push(' reasoning: "why this approach works — 1-3 sentences max"');
|
|
36
|
+
lines.push(' tradeoffs: "risk1", "risk2", "risk3"');
|
|
37
|
+
lines.push(' confidence: 0-100');
|
|
38
|
+
lines.push(' keyFiles: "src/file1.ts", "src/file2.ts"');
|
|
39
|
+
lines.push(' steps {');
|
|
40
|
+
lines.push(' 1: "first step"');
|
|
41
|
+
lines.push(' 2: "second step"');
|
|
42
|
+
lines.push(' 3: "third step"');
|
|
43
|
+
lines.push(' }');
|
|
44
|
+
lines.push('}');
|
|
45
|
+
lines.push('```');
|
|
46
|
+
lines.push('');
|
|
47
|
+
lines.push('Rules:');
|
|
48
|
+
lines.push('- approach: single sentence, what you would do');
|
|
49
|
+
lines.push('- reasoning: why, max 3 sentences');
|
|
50
|
+
lines.push('- tradeoffs: comma-separated quoted strings, risks or downsides');
|
|
51
|
+
lines.push('- confidence: integer 0-100, how sure you are');
|
|
52
|
+
lines.push('- keyFiles: comma-separated quoted paths, files you would touch');
|
|
53
|
+
lines.push('- steps: numbered, 3-7 concrete steps');
|
|
54
|
+
lines.push('- No text outside the draft block');
|
|
55
|
+
return lines.join('\n');
|
|
56
|
+
}
|
|
57
|
+
export function buildKernRankPrompt(drafts) {
|
|
58
|
+
const lines = [];
|
|
59
|
+
lines.push('Rank these drafts by: specificity (concrete vs vague), feasibility (can it actually work), and fit to project context.');
|
|
60
|
+
lines.push('');
|
|
61
|
+
for (const { engineId, draft } of drafts) {
|
|
62
|
+
lines.push(`## ${engineId}`);
|
|
63
|
+
lines.push(`Approach: ${draft.approach}`);
|
|
64
|
+
lines.push(`Reasoning: ${draft.reasoning}`);
|
|
65
|
+
lines.push(`Confidence: ${draft.confidence}`);
|
|
66
|
+
lines.push(`Steps: ${draft.steps.length}`);
|
|
67
|
+
lines.push(`Tradeoffs: ${draft.tradeoffs.join(', ')}`);
|
|
68
|
+
lines.push('');
|
|
69
|
+
}
|
|
70
|
+
lines.push('Respond with ONLY the engine IDs in ranked order (best first), comma-separated:');
|
|
71
|
+
lines.push('Example: engine2, engine1, engine3');
|
|
72
|
+
return lines.join('\n');
|
|
73
|
+
}
|
|
74
|
+
// ── Parser ───────────────────────────────────────────────────────────────
|
|
75
|
+
export function parseKernDraft(output) {
|
|
76
|
+
// Strip markdown fences if present
|
|
77
|
+
let text = output;
|
|
78
|
+
const fenceMatch = text.match(/```[\w]*\n?([\s\S]*?)```/);
|
|
79
|
+
if (fenceMatch) {
|
|
80
|
+
text = fenceMatch[1];
|
|
81
|
+
}
|
|
82
|
+
// Find the draft { ... } block
|
|
83
|
+
const draftMatch = text.match(/draft\s*\{([\s\S]*)\}/);
|
|
84
|
+
if (!draftMatch)
|
|
85
|
+
return null;
|
|
86
|
+
const body = draftMatch[1];
|
|
87
|
+
const draft = {
|
|
88
|
+
approach: '',
|
|
89
|
+
reasoning: '',
|
|
90
|
+
tradeoffs: [],
|
|
91
|
+
confidence: 0,
|
|
92
|
+
keyFiles: [],
|
|
93
|
+
steps: [],
|
|
94
|
+
};
|
|
95
|
+
// Parse simple key: "value" fields
|
|
96
|
+
draft.approach = parseStringField(body, 'approach') || '';
|
|
97
|
+
draft.reasoning = parseStringField(body, 'reasoning') || '';
|
|
98
|
+
draft.confidence = parseNumberField(body, 'confidence') || 0;
|
|
99
|
+
// Parse comma-separated quoted lists
|
|
100
|
+
draft.tradeoffs = parseQuotedList(body, 'tradeoffs');
|
|
101
|
+
draft.keyFiles = parseQuotedList(body, 'keyFiles');
|
|
102
|
+
// Parse steps { 1: "...", 2: "...", ... } block
|
|
103
|
+
const stepsMatch = body.match(/steps\s*\{([\s\S]*?)\}/);
|
|
104
|
+
if (stepsMatch) {
|
|
105
|
+
const stepsBody = stepsMatch[1];
|
|
106
|
+
const stepEntries = [...stepsBody.matchAll(/\d+\s*:\s*"([^"]*?)"/g)];
|
|
107
|
+
draft.steps = stepEntries.map(m => m[1]);
|
|
108
|
+
}
|
|
109
|
+
// Validate: must have at least an approach
|
|
110
|
+
if (!draft.approach)
|
|
111
|
+
return null;
|
|
112
|
+
return draft;
|
|
113
|
+
}
|
|
114
|
+
// ── Internal helpers ─────────────────────────────────────────────────────
|
|
115
|
+
function parseStringField(body, key) {
|
|
116
|
+
// Match key: "value" but not inside a steps block
|
|
117
|
+
const regex = new RegExp(`^\\s*${key}\\s*:\\s*"([^"]*)"`, 'm');
|
|
118
|
+
const match = body.match(regex);
|
|
119
|
+
return match ? match[1] : null;
|
|
120
|
+
}
|
|
121
|
+
function parseNumberField(body, key) {
|
|
122
|
+
const regex = new RegExp(`^\\s*${key}\\s*:\\s*(\\d+)`, 'm');
|
|
123
|
+
const match = body.match(regex);
|
|
124
|
+
return match ? Number(match[1]) : null;
|
|
125
|
+
}
|
|
126
|
+
function parseQuotedList(body, key) {
|
|
127
|
+
// Match key: "val1", "val2", "val3"
|
|
128
|
+
const regex = new RegExp(`^\\s*${key}\\s*:\\s*(.+)`, 'm');
|
|
129
|
+
const match = body.match(regex);
|
|
130
|
+
if (!match)
|
|
131
|
+
return [];
|
|
132
|
+
const values = [...match[1].matchAll(/"([^"]*?)"/g)];
|
|
133
|
+
return values.map(m => m[1]);
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=draft-protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draft-protocol.js","sourceRoot":"","sources":["../src/draft-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAaH,4EAA4E;AAE5E,MAAM,UAAU,oBAAoB,CAAC,IAIpC;IACC,MAAM,gBAAgB,GAA2B;QAC/C,YAAY,EAAE,kFAAkF;QAChG,YAAY,EAAE,6HAA6H;QAC3I,mBAAmB,EAAE,2FAA2F;KACjH,CAAC;IAEF,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACxC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEf,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QACjB,KAAK,CAAC,IAAI,CAAC,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C,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,QAAQ,GAAG,eAAe,EAAE,GAAG,CAAC,CAAC;IAC1D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAChC,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IACtB,MAAM,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC;IACrD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/B,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kern Error Types
|
|
3
|
+
*/
|
|
4
|
+
export declare class KernError extends Error {
|
|
5
|
+
line: number;
|
|
6
|
+
col: number;
|
|
7
|
+
source: string;
|
|
8
|
+
constructor(message: string, line: number, col: number, source: string);
|
|
9
|
+
}
|
|
10
|
+
export declare class KernParseError extends KernError {
|
|
11
|
+
constructor(message: string, line: number, col: number, source: string);
|
|
12
|
+
}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kern Error Types
|
|
3
|
+
*/
|
|
4
|
+
export class KernError extends Error {
|
|
5
|
+
line;
|
|
6
|
+
col;
|
|
7
|
+
source;
|
|
8
|
+
constructor(message, line, col, source) {
|
|
9
|
+
const frame = codeFrame(source, line, col);
|
|
10
|
+
super(`${message}\n\n${frame}`);
|
|
11
|
+
this.name = 'KernError';
|
|
12
|
+
this.line = line;
|
|
13
|
+
this.col = col;
|
|
14
|
+
this.source = source;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export class KernParseError extends KernError {
|
|
18
|
+
constructor(message, line, col, source) {
|
|
19
|
+
super(`Parse error: ${message}`, line, col, source);
|
|
20
|
+
this.name = 'KernParseError';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function codeFrame(source, line, col) {
|
|
24
|
+
const lines = source.split('\n');
|
|
25
|
+
const start = Math.max(0, line - 3);
|
|
26
|
+
const end = Math.min(lines.length, line + 2);
|
|
27
|
+
const result = [];
|
|
28
|
+
const gutterWidth = String(end).length;
|
|
29
|
+
for (let i = start; i < end; i++) {
|
|
30
|
+
const lineNum = String(i + 1).padStart(gutterWidth);
|
|
31
|
+
const marker = i + 1 === line ? '>' : ' ';
|
|
32
|
+
result.push(`${marker} ${lineNum} | ${lines[i]}`);
|
|
33
|
+
if (i + 1 === line) {
|
|
34
|
+
const pointer = ' '.repeat(gutterWidth + 4 + Math.max(0, col - 1)) + '^';
|
|
35
|
+
result.push(pointer);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return result.join('\n');
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,OAAO,SAAU,SAAQ,KAAK;IAClC,IAAI,CAAS;IACb,GAAG,CAAS;IACZ,MAAM,CAAS;IAEf,YAAY,OAAe,EAAE,IAAY,EAAE,GAAW,EAAE,MAAc;QACpE,MAAM,KAAK,GAAG,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;QAC3C,KAAK,CAAC,GAAG,OAAO,OAAO,KAAK,EAAE,CAAC,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED,MAAM,OAAO,cAAe,SAAQ,SAAS;IAC3C,YAAY,OAAe,EAAE,IAAY,EAAE,GAAW,EAA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C;QACvB,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kern — the LLM-native language.
|
|
3
|
+
*
|
|
4
|
+
* Swiss-engineered IR that transpiles to React, Next.js, Express,
|
|
5
|
+
* Tailwind, and React Native.
|
|
6
|
+
*/
|
|
7
|
+
export { parse } from './parser.js';
|
|
8
|
+
export { decompile } from './decompiler.js';
|
|
9
|
+
export type { IRNode, IRSourceLocation, SourceMapEntry, TranspileResult, DecompileResult, GeneratedArtifact, KernEngine, } from './types.js';
|
|
10
|
+
export { resolveConfig, mergeConfig, DEFAULT_CONFIG, VALID_TARGETS } from './config.js';
|
|
11
|
+
export type { KernConfig, KernTarget, ResolvedKernConfig } from './config.js';
|
|
12
|
+
export { transpile } from './transpiler.js';
|
|
13
|
+
export { transpileWeb } from './transpiler-web.js';
|
|
14
|
+
export { transpileTailwind } from './transpiler-tailwind.js';
|
|
15
|
+
export { transpileNextjs } from './transpiler-nextjs.js';
|
|
16
|
+
export { transpileExpress } from './transpiler-express.js';
|
|
17
|
+
export { transpileCliApp } from './transpiler-cli.js';
|
|
18
|
+
export { transpileTerminal } from './transpiler-terminal.js';
|
|
19
|
+
export { collectLanguageMetrics, mergeMetrics, isEscapedStyleKey } from './metrics.js';
|
|
20
|
+
export type { LanguageMetrics, StyleMetrics, NodeTypeMetrics } from './metrics.js';
|
|
21
|
+
export { scanKernProject, projectToKern } from './context-export.js';
|
|
22
|
+
export type { ProjectSummary } from './context-export.js';
|
|
23
|
+
export { buildKernDraftPrompt, parseKernDraft, buildKernRankPrompt } from './draft-protocol.js';
|
|
24
|
+
export type { KernDraft } from './draft-protocol.js';
|
|
25
|
+
export { KERN_VERSION, NODE_TYPES, STYLE_SHORTHANDS, VALUE_SHORTHANDS } from './spec.js';
|
|
26
|
+
export { stylesToTailwind, colorToTw, pxToTw, DEFAULT_COLORS } from './styles-tailwind.js';
|
|
27
|
+
export { expandStyles, expandStyleKey, expandStyleValue } from './styles-react.js';
|
|
28
|
+
export { countTokens, serializeIR, camelKey, escapeJsx } from './utils.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kern — the LLM-native language.
|
|
3
|
+
*
|
|
4
|
+
* Swiss-engineered IR that transpiles to React, Next.js, Express,
|
|
5
|
+
* Tailwind, and React Native.
|
|
6
|
+
*/
|
|
7
|
+
// Core
|
|
8
|
+
export { parse } from './parser.js';
|
|
9
|
+
export { decompile } from './decompiler.js';
|
|
10
|
+
// Config
|
|
11
|
+
export { resolveConfig, mergeConfig, DEFAULT_CONFIG, VALID_TARGETS } from './config.js';
|
|
12
|
+
// Transpilers
|
|
13
|
+
export { transpile } from './transpiler.js';
|
|
14
|
+
export { transpileWeb } from './transpiler-web.js';
|
|
15
|
+
export { transpileTailwind } from './transpiler-tailwind.js';
|
|
16
|
+
export { transpileNextjs } from './transpiler-nextjs.js';
|
|
17
|
+
export { transpileExpress } from './transpiler-express.js';
|
|
18
|
+
export { transpileCliApp } from './transpiler-cli.js';
|
|
19
|
+
export { transpileTerminal } from './transpiler-terminal.js';
|
|
20
|
+
// Metrics
|
|
21
|
+
export { collectLanguageMetrics, mergeMetrics, isEscapedStyleKey } from './metrics.js';
|
|
22
|
+
// Context export (for Agon integration)
|
|
23
|
+
export { scanKernProject, projectToKern } from './context-export.js';
|
|
24
|
+
// Draft protocol (for Agon forge/brainstorm/tribunal)
|
|
25
|
+
export { buildKernDraftPrompt, parseKernDraft, buildKernRankPrompt } from './draft-protocol.js';
|
|
26
|
+
// Spec
|
|
27
|
+
export { KERN_VERSION, NODE_TYPES, STYLE_SHORTHANDS, VALUE_SHORTHANDS } from './spec.js';
|
|
28
|
+
// Shared style engines
|
|
29
|
+
export { stylesToTailwind, colorToTw, pxToTw, DEFAULT_COLORS } from './styles-tailwind.js';
|
|
30
|
+
export { expandStyles, expandStyleKey, expandStyleValue } from './styles-react.js';
|
|
31
|
+
// Utilities
|
|
32
|
+
export { countTokens, serializeIR, camelKey, escapeJsx } from './utils.js';
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO;AACP,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAa5C,SAAS;AACT,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGxF,cAAc;AACd,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,UAAU;AACV,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGvF,wCAAwC;AACxC,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGrE,sDAAsD;AACtD,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAGhG,OAAO;AACP,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAEzF,uBAAuB;AACvB,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3F,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAEnF,YAAY;AACZ,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { IRNode, TranspileResult } from './types.js';
|
|
2
|
+
export interface StyleMetrics {
|
|
3
|
+
totalStyleDecls: number;
|
|
4
|
+
mappedStyleDecls: number;
|
|
5
|
+
escapedStyleDecls: number;
|
|
6
|
+
escapeRatio: number;
|
|
7
|
+
escapedKeys: string[];
|
|
8
|
+
}
|
|
9
|
+
export interface NodeTypeMetrics {
|
|
10
|
+
type: string;
|
|
11
|
+
count: number;
|
|
12
|
+
styleDecls: number;
|
|
13
|
+
}
|
|
14
|
+
export interface LanguageMetrics {
|
|
15
|
+
nodeCount: number;
|
|
16
|
+
unknownNodeCount: number;
|
|
17
|
+
nodeTypes: NodeTypeMetrics[];
|
|
18
|
+
styleMetrics: StyleMetrics;
|
|
19
|
+
shorthandCoverage: number;
|
|
20
|
+
themeRefCount: number;
|
|
21
|
+
pseudoStyleCount: number;
|
|
22
|
+
tokenEfficiency: {
|
|
23
|
+
irTokenCount: number;
|
|
24
|
+
tsTokenCount: number;
|
|
25
|
+
tokenReduction: number;
|
|
26
|
+
} | null;
|
|
27
|
+
}
|
|
28
|
+
export declare function isEscapedStyleKey(rawKey: string): boolean;
|
|
29
|
+
export declare function collectLanguageMetrics(root: IRNode, result?: TranspileResult): LanguageMetrics;
|
|
30
|
+
export declare function mergeMetrics(metrics: LanguageMetrics[]): LanguageMetrics;
|