magi-code 0.77.1

Repository-aware CLI coding agent for terminal work
Documentation
use super::super::*;
pub(super) use crate::output::{
    ActivityEvent, ActivityId, ActivityKind, ActivityMetadata, ActivityStatus,
};

pub(super) fn key(code: KeyCode) -> KeyEvent {
    KeyEvent::new(code, KeyModifiers::NONE)
}

pub(super) fn modified_key(code: KeyCode, modifiers: KeyModifiers) -> KeyEvent {
    KeyEvent::new(code, modifiers)
}

pub(super) fn key_with_kind(code: KeyCode, kind: crossterm::event::KeyEventKind) -> KeyEvent {
    KeyEvent::new_with_kind(code, KeyModifiers::NONE, kind)
}

pub(super) fn modified_key_with_kind(
    code: KeyCode,
    modifiers: KeyModifiers,
    kind: crossterm::event::KeyEventKind,
) -> KeyEvent {
    KeyEvent::new_with_kind(code, modifiers, kind)
}

pub(super) fn state_with_activity() -> MissionControlState {
    let mut state = MissionControlState::default();
    state.apply_activity_event(ActivityEvent::Started {
        id: ActivityId::new("running"),
        parent_id: None,
        kind: ActivityKind::Tool,
        status: ActivityStatus::Running,
        metadata: ActivityMetadata::new("running"),
    });
    state.apply_activity_event(ActivityEvent::Started {
        id: ActivityId::new("failed"),
        parent_id: None,
        kind: ActivityKind::Tool,
        status: ActivityStatus::Failed,
        metadata: ActivityMetadata::new("failed"),
    });
    state.selected = 0;
    state.activity_follow_tail = false;
    state
}

pub(super) fn state_with_parent_and_child() -> MissionControlState {
    let mut state = MissionControlState {
        focus_pane: crate::tui::state::TuiFocusPane::ActivityTree,
        ..Default::default()
    };
    let parent = ActivityId::new("parent");
    state.apply_activity_event(ActivityEvent::Started {
        id: parent.clone(),
        parent_id: None,
        kind: ActivityKind::SubagentBatch,
        status: ActivityStatus::Running,
        metadata: ActivityMetadata::new("parent activity"),
    });
    state.apply_activity_event(ActivityEvent::Started {
        id: ActivityId::new("child"),
        parent_id: Some(parent),
        kind: ActivityKind::Tool,
        status: ActivityStatus::Success,
        metadata: ActivityMetadata::new("child activity"),
    });
    state.selected = 0;
    state
}

pub(super) fn autocomplete_candidates() -> Vec<AutocompleteCandidate> {
    vec![
        AutocompleteCandidate::slash_command("new", "start a new session"),
        AutocompleteCandidate::slash_command("quit", "exit magi-code"),
    ]
}

pub(super) fn handle_key_with_candidates(
    key: KeyEvent,
    state: &mut MissionControlState,
) -> InputAction {
    let candidates = autocomplete_candidates();
    handle_key_with_viewport(key, state, None, &candidates)
}