@shahmarasy/prodo 0.1.4 → 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.
- package/README.md +201 -97
- package/bin/prodo.cjs +6 -6
- package/dist/agents/agent-registry.d.ts +13 -0
- package/dist/agents/agent-registry.js +79 -0
- package/dist/agents/anthropic/index.d.ts +9 -0
- package/dist/agents/anthropic/index.js +55 -0
- package/dist/agents/base.d.ts +25 -0
- package/dist/agents/base.js +71 -0
- package/dist/agents/google/index.d.ts +9 -0
- package/dist/agents/google/index.js +53 -0
- package/dist/agents/mock/index.d.ts +11 -0
- package/dist/agents/mock/index.js +26 -0
- package/dist/agents/openai/index.d.ts +9 -0
- package/dist/agents/openai/index.js +57 -0
- package/dist/agents/system-prompts.d.ts +3 -0
- package/dist/agents/system-prompts.js +32 -0
- package/dist/cli/agent-command-installer.d.ts +4 -0
- package/dist/cli/agent-command-installer.js +148 -0
- package/dist/cli/agent-ids.d.ts +15 -0
- package/dist/cli/agent-ids.js +49 -0
- package/dist/cli/doctor.d.ts +1 -0
- package/dist/cli/doctor.js +144 -0
- package/dist/cli/fix-tui.d.ts +4 -0
- package/dist/cli/fix-tui.js +79 -0
- package/dist/cli/index.d.ts +9 -0
- package/dist/cli/index.js +465 -0
- package/dist/cli/init-tui.d.ts +23 -0
- package/dist/cli/init-tui.js +176 -0
- package/dist/cli/init.d.ts +11 -0
- package/dist/cli/init.js +334 -0
- package/dist/cli/normalize-interactive.d.ts +8 -0
- package/dist/cli/normalize-interactive.js +167 -0
- package/dist/cli/preset-loader.d.ts +4 -0
- package/dist/cli/preset-loader.js +210 -0
- package/dist/core/artifact-registry.d.ts +11 -0
- package/dist/core/artifact-registry.js +49 -0
- package/dist/core/artifacts.d.ts +10 -0
- package/dist/core/artifacts.js +892 -0
- package/dist/core/clean.d.ts +10 -0
- package/dist/core/clean.js +74 -0
- package/dist/core/consistency.d.ts +8 -0
- package/dist/core/consistency.js +328 -0
- package/dist/core/constants.d.ts +7 -0
- package/dist/core/constants.js +64 -0
- package/dist/core/errors.d.ts +3 -0
- package/dist/core/errors.js +10 -0
- package/dist/core/fix.d.ts +31 -0
- package/dist/core/fix.js +188 -0
- package/dist/core/hook-executor.d.ts +1 -0
- package/dist/core/hook-executor.js +175 -0
- package/dist/core/markdown.d.ts +16 -0
- package/dist/core/markdown.js +81 -0
- package/dist/core/normalize.d.ts +8 -0
- package/dist/core/normalize.js +125 -0
- package/dist/core/normalized-brief.d.ts +48 -0
- package/dist/core/normalized-brief.js +182 -0
- package/dist/core/output-index.d.ts +13 -0
- package/dist/core/output-index.js +55 -0
- package/dist/core/paths.d.ts +17 -0
- package/dist/core/paths.js +80 -0
- package/dist/core/project-config.d.ts +14 -0
- package/dist/core/project-config.js +69 -0
- package/dist/core/registry.d.ts +13 -0
- package/dist/core/registry.js +115 -0
- package/dist/core/settings.d.ts +7 -0
- package/dist/core/settings.js +35 -0
- package/dist/core/template-engine.d.ts +3 -0
- package/dist/core/template-engine.js +43 -0
- package/dist/core/template-resolver.d.ts +15 -0
- package/dist/core/template-resolver.js +46 -0
- package/dist/core/templates.d.ts +33 -0
- package/dist/core/templates.js +440 -0
- package/dist/core/terminology.d.ts +21 -0
- package/dist/core/terminology.js +143 -0
- package/dist/core/tracing.d.ts +21 -0
- package/dist/core/tracing.js +74 -0
- package/dist/core/types.d.ts +35 -0
- package/dist/core/types.js +5 -0
- package/dist/core/utils.d.ts +7 -0
- package/dist/core/utils.js +66 -0
- package/dist/core/validate.d.ts +10 -0
- package/dist/core/validate.js +226 -0
- package/dist/core/validator.d.ts +5 -0
- package/dist/core/validator.js +76 -0
- package/dist/core/version.d.ts +1 -0
- package/dist/core/version.js +30 -0
- package/dist/core/workflow-commands.d.ts +7 -0
- package/dist/core/workflow-commands.js +29 -0
- package/dist/i18n/en.json +45 -0
- package/dist/i18n/index.d.ts +5 -0
- package/dist/i18n/index.js +63 -0
- package/dist/i18n/tr.json +45 -0
- package/dist/providers/index.d.ts +2 -1
- package/dist/providers/index.js +20 -6
- package/dist/providers/mock-provider.d.ts +1 -1
- package/dist/providers/mock-provider.js +7 -6
- package/dist/providers/openai-provider.d.ts +1 -1
- package/dist/providers/openai-provider.js +1 -1
- package/dist/skills/engine.d.ts +10 -0
- package/dist/skills/engine.js +75 -0
- package/dist/skills/fix-skill.d.ts +2 -0
- package/dist/skills/fix-skill.js +38 -0
- package/dist/skills/generate-artifact-skill.d.ts +2 -0
- package/dist/skills/generate-artifact-skill.js +32 -0
- package/dist/skills/generate-pipeline-skill.d.ts +2 -0
- package/dist/skills/generate-pipeline-skill.js +45 -0
- package/dist/skills/normalize-skill.d.ts +2 -0
- package/dist/skills/normalize-skill.js +29 -0
- package/dist/skills/types.d.ts +28 -0
- package/dist/skills/types.js +2 -0
- package/dist/skills/validate-skill.d.ts +2 -0
- package/dist/skills/validate-skill.js +29 -0
- package/package.json +74 -45
- package/src/agents/agent-registry.ts +93 -0
- package/src/agents/anthropic/index.ts +86 -0
- package/src/agents/anthropic/manifest.json +7 -0
- package/src/agents/base.ts +77 -0
- package/src/agents/google/index.ts +79 -0
- package/src/agents/google/manifest.json +7 -0
- package/src/agents/mock/index.ts +32 -0
- package/src/agents/mock/manifest.json +7 -0
- package/src/agents/openai/index.ts +83 -0
- package/src/agents/openai/manifest.json +7 -0
- package/src/agents/system-prompts.ts +35 -0
- package/src/{agent-command-installer.ts → cli/agent-command-installer.ts} +164 -164
- package/src/{agents.ts → cli/agent-ids.ts} +58 -58
- package/src/{doctor.ts → cli/doctor.ts} +157 -137
- package/src/cli/fix-tui.ts +111 -0
- package/src/{cli.ts → cli/index.ts} +459 -410
- package/src/{init-tui.ts → cli/init-tui.ts} +208 -208
- package/src/{init.ts → cli/init.ts} +398 -398
- package/src/cli/normalize-interactive.ts +241 -0
- package/src/{preset-loader.ts → cli/preset-loader.ts} +237 -237
- package/src/{artifact-registry.ts → core/artifact-registry.ts} +69 -69
- package/src/{artifacts.ts → core/artifacts.ts} +1081 -1072
- package/src/core/clean.ts +88 -0
- package/src/{consistency.ts → core/consistency.ts} +374 -303
- package/src/{constants.ts → core/constants.ts} +72 -72
- package/src/{errors.ts → core/errors.ts} +7 -7
- package/src/core/fix.ts +253 -0
- package/src/{hook-executor.ts → core/hook-executor.ts} +196 -196
- package/src/{markdown.ts → core/markdown.ts} +93 -73
- package/src/{normalize.ts → core/normalize.ts} +145 -137
- package/src/{normalized-brief.ts → core/normalized-brief.ts} +227 -206
- package/src/{output-index.ts → core/output-index.ts} +59 -59
- package/src/{paths.ts → core/paths.ts} +75 -71
- package/src/{project-config.ts → core/project-config.ts} +78 -78
- package/src/{registry.ts → core/registry.ts} +119 -119
- package/src/{settings.ts → core/settings.ts} +35 -35
- package/src/core/template-engine.ts +45 -0
- package/src/{template-resolver.ts → core/template-resolver.ts} +54 -54
- package/src/{templates.ts → core/templates.ts} +452 -452
- package/src/core/terminology.ts +177 -0
- package/src/core/tracing.ts +110 -0
- package/src/{types.ts → core/types.ts} +46 -46
- package/src/{utils.ts → core/utils.ts} +64 -64
- package/src/{validate.ts → core/validate.ts} +252 -246
- package/src/{validator.ts → core/validator.ts} +92 -92
- package/src/{version.ts → core/version.ts} +24 -24
- package/src/{workflow-commands.ts → core/workflow-commands.ts} +32 -32
- package/src/i18n/en.json +45 -0
- package/src/i18n/index.ts +58 -0
- package/src/i18n/tr.json +45 -0
- package/src/providers/index.ts +29 -12
- package/src/providers/mock-provider.ts +200 -199
- package/src/providers/openai-provider.ts +88 -88
- package/src/skills/engine.ts +94 -0
- package/src/skills/fix-skill.ts +38 -0
- package/src/skills/generate-artifact-skill.ts +32 -0
- package/src/skills/generate-pipeline-skill.ts +49 -0
- package/src/skills/normalize-skill.ts +29 -0
- package/src/skills/types.ts +36 -0
- package/src/skills/validate-skill.ts +29 -0
|
@@ -1,206 +1,227 @@
|
|
|
1
|
-
import Ajv2020 from "ajv/dist/2020";
|
|
2
|
-
import { UserError } from "./errors";
|
|
3
|
-
import type { ValidationIssue } from "./types";
|
|
4
|
-
|
|
5
|
-
export type BriefContractItem = {
|
|
6
|
-
id: string;
|
|
7
|
-
text: string;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export type NormalizedBrief = {
|
|
11
|
-
schema_version: string;
|
|
12
|
-
product_name: string;
|
|
13
|
-
problem: string;
|
|
14
|
-
audience: string[];
|
|
15
|
-
goals: string[];
|
|
16
|
-
core_features: string[];
|
|
17
|
-
constraints: string[];
|
|
18
|
-
assumptions: string[];
|
|
19
|
-
contracts: {
|
|
20
|
-
goals: BriefContractItem[];
|
|
21
|
-
core_features: BriefContractItem[];
|
|
22
|
-
constraints: BriefContractItem[];
|
|
23
|
-
};
|
|
24
|
-
confidence?: Record<string, number>;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
type BriefContracts = NormalizedBrief["contracts"];
|
|
28
|
-
|
|
29
|
-
const schema: Record<string, unknown> = {
|
|
30
|
-
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
31
|
-
type: "object",
|
|
32
|
-
required: [
|
|
33
|
-
"schema_version",
|
|
34
|
-
"product_name",
|
|
35
|
-
"problem",
|
|
36
|
-
"audience",
|
|
37
|
-
"goals",
|
|
38
|
-
"core_features",
|
|
39
|
-
"constraints",
|
|
40
|
-
"assumptions",
|
|
41
|
-
"contracts"
|
|
42
|
-
],
|
|
43
|
-
properties: {
|
|
44
|
-
schema_version: { type: "string", minLength: 1 },
|
|
45
|
-
product_name: { type: "string", minLength: 2 },
|
|
46
|
-
problem: { type: "string", minLength: 10 },
|
|
47
|
-
audience: { type: "array", minItems: 1, items: { type: "string", minLength: 2 } },
|
|
48
|
-
goals: { type: "array", minItems: 1, items: { type: "string", minLength: 2 } },
|
|
49
|
-
core_features: { type: "array", minItems: 1, items: { type: "string", minLength: 2 } },
|
|
50
|
-
constraints: { type: "array", items: { type: "string", minLength: 2 } },
|
|
51
|
-
assumptions: { type: "array", items: { type: "string", minLength: 2 } },
|
|
52
|
-
contracts: {
|
|
53
|
-
type: "object",
|
|
54
|
-
required: ["goals", "core_features", "constraints"],
|
|
55
|
-
properties: {
|
|
56
|
-
goals: { $ref: "#/$defs/contractArray" },
|
|
57
|
-
core_features: { $ref: "#/$defs/contractArray" },
|
|
58
|
-
constraints: { $ref: "#/$defs/contractArray" }
|
|
59
|
-
},
|
|
60
|
-
additionalProperties: false
|
|
61
|
-
},
|
|
62
|
-
confidence: {
|
|
63
|
-
type: "object",
|
|
64
|
-
additionalProperties: { type: "number", minimum: 0, maximum: 1 }
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
$defs: {
|
|
68
|
-
contractItem: {
|
|
69
|
-
type: "object",
|
|
70
|
-
required: ["id", "text"],
|
|
71
|
-
properties: {
|
|
72
|
-
id: { type: "string", pattern: "^[A-Z]+[0-9]+$" },
|
|
73
|
-
text: { type: "string", minLength: 2 }
|
|
74
|
-
},
|
|
75
|
-
additionalProperties: false
|
|
76
|
-
},
|
|
77
|
-
contractArray: { type: "array", items: { $ref: "#/$defs/contractItem" } }
|
|
78
|
-
},
|
|
79
|
-
additionalProperties: false
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const ajv = new Ajv2020({ allErrors: true, strict: false });
|
|
83
|
-
const validateFn = ajv.compile(schema);
|
|
84
|
-
|
|
85
|
-
function asString(value: unknown): string | undefined {
|
|
86
|
-
if (typeof value !== "string") return undefined;
|
|
87
|
-
const trimmed = value.trim();
|
|
88
|
-
return trimmed.length > 0 ? trimmed : undefined;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function asStringArray(value: unknown): string[] {
|
|
92
|
-
if (!Array.isArray(value)) return [];
|
|
93
|
-
return value
|
|
94
|
-
.map((item) => asString(item))
|
|
95
|
-
.filter((item): item is string => typeof item === "string");
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function asContracts(value: unknown): BriefContractItem[] {
|
|
99
|
-
if (!Array.isArray(value)) return [];
|
|
100
|
-
return value
|
|
101
|
-
.map((item) => {
|
|
102
|
-
if (!item || typeof item !== "object") return null;
|
|
103
|
-
const record = item as Record<string, unknown>;
|
|
104
|
-
const id = asString(record.id);
|
|
105
|
-
const text = asString(record.text);
|
|
106
|
-
if (!id || !text) return null;
|
|
107
|
-
return { id, text };
|
|
108
|
-
})
|
|
109
|
-
.filter((item): item is BriefContractItem => item !== null);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function asConfidence(value: unknown): Record<string, number> | undefined {
|
|
113
|
-
if (!value || typeof value !== "object") return undefined;
|
|
114
|
-
const result: Record<string, number> = {};
|
|
115
|
-
for (const [key, raw] of Object.entries(value as Record<string, unknown>)) {
|
|
116
|
-
if (typeof raw !== "number" || Number.isNaN(raw)) continue;
|
|
117
|
-
result[key] = raw;
|
|
118
|
-
}
|
|
119
|
-
return Object.keys(result).length > 0 ? result : undefined;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function normalizeInput(input: Record<string, unknown>): NormalizedBrief {
|
|
123
|
-
const rawContracts = (input.contracts as Record<string, unknown> | undefined) ?? {};
|
|
124
|
-
return {
|
|
125
|
-
schema_version: asString(input.schema_version) ?? "1.0",
|
|
126
|
-
product_name: asString(input.product_name) ?? "",
|
|
127
|
-
problem: asString(input.problem) ?? "",
|
|
128
|
-
audience: asStringArray(input.audience),
|
|
129
|
-
goals: asStringArray(input.goals),
|
|
130
|
-
core_features: asStringArray(input.core_features),
|
|
131
|
-
constraints: asStringArray(input.constraints),
|
|
132
|
-
assumptions: asStringArray(input.assumptions),
|
|
133
|
-
contracts: {
|
|
134
|
-
goals: asContracts(rawContracts.goals),
|
|
135
|
-
core_features: asContracts(rawContracts.core_features),
|
|
136
|
-
constraints: asContracts(rawContracts.constraints)
|
|
137
|
-
},
|
|
138
|
-
confidence: asConfidence(input.confidence)
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export function buildContractsFromArrays(input: {
|
|
143
|
-
goals: string[];
|
|
144
|
-
core_features: string[];
|
|
145
|
-
constraints: string[];
|
|
146
|
-
}): BriefContracts {
|
|
147
|
-
return {
|
|
148
|
-
goals: input.goals.map((text, index) => ({ id: `G${index + 1}`, text })),
|
|
149
|
-
core_features: input.core_features.map((text, index) => ({ id: `F${index + 1}`, text })),
|
|
150
|
-
constraints: input.constraints.map((text, index) => ({ id: `C${index + 1}`, text }))
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export function parseNormalizedBrief(input: Record<string, unknown>): {
|
|
155
|
-
brief: NormalizedBrief;
|
|
156
|
-
issues: ValidationIssue[];
|
|
157
|
-
} {
|
|
158
|
-
const normalized = normalizeInput(input);
|
|
159
|
-
const valid = validateFn(normalized);
|
|
160
|
-
if (valid) return { brief: normalized, issues: [] };
|
|
161
|
-
const errors = validateFn.errors ?? [];
|
|
162
|
-
const issues = errors.map((error) => ({
|
|
163
|
-
level: "error" as const,
|
|
164
|
-
code: "normalized_brief_invalid",
|
|
165
|
-
check: "schema" as const,
|
|
166
|
-
field: error.instancePath || error.schemaPath,
|
|
167
|
-
message: `Normalized brief schema error: ${error.message ?? "unknown error"}`,
|
|
168
|
-
suggestion: "Fix missing content in start brief and rerun `prodo normalize`."
|
|
169
|
-
}));
|
|
170
|
-
return { brief: normalized, issues };
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export function parseNormalizedBriefOrThrow(input: Record<string, unknown>): NormalizedBrief {
|
|
174
|
-
const { brief, issues } = parseNormalizedBrief(input);
|
|
175
|
-
if (issues.length > 0) {
|
|
176
|
-
const detail = issues.map((issue) => `- ${issue.message}`).join("\n");
|
|
177
|
-
throw new UserError(`Normalized brief is invalid:\n${detail}`);
|
|
178
|
-
}
|
|
179
|
-
return brief;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export function requireConfidenceOrThrow(
|
|
183
|
-
brief: NormalizedBrief,
|
|
184
|
-
fields: Array<keyof Pick<NormalizedBrief, "product_name" | "problem" | "audience" | "goals" | "core_features">>,
|
|
185
|
-
threshold = 0.7
|
|
186
|
-
): void {
|
|
187
|
-
const confidence = brief.confidence ?? {};
|
|
188
|
-
const missing = fields.filter((field) => (confidence[field] ?? 0) < threshold);
|
|
189
|
-
if (missing.length > 0) {
|
|
190
|
-
throw new UserError(
|
|
191
|
-
`Normalization confidence too low for: ${missing.join(", ")}. Improve brief clarity and rerun \`prodo normalize\`.`
|
|
192
|
-
);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
export
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}
|
|
1
|
+
import Ajv2020 from "ajv/dist/2020";
|
|
2
|
+
import { UserError } from "./errors";
|
|
3
|
+
import type { ValidationIssue } from "./types";
|
|
4
|
+
|
|
5
|
+
export type BriefContractItem = {
|
|
6
|
+
id: string;
|
|
7
|
+
text: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type NormalizedBrief = {
|
|
11
|
+
schema_version: string;
|
|
12
|
+
product_name: string;
|
|
13
|
+
problem: string;
|
|
14
|
+
audience: string[];
|
|
15
|
+
goals: string[];
|
|
16
|
+
core_features: string[];
|
|
17
|
+
constraints: string[];
|
|
18
|
+
assumptions: string[];
|
|
19
|
+
contracts: {
|
|
20
|
+
goals: BriefContractItem[];
|
|
21
|
+
core_features: BriefContractItem[];
|
|
22
|
+
constraints: BriefContractItem[];
|
|
23
|
+
};
|
|
24
|
+
confidence?: Record<string, number>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
type BriefContracts = NormalizedBrief["contracts"];
|
|
28
|
+
|
|
29
|
+
const schema: Record<string, unknown> = {
|
|
30
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
31
|
+
type: "object",
|
|
32
|
+
required: [
|
|
33
|
+
"schema_version",
|
|
34
|
+
"product_name",
|
|
35
|
+
"problem",
|
|
36
|
+
"audience",
|
|
37
|
+
"goals",
|
|
38
|
+
"core_features",
|
|
39
|
+
"constraints",
|
|
40
|
+
"assumptions",
|
|
41
|
+
"contracts"
|
|
42
|
+
],
|
|
43
|
+
properties: {
|
|
44
|
+
schema_version: { type: "string", minLength: 1 },
|
|
45
|
+
product_name: { type: "string", minLength: 2 },
|
|
46
|
+
problem: { type: "string", minLength: 10 },
|
|
47
|
+
audience: { type: "array", minItems: 1, items: { type: "string", minLength: 2 } },
|
|
48
|
+
goals: { type: "array", minItems: 1, items: { type: "string", minLength: 2 } },
|
|
49
|
+
core_features: { type: "array", minItems: 1, items: { type: "string", minLength: 2 } },
|
|
50
|
+
constraints: { type: "array", items: { type: "string", minLength: 2 } },
|
|
51
|
+
assumptions: { type: "array", items: { type: "string", minLength: 2 } },
|
|
52
|
+
contracts: {
|
|
53
|
+
type: "object",
|
|
54
|
+
required: ["goals", "core_features", "constraints"],
|
|
55
|
+
properties: {
|
|
56
|
+
goals: { $ref: "#/$defs/contractArray" },
|
|
57
|
+
core_features: { $ref: "#/$defs/contractArray" },
|
|
58
|
+
constraints: { $ref: "#/$defs/contractArray" }
|
|
59
|
+
},
|
|
60
|
+
additionalProperties: false
|
|
61
|
+
},
|
|
62
|
+
confidence: {
|
|
63
|
+
type: "object",
|
|
64
|
+
additionalProperties: { type: "number", minimum: 0, maximum: 1 }
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
$defs: {
|
|
68
|
+
contractItem: {
|
|
69
|
+
type: "object",
|
|
70
|
+
required: ["id", "text"],
|
|
71
|
+
properties: {
|
|
72
|
+
id: { type: "string", pattern: "^[A-Z]+[0-9]+$" },
|
|
73
|
+
text: { type: "string", minLength: 2 }
|
|
74
|
+
},
|
|
75
|
+
additionalProperties: false
|
|
76
|
+
},
|
|
77
|
+
contractArray: { type: "array", items: { $ref: "#/$defs/contractItem" } }
|
|
78
|
+
},
|
|
79
|
+
additionalProperties: false
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const ajv = new Ajv2020({ allErrors: true, strict: false });
|
|
83
|
+
const validateFn = ajv.compile(schema);
|
|
84
|
+
|
|
85
|
+
function asString(value: unknown): string | undefined {
|
|
86
|
+
if (typeof value !== "string") return undefined;
|
|
87
|
+
const trimmed = value.trim();
|
|
88
|
+
return trimmed.length > 0 ? trimmed : undefined;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function asStringArray(value: unknown): string[] {
|
|
92
|
+
if (!Array.isArray(value)) return [];
|
|
93
|
+
return value
|
|
94
|
+
.map((item) => asString(item))
|
|
95
|
+
.filter((item): item is string => typeof item === "string");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function asContracts(value: unknown): BriefContractItem[] {
|
|
99
|
+
if (!Array.isArray(value)) return [];
|
|
100
|
+
return value
|
|
101
|
+
.map((item) => {
|
|
102
|
+
if (!item || typeof item !== "object") return null;
|
|
103
|
+
const record = item as Record<string, unknown>;
|
|
104
|
+
const id = asString(record.id);
|
|
105
|
+
const text = asString(record.text);
|
|
106
|
+
if (!id || !text) return null;
|
|
107
|
+
return { id, text };
|
|
108
|
+
})
|
|
109
|
+
.filter((item): item is BriefContractItem => item !== null);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function asConfidence(value: unknown): Record<string, number> | undefined {
|
|
113
|
+
if (!value || typeof value !== "object") return undefined;
|
|
114
|
+
const result: Record<string, number> = {};
|
|
115
|
+
for (const [key, raw] of Object.entries(value as Record<string, unknown>)) {
|
|
116
|
+
if (typeof raw !== "number" || Number.isNaN(raw)) continue;
|
|
117
|
+
result[key] = raw;
|
|
118
|
+
}
|
|
119
|
+
return Object.keys(result).length > 0 ? result : undefined;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function normalizeInput(input: Record<string, unknown>): NormalizedBrief {
|
|
123
|
+
const rawContracts = (input.contracts as Record<string, unknown> | undefined) ?? {};
|
|
124
|
+
return {
|
|
125
|
+
schema_version: asString(input.schema_version) ?? "1.0",
|
|
126
|
+
product_name: asString(input.product_name) ?? "",
|
|
127
|
+
problem: asString(input.problem) ?? "",
|
|
128
|
+
audience: asStringArray(input.audience),
|
|
129
|
+
goals: asStringArray(input.goals),
|
|
130
|
+
core_features: asStringArray(input.core_features),
|
|
131
|
+
constraints: asStringArray(input.constraints),
|
|
132
|
+
assumptions: asStringArray(input.assumptions),
|
|
133
|
+
contracts: {
|
|
134
|
+
goals: asContracts(rawContracts.goals),
|
|
135
|
+
core_features: asContracts(rawContracts.core_features),
|
|
136
|
+
constraints: asContracts(rawContracts.constraints)
|
|
137
|
+
},
|
|
138
|
+
confidence: asConfidence(input.confidence)
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function buildContractsFromArrays(input: {
|
|
143
|
+
goals: string[];
|
|
144
|
+
core_features: string[];
|
|
145
|
+
constraints: string[];
|
|
146
|
+
}): BriefContracts {
|
|
147
|
+
return {
|
|
148
|
+
goals: input.goals.map((text, index) => ({ id: `G${index + 1}`, text })),
|
|
149
|
+
core_features: input.core_features.map((text, index) => ({ id: `F${index + 1}`, text })),
|
|
150
|
+
constraints: input.constraints.map((text, index) => ({ id: `C${index + 1}`, text }))
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function parseNormalizedBrief(input: Record<string, unknown>): {
|
|
155
|
+
brief: NormalizedBrief;
|
|
156
|
+
issues: ValidationIssue[];
|
|
157
|
+
} {
|
|
158
|
+
const normalized = normalizeInput(input);
|
|
159
|
+
const valid = validateFn(normalized);
|
|
160
|
+
if (valid) return { brief: normalized, issues: [] };
|
|
161
|
+
const errors = validateFn.errors ?? [];
|
|
162
|
+
const issues = errors.map((error) => ({
|
|
163
|
+
level: "error" as const,
|
|
164
|
+
code: "normalized_brief_invalid",
|
|
165
|
+
check: "schema" as const,
|
|
166
|
+
field: error.instancePath || error.schemaPath,
|
|
167
|
+
message: `Normalized brief schema error: ${error.message ?? "unknown error"}`,
|
|
168
|
+
suggestion: "Fix missing content in start brief and rerun `prodo normalize`."
|
|
169
|
+
}));
|
|
170
|
+
return { brief: normalized, issues };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function parseNormalizedBriefOrThrow(input: Record<string, unknown>): NormalizedBrief {
|
|
174
|
+
const { brief, issues } = parseNormalizedBrief(input);
|
|
175
|
+
if (issues.length > 0) {
|
|
176
|
+
const detail = issues.map((issue) => `- ${issue.message}`).join("\n");
|
|
177
|
+
throw new UserError(`Normalized brief is invalid:\n${detail}`);
|
|
178
|
+
}
|
|
179
|
+
return brief;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function requireConfidenceOrThrow(
|
|
183
|
+
brief: NormalizedBrief,
|
|
184
|
+
fields: Array<keyof Pick<NormalizedBrief, "product_name" | "problem" | "audience" | "goals" | "core_features">>,
|
|
185
|
+
threshold = 0.7
|
|
186
|
+
): void {
|
|
187
|
+
const confidence = brief.confidence ?? {};
|
|
188
|
+
const missing = fields.filter((field) => (confidence[field] ?? 0) < threshold);
|
|
189
|
+
if (missing.length > 0) {
|
|
190
|
+
throw new UserError(
|
|
191
|
+
`Normalization confidence too low for: ${missing.join(", ")}. Improve brief clarity and rerun \`prodo normalize\`.`
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export type ConfidenceCheckResult = {
|
|
197
|
+
pass: boolean;
|
|
198
|
+
lowFields: Array<{ field: string; confidence: number; threshold: number }>;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
export function checkConfidence(
|
|
202
|
+
brief: NormalizedBrief,
|
|
203
|
+
fields: Array<keyof Pick<NormalizedBrief, "product_name" | "problem" | "audience" | "goals" | "core_features">>,
|
|
204
|
+
threshold = 0.7
|
|
205
|
+
): ConfidenceCheckResult {
|
|
206
|
+
const confidence = brief.confidence ?? {};
|
|
207
|
+
const lowFields = fields
|
|
208
|
+
.filter((field) => (confidence[field] ?? 0) < threshold)
|
|
209
|
+
.map((field) => ({
|
|
210
|
+
field,
|
|
211
|
+
confidence: confidence[field] ?? 0,
|
|
212
|
+
threshold
|
|
213
|
+
}));
|
|
214
|
+
return { pass: lowFields.length === 0, lowFields };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export function contractIds(contracts: BriefContracts): {
|
|
218
|
+
goals: string[];
|
|
219
|
+
core_features: string[];
|
|
220
|
+
constraints: string[];
|
|
221
|
+
} {
|
|
222
|
+
return {
|
|
223
|
+
goals: contracts.goals.map((item) => item.id),
|
|
224
|
+
core_features: contracts.core_features.map((item) => item.id),
|
|
225
|
+
constraints: contracts.constraints.map((item) => item.id)
|
|
226
|
+
};
|
|
227
|
+
}
|
|
@@ -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
|
+
|