@kaitranntt/ccs 3.5.0 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,268 @@
1
+ # Troubleshooting
2
+
3
+ AI-oriented error resolution guide for CCS delegation issues.
4
+
5
+ ## Error Pattern Matching
6
+
7
+ ### Profile Configuration Errors
8
+
9
+ **Pattern:** `Profile 'X' is not configured for delegation`
10
+ ```
11
+ Root cause: Missing ~/.ccs/{profile}.settings.json
12
+ Resolution:
13
+ 1. Check file exists: ls ~/.ccs/{profile}.settings.json
14
+ 2. Run diagnostics: ccs doctor
15
+ 3. If missing, user must configure profile manually
16
+ ```
17
+
18
+ **Pattern:** `Invalid API key` (401 error)
19
+ ```
20
+ Root cause: API token expired or invalid
21
+ Resolution:
22
+ 1. Verify token exists in settings.json
23
+ 2. Test with simple command: ccs {profile} "test"
24
+ 3. If fails, user must regenerate token from provider
25
+ ```
26
+
27
+ **Pattern:** `Settings file not found`
28
+ ```
29
+ Root cause: ~/.ccs/{profile}.settings.json doesn't exist
30
+ Resolution:
31
+ 1. Run: ccs doctor
32
+ 2. Shows missing profiles
33
+ 3. User must configure manually
34
+ ```
35
+
36
+ ### Delegation Execution Errors
37
+
38
+ **Pattern:** `No previous session found for {profile}`
39
+ ```
40
+ Root cause: Using :continue without initial session
41
+ Resolution:
42
+ - Cannot use ccs {profile}:continue without prior session
43
+ - Must run: ccs {profile} -p "initial task" first
44
+ - Then can continue with: ccs {profile}:continue -p "follow-up"
45
+ Example:
46
+ [X] ccs glm:continue -p "task" # ERROR: no session
47
+ [OK] ccs glm -p "task" # Creates session
48
+ [OK] ccs glm:continue -p "more" # Uses session
49
+ ```
50
+
51
+ **Pattern:** `Missing prompt after -p flag`
52
+ ```
53
+ Root cause: No argument provided after -p
54
+ Resolution:
55
+ - Syntax: ccs {profile} -p "prompt text"
56
+ - Quote prompt if contains spaces
57
+ Example:
58
+ [X] ccs glm -p # ERROR
59
+ [OK] ccs glm -p "add tests" # Correct
60
+ ```
61
+
62
+ **Pattern:** `No profile specified`
63
+ ```
64
+ Root cause: Command missing profile name
65
+ Resolution:
66
+ - Syntax: ccs <profile> -p "task"
67
+ - Available profiles: glm, kimi
68
+ Example:
69
+ [X] ccs -p "task" # ERROR: no profile
70
+ [OK] ccs glm -p "task" # Correct
71
+ ```
72
+
73
+ **Pattern:** Exit code 1 with JSON parse error
74
+ ```
75
+ Root cause: Claude CLI returned non-stream-JSON output
76
+ Resolution:
77
+ 1. Check if --output-format stream-json is supported
78
+ 2. Verify Claude CLI version (need recent version with stream-json support)
79
+ 3. Test manually: claude -p "test" --output-format stream-json
80
+ 4. If not supported, delegation won't work
81
+ ```
82
+
83
+ ### Session Management Errors
84
+
85
+ **Pattern:** Session file corrupted
86
+ ```
87
+ Root cause: ~/.ccs/delegation-sessions.json malformed
88
+ Resolution:
89
+ 1. Backup file: cp ~/.ccs/delegation-sessions.json ~/.ccs/delegation-sessions.json.bak
90
+ 2. Delete corrupted file: rm ~/.ccs/delegation-sessions.json
91
+ 3. New file created on next delegation
92
+ 4. Previous sessions lost but fresh start
93
+ ```
94
+
95
+ **Pattern:** Session expired
96
+ ```
97
+ Root cause: Session older than 30 days
98
+ Resolution:
99
+ - Sessions auto-expire after 30 days
100
+ - Start new session: ccs {profile} -p "task"
101
+ - Cannot resume expired sessions
102
+ ```
103
+
104
+ ### Network & API Errors
105
+
106
+ **Pattern:** Connection timeout
107
+ ```
108
+ Root cause: Network issue or API endpoint unreachable
109
+ Resolution:
110
+ 1. Check internet: ping 8.8.8.8
111
+ 2. Verify API endpoint in settings.json
112
+ 3. Check firewall/proxy settings
113
+ 4. Retry delegation
114
+ ```
115
+
116
+ **Pattern:** Rate limiting (429)
117
+ ```
118
+ Root cause: Too many API requests
119
+ Resolution:
120
+ 1. Wait 60 seconds before retry
121
+ 2. Reduce concurrent delegations
122
+ 3. Check API quota limits
123
+ ```
124
+
125
+ ### File Operation Errors
126
+
127
+ **Pattern:** File not found during delegation
128
+ ```
129
+ Root cause: Path doesn't exist or wrong working directory
130
+ Resolution:
131
+ 1. Delegation runs in cwd where command executed
132
+ 2. Verify file exists: ls <file>
133
+ 3. Use absolute paths in prompt if needed
134
+ Example:
135
+ Prompt: "refactor src/auth.js"
136
+ Check: ls src/auth.js # Must exist in cwd
137
+ ```
138
+
139
+ **Pattern:** Permission denied writing files
140
+ ```
141
+ Root cause: Insufficient permissions in target directory
142
+ Resolution:
143
+ 1. Check directory permissions: ls -la
144
+ 2. Verify cwd is writable
145
+ 3. Don't delegate in read-only directories
146
+ ```
147
+
148
+ ## Diagnostic Commands
149
+
150
+ **Profile validation:**
151
+ ```bash
152
+ ccs doctor # Check all profiles
153
+ cat ~/.ccs/glm.settings.json # Verify settings
154
+ ccs glm "echo test" 2>&1 # Test execution
155
+ ```
156
+
157
+ **Session inspection:**
158
+ ```bash
159
+ cat ~/.ccs/delegation-sessions.json # View sessions
160
+ jq '.glm' ~/.ccs/delegation-sessions.json # Check specific profile
161
+ ```
162
+
163
+ **Delegation test:**
164
+ ```bash
165
+ ccs glm -p "create test.txt file with 'hello'" # Simple test
166
+ cat test.txt # Verify result
167
+ ```
168
+
169
+ **Debug mode:**
170
+ ```bash
171
+ export CCS_DEBUG=1
172
+ ccs glm -p "task" 2>&1 | tee debug.log # Capture full output
173
+ ```
174
+
175
+ ## Decision Tree
176
+
177
+ ```
178
+ Delegation fails?
179
+
180
+ ├─→ "Profile not configured"
181
+ │ └─→ Run: ccs doctor
182
+ │ └─→ Configure missing profile
183
+
184
+ ├─→ "No previous session"
185
+ │ └─→ Using :continue?
186
+ │ ├─→ YES: Run initial task first
187
+ │ └─→ NO: Different error
188
+
189
+ ├─→ "Missing prompt"
190
+ │ └─→ Check syntax: ccs {profile} -p "prompt"
191
+
192
+ ├─→ Exit code 1
193
+ │ └─→ Check error message
194
+ │ ├─→ JSON parse: Claude CLI version issue
195
+ │ ├─→ File not found: Verify paths
196
+ │ └─→ API error: Check network/token
197
+
198
+ └─→ Silent failure
199
+ └─→ Enable debug: export CCS_DEBUG=1
200
+ ```
201
+
202
+ ## Common Patterns to Avoid
203
+
204
+ **Anti-pattern:** Delegating without profile validation
205
+ ```
206
+ [X] Assume profile exists
207
+ [OK] Run ccs doctor first to verify
208
+ ```
209
+
210
+ **Anti-pattern:** Using :continue immediately
211
+ ```
212
+ [X] ccs glm:continue -p "task" # No initial session
213
+ [OK] ccs glm -p "task" && ccs glm:continue -p "more"
214
+ ```
215
+
216
+ **Anti-pattern:** Delegating complex tasks
217
+ ```
218
+ [X] ccs glm -p "implement OAuth2" # Too complex
219
+ [OK] ccs glm -p "add tests for login function"
220
+ ```
221
+
222
+ **Anti-pattern:** Vague prompts
223
+ ```
224
+ [X] ccs glm -p "fix the bug" # No context
225
+ [OK] ccs glm -p "fix typo in src/auth.js line 42"
226
+ ```
227
+
228
+ ## Recovery Procedures
229
+
230
+ **Reset session state:**
231
+ ```bash
232
+ rm ~/.ccs/delegation-sessions.json
233
+ # Fresh start, all sessions lost
234
+ ```
235
+
236
+ **Reconfigure profile:**
237
+ ```bash
238
+ ccs doctor # Shows issues
239
+ # Edit ~/.ccs/{profile}.settings.json manually
240
+ # Verify: ccs {profile} "test"
241
+ ```
242
+
243
+ **Test delegation flow:**
244
+ ```bash
245
+ # 1. Simple task
246
+ ccs glm -p "create test.txt with content 'hello'"
247
+
248
+ # 2. Verify session created
249
+ cat ~/.ccs/delegation-sessions.json | jq '.glm.sessionId'
250
+
251
+ # 3. Test continue
252
+ ccs glm:continue -p "append 'world' to test.txt"
253
+
254
+ # 4. Verify aggregation
255
+ cat ~/.ccs/delegation-sessions.json | jq '.glm.turns'
256
+ ```
257
+
258
+ ## Emergency Fallback
259
+
260
+ If delegation completely broken:
261
+ ```bash
262
+ # Use Claude CLI directly
263
+ claude -p "task" --settings ~/.ccs/glm.settings.json
264
+
265
+ # Bypass delegation (no -p flag)
266
+ ccs glm
267
+ # Then work interactively
268
+ ```
package/README.md CHANGED
@@ -174,29 +174,51 @@ Then: 🔴 _"You've reached your usage limit."_
174
174
  <details>
