Skip to content

Repository files navigation

Alete Gate: The Sovereign Edge Threshold πŸ›‘οΈ

Alete Gate is a high-performance, privacy-first ingestion and classification layer for the Alete ecosystem. It serves as a "Sovereign Threshold"β€”identifying sensitive transactional portals (banking, health, PII) locally on-device before any data is processed for analysis.

πŸš€ Key Features

  • Contextual Transformer Classification: High-fidelity native inference using Apple's NLContextualEmbedding (BERT) transfer learning substrate.
  • Adaptive Tokenization: Preserves natural language lowercase context during ingestion to retain semantic signals for transformer embeddings.
  • camelCase Feature Namespaces: Transforms synthetic attributes (e.g., urlHostGithubCom) to prevent NLTokenizer split leakage.
  • Layout Density Detection: Automatically detects text-to-link ratio to append structural helper flags (layoutHighTextDensity / layoutHighLinkDensity).
  • Semantic Metadata Extraction: Powered by @mdream/js with fallback heuristics to extract titles and descriptions from fragmented HTML.
  • WXT-Optimized: Zero-dependency browser bundle (332KB) with Node.js shims, ready for Safari and Chrome extensions.

πŸ“Š Performance Telemetry (MobileBERT Substrate)

Based on the latest Strategic Verification Audit conducted on the on-device MobileBERT sequence classifier:

1. Dataset Scale

  • Main Training Set (Balanced): 820 samples
  • Staging Holdout Test Set (Generalization): 280 samples

2. Operational Metrics (Generalization)

Metric Legacy Baseline (PrivacyGatekeeper) New MobileBERT (Quantized INT4) Delta
Accuracy 55.71% 76.79% +21.08%
Avg. Inference Latency 14.99 ms 5.34 ms -9.65 ms (2.8x faster)
False Negatives (Leaks) 94 4 -90 leaks (18x safer)
Model Size 1.3 MB 13.0 MB INT4 Quantized

3. Generalization Performance Matrix (Staging Holdout Test Set)

Category Precision Recall (Success Rate) F1 Score Support
privacy_work 98.88% 96.70% 97.78% 91
noise 89.12% 84.52% 86.75% 155
informational 50.00% 64.52% 56.34% 31
communication 25.00% 33.33% 28.57% 3

Tests executed on the quantized MobileBERTGatekeeper model (v3.1.0) using the native Swift package unit tests and the Python verification harness.


🧩 System Architecture & Workflows

1. Ingestion & On-Device Processing Pipeline

This flowchart illustrates how a raw web page's HTML is extracted, sanitized, tokenized, and classified on-device without leaking user activity:

graph TD
    HTML[Raw HTML Page] -->|M-Dream Parser| MD[Markdown + Structural Tags]
    MD -->|PII Redaction & Formatter| Norm[Linguistic Input Normalizer]
    Norm -->|Semantic Cap: 300 chars| Prompt[Normalized Prompt String]
    Prompt -->|BERTTokenizer vocab.txt| Tokens[WordPiece Token IDs]
    Tokens -->|CLS, SEP Padding/Clamping to 128| InputProvider[MobileBERTInputProvider]
    InputProvider -->|input_ids, attention_mask, token_type_ids| ML[MobileBERT MLModel]
    ML -->|Softmax over Logits| Pred[Class Probability Mapping]
    Pred -->|Argmax Label| Output[Result: privacy_work, informational, communication, noise]
Loading

How to run Ingestion

  1. TypeScript (Browser/Node): Call processHtml from @alete-ai/gate-ingest to extract the normalized text and structural tokens.
  2. Swift (iOS/macOS): Instantiate GateClassifier to automatically compile, tokenize, and execute standard Core ML prediction.

2. Dataset Compilation & Retraining Pipeline

This flowchart illustrates the end-to-end retraining flow, combining raw production telemetry with gap-filling synthetic templates to produce the optimized Core ML model:

graph TD
    MongoDB[MongoDB Raw Staging Extractions] -->|pnpm retrain| Pull[Fetch Telemetry Data]
    Templates[Synthetic Privacy & Work Templates] -->|Generate Gap Fillers| Comp[Dataset Compiler]
    Pull --> Comp
    Comp -->|Vertex Gemini 3.5 Flash| Label[LLM Ground-Truth Labeler]
    Label -->|Linguistic Normalizer Parity| Dataset[Compiled Train/Test Curation Sets]
    Dataset -->|PyTorch Fine-Tuning venv| PyModel[MobileBERT PyTorch Model]
    PyModel -->|coremltools FP16 Convert| CoreML[Core ML Package]
    CoreML -->|coremltools Quantization| INT4[INT4 Quantized Model 13MB]
    INT4 -->|verify_mobilebert.py & swift test| Audit[Strategic Verification Audit]
Loading

How to execute Retraining

To retrain the model and build the compiled Core ML targets:

  1. Ensure your local virtual environment is active and contains transformers, torch, and coremltools.
  2. Configure your MongoDB staging cluster variables and Vertex Google project credentials.
  3. Run the retraining script in the project root:
    pnpm run retrain
    This will sequentially pull telemetry data, label the entries, compile datasets, fine-tune the PyTorch MobileBERT classifier, convert it to Core ML, quantize it to INT4, and verify the accuracy.

πŸ“¦ Packages

1. @alete/gate-ingest (npm)

The unified pipeline for converting HTML into structural tokens and semantic Markdown.

Installation:

pnpm add @alete/gate-ingest

Usage (Browser/Node):

import { processHtml } from '@alete-ai/gate-ingest';

const html = "<html>...</html>";
const { structural, semantic } = await processHtml(html);

2. AleteGateKit (Swift Package)

The native Apple Intelligence bridge for on-device classification.

Integration (SPM): Add this repository to your Xcode project or Package.swift:

.package(url: "https://github.com/alete-ai/gate.git", branch: "main")

⚑ Quick Recipes (AI-Ready Snippets)

These snippets are optimized for high-performance integration and clear semantic understanding by AI agents.

How to identify sensitive portals in a browser extension?

import { processHtml } from '@alete-ai/gate-ingest';

/**
 * Capture and Purify
 * This recipe prepares content for classification.
 */
async function capturePage() {
  const html = document.documentElement.outerHTML;
  const { structural, semantic } = await processHtml(html);

  return structural; // Prepared for local classification
}

How to use the native PrivacyGatekeeper in an iOS App?

import AleteGateKit
import CoreML

/**
 * Edge Classification Loop
 * Evaluates structural tokens against the PrivacyGatekeeper model.
 */
func classifyContent(tokens: String) async throws -> String {
    let gatekeeper = try PrivacyGatekeeper()
    let prediction = try gatekeeper.prediction(text: tokens)
    
    // returns 'privacy_work', 'informational', 'communication', or 'noise'
    return prediction.label 
}

πŸ› οΈ Development & Build

Build Pipeline

# Install dependencies
pnpm install

# Build all packages (including browser-optimized ESM)
pnpm build

# Run native substrate tests
cd ios/AleteGateKit && swift test

Generating XCFramework

./scripts/build_xcframework.sh

πŸ›‘οΈ Privacy & Strategy

Alete Gate prioritizes Cognitive Sovereignty by ensuring all classification happens on the edge substrate. We utilize empirical performance tracking to ensure the highest possible recall on sensitive portals while maintaining a friction-less user experience.

πŸ“„ License

AGPL-3.0 - Copyright (c) 2026 Alete Inc. https://github.com/StoyanD

Releases

Packages

Contributors

Languages