feat(cli): add safe claude-md init command
Add a genuinely useful /init command that creates a starter CLAUDE.md from the current repository shape without inventing unsupported setup flows. The scaffold pulls in real verification commands and repo-structure notes for this workspace, and it refuses to overwrite an existing CLAUDE.md. This keeps the command honest and low-risk while moving the CLI closer to Claude Code's practical bootstrap surface. Constraint: /init must be non-destructive and must not overwrite an existing CLAUDE.md Constraint: Generated guidance must come from observable repo structure rather than placeholder text Rejected: Interactive multi-step init workflow | too much unsupported UI/state machinery for this Rust CLI slice Confidence: high Scope-risk: moderate Reversibility: clean Directive: Keep generated CLAUDE.md templates concise and repo-derived; do not let /init drift into fake setup promises Tested: cargo fmt; cargo clippy --workspace --all-targets -- -D warnings; cargo test --workspace Not-tested: manual /init invocation in a separate temporary repository without a preexisting CLAUDE.md
This commit is contained in:
@@ -88,6 +88,11 @@ const SLASH_COMMAND_SPECS: &[SlashCommandSpec] = &[
|
||||
summary: "Inspect loaded Claude instruction memory files",
|
||||
argument_hint: None,
|
||||
},
|
||||
SlashCommandSpec {
|
||||
name: "init",
|
||||
summary: "Create a starter CLAUDE.md for this repo",
|
||||
argument_hint: None,
|
||||
},
|
||||
];
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@@ -102,6 +107,7 @@ pub enum SlashCommand {
|
||||
Resume { session_path: Option<String> },
|
||||
Config,
|
||||
Memory,
|
||||
Init,
|
||||
Unknown(String),
|
||||
}
|
||||
|
||||
@@ -132,6 +138,7 @@ impl SlashCommand {
|
||||
},
|
||||
"config" => Self::Config,
|
||||
"memory" => Self::Memory,
|
||||
"init" => Self::Init,
|
||||
other => Self::Unknown(other.to_string()),
|
||||
})
|
||||
}
|
||||
@@ -195,6 +202,7 @@ pub fn handle_slash_command(
|
||||
| SlashCommand::Resume { .. }
|
||||
| SlashCommand::Config
|
||||
| SlashCommand::Memory
|
||||
| SlashCommand::Init
|
||||
| SlashCommand::Unknown(_) => None,
|
||||
}
|
||||
}
|
||||
@@ -236,6 +244,7 @@ mod tests {
|
||||
);
|
||||
assert_eq!(SlashCommand::parse("/config"), Some(SlashCommand::Config));
|
||||
assert_eq!(SlashCommand::parse("/memory"), Some(SlashCommand::Memory));
|
||||
assert_eq!(SlashCommand::parse("/init"), Some(SlashCommand::Init));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -251,7 +260,8 @@ mod tests {
|
||||
assert!(help.contains("/resume <session-path>"));
|
||||
assert!(help.contains("/config"));
|
||||
assert!(help.contains("/memory"));
|
||||
assert_eq!(slash_command_specs().len(), 10);
|
||||
assert!(help.contains("/init"));
|
||||
assert_eq!(slash_command_specs().len(), 11);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user