diff options
| author | soryu <soryu@soryu.co> | 2026-02-04 12:05:58 +0000 |
|---|---|---|
| committer | soryu <soryu@soryu.co> | 2026-02-04 12:05:58 +0000 |
| commit | c95fce0173386050cc865dfd18315f9a6397f505 (patch) | |
| tree | 5145c78c1a2b027b1459c23569538b5d870e4b6b /makima/src/daemon | |
| parent | 9521910b1fcbbc29c80b791e2c91d814030cb3cf (diff) | |
| download | soryu-c95fce0173386050cc865dfd18315f9a6397f505.tar.gz soryu-c95fce0173386050cc865dfd18315f9a6397f505.zip | |
Add makima skills
Diffstat (limited to 'makima/src/daemon')
| -rw-r--r-- | makima/src/daemon/mod.rs | 2 | ||||
| -rw-r--r-- | makima/src/daemon/skill_installer.rs | 115 | ||||
| -rw-r--r-- | makima/src/daemon/skills/chain.md | 116 | ||||
| -rw-r--r-- | makima/src/daemon/skills/contract.md | 100 | ||||
| -rw-r--r-- | makima/src/daemon/skills/mod.rs | 20 | ||||
| -rw-r--r-- | makima/src/daemon/skills/supervisor.md | 197 |
6 files changed, 550 insertions, 0 deletions
diff --git a/makima/src/daemon/mod.rs b/makima/src/daemon/mod.rs index 62da20e..1ddc4cb 100644 --- a/makima/src/daemon/mod.rs +++ b/makima/src/daemon/mod.rs @@ -15,6 +15,8 @@ pub mod db; pub mod error; pub mod process; pub mod setup; +pub mod skill_installer; +pub mod skills; pub mod storage; pub mod task; pub mod temp; diff --git a/makima/src/daemon/skill_installer.rs b/makima/src/daemon/skill_installer.rs new file mode 100644 index 0000000..87cdc29 --- /dev/null +++ b/makima/src/daemon/skill_installer.rs @@ -0,0 +1,115 @@ +//! Claude Code skill installation for makima commands. +//! +//! This module installs makima CLI commands as Claude Code skills +//! to ~/.claude/skills/ on daemon startup. Skills allow Claude Code +//! instances to use makima commands via slash commands like +//! `/makima-supervisor`, `/makima-contract`, and `/makima-chain`. + +use std::path::PathBuf; +use tokio::fs; + +use super::skills; + +/// Get the global Claude skills directory (~/.claude/skills/) +fn skills_dir() -> Option<PathBuf> { + dirs::home_dir().map(|h| h.join(".claude").join("skills")) +} + +/// Check if a skill needs to be installed or updated +async fn needs_install(skill_dir: &PathBuf, expected_content: &str) -> bool { + let skill_file = skill_dir.join("SKILL.md"); + match fs::read_to_string(&skill_file).await { + Ok(content) => content != expected_content, + Err(_) => true, // File doesn't exist or can't be read + } +} + +/// Install or update all makima skills to ~/.claude/skills/ +/// +/// This function: +/// 1. Creates the skills directory if needed +/// 2. For each skill, checks if it needs updating +/// 3. Writes/updates the SKILL.md file only if content differs +/// +/// Returns Ok(()) on success, or an error message on failure. +pub async fn install_skills() -> Result<(), String> { + let base_dir = skills_dir() + .ok_or_else(|| "Could not determine home directory".to_string())?; + + // Create base skills directory if needed + fs::create_dir_all(&base_dir) + .await + .map_err(|e| format!("Failed to create skills directory: {}", e))?; + + let mut installed_count = 0; + + for (name, content) in skills::ALL_SKILLS { + let skill_dir = base_dir.join(name); + + if needs_install(&skill_dir, content).await { + // Create skill directory + fs::create_dir_all(&skill_dir) + .await + .map_err(|e| format!("Failed to create {} directory: {}", name, e))?; + + // Write SKILL.md + let skill_file = skill_dir.join("SKILL.md"); + fs::write(&skill_file, content) + .await + .map_err(|e| format!("Failed to write {}/SKILL.md: {}", name, e))?; + + eprintln!(" Installed skill: {}", name); + installed_count += 1; + } + } + + if installed_count == 0 { + eprintln!(" All {} skills up to date", skills::ALL_SKILLS.len()); + } + + Ok(()) +} + +/// Check if all skills are properly installed +/// +/// Returns a list of (skill_name, is_installed) pairs. +pub async fn verify_skills() -> Vec<(String, bool)> { + let mut results = Vec::new(); + + if let Some(base_dir) = skills_dir() { + for (name, content) in skills::ALL_SKILLS { + let skill_dir = base_dir.join(name); + let installed = !needs_install(&skill_dir, content).await; + results.push((name.to_string(), installed)); + } + } + + results +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_skills_dir() { + // Should return a valid path on most systems + let dir = skills_dir(); + assert!(dir.is_some()); + let path = dir.unwrap(); + assert!(path.ends_with(".claude/skills")); + } + + #[test] + fn test_skill_content_not_empty() { + // Verify all skills have content + for (name, content) in skills::ALL_SKILLS { + assert!(!content.is_empty(), "Skill {} has no content", name); + assert!( + content.starts_with("---"), + "Skill {} missing YAML frontmatter", + name + ); + } + } +} diff --git a/makima/src/daemon/skills/chain.md b/makima/src/daemon/skills/chain.md new file mode 100644 index 0000000..7831540 --- /dev/null +++ b/makima/src/daemon/skills/chain.md @@ -0,0 +1,116 @@ +--- +name: makima-chain +description: Chain commands for makima multi-contract orchestration. Use when running chains of contracts defined in YAML, checking chain status, or managing contract dependencies. +--- + +# Makima Chain Commands + +Chains are DAGs (directed acyclic graphs) of contracts that work together. Contracts can depend on each other and run in parallel when no dependencies exist. + +Environment variables (`MAKIMA_API_URL`, `MAKIMA_API_KEY`) must be set. + +## Running Chains + +### Run chain from YAML +```bash +makima chain run <yaml_file> +``` +Parses the chain definition, validates the DAG, and creates contracts. + +Options: +- `--dry-run` - Validate and preview without creating + +### Validate chain YAML +```bash +makima chain validate <yaml_file> +``` +Checks syntax and validates DAG structure (no cycles). + +### Preview chain +```bash +makima chain preview <yaml_file> +``` +Shows execution order and contract details without creating. + +## Chain Status + +### Get chain status +```bash +makima chain status <chain_id> +``` + +### List all chains +```bash +makima chain list +``` +Options: +- `--status <active|completed|archived>` - Filter by status +- `--limit <n>` - Limit results (default: 50) + +### List contracts in chain +```bash +makima chain contracts <chain_id> +``` + +### Display ASCII DAG visualization +```bash +makima chain graph <chain_id> +``` +Options: +- `--with-status` - Show contract status in visualization + +## Chain Management + +### Archive chain +```bash +makima chain archive <chain_id> +``` +Marks chain as archived (does not delete contracts). + +## Chain YAML Format + +```yaml +name: my-chain +description: Optional description +repository_url: https://github.com/org/repo + +contracts: + - name: setup + contract_type: implementation + description: Initial setup work + + - name: feature-a + contract_type: implementation + depends_on: [setup] + description: Implement feature A + + - name: feature-b + contract_type: implementation + depends_on: [setup] + description: Implement feature B (parallel with A) + + - name: integration + contract_type: review + depends_on: [feature-a, feature-b] + description: Integrate and test +``` + +## Output Format + +All commands output JSON to stdout. + +Example workflow: +```bash +# Validate before running +makima chain validate my-chain.yaml + +# Preview execution +makima chain preview my-chain.yaml + +# Run the chain +chain_id=$(makima chain run my-chain.yaml | jq -r '.chainId') + +# Monitor progress +makima chain status "$chain_id" +makima chain graph "$chain_id" --with-status +``` diff --git a/makima/src/daemon/skills/contract.md b/makima/src/daemon/skills/contract.md new file mode 100644 index 0000000..51bc0f1 --- /dev/null +++ b/makima/src/daemon/skills/contract.md @@ -0,0 +1,100 @@ +--- +name: makima-contract +description: Contract commands for makima task-contract interaction. Use when checking contract status, reading goals, reporting progress, or managing contract files. +--- + +# Makima Contract Commands + +These commands let tasks interact with their contract context. Environment variables (`MAKIMA_API_URL`, `MAKIMA_API_KEY`, `MAKIMA_CONTRACT_ID`, `MAKIMA_TASK_ID`) are pre-configured by the daemon. + +## Status and Information + +### Get contract status +```bash +makima contract status +``` +Returns current phase, progress, and task summary. + +### Get phase checklist +```bash +makima contract checklist +``` +Returns checklist items for current phase. + +### Get contract goals +```bash +makima contract goals +``` +Returns the goals and success criteria for the contract. + +### Get suggested next action +```bash +makima contract suggest-action +``` +Returns AI-suggested next step based on current state. + +### Get completion recommendation +```bash +makima contract completion-action --code --files "file1.ts,file2.ts" --lines-added 50 --lines-removed 10 +``` +Get recommendation for what to do after completing work. + +Options: +- `--code` - Indicates there are code changes +- `--files "<comma-separated>"` - List of modified files +- `--lines-added <n>` - Number of lines added +- `--lines-removed <n>` - Number of lines removed + +## Contract Files + +Contract files are shared documents (plans, specs, notes) managed by the contract. + +### List contract files +```bash +makima contract files +``` + +### Get file content +```bash +makima contract file <file_id> +``` + +### Update file content +```bash +echo "New content" | makima contract update-file <file_id> +``` +Reads content from stdin. + +### Create new file +```bash +echo "File content" | makima contract create-file "<filename>" +``` +Reads content from stdin. + +## Progress Reporting + +### Report progress +```bash +makima contract report "<progress_message>" +``` +Reports progress visible to supervisor and user. + +## Output Format + +All commands output JSON to stdout. + +Example workflow: +```bash +# Check current phase and goals +makima contract status +makima contract goals + +# Check what needs to be done +makima contract checklist + +# Report progress +makima contract report "Completed initial analysis" + +# Get next recommended action +makima contract suggest-action +``` diff --git a/makima/src/daemon/skills/mod.rs b/makima/src/daemon/skills/mod.rs new file mode 100644 index 0000000..3b0c0dc --- /dev/null +++ b/makima/src/daemon/skills/mod.rs @@ -0,0 +1,20 @@ +//! Embedded Claude Code skill content for makima commands. +//! +//! This module provides the SKILL.md content for each makima skill. +//! Skills are installed to ~/.claude/skills/ on daemon startup. + +/// Supervisor skill content - contract orchestration commands +pub const SUPERVISOR_SKILL: &str = include_str!("supervisor.md"); + +/// Contract skill content - task-contract interaction commands +pub const CONTRACT_SKILL: &str = include_str!("contract.md"); + +/// Chain skill content - multi-contract orchestration commands +pub const CHAIN_SKILL: &str = include_str!("chain.md"); + +/// All skills as (name, content) pairs for installation +pub const ALL_SKILLS: &[(&str, &str)] = &[ + ("makima-supervisor", SUPERVISOR_SKILL), + ("makima-contract", CONTRACT_SKILL), + ("makima-chain", CHAIN_SKILL), +]; diff --git a/makima/src/daemon/skills/supervisor.md b/makima/src/daemon/skills/supervisor.md new file mode 100644 index 0000000..7dc006f --- /dev/null +++ b/makima/src/daemon/skills/supervisor.md @@ -0,0 +1,197 @@ +--- +name: makima-supervisor +description: Supervisor commands for makima contract orchestration. Use when spawning subtasks, waiting for tasks, managing branches, creating PRs, or coordinating work across multiple Claude instances. +--- + +# Makima Supervisor Commands + +These commands are for supervisors coordinating work on a makima contract. Environment variables (`MAKIMA_API_URL`, `MAKIMA_API_KEY`, `MAKIMA_CONTRACT_ID`, `MAKIMA_TASK_ID`) are pre-configured by the daemon. + +## Task Management + +### Spawn a new subtask +```bash +makima supervisor spawn "<task_name>" "<task_plan>" +``` +Creates and starts a new task. Returns JSON with `taskId`. + +Options: +- `--parent <task_id>` - Branch from a parent task's worktree +- `--checkpoint <sha>` - Start from a specific checkpoint +- `--repo <url>` - Repository URL (detected from current directory if not provided) + +### Wait for task completion +```bash +makima supervisor wait <task_id> [timeout_seconds] +``` +Blocks until task completes. Default timeout: 300s. Returns task status JSON. + +Options: +- `--poll-interval <seconds>` - How often to check status (default: 5) + +### List all tasks +```bash +makima supervisor tasks +``` +Returns JSON array of all tasks in the contract. + +### Get task tree structure +```bash +makima supervisor tree +``` +Returns hierarchical JSON of task relationships. + +### Get individual task details +```bash +makima supervisor task <task_id> +``` + +### Get task output/log +```bash +makima supervisor output <task_id> +``` + +### View task diff +```bash +makima supervisor diff <task_id> +``` +Shows uncommitted changes in the task's worktree. + +### Read file from task worktree +```bash +makima supervisor read-file <task_id> <file_path> +``` + +## Git Operations + +### Create a branch +```bash +makima supervisor branch "<branch_name>" +``` +Options: +- `--from <task_id_or_sha>` - Branch from specific reference + +### Merge task changes +```bash +makima supervisor merge <task_id> +``` +Options: +- `--to <branch>` - Target branch (default: contract's target branch) +- `--squash` - Squash commits + +### Create pull request +```bash +makima supervisor pr "<branch_name>" --title "<title>" --body "<body>" +``` + +## Checkpoints + +### Create checkpoint +```bash +makima supervisor checkpoint "<message>" +``` +Creates a checkpoint of current state. + +### List task checkpoints +```bash +makima supervisor task-checkpoints <task_id> +``` +Options: +- `--with-diff` - Include diff summary + +## History and Recovery + +### View task conversation history +```bash +makima supervisor task-history <task_id> +``` +Options: +- `--tool-calls <true|false>` - Include tool calls (default: true) +- `--limit <n>` - Maximum messages to return +- `--format <table|json|chat>` - Output format (default: chat) + +### Resume from checkpoint +```bash +makima supervisor task-resume-from <task_id> --checkpoint <n> --plan "<plan>" +``` +Options: +- `--name "<name>"` - Name for the new task + +### Fork task from checkpoint +```bash +makima supervisor task-fork <task_id> --checkpoint <n> --name "<name>" --plan "<plan>" +``` +Options: +- `--include-conversation <true|false>` - Include conversation history (default: true) + +### Rewind task to checkpoint +```bash +makima supervisor task-rewind <task_id> --checkpoint <n> +``` +Options: +- `--preserve <discard|create_branch|stash>` - How to preserve current work (default: create_branch) +- `--branch-name "<name>"` - Branch name for create_branch mode + +## Contract Lifecycle + +### Get contract status +```bash +makima supervisor status +``` + +### Advance to next phase +```bash +makima supervisor advance-phase <phase> +``` +Phases: specify, plan, execute, review. +Options: +- `-y` - Confirm the transition (without this, returns deliverables for review) + +### Mark deliverable complete +```bash +makima supervisor mark-deliverable <deliverable_id> +``` +Options: +- `--phase <phase>` - Phase the deliverable belongs to + +### Ask user a question +```bash +makima supervisor ask "<question>" +``` +Options: +- `--choices "opt1,opt2,opt3"` - Provide choices +- `--context "<context>"` - Additional context +- `--timeout <seconds>` - Wait timeout (default: 3600) +- `--phaseguard` - Block indefinitely until response +- `--multi-select` - Allow multiple choice selection +- `--non-blocking` - Return immediately without waiting +- `--question-type <general|phase_confirmation|contract_complete>` - Question type + +### Mark contract complete +```bash +makima supervisor complete +``` + +### Resume a completed contract +```bash +makima supervisor resume-contract <contract_id> +``` + +## Output Format + +All commands output JSON to stdout. Parse with `jq` or handle in code. + +Example workflow: +```bash +# Spawn a subtask +task_id=$(makima supervisor spawn "Implement feature" "Add the new button to the header" | jq -r '.taskId') + +# Wait for completion +makima supervisor wait "$task_id" + +# Check the diff +makima supervisor diff "$task_id" + +# Merge if satisfied +makima supervisor merge "$task_id" +``` |
