Skip to main content

codewhale_command_contract/
tool_outputs.rs

1//! Pure output-pressure display; observation remains host-owned.
2use crate::config_policy::StatusToolOutputs as ToolOutputStatus;
3
4pub struct ToolOutputLabels {
5    pub raw_pressure: String,
6    pub compact_receipts: String,
7    pub artifacts: String,
8    pub none: String,
9}
10
11pub fn format_tool_output_status(status: &ToolOutputStatus, labels: &ToolOutputLabels) -> String {
12    let mut parts = Vec::new();
13    if status.raw_large_count > 0 {
14        parts.push(
15            labels
16                .raw_pressure
17                .clone()
18                .replace("{count}", &status.raw_large_count.to_string())
19                .replace("{chars}", &status.raw_large_chars.to_string()),
20        );
21    }
22    if status.receipt_count > 0 {
23        parts.push(
24            labels
25                .compact_receipts
26                .clone()
27                .replace("{count}", &status.receipt_count.to_string()),
28        );
29    }
30    if status.artifact_count > 0 {
31        parts.push(
32            labels
33                .artifacts
34                .clone()
35                .replace("{count}", &status.artifact_count.to_string())
36                .replace(
37                    "{bytes}",
38                    &codewhale_protocol::display::format_byte_size(status.artifact_bytes),
39                ),
40        );
41    }
42    if parts.is_empty() {
43        labels.none.clone()
44    } else {
45        parts.join("; ")
46    }
47}