@kaitranntt/ccs 4.3.1 → 4.3.3

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,15 @@
1
+ ---
2
+ description: Continue last CCS delegation session [AUTO ENHANCE]
3
+ argument-hint: [follow-up instruction]
4
+ ---
5
+
6
+ Activate `ccs-delegation` skill. The skill contains all execution logic.
7
+
8
+ Task: Detect last-used profile from `~/.ccs/delegation-sessions.json`, parse `$ARGUMENTS`, enhance with previous context, execute continuation via CCS CLI.
9
+
10
+ **Examples:**
11
+ ```
12
+ /ccs:continue "also update the examples section" # Use last profile
13
+ /ccs:continue --glm "add unit tests" # Switch profiles
14
+ /ccs:continue "/commit with message" # Nested slash command
15
+ ```
@@ -0,0 +1,17 @@
1
+ ---
2
+ description: Delegate task with intelligent profile selection [AUTO ENHANCE]
3
+ argument-hint: [task description]
4
+ ---
5
+
6
+ Activate `ccs-delegation` skill. The skill contains all execution logic.
7
+
8
+ Task: Parse `$ARGUMENTS`, select optimal profile from `~/.ccs/config.json`, enhance prompt, execute delegation via CCS CLI.
9
+
10
+ **Examples:**
11
+ ```
12
+ /ccs "refactor auth.js to use async/await" # Simple task
13
+ /ccs "analyze entire architecture" # Long-context task
14
+ /ccs "think about caching strategy" # Reasoning task
15
+ /ccs --glm "add tests for UserService" # Force specific profile
16
+ /ccs "/cook create landing page" # Nested slash command
17
+ ```
@@ -0,0 +1,17 @@
1
+ # CCS Auto-Delegation
2
+
3
+ Activate `ccs-delegation` skill for automatic delegation of eligible tasks.
4
+
5
+ **Commands:**
6
+ - `/ccs "task"` - Auto-select best profile (glm/kimi/custom)
7
+ - `/ccs:continue "follow-up"` - Continue last session
8
+ - `/ccs --glm "task"` - Force specific profile
9
+
10
+ **Auto-delegates:** typo fixes, test additions, refactoring, JSDoc, docs updates
11
+ **Override:** Say "don't delegate" to bypass automation
12
+
13
+ **Examples:**
14
+ - "use ccs to fix typos in README" → Auto-selects glm
15
+ - "use ccs to analyze architecture" → Auto-selects kimi
16
+ - "use ccs --glm to add tests" → Forces glm
17
+ - "use ccs:continue to commit" → Continues last session
@@ -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 CCS CLI delegation for deterministic tasks. Parses user input, auto-selects optimal profile (glm/kimi/custom) from ~/.ccs/config.json, enhances prompts with context, executes via `ccs {profile} -p "task"` or `ccs {profile}:continue`, and reports results. Trigger: "use ccs [task]" patterns, typo/test/refactor keywords. Excludes: complex architecture, security-critical code, performance optimization, breaking changes.
4
+ version: 3.0.0
5
5
  ---
6
6
 
7
7
  # CCS Delegation
@@ -10,9 +10,94 @@ Delegate deterministic tasks to cost-optimized models via CCS CLI.
10
10
 
11
11
  ## Core Concept
12
12
 
13
- Execute tasks via alternative models using `ccs {profile} -p "task"` equivalent to `claude --settings ~/.ccs/{profile}.settings -p "task"`
13
+ Execute tasks via alternative models using:
14
+ - **Initial delegation**: `ccs {profile} -p "task"`
15
+ - **Session continuation**: `ccs {profile}:continue -p "follow-up"`
14
16
 
