Giter VIP home page Giter VIP logo

copilot's Introduction

Copilot

My personal software development copilot.

Designed to play nicely with the ScriptBox extension for VSCode.

ScriptBox Integration

Presumes the following package.json is present in your ~/.scriptbox directory:

{
  "dependencies": {
    "axios": "^1.3.5",
    "dotenv": "^16.0.3",
    "lodash": "^4.17.15",
    "openai": "^3.2.1"
  }
}

Presumes the following .env file is present in your ~/.scriptbox directory:

COPILOT=http://localhost:1337

Code Generation

require("dotenv").config();

const axios = require("axios");

module.exports = async (selection) => {
  const result = await axios.post(`${process.env.COPILOT}/generate/v2`, {
    specification: selection,
  });

  return result.data;
};

Usage

  1. Create a new empty file (or use an existing one).
  2. Specify the code you want your Copilot to generate. For example:
a selector named countOfOthersState in a file named 'scratch.txt' that will
- count the items in three other imported selectors.
- the imported selectors are from 'myOtherSelectors.ts'

generate tests in a file named "mytests.tests.txt".
  1. If the spec is not the only content in your file, then select only the specification.
  2. Run your ScriptBox code generation script.

Refactoring

require("dotenv").config();

const axios = require("axios");

module.exports = async (selection) => {
  const result = await axios.post(`${process.env.COPILOT}/refactor/v1`, {
    specification: selection,
  });

  return result.data;
};

Usage

  1. Write a comment at the top of the block of code you want refactored.
  2. Select the comment + relevant code.
  3. Run your ScriptBox code refactoring script.
  4. Verify the refactor meets your expectations.

Phoenix Integration

The following addition to Pheonix will show a prompt on ⌘+P. Non-empty entries will be injected into the terminal:dev instance of Copilot.

// Inject a prompt into Copilot
keys.push(
  new Key("p", ["cmd"], async () => {
    const query = await prompt({ placeholder: "▶ Copilot" });

    if (query) {
      Task.run(
        "/usr/local/bin/node",
        ["/Users/caleb/Workspace/copilot/src/inject.mjs", query],
        (task) => {
          if (task.status > 0) {
            alert(task.error);
          }
        }
      );
    }
  })
);

const prompt = ({ placeholder = "" } = {}) =>
  new Promise((resolve, reject) => {
    const screenFrame = Screen.main().flippedVisibleFrame();
    const modal = new Modal();

    modal.isInput = true;
    modal.inputPlaceholder = placeholder;

    modal.origin = {
      x: screenFrame.width / 2 - modal.frame().width / 2,
      y: screenFrame.height / 2 - modal.frame().height / 2,
    };

    modal.textDidCommit = (value, action) => {
      modal.close();
      resolve(value);
    };

    modal.show();
  });

copilot's People

Contributors

calebpeterson avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.