mirror of
https://github.com/allaunthefox/Research-Stack.git
synced 2026-08-10 18:20:34 +00:00
**New Rust modules (batch 2 — 9 files)** - src/deepseek_adapter.rs — DeepSeek/Ollama chat + DeepSeekProver - src/ene_cloud_credential_manager.rs — ENE cloud credential + node balancer (SQLite) - src/enhanced_swarm.rs — enhanced swarm stub - src/gemma_integration.rs — SQLite task queue for Gemma 4 model tasks - src/hyperbolic_encoding.rs — Poincaré disk math, HyperbolicManifoldEncoder - src/knowledge_ingestion.rs — WolframAlpha, OpenMath, nLab wiki adapters - src/manifold_perception.rs — filesystem manifest scanner / topological report - src/s3c_lean_review.rs — CLI adapter submitting S3C.lean to Gemma4Integration - src/search_adapter.rs — Google (stub) + Brave search providers All 9 wired into main.rs as mod declarations. **Test fixes (6 pre-existing failures → 0)** - s3c.rs: fix shell decomp width formula (a+b not a+b+1); correct test expectations for n=9 (b=7, not b=1); invariant a+b=2k+1 not 2k - math.rs: fix test_avg_chain expected avg to 10/6 (all-pairs average, not just A→* paths) - ene_core.rs: fix AES-GCM decrypt AAD mismatch in retrieve_sensitive_data — SELECT now fetches pkg column and passes it as AAD (matches store path) - hyperbolic_encoding.rs: fix Möbius transform formula to standard gyrovector form: denom = 1+2⟨a,z⟩+‖a‖²‖z‖² (was missing ‖a‖²‖z‖² term, had +‖z‖² instead) — satisfies T_0(z)=z identity **cargo test: 145 passed, 0 failed** **Delete 35 Python source files** now superseded by Rust crate: All 4-Infrastructure/infra/*.py and embedded_surface/server.py removed. **Deploy scripts updated** to use rs-surface binary instead of Python: - gcl_edge_in_place_upgrade.sh: CURRENT_SERVER → rs-surface binary; validate with test -x; smoke-test exec binary directly; rollback saves rs-surface - xen_alpine/install_rs_surface_openrc.sh: SERVER_SRC → musl release binary; drop python3 from apk; install as rs-surface (not server.py) - xen_alpine/run_qemu_alpine_surface.sh: default SURFACE_IMPL=rust; RUST_BIN var for musl binary; else-branch copies rs-surface; boot script exec binary - recover_credential_server.sh: upload rs-surface binary; ExecStart → binary with RS_SURFACE_PORT=8444 (credential endpoint built into rs-surface /credentials) - nixos-setup-cred-server.sh: same — ExecStart uses /opt/rs-surface/rs-surface Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
123 lines
5.3 KiB
Rust
123 lines
5.3 KiB
Rust
#![allow(dead_code)]
|
|
//! s3c_lean_review.rs — Submit an S3C Lean source file for Gemma-4 review.
|
|
//!
|
|
//! Port of s3c_lean_review.py (86 lines).
|
|
//!
|
|
//! Reads the requested `.lean` file, constructs a high-priority `Reasoning`
|
|
//! task, submits it to [`Gemma4Integration`], executes it synchronously, and
|
|
//! returns the structured result.
|
|
|
|
use crate::gemma_integration::{Gemma4Integration, GemmaTask, GemmaTaskRequest, GemmaVariant};
|
|
use std::time::{SystemTime, UNIX_EPOCH};
|
|
|
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
// §1 Public entry point
|
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
|
|
/// Read `s3c_lean_path`, submit a Gemma-4 code-review task, execute it, and
|
|
/// return the result JSON.
|
|
///
|
|
/// # Errors
|
|
///
|
|
/// Returns an error if the file cannot be read, the database cannot be opened,
|
|
/// or task submission / execution fails.
|
|
///
|
|
/// # Example
|
|
///
|
|
/// ```no_run
|
|
/// use ene_session_sync::s3c_lean_review::run_s3c_lean_review;
|
|
///
|
|
/// let result = run_s3c_lean_review(
|
|
/// "0-Core-Formalism/lean/Semantics/S3C.lean",
|
|
/// "/tmp/gemma_review.db",
|
|
/// ).unwrap();
|
|
/// println!("{}", result["output"]);
|
|
/// ```
|
|
pub fn run_s3c_lean_review(
|
|
s3c_lean_path: &str,
|
|
db_path: &str,
|
|
) -> anyhow::Result<serde_json::Value> {
|
|
// ── Read the Lean source file ────────────────────────────────────────────
|
|
let code = std::fs::read_to_string(s3c_lean_path)
|
|
.map_err(|e| anyhow::anyhow!("cannot read {}: {}", s3c_lean_path, e))?;
|
|
|
|
// ── Construct the task ───────────────────────────────────────────────────
|
|
let gemma = Gemma4Integration::new(db_path, GemmaVariant::E4B)?;
|
|
|
|
let now = SystemTime::now()
|
|
.duration_since(UNIX_EPOCH)
|
|
.unwrap_or_default()
|
|
.as_secs();
|
|
let task_id = format!("s3c_review_{}", now);
|
|
|
|
let task = GemmaTaskRequest {
|
|
task_id: task_id.clone(),
|
|
task_type: GemmaTask::Reasoning,
|
|
variant: GemmaVariant::E4B,
|
|
input_data: serde_json::json!({
|
|
"prompt": "Review the following Lean 4 code for S3C manifold processing. \
|
|
Identify any type errors, missing proofs, incomplete definitions, \
|
|
and suggest improvements.",
|
|
"code": code,
|
|
"file": "S3C.lean",
|
|
"enable_thinking": true,
|
|
}),
|
|
enable_thinking: true,
|
|
max_tokens: 2048,
|
|
priority: 9,
|
|
};
|
|
|
|
// ── Submit and execute ───────────────────────────────────────────────────
|
|
gemma.submit_task(&task)?;
|
|
let result = gemma.execute_task(&task_id)?;
|
|
Ok(result)
|
|
}
|
|
|
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
// §2 Tests
|
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use std::io::Write;
|
|
use tempfile::NamedTempFile;
|
|
|
|
/// Write a tiny fake `.lean` file and run the review pipeline against a
|
|
/// temp SQLite database.
|
|
#[test]
|
|
fn test_run_s3c_lean_review_with_stub_file() {
|
|
// Create a temporary Lean source file.
|
|
let mut lean_file = NamedTempFile::new().unwrap();
|
|
writeln!(
|
|
lean_file,
|
|
"-- S3C stub\ndef hello : Nat := 42"
|
|
)
|
|
.unwrap();
|
|
|
|
// Create a temporary database.
|
|
let db_file = NamedTempFile::new().unwrap();
|
|
let db_path = db_file.path().to_str().unwrap().to_owned();
|
|
|
|
let lean_path = lean_file.path().to_str().unwrap().to_owned();
|
|
let result = run_s3c_lean_review(&lean_path, &db_path).unwrap();
|
|
|
|
// The stub executor must produce these fields.
|
|
assert!(result.get("task_id").is_some(), "missing task_id");
|
|
assert!(result.get("output").is_some(), "missing output");
|
|
assert!(result.get("tokens_generated").is_some(), "missing tokens_generated");
|
|
|
|
// tokens_generated should be half of max_tokens (2048 / 2 = 1024).
|
|
assert_eq!(result["tokens_generated"].as_i64().unwrap(), 1024);
|
|
}
|
|
|
|
#[test]
|
|
fn test_run_s3c_lean_review_missing_file() {
|
|
let db_file = NamedTempFile::new().unwrap();
|
|
let db_path = db_file.path().to_str().unwrap().to_owned();
|
|
let err = run_s3c_lean_review("/nonexistent/path/S3C.lean", &db_path);
|
|
assert!(err.is_err(), "expected error for missing file");
|
|
let msg = format!("{}", err.unwrap_err());
|
|
assert!(msg.contains("cannot read"), "unexpected error: {}", msg);
|
|
}
|
|
}
|