@kaitranntt/ccs 4.3.1 → 4.3.2

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.
@@ -1,7 +1,6 @@
1
1
  ---
2
2
  description: Continue last GLM delegation session [AUTO ENHANCE]
3
3
  argument-hint: [follow-up instruction]
4
- allowed-tools: Read, Grep, Glob, Bash
5
4
  ---
6
5
 
7
6
  Continue last GLM delegation session for iterative refinement.
@@ -1,7 +1,6 @@
1
1
  ---
2
2
  description: Delegate task to GLM-4.6 (cost-optimized model) [AUTO ENHANCE]
3
3
  argument-hint: [task description]
4
- allowed-tools: Read, Grep, Glob, Bash
5
4
  ---
6
5
 
7
6
  Delegate simple, deterministic tasks to GLM-4.6 for token optimization.
@@ -1,7 +1,6 @@
1
1
  ---
2
2
  description: Continue last Kimi delegation session [AUTO ENHANCE]
3
3
  argument-hint: [follow-up instruction]
4
- allowed-tools: Read, Grep, Glob, Bash
5
4
  ---
6
5
 
7
6
  Continue last Kimi delegation session for multi-turn analysis.
@@ -1,7 +1,6 @@
1
1
  ---
2
2
  description: Delegate task to Kimi (long-context model) [AUTO ENHANCE]
3
3
  argument-hint: [task description]
4
- allowed-tools: Read, Grep, Glob, Bash
5
4
  ---
6
5
 
7
6
  Delegate long-context, multi-file tasks to Kimi for comprehensive analysis.
@@ -0,0 +1,7 @@
1
+ # CCS Auto-Delegation
2
+
3
+ Activate `ccs-delegation` skill for automatic delegation of eligible tasks.
4
+
5
+ **Auto-delegates:** typo fixes, test additions, refactoring, JSDoc, docs updates
6
+ **Override:** Say "don't delegate" to bypass automation
7
+ **Commands:** `/ccs:glm "task"` or `/ccs:kimi "task"` for explicit delegation
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: ccs-delegation
3
- description: Delegate simple tasks to alternative models (GLM, Kimi) via CCS CLI for token optimization
4
- version: 2.2.0
3
+ description: AUTO-ACTIVATE for delegation-eligible tasks. Triggers on patterns like "fix typos", "add tests", "refactor to use", "add JSDoc", "analyze architecture". Also activates when user says "use ccs glm/kimi". Handles task validation, prompt enhancement, and execution via CCS CLI headless mode.
4
+ version: 2.6.0
5
5
  ---
6
6
 
7
7
  # CCS Delegation
@@ -14,6 +14,47 @@ Execute tasks via alternative models using `ccs {profile} -p "task"` equivalent
14
14
 
15
15
  **Profiles:** GLM (cost-optimized), Kimi (long-context)
16
16
 
17
+ ## User Invocation Patterns
18
+
19
+ Users trigger delegation naturally:
20
+ - "use ccs glm [task]" - Delegate to GLM (cost-optimized)
21
+ - "use ccs kimi [task]" - Delegate to Kimi (long-context)
22
+ - "use ccs glm:continue [task]" - Continue GLM session
23
+ - "use ccs kimi:continue [task]" - Continue Kimi session
24
+
25
+ **Examples:**
26
+ - "use ccs glm to fix typos in README.md"
27
+ - "use ccs kimi to analyze the entire architecture"
28
+ - "use ccs glm:continue to add unit tests"
29
+
30
+ ## Agent Response Protocol
31
+
32
+ When user says "use ccs {profile} [task]":
33
+
34
+ 1. **Validate eligibility** against Decision Framework
35
+ - Check: Simple, mechanical, <5 files
36
+ - Check: No design decisions required
37
+ - Check: Clear acceptance criteria exists
38
+
39
+ 2. **Enhance prompt** with context:
40
+ - Add file paths if mentioned
41
+ - Include working directory
42
+ - Specify success criteria
43
+ - Add relevant constraints
44
+
45
+ 3. **Execute via Bash tool**:
46
+ ```bash
47
+ ccs {profile} -p "enhanced prompt"
48
+ ```
49
+
50
+ 4. **Report results** to user:
51
+ - Cost (USD)
52
+ - Duration (seconds)
53
+ - Session ID (for continuation)
54
+ - Exit code/status
55
+
56
+ **If ineligible:** Explain why and handle in main session.
57
+
17
58
  ## Decision Framework
18
59
 
19
60
  **Delegate when:**
@@ -33,22 +74,26 @@ Execute tasks via alternative models using `ccs {profile} -p "task"` equivalent
33
74
  - **GLM**: Simple tasks (<5 files, clear scope, cost-optimized)
34
75
  - **Kimi**: Long-context (multi-file analysis, architecture docs)
35
76
 
