@pcoliveira90/pdd 0.2.6 → 0.3.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.
@@ -1,126 +1,125 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
-
4
- function ensureDir(filePath) {
5
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
6
- }
7
-
8
- function writeFile(filePath, content) {
9
- ensureDir(filePath);
10
- fs.writeFileSync(filePath, content, 'utf-8');
11
- }
12
-
13
- function slugify(value) {
14
- return value
15
- .toLowerCase()
16
- .replace(/[^a-z0-9]+/g, '-')
17
- .replace(/^-+|-+$/g, '')
18
- .slice(0, 48);
19
- }
20
-
21
- export function generatePatchArtifacts({ issue, baseDir = process.cwd() }) {
22
- const timestamp = Date.now();
23
- const changeId = `change-${timestamp}-${slugify(issue || 'update')}`;
24
- const changeDir = path.join(baseDir, 'changes', changeId);
25
-
26
- const files = [
27
- path.join('changes', changeId, 'delta-spec.md'),
28
- path.join('changes', changeId, 'patch-plan.md'),
29
- path.join('changes', changeId, 'verification-report.md')
30
- ];
31
-
32
- writeFile(
33
- path.join(changeDir, 'delta-spec.md'),
34
- `# Delta Spec
35
-
36
- ## Change ID
37
- ${changeId}
38
-
39
- ## Issue
40
- ${issue}
41
-
42
- ## Type
43
- bugfix | feature | refactor-safe | hotfix
44
-
45
- ## Context
46
-
47
- ## Current Behavior
48
-
49
- ## Expected Behavior
50
-
51
- ## Evidence
52
-
53
- ## Root Cause Hypothesis
54
-
55
- ## Impacted Areas
56
-
57
- ## Constraints
58
-
59
- ## Minimal Safe Delta
60
-
61
- ## Alternatives Considered
62
-
63
- ## Acceptance Criteria
64
-
65
- ## Verification Strategy
66
- `
67
- );
68
-
69
- writeFile(
70
- path.join(changeDir, 'patch-plan.md'),
71
- `# Patch Plan
72
-
73
- ## Change ID
74
- ${changeId}
75
-
76
- ## Issue
77
- ${issue}
78
-
79
- ## Files to Inspect
80
-
81
- ## Files to Change
82
-
83
- ## Execution Steps
84
- 1. Reproduce issue
85
- 2. Confirm root cause
86
- 3. Apply minimal change
87
- 4. Adjust tests
88
- 5. Run validations
89
-
90
- ## Regression Risks
91
-
92
- ## Rollback Strategy
93
- `
94
- );
95
-
96
- writeFile(
97
- path.join(changeDir, 'verification-report.md'),
98
- `# Verification Report
99
-
100
- ## Change ID
101
- ${changeId}
102
-
103
- ## Issue
104
- ${issue}
105
-
106
- ## Reproduction
107
-
108
- ## Changes Made
109
-
110
- ## Tests Run
111
-
112
- ## Manual Validation
113
-
114
- ## Residual Risks
115
-
116
- ## Final Status
117
- pending
118
- `
119
- );
120
-
121
- return {
122
- changeId,
123
- changeDir,
124
- files
125
- };
126
- }
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+
4
+ function ensureDir(filePath) {
5
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
6
+ }
7
+
8
+ function writeFile(filePath, content) {
9
+ ensureDir(filePath);
10
+ fs.writeFileSync(filePath, content, 'utf-8');
11
+ }
12
+
13
+ function slugify(value) {
14
+ return value
15
+ .toLowerCase()
16
+ .replace(/[^a-z0-9]+/g, '-')
17
+ .replace(/^-+|-+$/g, '')
18
+ .slice(0, 48);
19
+ }
20
+
21
+ export function generatePatchArtifacts({ issue, baseDir = process.cwd(), changeId = null }) {
22
+ const resolvedChangeId = changeId || `change-${Date.now()}-${slugify(issue || 'update')}`;
23
+ const changeDir = path.join(baseDir, 'changes', resolvedChangeId);
24
+
25
+ const files = [
26
+ path.join('changes', resolvedChangeId, 'delta-spec.md'),
27
+ path.join('changes', resolvedChangeId, 'patch-plan.md'),
28
+ path.join('changes', resolvedChangeId, 'verification-report.md')
29
+ ];
30
+
31
+ writeFile(
32
+ path.join(changeDir, 'delta-spec.md'),
33
+ `# Delta Spec
34
+
35
+ ## Change ID
36
+ ${resolvedChangeId}
37
+
38
+ ## Issue
39
+ ${issue}
40
+
41
+ ## Type
42
+ bugfix | feature | refactor-safe | hotfix
43
+
44
+ ## Context
45
+
46
+ ## Current Behavior
47
+
48
+ ## Expected Behavior
49
+
50
+ ## Evidence
51
+
52
+ ## Root Cause Hypothesis
53
+
54
+ ## Impacted Areas
55
+
56
+ ## Constraints
57
+
58
+ ## Minimal Safe Delta
59
+
60
+ ## Alternatives Considered
61
+
62
+ ## Acceptance Criteria
63
+
64
+ ## Verification Strategy
65
+ `
66
+ );
67
+
68
+ writeFile(
69
+ path.join(changeDir, 'patch-plan.md'),
70
+ `# Patch Plan
71
+
72
+ ## Change ID
73
+ ${resolvedChangeId}
74
+
75
+ ## Issue
76
+ ${issue}
77
+
78
+ ## Files to Inspect
79
+
80
+ ## Files to Change
81
+
82
+ ## Execution Steps
83
+ 1. Reproduce issue
84
+ 2. Confirm root cause
85
+ 3. Apply minimal change
86
+ 4. Adjust tests
87
+ 5. Run validations
88
+
89
+ ## Regression Risks
90
+
91
+ ## Rollback Strategy
92
+ `
93
+ );
94
+
95
+ writeFile(
96
+ path.join(changeDir, 'verification-report.md'),
97
+ `# Verification Report
98
+
99
+ ## Change ID
100
+ ${resolvedChangeId}
101
+
102
+ ## Issue
103
+ ${issue}
104
+
105
+ ## Reproduction
106
+
107
+ ## Changes Made
108
+
109
+ ## Tests Run
110
+
111
+ ## Manual Validation
112
+
113
+ ## Residual Risks
114
+
115
+ ## Final Status
116
+ pending
117
+ `
118
+ );
119
+
120
+ return {
121
+ changeId: resolvedChangeId,
122
+ changeDir,
123
+ files
124
+ };
125
+ }
@@ -1,21 +1,21 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import { execSync } from 'child_process';
4
-
5
- function exec(command) {
6
- execSync(command, { stdio: 'inherit' });
7
- }
8
-
9
- export async function openPullRequest({ issue, changeId, changeDir }) {
10
- const branch = `pdd/${changeId}`;
11
- const title = `fix: ${issue}`;
12
-
13
- fs.writeFileSync(path.join(changeDir, 'pr-title.txt'), title);
14
- fs.writeFileSync(path.join(changeDir, 'pr-body.md'), issue);
15
-
16
- exec(`git checkout -b ${branch}`);
17
- exec('git add .');
18
- exec(`git commit -m "${title}"`);
19
-
20
- console.log('PR ready (use IDE to open)');
21
- }
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { execFileSync } from 'child_process';
4
+
5
+ function runGit(args, baseDir = process.cwd()) {
6
+ execFileSync('git', args, { stdio: 'inherit', cwd: baseDir });
7
+ }
8
+
9
+ export async function openPullRequest({ issue, changeId, changeDir, baseDir = process.cwd() }) {
10
+ const branch = `pdd/${changeId}`;
11
+ const title = `fix: ${issue}`;
12
+
13
+ fs.writeFileSync(path.join(changeDir, 'pr-title.txt'), title);
14
+ fs.writeFileSync(path.join(changeDir, 'pr-body.md'), issue);
15
+
16
+ runGit(['checkout', '-b', branch], baseDir);
17
+ runGit(['add', '.'], baseDir);
18
+ runGit(['commit', '-m', title], baseDir);
19
+
20
+ console.log('PR ready (use IDE to open)');
21
+ }