Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions my-key.pem.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC4AHGRO4V56NhQ4cuuZIekST8SqEFpwostyAaLUjxZwGmtIIo7nroipu/ZjQi+xWuSZu94HveoYw1a8m2qLaUvF89VpkW9bzQqe1KwaStR1Zymsn0H3dJC+DC22uf604zKuhPivTe/0L9rBYNQEUWm10rfl+uWnOggY3yRIzQc06B08k8zjH2NGFFsvmbOFoP0xYlBXrdvNhRTCaJdKXyA+2xu7nY0b6ECMNW11WZjwXTtYvNrbDAdOoWVG9BRF2X8+g7L9Oh5Bh1uNNIxM5iQKnZXzfbGi8PtAeg+zEPeP1dvM2FwNCC41G2TnGTjNBQAy2Lwahhx0cKw2026TK//8iDXyfnLLOeAhpYrF8U8iRGKdJLmRNNn+IrVCLS3hOIVi4sj49X4vnmmy2fFuUIHH9RSAg9fBw/QR+gXhzIDlrDRJWw4v73HxCJFytphmkwIzV2n3/5g2fKQ0/WYRbEU/dHpbt84CuIftT4p7zspEeIRqskyHsUFc6eQptveAylZCRGty8uNuq2hlp71AcX6WAz+u7Ucf52oDUNtjSB1kAUT2mYH6LqrJRel2IGn38sW+Km2Ckx6t2BOdv0cr3n83YehDv7fkDWQyvFB3JiqwRLSMZt2WQjjCr1q4i6+1o9JE+ZVznsIFy/qybanhio6q09ywgvgKPEZ/sCNxOYnaQ== mohammedbensassi@Mohammeds-Air
2,928 changes: 731 additions & 2,197 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"gpt-tokenizer": "^2.1.2",
"groq-sdk": "^0.8.0",
"octokit": "^3.1.1",
"python-ast": "^0.1.0",
"xml2js": "^0.6.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,4 @@ const server = http.createServer((req, res) => {
server.listen(port, () => {
console.log(`Server is listening for events.`);
console.log("Press Ctrl + C to quit.");
});
});
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,4 @@ export const assignLineNumbers = (contents: string): string => {
return numberedLine;
});
return linesWithNumbers.join("\n");
};
};
2 changes: 1 addition & 1 deletion src/context/language/javascript-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ export class JavascriptParser implements AbstractParser {
};
}
}
}
}
70 changes: 65 additions & 5 deletions src/context/language/python-parser.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,75 @@
import { AbstractParser, EnclosingContext } from "../../constants";
import * as ast from "python-ast"; // Python AST parsing library

/**
* Processes a Python AST node to determine if it is the largest enclosing context.
*/
const processNode = (
node: any,
lineStart: number,
lineEnd: number,
largestSize: number,
largestEnclosingContext: any
) => {
const { start, end } = node.loc;
if (start.line <= lineStart && lineEnd <= end.line) {
const size = end.line - start.line;
if (size > largestSize) {
largestSize = size;
largestEnclosingContext = node;
}
}
return { largestSize, largestEnclosingContext };
};

export class PythonParser implements AbstractParser {
/**
* Finds the largest enclosing context for the specified line range.
*/
findEnclosingContext(
file: string,
lineStart: number,
lineEnd: number
): EnclosingContext {
// TODO: Implement this method for Python
return null;
try {
const parsed = ast.parse(file); // Parse the Python file into an AST
let largestEnclosingContext: any = null;
let largestSize = 0;

// Recursive traversal function to check each node
const traverseNode = (node: any) => {
({ largestSize, largestEnclosingContext } = processNode(
node,
lineStart,
lineEnd,
largestSize,
largestEnclosingContext
));
if (node.body) {
node.body.forEach(traverseNode); // Recursively process child nodes
}
};

traverseNode(parsed); // Start traversing from the root of the AST

return {
enclosingContext: largestEnclosingContext,
} as EnclosingContext;
} catch (error) {
console.error("Error parsing Python file:", error);
return null;
}
}

/**
* Performs a dry run to validate the Python file syntax.
*/
dryRun(file: string): { valid: boolean; error: string } {
// TODO: Implement this method for Python
return { valid: false, error: "Not implemented yet" };
try {
ast.parse(file); // Try parsing the file
return { valid: true, error: "" };
} catch (error) {
return { valid: false, error: error.message };
}
}
}
}
4 changes: 4 additions & 0 deletions src/context/python-ast.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module 'python-ast' {
export function parse(source: string): any;
// Add other function and type declarations as needed
}
2 changes: 1 addition & 1 deletion src/context/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,4 @@ export const smarterContextPatchStrategy = (file: PRFile) => {
} else {
return expandedPatchStrategy(file);
}
};
};
2 changes: 1 addition & 1 deletion src/data/PRSuggestionImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ export class PRSuggestionImpl implements PRSuggestion {
identity(): string {
return `${this.filename}:${this.comment}`;
}
}
}
2 changes: 1 addition & 1 deletion src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ if (!valid) {
chalk.bold("Please check your .env file and try again.\n")
);
process.exit(1);
}
}
2 changes: 1 addition & 1 deletion src/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,4 @@ export const isConversationWithinLimit = (
// the one for gpt-3.5-turbo as a rough equivalent.
const convoTokens = encodeChat(convo, "gpt-3.5-turbo").length;
return convoTokens < ModelsToTokenLimits[model];
};
};
4 changes: 2 additions & 2 deletions src/prompts/inline-prompt.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChatCompletionMessageParam } from "groq-sdk/resources/chat/completions";
import { PRSuggestion } from "../constants";

export const INLINE_FIX_PROMPT = `In this task, you are provided with a code suggestion in XML format, along with the corresponding file content. Your task is to radiate from this suggestion and draft a precise code fix. Here's how your input will look:
export const INLINE_FIX_PROMPT = `In this task, you are provided with a code suggestion in XML format, along with the corresponding file content. Your task is to radiate from this suggestion and draft a precise code fix. Here's how your input will look:

\`\`\`xml
<suggestion>
Expand Down Expand Up @@ -75,4 +75,4 @@ export const getInlineFixPrompt = (
{ role: "system", content: INLINE_FIX_PROMPT },
{ role: "user", content: userMessage },
];
};
};
2 changes: 1 addition & 1 deletion src/review-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,4 +584,4 @@ export const processPullRequest = async (
suggestions: [],
};
}
};
};
25 changes: 17 additions & 8 deletions src/reviews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,22 @@ export const getGitFile = async (
},
}
);
//@ts-ignore
const decodedContent = Buffer.from(
response.data.content,
"base64"
).toString("utf8");
//@ts-ignore
return { content: decodedContent, sha: response.data.sha };

// Narrow the type to ensure it is a file
if (Array.isArray(response.data)) {
// It's a directory, return null
return { content: null, sha: null };
} else if (response.data.type === "file") {
// Decode file content
const decodedContent = Buffer.from(
response.data.content as string,
"base64"
).toString("utf8");
return { content: decodedContent, sha: response.data.sha };
} else {
// It's a symlink or submodule
return { content: null, sha: null };
}
} catch (exc) {
if (exc.status === 404) {
return { content: null, sha: null };
Expand Down Expand Up @@ -213,4 +222,4 @@ export const createBranch = async (
console.log(exc);
}
return branchDetails;
};
};