@o-lang/olang 1.2.20 → 1.2.22

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.2.20",
3
+ "version": "1.2.22",
4
4
  "author": "Olalekan Ogundipe <info@olang.cloud>",
5
5
  "description": "O-Lang: A governance language for user-directed, rule-enforced agent workflows",
6
6
  "main": "./src/runtime/index.js",
@@ -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.2.15-alpha'; // 🔁 Update when safety rules change
6
+ const KERNEL_VERSION = '1.2.20-alpha'; // 🔁 Update when safety rules change
7
7
 
8
8
  class RuntimeAPI {
9
9
  constructor({ verbose = false } = {}) {
@@ -721,6 +721,70 @@ class RuntimeAPI {
721
721
  });
722
722
  }
723
723
 
724
+ // -----------------------------
725
+ // ✅ KERNEL-LEVEL INPUT VALIDATION (Pre-Flight Safety)
726
+ // -----------------------------
727
+ _validateInputs(inputs) {
728
+ // Only scan specific input fields that contain user text
729
+ const fieldsToScan = ['user_message', 'user_question', 'text', 'prompt', 'document_text'];
730
+
731
+ for (const field of fieldsToScan) {
732
+ const text = inputs[field];
733
+ if (!text || typeof text !== 'string') continue;
734
+
735
+ // Re-use the exact same forbiddenPatterns from _validateLLMOutput
736
+ // 🔒 CONJUGATION-AWARE + EVASION-RESISTANT PAN-AFRICAN INTENT DETECTION
737
+ const forbiddenPatterns = [
738
+ // 🇳🇬 NIGERIAN LANGUAGES
739
+ { pattern: /\b(fi\s+(?:owo|ẹ̀wọ̀|ewo|ku|fun|s'ọkọọ))\b/i, capability: 'transfer', lang: 'yo' },
740
+ { pattern: /\b(ranṣẹ\s+(?:owo|pesa|kuɗi|ego)|fi\s+.*\s+ranṣẹ)\b/i, capability: 'transfer', lang: 'yo' },
741
+ { pattern: /\b(ciyar\s*(?:da)?|shiga\s+kuɗi)\b/i, capability: 'transfer', lang: 'ha' },
742
+ { pattern: /\b(aika\s+(?:kuɗi)|turo\s+.*\s+aika)\b/i, capability: 'transfer', lang: 'ha' },
743
+ { pattern: /\b(zipu\s+(?:ego|moni)|zi\s+.*\s+zipu)\b/i, capability: 'transfer', lang: 'ig' },
744
+ { pattern: /\b(buru\s+(?:ego|moni))\b/i, capability: 'transfer', lang: 'ig' },
745
+ // 🌐 GLOBAL
746
+ { pattern: /\b(transfer(?:red|ring)?|send(?:t|ing)?|wire(?:d)?)\b/i, capability: 'financial_action', lang: 'en' },
747
+ { pattern: /\bI\s+(?:can|will|am able to)\s+(?:transfer|send|pay)\b/i, capability: 'unauthorized_action', lang: 'en' },
748
+ // 🛡️ PII
749
+ { pattern: /\b(?:account|acct|akaunti|asusu|hesabu|namba|#)\s*[:\-—–]?\s*(\d{6,})\b/i, capability: 'pii_exposure', lang: 'multi' },
750
+ { pattern: /\b(?:bvn|bank verification number)\s*[:\-]?\s*(\d{11})\b/i, capability: 'pii_exposure', lang: 'multi' },
751
+ { pattern: /\b(?:\+?234\s*|0)(?:70|80|81|90|91)\d{8}\b/, capability: 'pii_exposure', lang: 'multi' },
752
+ ];
753
+
754
+ for (const { pattern, capability, lang } of forbiddenPatterns) {
755
+ if (pattern.test(text)) {
756
+ const match = text.match(pattern);
757
+ const isAfrican = ['yo', 'ig', 'ha', 'sw', 'zu', 'am', 'om', 'ff', 'so', 'sn'].includes(lang);
758
+ const isFinancial = ['transfer', 'payment', 'withdrawal', 'deposit', 'financial_action'].includes(capability);
759
+
760
+ // ✅ AUDIT LOG: Input Safety Violation
761
+ this._createAuditEntry('input_safety_violation', {
762
+ type: 'blocked_input',
763
+ field: field,
764
+ detected_phrase: match ? match[0].trim() : 'unknown pattern',
765
+ capability: capability,
766
+ language: lang,
767
+ african_language_detected: isAfrican,
768
+ financial_expression_found: isFinancial,
769
+ severity: 'high'
770
+ });
771
+
772
+ throw new Error(
773
+ `[O-Lang SAFETY] Blocked Input in "${lang}":\n` +
774
+ ` → Detected: "${match ? match[0].trim() : 'Pattern Match'}"\n` +
775
+ ` → Capability: ${capability}\n` +
776
+ ` → Field: ${field}\n` +
777
+ ` → African Language Detected: ${isAfrican}\n` +
778
+ ` → Financial Expression: ${isFinancial}\n` +
779
+ `\n🛑 Workflow halted before execution.`
780
+ );
781
+ }
782
+ }
783
+ }
784
+ return { passed: true };
785
+ }
786
+
787
+
724
788
  // -----------------------------
725
789
  // ✅ KERNEL-LEVEL LLM HALLUCINATION PREVENTION (CONJUGATION-AWARE + EVASION-RESISTANT)
726
790
  // -----------------------------
@@ -816,6 +880,9 @@ class RuntimeAPI {
816
880
  { pattern: /\b(?:tumir|bhadhar)\s*a\b/i, capability: 'unauthorized_action', lang: 'sn' },
817
881
  { pattern: /\b(tumir\s*a\s+(?:mhando|ari))\b/i, capability: 'transfer', lang: 'sn' },
818
882
  { pattern: /\b(bhadhara|bhadharis\s*o)\b/i, capability: 'payment', lang: 'sn' },
883
+ { pattern: /\b(ranṣẹ\s+(?:owo|pesa|kuɗi|ego)|fi\s+.*\s+ranṣẹ)\b/i, capability: 'transfer', lang: 'yo' }, // Yoruba "Send money"
884
+ { pattern: /\b(zipu\s+(?:ego|moni)|zi\s+.*\s+zipu)\b/i, capability: 'transfer', lang: 'ig' }, // Igbo "Send money"
885
+ { pattern: /\b(aika\s+(?:kuɗi)|turo\s+.*\s+aika)\b/i, capability: 'transfer', lang: 'ha' }, // Hausa "Send money"
819
886
  // ────────────────────────────────────────────────
820
887
  // 🌐 GLOBAL LANGUAGES
821
888
  // ────────────────────────────────────────────────
@@ -852,20 +919,23 @@ class RuntimeAPI {
852
919
  c.includes('withdraw')
853
920
  );
854
921
 
855
- if (!hasCapability) {
856
- const match = output.match(pattern);
857
- return {
858
- passed: false,
859
- reason: `Hallucinated "${capability}" capability in ${lang} (not in workflow allowlist: ${allowedCapabilities.join(', ') || 'none'})`,
860
- detected: match ? match[0].trim() : 'unknown pattern',
861
- language: lang
862
- };
863
- }
864
- }
865
- }
866
-
867
- return { passed: true };
868
- }
922
+ if (!hasCapability) {
923
+ const match = output.match(pattern);
924
+
925
+ // ✅ Explicitly flag African & Financial context for Audit Logs
926
+ const isAfrican = ['yo', 'ig', 'ha', 'sw', 'zu', 'am', 'om', 'ff', 'so', 'sn'].includes(lang);
927
+ const isFinancial = ['transfer', 'payment', 'withdrawal', 'deposit', 'financial_action'].includes(capability);
928
+
929
+ return {
930
+ passed: false,
931
+ reason: `Hallucinated "${capability}" capability in ${lang}...`,
932
+ detected: match ? match[0].trim() : 'unknown pattern',
933
+ language: lang,
934
+ african_language_detected: isAfrican,
935
+ financial_expression_found: isFinancial,
936
+ capability_attempted: capability
937
+ };
938
+ }
869
939
  // -----------------------------
870
940
  // ✅ CRITICAL FIX: Resolver output unwrapping helper
871
941
  // -----------------------------
@@ -1440,6 +1510,9 @@ class RuntimeAPI {
1440
1510
  workflow_name: workflow.name
1441
1511
  };
1442
1512
 
1513
+ // ✅ NEW: Validate Inputs BEFORE any step runs
1514
+ this._validateInputs(inputs);
1515
+
1443
1516
  // ✅ AUDIT LOG: Workflow start (ENHANCED with governance metadata)
1444
1517
  const governanceHash = this._generateGovernanceProfileHash(workflow);
1445
1518