claude-code-workflow 7.2.29 → 7.2.30

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.
Files changed (124) hide show
  1. package/.ccw/workflows/cli-templates/schemas/plan-overview-base-schema.json +2 -2
  2. package/.ccw/workflows/cli-templates/schemas/task-schema.json +14 -7
  3. package/.claude/agents/action-planning-agent.md +7 -4
  4. package/.claude/agents/cli-explore-agent.md +77 -63
  5. package/.claude/agents/cli-lite-planning-agent.md +11 -10
  6. package/.claude/agents/issue-plan-agent.md +421 -426
  7. package/.claude/commands/workflow/spec/setup.md +1 -1
  8. package/.claude/skills/ccw-chain/SKILL.md +119 -0
  9. package/.claude/skills/ccw-chain/chains/ccw-cycle.json +21 -0
  10. package/.claude/skills/ccw-chain/chains/ccw-exploration.json +47 -0
  11. package/.claude/skills/ccw-chain/chains/ccw-issue.json +33 -0
  12. package/.claude/skills/ccw-chain/chains/ccw-lightweight.json +57 -0
  13. package/.claude/skills/ccw-chain/chains/ccw-main.json +52 -0
  14. package/.claude/skills/ccw-chain/chains/ccw-standard.json +39 -0
  15. package/.claude/skills/ccw-chain/chains/ccw-team.json +10 -0
  16. package/.claude/skills/ccw-chain/chains/ccw-with-file.json +31 -0
  17. package/.claude/skills/ccw-chain/phases/analyze-with-file.md +788 -0
  18. package/.claude/skills/ccw-chain/phases/brainstorm/SKILL.md +408 -0
  19. package/.claude/skills/ccw-chain/phases/brainstorm/phases/01-mode-routing.md +207 -0
  20. package/.claude/skills/ccw-chain/phases/brainstorm/phases/02-artifacts.md +567 -0
  21. package/.claude/skills/ccw-chain/phases/brainstorm/phases/03-role-analysis.md +748 -0
  22. package/.claude/skills/ccw-chain/phases/brainstorm/phases/04-synthesis.md +827 -0
  23. package/.claude/skills/ccw-chain/phases/brainstorm-with-file.md +482 -0
  24. package/.claude/skills/ccw-chain/phases/collaborative-plan-with-file.md +639 -0
  25. package/.claude/skills/ccw-chain/phases/debug-with-file.md +656 -0
  26. package/.claude/skills/ccw-chain/phases/integration-test-cycle.md +936 -0
  27. package/.claude/skills/ccw-chain/phases/issue-convert-to-plan.md +720 -0
  28. package/.claude/skills/ccw-chain/phases/issue-discover.md +483 -0
  29. package/.claude/skills/ccw-chain/phases/issue-execute.md +629 -0
  30. package/.claude/skills/ccw-chain/phases/issue-from-brainstorm.md +382 -0
  31. package/.claude/skills/ccw-chain/phases/issue-plan.md +343 -0
  32. package/.claude/skills/ccw-chain/phases/issue-queue.md +464 -0
  33. package/.claude/skills/ccw-chain/phases/refactor-cycle.md +852 -0
  34. package/.claude/skills/ccw-chain/phases/review-cycle/SKILL.md +132 -0
  35. package/.claude/skills/ccw-chain/phases/review-cycle/phases/review-fix.md +760 -0
  36. package/.claude/skills/ccw-chain/phases/review-cycle/phases/review-module.md +764 -0
  37. package/.claude/skills/ccw-chain/phases/review-cycle/phases/review-session.md +775 -0
  38. package/.claude/skills/ccw-chain/phases/roadmap-with-file.md +544 -0
  39. package/.claude/skills/ccw-chain/phases/spec-generator/SKILL.md +338 -0
  40. package/.claude/skills/ccw-chain/phases/spec-generator/phases/01-5-requirement-clarification.md +404 -0
  41. package/.claude/skills/ccw-chain/phases/spec-generator/phases/01-discovery.md +257 -0
  42. package/.claude/skills/ccw-chain/phases/spec-generator/phases/02-product-brief.md +274 -0
  43. package/.claude/skills/ccw-chain/phases/spec-generator/phases/03-requirements.md +184 -0
  44. package/.claude/skills/ccw-chain/phases/spec-generator/phases/04-architecture.md +248 -0
  45. package/.claude/skills/ccw-chain/phases/spec-generator/phases/05-epics-stories.md +178 -0
  46. package/.claude/skills/ccw-chain/phases/spec-generator/phases/06-5-auto-fix.md +144 -0
  47. package/.claude/skills/ccw-chain/phases/spec-generator/phases/06-readiness-check.md +480 -0
  48. package/.claude/skills/ccw-chain/phases/team-planex.md +123 -0
  49. package/.claude/skills/ccw-chain/phases/ui-design-explore-auto.md +678 -0
  50. package/.claude/skills/ccw-chain/phases/unified-execute-with-file.md +870 -0
  51. package/.claude/skills/ccw-chain/phases/workflow-execute/SKILL.md +625 -0
  52. package/.claude/skills/ccw-chain/phases/workflow-execute/phases/06-review.md +215 -0
  53. package/.claude/skills/ccw-chain/phases/workflow-lite-plan.md +616 -0
  54. package/.claude/skills/ccw-chain/phases/workflow-multi-cli-plan.md +424 -0
  55. package/.claude/skills/ccw-chain/phases/workflow-plan/SKILL.md +466 -0
  56. package/.claude/skills/ccw-chain/phases/workflow-plan/phases/01-session-discovery.md +99 -0
  57. package/.claude/skills/ccw-chain/phases/workflow-plan/phases/02-context-gathering.md +338 -0
  58. package/.claude/skills/ccw-chain/phases/workflow-plan/phases/03-conflict-resolution.md +422 -0
  59. package/.claude/skills/ccw-chain/phases/workflow-plan/phases/04-task-generation.md +440 -0
  60. package/.claude/skills/ccw-chain/phases/workflow-plan/phases/05-plan-verify.md +395 -0
  61. package/.claude/skills/ccw-chain/phases/workflow-plan/phases/06-replan.md +594 -0
  62. package/.claude/skills/ccw-chain/phases/workflow-tdd-plan/SKILL.md +527 -0
  63. package/.claude/skills/ccw-chain/phases/workflow-tdd-plan/phases/01-session-discovery.md +57 -0
  64. package/.claude/skills/ccw-chain/phases/workflow-tdd-plan/phases/02-context-gathering.md +407 -0
  65. package/.claude/skills/ccw-chain/phases/workflow-tdd-plan/phases/03-test-coverage-analysis.md +172 -0
  66. package/.claude/skills/ccw-chain/phases/workflow-tdd-plan/phases/04-conflict-resolution.md +426 -0
  67. package/.claude/skills/ccw-chain/phases/workflow-tdd-plan/phases/05-tdd-task-generation.md +473 -0
  68. package/.claude/skills/ccw-chain/phases/workflow-tdd-plan/phases/06-tdd-structure-validation.md +189 -0
  69. package/.claude/skills/ccw-chain/phases/workflow-tdd-plan/phases/07-tdd-verify.md +635 -0
  70. package/.claude/skills/ccw-chain/phases/workflow-test-fix/SKILL.md +482 -0
  71. package/.claude/skills/ccw-chain/phases/workflow-test-fix/phases/01-session-start.md +60 -0
  72. package/.claude/skills/ccw-chain/phases/workflow-test-fix/phases/02-test-context-gather.md +493 -0
  73. package/.claude/skills/ccw-chain/phases/workflow-test-fix/phases/03-test-concept-enhanced.md +150 -0
  74. package/.claude/skills/ccw-chain/phases/workflow-test-fix/phases/04-test-task-generate.md +346 -0
  75. package/.claude/skills/ccw-chain/phases/workflow-test-fix/phases/05-test-cycle-execute.md +538 -0
  76. package/.claude/skills/ccw-chain/specs/auto-mode.md +47 -0
  77. package/.claude/skills/ccw-chain/specs/intent-patterns.md +60 -0
  78. package/.claude/skills/chain-loader/SKILL.md +78 -0
  79. package/.claude/skills/chain-loader/phases/01-analyze-skill.md +53 -0
  80. package/.claude/skills/chain-loader/phases/02-design-graph.md +73 -0
  81. package/.claude/skills/chain-loader/phases/03-generate-validate.md +75 -0
  82. package/.claude/skills/chain-loader/specs/chain-schema.md +99 -0
  83. package/.claude/skills/chain-loader/specs/design-patterns.md +99 -0
  84. package/.claude/skills/chain-loader/templates/chain-json.md +63 -0
  85. package/.claude/skills/review-cycle/phases/review-module.md +764 -764
  86. package/.claude/skills/review-cycle/phases/review-session.md +775 -775
  87. package/.claude/skills/workflow-multi-cli-plan/SKILL.md +2 -2
  88. package/.claude/skills/workflow-plan/phases/03-conflict-resolution.md +422 -422
  89. package/.claude/skills/workflow-plan/phases/05-plan-verify.md +395 -395
  90. package/.claude/skills/workflow-tdd-plan/phases/02-context-gathering.md +407 -407
  91. package/.claude/skills/workflow-tdd-plan/phases/04-conflict-resolution.md +426 -426
  92. package/.claude/skills/workflow-test-fix/phases/02-test-context-gather.md +493 -493
  93. package/README.md +14 -0
  94. package/ccw/dist/core/routes/litellm-api-routes.d.ts.map +1 -1
  95. package/ccw/dist/core/routes/litellm-api-routes.js +0 -23
  96. package/ccw/dist/core/routes/litellm-api-routes.js.map +1 -1
  97. package/ccw/dist/tools/chain-loader.d.ts +10 -0
  98. package/ccw/dist/tools/chain-loader.d.ts.map +1 -0
  99. package/ccw/dist/tools/chain-loader.js +642 -0
  100. package/ccw/dist/tools/chain-loader.js.map +1 -0
  101. package/ccw/dist/tools/index.d.ts.map +1 -1
  102. package/ccw/dist/tools/index.js +2 -0
  103. package/ccw/dist/tools/index.js.map +1 -1
  104. package/ccw/dist/tools/json-builder.js +20 -0
  105. package/ccw/dist/tools/json-builder.js.map +1 -1
  106. package/ccw/dist/types/chain-types.d.ts +72 -0
  107. package/ccw/dist/types/chain-types.d.ts.map +1 -0
  108. package/ccw/dist/types/chain-types.js +5 -0
  109. package/ccw/dist/types/chain-types.js.map +1 -0
  110. package/ccw/scripts/prepublish-clean.mjs +0 -1
  111. package/package.json +1 -3
  112. package/ccw-litellm/README.md +0 -180
  113. package/ccw-litellm/pyproject.toml +0 -35
  114. package/ccw-litellm/src/ccw_litellm/__init__.py +0 -47
  115. package/ccw-litellm/src/ccw_litellm/cli.py +0 -108
  116. package/ccw-litellm/src/ccw_litellm/clients/__init__.py +0 -12
  117. package/ccw-litellm/src/ccw_litellm/clients/litellm_embedder.py +0 -270
  118. package/ccw-litellm/src/ccw_litellm/clients/litellm_llm.py +0 -198
  119. package/ccw-litellm/src/ccw_litellm/config/__init__.py +0 -22
  120. package/ccw-litellm/src/ccw_litellm/config/loader.py +0 -343
  121. package/ccw-litellm/src/ccw_litellm/config/models.py +0 -162
  122. package/ccw-litellm/src/ccw_litellm/interfaces/__init__.py +0 -14
  123. package/ccw-litellm/src/ccw_litellm/interfaces/embedder.py +0 -52
  124. package/ccw-litellm/src/ccw_litellm/interfaces/llm.py +0 -45
