chadtmiller.com/knotless
git that lives in your Atmosphere account
1
10
Accounts can set a knotless profile over their Bluesky one
crates/knotless/src/cli.rs+55−0
| @@ -10,6 +10,7 @@ use crate::helper::{self, Knotless}; | ||
use crate::manage; | ||
use crate::moderation; | ||
use crate::oauth; | ||
use crate::profile; | ||
use crate::records; | ||
use crate::remote::Remote; | ||
use crate::session; | ||
| @@ -133,6 +134,11 @@ const USAGE: &str = "usage: knotless <command> | ||
email add <address> show commits by an address as yours, | ||
email remove <address> on repositories you own or push to; | ||
your first push adds the one git uses | ||
profile [--name <text>] [--bio <text>] [--pronouns <text>] | ||
[--link <url> [--title <text>]]... [--avatar <png or jpeg file>] | ||
how you show on knotless, over your | ||
Bluesky profile; '' shows its again, | ||
and --link '' its links | ||
report <handle, url or at-uri> <reason> [-m <text>] | ||
report to the moderation service; reasons: | ||
spam violation misleading sexual rude other | ||
| @@ -675,6 +681,55 @@ async fn command( | ||
let said = if changed { done } else { "unchanged" }; | ||
writeln!(out, "{address} {said}")?; | ||
} | ||
"profile" => { | ||
let mut change = profile::Change::default(); | ||
while let Some(flag) = args.rest.next() { | ||
let value = args.next("<value>")?.to_string(); | ||
match flag.as_str() { | ||
"--name" => change.name = Some(value), | ||
"--bio" => change.bio = Some(value), | ||
"--pronouns" => change.pronouns = Some(value), | ||
"--link" => { | ||
let links = change.links.get_or_insert_with(Vec::new); | ||
let title = None; | ||
links.extend( | ||
(!value.is_empty()) | ||
.then_some(records::ProfileLink { url: value, title }), | ||
); | ||
} | ||
"--title" => match change.links.as_mut().and_then(|l| l.last_mut()) { | ||
Some(link) => link.title = Some(value), | ||
None => bail!("--title follows the --link it names"), | ||
}, | ||
"--avatar" if value.is_empty() => change.avatar = Some(Vec::new()), | ||
"--avatar" => { | ||
let bytes = | ||
std::fs::read(&value).with_context(|| format!("reading {value}")); | ||
change.avatar = Some(bytes?); | ||
} | ||
other => bail!("unexpected {other}"), | ||
} | ||
} | ||
let me = session::me(ctx).await?; | ||
let now = profile::set(ctx, &me, change).await?; | ||
let shown = [ | ||
("name", now.display_name), | ||
("bio", now.description), | ||
("pronouns", now.pronouns), | ||
("avatar", now.avatar.map(|a| a.link.cid)), | ||
]; | ||
for (field, value) in shown { | ||
let value = value.unwrap_or_else(|| "(as on Bluesky)".into()); | ||
writeln!(out, "{field}: {value}")?; | ||
} | ||
if now.links.is_empty() { | ||
writeln!(out, "links: (as on Bluesky)")?; | ||
} | ||
for link in now.links { | ||
let title = link.title.map(|t| format!(" ({t})")).unwrap_or_default(); | ||
writeln!(out, "link: {}{title}", link.url)?; | ||
} | ||
} | ||
"report" => { | ||
let target = args.next("<handle, url or at-uri>")?; | ||
let reason = args.next("<reason>")?; | ||
crates/knotless/src/lib.rs+1−0
| @@ -31,6 +31,7 @@ pub mod manage; | ||
pub mod mirror; | ||
pub mod moderation; | ||
pub mod oauth; | ||
pub mod profile; | ||
pub mod push; | ||
pub mod queue; | ||
pub mod read; | ||
crates/knotless/src/oauth.rs+6−2
| @@ -30,7 +30,7 @@ use tokio::net::TcpListener; | ||
const CALLBACK: &str = "/callback"; | ||
| ||
/// What knotless asks for, and nothing more: to write the records it keeps | ||
/// in an account, to upload the blobs that hold its packs, to call gateways | ||
/// in an account, to upload the blobs that hold its packs and pictures, to call gateways | ||
/// and moderation services as the account, and the spaces private | ||
/// repositories live in. A PDS without spaces drops the scope it does not | ||
/// know. The space scope names every space type: naming | ||
| @@ -38,9 +38,13 @@ const CALLBACK: &str = "/callback"; | ||
/// published yet. | ||
pub static SCOPE: LazyLock<String> = LazyLock::new(|| { | ||
let mut scope = vec!["atproto".to_string()]; | ||
let written = nsid::ALL.iter().chain(&nsid::FORGE).chain([&nsid::EMAILS]); | ||
let written = nsid::ALL | ||
.iter() | ||
.chain(&nsid::FORGE) | ||
.chain([&nsid::EMAILS, &nsid::PROFILE]); | ||
scope.extend(written.map(|collection| format!("repo:{collection}"))); | ||
scope.push(format!("blob:{PACK_MIME}")); | ||
scope.extend(crate::profile::PICTURES.map(|mime| format!("blob:{mime}"))); | ||
let called = [ | ||
gateway::PUSH, | ||
gateway::COMMIT, | ||
crates/knotless/src/profile.rsnew+163−0
| @@ -0,0 +1,163 @@ | ||
//! How an account shows on knotless, where that differs from its Bluesky | ||
//! profile: a `dev.knotless.profile` record in its own repo. Each | ||
//! field stands in for the Bluesky profile's, field by field, so one left | ||
//! out shows that one's, and an account with no record shows as Bluesky | ||
//! has it. | ||
| ||
use crate::env::Ctx; | ||
use crate::records::{self, ProfileLink, ProfileRecord, nsid}; | ||
use crate::remote::{self, Remote}; | ||
use crate::session::Session; | ||
use crate::url::RepoUrl; | ||
use anyhow::{Result, bail}; | ||
use reqwest::Url; | ||
| ||
/// The key of an account's one profile. | ||
pub const RKEY: &str = "self"; | ||
| ||
/// The kinds of picture a profile takes. | ||
pub const PICTURES: [&str; 2] = ["image/png", "image/jpeg"]; | ||
| ||
/// The most bytes a picture may have. | ||
const MAX_PICTURE: usize = 1_000_000; | ||
| ||
/// The most links a profile shows. | ||
pub const MAX_LINKS: usize = 10; | ||
| ||
/// What to change of a profile. A field left `None` stays as it is; one | ||
/// set empty is taken out, so the Bluesky profile's shows again. | ||
#[derive(Default, Debug)] | ||
pub struct Change { | ||
pub name: Option<String>, | ||
pub bio: Option<String>, | ||
pub pronouns: Option<String>, | ||
pub links: Option<Vec<ProfileLink>>, | ||
pub avatar: Option<Vec<u8>>, | ||
} | ||
| ||
/// The kind of picture `bytes` hold, from their first bytes, if a profile | ||
/// takes it. | ||
pub fn picture_type(bytes: &[u8]) -> Option<&'static str> { | ||
if bytes.starts_with(b"\x89PNG\r\n\x1a\n") { | ||
Some(PICTURES[0]) | ||
} else if bytes.starts_with(b"\xff\xd8\xff") { | ||
Some(PICTURES[1]) | ||
} else { | ||
None | ||
} | ||
} | ||
| ||
/// `text`, trimmed, unless it is empty or longer than the lexicon allows: | ||
/// `chars` characters (no fewer than graphemes) or ten times as many bytes. | ||
fn text(field: &str, text: &str, chars: usize) -> Result<Option<String>> { | ||
let text = text.trim(); | ||
if text.chars().count() > chars || text.len() > chars * 10 { | ||
bail!("{field} is longer than {chars} characters"); | ||
} | ||
Ok((!text.is_empty()).then(|| text.to_string())) | ||
} | ||
| ||
/// Whether `url` is an http or https address, which a page can link to. | ||
pub fn is_web(url: &str) -> bool { | ||
Url::parse(url).is_ok_and(|u| matches!(u.scheme(), "http" | "https")) | ||
} | ||
| ||
/// A link to `url`, called `title` if that is not empty, if `url` is an | ||
/// http or https address. | ||
pub fn link(url: &str, title: Option<&str>) -> Result<ProfileLink> { | ||
let url = url.trim(); | ||
if !is_web(url) { | ||
bail!("{url} is no http or https address"); | ||
} | ||
let title = title.map(|t| text("a link's title", t, 40)).transpose()?; | ||
Ok(ProfileLink { | ||
url: url.to_string(), | ||
title: title.flatten(), | ||
}) | ||
} | ||
| ||
/// `did`'s profile, if it has one. | ||
pub async fn get(account: &Remote) -> Result<Option<ProfileRecord>> { | ||
let found = account.get_record(nsid::PROFILE, RKEY).await?; | ||
Ok(found.map(|r| r.value)) | ||
} | ||
| ||
/// Changes `me`'s profile as `change` says, writing only if that changes | ||
/// anything: what it is now. A profile left with nothing in it is deleted. | ||
pub async fn set(ctx: &Ctx, me: &Session, change: Change) -> Result<ProfileRecord> { | ||
let mine = Remote::connect(ctx, &RepoUrl::parse(&format!("knotless://{}/_", me.did))?).await?; | ||
let found = get(&mine).await?; | ||
let mut profile = found.clone().unwrap_or_default(); | ||
if let Some(name) = &change.name { | ||
profile.display_name = text("name", name, 64)?; | ||
} | ||
if let Some(bio) = &change.bio { | ||
profile.description = text("bio", bio, 256)?; | ||
} | ||
if let Some(pronouns) = &change.pronouns { | ||
profile.pronouns = text("pronouns", pronouns, 20)?; | ||
} | ||
if let Some(links) = change.links { | ||
if links.len() > MAX_LINKS { | ||
bail!("a profile shows at most {MAX_LINKS} links"); | ||
} | ||
let checked = links.iter().map(|l| link(&l.url, l.title.as_deref())); | ||
profile.links = checked.collect::<Result<_>>()?; | ||
} | ||
if let Some(bytes) = change.avatar { | ||
profile.avatar = None; | ||
if !bytes.is_empty() { | ||
let Some(kind) = picture_type(&bytes) else { | ||
bail!("the picture is neither a PNG nor a JPEG"); | ||
}; | ||
if bytes.len() > MAX_PICTURE { | ||
bail!("the picture is larger than {MAX_PICTURE} bytes"); | ||
} | ||
let blob = mine.xrpc.upload_blob(bytes, kind, &me.auth()).await?; | ||
profile.avatar = Some(blob); | ||
} | ||
} | ||
let mut was = found.clone().unwrap_or_default(); | ||
(was.updated_at, profile.updated_at) = (None, None); | ||
if profile == was { | ||
return Ok(found.unwrap_or_default()); | ||
} | ||
let write = match found { | ||
Some(_) if profile == ProfileRecord::default() => remote::delete(nsid::PROFILE, RKEY), | ||
found => { | ||
profile.updated_at = Some(records::now()); | ||
let value = records::typed(nsid::PROFILE, &profile); | ||
match found { | ||
Some(_) => remote::update(nsid::PROFILE, RKEY, value), | ||
None => remote::create(nsid::PROFILE, RKEY, value), | ||
} | ||
} | ||
}; | ||
mine.apply(vec![write], &me.auth()).await?; | ||
Ok(profile) | ||
} | ||
| ||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
| ||
#[test] | ||
fn pictures_fields_and_links() { | ||
assert_eq!(picture_type(b"\x89PNG\r\n\x1a\nrest"), Some("image/png")); | ||
assert_eq!(picture_type(b"\xff\xd8\xff\xe0"), Some("image/jpeg")); | ||
assert_eq!(picture_type(b"GIF89a"), None); | ||
assert_eq!(text("bio", " hi ", 4).unwrap().as_deref(), Some("hi")); | ||
assert_eq!(text("bio", " ", 4).unwrap(), None); | ||
assert!(text("bio", "hello", 4).is_err()); | ||
let shown = link(" https://example.com ", Some(" ")).unwrap(); | ||
assert_eq!( | ||
(shown.url.as_str(), shown.title), | ||
("https://example.com", None) | ||
); | ||
let titled = link("http://a.example", Some("Blog")).unwrap(); | ||
assert_eq!(titled.title.as_deref(), Some("Blog")); | ||
assert!(link("javascript:alert(1)", None).is_err()); | ||
assert!(link("not a url", None).is_err()); | ||
assert!(link("https://a.example", Some(&"x".repeat(41))).is_err()); | ||
} | ||
} | ||
crates/knotless/src/records.rs+29−0
| @@ -31,6 +31,8 @@ pub mod nsid { | ||
pub const FORGE: [&str; 7] = [PULL, ISSUE, COMMENT, STATE, HIDE, BLOCK, QUEUE]; | ||
/// The email addresses an account's commits are authored as. | ||
pub const EMAILS: &str = "dev.knotless.emails"; | ||
/// How an account shows on knotless, over its Bluesky profile. | ||
pub const PROFILE: &str = "dev.knotless.profile"; | ||
/// What a runner reports of a workflow it ran, in the runner's account. | ||
/// Not among [`FORGE`]: a runner takes part in no thread. | ||
pub const CHECK: &str = "dev.knotless.check"; | ||
| @@ -197,6 +199,33 @@ pub struct EmailsRecord { | ||
pub updated_at: String, | ||
} | ||
| ||
/// How an account shows on knotless, keyed `self`: each field stands in | ||
/// for its Bluesky profile's, and one left out shows that one's. | ||
#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct ProfileRecord { | ||
#[serde(default, skip_serializing_if = "Option::is_none")] | ||
pub display_name: Option<String>, | ||
#[serde(default, skip_serializing_if = "Option::is_none")] | ||
pub description: Option<String>, | ||
#[serde(default, skip_serializing_if = "Option::is_none")] | ||
pub pronouns: Option<String>, | ||
#[serde(default, skip_serializing_if = "Vec::is_empty")] | ||
pub links: Vec<ProfileLink>, | ||
#[serde(default, skip_serializing_if = "Option::is_none")] | ||
pub avatar: Option<BlobRef>, | ||
#[serde(default, skip_serializing_if = "Option::is_none")] | ||
pub updated_at: Option<String>, | ||
} | ||
| ||
/// A link shown on an account's profile. | ||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] | ||
pub struct ProfileLink { | ||
pub url: String, | ||
#[serde(default, skip_serializing_if = "Option::is_none")] | ||
pub title: Option<String>, | ||
} | ||
| ||
/// An account that may push to a repository. An object rather than a bare | ||
/// DID, so what a collaborator may do can be said beside it later. | ||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] | ||
crates/knotless/tests/common/mod.rs+10−3
| @@ -471,8 +471,14 @@ impl Sandbox { | ||
res["blob"].clone() | ||
} | ||
| ||
/// Writes a record into the account directly, as any client could. | ||
pub fn put_record(&self, collection: &str, rkey: &str, record: serde_json::Value) { | ||
/// Writes a record into the account directly, as any client could: | ||
/// its `uri` and `cid`. | ||
pub fn put_record( | ||
&self, | ||
collection: &str, | ||
rkey: &str, | ||
record: serde_json::Value, | ||
) -> serde_json::Value { | ||
reqwest::blocking::Client::new() | ||
.post(format!("{}/xrpc/com.atproto.repo.putRecord", net().pds)) | ||
.bearer_auth(self.token()) | ||
| @@ -484,7 +490,8 @@ impl Sandbox { | ||
})) | ||
.send() | ||
.and_then(|r| r.error_for_status()) | ||
.unwrap(); | ||
.and_then(|r| r.json()) | ||
.unwrap() | ||
} | ||
| ||
pub fn commit_file(&self, dir: &Path, file: &str, content: &str) -> String { | ||
crates/knotless/tests/cli.rs+88−0
| @@ -87,6 +87,94 @@ fn claiming_email_addresses() { | ||
assert_eq!(claimed().len(), 1); | ||
} | ||
| ||
/// A knotless profile holds only what its account sets, each field taken | ||
/// out again with '', and the record with the last of them. | ||
#[test] | ||
fn setting_a_profile() { | ||
let s = Sandbox::new(); | ||
let (handle, password) = (&s.account.handle, &s.account.password); | ||
let login = s.cli(&["login", handle, "--password-stdin"], password.as_bytes()); | ||
assert_eq!(login.0, 0); | ||
let profile = |args: &[&str]| s.cli(&[&["profile"], args].concat(), b""); | ||
let unset = "name: (as on Bluesky)\nbio: (as on Bluesky)\npronouns: (as on Bluesky)\navatar: (as on Bluesky)\nlinks: (as on Bluesky)"; | ||
// Nothing set, nothing is written. | ||
assert_eq!(profile(&[]), (0, unset.into())); | ||
assert_eq!(profile(&["--bio", ""]), (0, unset.into())); | ||
assert_eq!( | ||
s.record("dev.knotless.profile", "self"), | ||
serde_json::Value::Null | ||
); | ||
| ||
let picture = s.path("me.png"); | ||
std::fs::write(&picture, b"\x89PNG\r\n\x1a\nnot really").unwrap(); | ||
let (code, out) = profile(&[ | ||
"--name", | ||
" Me ", | ||
"--bio", | ||
"Small tools.", | ||
"--pronouns", | ||
"they/them", | ||
"--link", | ||
"https://me.example", | ||
"--link", | ||
"https://me.example/blog", | ||
"--title", | ||
"Blog", | ||
"--avatar", | ||
picture.to_str().unwrap(), | ||
]); | ||
assert_eq!(code, 0, "{out}"); | ||
let record = s.record("dev.knotless.profile", "self"); | ||
let cid = record["avatar"]["ref"]["$link"].as_str().unwrap(); | ||
assert_eq!( | ||
out, | ||
format!( | ||
"name: Me\nbio: Small tools.\npronouns: they/them\navatar: {cid}\nlink: https://me.example\nlink: https://me.example/blog (Blog)" | ||
) | ||
); | ||
assert_eq!(record["displayName"], "Me"); | ||
assert_eq!( | ||
record["links"], | ||
serde_json::json!([{"url": "https://me.example"}, {"url": "https://me.example/blog", "title": "Blog"}]) | ||
); | ||
assert_eq!(record["avatar"]["mimeType"], "image/png"); | ||
| ||
// What it refuses, it leaves as it was. | ||
let eleven = ["--link", "https://a.example"].repeat(11); | ||
let gif = s.path("me.gif"); | ||
std::fs::write(&gif, b"GIF89a").unwrap(); | ||
let big = s.path("big.jpg"); | ||
std::fs::write(&big, [&b"\xff\xd8\xff"[..], &vec![0; 1_000_000]].concat()).unwrap(); | ||
for refused in [ | ||
&["--avatar", gif.to_str().unwrap()][..], | ||
&["--avatar", big.to_str().unwrap()], | ||
&["--avatar", "/nowhere/me.png"], | ||
&["--link", "javascript:alert(1)"], | ||
&["--title", "nothing to name"], | ||
&eleven, | ||
&["--pronouns", "far too many characters"], | ||
&["--bogus", "x"], | ||
&["--name"], | ||
] { | ||
assert_eq!(profile(refused).0, 1, "{refused:?}"); | ||
} | ||
assert_eq!(s.record("dev.knotless.profile", "self"), record); | ||
| ||
let (_, out) = profile(&["--name", "", "--avatar", ""]); | ||
assert!( | ||
out.starts_with("name: (as on Bluesky)\nbio: Small tools."), | ||
"{out}" | ||
); | ||
assert!(out.contains("avatar: (as on Bluesky)\nlink: "), "{out}"); | ||
let (_, out) = profile(&["--link", ""]); | ||
assert!(out.ends_with("links: (as on Bluesky)"), "{out}"); | ||
profile(&["--bio", "", "--pronouns", ""]); | ||
assert_eq!( | ||
s.record("dev.knotless.profile", "self"), | ||
serde_json::Value::Null | ||
); | ||
} | ||
| ||
#[test] | ||
fn repository_lifecycle() { | ||
let s = Sandbox::new(); | ||
crates/knotless-mcp/src/lib.rs+57−2
| @@ -17,8 +17,9 @@ use knotless::git::Git; | ||
use knotless::manage::{self, NewRepo}; | ||
use knotless::mirror::Mirror; | ||
use knotless::moderation::{self, Admin}; | ||
use knotless::profile; | ||
use knotless::read; | ||
use knotless::records::RerunVar; | ||
use knotless::records::{self, RerunVar}; | ||
use knotless::remote::Remote; | ||
use knotless::url::RepoUrl; | ||
use rmcp::handler::server::wrapper::Parameters; | ||
| @@ -300,6 +301,26 @@ pub struct Block { | ||
pub blocked: Option<bool>, | ||
} | ||
| ||
#[derive(Deserialize, schemars::JsonSchema)] | ||
pub struct ProfileLink { | ||
pub url: String, | ||
/// What to call it; its host, if left out. | ||
pub title: Option<String>, | ||
} | ||
| ||
#[derive(Deserialize, schemars::JsonSchema)] | ||
pub struct SetProfile { | ||
/// The name shown over your handle. | ||
pub name: Option<String>, | ||
pub bio: Option<String>, | ||
pub pronouns: Option<String>, | ||
/// Links to show, in order, each an http or https address; this list | ||
/// replaces the one there was. Empty shows your Bluesky profile's. | ||
pub links: Option<Vec<ProfileLink>>, | ||
/// Your picture, a PNG or JPEG of at most 1 MB, as base64. | ||
pub avatar: Option<String>, | ||
} | ||
| ||
#[derive(Deserialize, schemars::JsonSchema)] | ||
pub struct Report { | ||
/// An account (`handle`), a repository (`handle/name`) or a pull, issue | ||
| @@ -1157,6 +1178,40 @@ impl Server { | ||
) | ||
} | ||
| ||
#[tool( | ||
description = "Set how you show on knotless, where that differs from your Bluesky profile, and say what your knotless profile now holds. A field left out stays as it is; one set to an empty string is taken out, so your Bluesky profile's shows again. With none, only says what it holds." | ||
)] | ||
async fn set_profile( | ||
&self, | ||
Parameters(p): Parameters<SetProfile>, | ||
) -> Result<CallToolResult, McpError> { | ||
answer( | ||
async { | ||
use base64::Engine; | ||
let avatar = p | ||
.avatar | ||
.map(|a| base64::engine::general_purpose::STANDARD.decode(a)); | ||
let change = profile::Change { | ||
name: p.name, | ||
bio: p.bio, | ||
pronouns: p.pronouns, | ||
links: p.links.map(|links| { | ||
let link = |l: ProfileLink| records::ProfileLink { | ||
url: l.url, | ||
title: l.title, | ||
}; | ||
links.into_iter().map(link).collect() | ||
}), | ||
avatar: avatar.transpose()?, | ||
}; | ||
let me = knotless::session::me(&self.ctx).await?; | ||
let now = profile::set(&self.ctx, &me, change).await?; | ||
Ok(serde_json::to_value(now)?) | ||
} | ||
.await, | ||
) | ||
} | ||
| ||
#[tool( | ||
description = "Report an account, a repository, or a pull, issue or comment to the moderation service." | ||
)] | ||
| @@ -1345,7 +1400,7 @@ impl Server { | ||
| ||
#[tool_handler( | ||
name = "knotless", | ||
instructions = "Git repositories stored in atproto accounts. Name a repository as handle/name. Before changing a repository, read its AGENTS.md (or CLAUDE.md) with read_file if it has one: how that repository wants changes made and checked. Read with list_tree, read_file, search, log and diff: no clone needed. Change files with commit: no checkout needed. Collaborate with fork, open_pull, open_issue, list_items, show_item, comment, set_state and merge (with queue, into the merge queue: see merge_queue and leave_queue); change what you wrote with edit_item, and take a comment back with delete_comment. Workflows are YAML files under .knotless/workflows/, run by the runners a repository names (see runners) on the commit a push or a pull brings: `on: {push: {refs: [refs/heads/*]}, pull: {base: [refs/heads/main], paths: [web/**]}}` (a file with no `on` runs on every push to a branch; `paths`, globs, runs it only on a change touching one, and passes it as skipped otherwise), `image` (the one container all the steps run in, in turn, so a step sees what earlier ones installed), `env`, `secrets` (names; never given to a pull), and `steps: [{name, run, timeout}]`, each `run` a shell script, stopping at the first that fails. After a push, checks says whether they passed, and rerun asks for them again, or, as owner, for one workflow at a ref by name, with variables: one with `on: {asked: {refs: [refs/heads/main]}}` runs only so. Moderate your repositories with hide_item and block_account, and report with report." | ||
instructions = "Git repositories stored in atproto accounts. Name a repository as handle/name. Before changing a repository, read its AGENTS.md (or CLAUDE.md) with read_file if it has one: how that repository wants changes made and checked. Read with list_tree, read_file, search, log and diff: no clone needed. Change files with commit: no checkout needed. Collaborate with fork, open_pull, open_issue, list_items, show_item, comment, set_state and merge (with queue, into the merge queue: see merge_queue and leave_queue); change what you wrote with edit_item, and take a comment back with delete_comment. Workflows are YAML files under .knotless/workflows/, run by the runners a repository names (see runners) on the commit a push or a pull brings: `on: {push: {refs: [refs/heads/*]}, pull: {base: [refs/heads/main], paths: [web/**]}}` (a file with no `on` runs on every push to a branch; `paths`, globs, runs it only on a change touching one, and passes it as skipped otherwise), `image` (the one container all the steps run in, in turn, so a step sees what earlier ones installed), `env`, `secrets` (names; never given to a pull), and `steps: [{name, run, timeout}]`, each `run` a shell script, stopping at the first that fails. After a push, checks says whether they passed, and rerun asks for them again, or, as owner, for one workflow at a ref by name, with variables: one with `on: {asked: {refs: [refs/heads/main]}}` runs only so. Moderate your repositories with hide_item and block_account, and report with report. Set how you show on knotless with set_profile." | ||
)] | ||
impl ServerHandler for Server {} | ||
| ||
crates/knotless-mcp/tests/mcp.rs+24−0
| @@ -358,6 +358,30 @@ fn an_agent_works_on_a_repository() { | ||
} | ||
} | ||
| ||
#[test] | ||
fn an_agent_sets_its_profile() { | ||
let s = logged_in(); | ||
let c = Client::new(&s); | ||
assert_eq!(c.json("set_profile", json!({})), json!({})); | ||
let set = c.json( | ||
"set_profile", | ||
json!({"bio": "Writes tools.", "pronouns": "they/them", "avatar": "iVBORw0KGgo=", | ||
"links": [{"url": "https://agent.example", "title": "Home"}]}), | ||
); | ||
assert_eq!(set["description"], "Writes tools."); | ||
assert_eq!(set["avatar"]["mimeType"], "image/png"); | ||
let record = s.record("dev.knotless.profile", "self"); | ||
assert_eq!(record["pronouns"], "they/them"); | ||
assert_eq!(record["links"][0]["title"], "Home"); | ||
let (text, err) = c.call("set_profile", json!({"avatar": "not base64!"})); | ||
assert!(err, "{text}"); | ||
let left = c.json("set_profile", json!({"name": "Agent"})); | ||
assert_eq!( | ||
(&left["displayName"], &left["pronouns"]), | ||
(&json!("Agent"), &json!("they/them")) | ||
); | ||
} | ||
| ||
#[test] | ||
fn sharing_from_an_agent() { | ||
if !net().spaces { | ||
crates/knotless-serve/src/lib.rs+1−0
| @@ -514,6 +514,7 @@ pub fn router(app: Arc<App>) -> Router { | ||
.route("/xrpc/dev.knotless.listRepos", get(appview::list_repos)) | ||
.route("/xrpc/dev.knotless.listChecks", get(appview::list_checks)) | ||
.route("/xrpc/dev.knotless.getFeed", get(web::get_feed)) | ||
.route("/xrpc/dev.knotless.getProfile", get(web::get_profile)) | ||
.route( | ||
"/xrpc/com.atproto.moderation.createReport", | ||
post(moderation::create_report), | ||