175
175
  <summary><strong>❌ OLD WAY:</strong> Switch When You Hit Limits (Reactive)</summary>
176
176
 
177
- ### Your Current Workflow:
178
- - **2pm:** Building features, in the zone
179
- - **3pm:** 🔴 Usage limit hit
180
- - **3:05pm:** Stop work, edit `~/.claude/settings.json`
181
- - **3:15pm:** Switch accounts, lose context
182
- - **3:30pm:** Try to get back in flow state
183
- - **4pm:** Finally productive again
177
+ <br>
178
+
179
+ ```mermaid
180
+ graph LR
181
+ A[2pm: Building features<br/>In the zone] --> B[3pm: Usage limit hit<br/>BLOCKED]
182
+ B --> C[3:05pm: Stop work<br/>Edit settings.json]
183
+ C --> D[3:15pm: Switch accounts<br/>Context lost]
184
+ D --> E[3:30pm: Restart<br/>Trying to focus]
185
+ E --> F[4pm: Finally productive<br/>Back in flow]
186
+
187
+ style A fill:#d4edda,stroke:#333,color:#000
188
+ style B fill:#f8d7da,stroke:#333,color:#000
189
+ style C fill:#fff3cd,stroke:#333,color:#000
190
+ style D fill:#f8d7da,stroke:#333,color:#000
191
+ style E fill:#fff3cd,stroke:#333,color:#000
192
+ style F fill:#d4edda,stroke:#333,color:#000
193
+ ```
184
194
 
