Skip to content

Conversation

@ProdByBuddha
Copy link

PR Description: Personal AI Infrastructure (PAI) Core - Rust Implementation

🎯 Overview

This PR introduces the pai-core crate, a high-performance, security-hardened Rust implementation of the Personal AI Infrastructure.
It transitions the core "Agency" logic into an adversarial-grade intelligence fabric, focusing on deterministic state management,
rigorous security validation, and modular "intelligence threads."

🏗️ Architectural Pillars

1. Deterministic Intelligence (algorithm.rs)

The heart of the crate is the Algorithm Engine, a deterministic state machine that drives the PAI lifecycle through 7 distinct
phases:

  • Phases: Observe → Think → Plan → Build → Execute → Verify → Learn.
  • ISC (Intelligent State Control): Implements requirement tracking with status management (Pending, Active, Looping, Blocked,
    Done).
  • Thread Safety: Uses RwLock and AtomicU32 for high-concurrency "swarm" environments, eliminating global mutex bottlenecks.

2. Adversarial-Grade Security (safety.rs, oracle.rs, privacy.rs)

  • SecurityValidator: A PAIHook that intercepts tool usage to block catastrophic commands (rm -rf /), reverse shells, and data
    exfiltration patterns.
  • VerificationOracle: Restricts execution to a strict whitelist and implements SSRF Protection by enforcing HTTPS for external
    lookups and blocking internal IP probing.
  • PrivacyGuard: Automated PII redaction for API keys, Bearer tokens, and internal IPs using pre-compiled regex patterns.

3. Modular Intelligence Fabric

  • prosody.rs: A linguistic cleaning engine that detects emotional markers (e.g., [🚨 urgent], [✨ success]) to adjust speech
    synthesis parameters while stripping markdown for high-fidelity audio output.
  • telos.rs: Deep context management that aligns agent actions with core user values, missions, and beliefs.
  • swarm.rs: Aggregation logic for multi-agent consensus, utilizing Pareto-optimal selection to maximize quality while minimizing
    risk.

4. Memory & Observability (memory.rs, learning.rs, observability.rs)

  • Tiered Memory: Implements Hot (active work), Warm (synthesis), and Cold (immutable history) storage tiers.
  • Learning Engine: Captures "signals" (Failures, Anomalies, Ratings) to update performance stats and provide reinforcement context
    for future tasks.
  • Structured Telemetry: Real-time event streaming formatted for dashboard integration with automatic phase tracing.

⚡ Technical Highlights

  • Performance: Async I/O powered by tokio, global regex optimization via OnceLock, and zero-waste hooks that minimize memory
    cloning.
  • Reliability: includes 83 integration tests covering edge cases like path traversal protection and lock contention.
  • Extensibility: A robust HookManager allowing for Modify, Block, or Continue actions across the tool-use pipeline.

🧪 Testing State

  • Unit Tests: 100% pass rate across all core modules.
  • Integration Tests: tests/integration_tests.rs verifies the end-to-end pipeline, from security validation to memory persistence.
  • Benchmarks: pai_bench.rs tracks performance for the Algorithm and Prosody engines.

📦 Dependencies

  • tokio (Async runtime)
  • serde / serde_json / serde_yaml (Serialization)
  • handlebars (Template rendering for prompts)
  • reqwest (Secure HTTP client)
  • chrono (Temporal management)

Part of the Personal AI Infrastructure (PAI) Project.

…, prosody engine, privacy guard, and learning engine
- Updated the `detect_and_clean` method to prioritize emotions based on intensity, allowing for multiple emotion tags in a message.
- Improved regex patterns for better matching of emotion tags and markdown links.
- Added tests to validate emotion priority handling and cleaning functionality.
- Introduced a new `debug_prosody.rs` file for debugging purposes.

Refactor Recovery Journal to Limit Snapshot Size

- Implemented a maximum file size limit for snapshots in the `RecoveryJournal` to prevent excessive disk usage.
- Added tests to ensure that large files are correctly rejected during snapshot attempts.

Expand Skill Metadata Structure

- Enhanced `SkillMetadata` to include version and author fields, along with science implementation details.
- Updated the skill scanning logic to parse and store these new metadata fields.
- Added tests to verify the correct parsing of skill metadata.

Improve Skill Matching Logic

- Refactored the `find_matching_skills` method to return a score based on the relevance of the match, allowing for better ranking of results.
- Added tests to ensure the matching logic works as expected.

Integration Tests Enhancements

- Added various integration tests to validate the functionality of the prosody engine, recovery journal, and skill registry.
- Ensured comprehensive coverage of new features and edge cases.
…ality with YAML loading and retrieval methods
ProdByBuddha and others added 11 commits January 14, 2026 04:33
…ding SSRF prevention, command whitelisting, and data leakage protection
- Implement async I/O using tokio::fs for all persistence modules
- Add domain-specific error handling with thiserror
- Implement Black Swan protections: file size limits, path sanitization, recursion checks
- Harden VerificationOracle against command injection and SSRF
- Enhance PrivacyGuard with content redaction for API keys
- Optimize regex usage with OnceLock pre-compilation
- Fix all failing integration tests (81 passing)
@Daanvdplas
Copy link

Daanvdplas commented Jan 15, 2026

Why refactor in rust? Don't get me wrong, I prefer Rust too, but is this an important refactor for now? The stuff works, many other things to work on that are more important imo.

@eccentricnode
Copy link

you could literally just have your preferred language be rust, and then all your core apps would run it.... No?

@ProdByBuddha
Copy link
Author

ProdByBuddha commented Jan 16, 2026

Why refactor in rust? Don't get me wrong, I prefer Rust too, but is this an important refactor for now? The stuff works, many other things to work on that are more important imo.

It fit my needs, and I'm open to sharing what works for me, in case others need it too. Also, its importance is irrelevant against the fact that it's already been accomplished non-destructively. This code does no harm to the main branch, notice it's only additions.

@ProdByBuddha
Copy link
Author

you could literally just have your preferred language be rust, and then all your core apps would run it.... No?

I don't understand this question, could you elaborate?

@ProdByBuddha
Copy link
Author

Why refactor in rust? Don't get me wrong, I prefer Rust too, but is this an important refactor for now? The stuff works, many other things to work on that are more important imo.

https://github.com/prodbybuddha/agency is why I refactored to rust, fyi.

@eccentricnode
Copy link

you could literally just have your preferred language be rust, and then all your core apps would run it.... No?

I don't understand this question, could you elaborate?

in the core pai, system core skill defines your preferred languages, etc. Then, all of the apps can be built in your preferred language. You just tell your PAI to do so right?

@ProdByBuddha
Copy link
Author

you could literally just have your preferred language be rust, and then all your core apps would run it.... No?

I don't understand this question, could you elaborate?

in the core pai, system core skill defines your preferred languages, etc. Then, all of the apps can be built in your preferred language. You just tell your PAI to do so right?

Ah, thank you for clarifying. Yes, I suppose that's an option. However, that's not my reasoning behind this refactor. It has everything to do with leveraging memory safety benefits, concurrency and the other tropes that come along with utilizing Rust, toward the semi-autonomous agent I've been building, which is native to this programming language. In effect, if I defined Rust to be my preferred skill to PAI, it simply would honor that preference, only running on Rust in this instance. https://github.com/prodbybuddha/agency

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants