context-engineer 1.1.0

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 (74) hide show
  1. package/README.md +88 -0
  2. package/bin/cli.mjs +91 -0
  3. package/lib/copy.mjs +102 -0
  4. package/lib/init.mjs +166 -0
  5. package/lib/prompts.mjs +144 -0
  6. package/lib/update.mjs +198 -0
  7. package/package.json +35 -0
  8. package/templates/checksums.json +68 -0
  9. package/templates/claude/.claude/rules/context-maintenance.md +38 -0
  10. package/templates/claude/.claude/rules/experience-capture.md +46 -0
  11. package/templates/claude/.claude/settings.project.json +22 -0
  12. package/templates/claude/.claude/skills/bootstrap/SKILL.md +223 -0
  13. package/templates/claude/.claude/skills/dev/SKILL.md +119 -0
  14. package/templates/claude/.claude/skills/dev-capture/SKILL.md +111 -0
  15. package/templates/claude/.claude/skills/dev-commit/SKILL.md +90 -0
  16. package/templates/claude/.claude/skills/dev-decompose/SKILL.md +113 -0
  17. package/templates/claude/.claude/skills/dev-deps/SKILL.md +108 -0
  18. package/templates/claude/.claude/skills/dev-execute/SKILL.md +196 -0
  19. package/templates/claude/.claude/skills/dev-prd/SKILL.md +100 -0
  20. package/templates/claude/.claude/skills/dev-quality/SKILL.md +109 -0
  21. package/templates/claude/.claude/skills/dev-requirements/SKILL.md +75 -0
  22. package/templates/claude/.claude/skills/review-context/SKILL.md +120 -0
  23. package/templates/claude/.claude/skills/sync/SKILL.md +107 -0
  24. package/templates/claude/.claude/skills/update-context/SKILL.md +105 -0
  25. package/templates/claude/.claude/workflow/agents/implementer.md +65 -0
  26. package/templates/claude/.claude/workflow/agents/reviewer.md +96 -0
  27. package/templates/claude/.claude/workflow/agents/team-config.md +97 -0
  28. package/templates/claude/.claude/workflow/agents/tester.md +98 -0
  29. package/templates/claude/.claude/workflow/interfaces/phase-contract.md +157 -0
  30. package/templates/claude/CLAUDE.md +50 -0
  31. package/templates/core/.context/_meta/concepts.md +9 -0
  32. package/templates/core/.context/_meta/drift-report.md +16 -0
  33. package/templates/core/.context/_meta/last-sync.json +6 -0
  34. package/templates/core/.context/_meta/schema.md +242 -0
  35. package/templates/core/.context/architecture/api-surface.md +52 -0
  36. package/templates/core/.context/architecture/class-index.md +49 -0
  37. package/templates/core/.context/architecture/data-flow.md +103 -0
  38. package/templates/core/.context/architecture/data-model.md +35 -0
  39. package/templates/core/.context/architecture/decisions/001-template.md +35 -0
  40. package/templates/core/.context/architecture/dependencies.md +35 -0
  41. package/templates/core/.context/architecture/infrastructure.md +42 -0
  42. package/templates/core/.context/architecture/module-graph.md +68 -0
  43. package/templates/core/.context/architecture/overview.md +87 -0
  44. package/templates/core/.context/business/domain-model.md +43 -0
  45. package/templates/core/.context/business/glossary.md +23 -0
  46. package/templates/core/.context/business/overview.md +29 -0
  47. package/templates/core/.context/business/workflows.md +61 -0
  48. package/templates/core/.context/constitution.md +84 -0
  49. package/templates/core/.context/conventions/code-style.md +47 -0
  50. package/templates/core/.context/conventions/error-handling.md +50 -0
  51. package/templates/core/.context/conventions/git.md +46 -0
  52. package/templates/core/.context/conventions/patterns.md +41 -0
  53. package/templates/core/.context/conventions/testing.md +49 -0
  54. package/templates/core/.context/experience/debugging.md +21 -0
  55. package/templates/core/.context/experience/incidents.md +26 -0
  56. package/templates/core/.context/experience/lessons.md +23 -0
  57. package/templates/core/.context/experience/performance.md +29 -0
  58. package/templates/core/.context/index.md +93 -0
  59. package/templates/core/.context/progress/backlog.md +23 -0
  60. package/templates/core/.context/progress/status.md +30 -0
  61. package/templates/core/.context/workflow/artifacts/.gitkeep +0 -0
  62. package/templates/core/.context/workflow/config.md +35 -0
  63. package/templates/core/AGENTS.md +53 -0
  64. package/templates/core/scripts/compact-experience.sh +83 -0
  65. package/templates/core/scripts/detect-drift.sh +388 -0
  66. package/templates/core/scripts/extract-structure.sh +757 -0
  67. package/templates/core/scripts/sync-context.sh +510 -0
  68. package/templates/cursor/.cursor/rules/always.mdc +18 -0
  69. package/templates/cursor/.cursor/rules/backend.mdc +16 -0
  70. package/templates/cursor/.cursor/rules/database.mdc +16 -0
  71. package/templates/cursor/.cursor/rules/frontend.mdc +13 -0
  72. package/templates/cursor/.cursorrules +23 -0
  73. package/templates/github/.github/copilot-instructions.md +15 -0
  74. package/templates/github/.github/workflows/context-drift.yml +73 -0
