@makerkit/prd 0.0.0 → 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.
Files changed (53) hide show
  1. package/package.json +2 -21
  2. package/.turbo/turbo-build.log +0 -46
  3. package/.turbo/turbo-test.log +0 -21
  4. package/.turbo/turbo-typecheck.log +0 -1
  5. package/dist/README.md +0 -65
  6. package/dist/package.json +0 -49
  7. package/src/__tests__/agent-workflow.test.ts +0 -377
  8. package/src/__tests__/attachments.test.ts +0 -475
  9. package/src/__tests__/node.test.ts +0 -141
  10. package/src/__tests__/plan-check.test.ts +0 -229
  11. package/src/__tests__/planning.test.ts +0 -1059
  12. package/src/__tests__/prd-operations.test.ts +0 -423
  13. package/src/__tests__/prd.service.test.ts +0 -477
  14. package/src/__tests__/prd.tool.test.ts +0 -282
  15. package/src/__tests__/templates.test.ts +0 -141
  16. package/src/applicability.ts +0 -73
  17. package/src/attachment-paths.ts +0 -78
  18. package/src/attachments.ts +0 -160
  19. package/src/edge-cases.ts +0 -52
  20. package/src/index.ts +0 -35
  21. package/src/markdown.ts +0 -268
  22. package/src/mcp/index.ts +0 -839
  23. package/src/mcp/tool-response.ts +0 -85
  24. package/src/node.ts +0 -146
  25. package/src/open-questions.ts +0 -93
  26. package/src/plan-check.ts +0 -282
  27. package/src/planning-operations.ts +0 -429
  28. package/src/prd-operations.ts +0 -690
  29. package/src/prd.service.ts +0 -1051
  30. package/src/prompts.ts +0 -110
  31. package/src/safe-file-name.ts +0 -42
  32. package/src/schema.ts +0 -976
  33. package/src/templates.ts +0 -173
  34. package/src/testing/fake-mcp-server.ts +0 -81
  35. package/src/types.ts +0 -333
  36. package/tsconfig.json +0 -23
  37. package/tsconfig.lib.json +0 -8
  38. package/tsconfig.spec.json +0 -7
  39. package/tsdown.config.mts +0 -11
  40. package/vitest.config.mts +0 -8
  41. /package/{dist/LICENSE → LICENSE} +0 -0
  42. /package/{dist/index.d.ts → index.d.ts} +0 -0
  43. /package/{dist/index.js → index.js} +0 -0
  44. /package/{dist/index.mjs → index.mjs} +0 -0
  45. /package/{dist/mcp.d.ts → mcp.d.ts} +0 -0
  46. /package/{dist/mcp.js → mcp.js} +0 -0
  47. /package/{dist/mcp.mjs → mcp.mjs} +0 -0
  48. /package/{dist/node.d.ts → node.d.ts} +0 -0
  49. /package/{dist/node.js → node.js} +0 -0
  50. /package/{dist/node.mjs → node.mjs} +0 -0
  51. /package/{dist/prd.service-DSBp8sMl.d.ts → prd.service-DSBp8sMl.d.ts} +0 -0
  52. /package/{dist/prompts-Bber0S1Z.mjs → prompts-Bber0S1Z.mjs} +0 -0
  53. /package/{dist/prompts-CIX8IeAx.js → prompts-CIX8IeAx.js} +0 -0