15
- **Profiles:** GLM (cost-optimized), Kimi (long-context)
17
+ **Profile Selection:**
18
+ - Auto-select from `~/.ccs/config.json` via task analysis
19
+ - Profiles: glm (cost-optimized), kimi (long-context/reasoning), custom profiles
20
+ - Override: `--{profile}` flag forces specific profile
21
+
22
+ ## User Invocation Patterns
23
+
24
+ Users trigger delegation naturally:
25
+ - "use ccs [task]" - Auto-select best profile
26
+ - "use ccs --glm [task]" - Force GLM profile
27
+ - "use ccs --kimi [task]" - Force Kimi profile
28
+ - "use ccs:continue [task]" - Continue last session
29
+
30
+ **Examples:**
31
+ - "use ccs to fix typos in README.md"
32
+ - "use ccs to analyze the entire architecture"
33
+ - "use ccs --glm to add unit tests"
34
+ - "use ccs:continue to commit the changes"
35
+
36
+ ## Agent Response Protocol
37
+
38
+ **For `/ccs [task]`:**
39
+
40
+ 1. **Parse override flag**
41
+ - Scan task for pattern: `--(\w+)`
42
+ - If match: `profile = match[1]`, remove flag from task, skip to step 5
43
+ - If no match: continue to step 2
44
+
45
+ 2. **Discover profiles**
46
+ - Read `~/.ccs/config.json` using Read tool
47
+ - Extract `Object.keys(config.profiles)` → `availableProfiles[]`
48
+ - If file missing → Error: "CCS not configured. Run: ccs doctor"
49
+ - If empty → Error: "No profiles in config.json"
50
+
51
+ 3. **Analyze task requirements**
52
+ - Scan task for keywords:
53
+ - `/(think|analyze|reason|debug|investigate|evaluate)/i` → `needsReasoning = true`
54
+ - `/(architecture|entire|all files|codebase|analyze all)/i` → `needsLongContext = true`
55
+ - `/(typo|test|refactor|update|fix)/i` → `preferCostOptimized = true`
56
+
57
+ 4. **Select profile**
58
+ - For each profile in `availableProfiles`: classify by name pattern (see Profile Characteristic Inference table)
59
+ - If `needsReasoning`: filter profiles where `reasoning=true` → prefer kimi
60
+ - Else if `needsLongContext`: filter profiles where `context=long` → prefer kimi
61
+ - Else: filter profiles where `cost=low` → prefer glm
62
+ - `selectedProfile = filteredProfiles[0]`
63
+ - If `filteredProfiles.length === 0`: fallback to `glm` if exists, else first available
64
+ - If no profiles: Error
65
+
66
+ 5. **Enhance prompt**
67
+ - If task mentions files: gather context using Read tool
68
+ - Add: file paths, current implementation, expected behavior, success criteria
69
+ - Preserve slash commands at task start (e.g., `/cook`, `/commit`)
70
+
71
+ 6. **Execute delegation**
72
+ - Run: `ccs {selectedProfile} -p "$enhancedPrompt"` via Bash tool
73
+
74
+ 7. **Report results**
75
+ - Log: "Selected {profile} (reason: {reasoning/long-context/cost-optimized})"
76
+ - Report: Cost (USD), Duration (sec), Session ID, Exit code
77
+
78
+ **For `/ccs:continue [follow-up]`:**
79
+
80
+ 1. **Detect profile**
81
+ - Read `~/.ccs/delegation-sessions.json` using Read tool
82
+ - Find most recent session (latest timestamp)
83
+ - Extract profile name from session data
84
+ - If no sessions → Error: "No previous delegation. Use /ccs first"
85
+
86
+ 2. **Parse override flag**
87
+ - Scan follow-up for pattern: `--(\w+)`
88
+ - If match: `profile = match[1]`, remove flag from follow-up, log profile switch
89
+ - If no match: use detected profile from step 1
90
+
91
+ 3. **Enhance prompt**
92
+ - Review previous work (check what was accomplished)
93
+ - Add: previous context, incomplete tasks, validation criteria
94
+ - Preserve slash commands at start
95
+
96
+ 4. **Execute continuation**
97
+ - Run: `ccs {profile}:continue -p "$enhancedPrompt"` via Bash tool
98
+
99
+ 5. **Report results**
100
+ - Report: Profile, Session #, Incremental cost, Total cost, Duration, Exit code
16
101
 
17
102
  ## Decision Framework
18
103
 
@@ -28,27 +113,77 @@ Execute tasks via alternative models using `ccs {profile} -p "task"` equivalent
28
113
  - Performance optimization
29
114
  - Breaking changes/migrations
30
115
 
31
- ## Profile Selection
116
+ ## Profile Selection Logic
32
117
 
33
- - **GLM**: Simple tasks (<5 files, clear scope, cost-optimized)
34
- - **Kimi**: Long-context (multi-file analysis, architecture docs)
118
+ **Task Analysis Keywords** (scan task string with regex):
35
119
 
