summaryrefslogtreecommitdiff
path: root/makima/src/bin
diff options
context:
space:
mode:
authorsoryu <soryu@soryu.co>2026-05-01 23:56:51 +0100
committerGitHub <noreply@github.com>2026-05-01 23:56:51 +0100
commite11759447b1ac00becfb1e979e488f7f9c9cf478 (patch)
treef8a58368de3f6dda3f2f5c1af34e869a0e714205 /makima/src/bin
parent80085c7cfa9d679ed3e3fd54a7d55fa8ab1addef (diff)
downloadsoryu-e11759447b1ac00becfb1e979e488f7f9c9cf478.tar.gz
soryu-e11759447b1ac00becfb1e979e488f7f9c9cf478.zip
chore(cleanup): Phase 5 contracts removal + tmp directive + 30-day expiry + scroll fix (#118)
Sweeping cleanup across the surface and the wire. Net: -14k LOC of legacy contracts code, plus the tmp/scroll/UX fixes the user asked for. ## Sidebar/editor independent scroll Replace `height: calc(100vh - 80px)` (which assumed an 80px masthead and quietly clipped or pushed the whole page below the fold when the masthead was taller) with `h-screen + overflow-hidden` on the page root and proper `flex-1 min-h-0` sizing on `<main>`. Sidebar and editor pane now manage their own scroll independently; the page itself never scrolls. Same fix in /tmp/:taskId. ## tmp directive — real backing for orphans/ephemerals New migration `20260501100000_tmp_directive_and_clear_orphans.sql`: * Adds `directives.is_tmp` BOOLEAN NOT NULL DEFAULT false. * Partial unique index `(owner_id) WHERE is_tmp` — at most ONE tmp directive per owner. * Hard-deletes every existing orphan task (`directive_id IS NULL`). Per the user spec: "ALSO there are TOO MANY old tasks in tmp, we need to remove all of them as well." New repository helpers: * `get_or_create_tmp_directive(pool, owner_id) -> Directive` INSERT ON CONFLICT DO NOTHING + fallback SELECT, race-safe. * `list_all_tmp_directives` — drives the expiry sweep. * `delete_expired_tmp_tasks(tmp_directive_id) -> u64`. * `list_tmp_tasks_for_owner` (replaces `list_orphan_tasks_for_owner`). `mesh::create_task`: every top-level task must have a directive. If a caller doesn't supply `directive_id` and isn't a subtask, attach to the caller's tmp directive (auto-creating it on first use). `list_directives_for_owner` filters out `is_tmp=true` so the scratchpad directive doesn't pollute the contract list — surfaced via the sidebar's `tmp/` folder instead. ## 30-day expiry on tmp tasks New `phase_tmp_expiry` in the directive reconciler. Throttled to once per hour: enumerates every tmp directive, calls `delete_expired_tmp_tasks`, logs the count. The actual delete is `WHERE created_at < NOW() - INTERVAL '30 days'` and is fast on the existing index. Subtasks die via FK cascade. ## Phase 5 — contracts removed ### Frontend Deleted entire `/contracts` surface: * routes: `contracts.tsx`, `contract-file.tsx` * components/contracts: ContractList, ContractDetail, ContractCliInput, ContractContextMenu, CommandModePanel, PhaseBadge, PhaseHint, PhaseDeliverablesPanel, PhaseProgressBar, QuickActionButtons, RepositoryPanel, TaskDerivationPreview * (Kept `PhaseConfirmationModal` — used outside the contracts surface by `TaskOutput` and `PhaseConfirmationNotification`.) * Routes deregistered from `main.tsx`; nav entry removed from `NavStrip`. ### Backend handlers Deleted: `contracts.rs` (2.4k LOC), `contract_chat.rs` (3.2k LOC), `contract_daemon.rs` (~940 LOC), `contract_discuss.rs` (~590 LOC), `transcript_analysis.rs` (~690 LOC). All `/api/v1/contracts/*` routes deregistered. OpenAPI entries dropped. Module declarations removed from `server/handlers/mod.rs`. ### CLI Removed `makima contract` and `makima supervisor` subcommands. Deleted `daemon/cli/contract.rs` and `daemon/cli/supervisor.rs`. Bin dispatch trimmed (~377 LOC). ### Orchestrator Removed the contract-spawn path from `phase_execution` (`spawn_step_contract` and its caller). `directive_steps.contract_type` now logs a warning and falls through to standalone-task spawn. Column itself stays — old data still reads, just no longer triggers a contract+supervisor spawn. ### TUI `Action::PerformCreateContract` is now a no-op that surfaces a status message: "Contracts have been removed. Use directives instead." The TUI form is dead code pending a wider refresh. ## Out of scope (deliberately left) * Contracts DB tables (`contracts`, `contract_repositories`, `contract_chat_history`, `contract_events`, `contract_templates`) are retained for historical data + because some peripheral code still joins to them in TaskSummary queries. * `mesh_supervisor` handlers are retained — they aren't only used by contracts (some mesh-level supervisor behaviour persists), and the cross-cutting cleanup is bigger than this PR. * `directive_steps.contract_type` column itself isn't dropped; just no longer functional. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'makima/src/bin')
-rw-r--r--makima/src/bin/makima.rs454
1 files changed, 10 insertions, 444 deletions
diff --git a/makima/src/bin/makima.rs b/makima/src/bin/makima.rs
index df3e8e7..338d8f9 100644
--- a/makima/src/bin/makima.rs
+++ b/makima/src/bin/makima.rs
@@ -4,10 +4,9 @@ use std::io::{self, Read};
use std::path::Path;
use std::sync::Arc;
-use makima::daemon::api::{ApiClient, CreateContractRequest};
+use makima::daemon::api::ApiClient;
use makima::daemon::cli::{
- Cli, CliConfig, Commands, ConfigCommand, ContractCommand,
- DirectiveCommand, SupervisorCommand, ViewArgs,
+ Cli, CliConfig, Commands, ConfigCommand, DirectiveCommand, ViewArgs,
};
use makima::daemon::tui::{self, Action, App, ListItem, ViewType, TuiWsClient, WsEvent, OutputLine, OutputMessageType, WsConnectionState, RepositorySuggestion};
use makima::daemon::config::{DaemonConfig, RepoEntry};
@@ -27,8 +26,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
match cli.command {
Commands::Server(args) => run_server(args).await,
Commands::Daemon(args) => run_daemon(args).await,
- Commands::Supervisor(cmd) => run_supervisor(cmd).await,
- Commands::Contract(cmd) => run_contract(cmd).await,
Commands::Directive(cmd) => run_directive(cmd).await,
Commands::View(args) => run_view(args).await,
Commands::Config(cmd) => run_config(cmd).await,
@@ -309,383 +306,6 @@ async fn run_daemon(
Ok(())
}
-/// Run supervisor commands.
-async fn run_supervisor(
- cmd: SupervisorCommand,
-) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
- use makima::daemon::api::supervisor::*;
-
- match cmd {
- SupervisorCommand::Tasks(args) => {
- let client = ApiClient::new(args.api_url, args.api_key)?;
- let result = client.supervisor_tasks(args.contract_id).await?;
- println!("{}", serde_json::to_string(&result.0)?);
- }
- SupervisorCommand::Tree(args) => {
- let client = ApiClient::new(args.api_url, args.api_key)?;
- let result = client.supervisor_tree(args.contract_id).await?;
- println!("{}", serde_json::to_string(&result.0)?);
- }
- SupervisorCommand::Spawn(args) => {
- let client = ApiClient::new(args.common.api_url, args.common.api_key)?;
- eprintln!("Creating task: {}...", args.name);
- let req = SpawnTaskRequest {
- name: args.name,
- plan: args.plan,
- contract_id: args.common.contract_id,
- parent_task_id: args.parent,
- checkpoint_sha: args.checkpoint,
- };
- let result = client.supervisor_spawn(req).await?;
- println!("{}", serde_json::to_string(&result.0)?);
- }
- SupervisorCommand::Wait(args) => {
- let client = ApiClient::new(args.common.api_url, args.common.api_key)?;
- eprintln!(
- "Waiting for task {} (timeout: {}s, poll interval: {}s)...",
- args.task_id, args.timeout, args.poll_interval
- );
-
- let start_time = std::time::Instant::now();
- let timeout_duration = std::time::Duration::from_secs(args.timeout as u64);
- let poll_interval = std::time::Duration::from_secs(args.poll_interval);
- let server_wait_timeout = 30i32; // Short timeout for server-side wait
-
- loop {
- // Check if we've exceeded the total timeout
- let remaining = timeout_duration.saturating_sub(start_time.elapsed());
- if remaining.is_zero() {
- eprintln!("Timeout reached after {}s", args.timeout);
- let result = client.supervisor_get_task(args.task_id).await?;
- println!("{}", serde_json::to_string(&result.0)?);
- break;
- }
-
- // Try server-side wait with short timeout
- let wait_timeout = std::cmp::min(server_wait_timeout, remaining.as_secs() as i32);
-
- match client.supervisor_wait(args.task_id, wait_timeout).await {
- Ok(result) => {
- if let Some(completed) = result.0.get("completed").and_then(|c| c.as_bool()) {
- if completed {
- println!("{}", serde_json::to_string(&result.0)?);
- break;
- }
- }
- // Not completed yet, continue loop
- eprintln!("Task still running (elapsed: {:?})", start_time.elapsed());
- }
- Err(e) => {
- eprintln!("Warning: Server wait failed: {}. Falling back to polling...", e);
- // Fall back to simple status poll
- if let Ok(result) = client.supervisor_get_task(args.task_id).await {
- if let Some(status) = result.0.get("status").and_then(|s| s.as_str()) {
- if status == "done" || status == "failed" || status == "merged" {
- let wait_response = serde_json::json!({
- "taskId": args.task_id,
- "status": status,
- "completed": true,
- "outputSummary": result.0.get("progressSummary")
- });
- println!("{}", serde_json::to_string(&wait_response)?);
- break;
- }
- }
- }
- }
- }
-
- // Small delay before retrying
- tokio::time::sleep(poll_interval).await;
- }
- }
- SupervisorCommand::ReadFile(args) => {
- let client = ApiClient::new(args.common.api_url, args.common.api_key)?;
- let result = client
- .supervisor_read_file(args.task_id, &args.file_path)
- .await?;
- println!("{}", serde_json::to_string(&result.0)?);
- }
- SupervisorCommand::Branch(args) => {
- let client = ApiClient::new(args.common.api_url, args.common.api_key)?;
- eprintln!("Creating branch: {}...", args.name);
- let result = client.supervisor_branch(&args.name, args.from).await?;
- println!("{}", serde_json::to_string(&result.0)?);
- }
- SupervisorCommand::Merge(args) => {
- let client = ApiClient::new(args.common.api_url, args.common.api_key)?;
- eprintln!("Merging task {}...", args.task_id);
- let result = client
- .supervisor_merge(args.task_id, args.to, args.squash)
- .await?;
- println!("{}", serde_json::to_string(&result.0)?);
- }
- SupervisorCommand::Pr(args) => {
- let client = ApiClient::new(args.common.api_url, args.common.api_key)?;
- eprintln!("Creating PR for branch {}...", args.branch);
- let body = args.body.as_deref().unwrap_or("");
- let result = client
- .supervisor_pr(&args.branch, &args.title, body)
- .await?;
- println!("{}", serde_json::to_string(&result.0)?);
- }
- SupervisorCommand::Diff(args) => {
- let client = ApiClient::new(args.common.api_url, args.common.api_key)?;
- let result = client.supervisor_diff(args.task_id).await?;
- println!("{}", serde_json::to_string(&result.0)?);
- }
- SupervisorCommand::Checkpoint(args) => {
- let client = ApiClient::new(args.common.api_url, args.common.api_key)?;
- let task_id = args
- .common
- .self_task_id
- .ok_or("MAKIMA_TASK_ID is required for checkpoint")?;
- let result = client
- .supervisor_checkpoint(task_id, &args.message)
- .await?;
- println!("{}", serde_json::to_string(&result.0)?);
- }
- SupervisorCommand::Checkpoints(args) => {
- let client = ApiClient::new(args.api_url, args.api_key)?;
- let task_id = args.self_task_id.ok_or("MAKIMA_TASK_ID is required")?;
- let result = client.supervisor_checkpoints(task_id).await?;
- println!("{}", serde_json::to_string(&result.0)?);
- }
- SupervisorCommand::Status(args) => {
- let client = ApiClient::new(args.api_url, args.api_key)?;
- let result = client.supervisor_status(args.contract_id).await?;
- println!("{}", serde_json::to_string(&result.0)?);
- }
- SupervisorCommand::Ask(args) => {
- let client = ApiClient::new(args.common.api_url, args.common.api_key)?;
- eprintln!("Asking user: {}...", args.question);
- let choices = args
- .choices
- .map(|c| c.split(',').map(|s| s.trim().to_string()).collect())
- .unwrap_or_default();
- let result = client
- .supervisor_ask(&args.question, choices, args.context, args.timeout, args.phaseguard, args.multi_select, args.non_blocking, args.question_type)
- .await?;
- println!("{}", serde_json::to_string(&result.0)?);
- }
- SupervisorCommand::AdvancePhase(args) => {
- let client = ApiClient::new(args.common.api_url, args.common.api_key)?;
- if args.confirmed {
- eprintln!("Advancing contract to phase: {} (confirmed)...", args.phase);
- } else {
- eprintln!("Requesting phase advance to: {} (use --confirmed to proceed)...", args.phase);
- }
- let result = client
- .supervisor_advance_phase(args.common.contract_id, &args.phase, args.confirmed)
- .await?;
- println!("{}", serde_json::to_string(&result.0)?);
- }
- SupervisorCommand::Task(args) => {
- let client = ApiClient::new(args.common.api_url, args.common.api_key)?;
- let result = client.supervisor_get_task(args.target_task_id).await?;
- println!("{}", serde_json::to_string(&result.0)?);
- }
- SupervisorCommand::Output(args) => {
- let client = ApiClient::new(args.common.api_url, args.common.api_key)?;
- let result = client.supervisor_get_task_output(args.target_task_id).await?;
- println!("{}", serde_json::to_string(&result.0)?);
- }
- SupervisorCommand::TaskHistory(args) => {
- eprintln!(
- "Task history for {} (limit: {:?}, format: {})",
- args.task_id, args.limit, args.format
- );
- eprintln!("CLI integration not yet implemented. Use the API directly:");
- eprintln!(" GET /api/v1/mesh/tasks/{}/conversation", args.task_id);
- }
- SupervisorCommand::TaskCheckpoints(args) => {
- eprintln!(
- "Task checkpoints for {} (with_diff: {})",
- args.task_id, args.with_diff
- );
- eprintln!("CLI integration not yet implemented. Use the API directly:");
- eprintln!(" GET /api/v1/mesh/tasks/{}/checkpoints", args.task_id);
- }
- SupervisorCommand::Resume(args) => {
- eprintln!(
- "Resume supervisor for contract {} (mode: {}, checkpoint: {:?})",
- args.common.contract_id, args.mode, args.checkpoint
- );
- eprintln!("CLI integration not yet implemented. Use the API directly:");
- eprintln!(
- " POST /api/v1/contracts/{}/supervisor/resume",
- args.common.contract_id
- );
- }
- SupervisorCommand::TaskResumeFrom(args) => {
- eprintln!(
- "Resume task {} from checkpoint {} with plan: {}",
- args.task_id, args.checkpoint, args.plan
- );
- eprintln!("CLI integration not yet implemented. Use the API directly:");
- eprintln!(
- " POST /api/v1/mesh/tasks/{}/checkpoints/{}/resume",
- args.task_id, args.checkpoint
- );
- }
- SupervisorCommand::TaskRewind(args) => {
- eprintln!(
- "Rewind task {} to checkpoint {} (preserve: {}, branch: {:?})",
- args.task_id, args.checkpoint, args.preserve, args.branch_name
- );
- eprintln!("CLI integration not yet implemented. Use the API directly:");
- eprintln!(" POST /api/v1/mesh/tasks/{}/rewind", args.task_id);
- }
- SupervisorCommand::TaskFork(args) => {
- eprintln!(
- "Fork task {} from checkpoint {} as '{}' with plan: {}",
- args.task_id, args.checkpoint, args.name, args.plan
- );
- eprintln!("CLI integration not yet implemented. Use the API directly:");
- eprintln!(" POST /api/v1/mesh/tasks/{}/fork", args.task_id);
- }
- SupervisorCommand::RewindConversation(args) => {
- eprintln!(
- "Rewind conversation for contract {} (by: {:?}, to: {:?}, rewind_code: {})",
- args.common.contract_id, args.by_messages, args.to_message, args.rewind_code
- );
- eprintln!("CLI integration not yet implemented. Use the API directly:");
- eprintln!(
- " POST /api/v1/contracts/{}/supervisor/conversation/rewind",
- args.common.contract_id
- );
- }
- SupervisorCommand::Complete(args) => {
- let client = ApiClient::new(args.common.api_url, args.common.api_key)?;
- eprintln!("Marking contract {} as complete...", args.common.contract_id);
- match client.supervisor_complete(args.common.contract_id).await {
- Ok(_) => {
- println!(r#"{{"success": true, "message": "Contract marked as complete"}}"#);
- }
- Err(e) => {
- eprintln!("Error: {}", e);
- println!(r#"{{"success": false, "error": "{}"}}"#, e);
- std::process::exit(1);
- }
- }
- }
- SupervisorCommand::ResumeContract(args) => {
- let client = ApiClient::new(args.api_url, args.api_key)?;
- eprintln!("Resuming contract {}...", args.contract_id);
- let result = client.supervisor_resume_contract(args.contract_id).await?;
- println!("{}", serde_json::to_string(&serde_json::json!({
- "success": true,
- "message": "Contract resumed",
- "contract": result.0
- }))?);
- }
- SupervisorCommand::MarkDeliverable(args) => {
- let client = ApiClient::new(args.common.api_url, args.common.api_key)?;
- eprintln!(
- "Marking deliverable '{}' as complete for contract {}...",
- args.deliverable_id, args.common.contract_id
- );
- let result = client
- .supervisor_mark_deliverable(
- args.common.contract_id,
- &args.deliverable_id,
- args.phase.as_deref(),
- )
- .await?;
- println!("{}", serde_json::to_string(&result.0)?);
- }
- }
-
- Ok(())
-}
-
-/// Run contract commands.
-async fn run_contract(
- cmd: ContractCommand,
-) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
- match cmd {
- ContractCommand::Status(args) => {
- let client = ApiClient::new(args.api_url, args.api_key)?;
- let result = client.contract_status(args.contract_id).await?;
- println!("{}", serde_json::to_string(&result.0)?);
- }
- ContractCommand::Checklist(args) => {
- let client = ApiClient::new(args.api_url, args.api_key)?;
- let result = client.contract_checklist(args.contract_id).await?;
- println!("{}", serde_json::to_string(&result.0)?);
- }
- ContractCommand::Goals(args) => {
- let client = ApiClient::new(args.api_url, args.api_key)?;
- let result = client.contract_goals(args.contract_id).await?;
- println!("{}", serde_json::to_string(&result.0)?);
- }
- ContractCommand::Files(args) => {
- let client = ApiClient::new(args.api_url, args.api_key)?;
- let result = client.contract_files(args.contract_id).await?;
- println!("{}", serde_json::to_string(&result.0)?);
- }
- ContractCommand::File(args) => {
- let client = ApiClient::new(args.common.api_url, args.common.api_key)?;
- let result = client
- .contract_file(args.common.contract_id, args.file_id)
- .await?;
- println!("{}", serde_json::to_string(&result.0)?);
- }
- ContractCommand::Report(args) => {
- let client = ApiClient::new(args.common.api_url, args.common.api_key)?;
- let result = client
- .contract_report(args.common.contract_id, &args.message, args.common.task_id)
- .await?;
- println!("{}", serde_json::to_string(&result.0)?);
- }
- ContractCommand::SuggestAction(args) => {
- let client = ApiClient::new(args.api_url, args.api_key)?;
- let result = client.contract_suggest_action(args.contract_id).await?;
- println!("{}", serde_json::to_string(&result.0)?);
- }
- ContractCommand::CompletionAction(args) => {
- let client = ApiClient::new(args.common.api_url, args.common.api_key)?;
- let files = args.files.map(|f| {
- f.split(',')
- .map(|s| s.trim().to_string())
- .collect::<Vec<_>>()
- });
- let result = client
- .contract_completion_action(
- args.common.contract_id,
- args.common.task_id,
- files,
- args.lines_added,
- args.lines_removed,
- args.code,
- )
- .await?;
- println!("{}", serde_json::to_string(&result.0)?);
- }
- ContractCommand::UpdateFile(args) => {
- let client = ApiClient::new(args.common.api_url, args.common.api_key)?;
- // Read content from stdin
- let mut content = String::new();
- io::stdin().read_to_string(&mut content)?;
- let result = client
- .contract_update_file(args.common.contract_id, args.file_id, &content)
- .await?;
- println!("{}", serde_json::to_string(&result.0)?);
- }
- ContractCommand::CreateFile(args) => {
- let client = ApiClient::new(args.common.api_url, args.common.api_key)?;
- // Read content from stdin
- let mut content = String::new();
- io::stdin().read_to_string(&mut content)?;
- let result = client
- .contract_create_file(args.common.contract_id, &args.name, &content)
- .await?;
- println!("{}", serde_json::to_string(&result.0)?);
- }
- }
-
- Ok(())
-}
/// Run directive commands.
async fn run_directive(
@@ -1380,68 +1000,14 @@ async fn run_tui_loop(
app.ws_state = WsConnectionState::Disconnected;
}
}
- Action::PerformCreateContract { name, description, contract_type, repository_url } => {
- // Create the contract via API
- let req = CreateContractRequest {
- name: name.clone(),
- description: if description.is_empty() { None } else { Some(description) },
- contract_type: Some(contract_type),
- initial_phase: None,
- autonomous_loop: None,
- phase_guard: None,
- local_only: None,
- auto_merge_local: None,
- };
-
- match client.create_contract(req).await {
- Ok(result) => {
- let contract_name = result.0.get("name")
- .and_then(|v| v.as_str())
- .unwrap_or(&name)
- .to_string();
- let contract_id = result.0.get("id")
- .and_then(|v| v.as_str())
- .and_then(|s| uuid::Uuid::parse_str(s).ok());
-
- // Add repository if provided
- if let (Some(repo_url), Some(cid)) = (repository_url.as_ref(), contract_id) {
- if !repo_url.is_empty() {
- // Extract repo name from URL (e.g., "owner/repo" from GitHub URL)
- let repo_name = extract_repo_name(repo_url);
- match client.add_remote_repository(cid, &repo_name, repo_url, true).await {
- Ok(_) => {
- app.status_message = Some(format!(
- "Created contract '{}' with repository",
- contract_name
- ));
- }
- Err(e) => {
- app.status_message = Some(format!(
- "Created contract but failed to add repository: {}",
- e
- ));
- }
- }
- } else {
- app.status_message = Some(format!("Created contract: {}", contract_name));
- }
- } else {
- app.status_message = Some(format!("Created contract: {}", contract_name));
- }
-
- // Refresh the contracts list
- match load_contracts(client).await {
- Ok(items) => app.set_items(items),
- Err(e) => {
- let msg = app.status_message.take().unwrap_or_default();
- app.status_message = Some(format!("{} (refresh failed: {})", msg, e));
- }
- }
- }
- Err(e) => {
- app.status_message = Some(format!("Create failed: {}", e));
- }
- }
+ Action::PerformCreateContract { name: _, description: _, contract_type: _, repository_url: _ } => {
+ // Contracts removed in Phase 5 — directives are
+ // the only way to organise multi-task work now.
+ // The TUI's contract create form is dead code
+ // pending a wider TUI refresh.
+ app.status_message = Some(
+ "Contracts have been removed. Use directives instead.".to_string()
+ );
}
Action::LoadRepoSuggestions => {
// Load repository suggestions for the create form