summaryrefslogtreecommitdiff
path: root/makima/src/db
diff options
context:
space:
mode:
Diffstat (limited to 'makima/src/db')
-rw-r--r--makima/src/db/models.rs45
-rw-r--r--makima/src/db/repository.rs143
2 files changed, 6 insertions, 182 deletions
diff --git a/makima/src/db/models.rs b/makima/src/db/models.rs
index 66c0a30..131dffc 100644
--- a/makima/src/db/models.rs
+++ b/makima/src/db/models.rs
@@ -2714,7 +2714,6 @@ pub struct Directive {
pub pr_url: Option<String>,
pub pr_branch: Option<String>,
pub completion_task_id: Option<Uuid>,
- pub memory_enabled: bool,
pub goal_updated_at: DateTime<Utc>,
pub started_at: Option<DateTime<Utc>>,
pub version: i32,
@@ -2764,7 +2763,6 @@ pub struct DirectiveSummary {
pub orchestrator_task_id: Option<Uuid>,
pub pr_url: Option<String>,
pub completion_task_id: Option<Uuid>,
- pub memory_enabled: bool,
pub version: i32,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
@@ -2791,8 +2789,6 @@ pub struct CreateDirectiveRequest {
pub repository_url: Option<String>,
pub local_path: Option<String>,
pub base_branch: Option<String>,
- #[serde(default)]
- pub memory_enabled: bool,
}
/// Request to update a directive.
@@ -2808,7 +2804,6 @@ pub struct UpdateDirectiveRequest {
pub orchestrator_task_id: Option<Uuid>,
pub pr_url: Option<String>,
pub pr_branch: Option<String>,
- pub memory_enabled: Option<bool>,
pub version: Option<i32>,
}
@@ -2853,43 +2848,3 @@ pub struct UpdateDirectiveStepRequest {
pub order_index: Option<i32>,
}
-// =============================================================================
-// Directive Memory Types
-// =============================================================================
-
-/// A memory entry for a directive — key-value context that persists across tasks.
-#[derive(Debug, Clone, FromRow, Serialize, Deserialize, ToSchema)]
-#[serde(rename_all = "camelCase")]
-pub struct DirectiveMemory {
- pub id: Uuid,
- pub directive_id: Uuid,
- pub key: String,
- pub value: String,
- pub category: Option<String>,
- pub created_at: DateTime<Utc>,
- pub updated_at: DateTime<Utc>,
-}
-
-/// Request to set a memory entry (upsert by key).
-#[derive(Debug, Deserialize, ToSchema)]
-#[serde(rename_all = "camelCase")]
-pub struct SetDirectiveMemoryRequest {
- pub key: String,
- pub value: String,
- pub category: Option<String>,
-}
-
-/// Request to batch set memory entries.
-#[derive(Debug, Deserialize, ToSchema)]
-#[serde(rename_all = "camelCase")]
-pub struct BatchSetDirectiveMemoryRequest {
- pub entries: Vec<SetDirectiveMemoryRequest>,
-}
-
-/// Response for listing memories.
-#[derive(Debug, Serialize, ToSchema)]
-#[serde(rename_all = "camelCase")]
-pub struct DirectiveMemoryListResponse {
- pub memories: Vec<DirectiveMemory>,
- pub total: i64,
-}
diff --git a/makima/src/db/repository.rs b/makima/src/db/repository.rs
index 51f49cd..8923f97 100644
--- a/makima/src/db/repository.rs
+++ b/makima/src/db/repository.rs
@@ -11,10 +11,9 @@ use super::models::{
ContractTypeTemplateRecord, ConversationMessage, ConversationSnapshot,
CreateContractRequest, CreateFileRequest, CreateTaskRequest,
CreateTemplateRequest, Daemon, DaemonTaskAssignment, DaemonWithCapacity,
- DeliverableDefinition, Directive, DirectiveMemory, DirectiveStep, DirectiveSummary,
+ DeliverableDefinition, Directive, DirectiveStep, DirectiveSummary,
CreateDirectiveRequest, CreateDirectiveStepRequest, UpdateDirectiveRequest,
- UpdateDirectiveStepRequest, SetDirectiveMemoryRequest,
- BatchSetDirectiveMemoryRequest, DirectiveMemoryListResponse,
+ UpdateDirectiveStepRequest,
File, FileSummary, FileVersion, HistoryEvent, HistoryQueryFilters,
MeshChatConversation, MeshChatMessageRecord, PhaseChangeResult, PhaseConfig,
PhaseDefinition, SupervisorHeartbeatRecord, SupervisorState,
@@ -4930,8 +4929,8 @@ pub async fn create_directive_for_owner(
) -> Result<Directive, sqlx::Error> {
sqlx::query_as::<_, Directive>(
r#"
- INSERT INTO directives (owner_id, title, goal, repository_url, local_path, base_branch, memory_enabled)
- VALUES ($1, $2, $3, $4, $5, $6, $7)
+ INSERT INTO directives (owner_id, title, goal, repository_url, local_path, base_branch)
+ VALUES ($1, $2, $3, $4, $5, $6)
RETURNING *
"#,
)
@@ -4941,7 +4940,6 @@ pub async fn create_directive_for_owner(
.bind(&req.repository_url)
.bind(&req.local_path)
.bind(&req.base_branch)
- .bind(req.memory_enabled)
.fetch_one(pool)
.await
}
@@ -4994,7 +4992,7 @@ pub async fn list_directives_for_owner(
SELECT
d.id, d.owner_id, d.title, d.goal, d.status, d.repository_url,
d.orchestrator_task_id, d.pr_url, d.completion_task_id,
- d.memory_enabled, d.version, d.created_at, d.updated_at,
+ d.version, d.created_at, d.updated_at,
COALESCE((SELECT COUNT(*) FROM directive_steps WHERE directive_id = d.id), 0) as total_steps,
COALESCE((SELECT COUNT(*) FROM directive_steps WHERE directive_id = d.id AND status = 'completed'), 0) as completed_steps,
COALESCE((SELECT COUNT(*) FROM directive_steps WHERE directive_id = d.id AND status = 'running'), 0) as running_steps,
@@ -5048,13 +5046,12 @@ pub async fn update_directive_for_owner(
let orchestrator_task_id = req.orchestrator_task_id.or(current.orchestrator_task_id);
let pr_url = req.pr_url.as_deref().or(current.pr_url.as_deref());
let pr_branch = req.pr_branch.as_deref().or(current.pr_branch.as_deref());
- let memory_enabled = req.memory_enabled.unwrap_or(current.memory_enabled);
let result = sqlx::query_as::<_, Directive>(
r#"
UPDATE directives
SET title = $3, goal = $4, status = $5, repository_url = $6, local_path = $7,
- base_branch = $8, orchestrator_task_id = $9, pr_url = $10, pr_branch = $11, memory_enabled = $12,
+ base_branch = $8, orchestrator_task_id = $9, pr_url = $10, pr_branch = $11,
version = version + 1, updated_at = NOW()
WHERE id = $1 AND owner_id = $2
RETURNING *
@@ -5071,7 +5068,6 @@ pub async fn update_directive_for_owner(
.bind(orchestrator_task_id)
.bind(pr_url)
.bind(pr_branch)
- .bind(memory_enabled)
.fetch_optional(pool)
.await
.map_err(RepositoryError::Database)?;
@@ -5609,7 +5605,6 @@ pub struct StepForDispatch {
pub directive_title: String,
pub repository_url: Option<String>,
pub base_branch: Option<String>,
- pub memory_enabled: bool,
/// The directive's PR branch (if a PR has already been created from previous steps).
pub pr_branch: Option<String>,
}
@@ -5633,7 +5628,6 @@ pub async fn get_ready_steps_for_dispatch(
d.title AS directive_title,
d.repository_url,
d.base_branch,
- d.memory_enabled,
d.pr_branch
FROM directive_steps ds
JOIN directives d ON d.id = ds.directive_id
@@ -5895,128 +5889,3 @@ pub async fn get_directive_max_generation(
Ok(row.0.unwrap_or(0))
}
-// =============================================================================
-// Directive Memory CRUD
-// =============================================================================
-
-/// List all memories for a directive, optionally filtered by category.
-pub async fn list_directive_memories(
- pool: &PgPool,
- directive_id: Uuid,
- category: Option<&str>,
-) -> Result<Vec<DirectiveMemory>, sqlx::Error> {
- match category {
- Some(cat) => {
- sqlx::query_as::<_, DirectiveMemory>(
- r#"
- SELECT * FROM directive_memories
- WHERE directive_id = $1 AND category = $2
- ORDER BY key
- "#,
- )
- .bind(directive_id)
- .bind(cat)
- .fetch_all(pool)
- .await
- }
- None => {
- sqlx::query_as::<_, DirectiveMemory>(
- r#"
- SELECT * FROM directive_memories
- WHERE directive_id = $1
- ORDER BY key
- "#,
- )
- .bind(directive_id)
- .fetch_all(pool)
- .await
- }
- }
-}
-
-/// Get a single memory entry by directive ID and key.
-pub async fn get_directive_memory(
- pool: &PgPool,
- directive_id: Uuid,
- key: &str,
-) -> Result<Option<DirectiveMemory>, sqlx::Error> {
- sqlx::query_as::<_, DirectiveMemory>(
- r#"
- SELECT * FROM directive_memories
- WHERE directive_id = $1 AND key = $2
- "#,
- )
- .bind(directive_id)
- .bind(key)
- .fetch_optional(pool)
- .await
-}
-
-/// Set (upsert) a memory entry for a directive.
-pub async fn set_directive_memory(
- pool: &PgPool,
- directive_id: Uuid,
- req: &SetDirectiveMemoryRequest,
-) -> Result<DirectiveMemory, sqlx::Error> {
- sqlx::query_as::<_, DirectiveMemory>(
- r#"
- INSERT INTO directive_memories (directive_id, key, value, category)
- VALUES ($1, $2, $3, $4)
- ON CONFLICT (directive_id, key)
- DO UPDATE SET value = EXCLUDED.value,
- category = EXCLUDED.category,
- updated_at = NOW()
- RETURNING *
- "#,
- )
- .bind(directive_id)
- .bind(&req.key)
- .bind(&req.value)
- .bind(&req.category)
- .fetch_one(pool)
- .await
-}
-
-/// Batch set memory entries for a directive.
-pub async fn batch_set_directive_memories(
- pool: &PgPool,
- directive_id: Uuid,
- memories: &[SetDirectiveMemoryRequest],
-) -> Result<Vec<DirectiveMemory>, sqlx::Error> {
- let mut results = Vec::with_capacity(memories.len());
- for mem in memories {
- let result = set_directive_memory(pool, directive_id, mem).await?;
- results.push(result);
- }
- Ok(results)
-}
-
-/// Delete a single memory entry by key.
-pub async fn delete_directive_memory(
- pool: &PgPool,
- directive_id: Uuid,
- key: &str,
-) -> Result<bool, sqlx::Error> {
- let result = sqlx::query(
- r#"DELETE FROM directive_memories WHERE directive_id = $1 AND key = $2"#,
- )
- .bind(directive_id)
- .bind(key)
- .execute(pool)
- .await?;
- Ok(result.rows_affected() > 0)
-}
-
-/// Delete all memory entries for a directive.
-pub async fn clear_directive_memories(
- pool: &PgPool,
- directive_id: Uuid,
-) -> Result<u64, sqlx::Error> {
- let result = sqlx::query(
- r#"DELETE FROM directive_memories WHERE directive_id = $1"#,
- )
- .bind(directive_id)
- .execute(pool)
- .await?;
- Ok(result.rows_affected())
-}