@makerkit/prd 0.0.0 → 0.0.2

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 (54) hide show
  1. package/README.md +1 -1
  2. package/{dist/index.d.ts → index.d.ts} +1 -0
  3. package/{dist/index.js → index.js} +74 -151
  4. package/{dist/index.mjs → index.mjs} +62 -140
  5. package/{dist/mcp.js → mcp.js} +12 -1
  6. package/{dist/mcp.mjs → mcp.mjs} +12 -1
  7. package/package.json +2 -21
  8. package/{dist/prompts-Bber0S1Z.mjs → prompts-B0ciGmv-.mjs} +101 -3
  9. package/{dist/prompts-CIX8IeAx.js → prompts-CTRnq1J5.js} +142 -2
  10. package/.turbo/turbo-build.log +0 -46
  11. package/.turbo/turbo-test.log +0 -21
  12. package/.turbo/turbo-typecheck.log +0 -1
  13. package/dist/README.md +0 -65
  14. package/dist/package.json +0 -49
  15. package/src/__tests__/agent-workflow.test.ts +0 -377
  16. package/src/__tests__/attachments.test.ts +0 -475
  17. package/src/__tests__/node.test.ts +0 -141
  18. package/src/__tests__/plan-check.test.ts +0 -229
  19. package/src/__tests__/planning.test.ts +0 -1059
  20. package/src/__tests__/prd-operations.test.ts +0 -423
  21. package/src/__tests__/prd.service.test.ts +0 -477
  22. package/src/__tests__/prd.tool.test.ts +0 -282
  23. package/src/__tests__/templates.test.ts +0 -141
  24. package/src/applicability.ts +0 -73
  25. package/src/attachment-paths.ts +0 -78
  26. package/src/attachments.ts +0 -160
  27. package/src/edge-cases.ts +0 -52
  28. package/src/index.ts +0 -35
  29. package/src/markdown.ts +0 -268
  30. package/src/mcp/index.ts +0 -839
  31. package/src/mcp/tool-response.ts +0 -85
  32. package/src/node.ts +0 -146
  33. package/src/open-questions.ts +0 -93
  34. package/src/plan-check.ts +0 -282
  35. package/src/planning-operations.ts +0 -429
  36. package/src/prd-operations.ts +0 -690
  37. package/src/prd.service.ts +0 -1051
  38. package/src/prompts.ts +0 -110
  39. package/src/safe-file-name.ts +0 -42
  40. package/src/schema.ts +0 -976
  41. package/src/templates.ts +0 -173
  42. package/src/testing/fake-mcp-server.ts +0 -81
  43. package/src/types.ts +0 -333
  44. package/tsconfig.json +0 -23
  45. package/tsconfig.lib.json +0 -8
  46. package/tsconfig.spec.json +0 -7
  47. package/tsdown.config.mts +0 -11
  48. package/vitest.config.mts +0 -8
  49. /package/{dist/LICENSE → LICENSE} +0 -0
  50. /package/{dist/mcp.d.ts → mcp.d.ts} +0 -0
  51. /package/{dist/node.d.ts → node.d.ts} +0 -0
  52. /package/{dist/node.js → node.js} +0 -0
  53. /package/{dist/node.mjs → node.mjs} +0 -0
  54. /package/{dist/prd.service-DSBp8sMl.d.ts → prd.service-DSBp8sMl.d.ts} +0 -0