77
+ ## Example Delegation Tasks
78
+
79
+ **Good candidates:**
80
+ - "add unit tests for UserService using Jest"
81
+ - "fix typos in README.md"
82
+ - "refactor parseConfig to use destructuring"
83
+ - "add JSDoc comments to auth.js"
84
+
85
+ **Bad candidates (keep in main):**
86
+ - "implement OAuth" (too complex, needs design)
87
+ - "improve performance" (requires profiling)
88
+ - "fix the bug" (needs investigation)
89
+
36
90
  ## Execution
37
91
 
38
- User invocation via slash commands:
39
- ```
40
- /ccs:glm "task"
41
- /ccs:glm:continue "follow-up"
42
- ```
92
+ Slash commands: `/ccs:glm "task"` or `/ccs:glm:continue "follow-up"`
43
93
 
44
- Agent execution via Bash tool:
45
- ```bash
46
- ccs glm -p "task"
47
- ccs glm:continue -p "follow-up"
48
- ```
94
+ Agent via Bash: `ccs glm -p "task"` or `ccs glm:continue -p "follow-up"`
49
95
 
50
96
  ## References
51
97
 
52
- Technical details: `references/headless-workflow.md`
53
- Decision guide: `references/delegation-guidelines.md`
98
+ Template: `CLAUDE.md.template` - Copy to user's CLAUDE.md for auto-delegation config
54
99
  Troubleshooting: `references/troubleshooting.md`
@@ -2,267 +2,205 @@
2
2
 
3
3
  AI-oriented error resolution guide for CCS delegation issues.
4
4
 
5
- ## Error Pattern Matching
5
+ **Structure**: Quick Reference → Error Catalog → Common Resolutions → Diagnostics → Recovery
6
6
 
7
- ### Profile Configuration Errors
7
+ **Cross-references**:
8
+ - Technical details: `headless-workflow.md`
9
+ - Decision framework: `delegation-guidelines.md`
8
10
 
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
- ```
11
+ ## Quick Reference
17
12
 
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
- ```
13
+ **Profile/Config Issues:**
14
+ - E-001: "Profile 'X' not configured" → `ccs doctor`
15
+ - E-002: "Invalid API key" (401) Check `~/.ccs/{profile}.settings.json`
16
+ - E-003: "Settings file not found" → `ccs doctor` to configure
17
+ - E-004: JSON parse error (settings) → Validate with `jq . ~/.ccs/{profile}.settings.json`
26
18
 
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
- ```
19
+ **Delegation Issues:**
20
+ - D-001: "No previous session" → Run `ccs {profile} -p "task"` first
21
+ - D-002: "Missing prompt" → Syntax: `ccs {profile} -p "prompt"`
22
+ - D-003: "No profile specified" → Syntax: `ccs <profile> -p "task"`
23
+ - D-005: File not found → Verify CWD (delegation runs in current directory)
35
24
 
36
- ### Delegation Execution Errors
25
+ **Session Issues:**
26
+ - S-001: Session corrupted → `rm ~/.ccs/delegation-sessions.json`
27
+ - S-002: Session expired → Start new: `ccs {profile} -p "task"`
37
28
 
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
- ```
29
+ **Network Issues:**
30
+ - N-001: Connection timeout → Check internet/endpoint → Retry
31
+ - N-002: Rate limit (429) Wait 60s → Retry
50
32
 
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
- ```
33
+ **CLI Issues:**
34
+ - C-001: Claude CLI not found → Install from code.claude.com
35
+ - C-002: Outdated version Update: `ccs sync` or `ccs update`
61
36
 
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
- ```
37
+ **See Error Catalog below for detailed troubleshooting.**
72
38
 
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
- ```
39
+ ## Error Catalog
82
40
 
83
- ### Session Management Errors
41
+ ### Environment/Config Errors
84
42
 
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
- ```
43
+ | Code | Pattern | Root Cause | Resolution |
44
+ |------|---------|------------|------------|
45
+ | E-001 | Profile 'X' not configured | Missing settings file | `ccs doctor` → configure manually |
46
+ | E-002 | Invalid API key (401) | Token expired/invalid | Verify token in settings.json → regenerate if needed |
47
+ | E-003 | Settings file not found | File doesn't exist | `ccs doctor` → shows missing profiles |
48
+ | E-004 | JSON parse error (settings) | Malformed JSON | Validate: `jq . ~/.ccs/{profile}.settings.json` |
94
49
 
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
50
+ **Examples:**
51
+ ```bash
52
+ [X] ccs glm -p "task" # E-001: Profile not configured
53
+ [OK] ccs doctor # Shows: glm.settings.json missing
102
54
  ```
103
55
 
