← back to initia-group__maestro

Function bodies 848 total

All specs Real LLM only Function bodies
test_prompt_type_short_text function · rust · L447-L458 (12 LOC)
src/agent/state.rs
    fn test_prompt_type_short_text() {
        assert_eq!(
            PromptType::ToolApproval {
                tool_name: "Edit".into()
            }
            .short_text(),
            "Tool: Edit"
        );
        assert_eq!(PromptType::Question.short_text(), "Question");
        assert_eq!(PromptType::InputPrompt.short_text(), "Input");
        assert_eq!(PromptType::Unknown.short_text(), "Waiting");
    }
test_same_variant_ignores_timestamps function · rust · L461-L469 (9 LOC)
src/agent/state.rs
    fn test_same_variant_ignores_timestamps() {
        let t1 = Utc::now();
        let t2 = t1 + chrono::Duration::seconds(5);
        assert!(AgentState::Running { since: t1 }.same_variant(&AgentState::Running { since: t2 }));
        assert!(
            AgentState::Spawning { since: t1 }.same_variant(&AgentState::Spawning { since: t2 })
        );
        assert!(AgentState::Idle { since: t1 }.same_variant(&AgentState::Idle { since: t2 }));
    }
test_same_variant_different_variants function · rust · L472-L478 (7 LOC)
src/agent/state.rs
    fn test_same_variant_different_variants() {
        let now = Utc::now();
        assert!(
            !AgentState::Running { since: now }.same_variant(&AgentState::Spawning { since: now })
        );
        assert!(!AgentState::Running { since: now }.same_variant(&AgentState::Idle { since: now }));
    }
test_same_variant_waiting_compares_prompt_type function · rust · L481-L497 (17 LOC)
src/agent/state.rs
    fn test_same_variant_waiting_compares_prompt_type() {
        let now = Utc::now();
        let w1 = AgentState::WaitingForInput {
            since: now,
            prompt_type: PromptType::Question,
        };
        let w2 = AgentState::WaitingForInput {
            since: now + chrono::Duration::seconds(1),
            prompt_type: PromptType::Question,
        };
        let w3 = AgentState::WaitingForInput {
            since: now,
            prompt_type: PromptType::InputPrompt,
        };
        assert!(w1.same_variant(&w2));
        assert!(!w1.same_variant(&w3));
    }
test_prompt_type_equality function · rust · L500-L519 (20 LOC)
src/agent/state.rs
    fn test_prompt_type_equality() {
        assert_eq!(PromptType::Question, PromptType::Question);
        assert_ne!(PromptType::Question, PromptType::InputPrompt);
        assert_eq!(
            PromptType::ToolApproval {
                tool_name: "Edit".into()
            },
            PromptType::ToolApproval {
                tool_name: "Edit".into()
            }
        );
        assert_ne!(
            PromptType::ToolApproval {
                tool_name: "Edit".into()
            },
            PromptType::ToolApproval {
                tool_name: "Write".into()
            }
        );
    }
parse_stream_event function · rust · L67-L73 (7 LOC)
src/agent/stream_json.rs
pub fn parse_stream_event(line: &str) -> Option<StreamEvent> {
    let trimmed = line.trim();
    if trimmed.is_empty() {
        return None;
    }
    serde_json::from_str(trimmed).ok()
}
truncate function · rust · L76-L83 (8 LOC)
src/agent/stream_json.rs
fn truncate(s: &str, max_len: usize) -> String {
    if s.len() <= max_len {
        s.to_string()
    } else {
        let end = max_len.saturating_sub(3);
        format!("{}...", &s[..end])
    }
}
Repobility · open methodology · https://repobility.com/research/
new function · rust · L107-L109 (3 LOC)
src/agent/stream_json.rs
    pub fn new() -> Self {
        Self::default()
    }