@@ -0,0 +1,119 @@
1
+ # /dev — Automated Development Workflow Orchestrator
2
+
3
+ > Orchestrates the full software development pipeline: requirements → PRD → task decomposition → dependency analysis → agent execution → quality gate → commit → knowledge capture.
4
+
5
+ ## Usage
6
+
7
+ ```
8
+ /dev # Start full pipeline from P0
9
+ /dev [feature description] # Start with inline requirements
10
+ /dev --from=prd # Resume from a specific phase
11
+ /dev --only=decompose # Run only one phase
12
+ ```
13
+
14
+ ## Pipeline Phases
15
+
16
+ | Phase | Skill | Artifact | Default Checkpoint |
17
+ |-------|-------|----------|--------------------|
18
+ | P0 | `/dev-requirements` | `artifacts/requirements.md` | false |
19
+ | P1 | `/dev-prd` | `artifacts/prd.md` | true |
20
+ | P2 | `/dev-decompose` | `artifacts/tasks.json` | true |
21
+ | P3 | `/dev-deps` | `artifacts/dep-graph.json` | false |
22
+ | P4 | `/dev-execute` | `artifacts/execution-log.md` + code | false |
23
+ | P5 | `/dev-quality` | `artifacts/quality-report.md` | false |
24
+ | P6 | `/dev-commit` | git commits | false |
25
+ | P7 | `/dev-capture` | updated `.context/` files | false |
26
+
27
+ ## Orchestrator Instructions
28
+
29
+ ### Step 1: Load Configuration
30
+
31
+ Read `.context/workflow/config.md` to get:
32
+ - Pipeline phase definitions (which phases to run)
33
+ - Checkpoint settings (where to pause for human review)
34
+ - Execution settings (max parallelism, isolation strategy)
35
+ - Plugin overrides (custom phase implementations)
36
+
37
+ If config.md does not exist, use defaults: all phases enabled, checkpoints after P1 and P2.
38
+
39
+ ### Step 2: Parse Arguments
40
+
41
+ - No arguments → start full pipeline from P0
42
+ - Inline text → treat as requirements input, start from P0 with pre-filled requirements
43
+ - `--from={phase}` → resume from the specified phase (valid values: requirements, prd, decompose, deps, execute, quality, commit, capture)
44
+ - `--only={phase}` → run only the specified phase
45
+
46
+ ### Step 3: Determine Current State
47
+
48
+ Check which artifacts already exist in `.context/workflow/artifacts/`:
49
+ ```
50
+ artifacts/requirements.md exists? → P0 was completed
51
+ artifacts/prd.md exists? → P1 was completed
52
+ artifacts/tasks.json exists? → P2 was completed
53
+ artifacts/dep-graph.json exists? → P3 was completed
54
+ artifacts/execution-log.md exists? → P4 was completed
55
+ artifacts/quality-report.md exists? → P5 was completed
56
+ ```
57
+
58
+ If artifacts from previous phases exist and no `--from` flag is given:
59
+ - Show the user what phases have been completed
60
+ - Ask whether to resume from where it left off or start fresh
61
+ - If starting fresh, delete all existing artifacts first
62
+
63
+ ### Step 4: Resolve Plugin for Each Phase
64
+
65
+ For each phase about to run, resolve the implementation in this priority order:
66
+
67
+ 1. **Config override**: Check `.context/workflow/config.md` "Plugin Overrides" table
68
+ - If override type is `skill`: read the SKILL.md at the specified location and follow its instructions
69
+ - If override type is `mcp`: use the specified MCP server tools
70
+ - If override type is `script`: run the specified script via Bash
71
+ 2. **Convention directory**: Check if `.claude/workflow/phases/{phase-id}/SKILL.md` exists
72
+ - phase-id mapping: P0=requirements, P1=prd, P2=decompose, P3=deps, P4=execute, P5=quality-gate, P6=commit, P7=capture
73
+ 3. **Built-in default**: Use `.claude/skills/dev-{phase}/SKILL.md`
74
+
75
+ ### Step 5: Execute Pipeline
76
+
77
+ For each phase in order:
78
+
79
+ 1. **Announce**: Tell the user which phase is starting (e.g., "Phase 1: Generating PRD...")
80
+ 2. **Execute**: Run the resolved phase implementation
81
+ - For built-in skills: follow the instructions in the corresponding SKILL.md
82
+ - For plugin skills: read and follow the plugin SKILL.md
83
+ - For MCP plugins: call the MCP tools as specified
84
+ - For script plugins: execute via Bash and capture output
85
+ 3. **Validate**: Check that the expected output artifact was produced
86
+ - If not produced, report the error and pause
87
+ 4. **Checkpoint**: If this phase has a checkpoint enabled in config:
88
+ - Display the output artifact to the user
89
+ - Ask the user to review: **Approve** / **Revise** (re-run with feedback) / **Abort**
90
+ - If Revise: re-run the phase incorporating user's feedback
91
+ - If Abort: stop the pipeline, keep all artifacts for later resumption
92
+ 5. **Continue**: Move to the next phase
93
+
94
+ ### Step 6: Completion
95
+
96
+ After all phases complete:
97
+
98
+ 1. Show a summary report:
99
+ ```
100
+ ## Workflow Complete
101
+ - Feature: [name]
102
+ - Tasks executed: [count]
103
+ - Quality: [pass/fail]
104
+ - Commits: [list]
105
+ - Context updated: [yes/no]
106
+ ```
107
+ 2. Ask user if they want to clean up workflow artifacts (delete `.context/workflow/artifacts/*`)
108
+
109
+ ## Error Handling
110
+
111
+ - **Phase failure**: Stop pipeline, show error, preserve artifacts. User can fix and `/dev --from={failed-phase}` to resume.
112
+ - **Quality gate failure**: Attempt one auto-fix retry. If still fails, pause for human guidance.
113
+ - **Merge conflict** (P4 worktree): Show conflict details, pause for human resolution.
114
+
115
+ ## Notes
116
+
117
+ - The orchestrator does NOT implement phase logic itself — it delegates to phase skills
118
+ - Each `/dev-{phase}` skill can also be called independently outside the orchestrator
119
+ - All artifacts are stored in `.context/workflow/artifacts/` for state persistence and resumability
@@ -0,0 +1,111 @@
1
+ # /dev-capture — P7: Knowledge Capture
2
+
3
+ > Updates the .context/ system to reflect changes made during the workflow. Captures experience and updates architecture docs.
4
+
5
+ ## Input
6
+ - All code changes from the current workflow cycle
7
+ - `.context/workflow/artifacts/tasks.json` (from P2)
8
+ - `.context/workflow/artifacts/execution-log.md` (from P4)
9
+ - Context: Full `.context/` system
10
+
11
+ ## Output
12
+ - Updated `.context/` files (architecture, conventions, experience, progress)
13
+
14
+ ## Instructions
15
+
16
+ ### Step 1: Analyze Changes
17
+
18
+ 1. **Collect all changed files** using a combined approach:
19
+ - Committed changes: `git diff --name-only HEAD~1..HEAD` (or appropriate range)
20
+ - Staged changes: `git diff --name-only --cached`
21
+ - Unstaged changes: `git diff --name-only`
22
+ - Untracked new files: `git ls-files --others --exclude-standard`
23
+ - **Union all results** into a single deduplicated changed-files list
24
+ 2. Read `.context/workflow/artifacts/tasks.json` for task metadata
25
+ 3. Read `.context/workflow/artifacts/execution-log.md` for execution details
26
+
27
+ ### Step 2: Determine What Needs Updating
28
+
29
+ Use the mapping from `.claude/rules/context-maintenance.md`:
30
+
31
+ | If changes include... | Then update... |
32
+ |----------------------|----------------|
33
+ | Database models, migrations, schema files | `.context/architecture/data-model.md` |
34
+ | API routes, controllers, endpoints | `.context/architecture/api-surface.md` |
35
+ | Package manifests (package.json, *.csproj, etc.) | `.context/architecture/dependencies.md` |
36
+ | System architecture, major structural changes | `.context/architecture/overview.md` |
37
+ | Module boundaries, added/removed/moved modules | `.context/architecture/module-graph.md` |
38
+ | Data pipelines, processing flows, threading | `.context/architecture/data-flow.md` |
39
+ | Core classes, interfaces, inheritance hierarchies | `.context/architecture/class-index.md` |
40
+ | CI/CD configs, Docker files, deployment configs | `.context/architecture/infrastructure.md` |
41
+ | New design patterns introduced | `.context/conventions/patterns.md` |
42
+ | Changed error handling approach | `.context/conventions/error-handling.md` |
43
+
44
+ ### Step 3: Regenerate Auto-Generated Files
45
+
46
+ **ALWAYS regenerate these files unconditionally** — they are cheap to rebuild:
47
+ 1. Run `scripts/extract-structure.sh --class-index` → regenerate `architecture/class-index.md`
48
+ 2. Run `scripts/extract-structure.sh --module-graph` → regenerate auto-generated sections of `architecture/module-graph.md`
49
+ 3. Run `scripts/sync-context.sh` → regenerate `architecture/dependencies.md`
50
+ 4. For `data-model.md` and `api-surface.md`: if the changed-files list includes relevant patterns, analyze and update
51
+
52
+ ### Step 4: Update Human-Maintained Files
53
+
54
+ For files that require human judgment:
55
+ - Read the current file content
56
+ - Identify what sections need updating based on the changes
57
+ - Make targeted edits (don't rewrite the whole file)
58
+ - Preserve existing content that hasn't changed
59
+
60
+ ### Step 5: Capture Experience (if applicable)
61
+
62
+ Check if any of these apply:
63
+
64
+ **Non-trivial bug fixed during execution?**
65
+ → Append to `.context/experience/debugging.md`:
66
+ ```markdown
67
+ ### "[Error/Symptom]"
68
+ - **Cause**: [Why this happened]
69
+ - **Fix**: [How it was resolved]
70
+ - **Prevention**: [How to avoid in future]
71
+ ```
72
+
73
+ **Significant architectural decision made?**
74
+ → Create a new ADR in `.context/architecture/decisions/`:
75
+ - Find the next available number
76
+ - Use the template from `001-template.md`
77
+
78
+ **New pattern or anti-pattern discovered?**
79
+ → Append to `.context/experience/lessons.md`
80
+
81
+ ### Step 6: Update Progress
82
+
83
+ Update `.context/progress/status.md` with:
84
+ - What was completed in this workflow cycle
85
+ - The feature name and task IDs
86
+ - Date of completion
87
+
88
+ ### Step 7: Cleanup (Optional)
89
+
90
+ Ask the user whether to:
91
+ - **Keep** workflow artifacts (for reference/debugging)
92
+ - **Clean** workflow artifacts (delete `.context/workflow/artifacts/*` except `.gitkeep`)
93
+
94
+ ### Step 8: Report
95
+
96
+ Show a summary:
97
+ ```
98
+ ## Knowledge Capture Summary
99
+
100
+ ### Context Files Updated
101
+ - [list of .context/ files that were updated]
102
+
103
+ ### Experience Captured
104
+ - [any debugging/lessons/ADR entries added]
105
+
106
+ ### Progress Updated
107
+ - [what was recorded in status.md]
108
+
109
+ ### Artifacts
110
+ - [kept/cleaned]
111
+ ```
@@ -0,0 +1,90 @@
1
+ # /dev-commit — P6: Commit & Integration
2
+
3
+ > Creates well-structured git commits for the workflow's code changes, following project conventions.
4
+
5
+ ## Input
6
+ - Verified code changes (in the working tree, quality-checked)
7
+ - `.context/workflow/artifacts/quality-report.md` (from P5)
8
+ - `.context/workflow/artifacts/tasks.json` (from P2)
9
+ - Context: `.context/conventions/git.md`
10
+
11
+ ## Output
12
+ - Git commits (one or more)
13
+
14
+ ## Instructions
15
+
16
+ ### Step 1: Load Context
17
+
18
+ 1. Read `.context/conventions/git.md` to understand the project's git conventions:
19
+ - Branch naming strategy
20
+ - Commit message format (conventional commits, etc.)
21
+ - PR process
22
+ 2. Read `.context/workflow/artifacts/tasks.json` to get task IDs and titles
23
+ 3. Read `.context/workflow/artifacts/quality-report.md` to confirm quality status
24
+ 4. If quality report shows FAIL, **stop** — do not commit failing code. Report this to the user.
25
+
26
+ ### Step 2: Review Changes
27
+
28
+ Run `git status` and `git diff` to see all changes made during the workflow.
29
+
30
+ Categorize changes:
31
+ - Which task produced which file changes (cross-reference with tasks.json `files_to_modify` / `files_to_create`)
32
+ - Are there any unexpected changes (files not in any task's scope)?
33
+
34
+ ### Step 3: Determine Commit Strategy
35
+
36
+ Based on the project's git conventions and the nature of changes:
37
+
38
+ **Option A — Single commit** (default for MVP):
39
+ - Stage all changes
40
+ - Write a commit message that summarizes the feature with task references
41
+
42
+ **Option B — Per-task commits** (if project conventions prefer atomic commits):
43
+ - Stage and commit changes for each task separately
44
+ - Each commit message references the task ID
45
+
46
+ Use the commit message format from `conventions/git.md`. If no convention is defined, use:
47
+ ```
48
+ feat: [feature description]
49
+
50
+ Tasks completed:
51
+ - T1: [title]
52
+ - T2: [title]
53
+ ...
54
+ ```
55
+
56
+ ### Step 4: Create Commits
57
+
58
+ **Important rules:**
59
+ - Do NOT push to remote — the user decides when to push
60
+ - Do NOT use `--no-verify` — let pre-commit hooks run
61
+ - Do NOT amend existing commits
62
+ - Check for files that should NOT be committed (.env, credentials, large binaries)
63
+ - Use `git add` with specific file paths, not `git add -A`
64
+
65
+ Stage and commit:
66
+ ```bash
67
+ git add [specific files]
68
+ git commit -m "[message]"
69
+ ```
70
+
71
+ If pre-commit hooks fail:
72
+ - Read the hook output
73
+ - Fix the issue (formatting, lint, etc.)
74
+ - Stage the fixes
75
+ - Create a NEW commit (do not amend)
76
+
77
+ ### Step 5: Report
78
+
79
+ Show the user:
80
+ ```
81
+ ## Commits Created
82
+
83
+ - [commit hash] [commit message]
84
+ - ...
85
+
86
+ Branch: [current branch name]
87
+ Push status: NOT pushed (run `git push` when ready)
88
+ ```
89
+
90
+ If running independently, confirm with the user before creating commits.
@@ -0,0 +1,113 @@
1
+ # /dev-decompose — P2: Task Decomposition
2
+
3
+ > Breaks a PRD into discrete, actionable development tasks with file scope and acceptance criteria.
4
+
5
+ ## Input
6
+ - `.context/workflow/artifacts/prd.md` (from P1)
7
+ - Context: `.context/architecture/overview.md`, `.context/architecture/module-graph.md`, `.context/conventions/patterns.md`
8
+
9
+ ## Output
10
+ - `.context/workflow/artifacts/tasks.json`
11
+
12
+ ## Instructions
13
+
14
+ ### Step 1: Load Inputs
15
+
16
+ 1. Read `.context/workflow/artifacts/prd.md` — the PRD from P1
17
+ 2. Read the following context files (skip any that don't exist):
18
+ - `.context/architecture/overview.md` — system architecture and tech stack
19
+ - `.context/architecture/module-graph.md` — module dependencies
20
+ - `.context/architecture/data-model.md` — current data model
21
+ - `.context/architecture/api-surface.md` — current API surface
22
+ - `.context/architecture/class-index.md` — core classes and interfaces
23
+ - `.context/conventions/patterns.md` — design patterns used in the project
24
+ - `.context/conventions/testing.md` — testing strategy and conventions
25
+ - `.context/conventions/code-style.md` — coding conventions
26
+
27
+ ### Step 2: Analyze the Codebase
28
+
29
+ Use Glob and Grep to understand the relevant parts of the codebase:
30
+ - Identify which files and directories correspond to the modules mentioned in the PRD
31
+ - Find existing code that will need modification
32
+ - Identify patterns used in similar features
33
+ - Locate existing tests for affected areas
34
+
35
+ ### Step 3: Decompose into Tasks
36
+
37
+ Break the PRD's functional requirements into tasks. For each task:
38
+
39
+ 1. **Keep tasks atomic**: Each task should be completable by a single agent in one session
40
+ 2. **Define file scope**: List specific files that need modification or creation
41
+ 3. **Set dependencies**: Identify which tasks must complete before others can start
42
+ 4. **Write acceptance criteria**: Make them specific and testable
43
+ 5. **Specify test requirements**: What tests should be written
44
+
45
+ **Task sizing guidance:**
46
+ - `small`: Single file change, < 50 lines, straightforward
47
+ - `medium`: 2-5 files, 50-200 lines, follows existing patterns
48
+ - `large`: 5+ files, 200+ lines, may require new patterns or significant refactoring
49
+
50
+ **Task type guidance:**
51
+ - `feature`: New functionality
52
+ - `bugfix`: Fix broken behavior
53
+ - `refactor`: Restructure without changing behavior
54
+ - `test`: Add or improve tests
55
+ - `docs`: Documentation changes
56
+ - `infra`: CI/CD, build, deployment changes
57
+
58
+ ### Step 4: Generate tasks.json
59
+
60
+ Write `.context/workflow/artifacts/tasks.json` following this schema:
61
+
62
+ ```json
63
+ {
64
+ "feature": "feature-name-kebab-case",
65
+ "created_at": "ISO-8601 timestamp",
66
+ "source_prd": ".context/workflow/artifacts/prd.md",
67
+ "tasks": [
68
+ {
69
+ "id": "T1",
70
+ "title": "Short imperative title",
71
+ "description": "What to implement, why, and key implementation notes",
72
+ "type": "feature",
73
+ "scope": "backend",
74
+ "files_to_modify": ["src/path/to/file.ts"],
75
+ "files_to_create": ["src/path/to/new-file.ts"],
76
+ "depends_on": [],
77
+ "acceptance_criteria": [
78
+ "Specific testable criterion 1",
79
+ "Specific testable criterion 2"
80
+ ],
81
+ "context_files": ["architecture/api-surface.md"],
82
+ "complexity": "medium",
83
+ "test_requirements": "Unit tests for [what], integration test for [what]"
84
+ }
85
+ ]
86
+ }
87
+ ```
88
+
89
+ ### Step 5: Validate Task List
90
+
91
+ Check for:
92
+ - **Coverage**: Every functional requirement in the PRD maps to at least one task
93
+ - **No orphan dependencies**: All `depends_on` IDs reference existing tasks
94
+ - **File scope clarity**: Every task has at least one file to modify or create
95
+ - **No circular dependencies**: The dependency graph is a DAG
96
+ - **Reasonable sizing**: No single task has complexity `large` with 10+ files (split it)
97
+
98
+ ### Step 6: Present Summary
99
+
100
+ Show a human-readable summary of the task breakdown:
101
+
102
+ ```
103
+ ## Task Breakdown: [Feature Name]
104
+ Total tasks: N
105
+
106
+ | ID | Title | Type | Complexity | Depends On |
107
+ |----|-------|------|-----------|------------|
108
+ | T1 | ... | feature | medium | — |
109
+ | T2 | ... | feature | small | T1 |
110
+ | T3 | ... | test | small | T1 |
111
+ ```
112
+
113
+ If running independently, ask the user for feedback and update the artifact.
@@ -0,0 +1,108 @@
1
+ # /dev-deps — P3: Dependency Analysis
2
+
3
+ > Analyzes task dependencies and file overlap to produce an execution plan with parallel groups and isolation strategy.
4
+
5
+ ## Input
6
+ - `.context/workflow/artifacts/tasks.json` (from P2)
7
+ - Context: `.context/architecture/module-graph.md`
8
+
9
+ ## Output
10
+ - `.context/workflow/artifacts/dep-graph.json`
11
+
12
+ ## Instructions
13
+
14
+ ### Step 1: Load Tasks
15
+
16
+ Read `.context/workflow/artifacts/tasks.json` to get the full task list with dependencies and file scopes.
17
+
18
+ Optionally read `.context/architecture/module-graph.md` for module-level dependency information.
19
+
20
+ ### Step 2: Build Dependency Graph
21
+
22
+ 1. Parse the `depends_on` field of each task to build a directed acyclic graph (DAG)
23
+ 2. Verify there are no circular dependencies — if found, report the cycle and stop
24
+ 3. Perform topological sort to determine execution order
25
+
26
+ ### Step 3: Identify Parallel Groups
27
+
28
+ Group tasks into execution waves (parallel groups):
29
+
30
+ 1. **Group 1**: All tasks with no dependencies (`depends_on: []`)
31
+ 2. **Group 2**: All tasks whose dependencies are entirely in Group 1
32
+ 3. **Group N**: All tasks whose dependencies are entirely in Groups 1 through N-1
33
+
34
+ Tasks in the same group can potentially execute in parallel.
35
+
36
+ ### Step 4: Analyze File Overlap (Isolation Strategy)
37
+
38
+ For each parallel group, check file overlap between tasks:
39
+
40
+ 1. For each pair of tasks (Ti, Tj) in the same group:
41
+ - Compute the intersection of `files_to_modify` ∪ `files_to_create`
42
+ - If intersection is empty → both tasks can use `isolation: "none"` (direct parallel)
43
+ - If intersection is non-empty → record the conflict, assign `isolation: "worktree"` to one or both
44
+
45
+ 2. **Isolation decision logic**:
46
+ - If no files overlap in the group → all tasks get `isolation: "none"`
47
+ - If some files overlap → tasks involved in overlap get `isolation: "worktree"`, others get `"none"`
48
+
49
+ 3. Read the `max_parallel_agents` setting from `.context/workflow/config.md` (default: 3)
50
+ - If a group has more tasks than `max_parallel_agents`, split into sub-groups
51
+
52
+ ### Step 5: Compute Critical Path
53
+
54
+ The critical path is the longest sequence of dependent tasks by total complexity weight:
55
+ - `small` = 1, `medium` = 2, `large` = 3
56
+ - Critical path = the dependency chain with the highest total weight
57
+
58
+ ### Step 6: Generate dep-graph.json
59
+
60
+ Write `.context/workflow/artifacts/dep-graph.json`:
61
+
62
+ ```json
63
+ {
64
+ "groups": [
65
+ {
66
+ "order": 1,
67
+ "tasks": ["T1", "T2"],
68
+ "isolation": {
69
+ "T1": "none",
70
+ "T2": "none"
71
+ }
72
+ },
73
+ {
74
+ "order": 2,
75
+ "tasks": ["T3", "T4"],
76
+ "isolation": {
77
+ "T3": "worktree",
78
+ "T4": "none"
79
+ }
80
+ }
81
+ ],
82
+ "critical_path": ["T1", "T3"],
83
+ "file_conflicts": {
84
+ "T3-T4": ["src/shared/utils.ts"]
85
+ },
86
+ "total_groups": 2,
87
+ "max_parallelism": 2
88
+ }
89
+ ```
90
+
91
+ ### Step 7: Present Summary
92
+
93
+ Show the execution plan:
94
+
95
+ ```
96
+ ## Execution Plan
97
+
98
+ ### Group 1 (parallel)
99
+ - T1: [title] (no isolation)
100
+ - T2: [title] (no isolation)
101
+
102
+ ### Group 2 (parallel with isolation)
103
+ - T3: [title] (worktree — conflicts with T4 on src/shared/utils.ts)
104
+ - T4: [title] (no isolation)
105
+
106
+ Critical path: T1 → T3 (weight: 4)
107
+ Estimated parallelism: 2 agents max
108
+ ```