@shahmarasy/prodo 0.1.3 → 0.1.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 (205) hide show
  1. package/README.md +201 -97
  2. package/bin/prodo.cjs +6 -6
  3. package/dist/agents/agent-registry.d.ts +13 -0
  4. package/dist/agents/agent-registry.js +79 -0
  5. package/dist/agents/anthropic/index.d.ts +9 -0
  6. package/dist/agents/anthropic/index.js +55 -0
  7. package/dist/agents/base.d.ts +25 -0
  8. package/dist/agents/base.js +71 -0
  9. package/dist/agents/google/index.d.ts +9 -0
  10. package/dist/agents/google/index.js +53 -0
  11. package/dist/agents/mock/index.d.ts +11 -0
  12. package/dist/agents/mock/index.js +26 -0
  13. package/dist/agents/openai/index.d.ts +9 -0
  14. package/dist/agents/openai/index.js +57 -0
  15. package/dist/agents/system-prompts.d.ts +3 -0
  16. package/dist/agents/system-prompts.js +32 -0
  17. package/dist/agents.js +4 -2
  18. package/dist/artifacts.d.ts +1 -0
  19. package/dist/artifacts.js +265 -31
  20. package/dist/cli/agent-command-installer.d.ts +4 -0
  21. package/dist/cli/agent-command-installer.js +148 -0
  22. package/dist/cli/agent-ids.d.ts +15 -0
  23. package/dist/cli/agent-ids.js +49 -0
  24. package/dist/cli/doctor.d.ts +1 -0
  25. package/dist/cli/doctor.js +144 -0
  26. package/dist/cli/fix-tui.d.ts +4 -0
  27. package/dist/cli/fix-tui.js +79 -0
  28. package/dist/cli/index.d.ts +9 -0
  29. package/dist/cli/index.js +465 -0
  30. package/dist/cli/init-tui.d.ts +23 -0
  31. package/dist/cli/init-tui.js +176 -0
  32. package/dist/cli/init.d.ts +11 -0
  33. package/dist/cli/init.js +334 -0
  34. package/dist/cli/normalize-interactive.d.ts +8 -0
  35. package/dist/cli/normalize-interactive.js +167 -0
  36. package/dist/cli/preset-loader.d.ts +4 -0
  37. package/dist/cli/preset-loader.js +210 -0
  38. package/dist/cli.js +80 -3
  39. package/dist/core/artifact-registry.d.ts +11 -0
  40. package/dist/core/artifact-registry.js +49 -0
  41. package/dist/core/artifacts.d.ts +10 -0
  42. package/dist/core/artifacts.js +892 -0
  43. package/dist/core/clean.d.ts +10 -0
  44. package/dist/core/clean.js +74 -0
  45. package/dist/core/consistency.d.ts +8 -0
  46. package/dist/core/consistency.js +328 -0
  47. package/dist/core/constants.d.ts +7 -0
  48. package/dist/core/constants.js +64 -0
  49. package/dist/core/errors.d.ts +3 -0
  50. package/dist/core/errors.js +10 -0
  51. package/dist/core/fix.d.ts +31 -0
  52. package/dist/core/fix.js +188 -0
  53. package/dist/core/hook-executor.d.ts +1 -0
  54. package/dist/core/hook-executor.js +175 -0
  55. package/dist/core/markdown.d.ts +16 -0
  56. package/dist/core/markdown.js +81 -0
  57. package/dist/core/normalize.d.ts +8 -0
  58. package/dist/core/normalize.js +125 -0
  59. package/dist/core/normalized-brief.d.ts +48 -0
  60. package/dist/core/normalized-brief.js +182 -0
  61. package/dist/core/output-index.d.ts +13 -0
  62. package/dist/core/output-index.js +55 -0
  63. package/dist/core/paths.d.ts +17 -0
  64. package/dist/core/paths.js +80 -0
  65. package/dist/core/project-config.d.ts +14 -0
  66. package/dist/core/project-config.js +69 -0
  67. package/dist/core/registry.d.ts +13 -0
  68. package/dist/core/registry.js +115 -0
  69. package/dist/core/settings.d.ts +7 -0
  70. package/dist/core/settings.js +35 -0
  71. package/dist/core/template-engine.d.ts +3 -0
  72. package/dist/core/template-engine.js +43 -0
  73. package/dist/core/template-resolver.d.ts +15 -0
  74. package/dist/core/template-resolver.js +46 -0
  75. package/dist/core/templates.d.ts +33 -0
  76. package/dist/core/templates.js +440 -0
  77. package/dist/core/terminology.d.ts +21 -0
  78. package/dist/core/terminology.js +143 -0
  79. package/dist/core/tracing.d.ts +21 -0
  80. package/dist/core/tracing.js +74 -0
  81. package/dist/core/types.d.ts +35 -0
  82. package/dist/core/types.js +5 -0
  83. package/dist/core/utils.d.ts +7 -0
  84. package/dist/core/utils.js +66 -0
  85. package/dist/core/validate.d.ts +10 -0
  86. package/dist/core/validate.js +226 -0
  87. package/dist/core/validator.d.ts +5 -0
  88. package/dist/core/validator.js +76 -0
  89. package/dist/core/version.d.ts +1 -0
  90. package/dist/core/version.js +30 -0
  91. package/dist/core/workflow-commands.d.ts +7 -0
  92. package/dist/core/workflow-commands.js +29 -0
  93. package/dist/i18n/en.json +45 -0
  94. package/dist/i18n/index.d.ts +5 -0
  95. package/dist/i18n/index.js +63 -0
  96. package/dist/i18n/tr.json +45 -0
  97. package/dist/init-tui.d.ts +3 -0
  98. package/dist/init-tui.js +28 -1
  99. package/dist/init.d.ts +1 -0
  100. package/dist/init.js +9 -3
  101. package/dist/normalize.js +55 -7
  102. package/dist/providers/index.d.ts +2 -1
  103. package/dist/providers/index.js +20 -6
  104. package/dist/providers/mock-provider.d.ts +1 -1
  105. package/dist/providers/mock-provider.js +7 -6
  106. package/dist/providers/openai-provider.d.ts +1 -1
  107. package/dist/providers/openai-provider.js +3 -2
  108. package/dist/settings.d.ts +1 -0
  109. package/dist/settings.js +2 -1
  110. package/dist/skills/engine.d.ts +10 -0
  111. package/dist/skills/engine.js +75 -0
  112. package/dist/skills/fix-skill.d.ts +2 -0
  113. package/dist/skills/fix-skill.js +38 -0
  114. package/dist/skills/generate-artifact-skill.d.ts +2 -0
  115. package/dist/skills/generate-artifact-skill.js +32 -0
  116. package/dist/skills/generate-pipeline-skill.d.ts +2 -0
  117. package/dist/skills/generate-pipeline-skill.js +45 -0
  118. package/dist/skills/normalize-skill.d.ts +2 -0
  119. package/dist/skills/normalize-skill.js +29 -0
  120. package/dist/skills/types.d.ts +28 -0
  121. package/dist/skills/types.js +2 -0
  122. package/dist/skills/validate-skill.d.ts +2 -0
  123. package/dist/skills/validate-skill.js +29 -0
  124. package/dist/templates.d.ts +1 -1
  125. package/dist/templates.js +2 -0
  126. package/dist/utils.d.ts +1 -0
  127. package/dist/utils.js +13 -0
  128. package/dist/validator.js +0 -4
  129. package/dist/workflow-commands.js +2 -1
  130. package/package.json +74 -45
  131. package/presets/fintech/preset.json +48 -1
  132. package/presets/fintech/prompts/prd.md +99 -2
  133. package/presets/marketplace/preset.json +51 -1
  134. package/presets/marketplace/prompts/prd.md +140 -2
  135. package/presets/saas/preset.json +53 -1
  136. package/presets/saas/prompts/prd.md +150 -2
  137. package/src/agents/agent-registry.ts +93 -0
  138. package/src/agents/anthropic/index.ts +86 -0
  139. package/src/agents/anthropic/manifest.json +7 -0
  140. package/src/agents/base.ts +77 -0
  141. package/src/agents/google/index.ts +79 -0
  142. package/src/agents/google/manifest.json +7 -0
  143. package/src/agents/mock/index.ts +32 -0
  144. package/src/agents/mock/manifest.json +7 -0
  145. package/src/agents/openai/index.ts +83 -0
  146. package/src/agents/openai/manifest.json +7 -0
  147. package/src/agents/system-prompts.ts +35 -0
  148. package/src/{agent-command-installer.ts → cli/agent-command-installer.ts} +164 -164
  149. package/src/{agents.ts → cli/agent-ids.ts} +58 -56
  150. package/src/{doctor.ts → cli/doctor.ts} +157 -137
  151. package/src/cli/fix-tui.ts +111 -0
  152. package/src/{cli.ts → cli/index.ts} +459 -319
  153. package/src/{init-tui.ts → cli/init-tui.ts} +208 -179
  154. package/src/{init.ts → cli/init.ts} +398 -391
  155. package/src/cli/normalize-interactive.ts +241 -0
  156. package/src/{preset-loader.ts → cli/preset-loader.ts} +237 -237
  157. package/src/{artifact-registry.ts → core/artifact-registry.ts} +69 -69
  158. package/src/{artifacts.ts → core/artifacts.ts} +1081 -777
  159. package/src/core/clean.ts +88 -0
  160. package/src/{consistency.ts → core/consistency.ts} +374 -303
  161. package/src/{constants.ts → core/constants.ts} +72 -72
  162. package/src/{errors.ts → core/errors.ts} +7 -7
  163. package/src/core/fix.ts +253 -0
  164. package/src/{hook-executor.ts → core/hook-executor.ts} +196 -196
  165. package/src/{markdown.ts → core/markdown.ts} +93 -73
  166. package/src/core/normalize.ts +145 -0
  167. package/src/{normalized-brief.ts → core/normalized-brief.ts} +227 -206
  168. package/src/{output-index.ts → core/output-index.ts} +59 -59
  169. package/src/{paths.ts → core/paths.ts} +75 -71
  170. package/src/{project-config.ts → core/project-config.ts} +78 -78
  171. package/src/{registry.ts → core/registry.ts} +119 -119
  172. package/src/{settings.ts → core/settings.ts} +35 -34
  173. package/src/core/template-engine.ts +45 -0
  174. package/src/{template-resolver.ts → core/template-resolver.ts} +54 -54
  175. package/src/{templates.ts → core/templates.ts} +452 -450
  176. package/src/core/terminology.ts +177 -0
  177. package/src/core/tracing.ts +110 -0
  178. package/src/{types.ts → core/types.ts} +46 -46
  179. package/src/{utils.ts → core/utils.ts} +64 -50
  180. package/src/{validate.ts → core/validate.ts} +252 -246
  181. package/src/{validator.ts → core/validator.ts} +92 -96
  182. package/src/{version.ts → core/version.ts} +24 -24
  183. package/src/{workflow-commands.ts → core/workflow-commands.ts} +32 -31
  184. package/src/i18n/en.json +45 -0
  185. package/src/i18n/index.ts +58 -0
  186. package/src/i18n/tr.json +45 -0
  187. package/src/providers/index.ts +29 -12
  188. package/src/providers/mock-provider.ts +200 -199
  189. package/src/providers/openai-provider.ts +88 -87
  190. package/src/skills/engine.ts +94 -0
  191. package/src/skills/fix-skill.ts +38 -0
  192. package/src/skills/generate-artifact-skill.ts +32 -0
  193. package/src/skills/generate-pipeline-skill.ts +49 -0
  194. package/src/skills/normalize-skill.ts +29 -0
  195. package/src/skills/types.ts +36 -0
  196. package/src/skills/validate-skill.ts +29 -0
  197. package/templates/commands/prodo-fix.md +46 -0
  198. package/templates/commands/prodo-normalize.md +118 -23
  199. package/templates/commands/prodo-prd.md +138 -17
  200. package/templates/commands/prodo-stories.md +153 -17
  201. package/templates/commands/prodo-techspec.md +167 -17
  202. package/templates/commands/prodo-validate.md +184 -26
  203. package/templates/commands/prodo-wireframe.md +188 -17
  204. package/templates/commands/prodo-workflow.md +200 -17
  205. package/src/normalize.ts +0 -89
