@contextrail/code-review-agent 0.1.2-alpha.1 → 0.1.2-alpha.3
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/dist/config/index.d.ts +8 -0
- package/dist/orchestrator/agentic-orchestrator.d.ts +4 -5
- package/dist/orchestrator/agentic-orchestrator.js +9 -13
- package/dist/orchestrator/writer.js +1 -1
- package/dist/output/aggregator.d.ts +2 -1
- package/dist/output/aggregator.js +3 -12
- package/dist/output/schema.d.ts +86 -86
- package/dist/pipeline.js +11 -2
- package/dist/prompts/blocks.d.ts +25 -0
- package/dist/prompts/blocks.js +129 -0
- package/dist/prompts/decision.d.ts +15 -0
- package/dist/prompts/decision.js +30 -0
- package/dist/prompts/index.d.ts +5 -0
- package/dist/prompts/index.js +5 -0
- package/dist/{orchestrator/prompts.d.ts → prompts/orchestrator.d.ts} +2 -3
- package/dist/{orchestrator/prompts.js → prompts/orchestrator.js} +2 -3
- package/dist/prompts/reviewer.d.ts +12 -0
- package/dist/prompts/reviewer.js +107 -0
- package/dist/{output/prompts.d.ts → prompts/synthesis.d.ts} +1 -16
- package/dist/{output/prompts.js → prompts/synthesis.js} +0 -30
- package/dist/reviewers/executor.d.ts +4 -5
- package/dist/reviewers/executor.js +1 -8
- package/dist/reviewers/prompt.d.ts +2 -28
- package/dist/reviewers/prompt.js +5 -235
- package/package.json +1 -1
package/dist/pipeline.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { DEFAULT_ORCHESTRATOR_MODEL, DEFAULT_REVIEWER_MODEL } from './config/defaults.js';
|
|
3
3
|
import { McpClient } from './mcp/client.js';
|
|
4
|
+
import { createLlmService } from './llm/factory.js';
|
|
4
5
|
import { buildReviewInputs, triagePr } from './review-inputs/index.js';
|
|
5
6
|
import { runOrchestrator } from './orchestrator/agentic-orchestrator.js';
|
|
6
7
|
import { runReviewerLoop } from './reviewers/executor.js';
|
|
@@ -29,6 +30,12 @@ export const runReview = async (input) => {
|
|
|
29
30
|
logger: log,
|
|
30
31
|
});
|
|
31
32
|
onMcpClientReady?.(mcpClient);
|
|
33
|
+
// Create a single LLM service instance for the entire pipeline
|
|
34
|
+
const { service: llmService } = createLlmService({
|
|
35
|
+
openRouterApiKey: config.openRouterApiKey,
|
|
36
|
+
mcpClient,
|
|
37
|
+
logger: log,
|
|
38
|
+
});
|
|
32
39
|
try {
|
|
33
40
|
try {
|
|
34
41
|
await mcpClient.connect();
|
|
@@ -91,6 +98,7 @@ export const runReview = async (input) => {
|
|
|
91
98
|
}
|
|
92
99
|
const orchestratorOutput = await runOrchestrator(inputs, outputDir, {
|
|
93
100
|
mcpClient,
|
|
101
|
+
llmService,
|
|
94
102
|
config: {
|
|
95
103
|
openRouterApiKey: config.openRouterApiKey,
|
|
96
104
|
orchestratorModel: config.orchestratorModel ?? DEFAULT_ORCHESTRATOR_MODEL,
|
|
@@ -111,6 +119,7 @@ export const runReview = async (input) => {
|
|
|
111
119
|
try {
|
|
112
120
|
const rawFindings = await runReviewerLoop(reviewer, inputs, orchestratorOutput.understanding, outputDir, {
|
|
113
121
|
mcpClient,
|
|
122
|
+
llmService,
|
|
114
123
|
config: {
|
|
115
124
|
openRouterApiKey: config.openRouterApiKey,
|
|
116
125
|
reviewerModel: config.reviewerModel ?? DEFAULT_REVIEWER_MODEL,
|
|
@@ -196,7 +205,7 @@ export const runReview = async (input) => {
|
|
|
196
205
|
// Synthesize findings across reviewers (deduplication, contradictions, compound risks)
|
|
197
206
|
log.info(`Synthesis pass starting (model: ${config.orchestratorModel ?? DEFAULT_ORCHESTRATOR_MODEL}, reviewers: ${reviewerResults.length})`);
|
|
198
207
|
const synthesisResult = await synthesizeFindings(reviewerResults, {
|
|
199
|
-
|
|
208
|
+
llmService,
|
|
200
209
|
model: config.orchestratorModel ?? DEFAULT_ORCHESTRATOR_MODEL,
|
|
201
210
|
maxSteps: config.aggregationMaxSteps,
|
|
202
211
|
logger: log,
|
|
@@ -213,7 +222,7 @@ export const runReview = async (input) => {
|
|
|
213
222
|
// Generate review decision based on synthesized findings
|
|
214
223
|
log.info(`Decision pass starting (model: ${config.orchestratorModel ?? DEFAULT_ORCHESTRATOR_MODEL}, synthesis findings: ${synthesisResult.synthesis.findings.length})`);
|
|
215
224
|
const decisionResult = await generateReviewDecision(orchestratorOutput.understanding, synthesisResult.synthesis, {
|
|
216
|
-
|
|
225
|
+
llmService,
|
|
217
226
|
model: config.orchestratorModel ?? DEFAULT_ORCHESTRATOR_MODEL,
|
|
218
227
|
maxSteps: config.aggregationMaxSteps,
|
|
219
228
|
logger: log,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Severity calibration block with definitions and examples for each severity level.
|
|
3
|
+
* This block is injected into reviewer system prompts to ensure consistent severity assignment.
|
|
4
|
+
*/
|
|
5
|
+
export declare const SEVERITY_CALIBRATION_BLOCK = "\n## Severity Calibration\n\nYou must assign severity levels accurately based on the following definitions and examples:\n\n### Critical\n**Definition**: Blocks deployment, active exploit path, or data corruption risk. Findings that could lead to security breaches, data loss, or system compromise.\n\n**Examples**:\n- SQL injection vulnerability: `const query = `SELECT * FROM users WHERE id = ${userInput}`;` (user input directly interpolated)\n- Authentication bypass: `if (user.role === 'admin' || user.id === 1) { grantAccess(); }` (hardcoded admin check)\n- Missing input validation on sensitive operations: `await db.delete(userId);` (no validation that userId belongs to requester)\n\n**When to use**: Only when there is a clear exploit path or risk of data corruption/integrity violation.\n\n### Major\n**Definition**: Significant bug, breaks functionality, or violates established patterns. Findings that cause incorrect behavior or violate architectural standards.\n\n**Examples**:\n- Missing error handling: `const data = await fetch(url); return data.json();` (no try-catch, will crash on network error)\n- Tight coupling: `import { DatabaseConnection } from './db'; class UserService { private db = new DatabaseConnection(); }` (direct instantiation, violates dependency injection)\n- Race condition: `let count = 0; async function increment() { count++; await save(count); }` (non-atomic increment)\n\n**When to use**: When functionality is broken or architectural patterns are violated, but no immediate security/data risk.\n\n### Minor\n**Definition**: Code quality issue, convention violation, or maintainability concern. Findings that don't break functionality but reduce code quality.\n\n**Examples**:\n- Magic numbers: `if (user.age > 18) { ... }` (should be `const MIN_ADULT_AGE = 18`)\n- Inconsistent naming: `function getUserData() { ... }` but `function fetch_user_info() { ... }` (mixed naming conventions)\n- Missing JSDoc: `function calculateTotal(items) { ... }` (no documentation for complex logic)\n\n**When to use**: Code quality, readability, or maintainability issues that don't affect functionality.\n\n### Info\n**Definition**: Observation, suggestion, or educational note. Findings that provide helpful context or suggestions without indicating a problem.\n\n**Examples**:\n- Performance suggestion: `// Consider caching this query result if called frequently`\n- Pattern suggestion: `// This could use the Repository pattern for better testability`\n- Documentation opportunity: `// This algorithm implements the Fisher-Yates shuffle`\n\n**When to use**: Helpful suggestions or observations that don't indicate actual problems.\n";
|
|
6
|
+
/**
|
|
7
|
+
* Severity validation rules for critic pass (iteration 2+).
|
|
8
|
+
* These rules help the critic validate and potentially downgrade severity.
|
|
9
|
+
*/
|
|
10
|
+
export declare const SEVERITY_VALIDATION_RULES = "\n## Severity Validation Rules\n\nDuring the critic pass, validate each finding's severity against these rules:\n\n1. **Critical findings MUST have exploit path or data integrity evidence**\n - If a critical finding lacks a clear exploit path or data corruption risk described in the rationale, downgrade to major\n - Example: \"SQL injection\" without showing how user input reaches the query \u2192 downgrade to major\n\n2. **Major findings MUST demonstrate functional impact**\n - If a major finding doesn't show how functionality is broken or patterns violated, downgrade to minor\n - Example: \"Missing error handling\" without showing what breaks \u2192 downgrade to minor\n\n3. **Minor findings MUST indicate code quality impact**\n - If a minor finding is just a style preference without maintainability impact, consider downgrade to info\n - Example: \"Use const instead of let\" without explaining why \u2192 consider info\n\n4. **Downgrade rules**:\n - Critical \u2192 Major: No exploit path or data integrity risk described\n - Major \u2192 Minor: No functional impact demonstrated\n - Minor \u2192 Info: No code quality/maintainability impact shown\n\n5. **Never upgrade severity** - Only downgrade if evidence doesn't support the assigned level\n";
|
|
11
|
+
/**
|
|
12
|
+
* ContextRail tooling workflow requirements.
|
|
13
|
+
* Forces reviewers to ground findings in retrieved contexts instead of guessing IDs/titles.
|
|
14
|
+
*/
|
|
15
|
+
export declare const CONTEXTRAIL_TOOLING_BLOCK = "\n## ContextRail Standards Workflow (Required)\n\nWhen you identify potential issues, you MUST ground them in retrieved ContextRail standards:\n\n1. Use `search_contexts` first to discover relevant standards for this change.\n2. Use `get_context` for each context you plan to cite in findings.\n3. Use `resolve_dependencies` when cited contexts have required dependencies.\n4. Perform at least one `search_contexts` call before finalizing your findings.\n\nAttribution rules:\n- NEVER invent context IDs or titles.\n- Only include `contextIdsUsed`, `contextIdsViolated`, and `contextTitles` from contexts you actually retrieved.\n- If no relevant ContextRail standard exists after tool lookup, set those fields to `null` (not empty arrays) and explain that briefly in `rationale`.\n";
|
|
16
|
+
/**
|
|
17
|
+
* Compact output contract optimized for structured-output reliability.
|
|
18
|
+
* Keeps formatting constraints in one place for both standard and critic prompts.
|
|
19
|
+
*/
|
|
20
|
+
export declare const OUTPUT_CONTRACT_BLOCK = "\n## Output Contract (Strict)\n\nReturn a JSON object with:\n- `findings`: array\n- `validated`: boolean\n- `notes`: string | null\n\nFor each finding:\n- Required keys: `severity`, `title`, `description`, `rationale`\n- Optional-but-required-by-schema keys: `suggestedFix`, `file`, `line`, `endLine`, `contextIdsUsed`, `contextIdsViolated`, `contextTitles`\n\nSchema compatibility rules:\n- Include all keys (never omit)\n- Use `null` when a value is not available\n- Use `null` (not empty arrays) for context attribution fields when no standards apply\n";
|
|
21
|
+
/**
|
|
22
|
+
* Final guardrail checklist near generation point.
|
|
23
|
+
* Repeats only non-negotiables to reduce mid-prompt loss on long inputs.
|
|
24
|
+
*/
|
|
25
|
+
export declare const FINAL_CHECKLIST_BLOCK = "\n## Final Checklist (Must Pass)\n1. Every finding is supported by concrete code/diff evidence.\n2. ContextRail workflow was used (`search_contexts` -> `get_context` -> `resolve_dependencies` as needed).\n3. Context attribution fields only reference retrieved contexts (or are `null`).\n4. Severity is calibrated to evidence.\n5. Output strictly matches the JSON contract, and `notes` summarizes retrieved contexts (or none found).\n";
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Severity calibration block with definitions and examples for each severity level.
|
|
3
|
+
* This block is injected into reviewer system prompts to ensure consistent severity assignment.
|
|
4
|
+
*/
|
|
5
|
+
export const SEVERITY_CALIBRATION_BLOCK = `
|
|
6
|
+
## Severity Calibration
|
|
7
|
+
|
|
8
|
+
You must assign severity levels accurately based on the following definitions and examples:
|
|
9
|
+
|
|
10
|
+
### Critical
|
|
11
|
+
**Definition**: Blocks deployment, active exploit path, or data corruption risk. Findings that could lead to security breaches, data loss, or system compromise.
|
|
12
|
+
|
|
13
|
+
**Examples**:
|
|
14
|
+
- SQL injection vulnerability: \`const query = \`SELECT * FROM users WHERE id = \${userInput}\`;\` (user input directly interpolated)
|
|
15
|
+
- Authentication bypass: \`if (user.role === 'admin' || user.id === 1) { grantAccess(); }\` (hardcoded admin check)
|
|
16
|
+
- Missing input validation on sensitive operations: \`await db.delete(userId);\` (no validation that userId belongs to requester)
|
|
17
|
+
|
|
18
|
+
**When to use**: Only when there is a clear exploit path or risk of data corruption/integrity violation.
|
|
19
|
+
|
|
20
|
+
### Major
|
|
21
|
+
**Definition**: Significant bug, breaks functionality, or violates established patterns. Findings that cause incorrect behavior or violate architectural standards.
|
|
22
|
+
|
|
23
|
+
**Examples**:
|
|
24
|
+
- Missing error handling: \`const data = await fetch(url); return data.json();\` (no try-catch, will crash on network error)
|
|
25
|
+
- Tight coupling: \`import { DatabaseConnection } from './db'; class UserService { private db = new DatabaseConnection(); }\` (direct instantiation, violates dependency injection)
|
|
26
|
+
- Race condition: \`let count = 0; async function increment() { count++; await save(count); }\` (non-atomic increment)
|
|
27
|
+
|
|
28
|
+
**When to use**: When functionality is broken or architectural patterns are violated, but no immediate security/data risk.
|
|
29
|
+
|
|
30
|
+
### Minor
|
|
31
|
+
**Definition**: Code quality issue, convention violation, or maintainability concern. Findings that don't break functionality but reduce code quality.
|
|
32
|
+
|
|
33
|
+
**Examples**:
|
|
34
|
+
- Magic numbers: \`if (user.age > 18) { ... }\` (should be \`const MIN_ADULT_AGE = 18\`)
|
|
35
|
+
- Inconsistent naming: \`function getUserData() { ... }\` but \`function fetch_user_info() { ... }\` (mixed naming conventions)
|
|
36
|
+
- Missing JSDoc: \`function calculateTotal(items) { ... }\` (no documentation for complex logic)
|
|
37
|
+
|
|
38
|
+
**When to use**: Code quality, readability, or maintainability issues that don't affect functionality.
|
|
39
|
+
|
|
40
|
+
### Info
|
|
41
|
+
**Definition**: Observation, suggestion, or educational note. Findings that provide helpful context or suggestions without indicating a problem.
|
|
42
|
+
|
|
43
|
+
**Examples**:
|
|
44
|
+
- Performance suggestion: \`// Consider caching this query result if called frequently\`
|
|
45
|
+
- Pattern suggestion: \`// This could use the Repository pattern for better testability\`
|
|
46
|
+
- Documentation opportunity: \`// This algorithm implements the Fisher-Yates shuffle\`
|
|
47
|
+
|
|
48
|
+
**When to use**: Helpful suggestions or observations that don't indicate actual problems.
|
|
49
|
+
`;
|
|
50
|
+
/**
|
|
51
|
+
* Severity validation rules for critic pass (iteration 2+).
|
|
52
|
+
* These rules help the critic validate and potentially downgrade severity.
|
|
53
|
+
*/
|
|
54
|
+
export const SEVERITY_VALIDATION_RULES = `
|
|
55
|
+
## Severity Validation Rules
|
|
56
|
+
|
|
57
|
+
During the critic pass, validate each finding's severity against these rules:
|
|
58
|
+
|
|
59
|
+
1. **Critical findings MUST have exploit path or data integrity evidence**
|
|
60
|
+
- If a critical finding lacks a clear exploit path or data corruption risk described in the rationale, downgrade to major
|
|
61
|
+
- Example: "SQL injection" without showing how user input reaches the query → downgrade to major
|
|
62
|
+
|
|
63
|
+
2. **Major findings MUST demonstrate functional impact**
|
|
64
|
+
- If a major finding doesn't show how functionality is broken or patterns violated, downgrade to minor
|
|
65
|
+
- Example: "Missing error handling" without showing what breaks → downgrade to minor
|
|
66
|
+
|
|
67
|
+
3. **Minor findings MUST indicate code quality impact**
|
|
68
|
+
- If a minor finding is just a style preference without maintainability impact, consider downgrade to info
|
|
69
|
+
- Example: "Use const instead of let" without explaining why → consider info
|
|
70
|
+
|
|
71
|
+
4. **Downgrade rules**:
|
|
72
|
+
- Critical → Major: No exploit path or data integrity risk described
|
|
73
|
+
- Major → Minor: No functional impact demonstrated
|
|
74
|
+
- Minor → Info: No code quality/maintainability impact shown
|
|
75
|
+
|
|
76
|
+
5. **Never upgrade severity** - Only downgrade if evidence doesn't support the assigned level
|
|
77
|
+
`;
|
|
78
|
+
/**
|
|
79
|
+
* ContextRail tooling workflow requirements.
|
|
80
|
+
* Forces reviewers to ground findings in retrieved contexts instead of guessing IDs/titles.
|
|
81
|
+
*/
|
|
82
|
+
export const CONTEXTRAIL_TOOLING_BLOCK = `
|
|
83
|
+
## ContextRail Standards Workflow (Required)
|
|
84
|
+
|
|
85
|
+
When you identify potential issues, you MUST ground them in retrieved ContextRail standards:
|
|
86
|
+
|
|
87
|
+
1. Use \`search_contexts\` first to discover relevant standards for this change.
|
|
88
|
+
2. Use \`get_context\` for each context you plan to cite in findings.
|
|
89
|
+
3. Use \`resolve_dependencies\` when cited contexts have required dependencies.
|
|
90
|
+
4. Perform at least one \`search_contexts\` call before finalizing your findings.
|
|
91
|
+
|
|
92
|
+
Attribution rules:
|
|
93
|
+
- NEVER invent context IDs or titles.
|
|
94
|
+
- Only include \`contextIdsUsed\`, \`contextIdsViolated\`, and \`contextTitles\` from contexts you actually retrieved.
|
|
95
|
+
- If no relevant ContextRail standard exists after tool lookup, set those fields to \`null\` (not empty arrays) and explain that briefly in \`rationale\`.
|
|
96
|
+
`;
|
|
97
|
+
/**
|
|
98
|
+
* Compact output contract optimized for structured-output reliability.
|
|
99
|
+
* Keeps formatting constraints in one place for both standard and critic prompts.
|
|
100
|
+
*/
|
|
101
|
+
export const OUTPUT_CONTRACT_BLOCK = `
|
|
102
|
+
## Output Contract (Strict)
|
|
103
|
+
|
|
104
|
+
Return a JSON object with:
|
|
105
|
+
- \`findings\`: array
|
|
106
|
+
- \`validated\`: boolean
|
|
107
|
+
- \`notes\`: string | null
|
|
108
|
+
|
|
109
|
+
For each finding:
|
|
110
|
+
- Required keys: \`severity\`, \`title\`, \`description\`, \`rationale\`
|
|
111
|
+
- Optional-but-required-by-schema keys: \`suggestedFix\`, \`file\`, \`line\`, \`endLine\`, \`contextIdsUsed\`, \`contextIdsViolated\`, \`contextTitles\`
|
|
112
|
+
|
|
113
|
+
Schema compatibility rules:
|
|
114
|
+
- Include all keys (never omit)
|
|
115
|
+
- Use \`null\` when a value is not available
|
|
116
|
+
- Use \`null\` (not empty arrays) for context attribution fields when no standards apply
|
|
117
|
+
`;
|
|
118
|
+
/**
|
|
119
|
+
* Final guardrail checklist near generation point.
|
|
120
|
+
* Repeats only non-negotiables to reduce mid-prompt loss on long inputs.
|
|
121
|
+
*/
|
|
122
|
+
export const FINAL_CHECKLIST_BLOCK = `
|
|
123
|
+
## Final Checklist (Must Pass)
|
|
124
|
+
1. Every finding is supported by concrete code/diff evidence.
|
|
125
|
+
2. ContextRail workflow was used (\`search_contexts\` -> \`get_context\` -> \`resolve_dependencies\` as needed).
|
|
126
|
+
3. Context attribution fields only reference retrieved contexts (or are \`null\`).
|
|
127
|
+
4. Severity is calibrated to evidence.
|
|
128
|
+
5. Output strictly matches the JSON contract, and \`notes\` summarizes retrieved contexts (or none found).
|
|
129
|
+
`;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const buildReviewDecisionPrompt: (understanding: string, synthesisResult: {
|
|
2
|
+
findings: Array<{
|
|
3
|
+
severity: string;
|
|
4
|
+
title: string;
|
|
5
|
+
description: string;
|
|
6
|
+
}>;
|
|
7
|
+
contradictions: Array<{
|
|
8
|
+
context: string;
|
|
9
|
+
}>;
|
|
10
|
+
compoundRisks: Array<{
|
|
11
|
+
description: string;
|
|
12
|
+
affectedFindings: string[];
|
|
13
|
+
severity: string;
|
|
14
|
+
}>;
|
|
15
|
+
}) => string;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export const buildReviewDecisionPrompt = (understanding, synthesisResult) => {
|
|
2
|
+
const findingsSummary = synthesisResult.findings.length > 0
|
|
3
|
+
? synthesisResult.findings
|
|
4
|
+
.map((f) => `- [${f.severity.toUpperCase()}] ${f.title}: ${f.description}`)
|
|
5
|
+
.join('\n')
|
|
6
|
+
: '- None';
|
|
7
|
+
const contradictionsText = synthesisResult.contradictions.length > 0
|
|
8
|
+
? `\n\nContradictions:\n${synthesisResult.contradictions.map((c) => `- ${c.context}`).join('\n')}`
|
|
9
|
+
: '';
|
|
10
|
+
const compoundRisksText = synthesisResult.compoundRisks.length > 0
|
|
11
|
+
? `\n\nCompound Risks:\n${synthesisResult.compoundRisks.map((r) => `- [${r.severity.toUpperCase()}] ${r.description}`).join('\n')}`
|
|
12
|
+
: '';
|
|
13
|
+
return `You are making a final review decision based on synthesized findings from multiple reviewers.
|
|
14
|
+
|
|
15
|
+
Return "approve" only when there are no critical or major findings.
|
|
16
|
+
Return "request-changes" when there are any critical/major findings.
|
|
17
|
+
Hard rule: if synthesized findings contain zero critical/major items, decision MUST be "approve".
|
|
18
|
+
|
|
19
|
+
Provide:
|
|
20
|
+
- decision: approve | request-changes
|
|
21
|
+
- summary: 2-4 sentences, plain language
|
|
22
|
+
- rationale: explain why the decision was made, referencing key findings or lack thereof
|
|
23
|
+
|
|
24
|
+
Review context:
|
|
25
|
+
${understanding}
|
|
26
|
+
|
|
27
|
+
Synthesized findings:
|
|
28
|
+
${findingsSummary}${contradictionsText}${compoundRisksText}
|
|
29
|
+
`;
|
|
30
|
+
};
|
|
@@ -8,7 +8,7 @@ import type { FilePatterns } from '../review-inputs/file-patterns.js';
|
|
|
8
8
|
* @param contextIds - The context IDs.
|
|
9
9
|
* @returns The activity content.
|
|
10
10
|
*/
|
|
11
|
-
declare const generateActivityContentPrompt: (understanding: string, reviewers: string[], toolCalls: Array<{
|
|
11
|
+
export declare const generateActivityContentPrompt: (understanding: string, reviewers: string[], toolCalls: Array<{
|
|
12
12
|
tool: string;
|
|
13
13
|
input?: unknown;
|
|
14
14
|
}>, contextIds: string[]) => string;
|
|
@@ -21,5 +21,4 @@ declare const generateActivityContentPrompt: (understanding: string, reviewers:
|
|
|
21
21
|
* @param reviewDomains - Optional review focus domains to prioritize.
|
|
22
22
|
* @returns The user message.
|
|
23
23
|
*/
|
|
24
|
-
declare const generateUserMessagePrompt: (inputs: ReviewInputs, availableReviewers: string[], prDescription?: string, reviewerFilePatterns?: Map<string, FilePatterns | undefined>, reviewDomains?: string[]) => string;
|
|
25
|
-
export { generateActivityContentPrompt, generateUserMessagePrompt };
|
|
24
|
+
export declare const generateUserMessagePrompt: (inputs: ReviewInputs, availableReviewers: string[], prDescription?: string, reviewerFilePatterns?: Map<string, FilePatterns | undefined>, reviewDomains?: string[]) => string;
|
|
@@ -9,7 +9,7 @@ import dedent from 'dedent';
|
|
|
9
9
|
* @param contextIds - The context IDs.
|
|
10
10
|
* @returns The activity content.
|
|
11
11
|
*/
|
|
12
|
-
const generateActivityContentPrompt = (understanding, reviewers, toolCalls, contextIds) => dedent(`# Orchestration Activity Log
|
|
12
|
+
export const generateActivityContentPrompt = (understanding, reviewers, toolCalls, contextIds) => dedent(`# Orchestration Activity Log
|
|
13
13
|
|
|
14
14
|
**Phase**: Orchestration
|
|
15
15
|
**Completed**: ${new Date().toISOString()}
|
|
@@ -39,7 +39,7 @@ const generateActivityContentPrompt = (understanding, reviewers, toolCalls, cont
|
|
|
39
39
|
* @param reviewDomains - Optional review focus domains to prioritize.
|
|
40
40
|
* @returns The user message.
|
|
41
41
|
*/
|
|
42
|
-
const generateUserMessagePrompt = (inputs, availableReviewers, prDescription, reviewerFilePatterns, reviewDomains) => {
|
|
42
|
+
export const generateUserMessagePrompt = (inputs, availableReviewers, prDescription, reviewerFilePatterns, reviewDomains) => {
|
|
43
43
|
const diffSummary = generateDiffSummary(inputs);
|
|
44
44
|
const prDescriptionBlock = prDescription ? `\n\nPR Description:\n${prDescription}\n` : '';
|
|
45
45
|
// Build reviewer scope information block
|
|
@@ -95,4 +95,3 @@ ${availableReviewers
|
|
|
95
95
|
- If review focus domains are provided, prioritize reviewers and rationale aligned to those domains.
|
|
96
96
|
`);
|
|
97
97
|
};
|
|
98
|
-
export { generateActivityContentPrompt, generateUserMessagePrompt };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ReviewInputs } from '../review-inputs/index.js';
|
|
2
|
+
import type { ReviewerFindings } from '../output/schema.js';
|
|
3
|
+
/**
|
|
4
|
+
* Build a critic prompt that challenges findings from a previous iteration.
|
|
5
|
+
* The critic pass validates findings, removes false positives, and enforces evidence/standards.
|
|
6
|
+
*/
|
|
7
|
+
export declare const buildCriticPrompt: (inputs: ReviewInputs, understanding: string, findings: ReviewerFindings, prDescription?: string, reviewDomains?: string[]) => string;
|
|
8
|
+
/**
|
|
9
|
+
* Build a standard reviewer prompt for initial review (iteration 1).
|
|
10
|
+
*/
|
|
11
|
+
export declare const buildStandardReviewPrompt: (inputs: ReviewInputs, understanding: string, prDescription?: string, reviewDomains?: string[]) => string;
|
|
12
|
+
export declare const buildReviewerUserMessage: (inputs: ReviewInputs, understanding: string, iteration: number, findings: ReviewerFindings | null, prDescription?: string, reviewDomains?: string[]) => string;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { isDiffInputs } from '../review-inputs/index.js';
|
|
2
|
+
import { SEVERITY_VALIDATION_RULES, CONTEXTRAIL_TOOLING_BLOCK, OUTPUT_CONTRACT_BLOCK, FINAL_CHECKLIST_BLOCK, } from './blocks.js';
|
|
3
|
+
/**
|
|
4
|
+
* Build a critic prompt that challenges findings from a previous iteration.
|
|
5
|
+
* The critic pass validates findings, removes false positives, and enforces evidence/standards.
|
|
6
|
+
*/
|
|
7
|
+
export const buildCriticPrompt = (inputs, understanding, findings, prDescription, reviewDomains) => {
|
|
8
|
+
const diffBlock = isDiffInputs(inputs)
|
|
9
|
+
? `\nDiffs:\n${Object.entries(inputs.diffs)
|
|
10
|
+
.map(([file, diff]) => `\n## ${file}\n\`\`\`diff\n${diff}\n\`\`\``)
|
|
11
|
+
.join('\n')}`
|
|
12
|
+
: '';
|
|
13
|
+
const contextBlock = inputs.context && Object.keys(inputs.context).length > 0
|
|
14
|
+
? `\n\nSurrounding Code Context:\n${Object.entries(inputs.context)
|
|
15
|
+
.map(([file, context]) => `\n## ${file}\n\`\`\`\n${context}\n\`\`\``)
|
|
16
|
+
.join('\n')}`
|
|
17
|
+
: '';
|
|
18
|
+
const prDescriptionBlock = prDescription ? `\n\nPR Description:\n${prDescription}\n` : '';
|
|
19
|
+
const reviewDomainsBlock = reviewDomains && reviewDomains.length > 0
|
|
20
|
+
? `\n\nReview Focus Domains:\n${reviewDomains.map((domain) => `- ${domain}`).join('\n')}\n`
|
|
21
|
+
: '';
|
|
22
|
+
return `You are performing a CRITIC PASS to validate and challenge findings from the previous iteration.
|
|
23
|
+
|
|
24
|
+
Your role is to:
|
|
25
|
+
1. Challenge each finding - require concrete evidence from the code or ContextRail standards
|
|
26
|
+
2. Remove false positives - findings that lack evidence or don't violate actual standards
|
|
27
|
+
3. Enforce ContextRail standards - each finding MUST be grounded in retrieved contexts
|
|
28
|
+
4. Validate severity - ensure severity matches the actual risk level using the severity validation rules below
|
|
29
|
+
5. Only keep findings that are:
|
|
30
|
+
- Supported by evidence in the code/diffs
|
|
31
|
+
- Linked to specific ContextRail standards (contextIdsUsed or contextIdsViolated)
|
|
32
|
+
- Accurately categorized by severity
|
|
33
|
+
|
|
34
|
+
${SEVERITY_VALIDATION_RULES}
|
|
35
|
+
${CONTEXTRAIL_TOOLING_BLOCK}
|
|
36
|
+
|
|
37
|
+
Context:
|
|
38
|
+
${understanding}
|
|
39
|
+
${prDescriptionBlock}${reviewDomainsBlock}
|
|
40
|
+
Files:
|
|
41
|
+
${inputs.files.map((f) => `- ${f}`).join('\n')}
|
|
42
|
+
${diffBlock}${contextBlock}
|
|
43
|
+
|
|
44
|
+
Previous findings (iteration 1) - CRITICALLY REVIEW THESE:
|
|
45
|
+
${JSON.stringify(findings.findings, null, 2)}
|
|
46
|
+
|
|
47
|
+
For each finding, ask yourself:
|
|
48
|
+
- Is there concrete evidence in the code/diffs that supports this finding?
|
|
49
|
+
- Does this finding reference specific ContextRail standards (contextIdsUsed or contextIdsViolated)?
|
|
50
|
+
- Is the severity appropriate for the actual risk? (Apply severity validation rules above)
|
|
51
|
+
- Could this be a false positive that should be removed?
|
|
52
|
+
- Should the severity be downgraded based on the validation rules?
|
|
53
|
+
|
|
54
|
+
Output requirements:
|
|
55
|
+
- Remove any findings that lack evidence
|
|
56
|
+
- Remove findings that claim ContextRail impact but do not include retrieved context attribution
|
|
57
|
+
- Keep only findings that are well-supported and properly attributed
|
|
58
|
+
- Validate severity using the rules above - downgrade if evidence doesn't support the assigned level
|
|
59
|
+
- Set validated: true only if all remaining findings meet these criteria
|
|
60
|
+
- Always include notes field: use a string when you have notes, or null when none
|
|
61
|
+
- If you remove findings or downgrade severity, explain why in notes
|
|
62
|
+
- In notes, summarize which ContextRail contexts were retrieved (or state that none were relevant after tool lookup)
|
|
63
|
+
|
|
64
|
+
${OUTPUT_CONTRACT_BLOCK}
|
|
65
|
+
${FINAL_CHECKLIST_BLOCK}`;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Build a standard reviewer prompt for initial review (iteration 1).
|
|
69
|
+
*/
|
|
70
|
+
export const buildStandardReviewPrompt = (inputs, understanding, prDescription, reviewDomains) => {
|
|
71
|
+
const diffBlock = isDiffInputs(inputs)
|
|
72
|
+
? `\nDiffs:\n${Object.entries(inputs.diffs)
|
|
73
|
+
.map(([file, diff]) => `\n## ${file}\n\`\`\`diff\n${diff}\n\`\`\``)
|
|
74
|
+
.join('\n')}`
|
|
75
|
+
: '';
|
|
76
|
+
const contextBlock = inputs.context && Object.keys(inputs.context).length > 0
|
|
77
|
+
? `\n\nSurrounding Code Context:\n${Object.entries(inputs.context)
|
|
78
|
+
.map(([file, context]) => `\n## ${file}\n\`\`\`\n${context}\n\`\`\``)
|
|
79
|
+
.join('\n')}`
|
|
80
|
+
: '';
|
|
81
|
+
const prDescriptionBlock = prDescription ? `\n\nPR Description:\n${prDescription}\n` : '';
|
|
82
|
+
const reviewDomainsBlock = reviewDomains && reviewDomains.length > 0
|
|
83
|
+
? `\n\nReview Focus Domains:\n${reviewDomains.map((domain) => `- ${domain}`).join('\n')}\n`
|
|
84
|
+
: '';
|
|
85
|
+
return `Review these changes using the reviewer prompt guidance.
|
|
86
|
+
|
|
87
|
+
Context:
|
|
88
|
+
${understanding}
|
|
89
|
+
${prDescriptionBlock}${reviewDomainsBlock}
|
|
90
|
+
Files:
|
|
91
|
+
${inputs.files.map((f) => `- ${f}`).join('\n')}
|
|
92
|
+
${diffBlock}${contextBlock}
|
|
93
|
+
|
|
94
|
+
Please review these changes and provide findings.
|
|
95
|
+
|
|
96
|
+
${CONTEXTRAIL_TOOLING_BLOCK}
|
|
97
|
+
${OUTPUT_CONTRACT_BLOCK}
|
|
98
|
+
${FINAL_CHECKLIST_BLOCK}`;
|
|
99
|
+
};
|
|
100
|
+
export const buildReviewerUserMessage = (inputs, understanding, iteration, findings, prDescription, reviewDomains) => {
|
|
101
|
+
// Use critic pass for iteration 2+
|
|
102
|
+
if (iteration > 1 && findings) {
|
|
103
|
+
return buildCriticPrompt(inputs, understanding, findings, prDescription, reviewDomains);
|
|
104
|
+
}
|
|
105
|
+
// Use standard review for iteration 1
|
|
106
|
+
return buildStandardReviewPrompt(inputs, understanding, prDescription, reviewDomains);
|
|
107
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ReviewerResult } from '
|
|
1
|
+
import type { ReviewerResult } from '../output/schema.js';
|
|
2
2
|
/**
|
|
3
3
|
* Generate a human-readable pre-summary from reviewer results.
|
|
4
4
|
* Includes severity counts and top findings per reviewer.
|
|
@@ -15,18 +15,3 @@ export declare const generatePreSummary: (reviewerResults: ReviewerResult[]) =>
|
|
|
15
15
|
* @returns Synthesis prompt string
|
|
16
16
|
*/
|
|
17
17
|
export declare const buildSynthesisPrompt: (reviewerResults: ReviewerResult[]) => string;
|
|
18
|
-
export declare const buildReviewDecisionPrompt: (understanding: string, synthesisResult: {
|
|
19
|
-
findings: Array<{
|
|
20
|
-
severity: string;
|
|
21
|
-
title: string;
|
|
22
|
-
description: string;
|
|
23
|
-
}>;
|
|
24
|
-
contradictions: Array<{
|
|
25
|
-
context: string;
|
|
26
|
-
}>;
|
|
27
|
-
compoundRisks: Array<{
|
|
28
|
-
description: string;
|
|
29
|
-
affectedFindings: string[];
|
|
30
|
-
severity: string;
|
|
31
|
-
}>;
|
|
32
|
-
}) => string;
|
|
@@ -121,33 +121,3 @@ Output requirements:
|
|
|
121
121
|
- \`notes\`: Always include this field; use a string when useful, otherwise \`null\`
|
|
122
122
|
`;
|
|
123
123
|
};
|
|
124
|
-
export const buildReviewDecisionPrompt = (understanding, synthesisResult) => {
|
|
125
|
-
const findingsSummary = synthesisResult.findings.length > 0
|
|
126
|
-
? synthesisResult.findings
|
|
127
|
-
.map((f) => `- [${f.severity.toUpperCase()}] ${f.title}: ${f.description}`)
|
|
128
|
-
.join('\n')
|
|
129
|
-
: '- None';
|
|
130
|
-
const contradictionsText = synthesisResult.contradictions.length > 0
|
|
131
|
-
? `\n\nContradictions:\n${synthesisResult.contradictions.map((c) => `- ${c.context}`).join('\n')}`
|
|
132
|
-
: '';
|
|
133
|
-
const compoundRisksText = synthesisResult.compoundRisks.length > 0
|
|
134
|
-
? `\n\nCompound Risks:\n${synthesisResult.compoundRisks.map((r) => `- [${r.severity.toUpperCase()}] ${r.description}`).join('\n')}`
|
|
135
|
-
: '';
|
|
136
|
-
return `You are making a final review decision based on synthesized findings from multiple reviewers.
|
|
137
|
-
|
|
138
|
-
Return "approve" only when there are no critical or major findings.
|
|
139
|
-
Return "request-changes" when there are any critical/major findings.
|
|
140
|
-
Hard rule: if synthesized findings contain zero critical/major items, decision MUST be "approve".
|
|
141
|
-
|
|
142
|
-
Provide:
|
|
143
|
-
- decision: approve | request-changes
|
|
144
|
-
- summary: 2-4 sentences, plain language
|
|
145
|
-
- rationale: explain why the decision was made, referencing key findings or lack thereof
|
|
146
|
-
|
|
147
|
-
Review context:
|
|
148
|
-
${understanding}
|
|
149
|
-
|
|
150
|
-
Synthesized findings:
|
|
151
|
-
${findingsSummary}${contradictionsText}${compoundRisksText}
|
|
152
|
-
`;
|
|
153
|
-
};
|
|
@@ -3,7 +3,9 @@ import { type ChunkingConfig } from '../review-inputs/chunking.js';
|
|
|
3
3
|
import { type FilePatterns } from '../review-inputs/file-patterns.js';
|
|
4
4
|
import type { McpClient } from '../mcp/client.js';
|
|
5
5
|
import type { ReviewerFindings } from '../output/schema.js';
|
|
6
|
+
import type { SharedAgentOpConfig } from '../config/index.js';
|
|
6
7
|
import type { Logger } from '../logging/logger.js';
|
|
8
|
+
import type { LlmService } from '../llm/service.js';
|
|
7
9
|
/**
|
|
8
10
|
* Extract filePatterns from prompt metadata.
|
|
9
11
|
*
|
|
@@ -11,18 +13,15 @@ import type { Logger } from '../logging/logger.js';
|
|
|
11
13
|
* @returns FilePatterns if found, undefined otherwise
|
|
12
14
|
*/
|
|
13
15
|
export declare function extractFilePatterns(metadata: unknown): FilePatterns | undefined;
|
|
14
|
-
export type AgenticExecutorConfig = {
|
|
15
|
-
openRouterApiKey: string;
|
|
16
|
+
export type AgenticExecutorConfig = SharedAgentOpConfig & {
|
|
16
17
|
reviewerModel: string;
|
|
17
18
|
criticModel?: string;
|
|
18
|
-
maxSteps?: number;
|
|
19
19
|
maxIterations?: number;
|
|
20
20
|
chunking?: ChunkingConfig;
|
|
21
|
-
prDescription?: string;
|
|
22
|
-
reviewDomains?: string[];
|
|
23
21
|
};
|
|
24
22
|
export type AgenticExecutorDeps = {
|
|
25
23
|
mcpClient: McpClient;
|
|
24
|
+
llmService: LlmService;
|
|
26
25
|
config: AgenticExecutorConfig;
|
|
27
26
|
logger?: Logger;
|
|
28
27
|
};
|
|
@@ -9,7 +9,6 @@ import { runReviewerIteration } from './iteration.js';
|
|
|
9
9
|
import { logCompletion, logContinuation, logIteration, writeFindings, writeTokenMetrics } from './persistence.js';
|
|
10
10
|
import { mergeIterationTracking, mergeTokenUsage } from './tool-call-tracker.js';
|
|
11
11
|
import { mergeChunkFindings } from './findings-merge.js';
|
|
12
|
-
import { createLlmService } from '../llm/factory.js';
|
|
13
12
|
const formatIssuePath = (pathSegments) => {
|
|
14
13
|
if (!Array.isArray(pathSegments) || pathSegments.length === 0) {
|
|
15
14
|
return '(root)';
|
|
@@ -115,7 +114,7 @@ export function extractFilePatterns(metadata) {
|
|
|
115
114
|
* @returns Reviewer findings
|
|
116
115
|
*/
|
|
117
116
|
export const runReviewerLoop = async (reviewer, inputs, understanding, outputDir, deps) => {
|
|
118
|
-
const { mcpClient, config, logger } = deps;
|
|
117
|
+
const { mcpClient, llmService, config, logger } = deps;
|
|
119
118
|
const maxIterations = config.maxIterations ?? DEFAULT_MAX_ITERATIONS;
|
|
120
119
|
const reviewersDir = path.join(outputDir, 'reviewers');
|
|
121
120
|
const reviewerDir = path.join(reviewersDir, reviewer);
|
|
@@ -193,12 +192,6 @@ export const runReviewerLoop = async (reviewer, inputs, understanding, outputDir
|
|
|
193
192
|
else {
|
|
194
193
|
logger?.debug(`[${reviewer}] No file pattern scope found in prompt metadata; reviewing all ${inputs.files.length} files`);
|
|
195
194
|
}
|
|
196
|
-
// Create LLM service with MCP tools
|
|
197
|
-
const { service: llmService } = createLlmService({
|
|
198
|
-
openRouterApiKey: config.openRouterApiKey,
|
|
199
|
-
mcpClient,
|
|
200
|
-
logger,
|
|
201
|
-
});
|
|
202
195
|
const maxSteps = config.maxSteps ?? DEFAULT_MAX_STEPS;
|
|
203
196
|
let findings = null;
|
|
204
197
|
let iteration = 0;
|
|
@@ -1,34 +1,9 @@
|
|
|
1
|
-
import { type ReviewInputs } from '../review-inputs/index.js';
|
|
2
|
-
import type { ReviewerFindings } from '../output/schema.js';
|
|
3
1
|
export type PromptMessage = {
|
|
4
2
|
role: 'system' | 'user' | 'assistant';
|
|
5
3
|
content: string;
|
|
6
4
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* This block is injected into reviewer system prompts to ensure consistent severity assignment.
|
|
10
|
-
*/
|
|
11
|
-
export declare const SEVERITY_CALIBRATION_BLOCK = "\n## Severity Calibration\n\nYou must assign severity levels accurately based on the following definitions and examples:\n\n### Critical\n**Definition**: Blocks deployment, active exploit path, or data corruption risk. Findings that could lead to security breaches, data loss, or system compromise.\n\n**Examples**:\n- SQL injection vulnerability: `const query = `SELECT * FROM users WHERE id = ${userInput}`;` (user input directly interpolated)\n- Authentication bypass: `if (user.role === 'admin' || user.id === 1) { grantAccess(); }` (hardcoded admin check)\n- Missing input validation on sensitive operations: `await db.delete(userId);` (no validation that userId belongs to requester)\n\n**When to use**: Only when there is a clear exploit path or risk of data corruption/integrity violation.\n\n### Major\n**Definition**: Significant bug, breaks functionality, or violates established patterns. Findings that cause incorrect behavior or violate architectural standards.\n\n**Examples**:\n- Missing error handling: `const data = await fetch(url); return data.json();` (no try-catch, will crash on network error)\n- Tight coupling: `import { DatabaseConnection } from './db'; class UserService { private db = new DatabaseConnection(); }` (direct instantiation, violates dependency injection)\n- Race condition: `let count = 0; async function increment() { count++; await save(count); }` (non-atomic increment)\n\n**When to use**: When functionality is broken or architectural patterns are violated, but no immediate security/data risk.\n\n### Minor\n**Definition**: Code quality issue, convention violation, or maintainability concern. Findings that don't break functionality but reduce code quality.\n\n**Examples**:\n- Magic numbers: `if (user.age > 18) { ... }` (should be `const MIN_ADULT_AGE = 18`)\n- Inconsistent naming: `function getUserData() { ... }` but `function fetch_user_info() { ... }` (mixed naming conventions)\n- Missing JSDoc: `function calculateTotal(items) { ... }` (no documentation for complex logic)\n\n**When to use**: Code quality, readability, or maintainability issues that don't affect functionality.\n\n### Info\n**Definition**: Observation, suggestion, or educational note. Findings that provide helpful context or suggestions without indicating a problem.\n\n**Examples**:\n- Performance suggestion: `// Consider caching this query result if called frequently`\n- Pattern suggestion: `// This could use the Repository pattern for better testability`\n- Documentation opportunity: `// This algorithm implements the Fisher-Yates shuffle`\n\n**When to use**: Helpful suggestions or observations that don't indicate actual problems.\n";
|
|
12
|
-
/**
|
|
13
|
-
* Severity validation rules for critic pass (iteration 2+).
|
|
14
|
-
* These rules help the critic validate and potentially downgrade severity.
|
|
15
|
-
*/
|
|
16
|
-
export declare const SEVERITY_VALIDATION_RULES = "\n## Severity Validation Rules\n\nDuring the critic pass, validate each finding's severity against these rules:\n\n1. **Critical findings MUST have exploit path or data integrity evidence**\n - If a critical finding lacks a clear exploit path or data corruption risk described in the rationale, downgrade to major\n - Example: \"SQL injection\" without showing how user input reaches the query \u2192 downgrade to major\n\n2. **Major findings MUST demonstrate functional impact**\n - If a major finding doesn't show how functionality is broken or patterns violated, downgrade to minor\n - Example: \"Missing error handling\" without showing what breaks \u2192 downgrade to minor\n\n3. **Minor findings MUST indicate code quality impact**\n - If a minor finding is just a style preference without maintainability impact, consider downgrade to info\n - Example: \"Use const instead of let\" without explaining why \u2192 consider info\n\n4. **Downgrade rules**:\n - Critical \u2192 Major: No exploit path or data integrity risk described\n - Major \u2192 Minor: No functional impact demonstrated\n - Minor \u2192 Info: No code quality/maintainability impact shown\n\n5. **Never upgrade severity** - Only downgrade if evidence doesn't support the assigned level\n";
|
|
17
|
-
/**
|
|
18
|
-
* ContextRail tooling workflow requirements.
|
|
19
|
-
* Forces reviewers to ground findings in retrieved contexts instead of guessing IDs/titles.
|
|
20
|
-
*/
|
|
21
|
-
export declare const CONTEXTRAIL_TOOLING_BLOCK = "\n## ContextRail Standards Workflow (Required)\n\nWhen you identify potential issues, you MUST ground them in retrieved ContextRail standards:\n\n1. Use `search_contexts` first to discover relevant standards for this change.\n2. Use `get_context` for each context you plan to cite in findings.\n3. Use `resolve_dependencies` when cited contexts have required dependencies.\n4. Perform at least one `search_contexts` call before finalizing your findings.\n\nAttribution rules:\n- NEVER invent context IDs or titles.\n- Only include `contextIdsUsed`, `contextIdsViolated`, and `contextTitles` from contexts you actually retrieved.\n- If no relevant ContextRail standard exists after tool lookup, set those fields to `null` (not empty arrays) and explain that briefly in `rationale`.\n";
|
|
22
|
-
/**
|
|
23
|
-
* Compact output contract optimized for structured-output reliability.
|
|
24
|
-
* Keeps formatting constraints in one place for both standard and critic prompts.
|
|
25
|
-
*/
|
|
26
|
-
export declare const OUTPUT_CONTRACT_BLOCK = "\n## Output Contract (Strict)\n\nReturn a JSON object with:\n- `findings`: array\n- `validated`: boolean\n- `notes`: string | null\n\nFor each finding:\n- Required keys: `severity`, `title`, `description`, `rationale`\n- Optional-but-required-by-schema keys: `suggestedFix`, `file`, `line`, `endLine`, `contextIdsUsed`, `contextIdsViolated`, `contextTitles`\n\nSchema compatibility rules:\n- Include all keys (never omit)\n- Use `null` when a value is not available\n- Use `null` (not empty arrays) for context attribution fields when no standards apply\n";
|
|
27
|
-
/**
|
|
28
|
-
* Final guardrail checklist near generation point.
|
|
29
|
-
* Repeats only non-negotiables to reduce mid-prompt loss on long inputs.
|
|
30
|
-
*/
|
|
31
|
-
export declare const FINAL_CHECKLIST_BLOCK = "\n## Final Checklist (Must Pass)\n1. Every finding is supported by concrete code/diff evidence.\n2. ContextRail workflow was used (`search_contexts` -> `get_context` -> `resolve_dependencies` as needed).\n3. Context attribution fields only reference retrieved contexts (or are `null`).\n4. Severity is calibrated to evidence.\n5. Output strictly matches the JSON contract, and `notes` summarizes retrieved contexts (or none found).\n";
|
|
5
|
+
export { SEVERITY_CALIBRATION_BLOCK, SEVERITY_VALIDATION_RULES, CONTEXTRAIL_TOOLING_BLOCK, OUTPUT_CONTRACT_BLOCK, FINAL_CHECKLIST_BLOCK, } from '../prompts/blocks.js';
|
|
6
|
+
export { buildCriticPrompt, buildStandardReviewPrompt, buildReviewerUserMessage } from '../prompts/reviewer.js';
|
|
32
7
|
export declare const buildPromptMessages: (promptResult: {
|
|
33
8
|
messages: {
|
|
34
9
|
role: string;
|
|
@@ -39,4 +14,3 @@ export declare const buildPromptMessages: (promptResult: {
|
|
|
39
14
|
}[];
|
|
40
15
|
metadata?: unknown;
|
|
41
16
|
}) => PromptMessage[];
|
|
42
|
-
export declare const buildReviewerUserMessage: (inputs: ReviewInputs, understanding: string, iteration: number, findings: ReviewerFindings | null, prDescription?: string, reviewDomains?: string[]) => string;
|