mirror of
https://github.com/instructkr/claw-code.git
synced 2026-04-26 10:34:59 +08:00
Compare commits
3 Commits
feat/jobdo
...
feat/jobdo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9dd7e79eb2 | ||
|
|
0ca034472b | ||
|
|
19638a015e |
@@ -733,6 +733,15 @@ enum LocalHelpTopic {
|
||||
BootstrapPlan,
|
||||
// #130c: help parity for `claw diff --help`
|
||||
Diff,
|
||||
// #130d: help parity for `claw config --help`
|
||||
Config,
|
||||
// #130e: help parity — dispatch-order bugs (help, submit, resume)
|
||||
Meta,
|
||||
Submit,
|
||||
Resume,
|
||||
// #130e-B: help parity — surface-level bugs (plugins, prompt)
|
||||
Plugins,
|
||||
Prompt,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -781,20 +790,20 @@ fn parse_args(args: &[String]) -> Result<CliAction, String> {
|
||||
if !rest.is_empty()
|
||||
&& matches!(
|
||||
rest[0].as_str(),
|
||||
"prompt"
|
||||
| "commit"
|
||||
"commit"
|
||||
| "pr"
|
||||
| "issue"
|
||||
) =>
|
||||
{
|
||||
// `--help` following a subcommand that would otherwise forward
|
||||
// the arg to the API (e.g. `claw prompt --help`) should show
|
||||
// top-level help instead. Subcommands that consume their own
|
||||
// args (agents, mcp, plugins, skills) and local help-topic
|
||||
// subcommands (status, sandbox, doctor, init, state, export,
|
||||
// version, system-prompt, dump-manifests, bootstrap-plan) must
|
||||
// NOT be intercepted here — they handle --help in their own
|
||||
// dispatch paths via parse_local_help_action(). See #141.
|
||||
// the arg to the API should show top-level help instead.
|
||||
// Subcommands that consume their own args (agents, mcp, plugins,
|
||||
// skills) and local help-topic subcommands (status, sandbox,
|
||||
// doctor, init, state, export, version, system-prompt,
|
||||
// dump-manifests, bootstrap-plan, diff, config, help, submit,
|
||||
// resume, prompt) must NOT be intercepted here — they handle
|
||||
// --help in their own dispatch paths via
|
||||
// parse_local_help_action(). See #141, #130c, #130d, #130e.
|
||||
wants_help = true;
|
||||
index += 1;
|
||||
}
|
||||
@@ -1046,6 +1055,10 @@ fn parse_args(args: &[String]) -> Result<CliAction, String> {
|
||||
// which is synthetic friction. Accepts an optional section name
|
||||
// (env|hooks|model|plugins) matching the slash command shape.
|
||||
"config" => {
|
||||
// #130d: accept --help / -h and route to help topic instead of silently ignoring
|
||||
if rest.len() >= 2 && is_help_flag(&rest[1]) {
|
||||
return Ok(CliAction::HelpTopic(LocalHelpTopic::Config));
|
||||
}
|
||||
let tail = &rest[1..];
|
||||
let section = tail.first().cloned();
|
||||
if tail.len() > 1 {
|
||||
@@ -1270,6 +1283,15 @@ fn parse_local_help_action(rest: &[String]) -> Option<Result<CliAction, String>>
|
||||
"bootstrap-plan" => LocalHelpTopic::BootstrapPlan,
|
||||
// #130c: help parity for `claw diff --help`
|
||||
"diff" => LocalHelpTopic::Diff,
|
||||
// #130d: help parity for `claw config --help`
|
||||
"config" => LocalHelpTopic::Config,
|
||||
// #130e: help parity — dispatch-order fixes
|
||||
"help" => LocalHelpTopic::Meta,
|
||||
"submit" => LocalHelpTopic::Submit,
|
||||
"resume" => LocalHelpTopic::Resume,
|
||||
// #130e-B: help parity — surface fixes
|
||||
"plugins" => LocalHelpTopic::Plugins,
|
||||
"prompt" => LocalHelpTopic::Prompt,
|
||||
_ => return None,
|
||||
};
|
||||
Some(Ok(CliAction::HelpTopic(topic)))
|
||||
@@ -6102,6 +6124,56 @@ fn render_help_topic(topic: LocalHelpTopic) -> String {
|
||||
Formats text (default), json
|
||||
Related claw status · claw config"
|
||||
.to_string(),
|
||||
// #130d: help topic for `claw config --help`.
|
||||
LocalHelpTopic::Config => "Config
|
||||
Usage claw config [--cwd <path>] [--output-format <format>]
|
||||
Purpose merge and display the resolved .claw.json / settings.json configuration
|
||||
Options --cwd overrides the workspace directory for config lookup
|
||||
Output loaded files and merged key-value pairs (text) or JSON object (json)
|
||||
Formats text (default), json
|
||||
Related claw status · claw doctor · claw init"
|
||||
.to_string(),
|
||||
// #130e: help topic for `claw help --help` (meta-help).
|
||||
LocalHelpTopic::Meta => "Help
|
||||
Usage claw help [--output-format <format>]
|
||||
Purpose show the full CLI help text (all subcommands, flags, environment)
|
||||
Aliases claw --help · claw -h
|
||||
Formats text (default), json
|
||||
Related claw <subcommand> --help · claw version"
|
||||
.to_string(),
|
||||
// #130e: help topic for `claw submit --help`.
|
||||
LocalHelpTopic::Submit => "Submit
|
||||
Usage claw submit [--session <id|latest>] <prompt-text>
|
||||
Purpose send a prompt to an existing managed session without starting a new one
|
||||
Defaults --session latest (resumes the most recent managed session)
|
||||
Requires valid Anthropic credentials (ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY)
|
||||
Related claw prompt · claw --resume · /session list"
|
||||
.to_string(),
|
||||
// #130e: help topic for `claw resume --help`.
|
||||
LocalHelpTopic::Resume => "Resume
|
||||
Usage claw resume [<session-id|latest>]
|
||||
Purpose restart an interactive REPL attached to a managed session
|
||||
Defaults latest session if no argument provided
|
||||
Requires valid Anthropic credentials (ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY)
|
||||
Related claw submit · claw --resume · /session list"
|
||||
.to_string(),
|
||||
// #130e-B: help topic for `claw plugins --help`.
|
||||
LocalHelpTopic::Plugins => "Plugins
|
||||
Usage claw plugins [list|install|enable|disable|uninstall|update] [<target>]
|
||||
Purpose manage bundled and user plugins from the CLI surface
|
||||
Defaults list (no action prints inventory)
|
||||
Sources .claw/plugins.json, bundled catalog, user-installed
|
||||
Formats text (default), json
|
||||
Related claw mcp · claw skills · /plugins (REPL)"
|
||||
.to_string(),
|
||||
// #130e-B: help topic for `claw prompt --help`.
|
||||
LocalHelpTopic::Prompt => "Prompt
|
||||
Usage claw prompt <prompt-text>
|
||||
Purpose run a single-turn, non-interactive prompt and exit (like --print mode)
|
||||
Flags --model · --allowedTools · --output-format · --compact
|
||||
Requires valid Anthropic credentials (ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY)
|
||||
Related claw submit · claw (bare, interactive REPL)"
|
||||
.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10412,6 +10484,122 @@ mod tests {
|
||||
diff_bad_arg.contains("unexpected extra arguments"),
|
||||
"#130c: diff with unknown arg must still error, got: {diff_bad_arg}"
|
||||
);
|
||||
// #130d: `claw config --help` must route to help topic, not silently run config.
|
||||
let config_help_action = parse_args(&[
|
||||
"config".to_string(),
|
||||
"--help".to_string(),
|
||||
])
|
||||
.expect("config --help must parse as help action");
|
||||
assert!(
|
||||
matches!(config_help_action, CliAction::HelpTopic(LocalHelpTopic::Config)),
|
||||
"#130d: config --help must route to LocalHelpTopic::Config, got: {config_help_action:?}"
|
||||
);
|
||||
let config_h_action = parse_args(&[
|
||||
"config".to_string(),
|
||||
"-h".to_string(),
|
||||
])
|
||||
.expect("config -h must parse as help action");
|
||||
assert!(
|
||||
matches!(config_h_action, CliAction::HelpTopic(LocalHelpTopic::Config)),
|
||||
"#130d: config -h (short form) must route to LocalHelpTopic::Config"
|
||||
);
|
||||
// #130d: bare `claw config` still routes to Config action with no section
|
||||
let config_action = parse_args(&[
|
||||
"config".to_string(),
|
||||
])
|
||||
.expect("bare config must parse as config action");
|
||||
assert!(
|
||||
matches!(config_action, CliAction::Config { section: None, .. }),
|
||||
"#130d: bare config must still route to Config action with section=None"
|
||||
);
|
||||
// #130d: config with section still works (non-regression)
|
||||
let config_section = parse_args(&[
|
||||
"config".to_string(),
|
||||
"permissions".to_string(),
|
||||
])
|
||||
.expect("config permissions must parse");
|
||||
assert!(
|
||||
matches!(config_section, CliAction::Config { section: Some(ref s), .. } if s == "permissions"),
|
||||
"#130d: config with section must still work"
|
||||
);
|
||||
// #130e: dispatch-order help fixes for help, submit, resume
|
||||
// These previously emitted `missing_credentials` instead of showing help,
|
||||
// because parse_local_help_action() didn't route them. Now they route
|
||||
// to dedicated help topics before credential check.
|
||||
let help_help = parse_args(&[
|
||||
"help".to_string(),
|
||||
"--help".to_string(),
|
||||
])
|
||||
.expect("help --help must parse as help action");
|
||||
assert!(
|
||||
matches!(help_help, CliAction::HelpTopic(LocalHelpTopic::Meta)),
|
||||
"#130e: help --help must route to LocalHelpTopic::Meta, got: {help_help:?}"
|
||||
);
|
||||
let submit_help = parse_args(&[
|
||||
"submit".to_string(),
|
||||
"--help".to_string(),
|
||||
])
|
||||
.expect("submit --help must parse as help action");
|
||||
assert!(
|
||||
matches!(submit_help, CliAction::HelpTopic(LocalHelpTopic::Submit)),
|
||||
"#130e: submit --help must route to LocalHelpTopic::Submit"
|
||||
);
|
||||
let resume_help = parse_args(&[
|
||||
"resume".to_string(),
|
||||
"--help".to_string(),
|
||||
])
|
||||
.expect("resume --help must parse as help action");
|
||||
assert!(
|
||||
matches!(resume_help, CliAction::HelpTopic(LocalHelpTopic::Resume)),
|
||||
"#130e: resume --help must route to LocalHelpTopic::Resume"
|
||||
);
|
||||
// Short form `-h` works for all three
|
||||
let help_h = parse_args(&["help".to_string(), "-h".to_string()])
|
||||
.expect("help -h must parse");
|
||||
assert!(matches!(help_h, CliAction::HelpTopic(LocalHelpTopic::Meta)));
|
||||
let submit_h = parse_args(&["submit".to_string(), "-h".to_string()])
|
||||
.expect("submit -h must parse");
|
||||
assert!(matches!(submit_h, CliAction::HelpTopic(LocalHelpTopic::Submit)));
|
||||
let resume_h = parse_args(&["resume".to_string(), "-h".to_string()])
|
||||
.expect("resume -h must parse");
|
||||
assert!(matches!(resume_h, CliAction::HelpTopic(LocalHelpTopic::Resume)));
|
||||
// #130e-B: surface-level help fixes for plugins and prompt.
|
||||
// These previously emitted "Unknown action" (plugins) or wrong help (prompt).
|
||||
let plugins_help = parse_args(&[
|
||||
"plugins".to_string(),
|
||||
"--help".to_string(),
|
||||
])
|
||||
.expect("plugins --help must parse as help action");
|
||||
assert!(
|
||||
matches!(plugins_help, CliAction::HelpTopic(LocalHelpTopic::Plugins)),
|
||||
"#130e-B: plugins --help must route to LocalHelpTopic::Plugins, got: {plugins_help:?}"
|
||||
);
|
||||
let prompt_help = parse_args(&[
|
||||
"prompt".to_string(),
|
||||
"--help".to_string(),
|
||||
])
|
||||
.expect("prompt --help must parse as help action");
|
||||
assert!(
|
||||
matches!(prompt_help, CliAction::HelpTopic(LocalHelpTopic::Prompt)),
|
||||
"#130e-B: prompt --help must route to LocalHelpTopic::Prompt, got: {prompt_help:?}"
|
||||
);
|
||||
// Short forms
|
||||
let plugins_h = parse_args(&["plugins".to_string(), "-h".to_string()])
|
||||
.expect("plugins -h must parse");
|
||||
assert!(matches!(plugins_h, CliAction::HelpTopic(LocalHelpTopic::Plugins)));
|
||||
let prompt_h = parse_args(&["prompt".to_string(), "-h".to_string()])
|
||||
.expect("prompt -h must parse");
|
||||
assert!(matches!(prompt_h, CliAction::HelpTopic(LocalHelpTopic::Prompt)));
|
||||
// Non-regression: `prompt "actual text"` still parses as Prompt action
|
||||
let prompt_action = parse_args(&[
|
||||
"prompt".to_string(),
|
||||
"hello world".to_string(),
|
||||
])
|
||||
.expect("prompt with real text must parse");
|
||||
assert!(
|
||||
matches!(prompt_action, CliAction::Prompt { ref prompt, .. } if prompt == "hello world"),
|
||||
"#130e-B: prompt with real text must route to Prompt action"
|
||||
);
|
||||
// #147: empty / whitespace-only positional args must be rejected
|
||||
// with a specific error instead of falling through to the prompt
|
||||
// path (where they surface a misleading "missing Anthropic
|
||||
|
||||
Reference in New Issue
Block a user