185
- - **Result:** 1 hour lost, momentum destroyed, frustration builds
195
+ **Result:** 1 hour lost, momentum destroyed, frustration builds
186
196
 
187
197
  </details>
188
198
 
189
199
  <details open>
190
200
  <summary><strong>✨ NEW WAY:</strong> Run Parallel From Start (Proactive) - <strong>RECOMMENDED</strong></summary>
191
201
 
192
- ### Your New Workflow:
193
- - **2pm:** **Terminal 1:** `ccs "Plan the API architecture"` → Strategic thinking (Claude Pro)
194
- - **2pm:** **Terminal 2:** `ccs glm "Implement the endpoints"` → Code execution (GLM)
195
- - **3pm:** Still shipping, no interruptions
196
- - **4pm:** Flow state achieved, productivity spiking
197
- - **5pm:** Features shipped, context maintained
202
+ <br>
198
203
 
199
- - **Result:** Zero downtime, continuous productivity, less frustration
204
+ ```mermaid
205
+ graph LR
206
+ A[2pm: Start work] --> B[Terminal 1: Claude Pro<br/>Strategic planning]
207
+ A --> C[Terminal 2: GLM<br/>Code execution]
208
+ B --> D[3pm: Still shipping<br/>No interruptions]
209
+ C --> D
210
+ D --> E[4pm: Flow state<br/>Productivity peak]
211
+ E --> F[5pm: Features shipped<br/>Context maintained]
212
+
213
+ style A fill:#e7f3ff,stroke:#333,color:#000
214
+ style B fill:#cfe2ff,stroke:#333,color:#000
215
+ style C fill:#cfe2ff,stroke:#333,color:#000
216
+ style D fill:#d4edda,stroke:#333,color:#000
217
+ style E fill:#d4edda,stroke:#333,color:#000
218
+ style F fill:#d4edda,stroke:#333,color:#000
219
+ ```
220
+
221
+ **Result:** Zero downtime, continuous productivity, less frustration
200
222
 
