@mergesignal/shared 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/dist/deriveScanNarrative.d.ts.map +1 -1
  2. package/dist/deriveScanNarrative.js +20 -3
  3. package/dist/deriveScanNarrative.test.js +6 -3
  4. package/dist/engineWireRegression.test.js +2 -2
  5. package/dist/fixtures/repoIntelligenceFixtures.d.ts.map +1 -1
  6. package/dist/fixtures/repoIntelligenceFixtures.js +13 -0
  7. package/dist/index.d.ts +3 -2
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +3 -2
  10. package/dist/narrativeParity.test.js +19 -18
  11. package/dist/narrativePresentation.d.ts.map +1 -1
  12. package/dist/narrativePresentation.js +6 -3
  13. package/dist/presentGitHubPrComment.d.ts +3 -4
  14. package/dist/presentGitHubPrComment.d.ts.map +1 -1
  15. package/dist/presentGitHubPrComment.js +15 -61
  16. package/dist/presentation/compose/narrativeCompose.d.ts +16 -0
  17. package/dist/presentation/compose/narrativeCompose.d.ts.map +1 -0
  18. package/dist/presentation/compose/narrativeCompose.js +167 -0
  19. package/dist/presentation/dto/githubAndCliPresentation.d.ts +53 -0
  20. package/dist/presentation/dto/githubAndCliPresentation.d.ts.map +1 -0
  21. package/dist/presentation/dto/githubAndCliPresentation.js +1 -0
  22. package/dist/presentation/dto/scanCardPresentation.d.ts +25 -0
  23. package/dist/presentation/dto/scanCardPresentation.d.ts.map +1 -0
  24. package/dist/presentation/dto/scanCardPresentation.js +1 -0
  25. package/dist/presentation/dto/scanDetailsPresentation.d.ts +111 -0
  26. package/dist/presentation/dto/scanDetailsPresentation.d.ts.map +1 -0
  27. package/dist/presentation/dto/scanDetailsPresentation.js +1 -0
  28. package/dist/presentation/dto/types.d.ts +24 -0
  29. package/dist/presentation/dto/types.d.ts.map +1 -0
  30. package/dist/presentation/dto/types.js +22 -0
  31. package/dist/presentation/fixtures/scanResultFixtures.d.ts +5 -0
  32. package/dist/presentation/fixtures/scanResultFixtures.d.ts.map +1 -0
  33. package/dist/presentation/fixtures/scanResultFixtures.js +83 -0
  34. package/dist/presentation/index.d.ts +25 -0
  35. package/dist/presentation/index.d.ts.map +1 -0
  36. package/dist/presentation/index.js +13 -0
  37. package/dist/presentation/orchestration/buildScanCardPresentation.d.ts +11 -0
  38. package/dist/presentation/orchestration/buildScanCardPresentation.d.ts.map +1 -0
  39. package/dist/presentation/orchestration/buildScanCardPresentation.js +44 -0
  40. package/dist/presentation/orchestration/buildScanDetailsPresentation.d.ts +14 -0
  41. package/dist/presentation/orchestration/buildScanDetailsPresentation.d.ts.map +1 -0
  42. package/dist/presentation/orchestration/buildScanDetailsPresentation.js +19 -0
  43. package/dist/presentation/orchestration/buildScanPresentationBundle.d.ts +15 -0
  44. package/dist/presentation/orchestration/buildScanPresentationBundle.d.ts.map +1 -0
  45. package/dist/presentation/orchestration/buildScanPresentationBundle.js +23 -0
  46. package/dist/presentation/orchestration/scanPresentationBundle.d.ts +15 -0
  47. package/dist/presentation/orchestration/scanPresentationBundle.d.ts.map +1 -0
  48. package/dist/presentation/orchestration/scanPresentationBundle.js +1 -0
  49. package/dist/presentation/presentation.test.d.ts +2 -0
  50. package/dist/presentation/presentation.test.d.ts.map +1 -0
  51. package/dist/presentation/presentation.test.js +95 -0
  52. package/dist/presentation/presenters/presentCliScanSummary.d.ts +6 -0
  53. package/dist/presentation/presenters/presentCliScanSummary.d.ts.map +1 -0
  54. package/dist/presentation/presenters/presentCliScanSummary.js +30 -0
  55. package/dist/presentation/presenters/presentGitHubCheckRun.d.ts +8 -0
  56. package/dist/presentation/presenters/presentGitHubCheckRun.d.ts.map +1 -0
  57. package/dist/presentation/presenters/presentGitHubCheckRun.js +32 -0
  58. package/dist/presentation/presenters/presentGitHubPrComment.d.ts +4 -0
  59. package/dist/presentation/presenters/presentGitHubPrComment.d.ts.map +1 -0
  60. package/dist/presentation/presenters/presentGitHubPrComment.js +40 -0
  61. package/dist/presentation/presenters/presentPipelineScanCard.d.ts +3 -0
  62. package/dist/presentation/presenters/presentPipelineScanCard.d.ts.map +1 -0
  63. package/dist/presentation/presenters/presentPipelineScanCard.js +23 -0
  64. package/dist/presentation/presenters/presentScanCard.d.ts +7 -0
  65. package/dist/presentation/presenters/presentScanCard.d.ts.map +1 -0
  66. package/dist/presentation/presenters/presentScanCard.js +43 -0
  67. package/dist/presentation/presenters/presentScanDetails.d.ts +9 -0
  68. package/dist/presentation/presenters/presentScanDetails.d.ts.map +1 -0
  69. package/dist/presentation/presenters/presentScanDetails.js +177 -0
  70. package/dist/presentation/profile/derivePresentationProfile.d.ts +12 -0
  71. package/dist/presentation/profile/derivePresentationProfile.d.ts.map +1 -0
  72. package/dist/presentation/profile/derivePresentationProfile.js +94 -0
  73. package/dist/presentation/profile/presentationProfile.d.ts +9 -0
  74. package/dist/presentation/profile/presentationProfile.d.ts.map +1 -0
  75. package/dist/presentation/profile/presentationProfile.js +1 -0
  76. package/dist/presentation/render/renderCliScanSummaryText.d.ts +3 -0
  77. package/dist/presentation/render/renderCliScanSummaryText.d.ts.map +1 -0
  78. package/dist/presentation/render/renderCliScanSummaryText.js +30 -0
  79. package/dist/presentation/render/renderGitHubCheckRunMarkdown.d.ts +3 -0
  80. package/dist/presentation/render/renderGitHubCheckRunMarkdown.d.ts.map +1 -0
  81. package/dist/presentation/render/renderGitHubCheckRunMarkdown.js +23 -0
  82. package/dist/presentation/render/renderGitHubPrCommentMarkdown.d.ts +3 -0
  83. package/dist/presentation/render/renderGitHubPrCommentMarkdown.d.ts.map +1 -0
  84. package/dist/presentation/render/renderGitHubPrCommentMarkdown.js +24 -0
  85. package/dist/repoIntelligenceMappers.d.ts.map +1 -1
  86. package/dist/repoIntelligenceMappers.js +8 -1
  87. package/dist/repoIntelligenceSchema.d.ts +75 -1
  88. package/dist/repoIntelligenceSchema.d.ts.map +1 -1
  89. package/dist/repoIntelligenceSchema.js +74 -1
  90. package/dist/repoIntelligenceSemantics.d.ts +29 -0
  91. package/dist/repoIntelligenceSemantics.d.ts.map +1 -0
  92. package/dist/repoIntelligenceSemantics.js +146 -0
  93. package/dist/repoIntelligenceSemantics.test.d.ts +2 -0
  94. package/dist/repoIntelligenceSemantics.test.d.ts.map +1 -0
  95. package/dist/repoIntelligenceSemantics.test.js +63 -0
  96. package/dist/scanCardSummary.d.ts +4 -35
  97. package/dist/scanCardSummary.d.ts.map +1 -1
  98. package/dist/scanCardSummary.js +12 -63
  99. package/dist/scanCardSummary.test.js +56 -75
  100. package/dist/scanDetailViewModel.d.ts +1 -0
  101. package/dist/scanDetailViewModel.d.ts.map +1 -1
  102. package/dist/scanDetailViewModel.js +1 -1
  103. package/dist/scanNarrativeFacts.d.ts +7 -0
  104. package/dist/scanNarrativeFacts.d.ts.map +1 -1
  105. package/dist/scanNarrativeFacts.js +1 -0
  106. package/dist/scanSurfaceCopy.d.ts +25 -0
  107. package/dist/scanSurfaceCopy.d.ts.map +1 -1
  108. package/dist/scanSurfaceCopy.js +25 -0
  109. package/package.json +1 -1
  110. package/dist/presentScanCardSummary.d.ts +0 -16
  111. package/dist/presentScanCardSummary.d.ts.map +0 -1
  112. package/dist/presentScanCardSummary.js +0 -212
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presentCliScanSummary.d.ts","sourceRoot":"","sources":["../../../src/presentation/presenters/presentCliScanSummary.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AAEzF,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,sBAAsB,EAC9B,GAAG,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GAC/B,mBAAmB,CA6BrB"}
@@ -0,0 +1,30 @@
1
+ import { composeHeadline, composeKeyPoints, composeSubheadline, composeSupportingContext, composeVerificationActions, evidenceContextFromProfile, } from "../compose/narrativeCompose.js";
2
+ export function presentCliScanSummary(bundle, ctx = {}) {
3
+ const { facts, profile, result } = bundle;
4
+ const layers = result.layerScores;
5
+ const layerLine = layers
6
+ ? `security=${layers.security} maintainability=${layers.maintainability} ecosystem=${layers.ecosystem} upgradeImpact=${layers.upgradeImpact}`
7
+ : "";
8
+ return {
9
+ header: {
10
+ repoLabel: ctx.repoLabel ?? "scan",
11
+ methodology: result.methodologyVersion ?? undefined,
12
+ confidence: profile.confidence,
13
+ },
14
+ status: profile.status,
15
+ density: profile.density,
16
+ confidence: profile.confidence,
17
+ evidenceContext: evidenceContextFromProfile(bundle),
18
+ headline: composeHeadline(bundle),
19
+ subheadline: composeSubheadline(bundle),
20
+ keyPoints: composeKeyPoints(bundle, 6),
21
+ verificationActions: composeVerificationActions(bundle, 5),
22
+ metrics: {
23
+ riskIndex: facts.riskIndex ?? result.totalScore ?? 0,
24
+ layerLine,
25
+ findingCount: result.findings?.length ?? 0,
26
+ recommendationCount: result.recommendations?.length ?? 0,
27
+ },
28
+ supportingContext: composeSupportingContext(bundle),
29
+ };
30
+ }
@@ -0,0 +1,8 @@
1
+ import type { GitHubCheckRunPresentation } from "../dto/githubAndCliPresentation.js";
2
+ import type { ScanPresentationBundle } from "../orchestration/scanPresentationBundle.js";
3
+ export declare function presentGitHubCheckRun(bundle: ScanPresentationBundle, ctx: {
4
+ scanId: string;
5
+ webAppOrigin: string;
6
+ baseline?: boolean;
7
+ }): GitHubCheckRunPresentation;
8
+ //# sourceMappingURL=presentGitHubCheckRun.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presentGitHubCheckRun.d.ts","sourceRoot":"","sources":["../../../src/presentation/presenters/presentGitHubCheckRun.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AACrF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AAEzF,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,sBAAsB,EAC9B,GAAG,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,GAChE,0BAA0B,CAkC5B"}
@@ -0,0 +1,32 @@
1
+ import { composeHeadline, composeKeyPoints, composeSubheadline, composeVerificationActions, evidenceContextFromProfile, } from "../compose/narrativeCompose.js";
2
+ export function presentGitHubCheckRun(bundle, ctx) {
3
+ const { profile } = bundle;
4
+ const headline = composeHeadline(bundle);
5
+ const keyPoints = composeKeyPoints(bundle, 3);
6
+ const actions = composeVerificationActions(bundle, 3);
7
+ const detailsUrl = `${ctx.webAppOrigin.replace(/\/$/, "")}/scan/${ctx.scanId}`;
8
+ const conclusion = profile.status === "safe"
9
+ ? "success"
10
+ : profile.status === "risky"
11
+ ? "failure"
12
+ : "neutral";
13
+ const sections = [];
14
+ if (keyPoints.length > 0) {
15
+ sections.push({ id: "why", title: "Why", bullets: keyPoints });
16
+ }
17
+ if (actions.length > 0) {
18
+ sections.push({ id: "actions", title: "What to verify", bullets: actions });
19
+ }
20
+ sections.push({ id: "footer", bullets: [`Full scan: ${detailsUrl}`] });
21
+ return {
22
+ status: profile.status,
23
+ density: profile.density,
24
+ confidence: profile.confidence,
25
+ evidenceContext: evidenceContextFromProfile(bundle),
26
+ title: headline,
27
+ conclusion,
28
+ summaryLead: composeSubheadline(bundle) ?? headline,
29
+ sections,
30
+ detailsUrl,
31
+ };
32
+ }
@@ -0,0 +1,4 @@
1
+ import type { GitHubPrCommentPresentation } from "../dto/githubAndCliPresentation.js";
2
+ import type { ScanPresentationBundle } from "../orchestration/scanPresentationBundle.js";
3
+ export declare function presentGitHubPrComment(bundle: ScanPresentationBundle): GitHubPrCommentPresentation;
4
+ //# sourceMappingURL=presentGitHubPrComment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presentGitHubPrComment.d.ts","sourceRoot":"","sources":["../../../src/presentation/presenters/presentGitHubPrComment.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AACtF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AAEzF,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,sBAAsB,GAC7B,2BAA2B,CAwC7B"}
@@ -0,0 +1,40 @@
1
+ import { MERGE_POSTURE_LABEL } from "../../riskVocabulary.js";
2
+ import { composeVerificationActions, evidenceContextFromProfile, } from "../compose/narrativeCompose.js";
3
+ import { formatChangedPackagesShort, formatUsageSummaryLine, selectReviewerGuidance, } from "../../narrativePresentation.js";
4
+ export function presentGitHubPrComment(bundle) {
5
+ const { facts, profile } = bundle;
6
+ const introLines = [];
7
+ const changed = formatChangedPackagesShort(facts, 3);
8
+ if (changed)
9
+ introLines.push(`Changed: ${changed}`);
10
+ const usage = formatUsageSummaryLine(facts, 1);
11
+ if (usage)
12
+ introLines.push(usage);
13
+ const verify = composeVerificationActions(bundle, 1)[0];
14
+ if (verify)
15
+ introLines.push(`Verify: ${verify}`);
16
+ const guidance = selectReviewerGuidance(facts, { scope: "changed", max: 3 });
17
+ const selected = guidance.length === 0
18
+ ? selectReviewerGuidance(facts, { max: 3 })
19
+ : guidance;
20
+ const guidanceBlocks = selected.map((g) => {
21
+ const where = g.context?.trim() ||
22
+ facts.packageUsage
23
+ .flatMap((u) => u.paths.slice(0, 1))
24
+ .filter(Boolean)[0] ||
25
+ "See scan detail for affected paths.";
26
+ const action = g.remediation?.trim() ||
27
+ composeVerificationActions(bundle, 1)[0] ||
28
+ "Review before merge.";
29
+ return { message: g.message, where, action };
30
+ });
31
+ return {
32
+ status: profile.status,
33
+ density: profile.density,
34
+ confidence: profile.confidence,
35
+ evidenceContext: evidenceContextFromProfile(bundle),
36
+ title: MERGE_POSTURE_LABEL[profile.status],
37
+ introLines,
38
+ guidanceBlocks,
39
+ };
40
+ }
@@ -0,0 +1,3 @@
1
+ import type { ScanCardPresentation } from "../dto/scanCardPresentation.js";
2
+ export declare function presentPipelineScanCard(pipelineStatus: "queued" | "running" | "failed"): ScanCardPresentation;
3
+ //# sourceMappingURL=presentPipelineScanCard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presentPipelineScanCard.d.ts","sourceRoot":"","sources":["../../../src/presentation/presenters/presentPipelineScanCard.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAE3E,wBAAgB,uBAAuB,CACrC,cAAc,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAC9C,oBAAoB,CAqBtB"}
@@ -0,0 +1,23 @@
1
+ import { scanSurfaceCopy } from "../../scanSurfaceCopy.js";
2
+ import { normalizeGeneratedText, } from "../../normalizeGeneratedText.js";
3
+ export function presentPipelineScanCard(pipelineStatus) {
4
+ const isRunning = pipelineStatus === "queued" || pipelineStatus === "running";
5
+ const headline = isRunning
6
+ ? scanSurfaceCopy.pipeline.scanRunning
7
+ : scanSurfaceCopy.pipeline.analysisIncomplete;
8
+ return {
9
+ pipeline: {
10
+ status: pipelineStatus,
11
+ headline: normalizeGeneratedText(headline),
12
+ subheadline: isRunning
13
+ ? scanSurfaceCopy.pipeline.scanIncomplete
14
+ : undefined,
15
+ },
16
+ headline: normalizeGeneratedText(headline),
17
+ changedPackages: [],
18
+ keyPoints: [],
19
+ affectedAreas: [],
20
+ verificationActions: [],
21
+ evidence: [],
22
+ };
23
+ }
@@ -0,0 +1,7 @@
1
+ import type { ScanCardPresentation } from "../dto/scanCardPresentation.js";
2
+ import type { ScanPresentationBundle } from "../orchestration/scanPresentationBundle.js";
3
+ export type PresentScanCardContext = {
4
+ includeFindingCounts?: boolean;
5
+ };
6
+ export declare function presentScanCard(bundle: ScanPresentationBundle, ctx?: PresentScanCardContext): ScanCardPresentation;
7
+ //# sourceMappingURL=presentScanCard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presentScanCard.d.ts","sourceRoot":"","sources":["../../../src/presentation/presenters/presentScanCard.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAgB3E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AAEzF,MAAM,MAAM,sBAAsB,GAAG;IACnC,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AAsBF,wBAAgB,eAAe,CAC7B,MAAM,EAAE,sBAAsB,EAC9B,GAAG,GAAE,sBAA2B,GAC/B,oBAAoB,CAyBtB"}
@@ -0,0 +1,43 @@
1
+ import { aggregateFindingCounts } from "../dto/types.js";
2
+ import { composeAffectedAreaLabels, composeEvidenceRows, composeHeadline, composeKeyPoints, composeSubheadline, composeSupportingContext, composeVerificationActions, evidenceContextFromProfile, } from "../compose/narrativeCompose.js";
3
+ import { normalizeGeneratedText, normalizeGeneratedTextNullable, } from "../../normalizeGeneratedText.js";
4
+ import { scanSurfaceCopy } from "../../scanSurfaceCopy.js";
5
+ function normalizeCard(p) {
6
+ return {
7
+ ...p,
8
+ headline: normalizeGeneratedText(p.headline),
9
+ subheadline: normalizeGeneratedTextNullable(p.subheadline) ?? undefined,
10
+ keyPoints: p.keyPoints.map((k) => normalizeGeneratedText(k)),
11
+ affectedAreas: p.affectedAreas.map((a) => normalizeGeneratedText(a)),
12
+ verificationActions: p.verificationActions.map((v) => normalizeGeneratedText(v)),
13
+ evidence: p.evidence.map((e) => ({
14
+ label: normalizeGeneratedText(e.label),
15
+ value: normalizeGeneratedText(e.value),
16
+ })),
17
+ supportingContext: p.supportingContext?.map((s) => normalizeGeneratedText(s)),
18
+ };
19
+ }
20
+ export function presentScanCard(bundle, ctx = {}) {
21
+ const { facts, profile, result } = bundle;
22
+ const presentation = {
23
+ status: profile.status,
24
+ density: profile.density,
25
+ confidence: profile.confidence,
26
+ evidenceContext: evidenceContextFromProfile(bundle),
27
+ headline: composeHeadline(bundle),
28
+ subheadline: composeSubheadline(bundle) ?? undefined,
29
+ changedPackages: facts.changedPackages.all,
30
+ primaryPackage: facts.changedPackages.primary ?? undefined,
31
+ keyPoints: composeKeyPoints(bundle, 3),
32
+ affectedAreas: composeAffectedAreaLabels(bundle, 2),
33
+ verificationActions: composeVerificationActions(bundle, 2),
34
+ evidence: composeEvidenceRows(bundle, 3),
35
+ supportingContext: composeSupportingContext(bundle),
36
+ riskIndex: facts.riskIndex,
37
+ findingCounts: ctx.includeFindingCounts
38
+ ? aggregateFindingCounts(result.findings)
39
+ : null,
40
+ actionLabel: scanSurfaceCopy.presentation.actionLabelReview,
41
+ };
42
+ return normalizeCard(presentation);
43
+ }
@@ -0,0 +1,9 @@
1
+ import type { ScanDetailsPresentation } from "../dto/scanDetailsPresentation.js";
2
+ import type { ScanPresentationBundle } from "../orchestration/scanPresentationBundle.js";
3
+ export type PresentScanDetailsContext = {
4
+ scanId: string;
5
+ methodologyVersion?: string | null;
6
+ prNumber?: number | null;
7
+ };
8
+ export declare function presentScanDetails(bundle: ScanPresentationBundle, ctx: PresentScanDetailsContext): ScanDetailsPresentation;
9
+ //# sourceMappingURL=presentScanDetails.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presentScanDetails.d.ts","sourceRoot":"","sources":["../../../src/presentation/presenters/presentScanDetails.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AAEzF,MAAM,MAAM,yBAAyB,GAAG;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B,CAAC;AAoHF,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,sBAAsB,EAC9B,GAAG,EAAE,yBAAyB,GAC7B,uBAAuB,CAgFzB"}
@@ -0,0 +1,177 @@
1
+ import { deriveDetailReachChip } from "../../formatCardExposureDisplay.js";
2
+ import { MERGE_POSTURE_LABEL } from "../../riskVocabulary.js";
3
+ import { deriveVerdictLineFromFacts, presentScanDetailViewModel, } from "../../scanDetailViewModel.js";
4
+ import { composeHeadline, composeKeyPoints, composeSubheadline, composeSupportingContext, composeVerificationActions, evidenceContextFromProfile, } from "../compose/narrativeCompose.js";
5
+ import { normalizeGeneratedText, normalizeGeneratedTextNullable, } from "../../normalizeGeneratedText.js";
6
+ import { scanSurfaceCopy } from "../../scanSurfaceCopy.js";
7
+ function mapOperationalImpact(vm) {
8
+ const oi = vm.operationalImpact;
9
+ if (oi.status === "hidden") {
10
+ return { status: "hidden", items: [] };
11
+ }
12
+ if (oi.status === "rich") {
13
+ return {
14
+ status: "rich",
15
+ items: oi.items.map((item) => ({
16
+ message: item.message,
17
+ where: item.where,
18
+ verify: item.verify,
19
+ affectedFiles: item.affectedFiles,
20
+ })),
21
+ };
22
+ }
23
+ return {
24
+ status: "compact",
25
+ items: oi.items,
26
+ fallbackMessage: oi.fallbackMessage,
27
+ };
28
+ }
29
+ function mapRecommendations(vm) {
30
+ const items = vm.recommendedActions.items.map((item) => ({
31
+ rank: item.rank,
32
+ title: item.title,
33
+ priority: item.priority === "high" ||
34
+ item.priority === "medium" ||
35
+ item.priority === "low"
36
+ ? item.priority
37
+ : "medium",
38
+ rationale: item.detail?.why,
39
+ }));
40
+ return { items };
41
+ }
42
+ function mapEvidence(bundle, vm) {
43
+ const defaultCollapsed = bundle.profile.priority === "pr_intelligence" &&
44
+ bundle.profile.density === "rich";
45
+ const ev = vm.evidence;
46
+ if (!ev) {
47
+ return {
48
+ defaultCollapsed,
49
+ attentionAreas: [],
50
+ findings: [],
51
+ findingsOverflowCount: 0,
52
+ };
53
+ }
54
+ return {
55
+ defaultCollapsed,
56
+ attentionAreas: ev.attentionAreas.map((area) => ({
57
+ problemLabel: area.problemLabel,
58
+ problemDescription: area.problemDescription,
59
+ packages: area.packages.map((p) => ({
60
+ name: p.name,
61
+ version: p.version,
62
+ direct: p.direct,
63
+ severity: p.severity,
64
+ evidence: p.evidence,
65
+ })),
66
+ overflowCount: area.overflowCount,
67
+ })),
68
+ findings: ev.findings.map((f) => ({
69
+ id: f.id,
70
+ severity: f.severity,
71
+ title: f.title,
72
+ description: f.description,
73
+ packageName: f.packageName,
74
+ recommendation: f.recommendation,
75
+ source: f.source,
76
+ })),
77
+ findingsOverflowCount: ev.findingsOverflowCount,
78
+ topology: ev.topology
79
+ ? {
80
+ summaryLine: ev.topology.summaryLine,
81
+ deepest: ev.topology.deepest,
82
+ }
83
+ : undefined,
84
+ };
85
+ }
86
+ function mapUsage(bundle) {
87
+ const { facts } = bundle;
88
+ if (facts.packageUsage.length === 0 && facts.frameworks.length === 0) {
89
+ return undefined;
90
+ }
91
+ return {
92
+ summary: facts.packageUsage[0]
93
+ ? `${facts.packageUsage.length} package(s) with usage data`
94
+ : undefined,
95
+ items: facts.packageUsage.map((row) => ({
96
+ packageName: row.packageName,
97
+ paths: row.paths,
98
+ areas: row.areas,
99
+ criticalPaths: row.criticalPaths,
100
+ })),
101
+ frameworks: facts.frameworks,
102
+ };
103
+ }
104
+ export function presentScanDetails(bundle, ctx) {
105
+ const { facts, profile, result } = bundle;
106
+ const vm = presentScanDetailViewModel(facts, result, {
107
+ scanId: ctx.scanId,
108
+ status: "done",
109
+ methodologyVersion: ctx.methodologyVersion,
110
+ prNumber: ctx.prNumber,
111
+ repoContext: { status: "hidden" },
112
+ });
113
+ const headline = composeHeadline(bundle);
114
+ const subheadline = composeSubheadline(bundle);
115
+ const keyPoints = composeKeyPoints(bundle, 6);
116
+ const verificationTitles = composeVerificationActions(bundle, 6);
117
+ const supportingLines = composeSupportingContext(bundle);
118
+ const supportingContext = supportingLines
119
+ ? {
120
+ title: scanSurfaceCopy.scanDetail.topologyCollapsedHint,
121
+ lines: supportingLines,
122
+ }
123
+ : undefined;
124
+ const posture = profile.status;
125
+ const postureLabel = MERGE_POSTURE_LABEL[posture];
126
+ return {
127
+ evidenceContext: evidenceContextFromProfile(bundle),
128
+ status: profile.status,
129
+ density: profile.density,
130
+ confidence: profile.confidence,
131
+ hero: {
132
+ headline: normalizeGeneratedText(headline),
133
+ subheadline: normalizeGeneratedTextNullable(subheadline) ?? undefined,
134
+ verdictLine: deriveVerdictLineFromFacts(facts, result),
135
+ scopeChip: deriveDetailReachChip(result.totalScore) ?? undefined,
136
+ postureLabel,
137
+ riskIndex: facts.riskIndex,
138
+ },
139
+ narrative: {
140
+ keyPoints: keyPoints.map((k) => normalizeGeneratedText(k)),
141
+ changedPackages: facts.changedPackages.all,
142
+ primaryPackage: facts.changedPackages.primary ?? undefined,
143
+ },
144
+ usage: mapUsage(bundle),
145
+ verification: {
146
+ actions: verificationTitles.map((title) => ({
147
+ title: normalizeGeneratedText(title),
148
+ })),
149
+ },
150
+ signalSummary: vm.signalSummary
151
+ ? {
152
+ riskIndex: vm.signalSummary.score,
153
+ band: vm.signalSummary.overallBand === "moderate"
154
+ ? "medium"
155
+ : vm.signalSummary.overallBand === "high"
156
+ ? "high"
157
+ : "low",
158
+ layers: vm.signalSummary.layers.map((l) => ({
159
+ layer: l.layer,
160
+ score: l.score,
161
+ band: l.concernLabel,
162
+ label: l.label,
163
+ })),
164
+ }
165
+ : undefined,
166
+ operationalImpact: mapOperationalImpact(vm),
167
+ recommendations: mapRecommendations(vm),
168
+ evidence: mapEvidence(bundle, vm),
169
+ supportingContext,
170
+ metadata: {
171
+ scanId: ctx.scanId,
172
+ generatedAt: result.generatedAt,
173
+ methodologyVersion: ctx.methodologyVersion,
174
+ changedPackagesSummary: facts.changedPackages.primary ?? facts.changedPackages.all.join(", "),
175
+ },
176
+ };
177
+ }
@@ -0,0 +1,12 @@
1
+ import type { ScanNarrativeFacts } from "../../scanNarrativeFacts.js";
2
+ import type { PipelineStatus } from "../dto/types.js";
3
+ import type { PresentationProfile } from "./presentationProfile.js";
4
+ type DerivePresentationProfileContext = {
5
+ pipelineStatus: PipelineStatus;
6
+ decision?: string | null;
7
+ totalScore?: number | null;
8
+ };
9
+ /** INTERNAL - only called from buildScanPresentationBundle */
10
+ export declare function derivePresentationProfile(facts: ScanNarrativeFacts, ctx: DerivePresentationProfileContext): PresentationProfile | null;
11
+ export {};
12
+ //# sourceMappingURL=derivePresentationProfile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"derivePresentationProfile.d.ts","sourceRoot":"","sources":["../../../src/presentation/profile/derivePresentationProfile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAGtE,OAAO,KAAK,EAAE,cAAc,EAAsB,MAAM,iBAAiB,CAAC;AAC1E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAEpE,KAAK,gCAAgC,GAAG;IACtC,cAAc,EAAE,cAAc,CAAC;IAC/B,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,CAAC;AAyGF,8DAA8D;AAC9D,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,kBAAkB,EACzB,GAAG,EAAE,gCAAgC,GACpC,mBAAmB,GAAG,IAAI,CAsB5B"}
@@ -0,0 +1,94 @@
1
+ import { mergePostureFromDecision } from "../../riskVocabulary.js";
2
+ import { scanSurfaceCopy } from "../../scanSurfaceCopy.js";
3
+ function statusFromScore(totalScore) {
4
+ if (totalScore == null || !Number.isFinite(totalScore))
5
+ return "needs_review";
6
+ if (totalScore <= 30)
7
+ return "safe";
8
+ if (totalScore <= 60)
9
+ return "needs_review";
10
+ return "risky";
11
+ }
12
+ function resolveStatus(facts, ctx) {
13
+ const fromFacts = facts.mergePosture;
14
+ if (fromFacts)
15
+ return fromFacts;
16
+ const fromDecision = mergePostureFromDecision(ctx.decision ?? undefined);
17
+ if (fromDecision)
18
+ return fromDecision;
19
+ return statusFromScore(ctx.totalScore ?? facts.riskIndex);
20
+ }
21
+ function hasStrongPrIntelligence(facts) {
22
+ return (facts.availability.tiersPresent.tier1 &&
23
+ facts.availability.repoIntelligenceParse === "ok");
24
+ }
25
+ function hasHighSeverityFindings(facts) {
26
+ return facts.reviewerGuidance.some((g) => g.kind === "finding" &&
27
+ (g.priority === "critical" || g.priority === "high"));
28
+ }
29
+ function hasRuntimeUsage(facts) {
30
+ if (facts.runtimeSurface?.kind === "runtime")
31
+ return true;
32
+ return facts.packageUsage.some((u) => u.paths.length > 0 || u.criticalPaths.length > 0);
33
+ }
34
+ function deriveDensity(facts, priority) {
35
+ if (priority === "limited") {
36
+ return hasHighSeverityFindings(facts) ? "standard" : "minimal";
37
+ }
38
+ const semantics = facts.packageSemantics;
39
+ const runtime = facts.runtimeSurface?.kind === "runtime" ||
40
+ semantics?.runtimeImpact === "confirmed";
41
+ const wideOrModerate = facts.blastRadius?.level === "wide" ||
42
+ facts.blastRadius?.level === "moderate";
43
+ const hasAreas = facts.affectedAreas.length > 0;
44
+ const hasRuntimePaths = hasRuntimeUsage(facts);
45
+ if (runtime && (wideOrModerate || hasAreas || hasRuntimePaths)) {
46
+ return "rich";
47
+ }
48
+ const toolingImpact = semantics?.expectedImpact === "typecheck" ||
49
+ semantics?.expectedImpact === "development_only" ||
50
+ semantics?.expectedImpact === "test_time" ||
51
+ semantics?.expectedImpact === "build_time";
52
+ const buildOnly = semantics?.suppressRuntimeNarrative === true ||
53
+ toolingImpact ||
54
+ facts.runtimeSurface?.kind === "build" ||
55
+ facts.reachability?.kind === "build_only";
56
+ const narrowBlast = !facts.blastRadius || facts.blastRadius.level === "narrow";
57
+ if (buildOnly && narrowBlast && !hasAreas) {
58
+ return "minimal";
59
+ }
60
+ return "standard";
61
+ }
62
+ function deriveConfidence(facts, priority) {
63
+ if (priority === "limited")
64
+ return "low";
65
+ const decisionConf = facts.confidence.decision;
66
+ if (decisionConf === "high" || decisionConf === "medium")
67
+ return "high";
68
+ const sparseUsage = facts.packageUsage.length === 0 ||
69
+ facts.packageUsage.every((u) => u.paths.length === 0 && u.criticalPaths.length === 0);
70
+ if (sparseUsage)
71
+ return "medium";
72
+ return "high";
73
+ }
74
+ /** INTERNAL - only called from buildScanPresentationBundle */
75
+ export function derivePresentationProfile(facts, ctx) {
76
+ if (ctx.pipelineStatus !== "done")
77
+ return null;
78
+ const priority = hasStrongPrIntelligence(facts)
79
+ ? "pr_intelligence"
80
+ : "limited";
81
+ const status = resolveStatus(facts, ctx);
82
+ const density = deriveDensity(facts, priority);
83
+ const confidence = deriveConfidence(facts, priority);
84
+ const degradedMessage = priority === "limited"
85
+ ? scanSurfaceCopy.presentation.limitedContextMessage
86
+ : undefined;
87
+ return {
88
+ status,
89
+ density,
90
+ confidence,
91
+ priority,
92
+ degradedMessage,
93
+ };
94
+ }
@@ -0,0 +1,9 @@
1
+ import type { PresentationConfidence, PresentationDensity, PresentationPriority, PresentationStatus } from "../dto/types.js";
2
+ export type PresentationProfile = {
3
+ status: PresentationStatus;
4
+ density: PresentationDensity;
5
+ confidence: PresentationConfidence;
6
+ priority: PresentationPriority;
7
+ degradedMessage?: string;
8
+ };
9
+ //# sourceMappingURL=presentationProfile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presentationProfile.d.ts","sourceRoot":"","sources":["../../../src/presentation/profile/presentationProfile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,kBAAkB,CAAC;IAC3B,OAAO,EAAE,mBAAmB,CAAC;IAC7B,UAAU,EAAE,sBAAsB,CAAC;IACnC,QAAQ,EAAE,oBAAoB,CAAC;IAC/B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { CliScanPresentation } from "../dto/githubAndCliPresentation.js";
2
+ export declare function renderCliScanSummaryText(p: CliScanPresentation): string;
3
+ //# sourceMappingURL=renderCliScanSummaryText.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderCliScanSummaryText.d.ts","sourceRoot":"","sources":["../../../src/presentation/render/renderCliScanSummaryText.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAE9E,wBAAgB,wBAAwB,CAAC,CAAC,EAAE,mBAAmB,GAAG,MAAM,CA+BvE"}
@@ -0,0 +1,30 @@
1
+ import { scanSurfaceCopy } from "../../scanSurfaceCopy.js";
2
+ export function renderCliScanSummaryText(p) {
3
+ const lines = [
4
+ `MergeSignal - ${p.header.repoLabel}`,
5
+ "",
6
+ p.headline,
7
+ ];
8
+ if (p.subheadline)
9
+ lines.push(p.subheadline);
10
+ lines.push("", `Status: ${p.status} | Density: ${p.density} | Confidence: ${p.confidence}`);
11
+ if (p.metrics) {
12
+ lines.push(`Risk index: ${p.metrics.riskIndex} (${scanSurfaceCopy.actions.riskIndexDirectionShort})`, p.metrics.layerLine, `Findings: ${p.metrics.findingCount} | Recommendations: ${p.metrics.recommendationCount}`);
13
+ }
14
+ if (p.keyPoints.length > 0) {
15
+ lines.push("", "Key points:");
16
+ for (const point of p.keyPoints)
17
+ lines.push(` - ${point}`);
18
+ }
19
+ if (p.verificationActions.length > 0) {
20
+ lines.push("", "Verify:");
21
+ for (const action of p.verificationActions)
22
+ lines.push(` - ${action}`);
23
+ }
24
+ if (p.supportingContext?.length) {
25
+ lines.push("", "Supporting context:");
26
+ for (const line of p.supportingContext)
27
+ lines.push(` - ${line}`);
28
+ }
29
+ return lines.join("\n");
30
+ }
@@ -0,0 +1,3 @@
1
+ import type { GitHubCheckRunPresentation } from "../dto/githubAndCliPresentation.js";
2
+ export declare function renderGitHubCheckRunMarkdown(p: GitHubCheckRunPresentation): string;
3
+ //# sourceMappingURL=renderGitHubCheckRunMarkdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderGitHubCheckRunMarkdown.d.ts","sourceRoot":"","sources":["../../../src/presentation/render/renderGitHubCheckRunMarkdown.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAErF,wBAAgB,4BAA4B,CAC1C,CAAC,EAAE,0BAA0B,GAC5B,MAAM,CAuBR"}
@@ -0,0 +1,23 @@
1
+ import { normalizeGeneratedText } from "../../normalizeGeneratedText.js";
2
+ export function renderGitHubCheckRunMarkdown(p) {
3
+ const parts = [
4
+ `**${normalizeGeneratedText(p.title)}**`,
5
+ "",
6
+ p.summaryLead,
7
+ "",
8
+ ];
9
+ for (const section of p.sections) {
10
+ if (section.id === "footer") {
11
+ parts.push(section.bullets.join("\n"));
12
+ continue;
13
+ }
14
+ if (section.title) {
15
+ parts.push(`### ${section.title}`, "");
16
+ }
17
+ for (const bullet of section.bullets) {
18
+ parts.push(`- ${normalizeGeneratedText(bullet)}`);
19
+ }
20
+ parts.push("");
21
+ }
22
+ return parts.join("\n").trimEnd();
23
+ }
@@ -0,0 +1,3 @@
1
+ import type { GitHubPrCommentPresentation } from "../dto/githubAndCliPresentation.js";
2
+ export declare function renderGitHubPrCommentMarkdown(p: GitHubPrCommentPresentation): string;
3
+ //# sourceMappingURL=renderGitHubPrCommentMarkdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderGitHubPrCommentMarkdown.d.ts","sourceRoot":"","sources":["../../../src/presentation/render/renderGitHubPrCommentMarkdown.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AAoBtF,wBAAgB,6BAA6B,CAC3C,CAAC,EAAE,2BAA2B,GAC7B,MAAM,CAmBR"}
@@ -0,0 +1,24 @@
1
+ import { normalizeGeneratedText } from "../../normalizeGeneratedText.js";
2
+ function renderGuidanceBlock(message, where, action) {
3
+ return [
4
+ normalizeGeneratedText(message),
5
+ "",
6
+ "**Where it shows up**",
7
+ "",
8
+ normalizeGeneratedText(where),
9
+ "",
10
+ "**What to do**",
11
+ "",
12
+ normalizeGeneratedText(action),
13
+ ].join("\n");
14
+ }
15
+ export function renderGitHubPrCommentMarkdown(p) {
16
+ const parts = [`**${normalizeGeneratedText(p.title)}**`];
17
+ if (p.introLines.length > 0) {
18
+ parts.push("", p.introLines.map((l) => normalizeGeneratedText(l)).join("\n"));
19
+ }
20
+ for (const block of p.guidanceBlocks) {
21
+ parts.push("", renderGuidanceBlock(block.message, block.where ?? "See scan detail.", block.action ?? "Review before merge."));
22
+ }
23
+ return parts.join("\n\n---\n\n").trimEnd();
24
+ }