36
- ## Execution
120
+ | Pattern | Variable | Example |
121
+ |---------|----------|---------|
122
+ | `/(think\|analyze\|reason\|debug\|investigate\|evaluate)/i` | `needsReasoning = true` | "think about caching" |
123
+ | `/(architecture\|entire\|all files\|codebase\|analyze all)/i` | `needsLongContext = true` | "analyze all files" |
124
+ | `/(typo\|test\|refactor\|update\|fix)/i` | `preferCostOptimized = true` | "fix typo in README" |
125
+
126
+ **Profile Characteristic Inference** (classify by name pattern):
127
+
128
+ | Profile Pattern | Cost | Context | Reasoning |
129
+ |----------------|------|---------|-----------|
130
+ | `/^glm/i` | low | standard | false |
131
+ | `/^kimi/i` | medium | long | true |
132
+ | `/^claude/i` | high | standard | false |
133
+ | others | low | standard | false |
134
+
135
+ **Selection Algorithm** (apply filters sequentially):
37
136
 
38
- User invocation via slash commands:
39
- ```
40
- /ccs:glm "task"
41
- /ccs:glm:continue "follow-up"
42
137
  ```
138
+ profiles = Object.keys(config.profiles)
139
+ classified = profiles.map(p => ({name: p, ...inferCharacteristics(p)}))
140
+
141
+ if (needsReasoning):
142
+ filtered = classified.filter(p => p.reasoning === true).sort(['kimi'])
143
+ else if (needsLongContext):
144
+ filtered = classified.filter(p => p.context === 'long').sort(['kimi'])
145
+ else:
146
+ filtered = classified.filter(p => p.cost === 'low').sort(['glm', ...])
147
+
148
+ selected = filtered[0] || profiles.find(p => p === 'glm') || profiles[0]
149
+ if (!selected): throw Error("No profiles configured")
43
150
 
44
- Agent execution via Bash tool:
45
- ```bash
46
- ccs glm -p "task"
47
- ccs glm:continue -p "follow-up"
151
+ log("Selected {selected} (reason: {reasoning|long-context|cost-optimized})")
48
152
  ```
49
153
 
154
+ **Override Logic**:
155
+ - Parse task for `/--(\w+)/`. If match: `profile = match[1]`, remove from task, skip selection
156
+
157
+ ## Example Delegation Tasks
158
+
159
+ **Good candidates:**
160
+ - "/ccs add unit tests for UserService using Jest"
161
+ → Auto-selects: glm (simple task)
162
+ - "/ccs analyze entire architecture in src/"
163
+ → Auto-selects: kimi (long-context)
164
+ - "/ccs think about the best database schema design"
165
+ → Auto-selects: kimi (reasoning)
166
+ - "/ccs --glm refactor parseConfig to use destructuring"
167
+ → Forces: glm (override)
168
+
169
+ **Bad candidates (keep in main):**
170
+ - "implement OAuth" (too complex, needs design)
171
+ - "improve performance" (requires profiling)
172
+ - "fix the bug" (needs investigation)
173
+
174
+ ## Execution
175
+
176
+ **Commands:**
177
+ - `/ccs "task"` - Intelligent delegation (auto-select profile)
178
+ - `/ccs --{profile} "task"` - Force specific profile
179
+ - `/ccs:continue "follow-up"` - Continue last session (auto-detect profile)
180
+ - `/ccs:continue --{profile} "follow-up"` - Continue with profile switch
181
+
182
+ **Agent via Bash:**
183
+ - Auto: `ccs {auto-selected} -p "task"`
184
+ - Continue: `ccs {detected}:continue -p "follow-up"`
185
+
50
186
  ## References
51
187
 
52
- Technical details: `references/headless-workflow.md`
53
- Decision guide: `references/delegation-guidelines.md`
188
+ Template: `CLAUDE.md.template` - Copy to user's CLAUDE.md for auto-delegation config
54
189
  Troubleshooting: `references/troubleshooting.md`
@@ -2,267 +2,200 @@
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
+ **Interactive mode (no -p flag):**
199
+ ```bash
200
+ ccs {profile} # Opens interactive session
268
201
  ```