{"id":19120678,"url":"https://github.com/waylonwalker/lockhart","last_synced_at":"2025-05-05T16:19:54.956Z","repository":{"id":65421250,"uuid":"591099524","full_name":"WaylonWalker/lockhart","owner":"WaylonWalker","description":"Lockhart is an AI-powered Python library that generates elegant and efficient code, much like the charming and deceiving wizard Gilderoy Lockhart. It allows developers to effortlessly create impressive code and deceive others with their skills, just as Gilderoy Lockhart deceives others with his charm and wizardry.","archived":false,"fork":false,"pushed_at":"2023-02-11T03:25:19.000Z","size":124,"stargazers_count":8,"open_issues_count":8,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-05T16:19:43.869Z","etag":null,"topics":["cli","gpt-3","openai","python","textual","tui"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WaylonWalker.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-01-19T23:11:53.000Z","updated_at":"2024-12-31T06:26:12.000Z","dependencies_parsed_at":"2023-02-12T20:01:29.718Z","dependency_job_id":null,"html_url":"https://github.com/WaylonWalker/lockhart","commit_stats":null,"previous_names":[],"tags_count":40,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WaylonWalker%2Flockhart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WaylonWalker%2Flockhart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WaylonWalker%2Flockhart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WaylonWalker%2Flockhart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WaylonWalker","download_url":"https://codeload.github.com/WaylonWalker/lockhart/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252531881,"owners_count":21763293,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","gpt-3","openai","python","textual","tui"],"created_at":"2024-11-09T05:14:41.875Z","updated_at":"2025-05-05T16:19:54.937Z","avatar_url":"https://github.com/WaylonWalker.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"https://user-images.githubusercontent.com/22648375/213756335-5695774d-fdf6-4afd-920f-36da7e2decf3.png\" alt=\"Markata\" width=\"250\" align=right\u003e\n\n# Lockhart\n\n[![PyPI - Version](https://img.shields.io/pypi/v/lockhart.svg)](https://pypi.org/project/lockhart)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/lockhart.svg)](https://pypi.org/project/lockhart)\n\n---\n\n**Table of Contents**\n\n- [Installation](#installation)\n- [License](#license)\n\n## Installation\n\n```bash\npip install lockhart\n## or with pipx\npipx install lockhart\n```\n\n## Instructions\n\nYou will need an openai key, you can obtain one from their\n[website](https://beta.openai.com/account/api-keys). Once you have it then set\nyour `OPENAI_API_KEY` environment variable.\n\n```bash\nexport OPENAI_API_KEY='sk-***'\n```\n\nLockhart it currently very crude, it works out of the clipboard. Copy a\nfunction to your clipboard, run `lockhart docstring` then paste the docstring\nin.\n\n## lockhart tui\n\n```bash\nlockhart tui\n```\n\nhttps://user-images.githubusercontent.com/22648375/217840817-04626da4-8558-4fc4-8b05-ff0e57a2a28b.mp4\n\n### keys\n\n* C - Create new code\n* e - edit return value from history item\n* E - open an empty edit template\n* o - open the current prompt from history\n* j - next item from history\n* k - prev item from history\n* q - quit\n* d - toggle dark mode\n* b - toggle sidebar of preset prompts\n* G - open an empty prompt for writing a git commit\n\n### Editing prompts\n\nCurrently the tui runs the users configured `$EDITOR` in a subprocess, waits for the editor to close, and if the file was changed then it runs the prompt.  If the file was not changed then it does not run the prompt.\n\n```bash\n## mac/linux\nexport EDITOR=vim\n \n## windows\nset EDITOR=notepad\n```\n\n### closing vim\n\n**:x** without a change to the content will not trigger a file change and the prompt will not run.  If you want to use the prompt as-is without edit close vim with **:wq**.\n\n## CLI\n\n### lockhart prompt run\n\nYou can also run stored prompts from the command line without the tui.\n\n``` bash\n## pipe text into your prompt\necho 'write a python3.10 hello world function' | lockhart prompt run code-create\n\n## use the --text flag\nlockhart prompt run code-create --text 'write a python3.10 hello world function' \n\n## directly edit your prompt with the editor\nlockhart prompt run code-create --edit\n```\n\nThe cli also handles text being piped into a prompt run.  You can still `--edit` it, or pipe the results somewhere.  Many of the commit messages in this repo were created using this.\n\n``` bash\n## pre-populate your commit message\ngit diff --staged | lockhart prompt run commit | git commit -evF -\n\n## write a changelog entry for your current pr\ngh pr diff | lockhart prompt run changelog --edit\n\n## write a changelog entry for your current staged changes\ngit diff --staged | lockhart prompt run changelog --edit\n```\n\n### listing prompts\n\nThe cli can list all of the prompts configured in `~/.config/lockhart/lockhart.toml` using the cli.\n\n``` bash\nlockhart prompt list\n```\n\n## lockhart history\n\nThe cli can output your entire history as json.\n\n``` bash\nlockhart history list\n```\n\n\n--- \n\n## Original features that need re-implemented\n\nThese shouldn't be too bad to get re-implemented, but I think we need a pre-processor to be able to get this working.\n\n## Docstring Examples\n\n```python\ndef add(a, b):\n    \"\"\"\n\n    Add two numbers together.\n\n    Args:\n        a (int): The first number to add.\n        b (int): The second number to add.\n\n    Returns:\n        int: The sum of the two numbers.\n\n    Example:\n        add(2, 3) -\u003e 5\n\n    \"\"\"\n    return a + b\n```\n\nWithout even type hinting the arguments `lockhart` can see that this function is using pandas.\n\n```python\ndef get_summary_data(df):\n    \"\"\"\n    This function takes a dataframe as an argument and returns a summary of the data grouped by column A.\n\n    Args:\n        df (DataFrame): The dataframe to be summarized.\n\n    Returns:\n        DataFrame: A summary of the data grouped by column A, containing the sum of columns C and D.\n\n    Example:\n        df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9], 'D': [10, 11, 12]})\n        get_summary_data(df)\n    \"\"\"\n    df.groupby(\"A\")[[\"C\", \"D\"]].sum()\n```\n\nHere is an example from the fastapi docs. It writes a correct docstring to\ndescribe the function, but misses out that its a fastapi route without more\ncontext than just the function.\n\n```python\n@app.put(\"/items/{item_id}\")\ndef update_item(item_id: int, item: Item):\n    \"\"\"\n    Update an item in the database.\n\n    This function takes an item_id and an item object as parameters and updates the item in the database.\n\n    Args:\n        item_id (int): The id of the item to be updated.\n        item (Item): The item object to be updated.\n\n    Returns:\n        dict: A dictionary containing the item_id and the updated item.\n\n    Example:\n        results = update_item(1, {'name': 'Foo', 'price': 10.99})\n    \"\"\"\n    results = {\"item_id\": item_id, \"item\": item}\n    return results\n```\n\n## Examples Refactor\n\n```python\ndef add(a, b):\n    return a + b\n\n# refactor the following code to compute the ratio of the two numbers\n\ndef ratio(a, b):\n    return a / b\n```\n\n```python\n# Before\ndef get_summary_data(df):\n    df.groupby(\"A\")[[\"C\", \"D\"]].sum()\n\n# refactor the following code to also return the averages\n\n# After\ndef get_summary_data(df):\n    df.groupby(\"A\")[[\"C\", \"D\"]].agg([\"sum\", \"mean\"])\n```\n\nRun `lockhart refactor`, then set the prompt to `refactor the following code to\naccept a parameter item_name`. It did a great job at adding it to the\narguments list, type hinting it to a string, but again missed that this is a\nfastapi route and we wanted to also update the decorator.\n\n````python\n\n``` python\n# before\n@app.put(\"/items/{item_id}\")\ndef update_item(item_id: int, item: Item):\n    results = {\"item_id\": item_id, \"item\": item}\n    return results\n\n# refactor the following code to accept a parameter item_name\n\n# after\n@app.put(\"/items/{item_id}\")\ndef update_item(item_id: int, item_name: str, item: Item):\n    results = {\"item_id\": item_id, \"item_name\": item_name, \"item\": item}\n    return results\n````\n\n## License\n\n`lockhart` is distributed under the terms of the\n[MIT](https://spdx.org/licenses/MIT.html) license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaylonwalker%2Flockhart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwaylonwalker%2Flockhart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaylonwalker%2Flockhart/lists"}