@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makerkit/prd",
3
- "version": "0.0.0",
3
+ "version": "0.0.2",
4
4
  "description": "Structured PRDs as JSON files: the format, a service to manage them, and MCP tools so coding agents can read and update them.",
5
5
  "keywords": [
6
6
  "ai-agents",
@@ -34,29 +34,10 @@
34
34
  "require": "./mcp.js"
35
35
  }
36
36
  },
37
- "publishConfig": {
38
- "access": "public",
39
- "directory": "dist",
40
- "linkDirectory": true
41
- },
42
- "scripts": {
43
- "build": "tsdown && node ../../scripts/prepare-dist.mjs",
44
- "typecheck": "tsc --noEmit -p tsconfig.lib.json && tsc --noEmit -p tsconfig.spec.json",
45
- "test": "vitest run"
46
- },
47
37
  "dependencies": {
48
- "@makerkit/repo-checks": "workspace:^",
38
+ "@makerkit/repo-checks": "^0.0.2",
49
39
  "zod": "^3.25.0 || ^4.0.0"
50
40
  },
51
- "devDependencies": {
52
- "@modelcontextprotocol/sdk": "catalog:",
53
- "@types/node": "catalog:",
54
- "tsdown": "catalog:",
55
- "typescript": "catalog:",
56
- "vite": "catalog:",
57
- "vitest": "catalog:",
58
- "zod": "catalog:"
59
- },
60
41
  "peerDependencies": {
61
42
  "@modelcontextprotocol/sdk": "^1.32.0"
62
43
  },
@@ -1,4 +1,82 @@
1
1
  import { z } from "zod/v3";
2
+ //#region src/safe-file-name.ts
3
+ /**
4
+ * Accept only a bare file name. Anything that could escape the intended
5
+ * directory (path separators, parent references, hidden files) is rejected
6
+ * before the filesystem is touched.
7
+ */
8
+ function assertSafeFileName(value, label = "file name") {
9
+ const name = value.trim();
10
+ if (name.length === 0 || name.includes("..") || name.includes("/") || name.includes("\\") || name.startsWith(".")) throw new Error(`Invalid ${label} "${value}"`);
11
+ return name;
12
+ }
13
+ /**
14
+ * Accept only a relative path that stays inside the directory it is joined
15
+ * to: no absolute paths, no `..`, no backslashes, no empty or hidden segments.
16
+ * This is a check on the text only; code that serves the file must still
17
+ * resolve symlinks before reading it.
18
+ */
19
+ function assertSafeRelativePath(value, label = "path") {
20
+ const path = value.trim();
21
+ const segments = path.split("/");
22
+ if (path.length === 0 || path.includes("\\") || /^[a-zA-Z]:/.test(path) || segments.some((segment) => segment.length === 0 || segment.startsWith("."))) throw new Error(`Invalid ${label} "${value}"`);
23
+ return path;
24
+ }
25
+ //#endregion
26
+ //#region src/attachment-paths.ts
27
+ /**
28
+ * The folder for a PRD's files, relative to `.prds`: the PRD file name
29
+ * without `.json`, so `notes.json` keeps its files in `.prds/notes/`.
30
+ */
31
+ function attachmentsFolder(filename) {
32
+ return filename.replace(/\.json$/, "");
33
+ }
34
+ /** An attachment's file relative to the project root, e.g. `.prds/notes/a.png`. */
35
+ function attachmentProjectPath(filename, path) {
36
+ return `.prds/${attachmentsFolder(filename)}/${path}`;
37
+ }
38
+ /** Attachments as an agent needs them: file paths from the project root. */
39
+ function resolveAttachments(filename, attachments) {
40
+ return attachments.map(({ path, ...attachment }) => ({
41
+ ...attachment,
42
+ ...path ? { path: attachmentProjectPath(filename, path) } : {}
43
+ }));
44
+ }
45
+ /**
46
+ * Attachments as stored, with hand-edited entries that would break readers
47
+ * or point outside the PRD folder dropped: each needs a string id and title
48
+ * and either a safe relative path or an http(s) url.
49
+ */
50
+ function normalizeAttachments(value) {
51
+ if (!Array.isArray(value)) return [];
52
+ return value.flatMap((entry) => {
53
+ if (typeof entry !== "object" || entry === null) return [];
54
+ const { id, title, path, url, note } = entry;
55
+ if (typeof id !== "string" || typeof title !== "string") return [];
56
+ const base = {
57
+ id,
58
+ title,
59
+ ...typeof note === "string" && note ? { note } : {}
60
+ };
61
+ if (typeof path === "string" && url === void 0 && isSafePath(path)) return [{
62
+ ...base,
63
+ path
64
+ }];
65
+ if (typeof url === "string" && path === void 0 && /^https?:\/\//i.test(url)) return [{
66
+ ...base,
67
+ url
68
+ }];
69
+ return [];
70
+ });
71
+ }
72
+ function isSafePath(path) {
73
+ try {
74
+ return assertSafeRelativePath(path) === path;
75
+ } catch {
76
+ return false;
77
+ }
78
+ }
79
+ //#endregion
2
80
  //#region src/templates.ts
