@trespies-source/dojo-genesis-plugin 1.0.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 (209) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/LICENSE +21 -0
  3. package/README.md +204 -0
  4. package/dist/hooks/after-tool-call/handler.d.ts +4 -0
  5. package/dist/hooks/after-tool-call/handler.d.ts.map +1 -0
  6. package/dist/hooks/after-tool-call/handler.js +37 -0
  7. package/dist/hooks/after-tool-call/handler.js.map +1 -0
  8. package/dist/hooks/agent-end/handler.d.ts +4 -0
  9. package/dist/hooks/agent-end/handler.d.ts.map +1 -0
  10. package/dist/hooks/agent-end/handler.js +16 -0
  11. package/dist/hooks/agent-end/handler.js.map +1 -0
  12. package/dist/hooks/before-agent-start/handler.d.ts +4 -0
  13. package/dist/hooks/before-agent-start/handler.d.ts.map +1 -0
  14. package/dist/hooks/before-agent-start/handler.js +81 -0
  15. package/dist/hooks/before-agent-start/handler.js.map +1 -0
  16. package/dist/index.d.ts +18 -0
  17. package/dist/index.d.ts.map +1 -0
  18. package/dist/index.js +35 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/src/commands/archive.d.ts +4 -0
  21. package/dist/src/commands/archive.d.ts.map +1 -0
  22. package/dist/src/commands/archive.js +20 -0
  23. package/dist/src/commands/archive.js.map +1 -0
  24. package/dist/src/commands/init.d.ts +4 -0
  25. package/dist/src/commands/init.d.ts.map +1 -0
  26. package/dist/src/commands/init.js +57 -0
  27. package/dist/src/commands/init.js.map +1 -0
  28. package/dist/src/commands/list.d.ts +4 -0
  29. package/dist/src/commands/list.d.ts.map +1 -0
  30. package/dist/src/commands/list.js +9 -0
  31. package/dist/src/commands/list.js.map +1 -0
  32. package/dist/src/commands/router.d.ts +3 -0
  33. package/dist/src/commands/router.d.ts.map +1 -0
  34. package/dist/src/commands/router.js +83 -0
  35. package/dist/src/commands/router.js.map +1 -0
  36. package/dist/src/commands/skill-invoke.d.ts +4 -0
  37. package/dist/src/commands/skill-invoke.d.ts.map +1 -0
  38. package/dist/src/commands/skill-invoke.js +26 -0
  39. package/dist/src/commands/skill-invoke.js.map +1 -0
  40. package/dist/src/commands/status.d.ts +4 -0
  41. package/dist/src/commands/status.d.ts.map +1 -0
  42. package/dist/src/commands/status.js +42 -0
  43. package/dist/src/commands/status.js.map +1 -0
  44. package/dist/src/commands/switch.d.ts +4 -0
  45. package/dist/src/commands/switch.d.ts.map +1 -0
  46. package/dist/src/commands/switch.js +20 -0
  47. package/dist/src/commands/switch.js.map +1 -0
  48. package/dist/src/orchestration/tool-registry.d.ts +18 -0
  49. package/dist/src/orchestration/tool-registry.d.ts.map +1 -0
  50. package/dist/src/orchestration/tool-registry.js +153 -0
  51. package/dist/src/orchestration/tool-registry.js.map +1 -0
  52. package/dist/src/skills/catalog.d.ts +9 -0
  53. package/dist/src/skills/catalog.d.ts.map +1 -0
  54. package/dist/src/skills/catalog.js +251 -0
  55. package/dist/src/skills/catalog.js.map +1 -0
  56. package/dist/src/state/manager.d.ts +19 -0
  57. package/dist/src/state/manager.d.ts.map +1 -0
  58. package/dist/src/state/manager.js +114 -0
  59. package/dist/src/state/manager.js.map +1 -0
  60. package/dist/src/state/migrations.d.ts +3 -0
  61. package/dist/src/state/migrations.d.ts.map +1 -0
  62. package/dist/src/state/migrations.js +8 -0
  63. package/dist/src/state/migrations.js.map +1 -0
  64. package/dist/src/state/types.d.ts +62 -0
  65. package/dist/src/state/types.d.ts.map +1 -0
  66. package/dist/src/state/types.js +2 -0
  67. package/dist/src/state/types.js.map +1 -0
  68. package/dist/src/ui/chat-formatter.d.ts +11 -0
  69. package/dist/src/ui/chat-formatter.d.ts.map +1 -0
  70. package/dist/src/ui/chat-formatter.js +39 -0
  71. package/dist/src/ui/chat-formatter.js.map +1 -0
  72. package/dist/src/utils/file-ops.d.ts +6 -0
  73. package/dist/src/utils/file-ops.d.ts.map +1 -0
  74. package/dist/src/utils/file-ops.js +38 -0
  75. package/dist/src/utils/file-ops.js.map +1 -0
  76. package/dist/src/utils/markdown.d.ts +2 -0
  77. package/dist/src/utils/markdown.d.ts.map +1 -0
  78. package/dist/src/utils/markdown.js +11 -0
  79. package/dist/src/utils/markdown.js.map +1 -0
  80. package/dist/src/utils/validation.d.ts +7 -0
  81. package/dist/src/utils/validation.d.ts.map +1 -0
  82. package/dist/src/utils/validation.js +29 -0
  83. package/dist/src/utils/validation.js.map +1 -0
  84. package/dist/tests/__mocks__/openclaw-types.d.ts +54 -0
  85. package/dist/tests/__mocks__/openclaw-types.d.ts.map +1 -0
  86. package/dist/tests/__mocks__/openclaw-types.js +29 -0
  87. package/dist/tests/__mocks__/openclaw-types.js.map +1 -0
  88. package/hooks/after-tool-call/HOOK.md +7 -0
  89. package/hooks/after-tool-call/handler.ts +41 -0
  90. package/hooks/agent-end/HOOK.md +7 -0
  91. package/hooks/agent-end/handler.ts +18 -0
  92. package/hooks/before-agent-start/HOOK.md +7 -0
  93. package/hooks/before-agent-start/handler.ts +133 -0
  94. package/openclaw.plugin.json +19 -0
  95. package/package.json +61 -0
  96. package/skills/agent-teaching/SKILL.md +583 -0
  97. package/skills/agent-teaching/claw.json +12 -0
  98. package/skills/compression-ritual/SKILL.md +136 -0
  99. package/skills/compression-ritual/claw.json +12 -0
  100. package/skills/context-ingestion/SKILL.md +109 -0
  101. package/skills/context-ingestion/claw.json +12 -0
  102. package/skills/decision-propagation/SKILL.md +130 -0
  103. package/skills/decision-propagation/claw.json +12 -0
  104. package/skills/documentation-audit/SKILL.md +146 -0
  105. package/skills/documentation-audit/claw.json +12 -0
  106. package/skills/era-architecture/SKILL.md +166 -0
  107. package/skills/era-architecture/claw.json +12 -0
  108. package/skills/file-management/SKILL.md +127 -0
  109. package/skills/file-management/claw.json +12 -0
  110. package/skills/frontend-from-backend/SKILL.md +127 -0
  111. package/skills/frontend-from-backend/claw.json +12 -0
  112. package/skills/handoff-protocol/SKILL.md +168 -0
  113. package/skills/handoff-protocol/claw.json +12 -0
  114. package/skills/health-audit/SKILL.md +123 -0
  115. package/skills/health-audit/claw.json +12 -0
  116. package/skills/implementation-prompt/SKILL.md +361 -0
  117. package/skills/implementation-prompt/claw.json +12 -0
  118. package/skills/iterative-scouting/SKILL.md +106 -0
  119. package/skills/iterative-scouting/claw.json +12 -0
  120. package/skills/memory-garden/SKILL.md +470 -0
  121. package/skills/memory-garden/claw.json +12 -0
  122. package/skills/multi-surface-strategy/SKILL.md +288 -0
  123. package/skills/multi-surface-strategy/claw.json +12 -0
  124. package/skills/parallel-tracks/SKILL.md +152 -0
  125. package/skills/parallel-tracks/claw.json +12 -0
  126. package/skills/patient-learning-protocol/SKILL.md +438 -0
  127. package/skills/patient-learning-protocol/claw.json +12 -0
  128. package/skills/planning-with-files/SKILL.md +139 -0
  129. package/skills/planning-with-files/claw.json +12 -0
  130. package/skills/pre-implementation-checklist/SKILL.md +156 -0
  131. package/skills/pre-implementation-checklist/claw.json +12 -0
  132. package/skills/process-extraction/SKILL.md +148 -0
  133. package/skills/process-extraction/claw.json +12 -0
  134. package/skills/process-extraction/references/process_example_template.md +40 -0
  135. package/skills/product-positioning/SKILL.md +293 -0
  136. package/skills/product-positioning/claw.json +12 -0
  137. package/skills/project-exploration/SKILL.md +168 -0
  138. package/skills/project-exploration/claw.json +12 -0
  139. package/skills/release-specification/SKILL.md +645 -0
  140. package/skills/release-specification/claw.json +12 -0
  141. package/skills/repo-context-sync/SKILL.md +362 -0
  142. package/skills/repo-context-sync/claw.json +12 -0
  143. package/skills/repo-context-sync/references/file_hierarchy_patterns.md +186 -0
  144. package/skills/repo-context-sync/references/zenflow_repo_patterns.md +328 -0
  145. package/skills/repo-context-sync/scripts/context_mapper.py +251 -0
  146. package/skills/repo-context-sync/scripts/diff_tracker.py +187 -0
  147. package/skills/repo-context-sync/scripts/smart_clone.sh +52 -0
  148. package/skills/repo-context-sync/templates/context_summary.md +58 -0
  149. package/skills/repo-status/SKILL.md +240 -0
  150. package/skills/repo-status/claw.json +12 -0
  151. package/skills/repo-status/references/semantic-clusters.md +159 -0
  152. package/skills/repo-status/references/status-template.md +214 -0
  153. package/skills/research-modes/SKILL.md +515 -0
  154. package/skills/research-modes/claw.json +12 -0
  155. package/skills/research-synthesis/SKILL.md +110 -0
  156. package/skills/research-synthesis/claw.json +12 -0
  157. package/skills/retrospective/SKILL.md +152 -0
  158. package/skills/retrospective/claw.json +12 -0
  159. package/skills/seed-extraction/SKILL.md +419 -0
  160. package/skills/seed-extraction/claw.json +12 -0
  161. package/skills/seed-library/SKILL.md +424 -0
  162. package/skills/seed-library/claw.json +12 -0
  163. package/skills/seed-library/references/seed_catalog.md +171 -0
  164. package/skills/seed-library/scripts/apply_seed.py +129 -0
  165. package/skills/seed-library/scripts/suggest_seeds.py +183 -0
  166. package/skills/seed-library/seeds/01_three_tiered_governance.md +90 -0
  167. package/skills/seed-library/seeds/02_harness_trace.md +135 -0
  168. package/skills/seed-library/seeds/03_context_iceberg.md +120 -0
  169. package/skills/seed-library/seeds/04_agent_connect.md +106 -0
  170. package/skills/seed-library/seeds/05_go_live_bundles.md +40 -0
  171. package/skills/seed-library/seeds/06_cost_guard.md +40 -0
  172. package/skills/seed-library/seeds/07_safety_switch.md +41 -0
  173. package/skills/seed-library/seeds/08_implicit_perspective_extraction.md +41 -0
  174. package/skills/seed-library/seeds/09_mode_based_complexity_gating.md +46 -0
  175. package/skills/seed-library/seeds/10_shared_infrastructure.md +75 -0
  176. package/skills/seed-library/seeds/11_voice_before_structure.md +74 -0
  177. package/skills/seed-library/seeds/12_pointer_directories.md +81 -0
  178. package/skills/seed-library/seeds/13_granular_visibility.md +82 -0
  179. package/skills/seed-library/seeds/meta_governance_multiplies_velocity.md +43 -0
  180. package/skills/seed-to-skill-converter/SKILL.md +113 -0
  181. package/skills/seed-to-skill-converter/claw.json +12 -0
  182. package/skills/semantic-clusters/SKILL.md +246 -0
  183. package/skills/semantic-clusters/claw.json +12 -0
  184. package/skills/semantic-clusters/references/verb-catalog.md +267 -0
  185. package/skills/skill-audit-upgrade/SKILL.md +427 -0
  186. package/skills/skill-audit-upgrade/claw.json +12 -0
  187. package/skills/skill-creation/LICENSE.txt +202 -0
  188. package/skills/skill-creation/SKILL.md +252 -0
  189. package/skills/skill-creation/claw.json +12 -0
  190. package/skills/skill-creation/references/output-patterns.md +82 -0
  191. package/skills/skill-creation/references/progressive-disclosure-patterns.md +79 -0
  192. package/skills/skill-creation/references/workflows.md +28 -0
  193. package/skills/skill-creation/scripts/init_skill.py +305 -0
  194. package/skills/skill-creation/scripts/quick_validate.py +134 -0
  195. package/skills/skill-maintenance/SKILL.md +413 -0
  196. package/skills/skill-maintenance/claw.json +12 -0
  197. package/skills/spec-constellation-to-prompt-suite/SKILL.md +174 -0
  198. package/skills/spec-constellation-to-prompt-suite/claw.json +12 -0
  199. package/skills/status-template/SKILL.md +211 -0
  200. package/skills/status-template/claw.json +12 -0
  201. package/skills/status-template/references/complete-template.md +191 -0
  202. package/skills/status-writing/SKILL.md +161 -0
  203. package/skills/status-writing/claw.json +12 -0
  204. package/skills/strategic-scout/SKILL.md +163 -0
  205. package/skills/strategic-scout/claw.json +12 -0
  206. package/skills/strategic-to-tactical-workflow/SKILL.md +391 -0
  207. package/skills/strategic-to-tactical-workflow/claw.json +12 -0
  208. package/skills/workspace-navigation/SKILL.md +622 -0
  209. package/skills/workspace-navigation/claw.json +12 -0
