@o-lang/olang 1.4.0-alpha.1 → 1.4.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@o-lang/olang",
3
- "version": "1.4.0-alpha.1",
3
+ "version": "1.4.1",
4
4
  "author": "Olalekan Ogundipe <info@olang.cloud>",
5
5
  "description": "O-Lang: A governance language for user-directed, rule-enforced agent workflows with native African language PII protection.",
6
6
  "main": "./src/runtime/index.js",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "files": [
11
11
  "src/",
12
- "cli/",
12
+ "cli/",
13
13
  "README.md",
14
14
  "LICENSE"
15
15
  ],
@@ -57,4 +57,4 @@
57
57
  "devDependencies": {
58
58
  "jest": "^29.7.0"
59
59
  }
60
- }
60
+ }
@@ -315,6 +315,20 @@ function parseWorkflowLines(lines, filename) {
315
315
 
316
316
  // --- 7. Standard Steps & Keywords ---
317
317
 
318
+ // Calculate (NEW v1.4.0 — math expression evaluation)
319
+ const calcMatch = line.match(/^Calculate\s+(.+)$/i);
320
+ if (calcMatch) {
321
+ flushCurrentStep();
322
+ workflow.steps.push({
323
+ type: 'calculate',
324
+ expression: calcMatch[1].trim(),
325
+ stepNumber: workflow.steps.length + 1,
326
+ saveAs: null,
327
+ constraints: {}
328
+ });
329
+ continue;
330
+ }
331
+
318
332
  // Connect: Connect "name" to url "..." OR Connect "name" to resolver "..."
319
333
  const connectMatch = line.match(/^Connect\s+"([^"]+)"\s+to\s+(url|resolver)\s+"([^"]+)"$/i);
320
334
  if (connectMatch) {
@@ -468,7 +482,7 @@ function parseWorkflowLines(lines, filename) {
468
482
 
469
483
  flushCurrentStep();
470
484
 
471
- // Post-process Save as in actionRaw
485
+ // Post-process Save as in actionRaw AND expression (calculate steps)
472
486
  workflow.steps.forEach(step => {
473
487
  if (step.actionRaw && step.saveAs === null) {
474
488
  const saveInAction = step.actionRaw.match(/(.+?)\s+Save as\s+(.+)$/i);
@@ -477,6 +491,14 @@ function parseWorkflowLines(lines, filename) {
477
491
  step.saveAs = normalizeSymbol(saveInAction[2].trim());
478
492
  }
479
493
  }
494
+ // ✅ NEW: Handle Calculate steps with inline Save as
495
+ if (step.type === 'calculate' && step.expression && step.saveAs === null) {
496
+ const saveInExpr = step.expression.match(/(.+?)\s+Save as\s+(.+)$/i);
497
+ if (saveInExpr) {
498
+ step.expression = saveInExpr[1].trim();
499
+ step.saveAs = normalizeSymbol(saveInExpr[2].trim());
500
+ }
501
+ }
480
502
  if (step.saveAs) {
481
503
  step.saveAs = normalizeSymbol(step.saveAs);
482
504
  }
@@ -504,6 +526,19 @@ function parseBlock(lines) {
504
526
  line = line.trim();
505
527
  if (!line || line.startsWith('#')) continue;
506
528
 
529
+ // Calculate in Block (NEW v1.4.0)
530
+ const calcMatch = line.match(/^Calculate\s+(.+)$/i);
531
+ if (calcMatch) {
532
+ flush();
533
+ steps.push({
534
+ type: 'calculate',
535
+ expression: calcMatch[1].trim(),
536
+ saveAs: null,
537
+ constraints: {}
538
+ });
539
+ continue;
540
+ }
541
+
507
542
  // Connect in Block
508
543
  const connectMatch = line.match(/^Connect\s+"([^"]+)"\s+to\s+(url|resolver)\s+"([^"]+)"$/i);
509
544
  if (connectMatch) {
@@ -604,6 +639,14 @@ function parseBlock(lines) {
604
639
  step.saveAs = normalizeSymbol(saveInAction[2].trim());
605
640
  }
606
641
  }
642
+ // ✅ NEW: Handle Calculate steps with inline Save as in blocks
643
+ if (step.type === 'calculate' && step.expression && step.saveAs === null) {
644
+ const saveInExpr = step.expression.match(/(.+?)\s+Save as\s+(.+)$/i);
645
+ if (saveInExpr) {
646
+ step.expression = saveInExpr[1].trim();
647
+ step.saveAs = normalizeSymbol(saveInExpr[2].trim());
648
+ }
649
+ }
607
650
  if (step.saveAs) {
608
651
  step.saveAs = normalizeSymbol(step.saveAs);
609
652
  }
@@ -3,7 +3,7 @@ const path = require('path');
3
3
  const crypto = require('crypto'); // ✅ CRYPTOGRAPHIC AUDIT LOGS
4
4
 
5
5
  // ✅ O-Lang Kernel Version (Safety Logic & Governance Rules)
6
- const KERNEL_VERSION = '1.4.0-alpha.1'; // 🔁 Bumped: PII redaction engine added
6
+ const KERNEL_VERSION = '1.4.1'; // 🔁 Bumped: PII redaction engine added
7
7
 
8
8
  // ─────────────────────────────────────────────────────────────────────────────
9
9
  // ✅ NEW v1.3.0 — SEPARATED PATTERN SETS
@@ -5,12 +5,13 @@ const crypto = require('crypto');
5
5
  const fs = require('fs');
6
6
  const path = require('path');
7
7
 
8
- // ── Load kernel private key (cached) ─────────────────────────────────────────
9
- let KERNEL_PRIVATE_KEY = null;
10
-
11
- function getKernelPrivateKey() {
12
- if (KERNEL_PRIVATE_KEY) return KERNEL_PRIVATE_KEY;
8
+ // ── Load kernel private key ───────────────────────────────────────────────────
9
+ // FIX: Load at module initialisation time (when kernel boots) instead of
10
+ // lazily on the first execute() call. This prevents a 5-10s delay on the
11
+ // first request caused by RSA key file I/O + audit chain signing overhead.
12
+ // ─────────────────────────────────────────────────────────────────────────────
13
13
 
14
+ function _loadPrivateKey() {
14
15
  const keyPath = process.env.KERNEL_PRIVATE_KEY_PATH || './kernel-keys/kernel-private.pem';
15
16
  const absolutePath = path.isAbsolute(keyPath)
16
17
  ? keyPath
@@ -22,11 +23,37 @@ function getKernelPrivateKey() {
22
23
  return null;
23
24
  }
24
25
 
25
- KERNEL_PRIVATE_KEY = fs.readFileSync(absolutePath, 'utf8');
26
+ const key = fs.readFileSync(absolutePath, 'utf8');
26
27
  console.log('[kernel] ✅ Private key loaded for signing');
27
- return KERNEL_PRIVATE_KEY;
28
+ return key;
28
29
  }
29
30
 
31
+ // Loaded once at require() time — cached for all subsequent execute() calls
32
+ const KERNEL_PRIVATE_KEY = _loadPrivateKey();
33
+
34
+ function _loadPublicKey() {
35
+ if (!KERNEL_PRIVATE_KEY) return null;
36
+ try {
37
+ const pubKeyPath = process.env.KERNEL_PUBLIC_KEY_PATH || './kernel-keys/kernel-public.pem';
38
+ const absolutePubPath = path.isAbsolute(pubKeyPath)
39
+ ? pubKeyPath
40
+ : path.join(process.cwd(), pubKeyPath);
41
+
42
+ if (!fs.existsSync(absolutePubPath)) return null;
43
+
44
+ return fs.readFileSync(absolutePubPath, 'utf8')
45
+ .replace('-----BEGIN PUBLIC KEY-----', '')
46
+ .replace('-----END PUBLIC KEY-----', '')
47
+ .replace(/\s/g, '');
48
+ } catch (err) {
49
+ console.warn('[kernel] Could not load public key:', err.message);
50
+ return null;
51
+ }
52
+ }
53
+
54
+ // Also loaded once at require() time
55
+ const KERNEL_PUBLIC_KEY = _loadPublicKey();
56
+
30
57
  // ── Sign audit data with RSA-SHA256 ──────────────────────────────────────────
31
58
  // Uses RSA-SHA256 to match the RSA key generated by crypto.generateKeyPairSync.
32
59
  // The same sorted JSON serialization is used during verification.
@@ -72,35 +99,14 @@ async function execute(workflow, inputs, agentResolver, verbose = false) {
72
99
  chain: rt.auditLog,
73
100
  };
74
101
 
75
- // Sign the audit data with the kernel private key
76
- const privateKey = getKernelPrivateKey();
77
- const signature = signAuditData(auditData, privateKey);
78
-
79
- // Load public key for client-side verification (stripped PEM)
80
- let publicKey = null;
81
- if (privateKey) {
82
- try {
83
- const pubKeyPath = process.env.KERNEL_PUBLIC_KEY_PATH || './kernel-keys/kernel-public.pem';
84
- const absolutePubPath = path.isAbsolute(pubKeyPath)
85
- ? pubKeyPath
86
- : path.join(process.cwd(), pubKeyPath);
87
-
88
- if (fs.existsSync(absolutePubPath)) {
89
- publicKey = fs.readFileSync(absolutePubPath, 'utf8')
90
- .replace('-----BEGIN PUBLIC KEY-----', '')
91
- .replace('-----END PUBLIC KEY-----', '')
92
- .replace(/\s/g, '');
93
- }
94
- } catch (err) {
95
- console.warn('[kernel] Could not load public key:', err.message);
96
- }
97
- }
102
+ // FIX: Use pre-loaded keys no file I/O on hot path
103
+ const signature = signAuditData(auditData, KERNEL_PRIVATE_KEY);
98
104
 
99
105
  // Attach audit to result — server.js detaches it before sending to client
100
106
  result.__audit = {
101
107
  ...auditData,
102
- signature, // RSA-SHA256 hex signature
103
- publicKey, // Stripped PEM for client verification
108
+ signature, // RSA-SHA256 hex signature
109
+ publicKey: KERNEL_PUBLIC_KEY, // Stripped PEM for client verification
104
110
  };
105
111
 
106
112
  return result;
@@ -115,5 +121,4 @@ function redact(text) {
115
121
  return rt.redact(text);
116
122
  }
117
123
 
118
-
119
124
  module.exports = { execute, parse, redact };