104
- ### Network & API Errors
56
+ ### Delegation Execution Errors
105
57
 
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
- ```
58
+ | Code | Pattern | Root Cause | Resolution |
59
+ |------|---------|------------|------------|
60
+ | D-001 | No previous session | Using :continue without init | Run `ccs {profile} -p "init"` first |
61
+ | D-002 | Missing prompt after -p | No argument provided | Quote prompt: `ccs {profile} -p "text"` |
62
+ | D-003 | No profile specified | Missing profile name | Syntax: `ccs <profile> -p "task"` |
63
+ | D-004 | Invalid profile name | Profile doesn't exist | Check: `ccs doctor` for available profiles |
64
+ | D-005 | File not found | CWD mismatch | Verify: delegation runs in current directory |
115
65
 
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
66
+ **Examples:**
67
+ ```bash
68
+ [X] ccs glm:continue -p "task" # D-001: No session
69
+ [OK] ccs glm -p "task" # Creates session
70
+ [OK] ccs glm:continue -p "more" # Uses session
123
71
  ```
124
72
 
125
- ### File Operation Errors
73
+ ### Session Management Errors
126
74
 
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
- ```
75
+ | Code | Pattern | Root Cause | Resolution |
76
+ |------|---------|------------|------------|
77
+ | S-001 | Session file corrupted | Malformed JSON | `rm ~/.ccs/delegation-sessions.json` → fresh start |
78
+ | S-002 | Session expired | >30 days old | Start new: `ccs {profile} -p "task"` |
79
+ | S-003 | Session ID mismatch | ID not found | Check: `jq '.{profile}' ~/.ccs/delegation-sessions.json` |
80
+ | S-004 | Cost aggregation error | Calculation failure | Reset session or ignore (doesn't affect execution) |
138
81
 
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
- ```
82
+ ### Network/API Errors
147
83
 
148
- ## Diagnostic Commands
84
+ | Code | Pattern | Root Cause | Resolution |
85
+ |------|---------|------------|------------|
86
+ | N-001 | Connection timeout | Network/API unreachable | Check: internet, endpoint, firewall → Retry |
87
+ | N-002 | Rate limiting (429) | Too many requests | Wait 60s → Retry |
88
+ | N-003 | API endpoint unreachable | Wrong URL in settings | Verify ANTHROPIC_BASE_URL in settings.json |
89
+ | N-004 | SSL/TLS error | Certificate issue | Check system certs, firewall SSL inspection |
149
90
 
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
- ```
91
+ ### File Operation Errors
156
92
 
157
- **Session inspection:**
158
- ```bash
159
- cat ~/.ccs/delegation-sessions.json # View sessions
160
- jq '.glm' ~/.ccs/delegation-sessions.json # Check specific profile
161
- ```
93
+ | Code | Pattern | Root Cause | Resolution |
94
+ |------|---------|------------|------------|
95
+ | F-001 | File not found during delegation | Path doesn't exist in CWD | Verify: `ls <file>` from current directory |
96
+ | F-002 | Permission denied (write) | Insufficient permissions | Check: `ls -la` directory permissions |
97
+ | F-003 | Relative path failure | Path resolution issue | Use absolute paths in prompts if needed |
98
+ | F-004 | Workspace confusion (monorepo) | Wrong package targeted | Specify workspace: "in packages/{name}, {task}" |
162
99
 
163
- **Delegation test:**
100
+ **Example:**
164
101
  ```bash
165
- ccs glm -p "create test.txt file with 'hello'" # Simple test
166
- cat test.txt # Verify result
102
+ # Delegation runs in CWD where command executed
103
+ ccs glm -p "refactor src/auth.js"
104
+ # Verify: ls src/auth.js # Must exist in current directory
167
105
  ```
168
106
 
169
- **Debug mode:**
107
+ ### Claude CLI Compatibility Errors
108
+
109
+ | Code | Pattern | Root Cause | Resolution |
110
+ |------|---------|------------|------------|
111
+ | C-001 | Claude CLI not found | Not installed | Install from code.claude.com |
112
+ | C-002 | Outdated CLI version | Old version | Update: `ccs sync` or `ccs update` |
113
+ | C-003 | stream-json not supported | Version < required | Upgrade CLI: check `claude --version` |
114
+ | C-004 | Permission mode unsupported | Old CLI version | Upgrade to support --permission-mode |
115
+
116
+ **Check version:**
170
117
  ```bash
171
- export CCS_DEBUG=1
172
- ccs glm -p "task" 2>&1 | tee debug.log # Capture full output
118
+ claude --version # Need recent version with --output-format stream-json
173
119
  ```
174
120
 
175
- ## Decision Tree
121
+ ### Timeout/Resource Errors
176
122
 
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
- ```
123
+ | Code | Pattern | Root Cause | Resolution |
124
+ |------|---------|------------|------------|
125
+ | T-001 | Execution timeout (10 min) | Task too complex/slow | Simplify task or split into smaller tasks |
126
+ | T-002 | Memory limit exceeded | Large file processing | Reduce scope, process in batches |
127
+ | T-003 | Process killed (SIGTERM) | External termination | Check system resources, retry |
201
128
 
202
- ## Common Patterns to Avoid
129
+ ### Output Format Errors
203
130
 
204
- **Anti-pattern:** Delegating without profile validation
205
- ```
206
- [X] Assume profile exists
207
- [OK] Run ccs doctor first to verify
208
- ```
131
+ | Code | Pattern | Root Cause | Resolution |
132
+ |------|---------|------------|------------|
133
+ | O-001 | JSON parse error (exit 1) | Non-stream-JSON output | Verify: `claude -p "test" --output-format stream-json` |
134
+ | O-002 | Malformed JSONL | Corrupted stream | Enable debug: `export CCS_DEBUG=1` → check logs |
135
+ | O-003 | Missing session_id | Incomplete response | Check CLI version, retry delegation |
136
+ | O-004 | Type mismatch in response | Unexpected data type | Enable debug mode, report issue |
209
137
 
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
- ```
138
+ ## Common Resolution Patterns
215
139
 
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"
140
+ **Profile Validation:**
141
+ ```bash
142
+ ccs doctor # Check all profiles
143
+ cat ~/.ccs/{profile}.settings.json # Verify settings
144
+ ccs {profile} "test" 2>&1 # Test execution
220
145
  ```
221
146
 
222
- **Anti-pattern:** Vague prompts
147
+ **Session Management:**
148
+ ```bash
149
+ jq . ~/.ccs/delegation-sessions.json # View all sessions
150
+ jq '.{profile}' ~/.ccs/delegation-sessions.json # Check specific profile
151
+ rm ~/.ccs/delegation-sessions.json # Reset (loses all sessions)
223
152
  ```
224
- [X] ccs glm -p "fix the bug" # No context
225
- [OK] ccs glm -p "fix typo in src/auth.js line 42"
153
+
154
+ **Debug Mode:**
155
+ ```bash
156
+ export CCS_DEBUG=1
157
+ ccs {profile} -p "task" 2>&1 | tee debug.log # Capture full output
226
158
  ```
227
159
 
228
- ## Recovery Procedures
160
+ ## Diagnostic Toolkit
229
161
 
230
- **Reset session state:**
231
- ```bash
232
- rm ~/.ccs/delegation-sessions.json
233
- # Fresh start, all sessions lost
162
+ **Profile diagnostics:**
163
+ ````bash
164
+ ccs doctor # All profiles status
165
+ ccs --version # CCS version + delegation status
166
+ claude --version # CLI version (check stream-json support)
234
167
  ```
235
168
 
236
- **Reconfigure profile:**
169
+ **Session inspection:**
237
170
  ```bash
238
- ccs doctor # Shows issues
239
- # Edit ~/.ccs/{profile}.settings.json manually
240
- # Verify: ccs {profile} "test"
171
+ jq . ~/.ccs/delegation-sessions.json # All sessions
172
+ jq '.glm.sessionId' ~/.ccs/delegation-sessions.json # GLM session ID
173
+ jq '.glm.totalCost' ~/.ccs/delegation-sessions.json # Total cost
241
174
  ```
242
175
 
243
176
  **Test delegation flow:**
244
177
  ```bash
245
178
  # 1. Simple task
246
- ccs glm -p "create test.txt with content 'hello'"
179
+ ccs glm -p "create test.txt with 'hello'"
247
180
 
248
- # 2. Verify session created
249
- cat ~/.ccs/delegation-sessions.json | jq '.glm.sessionId'
181
+ # 2. Verify session
182
+ jq '.glm.sessionId' ~/.ccs/delegation-sessions.json
250
183
 
251
- # 3. Test continue
184
+ # 3. Continue
252
185
  ccs glm:continue -p "append 'world' to test.txt"
253
186
 
254
- # 4. Verify aggregation
255
- cat ~/.ccs/delegation-sessions.json | jq '.glm.turns'
187
+ # 4. Check aggregation
188
+ jq '.glm.turns' ~/.ccs/delegation-sessions.json
256
189
  ```
257
190
 
258
- ## Emergency Fallback
191
+ ## Emergency Recovery
259
192
 
260
- If delegation completely broken:
193
+ **Reset session state:**
261
194
  ```bash
262
- # Use Claude CLI directly
263
- claude -p "task" --settings ~/.ccs/glm.settings.json
195
+ rm ~/.ccs/delegation-sessions.json # Fresh start (loses all sessions)
196
+ ```
264
197
 
265
- # Bypass delegation (no -p flag)
266
- ccs glm
267
- # Then work interactively
198
+ **Bypass delegation (use CLI directly):**
199
+ ```bash
200
+ claude -p "task" --settings ~/.ccs/{profile}.settings.json
201
+ ```
202
+
203
+ **Interactive mode (no -p flag):**
204
+ ```bash
205
+ ccs {profile} # Opens interactive session
268
206
  ```
package/VERSION CHANGED
@@ -1 +1 @@
1
- 4.3.1
1
+ 4.3.2
package/lib/ccs CHANGED
@@ -2,7 +2,7 @@
2
2
  set -euo pipefail
3
3
 
4
4
  # Version (updated by scripts/bump-version.sh)
5
- CCS_VERSION="4.3.1"
5
+ CCS_VERSION="4.3.2"
6
6
  SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7
7
  readonly CONFIG_FILE="${CCS_CONFIG:-$HOME/.ccs/config.json}"
8
8
  readonly PROFILES_JSON="$HOME/.ccs/profiles.json"
package/lib/ccs.ps1 CHANGED
@@ -12,7 +12,7 @@ param(
12
12
  $ErrorActionPreference = "Stop"
13
13
 
14
14
  # Version (updated by scripts/bump-version.sh)
15
- $CcsVersion = "4.3.1"
15
+ $CcsVersion = "4.3.2"
16
16
  $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
17
17
  $ConfigFile = if ($env:CCS_CONFIG) { $env:CCS_CONFIG } else { "$env:USERPROFILE\.ccs\config.json" }
18
18
  $ProfilesJson = "$env:USERPROFILE\.ccs\profiles.json"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaitranntt/ccs",
3
- "version": "4.3.1",
3
+ "version": "4.3.2",
4
4
  "description": "Claude Code Switch - Instant profile switching between Claude Sonnet 4.5 and GLM 4.6",
5
5
  "keywords": [
6
6
  "cli",
@@ -1,117 +0,0 @@
1
- ---
2
- name: ccs-delegator
3
- description: Execute delegated tasks in isolated GLM/Kimi sessions via headless mode. Use when parent agent invokes `/ccs:glm` or `/ccs:kimi` slash commands to delegate simple tasks to cost-optimized models. This agent handles the execution orchestration, result collection, and reporting back to the main session. Examples:\n\n<example>\nContext: Main agent receives `/ccs:glm "refactor the parseConfig function"` command.\nparent_agent: "Delegating refactoring task to GLM-4.6 via ccs-delegator"\nassistant: "I'll execute this task in an isolated GLM session using headless mode"\n<commentary>\nThe parent agent has enhanced the prompt and determined the working directory. This agent now executes via `ccs glm -p` using the glm profile, captures output, and reports results.\n</commentary>\n</example>\n\n<example>\nContext: Main agent delegates long-context analysis to Kimi.\nparent_agent: "Delegating codebase analysis to Kimi via ccs-delegator"\nassistant: "I'll execute the analysis in a Kimi session and report findings"\n<commentary>\nThis agent handles execution in the kimi profile, which supports long-context tasks, and formats the comprehensive results for the main session.\n</commentary>\n</example>\n\n<example>\nContext: Delegation execution fails due to unconfigured profile.\nparent_agent: "Attempting delegation to GLM"\nassistant: "Execution failed: GLM profile not configured. Reporting error to main agent."\n<commentary>\nWhen delegation fails, this agent reports the error gracefully without blocking the main session. The main agent can then choose to retry or execute directly.\n</commentary>\n</example>
4
- allowed-tools: Bash, Read, Grep, Glob
5
- default-model: sonnet
6
- ---
7
-
8
- You are a Delegation Executor, a specialized subagent that orchestrates task execution in isolated Claude sessions using alternative models (GLM-4.6, Kimi) via headless mode.
9
-
10
- **CRITICAL RULES:**
11
-
12
- 1. **YOU MUST DELEGATE** - Your ONLY job is to execute `ccs` commands via Bash. You MUST NOT edit or write files yourself.
13
- 2. **ACTIVATE SKILL FIRST** - Always activate the `ccs-delegation` skill before any delegation.
14
- 3. **READ-ONLY ANALYSIS** - You can read files to understand context, but ALL actual work must be done via `ccs` delegation.
15
-
16
- ## Your Mission
17
-
18
- Execute tasks by delegating to alternative models via `ccs` CLI, then report results back to the main session.
19
-
20
- ## Workflow (MANDATORY)
21
-
22
- 1. **Activate Skill** - Load `ccs-delegation` skill for delegation guidelines
23
- 2. **Analyze Task** - Read files if needed to understand context
24
- 3. **Select Profile** - Choose GLM (simple/cost-optimized) or Kimi (long-context)
25
- 4. **Delegate** - Execute via `ccs {profile} -p "enhanced task description"`
26
- 5. **Report Results** - Parse output and report to main session
27
-
28
- ## Delegation Methodology
29
-
30
- When delegating tasks, you will:
31
-
32
- 1. **Task Analysis**
33
- - Read `ccs-delegation` skill for decision framework
34
- - Determine if task is delegation-appropriate
35
- - Estimate time needed: Quick (<2 min) / Medium (<10 min) / Complex (>10 min)
36
- - Identify scope: Single file vs multiple files
37
-
38
- 2. **Profile Selection**
39
- - GLM: Simple, cost-optimized (refactoring, tests, typos)
40
- - Kimi: Long-context (multi-file analysis, architecture docs)
41
-
42
- 3. **Session Strategy**
43
- - **New session** (`ccs {profile} -p "task"`): Use when:
44
- - Starting a new, unrelated task
45
- - Previous session >30 days old
46
- - Different files/scope than last delegation
47
-
48
- - **Continue session** (`ccs {profile}:continue -p "task"`): Use when:
49
- - Completing work from previous delegation
50
- - Fixing issues from last attempt
51
- - Adding to previously created files
52
- - Iterative refinement of same task
53
- - **CRITICAL**: Check delegation output for session ID before continuing
54
-
55
- 4. **Execution**
56
- - **New delegation**: `ccs {profile} -p "enhanced task description"`
57
- - **Continue delegation**: `ccs {profile}:continue -p "enhanced follow-up"`
58
- - **Note**: If task contains a slash command (/cook, /plan, /commit), keep it at the start when enhancing
59
- - Parse output for results
60
- - Report success/failure with file changes
61
-
62
- 5. **Batch Operations**
63
- - For multiple similar tasks, delegate each separately
64
- - Aggregate results
65
- - Report combined outcome
66
-
67
- ## Tools and Techniques
68
-
69
- You will utilize:
70
- - **CCS CLI**: `ccs glm -p`, `ccs kimi -p` for delegation
71
- - **Bash Tool**: Execute CCS commands
72
- - **Read Tool**: Understand project context when needed
73
- - **ccs-delegation Skill**: Core knowledge base for delegation decisions
74
-
75
- ## Integration Components
76
-
77
- CCS delegation uses these internal components:
78
- - **DelegationHandler**: Routes `-p` flag to HeadlessExecutor
79
- - **HeadlessExecutor**: Spawns `claude -p` with enhanced flags (--output-format stream-json, --permission-mode acceptEdits)
80
- - **SessionManager**: Persists sessions to `~/.ccs/delegation-sessions.json`
81
- - **ResultFormatter**: Displays ASCII box output with session ID, cost, turns
82
-
83
- Results include metadata parsed from stream-json output with real-time tool visibility.
84
-
85
- ## Execution Pattern
86
-
87
- **Standard delegation** (new task):
88
- ```bash
89
- ccs glm -p "Refactor auth.js to use async/await"
90
- ```
91
-
92
- **Session continuation** (same task, iterative):
93
- ```bash
94
- # First delegation creates landing page but misses JavaScript
95
- ccs glm -p "Create landing page in HTML/CSS"
96
-
97
- # Output shows: Files Created: index.html, styles.css
98
- # You notice JavaScript file is missing
99
-
100
- # Continue the SAME session to add missing JavaScript
101
- ccs glm:continue -p "Create the missing JavaScript file script.js"
102
- ```
103
-
104
- **Batch delegation** (multiple unrelated tasks):
105
- ```bash
106
- # Each is a separate new session (different files)
107
- ccs glm -p "Add tests for UserService"
108
- ccs glm -p "Add tests for AuthService"
109
- ccs glm -p "Add tests for OrderService"
110
- ```
111
-
112
- ## Remember
113
-
114
- - **NEVER edit/write files yourself** - You lack Edit/Write tools for a reason
115
- - **ALWAYS delegate via `ccs`** - That's your only purpose
116
- - **ALWAYS activate `ccs-delegation` skill first** - It contains critical decision framework
117
- - Parse the delegation output and report results concisely to the main session
@@ -1,24 +0,0 @@
1
- # CCS Delegation References
2
-
3
- ## Reading Order
4
-
5
- 1. **Start here**: `../SKILL.md` - Entry point, quick start
6
- 2. `headless-workflow.md` - Technical details (command syntax, features, config)
7
- 3. **As needed**:
8
- - `delegation-guidelines.md` - Decision framework
9
- - `troubleshooting.md` - Error recovery
10
-
11
- ## File Hierarchy
12
-
13
- **PRIMARY (Authoritative Source)**
14
- - `headless-workflow.md` - Technical implementation details
15
-
16
- **SUPPORTING (Reference Primary)**
17
- - `delegation-guidelines.md` - When to delegate
18
- - `troubleshooting.md` - Error patterns
19
-
20
- ## Quick Navigation
21
-
22
- **Need command syntax?** → `headless-workflow.md`
23
- **Need to decide if delegate?** → `delegation-guidelines.md`
24
- **Got an error?** → `troubleshooting.md`
@@ -1,99 +0,0 @@
1
- # Delegation Guidelines
2
-
3
- AI decision framework for when to delegate tasks vs keep in main session.
4
-
5
- ## Task Classification Rules
6
-
7
- **Delegate if ALL criteria match:**
8
- - Task scope: Single concern, < 5 files
9
- - Complexity: Mechanical transformation, established pattern
10
- - Ambiguity: Zero decisions required, clear acceptance criteria
11
- - Context: Existing patterns to follow, no architecture changes
12
-
13
- **Keep in main if ANY criteria match:**
14
- - Requires design decisions or tradeoff analysis
15
- - Security-critical (auth, encryption, permissions)
16
- - Performance-sensitive requiring profiling/measurement
17
- - Breaking changes or API migrations
18
- - User discussion/clarification needed
19
- - Coordinated changes across multiple subsystems
20
-
21
- ## Delegation Pattern Matching
22
-
23
- **High-confidence delegation patterns:**
24
- ```
25
- Task patterns to delegate:
26
- - refactor .* to use (async/await|destructuring|arrow functions)
27
- - add (unit|integration) tests for .*
28
- - fix (typos?|formatting|linting errors?) in .*
29
- - add JSDoc comments to .*
30
- - extract .* into (function|method|util) .*
31
- - rename (variable|function) .* to .*
32
- - add DELETE endpoint for .*
33
- - update README to document .*
34
- ```
35
-
36
- **Anti-patterns (never delegate):**
37
- ```
38
- Task patterns to avoid:
39
- - implement .* (too vague, needs design)
40
- - improve .* (subjective, needs discussion)
41
- - fix bug .* (requires investigation)
42
- - optimize .* (requires profiling)
43
- - migrate .* to .* (breaking change)
44
- - design .* (architecture decision)
45
- - whatever .* you think (requires judgment)
46
- ```
47
-
48
- ## Prompt Quality Criteria
49
-
50
- **Well-formed delegation prompt:**
51
- - Specifies exact file paths: `in src/auth.js, ...`
52
- - Defines success criteria: `covering positive, zero, negative cases`
53
- - Single atomic task: One verb, one target
54
- - Uses imperative mood: "add tests" not "adding tests"
55
-
56
- **Malformed delegation prompt:**
57
- - Multiple tasks: "add tests, update docs, fix linting"
58
- - Vague scope: "improve the code"
59
- - Requires decisions: "use whatever library you want"
60
- - No file context: "fix the bug" (which file?)
61
-
62
- ## Token Efficiency Model
63
-
64
- **Delegation cost model:**
65
- - Main session overhead: ~2000 tokens (context, discussion)
66
- - Delegation overhead: ~500 tokens (focused execution)
67
- - Net savings: ~1500 tokens per delegated task
68
-
69
- **When to batch delegate:**
70
- - User requests N similar tasks (e.g., "add tests for all services")
71
- - Each task follows identical pattern
72
- - Tasks are independent (no coordination needed)
73
-
74
- **Execution pattern:**
75
- ```
76
- for each service in [UserService, AuthService, OrderService]:
77
- ccs glm -p "add unit tests for {service} using Jest"
78
- ```
79
-
80
- ## Monorepo Handling
81
-
82
- **Workspace specification required:**
83
- - Pattern: `in packages/{workspace}, {task}`
84
- - Example: `in packages/api, add validation middleware`
85
- - Without workspace: Task may target wrong package
86
-
87
- ## Scope Limits
88
-
89
- **Absolute limits (reject delegation):**
90
- - Estimated time > 30 minutes
91
- - File count > 5 files
92
- - Requires external research
93
- - Breaking changes to public APIs
94
- - User explicitly requests discussion
95
-
96
- **Examples of over-scoped tasks:**
97
- - "Migrate from SQLite to PostgreSQL" (breaking change)
98
- - "Implement OAuth2 authentication" (too complex)
99
- - "Analyze entire codebase for security issues" (research task)
@@ -1,174 +0,0 @@
1
- # Headless Workflow
2
-
3
- **Last Updated**: 2025-11-15
4
-
5
- CCS delegation uses Claude Code headless mode with enhanced features for token optimization.
6
-
7
- ## Core Concept
8
-
9
- CCS delegation executes tasks via alternative models using enhanced Claude Code headless mode with stream-JSON output, session management, and cost tracking.
10
-
11
- **Actual Command:**
12
- ```bash
13
- ccs {profile} -p "prompt"
14
- ```
15
-
16
- Internally executes:
17
- ```bash
18
- claude -p "prompt" --settings ~/.ccs/{profile}.settings.json --output-format stream-json --permission-mode acceptEdits
19
- ```
20
-
21
- **Docs:** https://code.claude.com/docs/en/headless.md
22
-
23
- ## How It Works
24
-
25
- **Workflow:**
26
- 1. User: `/ccs:glm "task"` in Claude Code session
27
- 2. CCS detects `-p` flag and routes to HeadlessExecutor
28
- 3. HeadlessExecutor spawns: `claude -p "task" --settings ~/.ccs/glm.settings.json --output-format stream-json --permission-mode acceptEdits`
29
- 4. Claude Code runs headless with GLM profile + enhanced flags
30
- 5. Returns stream-JSON with session_id, cost, turns
31
- 6. Real-time tool use visibility in TTY
32
- 7. ResultFormatter displays formatted results with metadata
33
-
34
- **Enhanced Features:**
35
- - Stream-JSON output parsing (`--output-format stream-json`)
36
- - Real-time tool use visibility (e.g., `[Tool Use: Bash]`)
37
- - Session persistence (`~/.ccs/delegation-sessions.json`)
38
- - Cost tracking (displays USD cost per execution)
39
- - Time-based limits (10 min default timeout with graceful termination)
40
- - Multi-turn session management (resume via session_id)
41
- - Formatted ASCII box output
42
-
43
- ## Profile Settings
44
-
45
- **Location:** `~/.ccs/{profile}.settings.json`
46
-
47
- **Examples:**
48
- - GLM: `~/.ccs/glm.settings.json`
49
- - Kimi: `~/.ccs/kimi.settings.json`
50
-
51
- **Example content:**
52
- ```json
53
- {
54
- "env": {
55
- "ANTHROPIC_BASE_URL": "https://api.z.ai/api/anthropic",
56
- "ANTHROPIC_AUTH_TOKEN": "your-glm-api-key",
57
- "ANTHROPIC_MODEL": "glm-4.6"
58
- }
59
- }
60
- ```
61
-
62
- ## Output Format
63
-
64
- **Stream-JSON Mode** (automatically enabled):
65
- Each message is a separate JSON object (jsonl format):
66
- ```json
67
- {"type":"init","session_id":"abc123def456"}
68
- {"type":"user","message":{"role":"user","content":"Task description"}}
69
- {"type":"assistant","message":{"role":"assistant","content":[{"type":"tool_use","name":"Bash"}]}}
70
- {"type":"result","subtype":"success","total_cost_usd":0.0025,"num_turns":3,"session_id":"abc123def456","result":"Task completed"}
71
- ```
72
-
73
- **Real-time Progress** (TTY only):
74
- ```
75
- [i] Delegating to GLM-4.6...
76
- [Tool Use: Write]
77
- [Tool Use: Write]
78
- [Tool Use: Bash]
79
- [i] Execution completed in 1.5s
80
- ```
81
-
82
- **Formatted Output** (displayed to user):
83
- ```
84
- ╔══════════════════════════════════════════════════════╗
85
- ║ Working Directory: /path/to/project ║
86
- ║ Model: GLM-4.6 ║
87
- ║ Duration: 1.5s ║
88
- ║ Exit Code: 0 ║
89
- ║ Session ID: abc123de ║
90
- ║ Cost: $0.0025 ║
91
- ║ Turns: 3 ║
92
- ╚══════════════════════════════════════════════════════╝
93
- ```
94
-
95
- **Extracted Fields:**
96
- - `session_id` - For multi-turn (--resume)
97
- - `total_cost_usd` - Cost per execution
98
- - `num_turns` - Turn count
99
- - `is_error` - Error flag
100
- - `result` - Task output
101
-
102
- **Exit codes:** 0 = success, non-zero = error
103
-
104
- ## Multi-Turn Sessions
105
-
106
- **Start session:**
107
- ```bash
108
- ccs glm -p "implement feature"
109
- ```
110
-
111
- **Continue session:**
112
- ```bash
113
- ccs glm:continue -p "add tests"
114
- ccs glm:continue -p "run tests"
115
- ```
116
-
117
- Via slash commands:
118
- ```
119
- /ccs:glm "implement feature"
120
- /ccs:glm:continue "add tests"
121
- ```
122
-
123
- **Session Storage:** `~/.ccs/delegation-sessions.json`
124
-
125
- **Metadata:**
126
- - Session ID
127
- - Total cost (aggregated across turns)
128
- - Turn count
129
- - Last turn timestamp
130
- - Working directory
131
-
132
- **Expiration:** ~30 days, auto-cleanup
133
-
134
- ## Usage Patterns
135
-
136
- **Single execution:**
137
- ```bash
138
- ccs glm -p "task description"
139
- ```
140
-
141
- **With options:**
142
- ```bash
143
- ccs glm -p "task" --permission-mode plan
144
- ```
145
-
146
- **Continue session:**
147
- ```bash
148
- ccs glm:continue -p "follow-up task"
149
- ```
150
-
151
- All standard Claude Code headless flags are supported. See: https://code.claude.com/docs/en/headless.md
152
-
153
- ## Error Handling
154
-
155
- **Common errors:**
156
- - `Settings file not found` - Profile not configured (`ccs doctor` to diagnose)
157
- - `Claude CLI not found` - Install Claude Code
158
- - `Invalid API key` - Check profile settings in `~/.ccs/{profile}.settings.json`
159
-
160
- **Diagnostics:**
161
- ```bash
162
- ccs doctor # Check configuration
163
- ccs --version # Show delegation status
164
- ```
165
-
166
- ---
167
-
168
- ## Related Documentation
169
-
170
- **Entry Point**: `../SKILL.md` - Quick start and decision framework
171
- **Decision Guide**: `delegation-guidelines.md` - When to delegate
172
- **Error Recovery**: `troubleshooting.md` - Common issues
173
-
174
- **Official Docs**: https://code.claude.com/docs/en/headless.md