@cmpsbl/runtime 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/README.md +43 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.js +202 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# @cmpsbl/runtime
|
|
2
|
+
|
|
3
|
+
CMPSBL® Mini-Runtime™ Engine — the canonical execution runtime for the CMPSBL substrate.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @cmpsbl/runtime
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { createRuntime } from '@cmpsbl/runtime';
|
|
15
|
+
|
|
16
|
+
const runtime = createRuntime();
|
|
17
|
+
|
|
18
|
+
// Score a discovery
|
|
19
|
+
const score = runtime.computeCJPI({ novelty: 80, utility: 90, complexity: 70, composability: 85 });
|
|
20
|
+
console.log(score.total, score.tier); // 83 'Mythic'
|
|
21
|
+
|
|
22
|
+
// Generate a manifest
|
|
23
|
+
const manifest = runtime.generateManifest({ name: 'my-pipeline', cjpi: 83, modules: ['BRAIN', 'CORTEX'] });
|
|
24
|
+
|
|
25
|
+
// Register custom primitives and execute chains
|
|
26
|
+
runtime.registerPrimitive('BRAIN', (data) => ({
|
|
27
|
+
success: true, output: { analyzed: true, ...data }, confidence: 0.9, durationMs: 12, handler: 'brain-local'
|
|
28
|
+
}));
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
- **CJPI Scoring** — Crown Jewel Performance Index computation with weighted dimensions
|
|
34
|
+
- **Auto-Tiering** — Automatic tier assignment (Mint → Apex)
|
|
35
|
+
- **Manifest Parsing** — Parse and generate CMPSBL export manifests
|
|
36
|
+
- **Pipeline Execution** — Chain execution with fallback handling
|
|
37
|
+
- **State Machine** — Generic finite state machine
|
|
38
|
+
- **Dependency Graph** — Topological sort for module ordering
|
|
39
|
+
- **Zero Dependencies** — Pure TypeScript, runs anywhere
|
|
40
|
+
|
|
41
|
+
## License
|
|
42
|
+
|
|
43
|
+
Apache-2.0 © Kenneth E Sweet Jr
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @cmpsbl/runtime — Mini-Runtime™ Engine
|
|
3
|
+
* CMPSBL® Core Execution Runtime
|
|
4
|
+
*
|
|
5
|
+
* Zero-dependency CJPI scoring, auto-tiering, manifest parsing,
|
|
6
|
+
* state machine, saga orchestration, and pipeline execution.
|
|
7
|
+
*
|
|
8
|
+
* © CMPSBL® — All rights reserved.
|
|
9
|
+
*/
|
|
10
|
+
import type { CJPIInput, CJPIScoreBreakdown, CrystallizedTier, ProductTier, CmpsblManifest, ChainManifest, ChainResult, ExecutionOptions, PrimitiveResult } from '@cmpsbl/types';
|
|
11
|
+
export type { CJPIInput, CJPIScoreBreakdown, CrystallizedTier, ProductTier, CmpsblManifest };
|
|
12
|
+
export declare function computeCJPI(input: CJPIInput): CJPIScoreBreakdown;
|
|
13
|
+
export declare function tierFromCJPI(score: number): CrystallizedTier;
|
|
14
|
+
export declare function productTierFromScore(score: number): ProductTier;
|
|
15
|
+
export declare function parseManifest(json: string): CmpsblManifest;
|
|
16
|
+
export declare function generateManifest(input: {
|
|
17
|
+
name: string;
|
|
18
|
+
cjpi?: number;
|
|
19
|
+
modules?: string[];
|
|
20
|
+
targets?: string[];
|
|
21
|
+
version?: string;
|
|
22
|
+
category?: string;
|
|
23
|
+
fingerprint?: string;
|
|
24
|
+
source?: string;
|
|
25
|
+
}): CmpsblManifest;
|
|
26
|
+
export interface DependencyNode {
|
|
27
|
+
id: string;
|
|
28
|
+
dependencies: string[];
|
|
29
|
+
}
|
|
30
|
+
export declare function buildDependencyGraph(nodes: DependencyNode[]): Map<string, string[]>;
|
|
31
|
+
export declare function topologicalSort(nodes: DependencyNode[]): string[];
|
|
32
|
+
export interface StateMachineConfig<S extends string, E extends string> {
|
|
33
|
+
initial: S;
|
|
34
|
+
transitions: Record<S, Partial<Record<E, S>>>;
|
|
35
|
+
}
|
|
36
|
+
export declare class StateMachine<S extends string, E extends string> {
|
|
37
|
+
private current;
|
|
38
|
+
private readonly transitions;
|
|
39
|
+
constructor(config: StateMachineConfig<S, E>);
|
|
40
|
+
get state(): S;
|
|
41
|
+
send(event: E): S;
|
|
42
|
+
canSend(event: E): boolean;
|
|
43
|
+
}
|
|
44
|
+
export type PrimitiveHandler = (data: Record<string, unknown>, confidence: number) => PrimitiveResult | Promise<PrimitiveResult>;
|
|
45
|
+
export declare function registerPrimitive(name: string, handler: PrimitiveHandler): void;
|
|
46
|
+
export declare function executePrimitive(name: string, data: Record<string, unknown>, confidence: number): Promise<PrimitiveResult>;
|
|
47
|
+
export declare function executeChain(manifest: ChainManifest, input: Record<string, unknown>, options?: ExecutionOptions): Promise<ChainResult>;
|
|
48
|
+
export interface MiniRuntime {
|
|
49
|
+
computeCJPI: typeof computeCJPI;
|
|
50
|
+
tierFromCJPI: typeof tierFromCJPI;
|
|
51
|
+
productTierFromScore: typeof productTierFromScore;
|
|
52
|
+
parseManifest: typeof parseManifest;
|
|
53
|
+
generateManifest: typeof generateManifest;
|
|
54
|
+
topologicalSort: typeof topologicalSort;
|
|
55
|
+
registerPrimitive: typeof registerPrimitive;
|
|
56
|
+
executePrimitive: typeof executePrimitive;
|
|
57
|
+
executeChain: typeof executeChain;
|
|
58
|
+
createStateMachine: <S extends string, E extends string>(config: StateMachineConfig<S, E>) => StateMachine<S, E>;
|
|
59
|
+
version: string;
|
|
60
|
+
}
|
|
61
|
+
export declare function createRuntime(): MiniRuntime;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @cmpsbl/runtime — Mini-Runtime™ Engine
|
|
4
|
+
* CMPSBL® Core Execution Runtime
|
|
5
|
+
*
|
|
6
|
+
* Zero-dependency CJPI scoring, auto-tiering, manifest parsing,
|
|
7
|
+
* state machine, saga orchestration, and pipeline execution.
|
|
8
|
+
*
|
|
9
|
+
* © CMPSBL® — All rights reserved.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.StateMachine = void 0;
|
|
13
|
+
exports.computeCJPI = computeCJPI;
|
|
14
|
+
exports.tierFromCJPI = tierFromCJPI;
|
|
15
|
+
exports.productTierFromScore = productTierFromScore;
|
|
16
|
+
exports.parseManifest = parseManifest;
|
|
17
|
+
exports.generateManifest = generateManifest;
|
|
18
|
+
exports.buildDependencyGraph = buildDependencyGraph;
|
|
19
|
+
exports.topologicalSort = topologicalSort;
|
|
20
|
+
exports.registerPrimitive = registerPrimitive;
|
|
21
|
+
exports.executePrimitive = executePrimitive;
|
|
22
|
+
exports.executeChain = executeChain;
|
|
23
|
+
exports.createRuntime = createRuntime;
|
|
24
|
+
// ═══════════════════════════════════════════════════════════════
|
|
25
|
+
// §1 — CJPI Scoring Engine
|
|
26
|
+
// ═══════════════════════════════════════════════════════════════
|
|
27
|
+
const CJPI_WEIGHTS = {
|
|
28
|
+
novelty: 0.25,
|
|
29
|
+
utility: 0.35,
|
|
30
|
+
complexity: 0.20,
|
|
31
|
+
composability: 0.20,
|
|
32
|
+
};
|
|
33
|
+
function computeCJPI(input) {
|
|
34
|
+
const total = Math.round(input.novelty * CJPI_WEIGHTS.novelty +
|
|
35
|
+
input.utility * CJPI_WEIGHTS.utility +
|
|
36
|
+
input.complexity * CJPI_WEIGHTS.complexity +
|
|
37
|
+
input.composability * CJPI_WEIGHTS.composability);
|
|
38
|
+
return {
|
|
39
|
+
novelty: input.novelty,
|
|
40
|
+
utility: input.utility,
|
|
41
|
+
complexity: input.complexity,
|
|
42
|
+
composability: input.composability,
|
|
43
|
+
total: Math.max(0, Math.min(100, total)),
|
|
44
|
+
tier: tierFromCJPI(total),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function tierFromCJPI(score) {
|
|
48
|
+
if (score >= 90)
|
|
49
|
+
return 'Apex';
|
|
50
|
+
if (score >= 75)
|
|
51
|
+
return 'Mythic';
|
|
52
|
+
if (score >= 55)
|
|
53
|
+
return 'Relic';
|
|
54
|
+
if (score >= 35)
|
|
55
|
+
return 'Prime';
|
|
56
|
+
return 'Mint';
|
|
57
|
+
}
|
|
58
|
+
function productTierFromScore(score) {
|
|
59
|
+
if (score >= 90)
|
|
60
|
+
return 'Apex';
|
|
61
|
+
if (score >= 75)
|
|
62
|
+
return 'Enterprise';
|
|
63
|
+
if (score >= 55)
|
|
64
|
+
return 'Architect';
|
|
65
|
+
if (score >= 35)
|
|
66
|
+
return 'Creator';
|
|
67
|
+
return 'Raw';
|
|
68
|
+
}
|
|
69
|
+
// ═══════════════════════════════════════════════════════════════
|
|
70
|
+
// §2 — Manifest Parser
|
|
71
|
+
// ═══════════════════════════════════════════════════════════════
|
|
72
|
+
function parseManifest(json) {
|
|
73
|
+
const data = JSON.parse(json);
|
|
74
|
+
if (!data.name || typeof data.cjpi !== 'number') {
|
|
75
|
+
throw new Error('Invalid CMPSBL manifest: missing name or cjpi');
|
|
76
|
+
}
|
|
77
|
+
return data;
|
|
78
|
+
}
|
|
79
|
+
function generateManifest(input) {
|
|
80
|
+
const cjpi = input.cjpi ?? 0;
|
|
81
|
+
return {
|
|
82
|
+
name: input.name,
|
|
83
|
+
tier: productTierFromScore(cjpi),
|
|
84
|
+
cjpi,
|
|
85
|
+
modules: input.modules ?? ['SYSTEM'],
|
|
86
|
+
exported: new Date().toISOString().slice(0, 10),
|
|
87
|
+
runtime: 'cmpsbl-mini-runtime-engine',
|
|
88
|
+
targets: input.targets ?? ['typescript'],
|
|
89
|
+
version: input.version ?? '1.0.0',
|
|
90
|
+
...(input.category ? { category: input.category } : {}),
|
|
91
|
+
...(input.fingerprint ? { fingerprint: input.fingerprint } : {}),
|
|
92
|
+
...(input.source ? { source: input.source } : {}),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function buildDependencyGraph(nodes) {
|
|
96
|
+
const graph = new Map();
|
|
97
|
+
for (const node of nodes) {
|
|
98
|
+
graph.set(node.id, node.dependencies);
|
|
99
|
+
}
|
|
100
|
+
return graph;
|
|
101
|
+
}
|
|
102
|
+
function topologicalSort(nodes) {
|
|
103
|
+
const graph = buildDependencyGraph(nodes);
|
|
104
|
+
const visited = new Set();
|
|
105
|
+
const result = [];
|
|
106
|
+
function visit(id) {
|
|
107
|
+
if (visited.has(id))
|
|
108
|
+
return;
|
|
109
|
+
visited.add(id);
|
|
110
|
+
for (const dep of graph.get(id) ?? []) {
|
|
111
|
+
visit(dep);
|
|
112
|
+
}
|
|
113
|
+
result.push(id);
|
|
114
|
+
}
|
|
115
|
+
for (const node of nodes) {
|
|
116
|
+
visit(node.id);
|
|
117
|
+
}
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
class StateMachine {
|
|
121
|
+
constructor(config) {
|
|
122
|
+
this.current = config.initial;
|
|
123
|
+
this.transitions = config.transitions;
|
|
124
|
+
}
|
|
125
|
+
get state() { return this.current; }
|
|
126
|
+
send(event) {
|
|
127
|
+
const next = this.transitions[this.current]?.[event];
|
|
128
|
+
if (next)
|
|
129
|
+
this.current = next;
|
|
130
|
+
return this.current;
|
|
131
|
+
}
|
|
132
|
+
canSend(event) {
|
|
133
|
+
return this.transitions[this.current]?.[event] !== undefined;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.StateMachine = StateMachine;
|
|
137
|
+
const primitiveRegistry = new Map();
|
|
138
|
+
function registerPrimitive(name, handler) {
|
|
139
|
+
primitiveRegistry.set(name, handler);
|
|
140
|
+
}
|
|
141
|
+
async function executePrimitive(name, data, confidence) {
|
|
142
|
+
const handler = primitiveRegistry.get(name);
|
|
143
|
+
if (handler) {
|
|
144
|
+
return handler(data, confidence);
|
|
145
|
+
}
|
|
146
|
+
// Default fallback
|
|
147
|
+
return {
|
|
148
|
+
success: true,
|
|
149
|
+
output: { echo: data, primitive: name },
|
|
150
|
+
confidence: confidence * 0.8,
|
|
151
|
+
durationMs: 0,
|
|
152
|
+
handler: 'default-fallback',
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
async function executeChain(manifest, input, options) {
|
|
156
|
+
const start = Date.now();
|
|
157
|
+
let current = input;
|
|
158
|
+
let stagesCompleted = 0;
|
|
159
|
+
for (const mod of manifest.modules) {
|
|
160
|
+
try {
|
|
161
|
+
const result = await executePrimitive(mod, current, manifest.cjpiScore / 100);
|
|
162
|
+
if (result.success) {
|
|
163
|
+
current = typeof result.output === 'object' && result.output !== null
|
|
164
|
+
? result.output
|
|
165
|
+
: { value: result.output };
|
|
166
|
+
stagesCompleted++;
|
|
167
|
+
}
|
|
168
|
+
else if (!options?.continueOnFailure) {
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
if (!options?.continueOnFailure)
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
success: stagesCompleted === manifest.modules.length,
|
|
179
|
+
output: current,
|
|
180
|
+
confidence: manifest.cjpiScore / 100,
|
|
181
|
+
totalDurationMs: Date.now() - start,
|
|
182
|
+
stagesCompleted,
|
|
183
|
+
totalStages: manifest.modules.length,
|
|
184
|
+
runtimeMode: 'offline',
|
|
185
|
+
bridgeType: 'offline-fallback',
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function createRuntime() {
|
|
189
|
+
return {
|
|
190
|
+
computeCJPI,
|
|
191
|
+
tierFromCJPI,
|
|
192
|
+
productTierFromScore,
|
|
193
|
+
parseManifest,
|
|
194
|
+
generateManifest,
|
|
195
|
+
topologicalSort,
|
|
196
|
+
registerPrimitive,
|
|
197
|
+
executePrimitive,
|
|
198
|
+
executeChain,
|
|
199
|
+
createStateMachine: (config) => new StateMachine(config),
|
|
200
|
+
version: '1.0.0',
|
|
201
|
+
};
|
|
202
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cmpsbl/runtime",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "CMPSBL® Mini-Runtime™ Engine — CJPI scoring, auto-tiering, pipeline orchestration, and manifest parsing. Zero dependencies.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"prepublishOnly": "npm run build"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"cmpsbl",
|
|
16
|
+
"runtime",
|
|
17
|
+
"cjpi",
|
|
18
|
+
"scoring",
|
|
19
|
+
"pipeline",
|
|
20
|
+
"orchestration"
|
|
21
|
+
],
|
|
22
|
+
"author": "Kenneth E Sweet Jr <promptfluid@gmail.com>",
|
|
23
|
+
"license": "Apache-2.0",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/cmpsbl/runtime"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://cmpsbl.com",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@cmpsbl/types": "^1.0.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/lodash": "^4.17.24",
|
|
34
|
+
"@types/lodash-es": "^4.17.12"
|
|
35
|
+
}
|
|
36
|
+
}
|