feat: preserve grounded sector ideas through private investment dossiers in QA

This commit is contained in:
2026-11-15 20:31:57 +02:00
parent 25d18f51bb
commit 6e7dfdabd0
17 changed files with 882 additions and 36 deletions
+52 -8
View File
@@ -35,7 +35,24 @@ export type PreparationReport = {
swot: SwotDraft;
swot_review_required: boolean;
};
export type SectorAnalysisSnapshot = {
key: string;
title: string;
quote: string;
section: string;
source_sha256: string;
source_version: number;
source_date: string;
location_label: string | null;
location_precision: string;
href: string;
};
export type InvestorDossierReportInput = {
content_sources?: {
title: string;
source_url: string;
analyses?: SectorAnalysisSnapshot[];
}[];
supply_aggregates?: SupplyAggregate[];
case: { id: string; title: string; version: number };
context_opportunity: string | null;
@@ -332,6 +349,28 @@ export function createInvestorDossierReport(
origin = 'Registo guardado neste dossier',
classification = 'Preparação do investimento',
): DossierReportRow => ({ field, value, origin, classification });
const sectorEvidence = (input.content_sources ?? []).flatMap((source) =>
(source.analyses ?? []).flatMap((a) => [
row(
'Hipótese: ' + a.title,
a.quote,
`${source.title} — ${a.section}; ${source.source_url}; edição ${a.source_date}`,
'Hipótese; afirmação atribuída à fonte',
),
row(
'Âmbito territorial',
a.location_label ?? 'Âmbito da fonte; implantação por definir',
a.href,
a.location_precision,
),
row(
'Versão preservada',
`${a.source_version}; SHA256 ${a.source_sha256}`,
a.href,
'Rastreabilidade da evidência',
),
]),
);
const finance: DossierReportRow[] = [];
for (const result of input.results.filter(
(item) =>
@@ -656,21 +695,26 @@ export function createInvestorDossierReport(
},
{
id: 'market',
title: 'Análise SWOT',
title: sectorEvidence.length
? 'Mercado, evidências sectoriais e SWOT'
: 'Análise SWOT',
private: true,
paragraphs: swot?.rows.length
? [
`Objecto: ${swot.object_key}; âmbito: ${swot.scope ?? 'não indicado'}. ${preparation?.swot_review_required ? 'Revisão necessária.' : 'Revisão guardada.'}`,
]
: ['Análise SWOT ainda não produzida neste âmbito.'],
rows: (swot?.rows ?? []).map((item) =>
row(
`${dimensions[item.dimension]} — ${item.text}`,
`${classifications[item.classification]}; data ${item.date ?? 'por confirmar'}`,
item.reference || 'Fonte por confirmar',
classifications[item.classification],
rows: [
...(swot?.rows ?? []).map((item) =>
row(
`${dimensions[item.dimension]} — ${item.text}`,
`${classifications[item.classification]}; data ${item.date ?? 'por confirmar'}`,
item.reference || 'Fonte por confirmar',
classifications[item.classification],
),
),
),
...sectorEvidence,
],
},
{
id: 'sources',