feat: initialize server structure and database schema

- Added initial server setup with Cargo.toml defining dependencies and project structure.
- Created build.rs for generating protobuf bindings and validating wire contracts.
- Established database schema with initial migration files for conversations, messages, and runs.
- Introduced tools and prompts for Cursor functionality, enhancing user interaction capabilities.
This commit is contained in:
leookun
2026-08-30 01:33:39 +08:00
parent d200b3791d
commit 44e2d8057a
206 changed files with 37923 additions and 21 deletions
+10
View File
@@ -0,0 +1,10 @@
//! Provides captured Cursor wire fixtures for integration tests.
use bytes::Bytes;
use cursor_server::{cursor::protocol::connect, Result};
use prost::Message;
pub fn decode_single<M: Message + Default>(frame: &Bytes) -> Result<M> {
let frames = connect::decode_frames(frame)?;
assert_eq!(frames.len(), 1);
Ok(M::decode(frames[0].1.clone())?)
}
+92
View File
@@ -0,0 +1,92 @@
//! Provides deterministic provider streams for integration tests.
#![allow(dead_code)]
use std::{
collections::VecDeque,
sync::{Arc, Mutex},
};
use cursor_server::{
model::{ModelInvocation, ModelRequest},
provider::{ModelEvent, Provider, ProviderStream},
Error,
};
use futures_util::{stream, StreamExt};
use tokio_util::sync::CancellationToken;
enum FakeResponse {
Events(Vec<Result<ModelEvent, Error>>),
Gated {
ready: Arc<tokio::sync::Notify>,
events: Vec<Result<ModelEvent, Error>>,
},
Pending,
}
#[derive(Clone, Default)]
pub struct FakeProvider {
responses: Arc<Mutex<VecDeque<FakeResponse>>>,
requests: Arc<Mutex<Vec<ModelRequest>>>,
}
impl FakeProvider {
pub fn push(&self, events: Vec<ModelEvent>) {
self.responses
.lock()
.unwrap()
.push_back(FakeResponse::Events(events.into_iter().map(Ok).collect()));
}
pub fn push_error(&self, error: Error) {
self.responses
.lock()
.unwrap()
.push_back(FakeResponse::Events(vec![Err(error)]));
}
pub fn push_pending(&self) {
self.responses
.lock()
.unwrap()
.push_back(FakeResponse::Pending);
}
pub fn push_gated(&self, events: Vec<ModelEvent>) -> Arc<tokio::sync::Notify> {
let ready = Arc::new(tokio::sync::Notify::new());
self.responses
.lock()
.unwrap()
.push_back(FakeResponse::Gated {
ready: ready.clone(),
events: events.into_iter().map(Ok).collect(),
});
ready
}
pub fn requests(&self) -> Vec<ModelRequest> {
self.requests.lock().unwrap().clone()
}
}
impl Provider for FakeProvider {
fn stream(
&self,
invocation: ModelInvocation,
_cancellation: CancellationToken,
) -> ProviderStream {
self.requests.lock().unwrap().push(invocation.request);
let events = self
.responses
.lock()
.unwrap()
.pop_front()
.expect("fake response configured");
match events {
FakeResponse::Events(events) => Box::pin(stream::iter(events)),
FakeResponse::Gated { ready, events } => Box::pin(
stream::once(async move {
ready.notified().await;
events
})
.flat_map(stream::iter),
),
FakeResponse::Pending => Box::pin(stream::pending()),
}
}
}
+18
View File
@@ -0,0 +1,18 @@
//! Provides isolated stores and canonical message fixtures for tests.
#![allow(dead_code)]
use cursor_server::{
model::{CanonicalMessage, Origin, Role},
store::Store,
};
pub async fn temp_store() -> (tempfile::TempDir, Store) {
let directory = tempfile::tempdir().unwrap();
let url = format!("sqlite://{}", directory.path().join("test.db").display());
let store = Store::connect(&url).await.unwrap();
(directory, store)
}
pub fn user(id: &str, text: &str) -> CanonicalMessage {
CanonicalMessage::text(id, Role::User, Origin::User, text)
}