code-as-plan 2.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 (188) 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 +1006 -0
  5. package/README.pt-BR.md +452 -0
  6. package/README.zh-CN.md +800 -0
  7. package/agents/cap-brainstormer.md +154 -0
  8. package/agents/cap-debugger.md +221 -0
  9. package/agents/cap-prototyper.md +170 -0
  10. package/agents/cap-reviewer.md +230 -0
  11. package/agents/cap-tester.md +193 -0
  12. package/bin/install.js +5002 -0
  13. package/cap/bin/gsd-tools.cjs +1141 -0
  14. package/cap/bin/lib/arc-scanner.cjs +341 -0
  15. package/cap/bin/lib/cap-feature-map.cjs +506 -0
  16. package/cap/bin/lib/cap-session.cjs +191 -0
  17. package/cap/bin/lib/cap-stack-docs.cjs +598 -0
  18. package/cap/bin/lib/cap-tag-scanner.cjs +458 -0
  19. package/cap/bin/lib/commands.cjs +959 -0
  20. package/cap/bin/lib/config.cjs +466 -0
  21. package/cap/bin/lib/convention-reader.cjs +180 -0
  22. package/cap/bin/lib/core.cjs +1230 -0
  23. package/cap/bin/lib/feature-aggregator.cjs +422 -0
  24. package/cap/bin/lib/frontmatter.cjs +336 -0
  25. package/cap/bin/lib/init.cjs +1442 -0
  26. package/cap/bin/lib/manifest-generator.cjs +381 -0
  27. package/cap/bin/lib/milestone.cjs +252 -0
  28. package/cap/bin/lib/model-profiles.cjs +68 -0
  29. package/cap/bin/lib/monorepo-context.cjs +224 -0
  30. package/cap/bin/lib/monorepo-migrator.cjs +507 -0
  31. package/cap/bin/lib/phase.cjs +888 -0
  32. package/cap/bin/lib/profile-output.cjs +952 -0
  33. package/cap/bin/lib/profile-pipeline.cjs +539 -0
  34. package/cap/bin/lib/roadmap.cjs +329 -0
  35. package/cap/bin/lib/security.cjs +382 -0
  36. package/cap/bin/lib/session-manager.cjs +290 -0
  37. package/cap/bin/lib/skeleton-generator.cjs +177 -0
  38. package/cap/bin/lib/state.cjs +1031 -0
  39. package/cap/bin/lib/template.cjs +222 -0
  40. package/cap/bin/lib/test-detector.cjs +61 -0
  41. package/cap/bin/lib/uat.cjs +282 -0
  42. package/cap/bin/lib/verify.cjs +888 -0
  43. package/cap/bin/lib/workspace-detector.cjs +369 -0
  44. package/cap/bin/lib/workstream.cjs +491 -0
  45. package/cap/commands/gsd/workstreams.md +63 -0
  46. package/cap/references/arc-standard.md +315 -0
  47. package/cap/references/cap-agent-architecture.md +102 -0
  48. package/cap/references/cap-gitignore-template +9 -0
  49. package/cap/references/cap-zero-deps.md +158 -0
  50. package/cap/references/checkpoints.md +778 -0
  51. package/cap/references/continuation-format.md +249 -0
  52. package/cap/references/decimal-phase-calculation.md +64 -0
  53. package/cap/references/feature-map-template.md +25 -0
  54. package/cap/references/git-integration.md +295 -0
  55. package/cap/references/git-planning-commit.md +38 -0
  56. package/cap/references/model-profile-resolution.md +36 -0
  57. package/cap/references/model-profiles.md +139 -0
  58. package/cap/references/phase-argument-parsing.md +61 -0
  59. package/cap/references/planning-config.md +202 -0
  60. package/cap/references/questioning.md +162 -0
  61. package/cap/references/session-template.json +8 -0
  62. package/cap/references/tdd.md +263 -0
  63. package/cap/references/ui-brand.md +160 -0
  64. package/cap/references/user-profiling.md +681 -0
  65. package/cap/references/verification-patterns.md +612 -0
  66. package/cap/references/workstream-flag.md +58 -0
  67. package/cap/templates/DEBUG.md +164 -0
  68. package/cap/templates/UAT.md +265 -0
  69. package/cap/templates/UI-SPEC.md +100 -0
  70. package/cap/templates/VALIDATION.md +76 -0
  71. package/cap/templates/claude-md.md +122 -0
  72. package/cap/templates/codebase/architecture.md +255 -0
  73. package/cap/templates/codebase/concerns.md +310 -0
  74. package/cap/templates/codebase/conventions.md +307 -0
  75. package/cap/templates/codebase/integrations.md +280 -0
  76. package/cap/templates/codebase/stack.md +186 -0
  77. package/cap/templates/codebase/structure.md +285 -0
  78. package/cap/templates/codebase/testing.md +480 -0
  79. package/cap/templates/config.json +44 -0
  80. package/cap/templates/context.md +352 -0
  81. package/cap/templates/continue-here.md +78 -0
  82. package/cap/templates/copilot-instructions.md +7 -0
  83. package/cap/templates/debug-subagent-prompt.md +91 -0
  84. package/cap/templates/dev-preferences.md +21 -0
  85. package/cap/templates/discovery.md +146 -0
  86. package/cap/templates/discussion-log.md +63 -0
  87. package/cap/templates/milestone-archive.md +123 -0
  88. package/cap/templates/milestone.md +115 -0
  89. package/cap/templates/phase-prompt.md +610 -0
  90. package/cap/templates/planner-subagent-prompt.md +117 -0
  91. package/cap/templates/project.md +186 -0
  92. package/cap/templates/requirements.md +231 -0
  93. package/cap/templates/research-project/ARCHITECTURE.md +204 -0
  94. package/cap/templates/research-project/FEATURES.md +147 -0
  95. package/cap/templates/research-project/PITFALLS.md +200 -0
  96. package/cap/templates/research-project/STACK.md +120 -0
  97. package/cap/templates/research-project/SUMMARY.md +170 -0
  98. package/cap/templates/research.md +552 -0
  99. package/cap/templates/retrospective.md +54 -0
  100. package/cap/templates/roadmap.md +202 -0
  101. package/cap/templates/state.md +176 -0
  102. package/cap/templates/summary-complex.md +59 -0
  103. package/cap/templates/summary-minimal.md +41 -0
  104. package/cap/templates/summary-standard.md +48 -0
  105. package/cap/templates/summary.md +248 -0
  106. package/cap/templates/user-profile.md +146 -0
  107. package/cap/templates/user-setup.md +311 -0
  108. package/cap/templates/verification-report.md +322 -0
  109. package/cap/workflows/add-phase.md +112 -0
  110. package/cap/workflows/add-tests.md +351 -0
  111. package/cap/workflows/add-todo.md +158 -0
  112. package/cap/workflows/audit-milestone.md +340 -0
  113. package/cap/workflows/audit-uat.md +109 -0
  114. package/cap/workflows/autonomous.md +891 -0
  115. package/cap/workflows/check-todos.md +177 -0
  116. package/cap/workflows/cleanup.md +152 -0
  117. package/cap/workflows/complete-milestone.md +767 -0
  118. package/cap/workflows/diagnose-issues.md +231 -0
  119. package/cap/workflows/discovery-phase.md +289 -0
  120. package/cap/workflows/discuss-phase-assumptions.md +653 -0
  121. package/cap/workflows/discuss-phase.md +1049 -0
  122. package/cap/workflows/do.md +104 -0
  123. package/cap/workflows/execute-phase.md +846 -0
  124. package/cap/workflows/execute-plan.md +514 -0
  125. package/cap/workflows/fast.md +105 -0
  126. package/cap/workflows/forensics.md +265 -0
  127. package/cap/workflows/health.md +181 -0
  128. package/cap/workflows/help.md +660 -0
  129. package/cap/workflows/insert-phase.md +130 -0
  130. package/cap/workflows/list-phase-assumptions.md +178 -0
  131. package/cap/workflows/list-workspaces.md +56 -0
  132. package/cap/workflows/manager.md +362 -0
  133. package/cap/workflows/map-codebase.md +377 -0
  134. package/cap/workflows/milestone-summary.md +223 -0
  135. package/cap/workflows/new-milestone.md +486 -0
  136. package/cap/workflows/new-project.md +1250 -0
  137. package/cap/workflows/new-workspace.md +237 -0
  138. package/cap/workflows/next.md +97 -0
  139. package/cap/workflows/node-repair.md +92 -0
  140. package/cap/workflows/note.md +156 -0
  141. package/cap/workflows/pause-work.md +176 -0
  142. package/cap/workflows/plan-milestone-gaps.md +273 -0
  143. package/cap/workflows/plan-phase.md +859 -0
  144. package/cap/workflows/plant-seed.md +169 -0
  145. package/cap/workflows/pr-branch.md +129 -0
  146. package/cap/workflows/profile-user.md +450 -0
  147. package/cap/workflows/progress.md +507 -0
  148. package/cap/workflows/quick.md +757 -0
  149. package/cap/workflows/remove-phase.md +155 -0
  150. package/cap/workflows/remove-workspace.md +90 -0
  151. package/cap/workflows/research-phase.md +82 -0
  152. package/cap/workflows/resume-project.md +326 -0
  153. package/cap/workflows/review.md +228 -0
  154. package/cap/workflows/session-report.md +146 -0
  155. package/cap/workflows/settings.md +283 -0
  156. package/cap/workflows/ship.md +228 -0
  157. package/cap/workflows/stats.md +60 -0
  158. package/cap/workflows/transition.md +671 -0
  159. package/cap/workflows/ui-phase.md +302 -0
  160. package/cap/workflows/ui-review.md +165 -0
  161. package/cap/workflows/update.md +323 -0
  162. package/cap/workflows/validate-phase.md +174 -0
  163. package/cap/workflows/verify-phase.md +254 -0
  164. package/cap/workflows/verify-work.md +637 -0
  165. package/commands/cap/annotate.md +165 -0
  166. package/commands/cap/brainstorm.md +238 -0
  167. package/commands/cap/debug.md +297 -0
  168. package/commands/cap/init.md +262 -0
  169. package/commands/cap/iterate.md +234 -0
  170. package/commands/cap/prototype.md +281 -0
  171. package/commands/cap/refresh-docs.md +37 -0
  172. package/commands/cap/review.md +272 -0
  173. package/commands/cap/scan.md +249 -0
  174. package/commands/cap/start.md +234 -0
  175. package/commands/cap/status.md +189 -0
  176. package/commands/cap/test.md +250 -0
  177. package/hooks/dist/gsd-check-update.js +114 -0
  178. package/hooks/dist/gsd-context-monitor.js +156 -0
  179. package/hooks/dist/gsd-prompt-guard.js +96 -0
  180. package/hooks/dist/gsd-statusline.js +119 -0
  181. package/hooks/dist/gsd-workflow-guard.js +94 -0
  182. package/package.json +51 -0
  183. package/scripts/base64-scan.sh +262 -0
  184. package/scripts/build-hooks.js +82 -0
  185. package/scripts/cap-removal-checklist.md +202 -0
  186. package/scripts/prompt-injection-scan.sh +198 -0
  187. package/scripts/run-tests.cjs +29 -0
  188. package/scripts/secret-scan.sh +227 -0
