Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ rig-core = { version = "0.47.2", default-features = false, features = ["reqwest"
rig-tools = "0.47.2"
serde = { version = "1.0.229", features = ["derive"] }
serde_json = "1.0.154"
tempfile = "3.27.0"
tokio = { version = "1.54.1", features = ["macros", "rt-multi-thread"] }
yaml_serde = "0.10.7"

[dev-dependencies]
rig-core = { version = "0.47.2", default-features = false, features = ["test-utils"] }
tempfile = "3.27.0"
111 changes: 111 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# killall-agent

A Rust CLI for running YAML-defined, read-only coding agents with Rig. Each run
loads the configured tools and instructions, sends one prompt, and prints the
answer. Tools may inspect the current directory but cannot write files or escape
that workspace.

## Run

Requires Rust 1.97.1 or newer and provider configuration in
`~/.pi/agent/models.json`. GitHub skill sources also require `git` on `PATH` and
network access.

```sh
cargo run --locked -- --agent sandbox/default.yaml --prompt "Explain this project"
```

The default definition uses `strata/qwen3.8-flash-next-q2_0`. Use a definition
matching your Pi configuration, or override its model:

```sh
cargo run --locked -- --agent sandbox/default.yaml --model provider/model --tools read,search
```

## Agent definitions

```yaml
name: reader
model: provider/model
tools: [Read, Search]
agentfile: instructions.md
skills:
- file://skills/explain
- github://killallgit/killall-skills/skills/parse-dont-validate
```

- `name` and `model` are required. Unknown YAML fields are rejected.
- `model` is a provider key and declared model ID from Pi's `models.json`, split
at the first slash. Supported provider APIs are `openai-completions`,
`openai-responses`, and `anthropic-messages`. Credentials may be literal keys
or `!command` values; Anthropic models need a positive configured or built-in
output-token limit.
- `tools` selects `read`, `list`, and `search`, case-insensitively. `ALL`, an
omitted list, or an empty list enables all three. Duplicates are ignored;
unknown names are errors, including alongside `ALL`.
- `agentfile` is optional. Its contents follow the built-in read-only
instructions in the system prompt.
- `skills` is optional. All selected `SKILL.md` instructions follow the
agentfile in source order, with collection entries sorted by path. Missing or
malformed sources and duplicate skill names are errors, not silent skips.

Relative agentfile paths and `file://` paths resolve from the YAML file's
containing directory. They do not change the workspace: tool paths still
resolve from the directory where you launched the CLI.

### Overrides

`--name`, `--model`, `--tools`, `--skills`, and `--agentfile` replace the matching
YAML values. CLI resource paths resolve from the current directory instead.
`--tools` accepts space- or comma-separated names; `--skills` accepts
space-separated sources. A bare `--skills` clears the YAML skills list.

```sh
cargo run --locked -- --agent sandbox/default.yaml \
--agentfile ./instructions.md --tools read list \
--skills file://./skills/explain github://owner/repository/path/to/skill \
--prompt "Review the implementation"
```

## Skill sources and trust

A skill requires a `SKILL.md` with YAML frontmatter containing nonempty `name`
and `description` fields, followed by a nonempty Markdown body.

- `file://path` accepts a skill file, a directory containing `SKILL.md`, or a
collection with immediate child skill directories. Repository collections
under `skills/` are also discovered.
- `github://owner/repository[/path]` shallow-clones the default branch over
HTTPS into a temporary directory, then loads the same formats. Checkouts are
discarded after reading. There is no cache, ref selection, or private-repo
authentication support; global Git configuration and hooks are disabled.

Only configure sources you trust: their text is supplied as model instructions.
Fetching does not run skill scripts, install packages, or initialize submodules.
Companion references and assets are not loaded, and skills do not expand the
workspace boundary of the read-only tools.

## Checks

```sh
cargo test --locked --all-targets
cargo fmt --all --check
cargo clippy --locked --all-targets -- -D warnings
```

The default tests use temporary files, local Git repositories, mock models, and
local HTTP servers; no external model API or GitHub access is needed. An
optional end-to-end GitHub fetch check uses a public skill and a local mock
model:

```sh
cargo test --locked --test agent_runtime github_skill_instructions -- --ignored
```

## Releases

From a clean, up-to-date `main`, maintainers can run `npm ci` followed by
`npm run release -- patch` (or `minor` / `major`). Release-it runs the local
checks, updates the Cargo version and lockfile, and commits, tags, and pushes.
The tag-triggered GitHub workflow verifies the version, reruns CI and security
checks, and publishes Linux and macOS binaries with checksums.
3 changes: 0 additions & 3 deletions sandbox/example-def.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: lenny
model: openai/sol
tools:
- ALL
- Read
- List
- Etc
skills:
- github://owner/repo
- file://path/to/dir
Expand Down
137 changes: 135 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use std::path::PathBuf;
use std::path::{Path, PathBuf};

use anyhow::{Result, ensure};
use clap::Parser;
use killall_agent::models::ModelSelection;
use killall_agent::{
definition::{self, Definition},
models::ModelSelection,
};

#[derive(Debug, Parser)]
#[command(
Expand All @@ -20,6 +24,53 @@ pub struct Args {
/// Override the agent definition's model
#[arg(short, long, value_name = "PROVIDER/MODEL")]
pub model: Option<ModelSelection>,

/// Override the agent's name
#[arg(long)]
pub name: Option<String>,

/// Replace tool selection (read, list, search, or ALL); empty means ALL
#[arg(long, value_name = "TOOL", num_args = 0.., value_delimiter = ',')]
pub tools: Option<Vec<String>>,

/// Replace skill sources; an empty --skills clears the YAML list
#[arg(long, value_name = "SOURCE", num_args = 0..)]
pub skills: Option<Vec<String>>,

/// Override the instruction file, relative to the current directory
#[arg(long, value_name = "PATH")]
pub agentfile: Option<PathBuf>,
}

impl Args {
pub fn load_definition(&self, workspace: &Path) -> Result<Definition> {
let mut definition = definition::load(&workspace.join(&self.agent))?;
if let Some(name) = &self.name {
ensure!(!name.trim().is_empty(), "Agent name must not be empty");
definition.name.clone_from(name);
}
if let Some(model) = &self.model {
definition.model = model.clone();
}
if let Some(tools) = &self.tools {
definition.tools.clone_from(tools);
}
if let Some(sources) = &self.skills {
definition.skills = sources
.iter()
.map(|source| match source.strip_prefix("file://") {
Some(path) if !path.trim().is_empty() => {
format!("file://{}", workspace.join(path).display())
}
_ => source.clone(),
})
.collect();
}
if let Some(path) = &self.agentfile {
definition.agentfile = Some(workspace.join(path));
}
Ok(definition)
}
}

#[cfg(test)]
Expand Down Expand Up @@ -60,6 +111,88 @@ mod tests {
}
}

#[test]
fn cli_resources_replace_yaml_values_and_use_the_workspace_for_relative_paths() {
let directory = tempfile::tempdir().unwrap();
let definitions = directory.path().join("definitions");
std::fs::create_dir(&definitions).unwrap();
let path = definitions.join("agent.yaml");
std::fs::write(&path, "name: yaml\nmodel: yaml/model\ntools: [search]\nskills: [file://old]\nagentfile: old.md\n").unwrap();
let args = Args::try_parse_from([
"killall-agent",
"--agent",
path.to_str().unwrap(),
"--name",
"cli",
"--model",
"cli/model",
"--tools",
"Read,List",
"--skills",
"file://guide",
"github://owner/repo",
"--agentfile",
"new.md",
])
.unwrap();

let definition = args.load_definition(directory.path()).unwrap();

assert_eq!(definition.name, "cli");
assert_eq!(definition.model, "cli/model".parse().unwrap());
assert_eq!(definition.tools, ["Read", "List"]);
assert_eq!(
definition.skills,
[
format!("file://{}", directory.path().join("guide").display()),
"github://owner/repo".into()
]
);
assert_eq!(definition.agentfile, Some(directory.path().join("new.md")));
}

#[test]
fn an_empty_skills_override_clears_yaml_skills() {
let directory = tempfile::tempdir().unwrap();
let path = directory.path().join("agent.yaml");
std::fs::write(
&path,
"name: yaml\nmodel: yaml/model\nskills: [file://old]\n",
)
.unwrap();
let args = Args::try_parse_from([
"killall-agent",
"--agent",
path.to_str().unwrap(),
"--skills",
])
.unwrap();

assert!(
args.load_definition(directory.path())
.unwrap()
.skills
.is_empty()
);
}

#[test]
fn rejects_a_blank_name_override() {
let directory = tempfile::tempdir().unwrap();
let path = directory.path().join("agent.yaml");
std::fs::write(&path, "name: yaml\nmodel: yaml/model\n").unwrap();
let args = Args::try_parse_from([
"killall-agent",
"--agent",
path.to_str().unwrap(),
"--name",
" ",
])
.unwrap();

assert!(args.load_definition(directory.path()).is_err());
}

#[test]
fn rejects_malformed_model_selections() {
for model in ["qwen3.8", "strata/", "/qwen3.8"] {
Expand Down
2 changes: 1 addition & 1 deletion src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ mod tests {
assert_eq!(definition.name, "lenny");
assert_eq!(definition.model.provider(), "openai");
assert_eq!(definition.model.id(), "sol");
assert_eq!(definition.tools, ["ALL", "Read", "List", "Etc"]);
assert_eq!(definition.tools, ["ALL"]);
assert_eq!(
definition.skills,
["github://owner/repo", "file://path/to/dir"]
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pub mod config;
pub mod definition;
pub mod models;
pub mod runtime;
pub mod skills;
pub mod tools;
13 changes: 7 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ mod cli;

use anyhow::{Context, Result};
use clap::Parser;
use killall_agent::{config, definition, models, tools};
use killall_agent::{config, models, runtime};
use rig_agent::AgentBuilder;

#[tokio::main]
async fn main() -> Result<()> {
let args = cli::Args::parse();
let definition = definition::load(&args.agent)?;
let workspace = std::env::current_dir().context("Cannot determine workspace directory")?;
let tools = tools::load(&workspace)?;
let definition = args.load_definition(&workspace)?;
let path = workspace.join(&args.agent);
let resources = runtime::load(&definition, path.parent().unwrap_or(&workspace), &workspace)?;
let config = config::load()?;
let model = models::load(&config, args.model.unwrap_or(definition.model))?;
let model = models::load(&config, definition.model)?;
let agent = AgentBuilder::new(model)
.tool_server_handle(tools)
.tool_server_handle(resources.tools)
.default_max_turns(10)
.preamble("You are a coding assistant with read-only tools. Relative tool paths resolve from the workspace directory. Use the tools when needed to inspect files; do not claim to have changed files.")
.preamble(resources.instructions)
.build();
let response = agent
.prompt(args.prompt)
Expand Down
33 changes: 33 additions & 0 deletions src/runtime.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use std::{fs, path::Path};

use anyhow::{Context, Result};
use rig_agent::tool::server::ToolServerHandle;

use crate::{definition::Definition, skills, tools};

pub struct Resources {
pub tools: ToolServerHandle,
pub instructions: String,
}

pub fn load(definition: &Definition, base: &Path, workspace: &Path) -> Result<Resources> {
let tools = tools::select(workspace, &definition.tools)?;
let mut instructions = format!(
"You are {}, a coding assistant with read-only tools. Relative tool paths resolve from the workspace directory. Use only the tools available to you; do not claim to have changed files.",
definition.name
);
if let Some(path) = &definition.agentfile {
let contents = fs::read_to_string(path)
.with_context(|| format!("Could not read agent instructions {}", path.display()))?;
instructions.push_str("\n\n# Agent instructions\n\n");
instructions.push_str(&contents);
}
for skill in skills::load(&definition.skills, base)? {
instructions.push_str(&format!("\n\n# Skill: {}\n\n", skill.name));
instructions.push_str(&skill.instructions);
}
Ok(Resources {
tools,
instructions,
})
}
Loading
Loading