Skills
Common GraphSitter code snippets
add_copyright_header_skill
Add a copyright header to all files in the codebase
add_decorator_to_foo_functions_skill
This skill adds a specified decorator to all functions within a codebase that start with a particular prefix, ensuring that the decorator is properly imported if not already present.
add_decorator_to_function
Adds a specified decorator to all functions and methods in a codebase, ensuring that it is not already present, and handles the necessary imports for the decorator.
add_docstrings_skill
This skill adds docstrings to all functions and methods in a codebase, ensuring that each function has a descriptive comment explaining its purpose and functionality.
add_return_type_hint_skill
Adds an integer return type hint to all functions whose names start with ‘foo’.
add_type_hints_skill
This skill adds type hints to function parameters and return values in a codebase, enhancing type safety and improving code readability.
add_wrapper_function_skill
Adds a trivial wrapper function around each function and class method, creating a new function that simply calls the original function.
append_parameter_skill
Appends a parameter to the signature of a specified function in both Python and TypeScript codebases.
append_to_global_list
Skill to append 2 to global list variable ‘a’.
append_type_to_union_type_skill
Appends an additional ‘str’ type to a piped union type in Python
asyncify_function_skill
Given a synchronous function ‘func_to_convert’, convert its signature to be asynchronous. The function’s call sites as well as the call sites’ functions are recursively converted as well.
asyncify_type_alias_elements
Given a type alias ‘MyMapper’ containing synchronous methods, convert ‘getFromMethod’ method to be asynchronous. The inherited implementations of the type alias as well as all their call sites are also update.
call_graph_filter
This skill shows a visualization of the call graph from a given function or symbol. It iterates through the usages of the starting function and its subsequent calls, creating a directed graph of function calls. The skill filters out test files and includes only methods with specific names (post, get, patch, delete). By default, the call graph uses red for the starting node, yellow for class methods, and can be customized based on user requests. The graph is limited to a specified depth to manage complexity. In its current form, it ignores recursive calls and external modules but can be modified trivially to include them
call_graph_from_node
This skill creates a directed call graph for a given function. Starting from the specified function, it recursively iterates through its function calls and the functions called by them, building a graph of the call paths to a maximum depth. The root of the directed graph is the starting function, each node represents a function call, and edge from node A to node B indicates that function A calls function B. In its current form, it ignores recursive calls and external modules but can be modified trivially to include them. Furthermore, this skill can easily be adapted to support creating a call graph for a class method. In order to do this one simply needs to replace
function_to_trace = codebase.get_function("function_to_trace")
with
function_to_trace = codebase.get_class("class_of_method_to_trace").get_method("method_to_trace")
call_paths_between_nodes
This skill generates and visualizes a call graph between two specified functions. It starts from a given function and iteratively traverses through its function calls, building a directed graph of the call paths. The skill then identifies all simple paths between the start and end functions, creating a subgraph that includes only the nodes in these paths.
By default, the call graph uses blue for the starting node and red for the ending node, but these colors can be customized based on user preferences. The visualization provides a clear representation of how functions are interconnected, helping developers understand the flow of execution and dependencies between different parts of the codebase.
In its current form, it ignores recursive calls and external modules but can be modified trivially to include them
clear_global_list
Skill to clear global list variable ‘a’.
convert_statement_to_argument
Converts http status code assertion statements into an expect_status
argument
for test functions that make a call to a http method.
convert_to_built_in_type_skill
Replaces type annotations using typing module with builtin types.
Examples: typing.List -> list typing.Dict -> dict typing.Set -> set typing.Tuple -> tuple
dead_code
This skill shows a visualization of the dead code in the codebase. It iterates through all functions in the codebase, identifying those that have no usages and are not in test files or decorated. These functions are considered ‘dead code’ and are added to a directed graph. The skill then explores the dependencies of these dead code functions, adding them to the graph as well. This process helps to identify not only directly unused code but also code that might only be used by other dead code (second-order dead code). The resulting visualization provides a clear picture of potentially removable code, helping developers to clean up and optimize their codebase.
delete_rolled_out_feature_flag_skill
Locates a fully rolled out feature flag that has changed from a default value of False to True, and deletes all uses of the flag assuming the flag value is True. This skill simplifies conditional statements and removes unnecessary imports related to the feature flag.
delete_unused_logger_skill
Removes all global variables that are defined as logger instances if they are unused. This skill works for both Python and TypeScript codebases, with slight variations in the logger initialization pattern.
delete_unused_symbols_skill
Deletes all unused symbols in the codebase except for those starting with bar
(case insensitive) and deletes all files without any remaining symbols.
dict_to_schema
Converts a dictionary into a Schema object. Converts the key value pairs into arguments for the constructor
eslint_comment_skill
Remove eslint disable comments for an eslint rule. This is useful if a codebase is making an eslint rule either not required or reducing it to warning level. If the rule is no longer required/warning level, the disable comments are also no longer required and can be cleaned up.
export_skills
Convert default exports to named exports in TypeScript
file_app_import_graph
This skill visualizes the import relationships for a specific file in the codebase. It creates a directed graph where nodes represent the target file and its imported modules. Edges in the graph indicate the import relationships, pointing from the file to its imports. The skill focuses on a particular file (‘path/to/file.py’) and analyzes its import statements to construct the graph. This visualization helps developers understand the dependencies and structure of imports within the specified file, which can be useful for code organization and dependency management.
foreign_key_graph
This skill helps analyze a data schema by creating a graph representation of SQLAlchemy models and their foreign key relationships.
It processes a collection of SQLAlchemy models with foreign keys referencing each other. All of these models are classes that inherit from BaseModel, similar to the one in this file. Foreign keys are typically defined in the following format: agent_run_id = Column(BigInteger, ForeignKey(“AgentRun.id”, ondelete=“CASCADE”), nullable=False)
The skill iterates through all classes in the codebase, identifying those that are subclasses of BaseModel. For each relevant class, it examines the attributes to find ForeignKey definitions. It then builds a mapping of these relationships.
Using this mapping, the skill constructs a directed graph where:
- Nodes represent the models (with the ‘Model’ suffix stripped from their names)
- Edges represent the foreign key relationships between models
This graph visualization allows for easy analysis of the data schema, showing how different models are interconnected through their foreign key relationships. The resulting graph can be used to understand data dependencies, optimize queries, or refactor the database schema.
generate_docstrings
This skill generates docstrings for all class methods. This is another example of Codebase AI, where is it being used to generate textual content that will then be used as the docstring for the class methods.
This is also an example usecase of the context feature, where additional context is provided to the AI to help it generate the docstrings.
mark_internal_functions_skill
This skill identifies functions that are exclusively used within the application directory and marks them as internal by appending an @internal tag to their docstrings.
move_dataclasses_skills
Moves all classes decorated with @dataclasses into a dedicated directory
move_enums_to_separate_file_skill
Moves any enumerations found within a file into a separate file named enums.py
. If the original file
contains only enumerations, it renames that file to enums.py
. If the enums.py
file does not exist,
it creates one.
move_foo_functions_skill
Moves all functions starting with ‘foo’ to a file named foo
move_non_default_exported_jsx_components_skill
Moves all JSX components that are not exported by default into a new file located in the same directory as the original file.
reduce_if_statement_condition_skill
Simplifies the if/else control flow by reducing conditions that are set to a specific value to True. This skill works for both Python and TypeScript codebases, with slight variations in the condition naming.
refactor_class
This skill refactors the given class to be shorter and more readable. It uses codebase to first find the class, then uses codebase AI to refactor the class. This is a trivial case of using Codebase AI to edit and generate new code that will then be applied to the codebase.
remove_from_global_list
Skill to remove 2 from global list variable ‘a’.
remove_unused_imports_skill
Removes all unused import statements from the codebase, ensuring that only necessary imports are retained in each file.
rename_class_skill
Renames a specified class in the codebase from an old name to a new name.
rename_foo_to_bar_skill
Renames all functions in the codebase that start with ‘foo’ to start with ‘bar’, ensuring consistent naming conventions throughout the code.
rename_global_var_skill
Renames all global variables named ‘x’ to ‘y’ across the codebase.
rename_methods
This skill renames all class methods to something better. This is an example of Codebase AI generating content that is not directly written to the codebase as-in, but is chained and applied to the codebase in a later step.
In this case, the agent is asked to create a new name for each class method, then the new name is used to rename the method in the codebase.
repo_dir_tree
This skill displays the directory or repository tree structure of a codebase. It analyzes the file paths within the codebase and constructs a hierarchical representation of the directory structure. The skill creates a visual graph where each node represents a directory or file, and edges represent the parent-child relationships between directories. This visualization helps developers understand the overall organization of the codebase, making it easier to navigate and manage large projects. Additionally, it can be useful for identifying potential structural issues or inconsistencies in the project layout.
search_type_alias_inheritance_skill
Gets all implementation instances of type alias ‘MyMapper’ in TypeScript codebase.
set_global_var_value_skill
This skill modifies the values of all global variables in the codebase, setting them to 2 if their current assigned value is 1.
skip_all_tests
This skill adds a decorator to all test functions in the codebase, marking them to be skipped during test execution with a specified reason.
unwrap_function_body
Unwraps the body of all functions in the codebase, transforming each function’s code block into a flat structure without nested scopes.
unwrap_if_statement
Unwraps the body of all if statements in the file
unwrap_with_statement
This unwraps a with
statement
update_doc_string_of_decorated_methods
Updates the docstring of methods whose decorator has with_user/withUser in their name by appending ‘OPERATES ON USER DATA’.
update_optional_type_hints_skill
This skill replaces type hints in functions and methods by updating instances of Optional[type] to type | None, ensuring compatibility with modern type hinting practices.
write_test
This skill writes a test for the given function. This is an example of Codebase AI generating brand new code that will then be added to the codebase.
Was this page helpful?