@@ -0,0 +1,224 @@
1
+ // @gsd-context Monorepo context resolver -- assembles per-app planning paths and agent context for scoped operations
2
+ // @gsd-decision Separate module from workspace-detector to keep detection (read-only) separate from planning structure (write operations)
3
+ // @gsd-constraint Zero external dependencies -- uses only Node.js built-ins (fs, path)
4
+ // @gsd-ref(ref:AC-3) Each scoped app gets its own .planning/ directory with independent CODE-INVENTORY.md, PRD.md, and FEATURES.md
5
+ // @gsd-ref(ref:AC-7) Root .planning/ holds global decisions; app .planning/ holds app-specific work
6
+ // @gsd-pattern Two-level planning: root .planning/ for global context, app-path/.planning/ for scoped work
7
+
8
+ 'use strict';
9
+
10
+ const fs = require('node:fs');
11
+ const path = require('node:path');
12
+
13
+ // @gsd-api resolveAppPlanningDir(rootPath, appRelativePath) -- returns absolute path to app-scoped .planning/ directory
14
+
15
+ /**
16
+ * @typedef {Object} MonorepoContext
17
+ * @property {string} rootPlanningDir - Absolute path to root .planning/
18
+ * @property {string} appPlanningDir - Absolute path to app-scoped .planning/
19
+ * @property {string} appRoot - Absolute path to the scoped app directory
20
+ * @property {string} appName - Name of the scoped app
21
+ * @property {string[]} manifestPaths - Paths to relevant package manifests for this app
22
+ * @property {Object} globalContext - Parsed global planning docs (lightweight refs)
23
+ */
24
+
25
+ /**
26
+ * Resolve the .planning/ directory for an app-scoped operation.
27
+ *
28
+ * @param {string} rootPath - Monorepo root
29
+ * @param {string} appRelativePath - Relative path to the app (e.g., 'apps/dashboard')
30
+ * @returns {string} Absolute path to app .planning/ directory
31
+ */
32
+ function resolveAppPlanningDir(rootPath, appRelativePath) {
33
+ return path.join(rootPath, appRelativePath, '.planning');
34
+ }
35
+
36
+ /**
37
+ * Initialize the per-app .planning/ directory structure.
38
+ * Creates the directory and placeholder files mirroring root .planning/.
39
+ *
40
+ * @param {string} rootPath - Monorepo root
41
+ * @param {string} appRelativePath - Relative path to the app
42
+ * @param {Object} [options]
43
+ * @param {string} [options.appName] - Display name for headers
44
+ * @returns {string} Path to created .planning/ directory
45
+ */
46
+ function initAppPlanning(rootPath, appRelativePath, options) {
47
+ options = options || {};
48
+ const appPlanningDir = resolveAppPlanningDir(rootPath, appRelativePath);
49
+ const appName = options.appName || path.basename(appRelativePath);
50
+
51
+ fs.mkdirSync(appPlanningDir, { recursive: true });
52
+ fs.mkdirSync(path.join(appPlanningDir, 'prototype'), { recursive: true });
53
+
54
+ // @gsd-decision Create stub PRD.md and FEATURES.md in app .planning/ -- agents expect these files to exist
55
+ const prdPath = path.join(appPlanningDir, 'PRD.md');
56
+ if (!fs.existsSync(prdPath)) {
57
+ fs.writeFileSync(prdPath, `# ${appName} -- PRD\n\nApp-scoped PRD. Generated by monorepo-init.\n`, 'utf-8');
58
+ }
59
+
60
+ const featuresPath = path.join(appPlanningDir, 'FEATURES.md');
61
+ if (!fs.existsSync(featuresPath)) {
62
+ fs.writeFileSync(featuresPath, `# ${appName} -- Feature Map\n\nAuto-generated. Run extract-plan --app ${appRelativePath} to populate.\n`, 'utf-8');
63
+ }
64
+
65
+ // Create prototype/CODE-INVENTORY.md stub
66
+ const codeInventoryPath = path.join(appPlanningDir, 'prototype', 'CODE-INVENTORY.md');
67
+ if (!fs.existsSync(codeInventoryPath)) {
68
+ fs.writeFileSync(codeInventoryPath, `# CODE-INVENTORY.md\n\nRun /gsd:extract-plan --app ${appRelativePath} to populate.\n`, 'utf-8');
69
+ }
70
+
71
+ return appPlanningDir;
72
+ }
73
+
74
+ /**
75
+ * Build the full MonorepoContext for an app-scoped operation.
76
+ * This is the primary function agents consume to get focused context.
77
+ *
78
+ * @param {string} rootPath - Monorepo root
79
+ * @param {string} appRelativePath - Relative path to app
80
+ * @param {Object} [options]
81
+ * @param {string} [options.appName] - App display name
82
+ * @param {string[]} [options.appDependencies] - Package names this app depends on
83
+ * @returns {MonorepoContext}
84
+ */
85
+ // @gsd-api buildMonorepoContext(rootPath, appRelativePath, options) -- returns MonorepoContext with local + global planning refs
86
+ function buildMonorepoContext(rootPath, appRelativePath, options) {
87
+ options = options || {};
88
+ const appAbsPath = path.join(rootPath, appRelativePath);
89
+ const appPlanningDir = resolveAppPlanningDir(rootPath, appRelativePath);
90
+ const rootPlanningDir = path.join(rootPath, '.planning');
91
+ const manifestsDir = path.join(rootPlanningDir, 'manifests');
92
+
93
+ const manifestPaths = resolveRelevantManifests(manifestsDir, appAbsPath, options.appDependencies || []);
94
+
95
+ // @gsd-decision Load global context lazily -- only read file headers, not full content, to minimize token usage
96
+ const globalContext = loadGlobalContextRefs(rootPlanningDir);
97
+
98
+ return {
99
+ rootPlanningDir,
100
+ appPlanningDir,
101
+ appRoot: appAbsPath,
102
+ appName: options.appName || path.basename(appRelativePath),
103
+ manifestPaths,
104
+ globalContext,
105
+ };
106
+ }
107
+
108
+ /**
109
+ * Find package manifests relevant to a specific app based on its dependencies.
110
+ *
111
+ * @param {string} manifestsDir - Path to .planning/manifests/
112
+ * @param {string} appAbsPath - Absolute path to the app
113
+ * @param {string[]} knownDeps - Package names from workspace detection
114
+ * @returns {string[]} Paths to relevant manifest .md files
115
+ */
116
+ function resolveRelevantManifests(manifestsDir, appAbsPath, knownDeps) {
117
+ // @gsd-risk If app package.json is missing or malformed, no manifests are resolved -- agent gets no package context
118
+ const manifestPaths = [];
119
+
120
+ if (!fs.existsSync(manifestsDir)) return manifestPaths;
121
+
122
+ // Read app's package.json for its dependencies
123
+ const appPkgPath = path.join(appAbsPath, 'package.json');
124
+ let appDeps = [...knownDeps];
125
+
126
+ try {
127
+ const appPkg = JSON.parse(fs.readFileSync(appPkgPath, 'utf-8'));
128
+ const allDeps = { ...(appPkg.dependencies || {}), ...(appPkg.devDependencies || {}) };
129
+ for (const [name, version] of Object.entries(allDeps)) {
130
+ if (typeof version === 'string' && version.startsWith('workspace:')) {
131
+ if (!appDeps.includes(name)) appDeps.push(name);
132
+ }
133
+ }
134
+ } catch {
135
+ // No package.json or malformed -- use knownDeps only
136
+ }
137
+
138
+ // Match dependency names to manifest files
139
+ try {
140
+ const manifestFiles = fs.readdirSync(manifestsDir).filter(f => f.endsWith('.md'));
141
+ for (const file of manifestFiles) {
142
+ const baseName = file.replace('.md', '').replace(/__/g, '/');
143
+ // Check if any app dependency matches this manifest (with or without @ prefix)
144
+ const matches = appDeps.some(dep => {
145
+ const depNorm = dep.replace(/^@/, '');
146
+ return baseName === depNorm || baseName === dep;
147
+ });
148
+ if (matches) {
149
+ manifestPaths.push(path.join(manifestsDir, file));
150
+ }
151
+ }
152
+ } catch {
153
+ // manifestsDir not readable
154
+ }
155
+
156
+ return manifestPaths;
157
+ }
158
+
159
+ /**
160
+ * Load lightweight references from global .planning/ docs.
161
+ * Reads only headers and first paragraphs to minimize context size.
162
+ *
163
+ * @param {string} rootPlanningDir - Path to root .planning/
164
+ * @returns {Object} Global context references
165
+ */
166
+ function loadGlobalContextRefs(rootPlanningDir) {
167
+ const refs = {
168
+ hasProject: false,
169
+ hasRoadmap: false,
170
+ hasRequirements: false,
171
+ projectSummary: null,
172
+ };
173
+
174
+ const projectPath = path.join(rootPlanningDir, 'PROJECT.md');
175
+ if (fs.existsSync(projectPath)) {
176
+ refs.hasProject = true;
177
+ try {
178
+ const content = fs.readFileSync(projectPath, 'utf-8');
179
+ // Extract first 5 lines as summary
180
+ refs.projectSummary = content.split('\n').slice(0, 5).join('\n');
181
+ } catch {
182
+ // Ignore
183
+ }
184
+ }
185
+
186
+ refs.hasRoadmap = fs.existsSync(path.join(rootPlanningDir, 'ROADMAP.md'));
187
+ refs.hasRequirements = fs.existsSync(path.join(rootPlanningDir, 'REQUIREMENTS.md'));
188
+
189
+ return refs;
190
+ }
191
+
192
+ /**
193
+ * Modify extract-tags scan path to scope to an app directory.
194
+ * Used by the --app flag in gsd-tools.cjs extract-tags case.
195
+ *
196
+ * @param {string} rootPath - Monorepo root
197
+ * @param {string} appRelativePath - App-scoped path
198
+ * @param {Object} originalOpts - Original extract-tags options
199
+ * @returns {Object} Modified options with scoped targetPath and outputFile
200
+ */
201
+ // @gsd-api scopeExtractTags(rootPath, appRelativePath, originalOpts) -- returns modified options for app-scoped tag extraction
202
+ function scopeExtractTags(rootPath, appRelativePath, originalOpts) {
203
+ const appAbsPath = path.join(rootPath, appRelativePath);
204
+ const appPlanningDir = resolveAppPlanningDir(rootPath, appRelativePath);
205
+
206
+ return {
207
+ ...originalOpts,
208
+ // Override target path to scan only the app directory
209
+ targetPath: appAbsPath,
210
+ // Write output to app-scoped .planning/prototype/
211
+ outputFile: originalOpts.outputFile
212
+ ? path.join(appPlanningDir, 'prototype', path.basename(originalOpts.outputFile))
213
+ : originalOpts.outputFile,
214
+ };
215
+ }
216
+
217
+ module.exports = {
218
+ resolveAppPlanningDir,
219
+ initAppPlanning,
220
+ buildMonorepoContext,
221
+ resolveRelevantManifests,
222
+ loadGlobalContextRefs,
223
+ scopeExtractTags,
224
+ };