3
81
  const TEMPLATE_IDS = [
4
82
  "saas-feature",
@@ -732,7 +810,27 @@ function shapePrdPrompt(idea, filename, templateId) {
732
810
  "- Create the phases first (create_custom_phase), in the order they should be built. Each phase should end with something a person can try (a page in the app, an API call, a command); say what in its description.",
733
811
  "- Add each story with add_user_story in one call: testSeams (the public entry points the tests will exercise), dependencies (stories that must be completed first) and phaseId. Add designNotes when the story has a screen or states the PRD design guidance does not settle, and securityNotes for each way this story in particular could be abused (whose ids it accepts, what input it trusts, what it costs to repeat) with the defence. Do not repeat the PRD-wide guidance or considerations there.",
734
812
  "- When the user shares mockups, screenshots or reference docs, save each file in the PRD folder (.prds/<prd file name without .json>/) and record it with add_attachment, linking the stories that use it. Record links to outside docs with a url instead.",
735
- "- Confirm the breakdown with the user, then fix anything with update_user_story or assign_story_to_phase."
813
+ "- Confirm the breakdown with the user, then fix anything with update_user_story or assign_story_to_phase.",
814
+ "- When the breakdown is confirmed, tell the user the next step is the architect_prd prompt, which designs the shape all the stories share before any of them is built."
815
+ ].join("\n");
816
+ }
817
+ function architectPrdPrompt(filename) {
818
+ const designPath = attachmentProjectPath(filename, "architecture.md");
819
+ return [
820
+ `Design how the PRD "${filename}" gets built, before any story is coded: the data model, the modules and who owns which rule, the entry points and the test seams all stories share. Without it, each story's agent invents its own shape.`,
821
+ "",
822
+ "1. Call get_prd and check_plan. If check_plan returns a required item, an edge case is still open, or an open question blocks a story, stop: tell the user what is missing and that shape_prd continues from there. A design built around an undecided behaviour bakes in a guess.",
823
+ "2. If an \"Architecture\" attachment already exists, this is a redesign. Read it, and call get_story on the completed stories to read their logs. The same kind of deviation in two or more stories means the shape is wrong; one deviation is information. If the shape still holds, say so and stop.",
824
+ `3. Design. If the project provides an architect skill (for example /architect), run it now. Give it the PRD's content itself (stories, acceptance criteria, edge cases, data models, permissions, security considerations, integrations, decisions), not just the file name, and ${designPath} as the output path. Ask it to key the work and test seams by story id. For a redesign, also give it the previous design and the deviations found in step 2, and say it is a redesign. Otherwise design it yourself: learn how the nearest existing feature works end to end; sketch two structurally different designs (where state lives, who owns which rule), each starting from the code that will call it, then the data model, then the interfaces and the test seams per story; drop shapes with shallow interfaces, logic split across owners, or two ways to do one thing; choose one, and write it to ${designPath} with what was rejected and why. Do not write production code or migrations.`,
825
+ "",
826
+ "Then record the design in the PRD, where story agents will find it. get_story does not return technicalContracts.apis or architecture decisions, so the attachment is how the design reaches them:",
827
+ "4. add_attachment with title \"Architecture\", path \"architecture.md\", a note (\"The contract for the data model, modules and test seams; record departures as deviations\"), and storyIds for every story it covers. If the attachment already exists, use update_attachment instead.",
828
+ "5. update_prd_section, section \"technicalContracts\", value { apis, dataModels }. Only the keys given change, but each list replaces the previous one, so pass every item. apis: one line per action, route, endpoint or function. dataModels: refine the existing descriptions with the real tables or entities, keeping their plain-language wording.",
829
+ "6. add_decision with topic \"architecture\": the chosen shape in one sentence, with a rationale that names the rejected alternative and why it lost. For a redesign, set supersedes to the previous architecture decision. Add a separate decision for each other hard-to-reverse choice.",
830
+ "7. For each story, update_user_story with its testSeams, and with dependencies when the design reveals an order the slicing missed.",
831
+ "8. If several stories need shared groundwork (the core schema, a module skeleton), add it as its own story with add_user_story in the earliest phase, and make the stories that need it depend on it. For a redesign, add stories that move the built parts to the new shape.",
832
+ "9. Open questions the design raised go to update_prd_section \"openQuestions\" with the stories they block (keep the ids of existing questions; the list replaces the previous one), or ask the user now and record the answer with add_decision. Never leave a question only in the design file: get_story and check_plan do not read it.",
833
+ "10. Do not change story statuses. Report the chosen shape, the rejected alternative, the decisions recorded, any new stories, and that implement_story is the next step."
736
834
  ].join("\n");
737
835
  }
