@makerkit/prd 0.0.3 → 0.0.5

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 (63) hide show
  1. package/.turbo/turbo-build.log +78 -0
  2. package/.turbo/turbo-test.log +19 -0
  3. package/.turbo/turbo-typecheck.log +6 -0
  4. package/README.md +7 -1
  5. package/dist/README.md +71 -0
  6. package/dist/attachment-paths-BAhRGiib.js +112 -0
  7. package/dist/attachment-paths-C-SWgoSx.mjs +77 -0
  8. package/dist/index.d.ts +81 -0
  9. package/{index.js → dist/index.js} +257 -524
  10. package/{index.mjs → dist/index.mjs} +189 -462
  11. package/{mcp.d.ts → dist/mcp.d.ts} +2 -4
  12. package/{mcp.js → dist/mcp.js} +24 -24
  13. package/{mcp.mjs → dist/mcp.mjs} +24 -24
  14. package/{node.d.ts → dist/node.d.ts} +4 -4
  15. package/{node.js → dist/node.js} +28 -4
  16. package/{node.mjs → dist/node.mjs} +30 -6
  17. package/dist/operations.d.ts +141 -0
  18. package/dist/operations.js +22 -0
  19. package/dist/operations.mjs +1 -0
  20. package/dist/package.json +54 -0
  21. package/dist/prd-operations-BvFxo9bg.mjs +459 -0
  22. package/dist/prd-operations-CcahfbOy.js +584 -0
  23. package/dist/prd.service-CTwKZV-3.d.ts +114 -0
  24. package/{prompts-DJQ4FQ11.js → dist/prompts-1qhax_dj.js} +150 -167
  25. package/{prompts-B0VejF7q.mjs → dist/prompts-BlsYD0gf.mjs} +121 -132
  26. package/{prd.service-x5EpOoMv.d.ts → dist/schema-BwTnt0B9.d.ts} +545 -323
  27. package/package.json +26 -2
  28. package/src/__tests__/agent-workflow.test.ts +417 -0
  29. package/src/__tests__/attachments.test.ts +505 -0
  30. package/src/__tests__/node.test.ts +199 -0
  31. package/src/__tests__/plan-check.test.ts +390 -0
  32. package/src/__tests__/planning.test.ts +1137 -0
  33. package/src/__tests__/prd-operations.test.ts +571 -0
  34. package/src/__tests__/prd.service.test.ts +652 -0
  35. package/src/__tests__/prd.tool.test.ts +282 -0
  36. package/src/__tests__/templates.test.ts +145 -0
  37. package/src/applicability.ts +73 -0
  38. package/src/attachment-paths.ts +83 -0
  39. package/src/attachments.ts +166 -0
  40. package/src/edge-cases.ts +61 -0
  41. package/src/index.ts +33 -0
  42. package/src/markdown.ts +297 -0
  43. package/src/mcp/index.ts +875 -0
  44. package/src/mcp/tool-response.ts +85 -0
  45. package/src/node.ts +184 -0
  46. package/src/open-questions.ts +98 -0
  47. package/src/plan-check.ts +385 -0
  48. package/src/planning-operations.ts +524 -0
  49. package/src/prd-operations.ts +769 -0
  50. package/src/prd.service.ts +1165 -0
  51. package/src/prompts.ts +161 -0
  52. package/src/safe-file-name.ts +42 -0
  53. package/src/schema.ts +1090 -0
  54. package/src/templates.ts +173 -0
  55. package/src/testing/fake-mcp-server.ts +81 -0
  56. package/src/types.ts +381 -0
  57. package/tsconfig.json +23 -0
  58. package/tsconfig.lib.json +8 -0
  59. package/tsconfig.spec.json +7 -0
  60. package/tsdown.config.mts +12 -0
  61. package/vitest.config.mts +8 -0
  62. package/index.d.ts +0 -228
  63. /package/{LICENSE → dist/LICENSE} +0 -0