201
223
  ### 💰 **The Value Proposition:**
202
224
  - **Setup:** Your existing Claude Pro + GLM Lite (cost-effective add-on)
@@ -291,16 +313,22 @@ Then: 🔴 _"You've reached your usage limit."_
291
313
  - Uses `CLAUDE_CONFIG_DIR` for isolated instances
292
314
  - Create with `ccs auth create <profile>`
293
315
 
294
- ### Shared Data (v3.1)
316
+ ### Shared Data (v3.1+)
317
+
318
+ **CCS items (v4.1)**: Commands and skills symlinked from `~/.ccs/.claude/` to `~/.claude/` - **single source of truth with auto-propagation**.
295
319
 
296
- Commands and skills symlinked from `~/.ccs/shared/` - **no duplication across profiles**.
320
+ **Profile access**: `~/.ccs/shared/` symlinks to `~/.claude/` - **no duplication across profiles**.
297
321
 
298
322
  ```plaintext
299
323
  ~/.ccs/
300
- ├── shared/ # Shared across all profiles
301
- │ ├── agents/
302
- │ ├── commands/
303
- │ └── skills/
324
+ ├── .claude/ # CCS items (ships with package, v4.1)
325
+ │ ├── commands/ccs/ # Delegation commands (/ccs:glm, /ccs:kimi)
326
+ │ ├── skills/ccs-delegation/ # AI decision framework
327
+ │ └── agents/ccs-delegator.md # Proactive delegation agent
328
+ ├── shared/ # Symlinks to ~/.claude/ (for profiles)
329
+ │ ├── agents@ → ~/.claude/agents/
330
+ │ ├── commands@ → ~/.claude/commands/
331
+ │ └── skills@ → ~/.claude/skills/
304
332
  ├── instances/ # Profile-specific data
305
333
  │ └── work/
306
334
  │ ├── agents@ → shared/agents/
@@ -309,15 +337,23 @@ Commands and skills symlinked from `~/.ccs/shared/` - **no duplication across pr
309
337
  │ ├── settings.json # API keys, credentials
310
338
  │ ├── sessions/ # Conversation history
311
339
  │ └── ...
340
+
341
+ ~/.claude/ # User's Claude directory
342
+ ├── commands/ccs@ → ~/.ccs/.claude/commands/ccs/ # Selective symlink
343
+ ├── skills/ccs-delegation@ → ~/.ccs/.claude/skills/ccs-delegation/
344
+ └── agents/ccs-delegator.md@ → ~/.ccs/.claude/agents/ccs-delegator.md
312
345
  ```
313
346
 
347
+ **Symlink Chain**: `work profile → ~/.ccs/shared/ → ~/.claude/ → ~/.ccs/.claude/` (CCS items)
348
+
314
349
  | Type | Files |
315
350
  |:-----|:------|
316
- | **Shared** | `commands/`, `skills/`, `agents/` |
351
+ | **CCS items** | `~/.ccs/.claude/` (ships with package, selective symlinks to `~/.claude/`) |
352
+ | **Shared** | `~/.ccs/shared/` (symlinks to `~/.claude/`) |
317
353
  | **Profile-specific** | `settings.json`, `sessions/`, `todolists/`, `logs/` |