@@ -1,59 +1,59 @@
1
- import fs from "node:fs/promises";
2
- import path from "node:path";
3
- import { outputIndexPath } from "./paths";
4
- import type { ArtifactType } from "./types";
5
- import { ensureDir, fileExists } from "./utils";
6
-
7
- type ArtifactMap = Partial<Record<ArtifactType, string>>;
8
- type ArtifactHistoryMap = Partial<Record<ArtifactType, string[]>>;
9
-
10
- export type OutputIndex = {
11
- active: ArtifactMap;
12
- history: ArtifactHistoryMap;
13
- updated_at: string;
14
- };
15
-
16
- function defaultIndex(): OutputIndex {
17
- return {
18
- active: {},
19
- history: {},
20
- updated_at: new Date(0).toISOString()
21
- };
22
- }
23
-
24
- export async function loadOutputIndex(cwd: string): Promise<OutputIndex> {
25
- const indexPath = outputIndexPath(cwd);
26
- if (!(await fileExists(indexPath))) return defaultIndex();
27
- const raw = await fs.readFile(indexPath, "utf8");
28
- const parsed = JSON.parse(raw) as Partial<OutputIndex>;
29
- return {
30
- active: parsed.active ?? {},
31
- history: parsed.history ?? {},
32
- updated_at: parsed.updated_at ?? new Date(0).toISOString()
33
- };
34
- }
35
-
36
- export async function saveOutputIndex(cwd: string, index: OutputIndex): Promise<void> {
37
- const indexPath = outputIndexPath(cwd);
38
- await ensureDir(path.dirname(indexPath));
39
- await fs.writeFile(indexPath, `${JSON.stringify(index, null, 2)}\n`, "utf8");
40
- }
41
-
42
- export async function setActiveArtifact(cwd: string, type: ArtifactType, filePath: string): Promise<void> {
43
- const index = await loadOutputIndex(cwd);
44
- const normalizedPath = path.resolve(filePath);
45
- const existing = index.history[type] ?? [];
46
- index.active[type] = normalizedPath;
47
- index.history[type] = [normalizedPath, ...existing.filter((item) => item !== normalizedPath)].slice(0, 100);
48
- index.updated_at = new Date().toISOString();
49
- await saveOutputIndex(cwd, index);
50
- }
51
-
52
- export async function getActiveArtifactPath(cwd: string, type: ArtifactType): Promise<string | undefined> {
53
- const index = await loadOutputIndex(cwd);
54
- const candidate = index.active[type];
55
- if (!candidate) return undefined;
56
- if (await fileExists(candidate)) return candidate;
57
- return undefined;
58
- }
59
-
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { outputIndexPath } from "./paths";
4
+ import type { ArtifactType } from "./types";
5
+ import { ensureDir, fileExists } from "./utils";
6
+
7
+ type ArtifactMap = Partial<Record<ArtifactType, string>>;
8
+ type ArtifactHistoryMap = Partial<Record<ArtifactType, string[]>>;
9
+
10
+ export type OutputIndex = {
11
+ active: ArtifactMap;
12
+ history: ArtifactHistoryMap;
13
+ updated_at: string;
14
+ };
15
+
16
+ function defaultIndex(): OutputIndex {
17
+ return {
18
+ active: {},
19
+ history: {},
20
+ updated_at: new Date(0).toISOString()
21
+ };
22
+ }
23
+
24
+ export async function loadOutputIndex(cwd: string): Promise<OutputIndex> {
25
+ const indexPath = outputIndexPath(cwd);
26
+ if (!(await fileExists(indexPath))) return defaultIndex();
27
+ const raw = await fs.readFile(indexPath, "utf8");
28
+ const parsed = JSON.parse(raw) as Partial<OutputIndex>;
29
+ return {
30
+ active: parsed.active ?? {},
31
+ history: parsed.history ?? {},
32
+ updated_at: parsed.updated_at ?? new Date(0).toISOString()
33
+ };
34
+ }
35
+
36
+ export async function saveOutputIndex(cwd: string, index: OutputIndex): Promise<void> {
37
+ const indexPath = outputIndexPath(cwd);
38
+ await ensureDir(path.dirname(indexPath));
39
+ await fs.writeFile(indexPath, `${JSON.stringify(index, null, 2)}\n`, "utf8");
40
+ }
41
+
42
+ export async function setActiveArtifact(cwd: string, type: ArtifactType, filePath: string): Promise<void> {
43
+ const index = await loadOutputIndex(cwd);
44
+ const normalizedPath = path.resolve(filePath);
45
+ const existing = index.history[type] ?? [];
46
+ index.active[type] = normalizedPath;
47
+ index.history[type] = [normalizedPath, ...existing.filter((item) => item !== normalizedPath)].slice(0, 100);
48
+ index.updated_at = new Date().toISOString();
49
+ await saveOutputIndex(cwd, index);
50
+ }
51
+
52
+ export async function getActiveArtifactPath(cwd: string, type: ArtifactType): Promise<string | undefined> {
53
+ const index = await loadOutputIndex(cwd);
54
+ const candidate = index.active[type];
55
+ if (!candidate) return undefined;
56
+ if (await fileExists(candidate)) return candidate;
57
+ return undefined;
58
+ }
59
+
@@ -1,72 +1,76 @@
1
- import path from "node:path";
2
- import { defaultOutputDir, PRODO_DIR } from "./constants";
3
- import type { ArtifactType } from "./types";
4
-
5
- export function prodoPath(cwd: string): string {
6
- return path.join(cwd, PRODO_DIR);
7
- }
8
-
9
- export function briefPath(cwd: string): string {
10
- return path.join(cwd, "brief.md");
11
- }
12
-
13
- export function normalizedBriefPath(cwd: string): string {
14
- return path.join(prodoPath(cwd), "briefs", "normalized-brief.json");
15
- }
16
-
17
- export function settingsPath(cwd: string): string {
18
- return path.join(prodoPath(cwd), "settings.json");
19
- }
20
-
21
- export function registryPath(cwd: string): string {
22
- return path.join(prodoPath(cwd), "registry.json");
23
- }
24
-
25
- export function promptPath(cwd: string, artifactType: ArtifactType): string {
26
- return path.join(prodoPath(cwd), "prompts", `${artifactType}.md`);
27
- }
28
-
29
- export function templatePath(cwd: string, artifactType: ArtifactType): string {
30
- return path.join(prodoPath(cwd), "templates", `${artifactType}.md`);
31
- }
32
-
33
- export function overrideTemplatePath(cwd: string, artifactType: ArtifactType): string {
34
- return path.join(prodoPath(cwd), "templates", "overrides", `${artifactType}.md`);
35
- }
36
-
37
- function templateExtensionsForArtifact(artifactType: ArtifactType): string[] {
38
- if (artifactType === "workflow") return ["md", "mmd"];
39
- if (artifactType === "wireframe") return ["md", "html"];
40
- return ["md"];
41
- }
42
-
43
- export function templateCandidatePaths(cwd: string, artifactType: ArtifactType): string[] {
44
- const root = path.join(prodoPath(cwd), "templates");
45
- return templateExtensionsForArtifact(artifactType).map((ext) => path.join(root, `${artifactType}.${ext}`));
46
- }
47
-
48
- export function overrideTemplateCandidatePaths(cwd: string, artifactType: ArtifactType): string[] {
49
- const root = path.join(prodoPath(cwd), "templates", "overrides");
50
- return templateExtensionsForArtifact(artifactType).map((ext) => path.join(root, `${artifactType}.${ext}`));
51
- }
52
-
53
- export function schemaPath(cwd: string, artifactType: ArtifactType): string {
54
- return path.join(prodoPath(cwd), "schemas", `${artifactType}.yaml`);
55
- }
56
-
57
- export function outputDirPath(cwd: string, artifactType: ArtifactType, outputDirOverride?: string): string {
58
- return path.join(cwd, "product-docs", outputDirOverride ?? defaultOutputDir(artifactType));
59
- }
60
-
61
- export function reportPath(cwd: string): string {
62
- return path.join(cwd, "product-docs", "reports", "latest-validation.md");
63
- }
64
-
65
- export function outputIndexPath(cwd: string): string {
66
- return path.join(prodoPath(cwd), "state", "index.json");
67
- }
68
-
69
- export function outputContextDirPath(cwd: string): string {
70
- return path.join(prodoPath(cwd), "state", "context");
71
- }
1
+ import path from "node:path";
2
+ import { defaultOutputDir, PRODO_DIR } from "./constants";
3
+ import type { ArtifactType } from "./types";
4
+
5
+ export function prodoPath(cwd: string): string {
6
+ return path.join(cwd, PRODO_DIR);
7
+ }
8
+
9
+ export function briefPath(cwd: string): string {
10
+ return path.join(cwd, "brief.md");
11
+ }
12
+
13
+ export function normalizedBriefPath(cwd: string): string {
14
+ return path.join(prodoPath(cwd), "briefs", "normalized-brief.json");
15
+ }
16
+
17
+ export function settingsPath(cwd: string): string {
18
+ return path.join(prodoPath(cwd), "settings.json");
19
+ }
20
+
21
+ export function registryPath(cwd: string): string {
22
+ return path.join(prodoPath(cwd), "registry.json");
23
+ }
24
+
25
+ export function promptPath(cwd: string, artifactType: ArtifactType): string {
26
+ return path.join(prodoPath(cwd), "prompts", `${artifactType}.md`);
27
+ }
28
+
29
+ export function templatePath(cwd: string, artifactType: ArtifactType): string {
30
+ return path.join(prodoPath(cwd), "templates", `${artifactType}.md`);
31
+ }
32
+
33
+ export function overrideTemplatePath(cwd: string, artifactType: ArtifactType): string {
34
+ return path.join(prodoPath(cwd), "templates", "overrides", `${artifactType}.md`);
35
+ }
36
+
37
+ function templateExtensionsForArtifact(artifactType: ArtifactType): string[] {
38
+ if (artifactType === "workflow") return ["md", "mmd"];
39
+ if (artifactType === "wireframe") return ["md", "html"];
40
+ return ["md"];
41
+ }
42
+
43
+ export function templateCandidatePaths(cwd: string, artifactType: ArtifactType): string[] {
44
+ const root = path.join(prodoPath(cwd), "templates");
45
+ return templateExtensionsForArtifact(artifactType).map((ext) => path.join(root, `${artifactType}.${ext}`));
46
+ }
47
+
48
+ export function overrideTemplateCandidatePaths(cwd: string, artifactType: ArtifactType): string[] {
49
+ const root = path.join(prodoPath(cwd), "templates", "overrides");
50
+ return templateExtensionsForArtifact(artifactType).map((ext) => path.join(root, `${artifactType}.${ext}`));
51
+ }
52
+
53
+ export function schemaPath(cwd: string, artifactType: ArtifactType): string {
54
+ return path.join(prodoPath(cwd), "schemas", `${artifactType}.yaml`);
55
+ }
56
+
57
+ export function outputDirPath(cwd: string, artifactType: ArtifactType, outputDirOverride?: string): string {
58
+ return path.join(cwd, "product-docs", outputDirOverride ?? defaultOutputDir(artifactType));
59
+ }
60
+
61
+ export function reportPath(cwd: string): string {
62
+ return path.join(cwd, "product-docs", "reports", "latest-validation.md");
63
+ }
64
+
65
+ export function outputIndexPath(cwd: string): string {
66
+ return path.join(prodoPath(cwd), "state", "index.json");
67
+ }
68
+
69
+ export function outputContextDirPath(cwd: string): string {
70
+ return path.join(prodoPath(cwd), "state", "context");
71
+ }
72
+
73
+ export function normHistoryPath(cwd: string): string {
74
+ return path.join(prodoPath(cwd), "_norm_history.json");
75
+ }
72
76
 