process_event function · rust · L112-L142 (31 LOC)
src/agent/stream_json.rs
    pub fn process_event(&mut self, event: StreamEvent) {
        match &event {
            StreamEvent::Assistant {
                text: Some(text), ..
            } => {
                self.current_activity = truncate(text, 60);
            }
            StreamEvent::ToolUse { tool, .. } => {
                self.current_activity = format!("Using {}", tool);
            }
            StreamEvent::ToolResult { error: Some(e), .. } => {
                self.current_activity = format!("Tool error: {}", truncate(e, 50));
            }
            StreamEvent::Result { subtype, cost } => {
                self.completed = true;
                if subtype == "error" {
                    self.error = Some("Agent reported error".into());
                }
                if let Some(cost) = cost {
                    if let Some(input) = cost.get("input_tokens").and_then(|v| v.as_u64()) {
                        self.total_input_tokens += input;
                    }
                    
process_line function · rust · L148-L155 (8 LOC)
src/agent/stream_json.rs
    pub fn process_line(&mut self, line: &str) -> bool {
        if let Some(event) = parse_stream_event(line) {
            self.process_event(event);
            true
        } else {
            false
        }
    }
to_agent_state function · rust · L158-L176 (19 LOC)
src/agent/stream_json.rs
    pub fn to_agent_state(&self) -> AgentState {
        if self.completed {
            if self.error.is_some() {
                AgentState::Errored {
                    at: Utc::now(),
                    error_hint: self.error.clone(),
                }
            } else {
                AgentState::Completed {
                    at: Utc::now(),
                    exit_code: Some(0),
                }
            }
        } else if self.events.is_empty() {
            AgentState::Spawning { since: Utc::now() }
        } else {
            AgentState::Running { since: Utc::now() }
        }
    }
current_activity function · rust · L179-L181 (3 LOC)
src/agent/stream_json.rs
    pub fn current_activity(&self) -> &str {
        &self.current_activity
    }
is_completed function · rust · L184-L186 (3 LOC)
src/agent/stream_json.rs
    pub fn is_completed(&self) -> bool {
        self.completed
    }
error function · rust · L189-L191 (3 LOC)
src/agent/stream_json.rs
    pub fn error(&self) -> Option<&str> {
        self.error.as_deref()
    }
total_input_tokens function · rust · L194-L196 (3 LOC)
src/agent/stream_json.rs
    pub fn total_input_tokens(&self) -> u64 {
        self.total_input_tokens
    }
If a scraper extracted this row, it came from Repobility (https://repobility.com)
total_output_tokens function · rust · L199-L201 (3 LOC)
src/agent/stream_json.rs
    pub fn total_output_tokens(&self) -> u64 {
        self.total_output_tokens
    }
events function · rust · L204-L206 (3 LOC)
src/agent/stream_json.rs
    pub fn events(&self) -> &[StreamEvent] {
        &self.events
    }
event_count function · rust · L209-L211 (3 LOC)
src/agent/stream_json.rs
    pub fn event_count(&self) -> usize {
        self.events.len()
    }
render_event_log function · rust · L217-L269 (53 LOC)
src/agent/stream_json.rs
    pub fn render_event_log(&self) -> String {
        let mut lines = Vec::new();

        for event in &self.events {
            match event {
                StreamEvent::System { subtype, .. } => {
                    lines.push(format!("  System: {}", subtype));
                }
                StreamEvent::Assistant { subtype, text } => {
                    let description = if let Some(text) = text {
                        truncate(text, 70)
                    } else {
                        subtype.clone()
                    };
                    let label = if subtype == "thinking" {
                        "Thinking"
                    } else {
                        "Assistant"
                    };
                    lines.push(format!("  {}: {}", label, description));
                }
                StreamEvent::ToolUse { tool, .. } => {
                    lines.push(format!("  Using {}", tool));
                }
                StreamEvent::ToolResult {
  
test_agent_mode_default function · rust · L279-L281 (3 LOC)
src/agent/stream_json.rs
    fn test_agent_mode_default() {
        assert_eq!(AgentMode::default(), AgentMode::Interactive);
    }
test_agent_mode_equality function · rust · L284-L288 (5 LOC)
src/agent/stream_json.rs
    fn test_agent_mode_equality() {
        assert_eq!(AgentMode::Interactive, AgentMode::Interactive);
        assert_eq!(AgentMode::StreamJson, AgentMode::StreamJson);
        assert_ne!(AgentMode::Interactive, AgentMode::StreamJson);
    }
test_parse_assistant_event function · rust · L293-L301 (9 LOC)
src/agent/stream_json.rs
    fn test_parse_assistant_event() {
        let line = r#"{"type":"assistant","subtype":"text","text":"Hello"}"#;
        let event = parse_stream_event(line).unwrap();
        assert!(matches!(event, StreamEvent::Assistant { .. }));
        if let StreamEvent::Assistant { subtype, text } = event {
            assert_eq!(subtype, "text");
            assert_eq!(text.unwrap(), "Hello");
        }
    }
test_parse_assistant_thinking_event function · rust · L304-L313 (10 LOC)
src/agent/stream_json.rs
    fn test_parse_assistant_thinking_event() {
        let line = r#"{"type":"assistant","subtype":"thinking","text":"Let me analyze..."}"#;
        let event = parse_stream_event(line).unwrap();
        if let StreamEvent::Assistant { subtype, text } = event {
            assert_eq!(subtype, "thinking");
            assert_eq!(text.unwrap(), "Let me analyze...");
        } else {
            panic!("Expected Assistant event");
        }
    }
Open data scored by Repobility · https://repobility.com
test_parse_tool_use_event function · rust · L316-L320 (5 LOC)
src/agent/stream_json.rs
    fn test_parse_tool_use_event() {
        let line = r#"{"type":"tool_use","tool":"Edit","input":{}}"#;
        let event = parse_stream_event(line).unwrap();
        assert!(matches!(event, StreamEvent::ToolUse { ref tool, .. } if tool == "Edit"));
    }
test_parse_tool_result_event function · rust · L323-L338 (16 LOC)
src/agent/stream_json.rs
    fn test_parse_tool_result_event() {
        let line = r#"{"type":"tool_result","tool":"Edit","output":"File edited successfully"}"#;
        let event = parse_stream_event(line).unwrap();
        if let StreamEvent::ToolResult {
            tool,
            output,
            error,
        } = event
        {
            assert_eq!(tool, "Edit");
            assert_eq!(output.unwrap(), "File edited successfully");
            assert!(error.is_none());
        } else {
            panic!("Expected ToolResult event");
        }
    }
test_parse_tool_result_error_event function · rust · L341-L356 (16 LOC)
src/agent/stream_json.rs
    fn test_parse_tool_result_error_event() {
        let line = r#"{"type":"tool_result","tool":"Bash","error":"Command failed"}"#;
        let event = parse_stream_event(line).unwrap();
        if let StreamEvent::ToolResult {
            tool,
            output,
            error,
        } = event
        {
            assert_eq!(tool, "Bash");
            assert!(output.is_none());
            assert_eq!(error.unwrap(), "Command failed");
        } else {
            panic!("Expected ToolResult event");
        }
    }
test_parse_system_event function · rust · L359-L368 (10 LOC)
src/agent/stream_json.rs
    fn test_parse_system_event() {
        let line = r#"{"type":"system","subtype":"init","session_id":"abc","model":"opus"}"#;
        let event = parse_stream_event(line).unwrap();
        if let StreamEvent::System { subtype, data } = event {
            assert_eq!(subtype, "init");
            assert_eq!(data.get("session_id").unwrap().as_str().unwrap(), "abc");
        } else {
            panic!("Expected System event");
        }
    }
test_parse_result_success_event function · rust · L371-L382 (12 LOC)
src/agent/stream_json.rs
    fn test_parse_result_success_event() {
        let line = r#"{"type":"result","subtype":"success","cost":{"input_tokens":1234,"output_tokens":567}}"#;
        let event = parse_stream_event(line).unwrap();
        if let StreamEvent::Result { subtype, cost } = event {
            assert_eq!(subtype, "success");
            let cost = cost.unwrap();
            assert_eq!(cost.get("input_tokens").unwrap().as_u64().unwrap(), 1234);
            assert_eq!(cost.get("output_tokens").unwrap().as_u64().unwrap(), 567);
        } else {
            panic!("Expected Result event");
        }
    }
test_parse_result_error_event function · rust · L385-L394 (10 LOC)
src/agent/stream_json.rs
    fn test_parse_result_error_event() {
        let line = r#"{"type":"result","subtype":"error"}"#;
        let event = parse_stream_event(line).unwrap();
        if let StreamEvent::Result { subtype, cost } = event {
            assert_eq!(subtype, "error");
            assert!(cost.is_none());
        } else {
            panic!("Expected Result event");
        }
    }
test_parse_empty_line function · rust · L397-L401 (5 LOC)
src/agent/stream_json.rs
    fn test_parse_empty_line() {
        assert!(parse_stream_event("").is_none());
        assert!(parse_stream_event("   ").is_none());
        assert!(parse_stream_event("\n").is_none());
    }
test_parse_malformed_json function · rust · L404-L408 (5 LOC)
src/agent/stream_json.rs
    fn test_parse_malformed_json() {
        assert!(parse_stream_event("not json").is_none());
        assert!(parse_stream_event("{incomplete").is_none());
        assert!(parse_stream_event(r#"{"type":"unknown_type"}"#).is_none());
    }
Repobility — the code-quality scanner for AI-generated software · https://repobility.com
test_parse_whitespace_trimmed function · rust · L411-L415 (5 LOC)
src/agent/stream_json.rs
    fn test_parse_whitespace_trimmed() {
        let line = r#"  {"type":"assistant","subtype":"text","text":"Hello"}  "#;
        let event = parse_stream_event(line);
        assert!(event.is_some());
    }
test_stream_state_initial function · rust · L420-L428 (9 LOC)
src/agent/stream_json.rs
    fn test_stream_state_initial() {
        let state = StreamJsonState::new();
        assert!(state.events.is_empty());
        assert!(state.current_activity.is_empty());
        assert!(!state.completed);
        assert!(state.error.is_none());
        assert_eq!(state.total_input_tokens, 0);
        assert_eq!(state.total_output_tokens, 0);
    }
test_stream_state_spawning function · rust · L431-L437 (7 LOC)
src/agent/stream_json.rs
    fn test_stream_state_spawning() {
        let state = StreamJsonState::new();
        assert!(matches!(
            state.to_agent_state(),
            AgentState::Spawning { .. }
        ));
    }
test_stream_state_running function · rust · L440-L448 (9 LOC)
src/agent/stream_json.rs
    fn test_stream_state_running() {
        let mut state = StreamJsonState::new();
        state.process_event(StreamEvent::Assistant {
            subtype: "text".into(),
            text: Some("Working...".into()),
        });
        assert!(matches!(state.to_agent_state(), AgentState::Running { .. }));
        assert_eq!(state.current_activity(), "Working...");
    }
test_stream_state_completed function · rust · L451-L463 (13 LOC)
src/agent/stream_json.rs
    fn test_stream_state_completed() {
        let mut state = StreamJsonState::new();
        state.process_event(StreamEvent::Result {
            subtype: "success".into(),
            cost: None,
        });
        assert!(matches!(
            state.to_agent_state(),
            AgentState::Completed { .. }
        ));
        assert!(state.is_completed());
        assert!(state.error().is_none());
    }
test_stream_state_errored function · rust · L466-L476 (11 LOC)
src/agent/stream_json.rs
    fn test_stream_state_errored() {
        let mut state = StreamJsonState::new();
        state.process_event(StreamEvent::Result {
            subtype: "error".into(),
            cost: None,
        });
        let agent_state = state.to_agent_state();
        assert!(matches!(agent_state, AgentState::Errored { .. }));
        assert!(state.is_completed());
        assert!(state.error().is_some());
    }
test_stream_state_tool_use_activity function · rust · L479-L486 (8 LOC)
src/agent/stream_json.rs
    fn test_stream_state_tool_use_activity() {
        let mut state = StreamJsonState::new();
        state.process_event(StreamEvent::ToolUse {
            tool: "Edit".into(),
            input: serde_json::Value::Object(serde_json::Map::new()),
        });
        assert_eq!(state.current_activity(), "Using Edit");
    }
test_stream_state_tool_error_activity function · rust · L489-L497 (9 LOC)
src/agent/stream_json.rs
    fn test_stream_state_tool_error_activity() {
        let mut state = StreamJsonState::new();
        state.process_event(StreamEvent::ToolResult {
            tool: "Bash".into(),
            output: None,
            error: Some("Command not found".into()),
        });
        assert!(state.current_activity().contains("Tool error"));
    }
Repobility · open methodology · https://repobility.com/research/
test_stream_state_token_tracking function · rust · L500-L511 (12 LOC)
src/agent/stream_json.rs
    fn test_stream_state_token_tracking() {
        let mut state = StreamJsonState::new();
        state.process_event(StreamEvent::Result {
            subtype: "success".into(),
            cost: Some(serde_json::json!({
                "input_tokens": 1234,
                "output_tokens": 567,
            })),
        });
        assert_eq!(state.total_input_tokens(), 1234);
        assert_eq!(state.total_output_tokens(), 567);
    }
test_stream_state_event_count function · rust · L514-L529 (16 LOC)
src/agent/stream_json.rs
    fn test_stream_state_event_count() {
        let mut state = StreamJsonState::new();
        assert_eq!(state.event_count(), 0);

        state.process_event(StreamEvent::Assistant {
            subtype: "text".into(),
            text: Some("Hello".into()),
        });
        assert_eq!(state.event_count(), 1);

        state.process_event(StreamEvent::ToolUse {
            tool: "Edit".into(),
            input: serde_json::Value::Null,
        });
        assert_eq!(state.event_count(), 2);
    }
test_stream_state_process_line function · rust · L532-L549 (18 LOC)
src/agent/stream_json.rs
    fn test_stream_state_process_line() {
        let mut state = StreamJsonState::new();

        // Valid line
        let ok = state.process_line(r#"{"type":"assistant","subtype":"text","text":"Hi"}"#);
        assert!(ok);
        assert_eq!(state.event_count(), 1);

        // Malformed line
        let ok = state.process_line("not json");
        assert!(!ok);
        assert_eq!(state.event_count(), 1); // unchanged

        // Empty line
        let ok = state.process_line("");
        assert!(!ok);
        assert_eq!(state.event_count(), 1); // unchanged
    }
test_stream_state_long_text_truncated function · rust · L552-L561 (10 LOC)
src/agent/stream_json.rs
    fn test_stream_state_long_text_truncated() {
        let mut state = StreamJsonState::new();
        let long_text = "x".repeat(200);
        state.process_event(StreamEvent::Assistant {
            subtype: "text".into(),
            text: Some(long_text),
        });
        assert!(state.current_activity().len() <= 60);
        assert!(state.current_activity().ends_with("..."));
    }
test_render_event_log_empty function · rust · L564-L568 (5 LOC)
src/agent/stream_json.rs
    fn test_render_event_log_empty() {
        let state = StreamJsonState::new();
        let log = state.render_event_log();
        assert!(log.is_empty());
    }
test_render_event_log_with_events function · rust · L571-L596 (26 LOC)
src/agent/stream_json.rs
    fn test_render_event_log_with_events() {
        let mut state = StreamJsonState::new();
        state.process_event(StreamEvent::System {
            subtype: "init".into(),
            data: serde_json::json!({"session_id": "abc"}),
        });
        state.process_event(StreamEvent::Assistant {
            subtype: "thinking".into(),
            text: Some("Let me analyze...".into()),
        });
        state.process_event(StreamEvent::ToolUse {
            tool: "Edit".into(),
            input: serde_json::json!({"file": "src/main.rs"}),
        });
        state.process_event(StreamEvent::ToolResult {
            tool: "Edit".into(),
            output: Some("File edited successfully".into()),
            error: None,
        });

        let log = state.render_event_log();
        assert!(log.contains("System: init"));
        assert!(log.contains("Thinking: Let me analyze..."));
        assert!(log.contains("Using Edit"));
        assert!(log.contains("Edit result: File e
test_render_event_log_with_tokens function · rust · L599-L611 (13 LOC)
src/agent/stream_json.rs
    fn test_render_event_log_with_tokens() {
        let mut state = StreamJsonState::new();
        state.process_event(StreamEvent::Result {
            subtype: "success".into(),
            cost: Some(serde_json::json!({
                "input_tokens": 1000,
                "output_tokens": 500,
            })),
        });

        let log = state.render_event_log();
        assert!(log.contains("Tokens: 1000 in / 500 out"));
    }
test_truncate_short_string function · rust · L616-L618 (3 LOC)
src/agent/stream_json.rs
    fn test_truncate_short_string() {
        assert_eq!(truncate("hello", 10), "hello");
    }
If a scraper extracted this row, it came from Repobility (https://repobility.com)
test_truncate_exact_length function · rust · L621-L623 (3 LOC)
src/agent/stream_json.rs
    fn test_truncate_exact_length() {
        assert_eq!(truncate("hello", 5), "hello");
    }
test_truncate_long_string function · rust · L626-L630 (5 LOC)
src/agent/stream_json.rs
    fn test_truncate_long_string() {
        let result = truncate("hello world this is a long string", 15);
        assert!(result.len() <= 15);
        assert!(result.ends_with("..."));
    }
new function · rust · L106-L145 (40 LOC)
src/app.rs
    pub fn new(config: MaestroConfig, event_tx: mpsc::UnboundedSender<AppEvent>) -> Self {
        let theme = Theme::from_name(&config.ui.theme.name);
        let initial_layout = match config.ui.default_layout {
            crate::config::settings::LayoutMode::Single => ActiveLayout::Single,
            crate::config::settings::LayoutMode::SplitH => ActiveLayout::SplitHorizontal,
            crate::config::settings::LayoutMode::SplitV => ActiveLayout::SplitVertical,
            crate::config::settings::LayoutMode::Grid => ActiveLayout::Grid,
        };

        let palette_commands = build_command_registry(&config.template);
        let palette_matcher = PaletteMatcher::new();
        let palette_suggestions = palette_matcher.match_commands("", &palette_commands);
        let profile_manager =
            ProfileManager::new(config.profile.clone(), config.active_profile.clone());

        let data_dir = expand_tilde(std::path::Path::new("~/.local/share/maestro"));
        let session
‹ prevpage 6 / 17next ›