Skip to content

Commit df6c8cf

Browse files
committed
feat: enhanced prompt
1 parent 376e0ee commit df6c8cf

3 files changed

Lines changed: 61 additions & 20 deletions

File tree

src/analysisWorker.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -106,24 +106,8 @@ class AnalysisWorker {
106106
this.emitJobUpdate(project_id, 'ready', 'Parsing completed. Starting knowledge extraction...');
107107

108108
// 🧠 Step 3: Send message to agent to perform analysis
109-
const userPrompt = `${question}.
110-
Answer only with the result formatted in a JSON structure like following:
111-
{
112-
"snippets": [{ "node_id": "...", "file_path": "...", "code": "...", "tags": [...], "description": "...", "line_start": 0, "line_end": 0 }],
113-
"snippets_count": <number>,
114-
"analysis_response": {...},
115-
"metadata": {
116-
"parsed_at": "<ISO date>",
117-
"total_nodes_found": <number>,
118-
"processed_nodes": <number>,
119-
"repo": "${repo}",
120-
"branch": "${branch}"
121-
}
122-
}
123-
`;
124-
125109
console.log(`🔄 [WORKER] Sending analysis request to agent...`);
126-
const response = await this.potpieClient.sendMessage(project_id, userPrompt);
110+
const response = await this.potpieClient.sendMessage(project_id, question);
127111

128112
console.log(response.data);
129113
if (!response.success) throw new Error(`Failed to create conversation for project ${project_id}. Error: ${JSON.stringify(response.error)}`);

src/constants.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
export const questionPrompt = `You are a strict JSON-producing analysis engine for software repositories.
2+
3+
Your task:
4+
- Fully analyze the repository architecture.
5+
- Extract every node, file, function, method, type, and relevant structure.
6+
- Produce a complete and rich "analysis_response".
7+
- Produce the full set of snippets representing your architectural understanding.
8+
9+
STRICT OUTPUT RULES (DO NOT VIOLATE):
10+
1. You MUST output VALID JSON only.
11+
2. You MUST NOT output markdown, code fences (\`\`\`), comments, or explanations.
12+
3. You MUST NOT output text before or after the JSON.
13+
4. You MUST NOT summarize your answer outside the JSON.
14+
5. You MUST NOT invent fields not defined in the schema.
15+
6. You MUST ensure the JSON parses successfully on first attempt.
16+
7. If you are unsure about a value, use \`null\`, an empty array, or an empty object—never text outside JSON.
17+
18+
JSON SCHEMA (STRICT — DO NOT MODIFY THE STRUCTURE):
19+
{
20+
"snippets": [
21+
{
22+
"node_id": "string",
23+
"file_path": "string",
24+
"code": "string",
25+
"tags": ["string"],
26+
"description": "string or null",
27+
"line_start": "number",
28+
"line_end": "number"
29+
}
30+
],
31+
"snippets_count": 0,
32+
"analysis_response": {},
33+
"metadata": {
34+
"parsed_at": "<ISO date>",
35+
"total_nodes_found": "number",
36+
"processed_nodes": "number",
37+
"repo": "${repo}",
38+
"branch": "${branch}"
39+
}
40+
}
41+
42+
REQUIREMENTS:
43+
- Replace all placeholder strings with real computed values.
44+
- Make \`snippets_count\` equal to the length of \`snippets\`.
45+
- \`parsed_at\` must be an ISO timestamp.
46+
- The output MUST be self-consistent and internally valid.
47+
48+
AUTO-VALIDATION RULE:
49+
Before responding, mentally validate your JSON and ensure:
50+
- It has NO syntax errors.
51+
- It contains NO trailing commas.
52+
- All arrays and objects are properly closed.
53+
- It contains NO text outside of JSON.
54+
55+
FINAL INSTRUCTION:
56+
Return ONLY the final valid JSON. No markdown. No commentary. No quotes around the whole JSON. No prefix or suffix text.
57+
`

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const PotpieClient = require('./potpieClient');
1111

1212
// Prometheus metrics
1313
const promClient = require('prom-client');
14+
const { questionPrompt } = require('./constants');
1415
const register = new promClient.Registry();
1516

1617
// Custom metrics
@@ -137,7 +138,7 @@ app.get('/health', async (req, res) => {
137138
// Repository analysis endpoint - Uses BullMQ Queue
138139
app.post('/analyze', async (req, res) => {
139140
try {
140-
const { repo, branch, question, github_token } = req.body;
141+
const { repo, branch, github_token } = req.body;
141142

142143
// Validate required parameters
143144
if (!repo) {
@@ -146,7 +147,6 @@ app.post('/analyze', async (req, res) => {
146147
example: {
147148
repo: 'org/repository-name',
148149
branch: 'main',
149-
question: 'Explain the authentication module',
150150
github_token: 'ghp_xxxxxxxxxxxxxxxxxxxx'
151151
}
152152
});
@@ -162,7 +162,7 @@ app.post('/analyze', async (req, res) => {
162162

163163
const repoName = repo;
164164
const branchName = branch || 'main';
165-
const analysisQuestion = question || 'Analyze and explain the repository architecture, return the full set of snippet for the full project architecture knowledge, analyze every node and provide a rich and complete "analysis_response" result';
165+
const analysisQuestion = questionPrompt ;
166166

167167
console.log(`Starting analysis for repository: ${repoName}, branch: ${branchName}`);
168168

0 commit comments

Comments
 (0)