mirror of
https://github.com/instructkr/claw-code.git
synced 2026-04-27 04:24:56 +08:00
Compare commits
2 Commits
feat/jobdo
...
feat/jobdo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83f744adf0 | ||
|
|
d49a75cad5 |
@@ -257,10 +257,18 @@ Run `claw --help` for usage."
|
||||
/// Returns a snake_case token that downstream consumers can switch on instead
|
||||
/// of regex-scraping the prose. The classification is best-effort prefix/keyword
|
||||
/// matching against the error messages produced throughout the CLI surface.
|
||||
/// #130b: Wrap io::Error with operation context so classifier can recognize filesystem failures.
|
||||
fn contextualize_io_error(operation: &str, target: &str, error: std::io::Error) -> String {
|
||||
format!("{} failed: {} ({})", operation, target, error)
|
||||
}
|
||||
|
||||
fn classify_error_kind(message: &str) -> &'static str {
|
||||
// Check specific patterns first (more specific before generic)
|
||||
if message.contains("missing Anthropic credentials") {
|
||||
"missing_credentials"
|
||||
} else if message.contains("export failed:") || message.contains("diff failed:") || message.contains("config failed:") {
|
||||
// #130b: Filesystem operation errors enriched with operation+path context.
|
||||
"filesystem_io_error"
|
||||
} else if message.contains("Manifest source files are missing") {
|
||||
"missing_manifests"
|
||||
} else if message.contains("no worker state file found") {
|
||||
@@ -723,6 +731,8 @@ enum LocalHelpTopic {
|
||||
SystemPrompt,
|
||||
DumpManifests,
|
||||
BootstrapPlan,
|
||||
// #130c: help parity for `claw diff --help`
|
||||
Diff,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -1053,6 +1063,12 @@ fn parse_args(args: &[String]) -> Result<CliAction, String> {
|
||||
// #146: `diff` is pure-local (shells out to `git diff --cached` +
|
||||
// `git diff`). No session needed to inspect the working tree.
|
||||
"diff" => {
|
||||
// #130c: accept --help / -h as first argument and route to help topic,
|
||||
// matching the behavior of status/sandbox/doctor/etc.
|
||||
// Without this guard, `claw diff --help` was rejected as extra arguments.
|
||||
if rest.len() == 2 && is_help_flag(&rest[1]) {
|
||||
return Ok(CliAction::HelpTopic(LocalHelpTopic::Diff));
|
||||
}
|
||||
if rest.len() > 1 {
|
||||
return Err(format!(
|
||||
"unexpected extra arguments after `claw diff`: {}",
|
||||
@@ -1252,6 +1268,8 @@ fn parse_local_help_action(rest: &[String]) -> Option<Result<CliAction, String>>
|
||||
"system-prompt" => LocalHelpTopic::SystemPrompt,
|
||||
"dump-manifests" => LocalHelpTopic::DumpManifests,
|
||||
"bootstrap-plan" => LocalHelpTopic::BootstrapPlan,
|
||||
// #130c: help parity for `claw diff --help`
|
||||
"diff" => LocalHelpTopic::Diff,
|
||||
_ => return None,
|
||||
};
|
||||
Some(Ok(CliAction::HelpTopic(topic)))
|
||||
@@ -6075,6 +6093,15 @@ fn render_help_topic(topic: LocalHelpTopic) -> String {
|
||||
Formats text (default), json
|
||||
Related claw doctor · claw status"
|
||||
.to_string(),
|
||||
// #130c: help topic for `claw diff --help`.
|
||||
LocalHelpTopic::Diff => "Diff
|
||||
Usage claw diff [--output-format <format>]
|
||||
Purpose show local git staged + unstaged changes for the current workspace
|
||||
Requires workspace must be inside a git repository
|
||||
Output unified diff (text) or structured diff object (json)
|
||||
Formats text (default), json
|
||||
Related claw status · claw config"
|
||||
.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6908,7 +6935,10 @@ fn run_export(
|
||||
let markdown = render_session_markdown(&session, &handle.id, &handle.path);
|
||||
|
||||
if let Some(path) = output_path {
|
||||
fs::write(path, &markdown)?;
|
||||
// #130b: Wrap io::Error with operation context so classifier recognizes filesystem failures.
|
||||
fs::write(path, &markdown).map_err(|e| -> Box<dyn std::error::Error> {
|
||||
contextualize_io_error("export", &path.display().to_string(), e).into()
|
||||
})?;
|
||||
let report = format!(
|
||||
"Export\n Result wrote markdown transcript\n File {}\n Session {}\n Messages {}",
|
||||
path.display(),
|
||||
@@ -10302,6 +10332,86 @@ mod tests {
|
||||
extra_err.contains("unexpected extra arguments"),
|
||||
"extra-args error should be specific, got: {extra_err}"
|
||||
);
|
||||
// #130b: classify_error_kind must recognize filesystem operation errors.
|
||||
// Messages produced by contextualize_io_error() must route to
|
||||
// "filesystem_io_error" kind, not default "unknown". This closes the
|
||||
// context-loss chain (run_export -> fs::write -> ? -> to_string ->
|
||||
// classify miss -> unknown) that #130b identified.
|
||||
let export_err_msg = "export failed: /tmp/bad/path (No such file or directory (os error 2))";
|
||||
assert_eq!(
|
||||
classify_error_kind(export_err_msg),
|
||||
"filesystem_io_error",
|
||||
"#130b: export fs::write errors must classify as filesystem_io_error, not unknown"
|
||||
);
|
||||
let diff_err_msg = "diff failed: /tmp/nowhere (Permission denied (os error 13))";
|
||||
assert_eq!(
|
||||
classify_error_kind(diff_err_msg),
|
||||
"filesystem_io_error",
|
||||
"#130b: diff fs errors must classify as filesystem_io_error"
|
||||
);
|
||||
let config_err_msg = "config failed: /tmp/x (Is a directory (os error 21))";
|
||||
assert_eq!(
|
||||
classify_error_kind(config_err_msg),
|
||||
"filesystem_io_error",
|
||||
"#130b: config fs errors must classify as filesystem_io_error"
|
||||
);
|
||||
// #130b: contextualize_io_error must produce messages that the classifier recognizes.
|
||||
let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "No such file or directory");
|
||||
let enriched = super::contextualize_io_error("export", "/tmp/bad/path", io_err);
|
||||
assert!(
|
||||
enriched.contains("export failed:"),
|
||||
"#130b: contextualize_io_error must include operation name, got: {enriched}"
|
||||
);
|
||||
assert!(
|
||||
enriched.contains("/tmp/bad/path"),
|
||||
"#130b: contextualize_io_error must include target path, got: {enriched}"
|
||||
);
|
||||
assert_eq!(
|
||||
classify_error_kind(&enriched),
|
||||
"filesystem_io_error",
|
||||
"#130b: enriched messages must be classifier-recognizable"
|
||||
);
|
||||
// #130c: `claw diff --help` must route to help topic, not reject as extra args.
|
||||
// Regression: `diff` was the outlier among local introspection commands
|
||||
// (status/config/mcp all accepted --help) because its parser arm rejected
|
||||
// all extra args before help detection could run.
|
||||
let diff_help_action = parse_args(&[
|
||||
"diff".to_string(),
|
||||
"--help".to_string(),
|
||||
])
|
||||
.expect("diff --help must parse as help action");
|
||||
assert!(
|
||||
matches!(diff_help_action, CliAction::HelpTopic(LocalHelpTopic::Diff)),
|
||||
"#130c: diff --help must route to LocalHelpTopic::Diff, got: {diff_help_action:?}"
|
||||
);
|
||||
let diff_h_action = parse_args(&[
|
||||
"diff".to_string(),
|
||||
"-h".to_string(),
|
||||
])
|
||||
.expect("diff -h must parse as help action");
|
||||
assert!(
|
||||
matches!(diff_h_action, CliAction::HelpTopic(LocalHelpTopic::Diff)),
|
||||
"#130c: diff -h (short form) must route to LocalHelpTopic::Diff"
|
||||
);
|
||||
// #130c: bare `claw diff` still routes to Diff action, not help.
|
||||
let diff_action = parse_args(&[
|
||||
"diff".to_string(),
|
||||
])
|
||||
.expect("bare diff must parse as diff action");
|
||||
assert!(
|
||||
matches!(diff_action, CliAction::Diff { .. }),
|
||||
"#130c: bare diff must still route to Diff action, got: {diff_action:?}"
|
||||
);
|
||||
// #130c: unknown args still rejected (non-regression).
|
||||
let diff_bad_arg = parse_args(&[
|
||||
"diff".to_string(),
|
||||
"foo".to_string(),
|
||||
])
|
||||
.expect_err("diff foo must still be rejected as extra args");
|
||||
assert!(
|
||||
diff_bad_arg.contains("unexpected extra arguments"),
|
||||
"#130c: diff with unknown arg must still error, got: {diff_bad_arg}"
|
||||
);
|
||||
// #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