Skip to main content

ralph_workflow/agents/
ccs.rs

1//! CCS (Claude Code Switch) Alias Resolution
2//!
3//! This module provides support for resolving CCS aliases to agent configurations.
4//! CCS is a universal AI profile manager that supports multiple Claude accounts,
5//! Gemini, Copilot, `OpenRouter`, and other providers.
6//!
7//! # Direct Claude Execution for CCS GLM Only
8//!
9//! **IMPORTANT**: This module bypasses the `ccs` wrapper command only for `ccs/glm`.
10//!
11//! ## Why?
12//!
13//! The `ccs` wrapper command does not pass through all Claude CLI flags properly
14//! (especially streaming-related flags like `--include-partial-messages`). For GLM,
15//! Ralph also needs to inject Anthropic-compatible env vars from CCS settings.
16//!
17//! For other CCS profiles/providers (e.g. Gemini, Codex), CCS must initialize
18//! provider-specific state itself, so Ralph runs `ccs ...` directly and does not
19//! inject GLM/Anthropic env vars.
20//!
21//! ## How?
22//!
23//! For `ccs/glm`, instead of running `ccs glm --print --output-format=stream-json ...`, we run:
24//! ```bash
25//! ANTHROPIC_BASE_URL="..." \
26//! ANTHROPIC_AUTH_TOKEN="..." \
27//! ANTHROPIC_MODEL="..." \
28//! claude --print --output-format=stream-json ...
29//! ```
30//!
31//! The environment variables are loaded from CCS' settings files using the same
32//! resolution rules CCS uses (via `~/.ccs/config.json` / `~/.ccs/config.yaml` and
33//! common settings filenames like `~/.ccs/{profile}.settings.json`). This avoids
34//! running the `ccs` wrapper while still using CCS-managed credentials.
35//!
36//! ## Fallback
37//!
38//! If the `claude` binary is not found in PATH (or env vars can't be loaded), the
39//! original `ccs` command is used.
40//!
41//! # Usage
42//!
43//! Agents can be specified using `ccs/alias` syntax:
44//! - `ccs/work` - Uses the "work" profile from CCS config
45//! - `ccs/personal` - Uses the "personal" profile
46//! - `ccs/gemini` - Uses CCS with Gemini provider
47//! - `ccs` - Uses the default CCS profile
48//!
49//! # Configuration
50//!
51//! CCS aliases are defined in `~/.config/ralph-workflow.toml`:
52//!
53//! ```toml
54//! [ccs]
55//! # Defaults applied to all CCS aliases unless overridden per-alias.
56//! # If your CCS version doesn't support these Claude CLI flags, set them to "".
57//! output_flag = "--output-format=stream-json"
58//! verbose_flag = "--verbose"
59//! # YOLO (autonomous) mode: enabled by default (skip permission/confirmation prompts).
60//! # Set to "" to disable and require confirmations.
61//! yolo_flag = "--dangerously-skip-permissions"
62//! json_parser = "claude"
63//!
64//! [ccs_aliases]
65//! work = "ccs work" # shorthand
66//! personal = { cmd = "ccs personal" } # explicit table form
67//! gemini = { cmd = "ccs gemini", output_flag = "", verbose_flag = "", json_parser = "generic" }
68//! ```
69
70use super::ccs_env::{
71    find_ccs_profile_suggestions, find_claude_binary, load_ccs_env_vars, CcsEnvVarsError,
72};
73use super::config::AgentConfig;
74use super::parser::JsonParserType;
75use crate::common::split_command;
76use crate::config::{CcsAliasConfig, CcsConfig};
77use std::collections::HashMap;
78use std::path::Path;
79
80// Sub-modules included via include!() macro
81include!("ccs/parsing.rs");
82include!("ccs/configuration.rs");
83
84#[cfg(test)]
85mod io_tests {
86    include!("ccs/io_tests.rs");
87}