@@ -1,429 +0,0 @@
1
- import { appendChangeLog, nextId } from './prd-operations';
2
- import {
3
- type AddDecisionInput,
4
- type AddDecisionOutput,
5
- type AddGlossaryTermInput,
6
- type AddGlossaryTermOutput,
7
- type DeletePhaseInput,
8
- type PhasesOutput,
9
- PrdSectionValueSchemas,
10
- type ReorderPhasesInput,
11
- type DecideEdgeCaseInput,
12
- type DecideEdgeCaseOutput,
13
- type ResolveOpenQuestionInput,
14
- type ResolveOpenQuestionOutput,
15
- type UpdatePhaseInput,
16
- type UpdatePrdSectionInput,
17
- type UpdatePrdSectionOutput,
18
- } from './schema';
19
- import { nextQuestionId } from './open-questions';
20
- import type { CustomPhase, OpenQuestion, StructuredPRD } from './types';
21
-
22
- /**
23
- * Pure transforms for shaping a PRD after it was created: sections, decisions,
24
- * open questions, glossary and phases. Same contract as `prd-operations`:
25
- * mutate the loaded PRD, return the tool payload.
26
- */
27
-
28
- /** Sections whose value replaces the whole list. */
29
- const LIST_SECTIONS = new Set([
30
- 'nonGoals',
31
- 'outOfScope',
32
- 'assumptions',
33
- 'designGuidance',
34
- 'securityConsiderations',
35
- ]);
36
-
37
- export function updatePrdSection(
38
- prd: StructuredPRD,
39
- input: UpdatePrdSectionInput,
40
- today: string,
41
- ): UpdatePrdSectionOutput {
42
- const parsed = PrdSectionValueSchemas[input.section].safeParse(input.value);
43
-
44
- if (!parsed.success) {
45
- const issues = parsed.error.issues
46
- .map((issue) => `${issue.path.join('.') || 'value'}: ${issue.message}`)
47
- .join('; ');
48
-
49
- throw new Error(`Invalid value for section "${input.section}": ${issues}`);
50
- }
51
-
52
- const value = parsed.data;
53
- let updated: string[];
54
-
55
- if (input.section === 'risks') {
56
- const risks = value as (typeof PrdSectionValueSchemas)['risks']['_output'];
57
- const assigned: StructuredPRD['risks'] = [];
58
-
59
- for (const risk of risks) {
60
- assigned.push({ ...risk, id: risk.id ?? nextId(assigned, 'RISK') });
61
- }
62
-
63
- prd.risks = assigned;
64
- updated = assigned.map((risk) => risk.id);
65
- } else if (input.section === 'dependencies') {
66
- const items =
67
- value as (typeof PrdSectionValueSchemas)['dependencies']['_output'];
68
- const assigned: StructuredPRD['dependencies'] = [];
69
-
70
- for (const item of items) {
71
- assigned.push({ ...item, id: item.id ?? nextId(assigned, 'DEP') });
72
- }
73
-
74
- prd.dependencies = assigned;
75
- updated = assigned.map((item) => item.id);
76
- } else if (input.section === 'openQuestions') {
77
- const items =
78
- value as (typeof PrdSectionValueSchemas)['openQuestions']['_output'];
79
- const storyIds = new Set(prd.userStories.map((story) => story.id));
80
- const unknown = items
81
- .flatMap((item) => (typeof item === 'string' ? [] : (item.storyIds ?? [])))
82
- .filter((id) => !storyIds.has(id));
83
-
84
- if (unknown.length > 0) {
85
- throw new Error(
86
- `Invalid value for section "openQuestions": unknown stories ${[...new Set(unknown)].join(', ')}`,
87
- );
88
- }
89
-
90
- const assigned: StructuredPRD['openQuestions'] = [];
91
-
92
- for (const item of items) {
93
- const question = typeof item === 'string' ? { question: item } : item;
94
- const { id, storyIds: linked, options, ...rest } = question as typeof question & {
95
- id?: string;
96
- storyIds?: string[];
97
- options?: string[];
98
- };
99
-
100
- assigned.push({
101
- ...rest,
102
- id: id ?? nextQuestionId(prd, assigned),
103
- ...(options?.length ? { options } : {}),
104
- ...(linked?.length ? { storyIds: linked } : {}),
105
- });
106
- }
107
-
108
- prd.openQuestions = assigned;
109
- updated = assigned.map((item) => item.id);
110
- } else if (input.section === 'edgeCases') {
111
- const items =
112
- value as (typeof PrdSectionValueSchemas)['edgeCases']['_output'];
113
- const storyIds = new Set(prd.userStories.map((story) => story.id));
114
- const unknown = items
115
- .flatMap((item) => item.storyIds ?? [])
116
- .filter((id) => !storyIds.has(id));
117
-
118
- if (unknown.length > 0) {
119
- throw new Error(
120
- `Invalid value for section "edgeCases": unknown stories ${[...new Set(unknown)].join(', ')}`,
121
- );
122
- }
123
-
124
- const assigned: StructuredPRD['edgeCases'] = [];
125
-
126
- for (const item of items) {
127
- const { storyIds: linked, ...rest } = item;
128
-
129
- assigned.push({
130
- ...rest,
131
- id: item.id ?? nextId([...prd.edgeCases, ...assigned], 'EC'),
132
- ...(linked?.length ? { storyIds: linked } : {}),
133
- });
134
- }
135
-
136
- prd.edgeCases = assigned;
137
- updated = assigned.map((item) => item.id);
138
- } else if (LIST_SECTIONS.has(input.section)) {
139
- const key = input.section as
140
- | 'nonGoals'
141
- | 'outOfScope'
142
- | 'assumptions'
143
- | 'designGuidance'
144
- | 'securityConsiderations';
145
-
146
- prd[key] = value as string[];
147
- updated = [key];
148
- } else {
149
- const key = input.section as Exclude<
150
- keyof typeof PrdSectionValueSchemas,
151
- | 'risks'
152
- | 'dependencies'
153
- | 'edgeCases'
154
- | 'openQuestions'
155
- | 'nonGoals'
156
- | 'outOfScope'
157
- | 'assumptions'
158
- | 'designGuidance'
159
- | 'securityConsiderations'
160
- >;
161
-
162
- Object.assign(prd[key], value);
163
- updated = Object.keys(value as object);
164
- }
165
-
166
- appendChangeLog(prd, `Updated ${input.section}`, today);
167
-
168
- return { section: input.section, updated };
169
- }
170
-
171
- export function addDecision(
172
- prd: StructuredPRD,
173
- input: AddDecisionInput,
174
- today: string,
175
- ): AddDecisionOutput {
176
- let superseded: string | null = null;
177
-
178
- if (input.supersedes) {
179
- const previous = prd.decisionLog.find(
180
- (entry) => entry.id === input.supersedes,
181
- );
182
-
183
- if (!previous) {
184
- throw new Error(`Decision "${input.supersedes}" not found.`);
185
- }
186
-
187
- previous.status = 'superseded';
188
- superseded = previous.id;
189
- }
190
-
191
- const id = nextId(prd.decisionLog, 'DEC');
192
-
193
- prd.decisionLog.push({
194
- id,
195
- date: today,
196
- decision: input.decision,
197
- rationale: input.rationale,
198
- status: input.status,
199
- ...(input.owner ? { owner: input.owner } : {}),
200
- ...(input.topic ? { topic: input.topic } : {}),
201
- });
202
-
203
- appendChangeLog(
204
- prd,
205
- superseded ? `Recorded ${id} (supersedes ${superseded})` : `Recorded ${id}`,
206
- today,
207
- );
208
-
209
- return {
210
- decision_id: id,
211
- superseded,
212
- total_decisions: prd.decisionLog.length,
213
- };
214
- }
215
-
216
- export function resolveOpenQuestion(
217
- prd: StructuredPRD,
218
- input: ResolveOpenQuestionInput,
219
- today: string,
220
- ): ResolveOpenQuestionOutput {
221
- const wanted = input.question ? normalizeText(input.question) : null;
222
- const index = prd.openQuestions.findIndex((question) =>
223
- input.questionId
224
- ? question.id === input.questionId
225
- : normalizeText(question.question) === wanted,
226
- );
227
-
228
- if (index === -1) {
229
- throw new Error(
230
- `Open question not found: "${input.questionId ?? input.question}". ` +
231
- (prd.openQuestions.length
232
- ? `Open questions: ${prd.openQuestions.map((q) => `${q.id} "${q.question}"`).join(', ')}.`
233
- : 'This PRD has no open questions.'),
234
- );
235
- }
236
-
237
- const [question] = prd.openQuestions.splice(index, 1) as [OpenQuestion];
238
-
239
- let decisionId: string | null = null;
240
-
241
- if (input.recordDecision) {
242
- decisionId = addDecision(
243
- prd,
244
- {
245
- filename: input.filename,
246
- decision: input.answer,
247
- rationale:
248
- `Answers ${question.id}: ${question.question}` + (question.why ? ` (${question.why})` : ''),
249
- topic: `open-question:${question.id}`,
250
- status: 'accepted',
251
- },
252
- today,
253
- ).decision_id;
254
- } else {
255
- appendChangeLog(prd, `Resolved ${question.id}: ${question.question}`, today);
256
- }
257
-
258
- return {
259
- remaining_questions: prd.openQuestions.length,
260
- decision_id: decisionId,
261
- };
262
- }
263
-
264
- /** Answer an open edge case: it becomes decided with the given behaviour. */
265
- export function decideEdgeCase(
266
- prd: StructuredPRD,
267
- input: DecideEdgeCaseInput,
268
- today: string,
269
- ): DecideEdgeCaseOutput {
270
- const edgeCase = prd.edgeCases.find((candidate) => candidate.id === input.edgeCaseId);
271
-
272
- if (!edgeCase) {
273
- throw new Error(`Edge case "${input.edgeCaseId}" not found.`);
274
- }
275
-
276
- edgeCase.expectedBehavior = input.expectedBehavior.trim();
277
- edgeCase.status = 'decided';
278
- appendChangeLog(prd, `Decided ${edgeCase.id}: ${edgeCase.case}`, today);
279
-
280
- return {
281
- edge_case_id: edgeCase.id,
282
- open_edge_cases: prd.edgeCases.filter((candidate) => candidate.status === 'open').length,
283
- };
284
- }
285
-
286
- /** Adds a term, or replaces the definition of an existing one (any casing). */
287
- export function addGlossaryTerm(
288
- prd: StructuredPRD,
289
- input: AddGlossaryTermInput,
290
- today: string,
291
- ): AddGlossaryTermOutput {
292
- const term = input.term.trim();
293
- const existing = prd.glossary.find(
294
- (entry) => entry.term.toLowerCase() === term.toLowerCase(),
295
- );
296
-
297
- if (existing) {
298
- existing.term = term;
299
- existing.definition = input.definition;
300
- existing.avoid = input.avoid;
301
- } else {
302
- prd.glossary.push({
303
- term,
304
- definition: input.definition,
305
- avoid: input.avoid,
306
- });
307
- }
308
-
309
- appendChangeLog(
310
- prd,
311
- `${existing ? 'Redefined' : 'Defined'} glossary term "${term}"`,
312
- today,
313
- );
314
-
315
- return {
316
- term,
317
- replaced: Boolean(existing),
318
- total_terms: prd.glossary.length,
319
- };
320
- }
321
-
322
- export function updatePhase(
323
- prd: StructuredPRD,
324
- input: UpdatePhaseInput,
325
- today: string,
326
- ): PhasesOutput {
327
- const phase = findPhase(prd, input.phaseId);
328
-
329
- if (input.name !== undefined) {
330
- const name = input.name.trim();
331
- const clash = prd.customPhases.some(
332
- (other) =>
333
- other.id !== phase.id &&
334
- other.name.toLowerCase() === name.toLowerCase(),
335
- );
336
-
337
- if (clash) {
338
- throw new Error(`A phase named "${name}" already exists.`);
339
- }
340
-
341
- phase.name = name;
342
- }
343
-
344
- if (input.description !== undefined) phase.description = input.description;
345
- if (input.color !== undefined) phase.color = input.color;
346
-
347
- appendChangeLog(prd, `Updated phase ${phase.id}`, today);
348
-
349
- return phasesPayload(prd);
350
- }
351
-
352
- /** Deletes a phase; its stories stay in the PRD without a phase. */
353
- export function deletePhase(
354
- prd: StructuredPRD,
355
- input: DeletePhaseInput,
356
- today: string,
357
- ): PhasesOutput {
358
- const phase = findPhase(prd, input.phaseId);
359
-
360
- prd.customPhases = prd.customPhases.filter((other) => other.id !== phase.id);
361
- renumberPhases(prd.customPhases);
362
-
363
- appendChangeLog(prd, `Deleted phase ${phase.id} (${phase.name})`, today);
364
-
365
- return phasesPayload(prd);
366
- }
367
-
368
- export function reorderPhases(
369
- prd: StructuredPRD,
370
- input: ReorderPhasesInput,
371
- today: string,
372
- ): PhasesOutput {
373
- const known = prd.customPhases.map((phase) => phase.id).sort();
374
- const given = [...input.phaseIds].sort();
375
-
376
- if (
377
- known.length !== given.length ||
378
- known.some((id, index) => id !== given[index])
379
- ) {
380
- throw new Error(
381
- `phaseIds must list every phase exactly once. Phases: ${known.join(', ') || 'none'}.`,
382
- );
383
- }
384
-
385
- prd.customPhases = input.phaseIds.map((id) => findPhase(prd, id));
386
- renumberPhases(prd.customPhases);
387
-
388
- appendChangeLog(prd, `Reordered phases: ${input.phaseIds.join(', ')}`, today);
389
-
390
- return phasesPayload(prd);
391
- }
392
-
393
- function findPhase(prd: StructuredPRD, phaseId: string): CustomPhase {
394
- const phase = prd.customPhases.find((candidate) => candidate.id === phaseId);
395
-
396
- if (!phase) {
397
- const known = prd.customPhases.map((candidate) => candidate.id).join(', ');
398
-
399
- throw new Error(
400
- `Phase "${phaseId}" not found.` +
401
- (known ? ` Known phases: ${known}.` : ' This PRD has no phases yet.'),
402
- );
403
- }
404
-
405
- return phase;
406
- }
407
-
408
- function renumberPhases(phases: CustomPhase[]) {
409
- phases.forEach((phase, index) => {
410
- phase.order = index;
411
- });
412
- }
413
-
414
- function phasesPayload(prd: StructuredPRD): PhasesOutput {
415
- return {
416
- phases: [...prd.customPhases]
417
- .sort((a, b) => a.order - b.order)
418
- .map((phase) => ({
419
- id: phase.id,
420
- name: phase.name,
421
- order: phase.order,
422
- user_story_ids: phase.userStoryIds,
423
- })),
424
- };
425
- }
426
-
427
- function normalizeText(value: string) {
428
- return value.trim().replace(/\s+/g, ' ').toLowerCase();
429
- }