Skip to content

Commit cb446a6

Browse files
echobtfactorydroid
andauthored
feat(cortex-cli): improve CLI help text and add file safety utilities (#203)
AGENT_8 CLI Help & Validation Improvements: 1. Added AFTER_HELP section to cortex-cli main.rs with: - Environment variables documentation (CORTEX_HOME, CORTEX_API_KEY, CORTEX_MODEL, CORTEX_LOG_LEVEL, NO_COLOR, VISUAL, EDITOR) - Configuration paths (config, sessions, logs, agents) - Usage examples for common commands 2. Created cortex-utils-file-safety crate with: - validate_file_for_read() - validates files before reading - validate_file_for_read_with_limit() - with custom size limit - is_special_path() - quick path safety check - FileError enum with detailed error types - Cross-platform support (Unix + Windows) - Protection against: - Block/character devices - FIFOs and sockets - Special paths (/dev, /proc, /sys on Unix) - DOS device names (CON, NUL, COM1, etc. on Windows) - Files exceeding size limit (100MB default) - Comprehensive test coverage Note: Many improvements from IMPROVEMENTS_STATUS.md were already implemented in the codebase: - PR 50 (logout confirmation) - PR 30 (built-in agent removal warning) - PR 61 (--force data loss warning) - PR 27 (session ID format validation) - PR 29 (host address validation) - PR 45 (JSON parse error handling) Co-authored-by: Droid Agent <droid@factory.ai>
1 parent c36e1f2 commit cb446a6

5 files changed

Lines changed: 412 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ members = [
4646
"cortex-utils/image",
4747
"cortex-utils/string",
4848
"cortex-utils/cache",
49+
"cortex-utils/file-safety",
4950

5051
# CLI - Features (Phase 1)
5152
"cortex-lsp",
@@ -183,6 +184,7 @@ cortex-utils-pty = { path = "cortex-utils/pty" }
183184
cortex-utils-image = { path = "cortex-utils/image" }
184185
cortex-utils-string = { path = "cortex-utils/string" }
185186
cortex-utils-cache = { path = "cortex-utils/cache" }
187+
cortex-utils-file-safety = { path = "cortex-utils/file-safety" }
186188
cortex-login = { path = "cortex-login" }
187189
cortex-keyring-store = { path = "cortex-keyring-store" }
188190
cortex-feedback = { path = "cortex-feedback" }

cortex-cli/src/main.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,31 @@ impl LogLevel {
8181
}
8282
}
8383

84+
/// After-help section with environment variables documentation.
85+
const AFTER_HELP: &str = "\
86+
ENVIRONMENT VARIABLES:
87+
CORTEX_HOME Override config directory (default: ~/.config/cortex)
88+
CORTEX_API_KEY API key (alternative to --with-api-key)
89+
CORTEX_MODEL Default model (alternative to --model)
90+
CORTEX_LOG_LEVEL Log verbosity (error, warn, info, debug, trace)
91+
NO_COLOR Disable colored output (set to '1' or 'true')
92+
VISUAL Editor for /edit command (fallback: EDITOR)
93+
EDITOR Fallback editor if VISUAL is not set
94+
95+
CONFIGURATION:
96+
Config file: ~/.config/cortex/config.toml
97+
Sessions: ~/.local/share/cortex/sessions/
98+
Logs: ~/.cache/cortex/logs/
99+
Agents: ~/.cortex/agents/ (personal), .cortex/agents/ (project)
100+
101+
EXAMPLES:
102+
cortex Start interactive TUI
103+
cortex \"fix the bug\" Start TUI with initial prompt
104+
cortex run \"explain this\" Non-interactive single request
105+
cortex exec \"run tests\" Headless execution for CI/CD
106+
cortex resume --last Continue most recent session
107+
";
108+
84109
/// Cortex CLI - AI Coding Agent
85110
///
86111
/// If no subcommand is specified, starts the interactive TUI.
@@ -90,7 +115,8 @@ impl LogLevel {
90115
#[command(about = "Cortex - AI Coding Agent", long_about = None)]
91116
#[command(
92117
subcommand_negates_reqs = true,
93-
override_usage = "cortex [OPTIONS] [PROMPT]\n cortex [OPTIONS] <COMMAND> [ARGS]"
118+
override_usage = "cortex [OPTIONS] [PROMPT]\n cortex [OPTIONS] <COMMAND> [ARGS]",
119+
after_help = AFTER_HELP
94120
)]
95121
struct Cli {
96122
#[clap(flatten)]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "cortex-utils-file-safety"
3+
version.workspace = true
4+
edition.workspace = true
5+
license.workspace = true
6+
description = "File safety utilities for Cortex - validates file paths and types before reading"
7+
8+
[lib]
9+
name = "cortex_utils_file_safety"
10+
path = "src/lib.rs"
11+
12+
[lints]
13+
workspace = true
14+
15+
[dependencies]
16+
thiserror = { workspace = true }
17+
18+
[dev-dependencies]
19+
tempfile = { workspace = true }

0 commit comments

Comments
 (0)