M8: command registry, skills as slash commands, completion engine + popup, rpc complete
Closes #68, closes #69, closes #70, closes #71, closes #72
This commit is contained in:
1 parent
6f0addcd47
commit
65765ce2b3
10 files changed
+651
-125
No files matched your search
@@ -118,6 +118,40 @@ impl Config {
|
||||
}
|
||||
}
|
||||
|
||||
/// Offered by `/model` completion; any other id still works.
|
||||
const MODELS: &[&str] = &[
|
||||
"claude-sonnet-4-5",
|
||||
"claude-opus-4-1",
|
||||
"claude-haiku-4-5",
|
||||
"gpt-5-codex",
|
||||
"gpt-5",
|
||||
];
|
||||
|
||||
/// Builtins, MCP prompts (`/server:prompt`), then skills (builtins win name clashes).
|
||||
fn command_specs(mcp: &hx_mcp::Hub, cwd: &std::path::Path) -> Vec<hx_core::command::CmdSpec> {
|
||||
use hx_core::command::{self as c, ArgKind, CmdSpec, Source};
|
||||
let mut v = c::builtins(MODELS);
|
||||
v.push(CmdSpec::new(
|
||||
"mcp",
|
||||
"MCP servers and prompts",
|
||||
Source::Builtin,
|
||||
ArgKind::None,
|
||||
));
|
||||
for (n, s) in &mcp.servers {
|
||||
v.extend(s.prompts.iter().map(|p| {
|
||||
CmdSpec::new(
|
||||
&format!("{n}:{}", p["name"].as_str().unwrap_or_default()),
|
||||
p["description"].as_str().unwrap_or_default(),
|
||||
Source::Mcp,
|
||||
ArgKind::Free,
|
||||
)
|
||||
}));
|
||||
}
|
||||
let sk = c::skill_specs(&context::skills(&context::hx_home(), cwd), &v);
|
||||
v.extend(sk);
|
||||
v
|
||||
}
|
||||
|
||||
fn default_model(k: Kind) -> String {
|
||||
match k {
|
||||
Kind::Claude => "claude-sonnet-4-5",
|
||||
@@ -377,8 +411,9 @@ async fn main() -> Result<()> {
|
||||
.collect();
|
||||
mgr.warm(probe).await;
|
||||
}
|
||||
let specs = command_specs(&mcp, &cwd);
|
||||
if cli.mode == Mode::Rpc {
|
||||
let r = rpc::serve(agent, abort).await;
|
||||
let r = rpc::serve(agent, abort, specs, hx_tui::project_files(&cwd)).await;
|
||||
mgr.shutdown().await;
|
||||
return r;
|
||||
}
|
||||
@@ -392,6 +427,7 @@ async fn main() -> Result<()> {
|
||||
make_provider: Box::new(provider),
|
||||
default_model,
|
||||
pricing,
|
||||
specs,
|
||||
commands: {
|
||||
let mcp = mcp.clone();
|
||||
Box::new(move |name: &str, arg: &str| {
|
||||
|
||||
@@ -44,8 +44,14 @@ fn reply(id: &Value, r: Result<Value, String>) {
|
||||
}
|
||||
|
||||
/// Methods: `prompt {text}` (replies when the run ends; events stream meanwhile), `abort`,
|
||||
/// `state`, `messages`, `fork {id}`, `clear`, `set_model {model}`, `compact`. One prompt at a time.
|
||||
pub async fn serve(mut agent: Agent, abort: AbortHandle) -> Result<()> {
|
||||
/// `state`, `messages`, `fork {id}`, `clear`, `set_model {model}`, `compact`,
|
||||
/// `complete {line, cursor?}` (cursor = byte offset, default end). One prompt at a time.
|
||||
pub async fn serve(
|
||||
mut agent: Agent,
|
||||
abort: AbortHandle,
|
||||
specs: Vec<hx_core::command::CmdSpec>,
|
||||
files: Vec<String>,
|
||||
) -> Result<()> {
|
||||
agent.bus.add(Notify);
|
||||
let agent = Arc::new(Mutex::new(agent));
|
||||
let busy = Arc::new(std::sync::atomic::AtomicBool::new(false));
|
||||
@@ -62,7 +68,22 @@ pub async fn serve(mut agent: Agent, abort: AbortHandle) -> Result<()> {
|
||||
let id = m["id"].clone();
|
||||
let p = &m["params"];
|
||||
let method = m["method"].as_str().unwrap_or_default();
|
||||
// abort must work while a prompt holds the agent lock
|
||||
// abort and complete must work while a prompt holds the agent lock
|
||||
if method == "complete" {
|
||||
let Some(line) = p["line"].as_str() else {
|
||||
reply(&id, Err("params.line required".into()));
|
||||
continue;
|
||||
};
|
||||
let cur = p["cursor"].as_u64().map_or(line.len(), |c| c as usize);
|
||||
let c = hx_core::command::complete(line, cur, &specs, &files);
|
||||
let items: Vec<_> = c
|
||||
.items
|
||||
.iter()
|
||||
.map(|i| json!({"label": i.label, "detail": i.detail}))
|
||||
.collect();
|
||||
reply(&id, Ok(json!({"start": c.start, "items": items})));
|
||||
continue;
|
||||
}
|
||||
if method == "abort" {
|
||||
abort.abort();
|
||||
reply(&id, Ok(json!({})));
|
||||
|
||||
Reference in new issue
Block a user