soverant / lattice

MIT License
0 stars 0 forks source link

User Interface Requirement #10

Open farhoud opened 1 month ago

farhoud commented 1 month ago

Stories

user can index a project by providing a project path and main function to lattice user can search for code in human language

Lattice HTTP API Documentation

Base URL

we can also use http over linux socket

http://localhost:12345

Endpoints

1. Index Project

Index a project by providing the project path and main function.

Endpoint

POST /index

Request Body

{
  "path": "<project_path>",
  "main": "<main_function>"
}

Example Request

{
  "path": "/path/to/your/project",
  "main": "main.py"
}

Response

{
  "status": "success",
  "message": "Project indexed successfully."
}

2. Search Code

Search for code in human language.

Endpoint

GET /search

Query Parameters

Example Request

GET /search?query=function+that+calculates+factorial

Response

{
  "status": "success",
  "results": [
    {
      "file": "utils.py",
      "line": 10,
      "code": "def factorial(n):"
    },
    {
      "file": "math_helpers.py",
      "line": 5,
      "code": "def compute_factorial(number):"
    }
  ]
}

Detailed Endpoint Descriptions

Index Project Endpoint

Description: This endpoint allows you to index a project, making it searchable by the Lattice system.

HTTP Method: POST

URL: /index

Request Body:

Example Request:

curl -X POST http://api.lattice.com/index \
  -H "Content-Type: application/json" \
  -d '{
        "path": "/home/user/projects/my_project",
        "main": "app.py"
      }'

Example Response:

{
  "status": "success",
  "message": "Project indexed successfully."
}

Search Code Endpoint

Description: This endpoint allows you to search your indexed codebase using human language.

HTTP Method: GET

URL: /search

Query Parameters:

Example Request:

curl -X GET "http://api.lattice.com/search?query=function+that+parses+JSON+data"

Example Response:

{
  "status": "success",
  "results": [
    {
      "file": "data_parser.py",
      "line": 20,
      "code": "def parse_json(json_string):"
    },
    {
      "file": "json_utils.py",
      "line": 15,
      "code": "def from_json(json_str):"
    }
  ]
}

Error Handling

Common Errors

  1. 400 Bad Request

    • Cause: Missing required fields in the request body or query parameters.
    • Response:
      {
      "status": "error",
      "message": "Missing required fields."
      }
  2. 404 Not Found

    • Cause: No matching results found for the search query.
    • Response:
      {
      "status": "error",
      "message": "No matching results found."
      }
  3. 500 Internal Server Error

    • Cause: An unexpected error occurred on the server.
    • Response:
      {
      "status": "error",
      "message": "An unexpected error occurred. Please try again later."
      }

Conclusion

This HTTP API allows you to index projects and search for code using human language, facilitating easy navigation and management of your codebase. Follow the endpoint guidelines and examples to integrate these capabilities into your applications.

Lattice CLI Documentation

Overview

The Lattice CLI allows you to index your projects and search for code using human language. This makes it easier to manage and navigate through your codebase, especially for larger projects.

Commands

1. index

Index a project by providing the project path and main function to Lattice.

Usage

lattice index --path <project_path> --main <main_function>

Arguments

Example

lattice index --path /path/to/your/project --main main.py

2. search

Search for code in human language.

Usage

lattice search --query "<search_query>"

Arguments

Example

lattice search --query "function that calculates factorial"

Detailed Command Descriptions

Index Command

The index command allows you to index your project, making it searchable by the Lattice system. This is useful for setting up your project in Lattice so that you can leverage advanced search capabilities.

Steps to Use

  1. Ensure your project is located in a specific directory.
  2. Identify the main function or entry point of your project.
  3. Run the index command with the appropriate arguments.

Example Explained

lattice index --path /home/user/projects/my_project --main app.py

Search Command

The search command enables you to search your indexed codebase using human language. This makes it easier to find specific functions, classes, or code snippets without having to remember exact code syntax or file locations.

Steps to Use

  1. Ensure your project has been indexed using the index command.
  2. Formulate a query in human language describing what you are looking for.
  3. Run the search command with your query.

Example Explained

lattice search --query "function that parses JSON data"

Troubleshooting

Common Issues

  1. Project Not Indexed

    • Ensure you have run the index command before attempting to use the search command.
    • Verify the project path and main function are correct.
  2. No Results Found

    • Check the query for accuracy and try using different keywords.
    • Ensure the project was indexed correctly.

Getting Help

For additional help, use the --help flag with any command to display usage information.

lattice index --help
lattice search --help

Conclusion

The Lattice CLI simplifies the process of navigating and managing your codebase by enabling human language search and efficient project indexing. Follow the usage guidelines and examples to make the most out of these powerful features.

farhoud commented 1 month ago

@rekino do we agree on the input for index?

@amrhssn are we on the same page on the provided response?

amrhssn commented 1 month ago

@farhoud This is neat! I like it 🙌🏻

farhoud commented 1 month ago

@amrhssn Does user need to provide a project as an optional input?

do we need to change the Response to:

Response

{
  "status": "success",
  "results": [
    {
      "project": "path or name?"
      "file": "utils.py",
      "line": 10,
      "code": "def factorial(n):"
    },
    {
     "project": "path or name?"
      "file": "math_helpers.py",
      "line": 5,
      "code": "def compute_factorial(number):"
    }
  ]
}
rekino commented 1 month ago

@rekino do we agree on the input for index?

@farhoud According to ast module standards, we need to keep the column number and end line as well as the start line number to uniquely specify a piece of code in a pyhton file.