Make init output match the console-style command UX

Reformat /init results into the same structured operator-console style used by the other polished commands so create and skip outcomes are easier to scan. This keeps the command behavior unchanged while making repo bootstrapping feedback feel more intentional.

Constraint: /init must stay non-destructive and continue refusing to overwrite an existing CLAUDE.md
Rejected: Expand /init to write more files in the same slice | broader scaffolding would be riskier than a focused UX polish commit
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: Keep /init output explicit about whether the file was created or skipped so users can trust the command in existing repos
Tested: cargo fmt --manifest-path ./rust/Cargo.toml --all; cargo clippy --manifest-path ./rust/Cargo.toml --workspace --all-targets -- -D warnings; cargo test --manifest-path ./rust/Cargo.toml --workspace
Not-tested: Manual /init run in a repo that already has a heavily customized CLAUDE.md
This commit is contained in:
Yeachan-Heo
2026-03-31 21:13:27 +00:00
parent 9f3be03463
commit 6076041f19

View File

@@ -338,6 +338,26 @@ fn format_resume_report(session_path: &str, message_count: usize, turns: u32) ->
) )
} }
fn format_init_report(path: &Path, created: bool) -> String {
if created {
format!(
"Init
CLAUDE.md {}
Result created
Next step Review and tailor the generated guidance",
path.display()
)
} else {
format!(
"Init
CLAUDE.md {}
Result skipped (already exists)
Next step Edit the existing file intentionally if workflows changed",
path.display()
)
}
}
fn parse_git_status_metadata(status: Option<&str>) -> (Option<PathBuf>, Option<String>) { fn parse_git_status_metadata(status: Option<&str>) -> (Option<PathBuf>, Option<String>) {
let Some(status) = status else { let Some(status) = status else {
return (None, None); return (None, None);
@@ -949,15 +969,12 @@ fn init_claude_md() -> Result<String, Box<dyn std::error::Error>> {
let cwd = env::current_dir()?; let cwd = env::current_dir()?;
let claude_md = cwd.join("CLAUDE.md"); let claude_md = cwd.join("CLAUDE.md");
if claude_md.exists() { if claude_md.exists() {
return Ok(format!( return Ok(format_init_report(&claude_md, false));
"init: skipped because {} already exists",
claude_md.display()
));
} }
let content = render_init_claude_md(&cwd); let content = render_init_claude_md(&cwd);
fs::write(&claude_md, content)?; fs::write(&claude_md, content)?;
Ok(format!("init: created {}", claude_md.display())) Ok(format_init_report(&claude_md, true))
} }
fn render_init_claude_md(cwd: &Path) -> String { fn render_init_claude_md(cwd: &Path) -> String {
@@ -1367,7 +1384,7 @@ fn print_help() {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::{ use super::{
format_cost_report, format_model_report, format_model_switch_report, format_cost_report, format_init_report, format_model_report, format_model_switch_report,
format_permissions_report, format_permissions_switch_report, format_resume_report, format_permissions_report, format_permissions_switch_report, format_resume_report,
format_status_report, normalize_permission_mode, parse_args, parse_git_status_metadata, format_status_report, normalize_permission_mode, parse_args, parse_git_status_metadata,
render_config_report, render_init_claude_md, render_memory_report, render_repl_help, render_config_report, render_init_claude_md, render_memory_report, render_repl_help,
@@ -1537,6 +1554,15 @@ mod tests {
assert!(report.contains("Current workspace-write")); assert!(report.contains("Current workspace-write"));
} }
#[test]
fn init_report_uses_structured_output() {
let created = format_init_report(Path::new("/tmp/CLAUDE.md"), true);
assert!(created.contains("Init"));
assert!(created.contains("Result created"));
let skipped = format_init_report(Path::new("/tmp/CLAUDE.md"), false);
assert!(skipped.contains("skipped (already exists)"));
}
#[test] #[test]
fn model_report_uses_sectioned_layout() { fn model_report_uses_sectioned_layout() {
let report = format_model_report("claude-sonnet", 12, 4); let report = format_model_report("claude-sonnet", 12, 4);