forked from popup-studio-ai/bkit-claude-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpdca-post-write.js
More file actions
98 lines (83 loc) · 2.63 KB
/
pdca-post-write.js
File metadata and controls
98 lines (83 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env node
/**
* pdca-post-write.js - Guide next steps after Write operation (v1.4.0)
* Supports: Claude Code (PostToolUse), Gemini CLI (AfterTool)
*
* Purpose: Suggest gap analysis after source file modifications
* Hook: PostToolUse (Claude Code) / AfterTool (Gemini CLI)
*
* v1.4.0 Changes:
* - Added debug logging for hook verification
*
* Converted from: scripts/pdca-post-write.sh
*/
const fs = require('fs');
const path = require('path');
const {
readStdinSync,
parseHookInput,
isSourceFile,
extractFeature,
outputAllow,
outputEmpty,
generateTaskGuidance,
debugLog,
PROJECT_DIR
} = require('../lib/common.js');
// ============================================================
// v1.4.4: Main Logic (exported for unified handler usage)
// ============================================================
/**
* Run pdca-post-write logic
* @param {Object} providedInput - Optional pre-parsed input (for unified handler)
*/
function run(providedInput = null) {
// Read input from stdin or use provided
const input = providedInput || readStdinSync();
const { filePath } = parseHookInput(input);
// Debug log hook execution
debugLog('PostToolUse', 'Hook started', { filePath: filePath || 'none' });
// Skip non-source files
if (!isSourceFile(filePath)) {
debugLog('PostToolUse', 'Skipped - not a source file');
outputEmpty();
return;
}
// Extract feature name
const feature = extractFeature(filePath);
// Skip if no feature detected
if (!feature) {
outputEmpty();
return;
}
// Check if design doc exists for gap analysis suggestion
const designDocPaths = [
path.join(PROJECT_DIR, `docs/02-design/features/${feature}.design.md`),
path.join(PROJECT_DIR, `docs/02-design/${feature}.design.md`)
];
const hasDesignDoc = designDocPaths.some(p => fs.existsSync(p));
if (hasDesignDoc) {
// Generate Task guidance for PDCA workflow
const taskGuidance = generateTaskGuidance('do', feature, 'design');
const context = `Write completed: ${filePath}\n\nWhen implementation is finished, run /pdca-analyze ${feature} to verify design-implementation alignment.\n\n${taskGuidance}`;
debugLog('PostToolUse', 'Hook completed', {
feature,
hasDesignDoc: true,
guidanceProvided: true
});
outputAllow(context, 'PostToolUse');
} else {
debugLog('PostToolUse', 'Hook completed', {
feature: feature || 'none',
hasDesignDoc: false,
guidanceProvided: false
});
outputEmpty();
}
}
// Export for unified handler usage (v1.4.4)
module.exports = { run };
// Self-execute when run directly
if (require.main === module) {
run();
}