@@ -0,0 +1,328 @@
1
+ # Zenflow Repository Patterns
2
+
3
+ This document describes how to work effectively with Zenflow's Git worktree-based workflow and how to integrate with existing codebases.
4
+
5
+ ## Core Concept: Worktrees
6
+
7
+ Zenflow uses **Git worktrees** to isolate each task in its own directory with a dedicated branch. This prevents interference between concurrent tasks and enables clean, atomic development.
8
+
9
+ ### Worktree Structure
10
+
11
+ ```
12
+ project-root/
13
+ ├── .git/ # Shared Git database
14
+ ├── .zenflow/
15
+ │ ├── tasks/
16
+ │ │ ├── task_001/ # Worktree for task 001
17
+ │ │ │ ├── plan.md
18
+ │ │ │ ├── spec.md
19
+ │ │ │ ├── implementation.md
20
+ │ │ │ └── [project files]
21
+ │ │ ├── task_002/ # Worktree for task 002
22
+ │ │ │ └── ...
23
+ │ └── workflows/ # Custom workflow templates
24
+ │ ├── quick_change.md
25
+ │ ├── fix_bug.md
26
+ │ └── spec_and_build.md
27
+ ├── src/ # Main project source
28
+ └── [other project files]
29
+ ```
30
+
31
+ ### Key Rules
32
+
33
+ 1. **One worktree per task** - Each task gets its own isolated directory
34
+ 2. **Don't manually manage worktrees** - Let Zenflow handle `git worktree add/remove`
35
+ 3. **Don't edit inside `.zenflow/tasks/` directly** - Use Zenflow's "Open in IDE" feature
36
+ 4. **Archive completed tasks** - Reclaim disk space by archiving finished work
37
+ 5. **All worktrees share `.git`** - Tags, branches, and config are shared
38
+
39
+ ## Built-in Workflow Types
40
+
41
+ Zenflow ships with four starter workflow types, each with its own artifact set:
42
+
43
+ ### 1. Quick Change
44
+ **Use for:** Small, single-step changes
45
+ **Artifacts:**
46
+ - `plan.md` - Brief description of the change
47
+
48
+ **When to use:** Bug fixes, typo corrections, minor refactors
49
+
50
+ ### 2. Fix Bug
51
+ **Use for:** Debugging and fixing issues
52
+ **Artifacts:**
53
+ - `plan.md` - Bug description and approach
54
+ - `investigation.md` - Root cause analysis
55
+ - `solution.md` - Proposed solution
56
+ - `implementation.md` - Implementation details
57
+
58
+ **When to use:** Investigating and fixing bugs
59
+
60
+ ### 3. Spec and Build
61
+ **Use for:** Feature development with specification
62
+ **Artifacts:**
63
+ - `plan.md` - High-level plan
64
+ - `spec.md` - Technical specification
65
+
66
+ **When to use:** New features that need upfront design
67
+
68
+ ### 4. Full SDD Workflow
69
+ **Use for:** Complex features with full software design document
70
+ **Artifacts:**
71
+ - `requirements.md` - Requirements gathering
72
+ - `spec.md` - Detailed technical spec
73
+ - `plan.md` - Implementation plan
74
+ - Plus verifier stages
75
+
76
+ **When to use:** Major features or architectural changes
77
+
78
+ ## Workflow Artifacts and File Hierarchy
79
+
80
+ Zenflow's workflow artifacts map to the standard file hierarchy:
81
+
82
+ | Zenflow Artifact | Standard Hierarchy Equivalent |
83
+ |------------------|------------------------------|
84
+ | `plan.md` | `/00_Roadmap/task_plan.md` |
85
+ | `requirements.md` | `/01_PRDs/{feature}_prd.md` |
86
+ | `spec.md` | `/02_Specs/{feature}_spec.md` |
87
+ | `implementation.md` | Development notes in `/05_Logs/` |
88
+
89
+ ## Best Practices for Reading Existing Codebases
90
+
91
+ When Zenflow (or you) work with an existing codebase, follow these principles:
92
+
93
+ ### 1. Read Before You Write
94
+
95
+ **Always** scan the existing codebase before generating new code. This ensures:
96
+ - Consistency with existing patterns
97
+ - Reuse of existing utilities
98
+ - Minimal refactoring needed
99
+
100
+ **How to read:**
101
+ ```bash
102
+ # Use context_mapper.py to get an overview
103
+ python3.11 context_mapper.py /path/to/repo [keywords]
104
+
105
+ # Check for standard hierarchy
106
+ ls -la /path/to/repo/0*_*/
107
+
108
+ # Look for existing patterns
109
+ grep -r "pattern_name" /path/to/repo/
110
+ ```
111
+
112
+ ### 2. Follow Existing Patterns
113
+
114
+ **Naming conventions:**
115
+ - If the repo uses `camelCase`, continue using `camelCase`
116
+ - If the repo uses `snake_case`, continue using `snake_case`
117
+
118
+ **Import structure:**
119
+ - Match the existing import order (e.g., stdlib → third-party → local)
120
+ - Use the same import style (e.g., `import X` vs `from X import Y`)
121
+
122
+ **Architecture:**
123
+ - Follow existing component structure
124
+ - Use existing state management patterns
125
+ - Integrate with existing API patterns
126
+
127
+ ### 3. Integrate Cleanly
128
+
129
+ **Avoid:**
130
+ - Creating parallel implementations of existing utilities
131
+ - Introducing new dependencies when existing ones can be used
132
+ - Breaking existing conventions
133
+
134
+ **Prefer:**
135
+ - Extending existing components
136
+ - Reusing existing utilities
137
+ - Adding to existing patterns
138
+
139
+ ### 4. Minimize Refactoring
140
+
141
+ **Only refactor when:**
142
+ - The existing code is clearly broken
143
+ - The refactor is explicitly part of the task
144
+ - The refactor is minimal and localized
145
+
146
+ **Otherwise:**
147
+ - Work with the existing structure
148
+ - Note technical debt in comments or logs
149
+ - Suggest refactoring as a separate task
150
+
151
+ ## Zenflow Automation Protocol
152
+
153
+ When working with Zenflow, define these four fields for each project:
154
+
155
+ ### 1. Setup Script
156
+ **Purpose:** Install all dependencies
157
+ **Example:**
158
+ ```bash
159
+ npm install && pip install -r requirements.txt
160
+ ```
161
+
162
+ ### 2. Dev Server Script
163
+ **Purpose:** Start development server(s)
164
+ **Example:**
165
+ ```bash
166
+ concurrently "npm run dev" "uvicorn main:app --reload"
167
+ ```
168
+
169
+ ### 3. Cleanup Script
170
+ **Purpose:** Lint and test before commit
171
+ **Example:**
172
+ ```bash
173
+ npm run lint && npm run test && ruff check . && pytest
174
+ ```
175
+
176
+ ### 4. Copy Files
177
+ **Purpose:** Environment configuration files to copy into each worktree
178
+ **Example:**
179
+ ```
180
+ .env.local, .env, .npmrc
181
+ ```
182
+
183
+ ## Working with Zenflow Tasks
184
+
185
+ ### Task Lifecycle
186
+
187
+ 1. **Create Task** - Zenflow creates worktree and branch
188
+ 2. **Agent Execution** - AI agent reads codebase, generates code, commits
189
+ 3. **Review** - Human reviews changes in worktree
190
+ 4. **Merge** - Changes merged back to main branch
191
+ 5. **Archive** - Worktree cleaned up
192
+
193
+ ### Accessing Task Context
194
+
195
+ When writing prompts for Zenflow, you can reference:
196
+
197
+ ```markdown
198
+ # Current task artifacts
199
+ See {@artifacts_path}/plan.md for the plan
200
+ See {@artifacts_path}/spec.md for the specification
201
+
202
+ # Project context
203
+ The project is located at {project_root}
204
+ The current task worktree is at {worktree_path}
205
+ ```
206
+
207
+ ### Auto-Commit Behavior
208
+
209
+ Zenflow **auto-commits each agent step**. This means:
210
+ - Every agent action creates a commit
211
+ - You can review the commit history to see what the agent did
212
+ - Manual edits show up as uncommitted changes
213
+
214
+ ### Manual Edits
215
+
216
+ If you make manual edits in the IDE:
217
+ 1. Zenflow surfaces them in the "Changes" page
218
+ 2. You can commit or discard via the UI
219
+ 3. Don't manually run `git commit` - use Zenflow's interface
220
+
221
+ ## Integration with Standard File Hierarchy
222
+
223
+ When Zenflow works on a project that follows the standard file hierarchy:
224
+
225
+ ### Reading Context
226
+ 1. Check `/00_Roadmap/task_plan.md` for current priorities
227
+ 2. Read relevant specs from `/02_Specs/`
228
+ 3. Review system prompts in `/04_System/` if working with agents
229
+ 4. Check logs in `/05_Logs/` for historical context
230
+
231
+ ### Writing Artifacts
232
+ 1. Zenflow's `plan.md` can reference `/00_Roadmap/`
233
+ 2. Zenflow's `spec.md` can be copied to `/02_Specs/` after completion
234
+ 3. Implementation notes can be logged to `/05_Logs/JOURNAL.md`
235
+
236
+ ### Example Workflow
237
+
238
+ ```markdown
239
+ # In Zenflow's plan.md
240
+
241
+ ## Context
242
+ - Project follows standard file hierarchy
243
+ - Current roadmap: /00_Roadmap/task_plan.md
244
+ - Relevant spec: /02_Specs/agent_routing_spec.md
245
+
246
+ ## Approach
247
+ 1. Read existing agent routing implementation
248
+ 2. Follow patterns in /04_System/supervisor_agent.md
249
+ 3. Integrate with existing codebase
250
+ 4. Update /02_Specs/agent_routing_spec.md with changes
251
+ 5. Log decision to /05_Logs/JOURNAL.md
252
+ ```
253
+
254
+ ## Common Patterns
255
+
256
+ ### Pattern 1: Feature Development
257
+
258
+ ```
259
+ 1. Create "Spec and Build" task in Zenflow
260
+ 2. Read /01_PRDs/{feature}_prd.md for requirements
261
+ 3. Write spec.md in task worktree
262
+ 4. Agent reads existing codebase patterns
263
+ 5. Agent generates code following patterns
264
+ 6. Review and merge
265
+ 7. Copy spec.md to /02_Specs/{feature}_spec.md
266
+ ```
267
+
268
+ ### Pattern 2: Bug Fix
269
+
270
+ ```
271
+ 1. Create "Fix Bug" task in Zenflow
272
+ 2. Read /05_Logs/ for recent changes
273
+ 3. Write investigation.md in task worktree
274
+ 4. Agent debugs using existing test patterns
275
+ 5. Agent fixes bug, adds test
276
+ 6. Review and merge
277
+ 7. Log fix to /05_Logs/AUDIT_LOG.md
278
+ ```
279
+
280
+ ### Pattern 3: Refactoring
281
+
282
+ ```
283
+ 1. Create "Spec and Build" task in Zenflow
284
+ 2. Read /02_Specs/architecture.md for current design
285
+ 3. Write refactoring spec in spec.md
286
+ 4. Agent reads existing code structure
287
+ 5. Agent refactors incrementally
288
+ 6. Review and merge
289
+ 7. Update /02_Specs/architecture.md
290
+ ```
291
+
292
+ ## Troubleshooting
293
+
294
+ ### Issue: Worktree conflicts
295
+ **Solution:** Don't manually manage worktrees. Let Zenflow handle it.
296
+
297
+ ### Issue: Agent generates code that doesn't match existing patterns
298
+ **Solution:** Explicitly instruct agent to read existing codebase first:
299
+ ```markdown
300
+ Before generating code:
301
+ 1. Read /src/components/ to understand component patterns
302
+ 2. Read /src/utils/ to find existing utilities
303
+ 3. Follow the same naming and structure conventions
304
+ ```
305
+
306
+ ### Issue: Changes break existing functionality
307
+ **Solution:** Ensure cleanup script includes tests:
308
+ ```bash
309
+ npm run test && pytest
310
+ ```
311
+
312
+ ### Issue: Lost context between tasks
313
+ **Solution:** Reference standard file hierarchy in task artifacts:
314
+ ```markdown
315
+ See /02_Specs/architecture.md for system design
316
+ See /04_System/dojo_agent.md for agent behavior
317
+ ```
318
+
319
+ ## Quick Reference
320
+
321
+ | Action | Command/Pattern |
322
+ |--------|----------------|
323
+ | Get repo overview | `python3.11 context_mapper.py <repo_path>` |
324
+ | Find relevant files | `python3.11 context_mapper.py <repo_path> <keywords>` |
325
+ | Check file hierarchy | `ls -la <repo_path>/0*_*/` |
326
+ | Read existing patterns | Scan `/02_Specs/`, `/03_Prompts/`, `/04_System/` |
327
+ | Reference task artifacts | `{@artifacts_path}/plan.md` |
328
+ | Follow existing conventions | Read codebase first, match style |
@@ -0,0 +1,251 @@
1
+ #!/usr/bin/env python3.11
2
+ """
3
+ context_mapper.py - Generate codebase overview for task context
4
+ Usage: python3.11 context_mapper.py <repo_path> [focus_keywords...]
5
+ Example: python3.11 context_mapper.py /home/ubuntu/repos/dojo-genesis agent routing supervisor
6
+ """
7
+
8
+ import sys
9
+ import subprocess
10
+ from pathlib import Path
11
+ from datetime import datetime
12
+ import json
13
+
14
+ def run_git_command(repo_path, command):
15
+ """Run a git command in the repo directory"""
16
+ try:
17
+ result = subprocess.run(
18
+ command,
19
+ cwd=repo_path,
20
+ capture_output=True,
21
+ text=True,
22
+ check=True
23
+ )
24
+ return result.stdout.strip()
25
+ except subprocess.CalledProcessError:
26
+ return ""
27
+
28
+ def get_repo_info(repo_path):
29
+ """Get basic repo information"""
30
+ current_branch = run_git_command(repo_path, ["git", "branch", "--show-current"])
31
+ current_commit = run_git_command(repo_path, ["git", "rev-parse", "HEAD"])
32
+ commit_message = run_git_command(repo_path, ["git", "log", "-1", "--pretty=%s"])
33
+ remote_url = run_git_command(repo_path, ["git", "config", "--get", "remote.origin.url"])
34
+
35
+ return {
36
+ 'name': Path(repo_path).name,
37
+ 'path': repo_path,
38
+ 'branch': current_branch,
39
+ 'commit': current_commit[:7] if current_commit else 'unknown',
40
+ 'commit_message': commit_message,
41
+ 'remote_url': remote_url
42
+ }
43
+
44
+ def generate_tree(repo_path, max_depth=3, exclude_patterns=None):
45
+ """Generate a tree view of the repo structure"""
46
+ if exclude_patterns is None:
47
+ exclude_patterns = ['.git', 'node_modules', '__pycache__', '.next', 'dist', 'build', '.venv', 'venv']
48
+
49
+ def should_exclude(path):
50
+ return any(pattern in str(path) for pattern in exclude_patterns)
51
+
52
+ def tree_recursive(path, prefix="", depth=0):
53
+ if depth >= max_depth:
54
+ return []
55
+
56
+ lines = []
57
+ try:
58
+ items = sorted(path.iterdir(), key=lambda x: (not x.is_dir(), x.name))
59
+ items = [item for item in items if not should_exclude(item)]
60
+
61
+ for i, item in enumerate(items):
62
+ is_last = i == len(items) - 1
63
+ current_prefix = "└── " if is_last else "├── "
64
+ next_prefix = " " if is_last else "│ "
65
+
66
+ if item.is_dir():
67
+ lines.append(f"{prefix}{current_prefix}{item.name}/")
68
+ lines.extend(tree_recursive(item, prefix + next_prefix, depth + 1))
69
+ else:
70
+ lines.append(f"{prefix}{current_prefix}{item.name}")
71
+ except PermissionError:
72
+ pass
73
+
74
+ return lines
75
+
76
+ root = Path(repo_path)
77
+ tree_lines = [f"{root.name}/"]
78
+ tree_lines.extend(tree_recursive(root, "", 0))
79
+ return "\n".join(tree_lines)
80
+
81
+ def find_relevant_files(repo_path, keywords):
82
+ """Find files relevant to the given keywords"""
83
+ if not keywords:
84
+ return []
85
+
86
+ # Use git grep to find files containing keywords
87
+ relevant_files = set()
88
+
89
+ for keyword in keywords:
90
+ try:
91
+ result = subprocess.run(
92
+ ["git", "grep", "-l", "-i", keyword],
93
+ cwd=repo_path,
94
+ capture_output=True,
95
+ text=True
96
+ )
97
+ if result.returncode == 0:
98
+ files = result.stdout.strip().split('\n')
99
+ relevant_files.update([f for f in files if f])
100
+ except:
101
+ pass
102
+
103
+ return sorted(list(relevant_files))
104
+
105
+ def extract_file_summary(file_path, max_lines=20):
106
+ """Extract a summary from a file (first few lines or key sections)"""
107
+ try:
108
+ content = file_path.read_text(encoding='utf-8', errors='ignore')
109
+ lines = content.split('\n')
110
+
111
+ # For markdown files, extract headers
112
+ if file_path.suffix == '.md':
113
+ headers = [line for line in lines if line.startswith('#')]
114
+ if headers:
115
+ return '\n'.join(headers[:10])
116
+
117
+ # For code files, extract imports and main definitions
118
+ if file_path.suffix in ['.py', '.js', '.ts', '.tsx', '.jsx']:
119
+ relevant_lines = []
120
+ for line in lines[:max_lines]:
121
+ stripped = line.strip()
122
+ if stripped.startswith(('import ', 'from ', 'export ', 'class ', 'function ', 'def ', 'async def ')):
123
+ relevant_lines.append(line)
124
+ if relevant_lines:
125
+ return '\n'.join(relevant_lines)
126
+
127
+ # Default: return first few non-empty lines
128
+ non_empty = [line for line in lines[:max_lines] if line.strip()]
129
+ return '\n'.join(non_empty[:10])
130
+ except:
131
+ return "(Unable to read file)"
132
+
133
+ def detect_patterns(repo_path):
134
+ """Detect common patterns in the codebase"""
135
+ patterns = {
136
+ 'languages': set(),
137
+ 'frameworks': set(),
138
+ 'file_structure': []
139
+ }
140
+
141
+ root = Path(repo_path)
142
+
143
+ # Detect languages by file extensions
144
+ for ext in ['.py', '.js', '.ts', '.tsx', '.jsx', '.go', '.rs', '.java', '.rb']:
145
+ if list(root.rglob(f'*{ext}')):
146
+ patterns['languages'].add(ext[1:])
147
+
148
+ # Detect frameworks by config files
149
+ framework_markers = {
150
+ 'package.json': 'Node.js',
151
+ 'requirements.txt': 'Python',
152
+ 'Cargo.toml': 'Rust',
153
+ 'go.mod': 'Go',
154
+ 'next.config.js': 'Next.js',
155
+ 'vite.config.ts': 'Vite',
156
+ 'tsconfig.json': 'TypeScript'
157
+ }
158
+
159
+ for marker, framework in framework_markers.items():
160
+ if (root / marker).exists():
161
+ patterns['frameworks'].add(framework)
162
+
163
+ # Detect file structure patterns (e.g., /00_Roadmap/, /01_PRDs/)
164
+ for item in root.iterdir():
165
+ if item.is_dir() and item.name.startswith(('00_', '01_', '02_', '03_', '04_', '05_')):
166
+ patterns['file_structure'].append(item.name)
167
+
168
+ return patterns
169
+
170
+ def generate_context_summary(repo_path, keywords=None):
171
+ """Generate a comprehensive context summary"""
172
+ repo_info = get_repo_info(repo_path)
173
+ tree = generate_tree(repo_path)
174
+ patterns = detect_patterns(repo_path)
175
+ relevant_files = find_relevant_files(repo_path, keywords) if keywords else []
176
+
177
+ current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
178
+
179
+ md = f"""# Repo Context Summary: {repo_info['name']}
180
+
181
+ **Generated:** {current_time}
182
+ **Path:** `{repo_info['path']}`
183
+ **Branch:** `{repo_info['branch']}`
184
+ **Commit:** `{repo_info['commit']}` - {repo_info['commit_message']}
185
+ **Remote:** {repo_info['remote_url']}
186
+
187
+ ## File Structure
188
+
189
+ ```
190
+ {tree}
191
+ ```
192
+
193
+ ## Detected Patterns
194
+
195
+ **Languages:** {', '.join(patterns['languages']) if patterns['languages'] else 'None detected'}
196
+ **Frameworks:** {', '.join(patterns['frameworks']) if patterns['frameworks'] else 'None detected'}
197
+ """
198
+
199
+ if patterns['file_structure']:
200
+ md += f"**File Hierarchy Pattern:** {', '.join(patterns['file_structure'])}\n"
201
+
202
+ if keywords:
203
+ md += f"\n## Relevant Files (Keywords: {', '.join(keywords)})\n\n"
204
+ if relevant_files:
205
+ md += f"Found {len(relevant_files)} relevant files:\n\n"
206
+ for file in relevant_files[:20]: # Limit to first 20
207
+ md += f"- `{file}`\n"
208
+
209
+ if len(relevant_files) > 20:
210
+ md += f"\n... and {len(relevant_files) - 20} more files\n"
211
+
212
+ # Show summaries for top 5 files
213
+ md += "\n### File Summaries (Top 5)\n\n"
214
+ for file in relevant_files[:5]:
215
+ file_path = Path(repo_path) / file
216
+ if file_path.exists():
217
+ md += f"#### `{file}`\n\n```\n"
218
+ md += extract_file_summary(file_path)
219
+ md += "\n```\n\n"
220
+ else:
221
+ md += "No files found matching the keywords.\n"
222
+
223
+ return md
224
+
225
+ def main():
226
+ if len(sys.argv) < 2:
227
+ print("Usage: python3.11 context_mapper.py <repo_path> [focus_keywords...]")
228
+ print("Example: python3.11 context_mapper.py /home/ubuntu/repos/dojo-genesis agent routing supervisor")
229
+ sys.exit(1)
230
+
231
+ repo_path = sys.argv[1]
232
+ keywords = sys.argv[2:] if len(sys.argv) > 2 else None
233
+
234
+ if not Path(repo_path).is_dir():
235
+ print(f"❌ Error: {repo_path} is not a directory", file=sys.stderr)
236
+ sys.exit(1)
237
+
238
+ print(f"🗺️ Mapping context for: {Path(repo_path).name}")
239
+ if keywords:
240
+ print(f"🎯 Focus keywords: {', '.join(keywords)}")
241
+
242
+ summary = generate_context_summary(repo_path, keywords)
243
+ print(summary)
244
+
245
+ # Save to file
246
+ output_file = Path(repo_path) / ".context_summary.md"
247
+ output_file.write_text(summary)
248
+ print(f"\n✅ Context summary saved to: {output_file}")
249
+
250
+ if __name__ == "__main__":
251
+ main()