Metadata-Version: 2.1
Name: polyglot-piranha-playground
Version: 0.0.3
Summary: A playground for Piranha
Home-page: https://github.com/uber/piranha
License: UNKNOWN
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: tree-sitter
Requires-Dist: tree-sitter-languages
Requires-Dist: attrs
Requires-Dist: openai
Requires-Dist: polyglot-piranha
Requires-Dist: toml
Requires-Dist: pytest
Requires-Dist: flask
Requires-Dist: flask-socketio
Requires-Dist: comby
Requires-Dist: eventlet

# PiranhaAgent

PiranhaAgent uses a static inference algorithm and OpenAI's GPT-4 model to generate human-like piranha rules from code examples.
It generates these rules in TOML format, which can be applied to refactor other parts of the codebase.


## Install

To get started with PiranhaAgent, follow these instructions:

```
pip install polyglot-piranha-playground
```

## Usage (Playground UI)

To run the playground:

```
piranha-playground
```

To define your transformation rules, you will need to provide pairs of code snippets: 'before' and 'after' transformation. Each piece of code that needs transformation should be marked by unique identifiers surrounded by comments (like `// 1`, `// 2`, etc.). These identifiers serve two purposes:

1. They denote which part of the code should be transformed.
2. They define the transformation sequence, or cascading, i.e., which transformations should follow which.

### Example

Consider the following code snippet:

#### Code before refactoring:

```java
class SomeClass {
  // 1 -> 2

  // 1
  void someMethod(String arg) {

  }
  // end

  void otherMethod() {
    String x;
    // 2
   	someMethod(x);
    // end
  }
}
```

#### Code after refactoring:

```java
class SomeClass {
  // 1 -> 2

  // 1
  public String someMethod() {

  }
  // end

  void otherMethod() {
    String x;
    // 2
    x = someMethod();
    // end
  }
}
```

In this example, there are two transformation points, marked by the identifiers `// 1` and `// 2`.

- `// 1` shows the transformation from `void someMethod(String arg)` to `public String someMethod()`.
- `// 2` shows the transformation from `someMethod(x)` to `x = someMethod()`.

The arrow notation `// 1 -> 2` indicates the transformation cascade, i.e., transformation `// 2` should be applied after transformation `// 1`.

Each transformation snippet begins with the identifier (like `// 1`) and ends with a `// end` comment.

This way of representing transformations helps to create clear, concise, and human-friendly refactoring rules, making it easier to manage and understand your transformations.

Make sure to follow these conventions when inputting your code for refactoring. Happy coding!

**Note: The code before and after must be syntactically correct, and it should parse. Moreover, after applying the rules to code before, the refactored code should match the code after. (spaces are ignored).**


