#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
#![deny(unused_imports)]
#![deny(unused_variables)]
#![allow(clippy::needless_range_loop)]
#![allow(clippy::single_match)]
#![allow(clippy::ptr_arg)]
#![allow(clippy::only_used_in_recursion)]
#![allow(clippy::if_same_then_else)]
#![allow(clippy::arc_with_non_send_sync)]
#![allow(clippy::manual_clamp)]
#![allow(rustdoc::invalid_rust_codeblocks)]
#![allow(rustdoc::bare_urls)]
#![allow(rustdoc::broken_intra_doc_links)]
#![allow(rustdoc::invalid_html_tags)]
#[cfg(all(feature = "standard-deps", feature = "agent-daemon"))]
pub mod agent; #[cfg(all(feature = "standard-deps", feature = "mcp-integration"))]
pub mod agents; #[cfg(all(feature = "standard-deps", feature = "agents-md"))]
pub mod agents_md; #[cfg(feature = "standard-deps")]
pub mod ast; #[cfg(feature = "standard-deps")]
pub mod cli;
#[cfg(feature = "standard-deps")]
pub mod contracts; #[cfg(all(feature = "standard-deps", feature = "demo"))]
pub mod demo;
#[cfg(feature = "standard-deps")]
pub mod docs_enforcement; #[cfg(feature = "standard-deps")]
pub mod entropy; #[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(feature = "standard-deps")]
pub mod explain; #[cfg(feature = "standard-deps")]
pub mod graph; #[cfg(feature = "standard-deps")]
pub mod handlers;
#[cfg(feature = "standard-deps")]
pub mod maintenance; #[cfg(feature = "standard-deps")]
pub mod mcp; #[cfg(all(feature = "standard-deps", feature = "mcp-integration"))]
pub mod mcp_integration; #[cfg(feature = "standard-deps")]
pub mod mcp_pmcp; #[cfg(feature = "standard-deps")]
pub mod mcp_server;
#[cfg(feature = "standard-deps")]
pub mod models;
#[cfg(all(feature = "standard-deps", feature = "mcp-integration"))]
pub mod modules; #[cfg(feature = "standard-deps")]
pub mod prompts; #[cfg(feature = "standard-deps")]
pub mod protocol; #[cfg(feature = "standard-deps")]
pub mod qdd; #[cfg(feature = "standard-deps")]
pub mod quality; #[cfg(feature = "standard-deps")]
pub mod red_team; #[cfg(all(feature = "standard-deps", feature = "mcp-integration"))]
pub mod resources; #[cfg(feature = "standard-deps")]
pub mod roadmap; #[cfg(feature = "standard-deps")]
pub mod scaffold;
#[cfg(feature = "standard-deps")]
pub mod services;
#[cfg(feature = "standard-deps")]
pub mod state; #[cfg(feature = "standard-deps")]
pub mod stateless_server;
#[cfg(feature = "standard-deps")]
pub mod tdg; #[cfg(feature = "standard-deps")]
pub mod test_performance;
#[cfg(all(feature = "standard-deps", feature = "mcp-integration"))]
pub mod workflow; #[cfg(all(feature = "standard-deps", feature = "unified-protocol"))]
pub mod unified_protocol;
#[cfg(feature = "standard-deps")]
pub mod unified_quality; #[cfg(feature = "standard-deps")]
pub mod utils;
#[cfg(feature = "standard-deps")]
pub mod viz; #[cfg(all(feature = "standard-deps", feature = "wasm-ast"))]
pub mod wasm;
#[cfg(feature = "standard-deps")]
use anyhow::Result;
#[cfg(feature = "standard-deps")]
use lru::LruCache;
#[cfg(feature = "standard-deps")]
use std::num::NonZeroUsize;
#[cfg(feature = "standard-deps")]
use std::sync::Arc;
#[cfg(feature = "standard-deps")]
use tokio::sync::RwLock;
#[cfg(feature = "standard-deps")]
use tracing::info;
#[cfg(feature = "standard-deps")]
use crate::models::template::TemplateResource;
#[cfg(feature = "standard-deps")]
use crate::services::renderer::TemplateRenderer;
#[cfg(feature = "standard-deps")]
pub type MetadataCache = Arc<RwLock<LruCache<String, Arc<TemplateResource>>>>;
#[cfg(feature = "standard-deps")]
pub type ContentCache = Arc<RwLock<LruCache<String, Arc<str>>>>;
#[cfg(feature = "standard-deps")]
pub use crate::models::template::TemplateResource as PublicTemplateResource;
#[cfg(feature = "standard-deps")]
pub use crate::services::renderer::TemplateRenderer as PublicTemplateRenderer;
#[cfg(feature = "standard-deps")]
pub struct S3Client;
#[cfg(feature = "standard-deps")]
#[async_trait::async_trait]
pub trait TemplateServerTrait: Send + Sync {
async fn get_template_metadata(&self, uri: &str) -> Result<Arc<TemplateResource>>;
async fn get_template_content(&self, s3_key: &str) -> Result<Arc<str>>;
async fn list_templates(&self, prefix: &str) -> Result<Vec<Arc<TemplateResource>>>;
fn get_renderer(&self) -> &TemplateRenderer;
fn get_metadata_cache(&self) -> Option<&MetadataCache>;
fn get_content_cache(&self) -> Option<&ContentCache>;
fn get_s3_client(&self) -> Option<&S3Client>;
fn get_bucket_name(&self) -> Option<&str>;
}
#[cfg(feature = "standard-deps")]
pub struct TemplateServer {
pub s3_client: S3Client,
pub bucket_name: String,
pub metadata_cache: MetadataCache,
pub content_cache: ContentCache,
pub renderer: TemplateRenderer,
}
#[cfg(feature = "standard-deps")]
#[cfg_attr(coverage_nightly, coverage(off))]
impl TemplateServer {
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub async fn new() -> Result<Self> {
let cache_size = 1024;
Ok(Self {
s3_client: S3Client,
bucket_name: "dummy".to_string(),
metadata_cache: Arc::new(RwLock::new(LruCache::new(
NonZeroUsize::new(cache_size / 2).expect("internal error"),
))),
content_cache: Arc::new(RwLock::new(LruCache::new(
NonZeroUsize::new(cache_size).expect("internal error"),
))),
renderer: TemplateRenderer::new()?,
})
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub async fn warm_cache(&self) -> Result<()> {
let common_templates = vec![
"template://makefile/rust/cli",
"template://makefile/deno/cli",
"template://makefile/python-uv/cli",
"template://readme/rust/cli",
"template://gitignore/rust/cli",
];
info!(
"Warming cache with {} common templates",
common_templates.len()
);
for template_uri in common_templates {
match self.get_template_metadata(template_uri).await {
Ok(resource) => {
let _ = self.get_template_content(&resource.s3_object_key).await;
}
Err(e) => {
info!("Failed to warm cache for {}: {}", template_uri, e);
}
}
}
Ok(())
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub async fn get_template_metadata(&self, _uri: &str) -> Result<Arc<TemplateResource>> {
Err(anyhow::anyhow!(
"TemplateServer with S3 is deprecated. Use StatelessTemplateServer instead."
))
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub async fn get_template_content(&self, _s3_key: &str) -> Result<Arc<str>> {
Err(anyhow::anyhow!(
"TemplateServer with S3 is deprecated. Use StatelessTemplateServer instead."
))
}
}
#[cfg(feature = "standard-deps")]
#[async_trait::async_trait]
#[cfg_attr(coverage_nightly, coverage(off))]
impl TemplateServerTrait for TemplateServer {
async fn get_template_metadata(&self, uri: &str) -> Result<Arc<TemplateResource>> {
self.get_template_metadata(uri).await
}
async fn get_template_content(&self, s3_key: &str) -> Result<Arc<str>> {
self.get_template_content(s3_key).await
}
async fn list_templates(&self, _prefix: &str) -> Result<Vec<Arc<TemplateResource>>> {
Err(anyhow::anyhow!(
"TemplateServer with S3 is deprecated. Use StatelessTemplateServer instead."
))
}
fn get_renderer(&self) -> &TemplateRenderer {
&self.renderer
}
fn get_metadata_cache(&self) -> Option<&MetadataCache> {
Some(&self.metadata_cache)
}
fn get_content_cache(&self) -> Option<&ContentCache> {
Some(&self.content_cache)
}
fn get_s3_client(&self) -> Option<&S3Client> {
Some(&self.s3_client)
}
fn get_bucket_name(&self) -> Option<&str> {
Some(&self.bucket_name)
}
}
#[cfg(feature = "standard-deps")]
pub use models::error::TemplateError;
#[cfg(feature = "standard-deps")]
pub use models::template::{ParameterSpec, ParameterType};
#[cfg(feature = "standard-deps")]
pub use services::template_service::{
generate_template, list_templates, scaffold_project, search_templates, validate_template,
};
#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(all(test, feature = "standard-deps"))]
mod lib_unit_tests {
use super::*;
#[tokio::test]
async fn test_template_server_new() {
let server = TemplateServer::new().await;
assert!(server.is_ok());
}
#[tokio::test]
async fn test_template_server_deprecated_methods() {
let server = TemplateServer::new().await.unwrap();
let metadata_result = server.get_template_metadata("test://uri").await;
assert!(metadata_result.is_err());
assert!(metadata_result
.unwrap_err()
.to_string()
.contains("deprecated"));
let content_result = server.get_template_content("test_key").await;
assert!(content_result.is_err());
assert!(content_result
.unwrap_err()
.to_string()
.contains("deprecated"));
}
#[tokio::test]
async fn test_template_server_trait_methods() {
let server = TemplateServer::new().await.unwrap();
let _ = server.get_renderer();
assert!(server.get_metadata_cache().is_some());
assert!(server.get_content_cache().is_some());
assert!(server.get_s3_client().is_some());
assert!(server.get_bucket_name().is_some());
let list_result = TemplateServerTrait::list_templates(&server, "").await;
assert!(list_result.is_err());
}
#[test]
fn test_s3_client_struct() {
let _client = S3Client; }
#[tokio::test]
async fn test_template_server_warm_cache() {
let server = TemplateServer::new().await.unwrap();
let result = server.warm_cache().await;
assert!(result.is_ok());
}
}
#[cfg(test)]
#[allow(dead_code, clippy::unwrap_used, clippy::expect_used)]
#[path = "../build_support.rs"]
mod build_support;