@@ -1,423 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
-
3
- import {
4
- assignStoryToPhase,
5
- createPhase,
6
- deleteStory,
7
- nextStoryId,
8
- updateStory,
9
- } from '../prd-operations';
10
- import { normalizePrd } from '../prd.service';
11
- import type { StructuredPRD, UserStory } from '../types';
12
-
13
- const TODAY = '2026-09-06';
14
-
15
- function prdWith(stories: Partial<UserStory>[] = []): StructuredPRD {
16
- const prd = normalizePrd({}, TODAY);
17
-
18
- prd.userStories = stories.map((overrides, index) => ({
19
- id: `US${String(index + 1).padStart(3, '0')}`,
20
- title: `Story ${index + 1}`,
21
- userStory: 'As a member, I want to export data so that I can audit it',
22
- businessValue: 'audit',
23
- acceptanceCriteria: [],
24
- status: 'not_started' as const,
25
- priority: 'P2' as const,
26
- estimatedComplexity: 'M' as const,
27
- dependencies: [],
28
- ...overrides,
29
- }));
30
-
31
- return prd;
32
- }
33
-
34
- describe('updateStory', () => {
35
- it('changes only the fields supplied', () => {
36
- const prd = prdWith([{}]);
37
- const before = prd.userStories[0]!.userStory;
38
-
39
- const result = updateStory(
40
- prd,
41
- { filename: 'f.json', storyId: 'US001', title: 'Bulk CSV export' },
42
- TODAY,
43
- );
44
-
45
- expect(result.updated_fields).toEqual(['title']);
46
- expect(prd.userStories[0]!.title).toBe('Bulk CSV export');
47
- expect(prd.userStories[0]!.userStory).toBe(before);
48
- });
49
-
50
- it('patches one part of the user-story sentence and keeps the rest', () => {
51
- const prd = prdWith([{}]);
52
-
53
- updateStory(
54
- prd,
55
- { filename: 'f.json', storyId: 'US001', userType: 'workspace owner' },
56
- TODAY,
57
- );
58
-
59
- expect(prd.userStories[0]!.userStory).toBe(
60
- 'As a workspace owner, I want to export data so that I can audit it',
61
- );
62
- });
63
-
64
- it('keeps businessValue in step with a changed benefit', () => {
65
- const prd = prdWith([{}]);
66
-
67
- updateStory(
68
- prd,
69
- {
70
- filename: 'f.json',
71
- storyId: 'US001',
72
- benefit: 'I can prove compliance',
73
- },
74
- TODAY,
75
- );
76
-
77
- expect(prd.userStories[0]!.businessValue).toBe('I can prove compliance');
78
- });
79
-
80
- it('lets an explicit businessValue win over the derived one', () => {
81
- const prd = prdWith([{}]);
82
-
83
- updateStory(
84
- prd,
85
- {
86
- filename: 'f.json',
87
- storyId: 'US001',
88
- benefit: 'I can prove compliance',
89
- businessValue: 'Unblocks the SOC2 audit',
90
- },
91
- TODAY,
92
- );
93
-
94
- expect(prd.userStories[0]!.businessValue).toBe('Unblocks the SOC2 audit');
95
- });
96
-
97
- it('refuses a partial sentence edit when the story is not in the standard form', () => {
98
- const prd = prdWith([{ userStory: 'Export things, somehow' }]);
99
-
100
- expect(() =>
101
- updateStory(
102
- prd,
103
- { filename: 'f.json', storyId: 'US001', action: 'export as CSV' },
104
- TODAY,
105
- ),
106
- ).toThrow(/cannot be patched individually/);
107
- });
108
-
109
- it('rebuilds a non-standard sentence when all three parts are supplied', () => {
110
- const prd = prdWith([{ userStory: 'Export things, somehow' }]);
111
-
112
- updateStory(
113
- prd,
114
- {
115
- filename: 'f.json',
116
- storyId: 'US001',
117
- userType: 'owner',
118
- action: 'export as CSV',
119
- benefit: 'I can audit access',
120
- },
121
- TODAY,
122
- );
123
-
124
- expect(prd.userStories[0]!.userStory).toBe(
125
- 'As a owner, I want to export as CSV so that I can audit access',
126
- );
127
- });
128
-
129
- it('rejects an update that names no fields', () => {
130
- const prd = prdWith([{}]);
131
-
132
- expect(() =>
133
- updateStory(prd, { filename: 'f.json', storyId: 'US001' }, TODAY),
134
- ).toThrow(/No fields supplied/);
135
- });
136
-
137
- it('names the known stories when the id is wrong', () => {
138
- const prd = prdWith([{}, {}]);
139
-
140
- expect(() =>
141
- updateStory(
142
- prd,
143
- { filename: 'f.json', storyId: 'US009', title: 'x' },
144
- TODAY,
145
- ),
146
- ).toThrow(/Known stories: US001, US002/);
147
- });
148
-
149
- it('records a change-log entry', () => {
150
- const prd = prdWith([{}]);
151
-
152
- updateStory(
153
- prd,
154
- { filename: 'f.json', storyId: 'US001', title: 'New' },
155
- TODAY,
156
- );
157
-
158
- expect(prd.changeLog.at(-1)).toBe('2026-09-06: Updated US001 (title)');
159
- });
160
-
161
- describe('dependencies', () => {
162
- it('accepts references to other stories and de-duplicates them', () => {
163
- const prd = prdWith([{}, {}]);
164
-
165
- updateStory(
166
- prd,
167
- {
168
- filename: 'f.json',
169
- storyId: 'US002',
170
- dependencies: ['US001', 'US001'],
171
- },
172
- TODAY,
173
- );
174
-
175
- expect(prd.userStories[1]!.dependencies).toEqual(['US001']);
176
- });
177
-
178
- it('rejects a self-dependency', () => {
179
- const prd = prdWith([{}]);
180
-
181
- expect(() =>
182
- updateStory(
183
- prd,
184
- { filename: 'f.json', storyId: 'US001', dependencies: ['US001'] },
185
- TODAY,
186
- ),
187
- ).toThrow(/cannot depend on itself/);
188
- });
189
-
190
- it('rejects an unknown dependency', () => {
191
- const prd = prdWith([{}]);
192
-
193
- expect(() =>
194
- updateStory(
195
- prd,
196
- { filename: 'f.json', storyId: 'US001', dependencies: ['US404'] },
197
- TODAY,
198
- ),
199
- ).toThrow(/not found/);
200
- });
201
-
202
- it('rejects a dependency cycle', () => {
203
- const prd = prdWith([{}, {}, {}]);
204
-
205
- prd.userStories[1]!.dependencies = ['US001'];
206
- prd.userStories[2]!.dependencies = ['US002'];
207
-
208
- // US001 -> US003 would close the loop US001 -> US003 -> US002 -> US001.
209
- expect(() =>
210
- updateStory(
211
- prd,
212
- { filename: 'f.json', storyId: 'US001', dependencies: ['US003'] },
213
- TODAY,
214
- ),
215
- ).toThrow(/Dependency cycle/);
216
-
217
- // The rejected edit must not have been partially applied.
218
- expect(prd.userStories[0]!.dependencies).toEqual([]);
219
- });
220
- });
221
- });
222
-
223
- describe('deleteStory', () => {
224
- it('removes the story and recomputes progress', () => {
225
- const prd = prdWith([{ status: 'completed' }, {}]);
226
-
227
- const result = deleteStory(prd, 'US002', TODAY);
228
-
229
- expect(result.total_stories).toBe(1);
230
- expect(result.progress).toBe(100);
231
- expect(prd.userStories.map((story) => story.id)).toEqual(['US001']);
232
- });
233
-
234
- it('cleans up dependency references and reports them', () => {
235
- const prd = prdWith([
236
- {},
237
- { dependencies: ['US001'] },
238
- { dependencies: ['US001'] },
239
- ]);
240
-
241
- const result = deleteStory(prd, 'US001', TODAY);
242
-
243
- expect(result.dependency_references_removed).toEqual(['US002', 'US003']);
244
- expect(
245
- prd.userStories.every((story) => story.dependencies.length === 0),
246
- ).toBe(true);
247
- });
248
-
249
- it('removes the story from any phase', () => {
250
- const prd = prdWith([{}]);
251
-
252
- createPhase(
253
- prd,
254
- { filename: 'f.json', name: 'MVP', description: '', color: '#4f46e5' },
255
- TODAY,
256
- );
257
- assignStoryToPhase(
258
- prd,
259
- { filename: 'f.json', storyId: 'US001', phaseId: 'PHASE001' },
260
- TODAY,
261
- );
262
-
263
- const result = deleteStory(prd, 'US001', TODAY);
264
-
265
- expect(result.phases_updated).toEqual(['PHASE001']);
266
- expect(prd.customPhases[0]!.userStoryIds).toEqual([]);
267
- });
268
-
269
- it('supersedes decisions about the deleted story', () => {
270
- const prd = prdWith([{}]);
271
-
272
- prd.decisionLog.push({
273
- id: 'DEC001',
274
- date: TODAY,
275
- decision: 'none',
276
- rationale: 'standalone',
277
- status: 'accepted',
278
- topic: 'story:US001:dependencies',
279
- });
280
-
281
- deleteStory(prd, 'US001', TODAY);
282
-
283
- expect(prd.decisionLog[0]!.status).toBe('superseded');
284
- });
285
- });
286
-
287
- describe('phases', () => {
288
- it('numbers phases from the highest existing id', () => {
289
- const prd = prdWith();
290
-
291
- createPhase(
292
- prd,
293
- { filename: 'f.json', name: 'MVP', description: '', color: '#4f46e5' },
294
- TODAY,
295
- );
296
- const second = createPhase(
297
- prd,
298
- {
299
- filename: 'f.json',
300
- name: 'Fast follow',
301
- description: '',
302
- color: '#4f46e5',
303
- },
304
- TODAY,
305
- );
306
-
307
- expect(second.phase.id).toBe('PHASE002');
308
- expect(second.total_phases).toBe(2);
309
- });
310
-
311
- it('rejects a duplicate phase name regardless of case', () => {
312
- const prd = prdWith();
313
-
314
- createPhase(
315
- prd,
316
- { filename: 'f.json', name: 'MVP', description: '', color: '#4f46e5' },
317
- TODAY,
318
- );
319
-
320
- expect(() =>
321
- createPhase(
322
- prd,
323
- { filename: 'f.json', name: 'mvp', description: '', color: '#4f46e5' },
324
- TODAY,
325
- ),
326
- ).toThrow(/already exists/);
327
- });
328
-
329
- it('moves a story between phases rather than duplicating it', () => {
330
- const prd = prdWith([{}]);
331
-
332
- createPhase(
333
- prd,
334
- { filename: 'f.json', name: 'A', description: '', color: '#4f46e5' },
335
- TODAY,
336
- );
337
- createPhase(
338
- prd,
339
- { filename: 'f.json', name: 'B', description: '', color: '#4f46e5' },
340
- TODAY,
341
- );
342
-
343
- assignStoryToPhase(
344
- prd,
345
- { filename: 'f.json', storyId: 'US001', phaseId: 'PHASE001' },
346
- TODAY,
347
- );
348
- const result = assignStoryToPhase(
349
- prd,
350
- { filename: 'f.json', storyId: 'US001', phaseId: 'PHASE002' },
351
- TODAY,
352
- );
353
-
354
- expect(result.moved_from).toBe('PHASE001');
355
- expect(prd.customPhases[0]!.userStoryIds).toEqual([]);
356
- expect(prd.customPhases[1]!.userStoryIds).toEqual(['US001']);
357
- });
358
-
359
- it('unassigns a story when phaseId is null', () => {
360
- const prd = prdWith([{}]);
361
-
362
- createPhase(
363
- prd,
364
- { filename: 'f.json', name: 'A', description: '', color: '#4f46e5' },
365
- TODAY,
366
- );
367
- assignStoryToPhase(
368
- prd,
369
- { filename: 'f.json', storyId: 'US001', phaseId: 'PHASE001' },
370
- TODAY,
371
- );
372
-
373
- const result = assignStoryToPhase(
374
- prd,
375
- { filename: 'f.json', storyId: 'US001', phaseId: null },
376
- TODAY,
377
- );
378
-
379
- expect(result.phase_id).toBeNull();
380
- expect(result.moved_from).toBe('PHASE001');
381
- expect(prd.customPhases[0]!.userStoryIds).toEqual([]);
382
- });
383
-
384
- it('names the known phases when the phase id is wrong', () => {
385
- const prd = prdWith([{}]);
386
-
387
- createPhase(
388
- prd,
389
- { filename: 'f.json', name: 'A', description: '', color: '#4f46e5' },
390
- TODAY,
391
- );
392
-
393
- expect(() =>
394
- assignStoryToPhase(
395
- prd,
396
- { filename: 'f.json', storyId: 'US001', phaseId: 'PHASE404' },
397
- TODAY,
398
- ),
399
- ).toThrow(/Known phases: PHASE001/);
400
- });
401
- });
402
-
403
- describe('nextStoryId', () => {
404
- it('never reissues the id of a deleted story', () => {
405
- const prd = prdWith();
406
-
407
- expect(nextStoryId(prd)).toBe('US001');
408
- expect(nextStoryId(prd)).toBe('US002');
409
-
410
- // Even with the document emptied, the mark keeps counting.
411
- prd.userStories = [];
412
-
413
- expect(nextStoryId(prd)).toBe('US003');
414
- });
415
-
416
- it('falls back to the highest present id on a PRD written before the mark existed', () => {
417
- const prd = prdWith([{}, {}, {}]);
418
-
419
- delete prd.metadata.lastStoryNumber;
420
-
421
- expect(nextStoryId(prd)).toBe('US004');
422
- });
423
- });