mirror of
https://github.com/instructkr/claude-code.git
synced 2026-05-14 01:46:44 +00:00
Compare commits
4 Commits
fix/resume
...
caeac828b5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
caeac828b5 | ||
|
|
85435ad4b5 | ||
|
|
5eb4b8a944 | ||
|
|
65aa559733 |
@@ -2674,10 +2674,44 @@ fn render_mcp_report_for(
|
|||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Some(args) if args.split_whitespace().next() == Some("list") && args.contains(' ') => {
|
||||||
|
// `mcp list <filter>` — list does not accept arguments; treat as unsupported action.
|
||||||
|
Ok(render_mcp_unsupported_action_text(
|
||||||
|
args,
|
||||||
|
"list accepts no filter argument; use `claw mcp list`",
|
||||||
|
))
|
||||||
|
}
|
||||||
|
Some(args) if matches!(args.split_whitespace().next(), Some("info" | "describe")) => {
|
||||||
|
Ok(render_mcp_unsupported_action_text(
|
||||||
|
args,
|
||||||
|
"use `claw mcp show <server>` to inspect a server",
|
||||||
|
))
|
||||||
|
}
|
||||||
Some(args) => Ok(render_mcp_usage(Some(args))),
|
Some(args) => Ok(render_mcp_usage(Some(args))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn render_mcp_unsupported_action_text(action: &str, hint: &str) -> String {
|
||||||
|
format!(
|
||||||
|
"MCP\n Error unsupported action '{action}'\n Hint {hint}\n Usage /mcp [list|show <server>|help]"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_mcp_unsupported_action_json(action: &str, hint: &str) -> Value {
|
||||||
|
json!({
|
||||||
|
"kind": "mcp",
|
||||||
|
"action": "error",
|
||||||
|
"ok": false,
|
||||||
|
"error_kind": "unsupported_action",
|
||||||
|
"requested_action": action,
|
||||||
|
"hint": hint,
|
||||||
|
"usage": {
|
||||||
|
"slash_command": "/mcp [list|show <server>|help]",
|
||||||
|
"direct_cli": "claw mcp [list|show <server>|help]",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn render_mcp_report_json_for(
|
fn render_mcp_report_json_for(
|
||||||
loader: &ConfigLoader,
|
loader: &ConfigLoader,
|
||||||
cwd: &Path,
|
cwd: &Path,
|
||||||
@@ -2758,6 +2792,18 @@ fn render_mcp_report_json_for(
|
|||||||
})),
|
})),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Some(args) if args.split_whitespace().next() == Some("list") && args.contains(' ') => {
|
||||||
|
Ok(render_mcp_unsupported_action_json(
|
||||||
|
args,
|
||||||
|
"list accepts no filter argument; use `claw mcp list`",
|
||||||
|
))
|
||||||
|
}
|
||||||
|
Some(args) if matches!(args.split_whitespace().next(), Some("info" | "describe")) => {
|
||||||
|
Ok(render_mcp_unsupported_action_json(
|
||||||
|
args,
|
||||||
|
"use `claw mcp show <server>` to inspect a server",
|
||||||
|
))
|
||||||
|
}
|
||||||
Some(args) => Ok(render_mcp_usage_json(Some(args))),
|
Some(args) => Ok(render_mcp_usage_json(Some(args))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4745,6 +4791,38 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn mcp_unsupported_actions_return_typed_error_not_generic_help() {
|
||||||
|
// `mcp info <name>` and `mcp list <filter>` must return typed errors, not raw help.
|
||||||
|
// Regression for #504: these previously fell through to render_mcp_usage with
|
||||||
|
// unexpected=arg, giving no machine-readable error_kind.
|
||||||
|
use crate::handle_mcp_slash_command_json;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
let cwd = PathBuf::from("/tmp");
|
||||||
|
|
||||||
|
let info_json = handle_mcp_slash_command_json(Some("info nonexistent"), &cwd)
|
||||||
|
.expect("info nonexistent should not error at IO level");
|
||||||
|
assert_eq!(info_json["kind"], "mcp");
|
||||||
|
assert_eq!(info_json["ok"], false);
|
||||||
|
assert_eq!(info_json["error_kind"], "unsupported_action");
|
||||||
|
assert!(info_json["hint"]
|
||||||
|
.as_str()
|
||||||
|
.unwrap_or_default()
|
||||||
|
.contains("show"));
|
||||||
|
|
||||||
|
let list_filter_json = handle_mcp_slash_command_json(Some("list nonexistent"), &cwd)
|
||||||
|
.expect("list nonexistent should not error at IO level");
|
||||||
|
assert_eq!(list_filter_json["kind"], "mcp");
|
||||||
|
assert_eq!(list_filter_json["ok"], false);
|
||||||
|
assert_eq!(list_filter_json["error_kind"], "unsupported_action");
|
||||||
|
|
||||||
|
let describe_json = handle_mcp_slash_command_json(Some("describe myserver"), &cwd)
|
||||||
|
.expect("describe myserver should not error at IO level");
|
||||||
|
assert_eq!(describe_json["kind"], "mcp");
|
||||||
|
assert_eq!(describe_json["ok"], false);
|
||||||
|
assert_eq!(describe_json["error_kind"], "unsupported_action");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn rejects_invalid_mcp_arguments() {
|
fn rejects_invalid_mcp_arguments() {
|
||||||
let show_error = parse_error_message("/mcp show alpha beta");
|
let show_error = parse_error_message("/mcp show alpha beta");
|
||||||
|
|||||||
@@ -877,13 +877,17 @@ fn parse_args(args: &[String]) -> Result<CliAction, String> {
|
|||||||
// `missing Anthropic credentials` even though the command is purely
|
// `missing Anthropic credentials` even though the command is purely
|
||||||
// local introspection. Mirror `agents`/`mcp`/`skills`: action is the
|
// local introspection. Mirror `agents`/`mcp`/`skills`: action is the
|
||||||
// first positional arg, target is the second.
|
// first positional arg, target is the second.
|
||||||
"plugins" => {
|
// `plugin` (singular) and `marketplace` are aliases for `plugins`.
|
||||||
|
// All three must route to the same local handler so that no form
|
||||||
|
// falls through to the LLM/prompt path.
|
||||||
|
"plugins" | "plugin" | "marketplace" => {
|
||||||
let tail = &rest[1..];
|
let tail = &rest[1..];
|
||||||
let action = tail.first().cloned();
|
let action = tail.first().cloned();
|
||||||
let target = tail.get(1).cloned();
|
let target = tail.get(1).cloned();
|
||||||
if tail.len() > 2 {
|
if tail.len() > 2 {
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
"unexpected extra arguments after `claw plugins {}`: {}",
|
"unexpected extra arguments after `claw {} {}`: {}",
|
||||||
|
rest[0],
|
||||||
tail[..2].join(" "),
|
tail[..2].join(" "),
|
||||||
tail[2..].join(" ")
|
tail[2..].join(" ")
|
||||||
));
|
));
|
||||||
@@ -926,6 +930,14 @@ fn parse_args(args: &[String]) -> Result<CliAction, String> {
|
|||||||
}
|
}
|
||||||
Ok(CliAction::Diff { output_format })
|
Ok(CliAction::Diff { output_format })
|
||||||
}
|
}
|
||||||
|
// `claw permissions <mode>` falls through to the LLM when called
|
||||||
|
// with a subcommand argument because parse_single_word_command_alias
|
||||||
|
// only intercepts the bare single-word form. Catch all multi-word
|
||||||
|
// forms here and return a structured guidance error so no network
|
||||||
|
// call or session is created.
|
||||||
|
"permissions" => Err(format!(
|
||||||
|
"`claw permissions` is a slash command. Start `claw` and run `/permissions` inside the REPL.\n Usage /permissions [read-only|workspace-write|danger-full-access]"
|
||||||
|
)),
|
||||||
"skills" => {
|
"skills" => {
|
||||||
let args = join_optional_args(&rest[1..]);
|
let args = join_optional_args(&rest[1..]);
|
||||||
match classify_skills_slash_command(args.as_deref()) {
|
match classify_skills_slash_command(args.as_deref()) {
|
||||||
@@ -3545,6 +3557,37 @@ fn run_resume_command(
|
|||||||
json: Some(handle_skills_slash_command_json(args.as_deref(), &cwd)?),
|
json: Some(handle_skills_slash_command_json(args.as_deref(), &cwd)?),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
SlashCommand::Plugins { action, target } => {
|
||||||
|
// Only list is supported in resume mode (no runtime to reload)
|
||||||
|
match action.as_deref() {
|
||||||
|
Some("install") | Some("uninstall") | Some("enable") | Some("disable")
|
||||||
|
| Some("update") => {
|
||||||
|
return Err(
|
||||||
|
"resumed /plugins mutations are interactive-only; start `claw` and run `/plugins` in the REPL".into(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
let cwd = env::current_dir()?;
|
||||||
|
let loader = ConfigLoader::default_for(&cwd);
|
||||||
|
let runtime_config = loader.load()?;
|
||||||
|
let mut manager = build_plugin_manager(&cwd, &loader, &runtime_config);
|
||||||
|
let result =
|
||||||
|
handle_plugins_slash_command(action.as_deref(), target.as_deref(), &mut manager)?;
|
||||||
|
let action_str = action.as_deref().unwrap_or("list");
|
||||||
|
let json = serde_json::json!({
|
||||||
|
"kind": "plugin",
|
||||||
|
"action": action_str,
|
||||||
|
"target": target,
|
||||||
|
"message": &result.message,
|
||||||
|
"reload_runtime": result.reload_runtime,
|
||||||
|
});
|
||||||
|
Ok(ResumeCommandOutcome {
|
||||||
|
session: session.clone(),
|
||||||
|
message: Some(result.message),
|
||||||
|
json: Some(json),
|
||||||
|
})
|
||||||
|
}
|
||||||
SlashCommand::Doctor => {
|
SlashCommand::Doctor => {
|
||||||
let report = render_doctor_report()?;
|
let report = render_doctor_report()?;
|
||||||
Ok(ResumeCommandOutcome {
|
Ok(ResumeCommandOutcome {
|
||||||
@@ -3631,7 +3674,6 @@ fn run_resume_command(
|
|||||||
| SlashCommand::Model { .. }
|
| SlashCommand::Model { .. }
|
||||||
| SlashCommand::Permissions { .. }
|
| SlashCommand::Permissions { .. }
|
||||||
| SlashCommand::Session { .. }
|
| SlashCommand::Session { .. }
|
||||||
| SlashCommand::Plugins { .. }
|
|
||||||
| SlashCommand::Login
|
| SlashCommand::Login
|
||||||
| SlashCommand::Logout
|
| SlashCommand::Logout
|
||||||
| SlashCommand::Vim
|
| SlashCommand::Vim
|
||||||
|
|||||||
@@ -397,6 +397,34 @@ fn resumed_inventory_commands_emit_structured_json_when_requested() {
|
|||||||
agents["count"].is_number(),
|
agents["count"].is_number(),
|
||||||
"count must be a number, not a text render"
|
"count must be a number, not a text render"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let plugins = assert_json_command_with_env(
|
||||||
|
&root,
|
||||||
|
&[
|
||||||
|
"--output-format",
|
||||||
|
"json",
|
||||||
|
"--resume",
|
||||||
|
session_path.to_str().expect("utf8 session path"),
|
||||||
|
"/plugins",
|
||||||
|
],
|
||||||
|
&[
|
||||||
|
(
|
||||||
|
"CLAW_CONFIG_HOME",
|
||||||
|
config_home.to_str().expect("utf8 config home"),
|
||||||
|
),
|
||||||
|
("HOME", home.to_str().expect("utf8 home")),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
assert_eq!(plugins["kind"], "plugin");
|
||||||
|
assert_eq!(plugins["action"], "list");
|
||||||
|
assert!(
|
||||||
|
plugins["reload_runtime"].is_boolean(),
|
||||||
|
"plugins reload_runtime should be a boolean"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
plugins["target"].is_null(),
|
||||||
|
"plugins target should be null when no plugin is targeted"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user