@@ -0,0 +1,652 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import {
4
+ type PrdDeps,
5
+ type PrdVerificationResult,
6
+ createPrdService,
7
+ } from '../prd.service';
8
+ import { implementStoryPrompt } from '../prompts';
9
+
10
+ const normalize = (path: string) => path.replace(/\\/g, '/');
11
+
12
+ const PASSING: PrdVerificationResult = {
13
+ passed: true,
14
+ checks: ['typecheck', 'lint'],
15
+ errors: 0,
16
+ warnings: 0,
17
+ diagnostics: [],
18
+ messages: [],
19
+ };
20
+
21
+ const FAILING: PrdVerificationResult = {
22
+ passed: false,
23
+ checks: ['typecheck', 'lint'],
24
+ errors: 2,
25
+ warnings: 1,
26
+ diagnostics: [
27
+ {
28
+ file: 'apps/web/app/page.tsx',
29
+ line: 12,
30
+ message: 'TS2322 boom',
31
+ severity: 'error',
32
+ },
33
+ {
34
+ file: 'packages/ui/x.ts',
35
+ line: null,
36
+ message: 'unused',
37
+ severity: 'warning',
38
+ },
39
+ ],
40
+ messages: [],
41
+ };
42
+
43
+ function createHarness(
44
+ overrides: Partial<PrdDeps> = {},
45
+ initialFiles: Record<string, string> = {},
46
+ ) {
47
+ const files: Record<string, string> = { ...initialFiles };
48
+ const dirs = new Set<string>();
49
+
50
+ const deps: PrdDeps = {
51
+ rootPath: '/repo',
52
+ async readdir() {
53
+ return Object.keys(files);
54
+ },
55
+ async readFile(path) {
56
+ const content = files[basename(path)];
57
+ if (content === undefined) throw new Error('ENOENT');
58
+ return content;
59
+ },
60
+ async writeFile(path, content) {
61
+ files[basename(path)] = content;
62
+ },
63
+ async mkdir(path) {
64
+ dirs.add(normalize(path));
65
+ },
66
+ async unlink(path) {
67
+ if (!(basename(path) in files)) {
68
+ throw Object.assign(new Error('ENOENT'), { code: 'ENOENT' });
69
+ }
70
+ delete files[basename(path)];
71
+ },
72
+ async fileExists(path) {
73
+ return basename(path) in files;
74
+ },
75
+ now: () => new Date('2026-09-06T10:00:00Z'),
76
+ verifyCompletion: async () => PASSING,
77
+ ...overrides,
78
+ };
79
+
80
+ return { service: createPrdService(deps), files, dirs };
81
+ }
82
+
83
+ function basename(path: string) {
84
+ return normalize(path).split('/').pop() ?? '';
85
+ }
86
+
87
+ const BASE_INPUT = {
88
+ title: 'Notes Feature',
89
+ overview: 'Users keep notes',
90
+ problemStatement: 'No notes',
91
+ marketOpportunity: 'Everyone wants notes',
92
+ targetUsers: ['makers'],
93
+ solutionDescription: 'Add notes',
94
+ keyFeatures: ['create', 'list'],
95
+ successMetrics: ['10 notes/day'],
96
+ };
97
+
98
+ describe('PrdService.create / list / get / delete', () => {
99
+ it('saves, patches, clears and orders optional roadmap metadata', async () => {
100
+ const { service } = createHarness();
101
+ const { filename } = await service.create({
102
+ ...BASE_INPUT,
103
+ roadmap: { order: 0, criticality: 'low', plan: 'Launch', group: 'Core' },
104
+ });
105
+ const { filename: urgent } = await service.create({
106
+ ...BASE_INPUT,
107
+ title: 'Urgent PRD',
108
+ roadmap: { criticality: 'critical', order: 0 },
109
+ });
110
+ const { filename: legacy } = await service.create({
111
+ ...BASE_INPUT,
112
+ title: 'Another PRD',
113
+ });
114
+
115
+ await service.updatePrdSection({
116
+ filename,
117
+ section: 'roadmap',
118
+ value: { group: null, section: ' First release ' },
119
+ });
120
+ await service.updatePrdSection({
121
+ filename,
122
+ section: 'introduction',
123
+ value: { overview: 'Updated overview' },
124
+ });
125
+ expect((await service.get({ filename })).prd.roadmap).toEqual({
126
+ order: 0,
127
+ criticality: 'low',
128
+ plan: 'Launch',
129
+ section: 'First release',
130
+ });
131
+ expect((await service.list()).prds.map((prd) => prd.filename)).toEqual([
132
+ urgent,
133
+ filename,
134
+ legacy,
135
+ ]);
136
+ await expect(
137
+ service.updatePrdSection({
138
+ filename,
139
+ section: 'roadmap',
140
+ value: { order: -1 },
141
+ }),
142
+ ).rejects.toThrow('Invalid value for section "roadmap"');
143
+ await service.updatePrdSection({
144
+ filename,
145
+ section: 'roadmap',
146
+ value: { order: null, criticality: null, plan: null, section: null },
147
+ });
148
+ expect((await service.get({ filename })).prd.roadmap).toBeUndefined();
149
+ });
150
+
151
+ it('creates a PRD file named after the title and lists it', async () => {
152
+ const { service, files, dirs } = createHarness();
153
+
154
+ const created = await service.create(BASE_INPUT);
155
+
156
+ expect(created.filename).toBe('notes-feature.json');
157
+ expect(normalize(created.path)).toBe('/repo/.prds/notes-feature.json');
158
+ expect(dirs.has('/repo/.prds')).toBe(true);
159
+ expect(JSON.parse(files['notes-feature.json']!).metadata.created).toBe(
160
+ '2026-09-06',
161
+ );
162
+
163
+ const list = await service.list();
164
+ expect(list.total).toBe(1);
165
+ expect(list.warnings).toEqual([]);
166
+ expect(list.prds[0]).toMatchObject({
167
+ filename: 'notes-feature.json',
168
+ title: 'Notes Feature',
169
+ progress: 0,
170
+ total_stories: 0,
171
+ });
172
+ });
173
+
174
+ it('refuses to overwrite an existing PRD with the same slug', async () => {
175
+ const { service, files } = createHarness();
176
+ await service.create(BASE_INPUT);
177
+ files['notes-feature.json'] = JSON.stringify({
178
+ introduction: { title: 'Keep me' },
179
+ });
180
+
181
+ await expect(
182
+ service.create({ ...BASE_INPUT, title: 'notes feature!' }),
183
+ ).rejects.toThrow(/already exists/);
184
+
185
+ expect(JSON.parse(files['notes-feature.json']!).introduction.title).toBe(
186
+ 'Keep me',
187
+ );
188
+ });
189
+
190
+ it('reports malformed files as warnings when listing', async () => {
191
+ const { service } = createHarness({}, { 'broken.json': '{not json' });
192
+
193
+ const result = await service.list();
194
+
195
+ expect(result.total).toBe(0);
196
+ expect(result.warnings).toEqual([
197
+ 'Skipped broken.json: PRD file "broken.json" is not valid JSON',
198
+ ]);
199
+ });
200
+
201
+ it('returns the normalised document from get', async () => {
202
+ const { service } = createHarness(
203
+ {},
204
+ { 'old.json': '{"introduction":{"title":"Old"}}' },
205
+ );
206
+
207
+ const result = await service.get({ filename: 'old.json' });
208
+
209
+ expect(result.prd.introduction).toEqual({
210
+ title: 'Old',
211
+ overview: '',
212
+ lastUpdated: '2026-09-06',
213
+ });
214
+ expect(result.prd.customPhases).toEqual([]);
215
+ });
216
+
217
+ it.each(['../x.json', 'a/b.json', '.hidden.json'])(
218
+ 'rejects unsafe filename %j on every entry point',
219
+ async (filename) => {
220
+ const { service } = createHarness();
221
+
222
+ await expect(service.get({ filename })).rejects.toThrow(
223
+ /Invalid PRD file name/,
224
+ );
225
+ await expect(service.delete({ filename })).rejects.toThrow(
226
+ /Invalid PRD file name/,
227
+ );
228
+ // load() is public and used by the dev tool with a URL segment.
229
+ await expect(service.load(filename)).rejects.toThrow(
230
+ /Invalid PRD file name/,
231
+ );
232
+ },
233
+ );
234
+
235
+ it('deletes a PRD, distinguishes missing files from other errors', async () => {
236
+ const { service, files } = createHarness({
237
+ async unlink(path) {
238
+ if (basename(path) === 'locked.json') {
239
+ throw Object.assign(new Error('EACCES'), { code: 'EACCES' });
240
+ }
241
+ if (!(basename(path) in files)) {
242
+ throw Object.assign(new Error('ENOENT'), { code: 'ENOENT' });
243
+ }
244
+ delete files[basename(path)];
245
+ },
246
+ });
247
+ await service.create(BASE_INPUT);
248
+
249
+ await service.delete({ filename: 'notes-feature.json' });
250
+ expect(files['notes-feature.json']).toBeUndefined();
251
+
252
+ await expect(
253
+ service.delete({ filename: 'notes-feature.json' }),
254
+ ).rejects.toThrow(/not found/);
255
+ await expect(service.delete({ filename: 'locked.json' })).rejects.toThrow(
256
+ /EACCES/,
257
+ );
258
+ });
259
+ });
260
+
261
+ describe('PrdService stories', () => {
262
+ async function withStory(overrides: Partial<PrdDeps> = {}) {
263
+ const harness = createHarness(overrides);
264
+ await harness.service.create(BASE_INPUT);
265
+
266
+ const story = await harness.service.addUserStory({
267
+ filename: 'notes-feature.json',
268
+ userType: 'member',
269
+ action: 'create a note quickly',
270
+ benefit: 'I remember things',
271
+ acceptanceCriteria: ['form exists', 'note saved', 'list updates'],
272
+ priority: 'P1',
273
+ });
274
+
275
+ return { ...harness, story };
276
+ }
277
+
278
+ it('adds a story with a proof per criterion, checked before it is saved', async () => {
279
+ const harness = createHarness();
280
+ await harness.service.create(BASE_INPUT);
281
+
282
+ await harness.service.addUserStory({
283
+ filename: 'notes-feature.json',
284
+ userType: 'member',
285
+ action: 'create a note quickly',
286
+ benefit: 'I remember things',
287
+ acceptanceCriteria: ['note saved', ''],
288
+ priority: 'P1',
289
+ proofs: [{ criterion: 'note saved', kind: 'unit', seam: 'saveNote' }],
290
+ });
291
+
292
+ const prd = JSON.parse(harness.files['notes-feature.json']!);
293
+ expect(prd.userStories[0].proofs).toEqual([
294
+ { criterion: 'note saved', kind: 'unit', seam: 'saveNote' },
295
+ ]);
296
+
297
+ await expect(
298
+ harness.service.addUserStory({
299
+ filename: 'notes-feature.json',
300
+ userType: 'member',
301
+ action: 'see notes',
302
+ benefit: 'I find them',
303
+ acceptanceCriteria: ['list shows notes'],
304
+ priority: 'P1',
305
+ proofs: [{ criterion: 'list shows notes', kind: 'manual' }],
306
+ }),
307
+ ).rejects.toThrow(/needs a reason/);
308
+
309
+ expect(
310
+ JSON.parse(harness.files['notes-feature.json']!).userStories,
311
+ ).toHaveLength(1);
312
+ });
313
+
314
+ it('adds a story with derived id, title and complexity', async () => {
315
+ const { story, files } = await withStory();
316
+
317
+ expect(story).toEqual({
318
+ story_id: 'US001',
319
+ title: 'Create A Note Quickly',
320
+ complexity: 'S',
321
+ total_stories: 1,
322
+ });
323
+
324
+ const prd = JSON.parse(files['notes-feature.json']!);
325
+ expect(prd.userStories[0].userStory).toBe(
326
+ 'As a member, I want to create a note quickly so that I remember things',
327
+ );
328
+ expect(prd.progress.total).toBe(1);
329
+ });
330
+
331
+ it('moves a story to in_progress without running checks', async () => {
332
+ let calls = 0;
333
+ const { service } = await withStory({
334
+ verifyCompletion: async () => {
335
+ calls += 1;
336
+ return PASSING;
337
+ },
338
+ });
339
+
340
+ const result = await service.updateStoryStatus({
341
+ filename: 'notes-feature.json',
342
+ storyId: 'US001',
343
+ status: 'in_progress',
344
+ notes: 'started',
345
+ });
346
+
347
+ expect(calls).toBe(0);
348
+ expect(result).toEqual({
349
+ story_id: 'US001',
350
+ title: 'Create A Note Quickly',
351
+ status: 'in_progress',
352
+ progress: 0,
353
+ verification: null,
354
+ recorded_decisions: [],
355
+ });
356
+ });
357
+
358
+ it('refuses to complete a story when verification fails', async () => {
359
+ const { service, files } = await withStory({
360
+ verifyCompletion: async () => FAILING,
361
+ });
362
+
363
+ await expect(
364
+ service.updateStoryStatus({
365
+ filename: 'notes-feature.json',
366
+ storyId: 'US001',
367
+ status: 'completed',
368
+ }),
369
+ ).rejects.toThrow(
370
+ /Cannot mark US001 as completed: verification failed \(2 errors, 1 warnings across typecheck, lint\)\. First diagnostics: apps\/web\/app\/page\.tsx:12 TS2322 boom/,
371
+ );
372
+
373
+ const prd = JSON.parse(files['notes-feature.json']!);
374
+ expect(prd.userStories[0].status).toBe('not_started');
375
+ expect(prd.progress.completed).toBe(0);
376
+ });
377
+
378
+ it('surfaces infrastructure failures that produced no diagnostics', async () => {
379
+ const { service } = await withStory({
380
+ verifyCompletion: async () => ({
381
+ ...FAILING,
382
+ errors: 0,
383
+ warnings: 0,
384
+ diagnostics: [],
385
+ messages: ['typecheck: fail (spawn pnpm ENOENT)'],
386
+ }),
387
+ });
388
+
389
+ await expect(
390
+ service.updateStoryStatus({
391
+ filename: 'notes-feature.json',
392
+ storyId: 'US001',
393
+ status: 'completed',
394
+ }),
395
+ ).rejects.toThrow(/typecheck: fail \(spawn pnpm ENOENT\)/);
396
+ });
397
+
398
+ it('completes a story and records verification when checks pass', async () => {
399
+ const { service, files } = await withStory();
400
+
401
+ const result = await service.updateStoryStatus({
402
+ filename: 'notes-feature.json',
403
+ storyId: 'US001',
404
+ status: 'completed',
405
+ });
406
+
407
+ expect(result.status).toBe('completed');
408
+ expect(result.progress).toBe(100);
409
+ expect(result.verification).toEqual({
410
+ verified_at: '2026-09-06T10:00:00.000Z',
411
+ checks: ['typecheck', 'lint'],
412
+ passed: true,
413
+ });
414
+
415
+ const prd = JSON.parse(files['notes-feature.json']!);
416
+ expect(prd.userStories[0].completedAt).toBe('2026-09-06');
417
+ expect(prd.userStories[0].verification.passed).toBe(true);
418
+ });
419
+
420
+ it('records accepted deviations as decisions when completing, once', async () => {
421
+ const { service, files } = await withStory();
422
+ const deviation = 'Saved to IndexedDB instead of localStorage, for size';
423
+
424
+ await service.addStoryLog({
425
+ filename: 'notes-feature.json',
426
+ storyId: 'US001',
427
+ whatsNew: ['Notes save'],
428
+ technicalNotes: [],
429
+ deviations: [deviation, 'Added a word count'],
430
+ });
431
+
432
+ const result = await service.updateStoryStatus({
433
+ filename: 'notes-feature.json',
434
+ storyId: 'US001',
435
+ status: 'completed',
436
+ recordDeviations: [deviation],
437
+ });
438
+
439
+ expect(result.recorded_decisions).toEqual(['DEC001']);
440
+
441
+ const prd = JSON.parse(files['notes-feature.json']!);
442
+ expect(prd.decisionLog).toEqual([
443
+ expect.objectContaining({
444
+ id: 'DEC001',
445
+ decision: deviation,
446
+ status: 'accepted',
447
+ topic: 'story:US001:deviation',
448
+ }),
449
+ ]);
450
+
451
+ // Reopened and approved again: the same deviation is not recorded twice
452
+ await service.updateStoryStatus({
453
+ filename: 'notes-feature.json',
454
+ storyId: 'US001',
455
+ status: 'not_started',
456
+ });
457
+ const again = await service.updateStoryStatus({
458
+ filename: 'notes-feature.json',
459
+ storyId: 'US001',
460
+ status: 'completed',
461
+ recordDeviations: [deviation],
462
+ });
463
+
464
+ expect(again.recorded_decisions).toEqual([]);
465
+ });
466
+
467
+ it('refuses deviations the story did not log, or outside completion, before the checks run', async () => {
468
+ let checks = 0;
469
+ const { service, files } = await withStory({
470
+ verifyCompletion: async () => {
471
+ checks += 1;
472
+ return PASSING;
473
+ },
474
+ });
475
+
476
+ await expect(
477
+ service.updateStoryStatus({
478
+ filename: 'notes-feature.json',
479
+ storyId: 'US001',
480
+ status: 'completed',
481
+ recordDeviations: ['Something else'],
482
+ }),
483
+ ).rejects.toThrow(/did not log the deviation/);
484
+
485
+ await expect(
486
+ service.updateStoryStatus({
487
+ filename: 'notes-feature.json',
488
+ storyId: 'US001',
489
+ status: 'in_progress',
490
+ recordDeviations: ['Something else'],
491
+ }),
492
+ ).rejects.toThrow(/only when a story is completed/);
493
+
494
+ expect(checks).toBe(0);
495
+ expect(JSON.parse(files['notes-feature.json']!).userStories[0].status).toBe(
496
+ 'not_started',
497
+ );
498
+ });
499
+
500
+ it('does not overwrite stories added while verification was running', async () => {
501
+ let harness: ReturnType<typeof createHarness> | undefined;
502
+
503
+ const deps: Partial<PrdDeps> = {
504
+ async verifyCompletion() {
505
+ // Simulate a concurrent add_user_story landing mid-verification.
506
+ await harness!.service.addUserStory({
507
+ filename: 'notes-feature.json',
508
+ userType: 'admin',
509
+ action: 'archive notes',
510
+ benefit: 'tidy',
511
+ acceptanceCriteria: ['works'],
512
+ priority: 'P3',
513
+ });
514
+
515
+ return PASSING;
516
+ },
517
+ };
518
+
519
+ harness = createHarness(deps);
520
+ await harness.service.create(BASE_INPUT);
521
+ await harness.service.addUserStory({
522
+ filename: 'notes-feature.json',
523
+ userType: 'member',
524
+ action: 'create a note',
525
+ benefit: 'memory',
526
+ acceptanceCriteria: ['a', 'b'],
527
+ priority: 'P1',
528
+ });
529
+
530
+ const result = await harness.service.updateStoryStatus({
531
+ filename: 'notes-feature.json',
532
+ storyId: 'US001',
533
+ status: 'completed',
534
+ });
535
+
536
+ const prd = JSON.parse(harness.files['notes-feature.json']!);
537
+ expect(prd.userStories).toHaveLength(2);
538
+ expect(prd.userStories[0].status).toBe('completed');
539
+ expect(prd.userStories[1].title).toBe('Archive Notes');
540
+ expect(result.progress).toBe(50);
541
+ });
542
+
543
+ it('clears verification when a completed story is reopened', async () => {
544
+ const { service, files } = await withStory();
545
+
546
+ await service.updateStoryStatus({
547
+ filename: 'notes-feature.json',
548
+ storyId: 'US001',
549
+ status: 'completed',
550
+ });
551
+ await service.updateStoryStatus({
552
+ filename: 'notes-feature.json',
553
+ storyId: 'US001',
554
+ status: 'review',
555
+ });
556
+
557
+ const prd = JSON.parse(files['notes-feature.json']!);
558
+ expect(prd.userStories[0].verification).toBeUndefined();
559
+ expect(prd.userStories[0].completedAt).toBeUndefined();
560
+ expect(prd.progress.completed).toBe(0);
561
+ });
562
+
563
+ it('throws for unknown stories before running checks', async () => {
564
+ let calls = 0;
565
+ const { service } = await withStory({
566
+ verifyCompletion: async () => {
567
+ calls += 1;
568
+ return PASSING;
569
+ },
570
+ });
571
+
572
+ await expect(
573
+ service.updateStoryStatus({
574
+ filename: 'notes-feature.json',
575
+ storyId: 'US999',
576
+ status: 'completed',
577
+ }),
578
+ ).rejects.toThrow(/Story US999 not found/);
579
+ expect(calls).toBe(0);
580
+ });
581
+ });
582
+
583
+ describe('PrdService reports', () => {
584
+ it('exports markdown next to the JSON file', async () => {
585
+ const { service, files } = createHarness();
586
+ await service.create(BASE_INPUT);
587
+
588
+ const result = await service.exportMarkdown({
589
+ filename: 'notes-feature.json',
590
+ });
591
+
592
+ expect(result.markdown_file).toBe('notes-feature.md');
593
+ expect(files['notes-feature.md']).toContain('# Notes Feature');
594
+ });
595
+
596
+ it('produces prompts, suggestions and status', async () => {
597
+ const { service } = createHarness();
598
+ await service.create(BASE_INPUT);
599
+
600
+ expect(
601
+ (await service.getImplementationPrompts('notes-feature.json')).total,
602
+ ).toBe(0);
603
+
604
+ await service.addUserStory({
605
+ filename: 'notes-feature.json',
606
+ userType: 'member',
607
+ action: 'do x',
608
+ benefit: 'y',
609
+ acceptanceCriteria: ['one'],
610
+ priority: 'P2',
611
+ });
612
+
613
+ const prompts =
614
+ await service.getImplementationPrompts('notes-feature.json');
615
+ expect(prompts.total).toBe(1);
616
+ expect(prompts.prompts[0]).toBe(implementStoryPrompt('notes-feature.json'));
617
+ expect(prompts.prompts[0]).not.toMatch(/Mark the story completed/);
618
+
619
+ const suggestions =
620
+ await service.getImprovementSuggestions('notes-feature.json');
621
+ expect(suggestions.suggestions).toContain(
622
+ '1 stories need more detailed acceptance criteria',
623
+ );
624
+
625
+ const status = await service.getProjectStatus('notes-feature.json');
626
+ expect(status.next_steps).toEqual(['Start: Do X']);
627
+ expect(status.blockers).toEqual([]);
628
+
629
+ // Independent ready stories and dependent stories still share one prompt.
630
+ await service.addUserStory({
631
+ filename: 'notes-feature.json',
632
+ userType: 'member',
633
+ action: 'do z',
634
+ benefit: 'y',
635
+ acceptanceCriteria: ['one'],
636
+ priority: 'P2',
637
+ dependencies: ['US001'],
638
+ });
639
+ await service.addUserStory({
640
+ filename: 'notes-feature.json',
641
+ userType: 'member',
642
+ action: 'do independent work',
643
+ benefit: 'y',
644
+ acceptanceCriteria: ['one'],
645
+ priority: 'P2',
646
+ });
647
+
648
+ expect(
649
+ (await service.getImplementationPrompts('notes-feature.json')).total,
650
+ ).toBe(1);
651
+ });
652
+ });