@@ -0,0 +1,78 @@
1
+ ---
2
+ name: chain-loader
3
+ description: Meta-skill for generating chain-based skills with progressive step loading and LLM-driven decision routing. Converts linear phase skills into chain graph skills. Triggers on "create chain", "chain skill", "add chain", "generate chain".
4
+ allowed-tools: Agent, AskUserQuestion, Read, Bash, Glob, Grep, Write
5
+ ---
6
+
7
+ # Chain Skill Generator
8
+
9
+ Generate chain graph JSON for skills, enabling progressive content delivery and LLM-driven decision routing via the `chain_loader` tool.
10
+
11
+ ## Architecture
12
+
13
+ ```
14
+ User Request (target skill + chain purpose)
15
+ |
16
+ Phase 1: Analyze target skill (existing phases/ or new requirements)
17
+ |
18
+ Phase 2: Design node graph (step/decision/delegate nodes + routing)
19
+ |
20
+ Phase 3: Generate chain JSON + validate with chain_loader
21
+ |
22
+ Output: .claude/skills/{skill}/chains/{chain}.json
23
+ ```
24
+
25
+ ## Key Rules
26
+
27
+ 1. **Spec-first** — Read `specs/chain-schema.md` and `specs/design-patterns.md` before any generation
28
+ 2. **content_ref over inline** — Use `@phases/` file references; `content_inline` only for <200 char
29
+ 3. **Validate before commit** — Never write chain JSON without graph connectivity check
30
+ 4. **Preserve existing content** — When adding chains to existing skills, never modify existing phase files
31
+ 5. **12-node limit** — If a chain exceeds 12 nodes, split into main + sub-chains
32
+
33
+ ## Exemplar
34
+
35
+ `ccw-chain` is the canonical example of this meta-skill's output:
36
+ - 8 chains, 79 total nodes, cross-chain routing via `->chain-name`
37
+ - phases/ contains actual command/skill documents (not orchestration code)
38
+ - Location: `.claude/skills/ccw-chain/`
39
+
40
+ Study its structure before generating new chains: `Read(".claude/skills/ccw-chain/SKILL.md")`
41
+
42
+ ## Execution Flow
43
+
44
+ ```
45
+ Pre-Phase: Read specs/chain-schema.md + specs/design-patterns.md
46
+
47
+ Phase 1: Analyze Target Skill
48
+ Ref: phases/01-analyze-skill.md
49
+ Input: user request, target skill name
50
+ Output: skill analysis (workflow steps, decision points, content files)
51
+
52
+ Phase 2: Design Node Graph
53
+ Ref: phases/02-design-graph.md
54
+ Input: skill analysis
55
+ Output: validated node graph (in-memory)
56
+
57
+ Phase 3: Generate & Validate
58
+ Ref: phases/03-generate-validate.md
59
+ Input: validated node graph
60
+ Output: chain JSON files, validation report
61
+ ```
62
+
63
+ | Phase | Document | Purpose |
64
+ |-------|----------|---------|
65
+ | 1 | phases/01-analyze-skill.md | Understand target skill workflow and content |
66
+ | 2 | phases/02-design-graph.md | Design nodes, routing, validate connectivity |
67
+ | 3 | phases/03-generate-validate.md | Write JSON, test with chain_loader |
68
+
69
+ ## Output Structure
70
+
71
+ ```
72
+ .claude/skills/{skill}/
73
+ ├── chains/
74
+ │ ├── {chain-name}.json # Main chain
75
+ │ └── {sub-chain}.json # Optional sub-chains
76
+ ├── phases/ # Content files (existing or generated)
77
+ └── SKILL.md # Existing or updated entry
78
+ ```
@@ -0,0 +1,53 @@
1
+ # Phase 1: Analyze Target Skill
2
+
3
+ Understand the target skill's workflow to identify nodes, decision points, and content files.
4
+
5
+ ## Step 1.1: Identify Target
6
+
7
+ Determine if adding chains to an existing skill or creating new:
8
+
9
+ **Existing skill**: Read its SKILL.md and list its phases/ directory
10
+ ```bash
11
+ # Find the skill
12
+ ls .claude/skills/{skill-name}/SKILL.md
13
+ ls .claude/skills/{skill-name}/phases/
14
+ ```
15
+
16
+ **New skill**: Collect requirements from user — what workflow steps, what branches, what content.
17
+
18
+ ## Step 1.2: Map Workflow Steps
19
+
20
+ For existing skills, read each phase file and identify:
21
+
22
+ 1. **Sequential steps** — each phase becomes a StepNode with `content_ref: "@phases/{file}"`
23
+ 2. **Decision points** — look for conditional language ("if...", "based on...", "choose...") that implies branching
24
+ 3. **Sub-workflows** — sections that reference other skills or could be extracted as separate chains
25
+
26
+ For new skills, work with the user to define:
27
+ - What are the execution steps?
28
+ - Where does the LLM need to make a routing decision?
29
+ - What content should each step load?
30
+
31
+ ## Step 1.3: Inventory Content Files
32
+
33
+ List all files that chain nodes will reference:
34
+
35
+ | Type | Source | content_ref Format |
36
+ |------|--------|--------------------|
37
+ | Phase files | `phases/01-xxx.md` | `@phases/01-xxx.md` |
38
+ | Skill subdirs | `phases/workflow-plan/SKILL.md` | `@phases/workflow-plan/SKILL.md` |
39
+ | Commands | `.claude/commands/workflow/xxx.md` | Copy to phases/ first, then `@phases/xxx.md` |
40
+ | Inline content | Short instructions (<200 chars) | Use `content_inline` instead |
41
+
42
+ **Key lesson from ccw-chain**: phases/ should contain **actual command/skill documents** that the LLM executes, not orchestration pseudocode.
43
+
44
+ ## Output
45
+
46
+ - Skill name and directory path
47
+ - List of workflow steps with their content file mappings
48
+ - Identified decision points with branch options
49
+ - List of content files that need to be created or copied
50
+
51
+ ## Next Phase
52
+
53
+ Proceed to [Phase 2: Design Node Graph](02-design-graph.md).
@@ -0,0 +1,73 @@
1
+ # Phase 2: Design Node Graph
2
+
3
+ Transform skill analysis into a validated directed graph of chain nodes.
4
+
5
+ ## Step 2.1: Choose Chain Pattern
6
+
7
+ Based on the workflow analysis from Phase 1, select a pattern from `specs/design-patterns.md`:
8
+
9
+ | Workflow Shape | Pattern | Example |
10
+ |----------------|---------|---------|
11
+ | Pure sequential | Linear Chain | `S1 → S2 → S3 → null` |
12
+ | Quality gate / retry | Decision Gate | `S1 → D1 --[pass]--> S2 --[fail]--> S1` |
13
+ | Normal vs escalation | Escalation Branch | `D1 --[simple]--> S2 --[complex]--> ->deep` |
14
+ | Reusable sub-workflow | Delegate | `S1 → DEL1 [->verify] → S2` |
15
+ | Multi-flow routing | Decision Router | `D1 --[A]--> S_A1 --[B]--> S_B1` (ccw-chain pattern) |
16
+
17
+ ## Step 2.2: Define Nodes
18
+
19
+ For each workflow step, create a node definition:
20
+
21
+ **StepNode** — loads content for LLM execution:
22
+ - `content_ref: "@phases/{file}"` for existing files
23
+ - `content_inline: "..."` for short instructions only (<200 chars)
24
+ - `next: "{node_id}"` or `null` for terminal
25
+
26
+ **DecisionNode** — LLM chooses a path:
27
+ - `prompt`: describe what the LLM should assess
28
+ - `choices[]`: each with `label`, `description`, `next`
29
+ - `default`: fallback node ID
30
+
31
+ **DelegateNode** — route to sub-chain:
32
+ - `chain`: sub-chain filename (without .json)
33
+ - `next`: return node after sub-chain completes
34
+
35
+ **Node ID conventions**:
36
+ - Steps: `S1`, `S2`, `S3` (sequential) or `S_{prefix}{n}` for multi-flow (e.g., `S_R1`, `S_B1`)
37
+ - Decisions: `D1`, `D2`
38
+ - Delegates: `DEL1`, `DEL2`
39
+
40
+ ## Step 2.3: Design Routing
41
+
42
+ For multi-flow chains (like ccw-chain's category chains), use the Decision Router pattern:
43
+
44
+ ```
45
+ D1 (Select Flow)
46
+ ├── choice 1 → S_A1 → S_A2 → null
47
+ ├── choice 2 → S_B1 → S_B2 → S_B3 → null
48
+ └── choice 3 → S_C1 → null
49
+ ```
50
+
51
+ For cross-chain routing, use `"next": "->chain-name"` to jump to another chain's entry node.
52
+
53
+ ## Step 2.4: Validate Graph
54
+
55
+ Before proceeding to generation, verify:
56
+
57
+ 1. **Entry exists** — `entry` points to a node in `nodes`
58
+ 2. **All `next` references resolve** — every node ID in `next`, `choices[].next`, `default` either exists in `nodes`, is `null`, or starts with `->` (cross-chain)
59
+ 3. **No orphan nodes** — BFS from entry reaches every node in `nodes`
60
+ 4. **Content files exist** — every `content_ref` path resolves to a real file
61
+ 5. **Decision completeness** — every DecisionNode has non-empty `choices` and a `default`
62
+
63
+ If validation fails, fix the graph before proceeding. Do NOT generate invalid chains.
64
+
65
+ ## Output
66
+
67
+ - Validated node graph (nodes map ready for JSON serialization)
68
+ - Sub-chain definitions if any
69
+ - List of content files that need creation
70
+
71
+ ## Next Phase
72
+
73
+ Proceed to [Phase 3: Generate & Validate](03-generate-validate.md).
@@ -0,0 +1,75 @@
1
+ # Phase 3: Generate & Validate
2
+
3
+ Write chain JSON files and validate with the chain_loader tool.
4
+
5
+ ## Step 3.1: Create Directory
6
+
7
+ ```bash
8
+ mkdir -p ".claude/skills/${skillName}/chains"
9
+ ```
10
+
11
+ ## Step 3.2: Write Chain JSON
12
+
13
+ Write the main chain file using the validated graph from Phase 2:
14
+
15
+ ```json
16
+ {
17
+ "chain_id": "{chain-id}",
18
+ "name": "{Human-Readable Name}",
19
+ "description": "{What this chain does}",
20
+ "version": "1.0",
21
+ "entry": "{first-node-id}",
22
+ "nodes": { ... }
23
+ }
24
+ ```
25
+
26
+ Write to: `.claude/skills/{skill}/chains/{chain-id}.json`
27
+
28
+ If there are sub-chains, write each as a separate JSON file in the same `chains/` directory.
29
+
30
+ ## Step 3.3: Create Missing Content Files
31
+
32
+ If any step nodes need new content files:
33
+ 1. Write the content to `phases/{filename}.md`
34
+ 2. Ensure the `content_ref` in the chain JSON matches: `@phases/{filename}.md`
35
+
36
+ For content files copied from commands or other skills, preserve the full document — do not summarize.
37
+
38
+ ## Step 3.4: Validate Structure
39
+
40
+ Check the generated JSON:
41
+
42
+ 1. **Required fields**: `chain_id`, `name`, `description`, `version`, `entry`, `nodes`
43
+ 2. **Entry exists**: `entry` points to a key in `nodes`
44
+ 3. **Node completeness**: every node has `type` and `name`
45
+ 4. **Step nodes**: have `content_ref` or `content_inline`
46
+ 5. **Decision nodes**: have non-empty `choices[]` and `default`
47
+ 6. **Delegate nodes**: have `chain` field
48
+ 7. **All `next` references**: resolve to existing nodes, `null`, or `->chain-name`
49
+ 8. **No orphans**: BFS from entry reaches every node
50
+ 9. **Content refs exist**: every `@phases/...` file is on disk
51
+
52
+ ## Step 3.5: Integration Test
53
+
54
+ Test with the chain_loader tool from the **project root** (not from the skill directory):
55
+
56
+ ```bash
57
+ # List — should show the new chain(s)
58
+ ccw tool exec chain_loader '{"cmd":"list","skill":"{skill-name}"}'
59
+
60
+ # Start — should return entry node content
61
+ ccw tool exec chain_loader '{"cmd":"start","skill":"{skill-name}","chain":"{chain-id}"}'
62
+ ```
63
+
64
+ **Known gotcha**: `chain_loader list` auto-detects skill from cwd. Run from project root with explicit `skill` param to avoid empty results.
65
+
66
+ ## Step 3.6: Report Results
67
+
68
+ Output summary:
69
+ - Chains generated (count and names)
70
+ - Total nodes, by type (step/decision/delegate)
71
+ - Validation status (PASS/FAIL)
72
+ - Any warnings (orphan nodes, missing content)
73
+
74
+ If FAIL: fix errors before marking complete.
75
+ If PASS: the chain is ready for use.
@@ -0,0 +1,99 @@
1
+ # Chain JSON Schema & State Machine
2
+
3
+ ## Chain JSON Structure
4
+
5
+ Files live at `.claude/skills/{skill}/chains/{chain-name}.json`.
6
+
7
+ ### Required Fields
8
+
9
+ | Field | Type | Description |
10
+ |-------|------|-------------|
11
+ | `chain_id` | string | Unique ID matching filename (without .json) |
12
+ | `name` | string | Human-readable name |
13
+ | `description` | string | What this chain does |
14
+ | `version` | string | Semantic version |
15
+ | `entry` | string | Node ID of entry point (must exist in nodes) |
16
+ | `nodes` | object | Map of node ID to node definition |
17
+
18
+ ### StepNode
19
+
20
+ ```json
21
+ {
22
+ "type": "step",
23
+ "name": "Phase Name",
24
+ "content_ref": "@phases/01-xxx.md",
25
+ "next": "S2"
26
+ }
27
+ ```
28
+ - `content_ref` (`@`-prefixed path) or `content_inline` (direct text) — at least one required
29
+ - `content_ref` resolved relative to skill directory: `resolve(skillPath, refPath.replace('@',''))`
30
+ - `next: null` = chain termination
31
+
32
+ ### DecisionNode
33
+
34
+ ```json
35
+ {
36
+ "type": "decision",
37
+ "name": "Select Flow",
38
+ "prompt": "Based on analysis, choose...",
39
+ "choices": [
40
+ { "label": "Option A", "description": "...", "next": "S_A1" },
41
+ { "label": "Option B", "description": "...", "next": "S_B1" }
42
+ ],
43
+ "default": "S_A1"
44
+ }
45
+ ```
46
+ - `choices` — non-empty array, selected by **1-based index**
47
+ - `choice.next` can be node ID or `"->chain-name"` for cross-chain routing
48
+ - `default` — fallback if no valid choice provided
49
+
50
+ ### DelegateNode
51
+
52
+ ```json
53
+ {
54
+ "type": "delegate",
55
+ "name": "Run Sub-workflow",
56
+ "chain": "sub-chain-name",
57
+ "next": "S5"
58
+ }
59
+ ```
60
+ - `chain` — filename (without .json) of another chain in same skill's `chains/` dir
61
+ - `next` — return node after sub-chain completes; `null` if no return
62
+
63
+ ### Cross-Chain Routing
64
+
65
+ - `"->chain-name"` in any `next` field jumps to that chain's entry node
66
+ - DelegateNode pushes current chain onto stack; sub-chain completion pops back to `next`
67
+
68
+ ---
69
+
70
+ ## Node State Machine
71
+
72
+ ### Lifecycle
73
+
74
+ ```
75
+ pending → active → completed
76
+ ```
77
+
78
+ ### Rules
79
+
80
+ 1. `start` — creates session, entry node becomes `active`
81
+ 2. `next` on `active` node — returns current content (idempotent, no state change)
82
+ 3. `next` on `completed` node — auto-advances to next node
83
+ 4. `done` — forces `active -> completed`, advances to next node
84
+ 5. Decision `done` requires `choice` (1-based index)
85
+ 6. Delegate `done` — pushes chain onto `chain_stack`, switches to sub-chain entry
86
+ 7. Sub-chain termination (`next: null`) — pops `chain_stack`, returns to parent's `return_node`
87
+ 8. All chains exhausted (empty stack + `next: null`) — session `completed`
88
+
89
+ ### chain_loader Commands
90
+
91
+ | cmd | Params | Description |
92
+ |-----|--------|-------------|
93
+ | `list` | `skill?` | List chains (auto-detects skill from cwd) |
94
+ | `start` | `chain`, `skill?` | Create session, load entry node |
95
+ | `next` | `session_id` | Read current node (idempotent if active) |
96
+ | `done` | `session_id`, `choice?` | Complete current node, advance |
97
+ | `status` | `session_id` | Query session state |
98
+ | `content` | `session_id` | Get all loaded content |
99
+ | `complete` | `session_id` | Mark session completed |
@@ -0,0 +1,99 @@
1
+ # Chain Design Patterns
2
+
3
+ Common patterns and anti-patterns for chain graph design.
4
+
5
+ ## Patterns
6
+
7
+ ### 1. Linear Chain (Simplest)
8
+
9
+ ```
10
+ S1 → S2 → S3 → null
11
+ ```
12
+
13
+ Use when: Pure sequential workflow, no branching needed. Equivalent to numbered phases but with session tracking.
14
+
15
+ ### 2. Decision Gate
16
+
17
+ ```
18
+ S1 → S2 → D1 --[pass]--> S3 → null
19
+ --[fail]--> S2 (loop back)
20
+ ```
21
+
22
+ Use when: Quality gate after analysis, confidence check, retry loop.
23
+
24
+ ### 3. Escalation Branch
25
+
26
+ ```
27
+ S1 → S2 → D1 --[simple]--> S3 → null
28
+ --[complex]--> →deep-analysis (cross-chain)
29
+ ```
30
+
31
+ Use when: Normal path vs. escalation to separate workflow.
32
+
33
+ ### 4. Delegate Sub-Chain
34
+
35
+ ```
36
+ S1 → S2 → DEL1 [→verification] → S3 → null
37
+ ```
38
+
39
+ Use when: Reusable sub-workflow that multiple chains can call.
40
+
41
+ ### 5. Multi-Path Merge
42
+
43
+ ```
44
+ S1 → D1 --[A]--> S2A → S3
45
+ --[B]--> S2B → S3
46
+ ```
47
+
48
+ Use when: Different approaches converge to same final step.
49
+
50
+ ### 6. Decision Router (Multi-Flow)
51
+
52
+ ```
53
+ D1 --[flow A]--> S_A1 → S_A2 → null
54
+ --[flow B]--> S_B1 → S_B2 → S_B3 → null
55
+ --[flow C]--> S_C1 → null
56
+ ```
57
+
58
+ Use when: Single entry point dispatches to multiple independent pipelines. Each flow has its own step sequence. This is the primary pattern used in ccw-chain's category chains (ccw-lightweight, ccw-standard, ccw-exploration, etc.).
59
+
60
+ ## Anti-Patterns
61
+
62
+ ### 1. Too Many Decisions
63
+
64
+ Bad: `D1 → D2 → D3 → D4` (decision after decision)
65
+
66
+ Fix: Combine into one decision with more choices, or add a step between decisions.
67
+
68
+ ### 2. Orphan Nodes
69
+
70
+ Bad: Node exists in `nodes` but unreachable from `entry`.
71
+
72
+ Fix: Remove it or connect it to the graph.
73
+
74
+ ### 3. Missing Default
75
+
76
+ Bad: Decision node without `default` field.
77
+
78
+ Fix: Always set `default` to a safe fallback node.
79
+
80
+ ### 4. Deep Delegation
81
+
82
+ Bad: Chain A delegates to B which delegates to C which delegates to D.
83
+
84
+ Fix: Keep delegation to max 2 levels. Flatten if possible.
85
+
86
+ ### 5. Inline Novel Content
87
+
88
+ Bad: `content_inline` with 500+ words of unique instruction.
89
+
90
+ Fix: Extract to a `phases/*.md` file and use `content_ref`.
91
+
92
+ ## Chain Sizing Guide
93
+
94
+ | Complexity | Nodes | Decisions | Sub-chains |
95
+ |-----------|-------|-----------|------------|
96
+ | Simple | 3-5 | 0-1 | 0 |
97
+ | Standard | 5-8 | 1-2 | 0-1 |
98
+ | Complex | 8-12 | 2-3 | 1-2 |
99
+ | Large | 12+ | Consider splitting into multiple chains |
@@ -0,0 +1,63 @@
1
+ # Chain JSON Template
2
+
3
+ ## Minimal Linear Chain
4
+
5
+ ```json
6
+ {
7
+ "chain_id": "my-workflow",
8
+ "name": "My Workflow",
9
+ "description": "Sequential 3-step workflow",
10
+ "version": "1.0",
11
+ "entry": "S1",
12
+ "nodes": {
13
+ "S1": { "type": "step", "name": "Step 1", "content_ref": "@phases/01-step.md", "next": "S2" },
14
+ "S2": { "type": "step", "name": "Step 2", "content_ref": "@phases/02-step.md", "next": "S3" },
15
+ "S3": { "type": "step", "name": "Step 3", "content_ref": "@phases/03-step.md", "next": null }
16
+ }
17
+ }
18
+ ```
19
+
20
+ ## Decision Router (from ccw-chain/ccw-lightweight)
21
+
22
+ ```json
23
+ {
24
+ "chain_id": "ccw-lightweight",
25
+ "name": "CCW Lightweight Workflows",
26
+ "description": "Level 2: rapid, bugfix, hotfix, docs-only",
27
+ "version": "2.0",
28
+ "entry": "D1",
29
+ "nodes": {
30
+ "D1": {
31
+ "type": "decision",
32
+ "name": "Select Lightweight Flow",
33
+ "prompt": "Based on the detected task_type, select the flow:\n1. Rapid\n2. Bugfix\n3. Hotfix\n4. Docs",
34
+ "choices": [
35
+ { "label": "Rapid", "description": "lite-plan + test-fix", "next": "S_R1" },
36
+ { "label": "Bugfix", "description": "lite-plan(--bugfix) + test-fix", "next": "S_B1" },
37
+ { "label": "Hotfix", "description": "lite-plan(--hotfix)", "next": "S_H1" },
38
+ { "label": "Docs", "description": "lite-plan(--docs)", "next": "S_D1" }
39
+ ],
40
+ "default": "S_R1"
41
+ },
42
+ "S_R1": { "type": "step", "name": "Rapid: workflow-lite-plan", "content_ref": "@phases/workflow-lite-plan.md", "next": "S_R2" },
43
+ "S_R2": { "type": "step", "name": "Rapid: workflow-test-fix", "content_ref": "@phases/workflow-test-fix/SKILL.md", "next": null },
44
+ "S_B1": { "type": "step", "name": "Bugfix: workflow-lite-plan", "content_ref": "@phases/workflow-lite-plan.md", "next": "S_B2" },
45
+ "S_B2": { "type": "step", "name": "Bugfix: workflow-test-fix", "content_ref": "@phases/workflow-test-fix/SKILL.md", "next": null },
46
+ "S_H1": { "type": "step", "name": "Hotfix: workflow-lite-plan", "content_ref": "@phases/workflow-lite-plan.md", "next": null },
47
+ "S_D1": { "type": "step", "name": "Docs: workflow-lite-plan", "content_ref": "@phases/workflow-lite-plan.md", "next": null }
48
+ }
49
+ }
50
+ ```
51
+
52
+ ## Cross-Chain Routing (from ccw-chain/ccw-main)
53
+
54
+ Decision choice with `"next": "->ccw-lightweight"` jumps to another chain's entry node.
55
+
56
+ ## Node ID Conventions
57
+
58
+ | Prefix | Type | Example |
59
+ |--------|------|---------|
60
+ | `S{n}` | Sequential step | S1, S2, S3 |
61
+ | `S_{prefix}{n}` | Flow-scoped step | S_R1, S_B1, S_CP2 |
62
+ | `D{n}` | Decision | D1, D2 |
63
+ | `DEL{n}` | Delegate | DEL1 |