Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,8 @@ We welcome contributions from the community! See our [Contributing Guide](./docs
## License

Copyright © 2025 Cortex Foundation. All rights reserved.

## Navigation

- [Back to `REPOS`](../README.md)
- [Back to `AI_REVENUE_SPRINT_100_24H`](../../README.md)
5 changes: 5 additions & 0 deletions docs/plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,8 @@ granted_permissions = ["read_files", "network"]
api_key = "your-api-key"
max_items = 20
```
## Navigation

- [Back to `cortex`](../../README.md)
- [Back to `REPOS`](../../../README.md)
- [Back to `AI_REVENUE_SPRINT_100_24H`](../../../../README.md)
6 changes: 6 additions & 0 deletions examples/plugins/code-stats/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,9 @@ The plugin can be tested by:
## License

MIT License - See LICENSE file for details.
## Navigation

- [Back to `examples/plugins`](../../README.md)
- [Back to `cortex`](../../../README.md)
- [Back to `REPOS`](../../../../README.md)
- [Back to `AI_REVENUE_SPRINT_100_24H`](../../../../../README.md)
6 changes: 6 additions & 0 deletions examples/plugins/hello-world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,9 @@ This is useful for debugging and auditing tool usage.
## License

MIT License - See LICENSE file for details.
## Navigation

- [Back to `examples/plugins`](../../README.md)
- [Back to `cortex`](../../../README.md)
- [Back to `REPOS`](../../../../README.md)
- [Back to `AI_REVENUE_SPRINT_100_24H`](../../../../../README.md)
40 changes: 38 additions & 2 deletions src/cortex-cli/src/export_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ pub struct ExportCommand {
#[arg(short, long, value_enum, default_value_t = ExportFormat::Json)]
pub format: ExportFormat,

/// Pretty-print the output (for json/yaml)
#[arg(long, default_value_t = true)]
/// Pretty-print JSON output
#[arg(long, action = clap::ArgAction::SetTrue)]
pub pretty: bool,
}

Expand Down Expand Up @@ -111,6 +111,8 @@ pub struct ExportToolCall {
impl ExportCommand {
/// Run the export command.
pub async fn run(self) -> Result<()> {
validate_format_options(self.format, self.pretty)?;

let cortex_home = dirs::home_dir()
.map(|h| h.join(".cortex"))
.ok_or_else(|| anyhow::anyhow!("Could not determine home directory"))?;
Expand Down Expand Up @@ -241,6 +243,14 @@ impl ExportCommand {
}
}

fn validate_format_options(format: ExportFormat, pretty: bool) -> Result<()> {
if pretty && format != ExportFormat::Json {
bail!("--pretty is only supported for JSON exports");
}

Ok(())
}

/// Escape a field for CSV output.
fn escape_csv_field(field: &str) -> String {
if field.contains(',') || field.contains('"') || field.contains('\n') {
Expand Down Expand Up @@ -466,4 +476,30 @@ mod tests {
assert_eq!(refs.len(), 1);
assert!(refs.contains(&"explore".to_string()));
}

#[test]
fn test_pretty_defaults_to_false() {
let cmd = ExportCommand::try_parse_from(["export", "session-id"]).unwrap();

assert!(!cmd.pretty);
}

#[test]
fn test_validate_format_options_allows_pretty_json() {
validate_format_options(ExportFormat::Json, true).unwrap();
}

#[test]
fn test_validate_format_options_rejects_pretty_yaml() {
let err = validate_format_options(ExportFormat::Yaml, true).unwrap_err();

assert!(err.to_string().contains("JSON exports"));
}

#[test]
fn test_validate_format_options_rejects_pretty_csv() {
let err = validate_format_options(ExportFormat::Csv, true).unwrap_err();

assert!(err.to_string().contains("JSON exports"));
}
}