Skip to content
Open
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ xURL gives you one URI scheme (`agents://`) to **read**, **query**, **discover**
<td align="center"><img src="https://cdn.simpleicons.org/googlegemini" alt="Gemini" width="36" height="36" /><br /><code>agents://gemini</code></td>
<td align="center"><img src="https://avatars.githubusercontent.com/u/129152888?s=200&v=4" alt="Kimi" width="36" height="36" /><br /><code>agents://kimi</code></td>
<td align="center"><img src="https://avatars.githubusercontent.com/u/208539476?s=200&v=4" alt="OpenCode" width="36" height="36" /><br /><code>agents://opencode</code></td>
<td align="center"><img src="https://openclaw.ai/favicon.svg" alt="OpenClaw" width="36" height="36" /><br /><code>agents://openclaw</code></td>
<td align="center"><img src=".github/assets/pi-logo-dark.svg" alt="Pi" width="36" height="36" /><br /><code>agents://pi</code></td>
</tr>
</table>
Expand Down Expand Up @@ -56,6 +57,7 @@ Ask your agent to summarize a thread:
Please summarize this thread: agents://codex/xxx_thread
```

<<
## Usage

> **Note:** The `agents://` scheme prefix is optional — `codex/...` is equivalent to `agents://codex/...`.
Expand Down Expand Up @@ -175,7 +177,7 @@ xurl [OPTIONS] <URI>
```

- `scheme`: optional `agents://` prefix. If omitted, `xurl` treats input as an `agents` URI shorthand.
- `provider`: target provider name, such as `amp`, `claude`, `codex`, `copilot`, `cursor`, `gemini`, `kimi`, `opencode`, `pi`.
- `provider`: target provider name, such as `amp`, `claude`, `codex`, `copilot`, `cursor`, `gemini`, `kimi`, `opencode`, `openclaw`, `pi`.
- `token`: main conversation identifier or role name.
- `child_id`: child/subagent identifier under a main conversation.
- `query`: optional key-value parameters, interpreted by context.
Expand Down
24 changes: 21 additions & 3 deletions xurl-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ fn run(cli: Cli) -> xurl_core::Result<()> {
| xurl_core::ProviderKind::Cursor
| xurl_core::ProviderKind::Gemini
| xurl_core::ProviderKind::Kimi
| xurl_core::ProviderKind::Opencode => uri.agent_id.is_some(),
| xurl_core::ProviderKind::Opencode
| xurl_core::ProviderKind::Openclaw => uri.agent_id.is_some(),
xurl_core::ProviderKind::Pi => uri.agent_id.as_deref().is_some_and(is_uuid_session_id),
};
let markdown = if is_subagent_drilldown {
Expand Down Expand Up @@ -377,7 +378,7 @@ impl WriteEventSink for CliWriteSink {

const ISSUE_CREATE_URL: &str = "https://github.com/Xuanwo/xurl/issues/new";
const SUPPORTED_PROVIDERS: &[&str] = &[
"amp", "copilot", "codex", "claude", "cursor", "gemini", "kimi", "pi", "opencode",
"amp", "copilot", "codex", "claude", "cursor", "gemini", "kimi", "openclaw", "pi", "opencode",
];

#[derive(Default)]
Expand Down Expand Up @@ -468,7 +469,7 @@ fn expected_session_id_shape(provider: Option<&str>) -> Option<&'static str> {
Some("amp") => Some("T-<uuid>"),
Some("opencode") => Some("ses_<id>"),
Some("codex") | Some("copilot") | Some("claude") | Some("cursor") | Some("gemini")
| Some("kimi") | Some("pi") => Some("<uuid>"),
| Some("kimi") | Some("openclaw") | Some("pi") => Some("<uuid>"),
_ => None,
}
}
Expand All @@ -489,6 +490,9 @@ fn provider_root_check(provider: &str) -> Option<String> {
Some("verify GEMINI_CLI_HOME/.gemini or ~/.gemini contains this thread".to_string())
}
"kimi" => Some("verify KIMI_SHARE_DIR or ~/.kimi contains this thread".to_string()),
"openclaw" => Some(
"verify OPENCLAW_HOME or ~/.openclaw contains this thread".to_string(),
),
"pi" => Some("verify PI_CODING_AGENT_DIR or ~/.pi/agent contains this thread".to_string()),
"opencode" => Some(
"verify XDG_DATA_HOME/opencode or ~/.local/share/opencode contains this thread"
Expand Down Expand Up @@ -582,6 +586,20 @@ fn provider_command_steps(command: &str, failed: bool) -> Vec<String> {
]
}
}
"openclaw" => {
if failed {
vec![
"verify OpenClaw gateway and authentication configuration".to_string(),
"retry with `openclaw agent --message \"hello\" --json` to inspect provider output"
.to_string(),
]
} else {
vec![
"run `openclaw --version` (or check XURL_OPENCLAW_BIN)".to_string(),
"install OpenClaw if missing, ensure `node` is available in PATH".to_string(),
]
}
}
"pi" => {
if failed {
vec![
Expand Down
227 changes: 105 additions & 122 deletions xurl-cli/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{env, os::unix::fs::PermissionsExt};

use assert_cmd::Command;
use predicates::prelude::*;
use rusqlite::{Connection, params};
use rusqlite::{params, Connection};
use tempfile::tempdir;

const SESSION_ID: &str = "019c871c-b1f9-7f60-9c4f-87ed09f13592";
Expand Down Expand Up @@ -33,6 +33,7 @@ const OPENCODE_REAL_SESSION_ID: &str = "ses_7v2md9kx3c1p";
const OPENCODE_MAIN_SESSION_ID: &str = "ses_5x7md9kx3c1p";
const OPENCODE_CHILD_SESSION_ID: &str = "ses_5x7md9kx3c2p";
const OPENCODE_CHILD_EMPTY_SESSION_ID: &str = "ses_5x7md9kx3c3p";
const OPENCLAW_SESSION_ID: &str = "0139048b-6a00-4636-8125-336ba5ed1cf9";

fn setup_codex_tree() -> tempfile::TempDir {
let temp = tempdir().expect("tempdir");
Expand Down Expand Up @@ -547,6 +548,38 @@ fn setup_opencode_subagent_tree() -> tempfile::TempDir {
temp
}

fn setup_openclaw_tree() -> tempfile::TempDir {
let temp = tempdir().expect("tempdir");
let main_path = temp.path().join(format!(
".openclaw/agents/main/sessions/{OPENCLAW_SESSION_ID}.jsonl"
));
let sub_path = temp.path().join(format!(
".openclaw/agents/primary/sessions/{OPENCLAW_SESSION_ID}.jsonl"
));
fs::create_dir_all(main_path.parent().expect("parent")).expect("mkdir");
fs::create_dir_all(sub_path.parent().expect("parent")).expect("mkdir");
fs::write(
&main_path,
format!(
"{{\"type\":\"session\",\"version\":3,\"id\":\"{OPENCLAW_SESSION_ID}\",\"timestamp\":\"2026-03-09T09:34:19.978Z\",\"cwd\":\"/tmp/openclaw\"}}\n\
{{\"type\":\"message\",\"id\":\"m1\",\"parentId\":null,\"timestamp\":\"2026-03-09T09:34:20.014Z\",\"message\":{{\"role\":\"user\",\"content\":[{{\"type\":\"text\",\"text\":\"hello from openclaw main\"}}]}}}}\n\
{{\"type\":\"message\",\"id\":\"m2\",\"parentId\":\"m1\",\"timestamp\":\"2026-03-09T09:34:21.014Z\",\"message\":{{\"role\":\"assistant\",\"content\":[{{\"type\":\"thinking\",\"thinking\":\"step by step\"}},{{\"type\":\"toolCall\",\"id\":\"call_1\",\"name\":\"exec\",\"arguments\":{{\"command\":\"echo hi\"}}}},{{\"type\":\"text\",\"text\":\"openclaw main done\"}}]}}}}\n\
{{\"type\":\"message\",\"id\":\"m3\",\"parentId\":\"m2\",\"timestamp\":\"2026-03-09T09:34:22.014Z\",\"message\":{{\"role\":\"toolResult\",\"content\":[{{\"type\":\"text\",\"text\":\"tool output\"}}]}}}}\n"
),
)
.expect("write openclaw main session");
fs::write(
&sub_path,
format!(
"{{\"type\":\"session\",\"version\":3,\"id\":\"{OPENCLAW_SESSION_ID}\",\"timestamp\":\"2026-03-09T09:34:19.978Z\",\"cwd\":\"/tmp/openclaw\"}}\n\
{{\"type\":\"message\",\"id\":\"s1\",\"parentId\":null,\"timestamp\":\"2026-03-09T09:34:20.014Z\",\"message\":{{\"role\":\"user\",\"content\":[{{\"type\":\"text\",\"text\":\"hello from openclaw subagent\"}}]}}}}\n\
{{\"type\":\"message\",\"id\":\"s2\",\"parentId\":\"s1\",\"timestamp\":\"2026-03-09T09:34:21.014Z\",\"message\":{{\"role\":\"assistant\",\"content\":[{{\"type\":\"text\",\"text\":\"openclaw subagent done\"}}]}}}}\n"
),
)
.expect("write openclaw subagent session");
temp
}

fn codex_real_fixture_root() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/codex_real_sanitized")
}
Expand Down Expand Up @@ -1006,6 +1039,23 @@ fn opencode_collection_query_outputs_markdown() {
.stdout(predicate::str::contains("- Match:"));
}

#[test]
fn openclaw_collection_query_outputs_markdown() {
let temp = setup_openclaw_tree();

let mut cmd = Command::new(assert_cmd::cargo::cargo_bin!("xurl"));
cmd.env("OPENCLAW_HOME", temp.path().join(".openclaw"))
.arg("agents://openclaw?q=openclaw&limit=1")
.assert()
.success()
.stdout(predicate::str::contains("# Threads"))
.stdout(predicate::str::contains("- Limit: `1`"))
.stdout(predicate::str::contains(format!(
"agents://openclaw/{OPENCLAW_SESSION_ID}"
)))
.stdout(predicate::str::contains("- Match:"));
}

#[test]
fn amp_path_query_outputs_markdown() {
let temp = setup_amp_tree();
Expand Down Expand Up @@ -1038,127 +1088,6 @@ fn codex_path_query_outputs_markdown() {
.stdout(predicate::str::contains("- Provider: `codex`"));
}

#[test]
fn claude_path_query_outputs_markdown() {
let temp = setup_claude_subagent_tree();

let mut cmd = Command::new(assert_cmd::cargo::cargo_bin!("xurl"));
cmd.env("CLAUDE_CONFIG_DIR", temp.path())
.arg("agents:///tmp/project?providers=claude&q=agent&limit=1")
.assert()
.success()
.stdout(predicate::str::contains("- Scope Path: `/tmp/project`"))
.stdout(predicate::str::contains("- Providers: `claude`"))
.stdout(predicate::str::contains("agents://claude/"))
.stdout(predicate::str::contains("- Provider: `claude`"));
}

#[test]
fn gemini_path_query_outputs_markdown() {
let temp = setup_gemini_tree();

let mut cmd = Command::new(assert_cmd::cargo::cargo_bin!("xurl"));
cmd.env("GEMINI_CLI_HOME", temp.path())
.arg("agents:///tmp/project?providers=gemini&q=hello&limit=1")
.assert()
.success()
.stdout(predicate::str::contains("- Scope Path: `/tmp/project`"))
.stdout(predicate::str::contains("- Providers: `gemini`"))
.stdout(predicate::str::contains(format!(
"agents://gemini/{GEMINI_SESSION_ID}"
)))
.stdout(predicate::str::contains("- Provider: `gemini`"));
}

#[test]
fn pi_path_query_outputs_markdown() {
let temp = setup_pi_tree();

let mut cmd = Command::new(assert_cmd::cargo::cargo_bin!("xurl"));
cmd.env("PI_CODING_AGENT_DIR", temp.path().join("agent"))
.arg("agents:///tmp/project?providers=pi&q=root&limit=1")
.assert()
.success()
.stdout(predicate::str::contains("- Scope Path: `/tmp/project`"))
.stdout(predicate::str::contains("- Providers: `pi`"))
.stdout(predicate::str::contains(format!(
"agents://pi/{PI_SESSION_ID}"
)))
.stdout(predicate::str::contains("- Provider: `pi`"));
}

#[test]
fn opencode_path_query_outputs_markdown() {
let temp = setup_opencode_subagent_tree();

let mut cmd = Command::new(assert_cmd::cargo::cargo_bin!("xurl"));
cmd.env("XDG_DATA_HOME", temp.path())
.arg("agents:///tmp/project?providers=opencode&q=help&limit=1")
.assert()
.success()
.stdout(predicate::str::contains("- Scope Path: `/tmp/project`"))
.stdout(predicate::str::contains("- Providers: `opencode`"))
.stdout(predicate::str::contains("agents://opencode/"))
.stdout(predicate::str::contains("- Provider: `opencode`"));
}

#[test]
fn path_query_current_dir_shorthand_outputs_canonical_uri() {
let temp = tempdir().expect("tempdir");
let workspace = temp.path().join("workspace");
fs::create_dir_all(&workspace).expect("mkdir");
let actual_workspace = workspace.canonicalize().expect("canonicalize workspace");
let codex_home = setup_codex_tree_with_scope(&actual_workspace);

let mut cmd = Command::new(assert_cmd::cargo::cargo_bin!("xurl"));
cmd.current_dir(&workspace)
.env("CODEX_HOME", codex_home.path())
.arg("agents://.?q=hello&providers=codex")
.arg("--head")
.assert()
.success()
.stdout(predicate::str::contains(format!(
"uri: 'agents://{}?q=hello&providers=codex'",
actual_workspace.display()
)))
.stdout(predicate::str::contains("mode: 'path_thread_query'"));
}

#[test]
fn path_query_home_shorthand_outputs_canonical_uri() {
let temp = tempdir().expect("tempdir");
let home = temp.path().join("home");
let repo = home.join("repo");
fs::create_dir_all(&repo).expect("mkdir");
let codex_home = setup_codex_tree_with_scope(&repo);

let mut cmd = Command::new(assert_cmd::cargo::cargo_bin!("xurl"));
cmd.env("HOME", &home)
.env("CODEX_HOME", codex_home.path())
.arg("agents://~/repo?q=hello&providers=codex")
.arg("--head")
.assert()
.success()
.stdout(predicate::str::contains(format!(
"uri: 'agents://{}?q=hello&providers=codex'",
repo.display()
)))
.stdout(predicate::str::contains("mode: 'path_thread_query'"));
}

#[test]
fn unsupported_global_query_form_returns_error() {
let temp = setup_codex_tree();

let mut cmd = Command::new(assert_cmd::cargo::cargo_bin!("xurl"));
cmd.env("CODEX_HOME", temp.path())
.arg("agents://?q=hello")
.assert()
.failure()
.stderr(predicate::str::contains("invalid URI"))
.stderr(predicate::str::contains("requested_uri: agents://?q=hello"));
}

#[test]
fn collection_query_not_found_outputs_empty_list() {
let temp = setup_codex_tree();
Expand Down Expand Up @@ -1960,6 +1889,60 @@ fn opencode_subagent_not_found_outputs_markdown_view() {
)));
}

#[test]
fn openclaw_read_outputs_markdown() {
let temp = setup_openclaw_tree();
let uri = format!("openclaw://{OPENCLAW_SESSION_ID}");

let mut cmd = Command::new(assert_cmd::cargo::cargo_bin!("xurl"));
cmd.env("OPENCLAW_HOME", temp.path().join(".openclaw"))
.arg(&uri)
.assert()
.success()
.stdout(predicate::str::contains("# Thread"))
.stdout(predicate::str::contains("## 1. User"))
.stdout(predicate::str::contains("hello from openclaw main"))
.stdout(predicate::str::contains("## 2. Assistant"))
.stdout(predicate::str::contains("openclaw main done"));
}

#[test]
fn openclaw_head_outputs_subagent_index() {
let temp = setup_openclaw_tree();
let uri = format!("openclaw://{OPENCLAW_SESSION_ID}");

let mut cmd = Command::new(assert_cmd::cargo::cargo_bin!("xurl"));
cmd.env("OPENCLAW_HOME", temp.path().join(".openclaw"))
.arg(&uri)
.arg("-I")
.assert()
.success()
.stdout(predicate::str::contains("---\n"))
.stdout(predicate::str::contains("mode: 'subagent_index'"))
.stdout(predicate::str::contains("subagents:"))
.stdout(predicate::str::contains(format!(
"agents://openclaw/{OPENCLAW_SESSION_ID}/primary"
)))
.stdout(predicate::str::contains("# Thread").not());
}

#[test]
fn openclaw_subagent_uri_outputs_markdown_view() {
let temp = setup_openclaw_tree();
let uri = format!("openclaw://{OPENCLAW_SESSION_ID}/primary");

let mut cmd = Command::new(assert_cmd::cargo::cargo_bin!("xurl"));
cmd.env("OPENCLAW_HOME", temp.path().join(".openclaw"))
.arg(&uri)
.assert()
.success()
.stdout(predicate::str::contains("# Subagent Thread"))
.stdout(predicate::str::contains(format!(
"agents://openclaw/{OPENCLAW_SESSION_ID}/primary"
)))
.stdout(predicate::str::contains("openclaw subagent done"));
}

#[test]
fn gemini_real_fixture_outputs_markdown() {
let fixture_root = gemini_real_fixture_root();
Expand Down
2 changes: 2 additions & 0 deletions xurl-core/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub enum ProviderKind {
Kimi,
Pi,
Opencode,
Openclaw,
}

impl fmt::Display for ProviderKind {
Expand All @@ -28,6 +29,7 @@ impl fmt::Display for ProviderKind {
Self::Kimi => write!(f, "kimi"),
Self::Pi => write!(f, "pi"),
Self::Opencode => write!(f, "opencode"),
Self::Openclaw => write!(f, "openclaw"),
}
}
}
Expand Down
Loading