318
354
 
319
355
  > [!NOTE]
320
- > **Windows**: Copies directories if symlinks unavailable (enable Developer Mode for true symlinks)
356
+ > **Windows**: Symlink support requires Developer Mode (v4.2 will add copy fallback)
321
357
 
322
358
  <br>
323
359
 
@@ -358,6 +394,123 @@ ccs --help # Show all commands and options
358
394
 
359
395
  <br>
360
396
 
397
+ ## AI-Powered Delegation
398
+
399
+ > [!TIP]
400
+ > **New in v4.0**: Delegate tasks to cost-optimized models (GLM, Kimi) directly from your main Claude session. Save 81% on simple tasks with real-time visibility.
401
+
402
+ ### What is Delegation?
403
+
404
+ CCS Delegation lets you **send tasks to alternative models** (`glm`, `kimi`) **from your main Claude session** using the `-p` flag or slash commands (`/ccs:glm`, `/ccs:kimi`).
405
+
406
+ **Why use it?**
407
+ - **Token efficiency**: Simple tasks cost 81% less on GLM vs main Claude session
408
+ - **Context preservation**: Main session stays clean, no pollution from mechanical tasks
409
+ - **Real-time visibility**: See tool usage as tasks execute (`[Tool] Write: index.html`)
410
+ - **Multi-turn support**: Resume sessions with `:continue` for iterative work
411
+
412
+ ### Quick Examples
413
+
414
+ **Direct CLI:**
415
+ ```bash
416
+ # Delegate simple task to GLM (cost-optimized)
417
+ ccs glm -p "add tests for UserService"
418
+
419
+ # Delegate long-context task to Kimi
420
+ ccs kimi -p "analyze all files in src/ and document architecture"
421
+
422
+ # Continue previous session
423
+ ccs glm:continue -p "run the tests and fix any failures"
424
+ ```
425
+
426
+ **Via Slash Commands** (inside Claude sessions):
427
+ ```bash
428
+ # In your main Claude session:
429
+ /ccs:glm "refactor auth.js to use async/await"
430
+ /ccs:kimi "find all deprecated API usages across codebase"
431
+ /ccs:glm:continue "also update the README examples"
432
+ ```
433
+
434
+ **Via Natural Language** (Claude auto-delegates):
435
+ ```bash
436
+ # Claude detects delegation patterns and auto-executes:
437
+ "Use ccs glm to add tests for all *.service.js files"
438
+ "Delegate to kimi: analyze project structure"
439
+ ```
440
+
441
+ ### Real-Time Output
442
+
443
+ See exactly what's happening as tasks execute:
444
+
445
+ ```
446
+ $ ccs glm -p "/cook create a landing page"
447
+ [i] Delegating to GLM-4.6...
448
+ [Tool] Write: /home/user/project/index.html
449
+ [Tool] Write: /home/user/project/styles.css
450
+ [Tool] Write: /home/user/project/script.js
451
+ [Tool] Edit: /home/user/project/styles.css
452
+ [i] Execution completed in 45.2s
453
+
454
+ ╔══════════════════════════════════════════════════════╗
455
+ ║ Working Directory: /home/user/project ║
456
+ ║ Model: GLM-4.6 ║
457
+ ║ Duration: 45.2s ║
458
+ ║ Exit Code: 0 ║
459
+ ║ Session ID: 3a4f8c21 ║
460
+ ║ Total Cost: $0.0015 ║
461
+ ║ Turns: 3 ║
462
+ ╚══════════════════════════════════════════════════════╝
463
+ ```
464
+
465
+ ### Advanced Features
466
+
467
+ **Slash Command Support:**
468
+ Delegation preserves custom slash commands in prompts:
469
+ ```bash
470
+ ccs glm -p "/cook create responsive landing page"
471
+ # Executes /cook command in delegated GLM session
472
+ ```
473
+
474
+ **Signal Handling:**
475
+ Ctrl+C or Esc properly kills delegated processes (no orphans):
476
+ ```bash
477
+ # Hit Ctrl+C during delegation
478
+ [!] Parent process terminating, killing delegated session...
479
+ ```
480
+
481
+ **Time-Based Limits:**
482
+ 10-minute default timeout with graceful termination (supports `:continue`):
483
+ ```bash
484
+ ccs glm -p "complex task" # Auto-terminates after 10min if needed
485
+ ccs glm:continue -p "pick up where we left off"
486
+ ```
487
+
488
+ ### Cost Savings Example
489
+
490
+ **Traditional (Main Session):**
491
+ ```
492
+ Context load: 2000 tokens
493
+ Discussion: 1500 tokens
494
+ Code gen: 4500 tokens
495
+ ─────────────────────────
496
+ Total: 8000 tokens → $0.032
497
+ ```
498
+
499
+ **Delegation (GLM):**
500
+ ```
501
+ 3x tasks via GLM: 1500 tokens → $0.0045
502
+ ─────────────────────────────────────────
503
+ Savings: $0.0275 (86% reduction)
504
+ ```
505
+
506
+ ### Documentation
507
+
508
+ - **Workflow Diagrams**: See [docs/ccs-delegation-diagrams.md](docs/ccs-delegation-diagrams.md) for visual architecture
509
+ - **Skill Reference**: `.claude/skills/ccs-delegation/` for AI decision framework
510
+ - **Agent Docs**: `.claude/agents/ccs-delegator.md` for orchestration patterns
511
+
512
+ <br>
513
+
361
514
  ## GLM with Thinking (GLMT)
