ghagga-core 2.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.
- package/README.md +51 -0
- package/dist/agents/consensus.d.ts +68 -0
- package/dist/agents/consensus.d.ts.map +1 -0
- package/dist/agents/consensus.js +216 -0
- package/dist/agents/consensus.js.map +1 -0
- package/dist/agents/prompts.d.ts +18 -0
- package/dist/agents/prompts.d.ts.map +1 -0
- package/dist/agents/prompts.js +194 -0
- package/dist/agents/prompts.js.map +1 -0
- package/dist/agents/simple.d.ts +49 -0
- package/dist/agents/simple.d.ts.map +1 -0
- package/dist/agents/simple.js +135 -0
- package/dist/agents/simple.js.map +1 -0
- package/dist/agents/workflow.d.ts +40 -0
- package/dist/agents/workflow.d.ts.map +1 -0
- package/dist/agents/workflow.js +127 -0
- package/dist/agents/workflow.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/memory/context.d.ts +23 -0
- package/dist/memory/context.d.ts.map +1 -0
- package/dist/memory/context.js +36 -0
- package/dist/memory/context.js.map +1 -0
- package/dist/memory/persist.d.ts +22 -0
- package/dist/memory/persist.d.ts.map +1 -0
- package/dist/memory/persist.js +103 -0
- package/dist/memory/persist.js.map +1 -0
- package/dist/memory/privacy.d.ts +19 -0
- package/dist/memory/privacy.d.ts.map +1 -0
- package/dist/memory/privacy.js +77 -0
- package/dist/memory/privacy.js.map +1 -0
- package/dist/memory/search.d.ts +20 -0
- package/dist/memory/search.d.ts.map +1 -0
- package/dist/memory/search.js +76 -0
- package/dist/memory/search.js.map +1 -0
- package/dist/pipeline.d.ts +30 -0
- package/dist/pipeline.d.ts.map +1 -0
- package/dist/pipeline.js +267 -0
- package/dist/pipeline.js.map +1 -0
- package/dist/providers/fallback.d.ts +46 -0
- package/dist/providers/fallback.d.ts.map +1 -0
- package/dist/providers/fallback.js +84 -0
- package/dist/providers/fallback.js.map +1 -0
- package/dist/providers/index.d.ts +40 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +76 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/tools/cpd.d.ts +24 -0
- package/dist/tools/cpd.d.ts.map +1 -0
- package/dist/tools/cpd.js +130 -0
- package/dist/tools/cpd.js.map +1 -0
- package/dist/tools/runner.d.ts +19 -0
- package/dist/tools/runner.d.ts.map +1 -0
- package/dist/tools/runner.js +61 -0
- package/dist/tools/runner.js.map +1 -0
- package/dist/tools/semgrep.d.ts +12 -0
- package/dist/tools/semgrep.d.ts.map +1 -0
- package/dist/tools/semgrep.js +97 -0
- package/dist/tools/semgrep.js.map +1 -0
- package/dist/tools/trivy.d.ts +11 -0
- package/dist/tools/trivy.d.ts.map +1 -0
- package/dist/tools/trivy.js +74 -0
- package/dist/tools/trivy.js.map +1 -0
- package/dist/types.d.ts +168 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +24 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/diff.d.ts +53 -0
- package/dist/utils/diff.d.ts.map +1 -0
- package/dist/utils/diff.js +103 -0
- package/dist/utils/diff.js.map +1 -0
- package/dist/utils/stack-detect.d.ts +15 -0
- package/dist/utils/stack-detect.d.ts.map +1 -0
- package/dist/utils/stack-detect.js +54 -0
- package/dist/utils/stack-detect.js.map +1 -0
- package/dist/utils/token-budget.d.ts +31 -0
- package/dist/utils/token-budget.d.ts.map +1 -0
- package/dist/utils/token-budget.js +62 -0
- package/dist/utils/token-budget.js.map +1 -0
- package/package.json +68 -0
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# @ghagga/core
|
|
2
|
+
|
|
3
|
+
Core review engine for [GHAGGA](https://github.com/JNZader/ghagga) — AI-powered multi-agent code reviewer.
|
|
4
|
+
|
|
5
|
+
This package contains the distribution-agnostic review pipeline, LLM provider integrations, static analysis runners, and all three review modes (simple, workflow, consensus).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @ghagga/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { reviewPipeline, DEFAULT_SETTINGS } from '@ghagga/core';
|
|
17
|
+
|
|
18
|
+
const result = await reviewPipeline({
|
|
19
|
+
diff: '...unified diff string...',
|
|
20
|
+
mode: 'simple', // 'simple' | 'workflow' | 'consensus'
|
|
21
|
+
provider: 'github', // 'github' | 'openai' | 'anthropic' | 'google'
|
|
22
|
+
model: 'gpt-4o-mini',
|
|
23
|
+
apiKey: process.env.GITHUB_TOKEN!,
|
|
24
|
+
settings: DEFAULT_SETTINGS,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
console.log(result.status); // 'PASSED' | 'FAILED' | 'NEEDS_HUMAN_REVIEW'
|
|
28
|
+
console.log(result.summary);
|
|
29
|
+
console.log(result.findings);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Review Modes
|
|
33
|
+
|
|
34
|
+
| Mode | LLM Calls | Best For |
|
|
35
|
+
|------|-----------|----------|
|
|
36
|
+
| **simple** | 1 | Small PRs, quick feedback |
|
|
37
|
+
| **workflow** | 6 | Thorough review with 5 specialist agents + synthesis |
|
|
38
|
+
| **consensus** | 3 | Balanced review with for/against/neutral voting |
|
|
39
|
+
|
|
40
|
+
## Providers
|
|
41
|
+
|
|
42
|
+
- **github** — Free via [GitHub Models](https://github.com/marketplace/models) (default)
|
|
43
|
+
- **openai** — OpenAI API (GPT-4o, GPT-4o-mini, etc.)
|
|
44
|
+
- **anthropic** — Anthropic API (Claude Sonnet, Haiku, etc.)
|
|
45
|
+
- **google** — Google AI (Gemini Pro, Flash, etc.)
|
|
46
|
+
|
|
47
|
+
> **Tip:** For the CLI experience, use [`@ghagga/cli`](https://www.npmjs.com/package/@ghagga/cli) instead.
|
|
48
|
+
|
|
49
|
+
## License
|
|
50
|
+
|
|
51
|
+
MIT
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Consensus review agent (multi-model voting).
|
|
3
|
+
*
|
|
4
|
+
* Each configured model reviews the code with an assigned stance
|
|
5
|
+
* (for, against, neutral). Individual votes are parsed for
|
|
6
|
+
* DECISION/CONFIDENCE/REASONING, then a weighted voting algorithm
|
|
7
|
+
* determines the final outcome.
|
|
8
|
+
*
|
|
9
|
+
* Thresholds:
|
|
10
|
+
* - 60% weighted votes for approve/reject → that decision wins
|
|
11
|
+
* - 30% minimum confidence gap between approve and reject
|
|
12
|
+
* - If thresholds not met → NEEDS_HUMAN_REVIEW
|
|
13
|
+
*/
|
|
14
|
+
import type { LLMProvider, ProgressCallback, ReviewResult, ReviewStatus, ConsensusStance, ConsensusVote } from '../types.js';
|
|
15
|
+
export interface ConsensusModelConfig {
|
|
16
|
+
provider: LLMProvider;
|
|
17
|
+
model: string;
|
|
18
|
+
apiKey: string;
|
|
19
|
+
stance: ConsensusStance;
|
|
20
|
+
}
|
|
21
|
+
export interface ConsensusReviewInput {
|
|
22
|
+
diff: string;
|
|
23
|
+
models: ConsensusModelConfig[];
|
|
24
|
+
staticContext: string;
|
|
25
|
+
memoryContext: string | null;
|
|
26
|
+
stackHints: string;
|
|
27
|
+
onProgress?: ProgressCallback;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Parse a single model's vote from its response text.
|
|
31
|
+
*
|
|
32
|
+
* Expects the format:
|
|
33
|
+
* DECISION: approve|reject|abstain
|
|
34
|
+
* CONFIDENCE: 0.0-1.0
|
|
35
|
+
* REASONING: ...
|
|
36
|
+
*/
|
|
37
|
+
export declare function parseVote(text: string, provider: LLMProvider, model: string, stance: ConsensusStance): ConsensusVote;
|
|
38
|
+
/**
|
|
39
|
+
* Calculate the final consensus from individual votes.
|
|
40
|
+
*
|
|
41
|
+
* Uses confidence-weighted voting:
|
|
42
|
+
* - Each vote's weight = confidence score
|
|
43
|
+
* - Approve weight = sum of approve confidences
|
|
44
|
+
* - Reject weight = sum of reject confidences
|
|
45
|
+
* - Abstain votes don't count toward either
|
|
46
|
+
*
|
|
47
|
+
* Decision rules:
|
|
48
|
+
* - If approve ratio ≥ 60% → PASSED
|
|
49
|
+
* - If reject ratio ≥ 60% → FAILED
|
|
50
|
+
* - If confidence gap < 30% → NEEDS_HUMAN_REVIEW
|
|
51
|
+
*/
|
|
52
|
+
export declare function calculateConsensus(votes: ConsensusVote[]): {
|
|
53
|
+
status: ReviewStatus;
|
|
54
|
+
summary: string;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Run a consensus (multi-model voting) code review.
|
|
58
|
+
*
|
|
59
|
+
* 1. Each model reviews the diff with its assigned stance prompt
|
|
60
|
+
* 2. Parse each response for DECISION/CONFIDENCE/REASONING
|
|
61
|
+
* 3. Calculate weighted consensus
|
|
62
|
+
* 4. Build the final ReviewResult
|
|
63
|
+
*
|
|
64
|
+
* @param input - Review input with diff, model configs, and context
|
|
65
|
+
* @returns ReviewResult with consensus-derived status and all vote reasoning
|
|
66
|
+
*/
|
|
67
|
+
export declare function runConsensusReview(input: ConsensusReviewInput): Promise<ReviewResult>;
|
|
68
|
+
//# sourceMappingURL=consensus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consensus.d.ts","sourceRoot":"","sources":["../../src/agents/consensus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAUH,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,aAAa,EACd,MAAM,aAAa,CAAC;AAIrB,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,WAAW,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,eAAe,CAAC;CACzB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,oBAAoB,EAAE,CAAC;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC/B;AAmBD;;;;;;;GAOG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,WAAW,EACrB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,eAAe,GACtB,aAAa,CAef;AAID;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG;IAC1D,MAAM,EAAE,YAAY,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB,CAuDA;AAID;;;;;;;;;;GAUG;AACH,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,oBAAoB,GAC1B,OAAO,CAAC,YAAY,CAAC,CA4GvB"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Consensus review agent (multi-model voting).
|
|
3
|
+
*
|
|
4
|
+
* Each configured model reviews the code with an assigned stance
|
|
5
|
+
* (for, against, neutral). Individual votes are parsed for
|
|
6
|
+
* DECISION/CONFIDENCE/REASONING, then a weighted voting algorithm
|
|
7
|
+
* determines the final outcome.
|
|
8
|
+
*
|
|
9
|
+
* Thresholds:
|
|
10
|
+
* - 60% weighted votes for approve/reject → that decision wins
|
|
11
|
+
* - 30% minimum confidence gap between approve and reject
|
|
12
|
+
* - If thresholds not met → NEEDS_HUMAN_REVIEW
|
|
13
|
+
*/
|
|
14
|
+
import { generateText } from 'ai';
|
|
15
|
+
import { createModel } from '../providers/index.js';
|
|
16
|
+
import { CONSENSUS_FOR_SYSTEM, CONSENSUS_AGAINST_SYSTEM, CONSENSUS_NEUTRAL_SYSTEM, buildMemoryContext, } from './prompts.js';
|
|
17
|
+
// ─── Constants ──────────────────────────────────────────────────
|
|
18
|
+
/** Minimum percentage of weighted votes to decide approve/reject */
|
|
19
|
+
const DECISION_THRESHOLD = 0.6;
|
|
20
|
+
/** Minimum gap between approve and reject confidence for a clear decision */
|
|
21
|
+
const CONFIDENCE_GAP_THRESHOLD = 0.3;
|
|
22
|
+
/** Map stance to system prompt */
|
|
23
|
+
const STANCE_PROMPTS = {
|
|
24
|
+
for: CONSENSUS_FOR_SYSTEM,
|
|
25
|
+
against: CONSENSUS_AGAINST_SYSTEM,
|
|
26
|
+
neutral: CONSENSUS_NEUTRAL_SYSTEM,
|
|
27
|
+
};
|
|
28
|
+
// ─── Vote Parsing ───────────────────────────────────────────────
|
|
29
|
+
/**
|
|
30
|
+
* Parse a single model's vote from its response text.
|
|
31
|
+
*
|
|
32
|
+
* Expects the format:
|
|
33
|
+
* DECISION: approve|reject|abstain
|
|
34
|
+
* CONFIDENCE: 0.0-1.0
|
|
35
|
+
* REASONING: ...
|
|
36
|
+
*/
|
|
37
|
+
export function parseVote(text, provider, model, stance) {
|
|
38
|
+
// Extract DECISION
|
|
39
|
+
const decisionMatch = /DECISION:\s*(approve|reject|abstain)/i.exec(text);
|
|
40
|
+
const decision = (decisionMatch?.[1]?.toLowerCase() ?? 'abstain');
|
|
41
|
+
// Extract CONFIDENCE
|
|
42
|
+
const confidenceMatch = /CONFIDENCE:\s*([\d.]+)/i.exec(text);
|
|
43
|
+
let confidence = confidenceMatch ? parseFloat(confidenceMatch[1]) : 0.5;
|
|
44
|
+
confidence = Math.max(0, Math.min(1, confidence)); // Clamp to [0, 1]
|
|
45
|
+
// Extract REASONING (everything after REASONING:)
|
|
46
|
+
const reasoningMatch = /REASONING:\s*([\s\S]+?)$/i.exec(text);
|
|
47
|
+
const reasoning = reasoningMatch?.[1]?.trim() ?? 'No reasoning provided.';
|
|
48
|
+
return { provider, model, stance, decision, confidence, reasoning };
|
|
49
|
+
}
|
|
50
|
+
// ─── Voting Algorithm ───────────────────────────────────────────
|
|
51
|
+
/**
|
|
52
|
+
* Calculate the final consensus from individual votes.
|
|
53
|
+
*
|
|
54
|
+
* Uses confidence-weighted voting:
|
|
55
|
+
* - Each vote's weight = confidence score
|
|
56
|
+
* - Approve weight = sum of approve confidences
|
|
57
|
+
* - Reject weight = sum of reject confidences
|
|
58
|
+
* - Abstain votes don't count toward either
|
|
59
|
+
*
|
|
60
|
+
* Decision rules:
|
|
61
|
+
* - If approve ratio ≥ 60% → PASSED
|
|
62
|
+
* - If reject ratio ≥ 60% → FAILED
|
|
63
|
+
* - If confidence gap < 30% → NEEDS_HUMAN_REVIEW
|
|
64
|
+
*/
|
|
65
|
+
export function calculateConsensus(votes) {
|
|
66
|
+
let approveWeight = 0;
|
|
67
|
+
let rejectWeight = 0;
|
|
68
|
+
let totalWeight = 0;
|
|
69
|
+
for (const vote of votes) {
|
|
70
|
+
if (vote.decision === 'approve') {
|
|
71
|
+
approveWeight += vote.confidence;
|
|
72
|
+
totalWeight += vote.confidence;
|
|
73
|
+
}
|
|
74
|
+
else if (vote.decision === 'reject') {
|
|
75
|
+
rejectWeight += vote.confidence;
|
|
76
|
+
totalWeight += vote.confidence;
|
|
77
|
+
}
|
|
78
|
+
// abstain votes are counted but don't contribute weight
|
|
79
|
+
}
|
|
80
|
+
// Prevent division by zero
|
|
81
|
+
if (totalWeight === 0) {
|
|
82
|
+
return {
|
|
83
|
+
status: 'NEEDS_HUMAN_REVIEW',
|
|
84
|
+
summary: 'All models abstained. Manual review is recommended.',
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const approveRatio = approveWeight / totalWeight;
|
|
88
|
+
const rejectRatio = rejectWeight / totalWeight;
|
|
89
|
+
const gap = Math.abs(approveRatio - rejectRatio);
|
|
90
|
+
// Check confidence gap
|
|
91
|
+
if (gap < CONFIDENCE_GAP_THRESHOLD) {
|
|
92
|
+
return {
|
|
93
|
+
status: 'NEEDS_HUMAN_REVIEW',
|
|
94
|
+
summary: `Consensus inconclusive (approve: ${(approveRatio * 100).toFixed(0)}%, reject: ${(rejectRatio * 100).toFixed(0)}%). The confidence gap (${(gap * 100).toFixed(0)}%) is below the ${(CONFIDENCE_GAP_THRESHOLD * 100).toFixed(0)}% threshold. Manual review recommended.`,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
// Check decision thresholds
|
|
98
|
+
if (approveRatio >= DECISION_THRESHOLD) {
|
|
99
|
+
return {
|
|
100
|
+
status: 'PASSED',
|
|
101
|
+
summary: `Consensus: APPROVED with ${(approveRatio * 100).toFixed(0)}% weighted confidence across ${votes.length} models.`,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
if (rejectRatio >= DECISION_THRESHOLD) {
|
|
105
|
+
return {
|
|
106
|
+
status: 'FAILED',
|
|
107
|
+
summary: `Consensus: REJECTED with ${(rejectRatio * 100).toFixed(0)}% weighted confidence across ${votes.length} models.`,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
status: 'NEEDS_HUMAN_REVIEW',
|
|
112
|
+
summary: `No clear consensus reached (approve: ${(approveRatio * 100).toFixed(0)}%, reject: ${(rejectRatio * 100).toFixed(0)}%). Manual review recommended.`,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
// ─── Main Function ──────────────────────────────────────────────
|
|
116
|
+
/**
|
|
117
|
+
* Run a consensus (multi-model voting) code review.
|
|
118
|
+
*
|
|
119
|
+
* 1. Each model reviews the diff with its assigned stance prompt
|
|
120
|
+
* 2. Parse each response for DECISION/CONFIDENCE/REASONING
|
|
121
|
+
* 3. Calculate weighted consensus
|
|
122
|
+
* 4. Build the final ReviewResult
|
|
123
|
+
*
|
|
124
|
+
* @param input - Review input with diff, model configs, and context
|
|
125
|
+
* @returns ReviewResult with consensus-derived status and all vote reasoning
|
|
126
|
+
*/
|
|
127
|
+
export async function runConsensusReview(input) {
|
|
128
|
+
const { diff, models, staticContext, memoryContext, stackHints } = input;
|
|
129
|
+
const emit = input.onProgress ?? (() => { });
|
|
130
|
+
const startTime = Date.now();
|
|
131
|
+
// Build the user prompt (same for all models)
|
|
132
|
+
const userPrompt = `Review the following code changes:\n\n\`\`\`diff\n${diff}\n\`\`\``;
|
|
133
|
+
emit({
|
|
134
|
+
step: 'consensus-start',
|
|
135
|
+
message: `Launching ${models.length} model votes in parallel`,
|
|
136
|
+
detail: models.map((m) => ` → ${m.provider}/${m.model} (stance: ${m.stance})`).join('\n'),
|
|
137
|
+
});
|
|
138
|
+
// ── Step 1: Run all model votes in parallel ────────────────
|
|
139
|
+
const votePromises = models.map(async (config) => {
|
|
140
|
+
const system = [
|
|
141
|
+
STANCE_PROMPTS[config.stance],
|
|
142
|
+
staticContext,
|
|
143
|
+
buildMemoryContext(memoryContext),
|
|
144
|
+
stackHints,
|
|
145
|
+
]
|
|
146
|
+
.filter(Boolean)
|
|
147
|
+
.join('\n');
|
|
148
|
+
const languageModel = createModel(config.provider, config.model, config.apiKey);
|
|
149
|
+
const result = await generateText({
|
|
150
|
+
model: languageModel,
|
|
151
|
+
system,
|
|
152
|
+
prompt: userPrompt,
|
|
153
|
+
temperature: 0.3,
|
|
154
|
+
});
|
|
155
|
+
const tokensUsed = (result.usage?.promptTokens ?? 0) + (result.usage?.completionTokens ?? 0);
|
|
156
|
+
return {
|
|
157
|
+
vote: parseVote(result.text, config.provider, config.model, config.stance),
|
|
158
|
+
tokensUsed,
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
const results = await Promise.allSettled(votePromises);
|
|
162
|
+
// ── Step 2: Collect votes and token usage ──────────────────
|
|
163
|
+
const votes = [];
|
|
164
|
+
let totalTokens = 0;
|
|
165
|
+
for (let i = 0; i < results.length; i++) {
|
|
166
|
+
const result = results[i];
|
|
167
|
+
const config = models[i];
|
|
168
|
+
if (result.status === 'fulfilled') {
|
|
169
|
+
votes.push(result.value.vote);
|
|
170
|
+
totalTokens += result.value.tokensUsed;
|
|
171
|
+
const v = result.value.vote;
|
|
172
|
+
emit({
|
|
173
|
+
step: `vote-${config.stance}`,
|
|
174
|
+
message: `✓ ${config.stance} (${config.provider}/${config.model}) → ${v.decision} (${(v.confidence * 100).toFixed(0)}% confidence)`,
|
|
175
|
+
detail: v.reasoning,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
const reason = result.reason instanceof Error ? result.reason.message : String(result.reason);
|
|
180
|
+
console.warn('[ghagga] Consensus model failed:', reason);
|
|
181
|
+
emit({
|
|
182
|
+
step: `vote-${config.stance}`,
|
|
183
|
+
message: `✗ ${config.stance} (${config.provider}/${config.model}) — FAILED: ${reason}`,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
emit({ step: 'consensus-voting', message: 'Calculating weighted consensus...' });
|
|
188
|
+
// ── Step 3: Calculate consensus ────────────────────────────
|
|
189
|
+
const { status, summary } = calculateConsensus(votes);
|
|
190
|
+
const executionTimeMs = Date.now() - startTime;
|
|
191
|
+
// Build detailed reasoning from all votes
|
|
192
|
+
const voteDetails = votes
|
|
193
|
+
.map((v) => `[${v.provider}/${v.model}] Stance: ${v.stance} | Decision: ${v.decision} | Confidence: ${v.confidence}\n${v.reasoning}`)
|
|
194
|
+
.join('\n\n---\n\n');
|
|
195
|
+
return {
|
|
196
|
+
status,
|
|
197
|
+
summary: `${summary}\n\n## Individual Votes\n\n${voteDetails}`,
|
|
198
|
+
findings: [], // Consensus mode produces votes, not individual findings
|
|
199
|
+
staticAnalysis: {
|
|
200
|
+
semgrep: { status: 'skipped', findings: [], executionTimeMs: 0 },
|
|
201
|
+
trivy: { status: 'skipped', findings: [], executionTimeMs: 0 },
|
|
202
|
+
cpd: { status: 'skipped', findings: [], executionTimeMs: 0 },
|
|
203
|
+
},
|
|
204
|
+
memoryContext,
|
|
205
|
+
metadata: {
|
|
206
|
+
mode: 'consensus',
|
|
207
|
+
provider: votes[0]?.provider ?? models[0].provider,
|
|
208
|
+
model: votes[0]?.model ?? models[0].model,
|
|
209
|
+
tokensUsed: totalTokens,
|
|
210
|
+
executionTimeMs,
|
|
211
|
+
toolsRun: [],
|
|
212
|
+
toolsSkipped: [],
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
//# sourceMappingURL=consensus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consensus.js","sourceRoot":"","sources":["../../src/agents/consensus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AA4BtB,mEAAmE;AAEnE,oEAAoE;AACpE,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAE/B,6EAA6E;AAC7E,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAErC,kCAAkC;AAClC,MAAM,cAAc,GAAoC;IACtD,GAAG,EAAE,oBAAoB;IACzB,OAAO,EAAE,wBAAwB;IACjC,OAAO,EAAE,wBAAwB;CAClC,CAAC;AAEF,mEAAmE;AAEnE;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CACvB,IAAY,EACZ,QAAqB,EACrB,KAAa,EACb,MAAuB;IAEvB,mBAAmB;IACnB,MAAM,aAAa,GAAG,uCAAuC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzE,MAAM,QAAQ,GAAG,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,SAAS,CAA8B,CAAC;IAE/F,qBAAqB;IACrB,MAAM,eAAe,GAAG,yBAAyB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7D,IAAI,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IACzE,UAAU,GAAG,IAAI,CAAC,GAAG,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,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,EAAE,eAAe,EAAE,CAAC,EAAE;YAC9D,GAAG,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,EAAE,eAAe,EAAE,CAAC,EAAE;SAC7D;QACD,aAAa;QACb,QAAQ,EAAE;YACR,IAAI,EAAE,WAAW;YACjB,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,QAAQ,IAAI,MAAM,CAAC,CAAC,CAAE,CAAC,QAAQ;YACnD,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,MAAM,CAAC,CAAC,CAAE,CAAC,KAAK;YAC1C,UAAU,EAAE,WAAW;YACvB,eAAe;YACf,QAAQ,EAAE,EAAE;YACZ,YAAY,EAAE,EAAE;SACjB;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent prompts for all review modes.
|
|
3
|
+
* Rescued and refined from GHAGGA v1.
|
|
4
|
+
*/
|
|
5
|
+
export declare const SIMPLE_REVIEW_SYSTEM = "You are an expert code reviewer. Analyze the provided code changes and provide a thorough review.\n\n1. Check for bugs, logic errors, and potential runtime issues\n2. Verify proper error handling and edge cases\n3. Assess code quality, readability, and maintainability\n4. Identify security vulnerabilities (SQL injection, XSS, auth issues, etc.)\n5. Evaluate performance implications\n6. Check adherence to the repository's coding standards and rules\n\nFormat your response EXACTLY as:\n\nSTATUS: [PASSED or FAILED]\nSUMMARY: [2-3 sentence summary of the review]\nFINDINGS:\n- SEVERITY: [critical|high|medium|low|info]\n CATEGORY: [security|performance|bug|style|error-handling|maintainability]\n FILE: [file path]\n LINE: [line number or \"N/A\"]\n MESSAGE: [clear description of the issue]\n SUGGESTION: [specific fix or improvement]\n\nIf there are no issues, return STATUS: PASSED with an empty FINDINGS section.\nFAILED if: Any critical issues, or 3+ high issues. PASSED otherwise.";
|
|
6
|
+
export declare const WORKFLOW_SCOPE_SYSTEM = "You analyze code scope. Identify what files are changed, affected modules, and dependencies.\n\nYour task:\n1. List all modified files and their purposes\n2. Identify which modules/components are affected\n3. Map out dependencies that might be impacted\n4. Assess the overall scope (small, medium, large)\n\nOutput format:\n- Changed Files: [list files with brief descriptions]\n- Affected Modules: [list modules]\n- Dependencies: [list impacted dependencies]\n- Scope Assessment: [small/medium/large with reasoning]";
|
|
7
|
+
export declare const WORKFLOW_STANDARDS_SYSTEM = "You enforce coding standards. Check naming conventions, formatting, and DRY violations.\n\nYour task:\n1. Check naming conventions (variables, functions, classes)\n2. Verify code formatting and consistency\n3. Identify DRY (Don't Repeat Yourself) violations\n4. Check for proper documentation/comments\n5. Verify import organization\n\nOutput format:\n- Naming Issues: [list any naming convention violations]\n- Formatting Issues: [list formatting problems]\n- DRY Violations: [list duplicated code/logic]\n- Documentation: [note missing or poor documentation]\n- Recommendations: [specific suggestions for improvement]";
|
|
8
|
+
export declare const WORKFLOW_ERRORS_SYSTEM = "You are a defensive programming expert. Check null handling, edge cases, and error messages.\n\nYour task:\n1. Check for proper null/undefined handling\n2. Identify missing edge case handling\n3. Review error messages for clarity and usefulness\n4. Check try/catch usage and error propagation\n5. Verify input validation\n\nOutput format:\n- Null Safety Issues: [list potential null/undefined problems]\n- Edge Cases: [list unhandled edge cases]\n- Error Messages: [review of error message quality]\n- Exception Handling: [issues with try/catch or error propagation]\n- Input Validation: [missing or weak validation]";
|
|
9
|
+
export declare const WORKFLOW_SECURITY_SYSTEM = "You are a security auditor. Check SQL injection, XSS, auth flaws, and data exposure.\n\nYour task:\n1. Check for SQL injection vulnerabilities\n2. Identify XSS (Cross-Site Scripting) risks\n3. Review authentication/authorization logic\n4. Check for sensitive data exposure\n5. Identify insecure dependencies or patterns\n\nOutput format:\n- SQL Injection: [any vulnerabilities found]\n- XSS Risks: [cross-site scripting issues]\n- Auth Issues: [authentication/authorization problems]\n- Data Exposure: [sensitive data handling issues]\n- Security Recommendations: [specific security improvements]\n\nSEVERITY LEVELS: CRITICAL, HIGH, MEDIUM, LOW";
|
|
10
|
+
export declare const WORKFLOW_PERFORMANCE_SYSTEM = "You are a performance engineer. Check algorithm complexity, N+1 queries, memory leaks.\n\nYour task:\n1. Analyze algorithm complexity (time and space)\n2. Identify N+1 query problems\n3. Check for potential memory leaks\n4. Review resource usage patterns\n5. Identify unnecessary computations\n\nOutput format:\n- Complexity Issues: [O(n) analysis and concerns]\n- Database Issues: [N+1 queries, missing indexes]\n- Memory Concerns: [potential leaks or excessive usage]\n- Resource Usage: [inefficient patterns]\n- Performance Recommendations: [specific optimizations]";
|
|
11
|
+
export declare const WORKFLOW_SYNTHESIS_SYSTEM = "Synthesize all findings into a final unified review. You received findings from 5 specialist reviewers: Scope Analysis, Coding Standards, Error Handling, Security Audit, and Performance Review.\n\nYour task:\n1. Combine all findings into a unified report\n2. Remove duplicate issues mentioned by multiple reviewers\n3. Prioritize by severity: CRITICAL > HIGH > MEDIUM > LOW\n4. Determine final status\n\nFormat your response EXACTLY as:\n\nSTATUS: [PASSED or FAILED]\nSUMMARY: [2-3 sentence overview]\nFINDINGS:\n- SEVERITY: [critical|high|medium|low|info]\n CATEGORY: [security|performance|bug|style|error-handling|maintainability]\n FILE: [file path]\n LINE: [line number or \"N/A\"]\n MESSAGE: [clear description]\n SUGGESTION: [specific fix]\n\nFAILED if: Any critical issues, or more than 3 high issues.\nPASSED if: No critical issues and 3 or fewer high issues.";
|
|
12
|
+
export declare const CONSENSUS_FOR_SYSTEM = "You are reviewing code changes. Argue strongly IN FAVOR of approving this code.\n\nFocus on:\n- Benefits and improvements the code brings\n- Problems it solves correctly\n- Sound architectural decisions\n- Good practices followed\n\nProvide your assessment as:\nDECISION: [approve|reject|abstain]\nCONFIDENCE: [0.0 to 1.0]\nREASONING: [detailed reasoning for your stance]";
|
|
13
|
+
export declare const CONSENSUS_AGAINST_SYSTEM = "You are reviewing code changes. Argue AGAINST approving this code.\n\nFocus on:\n- Potential bugs and logic errors\n- Security vulnerabilities\n- Performance concerns\n- Maintainability issues\n- Missing tests or edge cases\n\nProvide your assessment as:\nDECISION: [approve|reject|abstain]\nCONFIDENCE: [0.0 to 1.0]\nREASONING: [detailed reasoning for your stance]";
|
|
14
|
+
export declare const CONSENSUS_NEUTRAL_SYSTEM = "You are reviewing code changes. Provide a BALANCED, neutral analysis.\n\nConsider both:\n- Benefits and improvements the code brings\n- Potential issues and risks\n\nProvide your assessment as:\nDECISION: [approve|reject|abstain]\nCONFIDENCE: [0.0 to 1.0]\nREASONING: [balanced analysis of pros and cons]";
|
|
15
|
+
export declare function buildStaticAnalysisContext(staticFindings: string): string;
|
|
16
|
+
export declare function buildMemoryContext(memoryContext: string | null): string;
|
|
17
|
+
export declare function buildStackHints(stacks: string[]): string;
|
|
18
|
+
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../src/agents/prompts.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,eAAO,MAAM,oBAAoB,s+BAsBoC,CAAC;AAItE,eAAO,MAAM,qBAAqB,ygBAYsB,CAAC;AAEzD,eAAO,MAAM,yBAAyB,gnBAcoB,CAAC;AAE3D,eAAO,MAAM,sBAAsB,6mBAcc,CAAC;AAElD,eAAO,MAAM,wBAAwB,yoBAgBQ,CAAC;AAE9C,eAAO,MAAM,2BAA2B,6jBAcgB,CAAC;AAEzD,eAAO,MAAM,yBAAyB,62BAqBoB,CAAC;AAI3D,eAAO,MAAM,oBAAoB,wXAWe,CAAC;AAEjD,eAAO,MAAM,wBAAwB,kXAYW,CAAC;AAEjD,eAAO,MAAM,wBAAwB,qTASW,CAAC;AAIjD,wBAAgB,0BAA0B,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAGzE;AAED,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAGvE;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAoBxD"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent prompts for all review modes.
|
|
3
|
+
* Rescued and refined from GHAGGA v1.
|
|
4
|
+
*/
|
|
5
|
+
// ─── Simple Review ──────────────────────────────────────────────
|
|
6
|
+
export const SIMPLE_REVIEW_SYSTEM = `You are an expert code reviewer. Analyze the provided code changes and provide a thorough review.
|
|
7
|
+
|
|
8
|
+
1. Check for bugs, logic errors, and potential runtime issues
|
|
9
|
+
2. Verify proper error handling and edge cases
|
|
10
|
+
3. Assess code quality, readability, and maintainability
|
|
11
|
+
4. Identify security vulnerabilities (SQL injection, XSS, auth issues, etc.)
|
|
12
|
+
5. Evaluate performance implications
|
|
13
|
+
6. Check adherence to the repository's coding standards and rules
|
|
14
|
+
|
|
15
|
+
Format your response EXACTLY as:
|
|
16
|
+
|
|
17
|
+
STATUS: [PASSED or FAILED]
|
|
18
|
+
SUMMARY: [2-3 sentence summary of the review]
|
|
19
|
+
FINDINGS:
|
|
20
|
+
- SEVERITY: [critical|high|medium|low|info]
|
|
21
|
+
CATEGORY: [security|performance|bug|style|error-handling|maintainability]
|
|
22
|
+
FILE: [file path]
|
|
23
|
+
LINE: [line number or "N/A"]
|
|
24
|
+
MESSAGE: [clear description of the issue]
|
|
25
|
+
SUGGESTION: [specific fix or improvement]
|
|
26
|
+
|
|
27
|
+
If there are no issues, return STATUS: PASSED with an empty FINDINGS section.
|
|
28
|
+
FAILED if: Any critical issues, or 3+ high issues. PASSED otherwise.`;
|
|
29
|
+
// ─── Workflow Specialists ───────────────────────────────────────
|
|
30
|
+
export const WORKFLOW_SCOPE_SYSTEM = `You analyze code scope. Identify what files are changed, affected modules, and dependencies.
|
|
31
|
+
|
|
32
|
+
Your task:
|
|
33
|
+
1. List all modified files and their purposes
|
|
34
|
+
2. Identify which modules/components are affected
|
|
35
|
+
3. Map out dependencies that might be impacted
|
|
36
|
+
4. Assess the overall scope (small, medium, large)
|
|
37
|
+
|
|
38
|
+
Output format:
|
|
39
|
+
- Changed Files: [list files with brief descriptions]
|
|
40
|
+
- Affected Modules: [list modules]
|
|
41
|
+
- Dependencies: [list impacted dependencies]
|
|
42
|
+
- Scope Assessment: [small/medium/large with reasoning]`;
|
|
43
|
+
export const WORKFLOW_STANDARDS_SYSTEM = `You enforce coding standards. Check naming conventions, formatting, and DRY violations.
|
|
44
|
+
|
|
45
|
+
Your task:
|
|
46
|
+
1. Check naming conventions (variables, functions, classes)
|
|
47
|
+
2. Verify code formatting and consistency
|
|
48
|
+
3. Identify DRY (Don't Repeat Yourself) violations
|
|
49
|
+
4. Check for proper documentation/comments
|
|
50
|
+
5. Verify import organization
|
|
51
|
+
|
|
52
|
+
Output format:
|
|
53
|
+
- Naming Issues: [list any naming convention violations]
|
|
54
|
+
- Formatting Issues: [list formatting problems]
|
|
55
|
+
- DRY Violations: [list duplicated code/logic]
|
|
56
|
+
- Documentation: [note missing or poor documentation]
|
|
57
|
+
- Recommendations: [specific suggestions for improvement]`;
|
|
58
|
+
export const WORKFLOW_ERRORS_SYSTEM = `You are a defensive programming expert. Check null handling, edge cases, and error messages.
|
|
59
|
+
|
|
60
|
+
Your task:
|
|
61
|
+
1. Check for proper null/undefined handling
|
|
62
|
+
2. Identify missing edge case handling
|
|
63
|
+
3. Review error messages for clarity and usefulness
|
|
64
|
+
4. Check try/catch usage and error propagation
|
|
65
|
+
5. Verify input validation
|
|
66
|
+
|
|
67
|
+
Output format:
|
|
68
|
+
- Null Safety Issues: [list potential null/undefined problems]
|
|
69
|
+
- Edge Cases: [list unhandled edge cases]
|
|
70
|
+
- Error Messages: [review of error message quality]
|
|
71
|
+
- Exception Handling: [issues with try/catch or error propagation]
|
|
72
|
+
- Input Validation: [missing or weak validation]`;
|
|
73
|
+
export const WORKFLOW_SECURITY_SYSTEM = `You are a security auditor. Check SQL injection, XSS, auth flaws, and data exposure.
|
|
74
|
+
|
|
75
|
+
Your task:
|
|
76
|
+
1. Check for SQL injection vulnerabilities
|
|
77
|
+
2. Identify XSS (Cross-Site Scripting) risks
|
|
78
|
+
3. Review authentication/authorization logic
|
|
79
|
+
4. Check for sensitive data exposure
|
|
80
|
+
5. Identify insecure dependencies or patterns
|
|
81
|
+
|
|
82
|
+
Output format:
|
|
83
|
+
- SQL Injection: [any vulnerabilities found]
|
|
84
|
+
- XSS Risks: [cross-site scripting issues]
|
|
85
|
+
- Auth Issues: [authentication/authorization problems]
|
|
86
|
+
- Data Exposure: [sensitive data handling issues]
|
|
87
|
+
- Security Recommendations: [specific security improvements]
|
|
88
|
+
|
|
89
|
+
SEVERITY LEVELS: CRITICAL, HIGH, MEDIUM, LOW`;
|
|
90
|
+
export const WORKFLOW_PERFORMANCE_SYSTEM = `You are a performance engineer. Check algorithm complexity, N+1 queries, memory leaks.
|
|
91
|
+
|
|
92
|
+
Your task:
|
|
93
|
+
1. Analyze algorithm complexity (time and space)
|
|
94
|
+
2. Identify N+1 query problems
|
|
95
|
+
3. Check for potential memory leaks
|
|
96
|
+
4. Review resource usage patterns
|
|
97
|
+
5. Identify unnecessary computations
|
|
98
|
+
|
|
99
|
+
Output format:
|
|
100
|
+
- Complexity Issues: [O(n) analysis and concerns]
|
|
101
|
+
- Database Issues: [N+1 queries, missing indexes]
|
|
102
|
+
- Memory Concerns: [potential leaks or excessive usage]
|
|
103
|
+
- Resource Usage: [inefficient patterns]
|
|
104
|
+
- Performance Recommendations: [specific optimizations]`;
|
|
105
|
+
export const WORKFLOW_SYNTHESIS_SYSTEM = `Synthesize all findings into a final unified review. You received findings from 5 specialist reviewers: Scope Analysis, Coding Standards, Error Handling, Security Audit, and Performance Review.
|
|
106
|
+
|
|
107
|
+
Your task:
|
|
108
|
+
1. Combine all findings into a unified report
|
|
109
|
+
2. Remove duplicate issues mentioned by multiple reviewers
|
|
110
|
+
3. Prioritize by severity: CRITICAL > HIGH > MEDIUM > LOW
|
|
111
|
+
4. Determine final status
|
|
112
|
+
|
|
113
|
+
Format your response EXACTLY as:
|
|
114
|
+
|
|
115
|
+
STATUS: [PASSED or FAILED]
|
|
116
|
+
SUMMARY: [2-3 sentence overview]
|
|
117
|
+
FINDINGS:
|
|
118
|
+
- SEVERITY: [critical|high|medium|low|info]
|
|
119
|
+
CATEGORY: [security|performance|bug|style|error-handling|maintainability]
|
|
120
|
+
FILE: [file path]
|
|
121
|
+
LINE: [line number or "N/A"]
|
|
122
|
+
MESSAGE: [clear description]
|
|
123
|
+
SUGGESTION: [specific fix]
|
|
124
|
+
|
|
125
|
+
FAILED if: Any critical issues, or more than 3 high issues.
|
|
126
|
+
PASSED if: No critical issues and 3 or fewer high issues.`;
|
|
127
|
+
// ─── Consensus Stances ──────────────────────────────────────────
|
|
128
|
+
export const CONSENSUS_FOR_SYSTEM = `You are reviewing code changes. Argue strongly IN FAVOR of approving this code.
|
|
129
|
+
|
|
130
|
+
Focus on:
|
|
131
|
+
- Benefits and improvements the code brings
|
|
132
|
+
- Problems it solves correctly
|
|
133
|
+
- Sound architectural decisions
|
|
134
|
+
- Good practices followed
|
|
135
|
+
|
|
136
|
+
Provide your assessment as:
|
|
137
|
+
DECISION: [approve|reject|abstain]
|
|
138
|
+
CONFIDENCE: [0.0 to 1.0]
|
|
139
|
+
REASONING: [detailed reasoning for your stance]`;
|
|
140
|
+
export const CONSENSUS_AGAINST_SYSTEM = `You are reviewing code changes. Argue AGAINST approving this code.
|
|
141
|
+
|
|
142
|
+
Focus on:
|
|
143
|
+
- Potential bugs and logic errors
|
|
144
|
+
- Security vulnerabilities
|
|
145
|
+
- Performance concerns
|
|
146
|
+
- Maintainability issues
|
|
147
|
+
- Missing tests or edge cases
|
|
148
|
+
|
|
149
|
+
Provide your assessment as:
|
|
150
|
+
DECISION: [approve|reject|abstain]
|
|
151
|
+
CONFIDENCE: [0.0 to 1.0]
|
|
152
|
+
REASONING: [detailed reasoning for your stance]`;
|
|
153
|
+
export const CONSENSUS_NEUTRAL_SYSTEM = `You are reviewing code changes. Provide a BALANCED, neutral analysis.
|
|
154
|
+
|
|
155
|
+
Consider both:
|
|
156
|
+
- Benefits and improvements the code brings
|
|
157
|
+
- Potential issues and risks
|
|
158
|
+
|
|
159
|
+
Provide your assessment as:
|
|
160
|
+
DECISION: [approve|reject|abstain]
|
|
161
|
+
CONFIDENCE: [0.0 to 1.0]
|
|
162
|
+
REASONING: [balanced analysis of pros and cons]`;
|
|
163
|
+
// ─── Context Injection Templates ────────────────────────────────
|
|
164
|
+
export function buildStaticAnalysisContext(staticFindings) {
|
|
165
|
+
if (!staticFindings)
|
|
166
|
+
return '';
|
|
167
|
+
return `\n\n${staticFindings}\n`;
|
|
168
|
+
}
|
|
169
|
+
export function buildMemoryContext(memoryContext) {
|
|
170
|
+
if (!memoryContext)
|
|
171
|
+
return '';
|
|
172
|
+
return `\n\n## Past Review Memory (learned from previous reviews)\n\n${memoryContext}\n\n> Use these past observations to give more informed, context-aware reviews.\n`;
|
|
173
|
+
}
|
|
174
|
+
export function buildStackHints(stacks) {
|
|
175
|
+
if (stacks.length === 0)
|
|
176
|
+
return '';
|
|
177
|
+
const hints = {
|
|
178
|
+
typescript: 'Pay attention to type safety, strict null checks, and proper generic usage.',
|
|
179
|
+
javascript: 'Check for implicit type coercion, prototype pollution, and async/await patterns.',
|
|
180
|
+
react: 'Review hooks usage, component re-renders, key props, and effect cleanup.',
|
|
181
|
+
python: 'Check type hints, proper exception handling, and PEP 8 compliance.',
|
|
182
|
+
java: 'Review null safety, resource management (try-with-resources), and thread safety.',
|
|
183
|
+
go: 'Check error handling patterns, goroutine leaks, and defer usage.',
|
|
184
|
+
rust: 'Review ownership patterns, unsafe blocks, and error handling with Result/Option.',
|
|
185
|
+
sql: 'Check for injection risks, missing indexes, and N+1 query patterns.',
|
|
186
|
+
};
|
|
187
|
+
const relevant = stacks
|
|
188
|
+
.map((s) => hints[s.toLowerCase()])
|
|
189
|
+
.filter(Boolean);
|
|
190
|
+
if (relevant.length === 0)
|
|
191
|
+
return '';
|
|
192
|
+
return `\n\n## Stack-Specific Review Hints\n\n${relevant.map((h) => `- ${h}`).join('\n')}\n`;
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=prompts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../src/agents/prompts.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,mEAAmE;AAEnE,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;;;;;;;;qEAsBiC,CAAC;AAEtE,mEAAmE;AAEnE,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;;;;;;;wDAYmB,CAAC;AAEzD,MAAM,CAAC,MAAM,yBAAyB,GAAG;;;;;;;;;;;;;;0DAciB,CAAC;AAE3D,MAAM,CAAC,MAAM,sBAAsB,GAAG;;;;;;;;;;;;;;iDAcW,CAAC;AAElD,MAAM,CAAC,MAAM,wBAAwB,GAAG;;;;;;;;;;;;;;;;6CAgBK,CAAC;AAE9C,MAAM,CAAC,MAAM,2BAA2B,GAAG;;;;;;;;;;;;;;wDAca,CAAC;AAEzD,MAAM,CAAC,MAAM,yBAAyB,GAAG;;;;;;;;;;;;;;;;;;;;;0DAqBiB,CAAC;AAE3D,mEAAmE;AAEnE,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;;;;;;;;gDAWY,CAAC;AAEjD,MAAM,CAAC,MAAM,wBAAwB,GAAG;;;;;;;;;;;;gDAYQ,CAAC;AAEjD,MAAM,CAAC,MAAM,wBAAwB,GAAG;;;;;;;;;gDASQ,CAAC;AAEjD,mEAAmE;AAEnE,MAAM,UAAU,0BAA0B,CAAC,cAAsB;IAC/D,IAAI,CAAC,cAAc;QAAE,OAAO,EAAE,CAAC;IAC/B,OAAO,OAAO,cAAc,IAAI,CAAC;AACnC,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,aAA4B;IAC7D,IAAI,CAAC,aAAa;QAAE,OAAO,EAAE,CAAC;IAC9B,OAAO,gEAAgE,aAAa,mFAAmF,CAAC;AAC1K,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,MAAgB;IAC9C,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAEnC,MAAM,KAAK,GAA2B;QACpC,UAAU,EAAE,6EAA6E;QACzF,UAAU,EAAE,kFAAkF;QAC9F,KAAK,EAAE,0EAA0E;QACjF,MAAM,EAAE,oEAAoE;QAC5E,IAAI,EAAE,kFAAkF;QACxF,EAAE,EAAE,kEAAkE;QACtE,IAAI,EAAE,kFAAkF;QACxF,GAAG,EAAE,qEAAqE;KAC3E,CAAC;IAEF,MAAM,QAAQ,GAAG,MAAM;SACpB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;SAClC,MAAM,CAAC,OAAO,CAAC,CAAC;IAEnB,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACrC,OAAO,yCAAyC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AAC/F,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple review agent.
|
|
3
|
+
*
|
|
4
|
+
* Runs a single LLM call with the full diff and context.
|
|
5
|
+
* Best for small-to-medium PRs where parallel specialists
|
|
6
|
+
* would be overkill.
|
|
7
|
+
*/
|
|
8
|
+
import type { LLMProvider, ProgressCallback, ReviewResult, ReviewFinding } from '../types.js';
|
|
9
|
+
export interface SimpleReviewInput {
|
|
10
|
+
diff: string;
|
|
11
|
+
provider: LLMProvider;
|
|
12
|
+
model: string;
|
|
13
|
+
apiKey: string;
|
|
14
|
+
staticContext: string;
|
|
15
|
+
memoryContext: string | null;
|
|
16
|
+
stackHints: string;
|
|
17
|
+
onProgress?: ProgressCallback;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Parse the structured LLM response into a ReviewResult.
|
|
21
|
+
*
|
|
22
|
+
* Extracts STATUS, SUMMARY, and FINDINGS sections using regex
|
|
23
|
+
* patterns that match the format defined in SIMPLE_REVIEW_SYSTEM.
|
|
24
|
+
*/
|
|
25
|
+
declare function parseReviewResponse(text: string, provider: LLMProvider, model: string, tokensUsed: number, executionTimeMs: number, memoryContext: string | null): ReviewResult;
|
|
26
|
+
/**
|
|
27
|
+
* Parse the FINDINGS block from the LLM response.
|
|
28
|
+
*
|
|
29
|
+
* Each finding follows this format:
|
|
30
|
+
* - SEVERITY: critical
|
|
31
|
+
* CATEGORY: security
|
|
32
|
+
* FILE: src/auth.ts
|
|
33
|
+
* LINE: 42
|
|
34
|
+
* MESSAGE: SQL injection vulnerability
|
|
35
|
+
* SUGGESTION: Use parameterized queries
|
|
36
|
+
*/
|
|
37
|
+
declare function parseFindingsBlock(text: string): ReviewFinding[];
|
|
38
|
+
/**
|
|
39
|
+
* Run a simple (single-pass) code review.
|
|
40
|
+
*
|
|
41
|
+
* Combines the system prompt with all context layers (static analysis,
|
|
42
|
+
* memory, stack hints) and the diff into a single LLM call.
|
|
43
|
+
*
|
|
44
|
+
* @param input - Review input with diff, provider config, and context
|
|
45
|
+
* @returns Parsed ReviewResult
|
|
46
|
+
*/
|
|
47
|
+
export declare function runSimpleReview(input: SimpleReviewInput): Promise<ReviewResult>;
|
|
48
|
+
export { parseReviewResponse, parseFindingsBlock };
|
|
49
|
+
//# sourceMappingURL=simple.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simple.d.ts","sourceRoot":"","sources":["../../src/agents/simple.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAUH,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,aAAa,EAId,MAAM,aAAa,CAAC;AAIrB,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,WAAW,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC/B;AAaD;;;;;GAKG;AACH,iBAAS,mBAAmB,CAC1B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,WAAW,EACrB,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EAClB,eAAe,EAAE,MAAM,EACvB,aAAa,EAAE,MAAM,GAAG,IAAI,GAC3B,YAAY,CAgCd;AAED;;;;;;;;;;GAUG;AACH,iBAAS,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CA2BzD;AAID;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAkDrF;AAGD,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,CAAC"}
|