forge-workflow 0.0.1
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.
- package/.claude/commands/dev.md +314 -0
- package/.claude/commands/plan.md +389 -0
- package/.claude/commands/premerge.md +179 -0
- package/.claude/commands/research.md +42 -0
- package/.claude/commands/review.md +442 -0
- package/.claude/commands/rollback.md +721 -0
- package/.claude/commands/ship.md +134 -0
- package/.claude/commands/sonarcloud.md +152 -0
- package/.claude/commands/status.md +77 -0
- package/.claude/commands/validate.md +237 -0
- package/.claude/commands/verify.md +221 -0
- package/.claude/rules/greptile-review-process.md +285 -0
- package/.claude/rules/workflow.md +105 -0
- package/.claude/scripts/greptile-resolve.sh +526 -0
- package/.claude/scripts/load-env.sh +32 -0
- package/.forge/hooks/check-tdd.js +240 -0
- package/.github/PLUGIN_TEMPLATE.json +32 -0
- package/.mcp.json.example +12 -0
- package/AGENTS.md +169 -0
- package/CLAUDE.md +99 -0
- package/LICENSE +21 -0
- package/README.md +414 -0
- package/bin/forge-cmd.js +313 -0
- package/bin/forge-validate.js +303 -0
- package/bin/forge.js +4228 -0
- package/docs/AGENT_INSTALL_PROMPT.md +342 -0
- package/docs/ENHANCED_ONBOARDING.md +602 -0
- package/docs/EXAMPLES.md +482 -0
- package/docs/GREPTILE_SETUP.md +400 -0
- package/docs/MANUAL_REVIEW_GUIDE.md +106 -0
- package/docs/ROADMAP.md +359 -0
- package/docs/SETUP.md +632 -0
- package/docs/TOOLCHAIN.md +849 -0
- package/docs/VALIDATION.md +363 -0
- package/docs/WORKFLOW.md +400 -0
- package/docs/planning/PROGRESS.md +396 -0
- package/docs/plans/.gitkeep +0 -0
- package/docs/plans/2026-02-27-forge-test-suite-v2-decisions.md +21 -0
- package/docs/plans/2026-02-27-forge-test-suite-v2-design.md +362 -0
- package/docs/plans/2026-02-27-forge-test-suite-v2-tasks.md +343 -0
- package/docs/plans/2026-03-02-superpowers-gaps-decisions.md +26 -0
- package/docs/plans/2026-03-02-superpowers-gaps-design.md +239 -0
- package/docs/plans/2026-03-02-superpowers-gaps-tasks.md +260 -0
- package/docs/plans/2026-03-04-agent-command-parity-design.md +163 -0
- package/docs/plans/2026-03-04-verify-worktree-cleanup-decisions.md +7 -0
- package/docs/plans/2026-03-04-verify-worktree-cleanup-design.md +165 -0
- package/docs/plans/2026-03-05-forge-uto-decisions.md +6 -0
- package/docs/plans/2026-03-05-forge-uto-design.md +116 -0
- package/docs/plans/2026-03-05-forge-uto-tasks.md +244 -0
- package/docs/plans/2026-03-10-command-creator-and-eval-decisions.md +52 -0
- package/docs/plans/2026-03-10-command-creator-and-eval-design.md +350 -0
- package/docs/plans/2026-03-10-command-creator-and-eval-tasks.md +426 -0
- package/docs/plans/2026-03-10-stale-workflow-refs-decisions.md +8 -0
- package/docs/plans/2026-03-10-stale-workflow-refs-design.md +80 -0
- package/docs/plans/2026-03-10-stale-workflow-refs-tasks.md +90 -0
- package/docs/plans/2026-03-14-beads-plan-context-decisions.md +9 -0
- package/docs/plans/2026-03-14-beads-plan-context-design.md +171 -0
- package/docs/plans/2026-03-14-beads-plan-context-tasks.md +160 -0
- package/docs/plans/2026-03-14-skill-eval-loop-decisions.md +33 -0
- package/docs/plans/2026-03-14-skill-eval-loop-design.md +118 -0
- package/docs/plans/2026-03-14-skill-eval-loop-results.md +78 -0
- package/docs/plans/2026-03-14-skill-eval-loop-tasks.md +160 -0
- package/docs/plans/2026-03-15-agent-command-parity-v2-decisions.md +11 -0
- package/docs/plans/2026-03-15-agent-command-parity-v2-design.md +145 -0
- package/docs/plans/2026-03-15-agent-command-parity-v2-tasks.md +211 -0
- package/docs/research/TEMPLATE.md +292 -0
- package/docs/research/advanced-testing.md +297 -0
- package/docs/research/agent-permissions.md +167 -0
- package/docs/research/dependency-chain.md +328 -0
- package/docs/research/forge-workflow-v2.md +550 -0
- package/docs/research/plugin-architecture.md +772 -0
- package/docs/research/pr4-cli-automation.md +326 -0
- package/docs/research/premerge-verify-restructure.md +205 -0
- package/docs/research/skills-restructure.md +508 -0
- package/docs/research/sonarcloud-perfection-plan.md +166 -0
- package/docs/research/sonarcloud-quality-gate.md +184 -0
- package/docs/research/superpowers-integration.md +403 -0
- package/docs/research/superpowers.md +319 -0
- package/docs/research/test-environment.md +519 -0
- package/install.sh +1062 -0
- package/lefthook.yml +39 -0
- package/lib/agents/README.md +198 -0
- package/lib/agents/claude.plugin.json +28 -0
- package/lib/agents/cline.plugin.json +22 -0
- package/lib/agents/codex.plugin.json +19 -0
- package/lib/agents/copilot.plugin.json +24 -0
- package/lib/agents/cursor.plugin.json +25 -0
- package/lib/agents/kilocode.plugin.json +22 -0
- package/lib/agents/opencode.plugin.json +20 -0
- package/lib/agents/roo.plugin.json +23 -0
- package/lib/agents-config.js +2112 -0
- package/lib/commands/dev.js +513 -0
- package/lib/commands/plan.js +696 -0
- package/lib/commands/recommend.js +119 -0
- package/lib/commands/ship.js +377 -0
- package/lib/commands/status.js +378 -0
- package/lib/commands/validate.js +602 -0
- package/lib/context-merge.js +359 -0
- package/lib/plugin-catalog.js +360 -0
- package/lib/plugin-manager.js +166 -0
- package/lib/plugin-recommender.js +141 -0
- package/lib/project-discovery.js +491 -0
- package/lib/setup.js +118 -0
- package/lib/workflow-profiles.js +203 -0
- package/package.json +115 -0
package/bin/forge-cmd.js
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Forge CLI Command Dispatcher
|
|
5
|
+
* Executable automation for Forge workflow stages
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { execFileSync } = require('node:child_process');
|
|
9
|
+
const fs = require('node:fs');
|
|
10
|
+
|
|
11
|
+
// Command handlers - connected to lib/commands/
|
|
12
|
+
const HANDLERS = {
|
|
13
|
+
status: require('../lib/commands/status'),
|
|
14
|
+
plan: require('../lib/commands/plan'),
|
|
15
|
+
dev: require('../lib/commands/dev'),
|
|
16
|
+
validate: require('../lib/commands/validate'),
|
|
17
|
+
ship: require('../lib/commands/ship'),
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const VALID_COMMANDS = [
|
|
21
|
+
'status',
|
|
22
|
+
'plan',
|
|
23
|
+
'dev',
|
|
24
|
+
'validate',
|
|
25
|
+
'check', // backward-compat alias for validate
|
|
26
|
+
'ship',
|
|
27
|
+
'review',
|
|
28
|
+
'merge',
|
|
29
|
+
'verify',
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
const COMMAND_DESCRIPTIONS = {
|
|
33
|
+
status: 'Detect current workflow stage (1-7)',
|
|
34
|
+
plan: 'Create branch + Beads + design doc',
|
|
35
|
+
dev: 'Implement with TDD (RED-GREEN-REFACTOR)',
|
|
36
|
+
validate: 'Run type check, lint, security, tests',
|
|
37
|
+
check: 'Alias for validate (deprecated — use validate)',
|
|
38
|
+
ship: 'Auto-generate PR body and create PR',
|
|
39
|
+
review: 'Aggregate all review feedback',
|
|
40
|
+
merge: 'Update docs, merge PR, cleanup',
|
|
41
|
+
verify: 'Final documentation verification',
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const REQUIRED_ARGS = {
|
|
45
|
+
plan: ['feature-slug'],
|
|
46
|
+
ship: ['feature-slug', 'title'],
|
|
47
|
+
review: [],
|
|
48
|
+
merge: [],
|
|
49
|
+
// Other commands don't require arguments
|
|
50
|
+
status: [],
|
|
51
|
+
dev: [],
|
|
52
|
+
validate: [],
|
|
53
|
+
check: [], // backward-compat alias
|
|
54
|
+
verify: [],
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Parse command line arguments
|
|
59
|
+
* @param {string[]} argv - Process arguments
|
|
60
|
+
* @returns {{command: string|null, args: string[]}}
|
|
61
|
+
*/
|
|
62
|
+
function parseArgs(argv) {
|
|
63
|
+
// Skip 'node' and script name
|
|
64
|
+
const args = argv.slice(2);
|
|
65
|
+
|
|
66
|
+
if (args.length === 0) {
|
|
67
|
+
return { command: null, args: [] };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const command = args[0];
|
|
71
|
+
const commandArgs = args.slice(1);
|
|
72
|
+
|
|
73
|
+
return { command, args: commandArgs };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Check if command is valid
|
|
78
|
+
* @param {string} command - Command to validate
|
|
79
|
+
* @returns {boolean}
|
|
80
|
+
*/
|
|
81
|
+
function isValidCommand(command) {
|
|
82
|
+
return VALID_COMMANDS.includes(command);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const MIN_SLUG_LENGTH = 3;
|
|
86
|
+
const MAX_SLUG_LENGTH = 100;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Validate slug format (security: prevent path traversal, command injection)
|
|
90
|
+
* @param {string} slug - Feature slug to validate
|
|
91
|
+
* @returns {{valid: boolean, error?: string}}
|
|
92
|
+
*/
|
|
93
|
+
function validateSlug(slug) {
|
|
94
|
+
// Security: Enforce length limits to prevent resource exhaustion (OWASP A01)
|
|
95
|
+
if (!slug || slug.length < MIN_SLUG_LENGTH) {
|
|
96
|
+
return {
|
|
97
|
+
valid: false,
|
|
98
|
+
error: `Error: Slug too short (minimum ${MIN_SLUG_LENGTH} characters)\n\nExample: stripe-billing, user-auth, api-v2`,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
if (slug.length > MAX_SLUG_LENGTH) {
|
|
102
|
+
return {
|
|
103
|
+
valid: false,
|
|
104
|
+
error: `Error: Slug too long (maximum ${MAX_SLUG_LENGTH} characters)`,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Security: Only allow lowercase letters, numbers, and hyphens; must start and end with alphanumeric
|
|
109
|
+
const slugPattern = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/; // NOSONAR S5852 - no backtracking: anchored, alternation is possessive
|
|
110
|
+
if (!slugPattern.test(slug)) {
|
|
111
|
+
return {
|
|
112
|
+
valid: false,
|
|
113
|
+
error: `Error: Invalid slug format '${slug}'\n\nSlug must contain only lowercase letters, numbers, and hyphens, and must start and end with a letter or number\nExample: stripe-billing, user-auth, api-v2`,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return { valid: true };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Validate command arguments
|
|
122
|
+
* @param {string} command - Command name
|
|
123
|
+
* @param {string[]} args - Command arguments
|
|
124
|
+
* @returns {{valid: boolean, error?: string}}
|
|
125
|
+
*/
|
|
126
|
+
function validateArgs(command, args) {
|
|
127
|
+
const required = REQUIRED_ARGS[command] || [];
|
|
128
|
+
const positionalArgs = args.filter(a => !a.startsWith('--'));
|
|
129
|
+
|
|
130
|
+
if (required.length > 0 && positionalArgs.length < required.length) {
|
|
131
|
+
const missing = required.slice(positionalArgs.length);
|
|
132
|
+
return {
|
|
133
|
+
valid: false,
|
|
134
|
+
error: `Error: ${missing[0]} required\n\nUsage: forge ${command} <${required.join('> <')}>`,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Security: Validate slug format for slug-based commands
|
|
139
|
+
const slugCommands = ['plan', 'ship'];
|
|
140
|
+
if (slugCommands.includes(command) && positionalArgs.length > 0) {
|
|
141
|
+
const slugValidation = validateSlug(positionalArgs[0]);
|
|
142
|
+
if (!slugValidation.valid) {
|
|
143
|
+
return slugValidation;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return { valid: true };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Get help text
|
|
152
|
+
* @returns {string}
|
|
153
|
+
*/
|
|
154
|
+
function getHelpText() {
|
|
155
|
+
const lines = [
|
|
156
|
+
'',
|
|
157
|
+
'Forge CLI - Executable workflow automation',
|
|
158
|
+
'',
|
|
159
|
+
'Usage: forge <command> [args]',
|
|
160
|
+
'',
|
|
161
|
+
'Commands:',
|
|
162
|
+
];
|
|
163
|
+
|
|
164
|
+
for (const command of VALID_COMMANDS) {
|
|
165
|
+
const desc = COMMAND_DESCRIPTIONS[command];
|
|
166
|
+
lines.push(` ${command.padEnd(12)} ${desc}`);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
lines.push(
|
|
170
|
+
'',
|
|
171
|
+
'Examples:',
|
|
172
|
+
' forge status # Check current workflow stage',
|
|
173
|
+
' forge plan stripe-billing # Create implementation plan',
|
|
174
|
+
' forge ship stripe-billing "feat: add billing" # Create PR',
|
|
175
|
+
' forge review 123 # Aggregate PR feedback',
|
|
176
|
+
'',
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
return lines.join('\n');
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Main dispatcher
|
|
184
|
+
*/
|
|
185
|
+
async function main() { // NOSONAR S3776
|
|
186
|
+
const { command, args } = parseArgs(process.argv);
|
|
187
|
+
|
|
188
|
+
// No command - show help
|
|
189
|
+
if (!command) {
|
|
190
|
+
console.log(getHelpText());
|
|
191
|
+
process.exit(0);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Invalid command
|
|
195
|
+
if (!isValidCommand(command)) {
|
|
196
|
+
console.error(`Error: Unknown command '${command}'`);
|
|
197
|
+
console.log(getHelpText());
|
|
198
|
+
process.exit(1);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Validate arguments
|
|
202
|
+
const validation = validateArgs(command, args);
|
|
203
|
+
if (!validation.valid) {
|
|
204
|
+
console.error(validation.error);
|
|
205
|
+
process.exit(1);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Execute command
|
|
209
|
+
try {
|
|
210
|
+
const quotedArgs = args.map(a => `"${a.replaceAll('"', '\\"')}"`); // NOSONAR S7780 - intentional backslash escape for console quoting
|
|
211
|
+
console.log(`Executing: forge ${command}${quotedArgs.length > 0 ? ' ' + quotedArgs.join(' ') : ''}`);
|
|
212
|
+
console.log('');
|
|
213
|
+
|
|
214
|
+
let result;
|
|
215
|
+
const positionalArgs = args.filter(a => !a.startsWith('--'));
|
|
216
|
+
|
|
217
|
+
if (command === 'status') {
|
|
218
|
+
// Gather context from git + filesystem
|
|
219
|
+
const branch = (() => {
|
|
220
|
+
try { return execFileSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { encoding: 'utf8', timeout: 5000 }).trim(); } // NOSONAR S4036 - hardcoded CLI command, no user input, developer tool context
|
|
221
|
+
catch (error_) { void error_; return 'master'; } // NOSONAR S2486 - intentional: non-git dirs fallback
|
|
222
|
+
})();
|
|
223
|
+
const context = {
|
|
224
|
+
branch,
|
|
225
|
+
researchDoc: fs.existsSync('docs/research') ? fs.readdirSync('docs/research').find(f => f.endsWith('.md')) : null,
|
|
226
|
+
plan: fs.existsSync('.claude/plans') ? fs.readdirSync('.claude/plans').find(f => f.endsWith('.md')) : null,
|
|
227
|
+
tests: (() => { try { return fs.readdirSync('test').filter(f => f.endsWith('.test.js')); } catch (error_) { void error_; return []; } })(), // NOSONAR S2486 - intentional: missing test dir
|
|
228
|
+
};
|
|
229
|
+
const stageResult = HANDLERS.status.detectStage(context);
|
|
230
|
+
console.log(HANDLERS.status.formatStatus(stageResult));
|
|
231
|
+
|
|
232
|
+
} else if (command === 'plan') {
|
|
233
|
+
result = await HANDLERS.plan.executePlan(positionalArgs[0]);
|
|
234
|
+
if (result.success) {
|
|
235
|
+
console.log(`✓ Plan created: ${result.summary || result.branchName || ''}`);
|
|
236
|
+
if (result.beadsIssueId) console.log(` Beads: ${result.beadsIssueId}`);
|
|
237
|
+
} else {
|
|
238
|
+
console.error(`✗ Plan failed: ${result.error}`);
|
|
239
|
+
process.exit(1);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
} else if (command === 'dev') {
|
|
243
|
+
const featureName = positionalArgs[0] || 'feature';
|
|
244
|
+
const VALID_PHASES = ['RED', 'GREEN', 'REFACTOR'];
|
|
245
|
+
const phase = positionalArgs[1] ? positionalArgs[1].toUpperCase() : undefined;
|
|
246
|
+
if (phase && !VALID_PHASES.includes(phase)) {
|
|
247
|
+
console.error(`✗ Invalid phase '${positionalArgs[1]}'. Valid phases: red, green, refactor`);
|
|
248
|
+
process.exit(1);
|
|
249
|
+
}
|
|
250
|
+
result = await HANDLERS.dev.executeDev(featureName, { phase });
|
|
251
|
+
if (result.success) {
|
|
252
|
+
console.log(`✓ TDD Phase: ${result.phase || result.detectedPhase}`);
|
|
253
|
+
if (result.guidance) console.log('\n' + result.guidance);
|
|
254
|
+
} else {
|
|
255
|
+
console.error(`✗ Dev failed: ${result.error}`);
|
|
256
|
+
process.exit(1);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
} else if (command === 'validate' || command === 'check') {
|
|
260
|
+
if (command === 'check') console.warn('⚠ "forge check" is deprecated — use "forge validate"');
|
|
261
|
+
result = await HANDLERS.validate.executeValidate();
|
|
262
|
+
if (result.success) {
|
|
263
|
+
console.log(`✓ ${result.summary}`);
|
|
264
|
+
} else {
|
|
265
|
+
console.error(`✗ ${result.summary}`);
|
|
266
|
+
if (result.failedChecks) console.error(` Failed: ${result.failedChecks.join(', ')}`);
|
|
267
|
+
process.exit(1);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
} else if (command === 'ship') {
|
|
271
|
+
const featureSlug = positionalArgs[0];
|
|
272
|
+
const title = positionalArgs[1];
|
|
273
|
+
const dryRun = args.includes('--dry-run');
|
|
274
|
+
result = await HANDLERS.ship.executeShip({ featureSlug, title, dryRun });
|
|
275
|
+
if (result.success) {
|
|
276
|
+
console.log(`✓ ${result.message}`);
|
|
277
|
+
if (result.prUrl) console.log(` PR: ${result.prUrl}`);
|
|
278
|
+
} else {
|
|
279
|
+
console.error(`✗ Ship failed: ${result.error}`);
|
|
280
|
+
process.exit(1);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
} else {
|
|
284
|
+
// review, merge, verify - not yet implemented as automated CLI commands
|
|
285
|
+
// These stages require interactive AI assistance
|
|
286
|
+
const prRef = positionalArgs[0] ? ` ${positionalArgs[0]}` : '';
|
|
287
|
+
console.log(`ℹ️ '${command}' is a guided workflow stage.`);
|
|
288
|
+
console.log(` Use your AI agent with the /${command}${prRef} slash command for interactive execution.`);
|
|
289
|
+
console.log(` See .claude/commands/${command}.md for the full workflow guide.`);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
process.exit(0);
|
|
293
|
+
} catch (error) {
|
|
294
|
+
console.error(`Error executing '${command}':`, error.message);
|
|
295
|
+
process.exit(1);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// Export for testing
|
|
300
|
+
if (require.main === module) {
|
|
301
|
+
main().catch((error) => { // NOSONAR S7785 - CJS module, top-level await unavailable
|
|
302
|
+
console.error('Fatal error:', error);
|
|
303
|
+
process.exit(1);
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
module.exports = {
|
|
308
|
+
parseArgs,
|
|
309
|
+
isValidCommand,
|
|
310
|
+
validateArgs,
|
|
311
|
+
validateSlug,
|
|
312
|
+
getHelpText,
|
|
313
|
+
};
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Forge Validate CLI
|
|
5
|
+
*
|
|
6
|
+
* Prerequisite validation for workflow stages.
|
|
7
|
+
* Helps ensure developers have required tools and files before proceeding.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* forge-validate status - Check project prerequisites
|
|
11
|
+
* forge-validate dev - Validate before /dev stage
|
|
12
|
+
* forge-validate ship - Validate before /ship stage
|
|
13
|
+
*
|
|
14
|
+
* Security: Uses execFileSync to prevent command injection.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const { execFileSync } = require("node:child_process");
|
|
18
|
+
const fs = require("node:fs");
|
|
19
|
+
// const path = require("node:path"); // Currently unused
|
|
20
|
+
|
|
21
|
+
// Validation results
|
|
22
|
+
let checks = [];
|
|
23
|
+
|
|
24
|
+
function check(label, condition, message) {
|
|
25
|
+
const passed = typeof condition === "function" ? condition() : condition;
|
|
26
|
+
checks.push({ label, passed, message: passed ? "✓" : `✗ ${message}` });
|
|
27
|
+
return passed;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function printResults() {
|
|
31
|
+
console.log("\nValidation Results:\n");
|
|
32
|
+
checks.forEach(({ label, passed, message }) => {
|
|
33
|
+
const status = passed ? "✓" : "✗";
|
|
34
|
+
const color = passed ? "\x1b[32m" : "\x1b[31m"; // green : red
|
|
35
|
+
console.log(` ${color}${status}\x1b[0m ${label}`);
|
|
36
|
+
if (!passed) {
|
|
37
|
+
console.log(` ${message}`);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
console.log();
|
|
41
|
+
|
|
42
|
+
const allPassed = checks.every((c) => c.passed);
|
|
43
|
+
if (allPassed) {
|
|
44
|
+
console.log("✅ All checks passed!\n");
|
|
45
|
+
} else {
|
|
46
|
+
console.log("❌ Some checks failed. Please fix the issues above.\n");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return allPassed;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Validation functions
|
|
53
|
+
|
|
54
|
+
function validateStatus() {
|
|
55
|
+
console.log("Checking project prerequisites...\n");
|
|
56
|
+
|
|
57
|
+
check(
|
|
58
|
+
"Git repository",
|
|
59
|
+
() => {
|
|
60
|
+
return fs.existsSync(".git") || fs.existsSync("../.git");
|
|
61
|
+
},
|
|
62
|
+
"Not a git repository. Run: git init",
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
check(
|
|
66
|
+
"package.json exists",
|
|
67
|
+
() => {
|
|
68
|
+
return fs.existsSync("package.json");
|
|
69
|
+
},
|
|
70
|
+
"No package.json found. Run: npm init",
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
check(
|
|
74
|
+
"Test framework configured",
|
|
75
|
+
() => {
|
|
76
|
+
try {
|
|
77
|
+
const pkg = JSON.parse(fs.readFileSync("package.json", "utf8"));
|
|
78
|
+
return !!(pkg.scripts && pkg.scripts.test);
|
|
79
|
+
} catch {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
'No test script in package.json. Add "test" script.',
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
check(
|
|
87
|
+
"Node.js installed",
|
|
88
|
+
() => {
|
|
89
|
+
try {
|
|
90
|
+
execFileSync("node", ["--version"], { stdio: "pipe" });
|
|
91
|
+
return true;
|
|
92
|
+
} catch {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
"Node.js not found. Install from nodejs.org",
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
return printResults();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function validateDev() {
|
|
103
|
+
console.log("Validating prerequisites for /dev stage...\n");
|
|
104
|
+
|
|
105
|
+
check(
|
|
106
|
+
"On feature branch",
|
|
107
|
+
() => {
|
|
108
|
+
try {
|
|
109
|
+
const branch = execFileSync(
|
|
110
|
+
"git",
|
|
111
|
+
["rev-parse", "--abbrev-ref", "HEAD"],
|
|
112
|
+
{
|
|
113
|
+
encoding: "utf8",
|
|
114
|
+
},
|
|
115
|
+
).trim();
|
|
116
|
+
return (
|
|
117
|
+
branch.startsWith("feat/") ||
|
|
118
|
+
branch.startsWith("fix/") ||
|
|
119
|
+
branch.startsWith("docs/")
|
|
120
|
+
);
|
|
121
|
+
} catch {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
"Not on a feature branch. Create one: git checkout -b feat/your-feature",
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
check(
|
|
129
|
+
"Plan file exists",
|
|
130
|
+
() => {
|
|
131
|
+
try {
|
|
132
|
+
const plansDir = ".claude/plans";
|
|
133
|
+
if (!fs.existsSync(plansDir)) return false;
|
|
134
|
+
const plans = fs.readdirSync(plansDir).filter((f) => f.endsWith(".md"));
|
|
135
|
+
return plans.length > 0;
|
|
136
|
+
} catch {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
"No plan file found in .claude/plans/. Run: /plan",
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
check(
|
|
144
|
+
"Research file exists",
|
|
145
|
+
() => {
|
|
146
|
+
try {
|
|
147
|
+
const researchDir = "docs/research";
|
|
148
|
+
if (!fs.existsSync(researchDir)) return false;
|
|
149
|
+
const research = fs
|
|
150
|
+
.readdirSync(researchDir)
|
|
151
|
+
.filter((f) => f.endsWith(".md"));
|
|
152
|
+
return research.length > 0;
|
|
153
|
+
} catch {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
"No research file found in docs/research/. Run: /research",
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
check(
|
|
161
|
+
"Test directory exists",
|
|
162
|
+
() => {
|
|
163
|
+
return (
|
|
164
|
+
fs.existsSync("test") ||
|
|
165
|
+
fs.existsSync("tests") ||
|
|
166
|
+
fs.existsSync("__tests__")
|
|
167
|
+
);
|
|
168
|
+
},
|
|
169
|
+
"No test directory found. Create test/ directory",
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
return printResults();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function validateShip() {
|
|
176
|
+
console.log("Validating prerequisites for /ship stage...\n");
|
|
177
|
+
|
|
178
|
+
check(
|
|
179
|
+
"Tests exist",
|
|
180
|
+
() => {
|
|
181
|
+
const testDirs = ["test", "tests", "__tests__"];
|
|
182
|
+
return testDirs.some((dir) => {
|
|
183
|
+
if (!fs.existsSync(dir)) return false;
|
|
184
|
+
try {
|
|
185
|
+
const files = fs.readdirSync(dir, { recursive: true });
|
|
186
|
+
return files.some(
|
|
187
|
+
(f) => f.includes(".test.") || f.includes(".spec."),
|
|
188
|
+
);
|
|
189
|
+
} catch {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
},
|
|
194
|
+
"No test files found. Write tests before shipping!",
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
check(
|
|
198
|
+
"Tests pass",
|
|
199
|
+
() => {
|
|
200
|
+
try {
|
|
201
|
+
execFileSync("npm", ["test"], { stdio: "pipe" });
|
|
202
|
+
return true;
|
|
203
|
+
} catch {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
"Tests are failing. Fix them before shipping: npm test",
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
check(
|
|
211
|
+
"Documentation updated",
|
|
212
|
+
() => {
|
|
213
|
+
return fs.existsSync("README.md") || fs.existsSync("docs");
|
|
214
|
+
},
|
|
215
|
+
"No documentation found. Update README.md or docs/",
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
check(
|
|
219
|
+
"No uncommitted changes",
|
|
220
|
+
() => {
|
|
221
|
+
try {
|
|
222
|
+
const status = execFileSync("git", ["status", "--porcelain"], {
|
|
223
|
+
encoding: "utf8",
|
|
224
|
+
}).trim();
|
|
225
|
+
return status.length === 0;
|
|
226
|
+
} catch {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
"Uncommitted changes found. Commit all changes before shipping.",
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
return printResults();
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function showHelp() {
|
|
237
|
+
console.log(`
|
|
238
|
+
Forge Validate - Prerequisite validation for workflow stages
|
|
239
|
+
|
|
240
|
+
Usage:
|
|
241
|
+
forge-validate <command>
|
|
242
|
+
|
|
243
|
+
Commands:
|
|
244
|
+
status Check project prerequisites (git, npm, tests)
|
|
245
|
+
dev Validate before /dev stage (branch, plan, research)
|
|
246
|
+
ship Validate before /ship stage (tests pass, docs, clean)
|
|
247
|
+
help Show this help message
|
|
248
|
+
|
|
249
|
+
Examples:
|
|
250
|
+
forge-validate status
|
|
251
|
+
forge-validate dev
|
|
252
|
+
forge-validate ship
|
|
253
|
+
`);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Main CLI
|
|
257
|
+
function main() {
|
|
258
|
+
const args = process.argv.slice(2);
|
|
259
|
+
const command = args[0];
|
|
260
|
+
|
|
261
|
+
if (
|
|
262
|
+
!command ||
|
|
263
|
+
command === "help" ||
|
|
264
|
+
command === "--help" ||
|
|
265
|
+
command === "-h"
|
|
266
|
+
) {
|
|
267
|
+
showHelp();
|
|
268
|
+
process.exit(0);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
let success;
|
|
272
|
+
|
|
273
|
+
switch (command) {
|
|
274
|
+
case "status":
|
|
275
|
+
success = validateStatus();
|
|
276
|
+
break;
|
|
277
|
+
case "dev":
|
|
278
|
+
success = validateDev();
|
|
279
|
+
break;
|
|
280
|
+
case "ship":
|
|
281
|
+
success = validateShip();
|
|
282
|
+
break;
|
|
283
|
+
default:
|
|
284
|
+
console.error(`\n❌ Unknown command: ${command}\n`);
|
|
285
|
+
console.error("Valid commands: status, dev, ship, help\n");
|
|
286
|
+
showHelp();
|
|
287
|
+
process.exit(1);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
process.exit(success ? 0 : 1);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// Export for testing
|
|
294
|
+
module.exports = {
|
|
295
|
+
validateStatus,
|
|
296
|
+
validateDev,
|
|
297
|
+
validateShip,
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
// Run if called directly
|
|
301
|
+
if (require.main === module) {
|
|
302
|
+
main();
|
|
303
|
+
}
|