ghagga-core 2.9.1 → 3.0.0

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 (175) hide show
  1. package/LICENSE +21 -0
  2. package/dist/agents/consensus.d.ts.map +1 -1
  3. package/dist/agents/consensus.js +7 -2
  4. package/dist/agents/consensus.js.map +1 -1
  5. package/dist/agents/diagnostic.d.ts.map +1 -1
  6. package/dist/agents/diagnostic.js +7 -2
  7. package/dist/agents/diagnostic.js.map +1 -1
  8. package/dist/agents/fan-out-lenses.d.ts.map +1 -1
  9. package/dist/agents/fan-out-lenses.js +7 -2
  10. package/dist/agents/fan-out-lenses.js.map +1 -1
  11. package/dist/agents/prompts.d.ts +49 -1
  12. package/dist/agents/prompts.d.ts.map +1 -1
  13. package/dist/agents/prompts.js +133 -5
  14. package/dist/agents/prompts.js.map +1 -1
  15. package/dist/agents/simple.d.ts +1 -1
  16. package/dist/agents/simple.d.ts.map +1 -1
  17. package/dist/agents/simple.js +6 -4
  18. package/dist/agents/simple.js.map +1 -1
  19. package/dist/agents/workflow.d.ts.map +1 -1
  20. package/dist/agents/workflow.js +13 -4
  21. package/dist/agents/workflow.js.map +1 -1
  22. package/dist/critique/critique.d.ts.map +1 -1
  23. package/dist/critique/critique.js +14 -6
  24. package/dist/critique/critique.js.map +1 -1
  25. package/dist/diff/index.d.ts +12 -0
  26. package/dist/diff/index.d.ts.map +1 -0
  27. package/dist/diff/index.js +11 -0
  28. package/dist/diff/index.js.map +1 -0
  29. package/dist/diff/parse.d.ts +41 -0
  30. package/dist/diff/parse.d.ts.map +1 -0
  31. package/dist/diff/parse.js +303 -0
  32. package/dist/diff/parse.js.map +1 -0
  33. package/dist/diff/types.d.ts +106 -0
  34. package/dist/diff/types.d.ts.map +1 -0
  35. package/dist/diff/types.js +23 -0
  36. package/dist/diff/types.js.map +1 -0
  37. package/dist/embed.d.ts +5 -2
  38. package/dist/embed.d.ts.map +1 -1
  39. package/dist/embed.js +7 -3
  40. package/dist/embed.js.map +1 -1
  41. package/dist/enhance/prompt.d.ts +5 -1
  42. package/dist/enhance/prompt.d.ts.map +1 -1
  43. package/dist/enhance/prompt.js +9 -2
  44. package/dist/enhance/prompt.js.map +1 -1
  45. package/dist/format.d.ts +31 -0
  46. package/dist/format.d.ts.map +1 -1
  47. package/dist/format.js +256 -15
  48. package/dist/format.js.map +1 -1
  49. package/dist/index.d.ts +2 -1
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +1 -0
  52. package/dist/index.js.map +1 -1
  53. package/dist/memory/pageindex/index.d.ts +2 -2
  54. package/dist/memory/pageindex/index.d.ts.map +1 -1
  55. package/dist/memory/pageindex/index.js.map +1 -1
  56. package/dist/memory/pageindex/service.d.ts +10 -1
  57. package/dist/memory/pageindex/service.d.ts.map +1 -1
  58. package/dist/memory/pageindex/service.js +2 -2
  59. package/dist/memory/pageindex/service.js.map +1 -1
  60. package/dist/memory/persist.d.ts.map +1 -1
  61. package/dist/memory/persist.js +10 -3
  62. package/dist/memory/persist.js.map +1 -1
  63. package/dist/memory/privacy.d.ts.map +1 -1
  64. package/dist/memory/privacy.js +45 -6
  65. package/dist/memory/privacy.js.map +1 -1
  66. package/dist/memory/sqlite.d.ts +1 -13
  67. package/dist/memory/sqlite.d.ts.map +1 -1
  68. package/dist/memory/sqlite.js +45 -27
  69. package/dist/memory/sqlite.js.map +1 -1
  70. package/dist/memory/taxonomy.d.ts.map +1 -1
  71. package/dist/memory/taxonomy.js +6 -1
  72. package/dist/memory/taxonomy.js.map +1 -1
  73. package/dist/pipeline/degrade.d.ts +61 -0
  74. package/dist/pipeline/degrade.d.ts.map +1 -0
  75. package/dist/pipeline/degrade.js +58 -0
  76. package/dist/pipeline/degrade.js.map +1 -0
  77. package/dist/pipeline/enrich.d.ts +29 -0
  78. package/dist/pipeline/enrich.d.ts.map +1 -0
  79. package/dist/pipeline/enrich.js +271 -0
  80. package/dist/pipeline/enrich.js.map +1 -0
  81. package/dist/pipeline/execute.d.ts +22 -0
  82. package/dist/pipeline/execute.d.ts.map +1 -0
  83. package/dist/pipeline/execute.js +250 -0
  84. package/dist/pipeline/execute.js.map +1 -0
  85. package/dist/pipeline/finalize.d.ts +26 -0
  86. package/dist/pipeline/finalize.d.ts.map +1 -0
  87. package/dist/pipeline/finalize.js +52 -0
  88. package/dist/pipeline/finalize.js.map +1 -0
  89. package/dist/pipeline/gather-context.d.ts +25 -0
  90. package/dist/pipeline/gather-context.d.ts.map +1 -0
  91. package/dist/pipeline/gather-context.js +169 -0
  92. package/dist/pipeline/gather-context.js.map +1 -0
  93. package/dist/pipeline/gather-safe.d.ts +39 -0
  94. package/dist/pipeline/gather-safe.d.ts.map +1 -0
  95. package/dist/pipeline/gather-safe.js +127 -0
  96. package/dist/pipeline/gather-safe.js.map +1 -0
  97. package/dist/pipeline/prepare-graph.d.ts +54 -0
  98. package/dist/pipeline/prepare-graph.d.ts.map +1 -0
  99. package/dist/pipeline/prepare-graph.js +174 -0
  100. package/dist/pipeline/prepare-graph.js.map +1 -0
  101. package/dist/pipeline/prepare.d.ts +40 -0
  102. package/dist/pipeline/prepare.d.ts.map +1 -0
  103. package/dist/pipeline/prepare.js +233 -0
  104. package/dist/pipeline/prepare.js.map +1 -0
  105. package/dist/pipeline/providers.d.ts +54 -0
  106. package/dist/pipeline/providers.d.ts.map +1 -0
  107. package/dist/pipeline/providers.js +163 -0
  108. package/dist/pipeline/providers.js.map +1 -0
  109. package/dist/pipeline/results.d.ts +35 -0
  110. package/dist/pipeline/results.d.ts.map +1 -0
  111. package/dist/pipeline/results.js +122 -0
  112. package/dist/pipeline/results.js.map +1 -0
  113. package/dist/pipeline/state.d.ts +92 -0
  114. package/dist/pipeline/state.d.ts.map +1 -0
  115. package/dist/pipeline/state.js +13 -0
  116. package/dist/pipeline/state.js.map +1 -0
  117. package/dist/pipeline.d.ts +10 -9
  118. package/dist/pipeline.d.ts.map +1 -1
  119. package/dist/pipeline.js +36 -1213
  120. package/dist/pipeline.js.map +1 -1
  121. package/dist/providers/gateway.d.ts.map +1 -1
  122. package/dist/providers/gateway.js +8 -0
  123. package/dist/providers/gateway.js.map +1 -1
  124. package/dist/recursive/index.d.ts +1 -0
  125. package/dist/recursive/index.d.ts.map +1 -1
  126. package/dist/recursive/index.js +7 -3
  127. package/dist/recursive/index.js.map +1 -1
  128. package/dist/recursive/patch-extractor.d.ts +58 -6
  129. package/dist/recursive/patch-extractor.d.ts.map +1 -1
  130. package/dist/recursive/patch-extractor.js +207 -26
  131. package/dist/recursive/patch-extractor.js.map +1 -1
  132. package/dist/sanitize.d.ts +51 -0
  133. package/dist/sanitize.d.ts.map +1 -0
  134. package/dist/sanitize.js +90 -0
  135. package/dist/sanitize.js.map +1 -0
  136. package/dist/scope/diff-mapper.d.ts +12 -0
  137. package/dist/scope/diff-mapper.d.ts.map +1 -1
  138. package/dist/scope/diff-mapper.js +25 -18
  139. package/dist/scope/diff-mapper.js.map +1 -1
  140. package/dist/scope/entity-diff.d.ts +21 -4
  141. package/dist/scope/entity-diff.d.ts.map +1 -1
  142. package/dist/scope/entity-diff.js +132 -34
  143. package/dist/scope/entity-diff.js.map +1 -1
  144. package/dist/scope/types.d.ts +10 -0
  145. package/dist/scope/types.d.ts.map +1 -1
  146. package/dist/semantic-diff/index.d.ts +25 -2
  147. package/dist/semantic-diff/index.d.ts.map +1 -1
  148. package/dist/semantic-diff/index.js +147 -53
  149. package/dist/semantic-diff/index.js.map +1 -1
  150. package/dist/tools/gitleaks-config.toml +35 -0
  151. package/dist/tools/plugins/gitleaks.d.ts +10 -0
  152. package/dist/tools/plugins/gitleaks.d.ts.map +1 -1
  153. package/dist/tools/plugins/gitleaks.js +29 -2
  154. package/dist/tools/plugins/gitleaks.js.map +1 -1
  155. package/dist/tools/plugins/semgrep.d.ts +11 -0
  156. package/dist/tools/plugins/semgrep.d.ts.map +1 -1
  157. package/dist/tools/plugins/semgrep.js +30 -1
  158. package/dist/tools/plugins/semgrep.js.map +1 -1
  159. package/dist/tools/semgrep-rules.yml +305 -0
  160. package/dist/types.d.ts +51 -1
  161. package/dist/types.d.ts.map +1 -1
  162. package/dist/types.js.map +1 -1
  163. package/dist/utils/diff.d.ts +22 -2
  164. package/dist/utils/diff.d.ts.map +1 -1
  165. package/dist/utils/diff.js +36 -40
  166. package/dist/utils/diff.js.map +1 -1
  167. package/package.json +21 -22
  168. package/dist/providers/fallback.d.ts +0 -54
  169. package/dist/providers/fallback.d.ts.map +0 -1
  170. package/dist/providers/fallback.js +0 -102
  171. package/dist/providers/fallback.js.map +0 -1
  172. package/dist/providers/index.d.ts +0 -49
  173. package/dist/providers/index.d.ts.map +0 -1
  174. package/dist/providers/index.js +0 -146
  175. package/dist/providers/index.js.map +0 -1