738
836
  function reviewStoryPrompt(filename, storyId, base) {
@@ -763,7 +861,7 @@ function implementStoryPrompt(filename, storyId) {
763
861
  return [
764
862
  `You are implementing a story from the PRD "${filename}". ${storyId ? `Work on story ${storyId}.` : "Call get_next_story. If a story is already in progress (for example one sent back from review), finish that one first; otherwise take the story it returns. If none is ready, report why and stop."}`,
765
863
  "",
766
- "1. Call get_story. If the story has notes, read them first: a story sent back from review carries the reviewer's feedback there, and addressing it comes before anything else. Read the acceptance criteria, the non-goals and out-of-scope items, and the logs of its dependencies and of the previous story. Open the files and links in its attachments (mockups, reference docs); they show what is meant, but the acceptance criteria decide what is done. Build only what this story asks for.",
864
+ "1. Call get_story. If the story has notes, read them first: a story sent back from review carries the reviewer's feedback there, and addressing it comes before anything else. Read the acceptance criteria, the non-goals and out-of-scope items, and the logs of its dependencies and of the previous story. Open the files and links in its attachments (mockups, reference docs); they show what is meant, but the acceptance criteria decide what is done. An \"Architecture\" attachment is the contract for the data model, modules and test seams: build against it, and list every departure from it in deviations. Build only what this story asks for.",
767
865
  " Its edge_cases are part of the spec: implement and test each decided case as stated. If a case is still open, ask the user what should happen before building that part; never pick a behaviour yourself. Follow the design guidance, design decisions and the story's own design.story_notes for anything a person sees.",
768
866
  " If open_questions lists questions that block this story, ask the user, record the answer with resolve_open_question, and only then build the part it affects.",
769
867
  " The security rules are binding, including the story's own security.story_notes: enforce the permissions on the server for every read and write, never trust input from the browser, and keep secrets out of the client and logs. Before finishing, attack your own change: try another user's ids, a lower role, hostile input and repeated requests, and add tests for what you find. Parts listed in not_applicable do not apply: do not build them.",
@@ -775,4 +873,4 @@ function implementStoryPrompt(filename, storyId) {
775
873
  ].join("\n");
776
874
  }
777
875
  //#endregion
778
- export { PrdSummarySchema as $, ExportPrdMarkdownInputSchema as A, GetProjectStatusInputSchema as B, DecideEdgeCaseInputSchema as C, DeletePrdOutputSchema as D, DeletePrdInputSchema as E, GetImprovementSuggestionsOutputSchema as F, ListPrdsOutputSchema as G, GetStoryInputSchema as H, GetNextStoryInputSchema as I, MarkNotApplicableInputSchema as J, ListTemplatesInputSchema as K, GetNextStoryOutputSchema as L, GetImplementationPromptsInputSchema as M, GetImplementationPromptsOutputSchema as N, DeleteUserStoryInputSchema as O, GetImprovementSuggestionsInputSchema as P, PrdSectionValueSchemas as Q, GetPrdInputSchema as R, CustomPhaseSchema as S, getTemplate as St, DeletePhaseInputSchema as T, GetStoryOutputSchema as U, GetProjectStatusOutputSchema as V, ListPrdsInputSchema as W, NotApplicableTopicSchema as X, MarkNotApplicableOutputSchema as Y, PhasesOutputSchema as Z, CheckPlanOutputSchema as _, UpdateStoryStatusOutputSchema as _t, AddAttachmentOutputSchema as a, StoryAttachmentSchema as at, CreatePrdInputSchema as b, PRD_TEMPLATES as bt, AddGlossaryTermInputSchema as c, StoryPrioritySchema as ct, AddStoryLogOutputSchema as d, UpdateAttachmentInputSchema as dt, RemoveAttachmentInputSchema as et, AddUserStoryInputSchema as f, UpdateAttachmentOutputSchema as ft, CheckPlanInputSchema as g, UpdateStoryStatusInputSchema as gt, AssignStoryToPhaseOutputSchema as h, UpdatePrdSectionOutputSchema as ht, AddAttachmentInputSchema as i, ResolveOpenQuestionOutputSchema as it, ExportPrdMarkdownOutputSchema as j, DeleteUserStoryOutputSchema as k, AddGlossaryTermOutputSchema as l, StoryStatusSchema as lt, AssignStoryToPhaseInputSchema as m, UpdatePrdSectionInputSchema as mt, reviewStoryPrompt as n, ReorderPhasesInputSchema as nt, AddDecisionInputSchema as o, StoryComplexitySchema as ot, AddUserStoryOutputSchema as p, UpdatePhaseInputSchema as pt, ListTemplatesOutputSchema as q, shapePrdPrompt as r, ResolveOpenQuestionInputSchema as rt, AddDecisionOutputSchema as s, StoryLogEntrySchema as st, implementStoryPrompt as t, RemoveAttachmentOutputSchema as tt, AddStoryLogInputSchema as u, StoryVerificationSchema as ut, CreateCustomPhaseInputSchema as v, UpdateUserStoryInputSchema as vt, DecideEdgeCaseOutputSchema as w, CreatePrdOutputSchema as x, TEMPLATE_IDS as xt, CreateCustomPhaseOutputSchema as y, UpdateUserStoryOutputSchema as yt, GetPrdOutputSchema as z };
876
+ export { PrdSectionValueSchemas as $, DeleteUserStoryOutputSchema as A, GetPrdOutputSchema as B, CustomPhaseSchema as C, getTemplate as Ct, DeletePrdInputSchema as D, resolveAttachments as Dt, DeletePhaseInputSchema as E, normalizeAttachments as Et, GetImprovementSuggestionsInputSchema as F, ListPrdsInputSchema as G, GetProjectStatusOutputSchema as H, GetImprovementSuggestionsOutputSchema as I, ListTemplatesOutputSchema as J, ListPrdsOutputSchema as K, GetNextStoryInputSchema as L, ExportPrdMarkdownOutputSchema as M, GetImplementationPromptsInputSchema as N, DeletePrdOutputSchema as O, assertSafeFileName as Ot, GetImplementationPromptsOutputSchema as P, PhasesOutputSchema as Q, GetNextStoryOutputSchema as R, CreatePrdOutputSchema as S, TEMPLATE_IDS as St, DecideEdgeCaseOutputSchema as T, attachmentsFolder as Tt, GetStoryInputSchema as U, GetProjectStatusInputSchema as V, GetStoryOutputSchema as W, MarkNotApplicableOutputSchema as X, MarkNotApplicableInputSchema as Y, NotApplicableTopicSchema as Z, CheckPlanInputSchema as _, UpdateStoryStatusInputSchema as _t, AddAttachmentInputSchema as a, ResolveOpenQuestionOutputSchema as at, CreateCustomPhaseOutputSchema as b, UpdateUserStoryOutputSchema as bt, AddDecisionOutputSchema as c, StoryLogEntrySchema as ct, AddStoryLogInputSchema as d, StoryVerificationSchema as dt, PrdSummarySchema as et, AddStoryLogOutputSchema as f, UpdateAttachmentInputSchema as ft, AssignStoryToPhaseOutputSchema as g, UpdatePrdSectionOutputSchema as gt, AssignStoryToPhaseInputSchema as h, UpdatePrdSectionInputSchema as ht, shapePrdPrompt as i, ResolveOpenQuestionInputSchema as it, ExportPrdMarkdownInputSchema as j, DeleteUserStoryInputSchema as k, assertSafeRelativePath as kt, AddGlossaryTermInputSchema as l, StoryPrioritySchema as lt, AddUserStoryOutputSchema as m, UpdatePhaseInputSchema as mt, implementStoryPrompt as n, RemoveAttachmentOutputSchema as nt, AddAttachmentOutputSchema as o, StoryAttachmentSchema as ot, AddUserStoryInputSchema as p, UpdateAttachmentOutputSchema as pt, ListTemplatesInputSchema as q, reviewStoryPrompt as r, ReorderPhasesInputSchema as rt, AddDecisionInputSchema as s, StoryComplexitySchema as st, architectPrdPrompt as t, RemoveAttachmentInputSchema as tt, AddGlossaryTermOutputSchema as u, StoryStatusSchema as ut, CheckPlanOutputSchema as v, UpdateStoryStatusOutputSchema as vt, DecideEdgeCaseInputSchema as w, attachmentProjectPath as wt, CreatePrdInputSchema as x, PRD_TEMPLATES as xt, CreateCustomPhaseInputSchema as y, UpdateUserStoryInputSchema as yt, GetPrdInputSchema as z };
@@ -1,4 +1,82 @@
1
1
  let zod_v3 = require("zod/v3");
2
+ //#region src/safe-file-name.ts
3
+ /**
4
+ * Accept only a bare file name. Anything that could escape the intended
5
+ * directory (path separators, parent references, hidden files) is rejected
6
+ * before the filesystem is touched.
7
+ */
8
+ function assertSafeFileName(value, label = "file name") {
9
+ const name = value.trim();
10
+ if (name.length === 0 || name.includes("..") || name.includes("/") || name.includes("\\") || name.startsWith(".")) throw new Error(`Invalid ${label} "${value}"`);
11
+ return name;
12
+ }
13
+ /**
14
+ * Accept only a relative path that stays inside the directory it is joined
15
+ * to: no absolute paths, no `..`, no backslashes, no empty or hidden segments.
16
+ * This is a check on the text only; code that serves the file must still
17
+ * resolve symlinks before reading it.
18
+ */
19
+ function assertSafeRelativePath(value, label = "path") {
20
+ const path = value.trim();
21
+ const segments = path.split("/");
22
+ if (path.length === 0 || path.includes("\\") || /^[a-zA-Z]:/.test(path) || segments.some((segment) => segment.length === 0 || segment.startsWith("."))) throw new Error(`Invalid ${label} "${value}"`);
23
+ return path;
24
+ }
25
+ //#endregion
26
+ //#region src/attachment-paths.ts
27
+ /**
28
+ * The folder for a PRD's files, relative to `.prds`: the PRD file name
29
+ * without `.json`, so `notes.json` keeps its files in `.prds/notes/`.
30
+ */
31
+ function attachmentsFolder(filename) {
32
+ return filename.replace(/\.json$/, "");
33
+ }
34
+ /** An attachment's file relative to the project root, e.g. `.prds/notes/a.png`. */
35
+ function attachmentProjectPath(filename, path) {
36
+ return `.prds/${attachmentsFolder(filename)}/${path}`;
37
+ }
38
+ /** Attachments as an agent needs them: file paths from the project root. */
39
+ function resolveAttachments(filename, attachments) {
40
+ return attachments.map(({ path, ...attachment }) => ({
41
+ ...attachment,
42
+ ...path ? { path: attachmentProjectPath(filename, path) } : {}
43
+ }));
44
+ }
45
+ /**
46
+ * Attachments as stored, with hand-edited entries that would break readers
47
+ * or point outside the PRD folder dropped: each needs a string id and title
48
+ * and either a safe relative path or an http(s) url.
49
+ */
50
+ function normalizeAttachments(value) {
51
+ if (!Array.isArray(value)) return [];
52
+ return value.flatMap((entry) => {
53
+ if (typeof entry !== "object" || entry === null) return [];
54
+ const { id, title, path, url, note } = entry;
55
+ if (typeof id !== "string" || typeof title !== "string") return [];
56
+ const base = {
57
+ id,
58
+ title,
59
+ ...typeof note === "string" && note ? { note } : {}
60
+ };
61
+ if (typeof path === "string" && url === void 0 && isSafePath(path)) return [{
62
+ ...base,
63
+ path
64
+ }];
65
+ if (typeof url === "string" && path === void 0 && /^https?:\/\//i.test(url)) return [{
66
+ ...base,
67
+ url
68
+ }];
69
+ return [];
70
+ });
71
+ }
72
+ function isSafePath(path) {
73
+ try {
74
+ return assertSafeRelativePath(path) === path;
75
+ } catch {
76
+ return false;
77
+ }
78
+ }
79
+ //#endregion
2
80
  //#region src/templates.ts
3
81
  const TEMPLATE_IDS = [
4
82
  "saas-feature",
@@ -732,7 +810,27 @@ function shapePrdPrompt(idea, filename, templateId) {
732
810
  "- Create the phases first (create_custom_phase), in the order they should be built. Each phase should end with something a person can try (a page in the app, an API call, a command); say what in its description.",
733
811
  "- Add each story with add_user_story in one call: testSeams (the public entry points the tests will exercise), dependencies (stories that must be completed first) and phaseId. Add designNotes when the story has a screen or states the PRD design guidance does not settle, and securityNotes for each way this story in particular could be abused (whose ids it accepts, what input it trusts, what it costs to repeat) with the defence. Do not repeat the PRD-wide guidance or considerations there.",
734
812
  "- When the user shares mockups, screenshots or reference docs, save each file in the PRD folder (.prds/<prd file name without .json>/) and record it with add_attachment, linking the stories that use it. Record links to outside docs with a url instead.",
735
- "- Confirm the breakdown with the user, then fix anything with update_user_story or assign_story_to_phase."
813
+ "- Confirm the breakdown with the user, then fix anything with update_user_story or assign_story_to_phase.",
814
+ "- When the breakdown is confirmed, tell the user the next step is the architect_prd prompt, which designs the shape all the stories share before any of them is built."
815
+ ].join("\n");
816
+ }
817
+ function architectPrdPrompt(filename) {
818
+ const designPath = attachmentProjectPath(filename, "architecture.md");
819
+ return [
820
+ `Design how the PRD "${filename}" gets built, before any story is coded: the data model, the modules and who owns which rule, the entry points and the test seams all stories share. Without it, each story's agent invents its own shape.`,
821
+ "",
822
+ "1. Call get_prd and check_plan. If check_plan returns a required item, an edge case is still open, or an open question blocks a story, stop: tell the user what is missing and that shape_prd continues from there. A design built around an undecided behaviour bakes in a guess.",
823
+ "2. If an \"Architecture\" attachment already exists, this is a redesign. Read it, and call get_story on the completed stories to read their logs. The same kind of deviation in two or more stories means the shape is wrong; one deviation is information. If the shape still holds, say so and stop.",
824
+ `3. Design. If the project provides an architect skill (for example /architect), run it now. Give it the PRD's content itself (stories, acceptance criteria, edge cases, data models, permissions, security considerations, integrations, decisions), not just the file name, and ${designPath} as the output path. Ask it to key the work and test seams by story id. For a redesign, also give it the previous design and the deviations found in step 2, and say it is a redesign. Otherwise design it yourself: learn how the nearest existing feature works end to end; sketch two structurally different designs (where state lives, who owns which rule), each starting from the code that will call it, then the data model, then the interfaces and the test seams per story; drop shapes with shallow interfaces, logic split across owners, or two ways to do one thing; choose one, and write it to ${designPath} with what was rejected and why. Do not write production code or migrations.`,
825
+ "",
826
+ "Then record the design in the PRD, where story agents will find it. get_story does not return technicalContracts.apis or architecture decisions, so the attachment is how the design reaches them:",
827
+ "4. add_attachment with title \"Architecture\", path \"architecture.md\", a note (\"The contract for the data model, modules and test seams; record departures as deviations\"), and storyIds for every story it covers. If the attachment already exists, use update_attachment instead.",
828
+ "5. update_prd_section, section \"technicalContracts\", value { apis, dataModels }. Only the keys given change, but each list replaces the previous one, so pass every item. apis: one line per action, route, endpoint or function. dataModels: refine the existing descriptions with the real tables or entities, keeping their plain-language wording.",
829
+ "6. add_decision with topic \"architecture\": the chosen shape in one sentence, with a rationale that names the rejected alternative and why it lost. For a redesign, set supersedes to the previous architecture decision. Add a separate decision for each other hard-to-reverse choice.",
830
+ "7. For each story, update_user_story with its testSeams, and with dependencies when the design reveals an order the slicing missed.",
831
+ "8. If several stories need shared groundwork (the core schema, a module skeleton), add it as its own story with add_user_story in the earliest phase, and make the stories that need it depend on it. For a redesign, add stories that move the built parts to the new shape.",
832
+ "9. Open questions the design raised go to update_prd_section \"openQuestions\" with the stories they block (keep the ids of existing questions; the list replaces the previous one), or ask the user now and record the answer with add_decision. Never leave a question only in the design file: get_story and check_plan do not read it.",
833
+ "10. Do not change story statuses. Report the chosen shape, the rejected alternative, the decisions recorded, any new stories, and that implement_story is the next step."
736
834
  ].join("\n");
737
835
  }
738
836
  function reviewStoryPrompt(filename, storyId, base) {
@@ -763,7 +861,7 @@ function implementStoryPrompt(filename, storyId) {
763
861
  return [
764
862
  `You are implementing a story from the PRD "${filename}". ${storyId ? `Work on story ${storyId}.` : "Call get_next_story. If a story is already in progress (for example one sent back from review), finish that one first; otherwise take the story it returns. If none is ready, report why and stop."}`,
765
863
  "",
766
- "1. Call get_story. If the story has notes, read them first: a story sent back from review carries the reviewer's feedback there, and addressing it comes before anything else. Read the acceptance criteria, the non-goals and out-of-scope items, and the logs of its dependencies and of the previous story. Open the files and links in its attachments (mockups, reference docs); they show what is meant, but the acceptance criteria decide what is done. Build only what this story asks for.",
864
+ "1. Call get_story. If the story has notes, read them first: a story sent back from review carries the reviewer's feedback there, and addressing it comes before anything else. Read the acceptance criteria, the non-goals and out-of-scope items, and the logs of its dependencies and of the previous story. Open the files and links in its attachments (mockups, reference docs); they show what is meant, but the acceptance criteria decide what is done. An \"Architecture\" attachment is the contract for the data model, modules and test seams: build against it, and list every departure from it in deviations. Build only what this story asks for.",
767
865
  " Its edge_cases are part of the spec: implement and test each decided case as stated. If a case is still open, ask the user what should happen before building that part; never pick a behaviour yourself. Follow the design guidance, design decisions and the story's own design.story_notes for anything a person sees.",
768
866
  " If open_questions lists questions that block this story, ask the user, record the answer with resolve_open_question, and only then build the part it affects.",
769
867
  " The security rules are binding, including the story's own security.story_notes: enforce the permissions on the server for every read and write, never trust input from the browser, and keep secrets out of the client and logs. Before finishing, attack your own change: try another user's ids, a lower role, hostile input and repeated requests, and add tests for what you find. Parts listed in not_applicable do not apply: do not build them.",
@@ -1207,6 +1305,36 @@ Object.defineProperty(exports, "UpdateUserStoryOutputSchema", {
1207
1305
  return UpdateUserStoryOutputSchema;
1208
1306
  }
1209
1307
  });
1308
+ Object.defineProperty(exports, "architectPrdPrompt", {
1309
+ enumerable: true,
1310
+ get: function() {
1311
+ return architectPrdPrompt;
1312
+ }
1313
+ });
1314
+ Object.defineProperty(exports, "assertSafeFileName", {
1315
+ enumerable: true,
1316
+ get: function() {
1317
+ return assertSafeFileName;
1318
+ }
1319
+ });
1320
+ Object.defineProperty(exports, "assertSafeRelativePath", {
1321
+ enumerable: true,
1322
+ get: function() {
1323
+ return assertSafeRelativePath;
1324
+ }
1325
+ });
1326
+ Object.defineProperty(exports, "attachmentProjectPath", {
1327
+ enumerable: true,
1328
+ get: function() {
1329
+ return attachmentProjectPath;
1330
+ }
1331
+ });
1332
+ Object.defineProperty(exports, "attachmentsFolder", {
1333
+ enumerable: true,
1334
+ get: function() {
1335
+ return attachmentsFolder;
1336
+ }
1337
+ });
1210
1338
  Object.defineProperty(exports, "getTemplate", {
1211
1339
  enumerable: true,
1212
1340
  get: function() {
@@ -1219,6 +1347,18 @@ Object.defineProperty(exports, "implementStoryPrompt", {
1219
1347
  return implementStoryPrompt;
1220
1348
  }
1221
1349
  });
1350
+ Object.defineProperty(exports, "normalizeAttachments", {
1351
+ enumerable: true,
1352
+ get: function() {
1353
+ return normalizeAttachments;
1354
+ }
1355
+ });
1356
+ Object.defineProperty(exports, "resolveAttachments", {
1357
+ enumerable: true,
1358
+ get: function() {
1359
+ return resolveAttachments;
1360
+ }
1361
+ });
1222
1362
  Object.defineProperty(exports, "reviewStoryPrompt", {
1223
1363
  enumerable: true,
1224
1364
  get: function() {
@@ -1,46 +0,0 @@
1
- $ tsdown && node ../../scripts/prepare-dist.mjs
2
- ℹ tsdown v0.23.0 powered by rolldown v1.2.13
3
- ℹ config file: /Users/giancarlo/Code/makerkit/packages/prd/tsdown.config.mts
4
- ℹ entry: src/index.ts, src/node.ts, src/mcp/index.ts
5
- ℹ entry: src/index.ts, src/node.ts, src/mcp/index.ts
6
- ℹ tsconfig: tsconfig.lib.json
7
- ℹ tsconfig: tsconfig.lib.json
8
- ℹ Build start
9
- ℹ Cleaning 15 files
10
- ℹ [ESM] dist/index.mjs 57.30 kB │ gzip: 14.75 kB
11
- ℹ [ESM] dist/mcp.mjs 21.44 kB │ gzip: 4.71 kB
12
- ℹ [ESM] dist/node.mjs 2.79 kB │ gzip: 1.19 kB
13
- ℹ [ESM] dist/prompts-D-8eu2qV.mjs 31.30 kB │ gzip: 9.07 kB
14
- ℹ [ESM] 4 files, total: 112.84 kB
15
- src/prd.service.ts (87:21) [UNRESOLVED_IMPORT] Could not resolve 'node:path' in src/prd.service.ts
16
- ╭─[ src/prd.service.ts:87:22 ]
17
- │
18
- 87 │ import { join } from 'node:path';
19
-  │ ─────┬─────
20
-  │ ╰─────── Module not found, treating it as an external dependency
21
-  │
22
-  │ Help: The "main" field here was ignored. Main fields must be configured explicitly when using the "neutral" platform.
23
- ────╯
24
-
25
- src/node.ts (12:7) [UNRESOLVED_IMPORT] Could not resolve 'node:fs/promises' in src/node.ts
26
- ╭─[ src/node.ts:12:8 ]
27
- │
28
- 12 │ } from 'node:fs/promises';
29
-  │ ─────────┬────────
30
-  │ ╰────────── Module not found, treating it as an external dependency
31
-  │
32
-  │ Help: The "main" field here was ignored. Main fields must be configured explicitly when using the "neutral" platform.
33
- ────╯
34
-
35
- ✔ Build complete in 472ms
36
- ℹ [CJS] dist/index.js 59.60 kB │ gzip: 14.68 kB
37
- ℹ [CJS] dist/mcp.js 21.14 kB │ gzip: 4.40 kB
38
- ℹ [CJS] dist/node.js 3.04 kB │ gzip: 1.27 kB
39
- ℹ [CJS] dist/prompts-DUS02Mwl.js 41.35 kB │ gzip: 9.39 kB
40
- ℹ [CJS] 4 files, total: 125.15 kB
41
- ℹ [CJS] dist/index.d.ts 14.49 kB │ gzip: 3.91 kB
42
- ℹ [CJS] dist/node.d.ts 0.94 kB │ gzip: 0.51 kB
43
- ℹ [CJS] dist/mcp.d.ts 0.42 kB │ gzip: 0.28 kB
44
- ℹ [CJS] dist/prd.service-DoTF-akm.d.ts 61.23 kB │ gzip: 9.37 kB
45
- ℹ [CJS] 4 files, total: 77.08 kB
46
- ✔ Build complete in 777ms
@@ -1,21 +0,0 @@
1
- $ vitest run
2
-
3
-  RUN  v5.0.4 /Users/giancarlo/Code/makerkit/packages/prd
4
-
5
- ✓ src/__tests__/templates.test.ts (4 tests) 10ms
6
- ✓ src/__tests__/plan-check.test.ts (6 tests) 3ms
7
- ✓ src/__tests__/prd-operations.test.ts (24 tests) 5ms
8
- ✓ src/__tests__/prd.tool.test.ts (9 tests) 17ms
9
- ✓ src/__tests__/attachments.test.ts (14 tests) 18ms
10
- ✓ src/__tests__/agent-workflow.test.ts (12 tests) 21ms
11
- ✓ src/__tests__/planning.test.ts (17 tests) 23ms
12
- ✓ src/__tests__/prd.service.test.ts (18 tests) 16ms
13
- ✓ src/__tests__/node.test.ts (6 tests) 941ms
14
- ✓ createScriptVerifier (4)
15
- ✓ passes when every defined check exits 0 307ms
16
-
17
-  Test Files  9 passed (9)
18
-  Tests  110 passed (110)
19
-  Start at  23:31:27
20
-  Duration  1.15s (tests 47%, transform 41%, import 10%, worker 2%)
21
-
@@ -1 +0,0 @@
1
- $ tsc --noEmit -p tsconfig.lib.json && tsc --noEmit -p tsconfig.spec.json
package/dist/README.md DELETED
@@ -1,65 +0,0 @@
1
- # @makerkit/prd
2
-
3
- Structured product requirements documents (PRDs) stored as JSON files in `.prds/`, plus the tools to manage them from code or from a coding agent over MCP.
4
-
5
- - **Format**: a typed `StructuredPRD` (stories, statuses, priorities, dependencies, phases, risks, decisions) with Zod schemas. Hand-written files are normalized on load. Text fields may use Markdown; list items (acceptance criteria, non-goals, ...) keep to inline Markdown, and raw HTML is not rendered.
6
- - **Service**: create PRDs, add and update user stories, move stories through `not_started → research → in_progress → review → completed`, export markdown.
7
- - **Completion gate**: a story can only be marked `completed` when the project's checks pass, so "done" means the code verifies.
8
- - **MCP tools**: the same operations exposed to Claude Code, Codex, OpenCode or any MCP client.
9
- - **Attachments**: files (mockups, screenshots, reference docs) live in a folder next to the PRD, `.prds/<prd name>/`, and links can be recorded too. Stories reference them by id, and `get_story` returns them with their paths.
10
- - **Prompts**: `shape_prd` interviews you round by round (numbered questions, each with a recommended answer and its reason) and writes every decision into the PRD; `implement_story` walks an agent through one story and its hand-off log. The same text is exported (`implementStoryPrompt`, `shapePrdPrompt`, `reviewStoryPrompt`) for UIs and agents without MCP prompt support.
11
-
12
- ## Install
13
-
14
- ```bash
15
- pnpm add @makerkit/prd
16
- ```
17
-
18
- ## Usage
19
-
20
- ```ts
21
- import { createPrdService } from '@makerkit/prd';
22
- import { createNodePrdDeps } from '@makerkit/prd/node';
23
-
24
- const prds = createPrdService(createNodePrdDeps(process.cwd()));
25
-
26
- const { prds: list } = await prds.list();
27
- ```
28
-
29
- By default, completing a story runs the project's `typecheck` and `lint` scripts with its package manager (scripts that do not exist are skipped). Pass your own check instead:
30
-
31
- ```ts
32
- createNodePrdDeps(root, {
33
- verifyCompletion: async () => ({
34
- passed: true,
35
- checks: ['custom'],
36
- errors: 0,
37
- warnings: 0,
38
- diagnostics: [],
39
- messages: [],
40
- }),
41
- });
42
- ```
43
-
44
- ### MCP
45
-
46
- Requires `@modelcontextprotocol/sdk`.
47
-
48
- ```ts
49
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
50
- import { createPrdService } from '@makerkit/prd';
51
- import { registerPRDTools } from '@makerkit/prd/mcp';
52
- import { createNodePrdDeps } from '@makerkit/prd/node';
53
-
54
- const server = new McpServer({ name: 'prd', version: '1.0.0' });
55
-
56
- registerPRDTools(server, createPrdService(createNodePrdDeps()));
57
- ```
58
-
59
- ## Credits
60
-
61
- The `shape_prd` interview and the story-slicing rules are adapted from ideas in Matt Pocock's [skills](https://github.com/mattpocock/skills) (MIT), in particular grilling and to-tickets.
62
-
63
- ## License
64
-
65
- MIT
package/dist/package.json DELETED
@@ -1,49 +0,0 @@
1
- {
2
- "name": "@makerkit/prd",
3
- "version": "0.0.0",
4
- "description": "Structured PRDs as JSON files: the format, a service to manage them, and MCP tools so coding agents can read and update them.",
5
- "keywords": [
6
- "ai-agents",
7
- "claude-code",
8
- "codex",
9
- "mcp",
10
- "prd",
11
- "product-requirements"
12
- ],
13
- "license": "MIT",
14
- "repository": {
15
- "type": "git",
16
- "url": "https://github.com/makerkit/makerkit",
17
- "directory": "packages/prd"
18
- },
19
- "main": "./index.js",
20
- "exports": {
21
- ".": {
22
- "types": "./index.d.ts",
23
- "import": "./index.mjs",
24
- "require": "./index.js"
25
- },
26
- "./node": {
27
- "types": "./node.d.ts",
28
- "import": "./node.mjs",
29
- "require": "./node.js"
30
- },
31
- "./mcp": {
32
- "types": "./mcp.d.ts",
33
- "import": "./mcp.mjs",
34
- "require": "./mcp.js"
35
- }
36
- },
37
- "dependencies": {
38
- "@makerkit/repo-checks": "^0.0.0",
39
- "zod": "^3.25.0 || ^4.0.0"
40
- },
41
- "peerDependencies": {
42
- "@modelcontextprotocol/sdk": "^1.32.0"
43
- },
44
- "peerDependenciesMeta": {
45
- "@modelcontextprotocol/sdk": {
46
- "optional": true
47
- }
48
- }
49
- }