ag-agent 0.18.0

Agentty is an ADE (Agentic Development Environment) for structured, controllable AI-assisted software development.
Documentation
use ag_contracts::{AgentRequestKind, ReasoningLevel};
use ag_session::AgentModel;
use tempfile::tempdir;

use crate::agent::backend::{AgentBackend, BuildCommandRequest};
use crate::agent::gemini::GeminiBackend;

/// Returns a utility request kind for Gemini command construction tests.
fn utility_request_kind() -> AgentRequestKind {
    AgentRequestKind::UtilityPrompt
}

/// Returns a focused-review request kind for Gemini command construction
/// tests.
fn focused_review_request_kind() -> AgentRequestKind {
    AgentRequestKind::FocusedReview
}

/// Returns a session request kind for Gemini command construction tests.
fn session_request_kind() -> AgentRequestKind {
    AgentRequestKind::SessionStart
}

#[test]
fn test_gemini_setup_creates_no_files() {
    // Arrange
    let temp_directory = tempdir().expect("failed to create temp dir");
    let backend = GeminiBackend;

    // Act
    AgentBackend::setup(&backend, temp_directory.path()).expect("setup should succeed");

    // Assert
    assert_eq!(
        std::fs::read_dir(temp_directory.path())
            .expect("failed to read dir")
            .count(),
        0
    );
}

#[test]
/// Verifies Gemini startup uses the ACP runtime command shape.
fn test_gemini_build_command_uses_acp_runtime_command() {
    // Arrange
    let temp_directory = tempdir().expect("failed to create temp dir");
    let backend = GeminiBackend;

    // Act
    let command = AgentBackend::build_command(
        &backend,
        BuildCommandRequest {
            execution_policy: &ag_contracts::ExecutionPolicy::default(),
            attachments: &[],
            folder: temp_directory.path(),
            main_checkout_root: None,
            replay_transcript: None,
            model: AgentModel::Gemini4Argon.provider_model_str(),
            permission_mode: ag_contracts::PermissionMode::AutoEdit,
            personality_prompt: None,
            prompt: "Generate title",
            reasoning_level: ReasoningLevel::default(),
            request_kind: &utility_request_kind(),
            speed_mode: ag_contracts::SpeedMode::default(),
        },
    )
    .expect("command should build");
    let args = command
        .get_args()
        .map(|arg| arg.to_string_lossy().into_owned())
        .collect::<Vec<_>>();

    // Assert
    assert_eq!(args, vec!["--acp", "--model", "gemini-4-argon"]);
    assert_eq!(command.get_current_dir(), Some(temp_directory.path()));
}

#[test]
/// Verifies Gemini research turns combine ACP permission cancellation
/// with the CLI's native sandboxed plan mode.
fn test_gemini_read_only_command_uses_sandboxed_plan_mode() {
    // Arrange
    let temp_directory = tempdir().expect("failed to create temp dir");
    let backend = GeminiBackend;

    // Act
    let command = AgentBackend::build_command(
        &backend,
        BuildCommandRequest {
            execution_policy: &ag_contracts::ExecutionPolicy::default(),
            attachments: &[],
            folder: temp_directory.path(),
            main_checkout_root: None,
            replay_transcript: None,
            model: "gemini-3.8-flash",
            permission_mode: ag_contracts::PermissionMode::ReadOnly,
            personality_prompt: None,
            prompt: "Inspect the architecture",
            reasoning_level: ReasoningLevel::default(),
            request_kind: &session_request_kind(),
            speed_mode: ag_contracts::SpeedMode::default(),
        },
    )
    .expect("command should build");
    let args = command
        .get_args()
        .map(|argument| argument.to_string_lossy().into_owned())
        .collect::<Vec<_>>();

    // Assert
    assert_eq!(
        args,
        vec![
            "--acp",
            "--model",
            "gemini-3.8-flash",
            "--approval-mode",
            "plan",
            "--sandbox"
        ]
    );
}

#[test]
/// Verifies read-only Gemini utility prompts avoid the plan-mode bootstrap
/// while ACP permission cancellation continues to reject mutations.
fn test_gemini_read_only_utility_command_uses_standard_acp_mode() {
    // Arrange
    let temp_directory = tempdir().expect("failed to create temp dir");
    let backend = GeminiBackend;

    // Act
    let command = AgentBackend::build_command(
        &backend,
        BuildCommandRequest {
            execution_policy: &ag_contracts::ExecutionPolicy::default(),
            attachments: &[],
            folder: temp_directory.path(),
            main_checkout_root: None,
            replay_transcript: None,
            model: "gemini-3.8-flash",
            permission_mode: ag_contracts::PermissionMode::ReadOnly,
            personality_prompt: None,
            prompt: "Review the supplied diff",
            reasoning_level: ReasoningLevel::default(),
            request_kind: &utility_request_kind(),
            speed_mode: ag_contracts::SpeedMode::default(),
        },
    )
    .expect("command should build");
    let args = command
        .get_args()
        .map(|argument| argument.to_string_lossy().into_owned())
        .collect::<Vec<_>>();

    // Assert
    assert_eq!(args, vec!["--acp", "--model", "gemini-3.8-flash"]);
}

#[test]
/// Verifies focused reviews share the utility prompt's non-plan ACP mode.
fn test_gemini_read_only_focused_review_uses_standard_acp_mode() {
    // Arrange
    let temp_directory = tempdir().expect("failed to create temp dir");
    let backend = GeminiBackend;

    // Act
    let command = AgentBackend::build_command(
        &backend,
        BuildCommandRequest {
            execution_policy: &ag_contracts::ExecutionPolicy::default(),
            attachments: &[],
            folder: temp_directory.path(),
            main_checkout_root: None,
            replay_transcript: None,
            model: "gemini-3.8-flash",
            permission_mode: ag_contracts::PermissionMode::ReadOnly,
            personality_prompt: None,
            prompt: "Review the supplied diff",
            reasoning_level: ReasoningLevel::default(),
            request_kind: &focused_review_request_kind(),
            speed_mode: ag_contracts::SpeedMode::default(),
        },
    )
    .expect("command should build");
    let args = command
        .get_args()
        .map(|argument| argument.to_string_lossy().into_owned())
        .collect::<Vec<_>>();

    // Assert
    assert_eq!(args, vec!["--acp", "--model", "gemini-3.8-flash"]);
}