gsd-code-first 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 (238) hide show
  1. package/LICENSE +21 -0
  2. package/README.ja-JP.md +834 -0
  3. package/README.ko-KR.md +823 -0
  4. package/README.md +937 -0
  5. package/README.pt-BR.md +452 -0
  6. package/README.zh-CN.md +800 -0
  7. package/agents/gsd-advisor-researcher.md +104 -0
  8. package/agents/gsd-annotator.md +148 -0
  9. package/agents/gsd-arc-executor.md +537 -0
  10. package/agents/gsd-arc-planner.md +374 -0
  11. package/agents/gsd-assumptions-analyzer.md +105 -0
  12. package/agents/gsd-code-planner.md +155 -0
  13. package/agents/gsd-codebase-mapper.md +770 -0
  14. package/agents/gsd-debugger.md +1373 -0
  15. package/agents/gsd-executor.md +509 -0
  16. package/agents/gsd-integration-checker.md +443 -0
  17. package/agents/gsd-nyquist-auditor.md +176 -0
  18. package/agents/gsd-phase-researcher.md +698 -0
  19. package/agents/gsd-plan-checker.md +773 -0
  20. package/agents/gsd-planner.md +1354 -0
  21. package/agents/gsd-project-researcher.md +654 -0
  22. package/agents/gsd-prototyper.md +161 -0
  23. package/agents/gsd-research-synthesizer.md +247 -0
  24. package/agents/gsd-roadmapper.md +679 -0
  25. package/agents/gsd-ui-auditor.md +439 -0
  26. package/agents/gsd-ui-checker.md +300 -0
  27. package/agents/gsd-ui-researcher.md +357 -0
  28. package/agents/gsd-user-profiler.md +171 -0
  29. package/agents/gsd-verifier.md +700 -0
  30. package/bin/install.js +5009 -0
  31. package/commands/gsd/add-backlog.md +76 -0
  32. package/commands/gsd/add-phase.md +43 -0
  33. package/commands/gsd/add-tests.md +41 -0
  34. package/commands/gsd/add-todo.md +47 -0
  35. package/commands/gsd/annotate.md +54 -0
  36. package/commands/gsd/audit-milestone.md +36 -0
  37. package/commands/gsd/audit-uat.md +24 -0
  38. package/commands/gsd/autonomous.md +41 -0
  39. package/commands/gsd/check-todos.md +45 -0
  40. package/commands/gsd/cleanup.md +18 -0
  41. package/commands/gsd/complete-milestone.md +136 -0
  42. package/commands/gsd/debug.md +173 -0
  43. package/commands/gsd/deep-plan.md +52 -0
  44. package/commands/gsd/discuss-phase.md +64 -0
  45. package/commands/gsd/do.md +30 -0
  46. package/commands/gsd/execute-phase.md +59 -0
  47. package/commands/gsd/extract-plan.md +35 -0
  48. package/commands/gsd/fast.md +30 -0
  49. package/commands/gsd/forensics.md +56 -0
  50. package/commands/gsd/health.md +22 -0
  51. package/commands/gsd/help.md +22 -0
  52. package/commands/gsd/insert-phase.md +32 -0
  53. package/commands/gsd/iterate.md +124 -0
  54. package/commands/gsd/join-discord.md +18 -0
  55. package/commands/gsd/list-phase-assumptions.md +46 -0
  56. package/commands/gsd/list-workspaces.md +19 -0
  57. package/commands/gsd/manager.md +39 -0
  58. package/commands/gsd/map-codebase.md +71 -0
  59. package/commands/gsd/milestone-summary.md +51 -0
  60. package/commands/gsd/new-milestone.md +44 -0
  61. package/commands/gsd/new-project.md +42 -0
  62. package/commands/gsd/new-workspace.md +44 -0
  63. package/commands/gsd/next.md +24 -0
  64. package/commands/gsd/note.md +34 -0
  65. package/commands/gsd/pause-work.md +38 -0
  66. package/commands/gsd/plan-milestone-gaps.md +34 -0
  67. package/commands/gsd/plan-phase.md +47 -0
  68. package/commands/gsd/plant-seed.md +28 -0
  69. package/commands/gsd/pr-branch.md +25 -0
  70. package/commands/gsd/profile-user.md +46 -0
  71. package/commands/gsd/progress.md +24 -0
  72. package/commands/gsd/prototype.md +56 -0
  73. package/commands/gsd/quick.md +47 -0
  74. package/commands/gsd/reapply-patches.md +123 -0
  75. package/commands/gsd/remove-phase.md +31 -0
  76. package/commands/gsd/remove-workspace.md +26 -0
  77. package/commands/gsd/research-phase.md +195 -0
  78. package/commands/gsd/resume-work.md +40 -0
  79. package/commands/gsd/review-backlog.md +61 -0
  80. package/commands/gsd/review.md +37 -0
  81. package/commands/gsd/session-report.md +19 -0
  82. package/commands/gsd/set-mode.md +41 -0
  83. package/commands/gsd/set-profile.md +12 -0
  84. package/commands/gsd/settings.md +36 -0
  85. package/commands/gsd/ship.md +23 -0
  86. package/commands/gsd/stats.md +18 -0
  87. package/commands/gsd/thread.md +127 -0
  88. package/commands/gsd/ui-phase.md +34 -0
  89. package/commands/gsd/ui-review.md +32 -0
  90. package/commands/gsd/update.md +37 -0
  91. package/commands/gsd/validate-phase.md +35 -0
  92. package/commands/gsd/verify-work.md +38 -0
  93. package/commands/gsd/workstreams.md +63 -0
  94. package/get-shit-done/bin/gsd-tools.cjs +946 -0
  95. package/get-shit-done/bin/lib/arc-scanner.cjs +341 -0
  96. package/get-shit-done/bin/lib/commands.cjs +959 -0
  97. package/get-shit-done/bin/lib/config.cjs +466 -0
  98. package/get-shit-done/bin/lib/core.cjs +1230 -0
  99. package/get-shit-done/bin/lib/frontmatter.cjs +336 -0
  100. package/get-shit-done/bin/lib/init.cjs +1442 -0
  101. package/get-shit-done/bin/lib/milestone.cjs +252 -0
  102. package/get-shit-done/bin/lib/model-profiles.cjs +68 -0
  103. package/get-shit-done/bin/lib/phase.cjs +888 -0
  104. package/get-shit-done/bin/lib/profile-output.cjs +952 -0
  105. package/get-shit-done/bin/lib/profile-pipeline.cjs +539 -0
  106. package/get-shit-done/bin/lib/roadmap.cjs +329 -0
  107. package/get-shit-done/bin/lib/security.cjs +382 -0
  108. package/get-shit-done/bin/lib/state.cjs +1031 -0
  109. package/get-shit-done/bin/lib/template.cjs +222 -0
  110. package/get-shit-done/bin/lib/uat.cjs +282 -0
  111. package/get-shit-done/bin/lib/verify.cjs +888 -0
  112. package/get-shit-done/bin/lib/workstream.cjs +491 -0
  113. package/get-shit-done/commands/gsd/workstreams.md +63 -0
  114. package/get-shit-done/references/arc-standard.md +315 -0
  115. package/get-shit-done/references/checkpoints.md +778 -0
  116. package/get-shit-done/references/continuation-format.md +249 -0
  117. package/get-shit-done/references/decimal-phase-calculation.md +64 -0
  118. package/get-shit-done/references/git-integration.md +295 -0
  119. package/get-shit-done/references/git-planning-commit.md +38 -0
  120. package/get-shit-done/references/model-profile-resolution.md +36 -0
  121. package/get-shit-done/references/model-profiles.md +139 -0
  122. package/get-shit-done/references/phase-argument-parsing.md +61 -0
  123. package/get-shit-done/references/planning-config.md +202 -0
  124. package/get-shit-done/references/questioning.md +162 -0
  125. package/get-shit-done/references/tdd.md +263 -0
  126. package/get-shit-done/references/ui-brand.md +160 -0
  127. package/get-shit-done/references/user-profiling.md +681 -0
  128. package/get-shit-done/references/verification-patterns.md +612 -0
  129. package/get-shit-done/references/workstream-flag.md +58 -0
  130. package/get-shit-done/templates/DEBUG.md +164 -0
  131. package/get-shit-done/templates/UAT.md +265 -0
  132. package/get-shit-done/templates/UI-SPEC.md +100 -0
  133. package/get-shit-done/templates/VALIDATION.md +76 -0
  134. package/get-shit-done/templates/claude-md.md +122 -0
  135. package/get-shit-done/templates/codebase/architecture.md +255 -0
  136. package/get-shit-done/templates/codebase/concerns.md +310 -0
  137. package/get-shit-done/templates/codebase/conventions.md +307 -0
  138. package/get-shit-done/templates/codebase/integrations.md +280 -0
  139. package/get-shit-done/templates/codebase/stack.md +186 -0
  140. package/get-shit-done/templates/codebase/structure.md +285 -0
  141. package/get-shit-done/templates/codebase/testing.md +480 -0
  142. package/get-shit-done/templates/config.json +44 -0
  143. package/get-shit-done/templates/context.md +352 -0
  144. package/get-shit-done/templates/continue-here.md +78 -0
  145. package/get-shit-done/templates/copilot-instructions.md +7 -0
  146. package/get-shit-done/templates/debug-subagent-prompt.md +91 -0
  147. package/get-shit-done/templates/dev-preferences.md +21 -0
  148. package/get-shit-done/templates/discovery.md +146 -0
  149. package/get-shit-done/templates/discussion-log.md +63 -0
  150. package/get-shit-done/templates/milestone-archive.md +123 -0
  151. package/get-shit-done/templates/milestone.md +115 -0
  152. package/get-shit-done/templates/phase-prompt.md +610 -0
  153. package/get-shit-done/templates/planner-subagent-prompt.md +117 -0
  154. package/get-shit-done/templates/project.md +186 -0
  155. package/get-shit-done/templates/requirements.md +231 -0
  156. package/get-shit-done/templates/research-project/ARCHITECTURE.md +204 -0
  157. package/get-shit-done/templates/research-project/FEATURES.md +147 -0
  158. package/get-shit-done/templates/research-project/PITFALLS.md +200 -0
  159. package/get-shit-done/templates/research-project/STACK.md +120 -0
  160. package/get-shit-done/templates/research-project/SUMMARY.md +170 -0
  161. package/get-shit-done/templates/research.md +552 -0
  162. package/get-shit-done/templates/retrospective.md +54 -0
  163. package/get-shit-done/templates/roadmap.md +202 -0
  164. package/get-shit-done/templates/state.md +176 -0
  165. package/get-shit-done/templates/summary-complex.md +59 -0
  166. package/get-shit-done/templates/summary-minimal.md +41 -0
  167. package/get-shit-done/templates/summary-standard.md +48 -0
  168. package/get-shit-done/templates/summary.md +248 -0
  169. package/get-shit-done/templates/user-profile.md +146 -0
  170. package/get-shit-done/templates/user-setup.md +311 -0
  171. package/get-shit-done/templates/verification-report.md +322 -0
  172. package/get-shit-done/workflows/add-phase.md +112 -0
  173. package/get-shit-done/workflows/add-tests.md +351 -0
  174. package/get-shit-done/workflows/add-todo.md +158 -0
  175. package/get-shit-done/workflows/audit-milestone.md +340 -0
  176. package/get-shit-done/workflows/audit-uat.md +109 -0
  177. package/get-shit-done/workflows/autonomous.md +891 -0
  178. package/get-shit-done/workflows/check-todos.md +177 -0
  179. package/get-shit-done/workflows/cleanup.md +152 -0
  180. package/get-shit-done/workflows/complete-milestone.md +767 -0
  181. package/get-shit-done/workflows/diagnose-issues.md +231 -0
  182. package/get-shit-done/workflows/discovery-phase.md +289 -0
  183. package/get-shit-done/workflows/discuss-phase-assumptions.md +653 -0
  184. package/get-shit-done/workflows/discuss-phase.md +1049 -0
  185. package/get-shit-done/workflows/do.md +104 -0
  186. package/get-shit-done/workflows/execute-phase.md +846 -0
  187. package/get-shit-done/workflows/execute-plan.md +514 -0
  188. package/get-shit-done/workflows/fast.md +105 -0
  189. package/get-shit-done/workflows/forensics.md +265 -0
  190. package/get-shit-done/workflows/health.md +181 -0
  191. package/get-shit-done/workflows/help.md +634 -0
  192. package/get-shit-done/workflows/insert-phase.md +130 -0
  193. package/get-shit-done/workflows/list-phase-assumptions.md +178 -0
  194. package/get-shit-done/workflows/list-workspaces.md +56 -0
  195. package/get-shit-done/workflows/manager.md +362 -0
  196. package/get-shit-done/workflows/map-codebase.md +377 -0
  197. package/get-shit-done/workflows/milestone-summary.md +223 -0
  198. package/get-shit-done/workflows/new-milestone.md +486 -0
  199. package/get-shit-done/workflows/new-project.md +1250 -0
  200. package/get-shit-done/workflows/new-workspace.md +237 -0
  201. package/get-shit-done/workflows/next.md +97 -0
  202. package/get-shit-done/workflows/node-repair.md +92 -0
  203. package/get-shit-done/workflows/note.md +156 -0
  204. package/get-shit-done/workflows/pause-work.md +176 -0
  205. package/get-shit-done/workflows/plan-milestone-gaps.md +273 -0
  206. package/get-shit-done/workflows/plan-phase.md +859 -0
  207. package/get-shit-done/workflows/plant-seed.md +169 -0
  208. package/get-shit-done/workflows/pr-branch.md +129 -0
  209. package/get-shit-done/workflows/profile-user.md +450 -0
  210. package/get-shit-done/workflows/progress.md +507 -0
  211. package/get-shit-done/workflows/quick.md +757 -0
  212. package/get-shit-done/workflows/remove-phase.md +155 -0
  213. package/get-shit-done/workflows/remove-workspace.md +90 -0
  214. package/get-shit-done/workflows/research-phase.md +82 -0
  215. package/get-shit-done/workflows/resume-project.md +326 -0
  216. package/get-shit-done/workflows/review.md +228 -0
  217. package/get-shit-done/workflows/session-report.md +146 -0
  218. package/get-shit-done/workflows/settings.md +283 -0
  219. package/get-shit-done/workflows/ship.md +228 -0
  220. package/get-shit-done/workflows/stats.md +60 -0
  221. package/get-shit-done/workflows/transition.md +671 -0
  222. package/get-shit-done/workflows/ui-phase.md +302 -0
  223. package/get-shit-done/workflows/ui-review.md +165 -0
  224. package/get-shit-done/workflows/update.md +323 -0
  225. package/get-shit-done/workflows/validate-phase.md +174 -0
  226. package/get-shit-done/workflows/verify-phase.md +254 -0
  227. package/get-shit-done/workflows/verify-work.md +637 -0
  228. package/hooks/dist/gsd-check-update.js +114 -0
  229. package/hooks/dist/gsd-context-monitor.js +156 -0
  230. package/hooks/dist/gsd-prompt-guard.js +96 -0
  231. package/hooks/dist/gsd-statusline.js +119 -0
  232. package/hooks/dist/gsd-workflow-guard.js +94 -0
  233. package/package.json +52 -0
  234. package/scripts/base64-scan.sh +262 -0
  235. package/scripts/build-hooks.js +82 -0
  236. package/scripts/prompt-injection-scan.sh +198 -0
  237. package/scripts/run-tests.cjs +29 -0
  238. package/scripts/secret-scan.sh +227 -0