362
515
 
363
516
  > [!CAUTION]
@@ -568,6 +721,53 @@ cat ~/.ccs/logs/*response-openai.json | jq '.choices[0].message.reasoning_conten
568
721
 
569
722
  <br>
570
723
 
724
+ ## Maintenance
725
+
726
+ ### Health Check
727
+
728
+ Run diagnostics to verify your CCS installation:
729
+
730
+ ```bash
731
+ ccs doctor
732
+ ```
733
+
734
+ **Checks performed**:
735
+ - ✓ Claude CLI availability
736
+ - ✓ Configuration files (config.json, profiles)
737
+ - ✓ CCS symlinks to ~/.claude/
738
+ - ✓ Delegation system
739
+ - ✓ File permissions
740
+
741
+ **Output**:
742
+ ```
743
+ [?] Checking Claude CLI... [OK]
744
+ [?] Checking ~/.ccs/ directory... [OK]
745
+ [?] Checking config.json... [OK]
746
+ [?] Checking CCS symlinks... [OK]
747
+ ...
748
+ Status: Installation healthy
749
+ ```
750
+
751
+ ### Update CCS Items
752
+
753
+ If you modify CCS items or need to re-install symlinks:
754
+
755
+ ```bash
756
+ ccs update
757
+ ```
758
+
759
+ **What it does**:
760
+ - Re-creates selective symlinks from `~/.ccs/.claude/` to `~/.claude/`
761
+ - Backs up existing files before replacing
762
+ - Safe to run multiple times (idempotent)
763
+
764
+ **When to use**:
765
+ - After manual modifications to ~/.claude/
766
+ - If `ccs doctor` reports symlink issues
767
+ - After upgrading CCS to a new version
768
+
769
+ <br>
770
+
571
771
  ## Uninstall
572
772
 
573
773
  <details>
package/VERSION CHANGED
@@ -1 +1 @@
1
- 3.5.0
1
+ 4.1.1
package/bin/ccs.js CHANGED
@@ -73,6 +73,33 @@ function handleVersionCommand() {
73
73
  // Config path
74
74
  const configPath = getConfigPath();
75
75
  console.log(` ${colored('Config:', 'cyan')} ${configPath}`);
76
+
77
+ // Delegation status
78
+ const delegationRulesPath = path.join(os.homedir(), '.ccs', 'delegation-rules.json');
79
+ const delegationEnabled = fs.existsSync(delegationRulesPath);
80
+
81
+ if (delegationEnabled) {
82
+ console.log(` ${colored('Delegation:', 'cyan')} Enabled`);
83
+
84
+ // Check which profiles are delegation-ready
85
+ const readyProfiles = [];
86
+ const { DelegationValidator } = require('./utils/delegation-validator');
87
+
88
+ for (const profile of ['glm', 'kimi']) {
89
+ const validation = DelegationValidator.validate(profile);
90
+ if (validation.valid) {
91
+ readyProfiles.push(profile);
92
+ }
93
+ }
94
+
95
+ if (readyProfiles.length > 0) {
96
+ console.log(` ${colored('Ready:', 'cyan')} ${readyProfiles.join(', ')}`);
97
+ } else {
98
+ console.log(` ${colored('Ready:', 'cyan')} None (configure profiles first)`);
99
+ }
100
+ } else {
101
+ console.log(` ${colored('Delegation:', 'cyan')} Not configured`);
102
+ }
76
103
  console.log('');
77
104
 
78
105
  // Documentation
@@ -121,9 +148,19 @@ function handleHelpCommand() {
121
148
  console.log(` ${colored('ccs personal', 'yellow')} Switch to personal account`);
122
149
  console.log('');
123
150
 
151
+ // Delegation (NEW)
152
+ console.log(colored('Delegation (Token Optimization):', 'cyan'));
153
+ console.log(` ${colored('/ccs:glm "task"', 'yellow')} Delegate to GLM-4.6 within Claude session`);
154
+ console.log(` ${colored('/ccs:kimi "task"', 'yellow')} Delegate to Kimi for long context`);
155
+ console.log(` ${colored('/ccs:create m2', 'yellow')} Create custom delegation command`);
156
+ console.log(' Use delegation to save tokens on simple tasks');
157
+ console.log(' Commands work inside Claude Code sessions only');
158
+ console.log('');
159
+
124
160
  // Diagnostics
125
161
  console.log(colored('Diagnostics:', 'cyan'));
126
162
  console.log(` ${colored('ccs doctor', 'yellow')} Run health check and diagnostics`);
163
+ console.log(` ${colored('ccs update', 'yellow')} Re-install CCS items to ~/.claude/`);
127
164
  console.log('');
128
165
 
129
166
  // Flags
@@ -217,6 +254,22 @@ async function handleDoctorCommand() {
217
254
  process.exit(doctor.results.isHealthy() ? 0 : 1);
218
255
  }
219
256
 
257
+ async function handleUpdateCommand() {
258
+ // First, copy .claude/ directory from package to ~/.ccs/.claude/
259
+ const ClaudeDirInstaller = require('./utils/claude-dir-installer');
260
+ const installer = new ClaudeDirInstaller();
261
+ installer.install();
262
+
263
+ // Then, create symlinks from ~/.ccs/.claude/ to ~/.claude/
264
+ const ClaudeSymlinkManager = require('./utils/claude-symlink-manager');
265
+ const manager = new ClaudeSymlinkManager();
266
+
267
+ console.log('[i] Updating CCS items in ~/.claude/...');
268
+ manager.update();
269
+
270
+ process.exit(0);
271
+ }
272
+
220
273
  // Smart profile detection
221
274
  function detectProfile(args) {
222
275
  if (args.length === 0 || args[0].startsWith('-')) {
@@ -454,6 +507,12 @@ async function main() {
454
507
  return;
455
508
  }
456
509
 
510
+ // Special case: update command (re-install CCS symlinks)
511
+ if (firstArg === 'update' || firstArg === '--update') {
512
+ await handleUpdateCommand();
513
+ return;
514
+ }
515
+
457
516
  // Special case: auth command (multi-account management)
458
517
  if (firstArg === 'auth') {
459
518
  const AuthCommands = require('./auth/auth-commands');
@@ -462,6 +521,14 @@ async function main() {
462
521
  return;
463
522
  }
464
523
 
524
+ // Special case: headless delegation (-p flag)
525
+ if (args.includes('-p') || args.includes('--prompt')) {
526
+ const DelegationHandler = require('./delegation/delegation-handler');
527
+ const handler = new DelegationHandler();
528
+ await handler.route(args);
529
+ return;
530
+ }
531
+
465
532
  // Auto-recovery for missing configuration
466
533
  const recovery = new RecoveryManager();
467
534
  const recovered = recovery.recoverAll();