@o-lang/olang 1.2.21 → 1.2.23

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.21",
3
+ "version": "1.2.23",
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",
@@ -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
  // -----------------------------
@@ -855,23 +919,28 @@ class RuntimeAPI {
855
919
  c.includes('withdraw')
856
920
  );
857
921
 
858
- if (!hasCapability) {
859
- const match = output.match(pattern);
860
-
861
- // ✅ Explicitly flag African & Financial context for Audit Logs
862
- const isAfrican = ['yo', 'ig', 'ha', 'sw', 'zu', 'am', 'om', 'ff', 'so', 'sn'].includes(lang);
863
- const isFinancial = ['transfer', 'payment', 'withdrawal', 'deposit', 'financial_action'].includes(capability);
864
-
865
- return {
866
- passed: false,
867
- reason: `Hallucinated "${capability}" capability in ${lang}...`,
868
- detected: match ? match[0].trim() : 'unknown pattern',
869
- language: lang,
870
- african_language_detected: isAfrican,
871
- financial_expression_found: isFinancial,
872
- capability_attempted: capability
873
- };
874
- }
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
+ }
939
+ }
940
+ }
941
+ return { passed: true };
942
+ }
943
+
875
944
  // -----------------------------
876
945
  // ✅ CRITICAL FIX: Resolver output unwrapping helper
877
946
  // -----------------------------
@@ -1405,7 +1474,7 @@ class RuntimeAPI {
1405
1474
  const db = this.dbClient.client.db(process.env.DB_NAME || 'olang');
1406
1475
  await db.collection(step.collection).insertOne({
1407
1476
  workflow_name: this.context.workflow_name || 'unknown',
1408
- data: sourceValue,
1477
+ sourceValue,
1409
1478
  created_at: new Date()
1410
1479
  });
1411
1480
  break;
@@ -1446,6 +1515,9 @@ class RuntimeAPI {
1446
1515
  workflow_name: workflow.name
1447
1516
  };
1448
1517
 
1518
+ // ✅ NEW: Validate Inputs BEFORE any step runs
1519
+ this._validateInputs(inputs);
1520
+
1449
1521
  // ✅ AUDIT LOG: Workflow start (ENHANCED with governance metadata)
1450
1522
  const governanceHash = this._generateGovernanceProfileHash(workflow);
1451
1523