diff --git a/docs/plans/TRANSLATION_APPROACH.md b/docs/plans/TRANSLATION_APPROACH.md new file mode 100644 index 00000000..1af102ea --- /dev/null +++ b/docs/plans/TRANSLATION_APPROACH.md @@ -0,0 +1,233 @@ +# Translation Approach for Task 19: Te Reo Māori & Multilanguage Support + +**Date:** October 12, 2025 +**Status:** Planning - To be implemented after Task 12 (API Documentation) +**Priority:** CRITICAL (Values - Te Tiriti commitment) + +--- + +## Translation Service: DeepL + +**Decision:** Use DeepL API for translation services instead of i18next manual translations + +### Deployment Architecture + +**Local Development (Port 9000):** +- DeepL API integration in Node.js +- Local environment variable: `DEEPL_API_KEY` +- Translation caching in MongoDB + +**Production Server (vps-93a693da.vps.ovh.net):** +- DeepL API integration deployed +- Secure environment variable configuration +- Production translation cache + +--- + +## Implementation Plan + +### 1. DeepL API Integration + +```javascript +// Example integration approach +const deepl = require('deepl-node'); + +const translator = new deepl.Translator(process.env.DEEPL_API_KEY); + +async function translateContent(text, targetLang) { + const result = await translator.translateText(text, null, targetLang); + return result.text; +} +``` + +### 2. Language Selector UI + +- **Location:** Navigation bar (all pages) +- **Languages:** English (en), Te Reo Māori (mi) +- **Storage:** Browser localStorage + cookie +- **Behavior:** Persist selection across sessions + +### 3. Translation Cache + +**MongoDB Collection:** `translations` + +```javascript +{ + source_text: String, + source_lang: String, + target_lang: String, + translated_text: String, + verified: Boolean, + created_at: Date, + updated_at: Date +} +``` + +**Benefits:** +- Reduces API calls +- Faster page loads +- Cost optimization +- Human verification workflow + +### 4. Priority Pages for Translation + +**Phase 1 (Task 19):** +- Homepage (index.html) +- About/Values page (about.html) +- Core Framework Documentation + +**Phase 2 (Future):** +- All audience paths (researcher, implementer, advocate) +- Interactive demos +- Blog posts +- API documentation + +### 5. Māori Language Consultation + +**Critical:** Despite using DeepL, Māori language consultation is REQUIRED + +**Why:** +- Cultural appropriateness review +- Technical term accuracy +- Idiomatic expressions +- Values alignment + +**Process:** +1. DeepL generates initial translation +2. Store in database as `verified: false` +3. Submit to Māori language consultant +4. Update with corrections +5. Mark as `verified: true` + +### 6. Rate Limiting & Cost Management + +**DeepL API Limits:** +- Free tier: 500,000 characters/month +- Pro tier: Pay per character + +**Strategy:** +- Cache all translations +- Batch translation requests +- Monitor character usage +- Set monthly budget alerts + +--- + +## Technical Implementation + +### Routes + +```javascript +// POST /api/translate +// Translate text to specified language +router.post('/translate', async (req, res) => { + const { text, targetLang } = req.body; + + // Check cache first + const cached = await Translation.findOne({ + source_text: text, + target_lang: targetLang, + verified: true + }); + + if (cached) { + return res.json({ translation: cached.translated_text }); + } + + // Call DeepL API + const translation = await translateContent(text, targetLang); + + // Store in cache + await Translation.create({ + source_text: text, + source_lang: 'en', + target_lang: targetLang, + translated_text: translation, + verified: false + }); + + res.json({ translation }); +}); +``` + +### Frontend Integration + +```javascript +// Language selector component +class LanguageSelector { + constructor() { + this.currentLang = localStorage.getItem('lang') || 'en'; + } + + async switchLanguage(lang) { + localStorage.setItem('lang', lang); + await this.translatePage(lang); + } + + async translatePage(lang) { + if (lang === 'en') { + // Reload original content + location.reload(); + return; + } + + // Translate all translatable elements + const elements = document.querySelectorAll('[data-translate]'); + for (const el of elements) { + const originalText = el.textContent; + const translation = await this.translate(originalText, lang); + el.textContent = translation; + } + } +} +``` + +--- + +## Configuration + +### Environment Variables + +**Development (.env):** +```bash +DEEPL_API_KEY=your_dev_key +DEEPL_API_FREE_TIER=true +TRANSLATION_CACHE_ENABLED=true +``` + +**Production (remote):** +```bash +DEEPL_API_KEY=your_prod_key +DEEPL_API_FREE_TIER=false +TRANSLATION_CACHE_ENABLED=true +TRANSLATION_VERIFICATION_REQUIRED=true +``` + +--- + +## Success Criteria + +- [ ] DeepL API integrated on both dev and production +- [ ] Language selector functional in navigation +- [ ] Translation caching working +- [ ] Homepage, About, Core Docs translated to Te Reo Māori +- [ ] Māori language consultant review completed +- [ ] All translations marked as verified +- [ ] User preference persists across sessions +- [ ] Performance: <500ms translation load time (cached) + +--- + +## Notes + +- **Cost Estimate:** Homepage + About + Core Docs ≈ 50,000 characters +- **DeepL Free Tier:** Sufficient for Phase 1 +- **Future:** Add more languages (Samoan, Tongan, Cook Islands Māori, etc.) +- **Accessibility:** Ensure `lang` attribute updated on `` tag +- **SEO:** Consider separate URLs vs. client-side switching + +--- + +**To Be Implemented:** After Task 12 (API Documentation) completion +**Dependencies:** DeepL API account, MongoDB translations collection, Māori language consultant +**Timeline:** 5-7 days estimated diff --git a/public/api-reference.html b/public/api-reference.html index d99306a7..449e47e6 100644 --- a/public/api-reference.html +++ b/public/api-reference.html @@ -46,7 +46,13 @@
+ Note: All governance endpoints require admin authentication. These services implement architectural AI safety through runtime enforcement. +
+/governance
+ 🔒 Admin Only
Get governance framework status.
+Get overall governance framework status.
+ +Authorization: Bearer {admin_token}
{
@@ -256,11 +273,467 @@
"pressure": { "enabled": true, "status": "operational" },
"metacognitive": { "enabled": true, "status": "selective" }
},
- "instruction_count": 7,
- "last_validation": "2025-10-07T12:00:00Z"
+ "instruction_count": 28,
+ "last_validation": "2025-10-12T10:00:00Z"
}
}
Classifies instructions by quadrant (STRATEGIC/OPERATIONAL/TACTICAL/SYSTEM) and assigns persistence levels.
+ +/governance/classify
+ 🔒 Admin Only
+ Classify an instruction and get its quadrant, persistence level, and temporal scope.
+ +{
+ "text": "Always use MongoDB on port 27027",
+ "context": {
+ "source": "user",
+ "session_id": "sess_123"
+ }
+}
+
+ {
+ "success": true,
+ "classification": {
+ "quadrant": "SYSTEM",
+ "persistence": "HIGH",
+ "temporal_scope": "PROJECT",
+ "verification_required": "MANDATORY",
+ "reasoning": "Port configuration affects system infrastructure",
+ "confidence": 0.95
+ }
+}
+
+ | STRATEGIC | +Values, ethics, mission, Te Tiriti commitments | +
| OPERATIONAL | +Architecture, deployment, configuration | +
| TACTICAL | +Bug fixes, features, code changes | +
| SYSTEM | +Environment, infrastructure, database, tooling | +
| STOCHASTIC | +One-off requests, experimental, temporary | +
Prevents training pattern override ("27027 failure mode") by validating actions against stored instructions.
+ +/governance/validate
+ 🔒 Admin Only
+ Validate a proposed action against instruction history to detect conflicts.
+ +{
+ "action": {
+ "type": "database_config",
+ "target": "MongoDB",
+ "parameters": {
+ "port": 27017
+ }
+ },
+ "context": {
+ "messages": [],
+ "session_id": "sess_123"
+ }
+}
+
+ {
+ "success": true,
+ "validation": {
+ "status": "REJECTED",
+ "reason": "Pattern recognition override detected",
+ "conflicts": [
+ {
+ "instruction_id": "inst_008",
+ "text": "Always use MongoDB on port 27027",
+ "quadrant": "SYSTEM",
+ "persistence": "HIGH"
+ }
+ ],
+ "recommendation": "Use port 27027 as explicitly instructed"
+ }
+}
+
+ | APPROVED | +No conflicts, proceed safely | +
| REJECTED | +Conflicts with HIGH persistence instructions | +
| WARNING | +Potential conflicts, proceed with caution | +
Blocks values decisions requiring human judgment (privacy, ethics, strategic direction).
+ +/governance/enforce
+ 🔒 Admin Only
+ Check if a decision crosses into values territory and requires human approval.
+ +{
+ "action": {
+ "type": "policy_change",
+ "description": "Update privacy policy to enable more tracking",
+ "impact": "user_privacy"
+ },
+ "context": {
+ "requested_by": "user",
+ "reason": "improve analytics"
+ }
+}
+
+ {
+ "success": true,
+ "enforcement": {
+ "decision": "BLOCK",
+ "category": "VALUES_DECISION",
+ "reason": "Privacy vs. analytics trade-off requires human judgment",
+ "boundary_crossed": "privacy",
+ "requires_approval": true,
+ "alternatives": [
+ "Implement privacy-preserving analytics (Plausible/Fathom)",
+ "Consult user on acceptable tracking level",
+ "Review compliance with sovereignty principles"
+ ]
+ }
+}
+
+ | privacy | +User data, tracking, surveillance | +
| ethics | +Moral trade-offs, fairness, harm | +
| sovereignty | +Indigenous rights, Te Tiriti, CARE principles | +
| strategic | +Mission changes, major pivots | +
Multi-factor session health tracking to detect degradation before failures occur.
+ +/governance/pressure
+ 🔒 Admin Only
+ Analyze session context pressure across multiple factors.
+ +{
+ "context": {
+ "tokenUsage": 120000,
+ "tokenBudget": 200000,
+ "messageCount": 45,
+ "errorCount": 3,
+ "complexOperations": 8,
+ "sessionDuration": 3600
+ }
+}
+
+ {
+ "success": true,
+ "pressure": {
+ "level": "ELEVATED",
+ "score": 62.5,
+ "factors": {
+ "token_usage": { "value": 60, "weight": 0.4, "status": "ELEVATED" },
+ "message_depth": { "value": 45, "weight": 0.2, "status": "NORMAL" },
+ "error_rate": { "value": 6.7, "weight": 0.3, "status": "ELEVATED" },
+ "complexity": { "value": 8, "weight": 0.1, "status": "HIGH" }
+ },
+ "recommendation": "INCREASE_VERIFICATION",
+ "actions": [
+ "Review recent errors for patterns",
+ "Consider session checkpoint at 75% tokens",
+ "Reduce concurrent complex operations"
+ ],
+ "next_checkpoint": 150000
+ }
+}
+
+ | NORMAL | +0-40% - Standard operation | +
| ELEVATED | +41-60% - Increase verification | +
| HIGH | +61-80% - Consider checkpoint | +
| CRITICAL | +81-95% - Session handoff recommended | +
| DANGEROUS | +96-100% - Quality degradation likely | +
AI self-checks for complex operations to detect scope creep and misalignment.
+ +/governance/verify
+ 🔒 Admin Only
+ Verify proposed action through metacognitive self-assessment.
+ +{
+ "action": {
+ "type": "refactor",
+ "scope": "Refactor 47 files across 5 system areas",
+ "complexity": "high"
+ },
+ "reasoning": {
+ "intent": "Improve code organization",
+ "approach": "Extract shared utilities, consolidate duplicates",
+ "risks": "Potential breaking changes"
+ },
+ "context": {
+ "requested": "Refactor authentication module",
+ "original_scope": "single module"
+ }
+}
+
+ {
+ "success": true,
+ "verification": {
+ "decision": "REQUIRE_REVIEW",
+ "confidence": 0.45,
+ "concerns": [
+ {
+ "type": "SCOPE_CREEP",
+ "severity": "HIGH",
+ "detail": "Proposed scope (47 files, 5 areas) exceeds request (1 module)"
+ },
+ {
+ "type": "COMPLEXITY",
+ "severity": "MEDIUM",
+ "detail": "High-risk refactoring without test coverage verification"
+ }
+ ],
+ "criteria": {
+ "alignment": 0.3,
+ "coherence": 0.8,
+ "completeness": 0.9,
+ "safety": 0.4,
+ "alternatives_considered": 0.5
+ },
+ "recommendation": "Reduce scope to requested authentication module first",
+ "alternatives": [
+ "Refactor authentication module only (aligned with request)",
+ "Create phased refactoring plan with user approval",
+ "Run comprehensive tests before broader refactoring"
+ ]
+ }
+}
+
+ | APPROVED | +High confidence (>0.85), proceed | +
| REQUIRE_REVIEW | +Medium confidence (0.5-0.85), seek approval | +
| REJECTED | +Low confidence (<0.5), do not proceed | +
Comprehensive audit trail of all governance decisions and framework activity.
+ +/audit/audit-logs
+ 🔒 Admin Only
+ Retrieve audit logs with filtering and pagination.
+ +| limit | +Number of results (default: 50, max: 100) | +
| skip | +Pagination offset (default: 0) | +
| service | +Filter by service (classifier, validator, etc.) | +
| status | +Filter by status (APPROVED, REJECTED, etc.) | +
| from | +Start date (ISO 8601 format) | +
{
+ "success": true,
+ "logs": [
+ {
+ "_id": "672f8xxx",
+ "service": "CrossReferenceValidator",
+ "action": "validate_action",
+ "status": "REJECTED",
+ "details": {
+ "conflict": "Pattern override detected (port 27017 vs 27027)",
+ "instruction_id": "inst_008"
+ },
+ "timestamp": "2025-10-12T10:15:30Z",
+ "session_id": "sess_123"
+ },
+ {
+ "_id": "672f8yyy",
+ "service": "BoundaryEnforcer",
+ "action": "enforce_boundary",
+ "status": "BLOCKED",
+ "details": {
+ "category": "VALUES_DECISION",
+ "boundary": "privacy"
+ },
+ "timestamp": "2025-10-12T09:45:22Z",
+ "session_id": "sess_122"
+ }
+ ],
+ "total": 145,
+ "limit": 50,
+ "skip": 0
+}
+ /audit/audit-analytics
+ 🔒 Admin Only
+ Get aggregated analytics on audit activity.
+ +{
+ "success": true,
+ "analytics": {
+ "total_events": 1245,
+ "by_service": {
+ "CrossReferenceValidator": 425,
+ "BoundaryEnforcer": 78,
+ "ContextPressureMonitor": 312,
+ "InstructionPersistenceClassifier": 298,
+ "MetacognitiveVerifier": 132
+ },
+ "by_status": {
+ "APPROVED": 1089,
+ "REJECTED": 78,
+ "WARNING": 45,
+ "BLOCKED": 33
+ },
+ "rejection_rate": 6.3,
+ "period": {
+ "start": "2025-10-01T00:00:00Z",
+ "end": "2025-10-12T23:59:59Z",
+ "days": 12
+ }
+ }
+}
+