@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.
- package/.claude/agents/ccs-delegator.md +117 -0
- package/.claude/commands/ccs/glm/continue.md +22 -0
- package/.claude/commands/ccs/glm.md +22 -0
- package/.claude/commands/ccs/kimi/continue.md +22 -0
- package/.claude/commands/ccs/kimi.md +22 -0
- package/.claude/skills/ccs-delegation/SKILL.md +54 -0
- package/.claude/skills/ccs-delegation/references/README.md +24 -0
- package/.claude/skills/ccs-delegation/references/delegation-guidelines.md +99 -0
- package/.claude/skills/ccs-delegation/references/headless-workflow.md +174 -0
- package/.claude/skills/ccs-delegation/references/troubleshooting.md +268 -0
- package/README.md +223 -23
- package/VERSION +1 -1
- package/bin/ccs.js +67 -0
- package/bin/delegation/README.md +189 -0
- package/bin/delegation/delegation-handler.js +212 -0
- package/bin/delegation/headless-executor.js +618 -0
- package/bin/delegation/result-formatter.js +485 -0
- package/bin/delegation/session-manager.js +157 -0
- package/bin/delegation/settings-parser.js +109 -0
- package/bin/management/doctor.js +94 -1
- package/bin/utils/claude-dir-installer.js +102 -0
- package/bin/utils/claude-symlink-manager.js +238 -0
- package/bin/utils/delegation-validator.js +154 -0
- package/lib/ccs +35 -1
- package/lib/ccs.ps1 +1 -1
- package/package.json +2 -1
- package/scripts/postinstall.js +22 -0
|
@@ -0,0 +1,117 @@
|
|
|
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
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Continue last GLM delegation session [AUTO ENHANCE]
|
|
3
|
+
argument-hint: [follow-up instruction]
|
|
4
|
+
allowed-tools: Read, Grep, Glob, Bash
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Continue last GLM delegation session for iterative refinement.
|
|
8
|
+
|
|
9
|
+
**Workflow:**
|
|
10
|
+
- Review what was accomplished in previous session
|
|
11
|
+
- Analyze the follow-up instruction in `$ARGUMENTS`
|
|
12
|
+
- Enhance prompt with context (reference files, incomplete tasks, next steps)
|
|
13
|
+
- Execute continuation via `ccs glm:continue -p "$ENHANCED_PROMPT"`
|
|
14
|
+
|
|
15
|
+
**Note:** `$ENHANCED_PROMPT` is an enhanced version that references previous work, highlights incomplete tasks, and adds specific validation criteria. If the follow-up contains a slash command (e.g., /commit), keep it at the start of the enhanced prompt.
|
|
16
|
+
|
|
17
|
+
**Usage:**
|
|
18
|
+
```
|
|
19
|
+
/ccs:glm "fix typo in README"
|
|
20
|
+
/ccs:glm:continue "also update the examples section"
|
|
21
|
+
/ccs:glm:continue "/commit with descriptive message"
|
|
22
|
+
```
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Delegate task to GLM-4.6 (cost-optimized model) [AUTO ENHANCE]
|
|
3
|
+
argument-hint: [task description]
|
|
4
|
+
allowed-tools: Read, Grep, Glob, Bash
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Delegate simple, deterministic tasks to GLM-4.6 for token optimization.
|
|
8
|
+
|
|
9
|
+
**Workflow:**
|
|
10
|
+
- Analyze the task description in `$ARGUMENTS`
|
|
11
|
+
- Gather context if needed (read files, check structure)
|
|
12
|
+
- Enhance prompt with specific details (file paths, context, success criteria)
|
|
13
|
+
- Execute delegation via `ccs glm -p "$ENHANCED_PROMPT"`
|
|
14
|
+
|
|
15
|
+
**Note:** `$ENHANCED_PROMPT` is an enhanced version that adds specifics like file paths, current implementation context, expected behavior, and success criteria. If the task contains a slash command (e.g., /cook, /plan), keep it at the start of the enhanced prompt.
|
|
16
|
+
|
|
17
|
+
**Usage:**
|
|
18
|
+
```
|
|
19
|
+
/ccs:glm "refactor auth.js to use async/await"
|
|
20
|
+
/ccs:glm "add tests for UserService"
|
|
21
|
+
/ccs:glm "/cook create a landing page"
|
|
22
|
+
```
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Continue last Kimi delegation session [AUTO ENHANCE]
|
|
3
|
+
argument-hint: [follow-up instruction]
|
|
4
|
+
allowed-tools: Read, Grep, Glob, Bash
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Continue last Kimi delegation session for multi-turn analysis.
|
|
8
|
+
|
|
9
|
+
**Workflow:**
|
|
10
|
+
- Review analysis/work from previous session
|
|
11
|
+
- Analyze the follow-up instruction in `$ARGUMENTS`
|
|
12
|
+
- Enhance prompt with comprehensive context (findings, scope, deliverables, priority)
|
|
13
|
+
- Execute continuation via `ccs kimi:continue -p "$ENHANCED_PROMPT"`
|
|
14
|
+
|
|
15
|
+
**Note:** `$ENHANCED_PROMPT` is an enhanced version that references previous findings, specifies next scope, and adds actionable deliverables with priorities. If the follow-up contains a slash command (e.g., /plan), keep it at the start of the enhanced prompt.
|
|
16
|
+
|
|
17
|
+
**Usage:**
|
|
18
|
+
```
|
|
19
|
+
/ccs:kimi "analyze all files in src/"
|
|
20
|
+
/ccs:kimi:continue "suggest architectural improvements"
|
|
21
|
+
/ccs:kimi:continue "/plan for refactoring with phases"
|
|
22
|
+
```
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Delegate task to Kimi (long-context model) [AUTO ENHANCE]
|
|
3
|
+
argument-hint: [task description]
|
|
4
|
+
allowed-tools: Read, Grep, Glob, Bash
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Delegate long-context, multi-file tasks to Kimi for comprehensive analysis.
|
|
8
|
+
|
|
9
|
+
**Workflow:**
|
|
10
|
+
- Analyze the task description in `$ARGUMENTS`
|
|
11
|
+
- Gather context across multiple files/directories
|
|
12
|
+
- Enhance prompt with comprehensive details (structure, relationships, scope)
|
|
13
|
+
- Execute delegation via `ccs kimi -p "$ENHANCED_PROMPT"`
|
|
14
|
+
|
|
15
|
+
**Note:** `$ENHANCED_PROMPT` is an enhanced version that adds directory structures, cross-file relationships, architecture context, and deliverables. If the task contains a slash command (e.g., /plan, /commit), keep it at the start of the enhanced prompt.
|
|
16
|
+
|
|
17
|
+
**Usage:**
|
|
18
|
+
```
|
|
19
|
+
/ccs:kimi "analyze all files in src/ and document architecture"
|
|
20
|
+
/ccs:kimi "find all deprecated API usages across codebase"
|
|
21
|
+
/ccs:kimi "/plan for authentication system"
|
|
22
|
+
```
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
---
|
|
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
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# CCS Delegation
|
|
8
|
+
|
|
9
|
+
Delegate deterministic tasks to cost-optimized models via CCS CLI.
|
|
10
|
+
|
|
11
|
+
## Core Concept
|
|
12
|
+
|
|
13
|
+
Execute tasks via alternative models using `ccs {profile} -p "task"` equivalent to `claude --settings ~/.ccs/{profile}.settings -p "task"`
|
|
14
|
+
|
|
15
|
+
**Profiles:** GLM (cost-optimized), Kimi (long-context)
|
|
16
|
+
|
|
17
|
+
## Decision Framework
|
|
18
|
+
|
|
19
|
+
**Delegate when:**
|
|
20
|
+
- Simple refactoring, tests, typos, documentation
|
|
21
|
+
- Deterministic, well-defined scope
|
|
22
|
+
- No discussion/decisions needed
|
|
23
|
+
|
|
24
|
+
**Keep in main when:**
|
|
25
|
+
- Architecture/design decisions
|
|
26
|
+
- Security-critical code
|
|
27
|
+
- Complex debugging requiring investigation
|
|
28
|
+
- Performance optimization
|
|
29
|
+
- Breaking changes/migrations
|
|
30
|
+
|
|
31
|
+
## Profile Selection
|
|
32
|
+
|
|
33
|
+
- **GLM**: Simple tasks (<5 files, clear scope, cost-optimized)
|
|
34
|
+
- **Kimi**: Long-context (multi-file analysis, architecture docs)
|
|
35
|
+
|
|
36
|
+
## Execution
|
|
37
|
+
|
|
38
|
+
User invocation via slash commands:
|
|
39
|
+
```
|
|
40
|
+
/ccs:glm "task"
|
|
41
|
+
/ccs:glm:continue "follow-up"
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Agent execution via Bash tool:
|
|
45
|
+
```bash
|
|
46
|
+
ccs glm -p "task"
|
|
47
|
+
ccs glm:continue -p "follow-up"
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## References
|
|
51
|
+
|
|
52
|
+
Technical details: `references/headless-workflow.md`
|
|
53
|
+
Decision guide: `references/delegation-guidelines.md`
|
|
54
|
+
Troubleshooting: `references/troubleshooting.md`
|
|
@@ -0,0 +1,24 @@
|
|
|
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`
|
|
@@ -0,0 +1,99 @@
|
|
|
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)
|
|
@@ -0,0 +1,174 @@
|
|
|
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
|