@@ -0,0 +1,271 @@
1
+ /**
2
+ * Enrich phase: steps 7 → 7.8 of the review pipeline, IN ONE FUNCTION,
3
+ * in LITERAL sequence: 7 merge static findings + enhance-APPLY +
4
+ * metadata; 7.4 exploitability (mutates findings in-place);
5
+ * 7.5 checklist scoring; 7.6 recursive review (appends regressions);
6
+ * 7.7 doc validation (pushes findings); 7.8 semantic ranking (reorders).
7
+ *
8
+ * ⚠️ The final order of `result.findings` is output-visible and pinned
9
+ * by the golden snapshot suite: in-place → append → push → reorder.
10
+ * Do NOT split, reorder, or "tidy" this sequence.
11
+ */
12
+ import { scoreFindings } from '../checklist/index.js';
13
+ import { extractChangedSymbols as extractChangedSymbolsFromDiff, scanDocsForSymbols as scanDocsForSymbolRefs, } from '../doc-validation/index.js';
14
+ import { analyzeExploitability, analyzeUsage } from '../exploitability/index.js';
15
+ import { rankFindings } from '../ranking/index.js';
16
+ import { recursiveReview } from '../recursive/index.js';
17
+ import { extractSemanticDiff } from '../semantic-diff/index.js';
18
+ import { runDegradable } from './degrade.js';
19
+ import { resolveGenerateTextFns } from './providers.js';
20
+ /**
21
+ * Size gate for semantic-diff extraction: filteredDiff above this length
22
+ * (in chars) skips the extract entirely. 2 000 000 chars ≈ 2 MB of diff —
23
+ * roughly 40 000+ lines, an order of magnitude past any human-reviewable
24
+ * PR and well past the flood-detection threshold (5 000 changed lines →
25
+ * lightweight). filteredDiff is NEVER truncated (truncateDiff writes the
26
+ * separate truncatedDiff field), so without a cap a flood-scale diff would
27
+ * pay regex work proportional to its full size for a purely cosmetic
28
+ * comment section. The extract is O(n) single-pass, so 2 MB itself is
29
+ * cheap — the cap exists to bound the tail, not the typical case.
30
+ */
31
+ export const SEMANTIC_DIFF_MAX_DIFF_CHARS = 2_000_000;
32
+ /**
33
+ * Run the enrich phase. Mutates `state.result` in-place.
34
+ */
35
+ export async function enrich(state) {
36
+ const { input, emit, result } = state;
37
+ // ── Step 7: Merge static analysis into result ──────────────
38
+ result.staticAnalysis = state.staticResult;
39
+ result.memoryContext = state.memoryContext;
40
+ // Add static analysis findings to the result's findings array (dynamic — all tools)
41
+ const staticFindings = Object.values(state.staticResult).flatMap((toolResult) => toolResult && typeof toolResult === 'object' && 'findings' in toolResult
42
+ ? toolResult.findings
43
+ : []);
44
+ result.findings = [...result.findings, ...staticFindings];
45
+ // ── Merge enhanced static findings into result ──────────────
46
+ // enhance-APPLY: the COMPUTE half ran in step 5.5 — do NOT fuse them.
47
+ if (state.enhancedStaticFindings && state.enhanceMetadata) {
48
+ result.enhanced = true;
49
+ result.enhanceMetadata = state.enhanceMetadata;
50
+ // Replace static-sourced findings with enhanced versions
51
+ const nonStaticFindings = result.findings.filter((f) => f.source === 'ai');
52
+ result.findings = [...state.enhancedStaticFindings, ...nonStaticFindings];
53
+ }
54
+ // Track which tools ran successfully
55
+ result.metadata.toolsRun = [];
56
+ result.metadata.toolsSkipped = [];
57
+ for (const [name, tool] of Object.entries(state.staticResult)) {
58
+ if (tool.status === 'success') {
59
+ result.metadata.toolsRun.push(name);
60
+ }
61
+ else {
62
+ result.metadata.toolsSkipped.push(name);
63
+ }
64
+ }
65
+ // Update execution time to cover the full pipeline
66
+ result.metadata.executionTimeMs = Date.now() - state.startTime;
67
+ // Add file stats metadata (for emoji stats bar in comment)
68
+ // Note: metadata.fileList uses allFiles (pre-filter), NOT state.fileList.
69
+ result.metadata.totalAdditions = state.allFiles.reduce((sum, f) => sum + f.additions, 0);
70
+ result.metadata.totalDeletions = state.allFiles.reduce((sum, f) => sum + f.deletions, 0);
71
+ result.metadata.fileList = state.allFiles.map((f) => f.path);
72
+ // Add entity-level semantic diff ("What changed" comment section).
73
+ // Computed over filteredDiff — settled in prepare and NEVER truncated
74
+ // (truncateDiff writes the separate truncatedDiff field), so entity and
75
+ // import counts stay honest even when the prompt diff was cut.
76
+ // reportFailure: false is DELIBERATE — a cosmetic comment section must not
77
+ // enter failedSteps (no PARTIAL downgrade), but the degradation is still
78
+ // recorded in warnOnlyDegradations so coverageComplete tells the whole
79
+ // truth (call-chain / negative-examples pattern, see pipeline/degrade.ts).
80
+ //
81
+ // Size gate: skipping an oversized diff is POLICY (flood-style gate),
82
+ // not an error — semanticDiff simply stays undefined (the comment
83
+ // renderer shows nothing) and warnOnlyDegradations is NOT touched, so
84
+ // coverageComplete stays true. Nothing failed; we chose not to compute.
85
+ if (state.filteredDiff.length <= SEMANTIC_DIFF_MAX_DIFF_CHARS) {
86
+ await runDegradable(state, {
87
+ step: 'semantic-diff',
88
+ warnLabel: '[ghagga] Semantic diff extraction failed (non-fatal):',
89
+ reportFailure: false,
90
+ }, () => {
91
+ result.semanticDiff = extractSemanticDiff(state.filteredDiff);
92
+ });
93
+ }
94
+ // Add blast-radius metadata (if applicable)
95
+ if (state.blastRadiusMetadata) {
96
+ result.metadata.blastRadius = state.blastRadiusMetadata;
97
+ }
98
+ // Add code intelligence metadata (if applicable)
99
+ if (state.codeIntelMetadata) {
100
+ result.codeIntelMetadata = state.codeIntelMetadata;
101
+ }
102
+ // ── Step 7.4: Exploitability analysis (optional) ────────────
103
+ if (input.settings.enableBlastRadius && result.findings.length > 0) {
104
+ const trivyCveCount = result.findings.filter((f) => f.source === 'trivy' && f.category === 'dependency-vulnerability').length;
105
+ if (trivyCveCount > 0) {
106
+ emit({
107
+ step: 'exploitability',
108
+ message: `Analyzing exploitability for ${trivyCveCount} CVE(s)...`,
109
+ });
110
+ await runDegradable(state, {
111
+ step: 'exploitability',
112
+ warnLabel: '[ghagga] Exploitability analysis failed (non-fatal):',
113
+ failEmit: {
114
+ step: 'exploitability',
115
+ message: 'Exploitability analysis failed — continuing without',
116
+ },
117
+ }, async () => {
118
+ // Load graph if not already loaded (reuse from blast-radius when available)
119
+ const exploitGraph = input.graphLoader ? await input.graphLoader.load() : null;
120
+ analyzeExploitability(result.findings, exploitGraph);
121
+ const labels = result.findings
122
+ .filter((f) => f.exploitability)
123
+ .reduce((acc, f) => {
124
+ const key = f.exploitability ?? 'unknown';
125
+ acc[key] = (acc[key] ?? 0) + 1;
126
+ return acc;
127
+ }, {});
128
+ const exploitable = labels.exploitable ?? 0;
129
+ const potential = labels['potentially-exploitable'] ?? 0;
130
+ const notExploitable = labels['not-exploitable'] ?? 0;
131
+ emit({
132
+ step: 'exploitability',
133
+ message: `Exploitability analysis complete: ${exploitable} exploitable, ${potential} potentially, ${notExploitable} not exploitable`,
134
+ });
135
+ // Function-level usage analysis (requires fileReader)
136
+ if (input.fileReader) {
137
+ emit({
138
+ step: 'usage-analysis',
139
+ message: 'Analyzing function-level usage of vulnerable packages...',
140
+ });
141
+ await analyzeUsage(result.findings, exploitGraph, input.fileReader);
142
+ const usageLabels = result.findings
143
+ .filter((f) => f.usageLabel)
144
+ .reduce((acc, f) => {
145
+ const key = f.usageLabel ?? 'unknown';
146
+ acc[key] = (acc[key] ?? 0) + 1;
147
+ return acc;
148
+ }, {});
149
+ const inUse = usageLabels['in-use'] ?? 0;
150
+ const importedNotCalled = usageLabels['imported-not-called'] ?? 0;
151
+ const notInUse = usageLabels['not-in-use'] ?? 0;
152
+ emit({
153
+ step: 'usage-analysis',
154
+ message: `Usage analysis complete: ${inUse} in-use, ${importedNotCalled} imported-not-called, ${notInUse} not-in-use`,
155
+ });
156
+ }
157
+ });
158
+ }
159
+ }
160
+ // ── Step 7.5: Score findings against checklist (optional) ───
161
+ if (state.resolvedChecklist && result.findings.length > 0) {
162
+ result.checklistScore = scoreFindings(result.findings, state.resolvedChecklist);
163
+ emit({
164
+ step: 'checklist-score',
165
+ message: `Checklist score: ${result.checklistScore.totalScore} (${result.checklistScore.findings.length} matched findings)`,
166
+ });
167
+ }
168
+ // ── Step 7.6: Recursive review (optional) ──────────────────────
169
+ if (input.settings.enableRecursiveReview && state.aiEnabled && result.findings.length > 0) {
170
+ emit({ step: 'recursive-review', message: 'Running recursive review on suggested fixes...' });
171
+ await runDegradable(state, {
172
+ step: 'recursive-review',
173
+ warnLabel: '[ghagga] Recursive review failed (non-fatal):',
174
+ failEmit: {
175
+ step: 'recursive-review',
176
+ message: 'Recursive review failed — continuing without',
177
+ },
178
+ }, async () => {
179
+ // Re-resolved fresh on purpose (not reused from the dispatch) — preserve.
180
+ const generateFns = resolveGenerateTextFns(input, state.isCliBridge, state.isGateway, state.isOllama);
181
+ const report = await recursiveReview({
182
+ originalDiff: state.truncatedDiff,
183
+ findings: result.findings,
184
+ generateFn: generateFns[0],
185
+ config: {
186
+ maxIterations: input.settings.maxRecursiveIterations ?? 2,
187
+ },
188
+ onProgress: (message) => emit({ step: 'recursive-review', message }),
189
+ });
190
+ if (report) {
191
+ result.recursiveReview = report;
192
+ // Add regressions to the findings array
193
+ if (report.regressions.length > 0) {
194
+ result.findings = [...result.findings, ...report.regressions];
195
+ emit({
196
+ step: 'recursive-review',
197
+ message: `Recursive review: ${report.regressions.length} regression(s) found in suggested fixes`,
198
+ });
199
+ }
200
+ else {
201
+ emit({
202
+ step: 'recursive-review',
203
+ message: `Recursive review: suggestions validated — ${report.converged ? 'converged' : 'no regressions'} after ${report.iterations} iteration(s)`,
204
+ });
205
+ }
206
+ }
207
+ });
208
+ }
209
+ // ── Step 7.7: Code-doc validation (optional) ───────────────────
210
+ if (input.settings.enableDocValidation && state.filteredFiles.length > 0) {
211
+ await runDegradable(state, {
212
+ step: 'doc-validation',
213
+ warnLabel: '[ghagga] Doc validation failed (non-fatal):',
214
+ failEmit: { step: 'doc-validation', message: 'Doc validation failed — continuing without' },
215
+ }, () => {
216
+ const changedSymbols = extractChangedSymbolsFromDiff(state.filteredDiff);
217
+ if (changedSymbols.length > 0) {
218
+ emit({
219
+ step: 'doc-validation',
220
+ message: `Scanning docs for ${changedSymbols.length} changed symbol(s)...`,
221
+ });
222
+ const docResult = scanDocsForSymbolRefs(changedSymbols, state.allFiles, state.fileList);
223
+ result.docValidation = docResult;
224
+ if (docResult.staleReferences.length > 0) {
225
+ // Convert stale references to findings
226
+ for (const ref of docResult.staleReferences) {
227
+ result.findings.push({
228
+ severity: 'low',
229
+ category: 'documentation',
230
+ file: ref.file,
231
+ line: ref.line,
232
+ message: `Documentation references \`${ref.symbol}\` which was changed in this PR but this doc was not updated.`,
233
+ suggestion: `Review and update the reference to \`${ref.symbol}\` in this file.`,
234
+ source: 'doc-validation',
235
+ });
236
+ }
237
+ emit({
238
+ step: 'doc-validation',
239
+ message: `Doc validation: ${docResult.staleReferences.length} stale reference(s) found in ${docResult.docsScanned} doc(s)`,
240
+ });
241
+ }
242
+ else {
243
+ emit({
244
+ step: 'doc-validation',
245
+ message: `Doc validation: no stale references (${docResult.docsScanned} docs scanned)`,
246
+ });
247
+ }
248
+ }
249
+ });
250
+ }
251
+ // ── Step 7.8: Semantic ranking of findings (optional) ─────────
252
+ const semanticRankingEnabled = input.features?.semanticRanking !== false && !!input.embeddingProvider;
253
+ if (semanticRankingEnabled && result.findings.length > 1) {
254
+ emit({ step: 'semantic-ranking', message: 'Reranking findings by semantic relevance...' });
255
+ await runDegradable(state, {
256
+ step: 'semantic-ranking',
257
+ warnLabel: '[ghagga] Semantic ranking failed (non-fatal):',
258
+ failEmit: {
259
+ step: 'semantic-ranking',
260
+ message: 'Semantic ranking failed — continuing without',
261
+ },
262
+ }, async () => {
263
+ result.findings = await rankFindings(result.findings, input.embeddingProvider);
264
+ emit({
265
+ step: 'semantic-ranking',
266
+ message: `Semantic ranking complete (${result.findings.length} findings reranked)`,
267
+ });
268
+ });
269
+ }
270
+ }
271
+ //# sourceMappingURL=enrich.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enrich.js","sourceRoot":"","sources":["../../src/pipeline/enrich.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EACL,qBAAqB,IAAI,6BAA6B,EACtD,kBAAkB,IAAI,qBAAqB,GAC5C,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAGxD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,SAAS,CAAC;AAEtD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,KAAoB;IAC/C,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IAEtC,8DAA8D;IAC9D,MAAM,CAAC,cAAc,GAAG,KAAK,CAAC,YAAY,CAAC;IAC3C,MAAM,CAAC,aAAa,GAAG,KAAK,CAAC,aAAa,CAAC;IAE3C,oFAAoF;IACpF,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE,CAC9E,UAAU,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,UAAU,IAAI,UAAU;QACtE,CAAC,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wC,SAAS,CAAC,WAAW,gBAAgB;qBACvF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC,CACF,CAAC;IACJ,CAAC;IAED,iEAAiE;IACjE,MAAM,sBAAsB,GAC1B,KAAK,CAAC,QAAQ,EAAE,eAAe,KAAK,KAAK,IAAI,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC;IACzE,IAAI,sBAAsB,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzD,IAAI,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,6CAA6C,EAAE,CAAC,CAAC;QAC3F,MAAM,aAAa,CACjB,KAAK,EACL;YACE,IAAI,EAAE,kBAAkB;YACxB,SAAS,EAAE,+CAA+C;YAC1D,QAAQ,EAAE;gBACR,IAAI,EAAE,kBAAkB;gBACxB,OAAO,EAAE,8CAA8C;aACxD;SACF,EACD,KAAK,IAAI,EAAE;YACT,MAAM,CAAC,QAAQ,GAAG,MAAM,YAAY,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC;YAC/E,IAAI,CAAC;gBACH,IAAI,EAAE,kBAAkB;gBACxB,OAAO,EAAE,8BAA8B,MAAM,CAAC,QAAQ,CAAC,MAAM,qBAAqB;aACnF,CAAC,CAAC;QACL,CAAC,CACF,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Execute phase: steps 5.5 → 6 of the review pipeline.
3
+ *
4
+ * 5.5 AI enhance — COMPUTE only (the APPLY half lives in enrich
5
+ * step 7; do NOT fuse them)
6
+ * 5.6 author trust scoring → may override the review mode
7
+ * 6 agent dispatch (or static-only when AI is disabled)
8
+ *
9
+ * Resolves the provider flags onto state FIRST — enrich step 7.6
10
+ * re-resolves generateFns from those flags.
11
+ *
12
+ * Returns the freshly created `ReviewResult`; the orchestrator attaches
13
+ * it to the state (same object — enrich/finalize mutate it in-place).
14
+ */
15
+ import type { ReviewResult } from '../types.js';
16
+ import type { PipelineStateBase } from './state.js';
17
+ /**
18
+ * Run the execute phase. Mutates provider/enhance/trust fields on
19
+ * `state` and RETURNS the created `ReviewResult`.
20
+ */
21
+ export declare function execute(state: PipelineStateBase): Promise<ReviewResult>;
22
+ //# sourceMappingURL=execute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../src/pipeline/execute.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAWH,OAAO,KAAK,EAA0C,YAAY,EAAE,MAAM,aAAa,CAAC;AASxF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD;;;GAGG;AACH,wBAAsB,OAAO,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAmQ7E"}
@@ -0,0 +1,250 @@
1
+ /**
2
+ * Execute phase: steps 5.5 → 6 of the review pipeline.
3
+ *
4
+ * 5.5 AI enhance — COMPUTE only (the APPLY half lives in enrich
5
+ * step 7; do NOT fuse them)
6
+ * 5.6 author trust scoring → may override the review mode
7
+ * 6 agent dispatch (or static-only when AI is disabled)
8
+ *
9
+ * Resolves the provider flags onto state FIRST — enrich step 7.6
10
+ * re-resolves generateFns from those flags.
11
+ *
12
+ * Returns the freshly created `ReviewResult`; the orchestrator attaches
13
+ * it to the state (same object — enrich/finalize mutate it in-place).
14
+ */
15
+ import { runConsensusReview } from '../agents/consensus.js';
16
+ import { runDiagnosticReview } from '../agents/diagnostic.js';
17
+ import { loadLensesFromDir, runFanOutReview } from '../agents/fan-out-lenses.js';
18
+ import { runSimpleReview } from '../agents/simple.js';
19
+ import { runWorkflowReview } from '../agents/workflow.js';
20
+ import { enhanceFindings, mergeEnhanceResult } from '../enhance/index.js';
21
+ import { serializeFindings } from '../enhance/prompt.js';
22
+ import { SqliteMemoryStorage } from '../memory/sqlite.js';
23
+ import { computeAuthorTrustScore, getReviewModeForTier } from '../trust/index.js';
24
+ import { runDegradable } from './degrade.js';
25
+ import { buildConsensusModels, resolveEffectiveMode, resolveGenerateTextFns, resolvePrimaryProvider, } from './providers.js';
26
+ import { createStaticOnlyResult } from './results.js';
27
+ /**
28
+ * Run the execute phase. Mutates provider/enhance/trust fields on
29
+ * `state` and RETURNS the created `ReviewResult`.
30
+ */
31
+ export async function execute(state) {
32
+ const { input, emit, aiEnabled, startTime, staticResult } = state;
33
+ // ── Step 5.5: AI Enhance (optional) ─────────────────────────
34
+ // Resolve active provider early — needed by enhance block below and by Step 6
35
+ const activeProvider = input.providerChain?.[0]?.provider ?? input.provider ?? 'gateway';
36
+ const isCliBridge = activeProvider === 'cli-bridge';
37
+ const isGateway = activeProvider === 'gateway';
38
+ const isOllama = activeProvider === 'ollama';
39
+ state.activeProvider = activeProvider;
40
+ state.isCliBridge = isCliBridge;
41
+ state.isGateway = isGateway;
42
+ state.isOllama = isOllama;
43
+ if (input.enhance) {
44
+ // Collect all static findings
45
+ const allStaticFindings = [];
46
+ for (const toolResult of Object.values(staticResult)) {
47
+ allStaticFindings.push(...toolResult.findings);
48
+ }
49
+ if (allStaticFindings.length > 0) {
50
+ emit({ step: 'static-analysis', message: 'Enhancing findings with AI...' });
51
+ // No warnLabel: ai-enhance is the only push-site that degrades without a console.warn.
52
+ await runDegradable(state, {
53
+ step: 'ai-enhance',
54
+ failEmit: {
55
+ step: 'static-analysis',
56
+ message: 'AI enhance failed — continuing without enhancement',
57
+ },
58
+ }, async () => {
59
+ const primary = resolvePrimaryProvider(input);
60
+ const enhanceGenerateFn = resolveGenerateTextFns(input, isCliBridge, isGateway, isOllama)[0];
61
+ const serialized = serializeFindings(allStaticFindings);
62
+ const { result: eResult, metadata: eMeta } = await enhanceFindings({
63
+ findings: serialized,
64
+ provider: primary.provider,
65
+ model: primary.model,
66
+ apiKey: primary.apiKey,
67
+ generateFn: enhanceGenerateFn,
68
+ });
69
+ state.enhancedStaticFindings = mergeEnhanceResult(allStaticFindings, eResult);
70
+ state.enhanceMetadata = eMeta;
71
+ });
72
+ }
73
+ }
74
+ // ── Step 5.6: Author trust scoring (optional) ──────────────
75
+ // When features.authorTrust is enabled and input.author is set, compute a
76
+ // trust score from git history and potentially override the review mode.
77
+ if (input.features?.authorTrust && input.author) {
78
+ const author = input.author;
79
+ await runDegradable(state, { step: 'author-trust', warnLabel: '[ghagga] Author trust scoring failed (non-fatal):' }, async () => {
80
+ const sqliteStorage = input.memoryStorage instanceof SqliteMemoryStorage ? input.memoryStorage : null;
81
+ // Check for a cached (fresh) score — recompute if older than 1 day
82
+ const ONE_DAY_MS = 24 * 60 * 60 * 1000;
83
+ let trustScore = sqliteStorage?.getTrustScore(author) ?? null;
84
+ const isStale = !trustScore || Date.now() - trustScore.lastUpdated.getTime() > ONE_DAY_MS;
85
+ if (isStale) {
86
+ trustScore = await computeAuthorTrustScore(author, { cwd: process.cwd() });
87
+ sqliteStorage?.upsertTrustScore(trustScore);
88
+ }
89
+ if (!trustScore) {
90
+ throw new Error('Trust score unavailable');
91
+ }
92
+ const recommendedMode = getReviewModeForTier(trustScore.tier, input.mode);
93
+ if (recommendedMode !== input.mode) {
94
+ state.trustOverrideMode = recommendedMode;
95
+ }
96
+ emit({
97
+ step: 'author-trust',
98
+ message: `[trust] author=${author} score=${trustScore.score} tier=${trustScore.tier} → mode=${recommendedMode}`,
99
+ });
100
+ });
101
+ }
102
+ // Effective input mode — may be overridden by trust scoring
103
+ const resolvedInputMode = state.trustOverrideMode ?? input.mode;
104
+ state.resolvedInputMode = resolvedInputMode;
105
+ // ── Step 6: Execute agent mode (or skip if AI disabled) ────
106
+ let result;
107
+ // Changed / blast-radius "affected" file set used to scope static-analysis
108
+ // findings in the static-only verdict (createStaticOnlyResult). `filteredFiles`
109
+ // IS the blast-radius-narrowed set when blast radius is enabled, and the
110
+ // literal changed-file set (post ignore-pattern filter) otherwise — so it
111
+ // already serves as both the expanded set and the fallback. Static tools scan
112
+ // the whole repo, so without this scope a 1-file change would fail on
113
+ // unrelated repo-wide pre-existing findings.
114
+ const affectedFiles = state.filteredFiles.map((f) => f.path);
115
+ // activeProvider / isCliBridge / isGateway / isOllama are resolved above (Step 5.5)
116
+ if (!aiEnabled) {
117
+ // Static-only mode: no LLM calls
118
+ emit({ step: 'agent-start', message: 'AI review disabled — returning static analysis only' });
119
+ result = createStaticOnlyResult(staticResult, resolvedInputMode, startTime, affectedFiles);
120
+ }
121
+ else {
122
+ // ── Unified dispatch: all backends, all modes ──────────────
123
+ // Step 1: Build GenerateTextFn(s) for the detected backend
124
+ const generateFns = resolveGenerateTextFns(input, isCliBridge, isGateway, isOllama);
125
+ // Step 2: Resolve effective mode (diagnostic → simple for non-SDK backends; ollama keeps it)
126
+ const effectiveMode = resolveEffectiveMode(resolvedInputMode, isCliBridge, isGateway);
127
+ if (effectiveMode !== resolvedInputMode) {
128
+ emit({
129
+ step: 'mode-fallback',
130
+ message: `Diagnostic mode not supported with ${isCliBridge ? 'CLI bridge' : 'gateway'} — falling back to simple mode`,
131
+ });
132
+ }
133
+ // Resolve primary provider for progress messages and metadata
134
+ const primary = resolvePrimaryProvider(input);
135
+ emit({
136
+ step: 'agent-start',
137
+ message: `Running ${effectiveMode} agent with ${primary.provider}/${primary.model}...`,
138
+ });
139
+ // Combine stack hints, code intelligence context, and call-chain context for agent prompts
140
+ const combinedStackHints = state.stackHints + state.codeIntelContext + state.callChainContext;
141
+ try {
142
+ switch (effectiveMode) {
143
+ case 'simple':
144
+ result = await runSimpleReview({
145
+ diff: state.truncatedDiff,
146
+ staticContext: state.staticContext,
147
+ memoryContext: state.memoryContext,
148
+ stackHints: combinedStackHints,
149
+ checklistContext: state.checklistContext,
150
+ reviewLevel: input.settings.reviewLevel,
151
+ onProgress: input.onProgress,
152
+ generateFn: generateFns[0],
153
+ // Backward compat fields (not used when generateFn is provided)
154
+ provider: primary.provider ?? 'cli-bridge',
155
+ model: primary.model ?? 'auto',
156
+ apiKey: primary.apiKey ?? '',
157
+ });
158
+ break;
159
+ case 'workflow':
160
+ result = await runWorkflowReview({
161
+ diff: state.truncatedDiff,
162
+ staticContext: state.staticContext,
163
+ memoryContext: state.memoryContext,
164
+ stackHints: combinedStackHints,
165
+ checklistContext: state.checklistContext,
166
+ reviewLevel: input.settings.reviewLevel,
167
+ onProgress: input.onProgress,
168
+ generateFns,
169
+ concurrency: input.settings?.reviewConcurrency,
170
+ delayMs: input.settings?.reviewDelayMs,
171
+ // Backward compat fields (not used when generateFns is provided)
172
+ provider: primary.provider ?? 'cli-bridge',
173
+ model: primary.model ?? 'auto',
174
+ apiKey: primary.apiKey ?? '',
175
+ providerChain: input.providerChain,
176
+ });
177
+ break;
178
+ case 'consensus':
179
+ result = await runConsensusReview({
180
+ diff: state.truncatedDiff,
181
+ models: buildConsensusModels(input.providerChain, primary),
182
+ staticContext: state.staticContext,
183
+ memoryContext: state.memoryContext,
184
+ stackHints: combinedStackHints,
185
+ checklistContext: state.checklistContext,
186
+ reviewLevel: input.settings.reviewLevel,
187
+ onProgress: input.onProgress,
188
+ generateFns,
189
+ concurrency: input.settings?.reviewConcurrency,
190
+ delayMs: input.settings?.reviewDelayMs,
191
+ });
192
+ break;
193
+ case 'diagnostic':
194
+ // Diagnostic mode is AI SDK-only (resolveEffectiveMode ensures this)
195
+ result = await runDiagnosticReview({
196
+ diff: state.truncatedDiff,
197
+ provider: primary.provider,
198
+ model: primary.model,
199
+ apiKey: primary.apiKey,
200
+ staticContext: state.staticContext,
201
+ memoryContext: state.memoryContext,
202
+ stackHints: combinedStackHints,
203
+ checklistContext: state.checklistContext,
204
+ reviewLevel: input.settings.reviewLevel,
205
+ onProgress: input.onProgress,
206
+ });
207
+ break;
208
+ case 'fan-out':
209
+ // Load custom lenses from directory (if configured)
210
+ if (input.settings.lensDir) {
211
+ await loadLensesFromDir(input.settings.lensDir, input.onProgress);
212
+ }
213
+ result = await runFanOutReview({
214
+ diff: state.truncatedDiff,
215
+ provider: primary.provider ?? 'cli-bridge',
216
+ model: primary.model ?? 'auto',
217
+ apiKey: primary.apiKey ?? '',
218
+ staticContext: state.staticContext,
219
+ memoryContext: state.memoryContext,
220
+ stackHints: combinedStackHints,
221
+ checklistContext: state.checklistContext,
222
+ reviewLevel: input.settings.reviewLevel,
223
+ onProgress: input.onProgress,
224
+ generateFns,
225
+ // Forward lens selection from settings (CLI flags > config > defaults)
226
+ ...(input.settings.lenses ? { lenses: input.settings.lenses } : {}),
227
+ });
228
+ break;
229
+ default: {
230
+ const _exhaustive = effectiveMode;
231
+ throw new Error(`Unknown review mode: ${_exhaustive}`);
232
+ }
233
+ }
234
+ }
235
+ catch (error) {
236
+ // Agent failed — return static results with NEEDS_HUMAN_REVIEW
237
+ console.warn('[ghagga] AI review failed, returning static analysis only:', error instanceof Error ? error.message : String(error));
238
+ state.failedSteps.push({
239
+ step: 'ai-review',
240
+ error: error instanceof Error ? error.message : String(error),
241
+ });
242
+ emit({ step: 'agent-failed', message: 'AI review failed — returning static analysis only' });
243
+ result = createStaticOnlyResult(staticResult, resolvedInputMode, startTime, affectedFiles);
244
+ result.status = 'NEEDS_HUMAN_REVIEW';
245
+ result.summary = `AI review failed (${error instanceof Error ? error.message : 'unknown error'}). Static analysis results are shown below.`;
246
+ }
247
+ }
248
+ return result;
249
+ }
250
+ //# sourceMappingURL=execute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute.js","sourceRoot":"","sources":["../../src/pipeline/execute.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,eAA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IAAI,CACV,4DAA4D,EAC5D,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CACvD,CAAC;YACF,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC;gBACrB,IAAI,EAAE,WAAW;gBACjB,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;aAC9D,CAAC,CAAC;YACH,IAAI,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,mDAAmD,EAAE,CAAC,CAAC;YAC7F,MAAM,GAAG,sBAAsB,CAAC,YAAY,EAAE,iBAAiB,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;YAC3F,MAAM,CAAC,MAAM,GAAG,oBAAoB,CAAC;YACrC,MAAM,CAAC,OAAO,GAAG,qBAAqB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,6CAA6C,CAAC;QAC9I,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Finalize phase: steps 8 → 9 of the review pipeline.
3
+ *
4
+ * 8 persist review observations to memory (awaited for SQLite correctness)
5
+ * 9 attach failed steps, set coverageComplete, downgrade PASSED → PARTIAL
6
+ *
7
+ * ⚠️ The downgrade is PASSED-only ON PURPOSE: a FAILED review stays
8
+ * FAILED even when steps degraded (pinned by pipeline.test.ts —
9
+ * "preserves FAILED status even when steps fail"). Do NOT "fix" this.
10
+ * The first-class coverage signal for non-PASSED statuses is
11
+ * `coverageComplete` (orthogonal to the verdict), set below for EVERY
12
+ * result that reaches finalize. It accounts for BOTH degradation kinds:
13
+ * tracked failures (`failedSteps`) AND warn-only degradations
14
+ * (`reportFailure: false` sites — call-chain, negative-examples,
15
+ * self-improve, semantic-diff), which never enter `failedSteps`, never trigger the
16
+ * PARTIAL downgrade, and stay internal — but still mean incomplete
17
+ * coverage. SKIPPED early-returns (flood-skip / all-files-filtered)
18
+ * short-circuit in prepare and never reach this phase — they stay
19
+ * `coverageComplete: undefined` (not applicable).
20
+ */
21
+ import type { PipelineState } from './state.js';
22
+ /**
23
+ * Run the finalize phase. Mutates `state.result` in-place.
24
+ */
25
+ export declare function finalize(state: PipelineState): Promise<void>;
26
+ //# sourceMappingURL=finalize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"finalize.d.ts","sourceRoot":"","sources":["../../src/pipeline/finalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;GAEG;AACH,wBAAsB,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAoClE"}