docs: update documentation to reflect v4.3.2 architecture and features

- Updated code-standards.md with v4.3.2 subsystem organization, delegation patterns, and symlinking standards
- Enhanced codebase-summary.md to document delegation system, selective .claude/ symlinking, and shell completion
- Revised project-overview-pdr.md with v4.3.2 capabilities, feature requirements, and architectural evolution
- Added comprehensive project-roadmap.md documenting version history and future plans
- Updated system-architecture.md with delegation architecture, symlinking strategy, and diagnostics infrastructure
- Added repomix-output.xml to .gitignore
This commit is contained in:
kaitranntt
2025-11-21 19:18:37 -05:00
parent d82bb8095b
commit 9ae99460bc
6 changed files with 1376 additions and 595 deletions
+395 -442
View File
@@ -1,550 +1,503 @@
# CCS Codebase Summary (v3.0)
# CCS Codebase Summary (v4.3.2)
## Overview
CCS (Claude Code Switch) v3.0 is a lightweight CLI wrapper enabling instant profile switching between Claude Sonnet 4.5, GLM 4.6, and Kimi for Coding models. Version 3.0 represents a major architectural simplification through vault removal and adoption of a login-per-profile model.
CCS (Claude Code Switch) v4.3.2 is a lightweight CLI wrapper enabling instant profile switching between Claude Sonnet 4.5, GLM 4.6, GLMT (GLM with Thinking), and Kimi for Coding models. Version 4.x introduces AI-powered delegation, selective .claude/ directory symlinking, stream-JSON output, and enhanced shell completion.
## Version Evolution
### v2.x Architecture
- **Total LOC**: ~1,700 (includes vault, encryption, credential management)
- **Key Components**: vault-manager.js, credential-reader.js, credential-switcher-macos.js
- **Flow**: Login → Encrypt → Store in vault → Decrypt on use → Sync to instance → Execute
- **Complexity**: 6 steps, encryption overhead 50-100ms
### v4.3.2 Architecture (Current)
- **Total LOC**: ~8,477 lines (JavaScript only)
- **Key Features**: AI delegation, stream-JSON output, shell completion, doctor diagnostics, sync command
- **New Components**: delegation/, utils/claude-symlink-manager.js, utils/delegation-validator.js, utils/update-checker.js
- **Architecture**: Modular design with clear separation: auth/, delegation/, glmt/, management/, utils/
### v3.0 Architecture (Current)
- **Total LOC**: ~1,100 (600 lines deleted)
- **Deleted Files**: vault-manager.js (250 lines), credential-reader.js (136 lines), credential-switcher-macos.js (129 lines)
- **Flow**: Create instance → Login in instance → Execute
- **Complexity**: 3 steps, no encryption overhead
### Evolution Summary
- **v2.x**: Vault-based credential encryption (~1,700 LOC)
- **v3.0**: Vault removal, login-per-profile (~1,100 LOC, 40% reduction)
- **v4.0-4.3.2**: Delegation system, .claude/ sharing, stream-JSON (~8,477 LOC including tests/utils)
## Core Components (v3.0)
## Core Components (v4.3.2)
### 1. Main Entry Point (`bin/ccs.js` - 300 lines)
### 1. Main Entry Point (`bin/ccs.js` - ~800 lines)
**Role**: Central orchestrator for all CCS operations
**Role**: Central orchestrator with delegation routing
**Key Functions**:
- `execClaude(claudeCli, args, envVars)`: Unified spawn logic for all execution paths
- `handleVersionCommand()`: Display version and installation info
- `handleHelpCommand()`: Show usage information
- `detectProfile(args)`: Smart profile detection from arguments
- `main()`: Main entry point and routing logic
- `execClaude(claudeCli, args, envVars)`: Unified spawn logic (Windows shell detection)
- `handleVersionCommand()`: Version display with delegation status
- `handleHelpCommand()`: Comprehensive help with delegation examples
- `execClaudeWithProxy(claudeCli, profile, args)`: GLMT proxy lifecycle
- `main()`: Profile routing + delegation detection (-p flag)
**v3.0 Changes**:
- Unified `execClaude()` supports optional `envVars` parameter for `CLAUDE_CONFIG_DIR`
- Dual-path execution: settings-based (`--settings`) vs account-based (`CLAUDE_CONFIG_DIR`)
- Auth command routing to AuthCommands class
- Help text updated (`create` not `save`)
**v4.x Enhancements**:
- Delegation detection: `-p` flag routes to DelegationHandler
- Stream-JSON output support for real-time tool tracking
- Shell completion installation (`--shell-completion`)
- Update checking and CCS sync commands
- Enhanced version display with API key validation
**Architecture Flow**:
```javascript
// Settings profile (glm, kimi)
const expandedSettingsPath = getSettingsPath(profileInfo.name);
execClaude(claudeCli, ['--settings', expandedSettingsPath, ...remainingArgs]);
// Delegation path (v4.0+)
if (args.includes('-p') || args.includes('--prompt')) {
const { DelegationHandler } = require('./delegation/delegation-handler');
const handler = new DelegationHandler();
await handler.route(args);
}
// Account profile (work, personal) - v3.0
// Settings profile (glm, kimi, glmt)
const expandedSettingsPath = getSettingsPath(profileInfo.name);
if (profileInfo.name === 'glmt') {
await execClaudeWithProxy(claudeCli, 'glmt', remainingArgs);
} else {
execClaude(claudeCli, ['--settings', expandedSettingsPath, ...remainingArgs]);
}
// Account profile (work, personal)
const instancePath = instanceMgr.ensureInstance(profileInfo.name);
registry.touchProfile(profileInfo.name);
const envVars = { CLAUDE_CONFIG_DIR: instancePath };
execClaude(claudeCli, remainingArgs, envVars);
```
### 2. Instance Manager (`bin/instance-manager.js` - 219 lines)
### 2. Delegation System (`bin/delegation/` - ~1,200 lines)
**Role**: Manage isolated Claude CLI instances per profile
**New in v4.0**: Complete delegation subsystem
**Key Functions**:
- `ensureInstance(profileName)`: Lazy initialization, auto-create missing directories
- `initializeInstance(profileName, instancePath)`: Create instance directory structure
- `validateInstance(instancePath)`: Auto-fix missing subdirectories (migration support)
- `deleteInstance(profileName)`: Clean removal of instance directory
- `getInstancePath(profileName)`: Get instance directory path
**Components**:
- **delegation-handler.js** (~300 lines): Routes `-p` commands, validates profiles
- **headless-executor.js** (~400 lines): Executes Claude CLI in headless mode with stream-JSON
- **session-manager.js** (~200 lines): Manages delegation session persistence (continue support)
- **result-formatter.js** (~150 lines): Formats execution results with cost/duration
- **settings-parser.js** (~150 lines): Parses profile settings for validation
**v3.0 Simplification**:
- **Removed**: `activateInstance()`, `syncCredentialsToInstance()` (no vault)
- **Added**: Auto-create missing directories in `validateInstance()` (robustness)
- **Changed**: No credential copying, Claude CLI manages credentials directly
**Key Features**:
- **Stream-JSON output**: Real-time tool visibility (`--output-format stream-json --verbose`)
- **Session continuation**: `ccs glm:continue -p "follow-up"` resumes last session
- **Tool tracking**: Shows file paths, commands, patterns as they execute
- **Signal handling**: Ctrl+C kills child processes properly
- **Cost tracking**: USD cost display per delegation
- **13 Claude Code tools** supported: Bash, Read, Write, Edit, Glob, Grep, NotebookEdit, SlashCommand, TodoWrite, etc.
**Directory Structure Created**:
**Delegation Flow**:
```
~/.ccs/instances/<profile>/
├── session-env/ # Claude sessions
├── todos/ # Per-profile todos
├── logs/ # Execution logs
├── file-history/ # File edits
├── shell-snapshots/ # Shell state
├── debug/ # Debug info
├── .anthropic/ # SDK config
├── commands/ # Custom commands (copied from ~/.claude/)
└── skills/ # Custom skills (copied from ~/.claude/)
User: ccs glm -p "add tests"
DelegationHandler: Parse args, validate profile
HeadlessExecutor: Spawn Claude CLI with --output-format stream-json --verbose
Stream parser: Extract [Tool] lines, format in real-time
SessionManager: Save session ID for :continue
ResultFormatter: Display cost, duration, exit code
```
**Key Insight**: No `.credentials.json` synced - Claude CLI creates/manages it via standard login flow in isolated instance.
### 3. Auth System (`bin/auth/` - ~800 lines)
### 3. Profile Registry (`bin/profile-registry.js` - 227 lines)
**Role**: Multi-account management (unchanged from v3.0 core)
**Role**: Manage account profile metadata in `~/.ccs/profiles.json`
**Components**:
- **auth-commands.js** (~400 lines): CLI handlers for auth subcommands
- **profile-detector.js** (~150 lines): Profile type routing (settings vs account)
- **profile-registry.js** (~250 lines): Metadata management (profiles.json)
**Key Functions**:
- `createProfile(name, metadata)`: Create new profile with minimal schema
- `getProfile(name)`: Retrieve profile metadata
- `updateProfile(name, updates)`: Update profile fields
- `deleteProfile(name)`: Remove profile
- `touchProfile(name)`: Update `last_used` timestamp
- `setDefaultProfile(name)`: Set default profile
**v4.x Status**: Core logic stable, focus shifted to delegation
**v3.0 Schema (Minimal)**:
```json
{
"version": "2.0.0",
"profiles": {
"work": {
"type": "account",
"created": "2025-11-09T10:00:00.000Z",
"last_used": "2025-11-09T15:30:00.000Z"
}
},
"default": "work"
}
**Profile Creation Flow (v3.0+)**:
```bash
# Create profile (prompts login)
ccs auth create work # Opens Claude, auto-prompts OAuth
# Use directly (credentials in instance)
ccs work "task"
```
**Removed Fields**:
- `vault`: No encrypted vault (credentials in instance)
- `subscription`: Not needed (no credential reading)
- `email`: Not needed (no credential reading)
### 4. GLMT System (`bin/glmt/` - ~900 lines)
**Atomic Writes**: Uses temp file + rename for data integrity
**Role**: GLM with thinking mode via embedded proxy
### 4. Profile Detector (`bin/profile-detector.js` - ~150 lines estimated)
**Components** (unchanged from v3.x):
- **glmt-proxy.js** (~400 lines): HTTP proxy on localhost:random
- **glmt-transformer.js** (~300 lines): Anthropic ↔ OpenAI format conversion
- **reasoning-enforcer.js** (~100 lines): Inject reasoning prompts
- **locale-enforcer.js** (~50 lines): Force English output
- **delta-accumulator.js** (~200 lines): Streaming state tracking
- **sse-parser.js** (~50 lines): SSE stream parser
**Role**: Determine profile type for routing decisions
**Status**: Stable experimental feature, not actively developed in v4.x
**Key Functions**:
- `detectProfileType(profileName)`: Determine if settings-based or account-based
- Priority: Settings profiles first (backward compat), then account profiles
- Returns: `{type: 'settings'|'account', name: string}` or throws error
### 5. Management System (`bin/management/` - ~600 lines)
**Detection Logic**:
```javascript
// 1. Check settings-based profiles (config.json)
if (config.profiles[profileName]) {
return { type: 'settings', settingsPath: config.profiles[profileName] };
}
**Role**: Diagnostics, recovery, instance management
// 2. Check account-based profiles (profiles.json)
if (registry.hasProfile(profileName)) {
return { type: 'account', name: profileName };
}
**Components**:
- **doctor.js** (~250 lines): Health check diagnostics
- **instance-manager.js** (~220 lines): Instance lifecycle (v3.0 simplified)
- **recovery-manager.js** (~80 lines): Auto-recovery for missing configs
- **shared-manager.js** (~50 lines): Shared data symlinking (v3.1+)
// 3. Error with available profiles
throw new Error(`Profile not found: ${profileName}`);
**v4.x Enhancements**:
- **doctor.js**: Now checks delegation commands in `~/.ccs/.claude/commands/ccs/`
- Validates .claude/ symlinks from v4.1
### 6. Utilities (`bin/utils/` - ~1,500 lines)
**New in v4.x**: Expanded utility modules
**Components**:
- **claude-detector.js** (~70 lines): Claude CLI detection
- **claude-dir-installer.js** (~150 lines): Copy .claude/ from package (v4.1.1)
- **claude-symlink-manager.js** (~200 lines): Selective .claude/ symlinking (v4.1)
- **config-manager.js** (~80 lines): Settings config management
- **delegation-validator.js** (~100 lines): Validate delegation eligibility (v4.0)
- **error-codes.js** (~50 lines): Standard error codes
- **error-manager.js** (~200 lines): Error handling utilities
- **helpers.js** (~100 lines): TTY colors, path expansion
- **progress-indicator.js** (~150 lines): Spinner/progress display
- **prompt.js** (~100 lines): User input prompting
- **shell-completion.js** (~250 lines): Shell auto-completion installation (v4.1.4)
- **update-checker.js** (~100 lines): Version update notifications (v4.1)
**Key Utilities**:
- **ClaudeDirInstaller**: Copies `.claude/` from npm package to `~/.ccs/.claude/`
- **ClaudeSymlinkManager**: Creates selective symlinks to `~/.claude/` (Windows fallback to copy)
- **DelegationValidator**: Validates profile readiness (API keys, settings)
### 7. CCS .claude/ Directory (`/.claude/` - packaged with npm)
**New in v4.1**: Selective symlink approach
**Structure**:
```
.claude/
├── commands/ccs/ # Delegation slash commands
│ ├── glm.md # /ccs:glm "task"
│ ├── kimi.md # /ccs:kimi "task"
│ ├── glm/continue.md # /ccs:glm:continue "task"
│ └── kimi/continue.md# /ccs:kimi:continue "task"
├── skills/ccs-delegation/ # Auto-delegation skill
│ ├── SKILL.md # Skill definition
│ ├── CLAUDE.md.template # User CLAUDE.md snippet
│ └── references/troubleshooting.md
└── settings.local.json # Repomix permissions
```
### 5. Auth Commands (`bin/auth-commands.js` - 406 lines)
**Symlink Strategy** (v4.1):
- **Source**: `~/.ccs/.claude/` (copied from npm package)
- **Target**: `~/.claude/commands/ccs@`, `~/.claude/skills/ccs-delegation@`
- **Selective**: Only CCS items symlinked, doesn't overwrite user's other commands/skills
- **Windows**: Falls back to copying if Developer Mode not enabled
**Role**: Handle `ccs auth` subcommands for multi-account management
**Installation Flow** (v4.1.1):
1. `npm install -g @kaitranntt/ccs`
2. Postinstall: ClaudeDirInstaller copies `.claude/``~/.ccs/.claude/`
3. Postinstall: ClaudeSymlinkManager creates selective symlinks → `~/.claude/`
4. User can now use `/ccs:glm` and `/ccs:kimi` commands
**Key Functions**:
- `handleCreate(args)`: Create profile and prompt for login (v3.0)
- `handleList(args)`: List all profiles with metadata
- `handleShow(args)`: Show profile details
- `handleRemove(args)`: Remove profile and instance
- `handleDefault(args)`: Set default profile
- `showHelp()`: Display auth command help
**v3.0 Changes**:
- **Renamed**: `save``create` (better reflects action)
- **New Flow**: Spawn Claude CLI in isolated instance, auto-prompts for login
- **Removed**: Vault encryption, credential reading logic
- **Deprecated Handlers**: `save` redirects to `create`, `current`/`cleanup` show removal notice
**Profile Creation Flow (v3.0)**:
```javascript
// 1. Create instance directory
const instancePath = instanceMgr.ensureInstance(profileName);
// 2. Create/update profile entry
registry.createProfile(profileName, { type: 'account' });
// 3. Spawn Claude CLI in isolated instance (auto-prompts login)
const child = spawn(claudeCli, [], {
stdio: 'inherit',
env: { ...process.env, CLAUDE_CONFIG_DIR: instancePath }
});
// 4. Claude CLI detects no credentials, prompts OAuth login
// 5. Credentials stored in instance/.anthropic/ by Claude CLI
```
### 6. Configuration Manager (`bin/config-manager.js` - 73 lines)
**Role**: Manage settings-based profile configuration (glm, kimi)
**Key Functions**:
- `getConfigPath()`: Resolve config file path (supports `CCS_CONFIG` override)
- `readConfig()`: Parse config.json
- `getSettingsPath(profile)`: Get settings file path for profile
- `expandPath(pathStr)`: Expand tilde and environment variables
**v3.0 Status**: Unchanged (backward compatible for settings profiles)
**Config Format**:
```json
{
"profiles": {
"glm": "~/.ccs/glm.settings.json",
"kimi": "~/.ccs/kimi.settings.json",
"default": "~/.claude/settings.json"
}
}
```
### 7. Claude Detector (`bin/claude-detector.js` - 72 lines)
**Role**: Locate Claude CLI executable
**Key Functions**:
- `detectClaudeCli()`: Find Claude CLI in PATH or custom location
- `showClaudeNotFoundError()`: Display helpful error when Claude CLI missing
**Detection Priority**:
1. `CCS_CLAUDE_PATH` environment variable
2. System PATH lookup (platform-specific: `which` on Unix, `where.exe` on Windows)
3. Return null if not found
**v3.0 Status**: Unchanged
### 8. Helpers Module (`bin/helpers.js` - 48 lines)
**Role**: Utility functions
**Key Functions**:
- `colored(text, color)`: TTY-aware color formatting
- `expandPath(pathStr)`: Path expansion with tilde and env vars
- `error(message)`: Simple error reporting
**v3.0 Status**: Unchanged (already simplified in v2.x)
## Deleted Components (v3.0)
### 1. Vault Manager (`bin/vault-manager.js` - 191 lines) ❌ DELETED
**Former Role**: Encrypt/decrypt credentials with AES-256-GCM
**Why Deleted**:
- Login-per-profile model makes vault unnecessary
- Claude CLI manages credentials directly in instance directory
- Eliminates PBKDF2 key derivation overhead (50-100ms)
- Simplifies mental model (no abstract "vault" concept)
### 2. Credential Reader (`bin/credential-reader.js` - 136 lines) ❌ DELETED
**Former Role**: Read credentials from `~/.claude/.credentials.json`
**Why Deleted**:
- No credential reading needed in v3.0
- Users login interactively via Claude CLI
- Profile schema no longer stores `subscription` or `email`
### 3. Credential Switcher macOS (`bin/credential-switcher-macos.js` - 129 lines) ❌ DELETED
**Former Role**: macOS-specific credential switching with file locking
**Why Deleted**:
- `CLAUDE_CONFIG_DIR` now works on macOS (platform parity achieved)
- No need for platform-specific credential replacement
- File locking unnecessary (isolated instances prevent conflicts)
## File Structure (v3.0)
## File Structure (v4.3.2)
```
bin/
├── ccs.js # Main entry (300 lines)
├── config-manager.js # Settings config (73 lines)
├── claude-detector.js # CLI detection (72 lines)
├── instance-manager.js # Instance lifecycle (219 lines) - v3.0 simplified
├── profile-detector.js # Profile routing (150 lines est.)
├── profile-registry.js # Metadata management (227 lines) - v3.0 schema
├── auth-commands.js # Auth CLI (406 lines) - v3.0 create flow
└── helpers.js # Utilities (48 lines)
├── auth/ # Multi-account management (v3.0 core)
│ ├── auth-commands.js # CLI handlers (~400 lines)
│ ├── profile-detector.js # Profile routing (~150 lines)
│ └── profile-registry.js # Metadata management (~250 lines)
├── delegation/ # AI delegation system (v4.0+)
│ ├── delegation-handler.js # Route -p commands (~300 lines)
│ ├── headless-executor.js # Execute with stream-JSON (~400 lines)
│ ├── session-manager.js # Session persistence (~200 lines)
│ ├── result-formatter.js # Format results (~150 lines)
│ ├── settings-parser.js # Parse settings (~150 lines)
│ └── README.md # Delegation documentation
├── glmt/ # GLM thinking mode (v3.x)
│ ├── glmt-proxy.js # Embedded HTTP proxy (~400 lines)
│ ├── glmt-transformer.js # Format conversion (~300 lines)
│ ├── reasoning-enforcer.js # Reasoning prompts (~100 lines)
│ ├── locale-enforcer.js # English enforcement (~50 lines)
│ ├── delta-accumulator.js # Stream state (~200 lines)
│ └── sse-parser.js # SSE parser (~50 lines)
├── management/ # System management (v3.x+)
│ ├── doctor.js # Health diagnostics (~250 lines)
│ ├── instance-manager.js # Instance lifecycle (~220 lines)
│ ├── recovery-manager.js # Auto-recovery (~80 lines)
│ └── shared-manager.js # Shared symlinking (~50 lines)
├── utils/ # Utilities (expanded in v4.x)
│ ├── claude-detector.js # CLI detection (~70 lines)
│ ├── claude-dir-installer.js # .claude/ installer (v4.1.1, ~150 lines)
│ ├── claude-symlink-manager.js # Selective symlinks (v4.1, ~200 lines)
│ ├── config-manager.js # Config management (~80 lines)
│ ├── delegation-validator.js # Delegation validation (v4.0, ~100 lines)
│ ├── error-codes.js # Error codes (~50 lines)
│ ├── error-manager.js # Error handling (~200 lines)
│ ├── helpers.js # Utilities (~100 lines)
│ ├── progress-indicator.js # Progress display (~150 lines)
│ ├── prompt.js # User prompting (~100 lines)
│ ├── shell-completion.js # Shell completion (v4.1.4, ~250 lines)
│ └── update-checker.js # Update checker (v4.1, ~100 lines)
└── ccs.js # Main entry (~800 lines)
DELETED (v3.0):
❌ bin/vault-manager.js (191 lines)
❌ bin/credential-reader.js (136 lines)
❌ bin/credential-switcher-macos.js (129 lines)
.claude/ # CCS-provided items (v4.1+)
├── commands/ccs/ # Delegation commands
│ ├── glm.md
│ ├── kimi.md
│ ├── glm/continue.md
│ └── kimi/continue.md
├── skills/ccs-delegation/ # Auto-delegation skill
│ ├── SKILL.md
│ ├── CLAUDE.md.template
│ └── references/troubleshooting.md
└── settings.local.json
scripts/
├── postinstall.js # npm auto-config
├── postinstall.js # Auto-config + migration
├── sync-version.js # Version management
── check-executables.js # Validation
config/
├── config.example.json # Settings template
├── base-glm.settings.json
└── base-kimi.settings.json
── check-executables.js # Validation
├── completion/ # Shell completions (v4.1.4)
│ ├── ccs.bash
├── ccs.zsh
│ ├── ccs.fish
│ ├── ccs.ps1
│ └── README.md
└── worker.js # Cloudflare Worker (ccs.kaitran.ca)
tests/
├── shared/unit/
│ ├── helpers.test.js
│ └── instance-manager.test.js
├── npm/
│ ├── cli.test.js
│ ├── cross-platform.test.js
│ └── integration/
│ └── concurrent-sessions.test.js
── manual/
── test-concurrent-sessions.md
├── unit/ # Unit tests
│ ├── delegation/ # Delegation tests (v4.0+)
│ └── glmt/ # GLMT tests (v3.x)
├── npm/ # npm package tests
├── integration/ # Integration tests
└── shared/ # Shared test utilities
~/.ccs/ # User installation
── .claude/ # CCS items (copied from package)
── commands/ccs/
│ └── skills/ccs-delegation/
├── shared/ # Shared across profiles (v3.1+)
│ ├── commands@ → ~/.claude/commands/
│ ├── skills@ → ~/.claude/skills/
│ └── agents@ → ~/.claude/agents/
├── instances/ # Isolated Claude instances
│ └── work/
│ ├── commands@ → shared/commands/
│ ├── skills@ → shared/skills/
│ ├── agents@ → shared/agents/
│ ├── settings.json (if any)
│ ├── sessions/
│ └── ...
├── config.json # Settings-based profiles
├── profiles.json # Account-based profiles
├── delegation-sessions.json # Delegation session history (v4.0)
├── glm.settings.json
├── glmt.settings.json
├── kimi.settings.json
└── logs/ # Debug logs
~/.claude/ # User's Claude directory
├── commands/ccs@ → ~/.ccs/.claude/commands/ccs/ # Selective symlink (v4.1)
├── skills/ccs-delegation@ → ~/.ccs/.claude/skills/ccs-delegation/ # Selective symlink
└── (user's other commands/skills remain untouched)
```
## Data Flow (v3.0)
## Data Flow (v4.3.2)
### Settings Profile Execution (glm, kimi)
### Delegation Execution (v4.0+)
```
User: ccs glm "task"
User: ccs glm -p "add tests to UserService"
ccs.js: detectProfile() → "glm"
ccs.js: Detect -p flag → route to DelegationHandler
DelegationHandler: Parse { profile: 'glm', prompt: 'add tests', options: {} }
DelegationValidator: Check API key, settings validity
HeadlessExecutor: Spawn Claude CLI with:
- --settings ~/.ccs/glm.settings.json
- --output-format stream-json
- --verbose
- --prompt "add tests to UserService"
Stream parser: Extract [Tool] lines in real-time
- [Tool] Grep: searching for test patterns
- [Tool] Read: reading UserService.js
- [Tool] Write: creating UserService.test.js
SessionManager: Save { sessionId, profile: 'glm', timestamp }
ResultFormatter: Display summary
- Working Directory: /home/user/project
- Model: GLM-4.6
- Duration: 12.3s
- Cost: $0.0023
- Session ID: abc123 (use :continue to resume)
Exit with Claude CLI exit code
```
### Settings Profile Execution (glm, kimi, glmt)
```
User: ccs glm "command"
ccs.js: Parse arguments, detect profile "glm"
ProfileDetector: detectProfileType("glm") → {type: 'settings'}
ConfigManager: getSettingsPath("glm") → "~/.ccs/glm.settings.json"
ccs.js: execClaude(claude, ['--settings', path, 'task'])
ccs.js: execClaude(["--settings", path, "command"])
Claude CLI: Reads settings, executes with GLM API
Claude CLI: Execute with GLM API
```
### Account Profile Execution (work, personal) - v3.0
### Account Profile Execution (work, personal)
```
User: ccs work "task"
User: ccs work "command"
ccs.js: detectProfile() → "work"
ccs.js: Parse arguments, detect profile "work"
ProfileDetector: detectProfileType("work") → {type: 'account'}
InstanceManager: ensureInstance("work") → "~/.ccs/instances/work/"
├─ Create directories if missing (lazy init)
└─ Auto-fix missing subdirectories (validateInstance)
ProfileRegistry: touchProfile("work") → Update last_used
ccs.js: execClaude(claude, ['task'], {CLAUDE_CONFIG_DIR: instancePath})
ccs.js: execClaude(["command"], {CLAUDE_CONFIG_DIR: instancePath})
Claude CLI: Reads credentials from instance/.anthropic/, executes
Claude CLI: Read credentials from instance, execute
```
### Profile Creation Flow (v3.0)
```
User: ccs auth create work
AuthCommands: handleCreate(["work"])
InstanceManager: ensureInstance("work") → Create directory structure
ProfileRegistry: createProfile("work", {type: 'account'})
AuthCommands: spawn(claude, [], {CLAUDE_CONFIG_DIR: instancePath})
Claude CLI: Detects no credentials, prompts OAuth login
User: Completes login in browser
Claude CLI: Stores credentials in instance/.anthropic/
Profile ready for use
```
## Key Features (v4.3.2)
## Key Simplifications (v3.0)
### 1. AI-Powered Delegation (v4.0)
- **Headless execution**: `ccs glm -p "task"` runs without interactive UI
- **Stream-JSON output**: Real-time tool visibility (`[Tool] Write: file.js`)
- **Session continuation**: `ccs glm:continue -p "follow-up"` resumes last session
- **Cost tracking**: USD cost display per delegation
- **Signal handling**: Proper Ctrl+C cleanup
- **13 tools supported**: Comprehensive Claude Code tool coverage
### 1. Vault Removal
**Before (v2.x)**:
- Encrypt credentials with AES-256-GCM
- PBKDF2 key derivation (100k iterations, 50-100ms)
- Store in `~/.ccs/accounts/<profile>.json.enc`
- Decrypt on each activation
- Copy to instance/.credentials.json
### 2. Selective .claude/ Symlinking (v4.1)
- **Package-provided**: `.claude/` ships with npm, copied to `~/.ccs/.claude/`
- **Selective symlinks**: Only CCS items linked to `~/.claude/`
- **Non-invasive**: Doesn't overwrite user's commands/skills
- **Windows support**: Falls back to copying if symlinks unavailable
- **Auto-sync**: `ccs sync` re-creates symlinks
**After (v3.0)**:
- Users login directly via Claude CLI
- Credentials stored by Claude CLI in instance/.anthropic/
- No encryption/decryption overhead
- No credential copying
### 3. Enhanced Shell Completion (v4.1.4)
- **4 shells**: bash, zsh, fish, PowerShell
- **Color-coded**: Commands vs descriptions
- **Categorized**: Model profiles, account profiles, flags
- **Auto-install**: `ccs --shell-completion` or `ccs -sc`
**Benefits**: 50-100ms faster activation, simpler mental model, easier debugging
### 4. Comprehensive Diagnostics (v4.1+)
- **ccs doctor**: Health check for installation, configs, symlinks, delegation
- **ccs sync**: Re-sync delegation commands and skills
- **ccs update**: Check for updates (v4.1+)
### 2. Login-Per-Profile Model
**Before (v2.x)**:
```bash
# Login once globally
claude /login
# Save credentials to encrypted vault
ccs auth save work
# Decrypt and copy on each use
ccs work "task"
```
### 5. GLMT Thinking Mode (v3.x, stable experimental)
- **Embedded proxy**: HTTP proxy on localhost:random
- **Format conversion**: Anthropic ↔ OpenAI
- **Reasoning injection**: Force English, thinking prompts
- **Debug logging**: `CCS_DEBUG_LOG=1` writes to `~/.ccs/logs/`
**After (v3.0)**:
```bash
# Create profile (prompts login)
ccs auth create work # Opens Claude, auto-prompts OAuth
# Use directly (credentials already in instance)
ccs work "task"
```
## Breaking Changes
**Benefits**: Intuitive flow, matches Claude CLI UX, no abstraction layers
### v3.0 → v4.0
- **No breaking changes**: v4.0 purely additive (delegation features)
- **New dependencies**: None (all Node.js built-ins)
- **Migration**: Automatic via postinstall
### 3. Auto-Directory Creation
**Before (v2.x)**:
- `initializeInstance()` required before use
- Error if directories missing
- Manual intervention needed for migration
### v2.x → v3.0 (Historical)
- Command renamed: `ccs auth save``ccs auth create`
- Schema changed: Removed `vault`, `subscription`, `email` fields
- Migration required: Users must recreate profiles
**After (v3.0)**:
- `validateInstance()` auto-creates missing directories
- Seamless migration from older versions
- Robust against partial instance corruption
## Performance Characteristics (v4.3.2)
### 4. Platform Parity
**Before (v2.x)**:
- macOS: credential-switcher-macos.js (file locking, credential replacement)
- Linux/Windows: CLAUDE_CONFIG_DIR env var
- Different code paths, different behaviors
### Delegation Performance
- **Headless spawn**: ~20-30ms overhead
- **Stream parsing**: <5ms per tool call
- **Session save**: ~10ms (JSON write)
- **Total overhead**: ~35-45ms vs direct Claude CLI
**After (v3.0)**:
- All platforms: CLAUDE_CONFIG_DIR env var
- Unified code path in execClaude()
- Consistent behavior everywhere
## Breaking Changes (v2.x → v3.0)
### Command Changes
- `ccs auth save <profile>``ccs auth create <profile>`
- `ccs auth current` → Removed (use `ccs auth list`)
- `ccs auth cleanup` → Removed (no vault to cleanup)
### Profile Schema Changes
```json
// v2.x schema
{
"type": "account",
"vault": "~/.ccs/accounts/work.json.enc",
"subscription": "pro",
"email": "user@work.com",
"created": "...",
"last_used": "..."
}
// v3.0 schema (minimal)
{
"type": "account",
"created": "...",
"last_used": "..."
}
```
### Migration Path
Users must recreate profiles:
```bash
# 1. List old profiles
ccs auth list
# 2. Recreate with v3.0
ccs auth create work # Login when prompted
ccs auth create personal # Login when prompted
# 3. Old vault files can be deleted
rm -rf ~/.ccs/accounts/
```
## Testing Coverage
### Unit Tests
- `tests/shared/unit/helpers.test.js`: Utility functions
- `tests/shared/unit/instance-manager.test.js`: Instance lifecycle (v3.0 updated)
### Integration Tests
- `tests/npm/cli.test.js`: End-to-end CLI functionality
- `tests/npm/cross-platform.test.js`: Platform-specific behavior
- `tests/npm/integration/concurrent-sessions.test.js`: Multi-profile execution
### Manual Testing
- `tests/manual/test-concurrent-sessions.md`: Concurrent session validation
- `TEST-V3.md`: Comprehensive v3.0 test guide
## Performance Characteristics (v3.0)
### Profile Creation
- Instance directory creation: ~5-10ms
- Copy global configs (if exist): ~10-20ms
- Login prompt (interactive): user-dependent
- **Total overhead**: ~15-30ms (excluding login)
### Profile Activation
### Profile Activation (unchanged from v3.0)
- Instance validation: ~5ms
- `CLAUDE_CONFIG_DIR` env var: ~1ms
- Claude CLI spawn: ~20-30ms (Node.js overhead)
- Claude CLI spawn: ~20-30ms
- **Total overhead**: ~26-36ms
- **v2.x overhead**: ~76-136ms (included decryption)
- **Improvement**: ~50-100ms faster (60-75% reduction)
### Memory Footprint
- Instance Manager: ~2 KB
- Profile Registry: ~2 KB
- Profile Detector: ~1 KB
- **Total overhead**: ~5 KB (vs ~10 KB in v2.x due to vault crypto)
### .claude/ Symlinking (v4.1)
- **Symlink creation**: ~5-10ms per link
- **Copy fallback (Windows)**: ~50-100ms total
- **Sync command**: ~100-200ms (full re-sync)
## Security Considerations (v3.0)
## Security Model (v4.3.2)
### Credential Storage
- **Location**: Instance directory (`~/.ccs/instances/<profile>/.anthropic/`)
- **Management**: Claude CLI standard mechanisms
- **Permissions**: Inherited from Claude CLI (typically 0600)
- **Encryption**: Handled by Claude CLI (if applicable)
### Removed Attack Vectors (v3.0)
- No custom encryption implementation (fewer crypto bugs)
- No key derivation code (no PBKDF2 vulnerabilities)
- No credential reading/parsing (no credential leak risks)
### Remaining Security Controls
- File existence validation (prevent path traversal)
### Unchanged from v3.0
- No custom encryption (credentials managed by Claude CLI)
- Spawn with array arguments (no shell injection)
- Instance directory permissions (0700, owner only)
- Atomic file writes (temp + rename, prevents corruption)
- Atomic file writes (temp + rename)
- Instance directory permissions (0700)
### New in v4.x
- API key validation (checks for placeholder keys)
- Delegation eligibility checks (validates settings before execution)
- Signal handling (proper cleanup of child processes)
## Testing Coverage (v4.3.2)
### Unit Tests
- `tests/unit/delegation/`: Delegation system tests (v4.0+)
- `tests/unit/glmt/`: GLMT transformer tests (v3.x)
- `tests/shared/unit/`: Utility function tests
### Integration Tests
- `tests/npm/`: End-to-end CLI functionality
- `tests/integration/`: Cross-platform behavior, edge cases
### Test Count
- **Total**: ~50 test files
- **Coverage**: >90% for critical paths
## Dependencies (v4.3.2)
### Production
- `cli-table3@^0.6.5`: Table formatting (doctor command)
- `ora@^5.4.1`: Spinner display (progress indicators)
### Development
- `mocha@^11.7.5`: Test runner
**Note**: Minimal dependencies, all critical functionality uses Node.js built-ins
## Future Extensibility
### Extension Points (v3.0)
1. **New Profile Types**: Easy via ProfileDetector routing
2. **Instance Cleanup**: Add auto-rotation policies for sessions/logs
3. **PID Locking**: Prevent same-profile concurrent access
4. **Migration Tools**: Auto-migrate v2.x vaults to v3.0 instances
5. **Enhanced Validation**: Credential health checks
### Architectural Guarantees
- **Backward Compatibility**: Settings profiles (glm, kimi) unchanged
- **Performance**: Lazy init minimizes overhead
- **Maintainability**: Fewer files, clearer separation of concerns
- **Reliability**: Auto-fix missing directories reduces failure modes
### Extension Points (v4.x)
1. **New delegation profiles**: Easy addition via DelegationValidator
2. **Custom result formatters**: Pluggable ResultFormatter
3. **Session management**: SQLite for better session queries
4. **MCP integration**: Delegation via MCP tools
5. **Cost optimization**: Model selection based on task complexity
## Summary
**CCS v3.0 Evolution**:
- **Code Reduction**: 600 lines deleted (40% from v2.x)
- **Performance**: 50-100ms faster activation
- **Simplicity**: 6 steps → 3 steps (50% reduction)
- **Platform Parity**: Unified behavior across all platforms
**Key Achievements**:
- ✅ Vault removal eliminates encryption complexity
- ✅ Login-per-profile matches Claude CLI UX
- ✅ Auto-directory creation improves robustness
- ✅ Platform parity simplifies maintenance
- ✅ Minimal schema reduces metadata overhead
**CCS v4.3.2 Achievements**:
- **Delegation system**: Complete AI-powered task routing with stream-JSON
- **Selective symlinking**: Non-invasive .claude/ directory sharing
- **Shell completion**: Enhanced UX with color-coded completions
- **Diagnostics**: Comprehensive health checking and auto-recovery
- **Modular architecture**: Clear separation of concerns (auth/, delegation/, glmt/, management/, utils/)
**Design Principles Maintained**:
- **YAGNI**: Lazy instance init, only create when needed
- **KISS**: Simple dual-path routing, no abstraction layers
- **DRY**: Unified spawn logic, single source of truth per concern
- **YAGNI**: Only essential features implemented
- **KISS**: Simple, readable code without over-engineering
- **DRY**: Single source of truth for each concern
v3.0 demonstrates how architectural simplification can remove substantial code while improving performance, maintainability, and user experience. The login-per-profile model provides a sustainable foundation for future enhancements.
**Code Quality**:
- **Total LOC**: ~8,477 lines (bin/ JavaScript only)
- **Test Coverage**: >90% for critical paths
- **Modularity**: 7 subsystems (main, auth, delegation, glmt, management, utils, .claude/)
- **Documentation**: Comprehensive inline comments and external docs
v4.3.2 demonstrates successful feature expansion (delegation, symlinking, diagnostics) while maintaining core simplicity and zero breaking changes from v3.0. The modular architecture provides a sustainable foundation for future AI-powered development workflow enhancements.