@@ -1,78 +1,78 @@
1
- import fs from "node:fs/promises";
2
- import path from "node:path";
3
- import type { ContractCoverage } from "./types";
4
- import { UserError } from "./errors";
5
- import { fileExists } from "./utils";
6
-
7
- export type ArtifactConfig = {
8
- name: string;
9
- output_dir?: string;
10
- required_headings?: string[];
11
- upstream?: string[];
12
- required_contracts?: Array<keyof ContractCoverage>;
13
- };
14
-
15
- export type ProdoProjectConfig = {
16
- presets?: string[];
17
- artifacts?: ArtifactConfig[];
18
- command_packs?: string[];
19
- };
20
-
21
- function sanitizeStringArray(value: unknown): string[] {
22
- if (!Array.isArray(value)) return [];
23
- return value
24
- .filter((item): item is string => typeof item === "string")
25
- .map((item) => item.trim())
26
- .filter((item) => item.length > 0);
27
- }
28
-
29
- function sanitizeArtifact(raw: unknown): ArtifactConfig | null {
30
- if (!raw || typeof raw !== "object") return null;
31
- const rec = raw as Record<string, unknown>;
32
- const name = typeof rec.name === "string" ? rec.name.trim() : "";
33
- if (!name) return null;
34
- const outputDir = typeof rec.output_dir === "string" ? rec.output_dir.trim() : undefined;
35
- const requiredHeadings = sanitizeStringArray(rec.required_headings);
36
- const upstream = sanitizeStringArray(rec.upstream);
37
- const requiredContracts = sanitizeStringArray(rec.required_contracts)
38
- .filter((value): value is keyof ContractCoverage =>
39
- value === "goals" || value === "core_features" || value === "constraints");
40
- return {
41
- name,
42
- ...(outputDir ? { output_dir: outputDir } : {}),
43
- ...(requiredHeadings.length > 0 ? { required_headings: requiredHeadings } : {}),
44
- ...(upstream.length > 0 ? { upstream } : {}),
45
- ...(requiredContracts.length > 0 ? { required_contracts: requiredContracts } : {})
46
- };
47
- }
48
-
49
- function sanitizeConfig(raw: unknown): ProdoProjectConfig {
50
- if (!raw || typeof raw !== "object") return {};
51
- const rec = raw as Record<string, unknown>;
52
- const artifacts = Array.isArray(rec.artifacts)
53
- ? rec.artifacts.map(sanitizeArtifact).filter((item): item is ArtifactConfig => item !== null)
54
- : [];
55
- return {
56
- presets: sanitizeStringArray(rec.presets),
57
- command_packs: sanitizeStringArray(rec.command_packs),
58
- ...(artifacts.length > 0 ? { artifacts } : {})
59
- };
60
- }
61
-
62
- export async function readProjectConfig(cwd: string): Promise<ProdoProjectConfig> {
63
- const candidates = [
64
- path.join(cwd, ".prodo", "config.json"),
65
- path.join(cwd, "prodo.config.json")
66
- ];
67
- for (const candidate of candidates) {
68
- if (!(await fileExists(candidate))) continue;
69
- try {
70
- const parsed = JSON.parse(await fs.readFile(candidate, "utf8")) as unknown;
71
- return sanitizeConfig(parsed);
72
- } catch {
73
- throw new UserError(`Invalid project config JSON: ${candidate}`);
74
- }
75
- }
76
- return {};
77
- }
78
-
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import type { ContractCoverage } from "./types";
4
+ import { UserError } from "./errors";
5
+ import { fileExists } from "./utils";
6
+
7
+ export type ArtifactConfig = {
8
+ name: string;
9
+ output_dir?: string;
10
+ required_headings?: string[];
11
+ upstream?: string[];
12
+ required_contracts?: Array<keyof ContractCoverage>;
13
+ };
14
+
15
+ export type ProdoProjectConfig = {
16
+ presets?: string[];
17
+ artifacts?: ArtifactConfig[];
18
+ command_packs?: string[];
19
+ };
20
+
21
+ function sanitizeStringArray(value: unknown): string[] {
22
+ if (!Array.isArray(value)) return [];
23
+ return value
24
+ .filter((item): item is string => typeof item === "string")
25
+ .map((item) => item.trim())
26
+ .filter((item) => item.length > 0);
27
+ }
28
+
29
+ function sanitizeArtifact(raw: unknown): ArtifactConfig | null {
30
+ if (!raw || typeof raw !== "object") return null;
31
+ const rec = raw as Record<string, unknown>;
32
+ const name = typeof rec.name === "string" ? rec.name.trim() : "";
33
+ if (!name) return null;
34
+ const outputDir = typeof rec.output_dir === "string" ? rec.output_dir.trim() : undefined;
35
+ const requiredHeadings = sanitizeStringArray(rec.required_headings);
36
+ const upstream = sanitizeStringArray(rec.upstream);
37
+ const requiredContracts = sanitizeStringArray(rec.required_contracts)
38
+ .filter((value): value is keyof ContractCoverage =>
39
+ value === "goals" || value === "core_features" || value === "constraints");
40
+ return {
41
+ name,
42
+ ...(outputDir ? { output_dir: outputDir } : {}),
43
+ ...(requiredHeadings.length > 0 ? { required_headings: requiredHeadings } : {}),
44
+ ...(upstream.length > 0 ? { upstream } : {}),
45
+ ...(requiredContracts.length > 0 ? { required_contracts: requiredContracts } : {})
46
+ };
47
+ }
48
+
49
+ function sanitizeConfig(raw: unknown): ProdoProjectConfig {
50
+ if (!raw || typeof raw !== "object") return {};
51
+ const rec = raw as Record<string, unknown>;
52
+ const artifacts = Array.isArray(rec.artifacts)
53
+ ? rec.artifacts.map(sanitizeArtifact).filter((item): item is ArtifactConfig => item !== null)
54
+ : [];
55
+ return {
56
+ presets: sanitizeStringArray(rec.presets),
57
+ command_packs: sanitizeStringArray(rec.command_packs),
58
+ ...(artifacts.length > 0 ? { artifacts } : {})
59
+ };
60
+ }
61
+
62
+ export async function readProjectConfig(cwd: string): Promise<ProdoProjectConfig> {
63
+ const candidates = [
64
+ path.join(cwd, ".prodo", "config.json"),
65
+ path.join(cwd, "prodo.config.json")
66
+ ];
67
+ for (const candidate of candidates) {
68
+ if (!(await fileExists(candidate))) continue;
69
+ try {
70
+ const parsed = JSON.parse(await fs.readFile(candidate, "utf8")) as unknown;
71
+ return sanitizeConfig(parsed);
72
+ } catch {
73
+ throw new UserError(`Invalid project config JSON: ${candidate}`);
74
+ }
75
+ }
76
+ return {};
77
+ }
78
+
@@ -1,119 +1,119 @@
1
- import fs from "node:fs/promises";
2
- import path from "node:path";
3
- import { createHash } from "node:crypto";
4
- import { registryPath } from "./paths";
5
- import { ensureDir, fileExists } from "./utils";
6
-
7
- export type OverrideRegistryEntry = {
8
- artifact_type: string;
9
- file: string;
10
- sha256: string;
11
- };
12
-
13
- export type ProdoRegistry = {
14
- schema_version: "1.0";
15
- updated_at: string;
16
- installed_presets: string[];
17
- installed_overrides: OverrideRegistryEntry[];
18
- };
19
-
20
- const EMPTY_REGISTRY: ProdoRegistry = {
21
- schema_version: "1.0",
22
- updated_at: new Date(0).toISOString(),
23
- installed_presets: [],
24
- installed_overrides: []
25
- };
26
-
27
- async function sha256(filePath: string): Promise<string> {
28
- const raw = await fs.readFile(filePath);
29
- return createHash("sha256").update(raw).digest("hex");
30
- }
31
-
32
- function sanitizeRegistry(input: unknown): ProdoRegistry {
33
- if (!input || typeof input !== "object") return { ...EMPTY_REGISTRY };
34
- const raw = input as Record<string, unknown>;
35
- const installedPresets = Array.isArray(raw.installed_presets)
36
- ? raw.installed_presets
37
- .filter((value): value is string => typeof value === "string")
38
- .map((value) => value.trim())
39
- .filter((value) => value.length > 0)
40
- : [];
41
- const installedOverrides = Array.isArray(raw.installed_overrides)
42
- ? raw.installed_overrides
43
- .filter((item): item is Record<string, unknown> => !!item && typeof item === "object")
44
- .map((item) => ({
45
- artifact_type: typeof item.artifact_type === "string" ? item.artifact_type.trim() : "",
46
- file: typeof item.file === "string" ? item.file.trim() : "",
47
- sha256: typeof item.sha256 === "string" ? item.sha256.trim() : ""
48
- }))
49
- .filter((item) => item.artifact_type && item.file && item.sha256)
50
- : [];
51
- return {
52
- schema_version: "1.0",
53
- updated_at: typeof raw.updated_at === "string" && raw.updated_at.trim() ? raw.updated_at : EMPTY_REGISTRY.updated_at,
54
- installed_presets: Array.from(new Set(installedPresets)),
55
- installed_overrides: installedOverrides
56
- };
57
- }
58
-
59
- export async function readRegistry(cwd: string): Promise<ProdoRegistry> {
60
- const file = registryPath(cwd);
61
- if (!(await fileExists(file))) return { ...EMPTY_REGISTRY };
62
- try {
63
- const parsed = JSON.parse(await fs.readFile(file, "utf8")) as unknown;
64
- return sanitizeRegistry(parsed);
65
- } catch {
66
- return { ...EMPTY_REGISTRY };
67
- }
68
- }
69
-
70
- async function readInstalledPresetsFromFile(cwd: string): Promise<string[]> {
71
- const file = path.join(cwd, ".prodo", "presets", "installed.json");
72
- if (!(await fileExists(file))) return [];
73
- try {
74
- const parsed = JSON.parse(await fs.readFile(file, "utf8")) as unknown;
75
- if (!Array.isArray(parsed)) return [];
76
- return parsed
77
- .filter((value): value is string => typeof value === "string")
78
- .map((value) => value.trim())
79
- .filter((value) => value.length > 0);
80
- } catch {
81
- return [];
82
- }
83
- }
84
-
85
- async function discoverOverrides(cwd: string): Promise<OverrideRegistryEntry[]> {
86
- const overridesDir = path.join(cwd, ".prodo", "templates", "overrides");
87
- if (!(await fileExists(overridesDir))) return [];
88
- const entries = await fs.readdir(overridesDir, { withFileTypes: true });
89
- const out: OverrideRegistryEntry[] = [];
90
- for (const entry of entries) {
91
- if (!entry.isFile()) continue;
92
- if (!entry.name.endsWith(".md")) continue;
93
- const fullPath = path.join(overridesDir, entry.name);
94
- out.push({
95
- artifact_type: entry.name.replace(/\.md$/, ""),
96
- file: fullPath,
97
- sha256: await sha256(fullPath)
98
- });
99
- }
100
- out.sort((a, b) => a.artifact_type.localeCompare(b.artifact_type));
101
- return out;
102
- }
103
-
104
- export async function syncRegistry(cwd: string): Promise<ProdoRegistry> {
105
- const existing = await readRegistry(cwd);
106
- const discoveredPresets = await readInstalledPresetsFromFile(cwd);
107
- const discoveredOverrides = await discoverOverrides(cwd);
108
- const mergedPresets = Array.from(new Set([...existing.installed_presets, ...discoveredPresets])).sort();
109
- const merged: ProdoRegistry = {
110
- schema_version: "1.0",
111
- updated_at: new Date().toISOString(),
112
- installed_presets: mergedPresets,
113
- installed_overrides: discoveredOverrides
114
- };
115
- const file = registryPath(cwd);
116
- await ensureDir(path.dirname(file));
117
- await fs.writeFile(file, `${JSON.stringify(merged, null, 2)}\n`, "utf8");
118
- return merged;
119
- }
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { createHash } from "node:crypto";
4
+ import { registryPath } from "./paths";
5
+ import { ensureDir, fileExists } from "./utils";
6
+
7
+ export type OverrideRegistryEntry = {
8
+ artifact_type: string;
9
+ file: string;
10
+ sha256: string;
11
+ };
12
+
13
+ export type ProdoRegistry = {
14
+ schema_version: "1.0";
15
+ updated_at: string;
16
+ installed_presets: string[];
17
+ installed_overrides: OverrideRegistryEntry[];
18
+ };
19
+
20
+ const EMPTY_REGISTRY: ProdoRegistry = {
21
+ schema_version: "1.0",
22
+ updated_at: new Date(0).toISOString(),
23
+ installed_presets: [],
24
+ installed_overrides: []
25
+ };
26
+
27
+ async function sha256(filePath: string): Promise<string> {
28
+ const raw = await fs.readFile(filePath);
29
+ return createHash("sha256").update(raw).digest("hex");
30
+ }
31
+
32
+ function sanitizeRegistry(input: unknown): ProdoRegistry {
33
+ if (!input || typeof input !== "object") return { ...EMPTY_REGISTRY };
34
+ const raw = input as Record<string, unknown>;
35
+ const installedPresets = Array.isArray(raw.installed_presets)
36
+ ? raw.installed_presets
37
+ .filter((value): value is string => typeof value === "string")
38
+ .map((value) => value.trim())
39
+ .filter((value) => value.length > 0)
40
+ : [];
41
+ const installedOverrides = Array.isArray(raw.installed_overrides)
42
+ ? raw.installed_overrides
43
+ .filter((item): item is Record<string, unknown> => !!item && typeof item === "object")
44
+ .map((item) => ({
45
+ artifact_type: typeof item.artifact_type === "string" ? item.artifact_type.trim() : "",
46
+ file: typeof item.file === "string" ? item.file.trim() : "",
47
+ sha256: typeof item.sha256 === "string" ? item.sha256.trim() : ""
48
+ }))
49
+ .filter((item) => item.artifact_type && item.file && item.sha256)
50
+ : [];
51
+ return {
52
+ schema_version: "1.0",
53
+ updated_at: typeof raw.updated_at === "string" && raw.updated_at.trim() ? raw.updated_at : EMPTY_REGISTRY.updated_at,
54
+ installed_presets: Array.from(new Set(installedPresets)),
55
+ installed_overrides: installedOverrides
56
+ };
57
+ }
58
+
59
+ export async function readRegistry(cwd: string): Promise<ProdoRegistry> {
60
+ const file = registryPath(cwd);
61
+ if (!(await fileExists(file))) return { ...EMPTY_REGISTRY };
62
+ try {
63
+ const parsed = JSON.parse(await fs.readFile(file, "utf8")) as unknown;
64
+ return sanitizeRegistry(parsed);
65
+ } catch {
66
+ return { ...EMPTY_REGISTRY };
67
+ }
68
+ }
69
+
70
+ async function readInstalledPresetsFromFile(cwd: string): Promise<string[]> {
71
+ const file = path.join(cwd, ".prodo", "presets", "installed.json");
72
+ if (!(await fileExists(file))) return [];
73
+ try {
74
+ const parsed = JSON.parse(await fs.readFile(file, "utf8")) as unknown;
75
+ if (!Array.isArray(parsed)) return [];
76
+ return parsed
77
+ .filter((value): value is string => typeof value === "string")
78
+ .map((value) => value.trim())
79
+ .filter((value) => value.length > 0);
80
+ } catch {
81
+ return [];
82
+ }
83
+ }
84
+
85
+ async function discoverOverrides(cwd: string): Promise<OverrideRegistryEntry[]> {
86
+ const overridesDir = path.join(cwd, ".prodo", "templates", "overrides");
87
+ if (!(await fileExists(overridesDir))) return [];
88
+ const entries = await fs.readdir(overridesDir, { withFileTypes: true });
89
+ const out: OverrideRegistryEntry[] = [];
90
+ for (const entry of entries) {
91
+ if (!entry.isFile()) continue;
92
+ if (!entry.name.endsWith(".md")) continue;
93
+ const fullPath = path.join(overridesDir, entry.name);
94
+ out.push({
95
+ artifact_type: entry.name.replace(/\.md$/, ""),
96
+ file: fullPath,
97
+ sha256: await sha256(fullPath)
98
+ });
99
+ }
100
+ out.sort((a, b) => a.artifact_type.localeCompare(b.artifact_type));
101
+ return out;
102
+ }
103
+
104
+ export async function syncRegistry(cwd: string): Promise<ProdoRegistry> {
105
+ const existing = await readRegistry(cwd);
106
+ const discoveredPresets = await readInstalledPresetsFromFile(cwd);
107
+ const discoveredOverrides = await discoverOverrides(cwd);
108
+ const mergedPresets = Array.from(new Set([...existing.installed_presets, ...discoveredPresets])).sort();
109
+ const merged: ProdoRegistry = {
110
+ schema_version: "1.0",
111
+ updated_at: new Date().toISOString(),
112
+ installed_presets: mergedPresets,
113
+ installed_overrides: discoveredOverrides
114
+ };
115
+ const file = registryPath(cwd);
116
+ await ensureDir(path.dirname(file));
117
+ await fs.writeFile(file, `${JSON.stringify(merged, null, 2)}\n`, "utf8");
118
+ return merged;
119
+ }