@@ -0,0 +1,952 @@
1
+ /**
2
+ * Profile Output — profile rendering, questionnaire, and artifact generation
3
+ *
4
+ * Renders profiling analysis into user-facing artifacts:
5
+ * - write-profile: USER-PROFILE.md from analysis JSON
6
+ * - profile-questionnaire: fallback when no sessions available
7
+ * - generate-dev-preferences: dev-preferences.md command artifact
8
+ * - generate-claude-profile: Developer Profile section in CLAUDE.md
9
+ * - generate-claude-md: full CLAUDE.md with managed sections
10
+ */
11
+
12
+ const fs = require('fs');
13
+ const path = require('path');
14
+ const os = require('os');
15
+ const { output, error, safeReadFile } = require('./core.cjs');
16
+
17
+ // ─── Constants ────────────────────────────────────────────────────────────────
18
+
19
+ const DIMENSION_KEYS = [
20
+ 'communication_style', 'decision_speed', 'explanation_depth',
21
+ 'debugging_approach', 'ux_philosophy', 'vendor_philosophy',
22
+ 'frustration_triggers', 'learning_style'
23
+ ];
24
+
25
+ const PROFILING_QUESTIONS = [
26
+ {
27
+ dimension: 'communication_style',
28
+ header: 'Communication Style',
29
+ context: 'Think about the last few times you asked Claude to build or change something. How did you frame the request?',
30
+ question: 'When you ask Claude to build something, how much context do you typically provide?',
31
+ options: [
32
+ { label: 'Minimal -- "fix the bug", "add dark mode", just say what\'s needed', value: 'a', rating: 'terse-direct' },
33
+ { label: 'Some context -- explain what and why in a paragraph or two', value: 'b', rating: 'conversational' },
34
+ { label: 'Detailed specs -- headers, numbered lists, problem analysis, constraints', value: 'c', rating: 'detailed-structured' },
35
+ { label: 'It depends on the task -- simple tasks get short prompts, complex ones get detailed specs', value: 'd', rating: 'mixed' },
36
+ ],
37
+ },
38
+ {
39
+ dimension: 'decision_speed',
40
+ header: 'Decision Making',
41
+ context: 'Think about times when Claude presented you with multiple options -- like choosing a library, picking an architecture, or selecting an approach.',
42
+ question: 'When Claude presents you with options, how do you typically decide?',
43
+ options: [
44
+ { label: 'Pick quickly based on gut feeling or past experience', value: 'a', rating: 'fast-intuitive' },
45
+ { label: 'Ask for a comparison table or pros/cons, then decide', value: 'b', rating: 'deliberate-informed' },
46
+ { label: 'Research independently (read docs, check GitHub stars) before deciding', value: 'c', rating: 'research-first' },
47
+ { label: 'Let Claude recommend -- I generally trust the suggestion', value: 'd', rating: 'delegator' },
48
+ ],
49
+ },
50
+ {
51
+ dimension: 'explanation_depth',
52
+ header: 'Explanation Preferences',
53
+ context: 'Think about when Claude explains code it wrote or an approach it took. How much detail feels right?',
54
+ question: 'When Claude explains something, how much detail do you want?',
55
+ options: [
56
+ { label: 'Just the code -- I\'ll read it and figure it out myself', value: 'a', rating: 'code-only' },
57
+ { label: 'Brief explanation with the code -- a sentence or two about the approach', value: 'b', rating: 'concise' },
58
+ { label: 'Detailed walkthrough -- explain the approach, trade-offs, and code structure', value: 'c', rating: 'detailed' },
59
+ { label: 'Deep dive -- teach me the concepts behind it so I understand the fundamentals', value: 'd', rating: 'educational' },
60
+ ],
61
+ },
62
+ {
63
+ dimension: 'debugging_approach',
64
+ header: 'Debugging Style',
65
+ context: 'Think about the last few times something broke in your code. How did you approach it with Claude?',
66
+ question: 'When something breaks, how do you typically approach debugging with Claude?',
67
+ options: [
68
+ { label: 'Paste the error and say "fix it" -- get it working fast', value: 'a', rating: 'fix-first' },
69
+ { label: 'Share the error plus context, ask Claude to diagnose what went wrong', value: 'b', rating: 'diagnostic' },
70
+ { label: 'Investigate myself first, then ask Claude about my specific theories', value: 'c', rating: 'hypothesis-driven' },
71
+ { label: 'Walk through the code together step by step to understand the issue', value: 'd', rating: 'collaborative' },
72
+ ],
73
+ },
74
+ {
75
+ dimension: 'ux_philosophy',
76
+ header: 'UX Philosophy',
77
+ context: 'Think about user-facing features you have built recently. How did you balance functionality with design?',
78
+ question: 'When building user-facing features, what do you prioritize?',
79
+ options: [
80
+ { label: 'Get it working first, polish the UI later (or never)', value: 'a', rating: 'function-first' },
81
+ { label: 'Basic usability from the start -- nothing ugly, but no pixel-perfection', value: 'b', rating: 'pragmatic' },
82
+ { label: 'Design and UX are as important as functionality -- I care about the experience', value: 'c', rating: 'design-conscious' },
83
+ { label: 'I mostly build backend, CLI, or infrastructure -- UX is minimal', value: 'd', rating: 'backend-focused' },
84
+ ],
85
+ },
86
+ {
87
+ dimension: 'vendor_philosophy',
88
+ header: 'Library & Vendor Choices',
89
+ context: 'Think about the last time you needed a library or service for a project. How did you go about choosing it?',
90
+ question: 'When choosing libraries or services, what is your typical approach?',
91
+ options: [
92
+ { label: 'Use whatever Claude suggests -- speed matters more than the perfect choice', value: 'a', rating: 'pragmatic-fast' },
93
+ { label: 'Prefer well-known, battle-tested options (React, PostgreSQL, Express)', value: 'b', rating: 'conservative' },
94
+ { label: 'Research alternatives, read docs, compare benchmarks before committing', value: 'c', rating: 'thorough-evaluator' },
95
+ { label: 'Strong opinions -- I already know what I like and I stick with it', value: 'd', rating: 'opinionated' },
96
+ ],
97
+ },
98
+ {
99
+ dimension: 'frustration_triggers',
100
+ header: 'Frustration Triggers',
101
+ context: 'Think about moments when working with AI coding assistants that made you frustrated or annoyed.',
102
+ question: 'What frustrates you most when working with AI coding assistants?',
103
+ options: [
104
+ { label: 'Doing things I didn\'t ask for -- adding features, refactoring code, scope creep', value: 'a', rating: 'scope-creep' },
105
+ { label: 'Not following instructions precisely -- ignoring constraints or requirements I stated', value: 'b', rating: 'instruction-adherence' },
106
+ { label: 'Over-explaining or being too verbose -- just give me the code and move on', value: 'c', rating: 'verbosity' },
107
+ { label: 'Breaking working code while fixing something else -- regressions', value: 'd', rating: 'regression' },
108
+ ],
109
+ },
110
+ {
111
+ dimension: 'learning_style',
112
+ header: 'Learning Preferences',
113
+ context: 'Think about encountering something new -- an unfamiliar library, a codebase you inherited, a concept you hadn\'t used before.',
114
+ question: 'When you encounter something new in your codebase, how do you prefer to learn about it?',
115
+ options: [
116
+ { label: 'Read the code directly -- I figure things out by reading and experimenting', value: 'a', rating: 'self-directed' },
117
+ { label: 'Ask Claude to explain the relevant parts to me', value: 'b', rating: 'guided' },
118
+ { label: 'Read official docs and tutorials first, then try things', value: 'c', rating: 'documentation-first' },
119
+ { label: 'See a working example, then modify it to understand how it works', value: 'd', rating: 'example-driven' },
120
+ ],
121
+ },
122
+ ];
123
+
124
+ const CLAUDE_INSTRUCTIONS = {
125
+ communication_style: {
126
+ 'terse-direct': 'Keep responses concise and action-oriented. Skip lengthy preambles. Match this developer\'s direct style.',
127
+ 'conversational': 'Use a natural conversational tone. Explain reasoning briefly alongside code. Engage with the developer\'s questions.',
128
+ 'detailed-structured': 'Match this developer\'s structured communication: use headers for sections, numbered lists for steps, and acknowledge provided context before responding.',
129
+ 'mixed': 'Adapt response detail to match the complexity of each request. Brief for simple tasks, detailed for complex ones.',
130
+ },
131
+ decision_speed: {
132
+ 'fast-intuitive': 'Present a single strong recommendation with brief justification. Skip lengthy comparisons unless asked.',
133
+ 'deliberate-informed': 'Present options in a structured comparison table with pros/cons. Let the developer make the final call.',
134
+ 'research-first': 'Include links to docs, GitHub repos, or benchmarks when recommending tools. Support the developer\'s research process.',
135
+ 'delegator': 'Make clear recommendations with confidence. Explain your reasoning briefly, but own the suggestion.',
136
+ },
137
+ explanation_depth: {
138
+ 'code-only': 'Prioritize code output. Add comments inline rather than prose explanations. Skip walkthroughs unless asked.',
139
+ 'concise': 'Pair code with a brief explanation (1-2 sentences) of the approach. Keep prose minimal.',
140
+ 'detailed': 'Explain the approach, key trade-offs, and code structure alongside the implementation. Use headers to organize.',
141
+ 'educational': 'Teach the underlying concepts and principles, not just the implementation. Relate new patterns to fundamentals.',
142
+ },
143
+ debugging_approach: {
144
+ 'fix-first': 'Prioritize the fix. Show the corrected code first, then optionally explain what was wrong. Minimize diagnostic preamble.',
145
+ 'diagnostic': 'Diagnose the root cause before presenting the fix. Explain what went wrong and why the fix addresses it.',
146
+ 'hypothesis-driven': 'Engage with the developer\'s theories. Validate or refine their hypotheses before jumping to solutions.',
147
+ 'collaborative': 'Walk through the debugging process step by step. Explain the investigation approach, not just the conclusion.',
148
+ },
149
+ ux_philosophy: {
150
+ 'function-first': 'Focus on functionality and correctness. Keep UI minimal and functional. Skip design polish unless requested.',
151
+ 'pragmatic': 'Build clean, usable interfaces without over-engineering. Apply basic design principles (spacing, alignment, contrast).',
152
+ 'design-conscious': 'Invest in UX quality: thoughtful spacing, smooth transitions, responsive layouts. Treat design as a first-class concern.',
153
+ 'backend-focused': 'Optimize for developer experience (clear APIs, good error messages, helpful CLI output) over visual design.',
154
+ },
155
+ vendor_philosophy: {
156
+ 'pragmatic-fast': 'Suggest libraries quickly based on popularity and reliability. Don\'t over-analyze choices for non-critical dependencies.',
157
+ 'conservative': 'Recommend well-established, widely-adopted tools with strong community support. Avoid bleeding-edge options.',
158
+ 'thorough-evaluator': 'Compare alternatives with specific metrics (bundle size, GitHub stars, maintenance activity). Support informed decisions.',
159
+ 'opinionated': 'Respect the developer\'s existing tool preferences. Ask before suggesting alternatives to their preferred stack.',
160
+ },
161
+ frustration_triggers: {
162
+ 'scope-creep': 'Do exactly what is asked -- nothing more. Never add unrequested features, refactoring, or "improvements". Ask before expanding scope.',
163
+ 'instruction-adherence': 'Follow instructions precisely. Re-read constraints before responding. If requirements conflict, flag the conflict rather than silently choosing.',
164
+ 'verbosity': 'Be concise. Lead with code, follow with brief explanation only if needed. Avoid restating the problem or unnecessary context.',
165
+ 'regression': 'Before modifying working code, verify the change is safe. Run existing tests mentally. Flag potential regression risks explicitly.',
166
+ },
167
+ learning_style: {
168
+ 'self-directed': 'Point to relevant code sections and let the developer explore. Add signposts (file paths, function names) rather than full explanations.',
169
+ 'guided': 'Explain concepts in context of the developer\'s codebase. Use their actual code as examples when teaching.',
170
+ 'documentation-first': 'Link to official documentation and relevant sections. Structure explanations like reference material.',
171
+ 'example-driven': 'Lead with working code examples. Show a minimal example first, then explain how to extend or modify it.',
172
+ },
173
+ };
174
+
175
+ const CLAUDE_MD_FALLBACKS = {
176
+ project: 'Project not yet initialized. Run /gsd:new-project to set up.',
177
+ stack: 'Technology stack not yet documented. Will populate after codebase mapping or first phase.',
178
+ conventions: 'Conventions not yet established. Will populate as patterns emerge during development.',
179
+ architecture: 'Architecture not yet mapped. Follow existing patterns found in the codebase.',
180
+ };
181
+
182
+ const CLAUDE_MD_WORKFLOW_ENFORCEMENT = [
183
+ 'Before using Edit, Write, or other file-changing tools, start work through a GSD command so planning artifacts and execution context stay in sync.',
184
+ '',
185
+ 'Use these entry points:',
186
+ '- `/gsd:quick` for small fixes, doc updates, and ad-hoc tasks',
187
+ '- `/gsd:debug` for investigation and bug fixing',
188
+ '- `/gsd:execute-phase` for planned phase work',
189
+ '',
190
+ 'Do not make direct repo edits outside a GSD workflow unless the user explicitly asks to bypass it.',
191
+ ].join('\n');
192
+
193
+ const CLAUDE_MD_PROFILE_PLACEHOLDER = [
194
+ '<!-- GSD:profile-start -->',
195
+ '## Developer Profile',
196
+ '',
197
+ '> Profile not yet configured. Run `/gsd:profile-user` to generate your developer profile.',
198
+ '> This section is managed by `generate-claude-profile` -- do not edit manually.',
199
+ '<!-- GSD:profile-end -->',
200
+ ].join('\n');
201
+
202
+ // ─── Helper Functions ─────────────────────────────────────────────────────────
203
+
204
+ function isAmbiguousAnswer(dimension, value) {
205
+ if (dimension === 'communication_style' && value === 'd') return true;
206
+ const question = PROFILING_QUESTIONS.find(q => q.dimension === dimension);
207
+ if (!question) return false;
208
+ const option = question.options.find(o => o.value === value);
209
+ if (!option) return false;
210
+ return option.rating === 'mixed';
211
+ }
212
+
213
+ function generateClaudeInstruction(dimension, rating) {
214
+ const dimInstructions = CLAUDE_INSTRUCTIONS[dimension];
215
+ if (dimInstructions && dimInstructions[rating]) {
216
+ return dimInstructions[rating];
217
+ }
218
+ return `Adapt to this developer's ${dimension.replace(/_/g, ' ')} preference: ${rating}.`;
219
+ }
220
+
221
+ function extractSectionContent(fileContent, sectionName) {
222
+ const startMarker = `<!-- GSD:${sectionName}-start`;
223
+ const endMarker = `<!-- GSD:${sectionName}-end -->`;
224
+ const startIdx = fileContent.indexOf(startMarker);
225
+ const endIdx = fileContent.indexOf(endMarker);
226
+ if (startIdx === -1 || endIdx === -1) return null;
227
+ const startTagEnd = fileContent.indexOf('-->', startIdx);
228
+ if (startTagEnd === -1) return null;
229
+ return fileContent.substring(startTagEnd + 3, endIdx);
230
+ }
231
+
232
+ function buildSection(sectionName, sourceFile, content) {
233
+ return [
234
+ `<!-- GSD:${sectionName}-start source:${sourceFile} -->`,
235
+ content,
236
+ `<!-- GSD:${sectionName}-end -->`,
237
+ ].join('\n');
238
+ }
239
+
240
+ function updateSection(fileContent, sectionName, newContent) {
241
+ const startMarker = `<!-- GSD:${sectionName}-start`;
242
+ const endMarker = `<!-- GSD:${sectionName}-end -->`;
243
+ const startIdx = fileContent.indexOf(startMarker);
244
+ const endIdx = fileContent.indexOf(endMarker);
245
+ if (startIdx !== -1 && endIdx !== -1) {
246
+ const before = fileContent.substring(0, startIdx);
247
+ const after = fileContent.substring(endIdx + endMarker.length);
248
+ return { content: before + newContent + after, action: 'replaced' };
249
+ }
250
+ return { content: fileContent.trimEnd() + '\n\n' + newContent + '\n', action: 'appended' };
251
+ }
252
+
253
+ function detectManualEdit(fileContent, sectionName, expectedContent) {
254
+ const currentContent = extractSectionContent(fileContent, sectionName);
255
+ if (currentContent === null) return false;
256
+ const normalize = (s) => s.trim().replace(/\n{3,}/g, '\n\n');
257
+ return normalize(currentContent) !== normalize(expectedContent);
258
+ }
259
+
260
+ function extractMarkdownSection(content, sectionName) {
261
+ if (!content) return null;
262
+ const lines = content.split('\n');
263
+ let capturing = false;
264
+ const result = [];
265
+ const headingPattern = new RegExp(`^## ${sectionName}\\s*$`);
266
+ for (const line of lines) {
267
+ if (headingPattern.test(line)) {
268
+ capturing = true;
269
+ result.push(line);
270
+ continue;
271
+ }
272
+ if (capturing && /^## /.test(line)) break;
273
+ if (capturing) result.push(line);
274
+ }
275
+ return result.length > 0 ? result.join('\n').trim() : null;
276
+ }
277
+
278
+ // ─── CLAUDE.md Section Generators ─────────────────────────────────────────────
279
+
280
+ function generateProjectSection(cwd) {
281
+ const projectPath = path.join(cwd, '.planning', 'PROJECT.md');
282
+ const content = safeReadFile(projectPath);
283
+ if (!content) {
284
+ return { content: CLAUDE_MD_FALLBACKS.project, source: 'PROJECT.md', hasFallback: true };
285
+ }
286
+ const parts = [];
287
+ const h1Match = content.match(/^# (.+)$/m);
288
+ if (h1Match) parts.push(`**${h1Match[1]}**`);
289
+ const whatThisIs = extractMarkdownSection(content, 'What This Is');
290
+ if (whatThisIs) {
291
+ const body = whatThisIs.replace(/^## What This Is\s*/i, '').trim();
292
+ if (body) parts.push(body);
293
+ }
294
+ const coreValue = extractMarkdownSection(content, 'Core Value');
295
+ if (coreValue) {
296
+ const body = coreValue.replace(/^## Core Value\s*/i, '').trim();
297
+ if (body) parts.push(`**Core Value:** ${body}`);
298
+ }
299
+ const constraints = extractMarkdownSection(content, 'Constraints');
300
+ if (constraints) {
301
+ const body = constraints.replace(/^## Constraints\s*/i, '').trim();
302
+ if (body) parts.push(`### Constraints\n\n${body}`);
303
+ }
304
+ if (parts.length === 0) {
305
+ return { content: CLAUDE_MD_FALLBACKS.project, source: 'PROJECT.md', hasFallback: true };
306
+ }
307
+ return { content: parts.join('\n\n'), source: 'PROJECT.md', hasFallback: false };
308
+ }
309
+
310
+ function generateStackSection(cwd) {
311
+ const codebasePath = path.join(cwd, '.planning', 'codebase', 'STACK.md');
312
+ const researchPath = path.join(cwd, '.planning', 'research', 'STACK.md');
313
+ let content = safeReadFile(codebasePath);
314
+ let source = 'codebase/STACK.md';
315
+ if (!content) {
316
+ content = safeReadFile(researchPath);
317
+ source = 'research/STACK.md';
318
+ }
319
+ if (!content) {
320
+ return { content: CLAUDE_MD_FALLBACKS.stack, source: 'STACK.md', hasFallback: true };
321
+ }
322
+ const lines = content.split('\n');
323
+ const summaryLines = [];
324
+ let inTable = false;
325
+ for (const line of lines) {
326
+ if (line.startsWith('#')) {
327
+ if (!line.startsWith('# ') || summaryLines.length > 0) summaryLines.push(line);
328
+ continue;
329
+ }
330
+ if (line.startsWith('|')) { inTable = true; summaryLines.push(line); continue; }
331
+ if (inTable && line.trim() === '') inTable = false;
332
+ if (line.startsWith('- ') || line.startsWith('* ')) summaryLines.push(line);
333
+ }
334
+ const summary = summaryLines.length > 0 ? summaryLines.join('\n') : content.trim();
335
+ return { content: summary, source, hasFallback: false };
336
+ }
337
+
338
+ function generateConventionsSection(cwd) {
339
+ const conventionsPath = path.join(cwd, '.planning', 'codebase', 'CONVENTIONS.md');
340
+ const content = safeReadFile(conventionsPath);
341
+ if (!content) {
342
+ return { content: CLAUDE_MD_FALLBACKS.conventions, source: 'CONVENTIONS.md', hasFallback: true };
343
+ }
344
+ const lines = content.split('\n');
345
+ const summaryLines = [];
346
+ for (const line of lines) {
347
+ if (line.startsWith('#')) { if (!line.startsWith('# ')) summaryLines.push(line); continue; }
348
+ if (line.startsWith('- ') || line.startsWith('* ') || line.startsWith('|')) summaryLines.push(line);
349
+ }
350
+ const summary = summaryLines.length > 0 ? summaryLines.join('\n') : content.trim();
351
+ return { content: summary, source: 'CONVENTIONS.md', hasFallback: false };
352
+ }
353
+
354
+ function generateArchitectureSection(cwd) {
355
+ const architecturePath = path.join(cwd, '.planning', 'codebase', 'ARCHITECTURE.md');
356
+ const content = safeReadFile(architecturePath);
357
+ if (!content) {
358
+ return { content: CLAUDE_MD_FALLBACKS.architecture, source: 'ARCHITECTURE.md', hasFallback: true };
359
+ }
360
+ const lines = content.split('\n');
361
+ const summaryLines = [];
362
+ for (const line of lines) {
363
+ if (line.startsWith('#')) { if (!line.startsWith('# ')) summaryLines.push(line); continue; }
364
+ if (line.startsWith('- ') || line.startsWith('* ') || line.startsWith('|') || line.startsWith('```')) summaryLines.push(line);
365
+ }
366
+ const summary = summaryLines.length > 0 ? summaryLines.join('\n') : content.trim();
367
+ return { content: summary, source: 'ARCHITECTURE.md', hasFallback: false };
368
+ }
369
+
370
+ function generateWorkflowSection() {
371
+ return {
372
+ content: CLAUDE_MD_WORKFLOW_ENFORCEMENT,
373
+ source: 'GSD defaults',
374
+ hasFallback: false,
375
+ };
376
+ }
377
+
378
+ // ─── Commands ─────────────────────────────────────────────────────────────────
379
+
380
+ function cmdWriteProfile(cwd, options, raw) {
381
+ if (!options.input) {
382
+ error('--input <analysis-json-path> is required');
383
+ }
384
+
385
+ let analysisPath = options.input;
386
+ if (!path.isAbsolute(analysisPath)) analysisPath = path.join(cwd, analysisPath);
387
+ if (!fs.existsSync(analysisPath)) error(`Analysis file not found: ${analysisPath}`);
388
+
389
+ let analysis;
390
+ try {
391
+ analysis = JSON.parse(fs.readFileSync(analysisPath, 'utf-8'));
392
+ } catch (err) {
393
+ error(`Failed to parse analysis JSON: ${err.message}`);
394
+ }
395
+
396
+ if (!analysis.dimensions || typeof analysis.dimensions !== 'object') {
397
+ error('Analysis JSON must contain a "dimensions" object');
398
+ }
399
+ if (!analysis.profile_version) {
400
+ error('Analysis JSON must contain "profile_version"');
401
+ }
402
+
403
+ const SENSITIVE_PATTERNS = [
404
+ /sk-[a-zA-Z0-9]{20,}/g,
405
+ /Bearer\s+[a-zA-Z0-9._-]+/gi,
406
+ /password\s*[:=]\s*\S+/gi,
407
+ /secret\s*[:=]\s*\S+/gi,
408
+ /token\s*[:=]\s*\S+/gi,
409
+ /api[_-]?key\s*[:=]\s*\S+/gi,
410
+ /\/Users\/[a-zA-Z0-9._-]+\//g,
411
+ /\/home\/[a-zA-Z0-9._-]+\//g,
412
+ /ghp_[a-zA-Z0-9]{36}/g,
413
+ /gho_[a-zA-Z0-9]{36}/g,
414
+ /xoxb-[a-zA-Z0-9-]+/g,
415
+ ];
416
+
417
+ let redactedCount = 0;
418
+
419
+ function redactSensitive(text) {
420
+ if (typeof text !== 'string') return text;
421
+ let result = text;
422
+ for (const pattern of SENSITIVE_PATTERNS) {
423
+ pattern.lastIndex = 0;
424
+ const matches = result.match(pattern);
425
+ if (matches) {
426
+ redactedCount += matches.length;
427
+ result = result.replace(pattern, '[REDACTED]');
428
+ }
429
+ }
430
+ return result;
431
+ }
432
+
433
+ for (const dimKey of Object.keys(analysis.dimensions)) {
434
+ const dim = analysis.dimensions[dimKey];
435
+ if (dim.evidence && Array.isArray(dim.evidence)) {
436
+ for (let i = 0; i < dim.evidence.length; i++) {
437
+ const ev = dim.evidence[i];
438
+ if (ev.quote) ev.quote = redactSensitive(ev.quote);
439
+ if (ev.example) ev.example = redactSensitive(ev.example);
440
+ if (ev.signal) ev.signal = redactSensitive(ev.signal);
441
+ }
442
+ }
443
+ }
444
+
445
+ if (redactedCount > 0) {
446
+ process.stderr.write(`Sensitive content redacted: ${redactedCount} pattern(s) removed from evidence quotes\n`);
447
+ }
448
+
449
+ const templatePath = path.join(__dirname, '..', '..', 'templates', 'user-profile.md');
450
+ if (!fs.existsSync(templatePath)) error(`Template not found: ${templatePath}`);
451
+ let template = fs.readFileSync(templatePath, 'utf-8');
452
+
453
+ const dimensionLabels = {
454
+ communication_style: 'Communication',
455
+ decision_speed: 'Decisions',
456
+ explanation_depth: 'Explanations',
457
+ debugging_approach: 'Debugging',
458
+ ux_philosophy: 'UX Philosophy',
459
+ vendor_philosophy: 'Vendor Philosophy',
460
+ frustration_triggers: 'Frustration Triggers',
461
+ learning_style: 'Learning Style',
462
+ };
463
+
464
+ const summaryLines = [];
465
+ let highCount = 0, mediumCount = 0, lowCount = 0, dimensionsScored = 0;
466
+
467
+ for (const dimKey of DIMENSION_KEYS) {
468
+ const dim = analysis.dimensions[dimKey];
469
+ if (!dim) continue;
470
+ const conf = (dim.confidence || '').toUpperCase();
471
+ if (conf === 'HIGH' || conf === 'MEDIUM' || conf === 'LOW') dimensionsScored++;
472
+ if (conf === 'HIGH') {
473
+ highCount++;
474
+ if (dim.claude_instruction) summaryLines.push(`- **${dimensionLabels[dimKey] || dimKey}:** ${dim.claude_instruction} (HIGH)`);
475
+ } else if (conf === 'MEDIUM') {
476
+ mediumCount++;
477
+ if (dim.claude_instruction) summaryLines.push(`- **${dimensionLabels[dimKey] || dimKey}:** ${dim.claude_instruction} (MEDIUM)`);
478
+ } else if (conf === 'LOW') {
479
+ lowCount++;
480
+ }
481
+ }
482
+
483
+ const summaryInstructions = summaryLines.length > 0
484
+ ? summaryLines.join('\n')
485
+ : '- No high or medium confidence dimensions scored yet.';
486
+
487
+ template = template.replace(/\{\{generated_at\}\}/g, new Date().toISOString());
488
+ template = template.replace(/\{\{data_source\}\}/g, analysis.data_source || 'session_analysis');
489
+ template = template.replace(/\{\{projects_list\}\}/g, (analysis.projects_list || analysis.projects_analyzed || []).join(', '));
490
+ template = template.replace(/\{\{message_count\}\}/g, String(analysis.message_count || analysis.messages_analyzed || 0));
491
+ template = template.replace(/\{\{summary_instructions\}\}/g, summaryInstructions);
492
+ template = template.replace(/\{\{profile_version\}\}/g, analysis.profile_version);
493
+ template = template.replace(/\{\{projects_count\}\}/g, String((analysis.projects_list || analysis.projects_analyzed || []).length));
494
+ template = template.replace(/\{\{dimensions_scored\}\}/g, String(dimensionsScored));
495
+ template = template.replace(/\{\{high_confidence_count\}\}/g, String(highCount));
496
+ template = template.replace(/\{\{medium_confidence_count\}\}/g, String(mediumCount));
497
+ template = template.replace(/\{\{low_confidence_count\}\}/g, String(lowCount));
498
+ template = template.replace(/\{\{sensitive_excluded_summary\}\}/g,
499
+ redactedCount > 0 ? `${redactedCount} pattern(s) redacted` : 'None detected');
500
+
501
+ for (const dimKey of DIMENSION_KEYS) {
502
+ const dim = analysis.dimensions[dimKey] || {};
503
+ const rating = dim.rating || 'UNSCORED';
504
+ const confidence = dim.confidence || 'UNSCORED';
505
+ const instruction = dim.claude_instruction || 'No strong preference detected. Ask the developer when this dimension is relevant.';
506
+ const summary = dim.summary || '';
507
+
508
+ let evidenceBlock = '';
509
+ const evidenceArr = dim.evidence_quotes || dim.evidence;
510
+ if (evidenceArr && Array.isArray(evidenceArr) && evidenceArr.length > 0) {
511
+ const evidenceLines = evidenceArr.map(ev => {
512
+ const signal = ev.signal || ev.pattern || '';
513
+ const quote = ev.quote || ev.example || '';
514
+ const project = ev.project || 'unknown';
515
+ return `- **Signal:** ${signal} / **Example:** "${quote}" -- project: ${project}`;
516
+ });
517
+ evidenceBlock = evidenceLines.join('\n');
518
+ } else {
519
+ evidenceBlock = '- No evidence collected for this dimension.';
520
+ }
521
+
522
+ template = template.replace(new RegExp(`\\{\\{${dimKey}\\.rating\\}\\}`, 'g'), rating);
523
+ template = template.replace(new RegExp(`\\{\\{${dimKey}\\.confidence\\}\\}`, 'g'), confidence);
524
+ template = template.replace(new RegExp(`\\{\\{${dimKey}\\.claude_instruction\\}\\}`, 'g'), instruction);
525
+ template = template.replace(new RegExp(`\\{\\{${dimKey}\\.summary\\}\\}`, 'g'), summary);
526
+ template = template.replace(new RegExp(`\\{\\{${dimKey}\\.evidence\\}\\}`, 'g'), evidenceBlock);
527
+ }
528
+
529
+ let outputPath = options.output;
530
+ if (!outputPath) {
531
+ outputPath = path.join(os.homedir(), '.claude', 'get-shit-done', 'USER-PROFILE.md');
532
+ } else if (!path.isAbsolute(outputPath)) {
533
+ outputPath = path.join(cwd, outputPath);
534
+ }
535
+
536
+ fs.mkdirSync(path.dirname(outputPath), { recursive: true });
537
+ fs.writeFileSync(outputPath, template, 'utf-8');
538
+
539
+ const result = {
540
+ profile_path: outputPath,
541
+ dimensions_scored: dimensionsScored,
542
+ high_confidence: highCount,
543
+ medium_confidence: mediumCount,
544
+ low_confidence: lowCount,
545
+ sensitive_redacted: redactedCount,
546
+ source: analysis.data_source || 'session_analysis',
547
+ };
548
+
549
+ output(result, raw);
550
+ }
551
+
552
+ function cmdProfileQuestionnaire(options, raw) {
553
+ if (!options.answers) {
554
+ const questionsOutput = {
555
+ mode: 'interactive',
556
+ questions: PROFILING_QUESTIONS.map(q => ({
557
+ dimension: q.dimension,
558
+ header: q.header,
559
+ context: q.context,
560
+ question: q.question,
561
+ options: q.options.map(o => ({ label: o.label, value: o.value })),
562
+ })),
563
+ };
564
+ output(questionsOutput, raw);
565
+ return;
566
+ }
567
+
568
+ const answerValues = options.answers.split(',').map(a => a.trim());
569
+ if (answerValues.length !== PROFILING_QUESTIONS.length) {
570
+ error(`Expected ${PROFILING_QUESTIONS.length} answers (comma-separated), got ${answerValues.length}`);
571
+ }
572
+
573
+ const analysis = {
574
+ profile_version: '1.0',
575
+ analyzed_at: new Date().toISOString(),
576
+ data_source: 'questionnaire',
577
+ projects_analyzed: [],
578
+ messages_analyzed: 0,
579
+ message_threshold: 'questionnaire',
580
+ sensitive_excluded: [],
581
+ dimensions: {},
582
+ };
583
+
584
+ for (let i = 0; i < PROFILING_QUESTIONS.length; i++) {
585
+ const question = PROFILING_QUESTIONS[i];
586
+ const answerValue = answerValues[i];
587
+ const selectedOption = question.options.find(o => o.value === answerValue);
588
+
589
+ if (!selectedOption) {
590
+ error(`Invalid answer "${answerValue}" for ${question.dimension}. Valid values: ${question.options.map(o => o.value).join(', ')}`);
591
+ }
592
+
593
+ const ambiguous = isAmbiguousAnswer(question.dimension, answerValue);
594
+
595
+ analysis.dimensions[question.dimension] = {
596
+ rating: selectedOption.rating,
597
+ confidence: ambiguous ? 'LOW' : 'MEDIUM',
598
+ evidence_count: 1,
599
+ cross_project_consistent: null,
600
+ evidence: [{
601
+ signal: 'Self-reported via questionnaire',
602
+ quote: selectedOption.label,
603
+ project: 'N/A (questionnaire)',
604
+ }],
605
+ summary: `Developer self-reported as ${selectedOption.rating} for ${question.header.toLowerCase()}.`,
606
+ claude_instruction: generateClaudeInstruction(question.dimension, selectedOption.rating),
607
+ };
608
+ }
609
+
610
+ output(analysis, raw);
611
+ }
612
+
613
+ function cmdGenerateDevPreferences(cwd, options, raw) {
614
+ if (!options.analysis) error('--analysis <path> is required');
615
+
616
+ let analysisPath = options.analysis;
617
+ if (!path.isAbsolute(analysisPath)) analysisPath = path.join(cwd, analysisPath);
618
+ if (!fs.existsSync(analysisPath)) error(`Analysis file not found: ${analysisPath}`);
619
+
620
+ let analysis;
621
+ try {
622
+ analysis = JSON.parse(fs.readFileSync(analysisPath, 'utf-8'));
623
+ } catch (err) {
624
+ error(`Failed to parse analysis JSON: ${err.message}`);
625
+ }
626
+
627
+ if (!analysis.dimensions || typeof analysis.dimensions !== 'object') {
628
+ error('Analysis JSON must contain a "dimensions" object');
629
+ }
630
+
631
+ const devPrefLabels = {
632
+ communication_style: 'Communication',
633
+ decision_speed: 'Decision Support',
634
+ explanation_depth: 'Explanations',
635
+ debugging_approach: 'Debugging',
636
+ ux_philosophy: 'UX Approach',
637
+ vendor_philosophy: 'Library & Tool Choices',
638
+ frustration_triggers: 'Boundaries',
639
+ learning_style: 'Learning Support',
640
+ };
641
+
642
+ const templatePath = path.join(__dirname, '..', '..', 'templates', 'dev-preferences.md');
643
+ if (!fs.existsSync(templatePath)) error(`Template not found: ${templatePath}`);
644
+ let template = fs.readFileSync(templatePath, 'utf-8');
645
+
646
+ const directiveLines = [];
647
+ const dimensionsIncluded = [];
648
+
649
+ for (const dimKey of DIMENSION_KEYS) {
650
+ const dim = analysis.dimensions[dimKey];
651
+ if (!dim) continue;
652
+ const label = devPrefLabels[dimKey] || dimKey;
653
+ const confidence = dim.confidence || 'UNSCORED';
654
+ let instruction = dim.claude_instruction;
655
+ if (!instruction) {
656
+ const lookup = CLAUDE_INSTRUCTIONS[dimKey];
657
+ if (lookup && dim.rating && lookup[dim.rating]) {
658
+ instruction = lookup[dim.rating];
659
+ } else {
660
+ instruction = `Adapt to this developer's ${dimKey.replace(/_/g, ' ')} preference.`;
661
+ }
662
+ }
663
+ directiveLines.push(`### ${label}\n${instruction} (${confidence} confidence)\n`);
664
+ dimensionsIncluded.push(dimKey);
665
+ }
666
+
667
+ const directivesBlock = directiveLines.join('\n').trim();
668
+ template = template.replace(/\{\{behavioral_directives\}\}/g, directivesBlock);
669
+ template = template.replace(/\{\{generated_at\}\}/g, new Date().toISOString());
670
+ template = template.replace(/\{\{data_source\}\}/g, analysis.data_source || 'session_analysis');
671
+
672
+ let stackBlock;
673
+ if (analysis.data_source === 'questionnaire') {
674
+ stackBlock = 'Stack preferences not available (questionnaire-only profile). Run `/gsd:profile-user --refresh` with session data to populate.';
675
+ } else if (options.stack) {
676
+ stackBlock = options.stack;
677
+ } else {
678
+ stackBlock = 'Stack preferences will be populated from session analysis.';
679
+ }
680
+ template = template.replace(/\{\{stack_preferences\}\}/g, stackBlock);
681
+
682
+ let outputPath = options.output;
683
+ if (!outputPath) {
684
+ outputPath = path.join(os.homedir(), '.claude', 'commands', 'gsd', 'dev-preferences.md');
685
+ } else if (!path.isAbsolute(outputPath)) {
686
+ outputPath = path.join(cwd, outputPath);
687
+ }
688
+
689
+ fs.mkdirSync(path.dirname(outputPath), { recursive: true });
690
+ fs.writeFileSync(outputPath, template, 'utf-8');
691
+
692
+ const result = {
693
+ command_path: outputPath,
694
+ command_name: '/gsd:dev-preferences',
695
+ dimensions_included: dimensionsIncluded,
696
+ source: analysis.data_source || 'session_analysis',
697
+ };
698
+
699
+ output(result, raw);
700
+ }
701
+
702
+ function cmdGenerateClaudeProfile(cwd, options, raw) {
703
+ if (!options.analysis) error('--analysis <path> is required');
704
+
705
+ let analysisPath = options.analysis;
706
+ if (!path.isAbsolute(analysisPath)) analysisPath = path.join(cwd, analysisPath);
707
+ if (!fs.existsSync(analysisPath)) error(`Analysis file not found: ${analysisPath}`);
708
+
709
+ let analysis;
710
+ try {
711
+ analysis = JSON.parse(fs.readFileSync(analysisPath, 'utf-8'));
712
+ } catch (err) {
713
+ error(`Failed to parse analysis JSON: ${err.message}`);
714
+ }
715
+
716
+ if (!analysis.dimensions || typeof analysis.dimensions !== 'object') {
717
+ error('Analysis JSON must contain a "dimensions" object');
718
+ }
719
+
720
+ const profileLabels = {
721
+ communication_style: 'Communication',
722
+ decision_speed: 'Decisions',
723
+ explanation_depth: 'Explanations',
724
+ debugging_approach: 'Debugging',
725
+ ux_philosophy: 'UX Philosophy',
726
+ vendor_philosophy: 'Vendor Choices',
727
+ frustration_triggers: 'Frustrations',
728
+ learning_style: 'Learning',
729
+ };
730
+
731
+ const dataSource = analysis.data_source || 'session_analysis';
732
+ const tableRows = [];
733
+ const directiveLines = [];
734
+ const dimensionsIncluded = [];
735
+
736
+ for (const dimKey of DIMENSION_KEYS) {
737
+ const dim = analysis.dimensions[dimKey];
738
+ if (!dim) continue;
739
+ const label = profileLabels[dimKey] || dimKey;
740
+ const rating = dim.rating || 'UNSCORED';
741
+ const confidence = dim.confidence || 'UNSCORED';
742
+ tableRows.push(`| ${label} | ${rating} | ${confidence} |`);
743
+ let instruction = dim.claude_instruction;
744
+ if (!instruction) {
745
+ const lookup = CLAUDE_INSTRUCTIONS[dimKey];
746
+ if (lookup && dim.rating && lookup[dim.rating]) {
747
+ instruction = lookup[dim.rating];
748
+ } else {
749
+ instruction = `Adapt to this developer's ${dimKey.replace(/_/g, ' ')} preference.`;
750
+ }
751
+ }
752
+ directiveLines.push(`- **${label}:** ${instruction}`);
753
+ dimensionsIncluded.push(dimKey);
754
+ }
755
+
756
+ const sectionLines = [
757
+ '<!-- GSD:profile-start -->',
758
+ '## Developer Profile',
759
+ '',
760
+ `> Generated by GSD from ${dataSource}. Run \`/gsd:profile-user --refresh\` to update.`,
761
+ '',
762
+ '| Dimension | Rating | Confidence |',
763
+ '|-----------|--------|------------|',
764
+ ...tableRows,
765
+ '',
766
+ '**Directives:**',
767
+ ...directiveLines,
768
+ '<!-- GSD:profile-end -->',
769
+ ];
770
+
771
+ const sectionContent = sectionLines.join('\n');
772
+
773
+ let targetPath;
774
+ if (options.global) {
775
+ targetPath = path.join(os.homedir(), '.claude', 'CLAUDE.md');
776
+ } else if (options.output) {
777
+ targetPath = path.isAbsolute(options.output) ? options.output : path.join(cwd, options.output);
778
+ } else {
779
+ targetPath = path.join(cwd, 'CLAUDE.md');
780
+ }
781
+
782
+ let action;
783
+
784
+ if (fs.existsSync(targetPath)) {
785
+ let existingContent = fs.readFileSync(targetPath, 'utf-8');
786
+ const startMarker = '<!-- GSD:profile-start -->';
787
+ const endMarker = '<!-- GSD:profile-end -->';
788
+ const startIdx = existingContent.indexOf(startMarker);
789
+ const endIdx = existingContent.indexOf(endMarker);
790
+
791
+ if (startIdx !== -1 && endIdx !== -1) {
792
+ const before = existingContent.substring(0, startIdx);
793
+ const after = existingContent.substring(endIdx + endMarker.length);
794
+ existingContent = before + sectionContent + after;
795
+ action = 'updated';
796
+ } else {
797
+ existingContent = existingContent.trimEnd() + '\n\n' + sectionContent + '\n';
798
+ action = 'appended';
799
+ }
800
+ fs.writeFileSync(targetPath, existingContent, 'utf-8');
801
+ } else {
802
+ fs.mkdirSync(path.dirname(targetPath), { recursive: true });
803
+ fs.writeFileSync(targetPath, sectionContent + '\n', 'utf-8');
804
+ action = 'created';
805
+ }
806
+
807
+ const result = {
808
+ claude_md_path: targetPath,
809
+ action,
810
+ dimensions_included: dimensionsIncluded,
811
+ is_global: !!options.global,
812
+ };
813
+
814
+ output(result, raw);
815
+ }
816
+
817
+ function cmdGenerateClaudeMd(cwd, options, raw) {
818
+ const MANAGED_SECTIONS = ['project', 'stack', 'conventions', 'architecture', 'workflow'];
819
+ const generators = {
820
+ project: generateProjectSection,
821
+ stack: generateStackSection,
822
+ conventions: generateConventionsSection,
823
+ architecture: generateArchitectureSection,
824
+ workflow: generateWorkflowSection,
825
+ };
826
+ const sectionHeadings = {
827
+ project: '## Project',
828
+ stack: '## Technology Stack',
829
+ conventions: '## Conventions',
830
+ architecture: '## Architecture',
831
+ workflow: '## GSD Workflow Enforcement',
832
+ };
833
+
834
+ const generated = {};
835
+ const sectionsGenerated = [];
836
+ const sectionsFallback = [];
837
+ const sectionsSkipped = [];
838
+
839
+ for (const name of MANAGED_SECTIONS) {
840
+ const gen = generators[name](cwd);
841
+ generated[name] = gen;
842
+ if (gen.hasFallback) {
843
+ sectionsFallback.push(name);
844
+ } else {
845
+ sectionsGenerated.push(name);
846
+ }
847
+ }
848
+
849
+ let outputPath = options.output;
850
+ if (!outputPath) {
851
+ outputPath = path.join(cwd, 'CLAUDE.md');
852
+ } else if (!path.isAbsolute(outputPath)) {
853
+ outputPath = path.join(cwd, outputPath);
854
+ }
855
+
856
+ let existingContent = safeReadFile(outputPath);
857
+ let action;
858
+
859
+ if (existingContent === null) {
860
+ const sections = [];
861
+ for (const name of MANAGED_SECTIONS) {
862
+ const gen = generated[name];
863
+ const heading = sectionHeadings[name];
864
+ const body = `${heading}\n\n${gen.content}`;
865
+ sections.push(buildSection(name, gen.source, body));
866
+ }
867
+ sections.push('');
868
+ sections.push(CLAUDE_MD_PROFILE_PLACEHOLDER);
869
+ existingContent = sections.join('\n\n') + '\n';
870
+ action = 'created';
871
+ fs.mkdirSync(path.dirname(outputPath), { recursive: true });
872
+ fs.writeFileSync(outputPath, existingContent, 'utf-8');
873
+ } else {
874
+ action = 'updated';
875
+ let fileContent = existingContent;
876
+
877
+ for (const name of MANAGED_SECTIONS) {
878
+ const gen = generated[name];
879
+ const heading = sectionHeadings[name];
880
+ const body = `${heading}\n\n${gen.content}`;
881
+ const fullSection = buildSection(name, gen.source, body);
882
+ const hasMarkers = fileContent.indexOf(`<!-- GSD:${name}-start`) !== -1;
883
+
884
+ if (hasMarkers) {
885
+ if (options.auto) {
886
+ const expectedBody = `${heading}\n\n${gen.content}`;
887
+ if (detectManualEdit(fileContent, name, expectedBody)) {
888
+ sectionsSkipped.push(name);
889
+ const genIdx = sectionsGenerated.indexOf(name);
890
+ if (genIdx !== -1) sectionsGenerated.splice(genIdx, 1);
891
+ const fbIdx = sectionsFallback.indexOf(name);
892
+ if (fbIdx !== -1) sectionsFallback.splice(fbIdx, 1);
893
+ continue;
894
+ }
895
+ }
896
+ const result = updateSection(fileContent, name, fullSection);
897
+ fileContent = result.content;
898
+ } else {
899
+ const result = updateSection(fileContent, name, fullSection);
900
+ fileContent = result.content;
901
+ }
902
+ }
903
+
904
+ if (!options.auto && fileContent.indexOf('<!-- GSD:profile-start') === -1) {
905
+ fileContent = fileContent.trimEnd() + '\n\n' + CLAUDE_MD_PROFILE_PLACEHOLDER + '\n';
906
+ }
907
+
908
+ fs.writeFileSync(outputPath, fileContent, 'utf-8');
909
+ }
910
+
911
+ const finalContent = safeReadFile(outputPath);
912
+ let profileStatus;
913
+ if (finalContent && finalContent.indexOf('<!-- GSD:profile-start') !== -1) {
914
+ if (action === 'created' || existingContent.indexOf('<!-- GSD:profile-start') === -1) {
915
+ profileStatus = 'placeholder_added';
916
+ } else {
917
+ profileStatus = 'exists';
918
+ }
919
+ } else {
920
+ profileStatus = 'already_present';
921
+ }
922
+
923
+ const genCount = sectionsGenerated.length;
924
+ const totalManaged = MANAGED_SECTIONS.length;
925
+ let message = `Generated ${genCount}/${totalManaged} sections.`;
926
+ if (sectionsFallback.length > 0) message += ` Fallback: ${sectionsFallback.join(', ')}.`;
927
+ if (sectionsSkipped.length > 0) message += ` Skipped (manually edited): ${sectionsSkipped.join(', ')}.`;
928
+ if (profileStatus === 'placeholder_added') message += ' Run /gsd:profile-user to unlock Developer Profile.';
929
+
930
+ const result = {
931
+ claude_md_path: outputPath,
932
+ action,
933
+ sections_generated: sectionsGenerated,
934
+ sections_fallback: sectionsFallback,
935
+ sections_skipped: sectionsSkipped,
936
+ sections_total: totalManaged,
937
+ profile_status: profileStatus,
938
+ message,
939
+ };
940
+
941
+ output(result, raw);
942
+ }
943
+
944
+ module.exports = {
945
+ cmdWriteProfile,
946
+ cmdProfileQuestionnaire,
947
+ cmdGenerateDevPreferences,
948
+ cmdGenerateClaudeProfile,
949
+ cmdGenerateClaudeMd,
950
+ PROFILING_QUESTIONS,
951
+ CLAUDE_INSTRUCTIONS,
952
+ };